Skip to content

Commit 53f614c

Browse files
committed
Refactor layer loader.
1 parent 87de44c commit 53f614c

File tree

1 file changed

+15
-23
lines changed

1 file changed

+15
-23
lines changed

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

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ private void relinkStaticFinalFieldValues(boolean isLateLoading) {
294294
* registration will fail. That could mean that we try to register too late.
295295
*/
296296
if (constant.getHostedObject() != null) {
297-
universe.getHeapScanner().registerBaseLayerValue(constant, null);
297+
universe.getHeapScanner().registerBaseLayerValue(constant, PERSISTED);
298298
}
299299
}
300300
});
@@ -1204,15 +1204,12 @@ public boolean hasValueForConstant(JavaConstant javaConstant) {
12041204

12051205
@SuppressFBWarnings(value = "ES", justification = "Reference equality check needed to detect intern status")
12061206
private boolean hasValueForObject(Object object) {
1207-
if (object instanceof DynamicHub dynamicHub) {
1208-
AnalysisType type = ((SVMHost) universe.hostVM()).lookupType(dynamicHub);
1209-
return typeToConstant.containsKey(type.getId());
1210-
} else if (object instanceof String string) {
1211-
return stringToConstant.containsKey(string) && string.intern() == string;
1212-
} else if (object instanceof Enum<?>) {
1213-
return enumToConstant.containsKey(object);
1214-
}
1215-
return false;
1207+
return switch (object) {
1208+
case DynamicHub dynamicHub -> typeToConstant.containsKey(((SVMHost) universe.hostVM()).lookupType(dynamicHub).getId());
1209+
case String string -> stringToConstant.containsKey(string) && string.intern() == string;
1210+
case Enum<?> e -> enumToConstant.containsKey(e);
1211+
default -> false;
1212+
};
12161213
}
12171214

12181215
@Override
@@ -1222,18 +1219,13 @@ public ImageHeapConstant getValueForConstant(JavaConstant javaConstant) {
12221219
}
12231220

12241221
private ImageHeapConstant getValueForObject(Object object) {
1225-
if (object instanceof DynamicHub dynamicHub) {
1226-
AnalysisType type = ((SVMHost) universe.hostVM()).lookupType(dynamicHub);
1227-
int id = typeToConstant.get(type.getId());
1228-
return getOrCreateConstant(id);
1229-
} else if (object instanceof String string) {
1230-
int id = stringToConstant.get(string);
1231-
return getOrCreateConstant(id);
1232-
} else if (object instanceof Enum<?>) {
1233-
int id = enumToConstant.get(object);
1234-
return getOrCreateConstant(id);
1235-
}
1236-
throw AnalysisError.shouldNotReachHere("The constant was not in the persisted heap.");
1222+
return switch (object) {
1223+
case DynamicHub dynamicHub ->
1224+
getOrCreateConstant(typeToConstant.get(((SVMHost) universe.hostVM()).lookupType(dynamicHub).getId()));
1225+
case String string -> getOrCreateConstant(stringToConstant.get(string));
1226+
case Enum<?> e -> getOrCreateConstant(enumToConstant.get(e));
1227+
default -> throw AnalysisError.shouldNotReachHere("The constant was not in the persisted heap.");
1228+
};
12371229
}
12381230

12391231
@Override
@@ -1530,7 +1522,7 @@ private JavaConstant lookupHostedObject(PersistedConstant.Reader baseLayerConsta
15301522
return null;
15311523
} else if (relinking.isFieldConstant()) {
15321524
var fieldConstant = relinking.getFieldConstant();
1533-
AnalysisField analysisField = getAnalysisFieldForBaseLayerId(fieldConstant.getFieldId());
1525+
AnalysisField analysisField = getAnalysisFieldForBaseLayerId(fieldConstant.getOriginFieldId());
15341526
if (!(analysisField.getWrapped() instanceof BaseLayerField)) {
15351527
VMError.guarantee(!baseLayerConstant.getIsSimulated(), "Should not alter the initialization status for simulated constants.");
15361528
/*

0 commit comments

Comments
 (0)