changeset 7157:38b6d0389a90

added @MethodSubstitution to support substitutions for methods such as Object.getClass() where the substitute method cannot have the same name as the original method
author Doug Simon <doug.simon@oracle.com>
date Thu, 13 Dec 2012 14:26:55 +0100
parents 29ee920b35dd
children 7915888f5db5
files graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/ClassSubstitution.java graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/SnippetInstaller.java
diffstat 2 files changed, 23 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/ClassSubstitution.java	Thu Dec 13 14:18:37 2012 +0100
+++ b/graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/ClassSubstitution.java	Thu Dec 13 14:26:55 2012 +0100
@@ -32,4 +32,18 @@
 public @interface ClassSubstitution {
 
     Class<?> value();
+
+    /**
+     * Used to map a substitute method to an original method where the default mapping
+     * of name and signature is not possible due to name clashes with final methods in
+     * {@link Object} or signature types that are not public.
+     */
+    @Retention(RetentionPolicy.RUNTIME)
+    @Target(ElementType.METHOD)
+    public @interface MethodSubstitution {
+        /**
+         * Get the name of the original method.
+         */
+        String value() default "";
+    }
 }
--- a/graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/SnippetInstaller.java	Thu Dec 13 14:18:37 2012 +0100
+++ b/graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/SnippetInstaller.java	Thu Dec 13 14:26:55 2012 +0100
@@ -37,6 +37,7 @@
 import com.oracle.graal.nodes.java.*;
 import com.oracle.graal.phases.*;
 import com.oracle.graal.phases.common.*;
+import com.oracle.graal.snippets.ClassSubstitution.MethodSubstitution;
 import com.oracle.graal.snippets.Snippet.DefaultSnippetInliningPolicy;
 import com.oracle.graal.snippets.Snippet.SnippetInliningPolicy;
 
@@ -105,7 +106,14 @@
                 continue;
             }
             try {
-                Method originalMethod = originalClazz.getDeclaredMethod(method.getName(), method.getParameterTypes());
+                String name = method.getName();
+                MethodSubstitution a = method.getAnnotation(MethodSubstitution.class);
+                if (a != null) {
+                    if (!a.value().equals("")) {
+                        name = a.value();
+                    }
+                }
+                Method originalMethod = originalClazz.getDeclaredMethod(name, method.getParameterTypes());
                 if (!originalMethod.getReturnType().isAssignableFrom(method.getReturnType())) {
                     throw new RuntimeException("Snippet has incompatible return type");
                 }