changeset 18373:91283d4a1218

Use the base class Executable (introduced in Java 8) to unify the handling of Method and Constructor in MetaAccessProvider
author Christian Wimmer <christian.wimmer@oracle.com>
date Thu, 13 Nov 2014 14:56:04 -0800
parents 18b19a6f9851
children 8971259db8ed
files graal/com.oracle.graal.api.meta.test/src/com/oracle/graal/api/meta/test/MethodUniverse.java graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/MetaAccessProvider.java graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/FinalizableSubclassTest.java graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILHotSpotReplacementsImpl.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompileTheWorld.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotReplacementsImpl.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotMetaAccessProvider.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedObjectTypeImpl.java graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/ReplacementsImpl.java
diffstat 9 files changed, 19 insertions(+), 43 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.api.meta.test/src/com/oracle/graal/api/meta/test/MethodUniverse.java	Thu Nov 13 14:40:12 2014 -0800
+++ b/graal/com.oracle.graal.api.meta.test/src/com/oracle/graal/api/meta/test/MethodUniverse.java	Thu Nov 13 14:56:04 2014 -0800
@@ -42,7 +42,7 @@
                 methods.put(m, method);
             }
             for (Constructor<?> m : c.getDeclaredConstructors()) {
-                constructors.put(m, metaAccess.lookupJavaConstructor(m));
+                constructors.put(m, metaAccess.lookupJavaMethod(m));
             }
         }
     }
--- a/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/MetaAccessProvider.java	Thu Nov 13 14:40:12 2014 -0800
+++ b/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/MetaAccessProvider.java	Thu Nov 13 14:56:04 2014 -0800
@@ -53,14 +53,10 @@
     }
 
     /**
-     * Provides the {@link ResolvedJavaMethod} for a {@link Method} obtained via reflection.
+     * Provides the {@link ResolvedJavaMethod} for a {@link Method} or {@link Constructor} obtained
+     * via reflection.
      */
