Skip to content

Commit 8dd85b3

Browse files
committed
[GR-71195] Singleton labeling fourth batch
PullRequest: graal/22702
2 parents 3e08948 + bf375f3 commit 8dd85b3

File tree

51 files changed

+586
-186
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+586
-186
lines changed

substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/ChunkedImageHeapLayouter.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,17 @@
4343
import com.oracle.svm.core.image.ImageHeapLayouter;
4444
import com.oracle.svm.core.image.ImageHeapObject;
4545
import com.oracle.svm.core.option.SubstrateOptionsParser;
46+
import com.oracle.svm.core.traits.BuiltinTraits.BuildtimeAccessOnly;
47+
import com.oracle.svm.core.traits.BuiltinTraits.NoLayeredCallbacks;
48+
import com.oracle.svm.core.traits.SingletonLayeredInstallationKind.Independent;
49+
import com.oracle.svm.core.traits.SingletonTraits;
4650
import com.oracle.svm.core.util.UserError;
4751
import com.oracle.svm.core.util.VMError;
4852
import com.oracle.svm.util.JVMCIReflectionUtil;
4953

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

56+
@SingletonTraits(access = BuildtimeAccessOnly.class, layeredCallbacks = NoLayeredCallbacks.class, layeredInstallationKind = Independent.class)
5257
public class ChunkedImageHeapLayouter implements ImageHeapLayouter {
5358
/** A partition holding read-only objects. */
5459
private static final int ALIGNED_READ_ONLY_REGULAR = 0;

substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/metaspace/MetaspaceImpl.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@
4747
import com.oracle.svm.core.log.Log;
4848
import com.oracle.svm.core.metaspace.Metaspace;
4949
import com.oracle.svm.core.thread.VMOperation;
50+
import com.oracle.svm.core.traits.BuiltinTraits.AllAccess;
51+
import com.oracle.svm.core.traits.BuiltinTraits.NoLayeredCallbacks;
52+
import com.oracle.svm.core.traits.SingletonLayeredInstallationKind.Disallowed;
53+
import com.oracle.svm.core.traits.SingletonTraits;
5054

5155
import jdk.graal.compiler.api.replacements.Fold;
5256
import jdk.graal.compiler.word.Word;
@@ -58,7 +62,11 @@
5862
* {@link FirstObjectTable}, similar to the writable part of the image heap. The chunks are managed
5963
* in a single "To"-{@link Space}, which ensures that the GC doesn't try to move or promote the
6064
* objects.
65+
* <p>
66+
* This singleton is not fully layer aware because the {@link MetaspaceImpl#space} should be either
67+
* always relinked or properly duplicated for each layer.
6168
*/
69+
@SingletonTraits(access = AllAccess.class, layeredCallbacks = NoLayeredCallbacks.class, layeredInstallationKind = Disallowed.class)
6270
public class MetaspaceImpl implements Metaspace {
6371
private final Space space = new Space("Metaspace", "M", true, getAge());
6472
private final ChunkedMetaspaceMemory memory = new ChunkedMetaspaceMemory(space);

substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/PosixLoadAverageSupport.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,17 @@
2424
*/
2525
package com.oracle.svm.core.posix;
2626

27-
import com.oracle.svm.core.jdk.LoadAverageSupport;
28-
import com.oracle.svm.core.posix.headers.Stdlib;
2927
import com.oracle.svm.core.feature.AutomaticallyRegisteredImageSingleton;
3028
import com.oracle.svm.core.handles.PrimitiveArrayView;
29+
import com.oracle.svm.core.jdk.LoadAverageSupport;
30+
import com.oracle.svm.core.posix.headers.Stdlib;
31+
import com.oracle.svm.core.traits.BuiltinTraits.RuntimeAccessOnly;
32+
import com.oracle.svm.core.traits.BuiltinTraits.SingleLayer;
33+
import com.oracle.svm.core.traits.SingletonLayeredInstallationKind.InitialLayerOnly;
34+
import com.oracle.svm.core.traits.SingletonTraits;
3135

3236
@AutomaticallyRegisteredImageSingleton(LoadAverageSupport.class)
37+
@SingletonTraits(access = RuntimeAccessOnly.class, layeredCallbacks = SingleLayer.class, layeredInstallationKind = InitialLayerOnly.class)
3338
class PosixLoadAverageSupport implements LoadAverageSupport {
3439
@Override
3540
public int getLoadAverage(double[] loadavg, int nelems) {

substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/PosixRawFileOperationSupport.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
import java.io.File;
2828
import java.nio.ByteOrder;
2929

30-
import com.oracle.svm.core.jdk.SystemPropertiesSupport;
31-
import jdk.graal.compiler.word.Word;
3230
import org.graalvm.nativeimage.ImageSingletons;
3331
import org.graalvm.nativeimage.Platform;
3432
import org.graalvm.nativeimage.Platforms;
@@ -41,13 +39,21 @@
4139
import com.oracle.svm.core.Uninterruptible;
4240
import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature;
4341
import com.oracle.svm.core.feature.InternalFeature;
42+
import com.oracle.svm.core.imagelayer.ImageLayerBuildingSupport;
43+
import com.oracle.svm.core.jdk.SystemPropertiesSupport;
4444
import com.oracle.svm.core.memory.UntrackedNullableNativeMemory;
4545
import com.oracle.svm.core.os.AbstractRawFileOperationSupport;
4646
import com.oracle.svm.core.os.AbstractRawFileOperationSupport.RawFileOperationSupportHolder;
4747
import com.oracle.svm.core.posix.headers.Fcntl;
4848
import com.oracle.svm.core.posix.headers.Unistd;
49+
import com.oracle.svm.core.traits.BuiltinTraits.BuildtimeAccessOnly;
50+
import com.oracle.svm.core.traits.BuiltinTraits.SingleLayer;
51+
import com.oracle.svm.core.traits.SingletonLayeredInstallationKind.Independent;
52+
import com.oracle.svm.core.traits.SingletonTraits;
4953
import com.oracle.svm.core.util.VMError;
5054

55+
import jdk.graal.compiler.word.Word;
56+
5157
public class PosixRawFileOperationSupport extends AbstractRawFileOperationSupport {
5258
@Platforms(Platform.HOSTED_ONLY.class)
5359
public PosixRawFileOperationSupport(boolean useNativeByteOrder) {
@@ -200,8 +206,14 @@ private static int parseMode(FileAccessMode mode) {
200206
}
201207
}
202208

209+
@SingletonTraits(access = BuildtimeAccessOnly.class, layeredCallbacks = SingleLayer.class, layeredInstallationKind = Independent.class)
203210
@AutomaticallyRegisteredFeature
204211
class PosixRawFileOperationFeature implements InternalFeature {
212+
@Override
213+
public boolean isInConfiguration(IsInConfigurationAccess access) {
214+
return ImageLayerBuildingSupport.firstImageBuild();
215+
}
216+
205217
@Override
206218
public void afterRegistration(AfterRegistrationAccess access) {
207219
ByteOrder nativeByteOrder = ByteOrder.nativeOrder();

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

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@
2424
*/
2525
package com.oracle.svm.core;
2626

27+
import java.nio.charset.StandardCharsets;
28+
import java.util.Arrays;
2729
import java.util.EnumSet;
2830
import java.util.List;
2931

30-
import jdk.graal.compiler.debug.GraalError;
3132
import org.graalvm.nativeimage.ImageSingletons;
3233
import org.graalvm.nativeimage.Platform;
3334
import org.graalvm.nativeimage.Platforms;
@@ -36,8 +37,17 @@
3637

3738
import com.oracle.svm.core.c.CGlobalData;
3839
import com.oracle.svm.core.c.CGlobalDataFactory;
40+
import com.oracle.svm.core.layeredimagesingleton.ImageSingletonLoader;
41+
import com.oracle.svm.core.layeredimagesingleton.ImageSingletonWriter;
42+
import com.oracle.svm.core.layeredimagesingleton.LayeredPersistFlags;
43+
import com.oracle.svm.core.traits.SingletonLayeredCallbacks;
44+
import com.oracle.svm.core.traits.SingletonLayeredCallbacksSupplier;
45+
import com.oracle.svm.core.traits.SingletonTrait;
46+
import com.oracle.svm.core.traits.SingletonTraitKind;
3947
import com.oracle.svm.core.util.VMError;
4048

49+
import jdk.graal.compiler.debug.GraalError;
50+
4151
public abstract class CPUFeatureAccessImpl implements CPUFeatureAccess {
4252

4353
private final EnumSet<?> buildtimeCPUFeatures;
@@ -118,4 +128,52 @@ protected boolean isFeaturePresent(Enum<?> feature, Pointer cpuFeatures, List<St
118128
}
119129
return cpuFeatures.readByte(offset) != 0;
120130
}
131+
132+
public static class LayeredCallbacks extends SingletonLayeredCallbacksSupplier {
133+
private static final String BUILDTIME_CPU_FEATURES = "buildtimeCPUFeatures";
134+
private static final String CPU_FEATURE_ERROR_MESSAGE = "cpuFeatureErrorMessage";
135+
private static final String BUILDTIME_FEATURE_MASK = "buildtimeFeatureMask";
136+
private static final String CPU_FEATURE_ENUM_TO_STRUCT_OFFSETS = "cpuFeatureEnumToStructOffsets";
137+
138+
@Override
139+
public SingletonTrait getLayeredCallbacksTrait() {
140+
var action = new SingletonLayeredCallbacks<CPUFeatureAccessImpl>() {
141+
@Override
142+
public LayeredPersistFlags doPersist(ImageSingletonWriter writer, CPUFeatureAccessImpl singleton) {
143+
writer.writeStringList(BUILDTIME_CPU_FEATURES, getCPUFeaturesList(singleton));
144+
writer.writeString(CPU_FEATURE_ERROR_MESSAGE, new String(singleton.cpuFeatureErrorMessage, StandardCharsets.ISO_8859_1));
145+
writer.writeString(BUILDTIME_FEATURE_MASK, new String(singleton.buildtimeFeatureMask, StandardCharsets.ISO_8859_1));
146+
writer.writeIntList(CPU_FEATURE_ENUM_TO_STRUCT_OFFSETS, Arrays.stream(singleton.cpuFeatureEnumToStructOffsets).boxed().toList());
147+
return LayeredPersistFlags.CALLBACK_ON_REGISTRATION;
148+
}
149+
150+
@Override
151+
public void onSingletonRegistration(ImageSingletonLoader loader, CPUFeatureAccessImpl singleton) {
152+
List<String> previousLayerBuildtimeCPUFeatures = loader.readStringList(BUILDTIME_CPU_FEATURES);
153+
List<String> currentLayerBuildtimeCPUFeatures = getCPUFeaturesList(singleton);
154+
VMError.guarantee(previousLayerBuildtimeCPUFeatures.equals(currentLayerBuildtimeCPUFeatures),
155+
"The buildtime CPU Features should be consistent across layers. The previous layer CPU Features were %s, but the current layer are %s",
156+
previousLayerBuildtimeCPUFeatures, currentLayerBuildtimeCPUFeatures);
157+
158+
byte[] previousLayerCpuFeatureErrorMessage = loader.readString(CPU_FEATURE_ERROR_MESSAGE).getBytes(StandardCharsets.ISO_8859_1);
159+
VMError.guarantee(Arrays.equals(singleton.cpuFeatureErrorMessage, previousLayerCpuFeatureErrorMessage), "Previous layer CPU Feature error message was %s, but current layer is %s",
160+
Arrays.toString(previousLayerCpuFeatureErrorMessage), Arrays.toString(singleton.cpuFeatureErrorMessage));
161+
162+
byte[] previousLayerBuildtimeFeatureMask = loader.readString(BUILDTIME_FEATURE_MASK).getBytes(StandardCharsets.ISO_8859_1);
163+
VMError.guarantee(Arrays.equals(singleton.buildtimeFeatureMask, previousLayerBuildtimeFeatureMask), "Previous layer buildtime Feature mask was %s, but current layer is %s",
164+
Arrays.toString(previousLayerBuildtimeFeatureMask), Arrays.toString(singleton.buildtimeFeatureMask));
165+
166+
int[] previousLayerCpuFeatureEnumToStructOffsets = loader.readIntList(CPU_FEATURE_ENUM_TO_STRUCT_OFFSETS).stream().mapToInt(Integer::intValue).toArray();
167+
VMError.guarantee(Arrays.equals(singleton.cpuFeatureEnumToStructOffsets, previousLayerCpuFeatureEnumToStructOffsets),
168+
"Previous CPU Feature enum to struct offsets was %s, but current layer is %s",
169+
Arrays.toString(previousLayerCpuFeatureEnumToStructOffsets), Arrays.toString(singleton.cpuFeatureEnumToStructOffsets));
170+
}
171+
};
172+
return new SingletonTrait(SingletonTraitKind.LAYERED_CALLBACKS, action);
173+
}
174+
175+
private static List<String> getCPUFeaturesList(CPUFeatureAccessImpl cpuFeatureAccess) {
176+
return cpuFeatureAccess.buildtimeCPUFeatures.stream().map(Enum::toString).toList();
177+
}
178+
}
121179
}

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

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ public static boolean isNumeric(byte optionValueType) {
658658
*/
659659
@Platforms(Platform.HOSTED_ONLY.class)
660660
@AutomaticallyRegisteredImageSingleton(onlyWith = BuildingImageLayerPredicate.class)
661-
@SingletonTraits(access = BuildtimeAccessOnly.class, layeredCallbacks = LayeredCallbacks.class, layeredInstallationKind = Independent.class)
661+
@SingletonTraits(access = BuildtimeAccessOnly.class, layeredCallbacks = LayeredOptionInfo.LayeredCallbacks.class, layeredInstallationKind = Independent.class)
662662
static class LayeredOptionInfo {
663663
private static final int UNSET = -1;
664664
final int numOptions;
@@ -688,30 +688,30 @@ List<String> getOptionNames() {
688688
Objects.requireNonNull(optionNames);
689689
return optionNames;
690690
}
691-
}
692691

693-
static class LayeredCallbacks extends SingletonLayeredCallbacksSupplier {
692+
static class LayeredCallbacks extends SingletonLayeredCallbacksSupplier {
694693

695-
@Override
696-
public SingletonTrait getLayeredCallbacksTrait() {
697-
return new SingletonTrait(SingletonTraitKind.LAYERED_CALLBACKS, new SingletonLayeredCallbacks<LayeredOptionInfo>() {
698-
@Override
699-
public LayeredPersistFlags doPersist(ImageSingletonWriter writer, LayeredOptionInfo singleton) {
700-
if (ImageLayerBuildingSupport.firstImageBuild()) {
701-
writer.writeInt("numOptions", IsolateArgumentParser.getOptionCount());
702-
writer.writeStringList("optionNames", IsolateArgumentParser.getOptions().stream().map(OptionKey::getName).toList());
703-
} else {
704-
writer.writeInt("numOptions", singleton.getNumOptions());
705-
writer.writeStringList("optionNames", singleton.optionNames);
694+
@Override
695+
public SingletonTrait getLayeredCallbacksTrait() {
696+
return new SingletonTrait(SingletonTraitKind.LAYERED_CALLBACKS, new SingletonLayeredCallbacks<LayeredOptionInfo>() {
697+
@Override
698+
public LayeredPersistFlags doPersist(ImageSingletonWriter writer, LayeredOptionInfo singleton) {
699+
if (ImageLayerBuildingSupport.firstImageBuild()) {
700+
writer.writeInt("numOptions", IsolateArgumentParser.getOptionCount());
701+
writer.writeStringList("optionNames", IsolateArgumentParser.getOptions().stream().map(OptionKey::getName).toList());
702+
} else {
703+
writer.writeInt("numOptions", singleton.getNumOptions());
704+
writer.writeStringList("optionNames", singleton.optionNames);
705+
}
706+
return LayeredPersistFlags.CREATE;
706707
}
707-
return LayeredPersistFlags.CREATE;
708-
}
709708

710-
@Override
711-
public Class<? extends SingletonLayeredCallbacks.LayeredSingletonInstantiator<?>> getSingletonInstantiator() {
712-
return SingletonInstantiator.class;
713-
}
714-
});
709+
@Override
710+
public Class<? extends SingletonLayeredCallbacks.LayeredSingletonInstantiator<?>> getSingletonInstantiator() {
711+
return SingletonInstantiator.class;
712+
}
713+
});
714+
}
715715
}
716716
}
717717

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,7 @@ public static int maxJavaStackTraceDepth() {
651651
@Option(help = "Force no direct relocations to be present in the text section of the generated image", type = OptionType.Debug) //
652652
public static final HostedOptionKey<Boolean> NoDirectRelocationsInText = new HostedOptionKey<>(true);
653653

654+
@LayerVerifiedOption(kind = Kind.Changed, severity = Severity.Error)//
654655
@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") //
655656
public static final HostedOptionKey<Boolean> SpawnIsolates = new HostedOptionKey<>(true);
656657

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/aarch64/AArch64CPUFeatureAccess.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,17 @@
3636
import com.oracle.svm.core.Uninterruptible;
3737
import com.oracle.svm.core.UnmanagedMemoryUtil;
3838
import com.oracle.svm.core.graal.stackvalue.UnsafeStackValue;
39+
import com.oracle.svm.core.traits.BuiltinTraits.AllAccess;
40+
import com.oracle.svm.core.traits.BuiltinTraits.NoLayeredCallbacks;
41+
import com.oracle.svm.core.traits.SingletonLayeredInstallationKind.Disallowed;
42+
import com.oracle.svm.core.traits.SingletonTraits;
3943
import com.oracle.svm.core.util.VMError;
4044

4145
import jdk.graal.compiler.nodes.spi.LoweringProvider;
4246
import jdk.vm.ci.aarch64.AArch64;
4347
import jdk.vm.ci.code.Architecture;
4448

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

4752
@Platforms(Platform.HOSTED_ONLY.class)

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/amd64/AMD64CPUFeatureAccess.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@
3939
import com.oracle.svm.core.UnmanagedMemoryUtil;
4040
import com.oracle.svm.core.graal.stackvalue.UnsafeStackValue;
4141
import com.oracle.svm.core.jdk.JVMCISubstitutions;
42+
import com.oracle.svm.core.traits.BuiltinTraits.AllAccess;
43+
import com.oracle.svm.core.traits.BuiltinTraits.Duplicable;
44+
import com.oracle.svm.core.traits.BuiltinTraits.PartiallyLayerAware;
45+
import com.oracle.svm.core.traits.SingletonLayeredInstallationKind.Independent;
46+
import com.oracle.svm.core.traits.SingletonTraits;
4247
import com.oracle.svm.core.util.VMError;
4348

4449
import jdk.graal.compiler.nodes.spi.LoweringProvider;
@@ -48,6 +53,13 @@
4853
import jdk.vm.ci.amd64.AMD64Kind;
4954
import jdk.vm.ci.code.Architecture;
5055

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

5365
@Platforms(Platform.HOSTED_ONLY.class)

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/c/locale/LocaleSupport.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import com.oracle.svm.core.Uninterruptible;
3737
import com.oracle.svm.core.c.CGlobalData;
3838
import com.oracle.svm.core.c.CGlobalDataFactory;
39-
import com.oracle.svm.core.c.locale.LocaleSupport.LayeredCallbacks;
4039
import com.oracle.svm.core.feature.AutomaticallyRegisteredImageSingleton;
4140
import com.oracle.svm.core.headers.LibC;
4241
import com.oracle.svm.core.jdk.SystemPropertiesSupport;
@@ -72,7 +71,7 @@
7271
* Note that the JavaDoc of {@link java.util.Locale} explains commonly used terms such as script,
7372
* display, format, variant, and extensions.
7473
*/
75-
@SingletonTraits(access = BuildtimeAccessOnly.class, layeredCallbacks = LayeredCallbacks.class, layeredInstallationKind = Independent.class)
74+
@SingletonTraits(access = BuildtimeAccessOnly.class, layeredCallbacks = LocaleSupport.LayeredCallbacks.class, layeredInstallationKind = Independent.class)
7675
@AutomaticallyRegisteredImageSingleton
7776
public class LocaleSupport {
7877
private static final String LOCALE = "locale";

0 commit comments

Comments
 (0)