Skip to content

Commit 564924a

Browse files
committed
[GR-60876] Load all instantiated types in application layer
PullRequest: graal/19830
2 parents 4c10155 + 040c7d6 commit 564924a

File tree

5 files changed

+110
-54
lines changed

5 files changed

+110
-54
lines changed

substratevm/src/com.oracle.svm.hosted/resources/SharedLayerSnapshotCapnProtoSchema.capnp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,18 @@ struct PersistedAnalysisType {
3737
annotationList @23 :List(Annotation);
3838
classInitializationInfo @24 :ClassInitializationInfo;
3939
hasArrayType @25 :Bool;
40+
subTypes @26 :List(TypeId);
41+
isAnySubtypeInstantiated @27 :Bool;
4042
wrappedType :union {
41-
none @26 :Void; # default
43+
none @28 :Void; # default
4244
serializationGenerated :group {
43-
rawDeclaringClass @27 :Text;
44-
rawTargetConstructor @28 :Text;
45+
rawDeclaringClass @29 :Text;
46+
rawTargetConstructor @30 :Text;
4547
}
4648
lambda :group {
47-
capturingClass @29 :Text;
49+
capturingClass @31 :Text;
4850
}
49-
proxyType @30 :Void;
51+
proxyType @32 :Void;
5052
}
5153
}
5254

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1025,7 +1025,7 @@ protected void setupNativeImage(String imageName, OptionValues options, Map<Meth
10251025
}
10261026
((HostedSnippetReflectionProvider) aProviders.getSnippetReflection()).setHeapScanner(heapScanner);
10271027
if (imageLayerLoader != null) {
1028-
imageLayerLoader.executeHeapScannerTasks();
1028+
imageLayerLoader.postFutureBigbangTasks();
10291029
}
10301030
HeapSnapshotVerifier heapVerifier = new SVMImageHeapVerifier(bb, imageHeap, heapScanner);
10311031
aUniverse.setHeapVerifier(heapVerifier);

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/imagelayer/SVMImageLayerLoader.java

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
import com.oracle.graal.pointsto.meta.BaseLayerType;
8686
import com.oracle.graal.pointsto.util.AnalysisError;
8787
import com.oracle.graal.pointsto.util.AnalysisFuture;
88+
import com.oracle.graal.pointsto.util.CompletionExecutor.DebugContextRunnable;
8889
import com.oracle.svm.core.SubstrateOptions;
8990
import com.oracle.svm.core.classinitialization.ClassInitializationInfo;
9091
import com.oracle.svm.core.graal.code.CGlobalDataInfo;
@@ -163,7 +164,7 @@ public class SVMImageLayerLoader extends ImageLayerLoader {
163164
private final Map<Integer, BaseLayerMethod> baseLayerMethods = new ConcurrentHashMap<>();
164165
private final Map<Integer, BaseLayerField> baseLayerFields = new ConcurrentHashMap<>();
165166

166-
protected final Set<AnalysisFuture<Void>> heapScannerTasks = ConcurrentHashMap.newKeySet();
167+
protected final Set<DebugContextRunnable> futureBigbangTasks = ConcurrentHashMap.newKeySet();
167168
protected final Map<Integer, Integer> typeToConstant = new ConcurrentHashMap<>();
168169
protected final Map<String, Integer> stringToConstant = new ConcurrentHashMap<>();
169170
protected final Map<Enum<?>, Integer> enumToConstant = new ConcurrentHashMap<>();
@@ -608,17 +609,28 @@ public void initializeBaseLayerType(AnalysisType type) {
608609
return;
609610
}
610611
PersistedAnalysisType.Reader td = findType(id);
611-
registerFlag(td.getIsInstantiated(), () -> type.registerAsInstantiated(PERSISTED));
612-
registerFlag(td.getIsUnsafeAllocated(), () -> type.registerAsUnsafeAllocated(PERSISTED));
613-
registerFlag(td.getIsReachable(), () -> type.registerAsReachable(PERSISTED));
612+
registerFlag(td.getIsInstantiated(), debug -> type.registerAsInstantiated(PERSISTED));
613+
registerFlag(td.getIsUnsafeAllocated(), debug -> type.registerAsUnsafeAllocated(PERSISTED));
614+
registerFlag(td.getIsReachable(), debug -> type.registerAsReachable(PERSISTED));
615+
616+
if (!td.getIsInstantiated() && td.getIsAnySubtypeInstantiated()) {
617+
var subTypesReader = td.getSubTypes();
618+
for (int i = 0; i < subTypesReader.size(); ++i) {
619+
int tid = subTypesReader.get(i);
620+
var subTypeReader = findType(tid);
621+
if (subTypeReader.getIsInstantiated()) {
622+
registerFlag(true, debug -> getAnalysisTypeForBaseLayerId(subTypeReader.getId()));
623+
}
624+
}
625+
}
614626
}
615627

