Skip to content

Commit cd459f7

Browse files
committed
Reduce number of types loaded
1 parent 8fac6c4 commit cd459f7

File tree

5 files changed

+110
-65
lines changed

5 files changed

+110
-65
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 & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -810,9 +810,6 @@ protected boolean runPointsToAnalysis(String imageName, OptionValues options, De
810810
if (ImageLayerBuildingSupport.buildingSharedLayer()) {
811811
HostedImageLayerBuildingSupport.singleton().getWriter().initializeExternalValues();
812812
}
813-
if (ImageLayerBuildingSupport.buildingExtensionLayer()) {
814-
HostedImageLayerBuildingSupport.singleton().getLoader().loadInstantiatedTypes();
815-
}
816813
}
817814

818815
try (ReporterClosable c = ProgressReporter.singleton().printAnalysis(bb.getUniverse(), nativeLibraries.getLibraries())) {
@@ -1028,7 +1025,7 @@ protected void setupNativeImage(String imageName, OptionValues options, Map<Meth
10281025
}
10291026
((HostedSnippetReflectionProvider) aProviders.getSnippetReflection()).setHeapScanner(heapScanner);
10301027
if (imageLayerLoader != null) {
1031-
imageLayerLoader.executeHeapScannerTasks();
1028+
imageLayerLoader.postFutureBigbangTasks();
10321029
}
10331030
HeapSnapshotVerifier heapVerifier = new SVMImageHeapVerifier(bb, imageHeap, heapScanner);
10341031
aUniverse.setHeapVerifier(heapVerifier);

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

Lines changed: 33 additions & 28 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;
@@ -164,7 +165,7 @@ public class SVMImageLayerLoader extends ImageLayerLoader {
164165
private final Map<Integer, BaseLayerMethod> baseLayerMethods = new ConcurrentHashMap<>();
165166
private final Map<Integer, BaseLayerField> baseLayerFields = new ConcurrentHashMap<>();
166167

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

617-
private void registerFlag(boolean flag, Runnable runnable) {
629+
private void registerFlag(boolean flag, DebugContextRunnable task) {
618630
if (flag) {
619631
if (universe.getBigbang() != null) {
620-
universe.getBigbang().postTask(debug -> runnable.run());
632+
universe.getBigbang().postTask(task);
621633
} else {
622-
heapScannerTasks.add(new AnalysisFuture<>(runnable));
634+
futureBigbangTasks.add(task);
623635
}
624636
}
625637
}
@@ -806,11 +818,11 @@ public void addBaseLayerMethod(AnalysisMethod analysisMethod) {
806818
methods.putIfAbsent(analysisMethod.getId(), analysisMethod);
807819

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

816828
private PersistedAnalysisMethod.Reader getMethodData(AnalysisMethod analysisMethod) {
@@ -1063,10 +1075,10 @@ public void initializeBaseLayerField(AnalysisField analysisField) {
10631075
if (!analysisField.isStatic() && (isAccessed || isRead)) {
10641076
analysisField.getDeclaringClass().getInstanceFields(true);
10651077
}
1066-
registerFlag(isAccessed, () -> analysisField.registerAsAccessed(PERSISTED));
1067-
registerFlag(isRead, () -> analysisField.registerAsRead(PERSISTED));
1068-
registerFlag(fieldData.getIsWritten(), () -> analysisField.registerAsWritten(PERSISTED));
1069-
registerFlag(fieldData.getIsFolded(), () -> analysisField.registerAsFolded(PERSISTED));
1078+
registerFlag(isAccessed, debug -> analysisField.registerAsAccessed(PERSISTED));
1079+
registerFlag(isRead, debug -> analysisField.registerAsRead(PERSISTED));
1080+
registerFlag(fieldData.getIsWritten(), debug -> analysisField.registerAsWritten(PERSISTED));
1081+
registerFlag(fieldData.getIsFolded(), debug -> analysisField.registerAsFolded(PERSISTED));
10701082
}
10711083

10721084
private PersistedAnalysisField.Reader getFieldData(AnalysisField analysisField) {
@@ -1094,18 +1106,11 @@ private PersistedAnalysisField.Reader getFieldData(AnalysisField analysisField)
10941106
return null;
10951107
}
10961108

1097-
public void executeHeapScannerTasks() {
1098-
guarantee(universe.getHeapScanner() != null, "Those tasks should only be executed when the bigbang is not null.");
1099-
for (AnalysisFuture<Void> task : heapScannerTasks) {
1100-
task.ensureDone();
1101-
}
1102-
}
1103-
1104-
public void loadInstantiatedTypes() {
1105-
for (var type : snapshot.getTypes()) {
1106-
if (type.getIsInstantiated()) {
1107-
getAnalysisTypeForBaseLayerId(type.getId());
1108-
}
1109+
public void postFutureBigbangTasks() {
1110+
BigBang bigbang = universe.getBigbang();
1111+
guarantee(bigbang != null, "Those tasks should only be executed when the bigbang is not null.");
1112+
for (DebugContextRunnable task : futureBigbangTasks) {
1113+
bigbang.postTask(task);
11091114
}
11101115
}
11111116

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)