diff --git a/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/graal/GenScavengeGCFeature.java b/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/graal/GenScavengeGCFeature.java
index 14d45bfd9f64..0fcee811d5d4 100644
--- a/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/graal/GenScavengeGCFeature.java
+++ b/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/graal/GenScavengeGCFeature.java
@@ -61,6 +61,7 @@
import com.oracle.svm.core.jvmstat.PerfDataFeature;
import com.oracle.svm.core.jvmstat.PerfDataHolder;
import com.oracle.svm.core.jvmstat.PerfManager;
+import com.oracle.svm.core.layeredimagesingleton.LayeredImageSingletonSupport;
import com.oracle.svm.core.os.CommittedMemoryProvider;
import com.oracle.svm.core.os.OSCommittedMemoryProvider;
@@ -132,19 +133,19 @@ public void beforeAnalysis(BeforeAnalysisAccess access) {
access.registerAsUsed(Object[].class);
}
- private static ImageHeapInfo getImageHeapInfo() {
- return ImageSingletons.lookup(ImageHeapInfo.class);
+ private static ImageHeapInfo getCurrentLayerImageHeapInfo() {
+ return LayeredImageSingletonSupport.singleton().lookup(ImageHeapInfo.class, false, true);
}
@Override
public void afterAnalysis(AfterAnalysisAccess access) {
- ImageHeapLayouter heapLayouter = new ChunkedImageHeapLayouter(getImageHeapInfo(), Heap.getHeap().getImageHeapOffsetInAddressSpace());
+ ImageHeapLayouter heapLayouter = new ChunkedImageHeapLayouter(getCurrentLayerImageHeapInfo(), Heap.getHeap().getImageHeapOffsetInAddressSpace());
ImageSingletons.add(ImageHeapLayouter.class, heapLayouter);
}
@Override
public void beforeCompilation(BeforeCompilationAccess access) {
- access.registerAsImmutable(getImageHeapInfo());
+ access.registerAsImmutable(getCurrentLayerImageHeapInfo());
}
@Override
diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/code/CodeInfoTable.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/code/CodeInfoTable.java
index 458a250a6bfd..ccd85f946adc 100644
--- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/code/CodeInfoTable.java
+++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/code/CodeInfoTable.java
@@ -27,8 +27,9 @@
import java.util.Arrays;
import java.util.List;
-import jdk.graal.compiler.word.Word;
import org.graalvm.nativeimage.ImageSingletons;
+import org.graalvm.nativeimage.Platform;
+import org.graalvm.nativeimage.Platforms;
import org.graalvm.nativeimage.c.function.CodePointer;
import org.graalvm.nativeimage.hosted.Feature;
import org.graalvm.word.Pointer;
@@ -45,6 +46,7 @@
import com.oracle.svm.core.heap.RestrictHeapAccess;
import com.oracle.svm.core.heap.RestrictHeapAccess.Access;
import com.oracle.svm.core.heap.VMOperationInfos;
+import com.oracle.svm.core.layeredimagesingleton.LayeredImageSingletonSupport;
import com.oracle.svm.core.layeredimagesingleton.MultiLayeredImageSingleton;
import com.oracle.svm.core.log.Log;
import com.oracle.svm.core.meta.SharedMethod;
@@ -57,12 +59,13 @@
import jdk.graal.compiler.api.replacements.Fold;
import jdk.graal.compiler.options.Option;
+import jdk.graal.compiler.word.Word;
import jdk.vm.ci.code.InstalledCode;
/**
- * Provides the main entry points to look up metadata for code, either {@link #getImageCodeCache()
- * ahead-of-time compiled code in the native image} or {@link CodeInfoTable#getRuntimeCodeCache()
- * code compiled at runtime}.
+ * Provides the main entry points to look up metadata for code, either
+ * {@link #getImageCodeCacheForLayer(int) ahead-of-time compiled code in the native image} or
+ * {@link CodeInfoTable#getRuntimeCodeCache() code compiled at runtime}.
*
* Users of this class must take special care because code can be invalidated at arbitrary times and
* their metadata can be freed, see notes on {@link CodeInfoAccess}.
@@ -77,9 +80,14 @@ public static class Options {
public static final HostedOptionKey CodeCacheCounters = new HostedOptionKey<>(false);
}
- @Fold
- public static ImageCodeInfo getImageCodeCache() {
- return ImageSingletons.lookup(ImageCodeInfo.class);
+ @Platforms(Platform.HOSTED_ONLY.class)
+ public static ImageCodeInfo getCurrentLayerImageCodeCache() {
+ return LayeredImageSingletonSupport.singleton().lookup(ImageCodeInfo.class, false, true);
+ }
+
+ @Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
+ public static ImageCodeInfo getImageCodeCacheForLayer(int layerNumber) {
+ return MultiLayeredImageSingleton.getForLayer(ImageCodeInfo.class, layerNumber);
}
@Fold
@@ -90,7 +98,7 @@ public static RuntimeCodeCache getRuntimeCodeCache() {
@Uninterruptible(reason = "Executes during isolate creation.")
public static void prepareImageCodeInfo() {
// Stored in this class because ImageCodeInfo is immutable
- imageCodeInfo = getImageCodeCache().prepareCodeInfo();
+ imageCodeInfo = ImageCodeInfo.prepareCodeInfo();
assert imageCodeInfo.notEqual(Word.zero());
}
@@ -324,7 +332,7 @@ public void duringSetup(DuringSetupAccess access) {
@Override
public void afterCompilation(AfterCompilationAccess config) {
- ImageCodeInfo imageInfo = CodeInfoTable.getImageCodeCache();
+ ImageCodeInfo imageInfo = CodeInfoTable.getCurrentLayerImageCodeCache();
config.registerAsImmutable(imageInfo);
config.registerAsImmutable(imageInfo.codeInfoIndex);
config.registerAsImmutable(imageInfo.codeInfoEncodings);
diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/code/ImageCodeInfo.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/code/ImageCodeInfo.java
index e109288fd855..b718b6ad560e 100644
--- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/code/ImageCodeInfo.java
+++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/code/ImageCodeInfo.java
@@ -84,7 +84,7 @@ public class ImageCodeInfo implements MultiLayeredImageSingleton, UnsavedSinglet
}
@Uninterruptible(reason = "Executes during isolate creation.")
- CodeInfo prepareCodeInfo() {
+ static CodeInfo prepareCodeInfo() {
ImageCodeInfo[] imageCodeInfos = MultiLayeredImageSingleton.getAllLayers(ImageCodeInfo.class);
ImageCodeInfoStorage[] runtimeCodeInfos = MultiLayeredImageSingleton.getAllLayers(ImageCodeInfoStorage.class);
int size = imageCodeInfos.length;
diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/code/RuntimeMetadataDecoderImpl.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/code/RuntimeMetadataDecoderImpl.java
index f2f3a4bdb9ed..c2024cc90723 100644
--- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/code/RuntimeMetadataDecoderImpl.java
+++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/code/RuntimeMetadataDecoderImpl.java
@@ -37,7 +37,6 @@
import java.util.List;
import java.util.function.Function;
-import org.graalvm.nativeimage.ImageSingletons;
import org.graalvm.nativeimage.Platforms;
import org.graalvm.nativeimage.impl.InternalPlatform;
@@ -279,7 +278,7 @@ public boolean isNegative(int modifiers) {
@Override
public int getMetadataByteLength() {
- return ImageSingletons.lookup(RuntimeMetadataEncoding.class).getEncoding().length;
+ return RuntimeMetadataEncoding.currentLayer().getEncoding().length;
}
public static boolean isErrorIndex(int index) {
diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/code/RuntimeMetadataEncoding.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/code/RuntimeMetadataEncoding.java
index 7ac7c635b684..a8180a022237 100644
--- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/code/RuntimeMetadataEncoding.java
+++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/code/RuntimeMetadataEncoding.java
@@ -34,6 +34,7 @@
import com.oracle.svm.core.feature.AutomaticallyRegisteredImageSingleton;
import com.oracle.svm.core.heap.UnknownObjectField;
import com.oracle.svm.core.layeredimagesingleton.LayeredImageSingletonBuilderFlags;
+import com.oracle.svm.core.layeredimagesingleton.LayeredImageSingletonSupport;
import com.oracle.svm.core.layeredimagesingleton.MultiLayeredImageSingleton;
import com.oracle.svm.core.layeredimagesingleton.UnsavedSingleton;
@@ -51,6 +52,11 @@
public class RuntimeMetadataEncoding implements MultiLayeredImageSingleton, UnsavedSingleton {
@UnknownObjectField(availability = AfterCompilation.class) private byte[] encoding;
+ @Platforms(Platform.HOSTED_ONLY.class)
+ public static RuntimeMetadataEncoding currentLayer() {
+ return LayeredImageSingletonSupport.singleton().lookup(RuntimeMetadataEncoding.class, false, true);
+ }
+
public byte[] getEncoding() {
return encoding;
}
diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/hub/ClassForNameSupport.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/hub/ClassForNameSupport.java
index b78b746918e3..18a05ad417a1 100644
--- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/hub/ClassForNameSupport.java
+++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/hub/ClassForNameSupport.java
@@ -30,7 +30,6 @@
import java.util.Objects;
import org.graalvm.collections.EconomicMap;
-import org.graalvm.nativeimage.ImageSingletons;
import org.graalvm.nativeimage.Platform;
import org.graalvm.nativeimage.Platform.HOSTED_ONLY;
import org.graalvm.nativeimage.Platforms;
@@ -40,6 +39,7 @@
import com.oracle.svm.core.configure.RuntimeConditionSet;
import com.oracle.svm.core.feature.AutomaticallyRegisteredImageSingleton;
import com.oracle.svm.core.layeredimagesingleton.LayeredImageSingletonBuilderFlags;
+import com.oracle.svm.core.layeredimagesingleton.LayeredImageSingletonSupport;
import com.oracle.svm.core.layeredimagesingleton.MultiLayeredImageSingleton;
import com.oracle.svm.core.layeredimagesingleton.UnsavedSingleton;
import com.oracle.svm.core.reflect.MissingReflectionRegistrationUtils;
@@ -55,8 +55,13 @@ public void setLibGraalLoader(ClassLoader libGraalLoader) {
this.libGraalLoader = libGraalLoader;
}
- public static ClassForNameSupport singleton() {
- return ImageSingletons.lookup(ClassForNameSupport.class);
+ @Platforms(Platform.HOSTED_ONLY.class)
+ public static ClassForNameSupport currentLayer() {
+ return LayeredImageSingletonSupport.singleton().lookup(ClassForNameSupport.class, false, true);
+ }
+
+ private static ClassForNameSupport[] layeredSingletons() {
+ return MultiLayeredImageSingleton.getAllLayers(ClassForNameSupport.class);
}
/**
@@ -187,9 +192,13 @@ private static Class> forName(String className, ClassLoader classLoader, boole
if (className == null) {
return null;
}
- ClassForNameSupport classForNameSupport = singleton();
- Object result = classForNameSupport.getSingletonData(classForNameSupport, MultiLayeredImageSingleton.getAllLayers(ClassForNameSupport.class),
- singleton -> singleton.forName0(className, classLoader));
+ Object result = null;
+ for (var singleton : layeredSingletons()) {
+ result = singleton.forName0(className, classLoader);
+ if (result != null) {
+ break;
+ }
+ }
// Note: for non-predefined classes, we (currently) don't need to check the provided loader
// TODO rewrite stack traces (GR-42813)
if (result instanceof Class>) {
@@ -238,9 +247,13 @@ public int count() {
public static RuntimeConditionSet getConditionFor(Class> jClass) {
Objects.requireNonNull(jClass);
String jClassName = jClass.getName();
- ClassForNameSupport classForNameSupport = singleton();
- ConditionalRuntimeValue