src/share/vm/opto/callnode.cpp

Thu, 20 Mar 2008 15:11:44 -0700

author
kvn
date
Thu, 20 Mar 2008 15:11:44 -0700
changeset 509
2a9af0b9cb1c
parent 501
6dbf1a175d6b
child 598
885ed790ecf0
permissions
-rw-r--r--

6674600: (Escape Analysis) Optimize memory graph for instance's fields
Summary: EA gives opportunite to do more aggressive memory optimizations.
Reviewed-by: never, jrose

duke@435 1 /*
duke@435 2 * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
duke@435 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@435 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@435 21 * have any questions.
duke@435 22 *
duke@435 23 */
duke@435 24
duke@435 25 // Portions of code courtesy of Clifford Click
duke@435 26
duke@435 27 // Optimization - Graph Style
duke@435 28
duke@435 29 #include "incls/_precompiled.incl"
duke@435 30 #include "incls/_callnode.cpp.incl"
duke@435 31
duke@435 32 //=============================================================================
duke@435 33 uint StartNode::size_of() const { return sizeof(*this); }
duke@435 34 uint StartNode::cmp( const Node &n ) const
duke@435 35 { return _domain == ((StartNode&)n)._domain; }
duke@435 36 const Type *StartNode::bottom_type() const { return _domain; }
duke@435 37 const Type *StartNode::Value(PhaseTransform *phase) const { return _domain; }
duke@435 38 #ifndef PRODUCT
duke@435 39 void StartNode::dump_spec(outputStream *st) const { st->print(" #"); _domain->dump_on(st);}
duke@435 40 #endif
duke@435 41
duke@435 42 //------------------------------Ideal------------------------------------------
duke@435 43 Node *StartNode::Ideal(PhaseGVN *phase, bool can_reshape){
duke@435 44 return remove_dead_region(phase, can_reshape) ? this : NULL;
duke@435 45 }
duke@435 46
duke@435 47 //------------------------------calling_convention-----------------------------
duke@435 48 void StartNode::calling_convention( BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt ) const {
duke@435 49 Matcher::calling_convention( sig_bt, parm_regs, argcnt, false );
duke@435 50 }
duke@435 51
duke@435 52 //------------------------------Registers--------------------------------------
duke@435 53 const RegMask &StartNode::in_RegMask(uint) const {
duke@435 54 return RegMask::Empty;
duke@435 55 }
duke@435 56
duke@435 57 //------------------------------match------------------------------------------
duke@435 58 // Construct projections for incoming parameters, and their RegMask info
duke@435 59 Node *StartNode::match( const ProjNode *proj, const Matcher *match ) {
duke@435 60 switch (proj->_con) {
duke@435 61 case TypeFunc::Control:
duke@435 62 case TypeFunc::I_O:
duke@435 63 case TypeFunc::Memory:
duke@435 64 return new (match->C, 1) MachProjNode(this,proj->_con,RegMask::Empty,MachProjNode::unmatched_proj);
duke@435 65 case TypeFunc::FramePtr:
duke@435 66 return new (match->C, 1) MachProjNode(this,proj->_con,Matcher::c_frame_ptr_mask, Op_RegP);
duke@435 67 case TypeFunc::ReturnAdr:
duke@435 68 return new (match->C, 1) MachProjNode(this,proj->_con,match->_return_addr_mask,Op_RegP);
duke@435 69 case TypeFunc::Parms:
duke@435 70 default: {
duke@435 71 uint parm_num = proj->_con - TypeFunc::Parms;
duke@435 72 const Type *t = _domain->field_at(proj->_con);
duke@435 73 if (t->base() == Type::Half) // 2nd half of Longs and Doubles
duke@435 74 return new (match->C, 1) ConNode(Type::TOP);
duke@435 75 uint ideal_reg = Matcher::base2reg[t->base()];
duke@435 76 RegMask &rm = match->_calling_convention_mask[parm_num];
duke@435 77 return new (match->C, 1) MachProjNode(this,proj->_con,rm,ideal_reg);
duke@435 78 }
duke@435 79 }
duke@435 80 return NULL;
duke@435 81 }
duke@435 82
duke@435 83 //------------------------------StartOSRNode----------------------------------
duke@435 84 // The method start node for an on stack replacement adapter
duke@435 85
duke@435 86 //------------------------------osr_domain-----------------------------
duke@435 87 const TypeTuple *StartOSRNode::osr_domain() {
duke@435 88 const Type **fields = TypeTuple::fields(2);
duke@435 89 fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM; // address of osr buffer
duke@435 90
duke@435 91 return TypeTuple::make(TypeFunc::Parms+1, fields);
duke@435 92 }
duke@435 93
duke@435 94 //=============================================================================
duke@435 95 const char * const ParmNode::names[TypeFunc::Parms+1] = {
duke@435 96 "Control", "I_O", "Memory", "FramePtr", "ReturnAdr", "Parms"
duke@435 97 };
duke@435 98
duke@435 99 #ifndef PRODUCT
duke@435 100 void ParmNode::dump_spec(outputStream *st) const {
duke@435 101 if( _con < TypeFunc::Parms ) {
duke@435 102 st->print(names[_con]);
duke@435 103 } else {
duke@435 104 st->print("Parm%d: ",_con-TypeFunc::Parms);
duke@435 105 // Verbose and WizardMode dump bottom_type for all nodes
duke@435 106 if( !Verbose && !WizardMode ) bottom_type()->dump_on(st);
duke@435 107 }
duke@435 108 }
duke@435 109 #endif
duke@435 110
duke@435 111 uint ParmNode::ideal_reg() const {
duke@435 112 switch( _con ) {
duke@435 113 case TypeFunc::Control : // fall through
duke@435 114 case TypeFunc::I_O : // fall through
duke@435 115 case TypeFunc::Memory : return 0;
duke@435 116 case TypeFunc::FramePtr : // fall through
duke@435 117 case TypeFunc::ReturnAdr: return Op_RegP;
duke@435 118 default : assert( _con > TypeFunc::Parms, "" );
duke@435 119 // fall through
duke@435 120 case TypeFunc::Parms : {
duke@435 121 // Type of argument being passed
duke@435 122 const Type *t = in(0)->as_Start()->_domain->field_at(_con);
duke@435 123 return Matcher::base2reg[t->base()];
duke@435 124 }
duke@435 125 }
duke@435 126 ShouldNotReachHere();
duke@435 127 return 0;
duke@435 128 }
duke@435 129
duke@435 130 //=============================================================================
duke@435 131 ReturnNode::ReturnNode(uint edges, Node *cntrl, Node *i_o, Node *memory, Node *frameptr, Node *retadr ) : Node(edges) {
duke@435 132 init_req(TypeFunc::Control,cntrl);
duke@435 133 init_req(TypeFunc::I_O,i_o);
duke@435 134 init_req(TypeFunc::Memory,memory);
duke@435 135 init_req(TypeFunc::FramePtr,frameptr);
duke@435 136 init_req(TypeFunc::ReturnAdr,retadr);
duke@435 137 }
duke@435 138
duke@435 139 Node *ReturnNode::Ideal(PhaseGVN *phase, bool can_reshape){
duke@435 140 return remove_dead_region(phase, can_reshape) ? this : NULL;
duke@435 141 }
duke@435 142
duke@435 143 const Type *ReturnNode::Value( PhaseTransform *phase ) const {
duke@435 144 return ( phase->type(in(TypeFunc::Control)) == Type::TOP)
duke@435 145 ? Type::TOP
duke@435 146 : Type::BOTTOM;
duke@435 147 }
duke@435 148
duke@435 149 // Do we Match on this edge index or not? No edges on return nodes
duke@435 150 uint ReturnNode::match_edge(uint idx) const {
duke@435 151 return 0;
duke@435 152 }
duke@435 153
duke@435 154
duke@435 155 #ifndef PRODUCT
duke@435 156 void ReturnNode::dump_req() const {
duke@435 157 // Dump the required inputs, enclosed in '(' and ')'
duke@435 158 uint i; // Exit value of loop
duke@435 159 for( i=0; i<req(); i++ ) { // For all required inputs
duke@435 160 if( i == TypeFunc::Parms ) tty->print("returns");
duke@435 161 if( in(i) ) tty->print("%c%d ", Compile::current()->node_arena()->contains(in(i)) ? ' ' : 'o', in(i)->_idx);
duke@435 162 else tty->print("_ ");
duke@435 163 }
duke@435 164 }
duke@435 165 #endif
duke@435 166
duke@435 167 //=============================================================================
duke@435 168 RethrowNode::RethrowNode(
duke@435 169 Node* cntrl,
duke@435 170 Node* i_o,
duke@435 171 Node* memory,
duke@435 172 Node* frameptr,
duke@435 173 Node* ret_adr,
duke@435 174 Node* exception
duke@435 175 ) : Node(TypeFunc::Parms + 1) {
duke@435 176 init_req(TypeFunc::Control , cntrl );
duke@435 177 init_req(TypeFunc::I_O , i_o );
duke@435 178 init_req(TypeFunc::Memory , memory );
duke@435 179 init_req(TypeFunc::FramePtr , frameptr );
duke@435 180 init_req(TypeFunc::ReturnAdr, ret_adr);
duke@435 181 init_req(TypeFunc::Parms , exception);
duke@435 182 }
duke@435 183
duke@435 184 Node *RethrowNode::Ideal(PhaseGVN *phase, bool can_reshape){
duke@435 185 return remove_dead_region(phase, can_reshape) ? this : NULL;
duke@435 186 }
duke@435 187
duke@435 188 const Type *RethrowNode::Value( PhaseTransform *phase ) const {
duke@435 189 return (phase->type(in(TypeFunc::Control)) == Type::TOP)
duke@435 190 ? Type::TOP
duke@435 191 : Type::BOTTOM;
duke@435 192 }
duke@435 193
duke@435 194 uint RethrowNode::match_edge(uint idx) const {
duke@435 195 return 0;
duke@435 196 }
duke@435 197
duke@435 198 #ifndef PRODUCT
duke@435 199 void RethrowNode::dump_req() const {
duke@435 200 // Dump the required inputs, enclosed in '(' and ')'
duke@435 201 uint i; // Exit value of loop
duke@435 202 for( i=0; i<req(); i++ ) { // For all required inputs
duke@435 203 if( i == TypeFunc::Parms ) tty->print("exception");
duke@435 204 if( in(i) ) tty->print("%c%d ", Compile::current()->node_arena()->contains(in(i)) ? ' ' : 'o', in(i)->_idx);
duke@435 205 else tty->print("_ ");
duke@435 206 }
duke@435 207 }
duke@435 208 #endif
duke@435 209
duke@435 210 //=============================================================================
duke@435 211 // Do we Match on this edge index or not? Match only target address & method
duke@435 212 uint TailCallNode::match_edge(uint idx) const {
duke@435 213 return TypeFunc::Parms <= idx && idx <= TypeFunc::Parms+1;
duke@435 214 }
duke@435 215
duke@435 216 //=============================================================================
duke@435 217 // Do we Match on this edge index or not? Match only target address & oop
duke@435 218 uint TailJumpNode::match_edge(uint idx) const {
duke@435 219 return TypeFunc::Parms <= idx && idx <= TypeFunc::Parms+1;
duke@435 220 }
duke@435 221
duke@435 222 //=============================================================================
duke@435 223 JVMState::JVMState(ciMethod* method, JVMState* caller) {
duke@435 224 assert(method != NULL, "must be valid call site");
duke@435 225 _method = method;
duke@435 226 debug_only(_bci = -99); // random garbage value
duke@435 227 debug_only(_map = (SafePointNode*)-1);
duke@435 228 _caller = caller;
duke@435 229 _depth = 1 + (caller == NULL ? 0 : caller->depth());
duke@435 230 _locoff = TypeFunc::Parms;
duke@435 231 _stkoff = _locoff + _method->max_locals();
duke@435 232 _monoff = _stkoff + _method->max_stack();
kvn@498 233 _scloff = _monoff;
duke@435 234 _endoff = _monoff;
duke@435 235 _sp = 0;
duke@435 236 }
duke@435 237 JVMState::JVMState(int stack_size) {
duke@435 238 _method = NULL;
duke@435 239 _bci = InvocationEntryBci;
duke@435 240 debug_only(_map = (SafePointNode*)-1);
duke@435 241 _caller = NULL;
duke@435 242 _depth = 1;
duke@435 243 _locoff = TypeFunc::Parms;
duke@435 244 _stkoff = _locoff;
duke@435 245 _monoff = _stkoff + stack_size;
kvn@498 246 _scloff = _monoff;
duke@435 247 _endoff = _monoff;
duke@435 248 _sp = 0;
duke@435 249 }
duke@435 250
duke@435 251 //--------------------------------of_depth-------------------------------------
duke@435 252 JVMState* JVMState::of_depth(int d) const {
duke@435 253 const JVMState* jvmp = this;
duke@435 254 assert(0 < d && (uint)d <= depth(), "oob");
duke@435 255 for (int skip = depth() - d; skip > 0; skip--) {
duke@435 256 jvmp = jvmp->caller();
duke@435 257 }
duke@435 258 assert(jvmp->depth() == (uint)d, "found the right one");
duke@435 259 return (JVMState*)jvmp;
duke@435 260 }
duke@435 261
duke@435 262 //-----------------------------same_calls_as-----------------------------------
duke@435 263 bool JVMState::same_calls_as(const JVMState* that) const {
duke@435 264 if (this == that) return true;
duke@435 265 if (this->depth() != that->depth()) return false;
duke@435 266 const JVMState* p = this;
duke@435 267 const JVMState* q = that;
duke@435 268 for (;;) {
duke@435 269 if (p->_method != q->_method) return false;
duke@435 270 if (p->_method == NULL) return true; // bci is irrelevant
duke@435 271 if (p->_bci != q->_bci) return false;
duke@435 272 p = p->caller();
duke@435 273 q = q->caller();
duke@435 274 if (p == q) return true;
duke@435 275 assert(p != NULL && q != NULL, "depth check ensures we don't run off end");
duke@435 276 }
duke@435 277 }
duke@435 278
duke@435 279 //------------------------------debug_start------------------------------------
duke@435 280 uint JVMState::debug_start() const {
duke@435 281 debug_only(JVMState* jvmroot = of_depth(1));
duke@435 282 assert(jvmroot->locoff() <= this->locoff(), "youngest JVMState must be last");
duke@435 283 return of_depth(1)->locoff();
duke@435 284 }
duke@435 285
duke@435 286 //-------------------------------debug_end-------------------------------------
duke@435 287 uint JVMState::debug_end() const {
duke@435 288 debug_only(JVMState* jvmroot = of_depth(1));
duke@435 289 assert(jvmroot->endoff() <= this->endoff(), "youngest JVMState must be last");
duke@435 290 return endoff();
duke@435 291 }
duke@435 292
duke@435 293 //------------------------------debug_depth------------------------------------
duke@435 294 uint JVMState::debug_depth() const {
duke@435 295 uint total = 0;
duke@435 296 for (const JVMState* jvmp = this; jvmp != NULL; jvmp = jvmp->caller()) {
duke@435 297 total += jvmp->debug_size();
duke@435 298 }
duke@435 299 return total;
duke@435 300 }
duke@435 301
kvn@498 302 #ifndef PRODUCT
kvn@498 303
duke@435 304 //------------------------------format_helper----------------------------------
duke@435 305 // Given an allocation (a Chaitin object) and a Node decide if the Node carries
duke@435 306 // any defined value or not. If it does, print out the register or constant.
kvn@498 307 static void format_helper( PhaseRegAlloc *regalloc, outputStream* st, Node *n, const char *msg, uint i, GrowableArray<SafePointScalarObjectNode*> *scobjs ) {
duke@435 308 if (n == NULL) { st->print(" NULL"); return; }
kvn@498 309 if (n->is_SafePointScalarObject()) {
kvn@498 310 // Scalar replacement.
kvn@498 311 SafePointScalarObjectNode* spobj = n->as_SafePointScalarObject();
kvn@498 312 scobjs->append_if_missing(spobj);
kvn@498 313 int sco_n = scobjs->find(spobj);
kvn@498 314 assert(sco_n >= 0, "");
kvn@498 315 st->print(" %s%d]=#ScObj" INT32_FORMAT, msg, i, sco_n);
kvn@498 316 return;
kvn@498 317 }
duke@435 318 if( OptoReg::is_valid(regalloc->get_reg_first(n))) { // Check for undefined
duke@435 319 char buf[50];
duke@435 320 regalloc->dump_register(n,buf);
duke@435 321 st->print(" %s%d]=%s",msg,i,buf);
duke@435 322 } else { // No register, but might be constant
duke@435 323 const Type *t = n->bottom_type();
duke@435 324 switch (t->base()) {
duke@435 325 case Type::Int:
duke@435 326 st->print(" %s%d]=#"INT32_FORMAT,msg,i,t->is_int()->get_con());
duke@435 327 break;
duke@435 328 case Type::AnyPtr:
duke@435 329 assert( t == TypePtr::NULL_PTR, "" );
duke@435 330 st->print(" %s%d]=#NULL",msg,i);
duke@435 331 break;
duke@435 332 case Type::AryPtr:
duke@435 333 case Type::KlassPtr:
duke@435 334 case Type::InstPtr:
duke@435 335 st->print(" %s%d]=#Ptr" INTPTR_FORMAT,msg,i,t->isa_oopptr()->const_oop());
duke@435 336 break;
duke@435 337 case Type::RawPtr:
duke@435 338 st->print(" %s%d]=#Raw" INTPTR_FORMAT,msg,i,t->is_rawptr());
duke@435 339 break;
duke@435 340 case Type::DoubleCon:
duke@435 341 st->print(" %s%d]=#%fD",msg,i,t->is_double_constant()->_d);
duke@435 342 break;
duke@435 343 case Type::FloatCon:
duke@435 344 st->print(" %s%d]=#%fF",msg,i,t->is_float_constant()->_f);
duke@435 345 break;
duke@435 346 case Type::Long:
duke@435 347 st->print(" %s%d]=#"INT64_FORMAT,msg,i,t->is_long()->get_con());
duke@435 348 break;
duke@435 349 case Type::Half:
duke@435 350 case Type::Top:
duke@435 351 st->print(" %s%d]=_",msg,i);
duke@435 352 break;
duke@435 353 default: ShouldNotReachHere();
duke@435 354 }
duke@435 355 }
duke@435 356 }
duke@435 357
duke@435 358 //------------------------------format-----------------------------------------
duke@435 359 void JVMState::format(PhaseRegAlloc *regalloc, const Node *n, outputStream* st) const {
duke@435 360 st->print(" #");
duke@435 361 if( _method ) {
duke@435 362 _method->print_short_name(st);
duke@435 363 st->print(" @ bci:%d ",_bci);
duke@435 364 } else {
duke@435 365 st->print_cr(" runtime stub ");
duke@435 366 return;
duke@435 367 }
duke@435 368 if (n->is_MachSafePoint()) {
kvn@498 369 GrowableArray<SafePointScalarObjectNode*> scobjs;
duke@435 370 MachSafePointNode *mcall = n->as_MachSafePoint();
duke@435 371 uint i;
duke@435 372 // Print locals
duke@435 373 for( i = 0; i < (uint)loc_size(); i++ )
kvn@498 374 format_helper( regalloc, st, mcall->local(this, i), "L[", i, &scobjs );
duke@435 375 // Print stack
duke@435 376 for (i = 0; i < (uint)stk_size(); i++) {
duke@435 377 if ((uint)(_stkoff + i) >= mcall->len())
duke@435 378 st->print(" oob ");
duke@435 379 else
kvn@498 380 format_helper( regalloc, st, mcall->stack(this, i), "STK[", i, &scobjs );
duke@435 381 }
duke@435 382 for (i = 0; (int)i < nof_monitors(); i++) {
duke@435 383 Node *box = mcall->monitor_box(this, i);
duke@435 384 Node *obj = mcall->monitor_obj(this, i);
duke@435 385 if ( OptoReg::is_valid(regalloc->get_reg_first(box)) ) {
duke@435 386 while( !box->is_BoxLock() ) box = box->in(1);
kvn@498 387 format_helper( regalloc, st, box, "MON-BOX[", i, &scobjs );
duke@435 388 } else {
duke@435 389 OptoReg::Name box_reg = BoxLockNode::stack_slot(box);
duke@435 390 st->print(" MON-BOX%d=%s+%d",
duke@435 391 i,
duke@435 392 OptoReg::regname(OptoReg::c_frame_pointer),
duke@435 393 regalloc->reg2offset(box_reg));
duke@435 394 }
kvn@498 395 format_helper( regalloc, st, obj, "MON-OBJ[", i, &scobjs );
kvn@498 396 }
kvn@498 397
kvn@498 398 for (i = 0; i < (uint)scobjs.length(); i++) {
kvn@498 399 // Scalar replaced objects.
kvn@498 400 st->print_cr("");
kvn@498 401 st->print(" # ScObj" INT32_FORMAT " ", i);
kvn@498 402 SafePointScalarObjectNode* spobj = scobjs.at(i);
kvn@498 403 ciKlass* cik = spobj->bottom_type()->is_oopptr()->klass();
kvn@498 404 assert(cik->is_instance_klass() ||
kvn@498 405 cik->is_array_klass(), "Not supported allocation.");
kvn@498 406 ciInstanceKlass *iklass = NULL;
kvn@498 407 if (cik->is_instance_klass()) {
kvn@498 408 cik->print_name_on(st);
kvn@498 409 iklass = cik->as_instance_klass();
kvn@498 410 } else if (cik->is_type_array_klass()) {
kvn@498 411 cik->as_array_klass()->base_element_type()->print_name_on(st);
kvn@498 412 st->print("[%d]=", spobj->n_fields());
kvn@498 413 } else if (cik->is_obj_array_klass()) {
kvn@498 414 ciType* cie = cik->as_array_klass()->base_element_type();
kvn@498 415 int ndim = 1;
kvn@498 416 while (cie->is_obj_array_klass()) {
kvn@498 417 ndim += 1;
kvn@498 418 cie = cie->as_array_klass()->base_element_type();
kvn@498 419 }
kvn@498 420 cie->print_name_on(st);
kvn@498 421 while (ndim-- > 0) {
kvn@498 422 st->print("[]");
kvn@498 423 }
kvn@498 424 st->print("[%d]=", spobj->n_fields());
kvn@498 425 }
kvn@498 426 st->print("{");
kvn@498 427 uint nf = spobj->n_fields();
kvn@498 428 if (nf > 0) {
kvn@498 429 uint first_ind = spobj->first_index();
kvn@498 430 Node* fld_node = mcall->in(first_ind);
kvn@498 431 ciField* cifield;
kvn@498 432 if (iklass != NULL) {
kvn@498 433 st->print(" [");
kvn@498 434 cifield = iklass->nonstatic_field_at(0);
kvn@498 435 cifield->print_name_on(st);
kvn@498 436 format_helper( regalloc, st, fld_node, ":", 0, &scobjs );
kvn@498 437 } else {
kvn@498 438 format_helper( regalloc, st, fld_node, "[", 0, &scobjs );
kvn@498 439 }
kvn@498 440 for (uint j = 1; j < nf; j++) {
kvn@498 441 fld_node = mcall->in(first_ind+j);
kvn@498 442 if (iklass != NULL) {
kvn@498 443 st->print(", [");
kvn@498 444 cifield = iklass->nonstatic_field_at(j);
kvn@498 445 cifield->print_name_on(st);
kvn@498 446 format_helper( regalloc, st, fld_node, ":", j, &scobjs );
kvn@498 447 } else {
kvn@498 448 format_helper( regalloc, st, fld_node, ", [", j, &scobjs );
kvn@498 449 }
kvn@498 450 }
kvn@498 451 }
kvn@498 452 st->print(" }");
duke@435 453 }
duke@435 454 }
duke@435 455 st->print_cr("");
duke@435 456 if (caller() != NULL) caller()->format(regalloc, n, st);
duke@435 457 }
duke@435 458
kvn@498 459
duke@435 460 void JVMState::dump_spec(outputStream *st) const {
duke@435 461 if (_method != NULL) {
duke@435 462 bool printed = false;
duke@435 463 if (!Verbose) {
duke@435 464 // The JVMS dumps make really, really long lines.
duke@435 465 // Take out the most boring parts, which are the package prefixes.
duke@435 466 char buf[500];
duke@435 467 stringStream namest(buf, sizeof(buf));
duke@435 468 _method->print_short_name(&namest);
duke@435 469 if (namest.count() < sizeof(buf)) {
duke@435 470 const char* name = namest.base();
duke@435 471 if (name[0] == ' ') ++name;
duke@435 472 const char* endcn = strchr(name, ':'); // end of class name
duke@435 473 if (endcn == NULL) endcn = strchr(name, '(');
duke@435 474 if (endcn == NULL) endcn = name + strlen(name);
duke@435 475 while (endcn > name && endcn[-1] != '.' && endcn[-1] != '/')
duke@435 476 --endcn;
duke@435 477 st->print(" %s", endcn);
duke@435 478 printed = true;
duke@435 479 }
duke@435 480 }
duke@435 481 if (!printed)
duke@435 482 _method->print_short_name(st);
duke@435 483 st->print(" @ bci:%d",_bci);
duke@435 484 } else {
duke@435 485 st->print(" runtime stub");
duke@435 486 }
duke@435 487 if (caller() != NULL) caller()->dump_spec(st);
duke@435 488 }
duke@435 489
kvn@498 490
duke@435 491 void JVMState::dump_on(outputStream* st) const {
duke@435 492 if (_map && !((uintptr_t)_map & 1)) {
duke@435 493 if (_map->len() > _map->req()) { // _map->has_exceptions()
duke@435 494 Node* ex = _map->in(_map->req()); // _map->next_exception()
duke@435 495 // skip the first one; it's already being printed
duke@435 496 while (ex != NULL && ex->len() > ex->req()) {
duke@435 497 ex = ex->in(ex->req()); // ex->next_exception()
duke@435 498 ex->dump(1);
duke@435 499 }
duke@435 500 }
duke@435 501 _map->dump(2);
duke@435 502 }
kvn@498 503 st->print("JVMS depth=%d loc=%d stk=%d mon=%d scalar=%d end=%d mondepth=%d sp=%d bci=%d method=",
kvn@498 504 depth(), locoff(), stkoff(), monoff(), scloff(), endoff(), monitor_depth(), sp(), bci());
duke@435 505 if (_method == NULL) {
duke@435 506 st->print_cr("(none)");
duke@435 507 } else {
duke@435 508 _method->print_name(st);
duke@435 509 st->cr();
duke@435 510 if (bci() >= 0 && bci() < _method->code_size()) {
duke@435 511 st->print(" bc: ");
duke@435 512 _method->print_codes_on(bci(), bci()+1, st);
duke@435 513 }
duke@435 514 }
duke@435 515 if (caller() != NULL) {
duke@435 516 caller()->dump_on(st);
duke@435 517 }
duke@435 518 }
duke@435 519
duke@435 520 // Extra way to dump a jvms from the debugger,
duke@435 521 // to avoid a bug with C++ member function calls.
duke@435 522 void dump_jvms(JVMState* jvms) {
duke@435 523 jvms->dump();
duke@435 524 }
duke@435 525 #endif
duke@435 526
duke@435 527 //--------------------------clone_shallow--------------------------------------
duke@435 528 JVMState* JVMState::clone_shallow(Compile* C) const {
duke@435 529 JVMState* n = has_method() ? new (C) JVMState(_method, _caller) : new (C) JVMState(0);
duke@435 530 n->set_bci(_bci);
duke@435 531 n->set_locoff(_locoff);
duke@435 532 n->set_stkoff(_stkoff);
duke@435 533 n->set_monoff(_monoff);
kvn@498 534 n->set_scloff(_scloff);
duke@435 535 n->set_endoff(_endoff);
duke@435 536 n->set_sp(_sp);
duke@435 537 n->set_map(_map);
duke@435 538 return n;
duke@435 539 }
duke@435 540
duke@435 541 //---------------------------clone_deep----------------------------------------
duke@435 542 JVMState* JVMState::clone_deep(Compile* C) const {
duke@435 543 JVMState* n = clone_shallow(C);
duke@435 544 for (JVMState* p = n; p->_caller != NULL; p = p->_caller) {
duke@435 545 p->_caller = p->_caller->clone_shallow(C);
duke@435 546 }
duke@435 547 assert(n->depth() == depth(), "sanity");
duke@435 548 assert(n->debug_depth() == debug_depth(), "sanity");
duke@435 549 return n;
duke@435 550 }
duke@435 551
duke@435 552 //=============================================================================
duke@435 553 uint CallNode::cmp( const Node &n ) const
duke@435 554 { return _tf == ((CallNode&)n)._tf && _jvms == ((CallNode&)n)._jvms; }
duke@435 555 #ifndef PRODUCT
duke@435 556 void CallNode::dump_req() const {
duke@435 557 // Dump the required inputs, enclosed in '(' and ')'
duke@435 558 uint i; // Exit value of loop
duke@435 559 for( i=0; i<req(); i++ ) { // For all required inputs
duke@435 560 if( i == TypeFunc::Parms ) tty->print("(");
duke@435 561 if( in(i) ) tty->print("%c%d ", Compile::current()->node_arena()->contains(in(i)) ? ' ' : 'o', in(i)->_idx);
duke@435 562 else tty->print("_ ");
duke@435 563 }
duke@435 564 tty->print(")");
duke@435 565 }
duke@435 566
duke@435 567 void CallNode::dump_spec(outputStream *st) const {
duke@435 568 st->print(" ");
duke@435 569 tf()->dump_on(st);
duke@435 570 if (_cnt != COUNT_UNKNOWN) st->print(" C=%f",_cnt);
duke@435 571 if (jvms() != NULL) jvms()->dump_spec(st);
duke@435 572 }
duke@435 573 #endif
duke@435 574
duke@435 575 const Type *CallNode::bottom_type() const { return tf()->range(); }
duke@435 576 const Type *CallNode::Value(PhaseTransform *phase) const {
duke@435 577 if (phase->type(in(0)) == Type::TOP) return Type::TOP;
duke@435 578 return tf()->range();
duke@435 579 }
duke@435 580
duke@435 581 //------------------------------calling_convention-----------------------------
duke@435 582 void CallNode::calling_convention( BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt ) const {
duke@435 583 // Use the standard compiler calling convention
duke@435 584 Matcher::calling_convention( sig_bt, parm_regs, argcnt, true );
duke@435 585 }
duke@435 586
duke@435 587
duke@435 588 //------------------------------match------------------------------------------
duke@435 589 // Construct projections for control, I/O, memory-fields, ..., and
duke@435 590 // return result(s) along with their RegMask info
duke@435 591 Node *CallNode::match( const ProjNode *proj, const Matcher *match ) {
duke@435 592 switch (proj->_con) {
duke@435 593 case TypeFunc::Control:
duke@435 594 case TypeFunc::I_O:
duke@435 595 case TypeFunc::Memory:
duke@435 596 return new (match->C, 1) MachProjNode(this,proj->_con,RegMask::Empty,MachProjNode::unmatched_proj);
duke@435 597
duke@435 598 case TypeFunc::Parms+1: // For LONG & DOUBLE returns
duke@435 599 assert(tf()->_range->field_at(TypeFunc::Parms+1) == Type::HALF, "");
duke@435 600 // 2nd half of doubles and longs
duke@435 601 return new (match->C, 1) MachProjNode(this,proj->_con, RegMask::Empty, (uint)OptoReg::Bad);
duke@435 602
duke@435 603 case TypeFunc::Parms: { // Normal returns
duke@435 604 uint ideal_reg = Matcher::base2reg[tf()->range()->field_at(TypeFunc::Parms)->base()];
duke@435 605 OptoRegPair regs = is_CallRuntime()
duke@435 606 ? match->c_return_value(ideal_reg,true) // Calls into C runtime
duke@435 607 : match-> return_value(ideal_reg,true); // Calls into compiled Java code
duke@435 608 RegMask rm = RegMask(regs.first());
duke@435 609 if( OptoReg::is_valid(regs.second()) )
duke@435 610 rm.Insert( regs.second() );
duke@435 611 return new (match->C, 1) MachProjNode(this,proj->_con,rm,ideal_reg);
duke@435 612 }
duke@435 613
duke@435 614 case TypeFunc::ReturnAdr:
duke@435 615 case TypeFunc::FramePtr:
duke@435 616 default:
duke@435 617 ShouldNotReachHere();
duke@435 618 }
duke@435 619 return NULL;
duke@435 620 }
duke@435 621
duke@435 622 // Do we Match on this edge index or not? Match no edges
duke@435 623 uint CallNode::match_edge(uint idx) const {
duke@435 624 return 0;
duke@435 625 }
duke@435 626
kvn@500 627 //
kvn@509 628 // Determine whether the call could modify the field of the specified
kvn@509 629 // instance at the specified offset.
kvn@500 630 //
kvn@500 631 bool CallNode::may_modify(const TypePtr *addr_t, PhaseTransform *phase) {
kvn@500 632 const TypeOopPtr *adrInst_t = addr_t->isa_oopptr();
kvn@500 633
kvn@500 634 // if not an InstPtr or not an instance type, assume the worst
kvn@500 635 if (adrInst_t == NULL || !adrInst_t->is_instance_field()) {
kvn@500 636 return true;
kvn@500 637 }
kvn@500 638 Compile *C = phase->C;
kvn@500 639 int offset = adrInst_t->offset();
kvn@500 640 assert(offset >= 0, "should be valid offset");
kvn@509 641 ciKlass* adr_k = adrInst_t->klass();
kvn@509 642 assert(adr_k->is_loaded() &&
kvn@509 643 adr_k->is_java_klass() &&
kvn@509 644 !adr_k->is_interface(),
kvn@509 645 "only non-abstract classes are expected");
kvn@500 646
kvn@500 647 int base_idx = C->get_alias_index(adrInst_t);
kvn@509 648 int size = BytesPerLong; // If we don't know the size, assume largest.
kvn@509 649 if (adrInst_t->isa_instptr()) {
kvn@509 650 ciField* field = C->alias_type(base_idx)->field();
kvn@509 651 if (field != NULL) {
kvn@509 652 size = field->size_in_bytes();
kvn@509 653 }
kvn@509 654 } else {
kvn@509 655 assert(adrInst_t->isa_aryptr(), "only arrays are expected");
kvn@509 656 size = type2aelembytes(adr_k->as_array_klass()->element_type()->basic_type());
kvn@509 657 }
kvn@509 658
kvn@500 659 ciMethod * meth = is_CallStaticJava() ? as_CallStaticJava()->method() : NULL;
kvn@500 660 BCEscapeAnalyzer *bcea = (meth != NULL) ? meth->get_bcea() : NULL;
kvn@500 661
kvn@500 662 const TypeTuple * d = tf()->domain();
kvn@500 663 for (uint i = TypeFunc::Parms; i < d->cnt(); i++) {
kvn@500 664 const Type* t = d->field_at(i);
kvn@500 665 Node *arg = in(i);
kvn@500 666 const Type *at = phase->type(arg);
kvn@500 667 if (at == TypePtr::NULL_PTR || at == Type::TOP)
kvn@500 668 continue; // null can't affect anything
kvn@500 669
kvn@500 670 const TypeOopPtr *at_ptr = at->isa_oopptr();
kvn@500 671 if (!arg->is_top() && (t->isa_oopptr() != NULL ||
kvn@500 672 t->isa_ptr() && at_ptr != NULL)) {
kvn@500 673 assert(at_ptr != NULL, "expecting an OopPtr");
kvn@509 674 ciKlass* at_k = at_ptr->klass();
kvn@509 675 if ((adrInst_t->base() == at_ptr->base()) &&
kvn@509 676 at_k->is_loaded() &&
kvn@509 677 at_k->is_java_klass() &&
kvn@509 678 !at_k->is_interface()) {
kvn@509 679 // If we have found an argument matching addr_t, check if the field
kvn@509 680 // at the specified offset is modified.
kvn@509 681 int at_idx = C->get_alias_index(at_ptr->add_offset(offset)->isa_oopptr());
kvn@509 682 if (base_idx == at_idx &&
kvn@509 683 (bcea == NULL ||
kvn@509 684 bcea->is_arg_modified(i - TypeFunc::Parms, offset, size))) {
kvn@509 685 return true;
kvn@509 686 }
kvn@500 687 }
kvn@500 688 }
kvn@500 689 }
kvn@500 690 return false;
kvn@500 691 }
kvn@500 692
kvn@500 693 // Does this call have a direct reference to n other than debug information?
kvn@500 694 bool CallNode::has_non_debug_use(Node *n) {
kvn@500 695 const TypeTuple * d = tf()->domain();
kvn@500 696 for (uint i = TypeFunc::Parms; i < d->cnt(); i++) {
kvn@500 697 Node *arg = in(i);
kvn@500 698 if (arg == n) {
kvn@500 699 return true;
kvn@500 700 }
kvn@500 701 }
kvn@500 702 return false;
kvn@500 703 }
kvn@500 704
kvn@500 705 // Returns the unique CheckCastPP of a call
kvn@500 706 // or 'this' if there are several CheckCastPP
kvn@500 707 // or returns NULL if there is no one.
kvn@500 708 Node *CallNode::result_cast() {
kvn@500 709 Node *cast = NULL;
kvn@500 710
kvn@500 711 Node *p = proj_out(TypeFunc::Parms);
kvn@500 712 if (p == NULL)
kvn@500 713 return NULL;
kvn@500 714
kvn@500 715 for (DUIterator_Fast imax, i = p->fast_outs(imax); i < imax; i++) {
kvn@500 716 Node *use = p->fast_out(i);
kvn@500 717 if (use->is_CheckCastPP()) {
kvn@500 718 if (cast != NULL) {
kvn@500 719 return this; // more than 1 CheckCastPP
kvn@500 720 }
kvn@500 721 cast = use;
kvn@500 722 }
kvn@500 723 }
kvn@500 724 return cast;
kvn@500 725 }
kvn@500 726
kvn@500 727
duke@435 728 //=============================================================================
duke@435 729 uint CallJavaNode::size_of() const { return sizeof(*this); }
duke@435 730 uint CallJavaNode::cmp( const Node &n ) const {
duke@435 731 CallJavaNode &call = (CallJavaNode&)n;
duke@435 732 return CallNode::cmp(call) && _method == call._method;
duke@435 733 }
duke@435 734 #ifndef PRODUCT
duke@435 735 void CallJavaNode::dump_spec(outputStream *st) const {
duke@435 736 if( _method ) _method->print_short_name(st);
duke@435 737 CallNode::dump_spec(st);
duke@435 738 }
duke@435 739 #endif
duke@435 740
duke@435 741 //=============================================================================
duke@435 742 uint CallStaticJavaNode::size_of() const { return sizeof(*this); }
duke@435 743 uint CallStaticJavaNode::cmp( const Node &n ) const {
duke@435 744 CallStaticJavaNode &call = (CallStaticJavaNode&)n;
duke@435 745 return CallJavaNode::cmp(call);
duke@435 746 }
duke@435 747
duke@435 748 //----------------------------uncommon_trap_request----------------------------
duke@435 749 // If this is an uncommon trap, return the request code, else zero.
duke@435 750 int CallStaticJavaNode::uncommon_trap_request() const {
duke@435 751 if (_name != NULL && !strcmp(_name, "uncommon_trap")) {
duke@435 752 return extract_uncommon_trap_request(this);
duke@435 753 }
duke@435 754 return 0;
duke@435 755 }
duke@435 756 int CallStaticJavaNode::extract_uncommon_trap_request(const Node* call) {
duke@435 757 #ifndef PRODUCT
duke@435 758 if (!(call->req() > TypeFunc::Parms &&
duke@435 759 call->in(TypeFunc::Parms) != NULL &&
duke@435 760 call->in(TypeFunc::Parms)->is_Con())) {
duke@435 761 assert(_in_dump_cnt != 0, "OK if dumping");
duke@435 762 tty->print("[bad uncommon trap]");
duke@435 763 return 0;
duke@435 764 }
duke@435 765 #endif
duke@435 766 return call->in(TypeFunc::Parms)->bottom_type()->is_int()->get_con();
duke@435 767 }
duke@435 768
duke@435 769 #ifndef PRODUCT
duke@435 770 void CallStaticJavaNode::dump_spec(outputStream *st) const {
duke@435 771 st->print("# Static ");
duke@435 772 if (_name != NULL) {
duke@435 773 st->print("%s", _name);
duke@435 774 int trap_req = uncommon_trap_request();
duke@435 775 if (trap_req != 0) {
duke@435 776 char buf[100];
duke@435 777 st->print("(%s)",
duke@435 778 Deoptimization::format_trap_request(buf, sizeof(buf),
duke@435 779 trap_req));
duke@435 780 }
duke@435 781 st->print(" ");
duke@435 782 }
duke@435 783 CallJavaNode::dump_spec(st);
duke@435 784 }
duke@435 785 #endif
duke@435 786
duke@435 787 //=============================================================================
duke@435 788 uint CallDynamicJavaNode::size_of() const { return sizeof(*this); }
duke@435 789 uint CallDynamicJavaNode::cmp( const Node &n ) const {
duke@435 790 CallDynamicJavaNode &call = (CallDynamicJavaNode&)n;
duke@435 791 return CallJavaNode::cmp(call);
duke@435 792 }
duke@435 793 #ifndef PRODUCT
duke@435 794 void CallDynamicJavaNode::dump_spec(outputStream *st) const {
duke@435 795 st->print("# Dynamic ");
duke@435 796 CallJavaNode::dump_spec(st);
duke@435 797 }
duke@435 798 #endif
duke@435 799
duke@435 800 //=============================================================================
duke@435 801 uint CallRuntimeNode::size_of() const { return sizeof(*this); }
duke@435 802 uint CallRuntimeNode::cmp( const Node &n ) const {
duke@435 803 CallRuntimeNode &call = (CallRuntimeNode&)n;
duke@435 804 return CallNode::cmp(call) && !strcmp(_name,call._name);
duke@435 805 }
duke@435 806 #ifndef PRODUCT
duke@435 807 void CallRuntimeNode::dump_spec(outputStream *st) const {
duke@435 808 st->print("# ");
duke@435 809 st->print(_name);
duke@435 810 CallNode::dump_spec(st);
duke@435 811 }
duke@435 812 #endif
duke@435 813
duke@435 814 //------------------------------calling_convention-----------------------------
duke@435 815 void CallRuntimeNode::calling_convention( BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt ) const {
duke@435 816 Matcher::c_calling_convention( sig_bt, parm_regs, argcnt );
duke@435 817 }
duke@435 818
duke@435 819 //=============================================================================
duke@435 820 //------------------------------calling_convention-----------------------------
duke@435 821
duke@435 822
duke@435 823 //=============================================================================
duke@435 824 #ifndef PRODUCT
duke@435 825 void CallLeafNode::dump_spec(outputStream *st) const {
duke@435 826 st->print("# ");
duke@435 827 st->print(_name);
duke@435 828 CallNode::dump_spec(st);
duke@435 829 }
duke@435 830 #endif
duke@435 831
duke@435 832 //=============================================================================
duke@435 833
duke@435 834 void SafePointNode::set_local(JVMState* jvms, uint idx, Node *c) {
duke@435 835 assert(verify_jvms(jvms), "jvms must match");
duke@435 836 int loc = jvms->locoff() + idx;
duke@435 837 if (in(loc)->is_top() && idx > 0 && !c->is_top() ) {
duke@435 838 // If current local idx is top then local idx - 1 could
duke@435 839 // be a long/double that needs to be killed since top could
duke@435 840 // represent the 2nd half ofthe long/double.
duke@435 841 uint ideal = in(loc -1)->ideal_reg();
duke@435 842 if (ideal == Op_RegD || ideal == Op_RegL) {
duke@435 843 // set other (low index) half to top
duke@435 844 set_req(loc - 1, in(loc));
duke@435 845 }
duke@435 846 }
duke@435 847 set_req(loc, c);
duke@435 848 }
duke@435 849
duke@435 850 uint SafePointNode::size_of() const { return sizeof(*this); }
duke@435 851 uint SafePointNode::cmp( const Node &n ) const {
duke@435 852 return (&n == this); // Always fail except on self
duke@435 853 }
duke@435 854
duke@435 855 //-------------------------set_next_exception----------------------------------
duke@435 856 void SafePointNode::set_next_exception(SafePointNode* n) {
duke@435 857 assert(n == NULL || n->Opcode() == Op_SafePoint, "correct value for next_exception");
duke@435 858 if (len() == req()) {
duke@435 859 if (n != NULL) add_prec(n);
duke@435 860 } else {
duke@435 861 set_prec(req(), n);
duke@435 862 }
duke@435 863 }
duke@435 864
duke@435 865
duke@435 866 //----------------------------next_exception-----------------------------------
duke@435 867 SafePointNode* SafePointNode::next_exception() const {
duke@435 868 if (len() == req()) {
duke@435 869 return NULL;
duke@435 870 } else {
duke@435 871 Node* n = in(req());
duke@435 872 assert(n == NULL || n->Opcode() == Op_SafePoint, "no other uses of prec edges");
duke@435 873 return (SafePointNode*) n;
duke@435 874 }
duke@435 875 }
duke@435 876
duke@435 877
duke@435 878 //------------------------------Ideal------------------------------------------
duke@435 879 // Skip over any collapsed Regions
duke@435 880 Node *SafePointNode::Ideal(PhaseGVN *phase, bool can_reshape) {
duke@435 881 if (remove_dead_region(phase, can_reshape)) return this;
duke@435 882
duke@435 883 return NULL;
duke@435 884 }
duke@435 885
duke@435 886 //------------------------------Identity---------------------------------------
duke@435 887 // Remove obviously duplicate safepoints
duke@435 888 Node *SafePointNode::Identity( PhaseTransform *phase ) {
duke@435 889
duke@435 890 // If you have back to back safepoints, remove one
duke@435 891 if( in(TypeFunc::Control)->is_SafePoint() )
duke@435 892 return in(TypeFunc::Control);
duke@435 893
duke@435 894 if( in(0)->is_Proj() ) {
duke@435 895 Node *n0 = in(0)->in(0);
duke@435 896 // Check if he is a call projection (except Leaf Call)
duke@435 897 if( n0->is_Catch() ) {
duke@435 898 n0 = n0->in(0)->in(0);
duke@435 899 assert( n0->is_Call(), "expect a call here" );
duke@435 900 }
duke@435 901 if( n0->is_Call() && n0->as_Call()->guaranteed_safepoint() ) {
duke@435 902 // Useless Safepoint, so remove it
duke@435 903 return in(TypeFunc::Control);
duke@435 904 }
duke@435 905 }
duke@435 906
duke@435 907 return this;
duke@435 908 }
duke@435 909
duke@435 910 //------------------------------Value------------------------------------------
duke@435 911 const Type *SafePointNode::Value( PhaseTransform *phase ) const {
duke@435 912 if( phase->type(in(0)) == Type::TOP ) return Type::TOP;
duke@435 913 if( phase->eqv( in(0), this ) ) return Type::TOP; // Dead infinite loop
duke@435 914 return Type::CONTROL;
duke@435 915 }
duke@435 916
duke@435 917 #ifndef PRODUCT
duke@435 918 void SafePointNode::dump_spec(outputStream *st) const {
duke@435 919 st->print(" SafePoint ");
duke@435 920 }
duke@435 921 #endif
duke@435 922
duke@435 923 const RegMask &SafePointNode::in_RegMask(uint idx) const {
duke@435 924 if( idx < TypeFunc::Parms ) return RegMask::Empty;
duke@435 925 // Values outside the domain represent debug info
duke@435 926 return *(Compile::current()->matcher()->idealreg2debugmask[in(idx)->ideal_reg()]);
duke@435 927 }
duke@435 928 const RegMask &SafePointNode::out_RegMask() const {
duke@435 929 return RegMask::Empty;
duke@435 930 }
duke@435 931
duke@435 932
duke@435 933 void SafePointNode::grow_stack(JVMState* jvms, uint grow_by) {
duke@435 934 assert((int)grow_by > 0, "sanity");
duke@435 935 int monoff = jvms->monoff();
kvn@498 936 int scloff = jvms->scloff();
duke@435 937 int endoff = jvms->endoff();
duke@435 938 assert(endoff == (int)req(), "no other states or debug info after me");
duke@435 939 Node* top = Compile::current()->top();
duke@435 940 for (uint i = 0; i < grow_by; i++) {
duke@435 941 ins_req(monoff, top);
duke@435 942 }
duke@435 943 jvms->set_monoff(monoff + grow_by);
kvn@498 944 jvms->set_scloff(scloff + grow_by);
duke@435 945 jvms->set_endoff(endoff + grow_by);
duke@435 946 }
duke@435 947
duke@435 948 void SafePointNode::push_monitor(const FastLockNode *lock) {
duke@435 949 // Add a LockNode, which points to both the original BoxLockNode (the
duke@435 950 // stack space for the monitor) and the Object being locked.
duke@435 951 const int MonitorEdges = 2;
duke@435 952 assert(JVMState::logMonitorEdges == exact_log2(MonitorEdges), "correct MonitorEdges");
duke@435 953 assert(req() == jvms()->endoff(), "correct sizing");
kvn@498 954 int nextmon = jvms()->scloff();
duke@435 955 if (GenerateSynchronizationCode) {
duke@435 956 add_req(lock->box_node());
duke@435 957 add_req(lock->obj_node());
duke@435 958 } else {
duke@435 959 add_req(NULL);
duke@435 960 add_req(NULL);
duke@435 961 }
kvn@498 962 jvms()->set_scloff(nextmon+MonitorEdges);
duke@435 963 jvms()->set_endoff(req());
duke@435 964 }
duke@435 965
duke@435 966 void SafePointNode::pop_monitor() {
duke@435 967 // Delete last monitor from debug info
duke@435 968 debug_only(int num_before_pop = jvms()->nof_monitors());
duke@435 969 const int MonitorEdges = (1<<JVMState::logMonitorEdges);
kvn@498 970 int scloff = jvms()->scloff();
duke@435 971 int endoff = jvms()->endoff();
kvn@498 972 int new_scloff = scloff - MonitorEdges;
duke@435 973 int new_endoff = endoff - MonitorEdges;
kvn@498 974 jvms()->set_scloff(new_scloff);
duke@435 975 jvms()->set_endoff(new_endoff);
kvn@498 976 while (scloff > new_scloff) del_req(--scloff);
duke@435 977 assert(jvms()->nof_monitors() == num_before_pop-1, "");
duke@435 978 }
duke@435 979
duke@435 980 Node *SafePointNode::peek_monitor_box() const {
duke@435 981 int mon = jvms()->nof_monitors() - 1;
duke@435 982 assert(mon >= 0, "most have a monitor");
duke@435 983 return monitor_box(jvms(), mon);
duke@435 984 }
duke@435 985
duke@435 986 Node *SafePointNode::peek_monitor_obj() const {
duke@435 987 int mon = jvms()->nof_monitors() - 1;
duke@435 988 assert(mon >= 0, "most have a monitor");
duke@435 989 return monitor_obj(jvms(), mon);
duke@435 990 }
duke@435 991
duke@435 992 // Do we Match on this edge index or not? Match no edges
duke@435 993 uint SafePointNode::match_edge(uint idx) const {
duke@435 994 if( !needs_polling_address_input() )
duke@435 995 return 0;
duke@435 996
duke@435 997 return (TypeFunc::Parms == idx);
duke@435 998 }
duke@435 999
kvn@498 1000 //============== SafePointScalarObjectNode ==============
kvn@498 1001
kvn@498 1002 SafePointScalarObjectNode::SafePointScalarObjectNode(const TypeOopPtr* tp,
kvn@498 1003 #ifdef ASSERT
kvn@498 1004 AllocateNode* alloc,
kvn@498 1005 #endif
kvn@498 1006 uint first_index,
kvn@498 1007 uint n_fields) :
kvn@498 1008 TypeNode(tp, 1), // 1 control input -- seems required. Get from root.
kvn@498 1009 #ifdef ASSERT
kvn@498 1010 _alloc(alloc),
kvn@498 1011 #endif
kvn@498 1012 _first_index(first_index),
kvn@498 1013 _n_fields(n_fields)
kvn@498 1014 {
kvn@498 1015 init_class_id(Class_SafePointScalarObject);
kvn@498 1016 }
kvn@498 1017
kvn@498 1018
kvn@498 1019 uint SafePointScalarObjectNode::ideal_reg() const {
kvn@498 1020 return 0; // No matching to machine instruction
kvn@498 1021 }
kvn@498 1022
kvn@498 1023 const RegMask &SafePointScalarObjectNode::in_RegMask(uint idx) const {
kvn@498 1024 return *(Compile::current()->matcher()->idealreg2debugmask[in(idx)->ideal_reg()]);
kvn@498 1025 }
kvn@498 1026
kvn@498 1027 const RegMask &SafePointScalarObjectNode::out_RegMask() const {
kvn@498 1028 return RegMask::Empty;
kvn@498 1029 }
kvn@498 1030
kvn@498 1031 uint SafePointScalarObjectNode::match_edge(uint idx) const {
kvn@498 1032 return 0;
kvn@498 1033 }
kvn@498 1034
kvn@498 1035 SafePointScalarObjectNode*
kvn@498 1036 SafePointScalarObjectNode::clone(int jvms_adj, Dict* sosn_map) const {
kvn@498 1037 void* cached = (*sosn_map)[(void*)this];
kvn@498 1038 if (cached != NULL) {
kvn@498 1039 return (SafePointScalarObjectNode*)cached;
kvn@498 1040 }
kvn@498 1041 Compile* C = Compile::current();
kvn@498 1042 SafePointScalarObjectNode* res = (SafePointScalarObjectNode*)Node::clone();
kvn@498 1043 res->_first_index += jvms_adj;
kvn@498 1044 sosn_map->Insert((void*)this, (void*)res);
kvn@498 1045 return res;
kvn@498 1046 }
kvn@498 1047
kvn@498 1048
kvn@498 1049 #ifndef PRODUCT
kvn@498 1050 void SafePointScalarObjectNode::dump_spec(outputStream *st) const {
kvn@498 1051 st->print(" # fields@[%d..%d]", first_index(),
kvn@498 1052 first_index() + n_fields() - 1);
kvn@498 1053 }
kvn@498 1054
kvn@498 1055 #endif
kvn@498 1056
duke@435 1057 //=============================================================================
duke@435 1058 uint AllocateNode::size_of() const { return sizeof(*this); }
duke@435 1059
duke@435 1060 AllocateNode::AllocateNode(Compile* C, const TypeFunc *atype,
duke@435 1061 Node *ctrl, Node *mem, Node *abio,
duke@435 1062 Node *size, Node *klass_node, Node *initial_test)
duke@435 1063 : CallNode(atype, NULL, TypeRawPtr::BOTTOM)
duke@435 1064 {
duke@435 1065 init_class_id(Class_Allocate);
duke@435 1066 init_flags(Flag_is_macro);
kvn@474 1067 _is_scalar_replaceable = false;
duke@435 1068 Node *topnode = C->top();
duke@435 1069
duke@435 1070 init_req( TypeFunc::Control , ctrl );
duke@435 1071 init_req( TypeFunc::I_O , abio );
duke@435 1072 init_req( TypeFunc::Memory , mem );
duke@435 1073 init_req( TypeFunc::ReturnAdr, topnode );
duke@435 1074 init_req( TypeFunc::FramePtr , topnode );
duke@435 1075 init_req( AllocSize , size);
duke@435 1076 init_req( KlassNode , klass_node);
duke@435 1077 init_req( InitialTest , initial_test);
duke@435 1078 init_req( ALength , topnode);
duke@435 1079 C->add_macro_node(this);
duke@435 1080 }
duke@435 1081
duke@435 1082 //=============================================================================
duke@435 1083 uint AllocateArrayNode::size_of() const { return sizeof(*this); }
duke@435 1084
duke@435 1085 //=============================================================================
duke@435 1086 uint LockNode::size_of() const { return sizeof(*this); }
duke@435 1087
duke@435 1088 // Redundant lock elimination
duke@435 1089 //
duke@435 1090 // There are various patterns of locking where we release and
duke@435 1091 // immediately reacquire a lock in a piece of code where no operations
duke@435 1092 // occur in between that would be observable. In those cases we can
duke@435 1093 // skip releasing and reacquiring the lock without violating any
duke@435 1094 // fairness requirements. Doing this around a loop could cause a lock
duke@435 1095 // to be held for a very long time so we concentrate on non-looping
duke@435 1096 // control flow. We also require that the operations are fully
duke@435 1097 // redundant meaning that we don't introduce new lock operations on
duke@435 1098 // some paths so to be able to eliminate it on others ala PRE. This
duke@435 1099 // would probably require some more extensive graph manipulation to
duke@435 1100 // guarantee that the memory edges were all handled correctly.
duke@435 1101 //
duke@435 1102 // Assuming p is a simple predicate which can't trap in any way and s
duke@435 1103 // is a synchronized method consider this code:
duke@435 1104 //
duke@435 1105 // s();
duke@435 1106 // if (p)
duke@435 1107 // s();
duke@435 1108 // else
duke@435 1109 // s();
duke@435 1110 // s();
duke@435 1111 //
duke@435 1112 // 1. The unlocks of the first call to s can be eliminated if the
duke@435 1113 // locks inside the then and else branches are eliminated.
duke@435 1114 //
duke@435 1115 // 2. The unlocks of the then and else branches can be eliminated if
duke@435 1116 // the lock of the final call to s is eliminated.
duke@435 1117 //
duke@435 1118 // Either of these cases subsumes the simple case of sequential control flow
duke@435 1119 //
duke@435 1120 // Addtionally we can eliminate versions without the else case:
duke@435 1121 //
duke@435 1122 // s();
duke@435 1123 // if (p)
duke@435 1124 // s();
duke@435 1125 // s();
duke@435 1126 //
duke@435 1127 // 3. In this case we eliminate the unlock of the first s, the lock
duke@435 1128 // and unlock in the then case and the lock in the final s.
duke@435 1129 //
duke@435 1130 // Note also that in all these cases the then/else pieces don't have
duke@435 1131 // to be trivial as long as they begin and end with synchronization
duke@435 1132 // operations.
duke@435 1133 //
duke@435 1134 // s();
duke@435 1135 // if (p)
duke@435 1136 // s();
duke@435 1137 // f();
duke@435 1138 // s();
duke@435 1139 // s();
duke@435 1140 //
duke@435 1141 // The code will work properly for this case, leaving in the unlock
duke@435 1142 // before the call to f and the relock after it.
duke@435 1143 //
duke@435 1144 // A potentially interesting case which isn't handled here is when the
duke@435 1145 // locking is partially redundant.
duke@435 1146 //
duke@435 1147 // s();
duke@435 1148 // if (p)
duke@435 1149 // s();
duke@435 1150 //
duke@435 1151 // This could be eliminated putting unlocking on the else case and
duke@435 1152 // eliminating the first unlock and the lock in the then side.
duke@435 1153 // Alternatively the unlock could be moved out of the then side so it
duke@435 1154 // was after the merge and the first unlock and second lock
duke@435 1155 // eliminated. This might require less manipulation of the memory
duke@435 1156 // state to get correct.
duke@435 1157 //
duke@435 1158 // Additionally we might allow work between a unlock and lock before
duke@435 1159 // giving up eliminating the locks. The current code disallows any
duke@435 1160 // conditional control flow between these operations. A formulation
duke@435 1161 // similar to partial redundancy elimination computing the
duke@435 1162 // availability of unlocking and the anticipatability of locking at a
duke@435 1163 // program point would allow detection of fully redundant locking with
duke@435 1164 // some amount of work in between. I'm not sure how often I really
duke@435 1165 // think that would occur though. Most of the cases I've seen
duke@435 1166 // indicate it's likely non-trivial work would occur in between.
duke@435 1167 // There may be other more complicated constructs where we could
duke@435 1168 // eliminate locking but I haven't seen any others appear as hot or
duke@435 1169 // interesting.
duke@435 1170 //
duke@435 1171 // Locking and unlocking have a canonical form in ideal that looks
duke@435 1172 // roughly like this:
duke@435 1173 //
duke@435 1174 // <obj>
duke@435 1175 // | \\------+
duke@435 1176 // | \ \
duke@435 1177 // | BoxLock \
duke@435 1178 // | | | \
duke@435 1179 // | | \ \
duke@435 1180 // | | FastLock
duke@435 1181 // | | /
duke@435 1182 // | | /
duke@435 1183 // | | |
duke@435 1184 //
duke@435 1185 // Lock
duke@435 1186 // |
duke@435 1187 // Proj #0
duke@435 1188 // |
duke@435 1189 // MembarAcquire
duke@435 1190 // |
duke@435 1191 // Proj #0
duke@435 1192 //
duke@435 1193 // MembarRelease
duke@435 1194 // |
duke@435 1195 // Proj #0
duke@435 1196 // |
duke@435 1197 // Unlock
duke@435 1198 // |
duke@435 1199 // Proj #0
duke@435 1200 //
duke@435 1201 //
duke@435 1202 // This code proceeds by processing Lock nodes during PhaseIterGVN
duke@435 1203 // and searching back through its control for the proper code
duke@435 1204 // patterns. Once it finds a set of lock and unlock operations to
duke@435 1205 // eliminate they are marked as eliminatable which causes the
duke@435 1206 // expansion of the Lock and Unlock macro nodes to make the operation a NOP
duke@435 1207 //
duke@435 1208 //=============================================================================
duke@435 1209
duke@435 1210 //
duke@435 1211 // Utility function to skip over uninteresting control nodes. Nodes skipped are:
duke@435 1212 // - copy regions. (These may not have been optimized away yet.)
duke@435 1213 // - eliminated locking nodes
duke@435 1214 //
duke@435 1215 static Node *next_control(Node *ctrl) {
duke@435 1216 if (ctrl == NULL)
duke@435 1217 return NULL;
duke@435 1218 while (1) {
duke@435 1219 if (ctrl->is_Region()) {
duke@435 1220 RegionNode *r = ctrl->as_Region();
duke@435 1221 Node *n = r->is_copy();
duke@435 1222 if (n == NULL)
duke@435 1223 break; // hit a region, return it
duke@435 1224 else
duke@435 1225 ctrl = n;
duke@435 1226 } else if (ctrl->is_Proj()) {
duke@435 1227 Node *in0 = ctrl->in(0);
duke@435 1228 if (in0->is_AbstractLock() && in0->as_AbstractLock()->is_eliminated()) {
duke@435 1229 ctrl = in0->in(0);
duke@435 1230 } else {
duke@435 1231 break;
duke@435 1232 }
duke@435 1233 } else {
duke@435 1234 break; // found an interesting control
duke@435 1235 }
duke@435 1236 }
duke@435 1237 return ctrl;
duke@435 1238 }
duke@435 1239 //
duke@435 1240 // Given a control, see if it's the control projection of an Unlock which
duke@435 1241 // operating on the same object as lock.
duke@435 1242 //
duke@435 1243 bool AbstractLockNode::find_matching_unlock(const Node* ctrl, LockNode* lock,
duke@435 1244 GrowableArray<AbstractLockNode*> &lock_ops) {
duke@435 1245 ProjNode *ctrl_proj = (ctrl->is_Proj()) ? ctrl->as_Proj() : NULL;
duke@435 1246 if (ctrl_proj != NULL && ctrl_proj->_con == TypeFunc::Control) {
duke@435 1247 Node *n = ctrl_proj->in(0);
duke@435 1248 if (n != NULL && n->is_Unlock()) {
duke@435 1249 UnlockNode *unlock = n->as_Unlock();
duke@435 1250 if ((lock->obj_node() == unlock->obj_node()) &&
duke@435 1251 (lock->box_node() == unlock->box_node()) && !unlock->is_eliminated()) {
duke@435 1252 lock_ops.append(unlock);
duke@435 1253 return true;
duke@435 1254 }
duke@435 1255 }
duke@435 1256 }
duke@435 1257 return false;
duke@435 1258 }
duke@435 1259
duke@435 1260 //
duke@435 1261 // Find the lock matching an unlock. Returns null if a safepoint
duke@435 1262 // or complicated control is encountered first.
duke@435 1263 LockNode *AbstractLockNode::find_matching_lock(UnlockNode* unlock) {
duke@435 1264 LockNode *lock_result = NULL;
duke@435 1265 // find the matching lock, or an intervening safepoint
duke@435 1266 Node *ctrl = next_control(unlock->in(0));
duke@435 1267 while (1) {
duke@435 1268 assert(ctrl != NULL, "invalid control graph");
duke@435 1269 assert(!ctrl->is_Start(), "missing lock for unlock");
duke@435 1270 if (ctrl->is_top()) break; // dead control path
duke@435 1271 if (ctrl->is_Proj()) ctrl = ctrl->in(0);
duke@435 1272 if (ctrl->is_SafePoint()) {
duke@435 1273 break; // found a safepoint (may be the lock we are searching for)
duke@435 1274 } else if (ctrl->is_Region()) {
duke@435 1275 // Check for a simple diamond pattern. Punt on anything more complicated
duke@435 1276 if (ctrl->req() == 3 && ctrl->in(1) != NULL && ctrl->in(2) != NULL) {
duke@435 1277 Node *in1 = next_control(ctrl->in(1));
duke@435 1278 Node *in2 = next_control(ctrl->in(2));
duke@435 1279 if (((in1->is_IfTrue() && in2->is_IfFalse()) ||
duke@435 1280 (in2->is_IfTrue() && in1->is_IfFalse())) && (in1->in(0) == in2->in(0))) {
duke@435 1281 ctrl = next_control(in1->in(0)->in(0));
duke@435 1282 } else {
duke@435 1283 break;
duke@435 1284 }
duke@435 1285 } else {
duke@435 1286 break;
duke@435 1287 }
duke@435 1288 } else {
duke@435 1289 ctrl = next_control(ctrl->in(0)); // keep searching
duke@435 1290 }
duke@435 1291 }
duke@435 1292 if (ctrl->is_Lock()) {
duke@435 1293 LockNode *lock = ctrl->as_Lock();
duke@435 1294 if ((lock->obj_node() == unlock->obj_node()) &&
duke@435 1295 (lock->box_node() == unlock->box_node())) {
duke@435 1296 lock_result = lock;
duke@435 1297 }
duke@435 1298 }
duke@435 1299 return lock_result;
duke@435 1300 }
duke@435 1301
duke@435 1302 // This code corresponds to case 3 above.
duke@435 1303
duke@435 1304 bool AbstractLockNode::find_lock_and_unlock_through_if(Node* node, LockNode* lock,
duke@435 1305 GrowableArray<AbstractLockNode*> &lock_ops) {
duke@435 1306 Node* if_node = node->in(0);
duke@435 1307 bool if_true = node->is_IfTrue();
duke@435 1308
duke@435 1309 if (if_node->is_If() && if_node->outcnt() == 2 && (if_true || node->is_IfFalse())) {
duke@435 1310 Node *lock_ctrl = next_control(if_node->in(0));
duke@435 1311 if (find_matching_unlock(lock_ctrl, lock, lock_ops)) {
duke@435 1312 Node* lock1_node = NULL;
duke@435 1313 ProjNode* proj = if_node->as_If()->proj_out(!if_true);
duke@435 1314 if (if_true) {
duke@435 1315 if (proj->is_IfFalse() && proj->outcnt() == 1) {
duke@435 1316 lock1_node = proj->unique_out();
duke@435 1317 }
duke@435 1318 } else {
duke@435 1319 if (proj->is_IfTrue() && proj->outcnt() == 1) {
duke@435 1320 lock1_node = proj->unique_out();
duke@435 1321 }
duke@435 1322 }
duke@435 1323 if (lock1_node != NULL && lock1_node->is_Lock()) {
duke@435 1324 LockNode *lock1 = lock1_node->as_Lock();
duke@435 1325 if ((lock->obj_node() == lock1->obj_node()) &&
duke@435 1326 (lock->box_node() == lock1->box_node()) && !lock1->is_eliminated()) {
duke@435 1327 lock_ops.append(lock1);
duke@435 1328 return true;
duke@435 1329 }
duke@435 1330 }
duke@435 1331 }
duke@435 1332 }
duke@435 1333
duke@435 1334 lock_ops.trunc_to(0);
duke@435 1335 return false;
duke@435 1336 }
duke@435 1337
duke@435 1338 bool AbstractLockNode::find_unlocks_for_region(const RegionNode* region, LockNode* lock,
duke@435 1339 GrowableArray<AbstractLockNode*> &lock_ops) {
duke@435 1340 // check each control merging at this point for a matching unlock.
duke@435 1341 // in(0) should be self edge so skip it.
duke@435 1342 for (int i = 1; i < (int)region->req(); i++) {
duke@435 1343 Node *in_node = next_control(region->in(i));
duke@435 1344 if (in_node != NULL) {
duke@435 1345 if (find_matching_unlock(in_node, lock, lock_ops)) {
duke@435 1346 // found a match so keep on checking.
duke@435 1347 continue;
duke@435 1348 } else if (find_lock_and_unlock_through_if(in_node, lock, lock_ops)) {
duke@435 1349 continue;
duke@435 1350 }
duke@435 1351
duke@435 1352 // If we fall through to here then it was some kind of node we
duke@435 1353 // don't understand or there wasn't a matching unlock, so give
duke@435 1354 // up trying to merge locks.
duke@435 1355 lock_ops.trunc_to(0);
duke@435 1356 return false;
duke@435 1357 }
duke@435 1358 }
duke@435 1359 return true;
duke@435 1360
duke@435 1361 }
duke@435 1362
duke@435 1363 #ifndef PRODUCT
duke@435 1364 //
duke@435 1365 // Create a counter which counts the number of times this lock is acquired
duke@435 1366 //
duke@435 1367 void AbstractLockNode::create_lock_counter(JVMState* state) {
duke@435 1368 _counter = OptoRuntime::new_named_counter(state, NamedCounter::LockCounter);
duke@435 1369 }
duke@435 1370 #endif
duke@435 1371
duke@435 1372 void AbstractLockNode::set_eliminated() {
duke@435 1373 _eliminate = true;
duke@435 1374 #ifndef PRODUCT
duke@435 1375 if (_counter) {
duke@435 1376 // Update the counter to indicate that this lock was eliminated.
duke@435 1377 // The counter update code will stay around even though the
duke@435 1378 // optimizer will eliminate the lock operation itself.
duke@435 1379 _counter->set_tag(NamedCounter::EliminatedLockCounter);
duke@435 1380 }
duke@435 1381 #endif
duke@435 1382 }
duke@435 1383
duke@435 1384 //=============================================================================
duke@435 1385 Node *LockNode::Ideal(PhaseGVN *phase, bool can_reshape) {
duke@435 1386
kvn@501 1387 // perform any generic optimizations first (returns 'this' or NULL)
duke@435 1388 Node *result = SafePointNode::Ideal(phase, can_reshape);
duke@435 1389
duke@435 1390 // Now see if we can optimize away this lock. We don't actually
duke@435 1391 // remove the locking here, we simply set the _eliminate flag which
duke@435 1392 // prevents macro expansion from expanding the lock. Since we don't
duke@435 1393 // modify the graph, the value returned from this function is the
duke@435 1394 // one computed above.
kvn@501 1395 if (result == NULL && can_reshape && EliminateLocks && !is_eliminated()) {
kvn@501 1396 //
kvn@501 1397 // If we are locking an unescaped object, the lock/unlock is unnecessary
kvn@501 1398 //
kvn@501 1399 ConnectionGraph *cgr = Compile::current()->congraph();
kvn@501 1400 PointsToNode::EscapeState es = PointsToNode::GlobalEscape;
kvn@501 1401 if (cgr != NULL)
kvn@501 1402 es = cgr->escape_state(obj_node(), phase);
kvn@501 1403 if (es != PointsToNode::UnknownEscape && es != PointsToNode::GlobalEscape) {
kvn@501 1404 // Mark it eliminated to update any counters
kvn@501 1405 this->set_eliminated();
kvn@501 1406 return result;
kvn@501 1407 }
kvn@501 1408
duke@435 1409 //
duke@435 1410 // Try lock coarsening
duke@435 1411 //
duke@435 1412 PhaseIterGVN* iter = phase->is_IterGVN();
duke@435 1413 if (iter != NULL) {
duke@435 1414
duke@435 1415 GrowableArray<AbstractLockNode*> lock_ops;
duke@435 1416
duke@435 1417 Node *ctrl = next_control(in(0));
duke@435 1418
duke@435 1419 // now search back for a matching Unlock
duke@435 1420 if (find_matching_unlock(ctrl, this, lock_ops)) {
duke@435 1421 // found an unlock directly preceding this lock. This is the
duke@435 1422 // case of single unlock directly control dependent on a
duke@435 1423 // single lock which is the trivial version of case 1 or 2.
duke@435 1424 } else if (ctrl->is_Region() ) {
duke@435 1425 if (find_unlocks_for_region(ctrl->as_Region(), this, lock_ops)) {
duke@435 1426 // found lock preceded by multiple unlocks along all paths
duke@435 1427 // joining at this point which is case 3 in description above.
duke@435 1428 }
duke@435 1429 } else {
duke@435 1430 // see if this lock comes from either half of an if and the
duke@435 1431 // predecessors merges unlocks and the other half of the if
duke@435 1432 // performs a lock.
duke@435 1433 if (find_lock_and_unlock_through_if(ctrl, this, lock_ops)) {
duke@435 1434 // found unlock splitting to an if with locks on both branches.
duke@435 1435 }
duke@435 1436 }
duke@435 1437
duke@435 1438 if (lock_ops.length() > 0) {
duke@435 1439 // add ourselves to the list of locks to be eliminated.
duke@435 1440 lock_ops.append(this);
duke@435 1441
duke@435 1442 #ifndef PRODUCT
duke@435 1443 if (PrintEliminateLocks) {
duke@435 1444 int locks = 0;
duke@435 1445 int unlocks = 0;
duke@435 1446 for (int i = 0; i < lock_ops.length(); i++) {
duke@435 1447 AbstractLockNode* lock = lock_ops.at(i);
kvn@501 1448 if (lock->Opcode() == Op_Lock)
kvn@501 1449 locks++;
kvn@501 1450 else
kvn@501 1451 unlocks++;
duke@435 1452 if (Verbose) {
duke@435 1453 lock->dump(1);
duke@435 1454 }
duke@435 1455 }
duke@435 1456 tty->print_cr("***Eliminated %d unlocks and %d locks", unlocks, locks);
duke@435 1457 }
duke@435 1458 #endif
duke@435 1459
duke@435 1460 // for each of the identified locks, mark them
duke@435 1461 // as eliminatable
duke@435 1462 for (int i = 0; i < lock_ops.length(); i++) {
duke@435 1463 AbstractLockNode* lock = lock_ops.at(i);
duke@435 1464
duke@435 1465 // Mark it eliminated to update any counters
duke@435 1466 lock->set_eliminated();
duke@435 1467 }
duke@435 1468 } else if (result != NULL && ctrl->is_Region() &&
duke@435 1469 iter->_worklist.member(ctrl)) {
duke@435 1470 // We weren't able to find any opportunities but the region this
duke@435 1471 // lock is control dependent on hasn't been processed yet so put
duke@435 1472 // this lock back on the worklist so we can check again once any
duke@435 1473 // region simplification has occurred.
duke@435 1474 iter->_worklist.push(this);
duke@435 1475 }
duke@435 1476 }
duke@435 1477 }
duke@435 1478
duke@435 1479 return result;
duke@435 1480 }
duke@435 1481
duke@435 1482 //=============================================================================
duke@435 1483 uint UnlockNode::size_of() const { return sizeof(*this); }
duke@435 1484
duke@435 1485 //=============================================================================
duke@435 1486 Node *UnlockNode::Ideal(PhaseGVN *phase, bool can_reshape) {
duke@435 1487
kvn@501 1488 // perform any generic optimizations first (returns 'this' or NULL)
duke@435 1489 Node * result = SafePointNode::Ideal(phase, can_reshape);
duke@435 1490
duke@435 1491 // Now see if we can optimize away this unlock. We don't actually
duke@435 1492 // remove the unlocking here, we simply set the _eliminate flag which
duke@435 1493 // prevents macro expansion from expanding the unlock. Since we don't
duke@435 1494 // modify the graph, the value returned from this function is the
duke@435 1495 // one computed above.
kvn@501 1496 // Escape state is defined after Parse phase.
kvn@501 1497 if (result == NULL && can_reshape && EliminateLocks && !is_eliminated()) {
duke@435 1498 //
kvn@501 1499 // If we are unlocking an unescaped object, the lock/unlock is unnecessary.
duke@435 1500 //
duke@435 1501 ConnectionGraph *cgr = Compile::current()->congraph();
kvn@501 1502 PointsToNode::EscapeState es = PointsToNode::GlobalEscape;
kvn@501 1503 if (cgr != NULL)
kvn@501 1504 es = cgr->escape_state(obj_node(), phase);
kvn@501 1505 if (es != PointsToNode::UnknownEscape && es != PointsToNode::GlobalEscape) {
kvn@501 1506 // Mark it eliminated to update any counters
kvn@501 1507 this->set_eliminated();
duke@435 1508 }
duke@435 1509 }
duke@435 1510 return result;
duke@435 1511 }

mercurial