Skip to content
Merged
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 @@ -675,31 +675,30 @@ static class LayeredCallbacks extends SingletonLayeredCallbacksSupplier {

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

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

static class SingletonInstantiator implements SingletonLayeredCallbacks.LayeredSingletonInstantiator {
static class SingletonInstantiator implements SingletonLayeredCallbacks.LayeredSingletonInstantiator<LayeredOptionInfo> {
@Override
public Object createFromLoader(ImageSingletonLoader loader) {
public LayeredOptionInfo createFromLoader(ImageSingletonLoader loader) {
int numOptions = loader.readInt("numOptions");
var optionNames = Collections.unmodifiableList(loader.readStringList("optionNames"));
return new LayeredOptionInfo(numOptions, optionNames);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,13 @@ public boolean getDefaultSystemAssertionStatus() {
static class LayeredCallbacks extends SingletonLayeredCallbacksSupplier {
@Override
public SingletonTrait getLayeredCallbacksTrait() {
SingletonLayeredCallbacks action = new SingletonLayeredCallbacks() {
var action = new SingletonLayeredCallbacks<RuntimeAssertionsSupport>() {
@Override
public LayeredImageSingleton.PersistFlags doPersist(ImageSingletonWriter writer, Object singleton) {
RuntimeAssertionsSupport runtimeAssertionsSupport = (RuntimeAssertionsSupport) singleton;
persistAssertionStatus(writer, PACKAGE, runtimeAssertionsSupport.packageAssertionStatus);
persistAssertionStatus(writer, CLASS, runtimeAssertionsSupport.classAssertionStatus);
writer.writeInt(DEFAULT_ASSERTION_STATUS, runtimeAssertionsSupport.defaultAssertionStatus ? 1 : 0);
writer.writeInt(SYSTEM_ASSERTION_STATUS, runtimeAssertionsSupport.systemAssertionStatus ? 1 : 0);
public LayeredImageSingleton.PersistFlags doPersist(ImageSingletonWriter writer, RuntimeAssertionsSupport singleton) {
persistAssertionStatus(writer, PACKAGE, singleton.packageAssertionStatus);
persistAssertionStatus(writer, CLASS, singleton.classAssertionStatus);
writer.writeInt(DEFAULT_ASSERTION_STATUS, singleton.defaultAssertionStatus ? 1 : 0);
writer.writeInt(SYSTEM_ASSERTION_STATUS, singleton.systemAssertionStatus ? 1 : 0);
return PersistFlags.CALLBACK_ON_REGISTRATION;
}

Expand All @@ -252,12 +251,11 @@ private void persistAssertionStatus(ImageSingletonWriter writer, String type, Ma
}

@Override
public void onSingletonRegistration(ImageSingletonLoader loader, Object singleton) {
RuntimeAssertionsSupport runtimeAssertionsSupport = (RuntimeAssertionsSupport) singleton;
checkMaps(loadAssertionStatus(loader, PACKAGE), runtimeAssertionsSupport.packageAssertionStatus);
checkMaps(loadAssertionStatus(loader, CLASS), runtimeAssertionsSupport.classAssertionStatus);
checkBoolean(runtimeAssertionsSupport.defaultAssertionStatus, loader, DEFAULT_ASSERTION_STATUS);
checkBoolean(runtimeAssertionsSupport.systemAssertionStatus, loader, SYSTEM_ASSERTION_STATUS);
public void onSingletonRegistration(ImageSingletonLoader loader, RuntimeAssertionsSupport singleton) {
checkMaps(loadAssertionStatus(loader, PACKAGE), singleton.packageAssertionStatus);
checkMaps(loadAssertionStatus(loader, CLASS), singleton.classAssertionStatus);
checkBoolean(singleton.defaultAssertionStatus, loader, DEFAULT_ASSERTION_STATUS);
checkBoolean(singleton.systemAssertionStatus, loader, SYSTEM_ASSERTION_STATUS);
}

private void checkBoolean(boolean currentLayerAssertionStatus, ImageSingletonLoader loader, String assertionStatusKey) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,17 @@ public EnumSet<?> getRuntimeCheckedCPUFeatures() {
static class LayeredCallbacks extends SingletonLayeredCallbacksSupplier {
@Override
public SingletonTrait getLayeredCallbacksTrait() {
SingletonLayeredCallbacks action = new SingletonLayeredCallbacks() {
var action = new SingletonLayeredCallbacks<SubstrateTargetDescription>() {
@Override
public LayeredImageSingleton.PersistFlags doPersist(ImageSingletonWriter writer, Object singleton) {
SubstrateTargetDescription substrateTargetDescription = (SubstrateTargetDescription) singleton;
writer.writeStringList(RUNTIME_CHECKED_CPU_FEATURES, getCPUFeaturesList(substrateTargetDescription));
public LayeredImageSingleton.PersistFlags doPersist(ImageSingletonWriter writer, SubstrateTargetDescription singleton) {
writer.writeStringList(RUNTIME_CHECKED_CPU_FEATURES, getCPUFeaturesList(singleton));
return PersistFlags.CALLBACK_ON_REGISTRATION;
}

@Override
public void onSingletonRegistration(ImageSingletonLoader loader, Object singleton) {
SubstrateTargetDescription substrateTargetDescription = (SubstrateTargetDescription) singleton;
public void onSingletonRegistration(ImageSingletonLoader loader, SubstrateTargetDescription singleton) {
List<String> previousLayerRuntimeCheckedCPUFeatures = loader.readStringList(RUNTIME_CHECKED_CPU_FEATURES);
List<String> currentLayerRuntimeCheckedCPUFeatures = getCPUFeaturesList(substrateTargetDescription);
List<String> currentLayerRuntimeCheckedCPUFeatures = getCPUFeaturesList(singleton);
VMError.guarantee(previousLayerRuntimeCheckedCPUFeatures.equals(currentLayerRuntimeCheckedCPUFeatures),
"The runtime checked CPU Features should be consistent across layers. The previous layer CPU Features were %s, but the current layer are %s",
previousLayerRuntimeCheckedCPUFeatures, currentLayerRuntimeCheckedCPUFeatures);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,19 +218,17 @@ private static final class State {
static class LayeredCallbacks extends SingletonLayeredCallbacksSupplier {
@Override
public SingletonTrait getLayeredCallbacksTrait() {
SingletonLayeredCallbacks action = new SingletonLayeredCallbacks() {
var action = new SingletonLayeredCallbacks<LocaleSupport>() {
@Override
public LayeredImageSingleton.PersistFlags doPersist(ImageSingletonWriter writer, Object singleton) {
LocaleSupport localeSupport = (LocaleSupport) singleton;
writer.writeString(LOCALE, getLocaleString(localeSupport.locale));
public LayeredImageSingleton.PersistFlags doPersist(ImageSingletonWriter writer, LocaleSupport singleton) {
writer.writeString(LOCALE, getLocaleString(singleton.locale));
return PersistFlags.CALLBACK_ON_REGISTRATION;
}

@Override
public void onSingletonRegistration(ImageSingletonLoader loader, Object singleton) {
LocaleSupport localeSupport = (LocaleSupport) singleton;
public void onSingletonRegistration(ImageSingletonLoader loader, LocaleSupport singleton) {
String previousLocale = loader.readString(LOCALE);
String currentLocale = getLocaleString(localeSupport.locale);
String currentLocale = getLocaleString(singleton.locale);
VMError.guarantee(currentLocale.equals(previousLocale),
"The locale data should be consistent across layers. The previous layer locale data were %s, but the locale data are %s", previousLocale, currentLocale);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,20 +340,17 @@ public enum IdentityHashMode {
static class LayeredCallbacks extends SingletonLayeredCallbacksSupplier {
@Override
public SingletonTrait getLayeredCallbacksTrait() {
SingletonLayeredCallbacks action = new SingletonLayeredCallbacks() {
var action = new SingletonLayeredCallbacks<ObjectLayout>() {
@Override
public PersistFlags doPersist(ImageSingletonWriter writer, Object singleton) {
ObjectLayout objectLayout = (ObjectLayout) singleton;
List<Integer> currentValues = objectLayout.getCurrentValues();
public PersistFlags doPersist(ImageSingletonWriter writer, ObjectLayout singleton) {
List<Integer> currentValues = singleton.getCurrentValues();
writer.writeIntList("priorValues", currentValues);
return PersistFlags.CALLBACK_ON_REGISTRATION;
}

@Override
public void onSingletonRegistration(ImageSingletonLoader loader, Object singleton) {
ObjectLayout objectLayout = (ObjectLayout) singleton;

List<Integer> currentValues = objectLayout.getCurrentValues();
public void onSingletonRegistration(ImageSingletonLoader loader, ObjectLayout singleton) {
List<Integer> currentValues = singleton.getCurrentValues();
List<Integer> priorValues = loader.readIntList("priorValues");

var numFields = Arrays.stream(ObjectLayout.class.getDeclaredFields()).filter(Predicate.not(Field::isSynthetic)).count();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,9 @@ static class LayeredCallbacks extends SingletonLayeredCallbacksSupplier {

@Override
public SingletonTrait getLayeredCallbacksTrait() {
return new SingletonTrait(SingletonTraitKind.LAYERED_CALLBACKS, new SingletonLayeredCallbacks() {
return new SingletonTrait(SingletonTraitKind.LAYERED_CALLBACKS, new SingletonLayeredCallbacks<GCCauseFeature>() {
@Override
public LayeredImageSingleton.PersistFlags doPersist(ImageSingletonWriter writer, Object singleton) {
public LayeredImageSingleton.PersistFlags doPersist(ImageSingletonWriter writer, GCCauseFeature singleton) {
List<String> gcCauses;
if (ImageLayerBuildingSupport.buildingInitialLayer()) {
gcCauses = GCCause.getGCCauses().stream().map(gcCause -> {
Expand All @@ -198,16 +198,16 @@ public LayeredImageSingleton.PersistFlags doPersist(ImageSingletonWriter writer,
}
}).toList();
} else {
gcCauses = ((GCCauseFeature) singleton).registeredGCCauses;
gcCauses = singleton.registeredGCCauses;
}
writer.writeStringList("registeredGCCauses", gcCauses);

return LayeredImageSingleton.PersistFlags.CALLBACK_ON_REGISTRATION;
}

@Override
public void onSingletonRegistration(ImageSingletonLoader loader, Object singleton) {
((GCCauseFeature) singleton).registeredGCCauses = Collections.unmodifiableList(loader.readStringList("registeredGCCauses"));
public void onSingletonRegistration(ImageSingletonLoader loader, GCCauseFeature singleton) {
singleton.registeredGCCauses = Collections.unmodifiableList(loader.readStringList("registeredGCCauses"));
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -511,23 +511,22 @@ public static boolean canUnsafeInstantiateAsInstance(DynamicHub hub) {
static class LayeredCallbacks extends SingletonLayeredCallbacksSupplier {
@Override
public SingletonTrait getLayeredCallbacksTrait() {
return new SingletonTrait(SingletonTraitKind.LAYERED_CALLBACKS, new SingletonLayeredCallbacks() {
return new SingletonTrait(SingletonTraitKind.LAYERED_CALLBACKS, new SingletonLayeredCallbacks<ClassForNameSupport>() {

@Override
public LayeredImageSingleton.PersistFlags doPersist(ImageSingletonWriter writer, Object singleton) {
ClassForNameSupport support = (ClassForNameSupport) singleton;
public LayeredImageSingleton.PersistFlags doPersist(ImageSingletonWriter writer, ClassForNameSupport singleton) {
List<String> classNames = new ArrayList<>();
List<Boolean> classStates = new ArrayList<>();
Set<String> unsafeNames = new HashSet<>(support.previousLayerUnsafe);
Set<String> unsafeNames = new HashSet<>(singleton.previousLayerUnsafe);

var cursor = support.knownClasses.getEntries();
var cursor = singleton.knownClasses.getEntries();
while (cursor.advance()) {
classNames.add(cursor.getKey());
boolean isNegativeQuery = cursor.getValue().getValueUnconditionally() == NEGATIVE_QUERY;
classStates.add(!isNegativeQuery);
}

for (var entry : support.previousLayerClasses.entrySet()) {
for (var entry : singleton.previousLayerClasses.entrySet()) {
/*
* If a complete entry overwrites a negative query from a previous layer,
* the previousLayerClasses map entry needs to be skipped to register the
Expand All @@ -539,7 +538,7 @@ public LayeredImageSingleton.PersistFlags doPersist(ImageSingletonWriter writer,
}
}

support.unsafeInstantiatedClasses.getKeys().iterator().forEachRemaining(c -> unsafeNames.add(c.getName()));
singleton.unsafeInstantiatedClasses.getKeys().iterator().forEachRemaining(c -> unsafeNames.add(c.getName()));

writer.writeStringList(CLASSES_REGISTERED, classNames);
writer.writeBoolList(CLASSES_REGISTERED_STATES, classStates);
Expand All @@ -554,16 +553,16 @@ public LayeredImageSingleton.PersistFlags doPersist(ImageSingletonWriter writer,
}

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

static class SingletonInstantiator implements SingletonLayeredCallbacks.LayeredSingletonInstantiator {
static class SingletonInstantiator implements SingletonLayeredCallbacks.LayeredSingletonInstantiator<ClassForNameSupport> {
@Override
public Object createFromLoader(ImageSingletonLoader loader) {
public ClassForNameSupport createFromLoader(ImageSingletonLoader loader) {
List<String> previousLayerClassKeys = loader.readStringList(CLASSES_REGISTERED);
List<Boolean> previousLayerClassStates = loader.readBoolList(CLASSES_REGISTERED_STATES);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,22 +120,21 @@ static class LayeredCallbacks extends SingletonLayeredCallbacksSupplier {

@Override
public SingletonTrait getLayeredCallbacksTrait() {
return new SingletonTrait(SingletonTraitKind.LAYERED_CALLBACKS, new SingletonLayeredCallbacks() {
return new SingletonTrait(SingletonTraitKind.LAYERED_CALLBACKS, new SingletonLayeredCallbacks<LayeredReflectionMetadataSingleton>() {

@Override
public LayeredImageSingleton.PersistFlags doPersist(ImageSingletonWriter writer, Object singleton) {
LayeredReflectionMetadataSingleton metadata = (LayeredReflectionMetadataSingleton) singleton;
public LayeredImageSingleton.PersistFlags doPersist(ImageSingletonWriter writer, LayeredReflectionMetadataSingleton singleton) {
List<Integer> hubs = new ArrayList<>();
List<Integer> classFlagsList = new ArrayList<>();

var cursor = metadata.reflectionMetadataMap.getEntries();
var cursor = singleton.reflectionMetadataMap.getEntries();
while (cursor.advance()) {
int hub = cursor.getKey();
hubs.add(hub);
classFlagsList.add(getCombinedClassFlags(cursor.getValue(), metadata.previousLayerClassFlags.getOrDefault(hub, 0)));
classFlagsList.add(getCombinedClassFlags(cursor.getValue(), singleton.previousLayerClassFlags.getOrDefault(hub, 0)));
}

for (var entry : metadata.previousLayerClassFlags.entrySet()) {
for (var entry : singleton.previousLayerClassFlags.entrySet()) {
if (!hubs.contains(entry.getKey())) {
/*
* If new class flags were written in this layer, the class flags from
Expand All @@ -153,16 +152,16 @@ public LayeredImageSingleton.PersistFlags doPersist(ImageSingletonWriter writer,
}

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

static class SingletonInstantiator implements SingletonLayeredCallbacks.LayeredSingletonInstantiator {
static class SingletonInstantiator implements SingletonLayeredCallbacks.LayeredSingletonInstantiator<LayeredReflectionMetadataSingleton> {
@Override
public Object createFromLoader(ImageSingletonLoader loader) {
public LayeredReflectionMetadataSingleton createFromLoader(ImageSingletonLoader loader) {
List<Integer> hubs = loader.readIntList(LAYERED_REFLECTION_METADATA_HUBS);
List<Integer> previousLayerClassFlags = loader.readIntList(LAYERED_REFLECTION_METADATA_CLASS_FLAGS);

Expand Down
Loading