# HG changeset patch # User Gilles Duboscq # Date 1392313575 -3600 # Node ID d587baa55dd73a76ae7282e19ac824f2bebb738e # Parent b076b5c13c3f82f3533cd4e5025b3bad560f68bb Add shouldBeInlined method to ResolvedJavaMethod, implement it for HotSpot and use it in the inlining phase diff -r b076b5c13c3f -r d587baa55dd7 graal/com.oracle.graal.api.meta.test/src/com/oracle/graal/api/meta/test/TestResolvedJavaMethod.java --- a/graal/com.oracle.graal.api.meta.test/src/com/oracle/graal/api/meta/test/TestResolvedJavaMethod.java Fri Feb 14 15:09:57 2014 +0100 +++ b/graal/com.oracle.graal.api.meta.test/src/com/oracle/graal/api/meta/test/TestResolvedJavaMethod.java Thu Feb 13 18:46:15 2014 +0100 @@ -290,6 +290,7 @@ "reprofile", "getCompilerStorage", "canBeInlined", + "shouldBeInlined", "getLineNumberTable", "getLocalVariableTable", "isInVirtualMethodTable", diff -r b076b5c13c3f -r d587baa55dd7 graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/ResolvedJavaMethod.java --- a/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/ResolvedJavaMethod.java Fri Feb 14 15:09:57 2014 +0100 +++ b/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/ResolvedJavaMethod.java Thu Feb 13 18:46:15 2014 +0100 @@ -185,6 +185,8 @@ */ boolean canBeInlined(); + boolean shouldBeInlined(); + /** * Returns the LineNumberTable of this method or null if this method does not have a line * numbers table. diff -r b076b5c13c3f -r d587baa55dd7 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVM.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVM.java Fri Feb 14 15:09:57 2014 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVM.java Thu Feb 13 18:46:15 2014 +0100 @@ -54,20 +54,30 @@ boolean hasBalancedMonitors(long metaspaceMethod); /** - * Determines if a given metaspace Method object is compilable. A method may not be compilable - * for a number of reasons such as: + * Determines if a given metaspace Method can be inlined. A method may not be inlinable for a + * number of reasons such as: * * - * A non-compilable method should not be inlined. + * @param metaspaceMethod the metaspace Method object to query + * @return true if the method can be inlined + */ + boolean canInlineMethod(long metaspaceMethod); + + /** + * Determines if a given metaspace Method should be inlined at any cost. This could be because: + * * * @param metaspaceMethod the metaspace Method object to query - * @return true if the method is compilable + * @return true if the method should be inlined */ - boolean isMethodCompilable(long metaspaceMethod); + boolean shouldInlineMethod(long metaspaceMethod); /** * Used to implement {@link ResolvedJavaType#findUniqueConcreteMethod(ResolvedJavaMethod)}. diff -r b076b5c13c3f -r d587baa55dd7 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVMImpl.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVMImpl.java Fri Feb 14 15:09:57 2014 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVMImpl.java Thu Feb 13 18:46:15 2014 +0100 @@ -53,9 +53,6 @@ public native boolean hasBalancedMonitors(long metaspaceMethod); @Override - public native boolean isMethodCompilable(long metaspaceMethod); - - @Override public native long findUniqueConcreteMethod(long metaspaceMethod); @Override @@ -174,4 +171,8 @@ public native int allocateCompileId(HotSpotResolvedJavaMethod method, int entryBCI); public native String getGPUs(); + + public native boolean canInlineMethod(long metaspaceMethod); + + public native boolean shouldInlineMethod(long metaspaceMethod); } diff -r b076b5c13c3f -r d587baa55dd7 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaMethod.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaMethod.java Fri Feb 14 15:09:57 2014 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaMethod.java Thu Feb 13 18:46:15 2014 +0100 @@ -245,27 +245,9 @@ } /** - * Returns true if this method has a ForceInline annotation. - * - * @return true if ForceInline annotation present, false otherwise - */ - public boolean isForceInline() { - return forceInline; - } - - /** - * Returns true if this method has a DontInline annotation. - * - * @return true if DontInline annotation present, false otherwise - */ - public boolean isDontInline() { - return dontInline; - } - - /** * Manually adds a DontInline annotation to this method. */ - public void setDontInline() { + public void setNotInlineable() { dontInline = true; runtime().getCompilerToVM().doNotInlineOrCompile(metaspaceMethod); } @@ -488,7 +470,15 @@ if (dontInline) { return false; } - return runtime().getCompilerToVM().isMethodCompilable(metaspaceMethod); + return runtime().getCompilerToVM().canInlineMethod(metaspaceMethod); + } + + @Override + public boolean shouldBeInlined() { + if (forceInline) { + return true; + } + return runtime().getCompilerToVM().shouldInlineMethod(metaspaceMethod); } @Override diff -r b076b5c13c3f -r d587baa55dd7 graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/InliningPhase.java --- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/InliningPhase.java Fri Feb 14 15:09:57 2014 +0100 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/InliningPhase.java Thu Feb 13 18:46:15 2014 +0100 @@ -428,6 +428,10 @@ return InliningUtil.logInlinedMethod(info, inliningDepth, fullyProcessed, "intrinsic"); } + if (info.shouldInline()) { + return InliningUtil.logInlinedMethod(info, inliningDepth, fullyProcessed, "forced inlining"); + } + double inliningBonus = getInliningBonus(info); int nodes = determineNodeCount(info); int lowLevelGraphSize = previousLowLevelGraphSize(info); diff -r b076b5c13c3f -r d587baa55dd7 graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/InliningUtil.java --- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/InliningUtil.java Fri Feb 14 15:09:57 2014 +0100 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/InliningUtil.java Thu Feb 13 18:46:15 2014 +0100 @@ -295,6 +295,8 @@ * Try to make the call static bindable to avoid interface and virtual method calls. */ void tryToDevirtualizeInvoke(MetaAccessProvider metaAccess, Assumptions assumptions); + + boolean shouldInline(); } public abstract static class AbstractInlineInfo implements InlineInfo { @@ -411,6 +413,10 @@ assert index == 0; this.inlineableElement = inlineableElement; } + + public boolean shouldInline() { + return concrete.shouldBeInlined(); + } } /** @@ -497,6 +503,10 @@ public String toString() { return "type-checked with type " + type.getName() + " and method " + MetaUtil.format("%H.%n(%p):%r", concrete); } + + public boolean shouldInline() { + return concrete.shouldBeInlined(); + } } /** @@ -592,6 +602,15 @@ } } + public boolean shouldInline() { + for (ResolvedJavaMethod method : concretes) { + if (method.shouldBeInlined()) { + return true; + } + } + return false; + } + private boolean hasSingleMethod() { return concretes.size() == 1 && !shouldFallbackToInvoke(); } diff -r b076b5c13c3f -r d587baa55dd7 graal/com.oracle.graal.truffle.hotspot.amd64/src/com/oracle/graal/truffle/hotspot/amd64/AMD64OptimizedCallTargetInstrumentationFactory.java --- a/graal/com.oracle.graal.truffle.hotspot.amd64/src/com/oracle/graal/truffle/hotspot/amd64/AMD64OptimizedCallTargetInstrumentationFactory.java Fri Feb 14 15:09:57 2014 +0100 +++ b/graal/com.oracle.graal.truffle.hotspot.amd64/src/com/oracle/graal/truffle/hotspot/amd64/AMD64OptimizedCallTargetInstrumentationFactory.java Thu Feb 13 18:46:15 2014 +0100 @@ -81,7 +81,7 @@ public void setInstrumentedMethod(ResolvedJavaMethod method) { HotSpotResolvedJavaMethod hsMethod = (HotSpotResolvedJavaMethod) method; - hsMethod.setDontInline(); + hsMethod.setNotInlineable(); } public String getArchitecture() { diff -r b076b5c13c3f -r d587baa55dd7 src/share/vm/graal/graalCompilerToVM.cpp --- a/src/share/vm/graal/graalCompilerToVM.cpp Fri Feb 14 15:09:57 2014 +0100 +++ b/src/share/vm/graal/graalCompilerToVM.cpp Thu Feb 13 18:46:15 2014 +0100 @@ -197,9 +197,14 @@ HotSpotResolvedJavaMethod::set_ignoredBySecurityStackWalk(hotspot_method, method->is_ignored_by_security_stack_walk()); C2V_END -C2V_VMENTRY(jboolean, isMethodCompilable,(JNIEnv *, jobject, jlong metaspace_method)) +C2V_VMENTRY(jboolean, canInlineMethod,(JNIEnv *, jobject, jlong metaspace_method)) methodHandle method = asMethod(metaspace_method); - return !method->is_not_compilable() && !CompilerOracle::should_not_inline(method); + return !method->is_not_compilable() && !CompilerOracle::should_not_inline(method) && !method->dont_inline(); +C2V_END + +C2V_VMENTRY(jboolean, shouldInlineMethod,(JNIEnv *, jobject, jlong metaspace_method)) + methodHandle method = asMethod(metaspace_method); + return CompilerOracle::should_inline(method) || method->force_inline(); C2V_END C2V_ENTRY(jint, getCompiledCodeSize, (JNIEnv *env, jobject, jlong metaspace_method)) @@ -883,7 +888,8 @@ {CC"getStackTraceElement", CC"("METASPACE_METHOD"I)"STACK_TRACE_ELEMENT, FN_PTR(getStackTraceElement)}, {CC"initializeMethod", CC"("METASPACE_METHOD HS_RESOLVED_METHOD")V", FN_PTR(initializeMethod)}, {CC"doNotInlineOrCompile", CC"("METASPACE_METHOD")V", FN_PTR(doNotInlineOrCompile)}, - {CC"isMethodCompilable", CC"("METASPACE_METHOD")Z", FN_PTR(isMethodCompilable)}, + {CC"canInlineMethod", CC"("METASPACE_METHOD")Z", FN_PTR(canInlineMethod)}, + {CC"shouldInlineMethod", CC"("METASPACE_METHOD")Z", FN_PTR(shouldInlineMethod)}, {CC"getCompiledCodeSize", CC"("METASPACE_METHOD")I", FN_PTR(getCompiledCodeSize)}, {CC"lookupType", CC"("STRING CLASS"Z)"METASPACE_KLASS, FN_PTR(lookupType)}, {CC"lookupConstantInPool", CC"("METASPACE_CONSTANT_POOL"I)"OBJECT, FN_PTR(lookupConstantInPool)},