changeset 18823:5a21cac1968f

Add utilities ModifiersProvider#isConcrete, ResolvedJavaMethod#hasReceiver, ResolvedJavaMethod#hasBytecodes to Graal API.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Sun, 11 Jan 2015 18:12:51 +0100
parents fad37aaed6d2
children 53d2d5e8462a
files CHANGELOG.md graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/Assumptions.java graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/JavaTypeProfile.java graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/ModifiersProvider.java graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/ResolvedJavaMethod.java graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotNodeLIRBuilder.java graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotNodeLIRBuilder.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaMethodImpl.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedObjectTypeImpl.java graal/com.oracle.graal.nodes.test/src/com/oracle/graal/nodes/test/ObjectStampMeetTest.java graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/LoadMethodNode.java graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/MethodCallTargetNode.java graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/info/TypeGuardInlineInfo.java graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/walker/InliningData.java graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/ReplacementsImpl.java graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/PartialEvaluator.java graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCacheImpl.java
diffstat 17 files changed, 56 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/CHANGELOG.md	Sun Jan 11 17:46:47 2015 +0100
+++ b/CHANGELOG.md	Sun Jan 11 18:12:51 2015 +0100
@@ -5,6 +5,7 @@
 
 ## `tip`
 ### Graal
+* Add utilities ModifiersProvider#isConcrete, ResolvedJavaMethod#hasBytecodes, ResolvedJavaMethod#hasReceiver to Graal API.
 * ...
 
 ### Truffle
--- a/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/Assumptions.java	Sun Jan 11 17:46:47 2015 +0100
+++ b/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/Assumptions.java	Sun Jan 11 18:12:51 2015 +0100
@@ -96,7 +96,7 @@
         public ConcreteSubtype(ResolvedJavaType context, ResolvedJavaType subtype) {
             this.context = context;
             this.subtype = subtype;
-            assert !subtype.isAbstract() : subtype.toString() + " : " + context.toString();
+            assert subtype.isConcrete() : subtype.toString() + " : " + context.toString();
             assert !subtype.isArray() || subtype.getElementalType().isFinal() : subtype.toString() + " : " + context.toString();
         }
 
--- a/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/JavaTypeProfile.java	Sun Jan 11 17:46:47 2015 +0100
+++ b/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/JavaTypeProfile.java	Sun Jan 11 18:12:51 2015 +0100
@@ -150,7 +150,7 @@
 
         public ProfiledType(ResolvedJavaType type, double probability) {
             super(type, probability);
-            assert type.isArray() || !type.isAbstract() : type;
+            assert type.isArray() || type.isConcrete() : type;
         }
 
         /**
--- a/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/ModifiersProvider.java	Sun Jan 11 17:46:47 2015 +0100
+++ b/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/ModifiersProvider.java	Sun Jan 11 18:12:51 2015 +0100
@@ -128,4 +128,13 @@
     default boolean isAbstract() {
         return Modifier.isAbstract(getModifiers());
     }
+
+    /**
+     * Checks that the method is concrete and not abstract.
+     *
+     * @return whether the method is a concrete method
+     */
+    default boolean isConcrete() {
+        return !isAbstract();
+    }
 }
--- a/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/ResolvedJavaMethod.java	Sun Jan 11 17:46:47 2015 +0100
+++ b/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/ResolvedJavaMethod.java	Sun Jan 11 18:12:51 2015 +0100
@@ -173,7 +173,8 @@
     Type[] getGenericParameterTypes();
 
     /**
-     * Returns {@code true} if this method can be inlined.
+     * Returns {@code true} if this method is not excluded from inlining and has associated Java
+     * bytecodes (@see {@link ResolvedJavaMethod#hasBytecodes()}).
      */
     boolean canBeInlined();
 
@@ -269,4 +270,22 @@
         return result;
     }
 