616-
private void registerFlag(boolean flag, Runnable runnable) {
628+
private void registerFlag(boolean flag, DebugContextRunnable task) {
617629
if (flag) {
618630
if (universe.getBigbang() != null) {
619-
universe.getBigbang().postTask(debug -> runnable.run());
631+
universe.getBigbang().postTask(task);
620632
} else {
621-
heapScannerTasks.add(new AnalysisFuture<>(runnable));
633+
futureBigbangTasks.add(task);
622634
}
623635
}
624636
}
@@ -805,11 +817,11 @@ public void addBaseLayerMethod(AnalysisMethod analysisMethod) {
805817
methods.putIfAbsent(analysisMethod.getId(), analysisMethod);
806818

807819
PersistedAnalysisMethod.Reader md = getMethodData(analysisMethod);
808-
registerFlag(md.getIsVirtualRootMethod(), () -> analysisMethod.registerAsVirtualRootMethod(PERSISTED));
809-
registerFlag(md.getIsDirectRootMethod(), () -> analysisMethod.registerAsDirectRootMethod(PERSISTED));
810-
registerFlag(md.getIsInvoked(), () -> analysisMethod.registerAsInvoked(PERSISTED));
811-
registerFlag(md.getIsImplementationInvoked(), () -> analysisMethod.registerAsImplementationInvoked(PERSISTED));
812-
registerFlag(md.getIsIntrinsicMethod(), () -> analysisMethod.registerAsIntrinsicMethod(PERSISTED));
820+
registerFlag(md.getIsVirtualRootMethod(), debug -> analysisMethod.registerAsVirtualRootMethod(PERSISTED));
821+
registerFlag(md.getIsDirectRootMethod(), debug -> analysisMethod.registerAsDirectRootMethod(PERSISTED));
822+
registerFlag(md.getIsInvoked(), debug -> analysisMethod.registerAsInvoked(PERSISTED));
823+
registerFlag(md.getIsImplementationInvoked(), debug -> analysisMethod.registerAsImplementationInvoked(PERSISTED));
824+
registerFlag(md.getIsIntrinsicMethod(), debug -> analysisMethod.registerAsIntrinsicMethod(PERSISTED));
813825
}
814826

815827
private PersistedAnalysisMethod.Reader getMethodData(AnalysisMethod analysisMethod) {
@@ -1056,10 +1068,10 @@ public void initializeBaseLayerField(AnalysisField analysisField) {
10561068
if (!analysisField.isStatic() && (isAccessed || isRead)) {
10571069
analysisField.getDeclaringClass().getInstanceFields(true);
10581070
}
1059-
registerFlag(isAccessed, () -> analysisField.registerAsAccessed(PERSISTED));
1060-
registerFlag(isRead, () -> analysisField.registerAsRead(PERSISTED));
1061-
registerFlag(fieldData.getIsWritten(), () -> analysisField.registerAsWritten(PERSISTED));
1062-
registerFlag(fieldData.getIsFolded(), () -> analysisField.registerAsFolded(PERSISTED));
1071+
registerFlag(isAccessed, debug -> analysisField.registerAsAccessed(PERSISTED));
1072+
registerFlag(isRead, debug -> analysisField.registerAsRead(PERSISTED));
1073+
registerFlag(fieldData.getIsWritten(), debug -> analysisField.registerAsWritten(PERSISTED));
1074+
registerFlag(fieldData.getIsFolded(), debug -> analysisField.registerAsFolded(PERSISTED));
10631075
}
10641076

10651077
private PersistedAnalysisField.Reader getFieldData(AnalysisField analysisField) {
@@ -1087,10 +1099,11 @@ private PersistedAnalysisField.Reader getFieldData(AnalysisField analysisField)
10871099
return null;
10881100
}
10891101

1090-
public void executeHeapScannerTasks() {
1091-
guarantee(universe.getHeapScanner() != null, "Those tasks should only be executed when the bigbang is not null.");
1092-
for (AnalysisFuture<Void> task : heapScannerTasks) {
1093-
task.ensureDone();
1102+
public void postFutureBigbangTasks() {
1103+
BigBang bigbang = universe.getBigbang();
1104+
guarantee(bigbang != null, "Those tasks should only be executed when the bigbang is not null.");
1105+
for (DebugContextRunnable task : futureBigbangTasks) {
1106+
bigbang.postTask(task);
10941107
}
10951108
}
10961109

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/imagelayer/SVMImageLayerWriter.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
import java.util.function.IntFunction;
6464
import java.util.function.ObjIntConsumer;
6565
import java.util.function.Supplier;
66+
import java.util.stream.Collectors;
6667
import java.util.stream.IntStream;
6768
import java.util.stream.Stream;
6869

@@ -93,6 +94,7 @@
9394
import com.oracle.graal.pointsto.heap.ImageHeapPrimitiveArray;
9495
import com.oracle.graal.pointsto.heap.ImageHeapRelocatableConstant;
9596
import com.oracle.graal.pointsto.infrastructure.OriginalFieldProvider;
97+
import com.oracle.graal.pointsto.meta.AnalysisElement;
9698
import com.oracle.graal.pointsto.meta.AnalysisField;
9799
import com.oracle.graal.pointsto.meta.AnalysisMethod;
98100
import com.oracle.graal.pointsto.meta.AnalysisType;
@@ -451,6 +453,15 @@ private void persistType(AnalysisType type, Supplier<PersistedAnalysisType.Build
451453

452454
delegatePersistType(type, builder);
453455

456+
Set<AnalysisType> subTypes = type.getSubTypes().stream().filter(AnalysisElement::isTrackedAcrossLayers).collect(Collectors.toSet());
457+
var subTypesBuilder = builder.initSubTypes(subTypes.size());
458+
int i = 0;
459+
for (AnalysisType subType : subTypes) {
460+
subTypesBuilder.set(i, subType.getId());
461+
i++;
462+
}
463+
builder.setIsAnySubtypeInstantiated(type.isAnySubtypeInstantiated());
464+
454465
afterTypeAdded(type);
455466
}
456467

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/imagelayer/SharedLayerSnapshotCapnProtoSchemaHolder.java

Lines changed: 58 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
@SuppressWarnings("all")
3535
public final class SharedLayerSnapshotCapnProtoSchemaHolder {
3636
public static class PersistedAnalysisType {
37-
public static final org.capnproto.StructSize STRUCT_SIZE = new org.capnproto.StructSize((short)4,(short)13);
37+
public static final org.capnproto.StructSize STRUCT_SIZE = new org.capnproto.StructSize((short)4,(short)14);
3838
public static final class Factory extends org.capnproto.StructFactory<Builder, Reader> {
3939
public Factory() {
4040
}
@@ -307,13 +307,32 @@ public final void setHasArrayType(boolean value) {
307307
_setBooleanField(104, value);
308308
}
309309

310+
public final boolean hasSubTypes() {
311+
return !_pointerFieldIsNull(11);
312+
}
313+
public final org.capnproto.PrimitiveList.Int.Builder getSubTypes() {
314+
return _getPointerField(org.capnproto.PrimitiveList.Int.factory, 11, null, 0);
315+
}
316+
public final void setSubTypes(org.capnproto.PrimitiveList.Int.Reader value) {
317+
_setPointerField(org.capnproto.PrimitiveList.Int.factory, 11, value);
318+
}
319+
public final org.capnproto.PrimitiveList.Int.Builder initSubTypes(int size) {
320+
return _initPointerField(org.capnproto.PrimitiveList.Int.factory, 11, size);
321+
}
322+
public final boolean getIsAnySubtypeInstantiated() {
323+
return _getBooleanField(105);
324+
}
325+
public final void setIsAnySubtypeInstantiated(boolean value) {
326+
_setBooleanField(105, value);
327+
}
328+
310329
public final WrappedType.Builder getWrappedType() {
311330
return new PersistedAnalysisType.WrappedType.Builder(segment, data, pointers, dataSize, pointerCount);
312331
}
313332
public final WrappedType.Builder initWrappedType() {
314333
_setShortField(7,(short)0);
315-
_clearPointerField(11);
316334
_clearPointerField(12);
335+
_clearPointerField(13);
317336
return new PersistedAnalysisType.WrappedType.Builder(segment, data, pointers, dataSize, pointerCount);
318337
}
319338

@@ -461,14 +480,25 @@ public final boolean getHasArrayType() {
461480
return _getBooleanField(104);
462481
}
463482

483+
public final boolean hasSubTypes() {
484+
return !_pointerFieldIsNull(11);
485+
}
486+
public final org.capnproto.PrimitiveList.Int.Reader getSubTypes() {
487+
return _getPointerField(org.capnproto.PrimitiveList.Int.factory, 11, null, 0);
488+
}
489+
490+
public final boolean getIsAnySubtypeInstantiated() {
491+
return _getBooleanField(105);
492+
}
493+
464494
public WrappedType.Reader getWrappedType() {
465495
return new PersistedAnalysisType.WrappedType.Reader(segment, data, pointers, dataSize, pointerCount, nestingLimit);
466496
}
467497

468498
}
469499

470500
public static class WrappedType {
471-
public static final org.capnproto.StructSize STRUCT_SIZE = new org.capnproto.StructSize((short)4,(short)13);
501+
public static final org.capnproto.StructSize STRUCT_SIZE = new org.capnproto.StructSize((short)4,(short)14);
472502
public static final class Factory extends org.capnproto.StructFactory<Builder, Reader> {
473503
public Factory() {
474504
}
@@ -524,8 +554,8 @@ public final SerializationGenerated.Builder getSerializationGenerated() {
524554
}
525555
public final SerializationGenerated.Builder initSerializationGenerated() {
526556
_setShortField(7, (short)PersistedAnalysisType.WrappedType.Which.SERIALIZATION_GENERATED.ordinal());
527-
_clearPointerField(11);
528557
_clearPointerField(12);
558+
_clearPointerField(13);
529559
return new PersistedAnalysisType.WrappedType.SerializationGenerated.Builder(segment, data, pointers, dataSize, pointerCount);
530560
}
531561

@@ -537,7 +567,7 @@ public final Lambda.Builder getLambda() {
537567
}
538568
public final Lambda.Builder initLambda() {
539569
_setShortField(7, (short)PersistedAnalysisType.WrappedType.Which.LAMBDA.ordinal());
540-
_clearPointerField(11);
570+
_clearPointerField(12);
541571
return new PersistedAnalysisType.WrappedType.Lambda.Builder(segment, data, pointers, dataSize, pointerCount);
542572
}
543573

@@ -611,7 +641,7 @@ public enum Which {
611641
_NOT_IN_SCHEMA,
612642
}
613643
public static class SerializationGenerated {
614-
public static final org.capnproto.StructSize STRUCT_SIZE = new org.capnproto.StructSize((short)4,(short)13);
644+
public static final org.capnproto.StructSize STRUCT_SIZE = new org.capnproto.StructSize((short)4,(short)14);
615645
public static final class Factory extends org.capnproto.StructFactory<Builder, Reader> {
616646
public Factory() {
617647
}
@@ -639,34 +669,34 @@ public final Reader asReader() {
639669
return new Reader(segment, data, pointers, dataSize, pointerCount, 0x7fffffff);
640670
}
641671
public final boolean hasRawDeclaringClass() {
642-
return !_pointerFieldIsNull(11);
672+
return !_pointerFieldIsNull(12);
643673
}
644674
public final org.capnproto.Text.Builder getRawDeclaringClass() {
645-
return _getPointerField(org.capnproto.Text.factory, 11, null, 0, 0);
675+
return _getPointerField(org.capnproto.Text.factory, 12, null, 0, 0);
646676
}
647677
public final void setRawDeclaringClass(org.capnproto.Text.Reader value) {
648-
_setPointerField(org.capnproto.Text.factory, 11, value);
678+
_setPointerField(org.capnproto.Text.factory, 12, value);
649679
}
650680
public final void setRawDeclaringClass(String value) {
651-
_setPointerField(org.capnproto.Text.factory, 11, new org.capnproto.Text.Reader(value));
681+
_setPointerField(org.capnproto.Text.factory, 12, new org.capnproto.Text.Reader(value));
652682
}
653683
public final org.capnproto.Text.Builder initRawDeclaringClass(int size) {
654-
return _initPointerField(org.capnproto.Text.factory, 11, size);
684+
return _initPointerField(org.capnproto.Text.factory, 12, size);
655685
}
656686
public final boolean hasRawTargetConstructor() {
657-
return !_pointerFieldIsNull(12);
687+
return !_pointerFieldIsNull(13);
658688
}
659689
public final org.capnproto.Text.Builder getRawTargetConstructor() {
660-
return _getPointerField(org.capnproto.Text.factory, 12, null, 0, 0);
690+
return _getPointerField(org.capnproto.Text.factory, 13, null, 0, 0);
661691
}
662692
public final void setRawTargetConstructor(org.capnproto.Text.Reader value) {
663-
_setPointerField(org.capnproto.Text.factory, 12, value);
693+
_setPointerField(org.capnproto.Text.factory, 13, value);
664694
}
665695
public final void setRawTargetConstructor(String value) {
666-
_setPointerField(org.capnproto.Text.factory, 12, new org.capnproto.Text.Reader(value));
696+
_setPointerField(org.capnproto.Text.factory, 13, new org.capnproto.Text.Reader(value));
667697
}
668698
public final org.capnproto.Text.Builder initRawTargetConstructor(int size) {
669-
return _initPointerField(org.capnproto.Text.factory, 12, size);
699+
return _initPointerField(org.capnproto.Text.factory, 13, size);
670700
}
671701
}
672702

@@ -676,17 +706,17 @@ public static final class Reader extends org.capnproto.StructReader {
676706
}
677707

678708
public boolean hasRawDeclaringClass() {
679-
return !_pointerFieldIsNull(11);
709+
return !_pointerFieldIsNull(12);
680710
}
681711
public org.capnproto.Text.Reader getRawDeclaringClass() {
682-
return _getPointerField(org.capnproto.Text.factory, 11, null, 0, 0);
712+
return _getPointerField(org.capnproto.Text.factory, 12, null, 0, 0);
683713
}
684714

685715
public boolean hasRawTargetConstructor() {
686-
return !_pointerFieldIsNull(12);
716+
return !_pointerFieldIsNull(13);
687717
}
688718
public org.capnproto.Text.Reader getRawTargetConstructor() {
689-
return _getPointerField(org.capnproto.Text.factory, 12, null, 0, 0);
719+
return _getPointerField(org.capnproto.Text.factory, 13, null, 0, 0);
690720
}
691721

692722
}
@@ -695,7 +725,7 @@ public org.capnproto.Text.Reader getRawTargetConstructor() {
695725

696726

697727
public static class Lambda {
698-
public static final org.capnproto.StructSize STRUCT_SIZE = new org.capnproto.StructSize((short)4,(short)13);
728+
public static final org.capnproto.StructSize STRUCT_SIZE = new org.capnproto.StructSize((short)4,(short)14);
699729
public static final class Factory extends org.capnproto.StructFactory<Builder, Reader> {
700730
public Factory() {
701731
}
@@ -723,19 +753,19 @@ public final Reader asReader() {
723753
return new Reader(segment, data, pointers, dataSize, pointerCount, 0x7fffffff);
724754
}
725755
public final boolean hasCapturingClass() {
726-
return !_pointerFieldIsNull(11);
756+
return !_pointerFieldIsNull(12);
727757
}
728758
public final org.capnproto.Text.Builder getCapturingClass() {
729-
return _getPointerField(org.capnproto.Text.factory, 11, null, 0, 0);
759+
return _getPointerField(org.capnproto.Text.factory, 12, null, 0, 0);
730760
}
731761
public final void setCapturingClass(org.capnproto.Text.Reader value) {
732-
_setPointerField(org.capnproto.Text.factory, 11, value);
762+
_setPointerField(org.capnproto.Text.factory, 12, value);
733763
}
734764
public final void setCapturingClass(String value) {
735-
_setPointerField(org.capnproto.Text.factory, 11, new org.capnproto.Text.Reader(value));
765+
_setPointerField(org.capnproto.Text.factory, 12, new org.capnproto.Text.Reader(value));
736766
}
737767
public final org.capnproto.Text.Builder initCapturingClass(int size) {
738-
return _initPointerField(org.capnproto.Text.factory, 11, size);
768+
return _initPointerField(org.capnproto.Text.factory, 12, size);
739769
}
740770
}
741771

@@ -745,10 +775,10 @@ public static final class Reader extends org.capnproto.StructReader {
745775
}
746776

747777
public boolean hasCapturingClass() {
748-
return !_pointerFieldIsNull(11);
778+
return !_pointerFieldIsNull(12);
749779
}
750780
public org.capnproto.Text.Reader getCapturingClass() {
751-
return _getPointerField(org.capnproto.Text.factory, 11, null, 0, 0);
781+
return _getPointerField(org.capnproto.Text.factory, 12, null, 0, 0);
752782
}
753783

754784
}

0 commit comments

Comments
 (0)