annotate graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/phases/OnStackReplacementPhase.java @ 9533:298e47193781

Fix for delayed OSR: we must drop the precise stamps we have on the OSR locals since they may be too precise because of branch pruining in the graph builder.
author Gilles Duboscq <duboscq@ssw.jku.at>
date Fri, 03 May 2013 15:19:08 +0200
parents 8f854c4deabf
children 2eb56f87b01e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6677
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
1 /*
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
4 *
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
7 * published by the Free Software Foundation.
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
8 *
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
13 * accompanied this code).
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
14 *
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
18 *
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
21 * questions.
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
22 */
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
23 package com.oracle.graal.hotspot.phases;
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
24
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
25 import com.oracle.graal.api.code.*;
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
26 import com.oracle.graal.debug.*;
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
27 import com.oracle.graal.graph.*;
9532
8f854c4deabf Delay lowering of the platform specific OSR entry
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 8524
diff changeset
28 import com.oracle.graal.graph.Node.Verbosity;
6677
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
29 import com.oracle.graal.graph.iterators.*;
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
30 import com.oracle.graal.loop.*;
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
31 import com.oracle.graal.nodes.*;
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
32 import com.oracle.graal.nodes.extended.*;
9533
298e47193781 Fix for delayed OSR: we must drop the precise stamps we have on the OSR locals since they may be too precise because of branch pruining in the graph builder.
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 9532
diff changeset
33 import com.oracle.graal.nodes.type.*;
6677
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
34 import com.oracle.graal.nodes.util.*;
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
35 import com.oracle.graal.phases.*;
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
36 import com.oracle.graal.phases.common.*;
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
37
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
38 public class OnStackReplacementPhase extends Phase {
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
39
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
40 @Override
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
41 protected void run(StructuredGraph graph) {
6680
10a3d06d58dc fix for unnecessary BailoutExceptions in OSR
Lukas Stadler <lukas.stadler@jku.at>
parents: 6677
diff changeset
42 if (graph.getEntryBCI() == StructuredGraph.INVOCATION_ENTRY_BCI) {
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7300
diff changeset
43 // This happens during inlining in a OSR method, because the same phase plan will be
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7300
diff changeset
44 // used.
6680
10a3d06d58dc fix for unnecessary BailoutExceptions in OSR
Lukas Stadler <lukas.stadler@jku.at>
parents: 6677
diff changeset
45 return;
10a3d06d58dc fix for unnecessary BailoutExceptions in OSR
Lukas Stadler <lukas.stadler@jku.at>
parents: 6677
diff changeset
46 }
6677
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
47 Debug.dump(graph, "OnStackReplacement initial");
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
48 EntryMarkerNode osr;
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
49 do {
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
50 NodeIterable<EntryMarkerNode> osrNodes = graph.getNodes(EntryMarkerNode.class);
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
51 osr = osrNodes.first();
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
52 if (osr == null) {
8462
149dee7367e0 Bailout from OSR compilation when there is more than on EntryMarkerNode
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7897
diff changeset
53 throw new BailoutException("No OnStackReplacementNode generated");
6677
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
54 }
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
55 if (osrNodes.count() > 1) {
8524
ecb2446232ac Safer bailout for JSR+OSR
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 8462
diff changeset
56 throw new GraalInternalError("Multiple OnStackReplacementNodes generated");
6677
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
57 }
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
58 if (osr.stateAfter().locksSize() != 0) {
8462
149dee7367e0 Bailout from OSR compilation when there is more than on EntryMarkerNode
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7897
diff changeset
59 throw new BailoutException("OSR with locks not supported");
6677
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
60 }
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
61 if (osr.stateAfter().stackSize() != 0) {
8462
149dee7367e0 Bailout from OSR compilation when there is more than on EntryMarkerNode
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7897
diff changeset
62 throw new BailoutException("OSR with stack entries not supported: " + osr.stateAfter().toString(Verbosity.Debugger));
6677
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
63 }
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
64 LoopEx osrLoop = null;
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
65 LoopsData loops = new LoopsData(graph);
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
66 for (LoopEx loop : loops.loops()) {
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
67 if (loop.inside().contains(osr)) {
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
68 osrLoop = loop;
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
69 break;
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
70 }
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
71 }
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
72 if (osrLoop == null) {
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
73 break;
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
74 }
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
75
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
76 LoopTransformations.peel(osrLoop);
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
77 for (Node usage : osr.usages().snapshot()) {
7897
a58851061377 rename ValueProxyNode to ProxyNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 7877
diff changeset
78 ProxyNode proxy = (ProxyNode) usage;
6677
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
79 proxy.replaceAndDelete(proxy.value());
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
80 }
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
81 FixedNode next = osr.next();
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
82 osr.setNext(null);
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
83 ((FixedWithNextNode) osr.predecessor()).setNext(next);
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
84 GraphUtil.killWithUnusedFloatingInputs(osr);
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
85 Debug.dump(graph, "OnStackReplacement loop peeling result");
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
86 } while (true);
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
87
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
88 FrameState osrState = osr.stateAfter();
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
89 osr.setStateAfter(null);
9532
8f854c4deabf Delay lowering of the platform specific OSR entry
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 8524
diff changeset
90 OSRStartNode osrStart = graph.add(new OSRStartNode());
6677
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
91 StartNode start = graph.start();
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
92 FixedNode next = osr.next();
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
93 osr.setNext(null);
9532
8f854c4deabf Delay lowering of the platform specific OSR entry
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 8524
diff changeset
94 osrStart.setNext(next);
8f854c4deabf Delay lowering of the platform specific OSR entry
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 8524
diff changeset
95 graph.setStart(osrStart);
8f854c4deabf Delay lowering of the platform specific OSR entry
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 8524
diff changeset
96 osrStart.setStateAfter(osrState);
6677
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
97
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
98 for (int i = 0; i < osrState.localsSize(); i++) {
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
99 ValueNode value = osrState.localAt(i);
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
100 if (value != null) {
7897
a58851061377 rename ValueProxyNode to ProxyNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 7877
diff changeset
101 ProxyNode proxy = (ProxyNode) value;
9533
298e47193781 Fix for delayed OSR: we must drop the precise stamps we have on the OSR locals since they may be too precise because of branch pruining in the graph builder.
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 9532
diff changeset
102 /*
298e47193781 Fix for delayed OSR: we must drop the precise stamps we have on the OSR locals since they may be too precise because of branch pruining in the graph builder.
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 9532
diff changeset
103 * we need to drop the stamp and go back to the kind since the types we see during
298e47193781 Fix for delayed OSR: we must drop the precise stamps we have on the OSR locals since they may be too precise because of branch pruining in the graph builder.
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 9532
diff changeset
104 * OSR may be too precise (if a branch was not parsed for example).
298e47193781 Fix for delayed OSR: we must drop the precise stamps we have on the OSR locals since they may be too precise because of branch pruining in the graph builder.
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 9532
diff changeset
105 */
298e47193781 Fix for delayed OSR: we must drop the precise stamps we have on the OSR locals since they may be too precise because of branch pruining in the graph builder.
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 9532
diff changeset
106 proxy.replaceAndDelete(graph.unique(new OSRLocalNode(i, StampFactory.forKind(proxy.kind()))));
6677
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
107 }
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
108 }
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
109
9532
8f854c4deabf Delay lowering of the platform specific OSR entry
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 8524
diff changeset
110 GraphUtil.killCFG(start);
6677
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
111
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
112 Debug.dump(graph, "OnStackReplacement result");
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
113 new DeadCodeEliminationPhase().apply(graph);
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
114 }
3dddb311395f hotspot infrastructure for OnStackReplacement
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
115 }