+    /**
+     * Checks whether the method has bytecodes associated with it. Methods without bytecodes are
+     * either abstract or native methods.
+     *
+     * @return whether the definition of this method is Java bytecodes
+     */
+    default boolean hasBytecodes() {
+        return isConcrete() && !isNative();
+    }
+
+    /**
+     * Checks whether the method has a receiver parameter - i.e., whether it is not static.
+     * 
+     * @return whether the method has a receiver parameter
+     */
+    default boolean hasReceiver() {
+        return !isStatic();
+    }
 }
--- a/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotNodeLIRBuilder.java	Sun Jan 11 17:46:47 2015 +0100
+++ b/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotNodeLIRBuilder.java	Sun Jan 11 18:12:51 2015 +0100
@@ -155,7 +155,7 @@
         } else {
             assert invokeKind.isDirect();
             HotSpotResolvedJavaMethod resolvedMethod = (HotSpotResolvedJavaMethod) callTarget.targetMethod();
-            assert !resolvedMethod.isAbstract() : "Cannot make direct call to abstract method.";
+            assert resolvedMethod.isConcrete() : "Cannot make direct call to abstract method.";
             append(new AMD64HotspotDirectStaticCallOp(callTarget.targetMethod(), result, parameters, temps, callState, invokeKind));
         }
     }
--- a/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotNodeLIRBuilder.java	Sun Jan 11 17:46:47 2015 +0100
+++ b/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotNodeLIRBuilder.java	Sun Jan 11 18:12:51 2015 +0100
@@ -104,7 +104,7 @@
         } else {
             assert invokeKind.isDirect();
             HotSpotResolvedJavaMethod resolvedMethod = (HotSpotResolvedJavaMethod) callTarget.targetMethod();
-            assert !resolvedMethod.isAbstract() : "Cannot make direct call to abstract method.";
+            assert resolvedMethod.isConcrete() : "Cannot make direct call to abstract method.";
             append(new SPARCHotspotDirectStaticCallOp(callTarget.targetMethod(), result, parameters, temps, callState, invokeKind));
         }
     }
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaMethodImpl.java	Sun Jan 11 17:46:47 2015 +0100
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaMethodImpl.java	Sun Jan 11 18:12:51 2015 +0100
@@ -187,7 +187,7 @@
 
     @Override
     public boolean canBeStaticallyBound() {
-        return (isFinal() || isPrivate() || isStatic() || holder.isFinal()) && !isAbstract();
+        return (isFinal() || isPrivate() || isStatic() || holder.isFinal()) && isConcrete();
     }
 
     @Override
@@ -547,7 +547,7 @@
         if (isDontInline()) {
             return false;
         }
-        return runtime().getCompilerToVM().canInlineMethod(metaspaceMethod);
+        return this.hasBytecodes() && runtime().getCompilerToVM().canInlineMethod(metaspaceMethod);
     }
 
     @Override
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedObjectTypeImpl.java	Sun Jan 11 17:46:47 2015 +0100
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedObjectTypeImpl.java	Sun Jan 11 18:12:51 2015 +0100
@@ -383,7 +383,7 @@
             return resolveConcreteMethod(method, callerType);
         }
         assert !callerType.isArray();
