25
#include "precompiled.hpp"
26
#include "compiler/compileLog.hpp"
27
#include "ci/bcEscapeAnalyzer.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
#include "code/vmreg.hpp"
54
uint StartNode::size_of() const { return sizeof(*this); }
55
bool StartNode::cmp( const Node &n ) const
56
{ return _domain == ((StartNode&)n)._domain; }
57
const Type *StartNode::bottom_type() const { return _domain; }
58
const Type* StartNode::Value(PhaseGVN* phase) const { return _domain; }
60
void StartNode::dump_spec(outputStream *st) const { st->print(" #"); _domain->dump_on(st);}
61
void StartNode::dump_compact_spec(outputStream *st) const { }
65
Node *StartNode::Ideal(PhaseGVN *phase, bool can_reshape){
66
return remove_dead_region(phase, can_reshape) ? this : nullptr;
70
void StartNode::calling_convention(BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt) const {
71
SharedRuntime::java_calling_convention(sig_bt, parm_regs, argcnt);
75
const RegMask &StartNode::in_RegMask(uint) const {
76
return RegMask::Empty;
81
Node *StartNode::match( const ProjNode *proj, const Matcher *match ) {
83
case TypeFunc::Control:
85
case TypeFunc::Memory:
86
return new MachProjNode(this,proj->_con,RegMask::Empty,MachProjNode::unmatched_proj);
87
case TypeFunc::FramePtr:
88
return new MachProjNode(this,proj->_con,Matcher::c_frame_ptr_mask, Op_RegP);
89
case TypeFunc::ReturnAdr:
90
return new MachProjNode(this,proj->_con,match->_return_addr_mask,Op_RegP);
93
uint parm_num = proj->_con - TypeFunc::Parms;
94
const Type *t = _domain->field_at(proj->_con);
95
if (t->base() == Type::Half)
96
return new ConNode(Type::TOP);
97
uint ideal_reg = t->ideal_reg();
98
RegMask &rm = match->_calling_convention_mask[parm_num];
99
return new MachProjNode(this,proj->_con,rm,ideal_reg);
109
const TypeTuple *StartOSRNode::osr_domain() {
110
const Type **fields = TypeTuple::fields(2);
111
fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM;
113
return TypeTuple::make(TypeFunc::Parms+1, fields);
117
const char * const ParmNode::names[TypeFunc::Parms+1] = {
118
"Control", "I_O", "Memory", "FramePtr", "ReturnAdr", "Parms"
122
void ParmNode::dump_spec(outputStream *st) const {
123
if( _con < TypeFunc::Parms ) {
124
st->print("%s", names[_con]);
126
st->print("Parm%d: ",_con-TypeFunc::Parms);
128
if( !Verbose && !WizardMode ) bottom_type()->dump_on(st);
132
void ParmNode::dump_compact_spec(outputStream *st) const {
133
if (_con < TypeFunc::Parms) {
134
st->print("%s", names[_con]);
136
st->print("%d:", _con-TypeFunc::Parms);
138
bottom_type()->dump_on(st);
143
uint ParmNode::ideal_reg() const {
145
case TypeFunc::Control :
147
case TypeFunc::Memory : return 0;
148
case TypeFunc::FramePtr :
149
case TypeFunc::ReturnAdr: return Op_RegP;
150
default : assert( _con > TypeFunc::Parms, "" );
152
case TypeFunc::Parms : {
154
const Type *t = in(0)->as_Start()->_domain->field_at(_con);
155
return t->ideal_reg();
158
ShouldNotReachHere();
163
ReturnNode::ReturnNode(uint edges, Node *cntrl, Node *i_o, Node *memory, Node *frameptr, Node *retadr ) : Node(edges) {
164
init_req(TypeFunc::Control,cntrl);
165
init_req(TypeFunc::I_O,i_o);
166
init_req(TypeFunc::Memory,memory);
167
init_req(TypeFunc::FramePtr,frameptr);
168
init_req(TypeFunc::ReturnAdr,retadr);
171
Node *ReturnNode::Ideal(PhaseGVN *phase, bool can_reshape){
172
return remove_dead_region(phase, can_reshape) ? this : nullptr;
175
const Type* ReturnNode::Value(PhaseGVN* phase) const {
176
return ( phase->type(in(TypeFunc::Control)) == Type::TOP)
182
uint ReturnNode::match_edge(uint idx) const {
188
void ReturnNode::dump_req(outputStream *st, DumpConfig* dc) const {
191
for (i = 0; i < req(); i++) {
192
if (i == TypeFunc::Parms) st->print("returns ");
195
p->dump_idx(false, st, dc);
205
RethrowNode::RethrowNode(
212
) : Node(TypeFunc::Parms + 1) {
213
init_req(TypeFunc::Control , cntrl );
214
init_req(TypeFunc::I_O , i_o );
215
init_req(TypeFunc::Memory , memory );
216
init_req(TypeFunc::FramePtr , frameptr );
217
init_req(TypeFunc::ReturnAdr, ret_adr);
218
init_req(TypeFunc::Parms , exception);
221
Node *RethrowNode::Ideal(PhaseGVN *phase, bool can_reshape){
222
return remove_dead_region(phase, can_reshape) ? this : nullptr;
225
const Type* RethrowNode::Value(PhaseGVN* phase) const {
226
return (phase->type(in(TypeFunc::Control)) == Type::TOP)
231
uint RethrowNode::match_edge(uint idx) const {
236
void RethrowNode::dump_req(outputStream *st, DumpConfig* dc) const {
239
for (i = 0; i < req(); i++) {
240
if (i == TypeFunc::Parms) st->print("exception ");
243
p->dump_idx(false, st, dc);
254
uint TailCallNode::match_edge(uint idx) const {
255
return TypeFunc::Parms <= idx && idx <= TypeFunc::Parms+1;
260
uint TailJumpNode::match_edge(uint idx) const {
261
return TypeFunc::Parms <= idx && idx <= TypeFunc::Parms+1;
265
JVMState::JVMState(ciMethod* method, JVMState* caller) :
267
assert(method != nullptr, "must be valid call site");
268
_bci = InvocationEntryBci;
269
_reexecute = Reexecute_Undefined;
270
debug_only(_bci = -99);
271
debug_only(_map = (SafePointNode*)-1);
273
_depth = 1 + (caller == nullptr ? 0 : caller->depth());
274
_locoff = TypeFunc::Parms;
275
_stkoff = _locoff + _method->max_locals();
276
_monoff = _stkoff + _method->max_stack();
281
JVMState::JVMState(int stack_size) :
283
_bci = InvocationEntryBci;
284
_reexecute = Reexecute_Undefined;
285
debug_only(_map = (SafePointNode*)-1);
288
_locoff = TypeFunc::Parms;
290
_monoff = _stkoff + stack_size;
297
JVMState* JVMState::of_depth(int d) const {
298
const JVMState* jvmp = this;
299
assert(0 < d && (uint)d <= depth(), "oob");
300
for (int skip = depth() - d; skip > 0; skip--) {
301
jvmp = jvmp->caller();
303
assert(jvmp->depth() == (uint)d, "found the right one");
304
return (JVMState*)jvmp;
308
bool JVMState::same_calls_as(const JVMState* that) const {
309
if (this == that) return true;
310
if (this->depth() != that->depth()) return false;
311
const JVMState* p = this;
312
const JVMState* q = that;
314
if (p->_method != q->_method) return false;
315
if (p->_method == nullptr) return true;
316
if (p->_bci != q->_bci) return false;
317
if (p->_reexecute != q->_reexecute) return false;
320
if (p == q) return true;
321
assert(p != nullptr && q != nullptr, "depth check ensures we don't run off end");
326
uint JVMState::debug_start() const {
327
debug_only(JVMState* jvmroot = of_depth(1));
328
assert(jvmroot->locoff() <= this->locoff(), "youngest JVMState must be last");
329
return of_depth(1)->locoff();
333
uint JVMState::debug_end() const {
334
debug_only(JVMState* jvmroot = of_depth(1));
335
assert(jvmroot->endoff() <= this->endoff(), "youngest JVMState must be last");
340
uint JVMState::debug_depth() const {
342
for (const JVMState* jvmp = this; jvmp != nullptr; jvmp = jvmp->caller()) {
343
total += jvmp->debug_size();
353
static void format_helper( PhaseRegAlloc *regalloc, outputStream* st, Node *n, const char *msg, uint i, GrowableArray<SafePointScalarObjectNode*> *scobjs ) {
354
if (n == nullptr) { st->print(" null"); return; }
355
if (n->is_SafePointScalarObject()) {
357
SafePointScalarObjectNode* spobj = n->as_SafePointScalarObject();
358
scobjs->append_if_missing(spobj);
359
int sco_n = scobjs->find(spobj);
360
assert(sco_n >= 0, "");
361
st->print(" %s%d]=#ScObj" INT32_FORMAT, msg, i, sco_n);
364
if (regalloc->node_regs_max_index() > 0 &&
365
OptoReg::is_valid(regalloc->get_reg_first(n))) {
367
regalloc->dump_register(n,buf,sizeof(buf));
368
st->print(" %s%d]=%s",msg,i,buf);
370
const Type *t = n->bottom_type();
373
st->print(" %s%d]=#" INT32_FORMAT,msg,i,t->is_int()->get_con());
376
assert( t == TypePtr::NULL_PTR || n->in_dump(), "" );
377
st->print(" %s%d]=#null",msg,i);
381
st->print(" %s%d]=#Ptr" INTPTR_FORMAT,msg,i,p2i(t->isa_oopptr()->const_oop()));
384
case Type::AryKlassPtr:
385
case Type::InstKlassPtr:
386
st->print(" %s%d]=#Ptr" INTPTR_FORMAT,msg,i,p2i(t->make_ptr()->isa_klassptr()->exact_klass()));
388
case Type::MetadataPtr:
389
st->print(" %s%d]=#Ptr" INTPTR_FORMAT,msg,i,p2i(t->make_ptr()->isa_metadataptr()->metadata()));
391
case Type::NarrowOop:
392
st->print(" %s%d]=#Ptr" INTPTR_FORMAT,msg,i,p2i(t->make_ptr()->isa_oopptr()->const_oop()));
395
st->print(" %s%d]=#Raw" INTPTR_FORMAT,msg,i,p2i(t->is_rawptr()));
397
case Type::DoubleCon:
398
st->print(" %s%d]=#%fD",msg,i,t->is_double_constant()->_d);
401
st->print(" %s%d]=#%fF",msg,i,t->is_float_constant()->_f);
404
st->print(" %s%d]=#" INT64_FORMAT,msg,i,(int64_t)(t->is_long()->get_con()));
408
st->print(" %s%d]=_",msg,i);
410
default: ShouldNotReachHere();
416
void JVMState::print_method_with_lineno(outputStream* st, bool show_name) const {
417
if (show_name) _method->print_short_name(st);
419
int lineno = _method->line_number_from_bci(_bci);
421
st->print(" @ bci:%d (line %d)", _bci, lineno);
423
st->print(" @ bci:%d", _bci);
428
void JVMState::format(PhaseRegAlloc *regalloc, const Node *n, outputStream* st) const {
431
print_method_with_lineno(st, true);
433
st->print_cr(" runtime stub ");
436
if (n->is_MachSafePoint()) {
437
GrowableArray<SafePointScalarObjectNode*> scobjs;
438
MachSafePointNode *mcall = n->as_MachSafePoint();
441
for (i = 0; i < (uint)loc_size(); i++)
442
format_helper(regalloc, st, mcall->local(this, i), "L[", i, &scobjs);
444
for (i = 0; i < (uint)stk_size(); i++) {
445
if ((uint)(_stkoff + i) >= mcall->len())
448
format_helper(regalloc, st, mcall->stack(this, i), "STK[", i, &scobjs);
450
for (i = 0; (int)i < nof_monitors(); i++) {
451
Node *box = mcall->monitor_box(this, i);
452
Node *obj = mcall->monitor_obj(this, i);
453
if (regalloc->node_regs_max_index() > 0 &&
454
OptoReg::is_valid(regalloc->get_reg_first(box))) {
455
box = BoxLockNode::box_node(box);
456
format_helper(regalloc, st, box, "MON-BOX[", i, &scobjs);
458
OptoReg::Name box_reg = BoxLockNode::reg(box);
459
st->print(" MON-BOX%d=%s+%d",
461
OptoReg::regname(OptoReg::c_frame_pointer),
462
regalloc->reg2offset(box_reg));
464
const char* obj_msg = "MON-OBJ[";
465
if (EliminateLocks) {
466
if (BoxLockNode::box_node(box)->is_eliminated())
467
obj_msg = "MON-OBJ(LOCK ELIMINATED)[";
469
format_helper(regalloc, st, obj, obj_msg, i, &scobjs);
472
for (i = 0; i < (uint)scobjs.length(); i++) {
475
st->print(" # ScObj" INT32_FORMAT " ", i);
476
SafePointScalarObjectNode* spobj = scobjs.at(i);
477
ciKlass* cik = spobj->bottom_type()->is_oopptr()->exact_klass();
478
assert(cik->is_instance_klass() ||
479
cik->is_array_klass(), "Not supported allocation.");
480
ciInstanceKlass *iklass = nullptr;
481
if (cik->is_instance_klass()) {
482
cik->print_name_on(st);
483
iklass = cik->as_instance_klass();
484
} else if (cik->is_type_array_klass()) {
485
cik->as_array_klass()->base_element_type()->print_name_on(st);
486
st->print("[%d]", spobj->n_fields());
487
} else if (cik->is_obj_array_klass()) {
488
ciKlass* cie = cik->as_obj_array_klass()->base_element_klass();
489
if (cie->is_instance_klass()) {
490
cie->print_name_on(st);
491
} else if (cie->is_type_array_klass()) {
492
cie->as_array_klass()->base_element_type()->print_name_on(st);
494
ShouldNotReachHere();
496
st->print("[%d]", spobj->n_fields());
497
int ndim = cik->as_array_klass()->dimension() - 1;
503
uint nf = spobj->n_fields();
505
uint first_ind = spobj->first_index(mcall->jvms());
506
Node* fld_node = mcall->in(first_ind);
508
if (iklass != nullptr) {
510
cifield = iklass->nonstatic_field_at(0);
511
cifield->print_name_on(st);
512
format_helper(regalloc, st, fld_node, ":", 0, &scobjs);
514
format_helper(regalloc, st, fld_node, "[", 0, &scobjs);
516
for (uint j = 1; j < nf; j++) {
517
fld_node = mcall->in(first_ind+j);
518
if (iklass != nullptr) {
520
cifield = iklass->nonstatic_field_at(j);
521
cifield->print_name_on(st);
522
format_helper(regalloc, st, fld_node, ":", j, &scobjs);
524
format_helper(regalloc, st, fld_node, ", [", j, &scobjs);
532
if (caller() != nullptr) caller()->format(regalloc, n, st);
536
void JVMState::dump_spec(outputStream *st) const {
537
if (_method != nullptr) {
538
bool printed = false;
543
stringStream namest(buf, sizeof(buf));
544
_method->print_short_name(&namest);
545
if (namest.count() < sizeof(buf)) {
546
const char* name = namest.base();
547
if (name[0] == ' ') ++name;
548
const char* endcn = strchr(name, ':');
549
if (endcn == nullptr) endcn = strchr(name, '(');
550
if (endcn == nullptr) endcn = name + strlen(name);
551
while (endcn > name && endcn[-1] != '.' && endcn[-1] != '/')
553
st->print(" %s", endcn);
557
print_method_with_lineno(st, !printed);
558
if(_reexecute == Reexecute_True)
559
st->print(" reexecute");
561
st->print(" runtime stub");
563
if (caller() != nullptr) caller()->dump_spec(st);
567
void JVMState::dump_on(outputStream* st) const {
568
bool print_map = _map && !((uintptr_t)_map & 1) &&
569
((caller() == nullptr) || (caller()->map() != _map));
571
if (_map->len() > _map->req()) {
572
Node* ex = _map->in(_map->req());
574
while (ex != nullptr && ex->len() > ex->req()) {
575
ex = ex->in(ex->req());
579
_map->dump(Verbose ? 2 : 1);
581
if (caller() != nullptr) {
582
caller()->dump_on(st);
584
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=",
585
depth(), locoff(), stkoff(), argoff(), monoff(), scloff(), endoff(), monitor_depth(), sp(), bci(), should_reexecute()?"true":"false");
586
if (_method == nullptr) {
587
st->print_cr("(none)");
589
_method->print_name(st);
591
if (bci() >= 0 && bci() < _method->code_size()) {
593
_method->print_codes_on(bci(), bci()+1, st);
600
void dump_jvms(JVMState* jvms) {
606
JVMState* JVMState::clone_shallow(Compile* C) const {
607
JVMState* n = has_method() ? new (C) JVMState(_method, _caller) : new (C) JVMState(0);
609
n->_reexecute = _reexecute;
610
n->set_locoff(_locoff);
611
n->set_stkoff(_stkoff);
612
n->set_monoff(_monoff);
613
n->set_scloff(_scloff);
614
n->set_endoff(_endoff);
621
JVMState* JVMState::clone_deep(Compile* C) const {
622
JVMState* n = clone_shallow(C);
623
for (JVMState* p = n; p->_caller != nullptr; p = p->_caller) {
624
p->_caller = p->_caller->clone_shallow(C);
626
assert(n->depth() == depth(), "sanity");
627
assert(n->debug_depth() == debug_depth(), "sanity");
634
void JVMState::set_map_deep(SafePointNode* map) {
635
for (JVMState* p = this; p != nullptr; p = p->_caller) {
641
void JVMState::bind_map(SafePointNode* map) {
643
_map->set_jvms(this);
648
void JVMState::adapt_position(int delta) {
649
for (JVMState* jvms = this; jvms != nullptr; jvms = jvms->caller()) {
650
jvms->set_locoff(jvms->locoff() + delta);
651
jvms->set_stkoff(jvms->stkoff() + delta);
652
jvms->set_monoff(jvms->monoff() + delta);
653
jvms->set_scloff(jvms->scloff() + delta);
654
jvms->set_endoff(jvms->endoff() + delta);
661
int JVMState::interpreter_frame_size() const {
662
const JVMState* jvms = this;
664
int callee_parameters = 0;
665
int callee_locals = 0;
666
int extra_args = method()->max_stack() - stk_size();
668
while (jvms != nullptr) {
669
int locks = jvms->nof_monitors();
670
int temps = jvms->stk_size();
671
bool is_top_frame = (jvms == this);
672
ciMethod* method = jvms->method();
674
int frame_size = BytesPerWord * Interpreter::size_activation(method->max_stack(),
675
temps + callee_parameters,
683
callee_parameters = method->size_of_parameters();
684
callee_locals = method->max_locals();
686
jvms = jvms->caller();
688
return size + Deoptimization::last_frame_adjust(0, callee_locals) * BytesPerWord;
692
bool CallNode::cmp( const Node &n ) const
693
{ return _tf == ((CallNode&)n)._tf && _jvms == ((CallNode&)n)._jvms; }
695
void CallNode::dump_req(outputStream *st, DumpConfig* dc) const {
698
for (i = 0; i < req(); i++) {
699
if (i == TypeFunc::Parms) st->print("(");
702
p->dump_idx(false, st, dc);
711
void CallNode::dump_spec(outputStream *st) const {
713
if (tf() != nullptr) tf()->dump_on(st);
714
if (_cnt != COUNT_UNKNOWN) st->print(" C=%f",_cnt);
715
if (jvms() != nullptr) jvms()->dump_spec(st);
719
const Type *CallNode::bottom_type() const { return tf()->range(); }
720
const Type* CallNode::Value(PhaseGVN* phase) const {
721
if (phase->type(in(0)) == Type::TOP) return Type::TOP;
722
return tf()->range();
726
void CallNode::calling_convention(BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt) const {
728
SharedRuntime::java_calling_convention(sig_bt, parm_regs, argcnt);
735
Node *CallNode::match( const ProjNode *proj, const Matcher *match ) {
736
switch (proj->_con) {
737
case TypeFunc::Control:
739
case TypeFunc::Memory:
740
return new MachProjNode(this,proj->_con,RegMask::Empty,MachProjNode::unmatched_proj);
742
case TypeFunc::Parms+1:
743
assert(tf()->range()->field_at(TypeFunc::Parms+1) == Type::HALF, "");
745
return new MachProjNode(this,proj->_con, RegMask::Empty, (uint)OptoReg::Bad);
747
case TypeFunc::Parms: {
748
uint ideal_reg = tf()->range()->field_at(TypeFunc::Parms)->ideal_reg();
749
OptoRegPair regs = Opcode() == Op_CallLeafVector
750
? match->vector_return_value(ideal_reg)
752
? match->c_return_value(ideal_reg)
753
: match-> return_value(ideal_reg);
754
RegMask rm = RegMask(regs.first());
756
if (Opcode() == Op_CallLeafVector) {
758
if(ideal_reg >= Op_VecS && ideal_reg <= Op_VecZ) {
759
if(OptoReg::is_valid(regs.second())) {
760
for (OptoReg::Name r = regs.first(); r <= regs.second(); r = OptoReg::add(r, 1)) {
767
if( OptoReg::is_valid(regs.second()) )
768
rm.Insert( regs.second() );
769
return new MachProjNode(this,proj->_con,rm,ideal_reg);
772
case TypeFunc::ReturnAdr:
773
case TypeFunc::FramePtr:
775
ShouldNotReachHere();
781
uint CallNode::match_edge(uint idx) const {
789
bool CallNode::may_modify(const TypeOopPtr* t_oop, PhaseValues* phase) {
790
assert((t_oop != nullptr), "sanity");
791
if (is_call_to_arraycopystub() && strcmp(_name, "unsafe_arraycopy") != 0) {
792
const TypeTuple* args = _tf->domain();
793
Node* dest = nullptr;
797
for (uint i = TypeFunc::Parms, j = 0; i < args->cnt(); i++) {
798
if (args->field_at(i)->isa_ptr()) {
806
guarantee(dest != nullptr, "Call had only one ptr in, broken IR!");
807
if (!dest->is_top() && may_modify_arraycopy_helper(phase->type(dest)->is_oopptr(), t_oop, phase)) {
812
if (t_oop->is_known_instance()) {
817
if (t_oop->is_ptr_to_boxed_value()) {
818
ciKlass* boxing_klass = t_oop->is_instptr()->instance_klass();
819
if (is_CallStaticJava() && as_CallStaticJava()->is_boxing_method()) {
821
Node* proj = proj_out_or_null(TypeFunc::Parms);
822
if ((proj == nullptr) || (phase->type(proj)->is_instptr()->instance_klass() != boxing_klass)) {
826
if (is_CallJava() && as_CallJava()->method() != nullptr) {
827
ciMethod* meth = as_CallJava()->method();
828
if (meth->is_getter()) {
833
Node* proj = returns_pointer() ? proj_out_or_null(TypeFunc::Parms) : nullptr;
834
if (proj != nullptr) {
835
const TypeInstPtr* inst_t = phase->type(proj)->isa_instptr();
836
if ((inst_t != nullptr) && (!inst_t->klass_is_exact() ||
837
(inst_t->instance_klass() == boxing_klass))) {
841
const TypeTuple* d = tf()->domain();
842
for (uint i = TypeFunc::Parms; i < d->cnt(); i++) {
843
const TypeInstPtr* inst_t = d->field_at(i)->isa_instptr();
844
if ((inst_t != nullptr) && (!inst_t->klass_is_exact() ||
845
(inst_t->instance_klass() == boxing_klass))) {
856
bool CallNode::has_non_debug_use(Node *n) {
857
const TypeTuple * d = tf()->domain();
858
for (uint i = TypeFunc::Parms; i < d->cnt(); i++) {
870
Node *CallNode::result_cast() {
871
Node *cast = nullptr;
873
Node *p = proj_out_or_null(TypeFunc::Parms);
877
for (DUIterator_Fast imax, i = p->fast_outs(imax); i < imax; i++) {
878
Node *use = p->fast_out(i);
879
if (use->is_CheckCastPP()) {
880
if (cast != nullptr) {
884
} else if (!use->is_Initialize() &&
886
use->Opcode() != Op_MemBarStoreStore) {
898
void CallNode::extract_projections(CallProjections* projs, bool separate_io_proj, bool do_asserts) {
899
projs->fallthrough_proj = nullptr;
900
projs->fallthrough_catchproj = nullptr;
901
projs->fallthrough_ioproj = nullptr;
902
projs->catchall_ioproj = nullptr;
903
projs->catchall_catchproj = nullptr;
904
projs->fallthrough_memproj = nullptr;
905
projs->catchall_memproj = nullptr;
906
projs->resproj = nullptr;
907
projs->exobj = nullptr;
909
for (DUIterator_Fast imax, i = fast_outs(imax); i < imax; i++) {
910
ProjNode *pn = fast_out(i)->as_Proj();
911
if (pn->outcnt() == 0) continue;
913
case TypeFunc::Control:
916
projs->fallthrough_proj = pn;
917
const Node* cn = pn->unique_ctrl_out_or_null();
918
if (cn != nullptr && cn->is_Catch()) {
919
ProjNode *cpn = nullptr;
920
for (DUIterator_Fast kmax, k = cn->fast_outs(kmax); k < kmax; k++) {
921
cpn = cn->fast_out(k)->as_Proj();
922
assert(cpn->is_CatchProj(), "must be a CatchProjNode");
923
if (cpn->_con == CatchProjNode::fall_through_index)
924
projs->fallthrough_catchproj = cpn;
926
assert(cpn->_con == CatchProjNode::catch_all_index, "must be correct index.");
927
projs->catchall_catchproj = cpn;
935
projs->catchall_ioproj = pn;
937
projs->fallthrough_ioproj = pn;
938
for (DUIterator j = pn->outs(); pn->has_out(j); j++) {
939
Node* e = pn->out(j);
940
if (e->Opcode() == Op_CreateEx && e->in(0)->is_CatchProj() && e->outcnt() > 0) {
941
assert(projs->exobj == nullptr, "only one");
946
case TypeFunc::Memory:
948
projs->catchall_memproj = pn;
950
projs->fallthrough_memproj = pn;
952
case TypeFunc::Parms:
956
assert(false, "unexpected projection from allocation node.");
963
assert(projs->fallthrough_proj != nullptr, "must be found");
964
do_asserts = do_asserts && !Compile::current()->inlining_incrementally();
965
assert(!do_asserts || projs->fallthrough_catchproj != nullptr, "must be found");
966
assert(!do_asserts || projs->fallthrough_memproj != nullptr, "must be found");
967
assert(!do_asserts || projs->fallthrough_ioproj != nullptr, "must be found");
968
assert(!do_asserts || projs->catchall_catchproj != nullptr, "must be found");
969
if (separate_io_proj) {
970
assert(!do_asserts || projs->catchall_memproj != nullptr, "must be found");
971
assert(!do_asserts || projs->catchall_ioproj != nullptr, "must be found");
975
Node* CallNode::Ideal(PhaseGVN* phase, bool can_reshape) {
978
CallGenerator* cg = generator();
980
assert((is_CallStaticJava() && cg->is_mh_late_inline()) ||
981
(is_CallDynamicJava() && cg->is_virtual_late_inline()), "mismatch");
984
return SafePointNode::Ideal(phase, can_reshape);
987
bool CallNode::is_call_to_arraycopystub() const {
988
if (_name != nullptr && strstr(_name, "arraycopy") != nullptr) {
995
uint CallJavaNode::size_of() const { return sizeof(*this); }
996
bool CallJavaNode::cmp( const Node &n ) const {
997
CallJavaNode &call = (CallJavaNode&)n;
998
return CallNode::cmp(call) && _method == call._method &&
999
_override_symbolic_info == call._override_symbolic_info;
1002
void CallJavaNode::copy_call_debug_info(PhaseIterGVN* phase, SafePointNode* sfpt) {
1004
uint old_dbg_start = sfpt->is_Call() ? sfpt->as_Call()->tf()->domain()->cnt() : (uint)TypeFunc::Parms+1;
1005
uint new_dbg_start = tf()->domain()->cnt();
1006
int jvms_adj = new_dbg_start - old_dbg_start;
1007
assert (new_dbg_start == req(), "argument count mismatch");
1008
Compile* C = phase->C;
1012
Dict* sosn_map = new Dict(cmpkey,hashkey);
1013
for (uint i = old_dbg_start; i < sfpt->req(); i++) {
1014
Node* old_in = sfpt->in(i);
1016
if (old_in != nullptr && old_in->is_SafePointScalarObject()) {
1017
SafePointScalarObjectNode* old_sosn = old_in->as_SafePointScalarObject();
1019
Node* new_in = old_sosn->clone(sosn_map, new_node);
1021
new_in->set_req(0, C->root());
1022
new_in = phase->transform(new_in);
1030
set_jvms(sfpt->jvms() != nullptr ? sfpt->jvms()->clone_deep(C) : nullptr);
1031
for (JVMState *jvms = this->jvms(); jvms != nullptr; jvms = jvms->caller()) {
1032
jvms->set_map(this);
1033
jvms->set_locoff(jvms->locoff()+jvms_adj);
1034
jvms->set_stkoff(jvms->stkoff()+jvms_adj);
1035
jvms->set_monoff(jvms->monoff()+jvms_adj);
1036
jvms->set_scloff(jvms->scloff()+jvms_adj);
1037
jvms->set_endoff(jvms->endoff()+jvms_adj);
1042
bool CallJavaNode::validate_symbolic_info() const {
1043
if (method() == nullptr) {
1046
ciMethod* symbolic_info = jvms()->method()->get_method_at_bci(jvms()->bci());
1047
ciMethod* callee = method();
1048
if (symbolic_info->is_method_handle_intrinsic() && !callee->is_method_handle_intrinsic()) {
1049
assert(override_symbolic_info(), "should be set");
1051
assert(ciMethod::is_consistent_info(symbolic_info, callee), "inconsistent info");
1057
void CallJavaNode::dump_spec(outputStream* st) const {
1058
if( _method ) _method->print_short_name(st);
1059
CallNode::dump_spec(st);
1062
void CallJavaNode::dump_compact_spec(outputStream* st) const {
1064
_method->print_short_name(st);
1072
uint CallStaticJavaNode::size_of() const { return sizeof(*this); }
1073
bool CallStaticJavaNode::cmp( const Node &n ) const {
1074
CallStaticJavaNode &call = (CallStaticJavaNode&)n;
1075
return CallJavaNode::cmp(call);
1078
Node* CallStaticJavaNode::Ideal(PhaseGVN* phase, bool can_reshape) {
1079
CallGenerator* cg = generator();
1080
if (can_reshape && cg != nullptr) {
1081
assert(IncrementalInlineMH, "required");
1082
assert(cg->call_node() == this, "mismatch");
1083
assert(cg->is_mh_late_inline(), "not virtual");
1086
ciMethod* callee = cg->method();
1087
vmIntrinsics::ID iid = callee->intrinsic_id();
1088
if (iid == vmIntrinsics::_invokeBasic) {
1089
if (in(TypeFunc::Parms)->Opcode() == Op_ConP) {
1090
phase->C->prepend_late_inline(cg);
1091
set_generator(nullptr);
1093
} else if (iid == vmIntrinsics::_linkToNative) {
1096
assert(callee->has_member_arg(), "wrong type of call?");
1097
if (in(TypeFunc::Parms + callee->arg_size() - 1)->Opcode() == Op_ConP) {
1098
phase->C->prepend_late_inline(cg);
1099
set_generator(nullptr);
1103
return CallNode::Ideal(phase, can_reshape);
1108
bool CallStaticJavaNode::is_uncommon_trap() const {
1109
return (_name != nullptr && !strcmp(_name, "uncommon_trap"));
1114
int CallStaticJavaNode::uncommon_trap_request() const {
1115
return is_uncommon_trap() ? extract_uncommon_trap_request(this) : 0;
1117
int CallStaticJavaNode::extract_uncommon_trap_request(const Node* call) {
1119
if (!(call->req() > TypeFunc::Parms &&
1120
call->in(TypeFunc::Parms) != nullptr &&
1121
call->in(TypeFunc::Parms)->is_Con() &&
1122
call->in(TypeFunc::Parms)->bottom_type()->isa_int())) {
1123
assert(in_dump() != 0, "OK if dumping");
1124
tty->print("[bad uncommon trap]");
1128
return call->in(TypeFunc::Parms)->bottom_type()->is_int()->get_con();
1132
void CallStaticJavaNode::dump_spec(outputStream *st) const {
1133
st->print("# Static ");
1134
if (_name != nullptr) {
1135
st->print("%s", _name);
1136
int trap_req = uncommon_trap_request();
1137
if (trap_req != 0) {
1140
Deoptimization::format_trap_request(buf, sizeof(buf),
1145
CallJavaNode::dump_spec(st);
1148
void CallStaticJavaNode::dump_compact_spec(outputStream* st) const {
1150
_method->print_short_name(st);
1152
st->print("%s", _name);
1160
uint CallDynamicJavaNode::size_of() const { return sizeof(*this); }
1161
bool CallDynamicJavaNode::cmp( const Node &n ) const {
1162
CallDynamicJavaNode &call = (CallDynamicJavaNode&)n;
1163
return CallJavaNode::cmp(call);
1166
Node* CallDynamicJavaNode::Ideal(PhaseGVN* phase, bool can_reshape) {
1167
CallGenerator* cg = generator();
1168
if (can_reshape && cg != nullptr) {
1169
assert(IncrementalInlineVirtual, "required");
1170
assert(cg->call_node() == this, "mismatch");
1171
assert(cg->is_virtual_late_inline(), "not virtual");
1174
ciMethod* caller = jvms()->method();
1175
ciBytecodeStream iter(caller);
1176
iter.force_bci(jvms()->bci());
1179
ciSignature* not_used2;
1180
ciMethod* orig_callee = iter.get_method(not_used1, ¬_used2);
1181
ciKlass* holder = iter.get_declared_method_holder();
1182
if (orig_callee->is_method_handle_intrinsic()) {
1183
assert(_override_symbolic_info, "required");
1184
orig_callee = method();
1185
holder = method()->holder();
1188
ciInstanceKlass* klass = ciEnv::get_instance_klass_for_declared_method_holder(holder);
1190
Node* receiver_node = in(TypeFunc::Parms);
1191
const TypeOopPtr* receiver_type = phase->type(receiver_node)->isa_oopptr();
1194
bool call_does_dispatch;
1195
ciMethod* callee = phase->C->optimize_virtual_call(caller, klass, holder, orig_callee, receiver_type, true ,
1196
call_does_dispatch, not_used3);
1197
if (!call_does_dispatch) {
1199
cg->set_callee_method(callee);
1200
phase->C->prepend_late_inline(cg);
1201
set_generator(nullptr);
1204
return CallNode::Ideal(phase, can_reshape);
1208
void CallDynamicJavaNode::dump_spec(outputStream *st) const {
1209
st->print("# Dynamic ");
1210
CallJavaNode::dump_spec(st);
1215
uint CallRuntimeNode::size_of() const { return sizeof(*this); }
1216
bool CallRuntimeNode::cmp( const Node &n ) const {
1217
CallRuntimeNode &call = (CallRuntimeNode&)n;
1218
return CallNode::cmp(call) && !strcmp(_name,call._name);
1221
void CallRuntimeNode::dump_spec(outputStream *st) const {
1223
st->print("%s", _name);
1224
CallNode::dump_spec(st);
1227
uint CallLeafVectorNode::size_of() const { return sizeof(*this); }
1228
bool CallLeafVectorNode::cmp( const Node &n ) const {
1229
CallLeafVectorNode &call = (CallLeafVectorNode&)n;
1230
return CallLeafNode::cmp(call) && _num_bits == call._num_bits;
1234
void CallRuntimeNode::calling_convention(BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt) const {
1235
SharedRuntime::c_calling_convention(sig_bt, parm_regs, argcnt);
1238
void CallLeafVectorNode::calling_convention( BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt ) const {
1240
assert(tf()->range()->field_at(TypeFunc::Parms)->is_vect()->length_in_bytes() * BitsPerByte == _num_bits,
1241
"return vector size must match");
1242
const TypeTuple* d = tf()->domain();
1243
for (uint i = TypeFunc::Parms; i < d->cnt(); i++) {
1245
assert(arg->bottom_type()->is_vect()->length_in_bytes() * BitsPerByte == _num_bits,
1246
"vector argument size must match");
1250
SharedRuntime::vector_calling_convention(parm_regs, _num_bits, argcnt);
1259
void CallLeafNode::dump_spec(outputStream *st) const {
1261
st->print("%s", _name);
1262
CallNode::dump_spec(st);
1268
void SafePointNode::set_local(JVMState* jvms, uint idx, Node *c) {
1269
assert(verify_jvms(jvms), "jvms must match");
1270
int loc = jvms->locoff() + idx;
1271
if (in(loc)->is_top() && idx > 0 && !c->is_top() ) {
1275
uint ideal = in(loc -1)->ideal_reg();
1276
if (ideal == Op_RegD || ideal == Op_RegL) {
1278
set_req(loc - 1, in(loc));
1284
uint SafePointNode::size_of() const { return sizeof(*this); }
1285
bool SafePointNode::cmp( const Node &n ) const {
1286
return (&n == this);
1290
void SafePointNode::set_next_exception(SafePointNode* n) {
1291
assert(n == nullptr || n->Opcode() == Op_SafePoint, "correct value for next_exception");
1292
if (len() == req()) {
1293
if (n != nullptr) add_prec(n);
1301
SafePointNode* SafePointNode::next_exception() const {
1302
if (len() == req()) {
1305
Node* n = in(req());
1306
assert(n == nullptr || n->Opcode() == Op_SafePoint, "no other uses of prec edges");
1307
return (SafePointNode*) n;
1314
Node *SafePointNode::Ideal(PhaseGVN *phase, bool can_reshape) {
1315
assert(_jvms == nullptr || ((uintptr_t)_jvms->map() & 1) || _jvms->map() == this, "inconsistent JVMState");
1316
return remove_dead_region(phase, can_reshape) ? this : nullptr;
1321
Node* SafePointNode::Identity(PhaseGVN* phase) {
1324
if (in(TypeFunc::Control)->is_SafePoint()) {
1325
Node* out_c = unique_ctrl_out_or_null();
1328
if (out_c != nullptr && !out_c->is_OuterStripMinedLoopEnd()) {
1329
return in(TypeFunc::Control);
1335
if (in(0)->is_Proj() && !phase->C->major_progress()) {
1336
Node *n0 = in(0)->in(0);
1338
if( n0->is_Catch() ) {
1339
n0 = n0->in(0)->in(0);
1340
assert( n0->is_Call(), "expect a call here" );
1342
if( n0->is_Call() && n0->as_Call()->guaranteed_safepoint() ) {
1345
if (has_out_with(Op_OuterStripMinedLoopEnd)) {
1349
return in(TypeFunc::Control);
1357
const Type* SafePointNode::Value(PhaseGVN* phase) const {
1358
if (phase->type(in(0)) == Type::TOP) {
1361
if (in(0) == this) {
1364
return Type::CONTROL;
1368
void SafePointNode::dump_spec(outputStream *st) const {
1369
st->print(" SafePoint ");
1370
_replaced_nodes.dump(st);
1374
const RegMask &SafePointNode::in_RegMask(uint idx) const {
1375
if( idx < TypeFunc::Parms ) return RegMask::Empty;
1377
return *(Compile::current()->matcher()->idealreg2debugmask[in(idx)->ideal_reg()]);
1379
const RegMask &SafePointNode::out_RegMask() const {
1380
return RegMask::Empty;
1384
void SafePointNode::grow_stack(JVMState* jvms, uint grow_by) {
1385
assert((int)grow_by > 0, "sanity");
1386
int monoff = jvms->monoff();
1387
int scloff = jvms->scloff();
1388
int endoff = jvms->endoff();
1389
assert(endoff == (int)req(), "no other states or debug info after me");
1390
Node* top = Compile::current()->top();
1391
for (uint i = 0; i < grow_by; i++) {
1392
ins_req(monoff, top);
1394
jvms->set_monoff(monoff + grow_by);
1395
jvms->set_scloff(scloff + grow_by);
1396
jvms->set_endoff(endoff + grow_by);
1399
void SafePointNode::push_monitor(const FastLockNode *lock) {
1402
const int MonitorEdges = 2;
1403
assert(JVMState::logMonitorEdges == exact_log2(MonitorEdges), "correct MonitorEdges");
1404
assert(req() == jvms()->endoff(), "correct sizing");
1405
int nextmon = jvms()->scloff();
1406
if (GenerateSynchronizationCode) {
1407
ins_req(nextmon, lock->box_node());
1408
ins_req(nextmon+1, lock->obj_node());
1410
Node* top = Compile::current()->top();
1411
ins_req(nextmon, top);
1412
ins_req(nextmon, top);
1414
jvms()->set_scloff(nextmon + MonitorEdges);
1415
jvms()->set_endoff(req());
1418
void SafePointNode::pop_monitor() {
1420
debug_only(int num_before_pop = jvms()->nof_monitors());
1421
const int MonitorEdges = 2;
1422
assert(JVMState::logMonitorEdges == exact_log2(MonitorEdges), "correct MonitorEdges");
1423
int scloff = jvms()->scloff();
1424
int endoff = jvms()->endoff();
1425
int new_scloff = scloff - MonitorEdges;
1426
int new_endoff = endoff - MonitorEdges;
1427
jvms()->set_scloff(new_scloff);
1428
jvms()->set_endoff(new_endoff);
1429
while (scloff > new_scloff) del_req_ordered(--scloff);
1430
assert(jvms()->nof_monitors() == num_before_pop-1, "");
1433
Node *SafePointNode::peek_monitor_box() const {
1434
int mon = jvms()->nof_monitors() - 1;
1435
assert(mon >= 0, "must have a monitor");
1436
return monitor_box(jvms(), mon);
1439
Node *SafePointNode::peek_monitor_obj() const {
1440
int mon = jvms()->nof_monitors() - 1;
1441
assert(mon >= 0, "must have a monitor");
1442
return monitor_obj(jvms(), mon);
1445
Node* SafePointNode::peek_operand(uint off) const {
1446
assert(jvms()->sp() > 0, "must have an operand");
1447
assert(off < jvms()->sp(), "off is out-of-range");
1448
return stack(jvms(), jvms()->sp() - off - 1);
1452
uint SafePointNode::match_edge(uint idx) const {
1453
return (TypeFunc::Parms == idx);
1456
void SafePointNode::disconnect_from_root(PhaseIterGVN *igvn) {
1457
assert(Opcode() == Op_SafePoint, "only value for safepoint in loops");
1458
int nb = igvn->C->root()->find_prec_edge(this);
1460
igvn->delete_precedence_of(igvn->C->root(), nb);
1466
SafePointScalarObjectNode::SafePointScalarObjectNode(const TypeOopPtr* tp, Node* alloc, uint first_index, uint depth, uint n_fields) :
1468
_first_index(first_index),
1470
_n_fields(n_fields),
1474
if (!alloc->is_Allocate() && !(alloc->Opcode() == Op_VectorBox)) {
1476
assert(false, "unexpected call node");
1479
init_class_id(Class_SafePointScalarObject);
1483
uint SafePointScalarObjectNode::hash() const { return NO_HASH; }
1484
bool SafePointScalarObjectNode::cmp( const Node &n ) const {
1485
return (&n == this);
1488
uint SafePointScalarObjectNode::ideal_reg() const {
1492
const RegMask &SafePointScalarObjectNode::in_RegMask(uint idx) const {
1493
return *(Compile::current()->matcher()->idealreg2debugmask[in(idx)->ideal_reg()]);
1496
const RegMask &SafePointScalarObjectNode::out_RegMask() const {
1497
return RegMask::Empty;
1500
uint SafePointScalarObjectNode::match_edge(uint idx) const {
1504
SafePointScalarObjectNode*
1505
SafePointScalarObjectNode::clone(Dict* sosn_map, bool& new_node) const {
1506
void* cached = (*sosn_map)[(void*)this];
1507
if (cached != nullptr) {
1509
return (SafePointScalarObjectNode*)cached;
1512
SafePointScalarObjectNode* res = (SafePointScalarObjectNode*)Node::clone();
1513
sosn_map->Insert((void*)this, (void*)res);
1519
void SafePointScalarObjectNode::dump_spec(outputStream *st) const {
1520
st->print(" # fields@[%d..%d]", first_index(), first_index() + n_fields() - 1);
1526
SafePointScalarMergeNode::SafePointScalarMergeNode(const TypeOopPtr* tp, int merge_pointer_idx) :
1528
_merge_pointer_idx(merge_pointer_idx)
1530
init_class_id(Class_SafePointScalarMerge);
1534
uint SafePointScalarMergeNode::hash() const { return NO_HASH; }
1535
bool SafePointScalarMergeNode::cmp( const Node &n ) const {
1536
return (&n == this);
1539
uint SafePointScalarMergeNode::ideal_reg() const {
1543
const RegMask &SafePointScalarMergeNode::in_RegMask(uint idx) const {
1544
return *(Compile::current()->matcher()->idealreg2debugmask[in(idx)->ideal_reg()]);
1547
const RegMask &SafePointScalarMergeNode::out_RegMask() const {
1548
return RegMask::Empty;
1551
uint SafePointScalarMergeNode::match_edge(uint idx) const {
1555
SafePointScalarMergeNode*
1556
SafePointScalarMergeNode::clone(Dict* sosn_map, bool& new_node) const {
1557
void* cached = (*sosn_map)[(void*)this];
1558
if (cached != nullptr) {
1560
return (SafePointScalarMergeNode*)cached;
1563
SafePointScalarMergeNode* res = (SafePointScalarMergeNode*)Node::clone();
1564
sosn_map->Insert((void*)this, (void*)res);
1569
void SafePointScalarMergeNode::dump_spec(outputStream *st) const {
1570
st->print(" # merge_pointer_idx=%d, scalarized_objects=%d", _merge_pointer_idx, req()-1);
1575
uint AllocateNode::size_of() const { return sizeof(*this); }
1577
AllocateNode::AllocateNode(Compile* C, const TypeFunc *atype,
1578
Node *ctrl, Node *mem, Node *abio,
1579
Node *size, Node *klass_node, Node *initial_test)
1580
: CallNode(atype, nullptr, TypeRawPtr::BOTTOM)
1582
init_class_id(Class_Allocate);
1583
init_flags(Flag_is_macro);
1584
_is_scalar_replaceable = false;
1585
_is_non_escaping = false;
1586
_is_allocation_MemBar_redundant = false;
1587
Node *topnode = C->top();
1589
init_req( TypeFunc::Control , ctrl );
1590
init_req( TypeFunc::I_O , abio );
1591
init_req( TypeFunc::Memory , mem );
1592
init_req( TypeFunc::ReturnAdr, topnode );
1593
init_req( TypeFunc::FramePtr , topnode );
1594
init_req( AllocSize , size);
1595
init_req( KlassNode , klass_node);
1596
init_req( InitialTest , initial_test);
1597
init_req( ALength , topnode);
1598
init_req( ValidLengthTest , topnode);
1599
C->add_macro_node(this);
1602
void AllocateNode::compute_MemBar_redundancy(ciMethod* initializer)
1604
assert(initializer != nullptr && initializer->is_object_initializer(),
1605
"unexpected initializer method");
1606
BCEscapeAnalyzer* analyzer = initializer->get_bcea();
1607
if (analyzer == nullptr) {
1612
if (analyzer->is_arg_stack(0) || analyzer->is_arg_local(0)) {
1613
_is_allocation_MemBar_redundant = true;
1616
Node *AllocateNode::make_ideal_mark(PhaseGVN *phase, Node* obj, Node* control, Node* mem) {
1617
Node* mark_node = nullptr;
1619
mark_node = phase->MakeConX(markWord::prototype().value());
1626
Node *AllocateArrayNode::make_ideal_length(const TypeOopPtr* oop_type, PhaseValues* phase, bool allow_new_nodes) {
1627
Node *length = in(AllocateNode::ALength);
1628
assert(length != nullptr, "length is not null");
1630
const TypeInt* length_type = phase->find_int_type(length);
1631
const TypeAryPtr* ary_type = oop_type->isa_aryptr();
1633
if (ary_type != nullptr && length_type != nullptr) {
1634
const TypeInt* narrow_length_type = ary_type->narrow_size_type(length_type);
1635
if (narrow_length_type != length_type) {
1639
assert(narrow_length_type == TypeInt::ZERO ||
1640
(length_type->is_con() && narrow_length_type->is_con() &&
1641
(narrow_length_type->_hi <= length_type->_lo)) ||
1642
(narrow_length_type->_hi <= length_type->_hi &&
1643
narrow_length_type->_lo >= length_type->_lo),
1644
"narrow type must be narrower than length type");
1647
if (!allow_new_nodes) {
1652
InitializeNode* init = initialization();
1653
if (init != nullptr) {
1654
length = new CastIINode(init->proj_out_or_null(TypeFunc::Control), length, narrow_length_type);
1663
uint LockNode::size_of() const { return sizeof(*this); }
1792
static Node *next_control(Node *ctrl) {
1793
if (ctrl == nullptr)
1796
if (ctrl->is_Region()) {
1797
RegionNode *r = ctrl->as_Region();
1798
Node *n = r->is_copy();
1803
} else if (ctrl->is_Proj()) {
1804
Node *in0 = ctrl->in(0);
1805
if (in0->is_AbstractLock() && in0->as_AbstractLock()->is_eliminated()) {
1820
bool AbstractLockNode::find_matching_unlock(const Node* ctrl, LockNode* lock,
1821
GrowableArray<AbstractLockNode*> &lock_ops) {
1822
ProjNode *ctrl_proj = (ctrl->is_Proj()) ? ctrl->as_Proj() : nullptr;
1823
if (ctrl_proj != nullptr && ctrl_proj->_con == TypeFunc::Control) {
1824
Node *n = ctrl_proj->in(0);
1825
if (n != nullptr && n->is_Unlock()) {
1826
UnlockNode *unlock = n->as_Unlock();
1827
BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
1828
Node* lock_obj = bs->step_over_gc_barrier(lock->obj_node());
1829
Node* unlock_obj = bs->step_over_gc_barrier(unlock->obj_node());
1830
if (lock_obj->eqv_uncast(unlock_obj) &&
1831
BoxLockNode::same_slot(lock->box_node(), unlock->box_node()) &&
1832
!unlock->is_eliminated()) {
1833
lock_ops.append(unlock);
1844
LockNode *AbstractLockNode::find_matching_lock(UnlockNode* unlock) {
1845
LockNode *lock_result = nullptr;
1847
Node *ctrl = next_control(unlock->in(0));
1849
assert(ctrl != nullptr, "invalid control graph");
1850
assert(!ctrl->is_Start(), "missing lock for unlock");
1851
if (ctrl->is_top()) break;
1852
if (ctrl->is_Proj()) ctrl = ctrl->in(0);
1853
if (ctrl->is_SafePoint()) {
1855
} else if (ctrl->is_Region()) {
1857
if (ctrl->req() == 3 && ctrl->in(1) != nullptr && ctrl->in(2) != nullptr) {
1858
Node *in1 = next_control(ctrl->in(1));
1859
Node *in2 = next_control(ctrl->in(2));
1860
if (((in1->is_IfTrue() && in2->is_IfFalse()) ||
1861
(in2->is_IfTrue() && in1->is_IfFalse())) && (in1->in(0) == in2->in(0))) {
1862
ctrl = next_control(in1->in(0)->in(0));
1870
ctrl = next_control(ctrl->in(0));
1873
if (ctrl->is_Lock()) {
1874
LockNode *lock = ctrl->as_Lock();
1875
BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
1876
Node* lock_obj = bs->step_over_gc_barrier(lock->obj_node());
1877
Node* unlock_obj = bs->step_over_gc_barrier(unlock->obj_node());
1878
if (lock_obj->eqv_uncast(unlock_obj) &&
1879
BoxLockNode::same_slot(lock->box_node(), unlock->box_node())) {
1888
bool AbstractLockNode::find_lock_and_unlock_through_if(Node* node, LockNode* lock,
1889
GrowableArray<AbstractLockNode*> &lock_ops) {
1890
Node* if_node = node->in(0);
1891
bool if_true = node->is_IfTrue();
1893
if (if_node->is_If() && if_node->outcnt() == 2 && (if_true || node->is_IfFalse())) {
1894
Node *lock_ctrl = next_control(if_node->in(0));
1895
if (find_matching_unlock(lock_ctrl, lock, lock_ops)) {
1896
Node* lock1_node = nullptr;
1897
ProjNode* proj = if_node->as_If()->proj_out(!if_true);
1899
if (proj->is_IfFalse() && proj->outcnt() == 1) {
1900
lock1_node = proj->unique_out();
1903
if (proj->is_IfTrue() && proj->outcnt() == 1) {
1904
lock1_node = proj->unique_out();
1907
if (lock1_node != nullptr && lock1_node->is_Lock()) {
1908
LockNode *lock1 = lock1_node->as_Lock();
1909
BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
1910
Node* lock_obj = bs->step_over_gc_barrier(lock->obj_node());
1911
Node* lock1_obj = bs->step_over_gc_barrier(lock1->obj_node());
1912
if (lock_obj->eqv_uncast(lock1_obj) &&
1913
BoxLockNode::same_slot(lock->box_node(), lock1->box_node()) &&
1914
!lock1->is_eliminated()) {
1915
lock_ops.append(lock1);
1922
lock_ops.trunc_to(0);
1926
bool AbstractLockNode::find_unlocks_for_region(const RegionNode* region, LockNode* lock,
1927
GrowableArray<AbstractLockNode*> &lock_ops) {
1930
for (int i = 1; i < (int)region->req(); i++) {
1931
Node *in_node = next_control(region->in(i));
1932
if (in_node != nullptr) {
1933
if (find_matching_unlock(in_node, lock, lock_ops)) {
1936
} else if (find_lock_and_unlock_through_if(in_node, lock, lock_ops)) {
1943
lock_ops.trunc_to(0);
1952
bool AbstractLockNode::is_balanced() {
1953
Node* obj = obj_node();
1954
for (uint j = 0; j < obj->outcnt(); j++) {
1955
Node* n = obj->raw_out(j);
1956
if (n->is_AbstractLock() &&
1957
n->as_AbstractLock()->obj_node()->eqv_uncast(obj)) {
1958
BoxLockNode* n_box = n->as_AbstractLock()->box_node()->as_BoxLock();
1959
if (n_box->is_unbalanced()) {
1967
const char* AbstractLockNode::_kind_names[] = {"Regular", "NonEscObj", "Coarsened", "Nested"};
1969
const char * AbstractLockNode::kind_as_string() const {
1970
return _kind_names[_kind];
1977
void AbstractLockNode::create_lock_counter(JVMState* state) {
1978
_counter = OptoRuntime::new_named_counter(state, NamedCounter::LockCounter);
1981
void AbstractLockNode::set_eliminated_lock_counter() {
1986
_counter->set_tag(NamedCounter::EliminatedLockCounter);
1990
void AbstractLockNode::dump_spec(outputStream* st) const {
1991
st->print("%s ", _kind_names[_kind]);
1992
CallNode::dump_spec(st);
1995
void AbstractLockNode::dump_compact_spec(outputStream* st) const {
1996
st->print("%s", _kind_names[_kind]);
2001
Node *LockNode::Ideal(PhaseGVN *phase, bool can_reshape) {
2004
Node *result = SafePointNode::Ideal(phase, can_reshape);
2005
if (result != nullptr) return result;
2007
if (in(0) && in(0)->is_top()) return nullptr;
2014
if (can_reshape && EliminateLocks && !is_non_esc_obj()) {
2018
ConnectionGraph *cgr = phase->C->congraph();
2019
if (cgr != nullptr && cgr->can_eliminate_lock(this)) {
2020
assert(!is_eliminated() || is_coarsened(), "sanity");
2025
this->log_lock_optimization(phase->C,"eliminate_lock_set_non_esc1");
2027
this->set_non_esc_obj();
2031
if (!phase->C->do_locks_coarsening()) {
2037
PhaseIterGVN* iter = phase->is_IterGVN();
2038
if (iter != nullptr && !is_eliminated()) {
2040
GrowableArray<AbstractLockNode*> lock_ops;
2042
Node *ctrl = next_control(in(0));
2045
if (find_matching_unlock(ctrl, this, lock_ops)) {
2049
} else if (ctrl->is_Region() ) {
2050
if (find_unlocks_for_region(ctrl->as_Region(), this, lock_ops)) {
2058
if (find_lock_and_unlock_through_if(ctrl, this, lock_ops)) {
2063
if (lock_ops.length() > 0) {
2065
lock_ops.append(this);
2068
if (PrintEliminateLocks) {
2072
tty->print_cr("=== Locks coarsening ===");
2073
tty->print("Obj: ");
2076
for (int i = 0; i < lock_ops.length(); i++) {
2077
AbstractLockNode* lock = lock_ops.at(i);
2078
if (lock->Opcode() == Op_Lock)
2083
tty->print("Box %d: ", i);
2085
tty->print(" %d: ", i);
2089
tty->print_cr("=== Coarsened %d unlocks and %d locks", unlocks, locks);
2095
for (int i = 0; i < lock_ops.length(); i++) {
2096
AbstractLockNode* lock = lock_ops.at(i);
2100
lock->log_lock_optimization(phase->C, "eliminate_lock_set_coarsened");
2102
lock->set_coarsened();
2105
phase->C->add_coarsened_locks(lock_ops);
2106
} else if (ctrl->is_Region() &&
2107
iter->_worklist.member(ctrl)) {
2112
iter->_worklist.push(this);
2121
bool LockNode::is_nested_lock_region() {
2122
return is_nested_lock_region(nullptr);
2126
bool LockNode::is_nested_lock_region(Compile * c) {
2127
BoxLockNode* box = box_node()->as_BoxLock();
2128
int stk_slot = box->stack_slot();
2129
if (stk_slot <= 0) {
2131
this->log_lock_optimization(c, "eliminate_lock_INLR_1");
2137
Node* obj = obj_node();
2138
LockNode* unique_lock = nullptr;
2139
Node* bad_lock = nullptr;
2140
if (!box->is_simple_lock_region(&unique_lock, obj, &bad_lock)) {
2142
this->log_lock_optimization(c, "eliminate_lock_INLR_2a", bad_lock);
2146
if (unique_lock != this) {
2148
this->log_lock_optimization(c, "eliminate_lock_INLR_2b", (unique_lock != nullptr ? unique_lock : bad_lock));
2149
if (PrintEliminateLocks && Verbose) {
2150
tty->print_cr("=============== unique_lock != this ============");
2151
tty->print(" this: ");
2153
tty->print(" box: ");
2155
tty->print(" obj: ");
2157
if (unique_lock != nullptr) {
2158
tty->print(" unique_lock: ");
2159
unique_lock->dump();
2161
if (bad_lock != nullptr) {
2162
tty->print(" bad_lock: ");
2165
tty->print_cr("===============");
2171
BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
2172
obj = bs->step_over_gc_barrier(obj);
2174
SafePointNode* sfn = this->as_SafePoint();
2175
JVMState* youngest_jvms = sfn->jvms();
2176
int max_depth = youngest_jvms->depth();
2177
for (int depth = 1; depth <= max_depth; depth++) {
2178
JVMState* jvms = youngest_jvms->of_depth(depth);
2179
int num_mon = jvms->nof_monitors();
2181
for (int idx = 0; idx < num_mon; idx++) {
2182
Node* obj_node = sfn->monitor_obj(jvms, idx);
2183
obj_node = bs->step_over_gc_barrier(obj_node);
2184
BoxLockNode* box_node = sfn->monitor_box(jvms, idx)->as_BoxLock();
2185
if ((box_node->stack_slot() < stk_slot) && obj_node->eqv_uncast(obj)) {
2192
this->log_lock_optimization(c, "eliminate_lock_INLR_3");
2198
uint UnlockNode::size_of() const { return sizeof(*this); }
2201
Node *UnlockNode::Ideal(PhaseGVN *phase, bool can_reshape) {
2204
Node *result = SafePointNode::Ideal(phase, can_reshape);
2205
if (result != nullptr) return result;
2207
if (in(0) && in(0)->is_top()) return nullptr;
2215
if (can_reshape && EliminateLocks && !is_non_esc_obj()) {
2219
ConnectionGraph *cgr = phase->C->congraph();
2220
if (cgr != nullptr && cgr->can_eliminate_lock(this)) {
2221
assert(!is_eliminated() || is_coarsened(), "sanity");
2226
this->log_lock_optimization(phase->C, "eliminate_lock_set_non_esc2");
2228
this->set_non_esc_obj();
2234
void AbstractLockNode::log_lock_optimization(Compile *C, const char * tag, Node* bad_lock) const {
2238
CompileLog* log = C->log();
2239
if (log != nullptr) {
2240
Node* box = box_node();
2241
Node* obj = obj_node();
2242
int box_id = box != nullptr ? box->_idx : -1;
2243
int obj_id = obj != nullptr ? obj->_idx : -1;
2245
log->begin_head("%s compile_id='%d' lock_id='%d' class='%s' kind='%s' box_id='%d' obj_id='%d' bad_id='%d'",
2246
tag, C->compile_id(), this->_idx,
2247
is_Unlock() ? "unlock" : is_Lock() ? "lock" : "?",
2248
kind_as_string(), box_id, obj_id, (bad_lock != nullptr ? bad_lock->_idx : -1));
2251
JVMState* p = is_Unlock() ? (as_Unlock()->dbg_jvms()) : jvms();
2252
while (p != nullptr) {
2253
log->elem("jvms bci='%d' method='%d'", p->bci(), log->identify(p->method()));
2260
bool CallNode::may_modify_arraycopy_helper(const TypeOopPtr* dest_t, const TypeOopPtr* t_oop, PhaseValues* phase) {
2261
if (dest_t->is_known_instance() && t_oop->is_known_instance()) {
2262
return dest_t->instance_id() == t_oop->instance_id();
2265
if (dest_t->isa_instptr() && !dest_t->is_instptr()->instance_klass()->equals(phase->C->env()->Object_klass())) {
2267
if (t_oop->isa_aryptr()) {
2270
if (!t_oop->isa_instptr()) {
2273
if (dest_t->maybe_java_subtype_of(t_oop) || t_oop->maybe_java_subtype_of(dest_t)) {
2280
if (dest_t->isa_aryptr()) {
2282
if (t_oop->isa_instptr()) {
2285
if (!t_oop->isa_aryptr()) {
2289
const Type* elem = dest_t->is_aryptr()->elem();
2290
if (elem == Type::BOTTOM) {
2295
dest_t = dest_t->add_offset(Type::OffsetBot)->is_oopptr();
2296
uint dest_alias = phase->C->get_alias_index(dest_t);
2297
uint t_oop_alias = phase->C->get_alias_index(t_oop);
2299
return dest_alias == t_oop_alias;