Skip to content

Commit 59e1799

Browse files
committed
[GR-77557] Pin initial layer singleton accesses to the initial layer in doRunInNewThread
PullRequest: graal/24742
2 parents 364b83a + 6a99f36 commit 59e1799

2 files changed

Lines changed: 33 additions & 6 deletions

File tree

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/JavaMainWrapper.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
import org.graalvm.word.impl.Word;
5151

5252
import com.oracle.svm.core.jfr.events.ShutdownEvent;
53-
import com.oracle.svm.guest.staging.jdk.RuntimeSupport;
5453
import com.oracle.svm.core.jni.JNIJavaVMList;
5554
import com.oracle.svm.core.jni.functions.JNIFunctionTables;
5655
import com.oracle.svm.core.log.Log;
@@ -72,6 +71,7 @@
7271
import com.oracle.svm.guest.staging.core.UnmanagedMemoryUtil;
7372
import com.oracle.svm.guest.staging.core.thread.OSThreadHandle;
7473
import com.oracle.svm.guest.staging.jdk.InternalVMMethod;
74+
import com.oracle.svm.guest.staging.jdk.RuntimeSupport;
7575
import com.oracle.svm.sdk.staging.layeredimage.LayeredCompilationBehavior;
7676
import com.oracle.svm.sdk.staging.layeredimage.LayeredCompilationBehavior.Behavior;
7777
import com.oracle.svm.shared.Uninterruptible;
@@ -277,14 +277,13 @@ private static int doRun(int argc, CCharPointerPointer argv) {
277277
private static int doRunInNewThread(int argc, CCharPointerPointer argv) {
278278
try {
279279
Isolate isolate = createMainIsolate(argc, argv);
280-
long javaStackSize = PlatformThreads.singleton().getMainThreadRunnerJavaStackSize();
281-
PlatformThreads.singleton().releaseMainThreadFromCurrent();
280+
long javaStackSize = getJavaStackSize();
282281
WordPointer threadExitStatus = StackValue.get(WordPointer.class);
283282
/*
284283
* The launcher blocks in a no-transition OS join, so detach it before the runner can
285284
* request VM operations.
286285
*/
287-
VMThreads.singleton().detachCurrentThread();
286+
detachCurrentThread();
288287
int exitCode = startAndJoinMainRunner(isolate, javaStackSize, threadExitStatus);
289288

290289
runShutdownOnInitialThread(isolate);
@@ -294,6 +293,20 @@ private static int doRunInNewThread(int argc, CCharPointerPointer argv) {
294293
}
295294
}
296295

296+
@Uninterruptible(reason = "Thread state not setup yet.")
297+
@LayeredCompilationBehavior(Behavior.PINNED_TO_INITIAL_LAYER)
298+
private static long getJavaStackSize() {
299+
long javaStackSize = PlatformThreads.singleton().getMainThreadRunnerJavaStackSize();
300+
PlatformThreads.singleton().releaseMainThreadFromCurrent();
301+
return javaStackSize;
302+
}
303+
304+
@Uninterruptible(reason = "Thread state not setup yet.")
305+
@LayeredCompilationBehavior(Behavior.PINNED_TO_INITIAL_LAYER)
306+
private static void detachCurrentThread() {
307+
VMThreads.singleton().detachCurrentThread();
308+
}
309+
297310
/**
298311
* Starts and joins the runner while the current launcher thread is detached from the isolate.
299312
*/

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ExtensionLayerImageFeature.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,27 @@
2929
import java.util.function.Predicate;
3030

3131
import org.graalvm.collections.EconomicMap;
32+
import org.graalvm.collections.EconomicSet;
3233

3334
import com.oracle.graal.pointsto.api.HostVM;
3435
import com.oracle.graal.pointsto.meta.AnalysisType;
3536
import com.oracle.graal.pointsto.meta.AnalysisUniverse;
3637
import com.oracle.svm.core.c.BoxedRelocatedPointer;
3738
import com.oracle.svm.core.code.ImageCodeInfo;
38-
import com.oracle.svm.shared.feature.AutomaticallyRegisteredFeature;
3939
import com.oracle.svm.core.feature.InternalFeature;
4040
import com.oracle.svm.core.imagelayer.ImageLayerBuildingSupport;
41-
import com.oracle.svm.shared.util.VMError;
4241
import com.oracle.svm.hosted.FeatureImpl.BeforeAnalysisAccessImpl;
4342
import com.oracle.svm.hosted.FeatureImpl.BeforeCompilationAccessImpl;
4443
import com.oracle.svm.hosted.imagelayer.HostedImageLayerBuildingSupport;
4544
import com.oracle.svm.hosted.imagelayer.InitialLayerFeature;
4645
import com.oracle.svm.hosted.imagelayer.SVMImageLayerLoader;
4746
import com.oracle.svm.sdk.staging.layeredimage.LayeredCompilationBehavior;
47+
import com.oracle.svm.shared.feature.AutomaticallyRegisteredFeature;
4848
import com.oracle.svm.shared.util.ReflectionUtil;
49+
import com.oracle.svm.shared.util.VMError;
50+
import com.oracle.svm.util.GuestAccess;
51+
52+
import jdk.vm.ci.meta.ResolvedJavaType;
4953

5054
/**
5155
* This feature contains some configs currently necessary to build an extension layer. We'll need
@@ -97,7 +101,17 @@ public void beforeCompilation(BeforeCompilationAccess a) {
97101
SVMImageLayerLoader imageLayerLoader = HostedImageLayerBuildingSupport.singleton().getLoader();
98102
EconomicMap<AnalysisType, Object> superCoreTypes = EconomicMap.create();
99103

104+
EconomicSet<ResolvedJavaType> extensionLayerCoreTypes = EconomicSet.create();
105+
/*
106+
* This type is meant to be only accessed in the application layer if the application needs
107+
* a main routine, so it should not be checked here.
108+
*/
109+
extensionLayerCoreTypes.add(GuestAccess.get().lookupType("com.oracle.svm.core.JavaRunMainRoutinePointerHolder"));
110+
100111
for (var type : universe.getTypes()) {
112+
if (extensionLayerCoreTypes.contains(type.getWrapped())) {
113+
continue;
114+
}
101115
/*
102116
* These checks allow to ensure that core types can be treated as closed (see
103117
* PointsToAnalysis.isClosed(AnalysisType)).

0 commit comments

Comments
 (0)