Skip to content

[GR-62599] Sort fields by kind and name to ensure stable order. #10796

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,10 @@ public boolean platformSupported(AnnotatedElement element) {
return true;
}

public boolean sortFields() {
return false;
}

public void clearInThread() {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ public String getName() {
}

public void setPosition(int newPosition) {
AnalysisError.guarantee(position == -1 || newPosition == position, "Position already set for field %s, old position: %d, new position: %d", this, position, newPosition);
this.position = newPosition;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
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;
Expand Down Expand Up @@ -1227,8 +1228,16 @@ private ResolvedJavaField[] initializeInstanceFields(boolean includeSuperclasses
return result;
}

static final Comparator<ResolvedJavaField> FIELD_COMPARATOR = Comparator.comparing(ResolvedJavaField::getJavaKind).thenComparing(ResolvedJavaField::getName);

private ResolvedJavaField[] convertFields(ResolvedJavaField[] originals, List<ResolvedJavaField> list, boolean listIncludesSuperClassesFields) {
for (ResolvedJavaField original : originals) {
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) {
if (!original.isInternal() && universe.hostVM.platformSupported(original)) {
try {
AnalysisField aField = universe.lookup(original);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,15 @@ private void initializeExcludedFields() {
excludedFields.add(ReflectionUtil.lookupField(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 ImageLayerBuildingSupport.buildingImageLayer();
}

/**
* This method cannot use an {@link AnalysisField} because it is used before the analysis is set
* up.
Expand Down
Loading