diff --git a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/api/HostVM.java b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/api/HostVM.java index a08f9dbc3a45..711e26bae584 100644 --- a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/api/HostVM.java +++ b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/api/HostVM.java @@ -313,10 +313,6 @@ public boolean platformSupported(AnnotatedElement element) { return true; } - public boolean sortFields() { - return false; - } - public void clearInThread() { } diff --git a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/AnalysisType.java b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/AnalysisType.java index 5ddce7cce422..2ee4350ac4bb 100644 --- a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/AnalysisType.java +++ b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/AnalysisType.java @@ -28,7 +28,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.Comparator; import java.util.HashSet; import java.util.List; import java.util.Objects; @@ -1197,22 +1196,8 @@ private ResolvedJavaField[] initializeInstanceFields(boolean includeSuperclasses return result; } - /** - * Sort fields by the field's name *and* type. Note that sorting by name is not enough as the - * class file format doesn't disallow duplicated names with differing types in the same class. - * Even though you cannot declare duplicated names in source code the class file can be - * manipulated such that two fields will have the same name. - */ - static final Comparator FIELD_COMPARATOR = Comparator.comparing(ResolvedJavaField::getName).thenComparing(f -> f.getType().toJavaName()); - private ResolvedJavaField[] convertFields(ResolvedJavaField[] originals, List list, boolean listIncludesSuperClassesFields) { - ResolvedJavaField[] localOriginals = originals; - if (universe.hostVM.sortFields()) { - /* Clone the originals; it is a reference to the wrapped type's instanceFields array. */ - localOriginals = originals.clone(); - Arrays.sort(localOriginals, FIELD_COMPARATOR); - } - for (ResolvedJavaField original : localOriginals) { + for (ResolvedJavaField original : originals) { if (!original.isInternal() && universe.hostVM.platformSupported(original)) { try { AnalysisField aField = universe.lookup(original); diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SVMHost.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SVMHost.java index abbb26541a0a..407b1974daac 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SVMHost.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SVMHost.java @@ -1001,15 +1001,6 @@ private void initializeSharedLayerExcludedFields() { sharedLayerExcludedFields.add(lookupOriginalDeclaredField(NativeLibraries.class, "nativeLibraryLockMap")); } - @Override - public boolean sortFields() { - /* - * If building layered images sort the fields by kind and name to ensure stable order. - * Sorting fields in general may lead to some issues. (GR-62599) - */ - return buildingImageLayer; - } - /** If it's not one of the known builder types it must be an original VM type. */ private static boolean isOriginalType(ResolvedJavaType type) { return !(type instanceof OriginalClassProvider); diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/imagelayer/SVMImageLayerLoader.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/imagelayer/SVMImageLayerLoader.java index 0ffad7697992..3c32ac6ac40d 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/imagelayer/SVMImageLayerLoader.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/imagelayer/SVMImageLayerLoader.java @@ -51,7 +51,6 @@ import java.util.function.Supplier; import java.util.stream.IntStream; -import com.oracle.svm.hosted.substitute.SubstitutionMethod; import org.graalvm.collections.EconomicMap; import org.graalvm.nativeimage.AnnotationAccess; import org.graalvm.nativeimage.ImageSingletons; @@ -121,6 +120,7 @@ import com.oracle.svm.hosted.meta.PatchedWordConstant; import com.oracle.svm.hosted.reflect.ReflectionFeature; import com.oracle.svm.hosted.reflect.serialize.SerializationFeature; +import com.oracle.svm.hosted.substitute.SubstitutionMethod; import com.oracle.svm.hosted.util.IdentityHashCodeUtil; import com.oracle.svm.shaded.org.capnproto.PrimitiveList; import com.oracle.svm.shaded.org.capnproto.StructList; @@ -1318,6 +1318,12 @@ public void initializeBaseLayerField(AnalysisField analysisField) { }); registerFlag(fieldData.getIsFolded(), debug -> analysisField.registerAsFolded(PERSISTED)); registerFlag(fieldData.getIsUnsafeAccessed(), debug -> analysisField.registerAsUnsafeAccessed(PERSISTED)); + + /* + * Inject the base layer position. If the position computed for this layer, either before + * this step or later, is different this will result in a failed guarantee. + */ + analysisField.setPosition(fieldData.getPosition()); } private PersistedAnalysisField.Reader getFieldData(AnalysisField analysisField) {