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 phase->C->inc_number_of_mh_late_inlines();
1149 }
1150 }
1151 } else {
1152 assert(IncrementalInline, "required");
1153 assert(!cg->method()->is_method_handle_intrinsic(), "required");
1154 if (phase->C->print_inlining()) {
1155 phase->C->inline_printer()->record(cg->method(), cg->call_node()->jvms(), InliningResult::FAILURE,
1156 "static call node changed: trying again");
1157 }
1158 register_for_late_inline();
1159 }
1160 }
1161 return CallNode::Ideal(phase, can_reshape);
1162 }
1163
1164 //----------------------------is_uncommon_trap----------------------------
1165 // Returns true if this is an uncommon trap.
1166 bool CallStaticJavaNode::is_uncommon_trap() const {
1167 return (_name != nullptr && !strcmp(_name, "uncommon_trap"));
1168 }
1169
1170 //----------------------------uncommon_trap_request----------------------------
1171 // If this is an uncommon trap, return the request code, else zero.
1172 int CallStaticJavaNode::uncommon_trap_request() const {
1173 return is_uncommon_trap() ? extract_uncommon_trap_request(this) : 0;
1174 }
1175 int CallStaticJavaNode::extract_uncommon_trap_request(const Node* call) {
1176 #ifndef PRODUCT
1177 if (!(call->req() > TypeFunc::Parms &&
1178 call->in(TypeFunc::Parms) != nullptr &&
1179 call->in(TypeFunc::Parms)->is_Con() &&
1180 call->in(TypeFunc::Parms)->bottom_type()->isa_int())) {
1181 assert(in_dump() != 0, "OK if dumping");
1182 tty->print("[bad uncommon trap]");
1183 return 0;
1184 }
1185 #endif
1186 return call->in(TypeFunc::Parms)->bottom_type()->is_int()->get_con();
1187 }
1188
1189 #ifndef PRODUCT
1190 void CallStaticJavaNode::dump_spec(outputStream *st) const {
1191 st->print("# Static ");
1192 if (_name != nullptr) {
1193 st->print("%s", _name);
1194 int trap_req = uncommon_trap_request();
1195 if (trap_req != 0) {
1196 char buf[100];
1197 st->print("(%s)",
1198 Deoptimization::format_trap_request(buf, sizeof(buf),
1199 trap_req));
1200 }
1201 st->print(" ");
1202 }
1203 CallJavaNode::dump_spec(st);
1204 }
1205
1206 void CallStaticJavaNode::dump_compact_spec(outputStream* st) const {
1207 if (_method) {
1208 _method->print_short_name(st);
1209 } else if (_name) {
1210 st->print("%s", _name);
1211 } else {
1212 st->print("<?>");
1213 }
1214 }
1215 #endif
1216
1217 //=============================================================================
1218 uint CallDynamicJavaNode::size_of() const { return sizeof(*this); }
1219 bool CallDynamicJavaNode::cmp( const Node &n ) const {
1220 CallDynamicJavaNode &call = (CallDynamicJavaNode&)n;
1221 return CallJavaNode::cmp(call);
1222 }
1223
1224 Node* CallDynamicJavaNode::Ideal(PhaseGVN* phase, bool can_reshape) {
1225 CallGenerator* cg = generator();
1226 if (can_reshape && cg != nullptr) {
1227 if (cg->is_virtual_late_inline()) {
1228 assert(IncrementalInlineVirtual, "required");
1229 assert(cg->call_node() == this, "mismatch");
1230
1231 if (cg->callee_method() == nullptr) {
1232 // Recover symbolic info for method resolution.
1233 ciMethod* caller = jvms()->method();
1234 ciBytecodeStream iter(caller);
1235 iter.force_bci(jvms()->bci());
1236
1237 bool not_used1;
1238 ciSignature* not_used2;
1239 ciMethod* orig_callee = iter.get_method(not_used1, ¬_used2); // callee in the bytecode
1240 ciKlass* holder = iter.get_declared_method_holder();
1241 if (orig_callee->is_method_handle_intrinsic()) {
1242 assert(_override_symbolic_info, "required");
1243 orig_callee = method();
1244 holder = method()->holder();
1245 }
1246
1247 ciInstanceKlass* klass = ciEnv::get_instance_klass_for_declared_method_holder(holder);
1248
1249 Node* receiver_node = in(TypeFunc::Parms);
1250 const TypeOopPtr* receiver_type = phase->type(receiver_node)->isa_oopptr();
1251
1252 int not_used3;
1253 bool call_does_dispatch;
1254 ciMethod* callee = phase->C->optimize_virtual_call(caller, klass, holder, orig_callee, receiver_type, true /*is_virtual*/,
1255 call_does_dispatch, not_used3); // out-parameters
1256 if (!call_does_dispatch) {
1257 cg->set_callee_method(callee);
1258 }
1259 }
1260 if (cg->callee_method() != nullptr) {
1261 // Register for late inlining.
1262 register_for_late_inline(); // MH late inlining prepends to the list, so do the same
1263 }
1264 } else {
1265 assert(IncrementalInline, "required");
1266 if (phase->C->print_inlining()) {
1267 phase->C->inline_printer()->record(cg->method(), cg->call_node()->jvms(), InliningResult::FAILURE,
1268 "dynamic call node changed: trying again");
1269 }
1270 register_for_late_inline();
1271 }
1272 }
1273 return CallNode::Ideal(phase, can_reshape);
1274 }
1275
1276 #ifndef PRODUCT
1277 void CallDynamicJavaNode::dump_spec(outputStream *st) const {
1278 st->print("# Dynamic ");
1279 CallJavaNode::dump_spec(st);
1280 }
1281 #endif
1282
1283 //=============================================================================
1284 uint CallRuntimeNode::size_of() const { return sizeof(*this); }
1285 bool CallRuntimeNode::cmp( const Node &n ) const {
1286 CallRuntimeNode &call = (CallRuntimeNode&)n;
1287 return CallNode::cmp(call) && !strcmp(_name,call._name);
1288 }
1289 #ifndef PRODUCT
1290 void CallRuntimeNode::dump_spec(outputStream *st) const {
1291 st->print("# ");
1292 st->print("%s", _name);
1293 CallNode::dump_spec(st);
1294 }
1295 #endif
1296 uint CallLeafVectorNode::size_of() const { return sizeof(*this); }
1297 bool CallLeafVectorNode::cmp( const Node &n ) const {
1298 CallLeafVectorNode &call = (CallLeafVectorNode&)n;
1299 return CallLeafNode::cmp(call) && _num_bits == call._num_bits;
1300 }
1301
1302 //------------------------------calling_convention-----------------------------
1303 void CallRuntimeNode::calling_convention(BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt) const {
1304 SharedRuntime::c_calling_convention(sig_bt, parm_regs, argcnt);
1305 }
1306
1307 void CallLeafVectorNode::calling_convention( BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt ) const {
1308 #ifdef ASSERT
1309 assert(tf()->range()->field_at(TypeFunc::Parms)->is_vect()->length_in_bytes() * BitsPerByte == _num_bits,
1310 "return vector size must match");
1311 const TypeTuple* d = tf()->domain();
1312 for (uint i = TypeFunc::Parms; i < d->cnt(); i++) {
1313 Node* arg = in(i);
1314 assert(arg->bottom_type()->is_vect()->length_in_bytes() * BitsPerByte == _num_bits,
1315 "vector argument size must match");
1316 }
1317 #endif
1318
1319 SharedRuntime::vector_calling_convention(parm_regs, _num_bits, argcnt);
1320 }
1321
1322 //=============================================================================
1323 //------------------------------calling_convention-----------------------------
1324
1325
1326 //=============================================================================
1327 bool CallLeafPureNode::is_unused() const {
1328 return proj_out_or_null(TypeFunc::Parms) == nullptr;
1329 }
1330
1331 bool CallLeafPureNode::is_dead() const {
1332 return proj_out_or_null(TypeFunc::Control) == nullptr;
1333 }
1334
1335 /* We make a tuple of the global input state + TOP for the output values.
1336 * We use this to delete a pure function that is not used: by replacing the call with
1337 * such a tuple, we let output Proj's idealization pick the corresponding input of the
1338 * pure call, so jumping over it, and effectively, removing the call from the graph.
1339 * This avoids doing the graph surgery manually, but leaves that to IGVN
1340 * that is specialized for doing that right. We need also tuple components for output
1341 * values of the function to respect the return arity, and in case there is a projection
1342 * that would pick an output (which shouldn't happen at the moment).
1343 */
1344 TupleNode* CallLeafPureNode::make_tuple_of_input_state_and_top_return_values(const Compile* C) const {
1345 // Transparently propagate input state but parameters
1346 TupleNode* tuple = TupleNode::make(
1347 tf()->range(),
1348 in(TypeFunc::Control),
1349 in(TypeFunc::I_O),
1350 in(TypeFunc::Memory),
1351 in(TypeFunc::FramePtr),
1352 in(TypeFunc::ReturnAdr));
1353
1354 // And add TOPs for the return values
1355 for (uint i = TypeFunc::Parms; i < tf()->range()->cnt(); i++) {
1356 tuple->set_req(i, C->top());
1357 }
1358
1359 return tuple;
1360 }
1361
1362 Node* CallLeafPureNode::Ideal(PhaseGVN* phase, bool can_reshape) {
1363 if (is_dead()) {
1364 return nullptr;
1365 }
1366
1367 // We need to wait until IGVN because during parsing, usages might still be missing
1368 // and we would remove the call immediately.
1369 if (can_reshape && is_unused()) {
1370 // The result is not used. We remove the call by replacing it with a tuple, that
1371 // is later disintegrated by the projections.
1372 return make_tuple_of_input_state_and_top_return_values(phase->C);
1373 }
1374
1375 return CallRuntimeNode::Ideal(phase, can_reshape);
1376 }
1377
1378 #ifndef PRODUCT
1379 void CallLeafNode::dump_spec(outputStream *st) const {
1380 st->print("# ");
1381 st->print("%s", _name);
1382 CallNode::dump_spec(st);
1383 }
1384 #endif
1385
1386 //=============================================================================
1387
1388 void SafePointNode::set_local(const JVMState* jvms, uint idx, Node *c) {
1389 assert(verify_jvms(jvms), "jvms must match");
1390 int loc = jvms->locoff() + idx;
1391 if (in(loc)->is_top() && idx > 0 && !c->is_top() ) {
1392 // If current local idx is top then local idx - 1 could
1393 // be a long/double that needs to be killed since top could
1394 // represent the 2nd half of the long/double.
1395 uint ideal = in(loc -1)->ideal_reg();
1396 if (ideal == Op_RegD || ideal == Op_RegL) {
1397 // set other (low index) half to top
1398 set_req(loc - 1, in(loc));
1399 }
1400 }
1401 set_req(loc, c);
1402 }
1403
1404 uint SafePointNode::size_of() const { return sizeof(*this); }
1405 bool SafePointNode::cmp( const Node &n ) const {
1406 return (&n == this); // Always fail except on self
1407 }
1408
1409 //-------------------------set_next_exception----------------------------------
1410 void SafePointNode::set_next_exception(SafePointNode* n) {
1411 assert(n == nullptr || n->Opcode() == Op_SafePoint, "correct value for next_exception");
1412 if (len() == req()) {
1413 if (n != nullptr) add_prec(n);
1414 } else {
1415 set_prec(req(), n);
1416 }
1417 }
1418
1419
1420 //----------------------------next_exception-----------------------------------
1421 SafePointNode* SafePointNode::next_exception() const {
1422 if (len() == req()) {
1423 return nullptr;
1424 } else {
1425 Node* n = in(req());
1426 assert(n == nullptr || n->Opcode() == Op_SafePoint, "no other uses of prec edges");
1427 return (SafePointNode*) n;
1428 }
1429 }
1430
1431
1432 //------------------------------Ideal------------------------------------------
1433 // Skip over any collapsed Regions
1434 Node *SafePointNode::Ideal(PhaseGVN *phase, bool can_reshape) {
1435 assert(_jvms == nullptr || ((uintptr_t)_jvms->map() & 1) || _jvms->map() == this, "inconsistent JVMState");
1436 return remove_dead_region(phase, can_reshape) ? this : nullptr;
1437 }
1438
1439 //------------------------------Identity---------------------------------------
1440 // Remove obviously duplicate safepoints
1441 Node* SafePointNode::Identity(PhaseGVN* phase) {
1442
1443 // If you have back to back safepoints, remove one
1444 if (in(TypeFunc::Control)->is_SafePoint()) {
1445 Node* out_c = unique_ctrl_out_or_null();
1446 // This can be the safepoint of an outer strip mined loop if the inner loop's backedge was removed. Replacing the
1447 // outer loop's safepoint could confuse removal of the outer loop.
1448 if (out_c != nullptr && !out_c->is_OuterStripMinedLoopEnd()) {
1449 return in(TypeFunc::Control);
1450 }
1451 }
1452
1453 // Transforming long counted loops requires a safepoint node. Do not
1454 // eliminate a safepoint until loop opts are over.
1455 if (in(0)->is_Proj() && !phase->C->major_progress()) {
1456 Node *n0 = in(0)->in(0);
1457 // Check if he is a call projection (except Leaf Call)
1458 if( n0->is_Catch() ) {
1459 n0 = n0->in(0)->in(0);
1460 assert( n0->is_Call(), "expect a call here" );
1461 }
1462 if( n0->is_Call() && n0->as_Call()->guaranteed_safepoint() ) {
1463 // Don't remove a safepoint belonging to an OuterStripMinedLoopEndNode.
1464 // If the loop dies, they will be removed together.
1465 if (has_out_with(Op_OuterStripMinedLoopEnd)) {
1466 return this;
1467 }
1468 // Useless Safepoint, so remove it
1469 return in(TypeFunc::Control);
1470 }
1471 }
1472
1473 return this;
1474 }
1475
1476 //------------------------------Value------------------------------------------
1477 const Type* SafePointNode::Value(PhaseGVN* phase) const {
1478 if (phase->type(in(0)) == Type::TOP) {
1479 return Type::TOP;
1480 }
1481 if (in(0) == this) {
1482 return Type::TOP; // Dead infinite loop
1483 }
1484 return Type::CONTROL;
1485 }
1486
1487 #ifndef PRODUCT
1488 void SafePointNode::dump_spec(outputStream *st) const {
1489 st->print(" SafePoint ");
1490 _replaced_nodes.dump(st);
1491 }
1492 #endif
1493
1494 const RegMask &SafePointNode::in_RegMask(uint idx) const {
1495 if (idx < TypeFunc::Parms) {
1496 return RegMask::EMPTY;
1497 }
1498 // Values outside the domain represent debug info
1499 return *(Compile::current()->matcher()->idealreg2debugmask[in(idx)->ideal_reg()]);
1500 }
1501 const RegMask &SafePointNode::out_RegMask() const {
1502 return RegMask::EMPTY;
1503 }
1504
1505
1506 void SafePointNode::grow_stack(JVMState* jvms, uint grow_by) {
1507 assert((int)grow_by > 0, "sanity");
1508 int monoff = jvms->monoff();
1509 int scloff = jvms->scloff();
1510 int endoff = jvms->endoff();
1511 assert(endoff == (int)req(), "no other states or debug info after me");
1512 Node* top = Compile::current()->top();
1513 for (uint i = 0; i < grow_by; i++) {
1514 ins_req(monoff, top);
1515 }
1516 jvms->set_monoff(monoff + grow_by);
1517 jvms->set_scloff(scloff + grow_by);
1518 jvms->set_endoff(endoff + grow_by);
1519 }
1520
1521 void SafePointNode::push_monitor(const FastLockNode *lock) {
1522 // Add a LockNode, which points to both the original BoxLockNode (the
1523 // stack space for the monitor) and the Object being locked.
1524 const int MonitorEdges = 2;
1525 assert(JVMState::logMonitorEdges == exact_log2(MonitorEdges), "correct MonitorEdges");
1526 assert(req() == jvms()->endoff(), "correct sizing");
1527 int nextmon = jvms()->scloff();
1528 ins_req(nextmon, lock->box_node());
1529 ins_req(nextmon+1, lock->obj_node());
1530 jvms()->set_scloff(nextmon + MonitorEdges);
1531 jvms()->set_endoff(req());
1532 }
1533
1534 void SafePointNode::pop_monitor() {
1535 // Delete last monitor from debug info
1536 DEBUG_ONLY(int num_before_pop = jvms()->nof_monitors());
1537 const int MonitorEdges = 2;
1538 assert(JVMState::logMonitorEdges == exact_log2(MonitorEdges), "correct MonitorEdges");
1539 int scloff = jvms()->scloff();
1540 int endoff = jvms()->endoff();
1541 int new_scloff = scloff - MonitorEdges;
1542 int new_endoff = endoff - MonitorEdges;
1543 jvms()->set_scloff(new_scloff);
1544 jvms()->set_endoff(new_endoff);
1545 while (scloff > new_scloff) del_req_ordered(--scloff);
1546 assert(jvms()->nof_monitors() == num_before_pop-1, "");
1547 }
1548
1549 Node *SafePointNode::peek_monitor_box() const {
1550 int mon = jvms()->nof_monitors() - 1;
1551 assert(mon >= 0, "must have a monitor");
1552 return monitor_box(jvms(), mon);
1553 }
1554
1555 Node *SafePointNode::peek_monitor_obj() const {
1556 int mon = jvms()->nof_monitors() - 1;
1557 assert(mon >= 0, "must have a monitor");
1558 return monitor_obj(jvms(), mon);
1559 }
1560
1561 Node* SafePointNode::peek_operand(uint off) const {
1562 assert(jvms()->sp() > 0, "must have an operand");
1563 assert(off < jvms()->sp(), "off is out-of-range");
1564 return stack(jvms(), jvms()->sp() - off - 1);
1565 }
1566
1567 // Do we Match on this edge index or not? Match no edges
1568 uint SafePointNode::match_edge(uint idx) const {
1569 return (TypeFunc::Parms == idx);
1570 }
1571
1572 void SafePointNode::disconnect_from_root(PhaseIterGVN *igvn) {
1573 assert(Opcode() == Op_SafePoint, "only value for safepoint in loops");
1574 int nb = igvn->C->root()->find_prec_edge(this);
1575 if (nb != -1) {
1576 igvn->delete_precedence_of(igvn->C->root(), nb);
1577 }
1578 }
1579
1580 //============== SafePointScalarObjectNode ==============
1581
1582 SafePointScalarObjectNode::SafePointScalarObjectNode(const TypeOopPtr* tp, Node* alloc, uint first_index, uint depth, uint n_fields) :
1583 TypeNode(tp, 1), // 1 control input -- seems required. Get from root.
1584 _first_index(first_index),
1585 _depth(depth),
1586 _n_fields(n_fields),
1587 _alloc(alloc)
1588 {
1589 #ifdef ASSERT
1590 if (!alloc->is_Allocate() && !(alloc->Opcode() == Op_VectorBox)) {
1591 alloc->dump();
1592 assert(false, "unexpected call node");
1593 }
1594 #endif
1595 init_class_id(Class_SafePointScalarObject);
1596 }
1597
1598 // Do not allow value-numbering for SafePointScalarObject node.
1599 uint SafePointScalarObjectNode::hash() const { return NO_HASH; }
1600 bool SafePointScalarObjectNode::cmp( const Node &n ) const {
1601 return (&n == this); // Always fail except on self
1602 }
1603
1604 uint SafePointScalarObjectNode::ideal_reg() const {
1605 return 0; // No matching to machine instruction
1606 }
1607
1608 const RegMask &SafePointScalarObjectNode::in_RegMask(uint idx) const {
1609 return *(Compile::current()->matcher()->idealreg2debugmask[in(idx)->ideal_reg()]);
1610 }
1611
1612 const RegMask &SafePointScalarObjectNode::out_RegMask() const {
1613 return RegMask::EMPTY;
1614 }
1615
1616 uint SafePointScalarObjectNode::match_edge(uint idx) const {
1617 return 0;
1618 }
1619
1620 SafePointScalarObjectNode*
1621 SafePointScalarObjectNode::clone(Dict* sosn_map, bool& new_node) const {
1622 void* cached = (*sosn_map)[(void*)this];
1623 if (cached != nullptr) {
1624 new_node = false;
1625 return (SafePointScalarObjectNode*)cached;
1626 }
1627 new_node = true;
1628 SafePointScalarObjectNode* res = (SafePointScalarObjectNode*)Node::clone();
1629 sosn_map->Insert((void*)this, (void*)res);
1630 return res;
1631 }
1632
1633
1634 #ifndef PRODUCT
1635 void SafePointScalarObjectNode::dump_spec(outputStream *st) const {
1636 st->print(" # fields@[%d..%d]", first_index(), first_index() + n_fields() - 1);
1637 }
1638 #endif
1639
1640 //============== SafePointScalarMergeNode ==============
1641
1642 SafePointScalarMergeNode::SafePointScalarMergeNode(const TypeOopPtr* tp, int merge_pointer_idx) :
1643 TypeNode(tp, 1), // 1 control input -- seems required. Get from root.
1644 _merge_pointer_idx(merge_pointer_idx)
1645 {
1646 init_class_id(Class_SafePointScalarMerge);
1647 }
1648
1649 // Do not allow value-numbering for SafePointScalarMerge node.
1650 uint SafePointScalarMergeNode::hash() const { return NO_HASH; }
1651 bool SafePointScalarMergeNode::cmp( const Node &n ) const {
1652 return (&n == this); // Always fail except on self
1653 }
1654
1655 uint SafePointScalarMergeNode::ideal_reg() const {
1656 return 0; // No matching to machine instruction
1657 }
1658
1659 const RegMask &SafePointScalarMergeNode::in_RegMask(uint idx) const {
1660 return *(Compile::current()->matcher()->idealreg2debugmask[in(idx)->ideal_reg()]);
1661 }
1662
1663 const RegMask &SafePointScalarMergeNode::out_RegMask() const {
1664 return RegMask::EMPTY;
1665 }
1666
1667 uint SafePointScalarMergeNode::match_edge(uint idx) const {
1668 return 0;
1669 }
1670
1671 SafePointScalarMergeNode*
1672 SafePointScalarMergeNode::clone(Dict* sosn_map, bool& new_node) const {
1673 void* cached = (*sosn_map)[(void*)this];
1674 if (cached != nullptr) {
1675 new_node = false;
1676 return (SafePointScalarMergeNode*)cached;
1677 }
1678 new_node = true;
1679 SafePointScalarMergeNode* res = (SafePointScalarMergeNode*)Node::clone();
1680 sosn_map->Insert((void*)this, (void*)res);
1681 return res;
1682 }
1683
1684 #ifndef PRODUCT
1685 void SafePointScalarMergeNode::dump_spec(outputStream *st) const {
1686 st->print(" # merge_pointer_idx=%d, scalarized_objects=%d", _merge_pointer_idx, req()-1);
1687 }
1688 #endif
1689
1690 //=============================================================================
1691 uint AllocateNode::size_of() const { return sizeof(*this); }
1692
1693 AllocateNode::AllocateNode(Compile* C, const TypeFunc *atype,
1694 Node *ctrl, Node *mem, Node *abio,
1695 Node *size, Node *klass_node, Node *initial_test)
1696 : CallNode(atype, nullptr, TypeRawPtr::BOTTOM)
1697 {
1698 init_class_id(Class_Allocate);
1699 init_flags(Flag_is_macro);
1700 _is_scalar_replaceable = false;
1701 _is_non_escaping = false;
1702 _is_allocation_MemBar_redundant = false;
1703 Node *topnode = C->top();
1704
1705 init_req( TypeFunc::Control , ctrl );
1706 init_req( TypeFunc::I_O , abio );
1707 init_req( TypeFunc::Memory , mem );
1708 init_req( TypeFunc::ReturnAdr, topnode );
1709 init_req( TypeFunc::FramePtr , topnode );
1710 init_req( AllocSize , size);
1711 init_req( KlassNode , klass_node);
1712 init_req( InitialTest , initial_test);
1713 init_req( ALength , topnode);
1714 init_req( ValidLengthTest , topnode);
1715 C->add_macro_node(this);
1716 }
1717
1718 void AllocateNode::compute_MemBar_redundancy(ciMethod* initializer)
1719 {
1720 assert(initializer != nullptr && initializer->is_object_initializer(),
1721 "unexpected initializer method");
1722 BCEscapeAnalyzer* analyzer = initializer->get_bcea();
1723 if (analyzer == nullptr) {
1724 return;
1725 }
1726
1727 // Allocation node is first parameter in its initializer
1728 if (analyzer->is_arg_stack(0) || analyzer->is_arg_local(0)) {
1729 _is_allocation_MemBar_redundant = true;
1730 }
1731 }
1732 Node *AllocateNode::make_ideal_mark(PhaseGVN *phase, Node* obj, Node* control, Node* mem) {
1733 Node* mark_node = nullptr;
1734 if (UseCompactObjectHeaders) {
1735 Node* klass_node = in(AllocateNode::KlassNode);
1736 Node* proto_adr = phase->transform(new AddPNode(klass_node, klass_node, phase->MakeConX(in_bytes(Klass::prototype_header_offset()))));
1737 mark_node = LoadNode::make(*phase, control, mem, proto_adr, TypeRawPtr::BOTTOM, TypeX_X, TypeX_X->basic_type(), MemNode::unordered);
1738 } else {
1739 // For now only enable fast locking for non-array types
1740 mark_node = phase->MakeConX(markWord::prototype().value());
1741 }
1742 return mark_node;
1743 }
1744
1745 // Retrieve the length from the AllocateArrayNode. Narrow the type with a
1746 // CastII, if appropriate. If we are not allowed to create new nodes, and
1747 // a CastII is appropriate, return null.
1748 Node *AllocateArrayNode::make_ideal_length(const TypeOopPtr* oop_type, PhaseValues* phase, bool allow_new_nodes) {
1749 Node *length = in(AllocateNode::ALength);
1750 assert(length != nullptr, "length is not null");
1751
1752 const TypeInt* length_type = phase->find_int_type(length);
1753 const TypeAryPtr* ary_type = oop_type->isa_aryptr();
1754
1755 if (ary_type != nullptr && length_type != nullptr) {
1756 const TypeInt* narrow_length_type = ary_type->narrow_size_type(length_type);
1757 if (narrow_length_type != length_type) {
1758 // Assert one of:
1759 // - the narrow_length is 0
1760 // - the narrow_length is not wider than length
1761 assert(narrow_length_type == TypeInt::ZERO ||
1762 (length_type->is_con() && narrow_length_type->is_con() &&
1763 (narrow_length_type->_hi <= length_type->_lo)) ||
1764 (narrow_length_type->_hi <= length_type->_hi &&
1765 narrow_length_type->_lo >= length_type->_lo),
1766 "narrow type must be narrower than length type");
1767
1768 // Return null if new nodes are not allowed
1769 if (!allow_new_nodes) {
1770 return nullptr;
1771 }
1772 // Create a cast which is control dependent on the initialization to
1773 // propagate the fact that the array length must be positive.
1774 InitializeNode* init = initialization();
1775 if (init != nullptr) {
1776 length = new CastIINode(init->proj_out_or_null(TypeFunc::Control), length, narrow_length_type);
1777 }
1778 }
1779 }
1780
1781 return length;
1782 }
1783
1784 //=============================================================================
1785 const TypeFunc* LockNode::_lock_type_Type = nullptr;
1786
1787 uint LockNode::size_of() const { return sizeof(*this); }
1788
1789 // Redundant lock elimination
1790 //
1791 // There are various patterns of locking where we release and
1792 // immediately reacquire a lock in a piece of code where no operations
1793 // occur in between that would be observable. In those cases we can
1794 // skip releasing and reacquiring the lock without violating any
1795 // fairness requirements. Doing this around a loop could cause a lock
1796 // to be held for a very long time so we concentrate on non-looping
1797 // control flow. We also require that the operations are fully
1798 // redundant meaning that we don't introduce new lock operations on
1799 // some paths so to be able to eliminate it on others ala PRE. This
1800 // would probably require some more extensive graph manipulation to
1801 // guarantee that the memory edges were all handled correctly.
1802 //
1803 // Assuming p is a simple predicate which can't trap in any way and s
1804 // is a synchronized method consider this code:
1805 //
1806 // s();
1807 // if (p)
1808 // s();
1809 // else
1810 // s();
1811 // s();
1812 //
1813 // 1. The unlocks of the first call to s can be eliminated if the
1814 // locks inside the then and else branches are eliminated.
1815 //
1816 // 2. The unlocks of the then and else branches can be eliminated if
1817 // the lock of the final call to s is eliminated.
1818 //
1819 // Either of these cases subsumes the simple case of sequential control flow
1820 //
1821 // Additionally we can eliminate versions without the else case:
1822 //
1823 // s();
1824 // if (p)
1825 // s();
1826 // s();
1827 //
1828 // 3. In this case we eliminate the unlock of the first s, the lock
1829 // and unlock in the then case and the lock in the final s.
1830 //
1831 // Note also that in all these cases the then/else pieces don't have
1832 // to be trivial as long as they begin and end with synchronization
1833 // operations.
1834 //
1835 // s();
1836 // if (p)
1837 // s();
1838 // f();
1839 // s();
1840 // s();
1841 //
1842 // The code will work properly for this case, leaving in the unlock
1843 // before the call to f and the relock after it.
1844 //
1845 // A potentially interesting case which isn't handled here is when the
1846 // locking is partially redundant.
1847 //
1848 // s();
1849 // if (p)
1850 // s();
1851 //
1852 // This could be eliminated putting unlocking on the else case and
1853 // eliminating the first unlock and the lock in the then side.
1854 // Alternatively the unlock could be moved out of the then side so it
1855 // was after the merge and the first unlock and second lock
1856 // eliminated. This might require less manipulation of the memory
1857 // state to get correct.
1858 //
1859 // Additionally we might allow work between a unlock and lock before
1860 // giving up eliminating the locks. The current code disallows any
1861 // conditional control flow between these operations. A formulation
1862 // similar to partial redundancy elimination computing the
1863 // availability of unlocking and the anticipatability of locking at a
1864 // program point would allow detection of fully redundant locking with
1865 // some amount of work in between. I'm not sure how often I really
1866 // think that would occur though. Most of the cases I've seen
1867 // indicate it's likely non-trivial work would occur in between.
1868 // There may be other more complicated constructs where we could
1869 // eliminate locking but I haven't seen any others appear as hot or
1870 // interesting.
1871 //
1872 // Locking and unlocking have a canonical form in ideal that looks
1873 // roughly like this:
1874 //
1875 // <obj>
1876 // | \\------+
1877 // | \ \
1878 // | BoxLock \
1879 // | | | \
1880 // | | \ \
1881 // | | FastLock
1882 // | | /
1883 // | | /
1884 // | | |
1885 //
1886 // Lock
1887 // |
1888 // Proj #0
1889 // |
1890 // MembarAcquire
1891 // |
1892 // Proj #0
1893 //
1894 // MembarRelease
1895 // |
1896 // Proj #0
1897 // |
1898 // Unlock
1899 // |
1900 // Proj #0
1901 //
1902 //
1903 // This code proceeds by processing Lock nodes during PhaseIterGVN
1904 // and searching back through its control for the proper code
1905 // patterns. Once it finds a set of lock and unlock operations to
1906 // eliminate they are marked as eliminatable which causes the
1907 // expansion of the Lock and Unlock macro nodes to make the operation a NOP
1908 //
1909 //=============================================================================
1910
1911 //
1912 // Utility function to skip over uninteresting control nodes. Nodes skipped are:
1913 // - copy regions. (These may not have been optimized away yet.)
1914 // - eliminated locking nodes
1915 //
1916 static Node *next_control(Node *ctrl) {
1917 if (ctrl == nullptr)
1918 return nullptr;
1919 while (1) {
1920 if (ctrl->is_Region()) {
1921 RegionNode *r = ctrl->as_Region();
1922 Node *n = r->is_copy();
1923 if (n == nullptr)
1924 break; // hit a region, return it
1925 else
1926 ctrl = n;
1927 } else if (ctrl->is_Proj()) {
1928 Node *in0 = ctrl->in(0);
1929 if (in0->is_AbstractLock() && in0->as_AbstractLock()->is_eliminated()) {
1930 ctrl = in0->in(0);
1931 } else {
1932 break;
1933 }
1934 } else {
1935 break; // found an interesting control
1936 }
1937 }
1938 return ctrl;
1939 }
1940 //
1941 // Given a control, see if it's the control projection of an Unlock which
1942 // operating on the same object as lock.
1943 //
1944 bool AbstractLockNode::find_matching_unlock(const Node* ctrl, LockNode* lock,
1945 GrowableArray<AbstractLockNode*> &lock_ops) {
1946 ProjNode *ctrl_proj = (ctrl->is_Proj()) ? ctrl->as_Proj() : nullptr;
1947 if (ctrl_proj != nullptr && ctrl_proj->_con == TypeFunc::Control) {
1948 Node *n = ctrl_proj->in(0);
1949 if (n != nullptr && n->is_Unlock()) {
1950 UnlockNode *unlock = n->as_Unlock();
1951 BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
1952 Node* lock_obj = bs->step_over_gc_barrier(lock->obj_node());
1953 Node* unlock_obj = bs->step_over_gc_barrier(unlock->obj_node());
1954 if (lock_obj->eqv_uncast(unlock_obj) &&
1955 BoxLockNode::same_slot(lock->box_node(), unlock->box_node()) &&
1956 !unlock->is_eliminated()) {
1957 lock_ops.append(unlock);
1958 return true;
1959 }
1960 }
1961 }
1962 return false;
1963 }
1964
1965 //
1966 // Find the lock matching an unlock. Returns null if a safepoint
1967 // or complicated control is encountered first.
1968 LockNode *AbstractLockNode::find_matching_lock(UnlockNode* unlock) {
1969 LockNode *lock_result = nullptr;
1970 // find the matching lock, or an intervening safepoint
1971 Node *ctrl = next_control(unlock->in(0));
1972 while (1) {
1973 assert(ctrl != nullptr, "invalid control graph");
1974 assert(!ctrl->is_Start(), "missing lock for unlock");
1975 if (ctrl->is_top()) break; // dead control path
1976 if (ctrl->is_Proj()) ctrl = ctrl->in(0);
1977 if (ctrl->is_SafePoint()) {
1978 break; // found a safepoint (may be the lock we are searching for)
1979 } else if (ctrl->is_Region()) {
1980 // Check for a simple diamond pattern. Punt on anything more complicated
1981 if (ctrl->req() == 3 && ctrl->in(1) != nullptr && ctrl->in(2) != nullptr) {
1982 Node *in1 = next_control(ctrl->in(1));
1983 Node *in2 = next_control(ctrl->in(2));
1984 if (((in1->is_IfTrue() && in2->is_IfFalse()) ||
1985 (in2->is_IfTrue() && in1->is_IfFalse())) && (in1->in(0) == in2->in(0))) {
1986 ctrl = next_control(in1->in(0)->in(0));
1987 } else {
1988 break;
1989 }
1990 } else {
1991 break;
1992 }
1993 } else {
1994 ctrl = next_control(ctrl->in(0)); // keep searching
1995 }
1996 }
1997 if (ctrl->is_Lock()) {
1998 LockNode *lock = ctrl->as_Lock();
1999 BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
2000 Node* lock_obj = bs->step_over_gc_barrier(lock->obj_node());
2001 Node* unlock_obj = bs->step_over_gc_barrier(unlock->obj_node());
2002 if (lock_obj->eqv_uncast(unlock_obj) &&
2003 BoxLockNode::same_slot(lock->box_node(), unlock->box_node())) {
2004 lock_result = lock;
2005 }
2006 }
2007 return lock_result;
2008 }
2009
2010 // This code corresponds to case 3 above.
2011
2012 bool AbstractLockNode::find_lock_and_unlock_through_if(Node* node, LockNode* lock,
2013 GrowableArray<AbstractLockNode*> &lock_ops) {
2014 Node* if_node = node->in(0);
2015 bool if_true = node->is_IfTrue();
2016
2017 if (if_node->is_If() && if_node->outcnt() == 2 && (if_true || node->is_IfFalse())) {
2018 Node *lock_ctrl = next_control(if_node->in(0));
2019 if (find_matching_unlock(lock_ctrl, lock, lock_ops)) {
2020 Node* lock1_node = nullptr;
2021 ProjNode* proj = if_node->as_If()->proj_out(!if_true);
2022 if (if_true) {
2023 if (proj->is_IfFalse() && proj->outcnt() == 1) {
2024 lock1_node = proj->unique_out();
2025 }
2026 } else {
2027 if (proj->is_IfTrue() && proj->outcnt() == 1) {
2028 lock1_node = proj->unique_out();
2029 }
2030 }
2031 if (lock1_node != nullptr && lock1_node->is_Lock()) {
2032 LockNode *lock1 = lock1_node->as_Lock();
2033 BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
2034 Node* lock_obj = bs->step_over_gc_barrier(lock->obj_node());
2035 Node* lock1_obj = bs->step_over_gc_barrier(lock1->obj_node());
2036 if (lock_obj->eqv_uncast(lock1_obj) &&
2037 BoxLockNode::same_slot(lock->box_node(), lock1->box_node()) &&
2038 !lock1->is_eliminated()) {
2039 lock_ops.append(lock1);
2040 return true;
2041 }
2042 }
2043 }
2044 }
2045
2046 lock_ops.trunc_to(0);
2047 return false;
2048 }
2049
2050 bool AbstractLockNode::find_unlocks_for_region(const RegionNode* region, LockNode* lock,
2051 GrowableArray<AbstractLockNode*> &lock_ops) {
2052 // check each control merging at this point for a matching unlock.
2053 // in(0) should be self edge so skip it.
2054 for (int i = 1; i < (int)region->req(); i++) {
2055 Node *in_node = next_control(region->in(i));
2056 if (in_node != nullptr) {
2057 if (find_matching_unlock(in_node, lock, lock_ops)) {
2058 // found a match so keep on checking.
2059 continue;
2060 } else if (find_lock_and_unlock_through_if(in_node, lock, lock_ops)) {
2061 continue;
2062 }
2063
2064 // If we fall through to here then it was some kind of node we
2065 // don't understand or there wasn't a matching unlock, so give
2066 // up trying to merge locks.
2067 lock_ops.trunc_to(0);
2068 return false;
2069 }
2070 }
2071 return true;
2072
2073 }
2074
2075 // Check that all locks/unlocks associated with object come from balanced regions.
2076 bool AbstractLockNode::is_balanced() {
2077 Node* obj = obj_node();
2078 for (uint j = 0; j < obj->outcnt(); j++) {
2079 Node* n = obj->raw_out(j);
2080 if (n->is_AbstractLock() &&
2081 n->as_AbstractLock()->obj_node()->eqv_uncast(obj)) {
2082 BoxLockNode* n_box = n->as_AbstractLock()->box_node()->as_BoxLock();
2083 if (n_box->is_unbalanced()) {
2084 return false;
2085 }
2086 }
2087 }
2088 return true;
2089 }
2090
2091 const char* AbstractLockNode::_kind_names[] = {"Regular", "NonEscObj", "Coarsened", "Nested"};
2092
2093 const char * AbstractLockNode::kind_as_string() const {
2094 return _kind_names[_kind];
2095 }
2096
2097 #ifndef PRODUCT
2098 //
2099 // Create a counter which counts the number of times this lock is acquired
2100 //
2101 void AbstractLockNode::create_lock_counter(JVMState* state) {
2102 _counter = OptoRuntime::new_named_counter(state, NamedCounter::LockCounter);
2103 }
2104
2105 void AbstractLockNode::set_eliminated_lock_counter() {
2106 if (_counter) {
2107 // Update the counter to indicate that this lock was eliminated.
2108 // The counter update code will stay around even though the
2109 // optimizer will eliminate the lock operation itself.
2110 _counter->set_tag(NamedCounter::EliminatedLockCounter);
2111 }
2112 }
2113
2114 void AbstractLockNode::dump_spec(outputStream* st) const {
2115 st->print("%s ", _kind_names[_kind]);
2116 CallNode::dump_spec(st);
2117 }
2118
2119 void AbstractLockNode::dump_compact_spec(outputStream* st) const {
2120 st->print("%s", _kind_names[_kind]);
2121 }
2122 #endif
2123
2124 //=============================================================================
2125 Node *LockNode::Ideal(PhaseGVN *phase, bool can_reshape) {
2126
2127 // perform any generic optimizations first (returns 'this' or null)
2128 Node *result = SafePointNode::Ideal(phase, can_reshape);
2129 if (result != nullptr) return result;
2130 // Don't bother trying to transform a dead node
2131 if (in(0) && in(0)->is_top()) return nullptr;
2132
2133 // Now see if we can optimize away this lock. We don't actually
2134 // remove the locking here, we simply set the _eliminate flag which
2135 // prevents macro expansion from expanding the lock. Since we don't
2136 // modify the graph, the value returned from this function is the
2137 // one computed above.
2138 if (can_reshape && EliminateLocks && !is_non_esc_obj()) {
2139 //
2140 // If we are locking an non-escaped object, the lock/unlock is unnecessary
2141 //
2142 ConnectionGraph *cgr = phase->C->congraph();
2143 if (cgr != nullptr && cgr->can_eliminate_lock(this)) {
2144 assert(!is_eliminated() || is_coarsened(), "sanity");
2145 // The lock could be marked eliminated by lock coarsening
2146 // code during first IGVN before EA. Replace coarsened flag
2147 // to eliminate all associated locks/unlocks.
2148 #ifdef ASSERT
2149 this->log_lock_optimization(phase->C,"eliminate_lock_set_non_esc1");
2150 #endif
2151 this->set_non_esc_obj();
2152 return result;
2153 }
2154
2155 if (!phase->C->do_locks_coarsening()) {
2156 return result; // Compiling without locks coarsening
2157 }
2158 //
2159 // Try lock coarsening
2160 //
2161 PhaseIterGVN* iter = phase->is_IterGVN();
2162 if (iter != nullptr && !is_eliminated()) {
2163
2164 GrowableArray<AbstractLockNode*> lock_ops;
2165
2166 Node *ctrl = next_control(in(0));
2167
2168 // now search back for a matching Unlock
2169 if (find_matching_unlock(ctrl, this, lock_ops)) {
2170 // found an unlock directly preceding this lock. This is the
2171 // case of single unlock directly control dependent on a
2172 // single lock which is the trivial version of case 1 or 2.
2173 } else if (ctrl->is_Region() ) {
2174 if (find_unlocks_for_region(ctrl->as_Region(), this, lock_ops)) {
2175 // found lock preceded by multiple unlocks along all paths
2176 // joining at this point which is case 3 in description above.
2177 }
2178 } else {
2179 // see if this lock comes from either half of an if and the
2180 // predecessors merges unlocks and the other half of the if
2181 // performs a lock.
2182 if (find_lock_and_unlock_through_if(ctrl, this, lock_ops)) {
2183 // found unlock splitting to an if with locks on both branches.
2184 }
2185 }
2186
2187 if (lock_ops.length() > 0) {
2188 // add ourselves to the list of locks to be eliminated.
2189 lock_ops.append(this);
2190
2191 #ifndef PRODUCT
2192 if (PrintEliminateLocks) {
2193 int locks = 0;
2194 int unlocks = 0;
2195 if (Verbose) {
2196 tty->print_cr("=== Locks coarsening ===");
2197 tty->print("Obj: ");
2198 obj_node()->dump();
2199 }
2200 for (int i = 0; i < lock_ops.length(); i++) {
2201 AbstractLockNode* lock = lock_ops.at(i);
2202 if (lock->Opcode() == Op_Lock)
2203 locks++;
2204 else
2205 unlocks++;
2206 if (Verbose) {
2207 tty->print("Box %d: ", i);
2208 box_node()->dump();
2209 tty->print(" %d: ", i);
2210 lock->dump();
2211 }
2212 }
2213 tty->print_cr("=== Coarsened %d unlocks and %d locks", unlocks, locks);
2214 }
2215 #endif
2216
2217 // for each of the identified locks, mark them
2218 // as eliminatable
2219 for (int i = 0; i < lock_ops.length(); i++) {
2220 AbstractLockNode* lock = lock_ops.at(i);
2221
2222 // Mark it eliminated by coarsening and update any counters
2223 #ifdef ASSERT
2224 lock->log_lock_optimization(phase->C, "eliminate_lock_set_coarsened");
2225 #endif
2226 lock->set_coarsened();
2227 }
2228 // Record this coarsened group.
2229 phase->C->add_coarsened_locks(lock_ops);
2230 } else if (ctrl->is_Region() &&
2231 iter->_worklist.member(ctrl)) {
2232 // We weren't able to find any opportunities but the region this
2233 // lock is control dependent on hasn't been processed yet so put
2234 // this lock back on the worklist so we can check again once any
2235 // region simplification has occurred.
2236 iter->_worklist.push(this);
2237 }
2238 }
2239 }
2240
2241 return result;
2242 }
2243
2244 //=============================================================================
2245 bool LockNode::is_nested_lock_region() {
2246 return is_nested_lock_region(nullptr);
2247 }
2248
2249 // p is used for access to compilation log; no logging if null
2250 bool LockNode::is_nested_lock_region(Compile * c) {
2251 BoxLockNode* box = box_node()->as_BoxLock();
2252 int stk_slot = box->stack_slot();
2253 if (stk_slot <= 0) {
2254 #ifdef ASSERT
2255 this->log_lock_optimization(c, "eliminate_lock_INLR_1");
2256 #endif
2257 return false; // External lock or it is not Box (Phi node).
2258 }
2259
2260 // Ignore complex cases: merged locks or multiple locks.
2261 Node* obj = obj_node();
2262 LockNode* unique_lock = nullptr;
2263 Node* bad_lock = nullptr;
2264 if (!box->is_simple_lock_region(&unique_lock, obj, &bad_lock)) {
2265 #ifdef ASSERT
2266 this->log_lock_optimization(c, "eliminate_lock_INLR_2a", bad_lock);
2267 #endif
2268 return false;
2269 }
2270 if (unique_lock != this) {
2271 #ifdef ASSERT
2272 this->log_lock_optimization(c, "eliminate_lock_INLR_2b", (unique_lock != nullptr ? unique_lock : bad_lock));
2273 if (PrintEliminateLocks && Verbose) {
2274 tty->print_cr("=============== unique_lock != this ============");
2275 tty->print(" this: ");
2276 this->dump();
2277 tty->print(" box: ");
2278 box->dump();
2279 tty->print(" obj: ");
2280 obj->dump();
2281 if (unique_lock != nullptr) {
2282 tty->print(" unique_lock: ");
2283 unique_lock->dump();
2284 }
2285 if (bad_lock != nullptr) {
2286 tty->print(" bad_lock: ");
2287 bad_lock->dump();
2288 }
2289 tty->print_cr("===============");
2290 }
2291 #endif
2292 return false;
2293 }
2294
2295 BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
2296 obj = bs->step_over_gc_barrier(obj);
2297 // Look for external lock for the same object.
2298 SafePointNode* sfn = this->as_SafePoint();
2299 JVMState* youngest_jvms = sfn->jvms();
2300 int max_depth = youngest_jvms->depth();
2301 for (int depth = 1; depth <= max_depth; depth++) {
2302 JVMState* jvms = youngest_jvms->of_depth(depth);
2303 int num_mon = jvms->nof_monitors();
2304 // Loop over monitors
2305 for (int idx = 0; idx < num_mon; idx++) {
2306 Node* obj_node = sfn->monitor_obj(jvms, idx);
2307 obj_node = bs->step_over_gc_barrier(obj_node);
2308 BoxLockNode* box_node = sfn->monitor_box(jvms, idx)->as_BoxLock();
2309 if ((box_node->stack_slot() < stk_slot) && obj_node->eqv_uncast(obj)) {
2310 box->set_nested();
2311 return true;
2312 }
2313 }
2314 }
2315 #ifdef ASSERT
2316 this->log_lock_optimization(c, "eliminate_lock_INLR_3");
2317 #endif
2318 return false;
2319 }
2320
2321 //=============================================================================
2322 uint UnlockNode::size_of() const { return sizeof(*this); }
2323
2324 //=============================================================================
2325 Node *UnlockNode::Ideal(PhaseGVN *phase, bool can_reshape) {
2326
2327 // perform any generic optimizations first (returns 'this' or null)
2328 Node *result = SafePointNode::Ideal(phase, can_reshape);
2329 if (result != nullptr) return result;
2330 // Don't bother trying to transform a dead node
2331 if (in(0) && in(0)->is_top()) return nullptr;
2332
2333 // Now see if we can optimize away this unlock. We don't actually
2334 // remove the unlocking here, we simply set the _eliminate flag which
2335 // prevents macro expansion from expanding the unlock. Since we don't
2336 // modify the graph, the value returned from this function is the
2337 // one computed above.
2338 // Escape state is defined after Parse phase.
2339 if (can_reshape && EliminateLocks && !is_non_esc_obj()) {
2340 //
2341 // If we are unlocking an non-escaped object, the lock/unlock is unnecessary.
2342 //
2343 ConnectionGraph *cgr = phase->C->congraph();
2344 if (cgr != nullptr && cgr->can_eliminate_lock(this)) {
2345 assert(!is_eliminated() || is_coarsened(), "sanity");
2346 // The lock could be marked eliminated by lock coarsening
2347 // code during first IGVN before EA. Replace coarsened flag
2348 // to eliminate all associated locks/unlocks.
2349 #ifdef ASSERT
2350 this->log_lock_optimization(phase->C, "eliminate_lock_set_non_esc2");
2351 #endif
2352 this->set_non_esc_obj();
2353 }
2354 }
2355 return result;
2356 }
2357
2358 void AbstractLockNode::log_lock_optimization(Compile *C, const char * tag, Node* bad_lock) const {
2359 if (C == nullptr) {
2360 return;
2361 }
2362 CompileLog* log = C->log();
2363 if (log != nullptr) {
2364 Node* box = box_node();
2365 Node* obj = obj_node();
2366 int box_id = box != nullptr ? box->_idx : -1;
2367 int obj_id = obj != nullptr ? obj->_idx : -1;
2368
2369 log->begin_head("%s compile_id='%d' lock_id='%d' class='%s' kind='%s' box_id='%d' obj_id='%d' bad_id='%d'",
2370 tag, C->compile_id(), this->_idx,
2371 is_Unlock() ? "unlock" : is_Lock() ? "lock" : "?",
2372 kind_as_string(), box_id, obj_id, (bad_lock != nullptr ? bad_lock->_idx : -1));
2373 log->stamp();
2374 log->end_head();
2375 JVMState* p = is_Unlock() ? (as_Unlock()->dbg_jvms()) : jvms();
2376 while (p != nullptr) {
2377 log->elem("jvms bci='%d' method='%d'", p->bci(), log->identify(p->method()));
2378 p = p->caller();
2379 }
2380 log->tail(tag);
2381 }
2382 }
2383
2384 bool CallNode::may_modify_arraycopy_helper(const TypeOopPtr* dest_t, const TypeOopPtr* t_oop, PhaseValues* phase) {
2385 if (dest_t->is_known_instance() && t_oop->is_known_instance()) {
2386 return dest_t->instance_id() == t_oop->instance_id();
2387 }
2388
2389 if (dest_t->isa_instptr() && !dest_t->is_instptr()->instance_klass()->equals(phase->C->env()->Object_klass())) {
2390 // clone
2391 if (t_oop->isa_aryptr()) {
2392 return false;
2393 }
2394 if (!t_oop->isa_instptr()) {
2395 return true;
2396 }
2397 if (dest_t->maybe_java_subtype_of(t_oop) || t_oop->maybe_java_subtype_of(dest_t)) {
2398 return true;
2399 }
2400 // unrelated
2401 return false;
2402 }
2403
2404 if (dest_t->isa_aryptr()) {
2405 // arraycopy or array clone
2406 if (t_oop->isa_instptr()) {
2407 return false;
2408 }
2409 if (!t_oop->isa_aryptr()) {
2410 return true;
2411 }
2412
2413 const Type* elem = dest_t->is_aryptr()->elem();
2414 if (elem == Type::BOTTOM) {
2415 // An array but we don't know what elements are
2416 return true;
2417 }
2418
2419 dest_t = dest_t->add_offset(Type::OffsetBot)->is_oopptr();
2420 uint dest_alias = phase->C->get_alias_index(dest_t);
2421 uint t_oop_alias = phase->C->get_alias_index(t_oop);
2422
2423 return dest_alias == t_oop_alias;
2424 }
2425
2426 return true;
2427 }