# HG changeset patch # User Doug Simon # Date 1405029399 -7200 # Node ID cac0a7d1c32561109dbca08a665a626f618e6d6b # Parent db92d4a1564aedfa9a9b8545f468cb4b87648519 moved profileToString(ProfilingInfo info, ResolvedJavaMethod method, String sep) from MetaUtil to be a default method in ProfilingInfo diff -r db92d4a1564a -r cac0a7d1c325 graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/DefaultProfilingInfo.java --- a/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/DefaultProfilingInfo.java Thu Jul 10 23:50:09 2014 +0200 +++ b/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/DefaultProfilingInfo.java Thu Jul 10 23:56:39 2014 +0200 @@ -93,7 +93,7 @@ @Override public String toString() { - return "BaseProfilingInfo<" + MetaUtil.profileToString(this, null, "; ") + ">"; + return "BaseProfilingInfo<" + this.toString(null, "; ") + ">"; } public void setMature() { diff -r db92d4a1564a -r cac0a7d1c325 graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/MetaUtil.java --- a/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/MetaUtil.java Thu Jul 10 23:50:09 2014 +0200 +++ b/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/MetaUtil.java Thu Jul 10 23:56:39 2014 +0200 @@ -25,8 +25,6 @@ import java.io.*; import java.util.*; -import com.oracle.graal.api.meta.ProfilingInfo.TriState; - /** * Miscellaneous collection of utility methods used by {@code com.oracle.graal.api.meta} and its * clients. @@ -224,7 +222,7 @@ /** * Convenient shortcut for calling - * {@link #appendLocation(StringBuilder, ResolvedJavaMethod, int)} without having to supply a a + * {@link #appendLocation(StringBuilder, ResolvedJavaMethod, int)} without having to supply a * {@link StringBuilder} instance and convert the result to a string. */ public static String toLocation(ResolvedJavaMethod method, int bci) { @@ -267,71 +265,7 @@ return sb.append(" [bci: ").append(bci).append(']'); } - /** - * Formats some profiling information associated as a string. - * - * @param info the profiling info to format - * @param method an optional method that augments the profile string returned - * @param sep the separator to use for each separate profile record - */ - public static String profileToString(ProfilingInfo info, ResolvedJavaMethod method, String sep) { - StringBuilder buf = new StringBuilder(100); - if (method != null) { - buf.append(String.format("canBeStaticallyBound: %b%s", method.canBeStaticallyBound(), sep)); - } - for (int i = 0; i < info.getCodeSize(); i++) { - if (info.getExecutionCount(i) != -1) { - buf.append(String.format("executionCount@%d: %d%s", i, info.getExecutionCount(i), sep)); - } - - if (info.getBranchTakenProbability(i) != -1) { - buf.append(String.format("branchProbability@%d: %.6f%s", i, info.getBranchTakenProbability(i), sep)); - } - - double[] switchProbabilities = info.getSwitchProbabilities(i); - if (switchProbabilities != null) { - buf.append(String.format("switchProbabilities@%d:", i)); - for (int j = 0; j < switchProbabilities.length; j++) { - buf.append(String.format(" %.6f", switchProbabilities[j])); - } - buf.append(sep); - } - - if (info.getExceptionSeen(i) != TriState.UNKNOWN) { - buf.append(String.format("exceptionSeen@%d: %s%s", i, info.getExceptionSeen(i).name(), sep)); - } - - if (info.getNullSeen(i) != TriState.UNKNOWN) { - buf.append(String.format("nullSeen@%d: %s%s", i, info.getNullSeen(i).name(), sep)); - } - - JavaTypeProfile typeProfile = info.getTypeProfile(i); - appendProfile(buf, typeProfile, i, "types", sep); - - JavaMethodProfile methodProfile = info.getMethodProfile(i); - appendProfile(buf, methodProfile, i, "methods", sep); - } - - boolean firstDeoptReason = true; - for (DeoptimizationReason reason : DeoptimizationReason.values()) { - int count = info.getDeoptimizationCount(reason); - if (count > 0) { - if (firstDeoptReason) { - buf.append("deoptimization history").append(sep); - firstDeoptReason = false; - } - buf.append(String.format(" %s: %d%s", reason.name(), count, sep)); - } - } - if (buf.length() == 0) { - return ""; - } - String s = buf.toString(); - assert s.endsWith(sep); - return s.substring(0, s.length() - sep.length()); - } - - private static void appendProfile(StringBuilder buf, AbstractJavaProfile profile, int bci, String type, String sep) { + static void appendProfile(StringBuilder buf, AbstractJavaProfile profile, int bci, String type, String sep) { if (profile != null) { AbstractProfiledItem[] pitems = profile.getItems(); if (pitems != null) { diff -r db92d4a1564a -r cac0a7d1c325 graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/ProfilingInfo.java --- a/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/ProfilingInfo.java Thu Jul 10 23:50:09 2014 +0200 +++ b/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/ProfilingInfo.java Thu Jul 10 23:56:39 2014 +0200 @@ -50,7 +50,7 @@ /** * Returns an estimate of how often the branch at the given byte code was taken. - * + * * @return The estimated probability, with 0.0 meaning never and 1.0 meaning always, or -1 if * this information is not available. */ @@ -59,7 +59,7 @@ /** * Returns an estimate of how often the switch cases are taken at the given BCI. The default * case is stored as the last entry. - * + * * @return A double value that contains the estimated probabilities, with 0.0 meaning never and * 1.0 meaning always, or -1 if this information is not available. */ @@ -67,21 +67,21 @@ /** * Returns the TypeProfile for the given BCI. - * + * * @return Returns a JavaTypeProfile object, or null if not available. */ JavaTypeProfile getTypeProfile(int bci); /** * Returns the MethodProfile for the given BCI. - * + * * @return Returns a JavaMethodProfile object, or null if not available. */ JavaMethodProfile getMethodProfile(int bci); /** * Returns information if the given BCI did ever throw an exception. - * + * * @return {@link TriState#TRUE} if the instruction has thrown an exception at least once, * {@link TriState#FALSE} if it never threw an exception, and {@link TriState#UNKNOWN} * if this information was not recorded. @@ -91,7 +91,7 @@ /** * Returns information if null was ever seen for the given BCI. This information is collected * for the aastore, checkcast and instanceof bytecodes. - * + * * @return {@link TriState#TRUE} if null was seen for the instruction, {@link TriState#FALSE} if * null was NOT seen, and {@link TriState#UNKNOWN} if this information was not recorded. */ @@ -100,7 +100,7 @@ /** * Returns an estimate how often the current BCI was executed. Avoid comparing execution counts * to each other, as the returned value highly depends on the time of invocation. - * + * * @return the estimated execution count or -1 if not available. */ int getExecutionCount(int bci); @@ -109,7 +109,7 @@ * Returns how frequently a method was deoptimized for the given deoptimization reason. This * only indicates how often the method did fall back to the interpreter for the execution and * does not indicate how often it was recompiled. - * + * * @param reason the reason for which the number of deoptimizations should be queried * @return the number of times the compiled method deoptimized for the given reason. */ @@ -118,7 +118,7 @@ /** * Records the size of the compiler intermediate representation (IR) associated with this * method. - * + * * @param irType the IR type for which the size is being recorded * @param irSize the IR size to be recorded. The unit depends on the IR. * @return whether recording this information for {@code irType} is supported @@ -128,7 +128,7 @@ /** * Gets the size of the compiler intermediate representation (IR) associated with this method * last recorded by {@link #setCompilerIRSize(Class, int)}. - * + * * @param irType the IR type for which the size is being requested * @return the requested IR size or -1 if it is unavailable for {@code irType} */ @@ -136,7 +136,7 @@ /** * Returns true if the profiling information can be assumed as sufficiently accurate. - * + * * @return true if the profiling information was recorded often enough mature enough, false * otherwise. */ @@ -146,4 +146,68 @@ * Force data to be treated as mature if possible. */ void setMature(); + + /** + * Formats this profiling information to a string. + * + * @param method an optional method that augments the profile string returned + * @param sep the separator to use for each separate profile record + */ + default String toString(ResolvedJavaMethod method, String sep) { + StringBuilder buf = new StringBuilder(100); + if (method != null) { + buf.append(String.format("canBeStaticallyBound: %b%s", method.canBeStaticallyBound(), sep)); + } + for (int i = 0; i < getCodeSize(); i++) { + if (getExecutionCount(i) != -1) { + buf.append(String.format("executionCount@%d: %d%s", i, getExecutionCount(i), sep)); + } + + if (getBranchTakenProbability(i) != -1) { + buf.append(String.format("branchProbability@%d: %.6f%s", i, getBranchTakenProbability(i), sep)); + } + + double[] switchProbabilities = getSwitchProbabilities(i); + if (switchProbabilities != null) { + buf.append(String.format("switchProbabilities@%d:", i)); + for (int j = 0; j < switchProbabilities.length; j++) { + buf.append(String.format(" %.6f", switchProbabilities[j])); + } + buf.append(sep); + } + + if (getExceptionSeen(i) != TriState.UNKNOWN) { + buf.append(String.format("exceptionSeen@%d: %s%s", i, getExceptionSeen(i).name(), sep)); + } + + if (getNullSeen(i) != TriState.UNKNOWN) { + buf.append(String.format("nullSeen@%d: %s%s", i, getNullSeen(i).name(), sep)); + } + + JavaTypeProfile typeProfile = getTypeProfile(i); + MetaUtil.appendProfile(buf, typeProfile, i, "types", sep); + + JavaMethodProfile methodProfile = getMethodProfile(i); + MetaUtil.appendProfile(buf, methodProfile, i, "methods", sep); + } + + boolean firstDeoptReason = true; + for (DeoptimizationReason reason : DeoptimizationReason.values()) { + int count = getDeoptimizationCount(reason); + if (count > 0) { + if (firstDeoptReason) { + buf.append("deoptimization history").append(sep); + firstDeoptReason = false; + } + buf.append(String.format(" %s: %d%s", reason.name(), count, sep)); + } + } + if (buf.length() == 0) { + return ""; + } + String s = buf.toString(); + assert s.endsWith(sep); + return s.substring(0, s.length() - sep.length()); + } + } diff -r db92d4a1564a -r cac0a7d1c325 graal/com.oracle.graal.baseline/src/com/oracle/graal/baseline/BaselineBytecodeParser.java --- a/graal/com.oracle.graal.baseline/src/com/oracle/graal/baseline/BaselineBytecodeParser.java Thu Jul 10 23:50:09 2014 +0200 +++ b/graal/com.oracle.graal.baseline/src/com/oracle/graal/baseline/BaselineBytecodeParser.java Thu Jul 10 23:56:39 2014 +0200 @@ -87,7 +87,7 @@ protected void build() { if (PrintProfilingInformation.getValue()) { TTY.println("Profiling info for " + method.format("%H.%n(%p)")); - TTY.println(MetaUtil.indent(MetaUtil.profileToString(profilingInfo, method, CodeUtil.NEW_LINE), " ")); + TTY.println(MetaUtil.indent(profilingInfo.toString(method, CodeUtil.NEW_LINE), " ")); } try (Indent indent = Debug.logAndIndent("build graph for %s", method)) { diff -r db92d4a1564a -r cac0a7d1c325 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotProfilingInfo.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotProfilingInfo.java Thu Jul 10 23:50:09 2014 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotProfilingInfo.java Thu Jul 10 23:56:39 2014 +0200 @@ -199,7 +199,7 @@ @Override public String toString() { - return "HotSpotProfilingInfo<" + MetaUtil.profileToString(this, null, "; ") + ">"; + return "HotSpotProfilingInfo<" + this.toString(null, "; ") + ">"; } @Override diff -r db92d4a1564a -r cac0a7d1c325 graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java --- a/graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java Thu Jul 10 23:50:09 2014 +0200 +++ b/graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java Thu Jul 10 23:56:39 2014 +0200 @@ -214,7 +214,7 @@ protected void build() { if (PrintProfilingInformation.getValue()) { TTY.println("Profiling info for " + method.format("%H.%n(%p)")); - TTY.println(MetaUtil.indent(MetaUtil.profileToString(profilingInfo, method, CodeUtil.NEW_LINE), " ")); + TTY.println(MetaUtil.indent(profilingInfo.toString(method, CodeUtil.NEW_LINE), " ")); } try (Indent indent = Debug.logAndIndent("build graph for %s", method)) {