-    ResolvedJavaMethod lookupJavaMethod(Method reflectionMethod);
-
-    /**
-     * Provides the {@link ResolvedJavaMethod} for a {@link Constructor} obtained via reflection.
-     */
-    ResolvedJavaMethod lookupJavaConstructor(Constructor<?> reflectionConstructor);
+    ResolvedJavaMethod lookupJavaMethod(Executable reflectionMethod);
 
     /**
      * Provides the {@link ResolvedJavaField} for a {@link Field} obtained via reflection.
--- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/FinalizableSubclassTest.java	Thu Nov 13 14:40:12 2014 -0800
+++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/FinalizableSubclassTest.java	Thu Nov 13 14:56:04 2014 -0800
@@ -63,7 +63,7 @@
     private StructuredGraph parseAndProcess(Class<?> cl, Assumptions assumptions) {
         Constructor<?>[] constructors = cl.getConstructors();
         Assert.assertTrue(constructors.length == 1);
-        final ResolvedJavaMethod javaMethod = getMetaAccess().lookupJavaConstructor(constructors[0]);
+        final ResolvedJavaMethod javaMethod = getMetaAccess().lookupJavaMethod(constructors[0]);
         StructuredGraph graph = new StructuredGraph(javaMethod);
 
         GraphBuilderConfiguration conf = GraphBuilderConfiguration.getSnippetDefault();
--- a/graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILHotSpotReplacementsImpl.java	Thu Nov 13 14:40:12 2014 -0800
+++ b/graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILHotSpotReplacementsImpl.java	Thu Nov 13 14:56:04 2014 -0800
@@ -90,7 +90,7 @@
     }
 
     @Override
-    protected ResolvedJavaMethod registerMethodSubstitution(ClassReplacements cr, Member originalMethod, Method substituteMethod) {
+    protected ResolvedJavaMethod registerMethodSubstitution(ClassReplacements cr, Executable originalMethod, Method substituteMethod) {
         // TODO: decide if we want to override this in any way
         return super.registerMethodSubstitution(cr, originalMethod, substituteMethod);
     }
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompileTheWorld.java	Thu Nov 13 14:40:12 2014 -0800
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompileTheWorld.java	Thu Nov 13 14:56:04 2014 -0800
@@ -293,7 +293,7 @@
 
                             // Compile each constructor/method in the class.
                             for (Constructor<?> constructor : javaClass.getDeclaredConstructors()) {
-                                HotSpotResolvedJavaMethod javaMethod = (HotSpotResolvedJavaMethod) metaAccess.lookupJavaConstructor(constructor);
+                                HotSpotResolvedJavaMethod javaMethod = (HotSpotResolvedJavaMethod) metaAccess.lookupJavaMethod(constructor);
                                 if (canBeCompiled(javaMethod, constructor.getModifiers())) {
                                     compileMethod(javaMethod);
                                 }
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotReplacementsImpl.java	Thu Nov 13 14:40:12 2014 -0800
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotReplacementsImpl.java	Thu Nov 13 14:56:04 2014 -0800
@@ -48,7 +48,7 @@
     }
 
     @Override
-    protected ResolvedJavaMethod registerMethodSubstitution(ClassReplacements cr, Member originalMethod, Method substituteMethod) {
+    protected ResolvedJavaMethod registerMethodSubstitution(ClassReplacements cr, Executable originalMethod, Method substituteMethod) {
         final Class<?> substituteClass = substituteMethod.getDeclaringClass();
         if (substituteClass.getDeclaringClass() == BoxingSubstitutions.class) {
             if (config.useHeapProfiler) {
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotMetaAccessProvider.java	Thu Nov 13 14:40:12 2014 -0800
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotMetaAccessProvider.java	Thu Nov 13 14:56:04 2014 -0800
@@ -90,21 +90,11 @@
         }
     }
 
-    public ResolvedJavaMethod lookupJavaMethod(Method reflectionMethod) {
+    public ResolvedJavaMethod lookupJavaMethod(Executable reflectionMethod) {
         try {
             Class<?> holder = reflectionMethod.getDeclaringClass();
-            final int slot = reflectionMethodSlot.getInt(reflectionMethod);
-            final long metaspaceMethod = runtime.getCompilerToVM().getMetaspaceMethod(holder, slot);
-            return HotSpotResolvedJavaMethodImpl.fromMetaspace(metaspaceMethod);
-        } catch (IllegalArgumentException | IllegalAccessException e) {
-            throw new GraalInternalError(e);
-        }
-    }
-
-    public ResolvedJavaMethod lookupJavaConstructor(Constructor<?> reflectionConstructor) {
-        try {
-            Class<?> holder = reflectionConstructor.getDeclaringClass();
-            final int slot = reflectionConstructorSlot.getInt(reflectionConstructor);
+            Field slotField = reflectionMethod instanceof Constructor ? reflectionConstructorSlot : reflectionMethodSlot;
+            final int slot = slotField.getInt(reflectionMethod);
             final long metaspaceMethod = runtime.getCompilerToVM().getMetaspaceMethod(holder, slot);
             return HotSpotResolvedJavaMethodImpl.fromMetaspace(metaspaceMethod);
         } catch (IllegalArgumentException | IllegalAccessException e) {
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedObjectTypeImpl.java	Thu Nov 13 14:40:12 2014 -0800
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedObjectTypeImpl.java	Thu Nov 13 14:56:04 2014 -0800
@@ -833,7 +833,7 @@
         Constructor<?>[] constructors = mirror().getDeclaredConstructors();
         ResolvedJavaMethod[] result = new ResolvedJavaMethod[constructors.length];
         for (int i = 0; i < constructors.length; i++) {
-            result[i] = runtime().getHostProviders().getMetaAccess().lookupJavaConstructor(constructors[i]);
+            result[i] = runtime().getHostProviders().getMetaAccess().lookupJavaMethod(constructors[i]);
             assert result[i].isConstructor();
         }
         return result;
--- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/ReplacementsImpl.java	Thu Nov 13 14:40:12 2014 -0800
+++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/ReplacementsImpl.java	Thu Nov 13 14:56:04 2014 -0800
@@ -114,7 +114,7 @@
                         }
                         String originalName = originalName(substituteMethod, methodSubstitution.value());
                         JavaSignature originalSignature = originalSignature(substituteMethod, methodSubstitution.signature(), methodSubstitution.isStatic());
-                        Member originalMethod = originalMethod(classSubstitution, methodSubstitution.optional(), originalName, originalSignature);
+                        Executable originalMethod = originalMethod(classSubstitution, methodSubstitution.optional(), originalName, originalSignature);
                         if (originalMethod != null && (guard == null || guard.execute())) {
                             ResolvedJavaMethod original = registerMethodSubstitution(this, originalMethod, substituteMethod);
                             if (original != null && methodSubstitution.forced() && shouldIntrinsify(original)) {
@@ -127,7 +127,7 @@
                     if (macroSubstitution != null && (defaultGuard == null || defaultGuard.execute())) {
                         String originalName = originalName(substituteMethod, macroSubstitution.value());
                         JavaSignature originalSignature = originalSignature(substituteMethod, macroSubstitution.signature(), macroSubstitution.isStatic());
-                        Member originalMethod = originalMethod(classSubstitution, macroSubstitution.optional(), originalName, originalSignature);
+                        Executable originalMethod = originalMethod(classSubstitution, macroSubstitution.optional(), originalName, originalSignature);
                         if (originalMethod != null) {
                             ResolvedJavaMethod original = registerMacroSubstitution(this, originalMethod, macroSubstitution.macro());
                             if (original != null && macroSubstitution.forced() && shouldIntrinsify(original)) {
@@ -160,7 +160,7 @@
             return new JavaSignature(returnType, parameters);
         }
 
-        private Member originalMethod(ClassSubstitution classSubstitution, boolean optional, String name, JavaSignature signature) {
+        private Executable originalMethod(ClassSubstitution classSubstitution, boolean optional, String name, JavaSignature signature) {
             Class<?> originalClass = classSubstitution.value();
             if (originalClass == ClassSubstitution.class) {
                 originalClass = resolveClass(classSubstitution.className(), classSubstitution.optional());
@@ -346,15 +346,10 @@
      * @param substituteMethod the substitute method
      * @return the original method
      */
