changeset 21997:5576d06db82a

Fix substitution of CallSite.getTarget when receiver is ambigous; Unittests for all other substitutions which use GraphUtil.originalValue
author Stefan Anzinger <stefan.anzinger@oracle.com>
date Wed, 17 Jun 2015 18:42:35 +0200
parents d333f1cf2c42
children 416e4e9d70fa
files graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/HotSpotMethodSubstitutionTest.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotGraphBuilderPlugins.java
diffstat 2 files changed, 68 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/HotSpotMethodSubstitutionTest.java	Wed Jun 17 16:19:35 2015 +0200
+++ b/graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/HotSpotMethodSubstitutionTest.java	Wed Jun 17 18:42:35 2015 +0200
@@ -22,8 +22,11 @@
  */
 package com.oracle.graal.hotspot.test;
 
+import java.lang.invoke.*;
+
 import org.junit.*;
 
+import com.oracle.graal.api.directives.*;
 import com.oracle.graal.api.replacements.*;
 import com.oracle.graal.replacements.test.*;
 
@@ -150,4 +153,67 @@
 
     private static class TestClassA {
     }
+
+    public static String testCallSiteGetTargetSnippet(int i) throws Exception {
+        ConstantCallSite site;
+        MethodHandles.Lookup lookup = MethodHandles.lookup();
+        switch (i) {
+            case 1:
+                site = GraalDirectives.opaque(new ConstantCallSite(lookup.findVirtual(String.class, "replace", MethodType.methodType(String.class, char.class, char.class))));
+                break;
+            default:
+                site = GraalDirectives.opaque(new ConstantCallSite(lookup.findStatic(java.util.Arrays.class, "asList", MethodType.methodType(java.util.List.class, Object[].class))));
+        }
+        return site.getTarget().toString();
+    }
+
+    public static String testCastSnippet(int i, Object obj) throws Exception {
+        Class<?> c;
+        switch (i) {
+            case 1:
+                c = GraalDirectives.opaque(Number.class);
+                break;
+            default:
+                c = GraalDirectives.opaque(Integer.class);
+                break;
+        }
+        return c.cast(obj).toString();
+    }
+
+    public static String testGetClassSnippet(int i) {
+        Object c;
+        switch (i) {
+            case 1:
+                c = GraalDirectives.opaque(new Object());
+                break;
+            default:
+                c = GraalDirectives.opaque("TEST");
+                break;
+        }
+        return c.getClass().toString();
+    }
+
+    /**
+     * Tests ambiguous receiver of CallSite.getTarget.
+     */
+    @Test
+    public void testCallSiteGetTarget() {
+        test("testCallSiteGetTargetSnippet", 1);
+    }
+
+    /**
+     * Tests ambiguous receiver of Class.cast.
+     */
+    @Test
+    public void testCast() {
+        test("testCastSnippet", 1, new Integer(1));
+    }
+
+    /**
+     * Tests ambiguous receiver of Object.getClass.
+     */
+    @Test
+    public void testGetClass() {
+        test("testGetClassSnippet", 1);
+    }
 }
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotGraphBuilderPlugins.java	Wed Jun 17 16:19:35 2015 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotGraphBuilderPlugins.java	Wed Jun 17 18:42:35 2015 +0200
@@ -145,12 +145,8 @@
     private static void registerCallSitePlugins(InvocationPlugins plugins) {
         InvocationPlugin plugin = new InvocationPlugin() {
             public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
-                ValueNode callSite = GraphUtil.originalValue(receiver.get());
-                if (receiver.get() != null && callSite == null) {
-                    // Original receiver could not be determined, we use the given receiver
-                    callSite = receiver.get();
-                }
-                ValueNode folded = CallSiteTargetNode.tryFold(callSite, b.getMetaAccess(), b.getAssumptions());
+                ValueNode callSite = receiver.get();
+                ValueNode folded = CallSiteTargetNode.tryFold(GraphUtil.originalValue(callSite), b.getMetaAccess(), b.getAssumptions());
                 if (folded != null) {
                     b.addPush(Kind.Object, folded);
                 } else {