Skip to content

[GR-65174] Label and make singletons layer aware. #11337

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,13 @@ public HeapImpl() {
this.oldGeneration = SerialGCOptions.useCompactingOldGen() ? new CompactingOldGeneration("OldGeneration")
: new CopyingOldGeneration("OldGeneration");
HeapParameters.initialize();
DiagnosticThunkRegistry.singleton().add(new DumpHeapSettingsAndStatistics());
DiagnosticThunkRegistry.singleton().add(new DumpHeapUsage());
DiagnosticThunkRegistry.singleton().add(new DumpGCPolicy());
DiagnosticThunkRegistry.singleton().add(new DumpImageHeapInfo());
DiagnosticThunkRegistry.singleton().add(new DumpChunkInfo());
if (ImageLayerBuildingSupport.firstImageBuild()) {
DiagnosticThunkRegistry.singleton().add(new DumpHeapSettingsAndStatistics());
DiagnosticThunkRegistry.singleton().add(new DumpHeapUsage());
DiagnosticThunkRegistry.singleton().add(new DumpGCPolicy());
DiagnosticThunkRegistry.singleton().add(new DumpImageHeapInfo());
DiagnosticThunkRegistry.singleton().add(new DumpChunkInfo());
}
}

@Fold
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature;
import com.oracle.svm.core.feature.InternalFeature;
import com.oracle.svm.core.heap.GCCause;
import com.oracle.svm.core.imagelayer.ImageLayerBuildingSupport;
import com.oracle.svm.core.jfr.HasJfrSupport;
import com.oracle.svm.core.jfr.JfrEvent;
import com.oracle.svm.core.jfr.JfrGCName;
Expand All @@ -42,6 +43,7 @@
import com.oracle.svm.core.jfr.JfrNativeEventWriterData;
import com.oracle.svm.core.jfr.JfrNativeEventWriterDataAccess;
import com.oracle.svm.core.jfr.JfrTicks;
import com.oracle.svm.core.layeredimagesingleton.UnsupportedLayeredSingleton;
import com.oracle.svm.core.util.VMError;

