Skip to content

Commit

Permalink
Automatic merge of master into galahad
Browse files Browse the repository at this point in the history
  • Loading branch information
OracleLabsAutomation committed Jan 22, 2025
2 parents a4fd244 + 9406810 commit dd30ea1
Show file tree
Hide file tree
Showing 40 changed files with 259 additions and 164 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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}.
* <p>
* 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}.
Expand All @@ -77,9 +80,14 @@ public static class Options {
public static final HostedOptionKey<Boolean> 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
Expand All @@ -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());
}

Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -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<?>) {
Expand Down Expand Up @@ -238,9 +247,13 @@ public int count() {
public static RuntimeConditionSet getConditionFor(Class<?> jClass) {
Objects.requireNonNull(jClass);
String jClassName = jClass.getName();
ClassForNameSupport classForNameSupport = singleton();
ConditionalRuntimeValue<Object> conditionalClass = classForNameSupport.getSingletonData(classForNameSupport, MultiLayeredImageSingleton.getAllLayers(ClassForNameSupport.class),
singleton -> singleton.knownClasses.get(jClassName));
ConditionalRuntimeValue<Object> conditionalClass = null;
for (var singleton : layeredSingletons()) {
conditionalClass = singleton.knownClasses.get(jClassName);
if (conditionalClass != null) {
break;
}
}
if (conditionalClass == null) {
return RuntimeConditionSet.unmodifiableEmptySet();
} else {
Expand All @@ -254,9 +267,13 @@ public static RuntimeConditionSet getConditionFor(Class<?> jClass) {
*/
public static boolean canUnsafeInstantiateAsInstance(DynamicHub hub) {
Class<?> clazz = DynamicHub.toClass(hub);
ClassForNameSupport classForNameSupport = singleton();
RuntimeConditionSet conditionSet = classForNameSupport.getSingletonData(classForNameSupport, MultiLayeredImageSingleton.getAllLayers(ClassForNameSupport.class),
singleton -> singleton.unsafeInstantiatedClasses.get(clazz));
RuntimeConditionSet conditionSet = null;
for (var singleton : layeredSingletons()) {
conditionSet = singleton.unsafeInstantiatedClasses.get(clazz);
if (conditionSet != null) {
break;
}
}
return conditionSet != null && conditionSet.satisfied();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

import java.util.EnumSet;

import org.graalvm.nativeimage.ImageSingletons;
import org.graalvm.nativeimage.Platform;
import org.graalvm.nativeimage.Platforms;

Expand All @@ -39,6 +38,7 @@
import com.oracle.svm.core.heap.UnknownObjectField;
import com.oracle.svm.core.heap.UnknownPrimitiveField;
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;

Expand All @@ -49,8 +49,8 @@ public final class DynamicHubSupport implements MultiLayeredImageSingleton, Unsa
@UnknownObjectField(availability = AfterHostedUniverse.class) private byte[] referenceMapEncoding;

@Platforms(Platform.HOSTED_ONLY.class)
public static DynamicHubSupport singleton() {
return ImageSingletons.lookup(DynamicHubSupport.class);
public static DynamicHubSupport currentLayer() {
return LayeredImageSingletonSupport.singleton().lookup(DynamicHubSupport.class, false, true);
}

@AlwaysInline("Performance")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import java.util.function.BooleanSupplier;
import java.util.stream.Stream;

import org.graalvm.nativeimage.ImageSingletons;
import org.graalvm.nativeimage.Platform;
import org.graalvm.nativeimage.Platforms;
import org.graalvm.nativeimage.hosted.FieldValueTransformer;
Expand Down Expand Up @@ -171,7 +170,7 @@ final class Target_java_lang_String {
@Substitute
public String intern() {
String thisStr = SubstrateUtil.cast(this, String.class);
return ImageSingletons.lookup(StringInternSupport.class).intern(thisStr);
return StringInternSupport.intern(thisStr);
}

@AnnotateOriginal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
import com.oracle.svm.core.jdk.resources.CompressedGlobTrie.GlobTrieNode;
import com.oracle.svm.core.jdk.resources.CompressedGlobTrie.GlobUtils;
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.util.ImageHeapMap;
Expand All @@ -94,8 +95,8 @@ public final class Resources implements MultiLayeredImageSingleton, UnsavedSingl
* singleton otherwise
*/
@Platforms(Platform.HOSTED_ONLY.class)
public static Resources singleton() {
return ImageSingletons.lookup(Resources.class);
public static Resources currentLayer() {
return LayeredImageSingletonSupport.singleton().lookup(Resources.class, false, true);
}

/**
Expand Down Expand Up @@ -202,7 +203,7 @@ public static ModuleResourceKey createStorageKey(Module module, String resourceN

@Platforms(Platform.HOSTED_ONLY.class)
public static Set<String> getIncludedResourcesModules() {
return StreamSupport.stream(singleton().resources.getKeys().spliterator(), false)
return StreamSupport.stream(currentLayer().resources.getKeys().spliterator(), false)
.map(ModuleResourceKey::module)
.filter(Objects::nonNull)
.map(Module::getName)
Expand Down Expand Up @@ -255,7 +256,7 @@ private void addEntry(Module module, String resourceName, boolean isDirectory, b

@Platforms(Platform.HOSTED_ONLY.class)
public static void registerResource(String resourceName, InputStream is) {
singleton().registerResource(null, resourceName, is, true);
currentLayer().registerResource(null, resourceName, is, true);
}

@Platforms(Platform.HOSTED_ONLY.class)
Expand Down Expand Up @@ -607,7 +608,7 @@ public void afterCompilation(AfterCompilationAccess access) {
* of lazily initialized fields. Only the byte[] arrays themselves can be safely made
* read-only.
*/
for (ConditionalRuntimeValue<ResourceStorageEntryBase> entry : Resources.singleton().resources()) {
for (ConditionalRuntimeValue<ResourceStorageEntryBase> entry : Resources.currentLayer().resources()) {
var unconditionalEntry = entry.getValueUnconditionally();
if (unconditionalEntry.hasData()) {
for (byte[] resource : unconditionalEntry.getData()) {
Expand Down
Loading

0 comments on commit dd30ea1

Please sign in to comment.