annotate src/share/vm/opto/buildOopMap.cpp @ 17524:89152779163c

Merge with jdk8-b132
author Gilles Duboscq <duboscq@ssw.jku.at>
date Wed, 15 Oct 2014 11:59:32 +0200
parents 4ca6dc0799b6
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
17524
89152779163c Merge with jdk8-b132
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 14909
diff changeset
2 * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 844
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 844
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 844
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
25 #include "precompiled.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
26 #include "compiler/oopMap.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
27 #include "opto/addnode.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
28 #include "opto/callnode.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
29 #include "opto/compile.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
30 #include "opto/machnode.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
31 #include "opto/matcher.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
32 #include "opto/phase.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
33 #include "opto/regalloc.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
34 #include "opto/rootnode.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
35 #ifdef TARGET_ARCH_x86
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
36 # include "vmreg_x86.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
37 #endif
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
38 #ifdef TARGET_ARCH_sparc
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
39 # include "vmreg_sparc.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
40 #endif
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
41 #ifdef TARGET_ARCH_zero
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
42 # include "vmreg_zero.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
43 #endif
2192
b92c45f2bc75 7016023: Enable building ARM and PPC from src/closed repository
bobv
parents: 1972
diff changeset
44 #ifdef TARGET_ARCH_arm
b92c45f2bc75 7016023: Enable building ARM and PPC from src/closed repository
bobv
parents: 1972
diff changeset
45 # include "vmreg_arm.inline.hpp"
b92c45f2bc75 7016023: Enable building ARM and PPC from src/closed repository
bobv
parents: 1972
diff changeset
46 #endif
b92c45f2bc75 7016023: Enable building ARM and PPC from src/closed repository
bobv
parents: 1972
diff changeset
47 #ifdef TARGET_ARCH_ppc
b92c45f2bc75 7016023: Enable building ARM and PPC from src/closed repository
bobv
parents: 1972
diff changeset
48 # include "vmreg_ppc.inline.hpp"
b92c45f2bc75 7016023: Enable building ARM and PPC from src/closed repository
bobv
parents: 1972
diff changeset
49 #endif
0
a61af66fc99e Initial load
duke
parents:
diff changeset
50
a61af66fc99e Initial load
duke
parents:
diff changeset
51 // The functions in this file builds OopMaps after all scheduling is done.
a61af66fc99e Initial load
duke
parents:
diff changeset
52 //
a61af66fc99e Initial load
duke
parents:
diff changeset
53 // OopMaps contain a list of all registers and stack-slots containing oops (so
a61af66fc99e Initial load
duke
parents:
diff changeset
54 // they can be updated by GC). OopMaps also contain a list of derived-pointer
a61af66fc99e Initial load
duke
parents:
diff changeset
55 // base-pointer pairs. When the base is moved, the derived pointer moves to
a61af66fc99e Initial load
duke
parents:
diff changeset
56 // follow it. Finally, any registers holding callee-save values are also
a61af66fc99e Initial load
duke
parents:
diff changeset
57 // recorded. These might contain oops, but only the caller knows.
a61af66fc99e Initial load
duke
parents:
diff changeset
58 //
a61af66fc99e Initial load
duke
parents:
diff changeset
59 // BuildOopMaps implements a simple forward reaching-defs solution. At each
a61af66fc99e Initial load
duke
parents:
diff changeset
60 // GC point we'll have the reaching-def Nodes. If the reaching Nodes are
a61af66fc99e Initial load
duke
parents:
diff changeset
61 // typed as pointers (no offset), then they are oops. Pointers+offsets are
a61af66fc99e Initial load
duke
parents:
diff changeset
62 // derived pointers, and bases can be found from them. Finally, we'll also
a61af66fc99e Initial load
duke
parents:
diff changeset
63 // track reaching callee-save values. Note that a copy of a callee-save value
a61af66fc99e Initial load
duke
parents:
diff changeset
64 // "kills" it's source, so that only 1 copy of a callee-save value is alive at
a61af66fc99e Initial load
duke
parents:
diff changeset
65 // a time.
a61af66fc99e Initial load
duke
parents:
diff changeset
66 //
a61af66fc99e Initial load
duke
parents:
diff changeset
67 // We run a simple bitvector liveness pass to help trim out dead oops. Due to
a61af66fc99e Initial load
duke
parents:
diff changeset
68 // irreducible loops, we can have a reaching def of an oop that only reaches
a61af66fc99e Initial load
duke
parents:
diff changeset
69 // along one path and no way to know if it's valid or not on the other path.
a61af66fc99e Initial load
duke
parents:
diff changeset
70 // The bitvectors are quite dense and the liveness pass is fast.
a61af66fc99e Initial load
duke
parents:
diff changeset
71 //
a61af66fc99e Initial load
duke
parents:
diff changeset
72 // At GC points, we consult this information to build OopMaps. All reaching
a61af66fc99e Initial load
duke
parents:
diff changeset
73 // defs typed as oops are added to the OopMap. Only 1 instance of a
a61af66fc99e Initial load
duke
parents:
diff changeset
74 // callee-save register can be recorded. For derived pointers, we'll have to
a61af66fc99e Initial load
duke
parents:
diff changeset
75 // find and record the register holding the base.
a61af66fc99e Initial load
duke
parents:
diff changeset
76 //
a61af66fc99e Initial load
duke
parents:
diff changeset
77 // The reaching def's is a simple 1-pass worklist approach. I tried a clever
a61af66fc99e Initial load
duke
parents:
diff changeset
78 // breadth-first approach but it was worse (showed O(n^2) in the
a61af66fc99e Initial load
duke
parents:
diff changeset
79 // pick-next-block code).
a61af66fc99e Initial load
duke
parents:
diff changeset
80 //
605
98cb887364d3 6810672: Comment typos
twisti
parents: 196
diff changeset
81 // The relevant data is kept in a struct of arrays (it could just as well be
0
a61af66fc99e Initial load
duke
parents:
diff changeset
82 // an array of structs, but the struct-of-arrays is generally a little more
a61af66fc99e Initial load
duke
parents:
diff changeset
83 // efficient). The arrays are indexed by register number (including
a61af66fc99e Initial load
duke
parents:
diff changeset
84 // stack-slots as registers) and so is bounded by 200 to 300 elements in
a61af66fc99e Initial load
duke
parents:
diff changeset
85 // practice. One array will map to a reaching def Node (or NULL for
a61af66fc99e Initial load
duke
parents:
diff changeset
86 // conflict/dead). The other array will map to a callee-saved register or
a61af66fc99e Initial load
duke
parents:
diff changeset
87 // OptoReg::Bad for not-callee-saved.
a61af66fc99e Initial load
duke
parents:
diff changeset
88
a61af66fc99e Initial load
duke
parents:
diff changeset
89
a61af66fc99e Initial load
duke
parents:
diff changeset
90 // Structure to pass around
a61af66fc99e Initial load
duke
parents:
diff changeset
91 struct OopFlow : public ResourceObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
92 short *_callees; // Array mapping register to callee-saved
a61af66fc99e Initial load
duke
parents:
diff changeset
93 Node **_defs; // array mapping register to reaching def
a61af66fc99e Initial load
duke
parents:
diff changeset
94 // or NULL if dead/conflict
a61af66fc99e Initial load
duke
parents:
diff changeset
95 // OopFlow structs, when not being actively modified, describe the _end_ of
a61af66fc99e Initial load
duke
parents:
diff changeset
96 // this block.
a61af66fc99e Initial load
duke
parents:
diff changeset
97 Block *_b; // Block for this struct
a61af66fc99e Initial load
duke
parents:
diff changeset
98 OopFlow *_next; // Next free OopFlow
833
acba6af809c8 6840775: Multiple JVM crashes seen with 1.6.0_10 through 1.6.0_14
kvn
parents: 729
diff changeset
99 // or NULL if dead/conflict
acba6af809c8 6840775: Multiple JVM crashes seen with 1.6.0_10 through 1.6.0_14
kvn
parents: 729
diff changeset
100 Compile* C;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
101
833
acba6af809c8 6840775: Multiple JVM crashes seen with 1.6.0_10 through 1.6.0_14
kvn
parents: 729
diff changeset
102 OopFlow( short *callees, Node **defs, Compile* c ) : _callees(callees), _defs(defs),
acba6af809c8 6840775: Multiple JVM crashes seen with 1.6.0_10 through 1.6.0_14
kvn
parents: 729
diff changeset
103 _b(NULL), _next(NULL), C(c) { }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
104
a61af66fc99e Initial load
duke
parents:
diff changeset
105 // Given reaching-defs for this block start, compute it for this block end
a61af66fc99e Initial load
duke
parents:
diff changeset
106 void compute_reach( PhaseRegAlloc *regalloc, int max_reg, Dict *safehash );
a61af66fc99e Initial load
duke
parents:
diff changeset
107
a61af66fc99e Initial load
duke
parents:
diff changeset
108 // Merge these two OopFlows into the 'this' pointer.
a61af66fc99e Initial load
duke
parents:
diff changeset
109 void merge( OopFlow *flow, int max_reg );
a61af66fc99e Initial load
duke
parents:
diff changeset
110
a61af66fc99e Initial load
duke
parents:
diff changeset
111 // Copy a 'flow' over an existing flow
a61af66fc99e Initial load
duke
parents:
diff changeset
112 void clone( OopFlow *flow, int max_size);
a61af66fc99e Initial load
duke
parents:
diff changeset
113
a61af66fc99e Initial load
duke
parents:
diff changeset
114 // Make a new OopFlow from scratch
833
acba6af809c8 6840775: Multiple JVM crashes seen with 1.6.0_10 through 1.6.0_14
kvn
parents: 729
diff changeset
115 static OopFlow *make( Arena *A, int max_size, Compile* C );
0
a61af66fc99e Initial load
duke
parents:
diff changeset
116
a61af66fc99e Initial load
duke
parents:
diff changeset
117 // Build an oopmap from the current flow info
a61af66fc99e Initial load
duke
parents:
diff changeset
118 OopMap *build_oop_map( Node *n, int max_reg, PhaseRegAlloc *regalloc, int* live );
a61af66fc99e Initial load
duke
parents:
diff changeset
119 };
a61af66fc99e Initial load
duke
parents:
diff changeset
120
a61af66fc99e Initial load
duke
parents:
diff changeset
121 // Given reaching-defs for this block start, compute it for this block end
a61af66fc99e Initial load
duke
parents:
diff changeset
122 void OopFlow::compute_reach( PhaseRegAlloc *regalloc, int max_reg, Dict *safehash ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
123
12167
650868c062a9 8023691: Create interface for nodes in class Block
adlertz
parents: 12071
diff changeset
124 for( uint i=0; i<_b->number_of_nodes(); i++ ) {
650868c062a9 8023691: Create interface for nodes in class Block
adlertz
parents: 12071
diff changeset
125 Node *n = _b->get_node(i);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
126
a61af66fc99e Initial load
duke
parents:
diff changeset
127 if( n->jvms() ) { // Build an OopMap here?
a61af66fc99e Initial load
duke
parents:
diff changeset
128 JVMState *jvms = n->jvms();
a61af66fc99e Initial load
duke
parents:
diff changeset
129 // no map needed for leaf calls
a61af66fc99e Initial load
duke
parents:
diff changeset
130 if( n->is_MachSafePoint() && !n->is_MachCallLeaf() ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
131 int *live = (int*) (*safehash)[n];
a61af66fc99e Initial load
duke
parents:
diff changeset
132 assert( live, "must find live" );
a61af66fc99e Initial load
duke
parents:
diff changeset
133 n->as_MachSafePoint()->set_oop_map( build_oop_map(n,max_reg,regalloc, live) );
a61af66fc99e Initial load
duke
parents:
diff changeset
134 }
a61af66fc99e Initial load
duke
parents:
diff changeset
135 }
a61af66fc99e Initial load
duke
parents:
diff changeset
136
a61af66fc99e Initial load
duke
parents:
diff changeset
137 // Assign new reaching def's.
a61af66fc99e Initial load
duke
parents:
diff changeset
138 // Note that I padded the _defs and _callees arrays so it's legal
a61af66fc99e Initial load
duke
parents:
diff changeset
139 // to index at _defs[OptoReg::Bad].
a61af66fc99e Initial load
duke
parents:
diff changeset
140 OptoReg::Name first = regalloc->get_reg_first(n);
a61af66fc99e Initial load
duke
parents:
diff changeset
141 OptoReg::Name second = regalloc->get_reg_second(n);
a61af66fc99e Initial load
duke
parents:
diff changeset
142 _defs[first] = n;
a61af66fc99e Initial load
duke
parents:
diff changeset
143 _defs[second] = n;
a61af66fc99e Initial load
duke
parents:
diff changeset
144
a61af66fc99e Initial load
duke
parents:
diff changeset
145 // Pass callee-save info around copies
a61af66fc99e Initial load
duke
parents:
diff changeset
146 int idx = n->is_Copy();
a61af66fc99e Initial load
duke
parents:
diff changeset
147 if( idx ) { // Copies move callee-save info
a61af66fc99e Initial load
duke
parents:
diff changeset
148 OptoReg::Name old_first = regalloc->get_reg_first(n->in(idx));
a61af66fc99e Initial load
duke
parents:
diff changeset
149 OptoReg::Name old_second = regalloc->get_reg_second(n->in(idx));
a61af66fc99e Initial load
duke
parents:
diff changeset
150 int tmp_first = _callees[old_first];
a61af66fc99e Initial load
duke
parents:
diff changeset
151 int tmp_second = _callees[old_second];
a61af66fc99e Initial load
duke
parents:
diff changeset
152 _callees[old_first] = OptoReg::Bad; // callee-save is moved, dead in old location
a61af66fc99e Initial load
duke
parents:
diff changeset
153 _callees[old_second] = OptoReg::Bad;
a61af66fc99e Initial load
duke
parents:
diff changeset
154 _callees[first] = tmp_first;
a61af66fc99e Initial load
duke
parents:
diff changeset
155 _callees[second] = tmp_second;
a61af66fc99e Initial load
duke
parents:
diff changeset
156 } else if( n->is_Phi() ) { // Phis do not mod callee-saves
a61af66fc99e Initial load
duke
parents:
diff changeset
157 assert( _callees[first] == _callees[regalloc->get_reg_first(n->in(1))], "" );
a61af66fc99e Initial load
duke
parents:
diff changeset
158 assert( _callees[second] == _callees[regalloc->get_reg_second(n->in(1))], "" );
a61af66fc99e Initial load
duke
parents:
diff changeset
159 assert( _callees[first] == _callees[regalloc->get_reg_first(n->in(n->req()-1))], "" );
a61af66fc99e Initial load
duke
parents:
diff changeset
160 assert( _callees[second] == _callees[regalloc->get_reg_second(n->in(n->req()-1))], "" );
a61af66fc99e Initial load
duke
parents:
diff changeset
161 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
162 _callees[first] = OptoReg::Bad; // No longer holding a callee-save value
a61af66fc99e Initial load
duke
parents:
diff changeset
163 _callees[second] = OptoReg::Bad;
a61af66fc99e Initial load
duke
parents:
diff changeset
164
a61af66fc99e Initial load
duke
parents:
diff changeset
165 // Find base case for callee saves
a61af66fc99e Initial load
duke
parents:
diff changeset
166 if( n->is_Proj() && n->in(0)->is_Start() ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
167 if( OptoReg::is_reg(first) &&
a61af66fc99e Initial load
duke
parents:
diff changeset
168 regalloc->_matcher.is_save_on_entry(first) )
a61af66fc99e Initial load
duke
parents:
diff changeset
169 _callees[first] = first;
a61af66fc99e Initial load
duke
parents:
diff changeset
170 if( OptoReg::is_reg(second) &&
a61af66fc99e Initial load
duke
parents:
diff changeset
171 regalloc->_matcher.is_save_on_entry(second) )
a61af66fc99e Initial load
duke
parents:
diff changeset
172 _callees[second] = second;
a61af66fc99e Initial load
duke
parents:
diff changeset
173 }
a61af66fc99e Initial load
duke
parents:
diff changeset
174 }
a61af66fc99e Initial load
duke
parents:
diff changeset
175 }
a61af66fc99e Initial load
duke
parents:
diff changeset
176 }
a61af66fc99e Initial load
duke
parents:
diff changeset
177
a61af66fc99e Initial load
duke
parents:
diff changeset
178 // Merge the given flow into the 'this' flow
a61af66fc99e Initial load
duke
parents:
diff changeset
179 void OopFlow::merge( OopFlow *flow, int max_reg ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
180 assert( _b == NULL, "merging into a happy flow" );
a61af66fc99e Initial load
duke
parents:
diff changeset
181 assert( flow->_b, "this flow is still alive" );
a61af66fc99e Initial load
duke
parents:
diff changeset
182 assert( flow != this, "no self flow" );
a61af66fc99e Initial load
duke
parents:
diff changeset
183
a61af66fc99e Initial load
duke
parents:
diff changeset
184 // Do the merge. If there are any differences, drop to 'bottom' which
a61af66fc99e Initial load
duke
parents:
diff changeset
185 // is OptoReg::Bad or NULL depending.
a61af66fc99e Initial load
duke
parents:
diff changeset
186 for( int i=0; i<max_reg; i++ ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
187 // Merge the callee-save's
a61af66fc99e Initial load
duke
parents:
diff changeset
188 if( _callees[i] != flow->_callees[i] )
a61af66fc99e Initial load
duke
parents:
diff changeset
189 _callees[i] = OptoReg::Bad;
a61af66fc99e Initial load
duke
parents:
diff changeset
190 // Merge the reaching defs
a61af66fc99e Initial load
duke
parents:
diff changeset
191 if( _defs[i] != flow->_defs[i] )
a61af66fc99e Initial load
duke
parents:
diff changeset
192 _defs[i] = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
193 }
a61af66fc99e Initial load
duke
parents:
diff changeset
194
a61af66fc99e Initial load
duke
parents:
diff changeset
195 }
a61af66fc99e Initial load
duke
parents:
diff changeset
196
a61af66fc99e Initial load
duke
parents:
diff changeset
197 void OopFlow::clone( OopFlow *flow, int max_size ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
198 _b = flow->_b;
a61af66fc99e Initial load
duke
parents:
diff changeset
199 memcpy( _callees, flow->_callees, sizeof(short)*max_size);
a61af66fc99e Initial load
duke
parents:
diff changeset
200 memcpy( _defs , flow->_defs , sizeof(Node*)*max_size);
a61af66fc99e Initial load
duke
parents:
diff changeset
201 }
a61af66fc99e Initial load
duke
parents:
diff changeset
202
833
acba6af809c8 6840775: Multiple JVM crashes seen with 1.6.0_10 through 1.6.0_14
kvn
parents: 729
diff changeset
203 OopFlow *OopFlow::make( Arena *A, int max_size, Compile* C ) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
204 short *callees = NEW_ARENA_ARRAY(A,short,max_size+1);
a61af66fc99e Initial load
duke
parents:
diff changeset
205 Node **defs = NEW_ARENA_ARRAY(A,Node*,max_size+1);
a61af66fc99e Initial load
duke
parents:
diff changeset
206 debug_only( memset(defs,0,(max_size+1)*sizeof(Node*)) );
833
acba6af809c8 6840775: Multiple JVM crashes seen with 1.6.0_10 through 1.6.0_14
kvn
parents: 729
diff changeset
207 OopFlow *flow = new (A) OopFlow(callees+1, defs+1, C);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
208 assert( &flow->_callees[OptoReg::Bad] == callees, "Ok to index at OptoReg::Bad" );
a61af66fc99e Initial load
duke
parents:
diff changeset
209 assert( &flow->_defs [OptoReg::Bad] == defs , "Ok to index at OptoReg::Bad" );
a61af66fc99e Initial load
duke
parents:
diff changeset
210 return flow;
a61af66fc99e Initial load
duke
parents:
diff changeset
211 }
a61af66fc99e Initial load
duke
parents:
diff changeset
212
a61af66fc99e Initial load
duke
parents:
diff changeset
213 static int get_live_bit( int *live, int reg ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
214 return live[reg>>LogBitsPerInt] & (1<<(reg&(BitsPerInt-1))); }
a61af66fc99e Initial load
duke
parents:
diff changeset
215 static void set_live_bit( int *live, int reg ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
216 live[reg>>LogBitsPerInt] |= (1<<(reg&(BitsPerInt-1))); }
a61af66fc99e Initial load
duke
parents:
diff changeset
217 static void clr_live_bit( int *live, int reg ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
218 live[reg>>LogBitsPerInt] &= ~(1<<(reg&(BitsPerInt-1))); }
a61af66fc99e Initial load
duke
parents:
diff changeset
219
a61af66fc99e Initial load
duke
parents:
diff changeset
220 // Build an oopmap from the current flow info
a61af66fc99e Initial load
duke
parents:
diff changeset
221 OopMap *OopFlow::build_oop_map( Node *n, int max_reg, PhaseRegAlloc *regalloc, int* live ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
222 int framesize = regalloc->_framesize;
a61af66fc99e Initial load
duke
parents:
diff changeset
223 int max_inarg_slot = OptoReg::reg2stack(regalloc->_matcher._new_SP);
a61af66fc99e Initial load
duke
parents:
diff changeset
224 debug_only( char *dup_check = NEW_RESOURCE_ARRAY(char,OptoReg::stack0());
a61af66fc99e Initial load
duke
parents:
diff changeset
225 memset(dup_check,0,OptoReg::stack0()) );
a61af66fc99e Initial load
duke
parents:
diff changeset
226
a61af66fc99e Initial load
duke
parents:
diff changeset
227 OopMap *omap = new OopMap( framesize, max_inarg_slot );
a61af66fc99e Initial load
duke
parents:
diff changeset
228 MachCallNode *mcall = n->is_MachCall() ? n->as_MachCall() : NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
229 JVMState* jvms = n->jvms();
a61af66fc99e Initial load
duke
parents:
diff changeset
230
a61af66fc99e Initial load
duke
parents:
diff changeset
231 // For all registers do...
a61af66fc99e Initial load
duke
parents:
diff changeset
232 for( int reg=0; reg<max_reg; reg++ ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
233 if( get_live_bit(live,reg) == 0 )
a61af66fc99e Initial load
duke
parents:
diff changeset
234 continue; // Ignore if not live
a61af66fc99e Initial load
duke
parents:
diff changeset
235
a61af66fc99e Initial load
duke
parents:
diff changeset
236 // %%% C2 can use 2 OptoRegs when the physical register is only one 64bit
a61af66fc99e Initial load
duke
parents:
diff changeset
237 // register in that case we'll get an non-concrete register for the second
a61af66fc99e Initial load
duke
parents:
diff changeset
238 // half. We only need to tell the map the register once!
a61af66fc99e Initial load
duke
parents:
diff changeset
239 //
a61af66fc99e Initial load
duke
parents:
diff changeset
240 // However for the moment we disable this change and leave things as they
a61af66fc99e Initial load
duke
parents:
diff changeset
241 // were.
a61af66fc99e Initial load
duke
parents:
diff changeset
242
a61af66fc99e Initial load
duke
parents:
diff changeset
243 VMReg r = OptoReg::as_VMReg(OptoReg::Name(reg), framesize, max_inarg_slot);
a61af66fc99e Initial load
duke
parents:
diff changeset
244
a61af66fc99e Initial load
duke
parents:
diff changeset
245 if (false && r->is_reg() && !r->is_concrete()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
246 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
247 }
a61af66fc99e Initial load
duke
parents:
diff changeset
248
a61af66fc99e Initial load
duke
parents:
diff changeset
249 // See if dead (no reaching def).
a61af66fc99e Initial load
duke
parents:
diff changeset
250 Node *def = _defs[reg]; // Get reaching def
a61af66fc99e Initial load
duke
parents:
diff changeset
251 assert( def, "since live better have reaching def" );
a61af66fc99e Initial load
duke
parents:
diff changeset
252
a61af66fc99e Initial load
duke
parents:
diff changeset
253 // Classify the reaching def as oop, derived, callee-save, dead, or other
a61af66fc99e Initial load
duke
parents:
diff changeset
254 const Type *t = def->bottom_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
255 if( t->isa_oop_ptr() ) { // Oop or derived?
a61af66fc99e Initial load
duke
parents:
diff changeset
256 assert( !OptoReg::is_valid(_callees[reg]), "oop can't be callee save" );
a61af66fc99e Initial load
duke
parents:
diff changeset
257 #ifdef _LP64
a61af66fc99e Initial load
duke
parents:
diff changeset
258 // 64-bit pointers record oop-ishness on 2 aligned adjacent registers.
a61af66fc99e Initial load
duke
parents:
diff changeset
259 // Make sure both are record from the same reaching def, but do not
a61af66fc99e Initial load
duke
parents:
diff changeset
260 // put both into the oopmap.
a61af66fc99e Initial load
duke
parents:
diff changeset
261 if( (reg&1) == 1 ) { // High half of oop-pair?
a61af66fc99e Initial load
duke
parents:
diff changeset
262 assert( _defs[reg-1] == _defs[reg], "both halves from same reaching def" );
a61af66fc99e Initial load
duke
parents:
diff changeset
263 continue; // Do not record high parts in oopmap
a61af66fc99e Initial load
duke
parents:
diff changeset
264 }
a61af66fc99e Initial load
duke
parents:
diff changeset
265 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
266
a61af66fc99e Initial load
duke
parents:
diff changeset
267 // Check for a legal reg name in the oopMap and bailout if it is not.
a61af66fc99e Initial load
duke
parents:
diff changeset
268 if (!omap->legal_vm_reg_name(r)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
269 regalloc->C->record_method_not_compilable("illegal oopMap register name");
a61af66fc99e Initial load
duke
parents:
diff changeset
270 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
271 }
a61af66fc99e Initial load
duke
parents:
diff changeset
272 if( t->is_ptr()->_offset == 0 ) { // Not derived?
a61af66fc99e Initial load
duke
parents:
diff changeset
273 if( mcall ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
274 // Outgoing argument GC mask responsibility belongs to the callee,
a61af66fc99e Initial load
duke
parents:
diff changeset
275 // not the caller. Inspect the inputs to the call, to see if
a61af66fc99e Initial load
duke
parents:
diff changeset
276 // this live-range is one of them.
a61af66fc99e Initial load
duke
parents:
diff changeset
277 uint cnt = mcall->tf()->domain()->cnt();
a61af66fc99e Initial load
duke
parents:
diff changeset
278 uint j;
a61af66fc99e Initial load
duke
parents:
diff changeset
279 for( j = TypeFunc::Parms; j < cnt; j++)
a61af66fc99e Initial load
duke
parents:
diff changeset
280 if( mcall->in(j) == def )
a61af66fc99e Initial load
duke
parents:
diff changeset
281 break; // reaching def is an argument oop
a61af66fc99e Initial load
duke
parents:
diff changeset
282 if( j < cnt ) // arg oops dont go in GC map
a61af66fc99e Initial load
duke
parents:
diff changeset
283 continue; // Continue on to the next register
a61af66fc99e Initial load
duke
parents:
diff changeset
284 }
a61af66fc99e Initial load
duke
parents:
diff changeset
285 omap->set_oop(r);
a61af66fc99e Initial load
duke
parents:
diff changeset
286 } else { // Else it's derived.
a61af66fc99e Initial load
duke
parents:
diff changeset
287 // Find the base of the derived value.
a61af66fc99e Initial load
duke
parents:
diff changeset
288 uint i;
a61af66fc99e Initial load
duke
parents:
diff changeset
289 // Fast, common case, scan
a61af66fc99e Initial load
duke
parents:
diff changeset
290 for( i = jvms->oopoff(); i < n->req(); i+=2 )
a61af66fc99e Initial load
duke
parents:
diff changeset
291 if( n->in(i) == def ) break; // Common case
a61af66fc99e Initial load
duke
parents:
diff changeset
292 if( i == n->req() ) { // Missed, try a more generous scan
a61af66fc99e Initial load
duke
parents:
diff changeset
293 // Scan again, but this time peek through copies
a61af66fc99e Initial load
duke
parents:
diff changeset
294 for( i = jvms->oopoff(); i < n->req(); i+=2 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
295 Node *m = n->in(i); // Get initial derived value
a61af66fc99e Initial load
duke
parents:
diff changeset
296 while( 1 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
297 Node *d = def; // Get initial reaching def
a61af66fc99e Initial load
duke
parents:
diff changeset
298 while( 1 ) { // Follow copies of reaching def to end
a61af66fc99e Initial load
duke
parents:
diff changeset
299 if( m == d ) goto found; // breaks 3 loops
a61af66fc99e Initial load
duke
parents:
diff changeset
300 int idx = d->is_Copy();
a61af66fc99e Initial load
duke
parents:
diff changeset
301 if( !idx ) break;
a61af66fc99e Initial load
duke
parents:
diff changeset
302 d = d->in(idx); // Link through copy
a61af66fc99e Initial load
duke
parents:
diff changeset
303 }
a61af66fc99e Initial load
duke
parents:
diff changeset
304 int idx = m->is_Copy();
a61af66fc99e Initial load
duke
parents:
diff changeset
305 if( !idx ) break;
a61af66fc99e Initial load
duke
parents:
diff changeset
306 m = m->in(idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
307 }
a61af66fc99e Initial load
duke
parents:
diff changeset
308 }
833
acba6af809c8 6840775: Multiple JVM crashes seen with 1.6.0_10 through 1.6.0_14
kvn
parents: 729
diff changeset
309 guarantee( 0, "must find derived/base pair" );
0
a61af66fc99e Initial load
duke
parents:
diff changeset
310 }
a61af66fc99e Initial load
duke
parents:
diff changeset
311 found: ;
a61af66fc99e Initial load
duke
parents:
diff changeset
312 Node *base = n->in(i+1); // Base is other half of pair
a61af66fc99e Initial load
duke
parents:
diff changeset
313 int breg = regalloc->get_reg_first(base);
a61af66fc99e Initial load
duke
parents:
diff changeset
314 VMReg b = OptoReg::as_VMReg(OptoReg::Name(breg), framesize, max_inarg_slot);
a61af66fc99e Initial load
duke
parents:
diff changeset
315
a61af66fc99e Initial load
duke
parents:
diff changeset
316 // I record liveness at safepoints BEFORE I make the inputs
a61af66fc99e Initial load
duke
parents:
diff changeset
317 // live. This is because argument oops are NOT live at a
a61af66fc99e Initial load
duke
parents:
diff changeset
318 // safepoint (or at least they cannot appear in the oopmap).
a61af66fc99e Initial load
duke
parents:
diff changeset
319 // Thus bases of base/derived pairs might not be in the
a61af66fc99e Initial load
duke
parents:
diff changeset
320 // liveness data but they need to appear in the oopmap.
a61af66fc99e Initial load
duke
parents:
diff changeset
321 if( get_live_bit(live,breg) == 0 ) {// Not live?
a61af66fc99e Initial load
duke
parents:
diff changeset
322 // Flag it, so next derived pointer won't re-insert into oopmap
a61af66fc99e Initial load
duke
parents:
diff changeset
323 set_live_bit(live,breg);
a61af66fc99e Initial load
duke
parents:
diff changeset
324 // Already missed our turn?
a61af66fc99e Initial load
duke
parents:
diff changeset
325 if( breg < reg ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
326 if (b->is_stack() || b->is_concrete() || true ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
327 omap->set_oop( b);
a61af66fc99e Initial load
duke
parents:
diff changeset
328 }
a61af66fc99e Initial load
duke
parents:
diff changeset
329 }
a61af66fc99e Initial load
duke
parents:
diff changeset
330 }
a61af66fc99e Initial load
duke
parents:
diff changeset
331 if (b->is_stack() || b->is_concrete() || true ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
332 omap->set_derived_oop( r, b);
a61af66fc99e Initial load
duke
parents:
diff changeset
333 }
a61af66fc99e Initial load
duke
parents:
diff changeset
334 }
a61af66fc99e Initial load
duke
parents:
diff changeset
335
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
336 } else if( t->isa_narrowoop() ) {
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
337 assert( !OptoReg::is_valid(_callees[reg]), "oop can't be callee save" );
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
338 // Check for a legal reg name in the oopMap and bailout if it is not.
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
339 if (!omap->legal_vm_reg_name(r)) {
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
340 regalloc->C->record_method_not_compilable("illegal oopMap register name");
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
341 continue;
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
342 }
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
343 if( mcall ) {
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
344 // Outgoing argument GC mask responsibility belongs to the callee,
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
345 // not the caller. Inspect the inputs to the call, to see if
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
346 // this live-range is one of them.
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
347 uint cnt = mcall->tf()->domain()->cnt();
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
348 uint j;
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
349 for( j = TypeFunc::Parms; j < cnt; j++)
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
350 if( mcall->in(j) == def )
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
351 break; // reaching def is an argument oop
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
352 if( j < cnt ) // arg oops dont go in GC map
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
353 continue; // Continue on to the next register
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
354 }
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
355 omap->set_narrowoop(r);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
356 } else if( OptoReg::is_valid(_callees[reg])) { // callee-save?
a61af66fc99e Initial load
duke
parents:
diff changeset
357 // It's a callee-save value
a61af66fc99e Initial load
duke
parents:
diff changeset
358 assert( dup_check[_callees[reg]]==0, "trying to callee save same reg twice" );
a61af66fc99e Initial load
duke
parents:
diff changeset
359 debug_only( dup_check[_callees[reg]]=1; )
a61af66fc99e Initial load
duke
parents:
diff changeset
360 VMReg callee = OptoReg::as_VMReg(OptoReg::Name(_callees[reg]));
a61af66fc99e Initial load
duke
parents:
diff changeset
361 if ( callee->is_concrete() || true ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
362 omap->set_callee_saved( r, callee);
a61af66fc99e Initial load
duke
parents:
diff changeset
363 }
a61af66fc99e Initial load
duke
parents:
diff changeset
364
a61af66fc99e Initial load
duke
parents:
diff changeset
365 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
366 // Other - some reaching non-oop value
a61af66fc99e Initial load
duke
parents:
diff changeset
367 omap->set_value( r);
833
acba6af809c8 6840775: Multiple JVM crashes seen with 1.6.0_10 through 1.6.0_14
kvn
parents: 729
diff changeset
368 #ifdef ASSERT
acba6af809c8 6840775: Multiple JVM crashes seen with 1.6.0_10 through 1.6.0_14
kvn
parents: 729
diff changeset
369 if( t->isa_rawptr() && C->cfg()->_raw_oops.member(def) ) {
acba6af809c8 6840775: Multiple JVM crashes seen with 1.6.0_10 through 1.6.0_14
kvn
parents: 729
diff changeset
370 def->dump();
acba6af809c8 6840775: Multiple JVM crashes seen with 1.6.0_10 through 1.6.0_14
kvn
parents: 729
diff changeset
371 n->dump();
acba6af809c8 6840775: Multiple JVM crashes seen with 1.6.0_10 through 1.6.0_14
kvn
parents: 729
diff changeset
372 assert(false, "there should be a oop in OopMap instead of a live raw oop at safepoint");
acba6af809c8 6840775: Multiple JVM crashes seen with 1.6.0_10 through 1.6.0_14
kvn
parents: 729
diff changeset
373 }
acba6af809c8 6840775: Multiple JVM crashes seen with 1.6.0_10 through 1.6.0_14
kvn
parents: 729
diff changeset
374 #endif
0
a61af66fc99e Initial load
duke
parents:
diff changeset
375 }
a61af66fc99e Initial load
duke
parents:
diff changeset
376
a61af66fc99e Initial load
duke
parents:
diff changeset
377 }
a61af66fc99e Initial load
duke
parents:
diff changeset
378
a61af66fc99e Initial load
duke
parents:
diff changeset
379 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
380 /* Nice, Intel-only assert
a61af66fc99e Initial load
duke
parents:
diff changeset
381 int cnt_callee_saves=0;
a61af66fc99e Initial load
duke
parents:
diff changeset
382 int reg2 = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
383 while (OptoReg::is_reg(reg2)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
384 if( dup_check[reg2] != 0) cnt_callee_saves++;
a61af66fc99e Initial load
duke
parents:
diff changeset
385 assert( cnt_callee_saves==3 || cnt_callee_saves==5, "missed some callee-save" );
a61af66fc99e Initial load
duke
parents:
diff changeset
386 reg2++;
a61af66fc99e Initial load
duke
parents:
diff changeset
387 }
a61af66fc99e Initial load
duke
parents:
diff changeset
388 */
a61af66fc99e Initial load
duke
parents:
diff changeset
389 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
390
729
04fa5affa478 6709742: find_base_for_derived's use of Ideal NULL is unsafe causing crashes during register allocation
kvn
parents: 605
diff changeset
391 #ifdef ASSERT
04fa5affa478 6709742: find_base_for_derived's use of Ideal NULL is unsafe causing crashes during register allocation
kvn
parents: 605
diff changeset
392 for( OopMapStream oms1(omap, OopMapValue::derived_oop_value); !oms1.is_done(); oms1.next()) {
04fa5affa478 6709742: find_base_for_derived's use of Ideal NULL is unsafe causing crashes during register allocation
kvn
parents: 605
diff changeset
393 OopMapValue omv1 = oms1.current();
04fa5affa478 6709742: find_base_for_derived's use of Ideal NULL is unsafe causing crashes during register allocation
kvn
parents: 605
diff changeset
394 bool found = false;
04fa5affa478 6709742: find_base_for_derived's use of Ideal NULL is unsafe causing crashes during register allocation
kvn
parents: 605
diff changeset
395 for( OopMapStream oms2(omap,OopMapValue::oop_value); !oms2.is_done(); oms2.next()) {
04fa5affa478 6709742: find_base_for_derived's use of Ideal NULL is unsafe causing crashes during register allocation
kvn
parents: 605
diff changeset
396 if( omv1.content_reg() == oms2.current().reg() ) {
04fa5affa478 6709742: find_base_for_derived's use of Ideal NULL is unsafe causing crashes during register allocation
kvn
parents: 605
diff changeset
397 found = true;
04fa5affa478 6709742: find_base_for_derived's use of Ideal NULL is unsafe causing crashes during register allocation
kvn
parents: 605
diff changeset
398 break;
04fa5affa478 6709742: find_base_for_derived's use of Ideal NULL is unsafe causing crashes during register allocation
kvn
parents: 605
diff changeset
399 }
04fa5affa478 6709742: find_base_for_derived's use of Ideal NULL is unsafe causing crashes during register allocation
kvn
parents: 605
diff changeset
400 }
04fa5affa478 6709742: find_base_for_derived's use of Ideal NULL is unsafe causing crashes during register allocation
kvn
parents: 605
diff changeset
401 assert( found, "derived with no base in oopmap" );
04fa5affa478 6709742: find_base_for_derived's use of Ideal NULL is unsafe causing crashes during register allocation
kvn
parents: 605
diff changeset
402 }
04fa5affa478 6709742: find_base_for_derived's use of Ideal NULL is unsafe causing crashes during register allocation
kvn
parents: 605
diff changeset
403 #endif
04fa5affa478 6709742: find_base_for_derived's use of Ideal NULL is unsafe causing crashes during register allocation
kvn
parents: 605
diff changeset
404
0
a61af66fc99e Initial load
duke
parents:
diff changeset
405 return omap;
a61af66fc99e Initial load
duke
parents:
diff changeset
406 }
a61af66fc99e Initial load
duke
parents:
diff changeset
407
a61af66fc99e Initial load
duke
parents:
diff changeset
408 // Compute backwards liveness on registers
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
409 static void do_liveness(PhaseRegAlloc* regalloc, PhaseCFG* cfg, Block_List* worklist, int max_reg_ints, Arena* A, Dict* safehash) {
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
410 int* live = NEW_ARENA_ARRAY(A, int, (cfg->number_of_blocks() + 1) * max_reg_ints);
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
411 int* tmp_live = &live[cfg->number_of_blocks() * max_reg_ints];
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
412 Node* root = cfg->get_root_node();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
413 // On CISC platforms, get the node representing the stack pointer that regalloc
a61af66fc99e Initial load
duke
parents:
diff changeset
414 // used for spills
a61af66fc99e Initial load
duke
parents:
diff changeset
415 Node *fp = NodeSentinel;
a61af66fc99e Initial load
duke
parents:
diff changeset
416 if (UseCISCSpill && root->req() > 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
417 fp = root->in(1)->in(TypeFunc::FramePtr);
a61af66fc99e Initial load
duke
parents:
diff changeset
418 }
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
419 memset(live, 0, cfg->number_of_blocks() * (max_reg_ints << LogBytesPerInt));
0
a61af66fc99e Initial load
duke
parents:
diff changeset
420 // Push preds onto worklist
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 2426
diff changeset
421 for (uint i = 1; i < root->req(); i++) {
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 2426
diff changeset
422 Block* block = cfg->get_block_for_node(root->in(i));
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 2426
diff changeset
423 worklist->push(block);
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 2426
diff changeset
424 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
425
a61af66fc99e Initial load
duke
parents:
diff changeset
426 // ZKM.jar includes tiny infinite loops which are unreached from below.
a61af66fc99e Initial load
duke
parents:
diff changeset
427 // If we missed any blocks, we'll retry here after pushing all missed
a61af66fc99e Initial load
duke
parents:
diff changeset
428 // blocks on the worklist. Normally this outer loop never trips more
a61af66fc99e Initial load
duke
parents:
diff changeset
429 // than once.
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 2426
diff changeset
430 while (1) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
431
a61af66fc99e Initial load
duke
parents:
diff changeset
432 while( worklist->size() ) { // Standard worklist algorithm
a61af66fc99e Initial load
duke
parents:
diff changeset
433 Block *b = worklist->rpop();
a61af66fc99e Initial load
duke
parents:
diff changeset
434
a61af66fc99e Initial load
duke
parents:
diff changeset
435 // Copy first successor into my tmp_live space
a61af66fc99e Initial load
duke
parents:
diff changeset
436 int s0num = b->_succs[0]->_pre_order;
a61af66fc99e Initial load
duke
parents:
diff changeset
437 int *t = &live[s0num*max_reg_ints];
a61af66fc99e Initial load
duke
parents:
diff changeset
438 for( int i=0; i<max_reg_ints; i++ )
a61af66fc99e Initial load
duke
parents:
diff changeset
439 tmp_live[i] = t[i];
a61af66fc99e Initial load
duke
parents:
diff changeset
440
a61af66fc99e Initial load
duke
parents:
diff changeset
441 // OR in the remaining live registers
a61af66fc99e Initial load
duke
parents:
diff changeset
442 for( uint j=1; j<b->_num_succs; j++ ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
443 uint sjnum = b->_succs[j]->_pre_order;
a61af66fc99e Initial load
duke
parents:
diff changeset
444 int *t = &live[sjnum*max_reg_ints];
a61af66fc99e Initial load
duke
parents:
diff changeset
445 for( int i=0; i<max_reg_ints; i++ )
a61af66fc99e Initial load
duke
parents:
diff changeset
446 tmp_live[i] |= t[i];
a61af66fc99e Initial load
duke
parents:
diff changeset
447 }
a61af66fc99e Initial load
duke
parents:
diff changeset
448
a61af66fc99e Initial load
duke
parents:
diff changeset
449 // Now walk tmp_live up the block backwards, computing live
12167
650868c062a9 8023691: Create interface for nodes in class Block
adlertz
parents: 12071
diff changeset
450 for( int k=b->number_of_nodes()-1; k>=0; k-- ) {
650868c062a9 8023691: Create interface for nodes in class Block
adlertz
parents: 12071
diff changeset
451 Node *n = b->get_node(k);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
452 // KILL def'd bits
a61af66fc99e Initial load
duke
parents:
diff changeset
453 int first = regalloc->get_reg_first(n);
a61af66fc99e Initial load
duke
parents:
diff changeset
454 int second = regalloc->get_reg_second(n);
a61af66fc99e Initial load
duke
parents:
diff changeset
455 if( OptoReg::is_valid(first) ) clr_live_bit(tmp_live,first);
a61af66fc99e Initial load
duke
parents:
diff changeset
456 if( OptoReg::is_valid(second) ) clr_live_bit(tmp_live,second);
a61af66fc99e Initial load
duke
parents:
diff changeset
457
a61af66fc99e Initial load
duke
parents:
diff changeset
458 MachNode *m = n->is_Mach() ? n->as_Mach() : NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
459
a61af66fc99e Initial load
duke
parents:
diff changeset
460 // Check if m is potentially a CISC alternate instruction (i.e, possibly
a61af66fc99e Initial load
duke
parents:
diff changeset
461 // synthesized by RegAlloc from a conventional instruction and a
a61af66fc99e Initial load
duke
parents:
diff changeset
462 // spilled input)
a61af66fc99e Initial load
duke
parents:
diff changeset
463 bool is_cisc_alternate = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
464 if (UseCISCSpill && m) {
a61af66fc99e Initial load
duke
parents:
diff changeset
465 is_cisc_alternate = m->is_cisc_alternate();
a61af66fc99e Initial load
duke
parents:
diff changeset
466 }
a61af66fc99e Initial load
duke
parents:
diff changeset
467
a61af66fc99e Initial load
duke
parents:
diff changeset
468 // GEN use'd bits
a61af66fc99e Initial load
duke
parents:
diff changeset
469 for( uint l=1; l<n->req(); l++ ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
470 Node *def = n->in(l);
a61af66fc99e Initial load
duke
parents:
diff changeset
471 assert(def != 0, "input edge required");
a61af66fc99e Initial load
duke
parents:
diff changeset
472 int first = regalloc->get_reg_first(def);
a61af66fc99e Initial load
duke
parents:
diff changeset
473 int second = regalloc->get_reg_second(def);
a61af66fc99e Initial load
duke
parents:
diff changeset
474 if( OptoReg::is_valid(first) ) set_live_bit(tmp_live,first);
a61af66fc99e Initial load
duke
parents:
diff changeset
475 if( OptoReg::is_valid(second) ) set_live_bit(tmp_live,second);
a61af66fc99e Initial load
duke
parents:
diff changeset
476 // If we use the stack pointer in a cisc-alternative instruction,
a61af66fc99e Initial load
duke
parents:
diff changeset
477 // check for use as a memory operand. Then reconstruct the RegName
a61af66fc99e Initial load
duke
parents:
diff changeset
478 // for this stack location, and set the appropriate bit in the
a61af66fc99e Initial load
duke
parents:
diff changeset
479 // live vector 4987749.
a61af66fc99e Initial load
duke
parents:
diff changeset
480 if (is_cisc_alternate && def == fp) {
a61af66fc99e Initial load
duke
parents:
diff changeset
481 const TypePtr *adr_type = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
482 intptr_t offset;
a61af66fc99e Initial load
duke
parents:
diff changeset
483 const Node* base = m->get_base_and_disp(offset, adr_type);
a61af66fc99e Initial load
duke
parents:
diff changeset
484 if (base == NodeSentinel) {
a61af66fc99e Initial load
duke
parents:
diff changeset
485 // Machnode has multiple memory inputs. We are unable to reason
a61af66fc99e Initial load
duke
parents:
diff changeset
486 // with these, but are presuming (with trepidation) that not any of
a61af66fc99e Initial load
duke
parents:
diff changeset
487 // them are oops. This can be fixed by making get_base_and_disp()
a61af66fc99e Initial load
duke
parents:
diff changeset
488 // look at a specific input instead of all inputs.
a61af66fc99e Initial load
duke
parents:
diff changeset
489 assert(!def->bottom_type()->isa_oop_ptr(), "expecting non-oop mem input");
a61af66fc99e Initial load
duke
parents:
diff changeset
490 } else if (base != fp || offset == Type::OffsetBot) {
a61af66fc99e Initial load
duke
parents:
diff changeset
491 // Do nothing: the fp operand is either not from a memory use
a61af66fc99e Initial load
duke
parents:
diff changeset
492 // (base == NULL) OR the fp is used in a non-memory context
a61af66fc99e Initial load
duke
parents:
diff changeset
493 // (base is some other register) OR the offset is not constant,
a61af66fc99e Initial load
duke
parents:
diff changeset
494 // so it is not a stack slot.
a61af66fc99e Initial load
duke
parents:
diff changeset
495 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
496 assert(offset >= 0, "unexpected negative offset");
a61af66fc99e Initial load
duke
parents:
diff changeset
497 offset -= (offset % jintSize); // count the whole word
a61af66fc99e Initial load
duke
parents:
diff changeset
498 int stack_reg = regalloc->offset2reg(offset);
a61af66fc99e Initial load
duke
parents:
diff changeset
499 if (OptoReg::is_stack(stack_reg)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
500 set_live_bit(tmp_live, stack_reg);
a61af66fc99e Initial load
duke
parents:
diff changeset
501 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
502 assert(false, "stack_reg not on stack?");
a61af66fc99e Initial load
duke
parents:
diff changeset
503 }
a61af66fc99e Initial load
duke
parents:
diff changeset
504 }
a61af66fc99e Initial load
duke
parents:
diff changeset
505 }
a61af66fc99e Initial load
duke
parents:
diff changeset
506 }
a61af66fc99e Initial load
duke
parents:
diff changeset
507
a61af66fc99e Initial load
duke
parents:
diff changeset
508 if( n->jvms() ) { // Record liveness at safepoint
a61af66fc99e Initial load
duke
parents:
diff changeset
509
a61af66fc99e Initial load
duke
parents:
diff changeset
510 // This placement of this stanza means inputs to calls are
a61af66fc99e Initial load
duke
parents:
diff changeset
511 // considered live at the callsite's OopMap. Argument oops are
a61af66fc99e Initial load
duke
parents:
diff changeset
512 // hence live, but NOT included in the oopmap. See cutout in
a61af66fc99e Initial load
duke
parents:
diff changeset
513 // build_oop_map. Debug oops are live (and in OopMap).
a61af66fc99e Initial load
duke
parents:
diff changeset
514 int *n_live = NEW_ARENA_ARRAY(A, int, max_reg_ints);
a61af66fc99e Initial load
duke
parents:
diff changeset
515 for( int l=0; l<max_reg_ints; l++ )
a61af66fc99e Initial load
duke
parents:
diff changeset
516 n_live[l] = tmp_live[l];
a61af66fc99e Initial load
duke
parents:
diff changeset
517 safehash->Insert(n,n_live);
a61af66fc99e Initial load
duke
parents:
diff changeset
518 }
a61af66fc99e Initial load
duke
parents:
diff changeset
519
a61af66fc99e Initial load
duke
parents:
diff changeset
520 }
a61af66fc99e Initial load
duke
parents:
diff changeset
521
a61af66fc99e Initial load
duke
parents:
diff changeset
522 // Now at block top, see if we have any changes. If so, propagate
a61af66fc99e Initial load
duke
parents:
diff changeset
523 // to prior blocks.
a61af66fc99e Initial load
duke
parents:
diff changeset
524 int *old_live = &live[b->_pre_order*max_reg_ints];
a61af66fc99e Initial load
duke
parents:
diff changeset
525 int l;
a61af66fc99e Initial load
duke
parents:
diff changeset
526 for( l=0; l<max_reg_ints; l++ )
a61af66fc99e Initial load
duke
parents:
diff changeset
527 if( tmp_live[l] != old_live[l] )
a61af66fc99e Initial load
duke
parents:
diff changeset
528 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
529 if( l<max_reg_ints ) { // Change!
a61af66fc99e Initial load
duke
parents:
diff changeset
530 // Copy in new value
a61af66fc99e Initial load
duke
parents:
diff changeset
531 for( l=0; l<max_reg_ints; l++ )
a61af66fc99e Initial load
duke
parents:
diff changeset
532 old_live[l] = tmp_live[l];
a61af66fc99e Initial load
duke
parents:
diff changeset
533 // Push preds onto worklist
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 2426
diff changeset
534 for (l = 1; l < (int)b->num_preds(); l++) {
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 2426
diff changeset
535 Block* block = cfg->get_block_for_node(b->pred(l));
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 2426
diff changeset
536 worklist->push(block);
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 2426
diff changeset
537 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
538 }
a61af66fc99e Initial load
duke
parents:
diff changeset
539 }
a61af66fc99e Initial load
duke
parents:
diff changeset
540
a61af66fc99e Initial load
duke
parents:
diff changeset
541 // Scan for any missing safepoints. Happens to infinite loops
a61af66fc99e Initial load
duke
parents:
diff changeset
542 // ala ZKM.jar
a61af66fc99e Initial load
duke
parents:
diff changeset
543 uint i;
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
544 for (i = 1; i < cfg->number_of_blocks(); i++) {
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
545 Block* block = cfg->get_block(i);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
546 uint j;
12167
650868c062a9 8023691: Create interface for nodes in class Block
adlertz
parents: 12071
diff changeset
547 for (j = 1; j < block->number_of_nodes(); j++) {
650868c062a9 8023691: Create interface for nodes in class Block
adlertz
parents: 12071
diff changeset
548 if (block->get_node(j)->jvms() && (*safehash)[block->get_node(j)] == NULL) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
549 break;
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
550 }
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
551 }
12167
650868c062a9 8023691: Create interface for nodes in class Block
adlertz
parents: 12071
diff changeset
552 if (j < block->number_of_nodes()) {
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
553 break;
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
554 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
555 }
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
556 if (i == cfg->number_of_blocks()) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
557 break; // Got 'em all
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
558 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
559 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
560 if( PrintOpto && Verbose )
a61af66fc99e Initial load
duke
parents:
diff changeset
561 tty->print_cr("retripping live calc");
a61af66fc99e Initial load
duke
parents:
diff changeset
562 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
563 // Force the issue (expensively): recheck everybody
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
564 for (i = 1; i < cfg->number_of_blocks(); i++) {
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
565 worklist->push(cfg->get_block(i));
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
566 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
567 }
a61af66fc99e Initial load
duke
parents:
diff changeset
568 }
a61af66fc99e Initial load
duke
parents:
diff changeset
569
a61af66fc99e Initial load
duke
parents:
diff changeset
570 // Collect GC mask info - where are all the OOPs?
a61af66fc99e Initial load
duke
parents:
diff changeset
571 void Compile::BuildOopMaps() {
a61af66fc99e Initial load
duke
parents:
diff changeset
572 NOT_PRODUCT( TracePhase t3("bldOopMaps", &_t_buildOopMaps, TimeCompiler); )
a61af66fc99e Initial load
duke
parents:
diff changeset
573 // Can't resource-mark because I need to leave all those OopMaps around,
a61af66fc99e Initial load
duke
parents:
diff changeset
574 // or else I need to resource-mark some arena other than the default.
a61af66fc99e Initial load
duke
parents:
diff changeset
575 // ResourceMark rm; // Reclaim all OopFlows when done
a61af66fc99e Initial load
duke
parents:
diff changeset
576 int max_reg = _regalloc->_max_reg; // Current array extent
a61af66fc99e Initial load
duke
parents:
diff changeset
577
a61af66fc99e Initial load
duke
parents:
diff changeset
578 Arena *A = Thread::current()->resource_area();
a61af66fc99e Initial load
duke
parents:
diff changeset
579 Block_List worklist; // Worklist of pending blocks
a61af66fc99e Initial load
duke
parents:
diff changeset
580
a61af66fc99e Initial load
duke
parents:
diff changeset
581 int max_reg_ints = round_to(max_reg, BitsPerInt)>>LogBitsPerInt;
a61af66fc99e Initial load
duke
parents:
diff changeset
582 Dict *safehash = NULL; // Used for assert only
a61af66fc99e Initial load
duke
parents:
diff changeset
583 // Compute a backwards liveness per register. Needs a bitarray of
a61af66fc99e Initial load
duke
parents:
diff changeset
584 // #blocks x (#registers, rounded up to ints)
a61af66fc99e Initial load
duke
parents:
diff changeset
585 safehash = new Dict(cmpkey,hashkey,A);
a61af66fc99e Initial load
duke
parents:
diff changeset
586 do_liveness( _regalloc, _cfg, &worklist, max_reg_ints, A, safehash );
a61af66fc99e Initial load
duke
parents:
diff changeset
587 OopFlow *free_list = NULL; // Free, unused
a61af66fc99e Initial load
duke
parents:
diff changeset
588
a61af66fc99e Initial load
duke
parents:
diff changeset
589 // Array mapping blocks to completed oopflows
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
590 OopFlow **flows = NEW_ARENA_ARRAY(A, OopFlow*, _cfg->number_of_blocks());
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
591 memset( flows, 0, _cfg->number_of_blocks() * sizeof(OopFlow*) );
0
a61af66fc99e Initial load
duke
parents:
diff changeset
592
a61af66fc99e Initial load
duke
parents:
diff changeset
593
a61af66fc99e Initial load
duke
parents:
diff changeset
594 // Do the first block 'by hand' to prime the worklist
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
595 Block *entry = _cfg->get_block(1);
833
acba6af809c8 6840775: Multiple JVM crashes seen with 1.6.0_10 through 1.6.0_14
kvn
parents: 729
diff changeset
596 OopFlow *rootflow = OopFlow::make(A,max_reg,this);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
597 // Initialize to 'bottom' (not 'top')
a61af66fc99e Initial load
duke
parents:
diff changeset
598 memset( rootflow->_callees, OptoReg::Bad, max_reg*sizeof(short) );
a61af66fc99e Initial load
duke
parents:
diff changeset
599 memset( rootflow->_defs , 0, max_reg*sizeof(Node*) );
a61af66fc99e Initial load
duke
parents:
diff changeset
600 flows[entry->_pre_order] = rootflow;
a61af66fc99e Initial load
duke
parents:
diff changeset
601
a61af66fc99e Initial load
duke
parents:
diff changeset
602 // Do the first block 'by hand' to prime the worklist
a61af66fc99e Initial load
duke
parents:
diff changeset
603 rootflow->_b = entry;
a61af66fc99e Initial load
duke
parents:
diff changeset
604 rootflow->compute_reach( _regalloc, max_reg, safehash );
a61af66fc99e Initial load
duke
parents:
diff changeset
605 for( uint i=0; i<entry->_num_succs; i++ )
a61af66fc99e Initial load
duke
parents:
diff changeset
606 worklist.push(entry->_succs[i]);
a61af66fc99e Initial load
duke
parents:
diff changeset
607
a61af66fc99e Initial load
duke
parents:
diff changeset
608 // Now worklist contains blocks which have some, but perhaps not all,
a61af66fc99e Initial load
duke
parents:
diff changeset
609 // predecessors visited.
a61af66fc99e Initial load
duke
parents:
diff changeset
610 while( worklist.size() ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
611 // Scan for a block with all predecessors visited, or any randoms slob
a61af66fc99e Initial load
duke
parents:
diff changeset
612 // otherwise. All-preds-visited order allows me to recycle OopFlow
a61af66fc99e Initial load
duke
parents:
diff changeset
613 // structures rapidly and cut down on the memory footprint.
a61af66fc99e Initial load
duke
parents:
diff changeset
614 // Note: not all predecessors might be visited yet (must happen for
a61af66fc99e Initial load
duke
parents:
diff changeset
615 // irreducible loops). This is OK, since every live value must have the
a61af66fc99e Initial load
duke
parents:
diff changeset
616 // SAME reaching def for the block, so any reaching def is OK.
a61af66fc99e Initial load
duke
parents:
diff changeset
617 uint i;
a61af66fc99e Initial load
duke
parents:
diff changeset
618
a61af66fc99e Initial load
duke
parents:
diff changeset
619 Block *b = worklist.pop();
a61af66fc99e Initial load
duke
parents:
diff changeset
620 // Ignore root block
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
621 if (b == _cfg->get_root_block()) {
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
622 continue;
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
623 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
624 // Block is already done? Happens if block has several predecessors,
a61af66fc99e Initial load
duke
parents:
diff changeset
625 // he can get on the worklist more than once.
a61af66fc99e Initial load
duke
parents:
diff changeset
626 if( flows[b->_pre_order] ) continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
627
a61af66fc99e Initial load
duke
parents:
diff changeset
628 // If this block has a visited predecessor AND that predecessor has this
a61af66fc99e Initial load
duke
parents:
diff changeset
629 // last block as his only undone child, we can move the OopFlow from the
a61af66fc99e Initial load
duke
parents:
diff changeset
630 // pred to this block. Otherwise we have to grab a new OopFlow.
a61af66fc99e Initial load
duke
parents:
diff changeset
631 OopFlow *flow = NULL; // Flag for finding optimized flow
a61af66fc99e Initial load
duke
parents:
diff changeset
632 Block *pred = (Block*)0xdeadbeef;
a61af66fc99e Initial load
duke
parents:
diff changeset
633 // Scan this block's preds to find a done predecessor
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 2426
diff changeset
634 for (uint j = 1; j < b->num_preds(); j++) {
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 2426
diff changeset
635 Block* p = _cfg->get_block_for_node(b->pred(j));
0
a61af66fc99e Initial load
duke
parents:
diff changeset
636 OopFlow *p_flow = flows[p->_pre_order];
a61af66fc99e Initial load
duke
parents:
diff changeset
637 if( p_flow ) { // Predecessor is done
a61af66fc99e Initial load
duke
parents:
diff changeset
638 assert( p_flow->_b == p, "cross check" );
a61af66fc99e Initial load
duke
parents:
diff changeset
639 pred = p; // Record some predecessor
a61af66fc99e Initial load
duke
parents:
diff changeset
640 // If all successors of p are done except for 'b', then we can carry
a61af66fc99e Initial load
duke
parents:
diff changeset
641 // p_flow forward to 'b' without copying, otherwise we have to draw
a61af66fc99e Initial load
duke
parents:
diff changeset
642 // from the free_list and clone data.
a61af66fc99e Initial load
duke
parents:
diff changeset
643 uint k;
a61af66fc99e Initial load
duke
parents:
diff changeset
644 for( k=0; k<p->_num_succs; k++ )
a61af66fc99e Initial load
duke
parents:
diff changeset
645 if( !flows[p->_succs[k]->_pre_order] &&
a61af66fc99e Initial load
duke
parents:
diff changeset
646 p->_succs[k] != b )
a61af66fc99e Initial load
duke
parents:
diff changeset
647 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
648
a61af66fc99e Initial load
duke
parents:
diff changeset
649 // Either carry-forward the now-unused OopFlow for b's use
a61af66fc99e Initial load
duke
parents:
diff changeset
650 // or draw a new one from the free list
a61af66fc99e Initial load
duke
parents:
diff changeset
651 if( k==p->_num_succs ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
652 flow = p_flow;
a61af66fc99e Initial load
duke
parents:
diff changeset
653 break; // Found an ideal pred, use him
a61af66fc99e Initial load
duke
parents:
diff changeset
654 }
a61af66fc99e Initial load
duke
parents:
diff changeset
655 }
a61af66fc99e Initial load
duke
parents:
diff changeset
656 }
a61af66fc99e Initial load
duke
parents:
diff changeset
657
a61af66fc99e Initial load
duke
parents:
diff changeset
658 if( flow ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
659 // We have an OopFlow that's the last-use of a predecessor.
a61af66fc99e Initial load
duke
parents:
diff changeset
660 // Carry it forward.
a61af66fc99e Initial load
duke
parents:
diff changeset
661 } else { // Draw a new OopFlow from the freelist
a61af66fc99e Initial load
duke
parents:
diff changeset
662 if( !free_list )
833
acba6af809c8 6840775: Multiple JVM crashes seen with 1.6.0_10 through 1.6.0_14
kvn
parents: 729
diff changeset
663 free_list = OopFlow::make(A,max_reg,C);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
664 flow = free_list;
a61af66fc99e Initial load
duke
parents:
diff changeset
665 assert( flow->_b == NULL, "oopFlow is not free" );
a61af66fc99e Initial load
duke
parents:
diff changeset
666 free_list = flow->_next;
a61af66fc99e Initial load
duke
parents:
diff changeset
667 flow->_next = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
668
a61af66fc99e Initial load
duke
parents:
diff changeset
669 // Copy/clone over the data
a61af66fc99e Initial load
duke
parents:
diff changeset
670 flow->clone(flows[pred->_pre_order], max_reg);
a61af66fc99e Initial load
duke
parents:
diff changeset
671 }
a61af66fc99e Initial load
duke
parents:
diff changeset
672
a61af66fc99e Initial load
duke
parents:
diff changeset
673 // Mark flow for block. Blocks can only be flowed over once,
a61af66fc99e Initial load
duke
parents:
diff changeset
674 // because after the first time they are guarded from entering
a61af66fc99e Initial load
duke
parents:
diff changeset
675 // this code again.
a61af66fc99e Initial load
duke
parents:
diff changeset
676 assert( flow->_b == pred, "have some prior flow" );
a61af66fc99e Initial load
duke
parents:
diff changeset
677 flow->_b = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
678
a61af66fc99e Initial load
duke
parents:
diff changeset
679 // Now push flow forward
a61af66fc99e Initial load
duke
parents:
diff changeset
680 flows[b->_pre_order] = flow;// Mark flow for this block
a61af66fc99e Initial load
duke
parents:
diff changeset
681 flow->_b = b;
a61af66fc99e Initial load
duke
parents:
diff changeset
682 flow->compute_reach( _regalloc, max_reg, safehash );
a61af66fc99e Initial load
duke
parents:
diff changeset
683
a61af66fc99e Initial load
duke
parents:
diff changeset
684 // Now push children onto worklist
a61af66fc99e Initial load
duke
parents:
diff changeset
685 for( i=0; i<b->_num_succs; i++ )
a61af66fc99e Initial load
duke
parents:
diff changeset
686 worklist.push(b->_succs[i]);
a61af66fc99e Initial load
duke
parents:
diff changeset
687
a61af66fc99e Initial load
duke
parents:
diff changeset
688 }
a61af66fc99e Initial load
duke
parents:
diff changeset
689 }