Skip to content
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 @@ -43,12 +43,17 @@
import com.oracle.svm.core.image.ImageHeapLayouter;
import com.oracle.svm.core.image.ImageHeapObject;
import com.oracle.svm.core.option.SubstrateOptionsParser;
import com.oracle.svm.core.traits.BuiltinTraits.BuildtimeAccessOnly;
import com.oracle.svm.core.traits.BuiltinTraits.NoLayeredCallbacks;
import com.oracle.svm.core.traits.SingletonLayeredInstallationKind.Independent;
import com.oracle.svm.core.traits.SingletonTraits;
import com.oracle.svm.core.util.UserError;
import com.oracle.svm.core.util.VMError;
import com.oracle.svm.util.JVMCIReflectionUtil;

import jdk.graal.compiler.core.common.NumUtil;

@SingletonTraits(access = BuildtimeAccessOnly.class, layeredCallbacks = NoLayeredCallbacks.class, layeredInstallationKind = Independent.class)
public class ChunkedImageHeapLayouter implements ImageHeapLayouter {
/** A partition holding read-only objects. */
private static final int ALIGNED_READ_ONLY_REGULAR = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
import com.oracle.svm.core.log.Log;
import com.oracle.svm.core.metaspace.Metaspace;
import com.oracle.svm.core.thread.VMOperation;
import com.oracle.svm.core.traits.BuiltinTraits.AllAccess;
import com.oracle.svm.core.traits.BuiltinTraits.NoLayeredCallbacks;
import com.oracle.svm.core.traits.SingletonLayeredInstallationKind.Disallowed;
import com.oracle.svm.core.traits.SingletonTraits;

import jdk.graal.compiler.api.replacements.Fold;
import jdk.graal.compiler.word.Word;
Expand All @@ -56,7 +60,11 @@
* {@link FirstObjectTable}, similar to the writable part of the image heap. The chunks are managed
* in a single "To"-{@link Space}, which ensures that the GC doesn't try to move or promote the
* objects.
* <p>
* This singleton is not fully layer aware because the {@link MetaspaceImpl#space} should be either
* always relinked or properly duplicated for each layer.
*/
@SingletonTraits(access = AllAccess.class, layeredCallbacks = NoLayeredCallbacks.class, layeredInstallationKind = Disallowed.class)
public class MetaspaceImpl implements Metaspace {
private final Space space = new Space("Metaspace", "M", true, getAge());
private final ChunkedMetaspaceMemory memory = new ChunkedMetaspaceMemory(space);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,17 @@
*/
package com.oracle.svm.core.posix;

import com.oracle.svm.core.jdk.LoadAverageSupport;
import com.oracle.svm.core.posix.headers.Stdlib;
import com.oracle.svm.core.feature.AutomaticallyRegisteredImageSingleton;
import com.oracle.svm.core.handles.PrimitiveArrayView;
import com.oracle.svm.core.jdk.LoadAverageSupport;
import com.oracle.svm.core.posix.headers.Stdlib;
import com.oracle.svm.core.traits.BuiltinTraits.RuntimeAccessOnly;
import com.oracle.svm.core.traits.BuiltinTraits.SingleLayer;
import com.oracle.svm.core.traits.SingletonLayeredInstallationKind.InitialLayerOnly;
import com.oracle.svm.core.traits.SingletonTraits;

@AutomaticallyRegisteredImageSingleton(LoadAverageSupport.class)
@SingletonTraits(access = RuntimeAccessOnly.class, layeredCallbacks = SingleLayer.class, layeredInstallationKind = InitialLayerOnly.class)
class PosixLoadAverageSupport implements LoadAverageSupport {
@Override
public int getLoadAverage(double[] loadavg, int nelems) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
import java.io.File;
import java.nio.ByteOrder;

import com.oracle.svm.core.jdk.SystemPropertiesSupport;
import jdk.graal.compiler.word.Word;
import org.graalvm.nativeimage.ImageSingletons;
import org.graalvm.nativeimage.Platform;
import org.graalvm.nativeimage.Platforms;
Expand All @@ -41,13 +39,21 @@
import com.oracle.svm.core.Uninterruptible;
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.jdk.SystemPropertiesSupport;
import com.oracle.svm.core.memory.UntrackedNullableNativeMemory;
import com.oracle.svm.core.os.AbstractRawFileOperationSupport;
import com.oracle.svm.core.os.AbstractRawFileOperationSupport.RawFileOperationSupportHolder;
import com.oracle.svm.core.posix.headers.Fcntl;
import com.oracle.svm.core.posix.headers.Unistd;
import com.oracle.svm.core.traits.BuiltinTraits.BuildtimeAccessOnly;
import com.oracle.svm.core.traits.BuiltinTraits.SingleLayer;
import com.oracle.svm.core.traits.SingletonLayeredInstallationKind.Independent;
import com.oracle.svm.core.traits.SingletonTraits;
import com.oracle.svm.core.util.VMError;

import jdk.graal.compiler.word.Word;

public class PosixRawFileOperationSupport extends AbstractRawFileOperationSupport {
@Platforms(Platform.HOSTED_ONLY.class)
public PosixRawFileOperationSupport(boolean useNativeByteOrder) {
Expand Down Expand Up @@ -200,8 +206,14 @@ private static int parseMode(FileAccessMode mode) {
}
}

@SingletonTraits(access = BuildtimeAccessOnly.class, layeredCallbacks = SingleLayer.class, layeredInstallationKind = Independent.class)
@AutomaticallyRegisteredFeature
class PosixRawFileOperationFeature implements InternalFeature {
@Override
public boolean isInConfiguration(IsInConfigurationAccess access) {
return ImageLayerBuildingSupport.firstImageBuild();
}

@Override
public void afterRegistration(AfterRegistrationAccess access) {
ByteOrder nativeByteOrder = ByteOrder.nativeOrder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@
*/
package com.oracle.svm.core;

import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.List;

import jdk.graal.compiler.debug.GraalError;
import org.graalvm.nativeimage.ImageSingletons;
import org.graalvm.nativeimage.Platform;
import org.graalvm.nativeimage.Platforms;
Expand All @@ -36,8 +37,17 @@

import com.oracle.svm.core.c.CGlobalData;
import com.oracle.svm.core.c.CGlobalDataFactory;
import com.oracle.svm.core.layeredimagesingleton.ImageSingletonLoader;
import com.oracle.svm.core.layeredimagesingleton.ImageSingletonWriter;
import com.oracle.svm.core.layeredimagesingleton.LayeredPersistFlags;
import com.oracle.svm.core.traits.SingletonLayeredCallbacks;
import com.oracle.svm.core.traits.SingletonLayeredCallbacksSupplier;
import com.oracle.svm.core.traits.SingletonTrait;
import com.oracle.svm.core.traits.SingletonTraitKind;
import com.oracle.svm.core.util.VMError;

import jdk.graal.compiler.debug.GraalError;

public abstract class CPUFeatureAccessImpl implements CPUFeatureAccess {

private final EnumSet<?> buildtimeCPUFeatures;
Expand Down Expand Up @@ -118,4 +128,52 @@ protected boolean isFeaturePresent(Enum<?> feature, Pointer cpuFeatures, List<St
}
return cpuFeatures.readByte(offset) != 0;
}

public static class LayeredCallbacks extends SingletonLayeredCallbacksSupplier {
private static final String BUILDTIME_CPU_FEATURES = "buildtimeCPUFeatures";
private static final String CPU_FEATURE_ERROR_MESSAGE = "cpuFeatureErrorMessage";
private static final String BUILDTIME_FEATURE_MASK = "buildtimeFeatureMask";
private static final String CPU_FEATURE_ENUM_TO_STRUCT_OFFSETS = "cpuFeatureEnumToStructOffsets";

@Override
public SingletonTrait getLayeredCallbacksTrait() {
var action = new SingletonLayeredCallbacks<CPUFeatureAccessImpl>() {
@Override
public LayeredPersistFlags doPersist(ImageSingletonWriter writer, CPUFeatureAccessImpl singleton) {
writer.writeStringList(BUILDTIME_CPU_FEATURES, getCPUFeaturesList(singleton));
writer.writeString(CPU_FEATURE_ERROR_MESSAGE, new String(singleton.cpuFeatureErrorMessage, StandardCharsets.ISO_8859_1));
writer.writeString(BUILDTIME_FEATURE_MASK, new String(singleton.buildtimeFeatureMask, StandardCharsets.ISO_8859_1));
writer.writeIntList(CPU_FEATURE_ENUM_TO_STRUCT_OFFSETS, Arrays.stream(singleton.cpuFeatureEnumToStructOffsets).boxed().toList());
return LayeredPersistFlags.CALLBACK_ON_REGISTRATION;
}

@Override
public void onSingletonRegistration(ImageSingletonLoader loader, CPUFeatureAccessImpl singleton) {
List<String> previousLayerBuildtimeCPUFeatures = loader.readStringList(BUILDTIME_CPU_FEATURES);
List<String> currentLayerBuildtimeCPUFeatures = getCPUFeaturesList(singleton);
VMError.guarantee(previousLayerBuildtimeCPUFeatures.equals(currentLayerBuildtimeCPUFeatures),
"The buildtime CPU Features should be consistent across layers. The previous layer CPU Features were %s, but the current layer are %s",
previousLayerBuildtimeCPUFeatures, currentLayerBuildtimeCPUFeatures);

byte[] previousLayerCpuFeatureErrorMessage = loader.readString(CPU_FEATURE_ERROR_MESSAGE).getBytes(StandardCharsets.ISO_8859_1);
VMError.guarantee(Arrays.equals(singleton.cpuFeatureErrorMessage, previousLayerCpuFeatureErrorMessage), "Previous layer CPU Feature error message was %s, but current layer is %s",
Arrays.toString(previousLayerCpuFeatureErrorMessage), Arrays.toString(singleton.cpuFeatureErrorMessage));

byte[] previousLayerBuildtimeFeatureMask = loader.readString(BUILDTIME_FEATURE_MASK).getBytes(StandardCharsets.ISO_8859_1);
VMError.guarantee(Arrays.equals(singleton.buildtimeFeatureMask, previousLayerBuildtimeFeatureMask), "Previous layer buildtime Feature mask was %s, but current layer is %s",
Arrays.toString(previousLayerBuildtimeFeatureMask), Arrays.toString(singleton.buildtimeFeatureMask));

int[] previousLayerCpuFeatureEnumToStructOffsets = loader.readIntList(CPU_FEATURE_ENUM_TO_STRUCT_OFFSETS).stream().mapToInt(Integer::intValue).toArray();
VMError.guarantee(Arrays.equals(singleton.cpuFeatureEnumToStructOffsets, previousLayerCpuFeatureEnumToStructOffsets),
"Previous CPU Feature enum to struct offsets was %s, but current layer is %s",
Arrays.toString(previousLayerCpuFeatureEnumToStructOffsets), Arrays.toString(singleton.cpuFeatureEnumToStructOffsets));
}
};
return new SingletonTrait(SingletonTraitKind.LAYERED_CALLBACKS, action);
}

private static List<String> getCPUFeaturesList(CPUFeatureAccessImpl cpuFeatureAccess) {
return cpuFeatureAccess.buildtimeCPUFeatures.stream().map(Enum::toString).toList();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ public static boolean isNumeric(byte optionValueType) {
*/
@Platforms(Platform.HOSTED_ONLY.class)
@AutomaticallyRegisteredImageSingleton(onlyWith = BuildingImageLayerPredicate.class)
@SingletonTraits(access = BuildtimeAccessOnly.class, layeredCallbacks = LayeredCallbacks.class, layeredInstallationKind = Independent.class)
@SingletonTraits(access = BuildtimeAccessOnly.class, layeredCallbacks = LayeredOptionInfo.LayeredCallbacks.class, layeredInstallationKind = Independent.class)
static class LayeredOptionInfo {
private static final int UNSET = -1;
final int numOptions;
Expand Down Expand Up @@ -688,30 +688,30 @@ List<String> getOptionNames() {
Objects.requireNonNull(optionNames);
return optionNames;
}
}

static class LayeredCallbacks extends SingletonLayeredCallbacksSupplier {
static class LayeredCallbacks extends SingletonLayeredCallbacksSupplier {

@Override
public SingletonTrait getLayeredCallbacksTrait() {
return new SingletonTrait(SingletonTraitKind.LAYERED_CALLBACKS, new SingletonLayeredCallbacks<LayeredOptionInfo>() {
@Override
public LayeredPersistFlags doPersist(ImageSingletonWriter writer, LayeredOptionInfo singleton) {
if (ImageLayerBuildingSupport.firstImageBuild()) {
writer.writeInt("numOptions", IsolateArgumentParser.getOptionCount());
writer.writeStringList("optionNames", IsolateArgumentParser.getOptions().stream().map(OptionKey::getName).toList());
} else {
writer.writeInt("numOptions", singleton.getNumOptions());
writer.writeStringList("optionNames", singleton.optionNames);
@Override
public SingletonTrait getLayeredCallbacksTrait() {
return new SingletonTrait(SingletonTraitKind.LAYERED_CALLBACKS, new SingletonLayeredCallbacks<LayeredOptionInfo>() {
@Override
public LayeredPersistFlags doPersist(ImageSingletonWriter writer, LayeredOptionInfo singleton) {
if (ImageLayerBuildingSupport.firstImageBuild()) {
writer.writeInt("numOptions", IsolateArgumentParser.getOptionCount());
writer.writeStringList("optionNames", IsolateArgumentParser.getOptions().stream().map(OptionKey::getName).toList());
} else {
writer.writeInt("numOptions", singleton.getNumOptions());
writer.writeStringList("optionNames", singleton.optionNames);
}
return LayeredPersistFlags.CREATE;
}
return LayeredPersistFlags.CREATE;
}

@Override
public Class<? extends SingletonLayeredCallbacks.LayeredSingletonInstantiator<?>> getSingletonInstantiator() {
return SingletonInstantiator.class;
}
});
@Override
public Class<? extends SingletonLayeredCallbacks.LayeredSingletonInstantiator<?>> getSingletonInstantiator() {
return SingletonInstantiator.class;
}
});
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,7 @@ public static int maxJavaStackTraceDepth() {
@Option(help = "Force no direct relocations to be present in the text section of the generated image", type = OptionType.Debug) //
public static final HostedOptionKey<Boolean> NoDirectRelocationsInText = new HostedOptionKey<>(true);

@LayerVerifiedOption(kind = Kind.Changed, severity = Severity.Error)//
@Option(help = "Support multiple isolates.", deprecated = true, deprecationMessage = "This option disables a major feature of GraalVM Native Image and will be removed in a future release") //
public static final HostedOptionKey<Boolean> SpawnIsolates = new HostedOptionKey<>(true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,17 @@
import com.oracle.svm.core.Uninterruptible;
import com.oracle.svm.core.UnmanagedMemoryUtil;
import com.oracle.svm.core.graal.stackvalue.UnsafeStackValue;
import com.oracle.svm.core.traits.BuiltinTraits.AllAccess;
import com.oracle.svm.core.traits.BuiltinTraits.NoLayeredCallbacks;
import com.oracle.svm.core.traits.SingletonLayeredInstallationKind.Disallowed;
import com.oracle.svm.core.traits.SingletonTraits;
import com.oracle.svm.core.util.VMError;

import jdk.graal.compiler.nodes.spi.LoweringProvider;
import jdk.vm.ci.aarch64.AArch64;
import jdk.vm.ci.code.Architecture;

@SingletonTraits(access = AllAccess.class, layeredCallbacks = NoLayeredCallbacks.class, layeredInstallationKind = Disallowed.class)
public class AArch64CPUFeatureAccess extends CPUFeatureAccessImpl {

@Platforms(Platform.HOSTED_ONLY.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
import com.oracle.svm.core.UnmanagedMemoryUtil;
import com.oracle.svm.core.graal.stackvalue.UnsafeStackValue;
import com.oracle.svm.core.jdk.JVMCISubstitutions;
import com.oracle.svm.core.traits.BuiltinTraits.AllAccess;
import com.oracle.svm.core.traits.BuiltinTraits.Duplicable;
import com.oracle.svm.core.traits.BuiltinTraits.PartiallyLayerAware;
import com.oracle.svm.core.traits.SingletonLayeredInstallationKind.Independent;
import com.oracle.svm.core.traits.SingletonTraits;
import com.oracle.svm.core.util.VMError;

import jdk.graal.compiler.nodes.spi.LoweringProvider;
Expand All @@ -48,6 +53,13 @@
import jdk.vm.ci.amd64.AMD64Kind;
import jdk.vm.ci.code.Architecture;

/**
* This singleton should be converted to a multi layer singleton or an application layer only
* singleton. It is currently too strict, as different CPUFeatures are allowed in different layers,
* but at runtime, all the CPUFeatures used during all builds need to be supported.
*/
@SingletonTraits(access = AllAccess.class, layeredCallbacks = CPUFeatureAccessImpl.LayeredCallbacks.class, layeredInstallationKind = Independent.class, other = {Duplicable.class,
PartiallyLayerAware.class})
public class AMD64CPUFeatureAccess extends CPUFeatureAccessImpl {

@Platforms(Platform.HOSTED_ONLY.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import com.oracle.svm.core.Uninterruptible;
import com.oracle.svm.core.c.CGlobalData;
import com.oracle.svm.core.c.CGlobalDataFactory;
import com.oracle.svm.core.c.locale.LocaleSupport.LayeredCallbacks;
import com.oracle.svm.core.feature.AutomaticallyRegisteredImageSingleton;
import com.oracle.svm.core.headers.LibC;
import com.oracle.svm.core.jdk.SystemPropertiesSupport;
Expand Down Expand Up @@ -72,7 +71,7 @@
* Note that the JavaDoc of {@link java.util.Locale} explains commonly used terms such as script,
* display, format, variant, and extensions.
*/
@SingletonTraits(access = BuildtimeAccessOnly.class, layeredCallbacks = LayeredCallbacks.class, layeredInstallationKind = Independent.class)
@SingletonTraits(access = BuildtimeAccessOnly.class, layeredCallbacks = LocaleSupport.LayeredCallbacks.class, layeredInstallationKind = Independent.class)
@AutomaticallyRegisteredImageSingleton
public class LocaleSupport {
private static final String LOCALE = "locale";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@

import com.oracle.svm.core.SubstrateTargetDescription;
import com.oracle.svm.core.Uninterruptible;
import com.oracle.svm.core.config.ObjectLayout.LayeredCallbacks;
import com.oracle.svm.core.layeredimagesingleton.ImageSingletonLoader;
import com.oracle.svm.core.layeredimagesingleton.ImageSingletonWriter;
import com.oracle.svm.core.layeredimagesingleton.LayeredPersistFlags;
Expand Down Expand Up @@ -83,7 +82,7 @@
* See this classes instantiation sites (such as {@code HostedConfiguration#createObjectLayout}) for
* more details on the exact object layout for a given configuration.
*/
@SingletonTraits(access = AllAccess.class, layeredCallbacks = LayeredCallbacks.class, layeredInstallationKind = Independent.class)
@SingletonTraits(access = AllAccess.class, layeredCallbacks = ObjectLayout.LayeredCallbacks.class, layeredInstallationKind = Independent.class)
public final class ObjectLayout {

private final SubstrateTargetDescription target;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@

import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature;
import com.oracle.svm.core.feature.InternalFeature;
import com.oracle.svm.core.traits.BuiltinTraits.BuildtimeAccessOnly;
import com.oracle.svm.core.traits.BuiltinTraits.NoLayeredCallbacks;
import com.oracle.svm.core.traits.SingletonLayeredInstallationKind.Independent;
import com.oracle.svm.core.traits.SingletonTraits;

@SingletonTraits(access = BuildtimeAccessOnly.class, layeredCallbacks = NoLayeredCallbacks.class, layeredInstallationKind = Independent.class)
@AutomaticallyRegisteredFeature
public class ReferenceAccessFeature implements InternalFeature {
@Override
Expand Down
Loading