changeset 18920:4af661af76fd

Restructuring in the GraphBuilder to have less fields in the phase instance.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Wed, 21 Jan 2015 13:10:52 +0100
parents 0061f550ef31
children 13e43d2a413e
files graal/com.oracle.graal.baseline/src/com/oracle/graal/baseline/BaselineBytecodeParser.java graal/com.oracle.graal.baseline/src/com/oracle/graal/baseline/BaselineCompiler.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationTask.java graal/com.oracle.graal.java/src/com/oracle/graal/java/AbstractBytecodeParser.java graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java
diffstat 5 files changed, 38 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.baseline/src/com/oracle/graal/baseline/BaselineBytecodeParser.java	Wed Jan 21 12:01:14 2015 +0100
+++ b/graal/com.oracle.graal.baseline/src/com/oracle/graal/baseline/BaselineBytecodeParser.java	Wed Jan 21 13:10:52 2015 +0100
@@ -72,10 +72,11 @@
     }
 
     public BaselineBytecodeParser(MetaAccessProvider metaAccess, ResolvedJavaMethod method, GraphBuilderConfiguration graphBuilderConfig, OptimisticOptimizations optimisticOpts,
-                    BaselineFrameStateBuilder frameState, int entryBCI, Backend backend) {
+                    BaselineFrameStateBuilder frameState, Backend backend) {
 
-        super(metaAccess, method, graphBuilderConfig, optimisticOpts, frameState, entryBCI);
+        super(metaAccess, method, graphBuilderConfig, optimisticOpts);
         this.backend = backend;
+        this.setCurrentFrameState(frameState);
     }
 
     public LIRGenerationResult getLIRGenerationResult() {
--- a/graal/com.oracle.graal.baseline/src/com/oracle/graal/baseline/BaselineCompiler.java	Wed Jan 21 12:01:14 2015 +0100
+++ b/graal/com.oracle.graal.baseline/src/com/oracle/graal/baseline/BaselineCompiler.java	Wed Jan 21 13:10:52 2015 +0100
@@ -56,7 +56,7 @@
 
         BaselineFrameStateBuilder frameState = new BaselineFrameStateBuilder(method);
 
-        BaselineBytecodeParser parser = new BaselineBytecodeParser(metaAccess, method, graphBuilderConfig, optimisticOpts, frameState, entryBCI, backend);
+        BaselineBytecodeParser parser = new BaselineBytecodeParser(metaAccess, method, graphBuilderConfig, optimisticOpts, frameState, backend);
 
         // build blocks and LIR instructions
         try {
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationTask.java	Wed Jan 21 12:01:14 2015 +0100
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationTask.java	Wed Jan 21 13:10:52 2015 +0100
@@ -58,6 +58,7 @@
 import com.oracle.graal.nodes.*;
 import com.oracle.graal.nodes.spi.*;
 import com.oracle.graal.phases.*;
+import com.oracle.graal.phases.OptimisticOptimizations.Optimization;
 import com.oracle.graal.phases.tiers.*;
 import com.oracle.graal.printer.*;
 
@@ -224,6 +225,11 @@
                     Suites suites = getSuites(providers);
                     ProfilingInfo profilingInfo = getProfilingInfo();
                     OptimisticOptimizations optimisticOpts = getOptimisticOpts(profilingInfo);
+                    if (isOSR) {
+                        // In OSR compiles, we cannot rely on never executed code profiles, because
+                        // all code after the OSR loop is never executed.
+                        optimisticOpts.remove(Optimization.RemoveNeverExecutedCode);
+                    }
                     result = compileGraph(graph, null, cc, method, providers, backend, backend.getTarget(), graphCache, getGraphBuilderSuite(providers), optimisticOpts, profilingInfo,
                                     method.getSpeculationLog(), suites, new CompilationResult(), CompilationResultBuilderFactory.Default);
                 }
--- a/graal/com.oracle.graal.java/src/com/oracle/graal/java/AbstractBytecodeParser.java	Wed Jan 21 12:01:14 2015 +0100
+++ b/graal/com.oracle.graal.java/src/com/oracle/graal/java/AbstractBytecodeParser.java	Wed Jan 21 13:10:52 2015 +0100
@@ -36,7 +36,6 @@
 import com.oracle.graal.compiler.common.calc.*;
 import com.oracle.graal.debug.*;
 import com.oracle.graal.java.BciBlockMapping.BciBlock;
-import com.oracle.graal.nodes.*;
 import com.oracle.graal.options.*;
 import com.oracle.graal.phases.*;
 
@@ -71,23 +70,19 @@
     protected final OptimisticOptimizations optimisticOpts;
     protected final ConstantPool constantPool;
     private final MetaAccessProvider metaAccess;
-    protected final int entryBCI;
 
     /**
      * Meters the number of actual bytecodes parsed.
      */
     public static final DebugMetric BytecodesParsed = Debug.metric("BytecodesParsed");
 
-    public AbstractBytecodeParser(MetaAccessProvider metaAccess, ResolvedJavaMethod method, GraphBuilderConfiguration graphBuilderConfig, OptimisticOptimizations optimisticOpts, F frameState,
-                    int entryBCI) {
-        this.frameState = frameState;
+    public AbstractBytecodeParser(MetaAccessProvider metaAccess, ResolvedJavaMethod method, GraphBuilderConfiguration graphBuilderConfig, OptimisticOptimizations optimisticOpts) {
         this.graphBuilderConfig = graphBuilderConfig;
         this.optimisticOpts = optimisticOpts;
         this.metaAccess = metaAccess;
         this.stream = new BytecodeStream(method.getCode());
         this.profilingInfo = method.getProfilingInfo();
         this.constantPool = method.getConstantPool();
-        this.entryBCI = entryBCI;
         this.method = method;
         assert metaAccess != null;
     }
@@ -884,7 +879,7 @@
     protected abstract T append(T v);
 
     protected boolean isNeverExecutedCode(double probability) {
-        return probability == 0 && optimisticOpts.removeNeverExecutedCode() && entryBCI == StructuredGraph.INVOCATION_ENTRY_BCI;
+        return probability == 0 && optimisticOpts.removeNeverExecutedCode();
     }
 
     protected double branchProbability() {
@@ -895,7 +890,7 @@
             probability = 0.5;
         }
 
-        if (!removeNeverExecutedCode()) {
+        if (!optimisticOpts.removeNeverExecutedCode()) {
             if (probability == 0) {
                 probability = 0.0000001;
             } else if (probability == 1) {
@@ -905,10 +900,6 @@
         return probability;
     }
 
-    protected boolean removeNeverExecutedCode() {
-        return optimisticOpts.removeNeverExecutedCode() && entryBCI == StructuredGraph.INVOCATION_ENTRY_BCI;
-    }
-
     protected abstract void iterateBytecodesForBlock(BciBlock block);
 
     public final void processBytecode(int bci, int opcode) {
--- a/graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java	Wed Jan 21 12:01:14 2015 +0100
+++ b/graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java	Wed Jan 21 13:10:52 2015 +0100
@@ -74,21 +74,12 @@
 
     public static class Instance extends Phase {
 
-        private LineNumberTable lnt;
-        private int previousLineNumber;
-        private int currentLineNumber;
-
         protected StructuredGraph currentGraph;
 
         private final MetaAccessProvider metaAccess;
 
         private ResolvedJavaMethod rootMethod;
 
-        private ValueNode methodSynchronizedObject;
-        private ExceptionDispatchBlock unwindBlock;
-
-        private FixedWithNextNode lastInstr;                 // the last instruction added
-
         private final GraphBuilderConfiguration graphBuilderConfig;
         private final OptimisticOptimizations optimisticOpts;
 
@@ -110,21 +101,15 @@
         protected void run(StructuredGraph graph) {
             ResolvedJavaMethod method = graph.method();
             this.rootMethod = method;
-            if (graphBuilderConfig.insertNonSafepointDebugInfo()) {
-                lnt = method.getLineNumberTable();
-                previousLineNumber = -1;
-            }
             int entryBCI = graph.getEntryBCI();
             assert method.getCode() != null : "method must contain bytecodes: " + method;
-            unwindBlock = null;
-            methodSynchronizedObject = null;
             this.currentGraph = graph;
             HIRFrameStateBuilder frameState = new HIRFrameStateBuilder(method, graph);
             frameState.initializeForMethodStart(graphBuilderConfig.eagerResolving());
             TTY.Filter filter = new TTY.Filter(PrintFilter.getValue(), method);
             try {
-                BytecodeParser parser = new BytecodeParser(metaAccess, method, graphBuilderConfig, optimisticOpts, frameState, entryBCI);
-                parser.build(graph.start());
+                BytecodeParser parser = new BytecodeParser(metaAccess, method, graphBuilderConfig, optimisticOpts, entryBCI);
+                parser.build(0, graph.start(), frameState);
             } finally {
                 filter.remove();
             }
@@ -152,13 +137,30 @@
 
             private BciBlock[] loopHeaders;
             private LocalLiveness liveness;
+            protected final int entryBCI;
+            private int currentDepth;
 
-            public BytecodeParser(MetaAccessProvider metaAccess, ResolvedJavaMethod method, GraphBuilderConfiguration graphBuilderConfig, OptimisticOptimizations optimisticOpts,
-                            HIRFrameStateBuilder frameState, int entryBCI) {
-                super(metaAccess, method, graphBuilderConfig, optimisticOpts, frameState, entryBCI);
+            private LineNumberTable lnt;
+            private int previousLineNumber;
+            private int currentLineNumber;
+
+            private ValueNode methodSynchronizedObject;
+            private ExceptionDispatchBlock unwindBlock;
+
+            private FixedWithNextNode lastInstr;                 // the last instruction added
+
+            public BytecodeParser(MetaAccessProvider metaAccess, ResolvedJavaMethod method, GraphBuilderConfiguration graphBuilderConfig, OptimisticOptimizations optimisticOpts, int entryBCI) {
+                super(metaAccess, method, graphBuilderConfig, optimisticOpts);
+                this.entryBCI = entryBCI;
+
+                if (graphBuilderConfig.insertNonSafepointDebugInfo()) {
+                    lnt = method.getLineNumberTable();
+                    previousLineNumber = -1;
+                }
             }
 
-            protected void build(FixedWithNextNode startInstruction) {
+            protected void build(int depth, FixedWithNextNode startInstruction, HIRFrameStateBuilder startFrameState) {
+                this.currentDepth = depth;
                 if (PrintProfilingInformation.getValue()) {
                     TTY.println("Profiling info for " + method.format("%H.%n(%p)"));
                     TTY.println(MetaUtil.indent(profilingInfo.toString(method, CodeUtil.NEW_LINE), "  "));
@@ -172,6 +174,7 @@
                     liveness = blockMap.liveness;
 
                     lastInstr = startInstruction;
+                    this.setCurrentFrameState(startFrameState);
 
                     if (startInstruction == currentGraph.start()) {
                         StartNode startNode = currentGraph.start();
@@ -1243,7 +1246,7 @@
                     int opcode = stream.currentBC();
                     traceState();
                     traceInstruction(bci, opcode, bci == block.startBci);
-                    if (bci == entryBCI) {
+                    if (currentDepth == 0 && bci == entryBCI) {
                         if (block.getJsrScope() != JsrScope.EMPTY_SCOPE) {
                             throw new BailoutException("OSR into a JSR scope is not supported");
                         }