# HG changeset patch # User Lukas Stadler # Date 1354712216 -3600 # Node ID 4f62a7fa7f9fdac7f9be8a2719273610b582bc6c # Parent c41a958a39235c0341901d80d64297bcd75a4e8c sort the fields returned by getInstanceFields by offset diff -r c41a958a3923 -r 4f62a7fa7f9f graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/ResolvedJavaType.java --- a/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/ResolvedJavaType.java Tue Dec 04 11:05:01 2012 -0800 +++ b/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/ResolvedJavaType.java Wed Dec 05 13:56:56 2012 +0100 @@ -215,9 +215,12 @@ /** * Returns the instance fields of this class, including {@linkplain ResolvedJavaField#isInternal() internal} fields. * A zero-length array is returned for array and primitive types. The order of fields returned by this method is - * stable. That is, for a single JVM execution the same order is returned each time this method is called. + * stable. That is, for a single JVM execution the same order is returned each time this method is called. It is + * also the "natural" order, which means that the JVM would expect the fields in this order if no specific order is + * given. * - * @param includeSuperclasses if true, then instance fields for the complete hierarchy of this type are included in the result + * @param includeSuperclasses if true, then instance fields for the complete hierarchy of this type are included in + * the result * @return an array of instance fields */ ResolvedJavaField[] getInstanceFields(boolean includeSuperclasses); diff -r c41a958a3923 -r 4f62a7fa7f9f graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedObjectType.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedObjectType.java Tue Dec 04 11:05:01 2012 -0800 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedObjectType.java Wed Dec 05 13:56:56 2012 +0100 @@ -396,6 +396,13 @@ return ((HotSpotResolvedJavaMethod) method).uniqueConcreteMethod(); } + private static class OffsetComparator implements Comparator { + @Override + public int compare(HotSpotResolvedJavaField o1, HotSpotResolvedJavaField o2) { + return o1.offset() - o2.offset(); + } + } + @Override public ResolvedJavaField[] getInstanceFields(boolean includeSuperclasses) { if (instanceFields == null) { @@ -403,6 +410,7 @@ instanceFields = new HotSpotResolvedJavaField[0]; } else { HotSpotResolvedJavaField[] myFields = HotSpotGraalRuntime.getInstance().getCompilerToVM().getInstanceFields(this); + Arrays.sort(myFields, new OffsetComparator()); if (javaMirror != Object.class) { HotSpotResolvedJavaField[] superFields = (HotSpotResolvedJavaField[]) getSuperclass().getInstanceFields(true); HotSpotResolvedJavaField[] fields = Arrays.copyOf(superFields, superFields.length + myFields.length);