changeset 7136:4f62a7fa7f9f

sort the fields returned by getInstanceFields by offset
author Lukas Stadler <lukas.stadler@jku.at>
date Wed, 05 Dec 2012 13:56:56 +0100
parents c41a958a3923
children a818db37b7be
files graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/ResolvedJavaType.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedObjectType.java
diffstat 2 files changed, 13 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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);
--- 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<HotSpotResolvedJavaField> {
+        @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);