# HG changeset patch # User Christian Haeubl # Date 1329243698 28800 # Node ID f62db40b3b2ef153816895b97fbd2d409343a78f # Parent 33f181ad79d5a3cd9647105fac0e9d3629797d72# Parent 6bcf713a4f419a3dde25c7af8f395b78d52527a9 Merge diff -r 6bcf713a4f41 -r f62db40b3b2e graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalCompiler.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalCompiler.java Tue Feb 14 16:51:06 2012 +0100 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalCompiler.java Tue Feb 14 10:21:38 2012 -0800 @@ -163,7 +163,9 @@ if (GraalOptions.EscapeAnalysis && !plan.isPhaseDisabled(EscapeAnalysisPhase.class)) { new EscapeAnalysisPhase(target, runtime, assumptions, plan).apply(graph); new PhiStampPhase().apply(graph); - new CanonicalizerPhase(target, runtime, assumptions).apply(graph); + if (GraalOptions.OptCanonicalizer) { + new CanonicalizerPhase(target, runtime, assumptions).apply(graph); + } } if (GraalOptions.OptGVN) { diff -r 6bcf713a4f41 -r f62db40b3b2e graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalOptions.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalOptions.java Tue Feb 14 16:51:06 2012 +0100 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalOptions.java Tue Feb 14 10:21:38 2012 -0800 @@ -55,12 +55,13 @@ public static float InliningSizePenaltyExp = 20; public static float MaximumInlineWeight = 1.25f; public static float InliningSizePenalty = 1; - // StaticSizeBasedInliningPolicy (1), DynamicSizeBasedInliningPolicy (2), GreedySizeBasedInlining (3) + // StaticSizeBasedInliningPolicy (1), MinimumCodeSizeBasedInlining (2), + // DynamicSizeBasedInliningPolicy (3), GreedySizeBasedInlining (3) public static int MaximumInlineSize = 35; public static float NestedInliningSizeRatio = 0.9f; public static float BoostInliningForEscapeAnalysis = 2f; + public static int MaximumGreedyInlineSize = 250; public static float ProbabilityCapForInlining = 1f; - public static int MaximumGreedyInlineSize = 250; public static int SmallCompiledCodeSize = 1500; // escape analysis settings diff -r 6bcf713a4f41 -r f62db40b3b2e graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/InliningPhase.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/InliningPhase.java Tue Feb 14 16:51:06 2012 +0100 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/InliningPhase.java Tue Feb 14 10:21:38 2012 -0800 @@ -154,7 +154,9 @@ new DeadCodeEliminationPhase().apply(newGraph); new ComputeProbabilityPhase().apply(newGraph); } - new CanonicalizerPhase(target, runtime, assumptions).apply(newGraph); + if (GraalOptions.OptCanonicalizer) { + new CanonicalizerPhase(target, runtime, assumptions).apply(newGraph); + } return newGraph; } @@ -261,7 +263,9 @@ if (plan != null) { plan.runPhases(PhasePosition.AFTER_PARSING, newGraph); } - new CanonicalizerPhase(target, runtime, assumptions).apply(newGraph); + if (GraalOptions.OptCanonicalizer) { + new CanonicalizerPhase(target, runtime, assumptions).apply(newGraph); + } count = graphComplexity(newGraph); parsedMethods.put(method, count); } else { @@ -276,6 +280,10 @@ @Override public boolean isWorthInlining(StructuredGraph callerGraph, InlineInfo info) { + if (GraalOptions.SmallCompiledCodeSize >= 0 && info.compiledCodeSize() > GraalOptions.SmallCompiledCodeSize) { + return false; + } + double penalty = Math.pow(GraalOptions.InliningSizePenaltyExp, callerGraph.getNodeCount() / (double) GraalOptions.MaximumDesiredSize) / GraalOptions.InliningSizePenaltyExp; if (info.weight > GraalOptions.MaximumInlineWeight / (1 + penalty * GraalOptions.InliningSizePenalty)) { Debug.log("not inlining (cut off by weight): %e", info.weight); @@ -315,13 +323,14 @@ @Override public boolean isWorthInlining(StructuredGraph callerGraph, InlineInfo info) { assert GraalOptions.ProbabilityAnalysis; - if (info.compiledCodeSize() <= GraalOptions.SmallCompiledCodeSize) { - double inlineWeight = Math.min(GraalOptions.ProbabilityCapForInlining, info.invoke.probability()); - double maxSize = Math.pow(GraalOptions.NestedInliningSizeRatio, info.level) * GraalOptions.MaximumInlineSize * inlineWeight; - maxSize = Math.max(GraalOptions.MaximumTrivialSize, maxSize); - return info.weight <= maxSize; + if (GraalOptions.SmallCompiledCodeSize >= 0 && info.compiledCodeSize() > GraalOptions.SmallCompiledCodeSize) { + return false; } - return false; + + double inlineWeight = Math.min(GraalOptions.ProbabilityCapForInlining, info.invoke.probability()); + double maxSize = Math.pow(GraalOptions.NestedInliningSizeRatio, info.level) * GraalOptions.MaximumInlineSize * inlineWeight; + maxSize = Math.max(GraalOptions.MaximumTrivialSize, maxSize); + return info.weight <= maxSize; } } @@ -338,14 +347,15 @@ @Override public boolean isWorthInlining(StructuredGraph callerGraph, InlineInfo info) { assert GraalOptions.ProbabilityAnalysis; - if (info.compiledCodeSize() <= GraalOptions.SmallCompiledCodeSize) { - double inlineBoost = Math.min(GraalOptions.ProbabilityCapForInlining, info.invoke.probability()); - double maxSize = Math.pow(GraalOptions.NestedInliningSizeRatio, info.level) * GraalOptions.MaximumInlineSize; - maxSize = maxSize + maxSize * inlineBoost; - maxSize = Math.max(GraalOptions.MaximumTrivialSize, maxSize); - return info.weight <= maxSize; + if (GraalOptions.SmallCompiledCodeSize >= 0 && info.compiledCodeSize() > GraalOptions.SmallCompiledCodeSize) { + return false; } - return false; + + double inlineBoost = Math.min(GraalOptions.ProbabilityCapForInlining, info.invoke.probability()) + Math.log(Math.max(1, info.invoke.probability() - GraalOptions.ProbabilityCapForInlining + 1)); + double maxSize = Math.pow(GraalOptions.NestedInliningSizeRatio, info.level) * GraalOptions.MaximumInlineSize; + maxSize = maxSize + maxSize * inlineBoost; + maxSize = Math.min(GraalOptions.MaximumGreedyInlineSize, Math.max(GraalOptions.MaximumTrivialSize, maxSize)); + return info.weight <= maxSize; } } @@ -362,13 +372,14 @@ @Override public boolean isWorthInlining(StructuredGraph callerGraph, InlineInfo info) { assert GraalOptions.ProbabilityAnalysis; - if (info.compiledCodeSize() <= GraalOptions.SmallCompiledCodeSize) { - double inlineRatio = Math.min(GraalOptions.ProbabilityCapForInlining, info.invoke.probability()); - double maxSize = Math.pow(GraalOptions.NestedInliningSizeRatio, info.level) * GraalOptions.MaximumGreedyInlineSize * inlineRatio; - maxSize = Math.max(maxSize, GraalOptions.MaximumInlineSize); - return info.weight <= maxSize; + if (GraalOptions.SmallCompiledCodeSize >= 0 && info.compiledCodeSize() > GraalOptions.SmallCompiledCodeSize) { + return false; } - return false; + + double inlineRatio = Math.min(GraalOptions.ProbabilityCapForInlining, info.invoke.probability()); + double maxSize = Math.pow(GraalOptions.NestedInliningSizeRatio, info.level) * GraalOptions.MaximumGreedyInlineSize * inlineRatio; + maxSize = Math.max(maxSize, GraalOptions.MaximumInlineSize); + return info.weight <= maxSize; } } } diff -r 6bcf713a4f41 -r f62db40b3b2e graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/IntrinsificationPhase.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/IntrinsificationPhase.java Tue Feb 14 16:51:06 2012 +0100 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/IntrinsificationPhase.java Tue Feb 14 10:21:38 2012 -0800 @@ -47,22 +47,31 @@ } } - public static void tryIntrinsify(Invoke invoke, GraalRuntime runtime) { + public static boolean canIntrinsify(Invoke invoke, RiResolvedMethod target, GraalRuntime runtime) { + return getIntrinsicGraph(invoke, target, runtime) != null; + } + + private static void tryIntrinsify(Invoke invoke, GraalRuntime runtime) { RiResolvedMethod target = invoke.callTarget().targetMethod(); if (target != null) { tryIntrinsify(invoke, target, runtime); } } - public static void tryIntrinsify(Invoke invoke, RiResolvedMethod target, GraalRuntime runtime) { + private static void tryIntrinsify(Invoke invoke, RiResolvedMethod target, GraalRuntime runtime) { + StructuredGraph intrinsicGraph = getIntrinsicGraph(invoke, target, runtime); + if (intrinsicGraph != null) { + Debug.log(" > Intrinsify %s", target); + InliningUtil.inline(invoke, intrinsicGraph, true); + } + } + + private static StructuredGraph getIntrinsicGraph(Invoke invoke, RiResolvedMethod target, GraalRuntime runtime) { StructuredGraph intrinsicGraph = (StructuredGraph) target.compilerStorage().get(Graph.class); if (intrinsicGraph == null) { // TODO (ph) remove once all intrinsics are available via RiMethod intrinsicGraph = runtime.intrinsicGraph(invoke.stateAfter().method(), invoke.bci(), target, invoke.callTarget().arguments()); } - if (intrinsicGraph != null) { - Debug.log(" > Intrinsify %s", target); - InliningUtil.inline(invoke, intrinsicGraph, true); - } + return intrinsicGraph; } } diff -r 6bcf713a4f41 -r f62db40b3b2e graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/util/InliningUtil.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/util/InliningUtil.java Tue Feb 14 16:51:06 2012 +0100 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/util/InliningUtil.java Tue Feb 14 10:21:38 2012 -0800 @@ -29,6 +29,7 @@ import com.oracle.max.cri.ci.*; import com.oracle.max.cri.ri.*; import com.oracle.max.graal.compiler.*; +import com.oracle.max.graal.compiler.phases.*; import com.oracle.max.graal.cri.*; import com.oracle.max.graal.debug.*; import com.oracle.max.graal.graph.*; @@ -126,6 +127,7 @@ @Override public void inline(StructuredGraph compilerGraph, GraalRuntime runtime, final InliningCallback callback) { StructuredGraph graph = getGraph(concrete, callback); + assert !IntrinsificationPhase.canIntrinsify(invoke, concrete, runtime); InliningUtil.inline(invoke, graph, true); } @@ -179,6 +181,7 @@ Debug.log("inlining 1 method using 1 type check"); StructuredGraph calleeGraph = getGraph(concrete, callback); + assert !IntrinsificationPhase.canIntrinsify(invoke, concrete, runtime); InliningUtil.inline(invoke, calleeGraph, false); } @@ -234,9 +237,9 @@ // receiver null check must be the first node InliningUtil.receiverNullCheck(invoke); if (numberOfMethods > 1 || shouldFallbackToInvoke()) { - inlineMultipleMethods(graph, callback, numberOfMethods, hasReturnValue); + inlineMultipleMethods(graph, runtime, callback, numberOfMethods, hasReturnValue); } else { - inlineSingleMethod(graph, callback); + inlineSingleMethod(graph, runtime, callback); } Debug.log("inlining %d methods with %d type checks and falling back to %s if violated", numberOfMethods, types.length, shouldFallbackToInvoke() ? "invocation" : "deoptimization"); @@ -246,7 +249,7 @@ return notRecordedTypeProbability > 0; } - private void inlineMultipleMethods(StructuredGraph graph, InliningCallback callback, int numberOfMethods, boolean hasReturnValue) { + private void inlineMultipleMethods(StructuredGraph graph, GraalRuntime runtime, InliningCallback callback, int numberOfMethods, boolean hasReturnValue) { FixedNode continuation = invoke.next(); // setup merge and phi nodes for results and exceptions @@ -315,12 +318,14 @@ for (int i = 0; i < calleeEntryNodes.length; i++) { BeginNode node = calleeEntryNodes[i]; Invoke invokeForInlining = (Invoke) node.next(); - StructuredGraph calleeGraph = getGraph(concretes.get(i), callback); + RiResolvedMethod concrete = concretes.get(i); + StructuredGraph calleeGraph = getGraph(concrete, callback); + assert !IntrinsificationPhase.canIntrinsify(invokeForInlining, concrete, runtime); InliningUtil.inline(invokeForInlining, calleeGraph, false); } } - private void inlineSingleMethod(StructuredGraph graph, InliningCallback callback) { + private void inlineSingleMethod(StructuredGraph graph, GraalRuntime runtime, InliningCallback callback) { assert concretes.size() == 1 && types.length > 1 && !shouldFallbackToInvoke() && notRecordedTypeProbability == 0; MergeNode calleeEntryNode = graph.add(new MergeNode()); @@ -335,7 +340,9 @@ pred.setNext(dispatchOnType); calleeEntryNode.setNext(invoke.node()); - StructuredGraph calleeGraph = getGraph(concretes.get(0), callback); + RiResolvedMethod concrete = concretes.get(0); + StructuredGraph calleeGraph = getGraph(concrete, callback); + assert !IntrinsificationPhase.canIntrinsify(invoke, concrete, runtime); InliningUtil.inline(invoke, calleeGraph, false); } diff -r 6bcf713a4f41 -r f62db40b3b2e graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/Node.java --- a/graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/Node.java Tue Feb 14 16:51:06 2012 +0100 +++ b/graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/Node.java Tue Feb 14 10:21:38 2012 -0800 @@ -120,7 +120,7 @@ nodeClass = NodeClass.get(getClass()); } - int id() { + protected int id() { return id; } diff -r 6bcf713a4f41 -r f62db40b3b2e graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/snippets/IntrinsifyArrayCopyPhase.java --- a/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/snippets/IntrinsifyArrayCopyPhase.java Tue Feb 14 16:51:06 2012 +0100 +++ b/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/snippets/IntrinsifyArrayCopyPhase.java Tue Feb 14 10:21:38 2012 -0800 @@ -26,6 +26,7 @@ import com.oracle.max.cri.ci.*; import com.oracle.max.cri.ri.*; +import com.oracle.max.graal.compiler.*; import com.oracle.max.graal.compiler.phases.*; import com.oracle.max.graal.compiler.util.*; import com.oracle.max.graal.cri.*; @@ -122,7 +123,7 @@ InliningUtil.inline(methodCallTarget.invoke(), snippetGraph, false); } } - if (hits) { + if (GraalOptions.OptCanonicalizer && hits) { new CanonicalizerPhase(null, runtime, null).apply(graph); } } diff -r 6bcf713a4f41 -r f62db40b3b2e graal/com.oracle.max.graal.nodes/src/com/oracle/max/graal/nodes/java/IsTypeNode.java diff -r 6bcf713a4f41 -r f62db40b3b2e graal/com.oracle.max.graal.nodes/src/com/oracle/max/graal/nodes/type/StampFactory.java --- a/graal/com.oracle.max.graal.nodes/src/com/oracle/max/graal/nodes/type/StampFactory.java Tue Feb 14 16:51:06 2012 +0100 +++ b/graal/com.oracle.max.graal.nodes/src/com/oracle/max/graal/nodes/type/StampFactory.java Tue Feb 14 10:21:38 2012 -0800 @@ -176,7 +176,9 @@ assert current.kind() == first.kind() : values + " first=" + first + " current=" + current + " first kind=" + first.kind() + " current kind=" + current.kind(); nonNull &= current.nonNull(); declaredType = orTypes(declaredType, current.declaredType()); - exactType = orTypes(exactType, current.exactType()); + if (exactType != current.exactType()) { + exactType = null; + } } if (nonNull != first.nonNull() || declaredType != first.declaredType() || exactType != first.exactType()) { diff -r 6bcf713a4f41 -r f62db40b3b2e graal/com.oracle.max.graal.snippets/src/com/oracle/max/graal/snippets/Snippets.java --- a/graal/com.oracle.max.graal.snippets/src/com/oracle/max/graal/snippets/Snippets.java Tue Feb 14 16:51:06 2012 +0100 +++ b/graal/com.oracle.max.graal.snippets/src/com/oracle/max/graal/snippets/Snippets.java Tue Feb 14 10:21:38 2012 -0800 @@ -27,6 +27,7 @@ import com.oracle.max.cri.ci.*; import com.oracle.max.cri.ri.*; +import com.oracle.max.graal.compiler.*; import com.oracle.max.graal.compiler.phases.*; import com.oracle.max.graal.compiler.util.*; import com.oracle.max.graal.cri.*; @@ -111,7 +112,9 @@ targetGraph = buildSnippetGraph(targetMethod, runtime, target, pool, plan); } InliningUtil.inline(invoke, targetGraph, true); - new CanonicalizerPhase(target, runtime, null).apply(graph); + if (GraalOptions.OptCanonicalizer) { + new CanonicalizerPhase(target, runtime, null).apply(graph); + } } } @@ -119,7 +122,9 @@ Debug.dump(graph, "%s: %s", snippetRiMethod.name(), GraphBuilderPhase.class.getSimpleName()); new DeadCodeEliminationPhase().apply(graph); - new CanonicalizerPhase(target, runtime, null).apply(graph); + if (GraalOptions.OptCanonicalizer) { + new CanonicalizerPhase(target, runtime, null).apply(graph); + } // TODO (gd) remove when we have safepoint polling elimination for (LoopEndNode end : graph.getNodes(LoopEndNode.class)) { diff -r 6bcf713a4f41 -r f62db40b3b2e graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/MonitorTest.java --- a/graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/MonitorTest.java Tue Feb 14 16:51:06 2012 +0100 +++ b/graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/MonitorTest.java Tue Feb 14 10:21:38 2012 -0800 @@ -26,9 +26,10 @@ import java.util.*; -import junit.framework.AssertionFailedError; +import junit.framework.*; -import org.junit.*; +import org.junit.Assert; +import org.junit.Test; import com.oracle.max.graal.compiler.phases.*; import com.oracle.max.graal.graph.*;