changeset 7055:ec2e696fc3bc

Merge.
author Doug Simon <doug.simon@oracle.com>
date Tue, 27 Nov 2012 18:33:13 +0100
parents 5d4676ae84a4 (diff) 6cbaae52bab9 (current diff)
children 2841e28b5f41
files graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaType.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotTypePrimitive.java
diffstat 16 files changed, 82 insertions(+), 45 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.api.interpreter/src/com/oracle/graal/api/interpreter/RuntimeInterpreterInterface.java	Tue Nov 27 17:33:52 2012 +0100
+++ b/graal/com.oracle.graal.api.interpreter/src/com/oracle/graal/api/interpreter/RuntimeInterpreterInterface.java	Tue Nov 27 18:33:13 2012 +0100
@@ -100,4 +100,5 @@
 
     void setArrayObject(Object value, long index, Object array);
 
+    Class<?> getMirror(ResolvedJavaType type);
 }
--- a/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/MetaUtil.java	Tue Nov 27 17:33:52 2012 +0100
+++ b/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/MetaUtil.java	Tue Nov 27 18:33:13 2012 +0100
@@ -429,15 +429,6 @@
         return result;
     }
 
-    public static Class< ? >[] signatureToTypes(Signature signature, ResolvedJavaType accessingClass) {
-        int count = signature.getParameterCount(false);
-        Class< ? >[] result = new Class< ? >[count];
-        for (int i = 0; i < result.length; ++i) {
-            result[i] = signature.getParameterType(i, accessingClass).resolve(accessingClass).toJava();
-        }
-        return result;
-    }
-
     /**
      * Formats some profiling information associated as a string.
      *
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotRuntimeInterpreterInterface.java	Tue Nov 27 17:33:52 2012 +0100
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotRuntimeInterpreterInterface.java	Tue Nov 27 18:33:13 2012 +0100
@@ -40,6 +40,10 @@
         this.metaProvider = metaProvider;
     }
 
+    public Class< ? > getMirror(ResolvedJavaType type) {
+        return ((HotSpotJavaType) type).mirror();
+    }
+
     public native Object invoke(ResolvedJavaMethod method, Object... args);
 
     public void monitorEnter(Object value) {
@@ -53,7 +57,7 @@
     }
 
     public Object newObject(ResolvedJavaType type) throws InstantiationException {
-        return unsafe.allocateInstance(type.toJava());
+        return unsafe.allocateInstance(getMirror(type));
     }
 
     public Object getFieldObject(Object base, ResolvedJavaField field) {
@@ -286,7 +290,7 @@
             return;
         }
         ResolvedJavaType type = metaProvider.lookupJavaType(array.getClass()).getComponentType();
-        if (!type.toJava().isAssignableFrom(arrayType)) {
+        if (!getMirror(type).isAssignableFrom(arrayType)) {
             throw new ArrayStoreException(arrayType.getName());
         }
     }
@@ -315,10 +319,10 @@
         return ((HotSpotResolvedJavaField) field).offset();
     }
 
-    private static Object resolveBase(Object base, ResolvedJavaField field) {
+    private Object resolveBase(Object base, ResolvedJavaField field) {
         Object accessorBase = base;
         if (accessorBase == null) {
-            accessorBase = field.getDeclaringClass().toJava();
+            accessorBase = getMirror(field.getDeclaringClass());
         }
         return accessorBase;
     }
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java	Tue Nov 27 17:33:52 2012 +0100
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java	Tue Nov 27 18:33:13 2012 +0100
@@ -86,7 +86,7 @@
     }
 
     private static void initMirror(HotSpotTypePrimitive type, long offset) {
-        Class< ? > mirror = type.toJava();
+        Class<?> mirror = type.mirror();
         unsafe.putObject(mirror, offset, type);
         assert unsafe.getObject(mirror, offset) == type;
     }
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotJavaType.java	Tue Nov 27 17:33:52 2012 +0100
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotJavaType.java	Tue Nov 27 18:33:13 2012 +0100
@@ -41,4 +41,6 @@
     public final String getName() {
         return name;
     }
+
+    public abstract Class<?> mirror();
 }
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaField.java	Tue Nov 27 17:33:52 2012 +0100
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaField.java	Tue Nov 27 18:33:13 2012 +0100
@@ -79,7 +79,7 @@
             assert Modifier.isStatic(flags);
             if (constant == null) {
                 if (holder.isInitialized() && !holder.getName().equals(SystemClassName)) {
-                    if (Modifier.isFinal(getModifiers()) || assumeStaticFieldsFinal(holder.toJava())) {
+                    if (Modifier.isFinal(getModifiers()) || assumeStaticFieldsFinal(holder.mirror())) {
                         constant = readValue(receiver);
                     }
                 }
@@ -154,7 +154,7 @@
 
     private Field toJava() {
         try {
-            return holder.toJava().getDeclaredField(name);
+            return holder.mirror().getDeclaredField(name);
         } catch (NoSuchFieldException e) {
             return null;
         }
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaMethod.java	Tue Nov 27 17:33:52 2012 +0100
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaMethod.java	Tue Nov 27 18:33:13 2012 +0100
@@ -258,9 +258,19 @@
         return javaMethod == null ? null : javaMethod.getGenericParameterTypes();
     }
 
+    public Class<?>[] signatureToTypes() {
+        Signature sig = getSignature();
+        int count = sig.getParameterCount(false);
+        Class< ? >[] result = new Class< ? >[count];
+        for (int i = 0; i < result.length; ++i) {
+            result[i] = ((HotSpotJavaType) sig.getParameterType(i, holder).resolve(holder)).mirror();
+        }
+        return result;
+    }
+
     private Method toJava() {
         try {
-            return holder.toJava().getDeclaredMethod(name, MetaUtil.signatureToTypes(getSignature(), holder));
+            return holder.mirror().getDeclaredMethod(name, signatureToTypes());
         } catch (NoSuchMethodException e) {
             return null;
         }
@@ -268,7 +278,7 @@
 
     private Constructor toJavaConstructor() {
         try {
-            return holder.toJava().getDeclaredConstructor(MetaUtil.signatureToTypes(getSignature(), holder));
+            return holder.mirror().getDeclaredConstructor(signatureToTypes());
         } catch (NoSuchMethodException e) {
             return null;
         }
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaType.java	Tue Nov 27 17:33:52 2012 +0100
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaType.java	Tue Nov 27 18:33:13 2012 +0100
@@ -457,6 +457,11 @@
     }
 
     @Override
+    public Class<?> mirror() {
+        return javaMirror;
+    }
+
+    @Override
     public boolean isClass(Class c) {
         return c == javaMirror;
     }
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotRuntime.java	Tue Nov 27 17:33:52 2012 +0100
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotRuntime.java	Tue Nov 27 18:33:13 2012 +0100
@@ -460,7 +460,7 @@
             ValueNode expected = cas.expected();
             if (expected.kind() == Kind.Object && !cas.newValue().objectStamp().alwaysNull()) {
                 ResolvedJavaType type = cas.object().objectStamp().type();
-                if (type != null && !type.isArrayClass() && type.toJava() != Object.class) {
+                if (type != null && !type.isArrayClass() && !type.isClass(Object.class)) {
                     // Use a field write barrier since it's not an array store
                     FieldWriteBarrier writeBarrier = graph.add(new FieldWriteBarrier(cas.object()));
                     graph.addAfterFixed(cas, writeBarrier);
@@ -533,7 +533,7 @@
             if (write.value().kind() == Kind.Object && !write.value().objectStamp().alwaysNull()) {
                 ResolvedJavaType type = object.objectStamp().type();
                 WriteBarrier writeBarrier;
-                if (type != null && !type.isArrayClass() && type.toJava() != Object.class) {
+                if (type != null && !type.isArrayClass() && !type.isClass(Object.class)) {
                     // Use a field write barrier since it's not an array store
                     writeBarrier = graph.add(new FieldWriteBarrier(object));
                 } else {
@@ -600,7 +600,7 @@
         ResolvedJavaType holder = method.getDeclaringClass();
         String fullName = method.getName() + ((HotSpotSignature) method.getSignature()).asString();
         Kind wordKind = graalRuntime.getTarget().wordKind;
-        if (holder.toJava() == Object.class) {
+        if (holder.isClass(Object.class)) {
             if (fullName.equals("getClass()Ljava/lang/Class;")) {
                 ValueNode obj = (ValueNode) parameters.get(0);
                 ObjectStamp stamp = (ObjectStamp) obj.stamp();
@@ -621,7 +621,7 @@
                 hub.setNext(ret);
                 return graph;
             }
-        } else if (holder.toJava() == Class.class) {
+        } else if (holder.isClass(Class.class)) {
             if (fullName.equals("getModifiers()I")) {
                 StructuredGraph graph = new StructuredGraph();
                 LocalNode receiver = graph.unique(new LocalNode(0, StampFactory.objectNonNull()));
@@ -636,7 +636,7 @@
                 klass.setNext(ret);
                 return graph;
             }
-        } else if (holder.toJava() == Thread.class) {
+        } else if (holder.isClass(Thread.class)) {
             if (fullName.equals("currentThread()Ljava/lang/Thread;")) {
                 StructuredGraph graph = new StructuredGraph();
                 ReturnNode ret = graph.add(new ReturnNode(graph.unique(new CurrentThread(config.threadObjectOffset, this))));
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotTypePrimitive.java	Tue Nov 27 17:33:52 2012 +0100
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotTypePrimitive.java	Tue Nov 27 18:33:13 2012 +0100
@@ -187,4 +187,9 @@
     public ResolvedJavaField findFieldWithOffset(long offset) {
         return null;
     }
+
+    @Override
+    public Class<?> mirror() {
+        return javaMirror;
+    }
 }
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotTypeUnresolved.java	Tue Nov 27 17:33:52 2012 +0100
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotTypeUnresolved.java	Tue Nov 27 18:33:13 2012 +0100
@@ -87,4 +87,9 @@
     public ResolvedJavaType resolve(ResolvedJavaType accessingClass) {
         return (ResolvedJavaType) HotSpotGraalRuntime.getInstance().lookupType(getName(), (HotSpotResolvedJavaType) accessingClass, true);
     }
+
+    @Override
+    public Class<?> mirror() {
+        return ((HotSpotJavaType) resolve(null)).mirror();
+    }
 }
--- a/graal/com.oracle.graal.interpreter/src/com/oracle/graal/interpreter/BytecodeInterpreter.java	Tue Nov 27 17:33:52 2012 +0100
+++ b/graal/com.oracle.graal.interpreter/src/com/oracle/graal/interpreter/BytecodeInterpreter.java	Tue Nov 27 18:33:13 2012 +0100
@@ -89,7 +89,7 @@
 
             @Override
             public Object invoke(InterpreterFrame caller, ResolvedJavaMethod method, Object[] arguments) throws Throwable {
-                setBackTrace(caller, (Throwable) arguments[0], createStackTraceElements(caller));
+                setBackTrace(caller, (Throwable) arguments[0], createStackTraceElements(caller, runtimeInterface));
                 return null;
             }
         });
@@ -942,7 +942,7 @@
             setStackTrace(frame, t, elements);
             setBackTrace(frame, t, null);
         } else {
-            setBackTrace(frame, t, createStackTraceElements(frame));
+            setBackTrace(frame, t, createStackTraceElements(frame, runtimeInterface));
         }
     }
 
@@ -973,7 +973,7 @@
                     catchType = resolveType(frame, Bytecodes.INSTANCEOF, (char) handler.catchTypeCPI());
                 }
 
-                if (catchType == null || catchType.toJava().isInstance(t)) {
+                if (catchType == null || catchType.isInstance(Constant.forObject(t))) {
                     // the first found exception handler is our exception handler
                     return handler;
                 }
@@ -982,6 +982,10 @@
         return null;
     }
 
+    private Class<?> mirror(ResolvedJavaType type) {
+        return runtimeInterface.getMirror(type);
+    }
+
     private InterpreterFrame allocateFrame(InterpreterFrame frame, BytecodeStream bs) {
         try {
             InterpreterFrame nextFrame = this.callFrame;
@@ -1000,7 +1004,7 @@
                     traceOp(frame, "Method monitor enter");
                 }
                 if (Modifier.isStatic(nextFrame.getMethod().getModifiers())) {
-                    runtimeInterface.monitorEnter(nextFrame.getMethod().getDeclaringClass().toJava());
+                    runtimeInterface.monitorEnter(mirror(nextFrame.getMethod().getDeclaringClass()));
                 } else {
                     Object enterObject = nextFrame.getObject(frame.resolveLocalIndex(0));
                     assert enterObject != null;
@@ -1022,7 +1026,7 @@
                 traceOp(frame, "Method monitor exit");
             }
             if (Modifier.isStatic(frame.getMethod().getModifiers())) {
-                runtimeInterface.monitorExit(frame.getMethod().getDeclaringClass().toJava());
+                runtimeInterface.monitorExit(mirror(frame.getMethod().getDeclaringClass()));
             } else {
                 Object exitObject = frame.getObject(frame.resolveLocalIndex(0));
                 if (exitObject != null) {
@@ -1181,7 +1185,7 @@
     }
 
     private void checkCast(InterpreterFrame frame, char cpi) {
-        frame.pushObject(resolveType(frame, Bytecodes.CHECKCAST, cpi).toJava().cast(frame.popObject()));
+        frame.pushObject(mirror(resolveType(frame, Bytecodes.CHECKCAST, cpi)).cast(frame.popObject()));
     }
 
     private ResolvedJavaType resolveType(InterpreterFrame frame, int opcode, char cpi) {
@@ -1236,7 +1240,7 @@
                     assert false : "unspecified case";
             }
         } else if (constant instanceof JavaType) {
-            frame.pushObject(((JavaType) constant).resolve(method.getDeclaringClass()).toJava());
+            frame.pushObject(mirror(((JavaType) constant).resolve(method.getDeclaringClass())));
         } else {
             assert false : "unexpected case";
         }
@@ -1387,7 +1391,7 @@
         for (int i = dimension - 1; i >= 0; i--) {
             dimensions[i] = frame.popInt();
         }
-        return Array.newInstance(type.toJava(), dimensions);
+        return Array.newInstance(mirror(type), dimensions);
     }
 
     private ResolvedJavaType getLastDimensionType(ResolvedJavaType type) {
@@ -1400,7 +1404,7 @@
 
     private Object allocateArray(InterpreterFrame frame, char cpi) {
         ResolvedJavaType type = resolveType(frame, Bytecodes.ANEWARRAY, cpi);
-        return Array.newInstance(type.toJava(), frame.popInt());
+        return Array.newInstance(runtimeInterface.getMirror(type), frame.popInt());
     }
 
     private Object allocateNativeArray(InterpreterFrame frame, byte cpi) {
@@ -1613,12 +1617,12 @@
         }
     }
 
-    private static StackTraceElement[] createStackTraceElements(InterpreterFrame frame) {
+    private static StackTraceElement[] createStackTraceElements(InterpreterFrame frame, RuntimeInterpreterInterface runtimeInterface) {
         InterpreterFrame tmp = frame;
         List<StackTraceElement> elements = new ArrayList<>();
         boolean first = false; // filter only first stack elements
         while (tmp != null) {
-            if (first || !filterStackElement(tmp)) {
+            if (first || !filterStackElement(tmp, runtimeInterface)) {
                 first = true;
                 elements.add(tmp.getMethod().asStackTraceElement(tmp.getBCI()));
             }
@@ -1627,8 +1631,8 @@
         return elements.toArray(new StackTraceElement[elements.size()]);
     }
 
-    private static boolean filterStackElement(InterpreterFrame frame) {
-        return Throwable.class.isAssignableFrom(frame.getMethod().getDeclaringClass().toJava());
+    private static boolean filterStackElement(InterpreterFrame frame, RuntimeInterpreterInterface runtimeInterface) {
+        return Throwable.class.isAssignableFrom(runtimeInterface.getMirror(frame.getMethod().getDeclaringClass()));
     }
 
     private ResolvedJavaField findThrowableField(InterpreterFrame frame, String name) {
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/BoxingMethodPool.java	Tue Nov 27 17:33:52 2012 +0100
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/BoxingMethodPool.java	Tue Nov 27 18:33:13 2012 +0100
@@ -148,6 +148,6 @@
         if (boxing == null) {
             return false;
         }
-        return method.getDeclaringClass().toJava() == boxing.type && method.getName().equals(boxing.unboxMethod);
+        return method.getDeclaringClass().isClass(boxing.type) && method.getName().equals(boxing.unboxMethod);
     }
 }
--- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/BoxingEliminationPhase.java	Tue Nov 27 17:33:52 2012 +0100
+++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/BoxingEliminationPhase.java	Tue Nov 27 18:33:13 2012 +0100
@@ -71,7 +71,7 @@
             ObjectStamp stamp = phiNode.objectStamp();
             if (stamp.nonNull() && stamp.isExactType()) {
                 ResolvedJavaType type = stamp.type();
-                if (type != null && type.toJava() == kind.toBoxedJavaClass()) {
+                if (type != null && type.isClass(kind.toBoxedJavaClass())) {
                     StructuredGraph graph = (StructuredGraph) phiNode.graph();
                     result = graph.add(new PhiNode(kind, phiNode.merge()));
                     phiReplacements.put(phiNode, result);
--- a/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/BinaryGraphPrinter.java	Tue Nov 27 17:33:52 2012 +0100
+++ b/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/BinaryGraphPrinter.java	Tue Nov 27 18:33:13 2012 +0100
@@ -214,17 +214,13 @@
             writeByte(POOL_NULL);
             return;
         }
-        if (object instanceof ResolvedJavaType) {
-            writePoolObject(((ResolvedJavaType) object).toJava());
-            return;
-        }
         Integer id = constantPool.get(object);
         if (id == null) {
             addPoolEntry(object);
         } else {
             if (object instanceof Enum<?>) {
                 writeByte(POOL_ENUM);
-            } else if (object instanceof Class<?>) {
+            } else if (object instanceof Class<?> || object instanceof JavaType) {
                 writeByte(POOL_CLASS);
             } else if (object instanceof NodeClass) {
                 writeByte(POOL_NODE_CLASS);
@@ -270,6 +266,11 @@
             writeByte(POOL_ENUM);
             writePoolObject(object.getClass());
             writeInt(((Enum) object).ordinal());
+        } else if (object instanceof JavaType) {
+            JavaType type = (JavaType) object;
+            writeByte(POOL_CLASS);
+            writeString(MetaUtil.toJavaName(type));
+            writeByte(KLASS);
         } else if (object instanceof NodeClass) {
             NodeClass nodeClass = (NodeClass) object;
             writeByte(POOL_NODE_CLASS);
--- a/graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/SnippetIntrinsificationPhase.java	Tue Nov 27 17:33:52 2012 +0100
+++ b/graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/SnippetIntrinsificationPhase.java	Tue Nov 27 18:33:13 2012 +0100
@@ -79,6 +79,15 @@
         }
     }
 
+    public static Class< ? >[] signatureToTypes(Signature signature, ResolvedJavaType accessingClass) {
+        int count = signature.getParameterCount(false);
+        Class< ? >[] result = new Class< ? >[count];
+        for (int i = 0; i < result.length; ++i) {
+            result[i] = signature.getParameterType(i, accessingClass).resolve(accessingClass).toJava();
+        }
+        return result;
+    }
+
     private void tryIntrinsify(Invoke invoke) {
         ResolvedJavaMethod target = invoke.methodCallTarget().targetMethod();
         NodeIntrinsic intrinsic = target.getAnnotation(Node.NodeIntrinsic.class);
@@ -87,7 +96,7 @@
             assert target.getAnnotation(Fold.class) == null;
             assert Modifier.isNative(target.getModifiers()) : "node intrinsic " + target + " should be native";
 
-            Class< ? >[] parameterTypes = MetaUtil.signatureToTypes(target.getSignature(), declaringClass);
+            Class< ? >[] parameterTypes = signatureToTypes(target.getSignature(), declaringClass);
             ResolvedJavaType returnType = target.getSignature().getReturnType(declaringClass).resolve(declaringClass);
 
             // Prepare the arguments for the reflective constructor call on the node class.
@@ -104,7 +113,7 @@
             // Clean up checkcast instructions inserted by javac if the return type is generic.
             cleanUpReturnCheckCast(newInstance);
         } else if (target.getAnnotation(Fold.class) != null) {
-            Class< ? >[] parameterTypes = MetaUtil.signatureToTypes(target.getSignature(), declaringClass);
+            Class< ? >[] parameterTypes = signatureToTypes(target.getSignature(), declaringClass);
 
             // Prepare the arguments for the reflective method call
             Object[] arguments = prepareArguments(invoke, parameterTypes, target, true);