Skip to content

Commit fb9ade3

Browse files
committed
Refactor HostVM layer API
1 parent 2c57cba commit fb9ade3

File tree

10 files changed

+39
-35
lines changed

10 files changed

+39
-35
lines changed

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/api/HostVM.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,6 @@ public boolean isCoreType(@SuppressWarnings("unused") AnalysisType type) {
184184
return false;
185185
}
186186

187-
public boolean useBaseLayer() {
188-
return false;
189-
}
190-
191187
public boolean analyzedInPriorLayer(@SuppressWarnings("unused") AnalysisMethod method) {
192188
return false;
193189
}
@@ -432,6 +428,14 @@ public boolean buildingImageLayer() {
432428
return false;
433429
}
434430

431+
public boolean buildingSharedLayer() {
432+
return false;
433+
}
434+
435+
public boolean buildingExtensionLayer() {
436+
return false;
437+
}
438+
435439
@SuppressWarnings("unused")
436440
public boolean installableInLayer(AnalysisField aField) {
437441
return true;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,11 +333,11 @@ private ImageHeapConstant getSnapshot(JavaConstant constant, ScanReason reason)
333333
result = (ImageHeapConstant) constant;
334334
} else {
335335
Object task = imageHeap.getSnapshot(constant);
336-
if (task == null && bb.getUniverse().hostVM().useBaseLayer() && bb.getUniverse().getImageLayerLoader().hasValueForConstant(constant)) {
336+
if (task == null && bb.getUniverse().hostVM().buildingExtensionLayer() && bb.getUniverse().getImageLayerLoader().hasValueForConstant(constant)) {
337337
/* The constant might not have been accessed in the extension image yet */
338338
task = bb.getUniverse().getImageLayerLoader().getValueForConstant(constant);
339339
}
340-
if (task == null && bb.getUniverse().hostVM().useBaseLayer()) {
340+
if (task == null && bb.getUniverse().hostVM().buildingExtensionLayer()) {
341341
/*
342342
* This does not distinguish between base and extension layer constants at the
343343
* moment. Doing so would require some refactoring to determine earlier if the

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
@@ -266,7 +266,7 @@ protected ImageHeapConstant getOrCreateImageHeapConstant(JavaConstant javaConsta
266266
if (existingTask == null) {
267267
AnalysisFuture<ImageHeapConstant> newTask;
268268
ImageLayerLoader imageLayerLoader = universe.getImageLayerLoader();
269-
if (hostVM.useBaseLayer() && imageLayerLoader.hasValueForConstant(javaConstant)) {
269+
if (hostVM.buildingExtensionLayer() && imageLayerLoader.hasValueForConstant(javaConstant)) {
270270
ImageHeapConstant value = imageLayerLoader.getValueForConstant(javaConstant);
271271
ensureFieldPositionsComputed(value, nonNullReason);
272272
AnalysisError.guarantee(value.getHostedObject().equals(javaConstant));

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public AnalysisField(AnalysisUniverse universe, ResolvedJavaField wrappedField)
141141
sinkFlow = new ContextInsensitiveFieldTypeFlow(this, getType());
142142
}
143143

144-
if (universe.hostVM().useBaseLayer() && declaringClass.isInBaseLayer()) {
144+
if (universe.hostVM().buildingExtensionLayer() && declaringClass.isInBaseLayer()) {
145145
int fid = universe.getImageLayerLoader().lookupHostedFieldInBaseLayer(this);
146146
if (fid != -1) {
147147
/*

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ protected AnalysisMethod(AnalysisUniverse universe, ResolvedJavaMethod wrapped,
219219
qualifiedName = format("%H.%n(%P)");
220220
modifiers = wrapped.getModifiers();
221221

222-
if (universe.hostVM().useBaseLayer() && declaringClass.isInBaseLayer()) {
222+
if (universe.hostVM().buildingExtensionLayer() && declaringClass.isInBaseLayer()) {
223223
int mid = universe.getImageLayerLoader().lookupHostedMethodInBaseLayer(this);
224224
if (mid != -1) {
225225
/*

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ public AnalysisType(AnalysisUniverse universe, ResolvedJavaType javaType, JavaKi
287287
}
288288

289289
/* Set id after accessing super types, so that all these types get a lower id number. */
290-
if (universe.hostVM().useBaseLayer()) {
290+
if (universe.hostVM().buildingExtensionLayer()) {
291291
int tid = universe.getImageLayerLoader().lookupHostedTypeInBaseLayer(this);
292292
if (tid != -1) {
293293
/*

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ public JavaType lookupAllowUnresolved(JavaType rawType) {
216216
AnalysisType result = optionalLookup(type);
217217
if (result == null) {
218218
result = createType(type);
219-
if (hostVM.useBaseLayer() && result.isInBaseLayer()) {
219+
if (hostVM.buildingExtensionLayer() && result.isInBaseLayer()) {
220220
imageLayerLoader.initializeBaseLayerType(result);
221221
}
222222
}
@@ -308,7 +308,7 @@ private AnalysisType createType(ResolvedJavaType type) {
308308
* ensures that typesById doesn't contain any null values. This could happen since the
309309
* AnalysisType constructor increments the nextTypeId counter.
310310
*/
311-
if (hostVM.useBaseLayer() && imageLayerLoader.hasDynamicHubIdentityHashCode(newValue.getId())) {
311+
if (hostVM.buildingExtensionLayer() && imageLayerLoader.hasDynamicHubIdentityHashCode(newValue.getId())) {
312312
hostVM.registerType(newValue, imageLayerLoader.getDynamicHubIdentityHashCode(newValue.getId()));
313313
} else {
314314
hostVM.registerType(newValue);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ public static List<AnalysisMethod> reportedReachableMethods(AnalysisUniverse uni
536536

537537
private static <T extends AnalysisElement> List<T> reportedElements(AnalysisUniverse universe, Collection<T> elements, Predicate<T> elementsFilter, Predicate<T> baseLayerFilter) {
538538
Stream<T> reachableElements = elements.stream().filter(elementsFilter);
539-
return universe.hostVM().useBaseLayer() ? reachableElements.filter(baseLayerFilter).toList() : reachableElements.toList();
539+
return universe.hostVM().buildingExtensionLayer() ? reachableElements.filter(baseLayerFilter).toList() : reachableElements.toList();
540540
}
541541

542542
public ReporterClosable printUniverse() {

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

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,9 @@ public enum UsageKind {
212212
private final SymbolEncoder encoder = SymbolEncoder.singleton();
213213

214214
private final int layerId;
215-
private final boolean useBaseLayer;
215+
private final boolean buildingImageLayer = ImageLayerBuildingSupport.buildingImageLayer();
216+
private final boolean buildingSharedLayer = ImageLayerBuildingSupport.buildingSharedLayer();
217+
private final boolean buildingExtensionLayer = ImageLayerBuildingSupport.buildingExtensionLayer();
216218

217219
// All elements below are from the host VM universe, not the analysis universe
218220
private Set<ResolvedJavaField> sharedLayerExcludedFields;
@@ -221,9 +223,6 @@ public enum UsageKind {
221223

222224
private final Boolean optionAllowUnsafeAllocationOfAllInstantiatedTypes = SubstrateOptions.AllowUnsafeAllocationOfAllInstantiatedTypes.getValue();
223225
private final boolean isClosedTypeWorld = SubstrateOptions.useClosedTypeWorld();
224-
private final boolean enableTrackAcrossLayers;
225-
private final boolean enableReachableInCurrentLayer;
226-
private final boolean buildingImageLayer = ImageLayerBuildingSupport.buildingImageLayer();
227226
private final LayeredStaticFieldSupport layeredStaticFieldSupport;
228227
private final MetaAccessProvider originalMetaAccess;
229228

@@ -256,15 +255,11 @@ public SVMHost(OptionValues options, ImageClassLoader loader, ClassInitializatio
256255
} else {
257256
parsingSupport = null;
258257
}
259-
layerId = ImageLayerBuildingSupport.buildingImageLayer() ? DynamicImageLayerInfo.getCurrentLayerNumber() : 0;
260-
useBaseLayer = ImageLayerBuildingSupport.buildingExtensionLayer();
261-
if (ImageLayerBuildingSupport.buildingSharedLayer()) {
258+
layerId = buildingImageLayer ? DynamicImageLayerInfo.getCurrentLayerNumber() : 0;
259+
if (buildingSharedLayer) {
262260
initializeSharedLayerExcludedFields();
263261
}
264-
265-
enableTrackAcrossLayers = ImageLayerBuildingSupport.buildingSharedLayer();
266-
enableReachableInCurrentLayer = ImageLayerBuildingSupport.buildingExtensionLayer();
267-
layeredStaticFieldSupport = ImageLayerBuildingSupport.buildingImageLayer() ? LayeredStaticFieldSupport.singleton() : null;
262+
layeredStaticFieldSupport = buildingImageLayer ? LayeredStaticFieldSupport.singleton() : null;
268263

269264
optionKeyType = lookupOriginalType(OptionKey.class);
270265
featureType = lookupOriginalType(Feature.class);
@@ -283,8 +278,18 @@ public boolean isCoreType(AnalysisType type) {
283278
}
284279

285280
@Override
286-
public boolean useBaseLayer() {
287-
return useBaseLayer;
281+
public boolean buildingImageLayer() {
282+
return buildingImageLayer;
283+
}
284+
285+
@Override
286+
public boolean buildingSharedLayer() {
287+
return buildingSharedLayer;
288+
}
289+
290+
@Override
291+
public boolean buildingExtensionLayer() {
292+
return buildingExtensionLayer;
288293
}
289294

290295
/**
@@ -989,7 +994,7 @@ public boolean sortFields() {
989994
* If building layered images sort the fields by kind and name to ensure stable order.
990995
* Sorting fields in general may lead to some issues. (GR-62599)
991996
*/
992-
return ImageLayerBuildingSupport.buildingImageLayer();
997+
return buildingImageLayer;
993998
}
994999

9951000
/** If it's not one of the known builder types it must be an original VM type. */
@@ -1175,17 +1180,12 @@ public boolean isClosedTypeWorld() {
11751180

11761181
@Override
11771182
public boolean enableTrackAcrossLayers() {
1178-
return enableTrackAcrossLayers;
1183+
return buildingSharedLayer();
11791184
}
11801185

11811186
@Override
11821187
public boolean enableReachableInCurrentLayer() {
1183-
return enableReachableInCurrentLayer;
1184-
}
1185-
1186-
@Override
1187-
public boolean buildingImageLayer() {
1188-
return buildingImageLayer;
1188+
return buildingExtensionLayer;
11891189
}
11901190

11911191
@Override

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/analysis/DynamicHubInitializer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public void initializeMetaData(ImageHeapScanner heapScanner, AnalysisType type)
172172
* GR-60254.
173173
*/
174174
private boolean shouldRescanHub(ImageHeapScanner heapScanner, DynamicHub hub) {
175-
if (hostVM.useBaseLayer()) {
175+
if (hostVM.buildingExtensionLayer()) {
176176
ImageHeapConstant hubConstant = (ImageHeapConstant) heapScanner.createImageHeapConstant(hub, OtherReason.HUB);
177177
return hubConstant == null || !hubConstant.isInBaseLayer();
178178
}

0 commit comments

Comments
 (0)