src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.phases/src/org/graalvm/compiler/phases/verify/VerifyDebugUsage.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File
*** old/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.phases/src/org/graalvm/compiler/phases/verify/VerifyDebugUsage.java	Fri Jul  7 09:31:37 2017
--- new/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.phases/src/org/graalvm/compiler/phases/verify/VerifyDebugUsage.java	Fri Jul  7 09:31:37 2017

*** 20,45 **** --- 20,39 ---- * or visit www.oracle.com if you need additional information or have any * questions. */ package org.graalvm.compiler.phases.verify; ! import static org.graalvm.compiler.debug.DebugContext.BASIC_LEVEL; import static org.graalvm.compiler.debug.Debug.DETAILED_LEVEL; import static org.graalvm.compiler.debug.Debug.ENABLED_LEVEL; import static org.graalvm.compiler.debug.Debug.INFO_LEVEL; import static org.graalvm.compiler.debug.Debug.VERBOSE_LEVEL; import static org.graalvm.compiler.debug.Debug.VERY_DETAILED_LEVEL; import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Set; import org.graalvm.compiler.core.common.type.ObjectStamp; ! import org.graalvm.compiler.debug.DebugContext; import org.graalvm.compiler.debug.DebugMethodMetrics; import org.graalvm.compiler.debug.GraalError; import org.graalvm.compiler.graph.Graph; import org.graalvm.compiler.graph.Node; import org.graalvm.compiler.graph.NodeInputList; import org.graalvm.compiler.nodes.CallTargetNode;
*** 57,76 **** --- 51,71 ---- import jdk.vm.ci.meta.PrimitiveConstant; import jdk.vm.ci.meta.ResolvedJavaMethod; import jdk.vm.ci.meta.ResolvedJavaType; /** ! * Verifies that call sites calling one of the methods in {@link Debug} use them correctly. Correct * usage of the methods in {@link Debug} requires call sites to not eagerly evaluate their ! * arguments. Additionally this phase verifies that no argument is the result of a call to ! * Verifies that call sites calling one of the methods in {@link DebugContext} use them correctly. + * Correct usage of the methods in {@link DebugContext} requires call sites to not eagerly evaluate ! * their arguments. Additionally this phase verifies that no argument is the result of a call to * {@link StringBuilder#toString()} or {@link StringBuffer#toString()}. Ideally the parameters at ! * call sites of {@link DebugContext} are eliminated, and do not produce additional allocations, if ! * {@link Debug#isDumpEnabled(int)} (or {@link Debug#isLogEnabled(int)}, ...) is {@code false}. ! * {@link DebugContext#isDumpEnabled(int)} (or {@link DebugContext#isLogEnabled(int)}, ...) is + * {@code false}. * ! * Methods in {@link DebugContext} checked by this phase are various different versions of ! * {@link DebugContext#log(String)} , {@link DebugContext#dump(int, Object, String)}, ! * {@link DebugContext#logAndIndent(String)} and {@link DebugContext#verify(Object, String)}. */ public class VerifyDebugUsage extends VerifyPhase<PhaseContext> { @Override public boolean checkContract() {
*** 80,93 **** --- 75,87 ---- MetaAccessProvider metaAccess; @Override protected boolean verify(StructuredGraph graph, PhaseContext context) { metaAccess = context.getMetaAccess(); ! ResolvedJavaType debugType = metaAccess.lookupJavaType(DebugContext.class); ResolvedJavaType nodeType = metaAccess.lookupJavaType(Node.class); ResolvedJavaType stringType = metaAccess.lookupJavaType(String.class); ResolvedJavaType debugMethodMetricsType = metaAccess.lookupJavaType(DebugMethodMetrics.class); ResolvedJavaType graalErrorType = metaAccess.lookupJavaType(GraalError.class); for (MethodCallTargetNode t : graph.getNodes(MethodCallTargetNode.TYPE)) { ResolvedJavaMethod callee = t.targetMethod(); String calleeName = callee.getName();
*** 100,114 **** --- 94,103 ---- if (callee.getDeclaringClass().isAssignableFrom(nodeType)) { if (calleeName.equals("assertTrue") || calleeName.equals("assertFalse")) { verifyParameters(t, graph, t.arguments(), stringType, 1); } } if (callee.getDeclaringClass().equals(debugMethodMetricsType)) { if (calleeName.equals("addToMetric") || calleeName.equals("getCurrentMetricValue") || calleeName.equals("incrementMetric")) { verifyParameters(t, graph, t.arguments(), stringType, 1); } } if (callee.getDeclaringClass().isAssignableFrom(graalErrorType) && !graph.method().getDeclaringClass().isAssignableFrom(graalErrorType)) { if (calleeName.equals("guarantee")) { verifyParameters(t, graph, t.arguments(), stringType, 0); } if (calleeName.equals("<init>") && callee.getSignature().getParameterCount(false) == 2) {
*** 135,154 **** --- 124,144 ---- } else { verifyParameters(callerGraph, callTarget, args, stringType, startArgIdx, -1); } } - private static final Set<Integer> DebugLevels = new HashSet<>(Arrays.asList(ENABLED_LEVEL, BASIC_LEVEL, INFO_LEVEL, VERBOSE_LEVEL, DETAILED_LEVEL, VERY_DETAILED_LEVEL)); + Arrays.asList(DebugContext.ENABLED_LEVEL, BASIC_LEVEL, DebugContext.INFO_LEVEL, DebugContext.VERBOSE_LEVEL, DebugContext.DETAILED_LEVEL, DebugContext.VERY_DETAILED_LEVEL)); /** * The set of methods allowed to call a {@code Debug.dump(...)} method with the {@code level} ! * parameter bound to {@link Debug#BASIC_LEVEL} and the {@code object} parameter bound to a ! * {@link StructuredGraph} value. ! * parameter bound to {@link DebugContext#BASIC_LEVEL} and the {@code object} parameter bound to ! * a {@link StructuredGraph} value. * * This whitelist exists to ensure any increase in graph dumps is in line with the policy ! * outlined by {@link Debug#BASIC_LEVEL}. If you add a *justified* graph dump at this level, ! * then update the whitelist. ! * outlined by {@link DebugContext#BASIC_LEVEL}. If you add a *justified* graph dump at this ! * level, then update the whitelist. */ private static final Set<String> BasicLevelStructuredGraphDumpWhitelist = new HashSet<>(Arrays.asList( "org.graalvm.compiler.phases.BasePhase.dumpAfter", "org.graalvm.compiler.phases.BasePhase.dumpBefore", "org.graalvm.compiler.core.GraalCompiler.emitFrontEnd",
*** 159,174 **** --- 149,164 ---- "org.graalvm.compiler.core.test.VerifyDebugUsageTest$InvalidConcatDumpUsagePhase.run", "org.graalvm.compiler.core.test.VerifyDebugUsageTest$InvalidDumpUsagePhase.run")); /** * The set of methods allowed to call a {@code Debug.dump(...)} method with the {@code level} ! * parameter bound to {@link Debug#INFO_LEVEL} and the {@code object} parameter bound to a ! * {@link StructuredGraph} value. ! * parameter bound to {@link DebugContext#INFO_LEVEL} and the {@code object} parameter bound to ! * a {@link StructuredGraph} value. * * This whitelist exists to ensure any increase in graph dumps is in line with the policy ! * outlined by {@link Debug#INFO_LEVEL}. If you add a *justified* graph dump at this level, then ! * update the whitelist. ! * outlined by {@link DebugContext#INFO_LEVEL}. If you add a *justified* graph dump at this ! * level, then update the whitelist. */ private static final Set<String> InfoLevelStructuredGraphDumpWhitelist = new HashSet<>(Arrays.asList( "org.graalvm.compiler.core.GraalCompiler.emitFrontEnd", "org.graalvm.compiler.phases.BasePhase.dumpAfter", "org.graalvm.compiler.replacements.ReplacementsImpl$GraphMaker.makeGraph",
*** 200,216 **** --- 190,206 ---- verifyFormatCall(callerGraph, verifiedCallee, stringType, m, bci, nonVarArgIdx, reportVarArgs ? varArgsElementIndex : -1); } } } ! if (i == 0) { ! if (i == 1) { if (verifiedCallee.getName().equals("dump")) { dumpLevel = verifyDumpLevelParameter(callerGraph, debugCallTarget, verifiedCallee, arg); } ! } else if (i == 1) { ! } else if (i == 2) { if (dumpLevel != null) { - verifyDumpObjectParameter(callerGraph, debugCallTarget, args, verifiedCallee, dumpLevel); } } if (varArgsIndex >= 0 && i >= varArgsIndex) { varArgsElementIndex++; }
*** 231,272 **** --- 221,262 ---- if (c != null) { Integer dumpLevel = ((PrimitiveConstant) c).asInt(); if (!DebugLevels.contains(dumpLevel)) { StackTraceElement e = callerGraph.method().asStackTraceElement(debugCallTarget.invoke().bci()); throw new VerificationError( ! "In %s: parameter 0 of call to %s does not match a Debug.*_LEVEL constant: %s.%n", e, verifiedCallee.format("%H.%n(%p)"), dumpLevel); } return dumpLevel; } StackTraceElement e = callerGraph.method().asStackTraceElement(debugCallTarget.invoke().bci()); throw new VerificationError( ! "In %s: parameter 0 of call to %s must be a constant, not %s.%n", e, verifiedCallee.format("%H.%n(%p)"), arg); } ! protected void verifyDumpObjectParameter(StructuredGraph callerGraph, MethodCallTargetNode debugCallTarget, List<? extends ValueNode> args, ResolvedJavaMethod verifiedCallee, Integer dumpLevel) ! protected void verifyDumpObjectParameter(StructuredGraph callerGraph, MethodCallTargetNode debugCallTarget, ValueNode arg, ResolvedJavaMethod verifiedCallee, Integer dumpLevel) throws org.graalvm.compiler.phases.VerifyPhase.VerificationError { ! ResolvedJavaType arg1Type = ((ObjectStamp) args.get(1).stamp()).type(); ! if (metaAccess.lookupJavaType(Graph.class).isAssignableFrom(arg1Type)) { ! ResolvedJavaType argType = ((ObjectStamp) arg.stamp()).type(); ! if (metaAccess.lookupJavaType(Graph.class).isAssignableFrom(argType)) { verifyStructuredGraphDumping(callerGraph, debugCallTarget, verifiedCallee, dumpLevel); } } /** ! * Verifies that dumping a {@link StructuredGraph} at level {@link DebugContext#BASIC_LEVEL} or ! * {@link DebugContext#INFO_LEVEL} only occurs in white-listed methods. */ protected void verifyStructuredGraphDumping(StructuredGraph callerGraph, MethodCallTargetNode debugCallTarget, ResolvedJavaMethod verifiedCallee, Integer dumpLevel) throws org.graalvm.compiler.phases.VerifyPhase.VerificationError { ! if (dumpLevel == DebugContext.BASIC_LEVEL) { StackTraceElement e = callerGraph.method().asStackTraceElement(debugCallTarget.invoke().bci()); String qualifiedMethod = e.getClassName() + "." + e.getMethodName(); if (!BasicLevelStructuredGraphDumpWhitelist.contains(qualifiedMethod)) { throw new VerificationError( ! "In %s: call to %s with level == DebugContext.BASIC_LEVEL not in %s.BasicLevelDumpWhitelist.%n", e, verifiedCallee.format("%H.%n(%p)"), getClass().getName()); } ! } else if (dumpLevel == DebugContext.INFO_LEVEL) { StackTraceElement e = callerGraph.method().asStackTraceElement(debugCallTarget.invoke().bci()); String qualifiedMethod = e.getClassName() + "." + e.getMethodName(); if (!InfoLevelStructuredGraphDumpWhitelist.contains(qualifiedMethod)) { throw new VerificationError( "In %s: call to %s with level == Debug.INFO_LEVEL not in %s.InfoLevelDumpWhitelist.%n", e, verifiedCallee.format("%H.%n(%p)"),
*** 286,296 **** --- 276,286 ---- throw new VerificationError( "In %s: element %d of parameter %d of call to %s appears to be a String concatenation expression.%n", e, varArgsElementIndex, argIdx, verifiedCallee.format("%H.%n(%p)")); } else { throw new VerificationError( - "In %s: parameter %d of call to %s appears to be a String concatenation expression.%n", e, argIdx, verifiedCallee.format("%H.%n(%p)")); } } } /**

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.phases/src/org/graalvm/compiler/phases/verify/VerifyDebugUsage.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File