Skip to content

Commit b1b07b9

Browse files
committed
[GR-42743] Add runtime support for interpreter
PullRequest: graal/17719
2 parents a09a0bb + c203291 commit b1b07b9

File tree

30 files changed

+862
-341
lines changed

30 files changed

+862
-341
lines changed

compiler/mx.compiler/suite.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,7 @@
538538
org.graalvm.nativeimage.llvm,
539539
com.oracle.svm.svm_enterprise,
540540
com.oracle.svm_enterprise.ml_dataset,
541+
com.oracle.svm.enterprise.jdwp.resident,
541542
org.graalvm.nativeimage.base,
542543
org.graalvm.extraimage.builder,
543544
org.graalvm.extraimage.librarysupport,

substratevm/mx.substratevm/suite.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1521,6 +1521,9 @@
15211521
org.graalvm.extraimage.librarysupport,
15221522
com.oracle.svm.extraimage_enterprise,
15231523
org.graalvm.nativeimage.foreign,
1524+
com.oracle.svm.enterprise.jdwp.common,
1525+
com.oracle.svm.enterprise.jdwp.server,
1526+
com.oracle.svm.enterprise.jdwp.resident,
15241527
org.graalvm.truffle.runtime.svm,
15251528
com.oracle.truffle.enterprise.svm""",
15261529
"com.oracle.svm.hosted.c.libc to com.oracle.graal.sandbox",
@@ -1533,6 +1536,7 @@
15331536
"com.oracle.svm.hosted.fieldfolding to jdk.graal.compiler",
15341537
"com.oracle.svm.hosted.phases to jdk.graal.compiler",
15351538
"com.oracle.svm.hosted.reflect to jdk.graal.compiler",
1539+
"com.oracle.svm.core.thread to com.oracle.svm.enterprise.jdwp.resident",
15361540
],
15371541
"requires": [
15381542
"java.management",
@@ -2008,7 +2012,7 @@
20082012
"org.graalvm.collections",
20092013
],
20102014
"exports" : [
2011-
"com.oracle.svm.util to org.graalvm.nativeimage.pointsto,org.graalvm.nativeimage.builder,org.graalvm.nativeimage.librarysupport,org.graalvm.nativeimage.driver,org.graalvm.nativeimage.llvm,org.graalvm.nativeimage.agent.jvmtibase,org.graalvm.nativeimage.agent.tracing,org.graalvm.nativeimage.agent.diagnostics,org.graalvm.nativeimage.junitsupport,com.oracle.svm.svm_enterprise,com.oracle.svm_enterprise.ml_dataset,org.graalvm.extraimage.builder,com.oracle.svm.extraimage_enterprise,org.graalvm.extraimage.librarysupport,org.graalvm.nativeimage.foreign,org.graalvm.truffle.runtime.svm,com.oracle.truffle.enterprise.svm",
2015+
"com.oracle.svm.util to org.graalvm.nativeimage.pointsto,org.graalvm.nativeimage.builder,org.graalvm.nativeimage.librarysupport,org.graalvm.nativeimage.driver,org.graalvm.nativeimage.llvm,org.graalvm.nativeimage.agent.jvmtibase,org.graalvm.nativeimage.agent.tracing,org.graalvm.nativeimage.agent.diagnostics,org.graalvm.nativeimage.junitsupport,com.oracle.svm.svm_enterprise,com.oracle.svm_enterprise.ml_dataset,com.oracle.svm.enterprise.jdwp.resident,org.graalvm.extraimage.builder,com.oracle.svm.extraimage_enterprise,org.graalvm.extraimage.librarysupport,org.graalvm.nativeimage.foreign,org.graalvm.truffle.runtime.svm,com.oracle.truffle.enterprise.svm",
20122016
"com.oracle.svm.common.meta to org.graalvm.nativeimage.pointsto,org.graalvm.nativeimage.builder,org.graalvm.nativeimage.llvm,org.graalvm.extraimage.builder,org.graalvm.nativeimage.foreign,org.graalvm.truffle.runtime.svm,com.oracle.truffle.enterprise.svm",
20132017
"com.oracle.svm.common.option to org.graalvm.nativeimage.pointsto,org.graalvm.nativeimage.builder,org.graalvm.nativeimage.driver,org.graalvm.nativeimage.foreign,org.graalvm.truffle.runtime.svm,com.oracle.truffle.enterprise.svm",
20142018
],

substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/GCImpl.java

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828

2929
import java.lang.ref.Reference;
3030

31+
import com.oracle.svm.core.deopt.DeoptimizationSlotPacking;
32+
import com.oracle.svm.core.interpreter.InterpreterSupport;
3133
import org.graalvm.nativeimage.CurrentIsolate;
3234
import org.graalvm.nativeimage.IsolateThread;
3335
import org.graalvm.nativeimage.Platform;
@@ -842,20 +844,33 @@ private static void walkStack(IsolateThread thread, JavaStackWalk walk, ObjectRe
842844
if (deoptFrame == null) {
843845
Pointer sp = frame.getSP();
844846
CodeInfo codeInfo = CodeInfoAccess.unsafeConvert(frame.getIPCodeInfo());
845-
NonmovableArray<Byte> referenceMapEncoding = CodeInfoAccess.getStackReferenceMapEncoding(codeInfo);
846-
long referenceMapIndex = frame.getReferenceMapIndex();
847-
if (referenceMapIndex == ReferenceMapIndex.NO_REFERENCE_MAP) {
848-
throw CodeInfoTable.fatalErrorNoReferenceMap(sp, frame.getIP(), codeInfo);
849-
}
850-
CodeReferenceMapDecoder.walkOffsetsFromPointer(sp, referenceMapEncoding, referenceMapIndex, visitor, null);
851847

852-
if (RuntimeCompilation.isEnabled() && visitRuntimeCodeInfo && !CodeInfoAccess.isAOTImageCode(codeInfo)) {
848+
if (JavaFrames.isInterpreterLeaveStub(frame)) {
853849
/*
854-
* Runtime-compiled code that is currently on the stack must be kept alive. So,
855-
* we mark the tether as strongly reachable. The RuntimeCodeCacheWalker will
856-
* handle all other object references later on.
850+
* Variable frame size is packed into the first stack slot used for argument
851+
* passing (re-use of deopt slot).
857852
*/
858-
RuntimeCodeInfoAccess.walkTether(codeInfo, visitor);
853+
long varStackSize = DeoptimizationSlotPacking.decodeVariableFrameSizeFromDeoptSlot(sp.readLong(0));
854+
Pointer actualSP = sp.add(WordFactory.unsigned(varStackSize));
855+
856+
InterpreterSupport.walkInterpreterLeaveStubFrame(visitor, actualSP, sp);
857+
} else {
858+
NonmovableArray<Byte> referenceMapEncoding = CodeInfoAccess.getStackReferenceMapEncoding(codeInfo);
859+
long referenceMapIndex = frame.getReferenceMapIndex();
860+
if (referenceMapIndex == ReferenceMapIndex.NO_REFERENCE_MAP) {
861+
throw CodeInfoTable.fatalErrorNoReferenceMap(sp, frame.getIP(), codeInfo);
862+
}
863+
864+
CodeReferenceMapDecoder.walkOffsetsFromPointer(sp, referenceMapEncoding, referenceMapIndex, visitor, null);
865+
866+
if (RuntimeCompilation.isEnabled() && visitRuntimeCodeInfo && !CodeInfoAccess.isAOTImageCode(codeInfo)) {
867+
/*
868+
* Runtime-compiled code that is currently on the stack must be kept alive.
869+
* So, we mark the tether as strongly reachable. The RuntimeCodeCacheWalker
870+
* will handle all other object references later on.
871+
*/
872+
RuntimeCodeInfoAccess.walkTether(codeInfo, visitor);
873+
}
859874
}
860875
} else {
861876
/*

substratevm/src/com.oracle.svm.core.graal.aarch64/src/com/oracle/svm/core/graal/aarch64/SubstrateAArch64Backend.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,7 @@ public ForeignCallLinkage lookupGraalStub(ValueNode valueNode, ForeignCallDescri
825825
}
826826
}
827827

828-
protected static class SubstrateAArch64FrameContext implements FrameContext {
828+
public static class SubstrateAArch64FrameContext implements FrameContext {
829829

830830
protected final SharedMethod method;
831831

@@ -1206,14 +1206,7 @@ public CompilationResultBuilder newCompilationResultBuilder(LIRGenerationResult
12061206
Deoptimizer.StubType stubType = method.getDeoptStubType();
12071207
DataBuilder dataBuilder = new SubstrateDataBuilder();
12081208
CallingConvention callingConvention = lirGenResult.getCallingConvention();
1209-
final FrameContext frameContext;
1210-
if (stubType == Deoptimizer.StubType.EntryStub) {
1211-
frameContext = new DeoptEntryStubContext(method, callingConvention);
1212-
} else if (stubType == Deoptimizer.StubType.ExitStub) {
1213-
frameContext = new DeoptExitStubContext(method, callingConvention);
1214-
} else {
1215-
frameContext = createFrameContext(method);
1216-
}
1209+
FrameContext frameContext = createFrameContext(method, stubType, callingConvention);
12171210
LIR lir = lirGenResult.getLIR();
12181211
OptionValues options = lir.getOptions();
12191212
DebugContext debug = lir.getDebug();
@@ -1224,7 +1217,12 @@ public CompilationResultBuilder newCompilationResultBuilder(LIRGenerationResult
12241217
return crb;
12251218
}
12261219

1227-
protected FrameContext createFrameContext(SharedMethod method) {
1220+
protected FrameContext createFrameContext(SharedMethod method, Deoptimizer.StubType stubType, CallingConvention callingConvention) {
1221+
if (stubType == Deoptimizer.StubType.EntryStub) {
1222+
return new DeoptEntryStubContext(method, callingConvention);
1223+
} else if (stubType == Deoptimizer.StubType.ExitStub) {
1224+
return new DeoptExitStubContext(method, callingConvention);
1225+
}
12281226
return new SubstrateAArch64FrameContext(method);
12291227
}
12301228

@@ -1308,7 +1306,7 @@ public CompilationResult createJNITrampolineMethod(ResolvedJavaMethod method, Co
13081306
result.recordMark(asm.position(), PROLOGUE_END);
13091307
byte[] instructions = asm.close(true);
13101308
result.setTargetCode(instructions, instructions.length);
1311-
result.setTotalFrameSize(getTarget().wordSize * 2); // not really, but 0 not allowed
1309+
result.setTotalFrameSize(getTarget().stackAlignment); // not really, but 0 not allowed
13121310
return result;
13131311
}
13141312

substratevm/src/com.oracle.svm.core.graal.aarch64/src/com/oracle/svm/core/graal/aarch64/SubstrateAArch64RegisterConfig.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@
9595
import jdk.vm.ci.meta.JavaType;
9696
import jdk.vm.ci.meta.MetaAccessProvider;
9797
import jdk.vm.ci.meta.PlatformKind;
98-
import jdk.vm.ci.meta.ResolvedJavaType;
9998
import jdk.vm.ci.meta.Value;
10099
import jdk.vm.ci.meta.ValueKind;
101100

@@ -298,7 +297,7 @@ public CallingConvention getCallingConvention(Type t, JavaType returnType, JavaT
298297
JavaKind[] kinds = new JavaKind[locations.length];
299298
boolean isDarwinPlatform = Platform.includedIn(Platform.DARWIN.class);
300299
for (int i = 0; i < parameterTypes.length; i++) {
301-
JavaKind kind = ObjectLayout.getCallSignatureKind(isEntryPoint, (ResolvedJavaType) parameterTypes[i], metaAccess, target);
300+
JavaKind kind = ObjectLayout.getCallSignatureKind(isEntryPoint, parameterTypes[i], metaAccess, target);
302301
kinds[i] = kind;
303302

304303
Register register = null;
@@ -356,7 +355,7 @@ public CallingConvention getCallingConvention(Type t, JavaType returnType, JavaT
356355
}
357356
}
358357

359-
JavaKind returnKind = returnType == null ? JavaKind.Void : ObjectLayout.getCallSignatureKind(isEntryPoint, (ResolvedJavaType) returnType, metaAccess, target);
358+
JavaKind returnKind = returnType == null ? JavaKind.Void : ObjectLayout.getCallSignatureKind(isEntryPoint, returnType, metaAccess, target);
360359
AllocatableValue returnLocation = returnKind == JavaKind.Void ? Value.ILLEGAL : getReturnRegister(returnKind).asValue(valueKindFactory.getValueKind(returnKind.getStackKind()));
361360
return new SubstrateCallingConvention(type, kinds, currentStackOffset, returnLocation, locations);
362361
}

substratevm/src/com.oracle.svm.core.graal.amd64/src/com/oracle/svm/core/graal/amd64/SubstrateAMD64Backend.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,7 +1204,7 @@ private static ForeignCallDescriptor chooseCPUFeatureVariant(ForeignCallDescript
12041204
* prolog and epilog</a> for Windows), so any changes must take all such requirements into
12051205
* account.
12061206
*/
1207-
protected static class SubstrateAMD64FrameContext implements FrameContext {
1207+
public static class SubstrateAMD64FrameContext implements FrameContext {
12081208

12091209
protected final SharedMethod method;
12101210
protected final CallingConvention callingConvention;
@@ -1745,14 +1745,7 @@ public CompilationResultBuilder newCompilationResultBuilder(LIRGenerationResult
17451745
Deoptimizer.StubType stubType = method.getDeoptStubType();
17461746
DataBuilder dataBuilder = new SubstrateDataBuilder();
17471747
CallingConvention callingConvention = lirGenResult.getCallingConvention();
1748-
final FrameContext frameContext;
1749-
if (stubType == Deoptimizer.StubType.EntryStub) {
1750-
frameContext = new DeoptEntryStubContext(method, callingConvention);
1751-
} else if (stubType == Deoptimizer.StubType.ExitStub) {
1752-
frameContext = new DeoptExitStubContext(method, callingConvention);
1753-
} else {
1754-
frameContext = createFrameContext(method, callingConvention);
1755-
}
1748+
FrameContext frameContext = createFrameContext(method, stubType, callingConvention);
17561749
DebugContext debug = lir.getDebug();
17571750
Register uncompressedNullRegister = useLinearPointerCompression() ? ReservedRegisters.singleton().getHeapBaseRegister() : Register.None;
17581751
CompilationResultBuilder tasm = factory.createBuilder(getProviders(), lirGenResult.getFrameMap(), masm, dataBuilder, frameContext, options, debug, compilationResult,
@@ -1765,7 +1758,12 @@ protected AMD64MacroAssembler createAssembler(OptionValues options) {
17651758
return new AMD64MacroAssembler(getTarget(), options, true);
17661759
}
17671760

1768-
protected FrameContext createFrameContext(SharedMethod method, CallingConvention callingConvention) {
1761+
protected FrameContext createFrameContext(SharedMethod method, Deoptimizer.StubType stubType, CallingConvention callingConvention) {
1762+
if (stubType == Deoptimizer.StubType.EntryStub) {
1763+
return new DeoptEntryStubContext(method, callingConvention);
1764+
} else if (stubType == Deoptimizer.StubType.ExitStub) {
1765+
return new DeoptExitStubContext(method, callingConvention);
1766+
}
17691767
return new SubstrateAMD64FrameContext(method, callingConvention);
17701768
}
17711769

@@ -1835,7 +1833,7 @@ public CompilationResult createJNITrampolineMethod(ResolvedJavaMethod method, Co
18351833
result.recordMark(asm.position(), PROLOGUE_END);
18361834
byte[] instructions = asm.close(true);
18371835
result.setTargetCode(instructions, instructions.length);
1838-
result.setTotalFrameSize(getTarget().wordSize); // not really, but 0 not allowed
1836+
result.setTotalFrameSize(getTarget().stackAlignment); // not really, but 0 not allowed
18391837
return result;
18401838
}
18411839

substratevm/src/com.oracle.svm.core.graal.amd64/src/com/oracle/svm/core/graal/amd64/SubstrateAMD64RegisterConfig.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@
9898
import jdk.vm.ci.meta.JavaType;
9999
import jdk.vm.ci.meta.MetaAccessProvider;
100100
import jdk.vm.ci.meta.PlatformKind;
101-
import jdk.vm.ci.meta.ResolvedJavaType;
102101
import jdk.vm.ci.meta.Value;
103102
import jdk.vm.ci.meta.ValueKind;
104103

@@ -144,8 +143,10 @@ public SubstrateAMD64RegisterConfig(ConfigKind config, MetaAccessProvider metaAc
144143

145144
if (Platform.includedIn(Platform.WINDOWS.class)) {
146145
// This is the Windows 64-bit ABI for parameters.
147-
// Note that float parameters also "consume" a general register and vice versa.
146+
// Note that float parameters also "consume" a general register and vice versa in the
147+
// native ABI.
148148
nativeGeneralParameterRegs = new RegisterArray(rcx, rdx, r8, r9);
149+
149150
javaGeneralParameterRegs = new RegisterArray(rdx, r8, r9, rdi, rsi, rcx);
150151
xmmParameterRegs = new RegisterArray(xmm0, xmm1, xmm2, xmm3);
151152

@@ -289,7 +290,7 @@ public CallingConvention getCallingConvention(Type t, JavaType returnType, JavaT
289290
* argument. In the meantime, we put it in a scratch register. r10 contains the target,
290291
* rax the number of vector args, so r11 is the only scratch register left.
291292
*/
292-
JavaKind kind = ObjectLayout.getCallSignatureKind(isEntryPoint, (ResolvedJavaType) parameterTypes[0], metaAccess, target);
293+
JavaKind kind = ObjectLayout.getCallSignatureKind(isEntryPoint, parameterTypes[0], metaAccess, target);
293294
kinds[0] = kind;
294295
ValueKind<?> paramValueKind = valueKindFactory.getValueKind(isEntryPoint ? kind : kind.getStackKind());
295296
locations[0] = r11.asValue(paramValueKind);
@@ -300,7 +301,7 @@ public CallingConvention getCallingConvention(Type t, JavaType returnType, JavaT
300301
int currentXMM = 0;
301302

302303
for (int i = firstActualArgument; i < parameterTypes.length; i++) {
303-
JavaKind kind = ObjectLayout.getCallSignatureKind(isEntryPoint, (ResolvedJavaType) parameterTypes[i], metaAccess, target);
304+
JavaKind kind = ObjectLayout.getCallSignatureKind(isEntryPoint, parameterTypes[i], metaAccess, target);
304305
kinds[i] = kind;
305306

306307
if (type.nativeABI() && Platform.includedIn(Platform.WINDOWS.class)) {
@@ -362,7 +363,7 @@ public CallingConvention getCallingConvention(Type t, JavaType returnType, JavaT
362363
VMError.guarantee(parameterTypes.length == type.fixedParameterAssignment.length, "Parameters/assignments size mismatch.");
363364

364365
for (int i = firstActualArgument; i < locations.length; i++) {
365-
JavaKind kind = ObjectLayout.getCallSignatureKind(isEntryPoint, (ResolvedJavaType) parameterTypes[i], metaAccess, target);
366+
JavaKind kind = ObjectLayout.getCallSignatureKind(isEntryPoint, parameterTypes[i], metaAccess, target);
366367
kinds[i] = kind;
367368

368369
ValueKind<?> paramValueKind = valueKindFactory.getValueKind(isEntryPoint ? kind : kind.getStackKind());
@@ -414,7 +415,7 @@ public CallingConvention getCallingConvention(Type t, JavaType returnType, JavaT
414415
}
415416
}
416417

417-
JavaKind returnKind = returnType == null ? JavaKind.Void : ObjectLayout.getCallSignatureKind(isEntryPoint, (ResolvedJavaType) returnType, metaAccess, target);
418+
JavaKind returnKind = returnType == null ? JavaKind.Void : ObjectLayout.getCallSignatureKind(isEntryPoint, returnType, metaAccess, target);
418419
AllocatableValue returnLocation = returnKind == JavaKind.Void ? Value.ILLEGAL : getReturnRegister(returnKind).asValue(valueKindFactory.getValueKind(returnKind.getStackKind()));
419420
return new SubstrateCallingConvention(type, kinds, currentStackOffset, returnLocation, locations);
420421
}
@@ -434,4 +435,8 @@ public RegisterArray filterAllocatableRegisters(PlatformKind kind, RegisterArray
434435
public RegisterArray getJavaGeneralParameterRegs() {
435436
return javaGeneralParameterRegs;
436437
}
438+
439+
public RegisterArray getFloatingPointParameterRegs() {
440+
return xmmParameterRegs;
441+
}
437442
}

substratevm/src/com.oracle.svm.core.graal.riscv64/src/com/oracle/svm/core/graal/riscv64/SubstrateRISCV64RegisterConfig.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@
9898
import jdk.vm.ci.meta.JavaType;
9999
import jdk.vm.ci.meta.MetaAccessProvider;
100100
import jdk.vm.ci.meta.PlatformKind;
101-
import jdk.vm.ci.meta.ResolvedJavaType;
102101
import jdk.vm.ci.meta.Value;
103102
import jdk.vm.ci.meta.ValueKind;
104103

@@ -238,7 +237,7 @@ public CallingConvention getCallingConvention(Type t, JavaType returnType, JavaT
238237

239238
JavaKind[] kinds = new JavaKind[locations.length];
240239
for (int i = 0; i < parameterTypes.length; i++) {
241-
JavaKind kind = ObjectLayout.getCallSignatureKind(isEntryPoint, (ResolvedJavaType) parameterTypes[i], metaAccess, target);
240+
JavaKind kind = ObjectLayout.getCallSignatureKind(isEntryPoint, parameterTypes[i], metaAccess, target);
242241
kinds[i] = kind;
243242

244243
Register register = null;
@@ -288,7 +287,7 @@ public CallingConvention getCallingConvention(Type t, JavaType returnType, JavaT
288287
}
289288
}
290289

291-
JavaKind returnKind = returnType == null ? JavaKind.Void : ObjectLayout.getCallSignatureKind(isEntryPoint, (ResolvedJavaType) returnType, metaAccess, target);
290+
JavaKind returnKind = returnType == null ? JavaKind.Void : ObjectLayout.getCallSignatureKind(isEntryPoint, returnType, metaAccess, target);
292291
AllocatableValue returnLocation = returnKind == JavaKind.Void ? Value.ILLEGAL : getReturnRegister(returnKind).asValue(valueKindFactory.getValueKind(returnKind.getStackKind()));
293292
return new SubstrateCallingConvention(type, kinds, currentStackOffset, returnLocation, locations);
294293
}

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/classinitialization/ClassInitializationInfo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ private boolean isBeingInitialized() {
252252
return initState == InitState.BeingInitialized;
253253
}
254254

255-
private boolean isInErrorState() {
255+
public boolean isInErrorState() {
256256
return initState == InitState.InitializationError;
257257
}
258258

0 commit comments

Comments
 (0)