class JfrGCEventSupport {
Expand Down Expand Up @@ -139,10 +141,10 @@ private int popPhase() {
}

@AutomaticallyRegisteredFeature
class JfrGCEventFeature implements InternalFeature {
class JfrGCEventFeature implements InternalFeature, UnsupportedLayeredSingleton {
@Override
public boolean isInConfiguration(IsInConfigurationAccess access) {
return SubstrateOptions.useSerialGC();
return SubstrateOptions.useSerialGC() && !ImageLayerBuildingSupport.buildingImageLayer();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import com.oracle.svm.core.graal.code.SubstrateVectorArchitectureFactory;
import com.oracle.svm.core.graal.meta.SubstrateRegisterConfig.ConfigKind;
import com.oracle.svm.core.heap.ReferenceAccess;
import com.oracle.svm.core.layeredimagesingleton.FeatureSingleton;

import jdk.graal.compiler.core.common.spi.ForeignCallsProvider;
import jdk.graal.compiler.core.common.spi.MetaAccessExtensionProvider;
Expand All @@ -58,7 +59,7 @@

@AutomaticallyRegisteredFeature
@Platforms(Platform.AMD64.class)
class SubstrateAMD64Feature implements InternalFeature {
class SubstrateAMD64Feature implements InternalFeature, FeatureSingleton {

@Override
public void afterRegistration(AfterRegistrationAccess access) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@
import com.oracle.svm.core.Uninterruptible;
import com.oracle.svm.core.feature.AutomaticallyRegisteredImageSingleton;
import com.oracle.svm.core.headers.LibMSupport;
import com.oracle.svm.core.imagelayer.BuildingMonolithicImage;
import com.oracle.svm.core.posix.headers.PosixLibM;

@AutomaticallyRegisteredImageSingleton(LibMSupport.class)
@AutomaticallyRegisteredImageSingleton(value = LibMSupport.class, onlyWith = BuildingMonolithicImage.class)
public class PosixLibMSupport implements LibMSupport {
@Override
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,24 @@
import java.io.FileDescriptor;
import java.util.EnumSet;

import com.oracle.svm.core.imagelayer.ImageLayerBuildingSupport;
import org.graalvm.nativeimage.LogHandler;
import org.graalvm.nativeimage.c.type.CCharPointer;
import org.graalvm.word.UnsignedWord;

import com.oracle.svm.core.SubstrateDiagnostics;
import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature;
import com.oracle.svm.core.feature.InternalFeature;
import com.oracle.svm.core.headers.LibC;
import com.oracle.svm.core.layeredimagesingleton.InitialLayerInternalFeature;
import com.oracle.svm.core.layeredimagesingleton.InitialLayerOnlyImageSingleton;
import com.oracle.svm.core.layeredimagesingleton.LayeredImageSingletonBuilderFlags;
import com.oracle.svm.core.log.Log;
import com.oracle.svm.core.thread.VMThreads;

@AutomaticallyRegisteredFeature
class PosixLogHandlerFeature implements InternalFeature {
class PosixLogHandlerFeature implements InitialLayerInternalFeature {
@Override
public void beforeAnalysis(BeforeAnalysisAccess access) {
if (ImageLayerBuildingSupport.firstImageBuild()) {
Log.finalizeDefaultLogHandler(new PosixLogHandler());
}
Log.finalizeDefaultLogHandler(new PosixLogHandler());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import static com.oracle.svm.core.posix.headers.Mman.NoTransitions.munmap;
import static jdk.graal.compiler.word.Word.nullPointer;

import jdk.graal.compiler.word.Word;
import org.graalvm.nativeimage.ImageSingletons;
import org.graalvm.nativeimage.Platform;
import org.graalvm.nativeimage.c.type.WordPointer;
Expand All @@ -52,14 +51,16 @@
import com.oracle.svm.core.c.CGlobalData;
import com.oracle.svm.core.c.CGlobalDataFactory;
import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature;
import com.oracle.svm.core.feature.InternalFeature;
import com.oracle.svm.core.layeredimagesingleton.InitialLayerInternalFeature;
import com.oracle.svm.core.os.VirtualMemoryProvider;
import com.oracle.svm.core.posix.headers.Unistd;
import com.oracle.svm.core.util.PointerUtils;
import com.oracle.svm.core.util.UnsignedUtils;

import jdk.graal.compiler.word.Word;

@AutomaticallyRegisteredFeature
class PosixVirtualMemoryProviderFeature implements InternalFeature {
class PosixVirtualMemoryProviderFeature implements InitialLayerInternalFeature {
@Override
public void beforeAnalysis(BeforeAnalysisAccess access) {
if (!ImageSingletons.contains(VirtualMemoryProvider.class)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@

import org.graalvm.nativeimage.ImageSingletons;

import com.oracle.svm.core.feature.InternalFeature;
import com.oracle.svm.core.os.ImageHeapProvider;
import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature;
import com.oracle.svm.core.layeredimagesingleton.InitialLayerInternalFeature;
import com.oracle.svm.core.os.ImageHeapProvider;

@AutomaticallyRegisteredFeature
class DarwinImageSingletonsFeature implements InternalFeature {
class DarwinImageSingletonsFeature implements InitialLayerInternalFeature {
@Override
public void duringSetup(DuringSetupAccess access) {
if (!ImageSingletons.contains(ImageHeapProvider.class)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
import com.oracle.svm.core.c.CGlobalData;
import com.oracle.svm.core.c.CGlobalDataFactory;
import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature;
import com.oracle.svm.core.feature.InternalFeature;
import com.oracle.svm.core.heap.RestrictHeapAccess;
import com.oracle.svm.core.layeredimagesingleton.InitialLayerInternalFeature;
import com.oracle.svm.core.log.Log;
import com.oracle.svm.core.os.RawFileOperationSupport;

Expand Down Expand Up @@ -103,7 +103,7 @@ private static int countLineBytes(CCharPointer buffer, int len) {
}

@AutomaticallyRegisteredFeature
class DumpLinuxOSInfoFeature implements InternalFeature {
class DumpLinuxOSInfoFeature implements InitialLayerInternalFeature {
@Override
public void afterRegistration(AfterRegistrationAccess access) {
if (!SubstrateOptions.AsyncSignalSafeDiagnostics.getValue()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@
import com.oracle.svm.core.c.libc.BionicLibC;
import com.oracle.svm.core.c.libc.LibCBase;
import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature;
import com.oracle.svm.core.feature.InternalFeature;
import com.oracle.svm.core.headers.LibCSupport;
import com.oracle.svm.core.layeredimagesingleton.InitialLayerInternalFeature;
import com.oracle.svm.core.os.ImageHeapProvider;

@AutomaticallyRegisteredFeature
class LinuxImageSingletonsFeature implements InternalFeature {
class LinuxImageSingletonsFeature implements InitialLayerInternalFeature {
@Override
public void duringSetup(DuringSetupAccess access) {
if (LibCBase.singleton() instanceof BionicLibC) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@

import org.graalvm.nativeimage.ImageSingletons;

import com.oracle.svm.core.feature.InternalFeature;
import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature;
import com.oracle.svm.core.layeredimagesingleton.InitialLayerInternalFeature;
import com.oracle.svm.core.log.Log;
import com.oracle.svm.core.os.ImageHeapProvider;
import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature;

@AutomaticallyRegisteredFeature
class WindowsFeature implements InternalFeature {
class WindowsFeature implements InitialLayerInternalFeature {

@Override
public void duringSetup(DuringSetupAccess access) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@
import com.oracle.svm.core.Uninterruptible;
import com.oracle.svm.core.feature.AutomaticallyRegisteredImageSingleton;
import com.oracle.svm.core.headers.LibMSupport;
import com.oracle.svm.core.imagelayer.BuildingMonolithicImage;
import com.oracle.svm.core.windows.headers.WindowsLibC;

@AutomaticallyRegisteredImageSingleton(LibMSupport.class)
@AutomaticallyRegisteredImageSingleton(value = LibMSupport.class, onlyWith = BuildingMonolithicImage.class)
public class WindowsLibMSupport implements LibMSupport {
@Override
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@

import org.graalvm.nativeimage.ImageSingletons;

import com.oracle.svm.core.layeredimagesingleton.BuildTimeUnsavedSingleton;

/** Interface for collecting artifacts produced during native image build. */
public interface BuildArtifacts {
public interface BuildArtifacts extends BuildTimeUnsavedSingleton {

/**
* Artifact types generated by Native Image. Changing this enum requires updating the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@
import org.graalvm.nativeimage.Platform;
import org.graalvm.nativeimage.Platforms;

import com.oracle.svm.core.layeredimagesingleton.BuildTimeUnsavedSingleton;

@Platforms(Platform.HOSTED_ONLY.class)
public final class BuildPhaseProvider {
public final class BuildPhaseProvider implements BuildTimeUnsavedSingleton {

private boolean featureRegistrationFinished;
private boolean setupFinished;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@
import org.graalvm.nativeimage.Platforms;
import org.graalvm.nativeimage.impl.ConfigurationCondition;

import com.oracle.svm.core.layeredimagesingleton.BuildTimeUnsavedSingleton;

@Platforms(Platform.HOSTED_ONLY.class)
public abstract class ClassLoaderSupport {
public abstract class ClassLoaderSupport implements BuildTimeUnsavedSingleton {

public boolean isNativeImageClassLoader(ClassLoader classLoader) {
ClassLoader loader = classLoader;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,20 @@

import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature;
import com.oracle.svm.core.feature.InternalFeature;
import com.oracle.svm.core.imagelayer.ImageLayerBuildingSupport;
import com.oracle.svm.core.layeredimagesingleton.UnsupportedLayeredSingleton;

/**
* For compatibility with legacy code.
*/
@AutomaticallyRegisteredFeature
@Deprecated
public class IsolateListenerFeature implements InternalFeature {
public class IsolateListenerFeature implements InternalFeature, UnsupportedLayeredSingleton {
@Override
public boolean isInConfiguration(IsInConfigurationAccess access) {
return !ImageLayerBuildingSupport.buildingImageLayer();
}

@Override
public List<Class<? extends Feature>> getRequiredFeatures() {
return List.of(IsolateListenerSupportFeature.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,22 @@
package com.oracle.svm.core;

import java.util.Arrays;
import java.util.EnumSet;

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

import com.oracle.svm.core.feature.AutomaticallyRegisteredImageSingleton;
import com.oracle.svm.core.layeredimagesingleton.InitialLayerOnlyImageSingleton;
import com.oracle.svm.core.layeredimagesingleton.LayeredImageSingletonBuilderFlags;
import com.oracle.svm.core.util.VMError;

import jdk.graal.compiler.api.replacements.Fold;

@AutomaticallyRegisteredImageSingleton
public class IsolateListenerSupport {
public class IsolateListenerSupport implements InitialLayerOnlyImageSingleton {
private IsolateListener[] listeners;

@Platforms(Platform.HOSTED_ONLY.class)
Expand Down Expand Up @@ -80,6 +83,11 @@ public void onIsolateTeardown() {
}
}

@Override
public EnumSet<LayeredImageSingletonBuilderFlags> getImageBuilderFlags() {
return LayeredImageSingletonBuilderFlags.ALL_ACCESS;
}

public interface IsolateListener {
/**
* Implementations must not throw any exceptions. Note that the thread that creates the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,19 @@
*/
package com.oracle.svm.core;

import jdk.graal.compiler.word.Word;
import java.util.EnumSet;

import org.graalvm.nativeimage.ImageSingletons;
import org.graalvm.word.PointerBase;

import com.oracle.svm.core.layeredimagesingleton.InitialLayerOnlyImageSingleton;
import com.oracle.svm.core.layeredimagesingleton.LayeredImageSingletonBuilderFlags;
import com.oracle.svm.core.log.Log;
import com.oracle.svm.core.util.VMError;

public interface RegisterDumper {
import jdk.graal.compiler.word.Word;

public interface RegisterDumper extends InitialLayerOnlyImageSingleton {
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
static RegisterDumper singleton() {
if (!ImageSingletons.contains(RegisterDumper.class)) {
Expand Down Expand Up @@ -61,4 +66,14 @@ interface Context extends PointerBase {
PointerBase getSP(Context context);

PointerBase getIP(Context context);

@Override
default EnumSet<LayeredImageSingletonBuilderFlags> getImageBuilderFlags() {
return LayeredImageSingletonBuilderFlags.RUNTIME_ACCESS_ONLY;
}

@Override
default boolean accessibleInFutureLayers() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
import com.oracle.svm.core.feature.InternalFeature;
import com.oracle.svm.core.heap.UnknownObjectField;
import com.oracle.svm.core.imagelayer.ImageLayerBuildingSupport;
import com.oracle.svm.core.layeredimagesingleton.BuildTimeUnsavedSingleton;
import com.oracle.svm.core.layeredimagesingleton.FeatureSingleton;
import com.oracle.svm.core.layeredimagesingleton.LayeredImageSingletonBuilderFlags;
import com.oracle.svm.core.layeredimagesingleton.LayeredImageSingletonSupport;
import com.oracle.svm.core.layeredimagesingleton.MultiLayeredImageSingleton;
Expand Down Expand Up @@ -94,7 +96,7 @@
public final class StaticFieldsSupport {

@Platforms(Platform.HOSTED_ONLY.class)
public interface HostedStaticFieldSupport {
public interface HostedStaticFieldSupport extends BuildTimeUnsavedSingleton {

static HostedStaticFieldSupport singleton() {
return ImageSingletons.lookup(HostedStaticFieldSupport.class);
Expand Down Expand Up @@ -273,7 +275,7 @@ public void lower(LoweringTool tool) {
* We must ensure we are not querying the offset of a static field of a type assignable from
* {@link org.graalvm.word.WordBase}.
*/
public interface StaticFieldValidator {
public interface StaticFieldValidator extends BuildTimeUnsavedSingleton {
static void checkFieldOffsetAllowed(ResolvedJavaField field) {
if (field.isStatic()) {
if (SubstrateUtil.HOSTED) {
Expand Down Expand Up @@ -335,7 +337,7 @@ public EnumSet<LayeredImageSingletonBuilderFlags> getImageBuilderFlags() {
* See {@link StaticFieldsSupport} for how this prevents aliasing issues.
*/
@AutomaticallyRegisteredFeature
final class StaticFieldsFeature implements InternalFeature {
final class StaticFieldsFeature implements InternalFeature, FeatureSingleton {

@Override
public void registerInvocationPlugins(Providers providers, Plugins plugins, ParsingReason reason) {
Expand Down
Loading