# HG changeset patch # User Christian Wimmer # Date 1400638001 25200 # Node ID 2838203d4231feae336e246c11f8c834335b15d1 # Parent 15771ff797b45e1120c9cf73df00c45b0a4d10f3 Add method ResolvedJavaType.getStaticFields diff -r 15771ff797b4 -r 2838203d4231 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 May 20 19:02:33 2014 -0700 +++ b/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/ResolvedJavaType.java Tue May 20 19:06:41 2014 -0700 @@ -247,6 +247,14 @@ ResolvedJavaField[] getInstanceFields(boolean includeSuperclasses); /** + * Returns the static 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. + */ + ResolvedJavaField[] getStaticFields(); + + /** * Returns the annotation for the specified type of this class, if such an annotation is * present. * diff -r 15771ff797b4 -r 2838203d4231 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 May 20 19:02:33 2014 -0700 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedObjectType.java Tue May 20 19:06:41 2014 -0700 @@ -607,6 +607,29 @@ return instanceFields; } + @Override + public ResolvedJavaField[] getStaticFields() { + if (isArray()) { + return new HotSpotResolvedJavaField[0]; + } else { + final int fieldCount = getFieldCount(); + ArrayList fieldsArray = new ArrayList<>(fieldCount); + + for (int i = 0; i < fieldCount; i++) { + FieldInfo field = new FieldInfo(i); + + // We are only interested in static fields. + if (field.isStatic()) { + HotSpotResolvedJavaField resolvedJavaField = createField(field.getName(), field.getType(), field.getOffset(), field.getAccessFlags()); + fieldsArray.add(resolvedJavaField); + } + } + + fieldsArray.sort(new OffsetComparator()); + return fieldsArray.toArray(new HotSpotResolvedJavaField[fieldsArray.size()]); + } + } + /** * Returns the actual field count of this class's internal {@code InstanceKlass::_fields} array * by walking the array and discounting the generic signature slots at the end of the array. diff -r 15771ff797b4 -r 2838203d4231 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedPrimitiveType.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedPrimitiveType.java Tue May 20 19:02:33 2014 -0700 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedPrimitiveType.java Tue May 20 19:06:41 2014 -0700 @@ -39,7 +39,7 @@ /** * Gets the Graal mirror for a {@link Kind}. - * + * * @return the {@link HotSpotResolvedObjectType} corresponding to {@code kind} */ public static ResolvedJavaType fromKind(Kind kind) { @@ -49,12 +49,12 @@ /** * Creates the Graal mirror for a primitive {@link Kind}. - * + * *

* NOTE: Creating an instance of this class does not install the mirror for the * {@link Class} type. Use {@link #fromKind(Kind)} or {@link #fromClass(Class)} instead. *

- * + * * @param kind the Kind to create the mirror for */ public HotSpotResolvedPrimitiveType(Kind kind) { @@ -188,6 +188,11 @@ } @Override + public ResolvedJavaField[] getStaticFields() { + return new ResolvedJavaField[0]; + } + + @Override public T getAnnotation(Class annotationClass) { return null; }