-    protected ResolvedJavaMethod registerMethodSubstitution(ClassReplacements cr, Member originalMember, Method substituteMethod) {
+    protected ResolvedJavaMethod registerMethodSubstitution(ClassReplacements cr, Executable originalMember, Method substituteMethod) {
         MetaAccessProvider metaAccess = providers.getMetaAccess();
         ResolvedJavaMethod substitute = metaAccess.lookupJavaMethod(substituteMethod);
-        ResolvedJavaMethod original;
-        if (originalMember instanceof Method) {
-            original = metaAccess.lookupJavaMethod((Method) originalMember);
-        } else {
-            original = metaAccess.lookupJavaConstructor((Constructor<?>) originalMember);
-        }
+        ResolvedJavaMethod original = metaAccess.lookupJavaMethod(originalMember);
         if (Debug.isLogEnabled()) {
             Debug.log("substitution: %s --> %s", original.format("%H.%n(%p) %r"), substitute.format("%H.%n(%p) %r"));
         }
@@ -370,14 +365,9 @@
      * @param macro the substitute macro node class
      * @return the original method
      */
-    protected ResolvedJavaMethod registerMacroSubstitution(ClassReplacements cr, Member originalMethod, Class<? extends FixedWithNextNode> macro) {
-        ResolvedJavaMethod originalJavaMethod;
+    protected ResolvedJavaMethod registerMacroSubstitution(ClassReplacements cr, Executable originalMethod, Class<? extends FixedWithNextNode> macro) {
         MetaAccessProvider metaAccess = providers.getMetaAccess();
-        if (originalMethod instanceof Method) {
-            originalJavaMethod = metaAccess.lookupJavaMethod((Method) originalMethod);
-        } else {
-            originalJavaMethod = metaAccess.lookupJavaConstructor((Constructor<?>) originalMethod);
-        }
+        ResolvedJavaMethod originalJavaMethod = metaAccess.lookupJavaMethod(originalMethod);
         cr.macroSubstitutions.put(originalJavaMethod, macro);
         return originalJavaMethod;
     }