-        if (!method.isAbstract() && method.getDeclaringClass().equals(this) && method.isPublic()) {
+        if (method.isConcrete() && method.getDeclaringClass().equals(this) && method.isPublic()) {
             return method;
         }
         if (!method.getDeclaringClass().isAssignableFrom(this)) {
--- a/graal/com.oracle.graal.nodes.test/src/com/oracle/graal/nodes/test/ObjectStampMeetTest.java	Sun Jan 11 17:46:47 2015 +0100
+++ b/graal/com.oracle.graal.nodes.test/src/com/oracle/graal/nodes/test/ObjectStampMeetTest.java	Sun Jan 11 18:12:51 2015 +0100
@@ -113,7 +113,7 @@
         for (Class<?> clazz : new Class<?>[]{A.class, B.class, C.class, D.class, E.class, I.class, Object.class}) {
             ResolvedJavaType type = getType(clazz);
             for (Stamp test : new Stamp[]{StampFactory.declared(type), StampFactory.declaredNonNull(type), StampFactory.exact(type), StampFactory.exactNonNull(type)}) {
-                if (!type.isAbstract() || !((ObjectStamp) test).isExactType()) {
+                if (type.isConcrete() || !((ObjectStamp) test).isExactType()) {
                     Assert.assertEquals("meeting illegal and " + test, test, meet(StampFactory.illegal(Kind.Object), test));
                 }
             }
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/LoadMethodNode.java	Sun Jan 11 17:46:47 2015 +0100
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/LoadMethodNode.java	Sun Jan 11 18:12:51 2015 +0100
@@ -54,8 +54,8 @@
         this.receiverType = receiverType;
         this.hub = hub;
         this.method = method;
-        assert !method.isAbstract() : "Cannot load abstract method from a hub";
-        assert !method.isStatic() : "Cannot load a static method from a hub";
+        assert method.isConcrete() : "Cannot load abstract method from a hub";
+        assert method.hasReceiver() : "Cannot load a static method from a hub";
         assert method.isInVirtualMethodTable(receiverType);
     }
 
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/MethodCallTargetNode.java	Sun Jan 11 17:46:47 2015 +0100
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/MethodCallTargetNode.java	Sun Jan 11 18:12:51 2015 +0100
@@ -81,7 +81,7 @@
             assertTrue(n instanceof Invoke, "call target can only be used from an invoke (%s)", n);
         }
         if (invokeKind().isDirect()) {
-            assertFalse(targetMethod().isAbstract(), "special calls or static calls are only allowed for concrete methods (%s)", targetMethod());
+            assertTrue(targetMethod().isConcrete(), "special calls or static calls are only allowed for concrete methods (%s)", targetMethod());
         }
         if (invokeKind() == InvokeKind.Static) {
             assertTrue(targetMethod().isStatic(), "static calls are only allowed for static methods (%s)", targetMethod());
--- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/info/TypeGuardInlineInfo.java	Sun Jan 11 17:46:47 2015 +0100
+++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/info/TypeGuardInlineInfo.java	Sun Jan 11 18:12:51 2015 +0100
@@ -51,7 +51,7 @@
         super(invoke);
         this.concrete = concrete;
         this.type = type;
-        assert type.isArray() || !type.isAbstract() : type;
+        assert type.isArray() || type.isConcrete() : type;
     }
 
     @Override
--- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/walker/InliningData.java	Sun Jan 11 17:46:47 2015 +0100
+++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/walker/InliningData.java	Sun Jan 11 18:12:51 2015 +0100
@@ -239,7 +239,7 @@
             }
 
             ResolvedJavaType type = ptypes[0].getType();
-            assert type.isArray() || !type.isAbstract();
+            assert type.isArray() || type.isConcrete();
             ResolvedJavaMethod concrete = type.resolveConcreteMethod(targetMethod, contextType);
             if (!checkTargetConditions(invoke, concrete)) {
                 return null;
@@ -339,19 +339,19 @@
     }
 
     private InlineInfo getAssumptionInlineInfo(Invoke invoke, ResolvedJavaMethod concrete, Assumptions.Assumption takenAssumption) {
-        assert !concrete.isAbstract();
-        if (!checkTargetConditions(invoke, concrete)) {
-            return null;
+        assert concrete.isConcrete();
+        if (checkTargetConditions(invoke, concrete)) {
+            return new AssumptionInlineInfo(invoke, concrete, takenAssumption);
         }
-        return new AssumptionInlineInfo(invoke, concrete, takenAssumption);
+        return null;
     }
 
     private InlineInfo getExactInlineInfo(Invoke invoke, ResolvedJavaMethod targetMethod) {
-        assert !targetMethod.isAbstract();
-        if (!checkTargetConditions(invoke, targetMethod)) {
-            return null;
+        assert targetMethod.isConcrete();
+        if (checkTargetConditions(invoke, targetMethod)) {
+            return new ExactInlineInfo(invoke, targetMethod);
         }
-        return new ExactInlineInfo(invoke, targetMethod);
+        return null;
     }
 
     private void doInline(CallsiteHolderExplorable callerCallsiteHolder, MethodInvocation calleeInvocation, Assumptions callerAssumptions) {
--- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/ReplacementsImpl.java	Sun Jan 11 17:46:47 2015 +0100
+++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/ReplacementsImpl.java	Sun Jan 11 18:12:51 2015 +0100
@@ -236,7 +236,7 @@
     @Override
     public StructuredGraph getSnippet(ResolvedJavaMethod method, ResolvedJavaMethod recursiveEntry) {
         assert method.getAnnotation(Snippet.class) != null : "Snippet must be annotated with @" + Snippet.class.getSimpleName();
-        assert !method.isAbstract() && !method.isNative() : "Snippet must not be abstract or native";
+        assert method.hasBytecodes() : "Snippet must not be abstract or native";
 
         StructuredGraph graph = UseSnippetGraphCache ? graphs.get(method) : null;
         if (graph == null) {
@@ -643,7 +643,7 @@
 
         private StructuredGraph buildGraph(final ResolvedJavaMethod methodToParse, final SnippetInliningPolicy policy, int inliningDepth) {
             assert inliningDepth < MAX_GRAPH_INLINING_DEPTH : "inlining limit exceeded";
-            assert isInlinable(methodToParse) : methodToParse;
+            assert methodToParse.hasBytecodes() : methodToParse;
             final StructuredGraph graph = buildInitialGraph(methodToParse);
             try (Scope s = Debug.scope("buildGraph", graph)) {
                 Set<MethodCallTargetNode> doNotInline = null;
@@ -657,7 +657,7 @@
                          * Ensure that calls to the original method inside of a substitution ends up
                          * calling it instead of the Graal substitution.
                          */
-                        if (isInlinable(substitutedMethod)) {
+                        if (substitutedMethod.hasBytecodes()) {
                             final StructuredGraph originalGraph = buildInitialGraph(substitutedMethod);
                             Mark mark = graph.getMark();
                             InliningUtil.inline(callTarget.invoke(), originalGraph, true, null);
@@ -715,10 +715,6 @@
         }
     }
 
-    private static boolean isInlinable(final ResolvedJavaMethod method) {
-        return !method.isAbstract() && !method.isNative();
-    }
-
     private static String originalName(Method substituteMethod, String methodSubstitution) {
         if (methodSubstitution.isEmpty()) {
             return substituteMethod.getName();
--- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/PartialEvaluator.java	Sun Jan 11 17:46:47 2015 +0100
+++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/PartialEvaluator.java	Sun Jan 11 18:12:51 2015 +0100
@@ -270,7 +270,7 @@
                         StructuredGraph inlineGraph = replacements.getMethodSubstitution(methodCallTargetNode.targetMethod());
 
                         ResolvedJavaMethod targetMethod = methodCallTargetNode.targetMethod();
-                        if (inlineGraph == null && !targetMethod.isNative() && targetMethod.canBeInlined()) {
+                        if (inlineGraph == null && targetMethod.canBeInlined()) {
                             inlineGraph = parseGraph(methodCallTargetNode.targetMethod(), methodCallTargetNode.arguments(), phaseContext);
                         }
 
--- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCacheImpl.java	Sun Jan 11 17:46:47 2015 +0100
+++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCacheImpl.java	Sun Jan 11 18:12:51 2015 +0100
@@ -330,7 +330,7 @@
     }
 
     protected boolean shouldInline(MethodCallTargetNode methodCallTargetNode) {
-        boolean result = methodCallTargetNode.invokeKind().isDirect() && methodCallTargetNode.targetMethod().canBeInlined() && !methodCallTargetNode.targetMethod().isNative() &&
+        boolean result = methodCallTargetNode.invokeKind().isDirect() && methodCallTargetNode.targetMethod().canBeInlined() &&
                         methodCallTargetNode.targetMethod().getAnnotation(ExplodeLoop.class) == null &&
                         methodCallTargetNode.targetMethod().getAnnotation(CompilerDirectives.TruffleBoundary.class) == null &&
                         !methodCallTargetNode.targetMethod().getDeclaringClass().equals(stringBuilderClass);