Skip to content

Commit 45f3c25

Browse files
Zeaveeteshull
authored andcommitted
[GR-60500] Refactor ImageLayerWriter/Loader
PullRequest: graal/19670
2 parents 0e2520d + 62f5ab0 commit 45f3c25

39 files changed

+2722
-3139
lines changed

substratevm/mx.substratevm/mx_substratevm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2478,7 +2478,7 @@ def capnp_compile(args):
24782478
if capnpcjava_home is None or not exists(capnpcjava_home + '/capnpc-java'):
24792479
mx.abort('Clone and build capnproto/capnproto-java from GitHub and point CAPNPROTOJAVA_HOME to its path.')
24802480
srcdir = 'src/com.oracle.svm.hosted/resources/'
2481-
outdir = 'src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/heap/'
2481+
outdir = 'src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/imagelayer/'
24822482
command = ['capnp', 'compile',
24832483
'--import-path=' + capnpcjava_home + '/compiler/src/main/schema/',
24842484
'--output=' + capnpcjava_home + '/capnpc-java:' + outdir,

substratevm/src/com.oracle.graal.pointsto.standalone/src/com/oracle/graal/pointsto/standalone/PointsToAnalyzer.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@
4848
import com.oracle.graal.pointsto.heap.HeapSnapshotVerifier;
4949
import com.oracle.graal.pointsto.heap.HostedValuesProvider;
5050
import com.oracle.graal.pointsto.heap.ImageHeap;
51-
import com.oracle.graal.pointsto.heap.ImageLayerLoader;
52-
import com.oracle.graal.pointsto.heap.ImageLayerSnapshotUtil;
53-
import com.oracle.graal.pointsto.heap.ImageLayerWriter;
5451
import com.oracle.graal.pointsto.infrastructure.SubstitutionProcessor;
5552
import com.oracle.graal.pointsto.meta.AnalysisMetaAccess;
5653
import com.oracle.graal.pointsto.meta.AnalysisMetaAccessExtensionProvider;
@@ -163,18 +160,9 @@ private PointsToAnalyzer(String mainEntryClass, OptionValues options) {
163160
aUniverse.setBigBang(bigbang);
164161
ImageHeap heap = new ImageHeap();
165162
HostedValuesProvider hostedValuesProvider = new HostedValuesProvider(aMetaAccess, aUniverse);
166-
ImageLayerSnapshotUtil imageLayerSnapshotUtil = new ImageLayerSnapshotUtil(false);
167-
ImageLayerLoader imageLayerLoader = new ImageLayerLoader();
168-
imageLayerLoader.setImageLayerSnapshotUtil(imageLayerSnapshotUtil);
169-
imageLayerLoader.setUniverse(aUniverse);
170-
aUniverse.setImageLayerLoader(imageLayerLoader);
171163
StandaloneImageHeapScanner heapScanner = new StandaloneImageHeapScanner(bigbang, heap, aMetaAccess,
172164
snippetReflection, aConstantReflection, new AnalysisObjectScanningObserver(bigbang), analysisClassLoader, hostedValuesProvider);
173165
aUniverse.setHeapScanner(heapScanner);
174-
imageLayerLoader.executeHeapScannerTasks();
175-
ImageLayerWriter imageLayerWriter = new ImageLayerWriter(true, true);
176-
imageLayerWriter.setImageLayerSnapshotUtil(imageLayerSnapshotUtil);
177-
imageLayerWriter.setImageHeap(heap);
178166
HeapSnapshotVerifier heapVerifier = new StandaloneHeapSnapshotVerifier(bigbang, heap, heapScanner);
179167
aUniverse.setHeapVerifier(heapVerifier);
180168
/* Register already created types as assignable. */

substratevm/src/com.oracle.graal.pointsto.standalone/src/com/oracle/graal/pointsto/standalone/heap/StandaloneImageHeapScanner.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ protected Class<?> getClass(String className) {
6868
}
6969

7070
@Override
71-
protected ValueSupplier<JavaConstant> readHostedFieldValue(AnalysisField field, JavaConstant receiver) {
71+
public ValueSupplier<JavaConstant> readHostedFieldValue(AnalysisField field, JavaConstant receiver) {
7272
ValueSupplier<JavaConstant> ret = super.readHostedFieldValue(field, receiver);
7373
if (ret.get() == null && field.isStatic()) {
7474
ResolvedJavaField wrappedField = field.getWrapped();
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
/*
2+
* Copyright (c) 2024, 2024, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
package com.oracle.graal.pointsto.api;
26+
27+
import java.util.Set;
28+
29+
import com.oracle.graal.pointsto.flow.AnalysisParsedGraph;
30+
import com.oracle.graal.pointsto.heap.ImageHeapConstant;
31+
import com.oracle.graal.pointsto.meta.AnalysisField;
32+
import com.oracle.graal.pointsto.meta.AnalysisMethod;
33+
import com.oracle.graal.pointsto.meta.AnalysisType;
34+
import com.oracle.graal.pointsto.util.AnalysisError;
35+
36+
import jdk.vm.ci.meta.JavaConstant;
37+
38+
public class ImageLayerLoader {
39+
/**
40+
* Returns the type id of the given type in the base layer if it exists. This makes the link
41+
* between the base layer and the extension layer as the id is used to determine which constant
42+
* should be linked to this type.
43+
*/
44+
@SuppressWarnings("unused")
45+
public int lookupHostedTypeInBaseLayer(AnalysisType type) {
46+
throw AnalysisError.shouldNotReachHere("This method should not be called");
47+
}
48+
49+
@SuppressWarnings("unused")
50+
public void initializeBaseLayerType(AnalysisType type) {
51+
throw AnalysisError.shouldNotReachHere("This method should not be called");
52+
}
53+
54+
/**
55+
* Returns the method id of the given method in the base layer if it exists. This makes the link
56+
* between the base layer and the extension layer as the id is used to determine the method used
57+
* in RelocatableConstants.
58+
*/
59+
@SuppressWarnings("unused")
60+
public int lookupHostedMethodInBaseLayer(AnalysisMethod analysisMethod) {
61+
throw AnalysisError.shouldNotReachHere("This method should not be called");
62+
}
63+
64+
@SuppressWarnings("unused")
65+
public void addBaseLayerMethod(AnalysisMethod analysisMethod) {
66+
throw AnalysisError.shouldNotReachHere("This method should not be called");
67+
}
68+
69+
/**
70+
* We save analysis parsed graphs for methods considered
71+
* {@link AnalysisMethod#isTrackedAcrossLayers()}.
72+
*/
73+
@SuppressWarnings("unused")
74+
public boolean hasAnalysisParsedGraph(AnalysisMethod analysisMethod) {
75+
throw AnalysisError.shouldNotReachHere("This method should not be called");
76+
}
77+
78+
@SuppressWarnings("unused")
79+
public AnalysisParsedGraph getAnalysisParsedGraph(AnalysisMethod analysisMethod) {
80+
throw AnalysisError.shouldNotReachHere("This method should not be called");
81+
}
82+
83+
@SuppressWarnings("unused")
84+
public void loadPriorStrengthenedGraphAnalysisElements(AnalysisMethod analysisMethod) {
85+
throw AnalysisError.shouldNotReachHere("This method should not be called");
86+
}
87+
88+
/**
89+
* Returns the field id of the given field in the base layer if it exists. This makes the link
90+
* between the base layer and the extension image as the id allows to set the flags of the
91+
* fields in the extension image.
92+
*/
93+
@SuppressWarnings("unused")
94+
public int lookupHostedFieldInBaseLayer(AnalysisField analysisField) {
95+
throw AnalysisError.shouldNotReachHere("This method should not be called");
96+
}
97+
98+
@SuppressWarnings("unused")
99+
public void addBaseLayerField(AnalysisField analysisField) {
100+
throw AnalysisError.shouldNotReachHere("This method should not be called");
101+
}
102+
103+
@SuppressWarnings("unused")
104+
public void initializeBaseLayerField(AnalysisField analysisField) {
105+
throw AnalysisError.shouldNotReachHere("This method should not be called");
106+
}
107+
108+
@SuppressWarnings("unused")
109+
public boolean hasValueForConstant(JavaConstant javaConstant) {
110+
throw AnalysisError.shouldNotReachHere("This method should not be called");
111+
}
112+
113+
@SuppressWarnings("unused")
114+
public ImageHeapConstant getValueForConstant(JavaConstant javaConstant) {
115+
throw AnalysisError.shouldNotReachHere("This method should not be called");
116+
}
117+
118+
@SuppressWarnings("unused")
119+
public Set<Integer> getRelinkedFields(AnalysisType type) {
120+
throw AnalysisError.shouldNotReachHere("This method should not be called");
121+
}
122+
123+
@SuppressWarnings("unused")
124+
public boolean hasDynamicHubIdentityHashCode(int tid) {
125+
throw AnalysisError.shouldNotReachHere("This method should not be called");
126+
}
127+
128+
@SuppressWarnings("unused")
129+
public int getDynamicHubIdentityHashCode(int tid) {
130+
throw AnalysisError.shouldNotReachHere("This method should not be called");
131+
}
132+
}
Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,15 @@
2222
* or visit www.oracle.com if you need additional information or have any
2323
* questions.
2424
*/
25-
package com.oracle.graal.pointsto.heap;
25+
package com.oracle.graal.pointsto.api;
2626

27-
import com.oracle.graal.pointsto.heap.SharedLayerSnapshotCapnProtoSchemaHolder.PersistedAnalysisMethod;
28-
import com.oracle.graal.pointsto.heap.SharedLayerSnapshotCapnProtoSchemaHolder.PersistedAnalysisType;
27+
import com.oracle.graal.pointsto.meta.AnalysisMethod;
28+
import com.oracle.graal.pointsto.util.AnalysisError;
2929

30-
public class ImageLayerLoaderHelper {
31-
protected ImageLayerLoader imageLayerLoader;
32-
33-
public ImageLayerLoaderHelper(ImageLayerLoader imageLayerLoader) {
34-
this.imageLayerLoader = imageLayerLoader;
35-
}
36-
37-
@SuppressWarnings("unused")
38-
protected boolean loadType(PersistedAnalysisType.Reader typeData, int tid) {
39-
return false;
40-
}
30+
public class ImageLayerWriter {
4131

4232
@SuppressWarnings("unused")
43-
protected boolean loadMethod(PersistedAnalysisMethod.Reader methodData, int mid) {
44-
return false;
33+
public void onTrackedAcrossLayer(AnalysisMethod method, Object reason) {
34+
throw AnalysisError.shouldNotReachHere("This method should not be called");
4535
}
4636
}

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ private InstanceData(AnalysisType type, JavaConstant hostedObject, Object[] fiel
8181
this(type, hostedObject, -1, -1);
8282
}
8383

84-
ImageHeapInstance(AnalysisType type, JavaConstant hostedObject, int identityHashCode, int id) {
84+
public ImageHeapInstance(AnalysisType type, JavaConstant hostedObject, int identityHashCode, int id) {
8585
super(new InstanceData(type, hostedObject, null, identityHashCode, id), false);
8686
}
8787

@@ -98,7 +98,7 @@ public InstanceData getConstantData() {
9898
return (InstanceData) super.getConstantData();
9999
}
100100

101-
void setFieldValues(Object[] fieldValues) {
101+
public void setFieldValues(Object[] fieldValues) {
102102
boolean success = valuesHandle.compareAndSet(constantData, null, fieldValues);
103103
AnalysisError.guarantee(success, "Unexpected field values reference for constant %s", this);
104104
}
@@ -149,7 +149,18 @@ public Object getFieldValue(AnalysisField field) {
149149
/* Base layer constants that are not relinked might not have field positions computed */
150150
field.getType().getInstanceFields(true);
151151
}
152-
return arrayHandle.getVolatile(getFieldValues(), field.getPosition());
152+
return getFieldValue(field.getPosition());
153+
}
154+
155+
public Object getFieldValue(int fieldPosition) {
156+
return arrayHandle.getVolatile(getFieldValues(), fieldPosition);
157+
}
158+
159+
public int getFieldValuesSize() {
160+
if (isReaderInstalled()) {
161+
return getConstantData().fieldValues.length;
162+
}
163+
return 0;
153164
}
154165

155166
/**

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ private ObjectArrayData(AnalysisType type, JavaConstant hostedObject, Object[] a
7171
this(type, hostedObject, length, -1, -1);
7272
}
7373

74-
ImageHeapObjectArray(AnalysisType type, JavaConstant hostedObject, int length, int identityHashCode, int id) {
74+
public ImageHeapObjectArray(AnalysisType type, JavaConstant hostedObject, int length, int identityHashCode, int id) {
7575
super(new ObjectArrayData(type, hostedObject, null, length, identityHashCode, id), false);
7676
}
7777

@@ -92,7 +92,7 @@ public ObjectArrayData getConstantData() {
9292
return (ObjectArrayData) super.getConstantData();
9393
}
9494

95-
void setElementValues(Object[] elementValues) {
95+
public void setElementValues(Object[] elementValues) {
9696
boolean success = elementsHandle.compareAndSet(constantData, null, elementValues);
9797
AnalysisError.guarantee(success, "Unexpected field values reference for constant %s", this);
9898
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ private PrimitiveArrayData(AnalysisType type, JavaConstant hostedObject, Object
6060
this(type, hostedObject, array, length, -1, -1);
6161
}
6262

63-
ImageHeapPrimitiveArray(AnalysisType type, JavaConstant hostedObject, Object array, int length, int identityHashCode, int id) {
63+
public ImageHeapPrimitiveArray(AnalysisType type, JavaConstant hostedObject, Object array, int length, int identityHashCode, int id) {
6464
super(new PrimitiveArrayData(type, hostedObject,
6565
/* We need a clone of the hosted array so that we have a stable snapshot. */
6666
getClone(type.getComponentType().getJavaKind(), array),

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import com.oracle.graal.pointsto.ObjectScanner.ScanReason;
4545
import com.oracle.graal.pointsto.ObjectScanningObserver;
4646
import com.oracle.graal.pointsto.api.HostVM;
47+
import com.oracle.graal.pointsto.api.ImageLayerLoader;
4748
import com.oracle.graal.pointsto.constraints.UnsupportedFeatureException;
4849
import com.oracle.graal.pointsto.heap.HeapSnapshotVerifier.ScanningObserver;
4950
import com.oracle.graal.pointsto.heap.value.ValueSupplier;
@@ -830,7 +831,7 @@ protected void rescanEconomicMap(EconomicMap<?, ?> object) {
830831
}
831832
}
832833

833-
void doScan(JavaConstant constant) {
834+
public void doScan(JavaConstant constant) {
834835
doScan(constant, OtherReason.RESCAN);
835836
}
836837

0 commit comments

Comments
 (0)