Skip to content

Commit aac7cde

Browse files
committed
Add documentation for layered parts of AnalysisType/Method/Field
1 parent f6c7115 commit aac7cde

28 files changed

+110
-93
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ private boolean verifyFieldValue(JavaConstant receiver, AnalysisField field, Jav
187187
verifyStaticFieldValue(typeData, field, fieldSnapshot, fieldValue, reason);
188188
} else {
189189
ImageHeapInstance receiverObject = (ImageHeapInstance) getSnapshot(receiver, reason);
190-
if (receiverObject == null || (receiverObject.isInBaseLayer() && !bb.getUniverse().getImageLayerLoader().getRelinkedFields(receiverObject.getType()).contains(field.getPosition()))) {
190+
if (receiverObject == null || (receiverObject.isInSharedLayer() && !bb.getUniverse().getImageLayerLoader().getRelinkedFields(receiverObject.getType()).contains(field.getPosition()))) {
191191
return false;
192192
}
193193
JavaConstant fieldSnapshot = receiverObject.readFieldValue(field);
@@ -211,7 +211,7 @@ private void verifyStaticFieldValue(TypeData typeData, AnalysisField field, Java
211211
}
212212

213213
private void verifyInstanceFieldValue(AnalysisField field, JavaConstant receiver, ImageHeapInstance receiverObject, JavaConstant fieldSnapshot, JavaConstant fieldValue, ScanReason reason) {
214-
if (fieldSnapshot instanceof ImageHeapConstant ihc && ihc.isInBaseLayer() && ihc.getHostedObject() == null && !(ihc instanceof ImageHeapRelocatableConstant)) {
214+
if (fieldSnapshot instanceof ImageHeapConstant ihc && ihc.isInSharedLayer() && ihc.getHostedObject() == null && !(ihc instanceof ImageHeapRelocatableConstant)) {
215215
/*
216216
* We cannot verify a base layer constant which doesn't have a backing hosted
217217
* object. Since the hosted object is missing the constant would be replaced with
@@ -268,7 +268,7 @@ private boolean verifyArrayElementValue(JavaConstant elementValue, int index, Sc
268268
* the future, then compare the produced value.
269269
*/
270270
JavaConstant elementSnapshot = arrayObject.readElementValue(index);
271-
if (elementSnapshot instanceof ImageHeapConstant ihc && ihc.isInBaseLayer() && ihc.getHostedObject() == null) {
271+
if (elementSnapshot instanceof ImageHeapConstant ihc && ihc.isInSharedLayer() && ihc.getHostedObject() == null) {
272272
/*
273273
* We cannot verify a base layer constant which doesn't have a backing hosted
274274
* object. Since the hosted object is missing the constant would be replaced with

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public Object getSnapshot(JavaConstant constant) {
8484
* A base layer constant was in the objectsCache from the base image. It might not have
8585
* been put in the objectsCache of the extension image yet.
8686
*/
87-
assert imageHeapConstant.getHostedObject() == null || imageHeapConstant.isInBaseLayer() || objectsCache.get(imageHeapConstant.getHostedObject()).equals(imageHeapConstant);
87+
assert imageHeapConstant.getHostedObject() == null || imageHeapConstant.isInSharedLayer() || objectsCache.get(imageHeapConstant.getHostedObject()).equals(imageHeapConstant);
8888
return imageHeapConstant;
8989
}
9090
return objectsCache.get(uncompressed);

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,12 @@ abstract static class ConstantData {
9393
*/
9494
@SuppressWarnings("unused") private volatile Object isReachable;
9595
/**
96-
* A boolean allowing to distinguish a constant that was persisted from a base layer and a
96+
* A boolean allowing to distinguish a constant that was persisted from a shared layer and a
9797
* constant created in the current layer.
9898
*/
99-
private boolean isInBaseLayer;
99+
private boolean isInSharedLayer;
100100
/**
101-
* A boolean telling if the constant was written in the image heap of the base layer.
101+
* A boolean telling if the constant was written in the image heap of the shared layer.
102102
*/
103103
private boolean writtenInPreviousLayer;
104104
/**
@@ -209,16 +209,16 @@ public int getIdentityHashCode() {
209209
return constantData.identityHashCode;
210210
}
211211

212-
public void markInBaseLayer() {
213-
constantData.isInBaseLayer = true;
212+
public void markInSharedLayer() {
213+
constantData.isInSharedLayer = true;
214214
}
215215

216-
public boolean isInBaseLayer() {
217-
return constantData.isInBaseLayer;
216+
public boolean isInSharedLayer() {
217+
return constantData.isInSharedLayer;
218218
}
219219

220220
public void markWrittenInPreviousLayer() {
221-
AnalysisError.guarantee(isInBaseLayer(), "Constant must be in base layer to be marked as written in the base layer.");
221+
AnalysisError.guarantee(isInSharedLayer(), "Constant must be in base layer to be marked as written in the base layer.");
222222
constantData.writtenInPreviousLayer = true;
223223
}
224224

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public void setFieldValue(AnalysisField field, JavaConstant value) {
145145
* or the result of executing the task, i.e., a {@link JavaConstant}.
146146
*/
147147
public Object getFieldValue(AnalysisField field) {
148-
if (isInBaseLayer()) {
148+
if (isInSharedLayer()) {
149149
/* Base layer constants that are not relinked might not have field positions computed */
150150
field.getType().getInstanceFields(true);
151151
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,7 @@ public void rescanField(Object receiver, AnalysisField field, ScanReason reason)
732732
JavaConstant fieldSnapshot = receiverObject.readFieldValue(field);
733733
JavaConstant unwrappedSnapshot = ScanningObserver.maybeUnwrapSnapshot(fieldSnapshot, fieldValue instanceof ImageHeapConstant);
734734

735-
if (fieldSnapshot instanceof ImageHeapConstant ihc && ihc.isInBaseLayer() && ihc.getHostedObject() == null) {
735+
if (fieldSnapshot instanceof ImageHeapConstant ihc && ihc.isInSharedLayer() && ihc.getHostedObject() == null) {
736736
/*
737737
* We cannot verify a base layer constant which doesn't have a backing
738738
* hosted object. Since the hosted object is missing the constant would be

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/AnalysisField.java

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,13 @@ public abstract class AnalysisField extends AnalysisElement implements WrappedJa
6565

6666
private static final AtomicReferenceFieldUpdater<AnalysisField, Object> isUnsafeAccessedUpdater = AtomicReferenceFieldUpdater
6767
.newUpdater(AnalysisField.class, Object.class, "isUnsafeAccessed");
68+
/**
69+
* Unique id assigned to each {@link AnalysisField}. This id is consistent across layers and can
70+
* be used to load or match a field in an extension layer.
71+
*/
6872
private final int id;
69-
/** Marks a field loaded from a base layer. */
70-
private final boolean isInBaseLayer;
73+
/** Marks a field loaded from a shared layer. */
74+
private final boolean isInSharedLayer;
7175

7276
public final ResolvedJavaField wrapped;
7377

@@ -81,7 +85,10 @@ public abstract class AnalysisField extends AnalysisElement implements WrappedJa
8185
private ConcurrentMap<Object, Boolean> readBy;
8286
private ConcurrentMap<Object, Boolean> writtenBy;
8387

84-
/** Field's position in the list of declaring type's fields, including inherited fields. */
88+
/**
89+
* Field's position in the list of declaring type's fields, including inherited fields. The
90+
* position needs to be consistent across layers.
91+
*/
8592
protected int position;
8693

8794
protected final AnalysisType declaringClass;
@@ -117,22 +124,22 @@ public AnalysisField(AnalysisUniverse universe, ResolvedJavaField wrappedField)
117124
declaringClass = universe.lookup(wrappedField.getDeclaringClass());
118125
fieldType = getDeclaredType(universe, wrappedField);
119126

120-
if (universe.hostVM().buildingExtensionLayer() && declaringClass.isInBaseLayer()) {
127+
if (universe.hostVM().buildingExtensionLayer() && declaringClass.isInSharedLayer()) {
121128
int fid = universe.getImageLayerLoader().lookupHostedFieldInBaseLayer(this);
122129
if (fid != -1) {
123130
/*
124-
* This id is the actual link between the corresponding field from the base layer
131+
* This id is the actual link between the corresponding field from the shared layer
125132
* and this new field.
126133
*/
127134
id = fid;
128-
isInBaseLayer = true;
135+
isInSharedLayer = true;
129136
} else {
130137
id = universe.computeNextFieldId();
131-
isInBaseLayer = false;
138+
isInSharedLayer = false;
132139
}
133140
} else {
134141
id = universe.computeNextFieldId();
135-
isInBaseLayer = false;
142+
isInSharedLayer = false;
136143
}
137144
isLayeredStaticField = isStatic() && universe.hostVM.buildingImageLayer();
138145
}
@@ -167,8 +174,8 @@ public int getId() {
167174
return id;
168175
}
169176

170-
public boolean isInBaseLayer() {
171-
return isInBaseLayer;
177+
public boolean isInSharedLayer() {
178+
return isInSharedLayer;
172179
}
173180

174181
public boolean installableInLayer() {

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/AnalysisMethod.java

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,16 @@ public record Signature(String name, AnalysisType[] parameterTypes) {
129129

130130
public final ResolvedJavaMethod wrapped;
131131

132+
/**
133+
* Unique id assigned to each {@link AnalysisMethod}. This id is consistent across layers and
134+
* can be used to load or match a method in an extension layer.
135+
*/
132136
private final int id;
137+
/** True when the current layer built is a shared layer. */
133138
private final boolean buildingSharedLayer;
134-
/** Marks a method loaded from a base layer. */
135-
private final boolean isInBaseLayer;
139+
/** Marks a method loaded from a shared layer. */
140+
private final boolean isInSharedLayer;
141+
/** Marks a method analyzed in a prior layer. */
136142
private final boolean analyzedInPriorLayer;
137143
private final boolean hasNeverInlineDirective;
138144
private final ExceptionHandler[] exceptionHandlers;
@@ -228,24 +234,24 @@ protected AnalysisMethod(AnalysisUniverse universe, ResolvedJavaMethod wrapped,
228234
modifiers = wrapped.getModifiers();
229235

230236
buildingSharedLayer = hostVM.buildingSharedLayer();
231-
if (hostVM.buildingExtensionLayer() && declaringClass.isInBaseLayer()) {
237+
if (hostVM.buildingExtensionLayer() && declaringClass.isInSharedLayer()) {
232238
int mid = universe.getImageLayerLoader().lookupHostedMethodInBaseLayer(this);
233239
if (mid != -1) {
234240
/*
235-
* This id is the actual link between the corresponding method from the base layer
241+
* This id is the actual link between the corresponding method from the shared layer
236242
* and this new method.
237243
*/
238244
id = mid;
239-
isInBaseLayer = true;
245+
isInSharedLayer = true;
240246
} else {
241247
id = universe.computeNextMethodId();
242-
isInBaseLayer = false;
248+
isInSharedLayer = false;
243249
}
244250
} else {
245251
id = universe.computeNextMethodId();
246-
isInBaseLayer = false;
252+
isInSharedLayer = false;
247253
}
248-
analyzedInPriorLayer = isInBaseLayer && hostVM.analyzedInPriorLayer(this);
254+
analyzedInPriorLayer = isInSharedLayer && hostVM.analyzedInPriorLayer(this);
249255

250256
ExceptionHandler[] original = wrapped.getExceptionHandlers();
251257
exceptionHandlers = new ExceptionHandler[original.length];
@@ -288,7 +294,7 @@ protected AnalysisMethod(AnalysisUniverse universe, ResolvedJavaMethod wrapped,
288294
LayeredCompilationBehavior behavior = AnnotationUtil.getAnnotation(wrapped, LayeredCompilationBehavior.class);
289295
if (behavior != null) {
290296
compilationBehavior = behavior.value();
291-
if (compilationBehavior == LayeredCompilationBehavior.Behavior.PINNED_TO_INITIAL_LAYER && universe.hostVM.buildingExtensionLayer() && !isInBaseLayer) {
297+
if (compilationBehavior == LayeredCompilationBehavior.Behavior.PINNED_TO_INITIAL_LAYER && universe.hostVM.buildingExtensionLayer() && !isInSharedLayer) {
292298
var errorMessage = String.format("User methods with layered compilation behavior %s must be registered via %s in the initial layer",
293299
LayeredCompilationBehavior.Behavior.PINNED_TO_INITIAL_LAYER, LayeredCompilationSupport.class);
294300
throw AnalysisError.userError(errorMessage);
@@ -303,7 +309,7 @@ protected AnalysisMethod(AnalysisMethod original, MultiMethodKey multiMethodKey)
303309
wrapped = original.wrapped;
304310
id = original.id;
305311
buildingSharedLayer = original.buildingSharedLayer;
306-
isInBaseLayer = original.isInBaseLayer;
312+
isInSharedLayer = original.isInSharedLayer;
307313
analyzedInPriorLayer = original.analyzedInPriorLayer;
308314
declaringClass = original.declaringClass;
309315
signature = original.signature;
@@ -338,7 +344,7 @@ public void setCompilationBehavior(LayeredCompilationBehavior.Behavior compilati
338344
}
339345

340346
private void setNewCompilationBehavior(LayeredCompilationBehavior.Behavior compilationBehavior) {
341-
assert (!isInBaseLayer && this.compilationBehavior == LayeredCompilationBehavior.Behavior.DEFAULT) || this.compilationBehavior == compilationBehavior : "The method was already assigned " +
347+
assert (!isInSharedLayer && this.compilationBehavior == LayeredCompilationBehavior.Behavior.DEFAULT) || this.compilationBehavior == compilationBehavior : "The method was already assigned " +
342348
this.compilationBehavior + ", but trying to assign " + compilationBehavior;
343349
setCompilationBehavior(compilationBehavior);
344350
}
@@ -480,8 +486,8 @@ public int getId() {
480486
return id;
481487
}
482488

483-
public boolean isInBaseLayer() {
484-
return isInBaseLayer;
489+
public boolean isInSharedLayer() {
490+
return isInSharedLayer;
485491
}
486492

487493
public boolean analyzedInPriorLayer() {
@@ -1169,7 +1175,7 @@ private AnalysisParsedGraph ensureGraphParsedHelper(BigBang bb, Stage stage, boo
11691175

11701176
if (curState.isUnparsed(stage) || (forceReparse && curState.isStageParsed(stage))) {
11711177
AnalysisParsedGraph graph;
1172-
if (isInBaseLayer && getUniverse().getImageLayerLoader().hasAnalysisParsedGraph(this)) {
1178+
if (isInSharedLayer && getUniverse().getImageLayerLoader().hasAnalysisParsedGraph(this)) {
11731179
graph = getBaseLayerGraph(bb, curState);
11741180
} else {
11751181
graph = createAnalysisParsedGraph(bb, stage, curState, forceReparse);

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/AnalysisType.java

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,13 @@ public abstract class AnalysisType extends AnalysisElement implements WrappedJav
133133
@SuppressWarnings("unused") private volatile Object subTypes;
134134
AnalysisType superClass;
135135

136+
/**
137+
* Unique id assigned to each {@link AnalysisType}. This id is consistent across layers and can
138+
* be used to load or match a type in an extension layer.
139+
*/
136140
private final int id;
137-
/** Marks a type loaded from a base layer. */
138-
private final boolean isInBaseLayer;
141+
/** Marks a type loaded from a shared layer. */
142+
private final boolean isInSharedLayer;
139143

140144
private final JavaKind storageKind;
141145
private final boolean isCloneableWithAllocation;
@@ -302,24 +306,24 @@ public AnalysisType(AnalysisUniverse universe, ResolvedJavaType javaType, JavaKi
302306
int tid = universe.getImageLayerLoader().lookupHostedTypeInBaseLayer(this);
303307
if (tid != -1) {
304308
/*
305-
* This id is the actual link between the corresponding type from the base layer and
306-
* this new type.
309+
* This id is the actual link between the corresponding type from the shared layer
310+
* and this new type.
307311
*/
308312
this.id = tid;
309-
this.isInBaseLayer = true;
313+
this.isInSharedLayer = true;
310314
} else {
311315
this.id = universe.computeNextTypeId();
312316
/*
313317
* If both the BaseLayerType and the complete type are created at the same time,
314-
* there can be a race for the base layer id. It is possible that the complete type
315-
* gets the base layer id even though the BaseLayerType is created. In this case,
316-
* the AnalysisType should still be marked as isInBaseLayer.
318+
* there can be a race for the shared layer id. It is possible that the complete
319+
* type gets the shared layer id even though the BaseLayerType is created. In this
320+
* case, the AnalysisType should still be marked as isInSharedLayer.
317321
*/
318-
this.isInBaseLayer = wrapped instanceof BaseLayerType;
322+
this.isInSharedLayer = wrapped instanceof BaseLayerType;
319323
}
320324
} else {
321325
this.id = universe.computeNextTypeId();
322-
this.isInBaseLayer = false;
326+
this.isInSharedLayer = false;
323327
}
324328

325329
/*
@@ -398,8 +402,8 @@ public int getId() {
398402
return id;
399403
}
400404

401-
public boolean isInBaseLayer() {
402-
return isInBaseLayer;
405+
public boolean isInSharedLayer() {
406+
return isInSharedLayer;
403407
}
404408

405409
public AnalysisObject getContextInsensitiveAnalysisObject() {
@@ -595,7 +599,7 @@ protected void onReachable(Object reason) {
595599
scheduledTypeReachableNotifications = futures;
596600
}
597601

598-
if (isInBaseLayer && !(wrapped instanceof BaseLayerType)) {
602+
if (isInSharedLayer && !(wrapped instanceof BaseLayerType)) {
599603
/*
600604
* Since the analysis of the type is skipped, the fields have to be created manually to
601605
* ensure their flags are loaded from the base layer. Not creating the fields would

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/AnalysisUniverse.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ public JavaType lookupAllowUnresolved(JavaType rawType) {
220220
AnalysisType result = optionalLookup(type);
221221
if (result == null) {
222222
result = createType(type);
223-
if (hostVM.buildingExtensionLayer() && result.isInBaseLayer()) {
223+
if (hostVM.buildingExtensionLayer() && result.isInSharedLayer()) {
224224
imageLayerLoader.initializeBaseLayerType(result);
225225
}
226226
}
@@ -387,14 +387,14 @@ private AnalysisField createField(ResolvedJavaField field) {
387387
}
388388
AnalysisField newValue = analysisFactory.createField(this, field);
389389
AnalysisField result = fields.computeIfAbsent(field, f -> {
390-
if (newValue.isInBaseLayer()) {
390+
if (newValue.isInSharedLayer()) {
391391
getImageLayerLoader().addBaseLayerField(newValue);
392392
}
393393
return newValue;
394394
});
395395

396396
if (result.equals(newValue)) {
397-
if (newValue.isInBaseLayer()) {
397+
if (newValue.isInSharedLayer()) {
398398
getImageLayerLoader().initializeBaseLayerField(newValue);
399399
}
400400
}
@@ -441,7 +441,7 @@ private AnalysisMethod createMethod(ResolvedJavaMethod method) {
441441
}
442442
AnalysisMethod newValue = analysisFactory.createMethod(this, method);
443443
AnalysisMethod result = methods.computeIfAbsent(method, m -> {
444-
if (newValue.isInBaseLayer()) {
444+
if (newValue.isInSharedLayer()) {
445445
getImageLayerLoader().addBaseLayerMethod(newValue);
446446
}
447447
return newValue;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ public void afterAnalysis(AfterAnalysisAccess access) {
307307

308308
Set<Module> runtimeImageModules = accessImpl.getUniverse().getTypes()
309309
.stream()
310-
.filter(t1 -> !t1.isInBaseLayer() && typeIsReachable(t1))
310+
.filter(t1 -> !t1.isInSharedLayer() && typeIsReachable(t1))
311311
.map(t -> t.getJavaClass().getModule())
312312
.collect(Collectors.toSet());
313313

0 commit comments

Comments
 (0)