graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/InliningUtil.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File GRAAL-213 Sdiff graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common

graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/InliningUtil.java

Print this page




  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 package com.oracle.graal.phases.common;
  24 
  25 import java.lang.reflect.*;
  26 import java.util.*;
  27 import java.util.concurrent.*;
  28 
  29 import com.oracle.graal.api.code.*;
  30 import com.oracle.graal.api.code.Assumptions.Assumption;
  31 import com.oracle.graal.api.meta.*;
  32 import com.oracle.graal.api.meta.JavaTypeProfile.ProfiledType;
  33 import com.oracle.graal.api.meta.ResolvedJavaType.Representation;
  34 import com.oracle.graal.debug.*;
  35 import com.oracle.graal.graph.*;

  36 import com.oracle.graal.nodes.*;
  37 import com.oracle.graal.nodes.calc.*;
  38 import com.oracle.graal.nodes.extended.*;
  39 import com.oracle.graal.nodes.java.*;
  40 import com.oracle.graal.nodes.java.MethodCallTargetNode.InvokeKind;
  41 import com.oracle.graal.nodes.spi.*;
  42 import com.oracle.graal.nodes.type.*;
  43 import com.oracle.graal.nodes.util.*;
  44 import com.oracle.graal.phases.*;
  45 
  46 public class InliningUtil {
  47 
  48     private static final DebugMetric metricInliningTailDuplication = Debug.metric("InliningTailDuplication");
  49     private static final String inliningDecisionsScopeString = "InliningDecisions";
  50 
  51     /**
  52      * Meters the size (in bytecodes) of all methods processed during compilation (i.e., top level
  53      * and all inlined methods), irrespective of how many bytecodes in each method are actually
  54      * parsed (which may be none for methods whose IR is retrieved from a cache).
  55      */
  56     public static final DebugMetric InlinedBytecodes = Debug.metric("InlinedBytecodes");
  57 
  58     public interface InliningCallback {
  59 
  60         StructuredGraph buildGraph(final ResolvedJavaMethod method);
  61     }
  62 
  63     public interface InliningPolicy {
  64 
  65         void initialize(StructuredGraph graph);
  66 
  67         boolean continueInlining(StructuredGraph graph);
  68 
  69         InlineInfo next();
  70 
  71         void scanInvokes(Iterable<? extends Node> newNodes);
  72 
  73         boolean isWorthInlining(InlineInfo info);
  74     }
  75 
  76     public static boolean logNotInlinedMethod(InlineInfo info, String msg, Object... args) {








































  77 

  78         logInliningDecision(info, false, msg, args);
  79         return false;
  80     }
  81 
  82     public static void logInliningDecision(InlineInfo info, boolean success, String msg, final Object... args) {

  83         if (shouldLogInliningDecision()) {
  84             logInliningDecision(methodName(info), success, msg, args);
  85         }
  86     }
  87 
  88     public static void logInliningDecision(final String msg, final Object... args) {
  89         Debug.scope(inliningDecisionsScopeString, new Runnable() {
  90 
  91             public void run() {
  92                 Debug.log(msg, args);
  93             }
  94         });
  95     }
  96 
  97     public static boolean logInlinedMethod(InlineInfo info, String string, Object... args) {
  98         logInliningDecision(info, true, string, args);
  99         return true;
 100     }
 101 
 102     private static boolean logNotInlinedMethodAndReturnFalse(Invoke invoke, String msg) {
 103         if (shouldLogInliningDecision()) {
 104             String methodString = invoke.toString() + (invoke.callTarget() == null ? " callTarget=null" : invoke.callTarget().targetName());
 105             logInliningDecision(methodString, false, msg, new Object[0]);
 106         }
 107         return false;
 108     }
 109 
 110     private static InlineInfo logNotInlinedMethodAndReturnNull(Invoke invoke, ResolvedJavaMethod method, String msg) {
 111         return logNotInlinedMethodAndReturnNull(invoke, method, msg, new Object[0]);
 112     }
 113 
 114     private static InlineInfo logNotInlinedMethodAndReturnNull(Invoke invoke, ResolvedJavaMethod method, String msg, Object... args) {

 115         if (shouldLogInliningDecision()) {
 116             String methodString = methodName(method, invoke);
 117             logInliningDecision(methodString, false, msg, args);
 118         }
 119         return null;
 120     }
 121 
 122     private static boolean logNotInlinedMethodAndReturnFalse(Invoke invoke, ResolvedJavaMethod method, String msg) {

 123         if (shouldLogInliningDecision()) {
 124             String methodString = methodName(method, invoke);
 125             logInliningDecision(methodString, false, msg, new Object[0]);
 126         }
 127         return false;
 128     }
 129 
 130     private static void logInliningDecision(final String methodString, final boolean success, final String msg, final Object... args) {
 131         String inliningMsg = "inlining " + methodString + ": " + msg;
 132         if (!success) {
 133             inliningMsg = "not " + inliningMsg;
 134         }
 135         logInliningDecision(inliningMsg, args);
 136     }
 137 
 138     public static boolean shouldLogInliningDecision() {
 139         return Debug.scope(inliningDecisionsScopeString, new Callable<Boolean>() {
 140 
 141             public Boolean call() {
 142                 return Debug.isLogEnabled();




  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 package com.oracle.graal.phases.common;
  24 
  25 import java.lang.reflect.*;
  26 import java.util.*;
  27 import java.util.concurrent.*;
  28 
  29 import com.oracle.graal.api.code.*;
  30 import com.oracle.graal.api.code.Assumptions.Assumption;
  31 import com.oracle.graal.api.meta.*;
  32 import com.oracle.graal.api.meta.JavaTypeProfile.ProfiledType;
  33 import com.oracle.graal.api.meta.ResolvedJavaType.Representation;
  34 import com.oracle.graal.debug.*;
  35 import com.oracle.graal.graph.*;
  36 import com.oracle.graal.hotspot.HotSpotGraalRuntime;
  37 import com.oracle.graal.nodes.*;
  38 import com.oracle.graal.nodes.calc.*;
  39 import com.oracle.graal.nodes.extended.*;
  40 import com.oracle.graal.nodes.java.*;
  41 import com.oracle.graal.nodes.java.MethodCallTargetNode.InvokeKind;
  42 import com.oracle.graal.nodes.spi.*;
  43 import com.oracle.graal.nodes.type.*;
  44 import com.oracle.graal.nodes.util.*;
  45 import com.oracle.graal.phases.*;
  46 
  47 public class InliningUtil {
  48 
  49     private static final DebugMetric metricInliningTailDuplication = Debug.metric("InliningTailDuplication");
  50     private static final String inliningDecisionsScopeString = "InliningDecisions";
  51 
  52     /**
  53      * Meters the size (in bytecodes) of all methods processed during compilation (i.e., top level
  54      * and all inlined methods), irrespective of how many bytecodes in each method are actually
  55      * parsed (which may be none for methods whose IR is retrieved from a cache).
  56      */
  57     public static final DebugMetric InlinedBytecodes = Debug.metric("InlinedBytecodes");
  58 
  59     public interface InliningCallback {
  60 
  61         StructuredGraph buildGraph(final ResolvedJavaMethod method);
  62     }
  63 
  64     public interface InliningPolicy {
  65 
  66         void initialize(StructuredGraph graph);
  67 
  68         boolean continueInlining(StructuredGraph graph);
  69 
  70         InlineInfo next();
  71 
  72         void scanInvokes(Iterable<? extends Node> newNodes);
  73 
  74         boolean isWorthInlining(InlineInfo info);
  75     }
  76 
  77     /**
  78      * Print a HotSpot-style inlining message to the console.
  79      */
  80     private static void printInlining(final InlineInfo info, final boolean success, final String msg, final Object... args) {
  81         printInlining(info.methodAt(0), info.invoke(), success, msg, args);
  82     }
  83 
  84     /**
  85      * Print a HotSpot-style inlining message to the console.
  86      */
  87     private static void printInlining(final ResolvedJavaMethod method, final Invoke invoke, final boolean success, final String msg, final Object... args) {
  88         if (GraalOptions.HotSpotPrintInlining) {
  89             final int mod = method.getModifiers();
  90             //         1234567
  91             TTY.print("        ");     // print timestamp
  92             //         1234
  93             TTY.print("     ");        // print compilation number
  94             //          % s ! b n
  95             TTY.print("%c%c%c%c%c ",
  96                     ' ',
  97                     Modifier.isSynchronized(mod) ? 's' : ' ',
  98                     ' ',
  99                     ' ',
 100                     Modifier.isNative(mod) ? 'n' : ' ');
 101             TTY.print("     ");        // more indent
 102             TTY.print("    ");         // initial inlining indent
 103             final int level = computeInliningLevel(invoke);
 104             for (int i = 0; i < level; i++) {
 105                 TTY.print("  ");
 106             }
 107             TTY.println(String.format("@ %d  %s   %s%s",
 108                     invoke.bci(), methodName(method, null),
 109                     success ? "" : "not inlining ",
 110                     String.format(msg, args)));
 111         }
 112     }
 113 
 114     public static boolean logInlinedMethod(InlineInfo info, String msg, Object... args) {
 115         logInliningDecision(info, true, msg, args);
 116         return true;
 117     }
 118 
 119     public static boolean logNotInlinedMethod(InlineInfo info, String msg, Object... args) {
 120         logInliningDecision(info, false, msg, args);
 121         return false;
 122     }
 123 
 124     public static void logInliningDecision(InlineInfo info, boolean success, String msg, final Object... args) {
 125         printInlining(info, success, msg, args);
 126         if (shouldLogInliningDecision()) {
 127             logInliningDecision(methodName(info), success, msg, args);
 128         }
 129     }
 130 
 131     public static void logInliningDecision(final String msg, final Object... args) {
 132         Debug.scope(inliningDecisionsScopeString, new Runnable() {
 133 
 134             public void run() {
 135                 Debug.log(msg, args);
 136             }
 137         });
 138     }
 139 





 140     private static boolean logNotInlinedMethodAndReturnFalse(Invoke invoke, String msg) {
 141         if (shouldLogInliningDecision()) {
 142             String methodString = invoke.toString() + (invoke.callTarget() == null ? " callTarget=null" : invoke.callTarget().targetName());
 143             logInliningDecision(methodString, false, msg, new Object[0]);
 144         }
 145         return false;
 146     }
 147 
 148     private static InlineInfo logNotInlinedMethodAndReturnNull(Invoke invoke, ResolvedJavaMethod method, String msg) {
 149         return logNotInlinedMethodAndReturnNull(invoke, method, msg, new Object[0]);
 150     }
 151 
 152     private static InlineInfo logNotInlinedMethodAndReturnNull(Invoke invoke, ResolvedJavaMethod method, String msg, Object... args) {
 153         printInlining(method, invoke, false, msg, args);
 154         if (shouldLogInliningDecision()) {
 155             String methodString = methodName(method, invoke);
 156             logInliningDecision(methodString, false, msg, args);
 157         }
 158         return null;
 159     }
 160 
 161     private static boolean logNotInlinedMethodAndReturnFalse(Invoke invoke, ResolvedJavaMethod method, String msg) {
 162         printInlining(method, invoke, false, msg, new Object[0]);
 163         if (shouldLogInliningDecision()) {
 164             String methodString = methodName(method, invoke);
 165             logInliningDecision(methodString, false, msg, new Object[0]);
 166         }
 167         return false;
 168     }
 169 
 170     private static void logInliningDecision(final String methodString, final boolean success, final String msg, final Object... args) {
 171         String inliningMsg = "inlining " + methodString + ": " + msg;
 172         if (!success) {
 173             inliningMsg = "not " + inliningMsg;
 174         }
 175         logInliningDecision(inliningMsg, args);
 176     }
 177 
 178     public static boolean shouldLogInliningDecision() {
 179         return Debug.scope(inliningDecisionsScopeString, new Callable<Boolean>() {
 180 
 181             public Boolean call() {
 182                 return Debug.isLogEnabled();


graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/InliningUtil.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File