Skip to content

Commit 1517573

Browse files
committed
Ensure fields position is stable between layers.
1 parent 9b893b0 commit 1517573

File tree

4 files changed

+8
-30
lines changed

4 files changed

+8
-30
lines changed

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -313,10 +313,6 @@ public boolean platformSupported(AnnotatedElement element) {
313313
return true;
314314
}
315315

316-
public boolean sortFields() {
317-
return false;
318-
}
319-
320316
public void clearInThread() {
321317
}
322318

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

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import java.util.ArrayList;
2929
import java.util.Arrays;
3030
import java.util.Collection;
31-
import java.util.Comparator;
3231
import java.util.HashSet;
3332
import java.util.List;
3433
import java.util.Objects;
@@ -1197,22 +1196,8 @@ private ResolvedJavaField[] initializeInstanceFields(boolean includeSuperclasses
11971196
return result;
11981197
}
11991198

1200-
/**
1201-
* Sort fields by the field's name *and* type. Note that sorting by name is not enough as the
1202-
* class file format doesn't disallow duplicated names with differing types in the same class.
1203-
* Even though you cannot declare duplicated names in source code the class file can be
1204-
* manipulated such that two fields will have the same name.
1205-
*/
1206-
static final Comparator<ResolvedJavaField> FIELD_COMPARATOR = Comparator.comparing(ResolvedJavaField::getName).thenComparing(f -> f.getType().toJavaName());
1207-
12081199
private ResolvedJavaField[] convertFields(ResolvedJavaField[] originals, List<ResolvedJavaField> list, boolean listIncludesSuperClassesFields) {
1209-
ResolvedJavaField[] localOriginals = originals;
1210-
if (universe.hostVM.sortFields()) {
1211-
/* Clone the originals; it is a reference to the wrapped type's instanceFields array. */
1212-
localOriginals = originals.clone();
1213-
Arrays.sort(localOriginals, FIELD_COMPARATOR);
1214-
}
1215-
for (ResolvedJavaField original : localOriginals) {
1200+
for (ResolvedJavaField original : originals) {
12161201
if (!original.isInternal() && universe.hostVM.platformSupported(original)) {
12171202
try {
12181203
AnalysisField aField = universe.lookup(original);

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,15 +1001,6 @@ private void initializeSharedLayerExcludedFields() {
10011001
sharedLayerExcludedFields.add(lookupOriginalDeclaredField(NativeLibraries.class, "nativeLibraryLockMap"));
10021002
}
10031003

1004-
@Override
1005-
public boolean sortFields() {
1006-
/*
1007-
* If building layered images sort the fields by kind and name to ensure stable order.
1008-
* Sorting fields in general may lead to some issues. (GR-62599)
1009-
*/
1010-
return buildingImageLayer;
1011-
}
1012-
10131004
/** If it's not one of the known builder types it must be an original VM type. */
10141005
private static boolean isOriginalType(ResolvedJavaType type) {
10151006
return !(type instanceof OriginalClassProvider);

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
import java.util.function.Supplier;
5252
import java.util.stream.IntStream;
5353

54-
import com.oracle.svm.hosted.substitute.SubstitutionMethod;
5554
import org.graalvm.collections.EconomicMap;
5655
import org.graalvm.nativeimage.AnnotationAccess;
5756
import org.graalvm.nativeimage.ImageSingletons;
@@ -121,6 +120,7 @@
121120
import com.oracle.svm.hosted.meta.PatchedWordConstant;
122121
import com.oracle.svm.hosted.reflect.ReflectionFeature;
123122
import com.oracle.svm.hosted.reflect.serialize.SerializationFeature;
123+
import com.oracle.svm.hosted.substitute.SubstitutionMethod;
124124
import com.oracle.svm.hosted.util.IdentityHashCodeUtil;
125125
import com.oracle.svm.shaded.org.capnproto.PrimitiveList;
126126
import com.oracle.svm.shaded.org.capnproto.StructList;
@@ -1318,6 +1318,12 @@ public void initializeBaseLayerField(AnalysisField analysisField) {
13181318
});
13191319
registerFlag(fieldData.getIsFolded(), debug -> analysisField.registerAsFolded(PERSISTED));
13201320
registerFlag(fieldData.getIsUnsafeAccessed(), debug -> analysisField.registerAsUnsafeAccessed(PERSISTED));
1321+
1322+
/*
1323+
* Inject the base layer position. If the position computed for this layer, either before
1324+
* this step or later, is different this will result in a failed guarantee.
1325+
*/
1326+
analysisField.setPosition(fieldData.getPosition());
13211327
}
13221328

13231329
private PersistedAnalysisField.Reader getFieldData(AnalysisField analysisField) {

0 commit comments

Comments
 (0)