Skip to content

Commit 6fe6878

Browse files
committed
[GR-20608] Set UseBranchesWithin32ByteBoundary accordingly.
PullRequest: graal/5273
2 parents 0dc9a65 + 32100f5 commit 6fe6878

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

compiler/src/org.graalvm.compiler.asm.amd64/src/org/graalvm/compiler/asm/amd64/AMD64Assembler.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ public class AMD64Assembler extends AMD64BaseAssembler {
107107
public static class Options {
108108
// @formatter:off
109109
@Option(help = "Force branch instructions to align with 32-bytes boundary, to mitigate the jcc erratum. " +
110-
"See https://www.intel.com/content/dam/support/us/en/documents/processors/mitigations-jump-conditional-code-erratum.pdf for more details.", type = OptionType.User)
110+
"See https://www.intel.com/content/dam/support/us/en/documents/processors/mitigations-jump-conditional-code-erratum.pdf for more details. " +
111+
"If not set explicitly, the default value will be determined according to the CPU model.", type = OptionType.User)
111112
public static final OptionKey<Boolean> UseBranchesWithin32ByteBoundary = new OptionKey<>(false);
112113
// @formatter:on
113114
}
@@ -120,19 +121,28 @@ public interface CodePatchShifter {
120121

121122
protected CodePatchShifter codePatchShifter = null;
122123

124+
/**
125+
* Constructs an assembler for the AMD64 architecture.
126+
*/
123127
public AMD64Assembler(TargetDescription target) {
124128
super(target);
125129
useBranchesWithin32ByteBoundary = false;
126130
}
127131

128-
/**
129-
* Constructs an assembler for the AMD64 architecture.
130-
*/
131132
public AMD64Assembler(TargetDescription target, OptionValues optionValues) {
132133
super(target);
133134
useBranchesWithin32ByteBoundary = Options.UseBranchesWithin32ByteBoundary.getValue(optionValues);
134135
}
135136

137+
public AMD64Assembler(TargetDescription target, OptionValues optionValues, boolean hasIntelJccErratum) {
138+
super(target);
139+
if (Options.UseBranchesWithin32ByteBoundary.hasBeenSet(optionValues)) {
140+
useBranchesWithin32ByteBoundary = Options.UseBranchesWithin32ByteBoundary.getValue(optionValues);
141+
} else {
142+
useBranchesWithin32ByteBoundary = hasIntelJccErratum;
143+
}
144+
}
145+
136146
public void setCodePatchShifter(CodePatchShifter codePatchShifter) {
137147
assert this.codePatchShifter == null : "overwriting existing value";
138148
this.codePatchShifter = codePatchShifter;

compiler/src/org.graalvm.compiler.asm.amd64/src/org/graalvm/compiler/asm/amd64/AMD64MacroAssembler.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ public AMD64MacroAssembler(TargetDescription target, OptionValues optionValues)
6363
super(target, optionValues);
6464
}
6565

66+
public AMD64MacroAssembler(TargetDescription target, OptionValues optionValues, boolean hasIntelJccErratum) {
67+
super(target, optionValues, hasIntelJccErratum);
68+
}
69+
6670
public final void decrementq(Register reg, int value) {
6771
if (value == Integer.MIN_VALUE) {
6872
subq(reg, value);

compiler/src/org.graalvm.compiler.hotspot.amd64/src/org/graalvm/compiler/hotspot/amd64/AMD64HotSpotBackend.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ public CompilationResultBuilder newCompilationResultBuilder(LIRGenerationResult
217217
!((AMD64FrameMap) frameMap).useStandardFrameProlog();
218218

219219
Stub stub = gen.getStub();
220-
AMD64MacroAssembler masm = new AMD64MacroAssembler(getTarget(), options);
220+
AMD64MacroAssembler masm = new AMD64MacroAssembler(getTarget(), options, config.CPU_HAS_INTEL_JCC_ERRATUM);
221221
masm.setCodePatchShifter(compilationResult::shiftCodePatch);
222222
HotSpotFrameContext frameContext = new HotSpotFrameContext(stub != null, omitFrame, config.preserveFramePointer);
223223
DataBuilder dataBuilder = new HotSpotDataBuilder(getCodeCache().getTarget());

compiler/src/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/GraalHotSpotVMConfig.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,9 @@ private boolean checkNullAllocationStubs() {
897897
public final int MARKID_CARD_TABLE_ADDRESS = getConstant("CodeInstaller::CARD_TABLE_ADDRESS", Integer.class);
898898
public final int MARKID_INVOKE_INVALID = getConstant("CodeInstaller::INVOKE_INVALID", Integer.class);
899899

900+
public final boolean CPU_HAS_INTEL_JCC_ERRATUM = getFieldValue("VM_Version::_has_intel_jcc_erratum", Boolean.class, "bool",
901+
true, "amd64".equals(osArch) && (JVMCI ? jvmciGE(JVMCI_20_1_b01) : JDK >= 15));
902+
900903
/**
901904
* The following constants are given default values here since they are missing in the native
902905
* JVMCI-8 code but are still required for {@link GraalHotSpotVMConfigNode#canonical} to work in

0 commit comments

Comments
 (0)