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 "ci/bcEscapeAnalyzer.hpp"
26 #include "code/vmreg.hpp"
27 #include "compiler/compileLog.hpp"
28 #include "compiler/oopMap.hpp"
29 #include "gc/shared/barrierSet.hpp"
30 #include "gc/shared/c2/barrierSetC2.hpp"
31 #include "interpreter/interpreter.hpp"
32 #include "opto/callGenerator.hpp"
33 #include "opto/callnode.hpp"
34 #include "opto/castnode.hpp"
35 #include "opto/convertnode.hpp"
36 #include "opto/escape.hpp"
37 #include "opto/locknode.hpp"
38 #include "opto/machnode.hpp"
39 #include "opto/matcher.hpp"
40 #include "opto/parse.hpp"
41 #include "opto/regalloc.hpp"
42 #include "opto/regmask.hpp"
43 #include "opto/rootnode.hpp"
44 #include "opto/runtime.hpp"
45 #include "runtime/sharedRuntime.hpp"
46 #include "utilities/powerOfTwo.hpp"
47
48 // Portions of code courtesy of Clifford Click
49
50 // Optimization - Graph Style
51
52 //=============================================================================
53 uint StartNode::size_of() const { return sizeof(*this); }
54 bool StartNode::cmp( const Node &n ) const
55 { return _domain == ((StartNode&)n)._domain; }
56 const Type *StartNode::bottom_type() const { return _domain; }
57 const Type* StartNode::Value(PhaseGVN* phase) const { return _domain; }
58 #ifndef PRODUCT
59 void StartNode::dump_spec(outputStream *st) const { st->print(" #"); _domain->dump_on(st);}
60 void StartNode::dump_compact_spec(outputStream *st) const { /* empty */ }
61 #endif
62
63 //------------------------------Ideal------------------------------------------
64 Node *StartNode::Ideal(PhaseGVN *phase, bool can_reshape){
65 return remove_dead_region(phase, can_reshape) ? this : nullptr;
66 }
67
68 //------------------------------calling_convention-----------------------------
69 void StartNode::calling_convention(BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt) const {
70 SharedRuntime::java_calling_convention(sig_bt, parm_regs, argcnt);
71 }
72
73 //------------------------------Registers--------------------------------------
74 const RegMask &StartNode::in_RegMask(uint) const {
75 return RegMask::EMPTY;
76 }
77
78 //------------------------------match------------------------------------------
79 // Construct projections for incoming parameters, and their RegMask info
80 Node *StartNode::match( const ProjNode *proj, const Matcher *match ) {
81 switch (proj->_con) {
82 case TypeFunc::Control:
83 case TypeFunc::I_O:
84 case TypeFunc::Memory:
85 return new MachProjNode(this,proj->_con,RegMask::EMPTY,MachProjNode::unmatched_proj);
86 case TypeFunc::FramePtr:
87 return new MachProjNode(this,proj->_con,Matcher::c_frame_ptr_mask, Op_RegP);
88 case TypeFunc::ReturnAdr:
89 return new MachProjNode(this,proj->_con,match->_return_addr_mask,Op_RegP);
90 case TypeFunc::Parms:
91 default: {
92 uint parm_num = proj->_con - TypeFunc::Parms;
93 const Type *t = _domain->field_at(proj->_con);
94 if (t->base() == Type::Half) // 2nd half of Longs and Doubles
95 return new ConNode(Type::TOP);
96 uint ideal_reg = t->ideal_reg();
97 RegMask &rm = match->_calling_convention_mask[parm_num];
98 return new MachProjNode(this,proj->_con,rm,ideal_reg);
99 }
100 }
101 return nullptr;
102 }
103
104 //------------------------------StartOSRNode----------------------------------
105 // The method start node for an on stack replacement adapter
106
107 //------------------------------osr_domain-----------------------------
108 const TypeTuple *StartOSRNode::osr_domain() {
109 const Type **fields = TypeTuple::fields(2);
110 fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM; // address of osr buffer
111
112 return TypeTuple::make(TypeFunc::Parms+1, fields);
113 }
114
115 //=============================================================================
116 const char * const ParmNode::names[TypeFunc::Parms+1] = {
117 "Control", "I_O", "Memory", "FramePtr", "ReturnAdr", "Parms"
118 };
119
120 #ifndef PRODUCT
121 void ParmNode::dump_spec(outputStream *st) const {
122 if( _con < TypeFunc::Parms ) {
123 st->print("%s", names[_con]);
124 } else {
125 st->print("Parm%d: ",_con-TypeFunc::Parms);
126 // Verbose and WizardMode dump bottom_type for all nodes
127 if( !Verbose && !WizardMode ) bottom_type()->dump_on(st);
128 }
129 }
130
131 void ParmNode::dump_compact_spec(outputStream *st) const {
132 if (_con < TypeFunc::Parms) {
133 st->print("%s", names[_con]);
134 } else {
135 st->print("%d:", _con-TypeFunc::Parms);
136 // unconditionally dump bottom_type
137 bottom_type()->dump_on(st);
138 }
139 }
140 #endif
141
142 uint ParmNode::ideal_reg() const {
143 switch( _con ) {
144 case TypeFunc::Control : // fall through
145 case TypeFunc::I_O : // fall through
146 case TypeFunc::Memory : return 0;
147 case TypeFunc::FramePtr : // fall through
148 case TypeFunc::ReturnAdr: return Op_RegP;
149 default : assert( _con > TypeFunc::Parms, "" );
150 // fall through
151 case TypeFunc::Parms : {
152 // Type of argument being passed
153 const Type *t = in(0)->as_Start()->_domain->field_at(_con);
154 return t->ideal_reg();
155 }
156 }
157 ShouldNotReachHere();
158 return 0;
159 }
160
161 //=============================================================================
162 ReturnNode::ReturnNode(uint edges, Node *cntrl, Node *i_o, Node *memory, Node *frameptr, Node *retadr ) : Node(edges) {
163 init_req(TypeFunc::Control,cntrl);
164 init_req(TypeFunc::I_O,i_o);
165 init_req(TypeFunc::Memory,memory);
166 init_req(TypeFunc::FramePtr,frameptr);
167 init_req(TypeFunc::ReturnAdr,retadr);
168 }
169
170 Node *ReturnNode::Ideal(PhaseGVN *phase, bool can_reshape){
171 return remove_dead_region(phase, can_reshape) ? this : nullptr;
172 }
173
174 const Type* ReturnNode::Value(PhaseGVN* phase) const {
175 return ( phase->type(in(TypeFunc::Control)) == Type::TOP)
176 ? Type::TOP
177 : Type::BOTTOM;
178 }
179
180 // Do we Match on this edge index or not? No edges on return nodes
181 uint ReturnNode::match_edge(uint idx) const {
182 return 0;
183 }
184
185
186 #ifndef PRODUCT
187 void ReturnNode::dump_req(outputStream *st, DumpConfig* dc) const {
188 // Dump the required inputs, after printing "returns"
189 uint i; // Exit value of loop
190 for (i = 0; i < req(); i++) { // For all required inputs
191 if (i == TypeFunc::Parms) st->print("returns ");
192 Node* p = in(i);
193 if (p != nullptr) {
194 p->dump_idx(false, st, dc);
195 st->print(" ");
196 } else {
197 st->print("_ ");
198 }
199 }
200 }
201 #endif
202
203 //=============================================================================
204 RethrowNode::RethrowNode(
205 Node* cntrl,
206 Node* i_o,
207 Node* memory,
208 Node* frameptr,
209 Node* ret_adr,
210 Node* exception
211 ) : Node(TypeFunc::Parms + 1) {
212 init_req(TypeFunc::Control , cntrl );
213 init_req(TypeFunc::I_O , i_o );
214 init_req(TypeFunc::Memory , memory );
215 init_req(TypeFunc::FramePtr , frameptr );
216 init_req(TypeFunc::ReturnAdr, ret_adr);
217 init_req(TypeFunc::Parms , exception);
218 }
219
220 Node *RethrowNode::Ideal(PhaseGVN *phase, bool can_reshape){
221 return remove_dead_region(phase, can_reshape) ? this : nullptr;
222 }
223
224 const Type* RethrowNode::Value(PhaseGVN* phase) const {
225 return (phase->type(in(TypeFunc::Control)) == Type::TOP)
226 ? Type::TOP
227 : Type::BOTTOM;
228 }
229
230 uint RethrowNode::match_edge(uint idx) const {
231 return 0;
232 }
233
234 #ifndef PRODUCT
235 void RethrowNode::dump_req(outputStream *st, DumpConfig* dc) const {
236 // Dump the required inputs, after printing "exception"
237 uint i; // Exit value of loop
238 for (i = 0; i < req(); i++) { // For all required inputs
239 if (i == TypeFunc::Parms) st->print("exception ");
240 Node* p = in(i);
241 if (p != nullptr) {
242 p->dump_idx(false, st, dc);
243 st->print(" ");
244 } else {
245 st->print("_ ");
246 }
247 }
248 }
249 #endif
250
251 //=============================================================================
252 // Do we Match on this edge index or not? Match only target address & method
253 uint TailCallNode::match_edge(uint idx) const {
254 return TypeFunc::Parms <= idx && idx <= TypeFunc::Parms+1;
255 }
256
257 //=============================================================================
258 // Do we Match on this edge index or not? Match only target address & oop
259 uint TailJumpNode::match_edge(uint idx) const {
260 return TypeFunc::Parms <= idx && idx <= TypeFunc::Parms+1;
261 }
262
263 //=============================================================================
264 JVMState::JVMState(ciMethod* method, JVMState* caller) :
265 _method(method),
266 _receiver_info(nullptr) {
267 assert(method != nullptr, "must be valid call site");
268 _bci = InvocationEntryBci;
269 _reexecute = Reexecute_Undefined;
270 DEBUG_ONLY(_bci = -99); // random garbage value
271 DEBUG_ONLY(_map = (SafePointNode*)-1);
272 _caller = caller;
273 _depth = 1 + (caller == nullptr ? 0 : caller->depth());
274 _locoff = TypeFunc::Parms;
275 _stkoff = _locoff + _method->max_locals();
276 _monoff = _stkoff + _method->max_stack();
277 _scloff = _monoff;
278 _endoff = _monoff;
279 _sp = 0;
280 }
281 JVMState::JVMState(int stack_size) :
282 _method(nullptr),
283 _receiver_info(nullptr) {
284 _bci = InvocationEntryBci;
285 _reexecute = Reexecute_Undefined;
286 DEBUG_ONLY(_map = (SafePointNode*)-1);
287 _caller = nullptr;
288 _depth = 1;
289 _locoff = TypeFunc::Parms;
290 _stkoff = _locoff;
291 _monoff = _stkoff + stack_size;
292 _scloff = _monoff;
293 _endoff = _monoff;
294 _sp = 0;
295 }
296
297 //--------------------------------of_depth-------------------------------------
298 JVMState* JVMState::of_depth(int d) const {
299 const JVMState* jvmp = this;
300 assert(0 < d && (uint)d <= depth(), "oob");
301 for (int skip = depth() - d; skip > 0; skip--) {
302 jvmp = jvmp->caller();
303 }
304 assert(jvmp->depth() == (uint)d, "found the right one");
305 return (JVMState*)jvmp;
306 }
307
308 //-----------------------------same_calls_as-----------------------------------
309 bool JVMState::same_calls_as(const JVMState* that) const {
310 if (this == that) return true;
311 if (this->depth() != that->depth()) return false;
312 const JVMState* p = this;
313 const JVMState* q = that;
314 for (;;) {
315 if (p->_method != q->_method) return false;
316 if (p->_method == nullptr) return true; // bci is irrelevant
317 if (p->_bci != q->_bci) return false;
318 if (p->_reexecute != q->_reexecute) return false;
319 p = p->caller();
320 q = q->caller();
321 if (p == q) return true;
322 assert(p != nullptr && q != nullptr, "depth check ensures we don't run off end");
323 }
324 }
325
326 //------------------------------debug_start------------------------------------
327 uint JVMState::debug_start() const {
328 DEBUG_ONLY(JVMState* jvmroot = of_depth(1));
329 assert(jvmroot->locoff() <= this->locoff(), "youngest JVMState must be last");
330 return of_depth(1)->locoff();
331 }
332
333 //-------------------------------debug_end-------------------------------------
334 uint JVMState::debug_end() const {
335 DEBUG_ONLY(JVMState* jvmroot = of_depth(1));
336 assert(jvmroot->endoff() <= this->endoff(), "youngest JVMState must be last");
337 return endoff();
338 }
339
340 //------------------------------debug_depth------------------------------------
341 uint JVMState::debug_depth() const {
342 uint total = 0;
343 for (const JVMState* jvmp = this; jvmp != nullptr; jvmp = jvmp->caller()) {
344 total += jvmp->debug_size();
345 }
346 return total;
347 }
348
349 #ifndef PRODUCT
350
351 //------------------------------format_helper----------------------------------
352 // Given an allocation (a Chaitin object) and a Node decide if the Node carries
353 // any defined value or not. If it does, print out the register or constant.
354 static void format_helper( PhaseRegAlloc *regalloc, outputStream* st, Node *n, const char *msg, uint i, GrowableArray<SafePointScalarObjectNode*> *scobjs ) {
355 if (n == nullptr) { st->print(" null"); return; }
356 if (n->is_SafePointScalarObject()) {
357 // Scalar replacement.
358 SafePointScalarObjectNode* spobj = n->as_SafePointScalarObject();
359 scobjs->append_if_missing(spobj);
360 int sco_n = scobjs->find(spobj);
361 assert(sco_n >= 0, "");
362 st->print(" %s%d]=#ScObj" INT32_FORMAT, msg, i, sco_n);
363 return;
364 }
365 if (regalloc->node_regs_max_index() > 0 &&
366 OptoReg::is_valid(regalloc->get_reg_first(n))) { // Check for undefined
367 char buf[50];
368 regalloc->dump_register(n,buf,sizeof(buf));
369 st->print(" %s%d]=%s",msg,i,buf);
370 } else { // No register, but might be constant
371 const Type *t = n->bottom_type();
372 switch (t->base()) {
373 case Type::Int:
374 st->print(" %s%d]=#" INT32_FORMAT,msg,i,t->is_int()->get_con());
375 break;
376 case Type::AnyPtr:
377 assert( t == TypePtr::NULL_PTR || n->in_dump(), "" );
378 st->print(" %s%d]=#null",msg,i);
379 break;
380 case Type::AryPtr:
381 case Type::InstPtr:
382 st->print(" %s%d]=#Ptr" INTPTR_FORMAT,msg,i,p2i(t->isa_oopptr()->const_oop()));
383 break;
384 case Type::KlassPtr:
385 case Type::AryKlassPtr:
386 case Type::InstKlassPtr:
387 st->print(" %s%d]=#Ptr" INTPTR_FORMAT,msg,i,p2i(t->make_ptr()->isa_klassptr()->exact_klass()));
388 break;
389 case Type::MetadataPtr:
390 st->print(" %s%d]=#Ptr" INTPTR_FORMAT,msg,i,p2i(t->make_ptr()->isa_metadataptr()->metadata()));
391 break;
392 case Type::NarrowOop:
393 st->print(" %s%d]=#Ptr" INTPTR_FORMAT,msg,i,p2i(t->make_ptr()->isa_oopptr()->const_oop()));
394 break;
395 case Type::RawPtr:
396 st->print(" %s%d]=#Raw" INTPTR_FORMAT,msg,i,p2i(t->is_rawptr()));
397 break;
398 case Type::DoubleCon:
399 st->print(" %s%d]=#%fD",msg,i,t->is_double_constant()->_d);
400 break;
401 case Type::FloatCon:
402 st->print(" %s%d]=#%fF",msg,i,t->is_float_constant()->_f);
403 break;
404 case Type::Long:
405 st->print(" %s%d]=#" INT64_FORMAT,msg,i,(int64_t)(t->is_long()->get_con()));
406 break;
407 case Type::Half:
408 case Type::Top:
409 st->print(" %s%d]=_",msg,i);
410 break;
411 default: ShouldNotReachHere();
412 }
413 }
414 }
415
416 //---------------------print_method_with_lineno--------------------------------
417 void JVMState::print_method_with_lineno(outputStream* st, bool show_name) const {
418 if (show_name) _method->print_short_name(st);
419
420 int lineno = _method->line_number_from_bci(_bci);
421 if (lineno != -1) {
422 st->print(" @ bci:%d (line %d)", _bci, lineno);
423 } else {
424 st->print(" @ bci:%d", _bci);
425 }
426 }
427
428 //------------------------------format-----------------------------------------
429 void JVMState::format(PhaseRegAlloc *regalloc, const Node *n, outputStream* st) const {
430 st->print(" #");
431 if (_method) {
432 print_method_with_lineno(st, true);
433 } else {
434 st->print_cr(" runtime stub ");
435 return;
436 }
437 if (n->is_MachSafePoint()) {
438 GrowableArray<SafePointScalarObjectNode*> scobjs;
439 MachSafePointNode *mcall = n->as_MachSafePoint();
440 uint i;
441 // Print locals
442 for (i = 0; i < (uint)loc_size(); i++)
443 format_helper(regalloc, st, mcall->local(this, i), "L[", i, &scobjs);
444 // Print stack
445 for (i = 0; i < (uint)stk_size(); i++) {
446 if ((uint)(_stkoff + i) >= mcall->len())
447 st->print(" oob ");
448 else
449 format_helper(regalloc, st, mcall->stack(this, i), "STK[", i, &scobjs);
450 }
451 for (i = 0; (int)i < nof_monitors(); i++) {
452 Node *box = mcall->monitor_box(this, i);
453 Node *obj = mcall->monitor_obj(this, i);
454 if (regalloc->node_regs_max_index() > 0 &&
455 OptoReg::is_valid(regalloc->get_reg_first(box))) {
456 box = BoxLockNode::box_node(box);
457 format_helper(regalloc, st, box, "MON-BOX[", i, &scobjs);
458 } else {
459 OptoReg::Name box_reg = BoxLockNode::reg(box);
460 st->print(" MON-BOX%d=%s+%d",
461 i,
462 OptoReg::regname(OptoReg::c_frame_pointer),
463 regalloc->reg2offset(box_reg));
464 }
465 const char* obj_msg = "MON-OBJ[";
466 if (EliminateLocks) {
467 if (BoxLockNode::box_node(box)->is_eliminated())
468 obj_msg = "MON-OBJ(LOCK ELIMINATED)[";
469 }
470 format_helper(regalloc, st, obj, obj_msg, i, &scobjs);
471 }
472
473 for (i = 0; i < (uint)scobjs.length(); i++) {
474 // Scalar replaced objects.
475 st->cr();
476 st->print(" # ScObj" INT32_FORMAT " ", i);
477 SafePointScalarObjectNode* spobj = scobjs.at(i);
478 ciKlass* cik = spobj->bottom_type()->is_oopptr()->exact_klass();
479 assert(cik->is_instance_klass() ||
480 cik->is_array_klass(), "Not supported allocation.");
481 ciInstanceKlass *iklass = nullptr;
482 if (cik->is_instance_klass()) {
483 cik->print_name_on(st);
484 iklass = cik->as_instance_klass();
485 } else if (cik->is_type_array_klass()) {
486 cik->as_array_klass()->base_element_type()->print_name_on(st);
487 st->print("[%d]", spobj->n_fields());
488 } else if (cik->is_obj_array_klass()) {
489 ciKlass* cie = cik->as_obj_array_klass()->base_element_klass();
490 if (cie->is_instance_klass()) {
491 cie->print_name_on(st);
492 } else if (cie->is_type_array_klass()) {
493 cie->as_array_klass()->base_element_type()->print_name_on(st);
494 } else {
495 ShouldNotReachHere();
496 }
497 st->print("[%d]", spobj->n_fields());
498 int ndim = cik->as_array_klass()->dimension() - 1;
499 while (ndim-- > 0) {
500 st->print("[]");
501 }
502 }
503 st->print("={");
504 uint nf = spobj->n_fields();
505 if (nf > 0) {
506 uint first_ind = spobj->first_index(mcall->jvms());
507 Node* fld_node = mcall->in(first_ind);
508 ciField* cifield;
509 if (iklass != nullptr) {
510 st->print(" [");
511 cifield = iklass->nonstatic_field_at(0);
512 cifield->print_name_on(st);
513 format_helper(regalloc, st, fld_node, ":", 0, &scobjs);
514 } else {
515 format_helper(regalloc, st, fld_node, "[", 0, &scobjs);
516 }
517 for (uint j = 1; j < nf; j++) {
518 fld_node = mcall->in(first_ind+j);
519 if (iklass != nullptr) {
520 st->print(", [");
521 cifield = iklass->nonstatic_field_at(j);
522 cifield->print_name_on(st);
523 format_helper(regalloc, st, fld_node, ":", j, &scobjs);
524 } else {
525 format_helper(regalloc, st, fld_node, ", [", j, &scobjs);
526 }
527 }
528 }
529 st->print(" }");
530 }
531 }
532 st->cr();
533 if (caller() != nullptr) caller()->format(regalloc, n, st);
534 }
535
536
537 void JVMState::dump_spec(outputStream *st) const {
538 if (_method != nullptr) {
539 bool printed = false;
540 if (!Verbose) {
541 // The JVMS dumps make really, really long lines.
542 // Take out the most boring parts, which are the package prefixes.
543 char buf[500];
544 stringStream namest(buf, sizeof(buf));
545 _method->print_short_name(&namest);
546 if (namest.count() < sizeof(buf)) {
547 const char* name = namest.base();
548 if (name[0] == ' ') ++name;
549 const char* endcn = strchr(name, ':'); // end of class name
550 if (endcn == nullptr) endcn = strchr(name, '(');
551 if (endcn == nullptr) endcn = name + strlen(name);
552 while (endcn > name && endcn[-1] != '.' && endcn[-1] != '/')
553 --endcn;
554 st->print(" %s", endcn);
555 printed = true;
556 }
557 }
558 print_method_with_lineno(st, !printed);
559 if(_reexecute == Reexecute_True)
560 st->print(" reexecute");
561 } else {
562 st->print(" runtime stub");
563 }
564 if (caller() != nullptr) caller()->dump_spec(st);
565 }
566
567
568 void JVMState::dump_on(outputStream* st) const {
569 bool print_map = _map && !((uintptr_t)_map & 1) &&
570 ((caller() == nullptr) || (caller()->map() != _map));
571 if (print_map) {
572 if (_map->len() > _map->req()) { // _map->has_exceptions()
573 Node* ex = _map->in(_map->req()); // _map->next_exception()
574 // skip the first one; it's already being printed
575 while (ex != nullptr && ex->len() > ex->req()) {
576 ex = ex->in(ex->req()); // ex->next_exception()
577 ex->dump(1);
578 }
579 }
580 _map->dump(Verbose ? 2 : 1);
581 }
582 if (caller() != nullptr) {
583 caller()->dump_on(st);
584 }
585 st->print("JVMS depth=%d loc=%d stk=%d arg=%d mon=%d scalar=%d end=%d mondepth=%d sp=%d bci=%d reexecute=%s method=",
586 depth(), locoff(), stkoff(), argoff(), monoff(), scloff(), endoff(), monitor_depth(), sp(), bci(), should_reexecute()?"true":"false");
587 if (_method == nullptr) {
588 st->print_cr("(none)");
589 } else {
590 _method->print_name(st);
591 st->cr();
592 if (bci() >= 0 && bci() < _method->code_size()) {
593 st->print(" bc: ");
594 _method->print_codes_on(bci(), bci()+1, st);
595 }
596 }
597 }
598
599 // Extra way to dump a jvms from the debugger,
600 // to avoid a bug with C++ member function calls.
601 void dump_jvms(JVMState* jvms) {
602 jvms->dump();
603 }
604 #endif
605
606 //--------------------------clone_shallow--------------------------------------
607 JVMState* JVMState::clone_shallow(Compile* C) const {
608 JVMState* n = has_method() ? new (C) JVMState(_method, _caller) : new (C) JVMState(0);
609 n->set_bci(_bci);
610 n->_reexecute = _reexecute;
611 n->set_locoff(_locoff);
612 n->set_stkoff(_stkoff);
613 n->set_monoff(_monoff);
614 n->set_scloff(_scloff);
615 n->set_endoff(_endoff);
616 n->set_sp(_sp);
617 n->set_map(_map);
618 n->set_receiver_info(_receiver_info);
619 return n;
620 }
621
622 //---------------------------clone_deep----------------------------------------
623 JVMState* JVMState::clone_deep(Compile* C) const {
624 JVMState* n = clone_shallow(C);
625 for (JVMState* p = n; p->_caller != nullptr; p = p->_caller) {
626 p->_caller = p->_caller->clone_shallow(C);
627 }
628 assert(n->depth() == depth(), "sanity");
629 assert(n->debug_depth() == debug_depth(), "sanity");
630 return n;
631 }
632
633 /**
634 * Reset map for all callers
635 */
636 void JVMState::set_map_deep(SafePointNode* map) {
637 for (JVMState* p = this; p != nullptr; p = p->_caller) {
638 p->set_map(map);
639 }
640 }
641
642 // unlike set_map(), this is two-way setting.
643 void JVMState::bind_map(SafePointNode* map) {
644 set_map(map);
645 _map->set_jvms(this);
646 }
647
648 // Adapt offsets in in-array after adding or removing an edge.
649 // Prerequisite is that the JVMState is used by only one node.
650 void JVMState::adapt_position(int delta) {
651 for (JVMState* jvms = this; jvms != nullptr; jvms = jvms->caller()) {
652 jvms->set_locoff(jvms->locoff() + delta);
653 jvms->set_stkoff(jvms->stkoff() + delta);
654 jvms->set_monoff(jvms->monoff() + delta);
655 jvms->set_scloff(jvms->scloff() + delta);
656 jvms->set_endoff(jvms->endoff() + delta);
657 }
658 }
659
660 // Mirror the stack size calculation in the deopt code
661 // How much stack space would we need at this point in the program in
662 // case of deoptimization?
663 int JVMState::interpreter_frame_size() const {
664 const JVMState* jvms = this;
665 int size = 0;
666 int callee_parameters = 0;
667 int callee_locals = 0;
668 int extra_args = method()->max_stack() - stk_size();
669
670 while (jvms != nullptr) {
671 int locks = jvms->nof_monitors();
672 int temps = jvms->stk_size();
673 bool is_top_frame = (jvms == this);
674 ciMethod* method = jvms->method();
675
676 int frame_size = BytesPerWord * Interpreter::size_activation(method->max_stack(),
677 temps + callee_parameters,
678 extra_args,
679 locks,
680 callee_parameters,
681 callee_locals,
682 is_top_frame);
683 size += frame_size;
684
685 callee_parameters = method->size_of_parameters();
686 callee_locals = method->max_locals();
687 extra_args = 0;
688 jvms = jvms->caller();
689 }
690 return size + Deoptimization::last_frame_adjust(0, callee_locals) * BytesPerWord;
691 }
692
693 // Compute receiver info for a compiled lambda form at call site.
694 ciInstance* JVMState::compute_receiver_info(ciMethod* callee) const {
695 assert(callee != nullptr && callee->is_compiled_lambda_form(), "");
696 if (has_method() && method()->is_compiled_lambda_form()) { // callee is not a MH invoker
697 Node* recv = map()->argument(this, 0);
698 assert(recv != nullptr, "");
699 const TypeOopPtr* recv_toop = recv->bottom_type()->isa_oopptr();
700 if (recv_toop != nullptr && recv_toop->const_oop() != nullptr) {
701 return recv_toop->const_oop()->as_instance();
702 }
703 }
704 return nullptr;
705 }
706
707 //=============================================================================
708 bool CallNode::cmp( const Node &n ) const
709 { return _tf == ((CallNode&)n)._tf && _jvms == ((CallNode&)n)._jvms; }
710 #ifndef PRODUCT
711 void CallNode::dump_req(outputStream *st, DumpConfig* dc) const {
712 // Dump the required inputs, enclosed in '(' and ')'
713 uint i; // Exit value of loop
714 for (i = 0; i < req(); i++) { // For all required inputs
715 if (i == TypeFunc::Parms) st->print("(");
716 Node* p = in(i);
717 if (p != nullptr) {
718 p->dump_idx(false, st, dc);
719 st->print(" ");
720 } else {
721 st->print("_ ");
722 }
723 }
724 st->print(")");
725 }
726
727 void CallNode::dump_spec(outputStream *st) const {
728 st->print(" ");
729 if (tf() != nullptr) tf()->dump_on(st);
730 if (_cnt != COUNT_UNKNOWN) st->print(" C=%f",_cnt);
731 if (jvms() != nullptr) jvms()->dump_spec(st);
732 }
733
734 void AllocateNode::dump_spec(outputStream* st) const {
735 st->print(" ");
736 if (tf() != nullptr) {
737 tf()->dump_on(st);
738 }
739 if (_cnt != COUNT_UNKNOWN) {
740 st->print(" C=%f", _cnt);
741 }
742 const Node* const klass_node = in(KlassNode);
743 if (klass_node != nullptr) {
744 const TypeKlassPtr* const klass_ptr = klass_node->bottom_type()->isa_klassptr();
745
746 if (klass_ptr != nullptr && klass_ptr->klass_is_exact()) {
747 st->print(" allocationKlass:");
748 klass_ptr->exact_klass()->print_name_on(st);
749 }
750 }
751 if (jvms() != nullptr) {
752 jvms()->dump_spec(st);
753 }
754 }
755 #endif
756
757 const Type *CallNode::bottom_type() const { return tf()->range(); }
758 const Type* CallNode::Value(PhaseGVN* phase) const {
759 if (in(0) == nullptr || phase->type(in(0)) == Type::TOP) {
760 return Type::TOP;
761 }
762 return tf()->range();
763 }
764
765 //------------------------------calling_convention-----------------------------
766 void CallNode::calling_convention(BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt) const {
767 // Use the standard compiler calling convention
768 SharedRuntime::java_calling_convention(sig_bt, parm_regs, argcnt);
769 }
770
771
772 //------------------------------match------------------------------------------
773 // Construct projections for control, I/O, memory-fields, ..., and
774 // return result(s) along with their RegMask info
775 Node *CallNode::match( const ProjNode *proj, const Matcher *match ) {
776 switch (proj->_con) {
777 case TypeFunc::Control:
778 case TypeFunc::I_O:
779 case TypeFunc::Memory:
780 return new MachProjNode(this,proj->_con,RegMask::EMPTY,MachProjNode::unmatched_proj);
781
782 case TypeFunc::Parms+1: // For LONG & DOUBLE returns
783 assert(tf()->range()->field_at(TypeFunc::Parms+1) == Type::HALF, "");
784 // 2nd half of doubles and longs
785 return new MachProjNode(this,proj->_con, RegMask::EMPTY, (uint)OptoReg::Bad);
786
787 case TypeFunc::Parms: { // Normal returns
788 uint ideal_reg = tf()->range()->field_at(TypeFunc::Parms)->ideal_reg();
789 OptoRegPair regs = Opcode() == Op_CallLeafVector
790 ? match->vector_return_value(ideal_reg) // Calls into assembly vector routine
791 : is_CallRuntime()
792 ? match->c_return_value(ideal_reg) // Calls into C runtime
793 : match-> return_value(ideal_reg); // Calls into compiled Java code
794 RegMask rm = RegMask(regs.first());
795
796 if (Opcode() == Op_CallLeafVector) {
797 // If the return is in vector, compute appropriate regmask taking into account the whole range
798 if(ideal_reg >= Op_VecA && ideal_reg <= Op_VecZ) {
799 if(OptoReg::is_valid(regs.second())) {
800 for (OptoReg::Name r = regs.first(); r <= regs.second(); r = OptoReg::add(r, 1)) {
801 rm.insert(r);
802 }
803 }
804 }
805 }
806
807 if( OptoReg::is_valid(regs.second()) )
808 rm.insert(regs.second());
809 return new MachProjNode(this,proj->_con,rm,ideal_reg);
810 }
811
812 case TypeFunc::ReturnAdr:
813 case TypeFunc::FramePtr:
814 default:
815 ShouldNotReachHere();
816 }
817 return nullptr;
818 }
819
820 // Do we Match on this edge index or not? Match no edges
821 uint CallNode::match_edge(uint idx) const {
822 return 0;
823 }
824
825 //
826 // Determine whether the call could modify the field of the specified
827 // instance at the specified offset.
828 //
829 bool CallNode::may_modify(const TypeOopPtr* t_oop, PhaseValues* phase) {
830 assert((t_oop != nullptr), "sanity");
831 if (is_call_to_arraycopystub() && strcmp(_name, "unsafe_arraycopy") != 0) {
832 const TypeTuple* args = _tf->domain();
833 Node* dest = nullptr;
834 // Stubs that can be called once an ArrayCopyNode is expanded have
835 // different signatures. Look for the second pointer argument,
836 // that is the destination of the copy.
837 for (uint i = TypeFunc::Parms, j = 0; i < args->cnt(); i++) {
838 if (args->field_at(i)->isa_ptr()) {
839 j++;
840 if (j == 2) {
841 dest = in(i);
842 break;
843 }
844 }
845 }
846 guarantee(dest != nullptr, "Call had only one ptr in, broken IR!");
847 if (!dest->is_top() && may_modify_arraycopy_helper(phase->type(dest)->is_oopptr(), t_oop, phase)) {
848 return true;
849 }
850 return false;
851 }
852 if (t_oop->is_known_instance()) {
853 // The instance_id is set only for scalar-replaceable allocations which
854 // are not passed as arguments according to Escape Analysis.
855 return false;
856 }
857 if (t_oop->is_ptr_to_boxed_value()) {
858 ciKlass* boxing_klass = t_oop->is_instptr()->instance_klass();
859 if (is_CallStaticJava() && as_CallStaticJava()->is_boxing_method()) {
860 // Skip unrelated boxing methods.
861 Node* proj = proj_out_or_null(TypeFunc::Parms);
862 if ((proj == nullptr) || (phase->type(proj)->is_instptr()->instance_klass() != boxing_klass)) {
863 return false;
864 }
865 }
866 if (is_CallJava() && as_CallJava()->method() != nullptr) {
867 ciMethod* meth = as_CallJava()->method();
868 if (meth->is_getter()) {
869 return false;
870 }
871 // May modify (by reflection) if an boxing object is passed
872 // as argument or returned.
873 Node* proj = returns_pointer() ? proj_out_or_null(TypeFunc::Parms) : nullptr;
874 if (proj != nullptr) {
875 const TypeInstPtr* inst_t = phase->type(proj)->isa_instptr();
876 if ((inst_t != nullptr) && (!inst_t->klass_is_exact() ||
877 (inst_t->instance_klass() == boxing_klass))) {
878 return true;
879 }
880 }
881 const TypeTuple* d = tf()->domain();
882 for (uint i = TypeFunc::Parms; i < d->cnt(); i++) {
883 const TypeInstPtr* inst_t = d->field_at(i)->isa_instptr();
884 if ((inst_t != nullptr) && (!inst_t->klass_is_exact() ||
885 (inst_t->instance_klass() == boxing_klass))) {
886 return true;
887 }
888 }
889 return false;
890 }
891 }
892 return true;
893 }
894
895 // Does this call have a direct reference to n other than debug information?
896 bool CallNode::has_non_debug_use(Node *n) {
897 const TypeTuple * d = tf()->domain();
898 for (uint i = TypeFunc::Parms; i < d->cnt(); i++) {
899 Node *arg = in(i);
900 if (arg == n) {
901 return true;
902 }
903 }
904 return false;
905 }
906
907 // Returns the unique CheckCastPP of a call
908 // or 'this' if there are several CheckCastPP or unexpected uses
909 // or returns null if there is no one.
910 Node *CallNode::result_cast() {
911 Node *cast = nullptr;
912
913 Node *p = proj_out_or_null(TypeFunc::Parms);
914 if (p == nullptr)
915 return nullptr;
916
917 for (DUIterator_Fast imax, i = p->fast_outs(imax); i < imax; i++) {
918 Node *use = p->fast_out(i);
919 if (use->is_CheckCastPP()) {
920 if (cast != nullptr) {
921 return this; // more than 1 CheckCastPP
922 }
923 cast = use;
924 } else if (!use->is_Initialize() &&
925 !use->is_AddP() &&
926 use->Opcode() != Op_MemBarStoreStore) {
927 // Expected uses are restricted to a CheckCastPP, an Initialize
928 // node, a MemBarStoreStore (clone) and AddP nodes. If we
929 // encounter any other use (a Phi node can be seen in rare
930 // cases) return this to prevent incorrect optimizations.
931 return this;
932 }
933 }
934 return cast;
935 }
936
937
938 void CallNode::extract_projections(CallProjections* projs, bool separate_io_proj, bool do_asserts) const {
939 projs->fallthrough_proj = nullptr;
940 projs->fallthrough_catchproj = nullptr;
941 projs->fallthrough_ioproj = nullptr;
942 projs->catchall_ioproj = nullptr;
943 projs->catchall_catchproj = nullptr;
944 projs->fallthrough_memproj = nullptr;
945 projs->catchall_memproj = nullptr;
946 projs->resproj = nullptr;
947 projs->exobj = nullptr;
948
949 for (DUIterator_Fast imax, i = fast_outs(imax); i < imax; i++) {
950 ProjNode *pn = fast_out(i)->as_Proj();
951 if (pn->outcnt() == 0) continue;
952 switch (pn->_con) {
953 case TypeFunc::Control:
954 {
955 // For Control (fallthrough) and I_O (catch_all_index) we have CatchProj -> Catch -> Proj
956 projs->fallthrough_proj = pn;
957 const Node* cn = pn->unique_ctrl_out_or_null();
958 if (cn != nullptr && cn->is_Catch()) {
959 ProjNode *cpn = nullptr;
960 for (DUIterator_Fast kmax, k = cn->fast_outs(kmax); k < kmax; k++) {
961 cpn = cn->fast_out(k)->as_Proj();
962 assert(cpn->is_CatchProj(), "must be a CatchProjNode");
963 if (cpn->_con == CatchProjNode::fall_through_index)
964 projs->fallthrough_catchproj = cpn;
965 else {
966 assert(cpn->_con == CatchProjNode::catch_all_index, "must be correct index.");
967 projs->catchall_catchproj = cpn;
968 }
969 }
970 }
971 break;
972 }
973 case TypeFunc::I_O:
974 if (pn->_is_io_use)
975 projs->catchall_ioproj = pn;
976 else
977 projs->fallthrough_ioproj = pn;
978 for (DUIterator j = pn->outs(); pn->has_out(j); j++) {
979 Node* e = pn->out(j);
980 if (e->Opcode() == Op_CreateEx && e->in(0)->is_CatchProj() && e->outcnt() > 0) {
981 assert(projs->exobj == nullptr, "only one");
982 projs->exobj = e;
983 }
984 }
985 break;
986 case TypeFunc::Memory:
987 if (pn->_is_io_use)
988 projs->catchall_memproj = pn;
989 else
990 projs->fallthrough_memproj = pn;
991 break;
992 case TypeFunc::Parms:
993 projs->resproj = pn;
994 break;
995 default:
996 assert(false, "unexpected projection from allocation node.");
997 }
998 }
999
1000 // The resproj may not exist because the result could be ignored
1001 // and the exception object may not exist if an exception handler
1002 // swallows the exception but all the other must exist and be found.
1003 assert(projs->fallthrough_proj != nullptr, "must be found");
1004 do_asserts = do_asserts && !Compile::current()->inlining_incrementally();
1005 assert(!do_asserts || projs->fallthrough_catchproj != nullptr, "must be found");
1006 assert(!do_asserts || projs->fallthrough_memproj != nullptr, "must be found");
1007 assert(!do_asserts || projs->fallthrough_ioproj != nullptr, "must be found");
1008 assert(!do_asserts || projs->catchall_catchproj != nullptr, "must be found");
1009 if (separate_io_proj) {
1010 assert(!do_asserts || projs->catchall_memproj != nullptr, "must be found");
1011 assert(!do_asserts || projs->catchall_ioproj != nullptr, "must be found");
1012 }
1013 }
1014
1015 Node* CallNode::Ideal(PhaseGVN* phase, bool can_reshape) {
1016 #ifdef ASSERT
1017 // Validate attached generator
1018 CallGenerator* cg = generator();
1019 if (cg != nullptr) {
1020 assert((is_CallStaticJava() && cg->is_mh_late_inline()) ||
1021 (is_CallDynamicJava() && cg->is_virtual_late_inline()), "mismatch");
1022 }
1023 #endif // ASSERT
1024 return SafePointNode::Ideal(phase, can_reshape);
1025 }
1026
1027 bool CallNode::is_call_to_arraycopystub() const {
1028 if (_name != nullptr && strstr(_name, "arraycopy") != nullptr) {
1029 return true;
1030 }
1031 return false;
1032 }
1033
1034 //=============================================================================
1035 uint CallJavaNode::size_of() const { return sizeof(*this); }
1036 bool CallJavaNode::cmp( const Node &n ) const {
1037 CallJavaNode &call = (CallJavaNode&)n;
1038 return CallNode::cmp(call) && _method == call._method &&
1039 _override_symbolic_info == call._override_symbolic_info;
1040 }
1041
1042 void CallJavaNode::copy_call_debug_info(PhaseIterGVN* phase, SafePointNode* sfpt) {
1043 // Copy debug information and adjust JVMState information
1044 uint old_dbg_start = sfpt->is_Call() ? sfpt->as_Call()->tf()->domain()->cnt() : (uint)TypeFunc::Parms+1;
1045 uint new_dbg_start = tf()->domain()->cnt();
1046 int jvms_adj = new_dbg_start - old_dbg_start;
1047 assert (new_dbg_start == req(), "argument count mismatch");
1048 Compile* C = phase->C;
1049
1050 // SafePointScalarObject node could be referenced several times in debug info.
1051 // Use Dict to record cloned nodes.
1052 Dict* sosn_map = new Dict(cmpkey,hashkey);
1053 for (uint i = old_dbg_start; i < sfpt->req(); i++) {
1054 Node* old_in = sfpt->in(i);
1055 // Clone old SafePointScalarObjectNodes, adjusting their field contents.
1056 if (old_in != nullptr && old_in->is_SafePointScalarObject()) {
1057 SafePointScalarObjectNode* old_sosn = old_in->as_SafePointScalarObject();
1058 bool new_node;
1059 Node* new_in = old_sosn->clone(sosn_map, new_node);
1060 if (new_node) { // New node?
1061 new_in->set_req(0, C->root()); // reset control edge
1062 new_in = phase->transform(new_in); // Register new node.
1063 }
1064 old_in = new_in;
1065 }
1066 add_req(old_in);
1067 }
1068
1069 // JVMS may be shared so clone it before we modify it
1070 set_jvms(sfpt->jvms() != nullptr ? sfpt->jvms()->clone_deep(C) : nullptr);
1071 for (JVMState *jvms = this->jvms(); jvms != nullptr; jvms = jvms->caller()) {
1072 jvms->set_map(this);
1073 jvms->set_locoff(jvms->locoff()+jvms_adj);
1074 jvms->set_stkoff(jvms->stkoff()+jvms_adj);
1075 jvms->set_monoff(jvms->monoff()+jvms_adj);
1076 jvms->set_scloff(jvms->scloff()+jvms_adj);
1077 jvms->set_endoff(jvms->endoff()+jvms_adj);
1078 }
1079 }
1080
1081 #ifdef ASSERT
1082 bool CallJavaNode::validate_symbolic_info() const {
1083 if (method() == nullptr) {
1084 return true; // call into runtime or uncommon trap
1085 }
1086 ciMethod* symbolic_info = jvms()->method()->get_method_at_bci(jvms()->bci());
1087 ciMethod* callee = method();
1088 if (symbolic_info->is_method_handle_intrinsic() && !callee->is_method_handle_intrinsic()) {
1089 assert(override_symbolic_info(), "should be set");
1090 }
1091 assert(ciMethod::is_consistent_info(symbolic_info, callee), "inconsistent info");
1092 return true;
1093 }
1094 #endif
1095
1096 #ifndef PRODUCT
1097 void CallJavaNode::dump_spec(outputStream* st) const {
1098 if( _method ) _method->print_short_name(st);
1099 CallNode::dump_spec(st);
1100 }
1101
1102 void CallJavaNode::dump_compact_spec(outputStream* st) const {
1103 if (_method) {
1104 _method->print_short_name(st);
1105 } else {
1106 st->print("<?>");
1107 }
1108 }
1109 #endif
1110
1111 void CallJavaNode::register_for_late_inline() {
1112 if (generator() != nullptr) {
1113 Compile::current()->prepend_late_inline(generator());
1114 set_generator(nullptr);
1115 } else {
1116 assert(false, "repeated inline attempt");
1117 }
1118 }
1119
1120 //=============================================================================
1121 uint CallStaticJavaNode::size_of() const { return sizeof(*this); }
1122 bool CallStaticJavaNode::cmp( const Node &n ) const {
1123 CallStaticJavaNode &call = (CallStaticJavaNode&)n;
1124 return CallJavaNode::cmp(call);
1125 }
1126
1127 Node* CallStaticJavaNode::Ideal(PhaseGVN* phase, bool can_reshape) {
1128 CallGenerator* cg = generator();
1129 if (can_reshape && cg != nullptr) {
1130 if (cg->is_mh_late_inline()) {
1131 assert(IncrementalInlineMH, "required");
1132 assert(cg->call_node() == this, "mismatch");
1133 assert(cg->method()->is_method_handle_intrinsic(), "required");
1134
1135 // Check whether this MH handle call becomes a candidate for inlining.
1136 ciMethod* callee = cg->method();
1137 vmIntrinsics::ID iid = callee->intrinsic_id();
1138 if (iid == vmIntrinsics::_invokeBasic) {
1139 if (in(TypeFunc::Parms)->Opcode() == Op_ConP) {
1140 register_for_late_inline();
1141 }
1142 } else if (iid == vmIntrinsics::_linkToNative) {
1143 // never retry
1144 } else {
1145 assert(callee->has_member_arg(), "wrong type of call?");
1146 if (in(TypeFunc::Parms + callee->arg_size() - 1)->Opcode() == Op_ConP) {
1147 register_for_late_inline();
1148 }
1149 }
1150 } else {
1151 assert(IncrementalInline, "required");
1152 assert(!cg->method()->is_method_handle_intrinsic(), "required");
1153 if (phase->C->print_inlining()) {
1154 phase->C->inline_printer()->record(cg->method(), cg->call_node()->jvms(), InliningResult::FAILURE,
1155 "static call node changed: trying again");
1156 }
1157 register_for_late_inline();
1158 }
1159 }
1160 return CallNode::Ideal(phase, can_reshape);
1161 }
1162
1163 //----------------------------is_uncommon_trap----------------------------
1164 // Returns true if this is an uncommon trap.
1165 bool CallStaticJavaNode::is_uncommon_trap() const {
1166 return (_name != nullptr && !strcmp(_name, "uncommon_trap"));
1167 }
1168
1169 //----------------------------uncommon_trap_request----------------------------
1170 // If this is an uncommon trap, return the request code, else zero.
1171 int CallStaticJavaNode::uncommon_trap_request() const {
1172 return is_uncommon_trap() ? extract_uncommon_trap_request(this) : 0;
1173 }
1174 int CallStaticJavaNode::extract_uncommon_trap_request(const Node* call) {
1175 #ifndef PRODUCT
1176 if (!(call->req() > TypeFunc::Parms &&
1177 call->in(TypeFunc::Parms) != nullptr &&
1178 call->in(TypeFunc::Parms)->is_Con() &&
1179 call->in(TypeFunc::Parms)->bottom_type()->isa_int())) {
1180 assert(in_dump() != 0, "OK if dumping");
1181 tty->print("[bad uncommon trap]");
1182 return 0;
1183 }
1184 #endif
1185 return call->in(TypeFunc::Parms)->bottom_type()->is_int()->get_con();
1186 }
1187
1188 #ifndef PRODUCT
1189 void CallStaticJavaNode::dump_spec(outputStream *st) const {
1190 st->print("# Static ");
1191 if (_name != nullptr) {
1192 st->print("%s", _name);
1193 int trap_req = uncommon_trap_request();
1194 if (trap_req != 0) {
1195 char buf[100];
1196 st->print("(%s)",
1197 Deoptimization::format_trap_request(buf, sizeof(buf),
1198 trap_req));
1199 }
1200 st->print(" ");
1201 }
1202 CallJavaNode::dump_spec(st);
1203 }
1204
1205 void CallStaticJavaNode::dump_compact_spec(outputStream* st) const {
1206 if (_method) {
1207 _method->print_short_name(st);
1208 } else if (_name) {
1209 st->print("%s", _name);
1210 } else {
1211 st->print("<?>");
1212 }
1213 }
1214 #endif
1215
1216 //=============================================================================
1217 uint CallDynamicJavaNode::size_of() const { return sizeof(*this); }
1218 bool CallDynamicJavaNode::cmp( const Node &n ) const {
1219 CallDynamicJavaNode &call = (CallDynamicJavaNode&)n;
1220 return CallJavaNode::cmp(call);
1221 }
1222
1223 Node* CallDynamicJavaNode::Ideal(PhaseGVN* phase, bool can_reshape) {
1224 CallGenerator* cg = generator();
1225 if (can_reshape && cg != nullptr) {
1226 if (cg->is_virtual_late_inline()) {
1227 assert(IncrementalInlineVirtual, "required");
1228 assert(cg->call_node() == this, "mismatch");
1229
1230 if (cg->callee_method() == nullptr) {
1231 // Recover symbolic info for method resolution.
1232 ciMethod* caller = jvms()->method();
1233 ciBytecodeStream iter(caller);
1234 iter.force_bci(jvms()->bci());
1235
1236 bool not_used1;
1237 ciSignature* not_used2;
1238 ciMethod* orig_callee = iter.get_method(not_used1, ¬_used2); // callee in the bytecode
1239 ciKlass* holder = iter.get_declared_method_holder();
1240 if (orig_callee->is_method_handle_intrinsic()) {
1241 assert(_override_symbolic_info, "required");
1242 orig_callee = method();
1243 holder = method()->holder();
1244 }
1245
1246 ciInstanceKlass* klass = ciEnv::get_instance_klass_for_declared_method_holder(holder);
1247
1248 Node* receiver_node = in(TypeFunc::Parms);
1249 const TypeOopPtr* receiver_type = phase->type(receiver_node)->isa_oopptr();
1250
1251 int not_used3;
1252 bool call_does_dispatch;
1253 ciMethod* callee = phase->C->optimize_virtual_call(caller, klass, holder, orig_callee, receiver_type, true /*is_virtual*/,
1254 call_does_dispatch, not_used3); // out-parameters
1255 if (!call_does_dispatch) {
1256 cg->set_callee_method(callee);
1257 }
1258 }
1259 if (cg->callee_method() != nullptr) {
1260 // Register for late inlining.
1261 register_for_late_inline(); // MH late inlining prepends to the list, so do the same
1262 }
1263 } else {
1264 assert(IncrementalInline, "required");
1265 if (phase->C->print_inlining()) {
1266 phase->C->inline_printer()->record(cg->method(), cg->call_node()->jvms(), InliningResult::FAILURE,
1267 "dynamic call node changed: trying again");
1268 }
1269 register_for_late_inline();
1270 }
1271 }
1272 return CallNode::Ideal(phase, can_reshape);
1273 }
1274
1275 #ifndef PRODUCT
1276 void CallDynamicJavaNode::dump_spec(outputStream *st) const {
1277 st->print("# Dynamic ");
1278 CallJavaNode::dump_spec(st);
1279 }
1280 #endif
1281
1282 //=============================================================================
1283 uint CallRuntimeNode::size_of() const { return sizeof(*this); }
1284 bool CallRuntimeNode::cmp( const Node &n ) const {
1285 CallRuntimeNode &call = (CallRuntimeNode&)n;
1286 return CallNode::cmp(call) && !strcmp(_name,call._name);
1287 }
1288 #ifndef PRODUCT
1289 void CallRuntimeNode::dump_spec(outputStream *st) const {
1290 st->print("# ");
1291 st->print("%s", _name);
1292 CallNode::dump_spec(st);
1293 }
1294 #endif
1295 uint CallLeafVectorNode::size_of() const { return sizeof(*this); }
1296 bool CallLeafVectorNode::cmp( const Node &n ) const {
1297 CallLeafVectorNode &call = (CallLeafVectorNode&)n;
1298 return CallLeafNode::cmp(call) && _num_bits == call._num_bits;
1299 }
1300
1301 //------------------------------calling_convention-----------------------------
1302 void CallRuntimeNode::calling_convention(BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt) const {
1303 SharedRuntime::c_calling_convention(sig_bt, parm_regs, argcnt);
1304 }
1305
1306 void CallLeafVectorNode::calling_convention( BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt ) const {
1307 #ifdef ASSERT
1308 assert(tf()->range()->field_at(TypeFunc::Parms)->is_vect()->length_in_bytes() * BitsPerByte == _num_bits,
1309 "return vector size must match");
1310 const TypeTuple* d = tf()->domain();
1311 for (uint i = TypeFunc::Parms; i < d->cnt(); i++) {
1312 Node* arg = in(i);
1313 assert(arg->bottom_type()->is_vect()->length_in_bytes() * BitsPerByte == _num_bits,
1314 "vector argument size must match");
1315 }
1316 #endif
1317
1318 SharedRuntime::vector_calling_convention(parm_regs, _num_bits, argcnt);
1319 }
1320
1321 //=============================================================================
1322 //------------------------------calling_convention-----------------------------
1323
1324
1325 //=============================================================================
1326 bool CallLeafPureNode::is_unused() const {
1327 return proj_out_or_null(TypeFunc::Parms) == nullptr;
1328 }
1329
1330 bool CallLeafPureNode::is_dead() const {
1331 return proj_out_or_null(TypeFunc::Control) == nullptr;
1332 }
1333
1334 /* We make a tuple of the global input state + TOP for the output values.
1335 * We use this to delete a pure function that is not used: by replacing the call with
1336 * such a tuple, we let output Proj's idealization pick the corresponding input of the
1337 * pure call, so jumping over it, and effectively, removing the call from the graph.
1338 * This avoids doing the graph surgery manually, but leaves that to IGVN
1339 * that is specialized for doing that right. We need also tuple components for output
1340 * values of the function to respect the return arity, and in case there is a projection
1341 * that would pick an output (which shouldn't happen at the moment).
1342 */
1343 TupleNode* CallLeafPureNode::make_tuple_of_input_state_and_top_return_values(const Compile* C) const {
1344 // Transparently propagate input state but parameters
1345 TupleNode* tuple = TupleNode::make(
1346 tf()->range(),
1347 in(TypeFunc::Control),
1348 in(TypeFunc::I_O),
1349 in(TypeFunc::Memory),
1350 in(TypeFunc::FramePtr),
1351 in(TypeFunc::ReturnAdr));
1352
1353 // And add TOPs for the return values
1354 for (uint i = TypeFunc::Parms; i < tf()->range()->cnt(); i++) {
1355 tuple->set_req(i, C->top());
1356 }
1357
1358 return tuple;
1359 }
1360
1361 Node* CallLeafPureNode::Ideal(PhaseGVN* phase, bool can_reshape) {
1362 if (is_dead()) {
1363 return nullptr;
1364 }
1365
1366 // We need to wait until IGVN because during parsing, usages might still be missing
1367 // and we would remove the call immediately.
1368 if (can_reshape && is_unused()) {
1369 // The result is not used. We remove the call by replacing it with a tuple, that
1370 // is later disintegrated by the projections.
1371 return make_tuple_of_input_state_and_top_return_values(phase->C);
1372 }
1373
1374 return CallRuntimeNode::Ideal(phase, can_reshape);
1375 }
1376
1377 #ifndef PRODUCT
1378 void CallLeafNode::dump_spec(outputStream *st) const {
1379 st->print("# ");
1380 st->print("%s", _name);
1381 CallNode::dump_spec(st);
1382 }
1383 #endif
1384
1385 //=============================================================================
1386
1387 void SafePointNode::set_local(const JVMState* jvms, uint idx, Node *c) {
1388 assert(verify_jvms(jvms), "jvms must match");
1389 int loc = jvms->locoff() + idx;
1390 if (in(loc)->is_top() && idx > 0 && !c->is_top() ) {
1391 // If current local idx is top then local idx - 1 could
1392 // be a long/double that needs to be killed since top could
1393 // represent the 2nd half of the long/double.
1394 uint ideal = in(loc -1)->ideal_reg();
1395 if (ideal == Op_RegD || ideal == Op_RegL) {
1396 // set other (low index) half to top
1397 set_req(loc - 1, in(loc));
1398 }
1399 }
1400 set_req(loc, c);
1401 }
1402
1403 uint SafePointNode::size_of() const { return sizeof(*this); }
1404 bool SafePointNode::cmp( const Node &n ) const {
1405 return (&n == this); // Always fail except on self
1406 }
1407
1408 //-------------------------set_next_exception----------------------------------
1409 void SafePointNode::set_next_exception(SafePointNode* n) {
1410 assert(n == nullptr || n->Opcode() == Op_SafePoint, "correct value for next_exception");
1411 if (len() == req()) {
1412 if (n != nullptr) add_prec(n);
1413 } else {
1414 set_prec(req(), n);
1415 }
1416 }
1417
1418
1419 //----------------------------next_exception-----------------------------------
1420 SafePointNode* SafePointNode::next_exception() const {
1421 if (len() == req()) {
1422 return nullptr;
1423 } else {
1424 Node* n = in(req());
1425 assert(n == nullptr || n->Opcode() == Op_SafePoint, "no other uses of prec edges");
1426 return (SafePointNode*) n;
1427 }
1428 }
1429
1430
1431 //------------------------------Ideal------------------------------------------
1432 // Skip over any collapsed Regions
1433 Node *SafePointNode::Ideal(PhaseGVN *phase, bool can_reshape) {
1434 assert(_jvms == nullptr || ((uintptr_t)_jvms->map() & 1) || _jvms->map() == this, "inconsistent JVMState");
1435 return remove_dead_region(phase, can_reshape) ? this : nullptr;
1436 }
1437
1438 //------------------------------Identity---------------------------------------
1439 // Remove obviously duplicate safepoints
1440 Node* SafePointNode::Identity(PhaseGVN* phase) {
1441
1442 // If you have back to back safepoints, remove one
1443 if (in(TypeFunc::Control)->is_SafePoint()) {
1444 Node* out_c = unique_ctrl_out_or_null();
1445 // This can be the safepoint of an outer strip mined loop if the inner loop's backedge was removed. Replacing the
1446 // outer loop's safepoint could confuse removal of the outer loop.
1447 if (out_c != nullptr && !out_c->is_OuterStripMinedLoopEnd()) {
1448 return in(TypeFunc::Control);
1449 }
1450 }
1451
1452 // Transforming long counted loops requires a safepoint node. Do not
1453 // eliminate a safepoint until loop opts are over.
1454 if (in(0)->is_Proj() && !phase->C->major_progress()) {
1455 Node *n0 = in(0)->in(0);
1456 // Check if he is a call projection (except Leaf Call)
1457 if( n0->is_Catch() ) {
1458 n0 = n0->in(0)->in(0);
1459 assert( n0->is_Call(), "expect a call here" );
1460 }
1461 if( n0->is_Call() && n0->as_Call()->guaranteed_safepoint() ) {
1462 // Don't remove a safepoint belonging to an OuterStripMinedLoopEndNode.
1463 // If the loop dies, they will be removed together.
1464 if (has_out_with(Op_OuterStripMinedLoopEnd)) {
1465 return this;
1466 }
1467 // Useless Safepoint, so remove it
1468 return in(TypeFunc::Control);
1469 }
1470 }
1471
1472 return this;
1473 }
1474
1475 //------------------------------Value------------------------------------------
1476 const Type* SafePointNode::Value(PhaseGVN* phase) const {
1477 if (phase->type(in(0)) == Type::TOP) {
1478 return Type::TOP;
1479 }
1480 if (in(0) == this) {
1481 return Type::TOP; // Dead infinite loop
1482 }
1483 return Type::CONTROL;
1484 }
1485
1486 #ifndef PRODUCT
1487 void SafePointNode::dump_spec(outputStream *st) const {
1488 st->print(" SafePoint ");
1489 _replaced_nodes.dump(st);
1490 }
1491 #endif
1492
1493 const RegMask &SafePointNode::in_RegMask(uint idx) const {
1494 if (idx < TypeFunc::Parms) {
1495 return RegMask::EMPTY;
1496 }
1497 // Values outside the domain represent debug info
1498 return *(Compile::current()->matcher()->idealreg2debugmask[in(idx)->ideal_reg()]);
1499 }
1500 const RegMask &SafePointNode::out_RegMask() const {
1501 return RegMask::EMPTY;
1502 }
1503
1504
1505 void SafePointNode::grow_stack(JVMState* jvms, uint grow_by) {
1506 assert((int)grow_by > 0, "sanity");
1507 int monoff = jvms->monoff();
1508 int scloff = jvms->scloff();
1509 int endoff = jvms->endoff();
1510 assert(endoff == (int)req(), "no other states or debug info after me");
1511 Node* top = Compile::current()->top();
1512 for (uint i = 0; i < grow_by; i++) {
1513 ins_req(monoff, top);
1514 }
1515 jvms->set_monoff(monoff + grow_by);
1516 jvms->set_scloff(scloff + grow_by);
1517 jvms->set_endoff(endoff + grow_by);
1518 }
1519
1520 void SafePointNode::push_monitor(const FastLockNode *lock) {
1521 // Add a LockNode, which points to both the original BoxLockNode (the
1522 // stack space for the monitor) and the Object being locked.
1523 const int MonitorEdges = 2;
1524 assert(JVMState::logMonitorEdges == exact_log2(MonitorEdges), "correct MonitorEdges");
1525 assert(req() == jvms()->endoff(), "correct sizing");
1526 int nextmon = jvms()->scloff();
1527 ins_req(nextmon, lock->box_node());
1528 ins_req(nextmon+1, lock->obj_node());
1529 jvms()->set_scloff(nextmon + MonitorEdges);
1530 jvms()->set_endoff(req());
1531 }
1532
1533 void SafePointNode::pop_monitor() {
1534 // Delete last monitor from debug info
1535 DEBUG_ONLY(int num_before_pop = jvms()->nof_monitors());
1536 const int MonitorEdges = 2;
1537 assert(JVMState::logMonitorEdges == exact_log2(MonitorEdges), "correct MonitorEdges");
1538 int scloff = jvms()->scloff();
1539 int endoff = jvms()->endoff();
1540 int new_scloff = scloff - MonitorEdges;
1541 int new_endoff = endoff - MonitorEdges;
1542 jvms()->set_scloff(new_scloff);
1543 jvms()->set_endoff(new_endoff);
1544 while (scloff > new_scloff) del_req_ordered(--scloff);
1545 assert(jvms()->nof_monitors() == num_before_pop-1, "");
1546 }
1547
1548 Node *SafePointNode::peek_monitor_box() const {
1549 int mon = jvms()->nof_monitors() - 1;
1550 assert(mon >= 0, "must have a monitor");
1551 return monitor_box(jvms(), mon);
1552 }
1553
1554 Node *SafePointNode::peek_monitor_obj() const {
1555 int mon = jvms()->nof_monitors() - 1;
1556 assert(mon >= 0, "must have a monitor");
1557 return monitor_obj(jvms(), mon);
1558 }
1559
1560 Node* SafePointNode::peek_operand(uint off) const {
1561 assert(jvms()->sp() > 0, "must have an operand");
1562 assert(off < jvms()->sp(), "off is out-of-range");
1563 return stack(jvms(), jvms()->sp() - off - 1);
1564 }
1565
1566 // Do we Match on this edge index or not? Match no edges
1567 uint SafePointNode::match_edge(uint idx) const {
1568 return (TypeFunc::Parms == idx);
1569 }
1570
1571 void SafePointNode::disconnect_from_root(PhaseIterGVN *igvn) {
1572 assert(Opcode() == Op_SafePoint, "only value for safepoint in loops");
1573 int nb = igvn->C->root()->find_prec_edge(this);
1574 if (nb != -1) {
1575 igvn->delete_precedence_of(igvn->C->root(), nb);
1576 }
1577 }
1578
1579 //============== SafePointScalarObjectNode ==============
1580
1581 SafePointScalarObjectNode::SafePointScalarObjectNode(const TypeOopPtr* tp, Node* alloc, uint first_index, uint depth, uint n_fields) :
1582 TypeNode(tp, 1), // 1 control input -- seems required. Get from root.
1583 _first_index(first_index),
1584 _depth(depth),
1585 _n_fields(n_fields),
1586 _alloc(alloc)
1587 {
1588 #ifdef ASSERT
1589 if (!alloc->is_Allocate() && !(alloc->Opcode() == Op_VectorBox)) {
1590 alloc->dump();
1591 assert(false, "unexpected call node");
1592 }
1593 #endif
1594 init_class_id(Class_SafePointScalarObject);
1595 }
1596
1597 // Do not allow value-numbering for SafePointScalarObject node.
1598 uint SafePointScalarObjectNode::hash() const { return NO_HASH; }
1599 bool SafePointScalarObjectNode::cmp( const Node &n ) const {
1600 return (&n == this); // Always fail except on self
1601 }
1602
1603 uint SafePointScalarObjectNode::ideal_reg() const {
1604 return 0; // No matching to machine instruction
1605 }
1606
1607 const RegMask &SafePointScalarObjectNode::in_RegMask(uint idx) const {
1608 return *(Compile::current()->matcher()->idealreg2debugmask[in(idx)->ideal_reg()]);
1609 }
1610
1611 const RegMask &SafePointScalarObjectNode::out_RegMask() const {
1612 return RegMask::EMPTY;
1613 }
1614
1615 uint SafePointScalarObjectNode::match_edge(uint idx) const {
1616 return 0;
1617 }
1618
1619 SafePointScalarObjectNode*
1620 SafePointScalarObjectNode::clone(Dict* sosn_map, bool& new_node) const {
1621 void* cached = (*sosn_map)[(void*)this];
1622 if (cached != nullptr) {
1623 new_node = false;
1624 return (SafePointScalarObjectNode*)cached;
1625 }
1626 new_node = true;
1627 SafePointScalarObjectNode* res = (SafePointScalarObjectNode*)Node::clone();
1628 sosn_map->Insert((void*)this, (void*)res);
1629 return res;
1630 }
1631
1632
1633 #ifndef PRODUCT
1634 void SafePointScalarObjectNode::dump_spec(outputStream *st) const {
1635 st->print(" # fields@[%d..%d]", first_index(), first_index() + n_fields() - 1);
1636 }
1637 #endif
1638
1639 //============== SafePointScalarMergeNode ==============
1640
1641 SafePointScalarMergeNode::SafePointScalarMergeNode(const TypeOopPtr* tp, int merge_pointer_idx) :
1642 TypeNode(tp, 1), // 1 control input -- seems required. Get from root.
1643 _merge_pointer_idx(merge_pointer_idx)
1644 {
1645 init_class_id(Class_SafePointScalarMerge);
1646 }
1647
1648 // Do not allow value-numbering for SafePointScalarMerge node.
1649 uint SafePointScalarMergeNode::hash() const { return NO_HASH; }
1650 bool SafePointScalarMergeNode::cmp( const Node &n ) const {
1651 return (&n == this); // Always fail except on self
1652 }
1653
1654 uint SafePointScalarMergeNode::ideal_reg() const {
1655 return 0; // No matching to machine instruction
1656 }
1657
1658 const RegMask &SafePointScalarMergeNode::in_RegMask(uint idx) const {
1659 return *(Compile::current()->matcher()->idealreg2debugmask[in(idx)->ideal_reg()]);
1660 }
1661
1662 const RegMask &SafePointScalarMergeNode::out_RegMask() const {
1663 return RegMask::EMPTY;
1664 }
1665
1666 uint SafePointScalarMergeNode::match_edge(uint idx) const {
1667 return 0;
1668 }
1669
1670 SafePointScalarMergeNode*
1671 SafePointScalarMergeNode::clone(Dict* sosn_map, bool& new_node) const {
1672 void* cached = (*sosn_map)[(void*)this];
1673 if (cached != nullptr) {
1674 new_node = false;
1675 return (SafePointScalarMergeNode*)cached;
1676 }
1677 new_node = true;
1678 SafePointScalarMergeNode* res = (SafePointScalarMergeNode*)Node::clone();
1679 sosn_map->Insert((void*)this, (void*)res);
1680 return res;
1681 }
1682
1683 #ifndef PRODUCT
1684 void SafePointScalarMergeNode::dump_spec(outputStream *st) const {
1685 st->print(" # merge_pointer_idx=%d, scalarized_objects=%d", _merge_pointer_idx, req()-1);
1686 }
1687 #endif
1688
1689 //=============================================================================
1690 uint AllocateNode::size_of() const { return sizeof(*this); }
1691
1692 AllocateNode::AllocateNode(Compile* C, const TypeFunc *atype,
1693 Node *ctrl, Node *mem, Node *abio,
1694 Node *size, Node *klass_node, Node *initial_test)
1695 : CallNode(atype, nullptr, TypeRawPtr::BOTTOM)
1696 {
1697 init_class_id(Class_Allocate);
1698 init_flags(Flag_is_macro);
1699 _is_scalar_replaceable = false;
1700 _is_non_escaping = false;
1701 _is_allocation_MemBar_redundant = false;
1702 Node *topnode = C->top();
1703
1704 init_req( TypeFunc::Control , ctrl );
1705 init_req( TypeFunc::I_O , abio );
1706 init_req( TypeFunc::Memory , mem );
1707 init_req( TypeFunc::ReturnAdr, topnode );
1708 init_req( TypeFunc::FramePtr , topnode );
1709 init_req( AllocSize , size);
1710 init_req( KlassNode , klass_node);
1711 init_req( InitialTest , initial_test);
1712 init_req( ALength , topnode);
1713 init_req( ValidLengthTest , topnode);
1714 C->add_macro_node(this);
1715 }
1716
1717 void AllocateNode::compute_MemBar_redundancy(ciMethod* initializer)
1718 {
1719 assert(initializer != nullptr && initializer->is_object_initializer(),
1720 "unexpected initializer method");
1721 BCEscapeAnalyzer* analyzer = initializer->get_bcea();
1722 if (analyzer == nullptr) {
1723 return;
1724 }
1725
1726 // Allocation node is first parameter in its initializer
1727 if (analyzer->is_arg_stack(0) || analyzer->is_arg_local(0)) {
1728 _is_allocation_MemBar_redundant = true;
1729 }
1730 }
1731 Node *AllocateNode::make_ideal_mark(PhaseGVN *phase, Node* obj, Node* control, Node* mem) {
1732 Node* mark_node = nullptr;
1733 if (UseCompactObjectHeaders) {
1734 Node* klass_node = in(AllocateNode::KlassNode);
1735 Node* proto_adr = phase->transform(new AddPNode(klass_node, klass_node, phase->MakeConX(in_bytes(Klass::prototype_header_offset()))));
1736 mark_node = LoadNode::make(*phase, control, mem, proto_adr, TypeRawPtr::BOTTOM, TypeX_X, TypeX_X->basic_type(), MemNode::unordered);
1737 } else {
1738 // For now only enable fast locking for non-array types
1739 mark_node = phase->MakeConX(markWord::prototype().value());
1740 }
1741 return mark_node;
1742 }
1743
1744 // Retrieve the length from the AllocateArrayNode. Narrow the type with a
1745 // CastII, if appropriate. If we are not allowed to create new nodes, and
1746 // a CastII is appropriate, return null.
1747 Node *AllocateArrayNode::make_ideal_length(const TypeOopPtr* oop_type, PhaseValues* phase, bool allow_new_nodes) {
1748 Node *length = in(AllocateNode::ALength);
1749 assert(length != nullptr, "length is not null");
1750
1751 const TypeInt* length_type = phase->find_int_type(length);
1752 const TypeAryPtr* ary_type = oop_type->isa_aryptr();
1753
1754 if (ary_type != nullptr && length_type != nullptr) {
1755 const TypeInt* narrow_length_type = ary_type->narrow_size_type(length_type);
1756 if (narrow_length_type != length_type) {
1757 // Assert one of:
1758 // - the narrow_length is 0
1759 // - the narrow_length is not wider than length
1760 assert(narrow_length_type == TypeInt::ZERO ||
1761 (length_type->is_con() && narrow_length_type->is_con() &&
1762 (narrow_length_type->_hi <= length_type->_lo)) ||
1763 (narrow_length_type->_hi <= length_type->_hi &&
1764 narrow_length_type->_lo >= length_type->_lo),
1765 "narrow type must be narrower than length type");
1766
1767 // Return null if new nodes are not allowed
1768 if (!allow_new_nodes) {
1769 return nullptr;
1770 }
1771 // Create a cast which is control dependent on the initialization to
1772 // propagate the fact that the array length must be positive.
1773 InitializeNode* init = initialization();
1774 if (init != nullptr) {
1775 length = new CastIINode(init->proj_out_or_null(TypeFunc::Control), length, narrow_length_type);
1776 }
1777 }
1778 }
1779
1780 return length;
1781 }
1782
1783 //=============================================================================
1784 const TypeFunc* LockNode::_lock_type_Type = nullptr;
1785
1786 uint LockNode::size_of() const { return sizeof(*this); }
1787
1788 // Redundant lock elimination
1789 //
1790 // There are various patterns of locking where we release and
1791 // immediately reacquire a lock in a piece of code where no operations
1792 // occur in between that would be observable. In those cases we can
1793 // skip releasing and reacquiring the lock without violating any
1794 // fairness requirements. Doing this around a loop could cause a lock
1795 // to be held for a very long time so we concentrate on non-looping
1796 // control flow. We also require that the operations are fully
1797 // redundant meaning that we don't introduce new lock operations on
1798 // some paths so to be able to eliminate it on others ala PRE. This
1799 // would probably require some more extensive graph manipulation to
1800 // guarantee that the memory edges were all handled correctly.
1801 //
1802 // Assuming p is a simple predicate which can't trap in any way and s
1803 // is a synchronized method consider this code:
1804 //
1805 // s();
1806 // if (p)
1807 // s();
1808 // else
1809 // s();
1810 // s();
1811 //
1812 // 1. The unlocks of the first call to s can be eliminated if the
1813 // locks inside the then and else branches are eliminated.
1814 //
1815 // 2. The unlocks of the then and else branches can be eliminated if
1816 // the lock of the final call to s is eliminated.
1817 //
1818 // Either of these cases subsumes the simple case of sequential control flow
1819 //
1820 // Additionally we can eliminate versions without the else case:
1821 //
1822 // s();
1823 // if (p)
1824 // s();
1825 // s();
1826 //
1827 // 3. In this case we eliminate the unlock of the first s, the lock
1828 // and unlock in the then case and the lock in the final s.
1829 //
1830 // Note also that in all these cases the then/else pieces don't have
1831 // to be trivial as long as they begin and end with synchronization
1832 // operations.
1833 //
1834 // s();
1835 // if (p)
1836 // s();
1837 // f();
1838 // s();
1839 // s();
1840 //
1841 // The code will work properly for this case, leaving in the unlock
1842 // before the call to f and the relock after it.
1843 //
1844 // A potentially interesting case which isn't handled here is when the
1845 // locking is partially redundant.
1846 //
1847 // s();
1848 // if (p)
1849 // s();
1850 //
1851 // This could be eliminated putting unlocking on the else case and
1852 // eliminating the first unlock and the lock in the then side.
1853 // Alternatively the unlock could be moved out of the then side so it
1854 // was after the merge and the first unlock and second lock
1855 // eliminated. This might require less manipulation of the memory
1856 // state to get correct.
1857 //
1858 // Additionally we might allow work between a unlock and lock before
1859 // giving up eliminating the locks. The current code disallows any
1860 // conditional control flow between these operations. A formulation
1861 // similar to partial redundancy elimination computing the
1862 // availability of unlocking and the anticipatability of locking at a
1863 // program point would allow detection of fully redundant locking with
1864 // some amount of work in between. I'm not sure how often I really
1865 // think that would occur though. Most of the cases I've seen
1866 // indicate it's likely non-trivial work would occur in between.
1867 // There may be other more complicated constructs where we could
1868 // eliminate locking but I haven't seen any others appear as hot or
1869 // interesting.
1870 //
1871 // Locking and unlocking have a canonical form in ideal that looks
1872 // roughly like this:
1873 //
1874 // <obj>
1875 // | \\------+
1876 // | \ \
1877 // | BoxLock \
1878 // | | | \
1879 // | | \ \
1880 // | | FastLock
1881 // | | /
1882 // | | /
1883 // | | |
1884 //
1885 // Lock
1886 // |
1887 // Proj #0
1888 // |
1889 // MembarAcquire
1890 // |
1891 // Proj #0
1892 //
1893 // MembarRelease
1894 // |
1895 // Proj #0
1896 // |
1897 // Unlock
1898 // |
1899 // Proj #0
1900 //
1901 //
1902 // This code proceeds by processing Lock nodes during PhaseIterGVN
1903 // and searching back through its control for the proper code
1904 // patterns. Once it finds a set of lock and unlock operations to
1905 // eliminate they are marked as eliminatable which causes the
1906 // expansion of the Lock and Unlock macro nodes to make the operation a NOP
1907 //
1908 //=============================================================================
1909
1910 //
1911 // Utility function to skip over uninteresting control nodes. Nodes skipped are:
1912 // - copy regions. (These may not have been optimized away yet.)
1913 // - eliminated locking nodes
1914 //
1915 static Node *next_control(Node *ctrl) {
1916 if (ctrl == nullptr)
1917 return nullptr;
1918 while (1) {
1919 if (ctrl->is_Region()) {
1920 RegionNode *r = ctrl->as_Region();
1921 Node *n = r->is_copy();
1922 if (n == nullptr)
1923 break; // hit a region, return it
1924 else
1925 ctrl = n;
1926 } else if (ctrl->is_Proj()) {
1927 Node *in0 = ctrl->in(0);
1928 if (in0->is_AbstractLock() && in0->as_AbstractLock()->is_eliminated()) {
1929 ctrl = in0->in(0);
1930 } else {
1931 break;
1932 }
1933 } else {
1934 break; // found an interesting control
1935 }
1936 }
1937 return ctrl;
1938 }
1939 //
1940 // Given a control, see if it's the control projection of an Unlock which
1941 // operating on the same object as lock.
1942 //
1943 bool AbstractLockNode::find_matching_unlock(const Node* ctrl, LockNode* lock,
1944 GrowableArray<AbstractLockNode*> &lock_ops) {
1945 ProjNode *ctrl_proj = (ctrl->is_Proj()) ? ctrl->as_Proj() : nullptr;
1946 if (ctrl_proj != nullptr && ctrl_proj->_con == TypeFunc::Control) {
1947 Node *n = ctrl_proj->in(0);
1948 if (n != nullptr && n->is_Unlock()) {
1949 UnlockNode *unlock = n->as_Unlock();
1950 BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
1951 Node* lock_obj = bs->step_over_gc_barrier(lock->obj_node());
1952 Node* unlock_obj = bs->step_over_gc_barrier(unlock->obj_node());
1953 if (lock_obj->eqv_uncast(unlock_obj) &&
1954 BoxLockNode::same_slot(lock->box_node(), unlock->box_node()) &&
1955 !unlock->is_eliminated()) {
1956 lock_ops.append(unlock);
1957 return true;
1958 }
1959 }
1960 }
1961 return false;
1962 }
1963
1964 //
1965 // Find the lock matching an unlock. Returns null if a safepoint
1966 // or complicated control is encountered first.
1967 LockNode *AbstractLockNode::find_matching_lock(UnlockNode* unlock) {
1968 LockNode *lock_result = nullptr;
1969 // find the matching lock, or an intervening safepoint
1970 Node *ctrl = next_control(unlock->in(0));
1971 while (1) {
1972 assert(ctrl != nullptr, "invalid control graph");
1973 assert(!ctrl->is_Start(), "missing lock for unlock");
1974 if (ctrl->is_top()) break; // dead control path
1975 if (ctrl->is_Proj()) ctrl = ctrl->in(0);
1976 if (ctrl->is_SafePoint()) {
1977 break; // found a safepoint (may be the lock we are searching for)
1978 } else if (ctrl->is_Region()) {
1979 // Check for a simple diamond pattern. Punt on anything more complicated
1980 if (ctrl->req() == 3 && ctrl->in(1) != nullptr && ctrl->in(2) != nullptr) {
1981 Node *in1 = next_control(ctrl->in(1));
1982 Node *in2 = next_control(ctrl->in(2));
1983 if (((in1->is_IfTrue() && in2->is_IfFalse()) ||
1984 (in2->is_IfTrue() && in1->is_IfFalse())) && (in1->in(0) == in2->in(0))) {
1985 ctrl = next_control(in1->in(0)->in(0));
1986 } else {
1987 break;
1988 }
1989 } else {
1990 break;
1991 }
1992 } else {
1993 ctrl = next_control(ctrl->in(0)); // keep searching
1994 }
1995 }
1996 if (ctrl->is_Lock()) {
1997 LockNode *lock = ctrl->as_Lock();
1998 BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
1999 Node* lock_obj = bs->step_over_gc_barrier(lock->obj_node());
2000 Node* unlock_obj = bs->step_over_gc_barrier(unlock->obj_node());
2001 if (lock_obj->eqv_uncast(unlock_obj) &&
2002 BoxLockNode::same_slot(lock->box_node(), unlock->box_node())) {
2003 lock_result = lock;
2004 }
2005 }
2006 return lock_result;
2007 }
2008
2009 // This code corresponds to case 3 above.
2010
2011 bool AbstractLockNode::find_lock_and_unlock_through_if(Node* node, LockNode* lock,
2012 GrowableArray<AbstractLockNode*> &lock_ops) {
2013 Node* if_node = node->in(0);
2014 bool if_true = node->is_IfTrue();
2015
2016 if (if_node->is_If() && if_node->outcnt() == 2 && (if_true || node->is_IfFalse())) {
2017 Node *lock_ctrl = next_control(if_node->in(0));
2018 if (find_matching_unlock(lock_ctrl, lock, lock_ops)) {
2019 Node* lock1_node = nullptr;
2020 ProjNode* proj = if_node->as_If()->proj_out(!if_true);
2021 if (if_true) {
2022 if (proj->is_IfFalse() && proj->outcnt() == 1) {
2023 lock1_node = proj->unique_out();
2024 }
2025 } else {
2026 if (proj->is_IfTrue() && proj->outcnt() == 1) {
2027 lock1_node = proj->unique_out();
2028 }
2029 }
2030 if (lock1_node != nullptr && lock1_node->is_Lock()) {
2031 LockNode *lock1 = lock1_node->as_Lock();
2032 BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
2033 Node* lock_obj = bs->step_over_gc_barrier(lock->obj_node());
2034 Node* lock1_obj = bs->step_over_gc_barrier(lock1->obj_node());
2035 if (lock_obj->eqv_uncast(lock1_obj) &&
2036 BoxLockNode::same_slot(lock->box_node(), lock1->box_node()) &&
2037 !lock1->is_eliminated()) {
2038 lock_ops.append(lock1);
2039 return true;
2040 }
2041 }
2042 }
2043 }
2044
2045 lock_ops.trunc_to(0);
2046 return false;
2047 }
2048
2049 bool AbstractLockNode::find_unlocks_for_region(const RegionNode* region, LockNode* lock,
2050 GrowableArray<AbstractLockNode*> &lock_ops) {
2051 // check each control merging at this point for a matching unlock.
2052 // in(0) should be self edge so skip it.
2053 for (int i = 1; i < (int)region->req(); i++) {
2054 Node *in_node = next_control(region->in(i));
2055 if (in_node != nullptr) {
2056 if (find_matching_unlock(in_node, lock, lock_ops)) {
2057 // found a match so keep on checking.
2058 continue;
2059 } else if (find_lock_and_unlock_through_if(in_node, lock, lock_ops)) {
2060 continue;
2061 }
2062
2063 // If we fall through to here then it was some kind of node we
2064 // don't understand or there wasn't a matching unlock, so give
2065 // up trying to merge locks.
2066 lock_ops.trunc_to(0);
2067 return false;
2068 }
2069 }
2070 return true;
2071
2072 }
2073
2074 // Check that all locks/unlocks associated with object come from balanced regions.
2075 bool AbstractLockNode::is_balanced() {
2076 Node* obj = obj_node();
2077 for (uint j = 0; j < obj->outcnt(); j++) {
2078 Node* n = obj->raw_out(j);
2079 if (n->is_AbstractLock() &&
2080 n->as_AbstractLock()->obj_node()->eqv_uncast(obj)) {
2081 BoxLockNode* n_box = n->as_AbstractLock()->box_node()->as_BoxLock();
2082 if (n_box->is_unbalanced()) {
2083 return false;
2084 }
2085 }
2086 }
2087 return true;
2088 }
2089
2090 const char* AbstractLockNode::_kind_names[] = {"Regular", "NonEscObj", "Coarsened", "Nested"};
2091
2092 const char * AbstractLockNode::kind_as_string() const {
2093 return _kind_names[_kind];
2094 }
2095
2096 #ifndef PRODUCT
2097 //
2098 // Create a counter which counts the number of times this lock is acquired
2099 //
2100 void AbstractLockNode::create_lock_counter(JVMState* state) {
2101 _counter = OptoRuntime::new_named_counter(state, NamedCounter::LockCounter);
2102 }
2103
2104 void AbstractLockNode::set_eliminated_lock_counter() {
2105 if (_counter) {
2106 // Update the counter to indicate that this lock was eliminated.
2107 // The counter update code will stay around even though the
2108 // optimizer will eliminate the lock operation itself.
2109 _counter->set_tag(NamedCounter::EliminatedLockCounter);
2110 }
2111 }
2112
2113 void AbstractLockNode::dump_spec(outputStream* st) const {
2114 st->print("%s ", _kind_names[_kind]);
2115 CallNode::dump_spec(st);
2116 }
2117
2118 void AbstractLockNode::dump_compact_spec(outputStream* st) const {
2119 st->print("%s", _kind_names[_kind]);
2120 }
2121 #endif
2122
2123 //=============================================================================
2124 Node *LockNode::Ideal(PhaseGVN *phase, bool can_reshape) {
2125
2126 // perform any generic optimizations first (returns 'this' or null)
2127 Node *result = SafePointNode::Ideal(phase, can_reshape);
2128 if (result != nullptr) return result;
2129 // Don't bother trying to transform a dead node
2130 if (in(0) && in(0)->is_top()) return nullptr;
2131
2132 // Now see if we can optimize away this lock. We don't actually
2133 // remove the locking here, we simply set the _eliminate flag which
2134 // prevents macro expansion from expanding the lock. Since we don't
2135 // modify the graph, the value returned from this function is the
2136 // one computed above.
2137 if (can_reshape && EliminateLocks && !is_non_esc_obj()) {
2138 //
2139 // If we are locking an non-escaped object, the lock/unlock is unnecessary
2140 //
2141 ConnectionGraph *cgr = phase->C->congraph();
2142 if (cgr != nullptr && cgr->can_eliminate_lock(this)) {
2143 assert(!is_eliminated() || is_coarsened(), "sanity");
2144 // The lock could be marked eliminated by lock coarsening
2145 // code during first IGVN before EA. Replace coarsened flag
2146 // to eliminate all associated locks/unlocks.
2147 #ifdef ASSERT
2148 this->log_lock_optimization(phase->C,"eliminate_lock_set_non_esc1");
2149 #endif
2150 this->set_non_esc_obj();
2151 return result;
2152 }
2153
2154 if (!phase->C->do_locks_coarsening()) {
2155 return result; // Compiling without locks coarsening
2156 }
2157 //
2158 // Try lock coarsening
2159 //
2160 PhaseIterGVN* iter = phase->is_IterGVN();
2161 if (iter != nullptr && !is_eliminated()) {
2162
2163 GrowableArray<AbstractLockNode*> lock_ops;
2164
2165 Node *ctrl = next_control(in(0));
2166
2167 // now search back for a matching Unlock
2168 if (find_matching_unlock(ctrl, this, lock_ops)) {
2169 // found an unlock directly preceding this lock. This is the
2170 // case of single unlock directly control dependent on a
2171 // single lock which is the trivial version of case 1 or 2.
2172 } else if (ctrl->is_Region() ) {
2173 if (find_unlocks_for_region(ctrl->as_Region(), this, lock_ops)) {
2174 // found lock preceded by multiple unlocks along all paths
2175 // joining at this point which is case 3 in description above.
2176 }
2177 } else {
2178 // see if this lock comes from either half of an if and the
2179 // predecessors merges unlocks and the other half of the if
2180 // performs a lock.
2181 if (find_lock_and_unlock_through_if(ctrl, this, lock_ops)) {
2182 // found unlock splitting to an if with locks on both branches.
2183 }
2184 }
2185
2186 if (lock_ops.length() > 0) {
2187 // add ourselves to the list of locks to be eliminated.
2188 lock_ops.append(this);
2189
2190 #ifndef PRODUCT
2191 if (PrintEliminateLocks) {
2192 int locks = 0;
2193 int unlocks = 0;
2194 if (Verbose) {
2195 tty->print_cr("=== Locks coarsening ===");
2196 tty->print("Obj: ");
2197 obj_node()->dump();
2198 }
2199 for (int i = 0; i < lock_ops.length(); i++) {
2200 AbstractLockNode* lock = lock_ops.at(i);
2201 if (lock->Opcode() == Op_Lock)
2202 locks++;
2203 else
2204 unlocks++;
2205 if (Verbose) {
2206 tty->print("Box %d: ", i);
2207 box_node()->dump();
2208 tty->print(" %d: ", i);
2209 lock->dump();
2210 }
2211 }
2212 tty->print_cr("=== Coarsened %d unlocks and %d locks", unlocks, locks);
2213 }
2214 #endif
2215
2216 // for each of the identified locks, mark them
2217 // as eliminatable
2218 for (int i = 0; i < lock_ops.length(); i++) {
2219 AbstractLockNode* lock = lock_ops.at(i);
2220
2221 // Mark it eliminated by coarsening and update any counters
2222 #ifdef ASSERT
2223 lock->log_lock_optimization(phase->C, "eliminate_lock_set_coarsened");
2224 #endif
2225 lock->set_coarsened();
2226 }
2227 // Record this coarsened group.
2228 phase->C->add_coarsened_locks(lock_ops);
2229 } else if (ctrl->is_Region() &&
2230 iter->_worklist.member(ctrl)) {
2231 // We weren't able to find any opportunities but the region this
2232 // lock is control dependent on hasn't been processed yet so put
2233 // this lock back on the worklist so we can check again once any
2234 // region simplification has occurred.
2235 iter->_worklist.push(this);
2236 }
2237 }
2238 }
2239
2240 return result;
2241 }
2242
2243 //=============================================================================
2244 bool LockNode::is_nested_lock_region() {
2245 return is_nested_lock_region(nullptr);
2246 }
2247
2248 // p is used for access to compilation log; no logging if null
2249 bool LockNode::is_nested_lock_region(Compile * c) {
2250 BoxLockNode* box = box_node()->as_BoxLock();
2251 int stk_slot = box->stack_slot();
2252 if (stk_slot <= 0) {
2253 #ifdef ASSERT
2254 this->log_lock_optimization(c, "eliminate_lock_INLR_1");
2255 #endif
2256 return false; // External lock or it is not Box (Phi node).
2257 }
2258
2259 // Ignore complex cases: merged locks or multiple locks.
2260 Node* obj = obj_node();
2261 LockNode* unique_lock = nullptr;
2262 Node* bad_lock = nullptr;
2263 if (!box->is_simple_lock_region(&unique_lock, obj, &bad_lock)) {
2264 #ifdef ASSERT
2265 this->log_lock_optimization(c, "eliminate_lock_INLR_2a", bad_lock);
2266 #endif
2267 return false;
2268 }
2269 if (unique_lock != this) {
2270 #ifdef ASSERT
2271 this->log_lock_optimization(c, "eliminate_lock_INLR_2b", (unique_lock != nullptr ? unique_lock : bad_lock));
2272 if (PrintEliminateLocks && Verbose) {
2273 tty->print_cr("=============== unique_lock != this ============");
2274 tty->print(" this: ");
2275 this->dump();
2276 tty->print(" box: ");
2277 box->dump();
2278 tty->print(" obj: ");
2279 obj->dump();
2280 if (unique_lock != nullptr) {
2281 tty->print(" unique_lock: ");
2282 unique_lock->dump();
2283 }
2284 if (bad_lock != nullptr) {
2285 tty->print(" bad_lock: ");
2286 bad_lock->dump();
2287 }
2288 tty->print_cr("===============");
2289 }
2290 #endif
2291 return false;
2292 }
2293
2294 BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
2295 obj = bs->step_over_gc_barrier(obj);
2296 // Look for external lock for the same object.
2297 SafePointNode* sfn = this->as_SafePoint();
2298 JVMState* youngest_jvms = sfn->jvms();
2299 int max_depth = youngest_jvms->depth();
2300 for (int depth = 1; depth <= max_depth; depth++) {
2301 JVMState* jvms = youngest_jvms->of_depth(depth);
2302 int num_mon = jvms->nof_monitors();
2303 // Loop over monitors
2304 for (int idx = 0; idx < num_mon; idx++) {
2305 Node* obj_node = sfn->monitor_obj(jvms, idx);
2306 obj_node = bs->step_over_gc_barrier(obj_node);
2307 BoxLockNode* box_node = sfn->monitor_box(jvms, idx)->as_BoxLock();
2308 if ((box_node->stack_slot() < stk_slot) && obj_node->eqv_uncast(obj)) {
2309 box->set_nested();
2310 return true;
2311 }
2312 }
2313 }
2314 #ifdef ASSERT
2315 this->log_lock_optimization(c, "eliminate_lock_INLR_3");
2316 #endif
2317 return false;
2318 }
2319
2320 //=============================================================================
2321 uint UnlockNode::size_of() const { return sizeof(*this); }
2322
2323 //=============================================================================
2324 Node *UnlockNode::Ideal(PhaseGVN *phase, bool can_reshape) {
2325
2326 // perform any generic optimizations first (returns 'this' or null)
2327 Node *result = SafePointNode::Ideal(phase, can_reshape);
2328 if (result != nullptr) return result;
2329 // Don't bother trying to transform a dead node
2330 if (in(0) && in(0)->is_top()) return nullptr;
2331
2332 // Now see if we can optimize away this unlock. We don't actually
2333 // remove the unlocking here, we simply set the _eliminate flag which
2334 // prevents macro expansion from expanding the unlock. Since we don't
2335 // modify the graph, the value returned from this function is the
2336 // one computed above.
2337 // Escape state is defined after Parse phase.
2338 if (can_reshape && EliminateLocks && !is_non_esc_obj()) {
2339 //
2340 // If we are unlocking an non-escaped object, the lock/unlock is unnecessary.
2341 //
2342 ConnectionGraph *cgr = phase->C->congraph();
2343 if (cgr != nullptr && cgr->can_eliminate_lock(this)) {
2344 assert(!is_eliminated() || is_coarsened(), "sanity");
2345 // The lock could be marked eliminated by lock coarsening
2346 // code during first IGVN before EA. Replace coarsened flag
2347 // to eliminate all associated locks/unlocks.
2348 #ifdef ASSERT
2349 this->log_lock_optimization(phase->C, "eliminate_lock_set_non_esc2");
2350 #endif
2351 this->set_non_esc_obj();
2352 }
2353 }
2354 return result;
2355 }
2356
2357 void AbstractLockNode::log_lock_optimization(Compile *C, const char * tag, Node* bad_lock) const {
2358 if (C == nullptr) {
2359 return;
2360 }
2361 CompileLog* log = C->log();
2362 if (log != nullptr) {
2363 Node* box = box_node();
2364 Node* obj = obj_node();
2365 int box_id = box != nullptr ? box->_idx : -1;
2366 int obj_id = obj != nullptr ? obj->_idx : -1;
2367
2368 log->begin_head("%s compile_id='%d' lock_id='%d' class='%s' kind='%s' box_id='%d' obj_id='%d' bad_id='%d'",
2369 tag, C->compile_id(), this->_idx,
2370 is_Unlock() ? "unlock" : is_Lock() ? "lock" : "?",
2371 kind_as_string(), box_id, obj_id, (bad_lock != nullptr ? bad_lock->_idx : -1));
2372 log->stamp();
2373 log->end_head();
2374 JVMState* p = is_Unlock() ? (as_Unlock()->dbg_jvms()) : jvms();
2375 while (p != nullptr) {
2376 log->elem("jvms bci='%d' method='%d'", p->bci(), log->identify(p->method()));
2377 p = p->caller();
2378 }
2379 log->tail(tag);
2380 }
2381 }
2382
2383 bool CallNode::may_modify_arraycopy_helper(const TypeOopPtr* dest_t, const TypeOopPtr* t_oop, PhaseValues* phase) {
2384 if (dest_t->is_known_instance() && t_oop->is_known_instance()) {
2385 return dest_t->instance_id() == t_oop->instance_id();
2386 }
2387
2388 if (dest_t->isa_instptr() && !dest_t->is_instptr()->instance_klass()->equals(phase->C->env()->Object_klass())) {
2389 // clone
2390 if (t_oop->isa_aryptr()) {
2391 return false;
2392 }
2393 if (!t_oop->isa_instptr()) {
2394 return true;
2395 }
2396 if (dest_t->maybe_java_subtype_of(t_oop) || t_oop->maybe_java_subtype_of(dest_t)) {
2397 return true;
2398 }
2399 // unrelated
2400 return false;
2401 }
2402
2403 if (dest_t->isa_aryptr()) {
2404 // arraycopy or array clone
2405 if (t_oop->isa_instptr()) {
2406 return false;
2407 }
2408 if (!t_oop->isa_aryptr()) {
2409 return true;
2410 }
2411
2412 const Type* elem = dest_t->is_aryptr()->elem();
2413 if (elem == Type::BOTTOM) {
2414 // An array but we don't know what elements are
2415 return true;
2416 }
2417
2418 dest_t = dest_t->add_offset(Type::OffsetBot)->is_oopptr();
2419 uint dest_alias = phase->C->get_alias_index(dest_t);
2420 uint t_oop_alias = phase->C->get_alias_index(t_oop);
2421
2422 return dest_alias == t_oop_alias;
2423 }
2424
2425 return true;
2426 }