Skip to content

Commit ca7e8b3

Browse files
cstancuZeavee
authored andcommitted
[GR-59867] Enable more testing with Native Image Layers.
PullRequest: graal/19606
2 parents f4e613f + 982e8b7 commit ca7e8b3

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/heap/ImageLayerWriter.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
import jdk.graal.compiler.nodes.EncodedGraph;
9898
import jdk.graal.compiler.nodes.spi.IdentityHashCodeProvider;
9999
import jdk.graal.compiler.util.ObjectCopier;
100+
import jdk.vm.ci.meta.ConstantReflectionProvider;
100101
import jdk.vm.ci.meta.JavaConstant;
101102
import jdk.vm.ci.meta.JavaKind;
102103
import jdk.vm.ci.meta.MethodHandleAccessProvider.IntrinsicMethod;
@@ -151,6 +152,7 @@ public void ensureFieldPersisted(AnalysisField field) {
151152
public void ensureConstantPersisted(ImageHeapConstant constant) {
152153
assert !sealed;
153154
constantsToPersist.add(constant);
155+
afterConstantAdded(constant);
154156
}
155157

156158
protected record ConstantParent(int constantId, int index) {
@@ -377,6 +379,8 @@ protected void persistType(AnalysisType type, String typeDescriptor, PersistedAn
377379
* created. If the enclosing type is missing, it is ignored for now. This try/catch
378380
* block could be removed after the trackAcrossLayers is fully implemented.
379381
*/
382+
} catch (InternalError | TypeNotPresentException | LinkageError e) {
383+
/* Ignore missing type errors. */
380384
}
381385
if (type.isArray()) {
382386
builder.setComponentTypeId(type.getComponentType().getId());
@@ -431,6 +435,16 @@ protected void afterMethodAdded(AnalysisMethod method) {
431435
imageLayerWriterHelper.afterMethodAdded(method);
432436
}
433437

438+
private void afterConstantAdded(ImageHeapConstant constant) {
439+
ensureTypePersisted(constant.getType());
440+
/* If this is a Class constant persist the corresponding type. */
441+
ConstantReflectionProvider constantReflection = aUniverse.getBigbang().getConstantReflectionProvider();
442+
AnalysisType typeFromClassConstant = (AnalysisType) constantReflection.asJavaType(constant);
443+
if (typeFromClassConstant != null) {
444+
ensureTypePersisted(typeFromClassConstant);
445+
}
446+
}
447+
434448
private void scanConstantReferencedObjects(ImageHeapConstant constant, Collection<ImageHeapConstant> discoveredConstants) {
435449
if (Objects.requireNonNull(constant) instanceof ImageHeapInstance instance) {
436450
if (instance.isReaderInstalled()) {

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,16 @@
8888
public class SVMImageLayerLoader extends ImageLayerLoader {
8989

9090
private final Field dynamicHubArrayHubField;
91+
private final boolean useSharedLayerGraphs;
9192

9293
private HostedUniverse hostedUniverse;
9394
private final ImageClassLoader imageClassLoader;
9495

95-
public SVMImageLayerLoader(List<FilePaths> loadPaths, ImageClassLoader imageClassLoader) {
96+
public SVMImageLayerLoader(List<FilePaths> loadPaths, ImageClassLoader imageClassLoader, boolean useSharedLayerGraphs) {
9697
super(loadPaths);
9798
dynamicHubArrayHubField = ReflectionUtil.lookupField(DynamicHub.class, "arrayHub");
9899
this.imageClassLoader = imageClassLoader;
100+
this.useSharedLayerGraphs = useSharedLayerGraphs;
99101
}
100102

101103
public void setHostedUniverse(HostedUniverse hostedUniverse) {
@@ -106,6 +108,14 @@ public HostedUniverse getHostedUniverse() {
106108
return hostedUniverse;
107109
}
108110

111+
@Override
112+
public boolean hasAnalysisParsedGraph(AnalysisMethod analysisMethod) {
113+
if (!useSharedLayerGraphs) {
114+
return false;
115+
}
116+
return super.hasAnalysisParsedGraph(analysisMethod);
117+
}
118+
109119
public ClassInitializationInfo getClassInitializationInfo(AnalysisType type) {
110120
PersistedAnalysisType.Reader typeMap = findType(type.getId());
111121

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,18 +175,19 @@ public static HostedImageLayerBuildingSupport initialize(HostedOptionValues valu
175175
WriteLayerArchiveSupport writeLayerArchiveSupport = null;
176176
SVMImageLayerWriter writer = null;
177177
ArchiveSupport archiveSupport = new ArchiveSupport(false);
178+
Boolean useSharedLayerGraphs = SubstrateOptions.UseSharedLayerGraphs.getValue(values);
178179
if (buildingSharedLayer) {
179180
LayerOption layerOption = LayerOption.parse(SubstrateOptions.LayerCreate.getValue(values).lastValue().orElseThrow());
180181
writeLayerArchiveSupport = new WriteLayerArchiveSupport(archiveSupport, layerOption.fileName());
181-
writer = new SVMImageLayerWriter(SubstrateOptions.UseSharedLayerGraphs.getValue(values));
182+
writer = new SVMImageLayerWriter(useSharedLayerGraphs);
182183
}
183184
SVMImageLayerLoader loader = null;
184185
LoadLayerArchiveSupport loadLayerArchiveSupport = null;
185186
if (buildingExtensionLayer) {
186187
Path layerFileName = SubstrateOptions.LayerUse.getValue(values).lastValue().orElseThrow();
187188
loadLayerArchiveSupport = new LoadLayerArchiveSupport(layerFileName, archiveSupport);
188189
ImageLayerLoader.FilePaths paths = new ImageLayerLoader.FilePaths(loadLayerArchiveSupport.getSnapshotPath(), loadLayerArchiveSupport.getSnapshotGraphsPath());
189-
loader = new SVMImageLayerLoader(List.of(paths), imageClassLoader);
190+
loader = new SVMImageLayerLoader(List.of(paths), imageClassLoader, useSharedLayerGraphs);
190191
}
191192

192193
return new HostedImageLayerBuildingSupport(loader, writer, buildingImageLayer, buildingInitialLayer, buildingFinalLayer, writeLayerArchiveSupport, loadLayerArchiveSupport);

0 commit comments

Comments
 (0)