# HG changeset patch # User Doug Simon # Date 1355405215 -3600 # Node ID 38b6d0389a9058a8211bb7635212323229605108 # Parent 29ee920b35ddbd12438cec24291e33bb426d908c added @MethodSubstitution to support substitutions for methods such as Object.getClass() where the substitute method cannot have the same name as the original method diff -r 29ee920b35dd -r 38b6d0389a90 graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/ClassSubstitution.java --- 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 ""; + } } diff -r 29ee920b35dd -r 38b6d0389a90 graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/SnippetInstaller.java --- 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"); }