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