src/share/vm/opto/callnode.cpp

Thu, 24 May 2018 18:41:44 +0800

author
aoqi
date
Thu, 24 May 2018 18:41:44 +0800
changeset 8856
ac27a9c85bea
parent 8777
09d0d56ca735
parent 7994
04ff2f6cd0eb
child 9448
73d689add964
permissions
-rw-r--r--

Merge

aoqi@0 1 /*
drchase@7605 2 * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #include "precompiled.hpp"
drchase@7605 26 #include "compiler/compileLog.hpp"
aoqi@0 27 #include "ci/bcEscapeAnalyzer.hpp"
aoqi@0 28 #include "compiler/oopMap.hpp"
aoqi@0 29 #include "opto/callGenerator.hpp"
aoqi@0 30 #include "opto/callnode.hpp"
aoqi@0 31 #include "opto/escape.hpp"
aoqi@0 32 #include "opto/locknode.hpp"
aoqi@0 33 #include "opto/machnode.hpp"
aoqi@0 34 #include "opto/matcher.hpp"
aoqi@0 35 #include "opto/parse.hpp"
aoqi@0 36 #include "opto/regalloc.hpp"
aoqi@0 37 #include "opto/regmask.hpp"
aoqi@0 38 #include "opto/rootnode.hpp"
aoqi@0 39 #include "opto/runtime.hpp"
aoqi@0 40
aoqi@0 41 // Portions of code courtesy of Clifford Click
aoqi@0 42
aoqi@0 43 // Optimization - Graph Style
aoqi@0 44
aoqi@0 45 //=============================================================================
aoqi@0 46 uint StartNode::size_of() const { return sizeof(*this); }
aoqi@0 47 uint StartNode::cmp( const Node &n ) const
aoqi@0 48 { return _domain == ((StartNode&)n)._domain; }
aoqi@0 49 const Type *StartNode::bottom_type() const { return _domain; }
aoqi@0 50 const Type *StartNode::Value(PhaseTransform *phase) const { return _domain; }
aoqi@0 51 #ifndef PRODUCT
aoqi@0 52 void StartNode::dump_spec(outputStream *st) const { st->print(" #"); _domain->dump_on(st);}
aoqi@0 53 #endif
aoqi@0 54
aoqi@0 55 //------------------------------Ideal------------------------------------------
aoqi@0 56 Node *StartNode::Ideal(PhaseGVN *phase, bool can_reshape){
aoqi@0 57 return remove_dead_region(phase, can_reshape) ? this : NULL;
aoqi@0 58 }
aoqi@0 59
aoqi@0 60 //------------------------------calling_convention-----------------------------
aoqi@0 61 void StartNode::calling_convention( BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt ) const {
aoqi@0 62 Matcher::calling_convention( sig_bt, parm_regs, argcnt, false );
aoqi@0 63 }
aoqi@0 64
aoqi@0 65 //------------------------------Registers--------------------------------------
aoqi@0 66 const RegMask &StartNode::in_RegMask(uint) const {
aoqi@0 67 return RegMask::Empty;
aoqi@0 68 }
aoqi@0 69
aoqi@0 70 //------------------------------match------------------------------------------
aoqi@0 71 // Construct projections for incoming parameters, and their RegMask info
aoqi@0 72 Node *StartNode::match( const ProjNode *proj, const Matcher *match ) {
aoqi@0 73 switch (proj->_con) {
aoqi@0 74 case TypeFunc::Control:
aoqi@0 75 case TypeFunc::I_O:
aoqi@0 76 case TypeFunc::Memory:
aoqi@0 77 return new (match->C) MachProjNode(this,proj->_con,RegMask::Empty,MachProjNode::unmatched_proj);
aoqi@0 78 case TypeFunc::FramePtr:
aoqi@0 79 return new (match->C) MachProjNode(this,proj->_con,Matcher::c_frame_ptr_mask, Op_RegP);
aoqi@0 80 case TypeFunc::ReturnAdr:
aoqi@0 81 return new (match->C) MachProjNode(this,proj->_con,match->_return_addr_mask,Op_RegP);
aoqi@0 82 case TypeFunc::Parms:
aoqi@0 83 default: {
aoqi@0 84 uint parm_num = proj->_con - TypeFunc::Parms;
aoqi@0 85 const Type *t = _domain->field_at(proj->_con);
aoqi@0 86 if (t->base() == Type::Half) // 2nd half of Longs and Doubles
aoqi@0 87 return new (match->C) ConNode(Type::TOP);
aoqi@0 88 uint ideal_reg = t->ideal_reg();
aoqi@0 89 RegMask &rm = match->_calling_convention_mask[parm_num];
aoqi@0 90 return new (match->C) MachProjNode(this,proj->_con,rm,ideal_reg);
aoqi@0 91 }
aoqi@0 92 }
aoqi@0 93 return NULL;
aoqi@0 94 }
aoqi@0 95
aoqi@0 96 //------------------------------StartOSRNode----------------------------------
aoqi@0 97 // The method start node for an on stack replacement adapter
aoqi@0 98
aoqi@0 99 //------------------------------osr_domain-----------------------------
aoqi@0 100 const TypeTuple *StartOSRNode::osr_domain() {
aoqi@0 101 const Type **fields = TypeTuple::fields(2);
aoqi@0 102 fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM; // address of osr buffer
aoqi@0 103
aoqi@0 104 return TypeTuple::make(TypeFunc::Parms+1, fields);
aoqi@0 105 }
aoqi@0 106
aoqi@0 107 //=============================================================================
aoqi@0 108 const char * const ParmNode::names[TypeFunc::Parms+1] = {
aoqi@0 109 "Control", "I_O", "Memory", "FramePtr", "ReturnAdr", "Parms"
aoqi@0 110 };
aoqi@0 111
aoqi@0 112 #ifndef PRODUCT
aoqi@0 113 void ParmNode::dump_spec(outputStream *st) const {
aoqi@0 114 if( _con < TypeFunc::Parms ) {
aoqi@0 115 st->print("%s", names[_con]);
aoqi@0 116 } else {
aoqi@0 117 st->print("Parm%d: ",_con-TypeFunc::Parms);
aoqi@0 118 // Verbose and WizardMode dump bottom_type for all nodes
aoqi@0 119 if( !Verbose && !WizardMode ) bottom_type()->dump_on(st);
aoqi@0 120 }
aoqi@0 121 }
aoqi@0 122 #endif
aoqi@0 123
aoqi@0 124 uint ParmNode::ideal_reg() const {
aoqi@0 125 switch( _con ) {
aoqi@0 126 case TypeFunc::Control : // fall through
aoqi@0 127 case TypeFunc::I_O : // fall through
aoqi@0 128 case TypeFunc::Memory : return 0;
aoqi@0 129 case TypeFunc::FramePtr : // fall through
aoqi@0 130 case TypeFunc::ReturnAdr: return Op_RegP;
aoqi@0 131 default : assert( _con > TypeFunc::Parms, "" );
aoqi@0 132 // fall through
aoqi@0 133 case TypeFunc::Parms : {
aoqi@0 134 // Type of argument being passed
aoqi@0 135 const Type *t = in(0)->as_Start()->_domain->field_at(_con);
aoqi@0 136 return t->ideal_reg();
aoqi@0 137 }
aoqi@0 138 }
aoqi@0 139 ShouldNotReachHere();
aoqi@0 140 return 0;
aoqi@0 141 }
aoqi@0 142
aoqi@0 143 //=============================================================================
aoqi@0 144 ReturnNode::ReturnNode(uint edges, Node *cntrl, Node *i_o, Node *memory, Node *frameptr, Node *retadr ) : Node(edges) {
aoqi@0 145 init_req(TypeFunc::Control,cntrl);
aoqi@0 146 init_req(TypeFunc::I_O,i_o);
aoqi@0 147 init_req(TypeFunc::Memory,memory);
aoqi@0 148 init_req(TypeFunc::FramePtr,frameptr);
aoqi@0 149 init_req(TypeFunc::ReturnAdr,retadr);
aoqi@0 150 }
aoqi@0 151
aoqi@0 152 Node *ReturnNode::Ideal(PhaseGVN *phase, bool can_reshape){
aoqi@0 153 return remove_dead_region(phase, can_reshape) ? this : NULL;
aoqi@0 154 }
aoqi@0 155
aoqi@0 156 const Type *ReturnNode::Value( PhaseTransform *phase ) const {
aoqi@0 157 return ( phase->type(in(TypeFunc::Control)) == Type::TOP)
aoqi@0 158 ? Type::TOP
aoqi@0 159 : Type::BOTTOM;
aoqi@0 160 }
aoqi@0 161
aoqi@0 162 // Do we Match on this edge index or not? No edges on return nodes
aoqi@0 163 uint ReturnNode::match_edge(uint idx) const {
aoqi@0 164 return 0;
aoqi@0 165 }
aoqi@0 166
aoqi@0 167
aoqi@0 168 #ifndef PRODUCT
aoqi@0 169 void ReturnNode::dump_req(outputStream *st) const {
aoqi@0 170 // Dump the required inputs, enclosed in '(' and ')'
aoqi@0 171 uint i; // Exit value of loop
aoqi@0 172 for (i = 0; i < req(); i++) { // For all required inputs
aoqi@0 173 if (i == TypeFunc::Parms) st->print("returns");
aoqi@0 174 if (in(i)) st->print("%c%d ", Compile::current()->node_arena()->contains(in(i)) ? ' ' : 'o', in(i)->_idx);
aoqi@0 175 else st->print("_ ");
aoqi@0 176 }
aoqi@0 177 }
aoqi@0 178 #endif
aoqi@0 179
aoqi@0 180 //=============================================================================
aoqi@0 181 RethrowNode::RethrowNode(
aoqi@0 182 Node* cntrl,
aoqi@0 183 Node* i_o,
aoqi@0 184 Node* memory,
aoqi@0 185 Node* frameptr,
aoqi@0 186 Node* ret_adr,
aoqi@0 187 Node* exception
aoqi@0 188 ) : Node(TypeFunc::Parms + 1) {
aoqi@0 189 init_req(TypeFunc::Control , cntrl );
aoqi@0 190 init_req(TypeFunc::I_O , i_o );
aoqi@0 191 init_req(TypeFunc::Memory , memory );
aoqi@0 192 init_req(TypeFunc::FramePtr , frameptr );
aoqi@0 193 init_req(TypeFunc::ReturnAdr, ret_adr);
aoqi@0 194 init_req(TypeFunc::Parms , exception);
aoqi@0 195 }
aoqi@0 196
aoqi@0 197 Node *RethrowNode::Ideal(PhaseGVN *phase, bool can_reshape){
aoqi@0 198 return remove_dead_region(phase, can_reshape) ? this : NULL;
aoqi@0 199 }
aoqi@0 200
aoqi@0 201 const Type *RethrowNode::Value( PhaseTransform *phase ) const {
aoqi@0 202 return (phase->type(in(TypeFunc::Control)) == Type::TOP)
aoqi@0 203 ? Type::TOP
aoqi@0 204 : Type::BOTTOM;
aoqi@0 205 }
aoqi@0 206
aoqi@0 207 uint RethrowNode::match_edge(uint idx) const {
aoqi@0 208 return 0;
aoqi@0 209 }
aoqi@0 210
aoqi@0 211 #ifndef PRODUCT
aoqi@0 212 void RethrowNode::dump_req(outputStream *st) const {
aoqi@0 213 // Dump the required inputs, enclosed in '(' and ')'
aoqi@0 214 uint i; // Exit value of loop
aoqi@0 215 for (i = 0; i < req(); i++) { // For all required inputs
aoqi@0 216 if (i == TypeFunc::Parms) st->print("exception");
aoqi@0 217 if (in(i)) st->print("%c%d ", Compile::current()->node_arena()->contains(in(i)) ? ' ' : 'o', in(i)->_idx);
aoqi@0 218 else st->print("_ ");
aoqi@0 219 }
aoqi@0 220 }
aoqi@0 221 #endif
aoqi@0 222
aoqi@0 223 //=============================================================================
aoqi@0 224 // Do we Match on this edge index or not? Match only target address & method
aoqi@0 225 uint TailCallNode::match_edge(uint idx) const {
aoqi@0 226 return TypeFunc::Parms <= idx && idx <= TypeFunc::Parms+1;
aoqi@0 227 }
aoqi@0 228
aoqi@0 229 //=============================================================================
aoqi@0 230 // Do we Match on this edge index or not? Match only target address & oop
aoqi@0 231 uint TailJumpNode::match_edge(uint idx) const {
aoqi@0 232 return TypeFunc::Parms <= idx && idx <= TypeFunc::Parms+1;
aoqi@0 233 }
aoqi@0 234
aoqi@0 235 //=============================================================================
aoqi@0 236 JVMState::JVMState(ciMethod* method, JVMState* caller) :
aoqi@0 237 _method(method) {
aoqi@0 238 assert(method != NULL, "must be valid call site");
aoqi@0 239 _reexecute = Reexecute_Undefined;
aoqi@0 240 debug_only(_bci = -99); // random garbage value
aoqi@0 241 debug_only(_map = (SafePointNode*)-1);
aoqi@0 242 _caller = caller;
aoqi@0 243 _depth = 1 + (caller == NULL ? 0 : caller->depth());
aoqi@0 244 _locoff = TypeFunc::Parms;
aoqi@0 245 _stkoff = _locoff + _method->max_locals();
aoqi@0 246 _monoff = _stkoff + _method->max_stack();
aoqi@0 247 _scloff = _monoff;
aoqi@0 248 _endoff = _monoff;
aoqi@0 249 _sp = 0;
aoqi@0 250 }
aoqi@0 251 JVMState::JVMState(int stack_size) :
aoqi@0 252 _method(NULL) {
aoqi@0 253 _bci = InvocationEntryBci;
aoqi@0 254 _reexecute = Reexecute_Undefined;
aoqi@0 255 debug_only(_map = (SafePointNode*)-1);
aoqi@0 256 _caller = NULL;
aoqi@0 257 _depth = 1;
aoqi@0 258 _locoff = TypeFunc::Parms;
aoqi@0 259 _stkoff = _locoff;
aoqi@0 260 _monoff = _stkoff + stack_size;
aoqi@0 261 _scloff = _monoff;
aoqi@0 262 _endoff = _monoff;
aoqi@0 263 _sp = 0;
aoqi@0 264 }
aoqi@0 265
aoqi@0 266 //--------------------------------of_depth-------------------------------------
aoqi@0 267 JVMState* JVMState::of_depth(int d) const {
aoqi@0 268 const JVMState* jvmp = this;
aoqi@0 269 assert(0 < d && (uint)d <= depth(), "oob");
aoqi@0 270 for (int skip = depth() - d; skip > 0; skip--) {
aoqi@0 271 jvmp = jvmp->caller();
aoqi@0 272 }
aoqi@0 273 assert(jvmp->depth() == (uint)d, "found the right one");
aoqi@0 274 return (JVMState*)jvmp;
aoqi@0 275 }
aoqi@0 276
aoqi@0 277 //-----------------------------same_calls_as-----------------------------------
aoqi@0 278 bool JVMState::same_calls_as(const JVMState* that) const {
aoqi@0 279 if (this == that) return true;
aoqi@0 280 if (this->depth() != that->depth()) return false;
aoqi@0 281 const JVMState* p = this;
aoqi@0 282 const JVMState* q = that;
aoqi@0 283 for (;;) {
aoqi@0 284 if (p->_method != q->_method) return false;
aoqi@0 285 if (p->_method == NULL) return true; // bci is irrelevant
aoqi@0 286 if (p->_bci != q->_bci) return false;
aoqi@0 287 if (p->_reexecute != q->_reexecute) return false;
aoqi@0 288 p = p->caller();
aoqi@0 289 q = q->caller();
aoqi@0 290 if (p == q) return true;
aoqi@0 291 assert(p != NULL && q != NULL, "depth check ensures we don't run off end");
aoqi@0 292 }
aoqi@0 293 }
aoqi@0 294
aoqi@0 295 //------------------------------debug_start------------------------------------
aoqi@0 296 uint JVMState::debug_start() const {
aoqi@0 297 debug_only(JVMState* jvmroot = of_depth(1));
aoqi@0 298 assert(jvmroot->locoff() <= this->locoff(), "youngest JVMState must be last");
aoqi@0 299 return of_depth(1)->locoff();
aoqi@0 300 }
aoqi@0 301
aoqi@0 302 //-------------------------------debug_end-------------------------------------
aoqi@0 303 uint JVMState::debug_end() const {
aoqi@0 304 debug_only(JVMState* jvmroot = of_depth(1));
aoqi@0 305 assert(jvmroot->endoff() <= this->endoff(), "youngest JVMState must be last");
aoqi@0 306 return endoff();
aoqi@0 307 }
aoqi@0 308
aoqi@0 309 //------------------------------debug_depth------------------------------------
aoqi@0 310 uint JVMState::debug_depth() const {
aoqi@0 311 uint total = 0;
aoqi@0 312 for (const JVMState* jvmp = this; jvmp != NULL; jvmp = jvmp->caller()) {
aoqi@0 313 total += jvmp->debug_size();
aoqi@0 314 }
aoqi@0 315 return total;
aoqi@0 316 }
aoqi@0 317
aoqi@0 318 #ifndef PRODUCT
aoqi@0 319
aoqi@0 320 //------------------------------format_helper----------------------------------
aoqi@0 321 // Given an allocation (a Chaitin object) and a Node decide if the Node carries
aoqi@0 322 // any defined value or not. If it does, print out the register or constant.
aoqi@0 323 static void format_helper( PhaseRegAlloc *regalloc, outputStream* st, Node *n, const char *msg, uint i, GrowableArray<SafePointScalarObjectNode*> *scobjs ) {
aoqi@0 324 if (n == NULL) { st->print(" NULL"); return; }
aoqi@0 325 if (n->is_SafePointScalarObject()) {
aoqi@0 326 // Scalar replacement.
aoqi@0 327 SafePointScalarObjectNode* spobj = n->as_SafePointScalarObject();
aoqi@0 328 scobjs->append_if_missing(spobj);
aoqi@0 329 int sco_n = scobjs->find(spobj);
aoqi@0 330 assert(sco_n >= 0, "");
aoqi@0 331 st->print(" %s%d]=#ScObj" INT32_FORMAT, msg, i, sco_n);
aoqi@0 332 return;
aoqi@0 333 }
aoqi@0 334 if (regalloc->node_regs_max_index() > 0 &&
aoqi@0 335 OptoReg::is_valid(regalloc->get_reg_first(n))) { // Check for undefined
aoqi@0 336 char buf[50];
aoqi@0 337 regalloc->dump_register(n,buf);
aoqi@0 338 st->print(" %s%d]=%s",msg,i,buf);
aoqi@0 339 } else { // No register, but might be constant
aoqi@0 340 const Type *t = n->bottom_type();
aoqi@0 341 switch (t->base()) {
aoqi@0 342 case Type::Int:
aoqi@0 343 st->print(" %s%d]=#"INT32_FORMAT,msg,i,t->is_int()->get_con());
aoqi@0 344 break;
aoqi@0 345 case Type::AnyPtr:
aoqi@0 346 assert( t == TypePtr::NULL_PTR || n->in_dump(), "" );
aoqi@0 347 st->print(" %s%d]=#NULL",msg,i);
aoqi@0 348 break;
aoqi@0 349 case Type::AryPtr:
aoqi@0 350 case Type::InstPtr:
aoqi@0 351 st->print(" %s%d]=#Ptr" INTPTR_FORMAT,msg,i,p2i(t->isa_oopptr()->const_oop()));
aoqi@0 352 break;
aoqi@0 353 case Type::KlassPtr:
aoqi@0 354 st->print(" %s%d]=#Ptr" INTPTR_FORMAT,msg,i,p2i(t->make_ptr()->isa_klassptr()->klass()));
aoqi@0 355 break;
aoqi@0 356 case Type::MetadataPtr:
aoqi@0 357 st->print(" %s%d]=#Ptr" INTPTR_FORMAT,msg,i,p2i(t->make_ptr()->isa_metadataptr()->metadata()));
aoqi@0 358 break;
aoqi@0 359 case Type::NarrowOop:
aoqi@0 360 st->print(" %s%d]=#Ptr" INTPTR_FORMAT,msg,i,p2i(t->make_ptr()->isa_oopptr()->const_oop()));
aoqi@0 361 break;
aoqi@0 362 case Type::RawPtr:
aoqi@0 363 st->print(" %s%d]=#Raw" INTPTR_FORMAT,msg,i,p2i(t->is_rawptr()));
aoqi@0 364 break;
aoqi@0 365 case Type::DoubleCon:
aoqi@0 366 st->print(" %s%d]=#%fD",msg,i,t->is_double_constant()->_d);
aoqi@0 367 break;
aoqi@0 368 case Type::FloatCon:
aoqi@0 369 st->print(" %s%d]=#%fF",msg,i,t->is_float_constant()->_f);
aoqi@0 370 break;
aoqi@0 371 case Type::Long:
aoqi@0 372 st->print(" %s%d]=#"INT64_FORMAT,msg,i,(int64_t)(t->is_long()->get_con()));
aoqi@0 373 break;
aoqi@0 374 case Type::Half:
aoqi@0 375 case Type::Top:
aoqi@0 376 st->print(" %s%d]=_",msg,i);
aoqi@0 377 break;
aoqi@0 378 default: ShouldNotReachHere();
aoqi@0 379 }
aoqi@0 380 }
aoqi@0 381 }
aoqi@0 382
aoqi@0 383 //------------------------------format-----------------------------------------
aoqi@0 384 void JVMState::format(PhaseRegAlloc *regalloc, const Node *n, outputStream* st) const {
aoqi@0 385 st->print(" #");
aoqi@0 386 if (_method) {
aoqi@0 387 _method->print_short_name(st);
aoqi@0 388 st->print(" @ bci:%d ",_bci);
aoqi@0 389 } else {
aoqi@0 390 st->print_cr(" runtime stub ");
aoqi@0 391 return;
aoqi@0 392 }
aoqi@0 393 if (n->is_MachSafePoint()) {
aoqi@0 394 GrowableArray<SafePointScalarObjectNode*> scobjs;
aoqi@0 395 MachSafePointNode *mcall = n->as_MachSafePoint();
aoqi@0 396 uint i;
aoqi@0 397 // Print locals
aoqi@0 398 for (i = 0; i < (uint)loc_size(); i++)
aoqi@0 399 format_helper(regalloc, st, mcall->local(this, i), "L[", i, &scobjs);
aoqi@0 400 // Print stack
aoqi@0 401 for (i = 0; i < (uint)stk_size(); i++) {
aoqi@0 402 if ((uint)(_stkoff + i) >= mcall->len())
aoqi@0 403 st->print(" oob ");
aoqi@0 404 else
aoqi@0 405 format_helper(regalloc, st, mcall->stack(this, i), "STK[", i, &scobjs);
aoqi@0 406 }
aoqi@0 407 for (i = 0; (int)i < nof_monitors(); i++) {
aoqi@0 408 Node *box = mcall->monitor_box(this, i);
aoqi@0 409 Node *obj = mcall->monitor_obj(this, i);
aoqi@0 410 if (regalloc->node_regs_max_index() > 0 &&
aoqi@0 411 OptoReg::is_valid(regalloc->get_reg_first(box))) {
aoqi@0 412 box = BoxLockNode::box_node(box);
aoqi@0 413 format_helper(regalloc, st, box, "MON-BOX[", i, &scobjs);
aoqi@0 414 } else {
aoqi@0 415 OptoReg::Name box_reg = BoxLockNode::reg(box);
aoqi@0 416 st->print(" MON-BOX%d=%s+%d",
aoqi@0 417 i,
aoqi@0 418 OptoReg::regname(OptoReg::c_frame_pointer),
aoqi@0 419 regalloc->reg2offset(box_reg));
aoqi@0 420 }
aoqi@0 421 const char* obj_msg = "MON-OBJ[";
aoqi@0 422 if (EliminateLocks) {
aoqi@0 423 if (BoxLockNode::box_node(box)->is_eliminated())
aoqi@0 424 obj_msg = "MON-OBJ(LOCK ELIMINATED)[";
aoqi@0 425 }
aoqi@0 426 format_helper(regalloc, st, obj, obj_msg, i, &scobjs);
aoqi@0 427 }
aoqi@0 428
aoqi@0 429 for (i = 0; i < (uint)scobjs.length(); i++) {
aoqi@0 430 // Scalar replaced objects.
aoqi@0 431 st->cr();
aoqi@0 432 st->print(" # ScObj" INT32_FORMAT " ", i);
aoqi@0 433 SafePointScalarObjectNode* spobj = scobjs.at(i);
aoqi@0 434 ciKlass* cik = spobj->bottom_type()->is_oopptr()->klass();
aoqi@0 435 assert(cik->is_instance_klass() ||
aoqi@0 436 cik->is_array_klass(), "Not supported allocation.");
aoqi@0 437 ciInstanceKlass *iklass = NULL;
aoqi@0 438 if (cik->is_instance_klass()) {
aoqi@0 439 cik->print_name_on(st);
aoqi@0 440 iklass = cik->as_instance_klass();
aoqi@0 441 } else if (cik->is_type_array_klass()) {
aoqi@0 442 cik->as_array_klass()->base_element_type()->print_name_on(st);
aoqi@0 443 st->print("[%d]", spobj->n_fields());
aoqi@0 444 } else if (cik->is_obj_array_klass()) {
aoqi@0 445 ciKlass* cie = cik->as_obj_array_klass()->base_element_klass();
aoqi@0 446 if (cie->is_instance_klass()) {
aoqi@0 447 cie->print_name_on(st);
aoqi@0 448 } else if (cie->is_type_array_klass()) {
aoqi@0 449 cie->as_array_klass()->base_element_type()->print_name_on(st);
aoqi@0 450 } else {
aoqi@0 451 ShouldNotReachHere();
aoqi@0 452 }
aoqi@0 453 st->print("[%d]", spobj->n_fields());
aoqi@0 454 int ndim = cik->as_array_klass()->dimension() - 1;
aoqi@0 455 while (ndim-- > 0) {
aoqi@0 456 st->print("[]");
aoqi@0 457 }
aoqi@0 458 }
aoqi@0 459 st->print("={");
aoqi@0 460 uint nf = spobj->n_fields();
aoqi@0 461 if (nf > 0) {
aoqi@0 462 uint first_ind = spobj->first_index(mcall->jvms());
aoqi@0 463 Node* fld_node = mcall->in(first_ind);
aoqi@0 464 ciField* cifield;
aoqi@0 465 if (iklass != NULL) {
aoqi@0 466 st->print(" [");
aoqi@0 467 cifield = iklass->nonstatic_field_at(0);
aoqi@0 468 cifield->print_name_on(st);
aoqi@0 469 format_helper(regalloc, st, fld_node, ":", 0, &scobjs);
aoqi@0 470 } else {
aoqi@0 471 format_helper(regalloc, st, fld_node, "[", 0, &scobjs);
aoqi@0 472 }
aoqi@0 473 for (uint j = 1; j < nf; j++) {
aoqi@0 474 fld_node = mcall->in(first_ind+j);
aoqi@0 475 if (iklass != NULL) {
aoqi@0 476 st->print(", [");
aoqi@0 477 cifield = iklass->nonstatic_field_at(j);
aoqi@0 478 cifield->print_name_on(st);
aoqi@0 479 format_helper(regalloc, st, fld_node, ":", j, &scobjs);
aoqi@0 480 } else {
aoqi@0 481 format_helper(regalloc, st, fld_node, ", [", j, &scobjs);
aoqi@0 482 }
aoqi@0 483 }
aoqi@0 484 }
aoqi@0 485 st->print(" }");
aoqi@0 486 }
aoqi@0 487 }
aoqi@0 488 st->cr();
aoqi@0 489 if (caller() != NULL) caller()->format(regalloc, n, st);
aoqi@0 490 }
aoqi@0 491
aoqi@0 492
aoqi@0 493 void JVMState::dump_spec(outputStream *st) const {
aoqi@0 494 if (_method != NULL) {
aoqi@0 495 bool printed = false;
aoqi@0 496 if (!Verbose) {
aoqi@0 497 // The JVMS dumps make really, really long lines.
aoqi@0 498 // Take out the most boring parts, which are the package prefixes.
aoqi@0 499 char buf[500];
aoqi@0 500 stringStream namest(buf, sizeof(buf));
aoqi@0 501 _method->print_short_name(&namest);
aoqi@0 502 if (namest.count() < sizeof(buf)) {
aoqi@0 503 const char* name = namest.base();
aoqi@0 504 if (name[0] == ' ') ++name;
aoqi@0 505 const char* endcn = strchr(name, ':'); // end of class name
aoqi@0 506 if (endcn == NULL) endcn = strchr(name, '(');
aoqi@0 507 if (endcn == NULL) endcn = name + strlen(name);
aoqi@0 508 while (endcn > name && endcn[-1] != '.' && endcn[-1] != '/')
aoqi@0 509 --endcn;
aoqi@0 510 st->print(" %s", endcn);
aoqi@0 511 printed = true;
aoqi@0 512 }
aoqi@0 513 }
aoqi@0 514 if (!printed)
aoqi@0 515 _method->print_short_name(st);
aoqi@0 516 st->print(" @ bci:%d",_bci);
aoqi@0 517 if(_reexecute == Reexecute_True)
aoqi@0 518 st->print(" reexecute");
aoqi@0 519 } else {
aoqi@0 520 st->print(" runtime stub");
aoqi@0 521 }
aoqi@0 522 if (caller() != NULL) caller()->dump_spec(st);
aoqi@0 523 }
aoqi@0 524
aoqi@0 525
aoqi@0 526 void JVMState::dump_on(outputStream* st) const {
aoqi@0 527 bool print_map = _map && !((uintptr_t)_map & 1) &&
aoqi@0 528 ((caller() == NULL) || (caller()->map() != _map));
aoqi@0 529 if (print_map) {
aoqi@0 530 if (_map->len() > _map->req()) { // _map->has_exceptions()
aoqi@0 531 Node* ex = _map->in(_map->req()); // _map->next_exception()
aoqi@0 532 // skip the first one; it's already being printed
aoqi@0 533 while (ex != NULL && ex->len() > ex->req()) {
aoqi@0 534 ex = ex->in(ex->req()); // ex->next_exception()
aoqi@0 535 ex->dump(1);
aoqi@0 536 }
aoqi@0 537 }
aoqi@0 538 _map->dump(Verbose ? 2 : 1);
aoqi@0 539 }
aoqi@0 540 if (caller() != NULL) {
aoqi@0 541 caller()->dump_on(st);
aoqi@0 542 }
aoqi@0 543 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=",
aoqi@0 544 depth(), locoff(), stkoff(), argoff(), monoff(), scloff(), endoff(), monitor_depth(), sp(), bci(), should_reexecute()?"true":"false");
aoqi@0 545 if (_method == NULL) {
aoqi@0 546 st->print_cr("(none)");
aoqi@0 547 } else {
aoqi@0 548 _method->print_name(st);
aoqi@0 549 st->cr();
aoqi@0 550 if (bci() >= 0 && bci() < _method->code_size()) {
aoqi@0 551 st->print(" bc: ");
aoqi@0 552 _method->print_codes_on(bci(), bci()+1, st);
aoqi@0 553 }
aoqi@0 554 }
aoqi@0 555 }
aoqi@0 556
aoqi@0 557 // Extra way to dump a jvms from the debugger,
aoqi@0 558 // to avoid a bug with C++ member function calls.
aoqi@0 559 void dump_jvms(JVMState* jvms) {
aoqi@0 560 jvms->dump();
aoqi@0 561 }
aoqi@0 562 #endif
aoqi@0 563
aoqi@0 564 //--------------------------clone_shallow--------------------------------------
aoqi@0 565 JVMState* JVMState::clone_shallow(Compile* C) const {
aoqi@0 566 JVMState* n = has_method() ? new (C) JVMState(_method, _caller) : new (C) JVMState(0);
aoqi@0 567 n->set_bci(_bci);
aoqi@0 568 n->_reexecute = _reexecute;
aoqi@0 569 n->set_locoff(_locoff);
aoqi@0 570 n->set_stkoff(_stkoff);
aoqi@0 571 n->set_monoff(_monoff);
aoqi@0 572 n->set_scloff(_scloff);
aoqi@0 573 n->set_endoff(_endoff);
aoqi@0 574 n->set_sp(_sp);
aoqi@0 575 n->set_map(_map);
aoqi@0 576 return n;
aoqi@0 577 }
aoqi@0 578
aoqi@0 579 //---------------------------clone_deep----------------------------------------
aoqi@0 580 JVMState* JVMState::clone_deep(Compile* C) const {
aoqi@0 581 JVMState* n = clone_shallow(C);
aoqi@0 582 for (JVMState* p = n; p->_caller != NULL; p = p->_caller) {
aoqi@0 583 p->_caller = p->_caller->clone_shallow(C);
aoqi@0 584 }
aoqi@0 585 assert(n->depth() == depth(), "sanity");
aoqi@0 586 assert(n->debug_depth() == debug_depth(), "sanity");
aoqi@0 587 return n;
aoqi@0 588 }
aoqi@0 589
aoqi@0 590 /**
aoqi@0 591 * Reset map for all callers
aoqi@0 592 */
aoqi@0 593 void JVMState::set_map_deep(SafePointNode* map) {
aoqi@0 594 for (JVMState* p = this; p->_caller != NULL; p = p->_caller) {
aoqi@0 595 p->set_map(map);
aoqi@0 596 }
aoqi@0 597 }
aoqi@0 598
aoqi@0 599 // Adapt offsets in in-array after adding or removing an edge.
aoqi@0 600 // Prerequisite is that the JVMState is used by only one node.
aoqi@0 601 void JVMState::adapt_position(int delta) {
aoqi@0 602 for (JVMState* jvms = this; jvms != NULL; jvms = jvms->caller()) {
aoqi@0 603 jvms->set_locoff(jvms->locoff() + delta);
aoqi@0 604 jvms->set_stkoff(jvms->stkoff() + delta);
aoqi@0 605 jvms->set_monoff(jvms->monoff() + delta);
aoqi@0 606 jvms->set_scloff(jvms->scloff() + delta);
aoqi@0 607 jvms->set_endoff(jvms->endoff() + delta);
aoqi@0 608 }
aoqi@0 609 }
aoqi@0 610
aoqi@0 611 // Mirror the stack size calculation in the deopt code
aoqi@0 612 // How much stack space would we need at this point in the program in
aoqi@0 613 // case of deoptimization?
aoqi@0 614 int JVMState::interpreter_frame_size() const {
aoqi@0 615 const JVMState* jvms = this;
aoqi@0 616 int size = 0;
aoqi@0 617 int callee_parameters = 0;
aoqi@0 618 int callee_locals = 0;
aoqi@0 619 int extra_args = method()->max_stack() - stk_size();
aoqi@0 620
aoqi@0 621 while (jvms != NULL) {
aoqi@0 622 int locks = jvms->nof_monitors();
aoqi@0 623 int temps = jvms->stk_size();
aoqi@0 624 bool is_top_frame = (jvms == this);
aoqi@0 625 ciMethod* method = jvms->method();
aoqi@0 626
aoqi@0 627 int frame_size = BytesPerWord * Interpreter::size_activation(method->max_stack(),
aoqi@0 628 temps + callee_parameters,
aoqi@0 629 extra_args,
aoqi@0 630 locks,
aoqi@0 631 callee_parameters,
aoqi@0 632 callee_locals,
aoqi@0 633 is_top_frame);
aoqi@0 634 size += frame_size;
aoqi@0 635
aoqi@0 636 callee_parameters = method->size_of_parameters();
aoqi@0 637 callee_locals = method->max_locals();
aoqi@0 638 extra_args = 0;
aoqi@0 639 jvms = jvms->caller();
aoqi@0 640 }
aoqi@0 641 return size + Deoptimization::last_frame_adjust(0, callee_locals) * BytesPerWord;
aoqi@0 642 }
aoqi@0 643
aoqi@0 644 //=============================================================================
aoqi@0 645 uint CallNode::cmp( const Node &n ) const
aoqi@0 646 { return _tf == ((CallNode&)n)._tf && _jvms == ((CallNode&)n)._jvms; }
aoqi@0 647 #ifndef PRODUCT
aoqi@0 648 void CallNode::dump_req(outputStream *st) const {
aoqi@0 649 // Dump the required inputs, enclosed in '(' and ')'
aoqi@0 650 uint i; // Exit value of loop
aoqi@0 651 for (i = 0; i < req(); i++) { // For all required inputs
aoqi@0 652 if (i == TypeFunc::Parms) st->print("(");
aoqi@0 653 if (in(i)) st->print("%c%d ", Compile::current()->node_arena()->contains(in(i)) ? ' ' : 'o', in(i)->_idx);
aoqi@0 654 else st->print("_ ");
aoqi@0 655 }
aoqi@0 656 st->print(")");
aoqi@0 657 }
aoqi@0 658
aoqi@0 659 void CallNode::dump_spec(outputStream *st) const {
aoqi@0 660 st->print(" ");
aoqi@0 661 tf()->dump_on(st);
aoqi@0 662 if (_cnt != COUNT_UNKNOWN) st->print(" C=%f",_cnt);
aoqi@0 663 if (jvms() != NULL) jvms()->dump_spec(st);
aoqi@0 664 }
aoqi@0 665 #endif
aoqi@0 666
aoqi@0 667 const Type *CallNode::bottom_type() const { return tf()->range(); }
aoqi@0 668 const Type *CallNode::Value(PhaseTransform *phase) const {
aoqi@0 669 if (phase->type(in(0)) == Type::TOP) return Type::TOP;
aoqi@0 670 return tf()->range();
aoqi@0 671 }
aoqi@0 672
aoqi@0 673 //------------------------------calling_convention-----------------------------
aoqi@0 674 void CallNode::calling_convention( BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt ) const {
aoqi@0 675 // Use the standard compiler calling convention
aoqi@0 676 Matcher::calling_convention( sig_bt, parm_regs, argcnt, true );
aoqi@0 677 }
aoqi@0 678
aoqi@0 679
aoqi@0 680 //------------------------------match------------------------------------------
aoqi@0 681 // Construct projections for control, I/O, memory-fields, ..., and
aoqi@0 682 // return result(s) along with their RegMask info
aoqi@0 683 Node *CallNode::match( const ProjNode *proj, const Matcher *match ) {
aoqi@0 684 switch (proj->_con) {
aoqi@0 685 case TypeFunc::Control:
aoqi@0 686 case TypeFunc::I_O:
aoqi@0 687 case TypeFunc::Memory:
aoqi@0 688 return new (match->C) MachProjNode(this,proj->_con,RegMask::Empty,MachProjNode::unmatched_proj);
aoqi@0 689
aoqi@0 690 case TypeFunc::Parms+1: // For LONG & DOUBLE returns
aoqi@0 691 assert(tf()->_range->field_at(TypeFunc::Parms+1) == Type::HALF, "");
aoqi@0 692 // 2nd half of doubles and longs
aoqi@0 693 return new (match->C) MachProjNode(this,proj->_con, RegMask::Empty, (uint)OptoReg::Bad);
aoqi@0 694
aoqi@0 695 case TypeFunc::Parms: { // Normal returns
aoqi@0 696 uint ideal_reg = tf()->range()->field_at(TypeFunc::Parms)->ideal_reg();
aoqi@0 697 OptoRegPair regs = is_CallRuntime()
aoqi@0 698 ? match->c_return_value(ideal_reg,true) // Calls into C runtime
aoqi@0 699 : match-> return_value(ideal_reg,true); // Calls into compiled Java code
aoqi@0 700 RegMask rm = RegMask(regs.first());
aoqi@0 701 if( OptoReg::is_valid(regs.second()) )
aoqi@0 702 rm.Insert( regs.second() );
aoqi@0 703 return new (match->C) MachProjNode(this,proj->_con,rm,ideal_reg);
aoqi@0 704 }
aoqi@0 705
aoqi@0 706 case TypeFunc::ReturnAdr:
aoqi@0 707 case TypeFunc::FramePtr:
aoqi@0 708 default:
aoqi@0 709 ShouldNotReachHere();
aoqi@0 710 }
aoqi@0 711 return NULL;
aoqi@0 712 }
aoqi@0 713
aoqi@0 714 // Do we Match on this edge index or not? Match no edges
aoqi@0 715 uint CallNode::match_edge(uint idx) const {
aoqi@0 716 return 0;
aoqi@0 717 }
aoqi@0 718
aoqi@0 719 //
aoqi@0 720 // Determine whether the call could modify the field of the specified
aoqi@0 721 // instance at the specified offset.
aoqi@0 722 //
aoqi@0 723 bool CallNode::may_modify(const TypeOopPtr *t_oop, PhaseTransform *phase) {
aoqi@0 724 assert((t_oop != NULL), "sanity");
aoqi@0 725 if (t_oop->is_known_instance()) {
aoqi@0 726 // The instance_id is set only for scalar-replaceable allocations which
aoqi@0 727 // are not passed as arguments according to Escape Analysis.
aoqi@0 728 return false;
aoqi@0 729 }
aoqi@0 730 if (t_oop->is_ptr_to_boxed_value()) {
aoqi@0 731 ciKlass* boxing_klass = t_oop->klass();
aoqi@0 732 if (is_CallStaticJava() && as_CallStaticJava()->is_boxing_method()) {
aoqi@0 733 // Skip unrelated boxing methods.
aoqi@0 734 Node* proj = proj_out(TypeFunc::Parms);
aoqi@0 735 if ((proj == NULL) || (phase->type(proj)->is_instptr()->klass() != boxing_klass)) {
aoqi@0 736 return false;
aoqi@0 737 }
aoqi@0 738 }
aoqi@0 739 if (is_CallJava() && as_CallJava()->method() != NULL) {
aoqi@0 740 ciMethod* meth = as_CallJava()->method();
aoqi@0 741 if (meth->is_accessor()) {
aoqi@0 742 return false;
aoqi@0 743 }
aoqi@0 744 // May modify (by reflection) if an boxing object is passed
aoqi@0 745 // as argument or returned.
rraghavan@8777 746 Node* proj = returns_pointer() ? proj_out(TypeFunc::Parms) : NULL;
rraghavan@8777 747 if (proj != NULL) {
aoqi@0 748 const TypeInstPtr* inst_t = phase->type(proj)->isa_instptr();
aoqi@0 749 if ((inst_t != NULL) && (!inst_t->klass_is_exact() ||
aoqi@0 750 (inst_t->klass() == boxing_klass))) {
aoqi@0 751 return true;
aoqi@0 752 }
aoqi@0 753 }
aoqi@0 754 const TypeTuple* d = tf()->domain();
aoqi@0 755 for (uint i = TypeFunc::Parms; i < d->cnt(); i++) {
aoqi@0 756 const TypeInstPtr* inst_t = d->field_at(i)->isa_instptr();
aoqi@0 757 if ((inst_t != NULL) && (!inst_t->klass_is_exact() ||
aoqi@0 758 (inst_t->klass() == boxing_klass))) {
aoqi@0 759 return true;
aoqi@0 760 }
aoqi@0 761 }
aoqi@0 762 return false;
aoqi@0 763 }
aoqi@0 764 }
aoqi@0 765 return true;
aoqi@0 766 }
aoqi@0 767
aoqi@0 768 // Does this call have a direct reference to n other than debug information?
aoqi@0 769 bool CallNode::has_non_debug_use(Node *n) {
aoqi@0 770 const TypeTuple * d = tf()->domain();
aoqi@0 771 for (uint i = TypeFunc::Parms; i < d->cnt(); i++) {
aoqi@0 772 Node *arg = in(i);
aoqi@0 773 if (arg == n) {
aoqi@0 774 return true;
aoqi@0 775 }
aoqi@0 776 }
aoqi@0 777 return false;
aoqi@0 778 }
aoqi@0 779
aoqi@0 780 // Returns the unique CheckCastPP of a call
roland@7166 781 // or 'this' if there are several CheckCastPP or unexpected uses
aoqi@0 782 // or returns NULL if there is no one.
aoqi@0 783 Node *CallNode::result_cast() {
aoqi@0 784 Node *cast = NULL;
aoqi@0 785
aoqi@0 786 Node *p = proj_out(TypeFunc::Parms);
aoqi@0 787 if (p == NULL)
aoqi@0 788 return NULL;
aoqi@0 789
aoqi@0 790 for (DUIterator_Fast imax, i = p->fast_outs(imax); i < imax; i++) {
aoqi@0 791 Node *use = p->fast_out(i);
aoqi@0 792 if (use->is_CheckCastPP()) {
aoqi@0 793 if (cast != NULL) {
aoqi@0 794 return this; // more than 1 CheckCastPP
aoqi@0 795 }
aoqi@0 796 cast = use;
roland@7166 797 } else if (!use->is_Initialize() &&
roland@7166 798 !use->is_AddP()) {
roland@7166 799 // Expected uses are restricted to a CheckCastPP, an Initialize
roland@7166 800 // node, and AddP nodes. If we encounter any other use (a Phi
roland@7166 801 // node can be seen in rare cases) return this to prevent
roland@7166 802 // incorrect optimizations.
roland@7166 803 return this;
aoqi@0 804 }
aoqi@0 805 }
aoqi@0 806 return cast;
aoqi@0 807 }
aoqi@0 808
aoqi@0 809
aoqi@0 810 void CallNode::extract_projections(CallProjections* projs, bool separate_io_proj) {
aoqi@0 811 projs->fallthrough_proj = NULL;
aoqi@0 812 projs->fallthrough_catchproj = NULL;
aoqi@0 813 projs->fallthrough_ioproj = NULL;
aoqi@0 814 projs->catchall_ioproj = NULL;
aoqi@0 815 projs->catchall_catchproj = NULL;
aoqi@0 816 projs->fallthrough_memproj = NULL;
aoqi@0 817 projs->catchall_memproj = NULL;
aoqi@0 818 projs->resproj = NULL;
aoqi@0 819 projs->exobj = NULL;
aoqi@0 820
aoqi@0 821 for (DUIterator_Fast imax, i = fast_outs(imax); i < imax; i++) {
aoqi@0 822 ProjNode *pn = fast_out(i)->as_Proj();
aoqi@0 823 if (pn->outcnt() == 0) continue;
aoqi@0 824 switch (pn->_con) {
aoqi@0 825 case TypeFunc::Control:
aoqi@0 826 {
aoqi@0 827 // For Control (fallthrough) and I_O (catch_all_index) we have CatchProj -> Catch -> Proj
aoqi@0 828 projs->fallthrough_proj = pn;
aoqi@0 829 DUIterator_Fast jmax, j = pn->fast_outs(jmax);
aoqi@0 830 const Node *cn = pn->fast_out(j);
aoqi@0 831 if (cn->is_Catch()) {
aoqi@0 832 ProjNode *cpn = NULL;
aoqi@0 833 for (DUIterator_Fast kmax, k = cn->fast_outs(kmax); k < kmax; k++) {
aoqi@0 834 cpn = cn->fast_out(k)->as_Proj();
aoqi@0 835 assert(cpn->is_CatchProj(), "must be a CatchProjNode");
aoqi@0 836 if (cpn->_con == CatchProjNode::fall_through_index)
aoqi@0 837 projs->fallthrough_catchproj = cpn;
aoqi@0 838 else {
aoqi@0 839 assert(cpn->_con == CatchProjNode::catch_all_index, "must be correct index.");
aoqi@0 840 projs->catchall_catchproj = cpn;
aoqi@0 841 }
aoqi@0 842 }
aoqi@0 843 }
aoqi@0 844 break;
aoqi@0 845 }
aoqi@0 846 case TypeFunc::I_O:
aoqi@0 847 if (pn->_is_io_use)
aoqi@0 848 projs->catchall_ioproj = pn;
aoqi@0 849 else
aoqi@0 850 projs->fallthrough_ioproj = pn;
aoqi@0 851 for (DUIterator j = pn->outs(); pn->has_out(j); j++) {
aoqi@0 852 Node* e = pn->out(j);
aoqi@0 853 if (e->Opcode() == Op_CreateEx && e->in(0)->is_CatchProj() && e->outcnt() > 0) {
aoqi@0 854 assert(projs->exobj == NULL, "only one");
aoqi@0 855 projs->exobj = e;
aoqi@0 856 }
aoqi@0 857 }
aoqi@0 858 break;
aoqi@0 859 case TypeFunc::Memory:
aoqi@0 860 if (pn->_is_io_use)
aoqi@0 861 projs->catchall_memproj = pn;
aoqi@0 862 else
aoqi@0 863 projs->fallthrough_memproj = pn;
aoqi@0 864 break;
aoqi@0 865 case TypeFunc::Parms:
aoqi@0 866 projs->resproj = pn;
aoqi@0 867 break;
aoqi@0 868 default:
aoqi@0 869 assert(false, "unexpected projection from allocation node.");
aoqi@0 870 }
aoqi@0 871 }
aoqi@0 872
aoqi@0 873 // The resproj may not exist because the result couuld be ignored
aoqi@0 874 // and the exception object may not exist if an exception handler
aoqi@0 875 // swallows the exception but all the other must exist and be found.
aoqi@0 876 assert(projs->fallthrough_proj != NULL, "must be found");
aoqi@0 877 assert(Compile::current()->inlining_incrementally() || projs->fallthrough_catchproj != NULL, "must be found");
aoqi@0 878 assert(Compile::current()->inlining_incrementally() || projs->fallthrough_memproj != NULL, "must be found");
aoqi@0 879 assert(Compile::current()->inlining_incrementally() || projs->fallthrough_ioproj != NULL, "must be found");
aoqi@0 880 assert(Compile::current()->inlining_incrementally() || projs->catchall_catchproj != NULL, "must be found");
aoqi@0 881 if (separate_io_proj) {
aoqi@0 882 assert(Compile::current()->inlining_incrementally() || projs->catchall_memproj != NULL, "must be found");
aoqi@0 883 assert(Compile::current()->inlining_incrementally() || projs->catchall_ioproj != NULL, "must be found");
aoqi@0 884 }
aoqi@0 885 }
aoqi@0 886
aoqi@0 887 Node *CallNode::Ideal(PhaseGVN *phase, bool can_reshape) {
aoqi@0 888 CallGenerator* cg = generator();
aoqi@0 889 if (can_reshape && cg != NULL && cg->is_mh_late_inline() && !cg->already_attempted()) {
aoqi@0 890 // Check whether this MH handle call becomes a candidate for inlining
aoqi@0 891 ciMethod* callee = cg->method();
aoqi@0 892 vmIntrinsics::ID iid = callee->intrinsic_id();
aoqi@0 893 if (iid == vmIntrinsics::_invokeBasic) {
aoqi@0 894 if (in(TypeFunc::Parms)->Opcode() == Op_ConP) {
aoqi@0 895 phase->C->prepend_late_inline(cg);
aoqi@0 896 set_generator(NULL);
aoqi@0 897 }
aoqi@0 898 } else {
aoqi@0 899 assert(callee->has_member_arg(), "wrong type of call?");
aoqi@0 900 if (in(TypeFunc::Parms + callee->arg_size() - 1)->Opcode() == Op_ConP) {
aoqi@0 901 phase->C->prepend_late_inline(cg);
aoqi@0 902 set_generator(NULL);
aoqi@0 903 }
aoqi@0 904 }
aoqi@0 905 }
aoqi@0 906 return SafePointNode::Ideal(phase, can_reshape);
aoqi@0 907 }
aoqi@0 908
aoqi@0 909
aoqi@0 910 //=============================================================================
aoqi@0 911 uint CallJavaNode::size_of() const { return sizeof(*this); }
aoqi@0 912 uint CallJavaNode::cmp( const Node &n ) const {
aoqi@0 913 CallJavaNode &call = (CallJavaNode&)n;
aoqi@0 914 return CallNode::cmp(call) && _method == call._method;
aoqi@0 915 }
aoqi@0 916 #ifndef PRODUCT
aoqi@0 917 void CallJavaNode::dump_spec(outputStream *st) const {
aoqi@0 918 if( _method ) _method->print_short_name(st);
aoqi@0 919 CallNode::dump_spec(st);
aoqi@0 920 }
aoqi@0 921 #endif
aoqi@0 922
aoqi@0 923 //=============================================================================
aoqi@0 924 uint CallStaticJavaNode::size_of() const { return sizeof(*this); }
aoqi@0 925 uint CallStaticJavaNode::cmp( const Node &n ) const {
aoqi@0 926 CallStaticJavaNode &call = (CallStaticJavaNode&)n;
aoqi@0 927 return CallJavaNode::cmp(call);
aoqi@0 928 }
aoqi@0 929
aoqi@0 930 //----------------------------uncommon_trap_request----------------------------
aoqi@0 931 // If this is an uncommon trap, return the request code, else zero.
aoqi@0 932 int CallStaticJavaNode::uncommon_trap_request() const {
aoqi@0 933 if (_name != NULL && !strcmp(_name, "uncommon_trap")) {
aoqi@0 934 return extract_uncommon_trap_request(this);
aoqi@0 935 }
aoqi@0 936 return 0;
aoqi@0 937 }
aoqi@0 938 int CallStaticJavaNode::extract_uncommon_trap_request(const Node* call) {
aoqi@0 939 #ifndef PRODUCT
aoqi@0 940 if (!(call->req() > TypeFunc::Parms &&
aoqi@0 941 call->in(TypeFunc::Parms) != NULL &&
aoqi@0 942 call->in(TypeFunc::Parms)->is_Con())) {
aoqi@0 943 assert(in_dump() != 0, "OK if dumping");
aoqi@0 944 tty->print("[bad uncommon trap]");
aoqi@0 945 return 0;
aoqi@0 946 }
aoqi@0 947 #endif
aoqi@0 948 return call->in(TypeFunc::Parms)->bottom_type()->is_int()->get_con();
aoqi@0 949 }
aoqi@0 950
aoqi@0 951 #ifndef PRODUCT
aoqi@0 952 void CallStaticJavaNode::dump_spec(outputStream *st) const {
aoqi@0 953 st->print("# Static ");
aoqi@0 954 if (_name != NULL) {
aoqi@0 955 st->print("%s", _name);
aoqi@0 956 int trap_req = uncommon_trap_request();
aoqi@0 957 if (trap_req != 0) {
aoqi@0 958 char buf[100];
aoqi@0 959 st->print("(%s)",
aoqi@0 960 Deoptimization::format_trap_request(buf, sizeof(buf),
aoqi@0 961 trap_req));
aoqi@0 962 }
aoqi@0 963 st->print(" ");
aoqi@0 964 }
aoqi@0 965 CallJavaNode::dump_spec(st);
aoqi@0 966 }
aoqi@0 967 #endif
aoqi@0 968
aoqi@0 969 //=============================================================================
aoqi@0 970 uint CallDynamicJavaNode::size_of() const { return sizeof(*this); }
aoqi@0 971 uint CallDynamicJavaNode::cmp( const Node &n ) const {
aoqi@0 972 CallDynamicJavaNode &call = (CallDynamicJavaNode&)n;
aoqi@0 973 return CallJavaNode::cmp(call);
aoqi@0 974 }
aoqi@0 975 #ifndef PRODUCT
aoqi@0 976 void CallDynamicJavaNode::dump_spec(outputStream *st) const {
aoqi@0 977 st->print("# Dynamic ");
aoqi@0 978 CallJavaNode::dump_spec(st);
aoqi@0 979 }
aoqi@0 980 #endif
aoqi@0 981
aoqi@0 982 //=============================================================================
aoqi@0 983 uint CallRuntimeNode::size_of() const { return sizeof(*this); }
aoqi@0 984 uint CallRuntimeNode::cmp( const Node &n ) const {
aoqi@0 985 CallRuntimeNode &call = (CallRuntimeNode&)n;
aoqi@0 986 return CallNode::cmp(call) && !strcmp(_name,call._name);
aoqi@0 987 }
aoqi@0 988 #ifndef PRODUCT
aoqi@0 989 void CallRuntimeNode::dump_spec(outputStream *st) const {
aoqi@0 990 st->print("# ");
aoqi@0 991 st->print("%s", _name);
aoqi@0 992 CallNode::dump_spec(st);
aoqi@0 993 }
aoqi@0 994 #endif
aoqi@0 995
aoqi@0 996 //------------------------------calling_convention-----------------------------
aoqi@0 997 void CallRuntimeNode::calling_convention( BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt ) const {
aoqi@0 998 Matcher::c_calling_convention( sig_bt, parm_regs, argcnt );
aoqi@0 999 }
aoqi@0 1000
aoqi@0 1001 //=============================================================================
aoqi@0 1002 //------------------------------calling_convention-----------------------------
aoqi@0 1003
aoqi@0 1004
aoqi@0 1005 //=============================================================================
aoqi@0 1006 #ifndef PRODUCT
aoqi@0 1007 void CallLeafNode::dump_spec(outputStream *st) const {
aoqi@0 1008 st->print("# ");
aoqi@0 1009 st->print("%s", _name);
aoqi@0 1010 CallNode::dump_spec(st);
aoqi@0 1011 }
aoqi@0 1012 #endif
aoqi@0 1013
aoqi@0 1014 //=============================================================================
aoqi@0 1015
aoqi@0 1016 void SafePointNode::set_local(JVMState* jvms, uint idx, Node *c) {
aoqi@0 1017 assert(verify_jvms(jvms), "jvms must match");
aoqi@0 1018 int loc = jvms->locoff() + idx;
aoqi@0 1019 if (in(loc)->is_top() && idx > 0 && !c->is_top() ) {
aoqi@0 1020 // If current local idx is top then local idx - 1 could
aoqi@0 1021 // be a long/double that needs to be killed since top could
aoqi@0 1022 // represent the 2nd half ofthe long/double.
aoqi@0 1023 uint ideal = in(loc -1)->ideal_reg();
aoqi@0 1024 if (ideal == Op_RegD || ideal == Op_RegL) {
aoqi@0 1025 // set other (low index) half to top
aoqi@0 1026 set_req(loc - 1, in(loc));
aoqi@0 1027 }
aoqi@0 1028 }
aoqi@0 1029 set_req(loc, c);
aoqi@0 1030 }
aoqi@0 1031
aoqi@0 1032 uint SafePointNode::size_of() const { return sizeof(*this); }
aoqi@0 1033 uint SafePointNode::cmp( const Node &n ) const {
aoqi@0 1034 return (&n == this); // Always fail except on self
aoqi@0 1035 }
aoqi@0 1036
aoqi@0 1037 //-------------------------set_next_exception----------------------------------
aoqi@0 1038 void SafePointNode::set_next_exception(SafePointNode* n) {
aoqi@0 1039 assert(n == NULL || n->Opcode() == Op_SafePoint, "correct value for next_exception");
aoqi@0 1040 if (len() == req()) {
aoqi@0 1041 if (n != NULL) add_prec(n);
aoqi@0 1042 } else {
aoqi@0 1043 set_prec(req(), n);
aoqi@0 1044 }
aoqi@0 1045 }
aoqi@0 1046
aoqi@0 1047
aoqi@0 1048 //----------------------------next_exception-----------------------------------
aoqi@0 1049 SafePointNode* SafePointNode::next_exception() const {
aoqi@0 1050 if (len() == req()) {
aoqi@0 1051 return NULL;
aoqi@0 1052 } else {
aoqi@0 1053 Node* n = in(req());
aoqi@0 1054 assert(n == NULL || n->Opcode() == Op_SafePoint, "no other uses of prec edges");
aoqi@0 1055 return (SafePointNode*) n;
aoqi@0 1056 }
aoqi@0 1057 }
aoqi@0 1058
aoqi@0 1059
aoqi@0 1060 //------------------------------Ideal------------------------------------------
aoqi@0 1061 // Skip over any collapsed Regions
aoqi@0 1062 Node *SafePointNode::Ideal(PhaseGVN *phase, bool can_reshape) {
aoqi@0 1063 return remove_dead_region(phase, can_reshape) ? this : NULL;
aoqi@0 1064 }
aoqi@0 1065
aoqi@0 1066 //------------------------------Identity---------------------------------------
aoqi@0 1067 // Remove obviously duplicate safepoints
aoqi@0 1068 Node *SafePointNode::Identity( PhaseTransform *phase ) {
aoqi@0 1069
aoqi@0 1070 // If you have back to back safepoints, remove one
aoqi@0 1071 if( in(TypeFunc::Control)->is_SafePoint() )
aoqi@0 1072 return in(TypeFunc::Control);
aoqi@0 1073
aoqi@0 1074 if( in(0)->is_Proj() ) {
aoqi@0 1075 Node *n0 = in(0)->in(0);
aoqi@0 1076 // Check if he is a call projection (except Leaf Call)
aoqi@0 1077 if( n0->is_Catch() ) {
aoqi@0 1078 n0 = n0->in(0)->in(0);
aoqi@0 1079 assert( n0->is_Call(), "expect a call here" );
aoqi@0 1080 }
aoqi@0 1081 if( n0->is_Call() && n0->as_Call()->guaranteed_safepoint() ) {
aoqi@0 1082 // Useless Safepoint, so remove it
aoqi@0 1083 return in(TypeFunc::Control);
aoqi@0 1084 }
aoqi@0 1085 }
aoqi@0 1086
aoqi@0 1087 return this;
aoqi@0 1088 }
aoqi@0 1089
aoqi@0 1090 //------------------------------Value------------------------------------------
aoqi@0 1091 const Type *SafePointNode::Value( PhaseTransform *phase ) const {
aoqi@0 1092 if( phase->type(in(0)) == Type::TOP ) return Type::TOP;
aoqi@0 1093 if( phase->eqv( in(0), this ) ) return Type::TOP; // Dead infinite loop
aoqi@0 1094 return Type::CONTROL;
aoqi@0 1095 }
aoqi@0 1096
aoqi@0 1097 #ifndef PRODUCT
aoqi@0 1098 void SafePointNode::dump_spec(outputStream *st) const {
aoqi@0 1099 st->print(" SafePoint ");
roland@7041 1100 _replaced_nodes.dump(st);
aoqi@0 1101 }
aoqi@0 1102 #endif
aoqi@0 1103
aoqi@0 1104 const RegMask &SafePointNode::in_RegMask(uint idx) const {
aoqi@0 1105 if( idx < TypeFunc::Parms ) return RegMask::Empty;
aoqi@0 1106 // Values outside the domain represent debug info
aoqi@0 1107 return *(Compile::current()->matcher()->idealreg2debugmask[in(idx)->ideal_reg()]);
aoqi@0 1108 }
aoqi@0 1109 const RegMask &SafePointNode::out_RegMask() const {
aoqi@0 1110 return RegMask::Empty;
aoqi@0 1111 }
aoqi@0 1112
aoqi@0 1113
aoqi@0 1114 void SafePointNode::grow_stack(JVMState* jvms, uint grow_by) {
aoqi@0 1115 assert((int)grow_by > 0, "sanity");
aoqi@0 1116 int monoff = jvms->monoff();
aoqi@0 1117 int scloff = jvms->scloff();
aoqi@0 1118 int endoff = jvms->endoff();
aoqi@0 1119 assert(endoff == (int)req(), "no other states or debug info after me");
aoqi@0 1120 Node* top = Compile::current()->top();
aoqi@0 1121 for (uint i = 0; i < grow_by; i++) {
aoqi@0 1122 ins_req(monoff, top);
aoqi@0 1123 }
aoqi@0 1124 jvms->set_monoff(monoff + grow_by);
aoqi@0 1125 jvms->set_scloff(scloff + grow_by);
aoqi@0 1126 jvms->set_endoff(endoff + grow_by);
aoqi@0 1127 }
aoqi@0 1128
aoqi@0 1129 void SafePointNode::push_monitor(const FastLockNode *lock) {
aoqi@0 1130 // Add a LockNode, which points to both the original BoxLockNode (the
aoqi@0 1131 // stack space for the monitor) and the Object being locked.
aoqi@0 1132 const int MonitorEdges = 2;
aoqi@0 1133 assert(JVMState::logMonitorEdges == exact_log2(MonitorEdges), "correct MonitorEdges");
aoqi@0 1134 assert(req() == jvms()->endoff(), "correct sizing");
aoqi@0 1135 int nextmon = jvms()->scloff();
aoqi@0 1136 if (GenerateSynchronizationCode) {
aoqi@0 1137 ins_req(nextmon, lock->box_node());
aoqi@0 1138 ins_req(nextmon+1, lock->obj_node());
aoqi@0 1139 } else {
aoqi@0 1140 Node* top = Compile::current()->top();
aoqi@0 1141 ins_req(nextmon, top);
aoqi@0 1142 ins_req(nextmon, top);
aoqi@0 1143 }
aoqi@0 1144 jvms()->set_scloff(nextmon + MonitorEdges);
aoqi@0 1145 jvms()->set_endoff(req());
aoqi@0 1146 }
aoqi@0 1147
aoqi@0 1148 void SafePointNode::pop_monitor() {
aoqi@0 1149 // Delete last monitor from debug info
aoqi@0 1150 debug_only(int num_before_pop = jvms()->nof_monitors());
aoqi@0 1151 const int MonitorEdges = 2;
aoqi@0 1152 assert(JVMState::logMonitorEdges == exact_log2(MonitorEdges), "correct MonitorEdges");
aoqi@0 1153 int scloff = jvms()->scloff();
aoqi@0 1154 int endoff = jvms()->endoff();
aoqi@0 1155 int new_scloff = scloff - MonitorEdges;
aoqi@0 1156 int new_endoff = endoff - MonitorEdges;
aoqi@0 1157 jvms()->set_scloff(new_scloff);
aoqi@0 1158 jvms()->set_endoff(new_endoff);
aoqi@0 1159 while (scloff > new_scloff) del_req_ordered(--scloff);
aoqi@0 1160 assert(jvms()->nof_monitors() == num_before_pop-1, "");
aoqi@0 1161 }
aoqi@0 1162
aoqi@0 1163 Node *SafePointNode::peek_monitor_box() const {
aoqi@0 1164 int mon = jvms()->nof_monitors() - 1;
aoqi@0 1165 assert(mon >= 0, "most have a monitor");
aoqi@0 1166 return monitor_box(jvms(), mon);
aoqi@0 1167 }
aoqi@0 1168
aoqi@0 1169 Node *SafePointNode::peek_monitor_obj() const {
aoqi@0 1170 int mon = jvms()->nof_monitors() - 1;
aoqi@0 1171 assert(mon >= 0, "most have a monitor");
aoqi@0 1172 return monitor_obj(jvms(), mon);
aoqi@0 1173 }
aoqi@0 1174
aoqi@0 1175 // Do we Match on this edge index or not? Match no edges
aoqi@0 1176 uint SafePointNode::match_edge(uint idx) const {
aoqi@0 1177 if( !needs_polling_address_input() )
aoqi@0 1178 return 0;
aoqi@0 1179
aoqi@0 1180 return (TypeFunc::Parms == idx);
aoqi@0 1181 }
aoqi@0 1182
aoqi@0 1183 //============== SafePointScalarObjectNode ==============
aoqi@0 1184
aoqi@0 1185 SafePointScalarObjectNode::SafePointScalarObjectNode(const TypeOopPtr* tp,
aoqi@0 1186 #ifdef ASSERT
aoqi@0 1187 AllocateNode* alloc,
aoqi@0 1188 #endif
aoqi@0 1189 uint first_index,
aoqi@0 1190 uint n_fields) :
aoqi@0 1191 TypeNode(tp, 1), // 1 control input -- seems required. Get from root.
aoqi@0 1192 #ifdef ASSERT
aoqi@0 1193 _alloc(alloc),
aoqi@0 1194 #endif
aoqi@0 1195 _first_index(first_index),
aoqi@0 1196 _n_fields(n_fields)
aoqi@0 1197 {
aoqi@0 1198 init_class_id(Class_SafePointScalarObject);
aoqi@0 1199 }
aoqi@0 1200
aoqi@0 1201 // Do not allow value-numbering for SafePointScalarObject node.
aoqi@0 1202 uint SafePointScalarObjectNode::hash() const { return NO_HASH; }
aoqi@0 1203 uint SafePointScalarObjectNode::cmp( const Node &n ) const {
aoqi@0 1204 return (&n == this); // Always fail except on self
aoqi@0 1205 }
aoqi@0 1206
aoqi@0 1207 uint SafePointScalarObjectNode::ideal_reg() const {
aoqi@0 1208 return 0; // No matching to machine instruction
aoqi@0 1209 }
aoqi@0 1210
aoqi@0 1211 const RegMask &SafePointScalarObjectNode::in_RegMask(uint idx) const {
aoqi@0 1212 return *(Compile::current()->matcher()->idealreg2debugmask[in(idx)->ideal_reg()]);
aoqi@0 1213 }
aoqi@0 1214
aoqi@0 1215 const RegMask &SafePointScalarObjectNode::out_RegMask() const {
aoqi@0 1216 return RegMask::Empty;
aoqi@0 1217 }
aoqi@0 1218
aoqi@0 1219 uint SafePointScalarObjectNode::match_edge(uint idx) const {
aoqi@0 1220 return 0;
aoqi@0 1221 }
aoqi@0 1222
aoqi@0 1223 SafePointScalarObjectNode*
aoqi@0 1224 SafePointScalarObjectNode::clone(Dict* sosn_map) const {
aoqi@0 1225 void* cached = (*sosn_map)[(void*)this];
aoqi@0 1226 if (cached != NULL) {
aoqi@0 1227 return (SafePointScalarObjectNode*)cached;
aoqi@0 1228 }
aoqi@0 1229 SafePointScalarObjectNode* res = (SafePointScalarObjectNode*)Node::clone();
aoqi@0 1230 sosn_map->Insert((void*)this, (void*)res);
aoqi@0 1231 return res;
aoqi@0 1232 }
aoqi@0 1233
aoqi@0 1234
aoqi@0 1235 #ifndef PRODUCT
aoqi@0 1236 void SafePointScalarObjectNode::dump_spec(outputStream *st) const {
aoqi@0 1237 st->print(" # fields@[%d..%d]", first_index(),
aoqi@0 1238 first_index() + n_fields() - 1);
aoqi@0 1239 }
aoqi@0 1240
aoqi@0 1241 #endif
aoqi@0 1242
aoqi@0 1243 //=============================================================================
aoqi@0 1244 uint AllocateNode::size_of() const { return sizeof(*this); }
aoqi@0 1245
aoqi@0 1246 AllocateNode::AllocateNode(Compile* C, const TypeFunc *atype,
aoqi@0 1247 Node *ctrl, Node *mem, Node *abio,
aoqi@0 1248 Node *size, Node *klass_node, Node *initial_test)
aoqi@0 1249 : CallNode(atype, NULL, TypeRawPtr::BOTTOM)
aoqi@0 1250 {
aoqi@0 1251 init_class_id(Class_Allocate);
aoqi@0 1252 init_flags(Flag_is_macro);
aoqi@0 1253 _is_scalar_replaceable = false;
aoqi@0 1254 _is_non_escaping = false;
aoqi@0 1255 Node *topnode = C->top();
aoqi@0 1256
aoqi@0 1257 init_req( TypeFunc::Control , ctrl );
aoqi@0 1258 init_req( TypeFunc::I_O , abio );
aoqi@0 1259 init_req( TypeFunc::Memory , mem );
aoqi@0 1260 init_req( TypeFunc::ReturnAdr, topnode );
aoqi@0 1261 init_req( TypeFunc::FramePtr , topnode );
aoqi@0 1262 init_req( AllocSize , size);
aoqi@0 1263 init_req( KlassNode , klass_node);
aoqi@0 1264 init_req( InitialTest , initial_test);
aoqi@0 1265 init_req( ALength , topnode);
aoqi@0 1266 C->add_macro_node(this);
aoqi@0 1267 }
aoqi@0 1268
aoqi@0 1269 //=============================================================================
aoqi@0 1270 Node* AllocateArrayNode::Ideal(PhaseGVN *phase, bool can_reshape) {
aoqi@0 1271 if (remove_dead_region(phase, can_reshape)) return this;
aoqi@0 1272 // Don't bother trying to transform a dead node
aoqi@0 1273 if (in(0) && in(0)->is_top()) return NULL;
aoqi@0 1274
aoqi@0 1275 const Type* type = phase->type(Ideal_length());
aoqi@0 1276 if (type->isa_int() && type->is_int()->_hi < 0) {
aoqi@0 1277 if (can_reshape) {
aoqi@0 1278 PhaseIterGVN *igvn = phase->is_IterGVN();
aoqi@0 1279 // Unreachable fall through path (negative array length),
aoqi@0 1280 // the allocation can only throw so disconnect it.
aoqi@0 1281 Node* proj = proj_out(TypeFunc::Control);
aoqi@0 1282 Node* catchproj = NULL;
aoqi@0 1283 if (proj != NULL) {
aoqi@0 1284 for (DUIterator_Fast imax, i = proj->fast_outs(imax); i < imax; i++) {
aoqi@0 1285 Node *cn = proj->fast_out(i);
aoqi@0 1286 if (cn->is_Catch()) {
aoqi@0 1287 catchproj = cn->as_Multi()->proj_out(CatchProjNode::fall_through_index);
aoqi@0 1288 break;
aoqi@0 1289 }
aoqi@0 1290 }
aoqi@0 1291 }
aoqi@0 1292 if (catchproj != NULL && catchproj->outcnt() > 0 &&
aoqi@0 1293 (catchproj->outcnt() > 1 ||
aoqi@0 1294 catchproj->unique_out()->Opcode() != Op_Halt)) {
aoqi@0 1295 assert(catchproj->is_CatchProj(), "must be a CatchProjNode");
aoqi@0 1296 Node* nproj = catchproj->clone();
aoqi@0 1297 igvn->register_new_node_with_optimizer(nproj);
aoqi@0 1298
aoqi@0 1299 Node *frame = new (phase->C) ParmNode( phase->C->start(), TypeFunc::FramePtr );
aoqi@0 1300 frame = phase->transform(frame);
aoqi@0 1301 // Halt & Catch Fire
aoqi@0 1302 Node *halt = new (phase->C) HaltNode( nproj, frame );
aoqi@0 1303 phase->C->root()->add_req(halt);
aoqi@0 1304 phase->transform(halt);
aoqi@0 1305
aoqi@0 1306 igvn->replace_node(catchproj, phase->C->top());
aoqi@0 1307 return this;
aoqi@0 1308 }
aoqi@0 1309 } else {
aoqi@0 1310 // Can't correct it during regular GVN so register for IGVN
aoqi@0 1311 phase->C->record_for_igvn(this);
aoqi@0 1312 }
aoqi@0 1313 }
aoqi@0 1314 return NULL;
aoqi@0 1315 }
aoqi@0 1316
aoqi@0 1317 // Retrieve the length from the AllocateArrayNode. Narrow the type with a
aoqi@0 1318 // CastII, if appropriate. If we are not allowed to create new nodes, and
aoqi@0 1319 // a CastII is appropriate, return NULL.
aoqi@0 1320 Node *AllocateArrayNode::make_ideal_length(const TypeOopPtr* oop_type, PhaseTransform *phase, bool allow_new_nodes) {
aoqi@0 1321 Node *length = in(AllocateNode::ALength);
aoqi@0 1322 assert(length != NULL, "length is not null");
aoqi@0 1323
aoqi@0 1324 const TypeInt* length_type = phase->find_int_type(length);
aoqi@0 1325 const TypeAryPtr* ary_type = oop_type->isa_aryptr();
aoqi@0 1326
aoqi@0 1327 if (ary_type != NULL && length_type != NULL) {
aoqi@0 1328 const TypeInt* narrow_length_type = ary_type->narrow_size_type(length_type);
aoqi@0 1329 if (narrow_length_type != length_type) {
aoqi@0 1330 // Assert one of:
aoqi@0 1331 // - the narrow_length is 0
aoqi@0 1332 // - the narrow_length is not wider than length
aoqi@0 1333 assert(narrow_length_type == TypeInt::ZERO ||
aoqi@0 1334 length_type->is_con() && narrow_length_type->is_con() &&
aoqi@0 1335 (narrow_length_type->_hi <= length_type->_lo) ||
aoqi@0 1336 (narrow_length_type->_hi <= length_type->_hi &&
aoqi@0 1337 narrow_length_type->_lo >= length_type->_lo),
aoqi@0 1338 "narrow type must be narrower than length type");
aoqi@0 1339
aoqi@0 1340 // Return NULL if new nodes are not allowed
aoqi@0 1341 if (!allow_new_nodes) return NULL;
aoqi@0 1342 // Create a cast which is control dependent on the initialization to
aoqi@0 1343 // propagate the fact that the array length must be positive.
aoqi@0 1344 length = new (phase->C) CastIINode(length, narrow_length_type);
aoqi@0 1345 length->set_req(0, initialization()->proj_out(0));
aoqi@0 1346 }
aoqi@0 1347 }
aoqi@0 1348
aoqi@0 1349 return length;
aoqi@0 1350 }
aoqi@0 1351
aoqi@0 1352 //=============================================================================
aoqi@0 1353 uint LockNode::size_of() const { return sizeof(*this); }
aoqi@0 1354
aoqi@0 1355 // Redundant lock elimination
aoqi@0 1356 //
aoqi@0 1357 // There are various patterns of locking where we release and
aoqi@0 1358 // immediately reacquire a lock in a piece of code where no operations
aoqi@0 1359 // occur in between that would be observable. In those cases we can
aoqi@0 1360 // skip releasing and reacquiring the lock without violating any
aoqi@0 1361 // fairness requirements. Doing this around a loop could cause a lock
aoqi@0 1362 // to be held for a very long time so we concentrate on non-looping
aoqi@0 1363 // control flow. We also require that the operations are fully
aoqi@0 1364 // redundant meaning that we don't introduce new lock operations on
aoqi@0 1365 // some paths so to be able to eliminate it on others ala PRE. This
aoqi@0 1366 // would probably require some more extensive graph manipulation to
aoqi@0 1367 // guarantee that the memory edges were all handled correctly.
aoqi@0 1368 //
aoqi@0 1369 // Assuming p is a simple predicate which can't trap in any way and s
aoqi@0 1370 // is a synchronized method consider this code:
aoqi@0 1371 //
aoqi@0 1372 // s();
aoqi@0 1373 // if (p)
aoqi@0 1374 // s();
aoqi@0 1375 // else
aoqi@0 1376 // s();
aoqi@0 1377 // s();
aoqi@0 1378 //
aoqi@0 1379 // 1. The unlocks of the first call to s can be eliminated if the
aoqi@0 1380 // locks inside the then and else branches are eliminated.
aoqi@0 1381 //
aoqi@0 1382 // 2. The unlocks of the then and else branches can be eliminated if
aoqi@0 1383 // the lock of the final call to s is eliminated.
aoqi@0 1384 //
aoqi@0 1385 // Either of these cases subsumes the simple case of sequential control flow
aoqi@0 1386 //
aoqi@0 1387 // Addtionally we can eliminate versions without the else case:
aoqi@0 1388 //
aoqi@0 1389 // s();
aoqi@0 1390 // if (p)
aoqi@0 1391 // s();
aoqi@0 1392 // s();
aoqi@0 1393 //
aoqi@0 1394 // 3. In this case we eliminate the unlock of the first s, the lock
aoqi@0 1395 // and unlock in the then case and the lock in the final s.
aoqi@0 1396 //
aoqi@0 1397 // Note also that in all these cases the then/else pieces don't have
aoqi@0 1398 // to be trivial as long as they begin and end with synchronization
aoqi@0 1399 // operations.
aoqi@0 1400 //
aoqi@0 1401 // s();
aoqi@0 1402 // if (p)
aoqi@0 1403 // s();
aoqi@0 1404 // f();
aoqi@0 1405 // s();
aoqi@0 1406 // s();
aoqi@0 1407 //
aoqi@0 1408 // The code will work properly for this case, leaving in the unlock
aoqi@0 1409 // before the call to f and the relock after it.
aoqi@0 1410 //
aoqi@0 1411 // A potentially interesting case which isn't handled here is when the
aoqi@0 1412 // locking is partially redundant.
aoqi@0 1413 //
aoqi@0 1414 // s();
aoqi@0 1415 // if (p)
aoqi@0 1416 // s();
aoqi@0 1417 //
aoqi@0 1418 // This could be eliminated putting unlocking on the else case and
aoqi@0 1419 // eliminating the first unlock and the lock in the then side.
aoqi@0 1420 // Alternatively the unlock could be moved out of the then side so it
aoqi@0 1421 // was after the merge and the first unlock and second lock
aoqi@0 1422 // eliminated. This might require less manipulation of the memory
aoqi@0 1423 // state to get correct.
aoqi@0 1424 //
aoqi@0 1425 // Additionally we might allow work between a unlock and lock before
aoqi@0 1426 // giving up eliminating the locks. The current code disallows any
aoqi@0 1427 // conditional control flow between these operations. A formulation
aoqi@0 1428 // similar to partial redundancy elimination computing the
aoqi@0 1429 // availability of unlocking and the anticipatability of locking at a
aoqi@0 1430 // program point would allow detection of fully redundant locking with
aoqi@0 1431 // some amount of work in between. I'm not sure how often I really
aoqi@0 1432 // think that would occur though. Most of the cases I've seen
aoqi@0 1433 // indicate it's likely non-trivial work would occur in between.
aoqi@0 1434 // There may be other more complicated constructs where we could
aoqi@0 1435 // eliminate locking but I haven't seen any others appear as hot or
aoqi@0 1436 // interesting.
aoqi@0 1437 //
aoqi@0 1438 // Locking and unlocking have a canonical form in ideal that looks
aoqi@0 1439 // roughly like this:
aoqi@0 1440 //
aoqi@0 1441 // <obj>
aoqi@0 1442 // | \\------+
aoqi@0 1443 // | \ \
aoqi@0 1444 // | BoxLock \
aoqi@0 1445 // | | | \
aoqi@0 1446 // | | \ \
aoqi@0 1447 // | | FastLock
aoqi@0 1448 // | | /
aoqi@0 1449 // | | /
aoqi@0 1450 // | | |
aoqi@0 1451 //
aoqi@0 1452 // Lock
aoqi@0 1453 // |
aoqi@0 1454 // Proj #0
aoqi@0 1455 // |
aoqi@0 1456 // MembarAcquire
aoqi@0 1457 // |
aoqi@0 1458 // Proj #0
aoqi@0 1459 //
aoqi@0 1460 // MembarRelease
aoqi@0 1461 // |
aoqi@0 1462 // Proj #0
aoqi@0 1463 // |
aoqi@0 1464 // Unlock
aoqi@0 1465 // |
aoqi@0 1466 // Proj #0
aoqi@0 1467 //
aoqi@0 1468 //
aoqi@0 1469 // This code proceeds by processing Lock nodes during PhaseIterGVN
aoqi@0 1470 // and searching back through its control for the proper code
aoqi@0 1471 // patterns. Once it finds a set of lock and unlock operations to
aoqi@0 1472 // eliminate they are marked as eliminatable which causes the
aoqi@0 1473 // expansion of the Lock and Unlock macro nodes to make the operation a NOP
aoqi@0 1474 //
aoqi@0 1475 //=============================================================================
aoqi@0 1476
aoqi@0 1477 //
aoqi@0 1478 // Utility function to skip over uninteresting control nodes. Nodes skipped are:
aoqi@0 1479 // - copy regions. (These may not have been optimized away yet.)
aoqi@0 1480 // - eliminated locking nodes
aoqi@0 1481 //
aoqi@0 1482 static Node *next_control(Node *ctrl) {
aoqi@0 1483 if (ctrl == NULL)
aoqi@0 1484 return NULL;
aoqi@0 1485 while (1) {
aoqi@0 1486 if (ctrl->is_Region()) {
aoqi@0 1487 RegionNode *r = ctrl->as_Region();
aoqi@0 1488 Node *n = r->is_copy();
aoqi@0 1489 if (n == NULL)
aoqi@0 1490 break; // hit a region, return it
aoqi@0 1491 else
aoqi@0 1492 ctrl = n;
aoqi@0 1493 } else if (ctrl->is_Proj()) {
aoqi@0 1494 Node *in0 = ctrl->in(0);
aoqi@0 1495 if (in0->is_AbstractLock() && in0->as_AbstractLock()->is_eliminated()) {
aoqi@0 1496 ctrl = in0->in(0);
aoqi@0 1497 } else {
aoqi@0 1498 break;
aoqi@0 1499 }
aoqi@0 1500 } else {
aoqi@0 1501 break; // found an interesting control
aoqi@0 1502 }
aoqi@0 1503 }
aoqi@0 1504 return ctrl;
aoqi@0 1505 }
aoqi@0 1506 //
aoqi@0 1507 // Given a control, see if it's the control projection of an Unlock which
aoqi@0 1508 // operating on the same object as lock.
aoqi@0 1509 //
aoqi@0 1510 bool AbstractLockNode::find_matching_unlock(const Node* ctrl, LockNode* lock,
aoqi@0 1511 GrowableArray<AbstractLockNode*> &lock_ops) {
aoqi@0 1512 ProjNode *ctrl_proj = (ctrl->is_Proj()) ? ctrl->as_Proj() : NULL;
aoqi@0 1513 if (ctrl_proj != NULL && ctrl_proj->_con == TypeFunc::Control) {
aoqi@0 1514 Node *n = ctrl_proj->in(0);
aoqi@0 1515 if (n != NULL && n->is_Unlock()) {
aoqi@0 1516 UnlockNode *unlock = n->as_Unlock();
aoqi@0 1517 if (lock->obj_node()->eqv_uncast(unlock->obj_node()) &&
aoqi@0 1518 BoxLockNode::same_slot(lock->box_node(), unlock->box_node()) &&
aoqi@0 1519 !unlock->is_eliminated()) {
aoqi@0 1520 lock_ops.append(unlock);
aoqi@0 1521 return true;
aoqi@0 1522 }
aoqi@0 1523 }
aoqi@0 1524 }
aoqi@0 1525 return false;
aoqi@0 1526 }
aoqi@0 1527
aoqi@0 1528 //
aoqi@0 1529 // Find the lock matching an unlock. Returns null if a safepoint
aoqi@0 1530 // or complicated control is encountered first.
aoqi@0 1531 LockNode *AbstractLockNode::find_matching_lock(UnlockNode* unlock) {
aoqi@0 1532 LockNode *lock_result = NULL;
aoqi@0 1533 // find the matching lock, or an intervening safepoint
aoqi@0 1534 Node *ctrl = next_control(unlock->in(0));
aoqi@0 1535 while (1) {
aoqi@0 1536 assert(ctrl != NULL, "invalid control graph");
aoqi@0 1537 assert(!ctrl->is_Start(), "missing lock for unlock");
aoqi@0 1538 if (ctrl->is_top()) break; // dead control path
aoqi@0 1539 if (ctrl->is_Proj()) ctrl = ctrl->in(0);
aoqi@0 1540 if (ctrl->is_SafePoint()) {
aoqi@0 1541 break; // found a safepoint (may be the lock we are searching for)
aoqi@0 1542 } else if (ctrl->is_Region()) {
aoqi@0 1543 // Check for a simple diamond pattern. Punt on anything more complicated
aoqi@0 1544 if (ctrl->req() == 3 && ctrl->in(1) != NULL && ctrl->in(2) != NULL) {
aoqi@0 1545 Node *in1 = next_control(ctrl->in(1));
aoqi@0 1546 Node *in2 = next_control(ctrl->in(2));
aoqi@0 1547 if (((in1->is_IfTrue() && in2->is_IfFalse()) ||
aoqi@0 1548 (in2->is_IfTrue() && in1->is_IfFalse())) && (in1->in(0) == in2->in(0))) {
aoqi@0 1549 ctrl = next_control(in1->in(0)->in(0));
aoqi@0 1550 } else {
aoqi@0 1551 break;
aoqi@0 1552 }
aoqi@0 1553 } else {
aoqi@0 1554 break;
aoqi@0 1555 }
aoqi@0 1556 } else {
aoqi@0 1557 ctrl = next_control(ctrl->in(0)); // keep searching
aoqi@0 1558 }
aoqi@0 1559 }
aoqi@0 1560 if (ctrl->is_Lock()) {
aoqi@0 1561 LockNode *lock = ctrl->as_Lock();
aoqi@0 1562 if (lock->obj_node()->eqv_uncast(unlock->obj_node()) &&
aoqi@0 1563 BoxLockNode::same_slot(lock->box_node(), unlock->box_node())) {
aoqi@0 1564 lock_result = lock;
aoqi@0 1565 }
aoqi@0 1566 }
aoqi@0 1567 return lock_result;
aoqi@0 1568 }
aoqi@0 1569
aoqi@0 1570 // This code corresponds to case 3 above.
aoqi@0 1571
aoqi@0 1572 bool AbstractLockNode::find_lock_and_unlock_through_if(Node* node, LockNode* lock,
aoqi@0 1573 GrowableArray<AbstractLockNode*> &lock_ops) {
aoqi@0 1574 Node* if_node = node->in(0);
aoqi@0 1575 bool if_true = node->is_IfTrue();
aoqi@0 1576
aoqi@0 1577 if (if_node->is_If() && if_node->outcnt() == 2 && (if_true || node->is_IfFalse())) {
aoqi@0 1578 Node *lock_ctrl = next_control(if_node->in(0));
aoqi@0 1579 if (find_matching_unlock(lock_ctrl, lock, lock_ops)) {
aoqi@0 1580 Node* lock1_node = NULL;
aoqi@0 1581 ProjNode* proj = if_node->as_If()->proj_out(!if_true);
aoqi@0 1582 if (if_true) {
aoqi@0 1583 if (proj->is_IfFalse() && proj->outcnt() == 1) {
aoqi@0 1584 lock1_node = proj->unique_out();
aoqi@0 1585 }
aoqi@0 1586 } else {
aoqi@0 1587 if (proj->is_IfTrue() && proj->outcnt() == 1) {
aoqi@0 1588 lock1_node = proj->unique_out();
aoqi@0 1589 }
aoqi@0 1590 }
aoqi@0 1591 if (lock1_node != NULL && lock1_node->is_Lock()) {
aoqi@0 1592 LockNode *lock1 = lock1_node->as_Lock();
aoqi@0 1593 if (lock->obj_node()->eqv_uncast(lock1->obj_node()) &&
aoqi@0 1594 BoxLockNode::same_slot(lock->box_node(), lock1->box_node()) &&
aoqi@0 1595 !lock1->is_eliminated()) {
aoqi@0 1596 lock_ops.append(lock1);
aoqi@0 1597 return true;
aoqi@0 1598 }
aoqi@0 1599 }
aoqi@0 1600 }
aoqi@0 1601 }
aoqi@0 1602
aoqi@0 1603 lock_ops.trunc_to(0);
aoqi@0 1604 return false;
aoqi@0 1605 }
aoqi@0 1606
aoqi@0 1607 bool AbstractLockNode::find_unlocks_for_region(const RegionNode* region, LockNode* lock,
aoqi@0 1608 GrowableArray<AbstractLockNode*> &lock_ops) {
aoqi@0 1609 // check each control merging at this point for a matching unlock.
aoqi@0 1610 // in(0) should be self edge so skip it.
aoqi@0 1611 for (int i = 1; i < (int)region->req(); i++) {
aoqi@0 1612 Node *in_node = next_control(region->in(i));
aoqi@0 1613 if (in_node != NULL) {
aoqi@0 1614 if (find_matching_unlock(in_node, lock, lock_ops)) {
aoqi@0 1615 // found a match so keep on checking.
aoqi@0 1616 continue;
aoqi@0 1617 } else if (find_lock_and_unlock_through_if(in_node, lock, lock_ops)) {
aoqi@0 1618 continue;
aoqi@0 1619 }
aoqi@0 1620
aoqi@0 1621 // If we fall through to here then it was some kind of node we
aoqi@0 1622 // don't understand or there wasn't a matching unlock, so give
aoqi@0 1623 // up trying to merge locks.
aoqi@0 1624 lock_ops.trunc_to(0);
aoqi@0 1625 return false;
aoqi@0 1626 }
aoqi@0 1627 }
aoqi@0 1628 return true;
aoqi@0 1629
aoqi@0 1630 }
aoqi@0 1631
aoqi@0 1632 #ifndef PRODUCT
aoqi@0 1633 //
aoqi@0 1634 // Create a counter which counts the number of times this lock is acquired
aoqi@0 1635 //
aoqi@0 1636 void AbstractLockNode::create_lock_counter(JVMState* state) {
aoqi@0 1637 _counter = OptoRuntime::new_named_counter(state, NamedCounter::LockCounter);
aoqi@0 1638 }
aoqi@0 1639
aoqi@0 1640 void AbstractLockNode::set_eliminated_lock_counter() {
aoqi@0 1641 if (_counter) {
aoqi@0 1642 // Update the counter to indicate that this lock was eliminated.
aoqi@0 1643 // The counter update code will stay around even though the
aoqi@0 1644 // optimizer will eliminate the lock operation itself.
aoqi@0 1645 _counter->set_tag(NamedCounter::EliminatedLockCounter);
aoqi@0 1646 }
aoqi@0 1647 }
aoqi@0 1648 #endif
aoqi@0 1649
aoqi@0 1650 //=============================================================================
aoqi@0 1651 Node *LockNode::Ideal(PhaseGVN *phase, bool can_reshape) {
aoqi@0 1652
aoqi@0 1653 // perform any generic optimizations first (returns 'this' or NULL)
aoqi@0 1654 Node *result = SafePointNode::Ideal(phase, can_reshape);
aoqi@0 1655 if (result != NULL) return result;
aoqi@0 1656 // Don't bother trying to transform a dead node
aoqi@0 1657 if (in(0) && in(0)->is_top()) return NULL;
aoqi@0 1658
aoqi@0 1659 // Now see if we can optimize away this lock. We don't actually
aoqi@0 1660 // remove the locking here, we simply set the _eliminate flag which
aoqi@0 1661 // prevents macro expansion from expanding the lock. Since we don't
aoqi@0 1662 // modify the graph, the value returned from this function is the
aoqi@0 1663 // one computed above.
aoqi@0 1664 if (can_reshape && EliminateLocks && !is_non_esc_obj()) {
aoqi@0 1665 //
aoqi@0 1666 // If we are locking an unescaped object, the lock/unlock is unnecessary
aoqi@0 1667 //
aoqi@0 1668 ConnectionGraph *cgr = phase->C->congraph();
aoqi@0 1669 if (cgr != NULL && cgr->not_global_escape(obj_node())) {
aoqi@0 1670 assert(!is_eliminated() || is_coarsened(), "sanity");
aoqi@0 1671 // The lock could be marked eliminated by lock coarsening
aoqi@0 1672 // code during first IGVN before EA. Replace coarsened flag
aoqi@0 1673 // to eliminate all associated locks/unlocks.
drchase@7605 1674 #ifdef ASSERT
drchase@7605 1675 this->log_lock_optimization(phase->C,"eliminate_lock_set_non_esc1");
drchase@7605 1676 #endif
aoqi@0 1677 this->set_non_esc_obj();
aoqi@0 1678 return result;
aoqi@0 1679 }
aoqi@0 1680
aoqi@0 1681 //
aoqi@0 1682 // Try lock coarsening
aoqi@0 1683 //
aoqi@0 1684 PhaseIterGVN* iter = phase->is_IterGVN();
aoqi@0 1685 if (iter != NULL && !is_eliminated()) {
aoqi@0 1686
aoqi@0 1687 GrowableArray<AbstractLockNode*> lock_ops;
aoqi@0 1688
aoqi@0 1689 Node *ctrl = next_control(in(0));
aoqi@0 1690
aoqi@0 1691 // now search back for a matching Unlock
aoqi@0 1692 if (find_matching_unlock(ctrl, this, lock_ops)) {
aoqi@0 1693 // found an unlock directly preceding this lock. This is the
aoqi@0 1694 // case of single unlock directly control dependent on a
aoqi@0 1695 // single lock which is the trivial version of case 1 or 2.
aoqi@0 1696 } else if (ctrl->is_Region() ) {
aoqi@0 1697 if (find_unlocks_for_region(ctrl->as_Region(), this, lock_ops)) {
aoqi@0 1698 // found lock preceded by multiple unlocks along all paths
aoqi@0 1699 // joining at this point which is case 3 in description above.
aoqi@0 1700 }
aoqi@0 1701 } else {
aoqi@0 1702 // see if this lock comes from either half of an if and the
aoqi@0 1703 // predecessors merges unlocks and the other half of the if
aoqi@0 1704 // performs a lock.
aoqi@0 1705 if (find_lock_and_unlock_through_if(ctrl, this, lock_ops)) {
aoqi@0 1706 // found unlock splitting to an if with locks on both branches.
aoqi@0 1707 }
aoqi@0 1708 }
aoqi@0 1709
aoqi@0 1710 if (lock_ops.length() > 0) {
aoqi@0 1711 // add ourselves to the list of locks to be eliminated.
aoqi@0 1712 lock_ops.append(this);
aoqi@0 1713
aoqi@0 1714 #ifndef PRODUCT
aoqi@0 1715 if (PrintEliminateLocks) {
aoqi@0 1716 int locks = 0;
aoqi@0 1717 int unlocks = 0;
aoqi@0 1718 for (int i = 0; i < lock_ops.length(); i++) {
aoqi@0 1719 AbstractLockNode* lock = lock_ops.at(i);
aoqi@0 1720 if (lock->Opcode() == Op_Lock)
aoqi@0 1721 locks++;
aoqi@0 1722 else
aoqi@0 1723 unlocks++;
aoqi@0 1724 if (Verbose) {
aoqi@0 1725 lock->dump(1);
aoqi@0 1726 }
aoqi@0 1727 }
aoqi@0 1728 tty->print_cr("***Eliminated %d unlocks and %d locks", unlocks, locks);
aoqi@0 1729 }
aoqi@0 1730 #endif
aoqi@0 1731
aoqi@0 1732 // for each of the identified locks, mark them
aoqi@0 1733 // as eliminatable
aoqi@0 1734 for (int i = 0; i < lock_ops.length(); i++) {
aoqi@0 1735 AbstractLockNode* lock = lock_ops.at(i);
aoqi@0 1736
aoqi@0 1737 // Mark it eliminated by coarsening and update any counters
drchase@7605 1738 #ifdef ASSERT
drchase@7605 1739 lock->log_lock_optimization(phase->C, "eliminate_lock_set_coarsened");
drchase@7605 1740 #endif
aoqi@0 1741 lock->set_coarsened();
aoqi@0 1742 }
aoqi@0 1743 } else if (ctrl->is_Region() &&
aoqi@0 1744 iter->_worklist.member(ctrl)) {
aoqi@0 1745 // We weren't able to find any opportunities but the region this
aoqi@0 1746 // lock is control dependent on hasn't been processed yet so put
aoqi@0 1747 // this lock back on the worklist so we can check again once any
aoqi@0 1748 // region simplification has occurred.
aoqi@0 1749 iter->_worklist.push(this);
aoqi@0 1750 }
aoqi@0 1751 }
aoqi@0 1752 }
aoqi@0 1753
aoqi@0 1754 return result;
aoqi@0 1755 }
aoqi@0 1756
aoqi@0 1757 //=============================================================================
aoqi@0 1758 bool LockNode::is_nested_lock_region() {
drchase@7605 1759 return is_nested_lock_region(NULL);
drchase@7605 1760 }
drchase@7605 1761
drchase@7605 1762 // p is used for access to compilation log; no logging if NULL
drchase@7605 1763 bool LockNode::is_nested_lock_region(Compile * c) {
aoqi@0 1764 BoxLockNode* box = box_node()->as_BoxLock();
aoqi@0 1765 int stk_slot = box->stack_slot();
drchase@7605 1766 if (stk_slot <= 0) {
drchase@7605 1767 #ifdef ASSERT
drchase@7605 1768 this->log_lock_optimization(c, "eliminate_lock_INLR_1");
drchase@7605 1769 #endif
aoqi@0 1770 return false; // External lock or it is not Box (Phi node).
drchase@7605 1771 }
aoqi@0 1772
aoqi@0 1773 // Ignore complex cases: merged locks or multiple locks.
aoqi@0 1774 Node* obj = obj_node();
aoqi@0 1775 LockNode* unique_lock = NULL;
drchase@7605 1776 if (!box->is_simple_lock_region(&unique_lock, obj)) {
drchase@7605 1777 #ifdef ASSERT
drchase@7605 1778 this->log_lock_optimization(c, "eliminate_lock_INLR_2a");
drchase@7605 1779 #endif
drchase@7605 1780 return false;
drchase@7605 1781 }
drchase@7605 1782 if (unique_lock != this) {
drchase@7605 1783 #ifdef ASSERT
drchase@7605 1784 this->log_lock_optimization(c, "eliminate_lock_INLR_2b");
drchase@7605 1785 #endif
aoqi@0 1786 return false;
aoqi@0 1787 }
aoqi@0 1788
aoqi@0 1789 // Look for external lock for the same object.
aoqi@0 1790 SafePointNode* sfn = this->as_SafePoint();
aoqi@0 1791 JVMState* youngest_jvms = sfn->jvms();
aoqi@0 1792 int max_depth = youngest_jvms->depth();
aoqi@0 1793 for (int depth = 1; depth <= max_depth; depth++) {
aoqi@0 1794 JVMState* jvms = youngest_jvms->of_depth(depth);
aoqi@0 1795 int num_mon = jvms->nof_monitors();
aoqi@0 1796 // Loop over monitors
aoqi@0 1797 for (int idx = 0; idx < num_mon; idx++) {
aoqi@0 1798 Node* obj_node = sfn->monitor_obj(jvms, idx);
aoqi@0 1799 BoxLockNode* box_node = sfn->monitor_box(jvms, idx)->as_BoxLock();
aoqi@0 1800 if ((box_node->stack_slot() < stk_slot) && obj_node->eqv_uncast(obj)) {
aoqi@0 1801 return true;
aoqi@0 1802 }
aoqi@0 1803 }
aoqi@0 1804 }
drchase@7605 1805 #ifdef ASSERT
drchase@7605 1806 this->log_lock_optimization(c, "eliminate_lock_INLR_3");
drchase@7605 1807 #endif
aoqi@0 1808 return false;
aoqi@0 1809 }
aoqi@0 1810
aoqi@0 1811 //=============================================================================
aoqi@0 1812 uint UnlockNode::size_of() const { return sizeof(*this); }
aoqi@0 1813
aoqi@0 1814 //=============================================================================
aoqi@0 1815 Node *UnlockNode::Ideal(PhaseGVN *phase, bool can_reshape) {
aoqi@0 1816
aoqi@0 1817 // perform any generic optimizations first (returns 'this' or NULL)
aoqi@0 1818 Node *result = SafePointNode::Ideal(phase, can_reshape);
aoqi@0 1819 if (result != NULL) return result;
aoqi@0 1820 // Don't bother trying to transform a dead node
aoqi@0 1821 if (in(0) && in(0)->is_top()) return NULL;
aoqi@0 1822
aoqi@0 1823 // Now see if we can optimize away this unlock. We don't actually
aoqi@0 1824 // remove the unlocking here, we simply set the _eliminate flag which
aoqi@0 1825 // prevents macro expansion from expanding the unlock. Since we don't
aoqi@0 1826 // modify the graph, the value returned from this function is the
aoqi@0 1827 // one computed above.
aoqi@0 1828 // Escape state is defined after Parse phase.
aoqi@0 1829 if (can_reshape && EliminateLocks && !is_non_esc_obj()) {
aoqi@0 1830 //
aoqi@0 1831 // If we are unlocking an unescaped object, the lock/unlock is unnecessary.
aoqi@0 1832 //
aoqi@0 1833 ConnectionGraph *cgr = phase->C->congraph();
aoqi@0 1834 if (cgr != NULL && cgr->not_global_escape(obj_node())) {
aoqi@0 1835 assert(!is_eliminated() || is_coarsened(), "sanity");
aoqi@0 1836 // The lock could be marked eliminated by lock coarsening
aoqi@0 1837 // code during first IGVN before EA. Replace coarsened flag
aoqi@0 1838 // to eliminate all associated locks/unlocks.
drchase@7605 1839 #ifdef ASSERT
drchase@7605 1840 this->log_lock_optimization(phase->C, "eliminate_lock_set_non_esc2");
drchase@7605 1841 #endif
aoqi@0 1842 this->set_non_esc_obj();
aoqi@0 1843 }
aoqi@0 1844 }
aoqi@0 1845 return result;
aoqi@0 1846 }
drchase@7605 1847
drchase@7605 1848 const char * AbstractLockNode::kind_as_string() const {
drchase@7605 1849 return is_coarsened() ? "coarsened" :
drchase@7605 1850 is_nested() ? "nested" :
drchase@7605 1851 is_non_esc_obj() ? "non_escaping" :
drchase@7605 1852 "?";
drchase@7605 1853 }
drchase@7605 1854
drchase@7605 1855 void AbstractLockNode::log_lock_optimization(Compile *C, const char * tag) const {
drchase@7605 1856 if (C == NULL) {
drchase@7605 1857 return;
drchase@7605 1858 }
drchase@7605 1859 CompileLog* log = C->log();
drchase@7605 1860 if (log != NULL) {
drchase@7605 1861 log->begin_head("%s lock='%d' compile_id='%d' class_id='%s' kind='%s'",
drchase@7605 1862 tag, is_Lock(), C->compile_id(),
drchase@7605 1863 is_Unlock() ? "unlock" : is_Lock() ? "lock" : "?",
drchase@7605 1864 kind_as_string());
drchase@7605 1865 log->stamp();
drchase@7605 1866 log->end_head();
drchase@7605 1867 JVMState* p = is_Unlock() ? (as_Unlock()->dbg_jvms()) : jvms();
drchase@7605 1868 while (p != NULL) {
drchase@7605 1869 log->elem("jvms bci='%d' method='%d'", p->bci(), log->identify(p->method()));
drchase@7605 1870 p = p->caller();
drchase@7605 1871 }
drchase@7605 1872 log->tail(tag);
drchase@7605 1873 }
drchase@7605 1874 }
drchase@7605 1875

mercurial