Mercurial > hg > truffle
annotate src/share/vm/opto/parse1.cpp @ 17783:85b20fdf2d24
Merge
author | kvn |
---|---|
date | Tue, 25 Mar 2014 11:38:48 -0700 |
parents | 606acabe7b5c |
children | 62c54fcc0a35 |
rev | line source |
---|---|
0 | 1 /* |
17467
55fb97c4c58d
8029233: Update copyright year to match last edit in jdk8 hotspot repository for 2013
mikael
parents:
12966
diff
changeset
|
2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. |
0 | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1377
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1377
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:
1377
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #include "precompiled.hpp" |
26 #include "compiler/compileLog.hpp" | |
27 #include "interpreter/linkResolver.hpp" | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6268
diff
changeset
|
28 #include "oops/method.hpp" |
1972 | 29 #include "opto/addnode.hpp" |
30 #include "opto/idealGraphPrinter.hpp" | |
31 #include "opto/locknode.hpp" | |
32 #include "opto/memnode.hpp" | |
33 #include "opto/parse.hpp" | |
34 #include "opto/rootnode.hpp" | |
35 #include "opto/runtime.hpp" | |
36 #include "runtime/arguments.hpp" | |
37 #include "runtime/handles.inline.hpp" | |
38 #include "runtime/sharedRuntime.hpp" | |
39 #include "utilities/copy.hpp" | |
0 | 40 |
41 // Static array so we can figure out which bytecodes stop us from compiling | |
42 // the most. Some of the non-static variables are needed in bytecodeInfo.cpp | |
43 // and eventually should be encapsulated in a proper class (gri 8/18/98). | |
44 | |
367
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
45 int nodes_created = 0; |
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
46 int methods_parsed = 0; |
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
47 int methods_seen = 0; |
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
48 int blocks_parsed = 0; |
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
49 int blocks_seen = 0; |
0 | 50 |
367
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
51 int explicit_null_checks_inserted = 0; |
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
52 int explicit_null_checks_elided = 0; |
0 | 53 int all_null_checks_found = 0, implicit_null_checks = 0; |
54 int implicit_null_throws = 0; | |
55 | |
56 int reclaim_idx = 0; | |
57 int reclaim_in = 0; | |
58 int reclaim_node = 0; | |
59 | |
60 #ifndef PRODUCT | |
61 bool Parse::BytecodeParseHistogram::_initialized = false; | |
62 uint Parse::BytecodeParseHistogram::_bytecodes_parsed [Bytecodes::number_of_codes]; | |
63 uint Parse::BytecodeParseHistogram::_nodes_constructed[Bytecodes::number_of_codes]; | |
64 uint Parse::BytecodeParseHistogram::_nodes_transformed[Bytecodes::number_of_codes]; | |
65 uint Parse::BytecodeParseHistogram::_new_values [Bytecodes::number_of_codes]; | |
66 #endif | |
67 | |
68 //------------------------------print_statistics------------------------------- | |
69 #ifndef PRODUCT | |
70 void Parse::print_statistics() { | |
71 tty->print_cr("--- Compiler Statistics ---"); | |
72 tty->print("Methods seen: %d Methods parsed: %d", methods_seen, methods_parsed); | |
73 tty->print(" Nodes created: %d", nodes_created); | |
74 tty->cr(); | |
75 if (methods_seen != methods_parsed) | |
76 tty->print_cr("Reasons for parse failures (NOT cumulative):"); | |
367
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
77 tty->print_cr("Blocks parsed: %d Blocks seen: %d", blocks_parsed, blocks_seen); |
0 | 78 |
79 if( explicit_null_checks_inserted ) | |
80 tty->print_cr("%d original NULL checks - %d elided (%2d%%); optimizer leaves %d,", explicit_null_checks_inserted, explicit_null_checks_elided, (100*explicit_null_checks_elided)/explicit_null_checks_inserted, all_null_checks_found); | |
81 if( all_null_checks_found ) | |
82 tty->print_cr("%d made implicit (%2d%%)", implicit_null_checks, | |
83 (100*implicit_null_checks)/all_null_checks_found); | |
84 if( implicit_null_throws ) | |
85 tty->print_cr("%d implicit null exceptions at runtime", | |
86 implicit_null_throws); | |
87 | |
88 if( PrintParseStatistics && BytecodeParseHistogram::initialized() ) { | |
89 BytecodeParseHistogram::print(); | |
90 } | |
91 } | |
92 #endif | |
93 | |
94 //------------------------------ON STACK REPLACEMENT--------------------------- | |
95 | |
96 // Construct a node which can be used to get incoming state for | |
97 // on stack replacement. | |
98 Node *Parse::fetch_interpreter_state(int index, | |
99 BasicType bt, | |
100 Node *local_addrs, | |
101 Node *local_addrs_base) { | |
102 Node *mem = memory(Compile::AliasIdxRaw); | |
103 Node *adr = basic_plus_adr( local_addrs_base, local_addrs, -index*wordSize ); | |
1609 | 104 Node *ctl = control(); |
0 | 105 |
106 // Very similar to LoadNode::make, except we handle un-aligned longs and | |
107 // doubles on Sparc. Intel can handle them just fine directly. | |
108 Node *l; | |
109 switch( bt ) { // Signature is flattened | |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
110 case T_INT: l = new (C) LoadINode( ctl, mem, adr, TypeRawPtr::BOTTOM ); break; |
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
111 case T_FLOAT: l = new (C) LoadFNode( ctl, mem, adr, TypeRawPtr::BOTTOM ); break; |
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
112 case T_ADDRESS: l = new (C) LoadPNode( ctl, mem, adr, TypeRawPtr::BOTTOM, TypeRawPtr::BOTTOM ); break; |
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
113 case T_OBJECT: l = new (C) LoadPNode( ctl, mem, adr, TypeRawPtr::BOTTOM, TypeInstPtr::BOTTOM ); break; |
0 | 114 case T_LONG: |
115 case T_DOUBLE: { | |
116 // Since arguments are in reverse order, the argument address 'adr' | |
117 // refers to the back half of the long/double. Recompute adr. | |
118 adr = basic_plus_adr( local_addrs_base, local_addrs, -(index+1)*wordSize ); | |
119 if( Matcher::misaligned_doubles_ok ) { | |
120 l = (bt == T_DOUBLE) | |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
121 ? (Node*)new (C) LoadDNode( ctl, mem, adr, TypeRawPtr::BOTTOM ) |
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
122 : (Node*)new (C) LoadLNode( ctl, mem, adr, TypeRawPtr::BOTTOM ); |
0 | 123 } else { |
124 l = (bt == T_DOUBLE) | |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
125 ? (Node*)new (C) LoadD_unalignedNode( ctl, mem, adr, TypeRawPtr::BOTTOM ) |
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
126 : (Node*)new (C) LoadL_unalignedNode( ctl, mem, adr, TypeRawPtr::BOTTOM ); |
0 | 127 } |
128 break; | |
129 } | |
130 default: ShouldNotReachHere(); | |
131 } | |
132 return _gvn.transform(l); | |
133 } | |
134 | |
135 // Helper routine to prevent the interpreter from handing | |
136 // unexpected typestate to an OSR method. | |
137 // The Node l is a value newly dug out of the interpreter frame. | |
138 // The type is the type predicted by ciTypeFlow. Note that it is | |
139 // not a general type, but can only come from Type::get_typeflow_type. | |
140 // The safepoint is a map which will feed an uncommon trap. | |
141 Node* Parse::check_interpreter_type(Node* l, const Type* type, | |
142 SafePointNode* &bad_type_exit) { | |
143 | |
144 const TypeOopPtr* tp = type->isa_oopptr(); | |
145 | |
146 // TypeFlow may assert null-ness if a type appears unloaded. | |
147 if (type == TypePtr::NULL_PTR || | |
148 (tp != NULL && !tp->klass()->is_loaded())) { | |
149 // Value must be null, not a real oop. | |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
150 Node* chk = _gvn.transform( new (C) CmpPNode(l, null()) ); |
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
151 Node* tst = _gvn.transform( new (C) BoolNode(chk, BoolTest::eq) ); |
0 | 152 IfNode* iff = create_and_map_if(control(), tst, PROB_MAX, COUNT_UNKNOWN); |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
153 set_control(_gvn.transform( new (C) IfTrueNode(iff) )); |
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
154 Node* bad_type = _gvn.transform( new (C) IfFalseNode(iff) ); |
0 | 155 bad_type_exit->control()->add_req(bad_type); |
156 l = null(); | |
157 } | |
158 | |
159 // Typeflow can also cut off paths from the CFG, based on | |
160 // types which appear unloaded, or call sites which appear unlinked. | |
161 // When paths are cut off, values at later merge points can rise | |
162 // toward more specific classes. Make sure these specific classes | |
163 // are still in effect. | |
164 if (tp != NULL && tp->klass() != C->env()->Object_klass()) { | |
165 // TypeFlow asserted a specific object type. Value must have that type. | |
166 Node* bad_type_ctrl = NULL; | |
167 l = gen_checkcast(l, makecon(TypeKlassPtr::make(tp->klass())), &bad_type_ctrl); | |
168 bad_type_exit->control()->add_req(bad_type_ctrl); | |
169 } | |
170 | |
171 BasicType bt_l = _gvn.type(l)->basic_type(); | |
172 BasicType bt_t = type->basic_type(); | |
173 assert(_gvn.type(l)->higher_equal(type), "must constrain OSR typestate"); | |
174 return l; | |
175 } | |
176 | |
177 // Helper routine which sets up elements of the initial parser map when | |
178 // performing a parse for on stack replacement. Add values into map. | |
179 // The only parameter contains the address of a interpreter arguments. | |
180 void Parse::load_interpreter_state(Node* osr_buf) { | |
181 int index; | |
182 int max_locals = jvms()->loc_size(); | |
183 int max_stack = jvms()->stk_size(); | |
184 | |
185 | |
186 // Mismatch between method and jvms can occur since map briefly held | |
187 // an OSR entry state (which takes up one RawPtr word). | |
188 assert(max_locals == method()->max_locals(), "sanity"); | |
189 assert(max_stack >= method()->max_stack(), "sanity"); | |
190 assert((int)jvms()->endoff() == TypeFunc::Parms + max_locals + max_stack, "sanity"); | |
191 assert((int)jvms()->endoff() == (int)map()->req(), "sanity"); | |
192 | |
193 // Find the start block. | |
194 Block* osr_block = start_block(); | |
195 assert(osr_block->start() == osr_bci(), "sanity"); | |
196 | |
197 // Set initial BCI. | |
198 set_parse_bci(osr_block->start()); | |
199 | |
200 // Set initial stack depth. | |
201 set_sp(osr_block->start_sp()); | |
202 | |
203 // Check bailouts. We currently do not perform on stack replacement | |
204 // of loops in catch blocks or loops which branch with a non-empty stack. | |
205 if (sp() != 0) { | |
206 C->record_method_not_compilable("OSR starts with non-empty stack"); | |
207 return; | |
208 } | |
209 // Do not OSR inside finally clauses: | |
210 if (osr_block->has_trap_at(osr_block->start())) { | |
211 C->record_method_not_compilable("OSR starts with an immediate trap"); | |
212 return; | |
213 } | |
214 | |
215 // Commute monitors from interpreter frame to compiler frame. | |
216 assert(jvms()->monitor_depth() == 0, "should be no active locks at beginning of osr"); | |
217 int mcnt = osr_block->flow()->monitor_count(); | |
218 Node *monitors_addr = basic_plus_adr(osr_buf, osr_buf, (max_locals+mcnt*2-1)*wordSize); | |
219 for (index = 0; index < mcnt; index++) { | |
220 // Make a BoxLockNode for the monitor. | |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
221 Node *box = _gvn.transform(new (C) BoxLockNode(next_monitor())); |
0 | 222 |
223 | |
224 // Displaced headers and locked objects are interleaved in the | |
225 // temp OSR buffer. We only copy the locked objects out here. | |
226 // Fetch the locked object from the OSR temp buffer and copy to our fastlock node. | |
227 Node *lock_object = fetch_interpreter_state(index*2, T_OBJECT, monitors_addr, osr_buf); | |
228 // Try and copy the displaced header to the BoxNode | |
229 Node *displaced_hdr = fetch_interpreter_state((index*2) + 1, T_ADDRESS, monitors_addr, osr_buf); | |
230 | |
231 | |
232 store_to_memory(control(), box, displaced_hdr, T_ADDRESS, Compile::AliasIdxRaw); | |
233 | |
234 // Build a bogus FastLockNode (no code will be generated) and push the | |
235 // monitor into our debug info. | |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
236 const FastLockNode *flock = _gvn.transform(new (C) FastLockNode( 0, lock_object, box ))->as_FastLock(); |
0 | 237 map()->push_monitor(flock); |
238 | |
239 // If the lock is our method synchronization lock, tuck it away in | |
240 // _sync_lock for return and rethrow exit paths. | |
241 if (index == 0 && method()->is_synchronized()) { | |
242 _synch_lock = flock; | |
243 } | |
244 } | |
245 | |
991 | 246 // Use the raw liveness computation to make sure that unexpected |
247 // values don't propagate into the OSR frame. | |
1070
87b2fdd4bf98
6892079: live value must not be garbage failure after fix for 6854812
never
parents:
991
diff
changeset
|
248 MethodLivenessResult live_locals = method()->liveness_at_bci(osr_bci()); |
0 | 249 if (!live_locals.is_valid()) { |
250 // Degenerate or breakpointed method. | |
251 C->record_method_not_compilable("OSR in empty or breakpointed method"); | |
252 return; | |
253 } | |
254 | |
255 // Extract the needed locals from the interpreter frame. | |
256 Node *locals_addr = basic_plus_adr(osr_buf, osr_buf, (max_locals-1)*wordSize); | |
257 | |
258 // find all the locals that the interpreter thinks contain live oops | |
259 const BitMap live_oops = method()->live_local_oops_at_bci(osr_bci()); | |
260 for (index = 0; index < max_locals; index++) { | |
261 | |
262 if (!live_locals.at(index)) { | |
263 continue; | |
264 } | |
265 | |
266 const Type *type = osr_block->local_type_at(index); | |
267 | |
268 if (type->isa_oopptr() != NULL) { | |
269 | |
270 // 6403625: Verify that the interpreter oopMap thinks that the oop is live | |
271 // else we might load a stale oop if the MethodLiveness disagrees with the | |
272 // result of the interpreter. If the interpreter says it is dead we agree | |
273 // by making the value go to top. | |
274 // | |
275 | |
276 if (!live_oops.at(index)) { | |
277 if (C->log() != NULL) { | |
278 C->log()->elem("OSR_mismatch local_index='%d'",index); | |
279 } | |
280 set_local(index, null()); | |
281 // and ignore it for the loads | |
282 continue; | |
283 } | |
284 } | |
285 | |
286 // Filter out TOP, HALF, and BOTTOM. (Cf. ensure_phi.) | |
287 if (type == Type::TOP || type == Type::HALF) { | |
288 continue; | |
289 } | |
290 // If the type falls to bottom, then this must be a local that | |
291 // is mixing ints and oops or some such. Forcing it to top | |
292 // makes it go dead. | |
293 if (type == Type::BOTTOM) { | |
294 continue; | |
295 } | |
296 // Construct code to access the appropriate local. | |
1377
ef74d6d1ac1e
6938026: C2 compiler fails in Node::rematerialize()const
never
parents:
1344
diff
changeset
|
297 BasicType bt = type->basic_type(); |
ef74d6d1ac1e
6938026: C2 compiler fails in Node::rematerialize()const
never
parents:
1344
diff
changeset
|
298 if (type == TypePtr::NULL_PTR) { |
ef74d6d1ac1e
6938026: C2 compiler fails in Node::rematerialize()const
never
parents:
1344
diff
changeset
|
299 // Ptr types are mixed together with T_ADDRESS but NULL is |
ef74d6d1ac1e
6938026: C2 compiler fails in Node::rematerialize()const
never
parents:
1344
diff
changeset
|
300 // really for T_OBJECT types so correct it. |
ef74d6d1ac1e
6938026: C2 compiler fails in Node::rematerialize()const
never
parents:
1344
diff
changeset
|
301 bt = T_OBJECT; |
ef74d6d1ac1e
6938026: C2 compiler fails in Node::rematerialize()const
never
parents:
1344
diff
changeset
|
302 } |
ef74d6d1ac1e
6938026: C2 compiler fails in Node::rematerialize()const
never
parents:
1344
diff
changeset
|
303 Node *value = fetch_interpreter_state(index, bt, locals_addr, osr_buf); |
0 | 304 set_local(index, value); |
305 } | |
306 | |
307 // Extract the needed stack entries from the interpreter frame. | |
308 for (index = 0; index < sp(); index++) { | |
309 const Type *type = osr_block->stack_type_at(index); | |
310 if (type != Type::TOP) { | |
311 // Currently the compiler bails out when attempting to on stack replace | |
312 // at a bci with a non-empty stack. We should not reach here. | |
313 ShouldNotReachHere(); | |
314 } | |
315 } | |
316 | |
317 // End the OSR migration | |
318 make_runtime_call(RC_LEAF, OptoRuntime::osr_end_Type(), | |
319 CAST_FROM_FN_PTR(address, SharedRuntime::OSR_migration_end), | |
320 "OSR_migration_end", TypeRawPtr::BOTTOM, | |
321 osr_buf); | |
322 | |
323 // Now that the interpreter state is loaded, make sure it will match | |
324 // at execution time what the compiler is expecting now: | |
325 SafePointNode* bad_type_exit = clone_map(); | |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
326 bad_type_exit->set_control(new (C) RegionNode(1)); |
0 | 327 |
1278
da9559b49b84
6915557: assert(_gvn.type(l)->higher_equal(type),"must constrain OSR typestate") with debug build
never
parents:
1264
diff
changeset
|
328 assert(osr_block->flow()->jsrs()->size() == 0, "should be no jsrs live at osr point"); |
0 | 329 for (index = 0; index < max_locals; index++) { |
330 if (stopped()) break; | |
331 Node* l = local(index); | |
332 if (l->is_top()) continue; // nothing here | |
333 const Type *type = osr_block->local_type_at(index); | |
334 if (type->isa_oopptr() != NULL) { | |
335 if (!live_oops.at(index)) { | |
336 // skip type check for dead oops | |
337 continue; | |
338 } | |
339 } | |
1281
7d236a9688c5
6930398: fix for return address locals in OSR entries uses wrong test
never
parents:
1278
diff
changeset
|
340 if (osr_block->flow()->local_type_at(index)->is_return_address()) { |
1278
da9559b49b84
6915557: assert(_gvn.type(l)->higher_equal(type),"must constrain OSR typestate") with debug build
never
parents:
1264
diff
changeset
|
341 // In our current system it's illegal for jsr addresses to be |
da9559b49b84
6915557: assert(_gvn.type(l)->higher_equal(type),"must constrain OSR typestate") with debug build
never
parents:
1264
diff
changeset
|
342 // live into an OSR entry point because the compiler performs |
da9559b49b84
6915557: assert(_gvn.type(l)->higher_equal(type),"must constrain OSR typestate") with debug build
never
parents:
1264
diff
changeset
|
343 // inlining of jsrs. ciTypeFlow has a bailout that detect this |
da9559b49b84
6915557: assert(_gvn.type(l)->higher_equal(type),"must constrain OSR typestate") with debug build
never
parents:
1264
diff
changeset
|
344 // case and aborts the compile if addresses are live into an OSR |
da9559b49b84
6915557: assert(_gvn.type(l)->higher_equal(type),"must constrain OSR typestate") with debug build
never
parents:
1264
diff
changeset
|
345 // entry point. Because of that we can assume that any address |
da9559b49b84
6915557: assert(_gvn.type(l)->higher_equal(type),"must constrain OSR typestate") with debug build
never
parents:
1264
diff
changeset
|
346 // locals at the OSR entry point are dead. Method liveness |
da9559b49b84
6915557: assert(_gvn.type(l)->higher_equal(type),"must constrain OSR typestate") with debug build
never
parents:
1264
diff
changeset
|
347 // isn't precise enought to figure out that they are dead in all |
da9559b49b84
6915557: assert(_gvn.type(l)->higher_equal(type),"must constrain OSR typestate") with debug build
never
parents:
1264
diff
changeset
|
348 // cases so simply skip checking address locals all |
da9559b49b84
6915557: assert(_gvn.type(l)->higher_equal(type),"must constrain OSR typestate") with debug build
never
parents:
1264
diff
changeset
|
349 // together. Any type check is guaranteed to fail since the |
da9559b49b84
6915557: assert(_gvn.type(l)->higher_equal(type),"must constrain OSR typestate") with debug build
never
parents:
1264
diff
changeset
|
350 // interpreter type is the result of a load which might have any |
da9559b49b84
6915557: assert(_gvn.type(l)->higher_equal(type),"must constrain OSR typestate") with debug build
never
parents:
1264
diff
changeset
|
351 // value and the expected type is a constant. |
1070
87b2fdd4bf98
6892079: live value must not be garbage failure after fix for 6854812
never
parents:
991
diff
changeset
|
352 continue; |
87b2fdd4bf98
6892079: live value must not be garbage failure after fix for 6854812
never
parents:
991
diff
changeset
|
353 } |
0 | 354 set_local(index, check_interpreter_type(l, type, bad_type_exit)); |
355 } | |
356 | |
357 for (index = 0; index < sp(); index++) { | |
358 if (stopped()) break; | |
359 Node* l = stack(index); | |
360 if (l->is_top()) continue; // nothing here | |
361 const Type *type = osr_block->stack_type_at(index); | |
362 set_stack(index, check_interpreter_type(l, type, bad_type_exit)); | |
363 } | |
364 | |
365 if (bad_type_exit->control()->req() > 1) { | |
366 // Build an uncommon trap here, if any inputs can be unexpected. | |
367 bad_type_exit->set_control(_gvn.transform( bad_type_exit->control() )); | |
368 record_for_igvn(bad_type_exit->control()); | |
369 SafePointNode* types_are_good = map(); | |
370 set_map(bad_type_exit); | |
371 // The unexpected type happens because a new edge is active | |
372 // in the CFG, which typeflow had previously ignored. | |
373 // E.g., Object x = coldAtFirst() && notReached()? "str": new Integer(123). | |
374 // This x will be typed as Integer if notReached is not yet linked. | |
6824
f13867c41f73
7199742: A lot of C2 OSR compilations of the same method's bci
kvn
parents:
6804
diff
changeset
|
375 // It could also happen due to a problem in ciTypeFlow analysis. |
f13867c41f73
7199742: A lot of C2 OSR compilations of the same method's bci
kvn
parents:
6804
diff
changeset
|
376 uncommon_trap(Deoptimization::Reason_constraint, |
0 | 377 Deoptimization::Action_reinterpret); |
378 set_map(types_are_good); | |
379 } | |
380 } | |
381 | |
382 //------------------------------Parse------------------------------------------ | |
383 // Main parser constructor. | |
12956
3213ba4d3dff
8024069: replace_in_map() should operate on parent maps
roland
parents:
10278
diff
changeset
|
384 Parse::Parse(JVMState* caller, ciMethod* parse_method, float expected_uses, Parse* parent) |
3213ba4d3dff
8024069: replace_in_map() should operate on parent maps
roland
parents:
10278
diff
changeset
|
385 : _exits(caller), _parent(parent) |
0 | 386 { |
387 // Init some variables | |
388 _caller = caller; | |
389 _method = parse_method; | |
390 _expected_uses = expected_uses; | |
391 _depth = 1 + (caller->has_method() ? caller->depth() : 0); | |
392 _wrote_final = false; | |
10278 | 393 _alloc_with_final = NULL; |
0 | 394 _entry_bci = InvocationEntryBci; |
395 _tf = NULL; | |
396 _block = NULL; | |
397 debug_only(_block_count = -1); | |
398 debug_only(_blocks = (Block*)-1); | |
399 #ifndef PRODUCT | |
400 if (PrintCompilation || PrintOpto) { | |
401 // Make sure I have an inline tree, so I can print messages about it. | |
402 JVMState* ilt_caller = is_osr_parse() ? caller->caller() : caller; | |
6266
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
4790
diff
changeset
|
403 InlineTree::find_subtree_from_root(C->ilt(), ilt_caller, parse_method); |
0 | 404 } |
405 _max_switch_depth = 0; | |
406 _est_switch_depth = 0; | |
407 #endif | |
408 | |
409 _tf = TypeFunc::make(method()); | |
410 _iter.reset_to_method(method()); | |
411 _flow = method()->get_flow_analysis(); | |
412 if (_flow->failing()) { | |
413 C->record_method_not_compilable_all_tiers(_flow->failure_reason()); | |
414 } | |
415 | |
367
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
416 #ifndef PRODUCT |
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
417 if (_flow->has_irreducible_entry()) { |
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
418 C->set_parsed_irreducible_loop(true); |
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
419 } |
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
420 #endif |
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
421 |
0 | 422 if (_expected_uses <= 0) { |
423 _prof_factor = 1; | |
424 } else { | |
425 float prof_total = parse_method->interpreter_invocation_count(); | |
426 if (prof_total <= _expected_uses) { | |
427 _prof_factor = 1; | |
428 } else { | |
429 _prof_factor = _expected_uses / prof_total; | |
430 } | |
431 } | |
432 | |
433 CompileLog* log = C->log(); | |
434 if (log != NULL) { | |
435 log->begin_head("parse method='%d' uses='%g'", | |
436 log->identify(parse_method), expected_uses); | |
437 if (depth() == 1 && C->is_osr_compilation()) { | |
438 log->print(" osr_bci='%d'", C->entry_bci()); | |
439 } | |
440 log->stamp(); | |
441 log->end_head(); | |
442 } | |
443 | |
444 // Accumulate deoptimization counts. | |
445 // (The range_check and store_check counts are checked elsewhere.) | |
446 ciMethodData* md = method()->method_data(); | |
447 for (uint reason = 0; reason < md->trap_reason_limit(); reason++) { | |
448 uint md_count = md->trap_count(reason); | |
449 if (md_count != 0) { | |
450 if (md_count == md->trap_count_limit()) | |
451 md_count += md->overflow_trap_count(); | |
452 uint total_count = C->trap_count(reason); | |
453 uint old_count = total_count; | |
454 total_count += md_count; | |
455 // Saturate the add if it overflows. | |
456 if (total_count < old_count || total_count < md_count) | |
457 total_count = (uint)-1; | |
458 C->set_trap_count(reason, total_count); | |
459 if (log != NULL) | |
460 log->elem("observe trap='%s' count='%d' total='%d'", | |
461 Deoptimization::trap_reason_name(reason), | |
462 md_count, total_count); | |
463 } | |
464 } | |
465 // Accumulate total sum of decompilations, also. | |
466 C->set_decompile_count(C->decompile_count() + md->decompile_count()); | |
467 | |
468 _count_invocations = C->do_count_invocations(); | |
469 _method_data_update = C->do_method_data_update(); | |
470 | |
471 if (log != NULL && method()->has_exception_handlers()) { | |
472 log->elem("observe that='has_exception_handlers'"); | |
473 } | |
474 | |
475 assert(method()->can_be_compiled(), "Can not parse this method, cutout earlier"); | |
476 assert(method()->has_balanced_monitors(), "Can not parse unbalanced monitors, cutout earlier"); | |
477 | |
478 // Always register dependence if JVMTI is enabled, because | |
479 // either breakpoint setting or hotswapping of methods may | |
480 // cause deoptimization. | |
780
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
726
diff
changeset
|
481 if (C->env()->jvmti_can_hotswap_or_post_breakpoint()) { |
0 | 482 C->dependencies()->assert_evol_method(method()); |
483 } | |
484 | |
485 methods_seen++; | |
486 | |
487 // Do some special top-level things. | |
488 if (depth() == 1 && C->is_osr_compilation()) { | |
489 _entry_bci = C->entry_bci(); | |
490 _flow = method()->get_osr_flow_analysis(osr_bci()); | |
491 if (_flow->failing()) { | |
492 C->record_method_not_compilable(_flow->failure_reason()); | |
493 #ifndef PRODUCT | |
494 if (PrintOpto && (Verbose || WizardMode)) { | |
495 tty->print_cr("OSR @%d type flow bailout: %s", _entry_bci, _flow->failure_reason()); | |
496 if (Verbose) { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6268
diff
changeset
|
497 method()->print(); |
0 | 498 method()->print_codes(); |
499 _flow->print(); | |
500 } | |
501 } | |
502 #endif | |
503 } | |
504 _tf = C->tf(); // the OSR entry type is different | |
505 } | |
506 | |
507 #ifdef ASSERT | |
508 if (depth() == 1) { | |
509 assert(C->is_osr_compilation() == this->is_osr_parse(), "OSR in sync"); | |
510 if (C->tf() != tf()) { | |
511 MutexLockerEx ml(Compile_lock, Mutex::_no_safepoint_check_flag); | |
512 assert(C->env()->system_dictionary_modification_counter_changed(), | |
513 "Must invalidate if TypeFuncs differ"); | |
514 } | |
515 } else { | |
516 assert(!this->is_osr_parse(), "no recursive OSR"); | |
517 } | |
518 #endif | |
519 | |
520 methods_parsed++; | |
521 #ifndef PRODUCT | |
522 // add method size here to guarantee that inlined methods are added too | |
523 if (TimeCompiler) | |
524 _total_bytes_compiled += method()->code_size(); | |
525 | |
526 show_parse_info(); | |
527 #endif | |
528 | |
529 if (failing()) { | |
530 if (log) log->done("parse"); | |
531 return; | |
532 } | |
533 | |
534 gvn().set_type(root(), root()->bottom_type()); | |
535 gvn().transform(top()); | |
536 | |
537 // Import the results of the ciTypeFlow. | |
538 init_blocks(); | |
539 | |
540 // Merge point for all normal exits | |
541 build_exits(); | |
542 | |
543 // Setup the initial JVM state map. | |
544 SafePointNode* entry_map = create_entry_map(); | |
545 | |
546 // Check for bailouts during map initialization | |
547 if (failing() || entry_map == NULL) { | |
548 if (log) log->done("parse"); | |
549 return; | |
550 } | |
551 | |
552 Node_Notes* caller_nn = C->default_node_notes(); | |
553 // Collect debug info for inlined calls unless -XX:-DebugInlinedCalls. | |
554 if (DebugInlinedCalls || depth() == 1) { | |
555 C->set_default_node_notes(make_node_notes(caller_nn)); | |
556 } | |
557 | |
558 if (is_osr_parse()) { | |
559 Node* osr_buf = entry_map->in(TypeFunc::Parms+0); | |
560 entry_map->set_req(TypeFunc::Parms+0, top()); | |
561 set_map(entry_map); | |
562 load_interpreter_state(osr_buf); | |
563 } else { | |
564 set_map(entry_map); | |
565 do_method_entry(); | |
566 } | |
17780 | 567 if (depth() == 1) { |
568 // Add check to deoptimize the nmethod if RTM state was changed | |
569 rtm_deopt(); | |
570 } | |
0 | 571 |
572 // Check for bailouts during method entry. | |
573 if (failing()) { | |
574 if (log) log->done("parse"); | |
575 C->set_default_node_notes(caller_nn); | |
576 return; | |
577 } | |
578 | |
579 entry_map = map(); // capture any changes performed by method setup code | |
580 assert(jvms()->endoff() == map()->req(), "map matches JVMS layout"); | |
581 | |
582 // We begin parsing as if we have just encountered a jump to the | |
583 // method entry. | |
584 Block* entry_block = start_block(); | |
585 assert(entry_block->start() == (is_osr_parse() ? osr_bci() : 0), ""); | |
586 set_map_clone(entry_map); | |
587 merge_common(entry_block, entry_block->next_path_num()); | |
588 | |
589 #ifndef PRODUCT | |
590 BytecodeParseHistogram *parse_histogram_obj = new (C->env()->arena()) BytecodeParseHistogram(this, C); | |
591 set_parse_histogram( parse_histogram_obj ); | |
592 #endif | |
593 | |
594 // Parse all the basic blocks. | |
595 do_all_blocks(); | |
596 | |
597 C->set_default_node_notes(caller_nn); | |
598 | |
599 // Check for bailouts during conversion to graph | |
600 if (failing()) { | |
601 if (log) log->done("parse"); | |
602 return; | |
603 } | |
604 | |
605 // Fix up all exiting control flow. | |
606 set_map(entry_map); | |
607 do_exits(); | |
608 | |
7196
2aff40cb4703
7092905: C2: Keep track of the number of dead nodes
bharadwaj
parents:
7194
diff
changeset
|
609 if (log) log->done("parse nodes='%d' live='%d' memory='%d'", |
2aff40cb4703
7092905: C2: Keep track of the number of dead nodes
bharadwaj
parents:
7194
diff
changeset
|
610 C->unique(), C->live_nodes(), C->node_arena()->used()); |
0 | 611 } |
612 | |
613 //---------------------------do_all_blocks------------------------------------- | |
614 void Parse::do_all_blocks() { | |
367
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
615 bool has_irreducible = flow()->has_irreducible_entry(); |
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
616 |
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
617 // Walk over all blocks in Reverse Post-Order. |
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
618 while (true) { |
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
619 bool progress = false; |
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
620 for (int rpo = 0; rpo < block_count(); rpo++) { |
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
621 Block* block = rpo_at(rpo); |
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
622 |
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
623 if (block->is_parsed()) continue; |
0 | 624 |
367
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
625 if (!block->is_merged()) { |
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
626 // Dead block, no state reaches this block |
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
627 continue; |
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
628 } |
0 | 629 |
367
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
630 // Prepare to parse this block. |
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
631 load_state_from(block); |
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
632 |
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
633 if (stopped()) { |
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
634 // Block is dead. |
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
635 continue; |
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
636 } |
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
637 |
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
638 blocks_parsed++; |
0 | 639 |
367
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
640 progress = true; |
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
641 if (block->is_loop_head() || block->is_handler() || has_irreducible && !block->is_ready()) { |
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
642 // Not all preds have been parsed. We must build phis everywhere. |
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
643 // (Note that dead locals do not get phis built, ever.) |
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
644 ensure_phis_everywhere(); |
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
645 |
2383
9dc311b8473e
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
1972
diff
changeset
|
646 if (block->is_SEL_head() && |
3345 | 647 (UseLoopPredicate || LoopLimitCheck)) { |
2383
9dc311b8473e
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
1972
diff
changeset
|
648 // Add predicate to single entry (not irreducible) loop head. |
9dc311b8473e
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
1972
diff
changeset
|
649 assert(!block->has_merged_backedge(), "only entry paths should be merged for now"); |
9dc311b8473e
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
1972
diff
changeset
|
650 // Need correct bci for predicate. |
9dc311b8473e
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
1972
diff
changeset
|
651 // It is fine to set it here since do_one_block() will set it anyway. |
9dc311b8473e
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
1972
diff
changeset
|
652 set_parse_bci(block->start()); |
9dc311b8473e
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
1972
diff
changeset
|
653 add_predicate(); |
9dc311b8473e
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
1972
diff
changeset
|
654 // Add new region for back branches. |
9dc311b8473e
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
1972
diff
changeset
|
655 int edges = block->pred_count() - block->preds_parsed() + 1; // +1 for original region |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
656 RegionNode *r = new (C) RegionNode(edges+1); |
2383
9dc311b8473e
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
1972
diff
changeset
|
657 _gvn.set_type(r, Type::CONTROL); |
9dc311b8473e
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
1972
diff
changeset
|
658 record_for_igvn(r); |
9dc311b8473e
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
1972
diff
changeset
|
659 r->init_req(edges, control()); |
9dc311b8473e
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
1972
diff
changeset
|
660 set_control(r); |
9dc311b8473e
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
1972
diff
changeset
|
661 // Add new phis. |
9dc311b8473e
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
1972
diff
changeset
|
662 ensure_phis_everywhere(); |
9dc311b8473e
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
1972
diff
changeset
|
663 } |
9dc311b8473e
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
1972
diff
changeset
|
664 |
367
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
665 // Leave behind an undisturbed copy of the map, for future merges. |
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
666 set_map(clone_map()); |
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
667 } |
0 | 668 |
367
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
669 if (control()->is_Region() && !block->is_loop_head() && !has_irreducible && !block->is_handler()) { |
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
670 // In the absence of irreducible loops, the Region and Phis |
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
671 // associated with a merge that doesn't involve a backedge can |
605 | 672 // be simplified now since the RPO parsing order guarantees |
367
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
673 // that any path which was supposed to reach here has already |
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
674 // been parsed or must be dead. |
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
675 Node* c = control(); |
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
676 Node* result = _gvn.transform_no_reclaim(control()); |
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
677 if (c != result && TraceOptoParse) { |
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
678 tty->print_cr("Block #%d replace %d with %d", block->rpo(), c->_idx, result->_idx); |
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
679 } |
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
680 if (result != top()) { |
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
681 record_for_igvn(result); |
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
682 } |
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
683 } |
0 | 684 |
367
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
685 // Parse the block. |
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
686 do_one_block(); |
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
687 |
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
688 // Check for bailouts. |
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
689 if (failing()) return; |
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
690 } |
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
691 |
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
692 // with irreducible loops multiple passes might be necessary to parse everything |
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
693 if (!has_irreducible || !progress) { |
0 | 694 break; |
695 } | |
367
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
696 } |
0 | 697 |
367
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
698 blocks_seen += block_count(); |
0 | 699 |
700 #ifndef PRODUCT | |
701 // Make sure there are no half-processed blocks remaining. | |
702 // Every remaining unprocessed block is dead and may be ignored now. | |
367
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
703 for (int rpo = 0; rpo < block_count(); rpo++) { |
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
704 Block* block = rpo_at(rpo); |
0 | 705 if (!block->is_parsed()) { |
706 if (TraceOptoParse) { | |
367
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
707 tty->print_cr("Skipped dead block %d at bci:%d", rpo, block->start()); |
0 | 708 } |
367
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
709 assert(!block->is_merged(), "no half-processed blocks"); |
0 | 710 } |
711 } | |
712 #endif | |
713 } | |
714 | |
715 //-------------------------------build_exits---------------------------------- | |
716 // Build normal and exceptional exit merge points. | |
717 void Parse::build_exits() { | |
718 // make a clone of caller to prevent sharing of side-effects | |
719 _exits.set_map(_exits.clone_map()); | |
720 _exits.clean_stack(_exits.sp()); | |
721 _exits.sync_jvms(); | |
722 | |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
723 RegionNode* region = new (C) RegionNode(1); |
0 | 724 record_for_igvn(region); |
725 gvn().set_type_bottom(region); | |
726 _exits.set_control(region); | |
727 | |
728 // Note: iophi and memphi are not transformed until do_exits. | |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
729 Node* iophi = new (C) PhiNode(region, Type::ABIO); |
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
730 Node* memphi = new (C) PhiNode(region, Type::MEMORY, TypePtr::BOTTOM); |
10278 | 731 gvn().set_type_bottom(iophi); |
732 gvn().set_type_bottom(memphi); | |
0 | 733 _exits.set_i_o(iophi); |
734 _exits.set_all_memory(memphi); | |
735 | |
736 // Add a return value to the exit state. (Do not push it yet.) | |
737 if (tf()->range()->cnt() > TypeFunc::Parms) { | |
738 const Type* ret_type = tf()->range()->field_at(TypeFunc::Parms); | |
739 // Don't "bind" an unloaded return klass to the ret_phi. If the klass | |
740 // becomes loaded during the subsequent parsing, the loaded and unloaded | |
741 // types will not join when we transform and push in do_exits(). | |
742 const TypeOopPtr* ret_oop_type = ret_type->isa_oopptr(); | |
743 if (ret_oop_type && !ret_oop_type->klass()->is_loaded()) { | |
744 ret_type = TypeOopPtr::BOTTOM; | |
745 } | |
746 int ret_size = type2size[ret_type->basic_type()]; | |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
747 Node* ret_phi = new (C) PhiNode(region, ret_type); |
10278 | 748 gvn().set_type_bottom(ret_phi); |
0 | 749 _exits.ensure_stack(ret_size); |
750 assert((int)(tf()->range()->cnt() - TypeFunc::Parms) == ret_size, "good tf range"); | |
751 assert(method()->return_type()->size() == ret_size, "tf agrees w/ method"); | |
752 _exits.set_argument(0, ret_phi); // here is where the parser finds it | |
753 // Note: ret_phi is not yet pushed, until do_exits. | |
754 } | |
755 } | |
756 | |
757 | |
758 //----------------------------build_start_state------------------------------- | |
759 // Construct a state which contains only the incoming arguments from an | |
760 // unknown caller. The method & bci will be NULL & InvocationEntryBci. | |
761 JVMState* Compile::build_start_state(StartNode* start, const TypeFunc* tf) { | |
762 int arg_size = tf->domain()->cnt(); | |
763 int max_size = MAX2(arg_size, (int)tf->range()->cnt()); | |
764 JVMState* jvms = new (this) JVMState(max_size - TypeFunc::Parms); | |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
765 SafePointNode* map = new (this) SafePointNode(max_size, NULL); |
0 | 766 record_for_igvn(map); |
767 assert(arg_size == TypeFunc::Parms + (is_osr_compilation() ? 1 : method()->arg_size()), "correct arg_size"); | |
768 Node_Notes* old_nn = default_node_notes(); | |
769 if (old_nn != NULL && has_method()) { | |
770 Node_Notes* entry_nn = old_nn->clone(this); | |
771 JVMState* entry_jvms = new(this) JVMState(method(), old_nn->jvms()); | |
772 entry_jvms->set_offsets(0); | |
773 entry_jvms->set_bci(entry_bci()); | |
774 entry_nn->set_jvms(entry_jvms); | |
775 set_default_node_notes(entry_nn); | |
776 } | |
777 uint i; | |
778 for (i = 0; i < (uint)arg_size; i++) { | |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
779 Node* parm = initial_gvn()->transform(new (this) ParmNode(start, i)); |
0 | 780 map->init_req(i, parm); |
781 // Record all these guys for later GVN. | |
782 record_for_igvn(parm); | |
783 } | |
784 for (; i < map->req(); i++) { | |
785 map->init_req(i, top()); | |
786 } | |
787 assert(jvms->argoff() == TypeFunc::Parms, "parser gets arguments here"); | |
788 set_default_node_notes(old_nn); | |
789 map->set_jvms(jvms); | |
790 jvms->set_map(map); | |
791 return jvms; | |
792 } | |
793 | |
794 //-----------------------------make_node_notes--------------------------------- | |
795 Node_Notes* Parse::make_node_notes(Node_Notes* caller_nn) { | |
796 if (caller_nn == NULL) return NULL; | |
797 Node_Notes* nn = caller_nn->clone(C); | |
798 JVMState* caller_jvms = nn->jvms(); | |
799 JVMState* jvms = new (C) JVMState(method(), caller_jvms); | |
800 jvms->set_offsets(0); | |
801 jvms->set_bci(_entry_bci); | |
802 nn->set_jvms(jvms); | |
803 return nn; | |
804 } | |
805 | |
806 | |
807 //--------------------------return_values-------------------------------------- | |
808 void Compile::return_values(JVMState* jvms) { | |
809 GraphKit kit(jvms); | |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
810 Node* ret = new (this) ReturnNode(TypeFunc::Parms, |
0 | 811 kit.control(), |
812 kit.i_o(), | |
813 kit.reset_memory(), | |
814 kit.frameptr(), | |
815 kit.returnadr()); | |
816 // Add zero or 1 return values | |
817 int ret_size = tf()->range()->cnt() - TypeFunc::Parms; | |
818 if (ret_size > 0) { | |
819 kit.inc_sp(-ret_size); // pop the return value(s) | |
820 kit.sync_jvms(); | |
821 ret->add_req(kit.argument(0)); | |
822 // Note: The second dummy edge is not needed by a ReturnNode. | |
823 } | |
824 // bind it to root | |
825 root()->add_req(ret); | |
826 record_for_igvn(ret); | |
827 initial_gvn()->transform_no_reclaim(ret); | |
828 } | |
829 | |
830 //------------------------rethrow_exceptions----------------------------------- | |
831 // Bind all exception states in the list into a single RethrowNode. | |
832 void Compile::rethrow_exceptions(JVMState* jvms) { | |
833 GraphKit kit(jvms); | |
834 if (!kit.has_exceptions()) return; // nothing to generate | |
835 // Load my combined exception state into the kit, with all phis transformed: | |
836 SafePointNode* ex_map = kit.combine_and_pop_all_exception_states(); | |
837 Node* ex_oop = kit.use_exception_state(ex_map); | |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
838 RethrowNode* exit = new (this) RethrowNode(kit.control(), |
0 | 839 kit.i_o(), kit.reset_memory(), |
840 kit.frameptr(), kit.returnadr(), | |
841 // like a return but with exception input | |
842 ex_oop); | |
843 // bind to root | |
844 root()->add_req(exit); | |
845 record_for_igvn(exit); | |
846 initial_gvn()->transform_no_reclaim(exit); | |
847 } | |
848 | |
849 //---------------------------do_exceptions------------------------------------- | |
850 // Process exceptions arising from the current bytecode. | |
851 // Send caught exceptions to the proper handler within this method. | |
852 // Unhandled exceptions feed into _exit. | |
853 void Parse::do_exceptions() { | |
854 if (!has_exceptions()) return; | |
855 | |
856 if (failing()) { | |
857 // Pop them all off and throw them away. | |
858 while (pop_exception_state() != NULL) ; | |
859 return; | |
860 } | |
861 | |
862 PreserveJVMState pjvms(this, false); | |
863 | |
864 SafePointNode* ex_map; | |
865 while ((ex_map = pop_exception_state()) != NULL) { | |
866 if (!method()->has_exception_handlers()) { | |
867 // Common case: Transfer control outward. | |
868 // Doing it this early allows the exceptions to common up | |
869 // even between adjacent method calls. | |
870 throw_to_exit(ex_map); | |
871 } else { | |
872 // Have to look at the exception first. | |
873 assert(stopped(), "catch_inline_exceptions trashes the map"); | |
874 catch_inline_exceptions(ex_map); | |
875 stop_and_kill_map(); // we used up this exception state; kill it | |
876 } | |
877 } | |
878 | |
879 // We now return to our regularly scheduled program: | |
880 } | |
881 | |
882 //---------------------------throw_to_exit------------------------------------- | |
883 // Merge the given map into an exception exit from this method. | |
884 // The exception exit will handle any unlocking of receiver. | |
885 // The ex_oop must be saved within the ex_map, unlike merge_exception. | |
886 void Parse::throw_to_exit(SafePointNode* ex_map) { | |
887 // Pop the JVMS to (a copy of) the caller. | |
888 GraphKit caller; | |
889 caller.set_map_clone(_caller->map()); | |
890 caller.set_bci(_caller->bci()); | |
891 caller.set_sp(_caller->sp()); | |
892 // Copy out the standard machine state: | |
893 for (uint i = 0; i < TypeFunc::Parms; i++) { | |
894 caller.map()->set_req(i, ex_map->in(i)); | |
895 } | |
896 // ...and the exception: | |
897 Node* ex_oop = saved_ex_oop(ex_map); | |
898 SafePointNode* caller_ex_map = caller.make_exception_state(ex_oop); | |
899 // Finally, collect the new exception state in my exits: | |
900 _exits.add_exception_state(caller_ex_map); | |
901 } | |
902 | |
903 //------------------------------do_exits--------------------------------------- | |
904 void Parse::do_exits() { | |
905 set_parse_bci(InvocationEntryBci); | |
906 | |
907 // Now peephole on the return bits | |
908 Node* region = _exits.control(); | |
909 _exits.set_control(gvn().transform(region)); | |
910 | |
911 Node* iophi = _exits.i_o(); | |
912 _exits.set_i_o(gvn().transform(iophi)); | |
913 | |
914 if (wrote_final()) { | |
915 // This method (which must be a constructor by the rules of Java) | |
916 // wrote a final. The effects of all initializations must be | |
917 // committed to memory before any code after the constructor | |
918 // publishes the reference to the newly constructor object. | |
919 // Rather than wait for the publication, we simply block the | |
920 // writes here. Rather than put a barrier on only those writes | |
921 // which are required to complete, we force all writes to complete. | |
922 // | |
923 // "All bets are off" unless the first publication occurs after a | |
924 // normal return from the constructor. We do not attempt to detect | |
925 // such unusual early publications. But no barrier is needed on | |
926 // exceptional returns, since they cannot publish normally. | |
927 // | |
10278 | 928 _exits.insert_mem_bar(Op_MemBarRelease, alloc_with_final()); |
0 | 929 #ifndef PRODUCT |
930 if (PrintOpto && (Verbose || WizardMode)) { | |
931 method()->print_name(); | |
932 tty->print_cr(" writes finals and needs a memory barrier"); | |
933 } | |
934 #endif | |
935 } | |
936 | |
937 for (MergeMemStream mms(_exits.merged_memory()); mms.next_non_empty(); ) { | |
938 // transform each slice of the original memphi: | |
939 mms.set_memory(_gvn.transform(mms.memory())); | |
940 } | |
941 | |
942 if (tf()->range()->cnt() > TypeFunc::Parms) { | |
943 const Type* ret_type = tf()->range()->field_at(TypeFunc::Parms); | |
944 Node* ret_phi = _gvn.transform( _exits.argument(0) ); | |
945 assert(_exits.control()->is_top() || !_gvn.type(ret_phi)->empty(), "return value must be well defined"); | |
946 _exits.push_node(ret_type->basic_type(), ret_phi); | |
947 } | |
948 | |
949 // Note: Logic for creating and optimizing the ReturnNode is in Compile. | |
950 | |
951 // Unlock along the exceptional paths. | |
952 // This is done late so that we can common up equivalent exceptions | |
953 // (e.g., null checks) arising from multiple points within this method. | |
954 // See GraphKit::add_exception_state, which performs the commoning. | |
955 bool do_synch = method()->is_synchronized() && GenerateSynchronizationCode; | |
956 | |
957 // record exit from a method if compiled while Dtrace is turned on. | |
780
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
726
diff
changeset
|
958 if (do_synch || C->env()->dtrace_method_probes()) { |
0 | 959 // First move the exception list out of _exits: |
960 GraphKit kit(_exits.transfer_exceptions_into_jvms()); | |
961 SafePointNode* normal_map = kit.map(); // keep this guy safe | |
962 // Now re-collect the exceptions into _exits: | |
963 SafePointNode* ex_map; | |
964 while ((ex_map = kit.pop_exception_state()) != NULL) { | |
965 Node* ex_oop = kit.use_exception_state(ex_map); | |
966 // Force the exiting JVM state to have this method at InvocationEntryBci. | |
967 // The exiting JVM state is otherwise a copy of the calling JVMS. | |
968 JVMState* caller = kit.jvms(); | |
969 JVMState* ex_jvms = caller->clone_shallow(C); | |
970 ex_jvms->set_map(kit.clone_map()); | |
971 ex_jvms->map()->set_jvms(ex_jvms); | |
972 ex_jvms->set_bci( InvocationEntryBci); | |
973 kit.set_jvms(ex_jvms); | |
974 if (do_synch) { | |
975 // Add on the synchronized-method box/object combo | |
976 kit.map()->push_monitor(_synch_lock); | |
977 // Unlock! | |
978 kit.shared_unlock(_synch_lock->box_node(), _synch_lock->obj_node()); | |
979 } | |
780
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
726
diff
changeset
|
980 if (C->env()->dtrace_method_probes()) { |
0 | 981 kit.make_dtrace_method_exit(method()); |
982 } | |
983 // Done with exception-path processing. | |
984 ex_map = kit.make_exception_state(ex_oop); | |
985 assert(ex_jvms->same_calls_as(ex_map->jvms()), "sanity"); | |
986 // Pop the last vestige of this method: | |
987 ex_map->set_jvms(caller->clone_shallow(C)); | |
988 ex_map->jvms()->set_map(ex_map); | |
989 _exits.push_exception_state(ex_map); | |
990 } | |
991 assert(_exits.map() == normal_map, "keep the same return state"); | |
992 } | |
993 | |
994 { | |
995 // Capture very early exceptions (receiver null checks) from caller JVMS | |
996 GraphKit caller(_caller); | |
997 SafePointNode* ex_map; | |
998 while ((ex_map = caller.pop_exception_state()) != NULL) { | |
999 _exits.add_exception_state(ex_map); | |
1000 } | |
1001 } | |
1002 } | |
1003 | |
1004 //-----------------------------create_entry_map------------------------------- | |
1005 // Initialize our parser map to contain the types at method entry. | |
1006 // For OSR, the map contains a single RawPtr parameter. | |
1007 // Initial monitor locking for sync. methods is performed by do_method_entry. | |
1008 SafePointNode* Parse::create_entry_map() { | |
1009 // Check for really stupid bail-out cases. | |
1010 uint len = TypeFunc::Parms + method()->max_locals() + method()->max_stack(); | |
1011 if (len >= 32760) { | |
1012 C->record_method_not_compilable_all_tiers("too many local variables"); | |
1013 return NULL; | |
1014 } | |
1015 | |
1016 // If this is an inlined method, we may have to do a receiver null check. | |
1017 if (_caller->has_method() && is_normal_parse() && !method()->is_static()) { | |
1018 GraphKit kit(_caller); | |
7194
beebba0acc11
7172640: C2: instrinsic implementations in LibraryCallKit should use argument() instead of pop()
twisti
parents:
6843
diff
changeset
|
1019 kit.null_check_receiver_before_call(method()); |
0 | 1020 _caller = kit.transfer_exceptions_into_jvms(); |
1021 if (kit.stopped()) { | |
1022 _exits.add_exception_states_from(_caller); | |
1023 _exits.set_jvms(_caller); | |
1024 return NULL; | |
1025 } | |
1026 } | |
1027 | |
1028 assert(method() != NULL, "parser must have a method"); | |
1029 | |
1030 // Create an initial safepoint to hold JVM state during parsing | |
1031 JVMState* jvms = new (C) JVMState(method(), _caller->has_method() ? _caller : NULL); | |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
1032 set_map(new (C) SafePointNode(len, jvms)); |
0 | 1033 jvms->set_map(map()); |
1034 record_for_igvn(map()); | |
1035 assert(jvms->endoff() == len, "correct jvms sizing"); | |
1036 | |
1037 SafePointNode* inmap = _caller->map(); | |
1038 assert(inmap != NULL, "must have inmap"); | |
1039 | |
1040 uint i; | |
1041 | |
1042 // Pass thru the predefined input parameters. | |
1043 for (i = 0; i < TypeFunc::Parms; i++) { | |
1044 map()->init_req(i, inmap->in(i)); | |
1045 } | |
1046 | |
1047 if (depth() == 1) { | |
1048 assert(map()->memory()->Opcode() == Op_Parm, ""); | |
1049 // Insert the memory aliasing node | |
1050 set_all_memory(reset_memory()); | |
1051 } | |
1052 assert(merged_memory(), ""); | |
1053 | |
1054 // Now add the locals which are initially bound to arguments: | |
1055 uint arg_size = tf()->domain()->cnt(); | |
1056 ensure_stack(arg_size - TypeFunc::Parms); // OSR methods have funny args | |
1057 for (i = TypeFunc::Parms; i < arg_size; i++) { | |
1058 map()->init_req(i, inmap->argument(_caller, i - TypeFunc::Parms)); | |
1059 } | |
1060 | |
1061 // Clear out the rest of the map (locals and stack) | |
1062 for (i = arg_size; i < len; i++) { | |
1063 map()->init_req(i, top()); | |
1064 } | |
1065 | |
1066 SafePointNode* entry_map = stop(); | |
1067 return entry_map; | |
1068 } | |
1069 | |
1070 //-----------------------------do_method_entry-------------------------------- | |
1071 // Emit any code needed in the pseudo-block before BCI zero. | |
1072 // The main thing to do is lock the receiver of a synchronized method. | |
1073 void Parse::do_method_entry() { | |
1074 set_parse_bci(InvocationEntryBci); // Pseudo-BCP | |
1075 set_sp(0); // Java Stack Pointer | |
1076 | |
1077 NOT_PRODUCT( count_compiled_calls(true/*at_method_entry*/, false/*is_inline*/); ) | |
1078 | |
780
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
726
diff
changeset
|
1079 if (C->env()->dtrace_method_probes()) { |
0 | 1080 make_dtrace_method_entry(method()); |
1081 } | |
1082 | |
1083 // If the method is synchronized, we need to construct a lock node, attach | |
1084 // it to the Start node, and pin it there. | |
1085 if (method()->is_synchronized()) { | |
1086 // Insert a FastLockNode right after the Start which takes as arguments | |
1087 // the current thread pointer, the "this" pointer & the address of the | |
1088 // stack slot pair used for the lock. The "this" pointer is a projection | |
1089 // off the start node, but the locking spot has to be constructed by | |
1090 // creating a ConLNode of 0, and boxing it with a BoxLockNode. The BoxLockNode | |
1091 // becomes the second argument to the FastLockNode call. The | |
1092 // FastLockNode becomes the new control parent to pin it to the start. | |
1093 | |
1094 // Setup Object Pointer | |
1095 Node *lock_obj = NULL; | |
1096 if(method()->is_static()) { | |
1097 ciInstance* mirror = _method->holder()->java_mirror(); | |
1098 const TypeInstPtr *t_lock = TypeInstPtr::make(mirror); | |
1099 lock_obj = makecon(t_lock); | |
1100 } else { // Else pass the "this" pointer, | |
1101 lock_obj = local(0); // which is Parm0 from StartNode | |
1102 } | |
1103 // Clear out dead values from the debug info. | |
1104 kill_dead_locals(); | |
1105 // Build the FastLockNode | |
1106 _synch_lock = shared_lock(lock_obj); | |
1107 } | |
1108 | |
12966 | 1109 // Feed profiling data for parameters to the type system so it can |
1110 // propagate it as speculative types | |
1111 record_profiled_parameters_for_speculation(); | |
1112 | |
0 | 1113 if (depth() == 1) { |
1114 increment_and_test_invocation_counter(Tier2CompileThreshold); | |
1115 } | |
1116 } | |
1117 | |
1118 //------------------------------init_blocks------------------------------------ | |
1119 // Initialize our parser map to contain the types/monitors at method entry. | |
1120 void Parse::init_blocks() { | |
1121 // Create the blocks. | |
1122 _block_count = flow()->block_count(); | |
1123 _blocks = NEW_RESOURCE_ARRAY(Block, _block_count); | |
1124 Copy::zero_to_bytes(_blocks, sizeof(Block)*_block_count); | |
1125 | |
367
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
1126 int rpo; |
0 | 1127 |
1128 // Initialize the structs. | |
367
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
1129 for (rpo = 0; rpo < block_count(); rpo++) { |
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
1130 Block* block = rpo_at(rpo); |
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
1131 block->init_node(this, rpo); |
0 | 1132 } |
1133 | |
1134 // Collect predecessor and successor information. | |
367
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
1135 for (rpo = 0; rpo < block_count(); rpo++) { |
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
1136 Block* block = rpo_at(rpo); |
0 | 1137 block->init_graph(this); |
1138 } | |
1139 } | |
1140 | |
1141 //-------------------------------init_node------------------------------------- | |
367
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
1142 void Parse::Block::init_node(Parse* outer, int rpo) { |
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
1143 _flow = outer->flow()->rpo_at(rpo); |
0 | 1144 _pred_count = 0; |
1145 _preds_parsed = 0; | |
1146 _count = 0; | |
1147 assert(pred_count() == 0 && preds_parsed() == 0, "sanity"); | |
2383
9dc311b8473e
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
1972
diff
changeset
|
1148 assert(!(is_merged() || is_parsed() || is_handler() || has_merged_backedge()), "sanity"); |
0 | 1149 assert(_live_locals.size() == 0, "sanity"); |
1150 | |
1151 // entry point has additional predecessor | |
1152 if (flow()->is_start()) _pred_count++; | |
1153 assert(flow()->is_start() == (this == outer->start_block()), ""); | |
1154 } | |
1155 | |
1156 //-------------------------------init_graph------------------------------------ | |
1157 void Parse::Block::init_graph(Parse* outer) { | |
1158 // Create the successor list for this parser block. | |
1159 GrowableArray<ciTypeFlow::Block*>* tfs = flow()->successors(); | |
1160 GrowableArray<ciTypeFlow::Block*>* tfe = flow()->exceptions(); | |
1161 int ns = tfs->length(); | |
1162 int ne = tfe->length(); | |
1163 _num_successors = ns; | |
1164 _all_successors = ns+ne; | |
1165 _successors = (ns+ne == 0) ? NULL : NEW_RESOURCE_ARRAY(Block*, ns+ne); | |
1166 int p = 0; | |
1167 for (int i = 0; i < ns+ne; i++) { | |
1168 ciTypeFlow::Block* tf2 = (i < ns) ? tfs->at(i) : tfe->at(i-ns); | |
367
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
1169 Block* block2 = outer->rpo_at(tf2->rpo()); |
0 | 1170 _successors[i] = block2; |
1171 | |
1172 // Accumulate pred info for the other block, too. | |
1173 if (i < ns) { | |
1174 block2->_pred_count++; | |
1175 } else { | |
1176 block2->_is_handler = true; | |
1177 } | |
1178 | |
1179 #ifdef ASSERT | |
1180 // A block's successors must be distinguishable by BCI. | |
1181 // That is, no bytecode is allowed to branch to two different | |
1182 // clones of the same code location. | |
1183 for (int j = 0; j < i; j++) { | |
1184 Block* block1 = _successors[j]; | |
1185 if (block1 == block2) continue; // duplicates are OK | |
1186 assert(block1->start() != block2->start(), "successors have unique bcis"); | |
1187 } | |
1188 #endif | |
1189 } | |
1190 | |
1191 // Note: We never call next_path_num along exception paths, so they | |
1192 // never get processed as "ready". Also, the input phis of exception | |
1193 // handlers get specially processed, so that | |
1194 } | |
1195 | |
1196 //---------------------------successor_for_bci--------------------------------- | |
1197 Parse::Block* Parse::Block::successor_for_bci(int bci) { | |
1198 for (int i = 0; i < all_successors(); i++) { | |
1199 Block* block2 = successor_at(i); | |
1200 if (block2->start() == bci) return block2; | |
1201 } | |
1202 // We can actually reach here if ciTypeFlow traps out a block | |
1203 // due to an unloaded class, and concurrently with compilation the | |
1204 // class is then loaded, so that a later phase of the parser is | |
1205 // able to see more of the bytecode CFG. Or, the flow pass and | |
1206 // the parser can have a minor difference of opinion about executability | |
1207 // of bytecodes. For example, "obj.field = null" is executable even | |
1208 // if the field's type is an unloaded class; the flow pass used to | |
1209 // make a trap for such code. | |
1210 return NULL; | |
1211 } | |
1212 | |
1213 | |
1214 //-----------------------------stack_type_at----------------------------------- | |
1215 const Type* Parse::Block::stack_type_at(int i) const { | |
1216 return get_type(flow()->stack_type_at(i)); | |
1217 } | |
1218 | |
1219 | |
1220 //-----------------------------local_type_at----------------------------------- | |
1221 const Type* Parse::Block::local_type_at(int i) const { | |
1222 // Make dead locals fall to bottom. | |
1223 if (_live_locals.size() == 0) { | |
1224 MethodLivenessResult live_locals = flow()->outer()->method()->liveness_at_bci(start()); | |
1225 // This bitmap can be zero length if we saw a breakpoint. | |
1226 // In such cases, pretend they are all live. | |
1227 ((Block*)this)->_live_locals = live_locals; | |
1228 } | |
1229 if (_live_locals.size() > 0 && !_live_locals.at(i)) | |
1230 return Type::BOTTOM; | |
1231 | |
1232 return get_type(flow()->local_type_at(i)); | |
1233 } | |
1234 | |
1235 | |
1236 #ifndef PRODUCT | |
1237 | |
1238 //----------------------------name_for_bc-------------------------------------- | |
1239 // helper method for BytecodeParseHistogram | |
1240 static const char* name_for_bc(int i) { | |
1241 return Bytecodes::is_defined(i) ? Bytecodes::name(Bytecodes::cast(i)) : "xxxunusedxxx"; | |
1242 } | |
1243 | |
1244 //----------------------------BytecodeParseHistogram------------------------------------ | |
1245 Parse::BytecodeParseHistogram::BytecodeParseHistogram(Parse *p, Compile *c) { | |
1246 _parser = p; | |
1247 _compiler = c; | |
1248 if( ! _initialized ) { _initialized = true; reset(); } | |
1249 } | |
1250 | |
1251 //----------------------------current_count------------------------------------ | |
1252 int Parse::BytecodeParseHistogram::current_count(BPHType bph_type) { | |
1253 switch( bph_type ) { | |
1254 case BPH_transforms: { return _parser->gvn().made_progress(); } | |
1255 case BPH_values: { return _parser->gvn().made_new_values(); } | |
1256 default: { ShouldNotReachHere(); return 0; } | |
1257 } | |
1258 } | |
1259 | |
1260 //----------------------------initialized-------------------------------------- | |
1261 bool Parse::BytecodeParseHistogram::initialized() { return _initialized; } | |
1262 | |
1263 //----------------------------reset-------------------------------------------- | |
1264 void Parse::BytecodeParseHistogram::reset() { | |
1265 int i = Bytecodes::number_of_codes; | |
1266 while (i-- > 0) { _bytecodes_parsed[i] = 0; _nodes_constructed[i] = 0; _nodes_transformed[i] = 0; _new_values[i] = 0; } | |
1267 } | |
1268 | |
1269 //----------------------------set_initial_state-------------------------------- | |
1270 // Record info when starting to parse one bytecode | |
1271 void Parse::BytecodeParseHistogram::set_initial_state( Bytecodes::Code bc ) { | |
1272 if( PrintParseStatistics && !_parser->is_osr_parse() ) { | |
1273 _initial_bytecode = bc; | |
1274 _initial_node_count = _compiler->unique(); | |
1275 _initial_transforms = current_count(BPH_transforms); | |
1276 _initial_values = current_count(BPH_values); | |
1277 } | |
1278 } | |
1279 | |
1280 //----------------------------record_change-------------------------------- | |
1281 // Record results of parsing one bytecode | |
1282 void Parse::BytecodeParseHistogram::record_change() { | |
1283 if( PrintParseStatistics && !_parser->is_osr_parse() ) { | |
1284 ++_bytecodes_parsed[_initial_bytecode]; | |
1285 _nodes_constructed [_initial_bytecode] += (_compiler->unique() - _initial_node_count); | |
1286 _nodes_transformed [_initial_bytecode] += (current_count(BPH_transforms) - _initial_transforms); | |
1287 _new_values [_initial_bytecode] += (current_count(BPH_values) - _initial_values); | |
1288 } | |
1289 } | |
1290 | |
1291 | |
1292 //----------------------------print-------------------------------------------- | |
1293 void Parse::BytecodeParseHistogram::print(float cutoff) { | |
1294 ResourceMark rm; | |
1295 // print profile | |
1296 int total = 0; | |
1297 int i = 0; | |
1298 for( i = 0; i < Bytecodes::number_of_codes; ++i ) { total += _bytecodes_parsed[i]; } | |
1299 int abs_sum = 0; | |
1300 tty->cr(); //0123456789012345678901234567890123456789012345678901234567890123456789 | |
1301 tty->print_cr("Histogram of %d parsed bytecodes:", total); | |
1302 if( total == 0 ) { return; } | |
1303 tty->cr(); | |
1304 tty->print_cr("absolute: count of compiled bytecodes of this type"); | |
1305 tty->print_cr("relative: percentage contribution to compiled nodes"); | |
1306 tty->print_cr("nodes : Average number of nodes constructed per bytecode"); | |
1307 tty->print_cr("rnodes : Significance towards total nodes constructed, (nodes*relative)"); | |
1308 tty->print_cr("transforms: Average amount of tranform progress per bytecode compiled"); | |
1309 tty->print_cr("values : Average number of node values improved per bytecode"); | |
1310 tty->print_cr("name : Bytecode name"); | |
1311 tty->cr(); | |
1312 tty->print_cr(" absolute relative nodes rnodes transforms values name"); | |
1313 tty->print_cr("----------------------------------------------------------------------"); | |
1314 while (--i > 0) { | |
1315 int abs = _bytecodes_parsed[i]; | |
1316 float rel = abs * 100.0F / total; | |
1317 float nodes = _bytecodes_parsed[i] == 0 ? 0 : (1.0F * _nodes_constructed[i])/_bytecodes_parsed[i]; | |
1318 float rnodes = _bytecodes_parsed[i] == 0 ? 0 : rel * nodes; | |
1319 float xforms = _bytecodes_parsed[i] == 0 ? 0 : (1.0F * _nodes_transformed[i])/_bytecodes_parsed[i]; | |
1320 float values = _bytecodes_parsed[i] == 0 ? 0 : (1.0F * _new_values [i])/_bytecodes_parsed[i]; | |
1321 if (cutoff <= rel) { | |
1322 tty->print_cr("%10d %7.2f%% %6.1f %6.2f %6.1f %6.1f %s", abs, rel, nodes, rnodes, xforms, values, name_for_bc(i)); | |
1323 abs_sum += abs; | |
1324 } | |
1325 } | |
1326 tty->print_cr("----------------------------------------------------------------------"); | |
1327 float rel_sum = abs_sum * 100.0F / total; | |
1328 tty->print_cr("%10d %7.2f%% (cutoff = %.2f%%)", abs_sum, rel_sum, cutoff); | |
1329 tty->print_cr("----------------------------------------------------------------------"); | |
1330 tty->cr(); | |
1331 } | |
1332 #endif | |
1333 | |
1334 //----------------------------load_state_from---------------------------------- | |
1335 // Load block/map/sp. But not do not touch iter/bci. | |
1336 void Parse::load_state_from(Block* block) { | |
1337 set_block(block); | |
1338 // load the block's JVM state: | |
1339 set_map(block->start_map()); | |
1340 set_sp( block->start_sp()); | |
1341 } | |
1342 | |
1343 | |
1344 //-----------------------------record_state------------------------------------ | |
1345 void Parse::Block::record_state(Parse* p) { | |
1346 assert(!is_merged(), "can only record state once, on 1st inflow"); | |
1347 assert(start_sp() == p->sp(), "stack pointer must agree with ciTypeFlow"); | |
1348 set_start_map(p->stop()); | |
1349 } | |
1350 | |
1351 | |
1352 //------------------------------do_one_block----------------------------------- | |
1353 void Parse::do_one_block() { | |
1354 if (TraceOptoParse) { | |
1355 Block *b = block(); | |
1356 int ns = b->num_successors(); | |
1357 int nt = b->all_successors(); | |
1358 | |
1359 tty->print("Parsing block #%d at bci [%d,%d), successors: ", | |
367
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
1360 block()->rpo(), block()->start(), block()->limit()); |
0 | 1361 for (int i = 0; i < nt; i++) { |
367
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
1362 tty->print((( i < ns) ? " %d" : " %d(e)"), b->successor_at(i)->rpo()); |
0 | 1363 } |
367
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
1364 if (b->is_loop_head()) tty->print(" lphd"); |
0 | 1365 tty->print_cr(""); |
1366 } | |
1367 | |
1368 assert(block()->is_merged(), "must be merged before being parsed"); | |
1369 block()->mark_parsed(); | |
1370 ++_blocks_parsed; | |
1371 | |
1372 // Set iterator to start of block. | |
1373 iter().reset_to_bci(block()->start()); | |
1374 | |
1375 CompileLog* log = C->log(); | |
1376 | |
1377 // Parse bytecodes | |
1378 while (!stopped() && !failing()) { | |
1379 iter().next(); | |
1380 | |
1381 // Learn the current bci from the iterator: | |
1382 set_parse_bci(iter().cur_bci()); | |
1383 | |
1384 if (bci() == block()->limit()) { | |
1385 // Do not walk into the next block until directed by do_all_blocks. | |
1386 merge(bci()); | |
1387 break; | |
1388 } | |
1389 assert(bci() < block()->limit(), "bci still in block"); | |
1390 | |
1391 if (log != NULL) { | |
1392 // Output an optional context marker, to help place actions | |
1393 // that occur during parsing of this BC. If there is no log | |
1394 // output until the next context string, this context string | |
1395 // will be silently ignored. | |
6843 | 1396 log->set_context("bc code='%d' bci='%d'", (int)bc(), bci()); |
0 | 1397 } |
1398 | |
1399 if (block()->has_trap_at(bci())) { | |
1400 // We must respect the flow pass's traps, because it will refuse | |
1401 // to produce successors for trapping blocks. | |
1402 int trap_index = block()->flow()->trap_index(); | |
1403 assert(trap_index != 0, "trap index must be valid"); | |
1404 uncommon_trap(trap_index); | |
1405 break; | |
1406 } | |
1407 | |
1408 NOT_PRODUCT( parse_histogram()->set_initial_state(bc()); ); | |
1409 | |
1410 #ifdef ASSERT | |
1411 int pre_bc_sp = sp(); | |
1412 int inputs, depth; | |
7194
beebba0acc11
7172640: C2: instrinsic implementations in LibraryCallKit should use argument() instead of pop()
twisti
parents:
6843
diff
changeset
|
1413 bool have_se = !stopped() && compute_stack_effects(inputs, depth); |
6268
6c5b7a6becc8
7187454: stack overflow in C2 compiler thread on Solaris x86
kvn
parents:
6266
diff
changeset
|
1414 assert(!have_se || pre_bc_sp >= inputs, err_msg_res("have enough stack to execute this BC: pre_bc_sp=%d, inputs=%d", pre_bc_sp, inputs)); |
0 | 1415 #endif //ASSERT |
1416 | |
1417 do_one_bytecode(); | |
1418 | |
7478 | 1419 assert(!have_se || stopped() || failing() || (sp() - pre_bc_sp) == depth, |
1420 err_msg_res("incorrect depth prediction: sp=%d, pre_bc_sp=%d, depth=%d", sp(), pre_bc_sp, depth)); | |
0 | 1421 |
1422 do_exceptions(); | |
1423 | |
1424 NOT_PRODUCT( parse_histogram()->record_change(); ); | |
1425 | |
6843 | 1426 if (log != NULL) |
1427 log->clear_context(); // skip marker if nothing was printed | |
0 | 1428 |
1429 // Fall into next bytecode. Each bytecode normally has 1 sequential | |
1430 // successor which is typically made ready by visiting this bytecode. | |
1431 // If the successor has several predecessors, then it is a merge | |
1432 // point, starts a new basic block, and is handled like other basic blocks. | |
1433 } | |
1434 } | |
1435 | |
1436 | |
1437 //------------------------------merge------------------------------------------ | |
1438 void Parse::set_parse_bci(int bci) { | |
1439 set_bci(bci); | |
1440 Node_Notes* nn = C->default_node_notes(); | |
1441 if (nn == NULL) return; | |
1442 | |
1443 // Collect debug info for inlined calls unless -XX:-DebugInlinedCalls. | |
1444 if (!DebugInlinedCalls && depth() > 1) { | |
1445 return; | |
1446 } | |
1447 | |
1448 // Update the JVMS annotation, if present. | |
1449 JVMState* jvms = nn->jvms(); | |
1450 if (jvms != NULL && jvms->bci() != bci) { | |
1451 // Update the JVMS. | |
1452 jvms = jvms->clone_shallow(C); | |
1453 jvms->set_bci(bci); | |
1454 nn->set_jvms(jvms); | |
1455 } | |
1456 } | |
1457 | |
1458 //------------------------------merge------------------------------------------ | |
1459 // Merge the current mapping into the basic block starting at bci | |
1460 void Parse::merge(int target_bci) { | |
1461 Block* target = successor_for_bci(target_bci); | |
1462 if (target == NULL) { handle_missing_successor(target_bci); return; } | |
1463 assert(!target->is_ready(), "our arrival must be expected"); | |
1464 int pnum = target->next_path_num(); | |
1465 merge_common(target, pnum); | |
1466 } | |
1467 | |
1468 //-------------------------merge_new_path-------------------------------------- | |
1469 // Merge the current mapping into the basic block, using a new path | |
1470 void Parse::merge_new_path(int target_bci) { | |
1471 Block* target = successor_for_bci(target_bci); | |
1472 if (target == NULL) { handle_missing_successor(target_bci); return; } | |
1473 assert(!target->is_ready(), "new path into frozen graph"); | |
1474 int pnum = target->add_new_path(); | |
1475 merge_common(target, pnum); | |
1476 } | |
1477 | |
1478 //-------------------------merge_exception------------------------------------- | |
1479 // Merge the current mapping into the basic block starting at bci | |
1480 // The ex_oop must be pushed on the stack, unlike throw_to_exit. | |
1481 void Parse::merge_exception(int target_bci) { | |
1482 assert(sp() == 1, "must have only the throw exception on the stack"); | |
1483 Block* target = successor_for_bci(target_bci); | |
1484 if (target == NULL) { handle_missing_successor(target_bci); return; } | |
1485 assert(target->is_handler(), "exceptions are handled by special blocks"); | |
1486 int pnum = target->add_new_path(); | |
1487 merge_common(target, pnum); | |
1488 } | |
1489 | |
1490 //--------------------handle_missing_successor--------------------------------- | |
1491 void Parse::handle_missing_successor(int target_bci) { | |
1492 #ifndef PRODUCT | |
1493 Block* b = block(); | |
1494 int trap_bci = b->flow()->has_trap()? b->flow()->trap_bci(): -1; | |
367
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
1495 tty->print_cr("### Missing successor at bci:%d for block #%d (trap_bci:%d)", target_bci, b->rpo(), trap_bci); |
0 | 1496 #endif |
1497 ShouldNotReachHere(); | |
1498 } | |
1499 | |
1500 //--------------------------merge_common--------------------------------------- | |
1501 void Parse::merge_common(Parse::Block* target, int pnum) { | |
1502 if (TraceOptoParse) { | |
367
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
1503 tty->print("Merging state at block #%d bci:%d", target->rpo(), target->start()); |
0 | 1504 } |
1505 | |
1506 // Zap extra stack slots to top | |
1507 assert(sp() == target->start_sp(), ""); | |
1508 clean_stack(sp()); | |
1509 | |
1510 if (!target->is_merged()) { // No prior mapping at this bci | |
1511 if (TraceOptoParse) { tty->print(" with empty state"); } | |
1512 | |
1513 // If this path is dead, do not bother capturing it as a merge. | |
1514 // It is "as if" we had 1 fewer predecessors from the beginning. | |
1515 if (stopped()) { | |
1516 if (TraceOptoParse) tty->print_cr(", but path is dead and doesn't count"); | |
1517 return; | |
1518 } | |
1519 | |
1520 // Record that a new block has been merged. | |
1521 ++_blocks_merged; | |
1522 | |
1523 // Make a region if we know there are multiple or unpredictable inputs. | |
1524 // (Also, if this is a plain fall-through, we might see another region, | |
1525 // which must not be allowed into this block's map.) | |
1526 if (pnum > PhiNode::Input // Known multiple inputs. | |
1527 || target->is_handler() // These have unpredictable inputs. | |
367
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
1528 || target->is_loop_head() // Known multiple inputs |
0 | 1529 || control()->is_Region()) { // We must hide this guy. |
2383
9dc311b8473e
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
1972
diff
changeset
|
1530 |
9dc311b8473e
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
1972
diff
changeset
|
1531 int current_bci = bci(); |
9dc311b8473e
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
1972
diff
changeset
|
1532 set_parse_bci(target->start()); // Set target bci |
9dc311b8473e
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
1972
diff
changeset
|
1533 if (target->is_SEL_head()) { |
9dc311b8473e
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
1972
diff
changeset
|
1534 DEBUG_ONLY( target->mark_merged_backedge(block()); ) |
9dc311b8473e
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
1972
diff
changeset
|
1535 if (target->start() == 0) { |
9dc311b8473e
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
1972
diff
changeset
|
1536 // Add loop predicate for the special case when |
9dc311b8473e
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
1972
diff
changeset
|
1537 // there are backbranches to the method entry. |
9dc311b8473e
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
1972
diff
changeset
|
1538 add_predicate(); |
9dc311b8473e
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
1972
diff
changeset
|
1539 } |
9dc311b8473e
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
1972
diff
changeset
|
1540 } |
0 | 1541 // Add a Region to start the new basic block. Phis will be added |
1542 // later lazily. | |
1543 int edges = target->pred_count(); | |
1544 if (edges < pnum) edges = pnum; // might be a new path! | |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
1545 RegionNode *r = new (C) RegionNode(edges+1); |
0 | 1546 gvn().set_type(r, Type::CONTROL); |
1547 record_for_igvn(r); | |
1548 // zap all inputs to NULL for debugging (done in Node(uint) constructor) | |
1549 // for (int j = 1; j < edges+1; j++) { r->init_req(j, NULL); } | |
1550 r->init_req(pnum, control()); | |
1551 set_control(r); | |
2383
9dc311b8473e
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
1972
diff
changeset
|
1552 set_parse_bci(current_bci); // Restore bci |
0 | 1553 } |
1554 | |
1555 // Convert the existing Parser mapping into a mapping at this bci. | |
1556 store_state_to(target); | |
1557 assert(target->is_merged(), "do not come here twice"); | |
1558 | |
1559 } else { // Prior mapping at this bci | |
1560 if (TraceOptoParse) { tty->print(" with previous state"); } | |
2383
9dc311b8473e
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
1972
diff
changeset
|
1561 #ifdef ASSERT |
9dc311b8473e
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
1972
diff
changeset
|
1562 if (target->is_SEL_head()) { |
9dc311b8473e
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
1972
diff
changeset
|
1563 target->mark_merged_backedge(block()); |
9dc311b8473e
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
1972
diff
changeset
|
1564 } |
9dc311b8473e
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
1972
diff
changeset
|
1565 #endif |
0 | 1566 // We must not manufacture more phis if the target is already parsed. |
1567 bool nophi = target->is_parsed(); | |
1568 | |
1569 SafePointNode* newin = map();// Hang on to incoming mapping | |
1570 Block* save_block = block(); // Hang on to incoming block; | |
1571 load_state_from(target); // Get prior mapping | |
1572 | |
1573 assert(newin->jvms()->locoff() == jvms()->locoff(), "JVMS layouts agree"); | |
1574 assert(newin->jvms()->stkoff() == jvms()->stkoff(), "JVMS layouts agree"); | |
1575 assert(newin->jvms()->monoff() == jvms()->monoff(), "JVMS layouts agree"); | |
1576 assert(newin->jvms()->endoff() == jvms()->endoff(), "JVMS layouts agree"); | |
1577 | |
1578 // Iterate over my current mapping and the old mapping. | |
1579 // Where different, insert Phi functions. | |
1580 // Use any existing Phi functions. | |
1581 assert(control()->is_Region(), "must be merging to a region"); | |
1582 RegionNode* r = control()->as_Region(); | |
1583 | |
1584 // Compute where to merge into | |
1585 // Merge incoming control path | |
367
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
1586 r->init_req(pnum, newin->control()); |
0 | 1587 |
1588 if (pnum == 1) { // Last merge for this Region? | |
367
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
1589 if (!block()->flow()->is_irreducible_entry()) { |
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
1590 Node* result = _gvn.transform_no_reclaim(r); |
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
1591 if (r != result && TraceOptoParse) { |
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
1592 tty->print_cr("Block #%d replace %d with %d", block()->rpo(), r->_idx, result->_idx); |
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
1593 } |
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
1594 } |
0 | 1595 record_for_igvn(r); |
1596 } | |
1597 | |
1598 // Update all the non-control inputs to map: | |
1599 assert(TypeFunc::Parms == newin->jvms()->locoff(), "parser map should contain only youngest jvms"); | |
367
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
1600 bool check_elide_phi = target->is_SEL_backedge(save_block); |
0 | 1601 for (uint j = 1; j < newin->req(); j++) { |
1602 Node* m = map()->in(j); // Current state of target. | |
1603 Node* n = newin->in(j); // Incoming change to target state. | |
1604 PhiNode* phi; | |
1605 if (m->is_Phi() && m->as_Phi()->region() == r) | |
1606 phi = m->as_Phi(); | |
1607 else | |
1608 phi = NULL; | |
1609 if (m != n) { // Different; must merge | |
1610 switch (j) { | |
1611 // Frame pointer and Return Address never changes | |
1612 case TypeFunc::FramePtr:// Drop m, use the original value | |
1613 case TypeFunc::ReturnAdr: | |
1614 break; | |
1615 case TypeFunc::Memory: // Merge inputs to the MergeMem node | |
1616 assert(phi == NULL, "the merge contains phis, not vice versa"); | |
1617 merge_memory_edges(n->as_MergeMem(), pnum, nophi); | |
1618 continue; | |
1619 default: // All normal stuff | |
367
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
1620 if (phi == NULL) { |
4790
b0ff910edfc9
7128355: assert(!nocreate) failed: Cannot build a phi for a block already parsed
kvn
parents:
4777
diff
changeset
|
1621 const JVMState* jvms = map()->jvms(); |
b0ff910edfc9
7128355: assert(!nocreate) failed: Cannot build a phi for a block already parsed
kvn
parents:
4777
diff
changeset
|
1622 if (EliminateNestedLocks && |
b0ff910edfc9
7128355: assert(!nocreate) failed: Cannot build a phi for a block already parsed
kvn
parents:
4777
diff
changeset
|
1623 jvms->is_mon(j) && jvms->is_monitor_box(j)) { |
b0ff910edfc9
7128355: assert(!nocreate) failed: Cannot build a phi for a block already parsed
kvn
parents:
4777
diff
changeset
|
1624 // BoxLock nodes are not commoning. |
b0ff910edfc9
7128355: assert(!nocreate) failed: Cannot build a phi for a block already parsed
kvn
parents:
4777
diff
changeset
|
1625 // Use old BoxLock node as merged box. |
b0ff910edfc9
7128355: assert(!nocreate) failed: Cannot build a phi for a block already parsed
kvn
parents:
4777
diff
changeset
|
1626 assert(newin->jvms()->is_monitor_box(j), "sanity"); |
b0ff910edfc9
7128355: assert(!nocreate) failed: Cannot build a phi for a block already parsed
kvn
parents:
4777
diff
changeset
|
1627 // This assert also tests that nodes are BoxLock. |
b0ff910edfc9
7128355: assert(!nocreate) failed: Cannot build a phi for a block already parsed
kvn
parents:
4777
diff
changeset
|
1628 assert(BoxLockNode::same_slot(n, m), "sanity"); |
b0ff910edfc9
7128355: assert(!nocreate) failed: Cannot build a phi for a block already parsed
kvn
parents:
4777
diff
changeset
|
1629 C->gvn_replace_by(n, m); |
b0ff910edfc9
7128355: assert(!nocreate) failed: Cannot build a phi for a block already parsed
kvn
parents:
4777
diff
changeset
|
1630 } else if (!check_elide_phi || !target->can_elide_SEL_phi(j)) { |
367
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
1631 phi = ensure_phi(j, nophi); |
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
1632 } |
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
1633 } |
0 | 1634 break; |
1635 } | |
1636 } | |
1637 // At this point, n might be top if: | |
1638 // - there is no phi (because TypeFlow detected a conflict), or | |
1639 // - the corresponding control edges is top (a dead incoming path) | |
1640 // It is a bug if we create a phi which sees a garbage value on a live path. | |
1641 | |
1642 if (phi != NULL) { | |
1643 assert(n != top() || r->in(pnum) == top(), "live value must not be garbage"); | |
1644 assert(phi->region() == r, ""); | |
1645 phi->set_req(pnum, n); // Then add 'n' to the merge | |
1646 if (pnum == PhiNode::Input) { | |
1647 // Last merge for this Phi. | |
1648 // So far, Phis have had a reasonable type from ciTypeFlow. | |
1649 // Now _gvn will join that with the meet of current inputs. | |
1650 // BOTTOM is never permissible here, 'cause pessimistically | |
1651 // Phis of pointers cannot lose the basic pointer type. | |
1652 debug_only(const Type* bt1 = phi->bottom_type()); | |
1653 assert(bt1 != Type::BOTTOM, "should not be building conflict phis"); | |
1654 map()->set_req(j, _gvn.transform_no_reclaim(phi)); | |
1655 debug_only(const Type* bt2 = phi->bottom_type()); | |
17671
de95063c0e34
8027422: assert(_gvn.type(obj)->higher_equal(tjp)) failed: cast_up is no longer needed
roland
parents:
17467
diff
changeset
|
1656 assert(bt2->higher_equal_speculative(bt1), "must be consistent with type-flow"); |
0 | 1657 record_for_igvn(phi); |
1658 } | |
1659 } | |
1660 } // End of for all values to be merged | |
1661 | |
1662 if (pnum == PhiNode::Input && | |
1663 !r->in(0)) { // The occasional useless Region | |
1664 assert(control() == r, ""); | |
1665 set_control(r->nonnull_req()); | |
1666 } | |
1667 | |
1668 // newin has been subsumed into the lazy merge, and is now dead. | |
1669 set_block(save_block); | |
1670 | |
1671 stop(); // done with this guy, for now | |
1672 } | |
1673 | |
1674 if (TraceOptoParse) { | |
1675 tty->print_cr(" on path %d", pnum); | |
1676 } | |
1677 | |
1678 // Done with this parser state. | |
1679 assert(stopped(), ""); | |
1680 } | |
1681 | |
1682 | |
1683 //--------------------------merge_memory_edges--------------------------------- | |
1684 void Parse::merge_memory_edges(MergeMemNode* n, int pnum, bool nophi) { | |
1685 // (nophi means we must not create phis, because we already parsed here) | |
1686 assert(n != NULL, ""); | |
1687 // Merge the inputs to the MergeMems | |
1688 MergeMemNode* m = merged_memory(); | |
1689 | |
1690 assert(control()->is_Region(), "must be merging to a region"); | |
1691 RegionNode* r = control()->as_Region(); | |
1692 | |
1693 PhiNode* base = NULL; | |
1694 MergeMemNode* remerge = NULL; | |
1695 for (MergeMemStream mms(m, n); mms.next_non_empty2(); ) { | |
1696 Node *p = mms.force_memory(); | |
1697 Node *q = mms.memory2(); | |
1698 if (mms.is_empty() && nophi) { | |
1699 // Trouble: No new splits allowed after a loop body is parsed. | |
1700 // Instead, wire the new split into a MergeMem on the backedge. | |
1701 // The optimizer will sort it out, slicing the phi. | |
1702 if (remerge == NULL) { | |
1703 assert(base != NULL, ""); | |
1704 assert(base->in(0) != NULL, "should not be xformed away"); | |
1705 remerge = MergeMemNode::make(C, base->in(pnum)); | |
1706 gvn().set_type(remerge, Type::MEMORY); | |
1707 base->set_req(pnum, remerge); | |
1708 } | |
1709 remerge->set_memory_at(mms.alias_idx(), q); | |
1710 continue; | |
1711 } | |
1712 assert(!q->is_MergeMem(), ""); | |
1713 PhiNode* phi; | |
1714 if (p != q) { | |
1715 phi = ensure_memory_phi(mms.alias_idx(), nophi); | |
1716 } else { | |
1717 if (p->is_Phi() && p->as_Phi()->region() == r) | |
1718 phi = p->as_Phi(); | |
1719 else | |
1720 phi = NULL; | |
1721 } | |
1722 // Insert q into local phi | |
1723 if (phi != NULL) { | |
1724 assert(phi->region() == r, ""); | |
1725 p = phi; | |
1726 phi->set_req(pnum, q); | |
1727 if (mms.at_base_memory()) { | |
1728 base = phi; // delay transforming it | |
1729 } else if (pnum == 1) { | |
1730 record_for_igvn(phi); | |
1731 p = _gvn.transform_no_reclaim(phi); | |
1732 } | |
1733 mms.set_memory(p);// store back through the iterator | |
1734 } | |
1735 } | |
1736 // Transform base last, in case we must fiddle with remerging. | |
1737 if (base != NULL && pnum == 1) { | |
1738 record_for_igvn(base); | |
1739 m->set_base_memory( _gvn.transform_no_reclaim(base) ); | |
1740 } | |
1741 } | |
1742 | |
1743 | |
1744 //------------------------ensure_phis_everywhere------------------------------- | |
1745 void Parse::ensure_phis_everywhere() { | |
1746 ensure_phi(TypeFunc::I_O); | |
1747 | |
1748 // Ensure a phi on all currently known memories. | |
1749 for (MergeMemStream mms(merged_memory()); mms.next_non_empty(); ) { | |
1750 ensure_memory_phi(mms.alias_idx()); | |
1751 debug_only(mms.set_memory()); // keep the iterator happy | |
1752 } | |
1753 | |
1754 // Note: This is our only chance to create phis for memory slices. | |
1755 // If we miss a slice that crops up later, it will have to be | |
1756 // merged into the base-memory phi that we are building here. | |
1757 // Later, the optimizer will comb out the knot, and build separate | |
1758 // phi-loops for each memory slice that matters. | |
1759 | |
1760 // Monitors must nest nicely and not get confused amongst themselves. | |
1761 // Phi-ify everything up to the monitors, though. | |
1762 uint monoff = map()->jvms()->monoff(); | |
1763 uint nof_monitors = map()->jvms()->nof_monitors(); | |
1764 | |
1765 assert(TypeFunc::Parms == map()->jvms()->locoff(), "parser map should contain only youngest jvms"); | |
367
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
1766 bool check_elide_phi = block()->is_SEL_head(); |
0 | 1767 for (uint i = TypeFunc::Parms; i < monoff; i++) { |
367
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
1768 if (!check_elide_phi || !block()->can_elide_SEL_phi(i)) { |
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
1769 ensure_phi(i); |
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
1770 } |
0 | 1771 } |
367
194b8e3a2fc4
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
196
diff
changeset
|
1772 |
0 | 1773 // Even monitors need Phis, though they are well-structured. |
1774 // This is true for OSR methods, and also for the rare cases where | |
1775 // a monitor object is the subject of a replace_in_map operation. | |
1776 // See bugs 4426707 and 5043395. | |
1777 for (uint m = 0; m < nof_monitors; m++) { | |
1778 ensure_phi(map()->jvms()->monitor_obj_offset(m)); | |
1779 } | |
1780 } | |
1781 | |
1782 | |
1783 //-----------------------------add_new_path------------------------------------ | |
1784 // Add a previously unaccounted predecessor to this block. | |
1785 int Parse::Block::add_new_path() { | |
1786 // If there is no map, return the lowest unused path number. | |
1787 if (!is_merged()) return pred_count()+1; // there will be a map shortly | |
1788 | |
1789 SafePointNode* map = start_map(); | |
1790 if (!map->control()->is_Region()) | |
1791 return pred_count()+1; // there may be a region some day | |
1792 RegionNode* r = map->control()->as_Region(); | |
1793 | |
1794 // Add new path to the region. | |
1795 uint pnum = r->req(); | |
1796 r->add_req(NULL); | |
1797 | |
1798 for (uint i = 1; i < map->req(); i++) { | |
1799 Node* n = map->in(i); | |
1800 if (i == TypeFunc::Memory) { | |
1801 // Ensure a phi on all currently known memories. | |
1802 for (MergeMemStream mms(n->as_MergeMem()); mms.next_non_empty(); ) { | |
1803 Node* phi = mms.memory(); | |
1804 if (phi->is_Phi() && phi->as_Phi()->region() == r) { | |
1805 assert(phi->req() == pnum, "must be same size as region"); | |
1806 phi->add_req(NULL); | |
1807 } | |
1808 } | |
1809 } else { | |
1810 if (n->is_Phi() && n->as_Phi()->region() == r) { | |
1811 assert(n->req() == pnum, "must be same size as region"); | |
1812 n->add_req(NULL); | |
1813 } | |
1814 } | |
1815 } | |
1816 | |
1817 return pnum; | |
1818 } | |
1819 | |
1820 //------------------------------ensure_phi------------------------------------- | |
1821 // Turn the idx'th entry of the current map into a Phi | |
1822 PhiNode *Parse::ensure_phi(int idx, bool nocreate) { | |
1823 SafePointNode* map = this->map(); | |
1824 Node* region = map->control(); | |
1825 assert(region->is_Region(), ""); | |
1826 | |
1827 Node* o = map->in(idx); | |
1828 assert(o != NULL, ""); | |
1829 | |
1830 if (o == top()) return NULL; // TOP always merges into TOP | |
1831 | |
1832 if (o->is_Phi() && o->as_Phi()->region() == region) { | |
1833 return o->as_Phi(); | |
1834 } | |
1835 | |
1836 // Now use a Phi here for merging | |
1837 assert(!nocreate, "Cannot build a phi for a block already parsed."); | |
1838 const JVMState* jvms = map->jvms(); | |
1839 const Type* t; | |
1840 if (jvms->is_loc(idx)) { | |
1841 t = block()->local_type_at(idx - jvms->locoff()); | |
1842 } else if (jvms->is_stk(idx)) { | |
1843 t = block()->stack_type_at(idx - jvms->stkoff()); | |
1844 } else if (jvms->is_mon(idx)) { | |
4790
b0ff910edfc9
7128355: assert(!nocreate) failed: Cannot build a phi for a block already parsed
kvn
parents:
4777
diff
changeset
|
1845 assert(!jvms->is_monitor_box(idx), "no phis for boxes"); |
b0ff910edfc9
7128355: assert(!nocreate) failed: Cannot build a phi for a block already parsed
kvn
parents:
4777
diff
changeset
|
1846 t = TypeInstPtr::BOTTOM; // this is sufficient for a lock object |
0 | 1847 } else if ((uint)idx < TypeFunc::Parms) { |
1848 t = o->bottom_type(); // Type::RETURN_ADDRESS or such-like. | |
1849 } else { | |
1850 assert(false, "no type information for this phi"); | |
1851 } | |
1852 | |
1853 // If the type falls to bottom, then this must be a local that | |
1854 // is mixing ints and oops or some such. Forcing it to top | |
1855 // makes it go dead. | |
1856 if (t == Type::BOTTOM) { | |
1857 map->set_req(idx, top()); | |
1858 return NULL; | |
1859 } | |
1860 | |
1861 // Do not create phis for top either. | |
1862 // A top on a non-null control flow must be an unused even after the.phi. | |
1863 if (t == Type::TOP || t == Type::HALF) { | |
1864 map->set_req(idx, top()); | |
1865 return NULL; | |
1866 } | |
1867 | |
1868 PhiNode* phi = PhiNode::make(region, o, t); | |
1869 gvn().set_type(phi, t); | |
38
b789bcaf2dd9
6667610: (Escape Analysis) retry compilation without EA if it fails
kvn
parents:
0
diff
changeset
|
1870 if (C->do_escape_analysis()) record_for_igvn(phi); |
0 | 1871 map->set_req(idx, phi); |
1872 return phi; | |
1873 } | |
1874 | |
1875 //--------------------------ensure_memory_phi---------------------------------- | |
1876 // Turn the idx'th slice of the current memory into a Phi | |
1877 PhiNode *Parse::ensure_memory_phi(int idx, bool nocreate) { | |
1878 MergeMemNode* mem = merged_memory(); | |
1879 Node* region = control(); | |
1880 assert(region->is_Region(), ""); | |
1881 | |
1882 Node *o = (idx == Compile::AliasIdxBot)? mem->base_memory(): mem->memory_at(idx); | |
1883 assert(o != NULL && o != top(), ""); | |
1884 | |
1885 PhiNode* phi; | |
1886 if (o->is_Phi() && o->as_Phi()->region() == region) { | |
1887 phi = o->as_Phi(); | |
1888 if (phi == mem->base_memory() && idx >= Compile::AliasIdxRaw) { | |
1889 // clone the shared base memory phi to make a new memory split | |
1890 assert(!nocreate, "Cannot build a phi for a block already parsed."); | |
1891 const Type* t = phi->bottom_type(); | |
1892 const TypePtr* adr_type = C->get_adr_type(idx); | |
1893 phi = phi->slice_memory(adr_type); | |
1894 gvn().set_type(phi, t); | |
1895 } | |
1896 return phi; | |
1897 } | |
1898 | |
1899 // Now use a Phi here for merging | |
1900 assert(!nocreate, "Cannot build a phi for a block already parsed."); | |
1901 const Type* t = o->bottom_type(); | |
1902 const TypePtr* adr_type = C->get_adr_type(idx); | |
1903 phi = PhiNode::make(region, o, t, adr_type); | |
1904 gvn().set_type(phi, t); | |
1905 if (idx == Compile::AliasIdxBot) | |
1906 mem->set_base_memory(phi); | |
1907 else | |
1908 mem->set_memory_at(idx, phi); | |
1909 return phi; | |
1910 } | |
1911 | |
1912 //------------------------------call_register_finalizer----------------------- | |
1913 // Check the klass of the receiver and call register_finalizer if the | |
1914 // class need finalization. | |
1915 void Parse::call_register_finalizer() { | |
1916 Node* receiver = local(0); | |
1917 assert(receiver != NULL && receiver->bottom_type()->isa_instptr() != NULL, | |
1918 "must have non-null instance type"); | |
1919 | |
1920 const TypeInstPtr *tinst = receiver->bottom_type()->isa_instptr(); | |
1921 if (tinst != NULL && tinst->klass()->is_loaded() && !tinst->klass_is_exact()) { | |
1922 // The type isn't known exactly so see if CHA tells us anything. | |
1923 ciInstanceKlass* ik = tinst->klass()->as_instance_klass(); | |
1924 if (!Dependencies::has_finalizable_subclass(ik)) { | |
1925 // No finalizable subclasses so skip the dynamic check. | |
1926 C->dependencies()->assert_has_no_finalizable_subclasses(ik); | |
1927 return; | |
1928 } | |
1929 } | |
1930 | |
1931 // Insert a dynamic test for whether the instance needs | |
1932 // finalization. In general this will fold up since the concrete | |
1933 // class is often visible so the access flags are constant. | |
1934 Node* klass_addr = basic_plus_adr( receiver, receiver, oopDesc::klass_offset_in_bytes() ); | |
164
c436414a719e
6703890: Compressed Oops: add LoadNKlass node to generate narrow oops (32-bits) compare instructions
kvn
parents:
38
diff
changeset
|
1935 Node* klass = _gvn.transform( LoadKlassNode::make(_gvn, immutable_memory(), klass_addr, TypeInstPtr::KLASS) ); |
0 | 1936 |
4762
069ab3f976d3
7118863: Move sizeof(klassOopDesc) into the *Klass::*_offset_in_bytes() functions
stefank
parents:
3345
diff
changeset
|
1937 Node* access_flags_addr = basic_plus_adr(klass, klass, in_bytes(Klass::access_flags_offset())); |
0 | 1938 Node* access_flags = make_load(NULL, access_flags_addr, TypeInt::INT, T_INT); |
1939 | |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
1940 Node* mask = _gvn.transform(new (C) AndINode(access_flags, intcon(JVM_ACC_HAS_FINALIZER))); |
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
1941 Node* check = _gvn.transform(new (C) CmpINode(mask, intcon(0))); |
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
1942 Node* test = _gvn.transform(new (C) BoolNode(check, BoolTest::ne)); |
0 | 1943 |
1944 IfNode* iff = create_and_map_if(control(), test, PROB_MAX, COUNT_UNKNOWN); | |
1945 | |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
1946 RegionNode* result_rgn = new (C) RegionNode(3); |
0 | 1947 record_for_igvn(result_rgn); |
1948 | |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
1949 Node *skip_register = _gvn.transform(new (C) IfFalseNode(iff)); |
0 | 1950 result_rgn->init_req(1, skip_register); |
1951 | |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
1952 Node *needs_register = _gvn.transform(new (C) IfTrueNode(iff)); |
0 | 1953 set_control(needs_register); |
1954 if (stopped()) { | |
1955 // There is no slow path. | |
1956 result_rgn->init_req(2, top()); | |
1957 } else { | |
1958 Node *call = make_runtime_call(RC_NO_LEAF, | |
1959 OptoRuntime::register_finalizer_Type(), | |
1960 OptoRuntime::register_finalizer_Java(), | |
1961 NULL, TypePtr::BOTTOM, | |
1962 receiver); | |
1963 make_slow_call_ex(call, env()->Throwable_klass(), true); | |
1964 | |
1965 Node* fast_io = call->in(TypeFunc::I_O); | |
1966 Node* fast_mem = call->in(TypeFunc::Memory); | |
1967 // These two phis are pre-filled with copies of of the fast IO and Memory | |
1968 Node* io_phi = PhiNode::make(result_rgn, fast_io, Type::ABIO); | |
1969 Node* mem_phi = PhiNode::make(result_rgn, fast_mem, Type::MEMORY, TypePtr::BOTTOM); | |
1970 | |
1971 result_rgn->init_req(2, control()); | |
1972 io_phi ->init_req(2, i_o()); | |
1973 mem_phi ->init_req(2, reset_memory()); | |
1974 | |
1975 set_all_memory( _gvn.transform(mem_phi) ); | |
1976 set_i_o( _gvn.transform(io_phi) ); | |
1977 } | |
1978 | |
1979 set_control( _gvn.transform(result_rgn) ); | |
1980 } | |
1981 | |
17780 | 1982 // Add check to deoptimize if RTM state is not ProfileRTM |
1983 void Parse::rtm_deopt() { | |
1984 #if INCLUDE_RTM_OPT | |
1985 if (C->profile_rtm()) { | |
1986 assert(C->method() != NULL, "only for normal compilations"); | |
1987 assert(!C->method()->method_data()->is_empty(), "MDO is needed to record RTM state"); | |
1988 assert(depth() == 1, "generate check only for main compiled method"); | |
1989 | |
1990 // Set starting bci for uncommon trap. | |
1991 set_parse_bci(is_osr_parse() ? osr_bci() : 0); | |
1992 | |
1993 // Load the rtm_state from the MethodData. | |
1994 const TypePtr* adr_type = TypeMetadataPtr::make(C->method()->method_data()); | |
1995 Node* mdo = makecon(adr_type); | |
1996 int offset = MethodData::rtm_state_offset_in_bytes(); | |
1997 Node* adr_node = basic_plus_adr(mdo, mdo, offset); | |
1998 Node* rtm_state = make_load(control(), adr_node, TypeInt::INT, T_INT, adr_type); | |
1999 | |
2000 // Separate Load from Cmp by Opaque. | |
2001 // In expand_macro_nodes() it will be replaced either | |
2002 // with this load when there are locks in the code | |
2003 // or with ProfileRTM (cmp->in(2)) otherwise so that | |
2004 // the check will fold. | |
2005 Node* profile_state = makecon(TypeInt::make(ProfileRTM)); | |
2006 Node* opq = _gvn.transform( new (C) Opaque3Node(C, rtm_state, Opaque3Node::RTM_OPT) ); | |
2007 Node* chk = _gvn.transform( new (C) CmpINode(opq, profile_state) ); | |
2008 Node* tst = _gvn.transform( new (C) BoolNode(chk, BoolTest::eq) ); | |
2009 // Branch to failure if state was changed | |
2010 { BuildCutout unless(this, tst, PROB_ALWAYS); | |
2011 uncommon_trap(Deoptimization::Reason_rtm_state_change, | |
2012 Deoptimization::Action_make_not_entrant); | |
2013 } | |
2014 } | |
2015 #endif | |
2016 } | |
2017 | |
0 | 2018 //------------------------------return_current--------------------------------- |
2019 // Append current _map to _exit_return | |
2020 void Parse::return_current(Node* value) { | |
2021 if (RegisterFinalizersAtInit && | |
2022 method()->intrinsic_id() == vmIntrinsics::_Object_init) { | |
2023 call_register_finalizer(); | |
2024 } | |
2025 | |
2026 // Do not set_parse_bci, so that return goo is credited to the return insn. | |
2027 set_bci(InvocationEntryBci); | |
2028 if (method()->is_synchronized() && GenerateSynchronizationCode) { | |
2029 shared_unlock(_synch_lock->box_node(), _synch_lock->obj_node()); | |
2030 } | |
780
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
726
diff
changeset
|
2031 if (C->env()->dtrace_method_probes()) { |
0 | 2032 make_dtrace_method_exit(method()); |
2033 } | |
2034 SafePointNode* exit_return = _exits.map(); | |
2035 exit_return->in( TypeFunc::Control )->add_req( control() ); | |
2036 exit_return->in( TypeFunc::I_O )->add_req( i_o () ); | |
2037 Node *mem = exit_return->in( TypeFunc::Memory ); | |
2038 for (MergeMemStream mms(mem->as_MergeMem(), merged_memory()); mms.next_non_empty2(); ) { | |
2039 if (mms.is_empty()) { | |
2040 // get a copy of the base memory, and patch just this one input | |
2041 const TypePtr* adr_type = mms.adr_type(C); | |
2042 Node* phi = mms.force_memory()->as_Phi()->slice_memory(adr_type); | |
2043 assert(phi->as_Phi()->region() == mms.base_memory()->in(0), ""); | |
2044 gvn().set_type_bottom(phi); | |
2045 phi->del_req(phi->req()-1); // prepare to re-patch | |
2046 mms.set_memory(phi); | |
2047 } | |
2048 mms.memory()->add_req(mms.memory2()); | |
2049 } | |
2050 | |
2051 // frame pointer is always same, already captured | |
2052 if (value != NULL) { | |
2053 // If returning oops to an interface-return, there is a silent free | |
2054 // cast from oop to interface allowed by the Verifier. Make it explicit | |
2055 // here. | |
2056 Node* phi = _exits.argument(0); | |
2057 const TypeInstPtr *tr = phi->bottom_type()->isa_instptr(); | |
2058 if( tr && tr->klass()->is_loaded() && | |
2059 tr->klass()->is_interface() ) { | |
2060 const TypeInstPtr *tp = value->bottom_type()->isa_instptr(); | |
2061 if (tp && tp->klass()->is_loaded() && | |
2062 !tp->klass()->is_interface()) { | |
2063 // sharpen the type eagerly; this eases certain assert checking | |
2064 if (tp->higher_equal(TypeInstPtr::NOTNULL)) | |
17671
de95063c0e34
8027422: assert(_gvn.type(obj)->higher_equal(tjp)) failed: cast_up is no longer needed
roland
parents:
17467
diff
changeset
|
2065 tr = tr->join_speculative(TypeInstPtr::NOTNULL)->is_instptr(); |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
2066 value = _gvn.transform(new (C) CheckCastPPNode(0,value,tr)); |
0 | 2067 } |
2068 } | |
2069 phi->add_req(value); | |
2070 } | |
2071 | |
2072 stop_and_kill_map(); // This CFG path dies here | |
2073 } | |
2074 | |
2075 | |
2076 //------------------------------add_safepoint---------------------------------- | |
2077 void Parse::add_safepoint() { | |
2078 // See if we can avoid this safepoint. No need for a SafePoint immediately | |
2079 // after a Call (except Leaf Call) or another SafePoint. | |
2080 Node *proj = control(); | |
2081 bool add_poll_param = SafePointNode::needs_polling_address_input(); | |
2082 uint parms = add_poll_param ? TypeFunc::Parms+1 : TypeFunc::Parms; | |
2083 if( proj->is_Proj() ) { | |
2084 Node *n0 = proj->in(0); | |
2085 if( n0->is_Catch() ) { | |
2086 n0 = n0->in(0)->in(0); | |
2087 assert( n0->is_Call(), "expect a call here" ); | |
2088 } | |
2089 if( n0->is_Call() ) { | |
2090 if( n0->as_Call()->guaranteed_safepoint() ) | |
2091 return; | |
2092 } else if( n0->is_SafePoint() && n0->req() >= parms ) { | |
2093 return; | |
2094 } | |
2095 } | |
2096 | |
2097 // Clear out dead values from the debug info. | |
2098 kill_dead_locals(); | |
2099 | |
2100 // Clone the JVM State | |
6804
e626685e9f6c
7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents:
6725
diff
changeset
|
2101 SafePointNode *sfpnt = new (C) SafePointNode(parms, NULL); |
0 | 2102 |
2103 // Capture memory state BEFORE a SafePoint. Since we can block at a | |
2104 // SafePoint we need our GC state to be safe; i.e. we need all our current | |
2105 // write barriers (card marks) to not float down after the SafePoint so we | |
2106 // must read raw memory. Likewise we need all oop stores to match the card | |
2107 // marks. If deopt can happen, we need ALL stores (we need the correct JVM | |
2108 // state on a deopt). | |
2109 | |
2110 // We do not need to WRITE the memory state after a SafePoint. The control | |
2111 // edge will keep card-marks and oop-stores from floating up from below a | |
2112 // SafePoint and our true dependency added here will keep them from floating | |
2113 // down below a SafePoint. | |
2114 | |
2115 // Clone the current memory state | |
2116 Node* mem = MergeMemNode::make(C, map()->memory()); | |
2117 | |
2118 mem = _gvn.transform(mem); | |
2119 | |
2120 // Pass control through the safepoint | |
2121 sfpnt->init_req(TypeFunc::Control , control()); | |
2122 // Fix edges normally used by a call | |
2123 sfpnt->init_req(TypeFunc::I_O , top() ); | |
2124 sfpnt->init_req(TypeFunc::Memory , mem ); | |
2125 sfpnt->init_req(TypeFunc::ReturnAdr, top() ); | |
2126 sfpnt->init_req(TypeFunc::FramePtr , top() ); | |
2127 | |
2128 // Create a node for the polling address | |
2129 if( add_poll_param ) { | |
2130 Node *polladr = ConPNode::make(C, (address)os::get_polling_page()); | |
2131 sfpnt->init_req(TypeFunc::Parms+0, _gvn.transform(polladr)); | |
2132 } | |
2133 | |
2134 // Fix up the JVM State edges | |
2135 add_safepoint_edges(sfpnt); | |
2136 Node *transformed_sfpnt = _gvn.transform(sfpnt); | |
2137 set_control(transformed_sfpnt); | |
2138 | |
2139 // Provide an edge from root to safepoint. This makes the safepoint | |
2140 // appear useful until the parse has completed. | |
2141 if( OptoRemoveUseless && transformed_sfpnt->is_SafePoint() ) { | |
2142 assert(C->root() != NULL, "Expect parse is still valid"); | |
2143 C->root()->add_prec(transformed_sfpnt); | |
2144 } | |
2145 } | |
2146 | |
2147 #ifndef PRODUCT | |
2148 //------------------------show_parse_info-------------------------------------- | |
2149 void Parse::show_parse_info() { | |
2150 InlineTree* ilt = NULL; | |
2151 if (C->ilt() != NULL) { | |
2152 JVMState* caller_jvms = is_osr_parse() ? caller()->caller() : caller(); | |
2153 ilt = InlineTree::find_subtree_from_root(C->ilt(), caller_jvms, method()); | |
2154 } | |
2155 if (PrintCompilation && Verbose) { | |
2156 if (depth() == 1) { | |
2157 if( ilt->count_inlines() ) { | |
2158 tty->print(" __inlined %d (%d bytes)", ilt->count_inlines(), | |
2159 ilt->count_inline_bcs()); | |
2160 tty->cr(); | |
2161 } | |
2162 } else { | |
2163 if (method()->is_synchronized()) tty->print("s"); | |
2164 if (method()->has_exception_handlers()) tty->print("!"); | |
2165 // Check this is not the final compiled version | |
2166 if (C->trap_can_recompile()) { | |
2167 tty->print("-"); | |
2168 } else { | |
2169 tty->print(" "); | |
2170 } | |
2171 method()->print_short_name(); | |
2172 if (is_osr_parse()) { | |
2173 tty->print(" @ %d", osr_bci()); | |
2174 } | |
2175 tty->print(" (%d bytes)",method()->code_size()); | |
2176 if (ilt->count_inlines()) { | |
2177 tty->print(" __inlined %d (%d bytes)", ilt->count_inlines(), | |
2178 ilt->count_inline_bcs()); | |
2179 } | |
2180 tty->cr(); | |
2181 } | |
2182 } | |
2183 if (PrintOpto && (depth() == 1 || PrintOptoInlining)) { | |
2184 // Print that we succeeded; suppress this message on the first osr parse. | |
2185 | |
2186 if (method()->is_synchronized()) tty->print("s"); | |
2187 if (method()->has_exception_handlers()) tty->print("!"); | |
2188 // Check this is not the final compiled version | |
2189 if (C->trap_can_recompile() && depth() == 1) { | |
2190 tty->print("-"); | |
2191 } else { | |
2192 tty->print(" "); | |
2193 } | |
2194 if( depth() != 1 ) { tty->print(" "); } // missing compile count | |
2195 for (int i = 1; i < depth(); ++i) { tty->print(" "); } | |
2196 method()->print_short_name(); | |
2197 if (is_osr_parse()) { | |
2198 tty->print(" @ %d", osr_bci()); | |
2199 } | |
2200 if (ilt->caller_bci() != -1) { | |
2201 tty->print(" @ %d", ilt->caller_bci()); | |
2202 } | |
2203 tty->print(" (%d bytes)",method()->code_size()); | |
2204 if (ilt->count_inlines()) { | |
2205 tty->print(" __inlined %d (%d bytes)", ilt->count_inlines(), | |
2206 ilt->count_inline_bcs()); | |
2207 } | |
2208 tty->cr(); | |
2209 } | |
2210 } | |
2211 | |
2212 | |
2213 //------------------------------dump------------------------------------------- | |
2214 // Dump information associated with the bytecodes of current _method | |
2215 void Parse::dump() { | |
2216 if( method() != NULL ) { | |
2217 // Iterate over bytecodes | |
2218 ciBytecodeStream iter(method()); | |
2219 for( Bytecodes::Code bc = iter.next(); bc != ciBytecodeStream::EOBC() ; bc = iter.next() ) { | |
2220 dump_bci( iter.cur_bci() ); | |
2221 tty->cr(); | |
2222 } | |
2223 } | |
2224 } | |
2225 | |
2226 // Dump information associated with a byte code index, 'bci' | |
2227 void Parse::dump_bci(int bci) { | |
2228 // Output info on merge-points, cloning, and within _jsr..._ret | |
2229 // NYI | |
2230 tty->print(" bci:%d", bci); | |
2231 } | |
2232 | |
2233 #endif |