1 /* 2 * Copyright (c) 2005, 2009, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #include "incls/_precompiled.incl" 26 #include "incls/_macro.cpp.incl" 27 28 29 // 30 // Replace any references to "oldref" in inputs to "use" with "newref". 31 // Returns the number of replacements made. 32 // 33 int PhaseMacroExpand::replace_input(Node *use, Node *oldref, Node *newref) { 34 int nreplacements = 0; 35 uint req = use->req(); 36 for (uint j = 0; j < use->len(); j++) { 37 Node *uin = use->in(j); 38 if (uin == oldref) { 39 if (j < req) 40 use->set_req(j, newref); 41 else 42 use->set_prec(j, newref); 43 nreplacements++; 44 } else if (j >= req && uin == NULL) { 45 break; 46 } 47 } 48 return nreplacements; 49 } 50 51 void PhaseMacroExpand::copy_call_debug_info(CallNode *oldcall, CallNode * newcall) { 52 // Copy debug information and adjust JVMState information 53 uint old_dbg_start = oldcall->tf()->domain()->cnt(); 54 uint new_dbg_start = newcall->tf()->domain()->cnt(); 55 int jvms_adj = new_dbg_start - old_dbg_start; 56 assert (new_dbg_start == newcall->req(), "argument count mismatch"); 57 58 Dict* sosn_map = new Dict(cmpkey,hashkey); 59 for (uint i = old_dbg_start; i < oldcall->req(); i++) { 60 Node* old_in = oldcall->in(i); 61 // Clone old SafePointScalarObjectNodes, adjusting their field contents. 62 if (old_in != NULL && old_in->is_SafePointScalarObject()) { 63 SafePointScalarObjectNode* old_sosn = old_in->as_SafePointScalarObject(); 64 uint old_unique = C->unique(); 65 Node* new_in = old_sosn->clone(jvms_adj, sosn_map); 66 if (old_unique != C->unique()) { 67 new_in->set_req(0, newcall->in(0)); // reset control edge 68 new_in = transform_later(new_in); // Register new node. 69 } 70 old_in = new_in; 71 } 72 newcall->add_req(old_in); 73 } 74 75 newcall->set_jvms(oldcall->jvms()); 76 for (JVMState *jvms = newcall->jvms(); jvms != NULL; jvms = jvms->caller()) { 77 jvms->set_map(newcall); 78 jvms->set_locoff(jvms->locoff()+jvms_adj); 79 jvms->set_stkoff(jvms->stkoff()+jvms_adj); 80 jvms->set_monoff(jvms->monoff()+jvms_adj); 81 jvms->set_scloff(jvms->scloff()+jvms_adj); 82 jvms->set_endoff(jvms->endoff()+jvms_adj); 83 } 84 } 85 86 Node* PhaseMacroExpand::opt_bits_test(Node* ctrl, Node* region, int edge, Node* word, int mask, int bits, bool return_fast_path) { 87 Node* cmp; 88 if (mask != 0) { 89 Node* and_node = transform_later(new (C, 3) AndXNode(word, MakeConX(mask))); 90 cmp = transform_later(new (C, 3) CmpXNode(and_node, MakeConX(bits))); 91 } else { 92 cmp = word; 93 } 94 Node* bol = transform_later(new (C, 2) BoolNode(cmp, BoolTest::ne)); 95 IfNode* iff = new (C, 2) IfNode( ctrl, bol, PROB_MIN, COUNT_UNKNOWN ); 96 transform_later(iff); 97 98 // Fast path taken. 99 Node *fast_taken = transform_later( new (C, 1) IfFalseNode(iff) ); 100 101 // Fast path not-taken, i.e. slow path 102 Node *slow_taken = transform_later( new (C, 1) IfTrueNode(iff) ); 103 104 if (return_fast_path) { 105 region->init_req(edge, slow_taken); // Capture slow-control 106 return fast_taken; 107 } else { 108 region->init_req(edge, fast_taken); // Capture fast-control 109 return slow_taken; 110 } 111 } 112 113 //--------------------copy_predefined_input_for_runtime_call-------------------- 114 void PhaseMacroExpand::copy_predefined_input_for_runtime_call(Node * ctrl, CallNode* oldcall, CallNode* call) { 115 // Set fixed predefined input arguments 116 call->init_req( TypeFunc::Control, ctrl ); 117 call->init_req( TypeFunc::I_O , oldcall->in( TypeFunc::I_O) ); 118 call->init_req( TypeFunc::Memory , oldcall->in( TypeFunc::Memory ) ); // ????? 119 call->init_req( TypeFunc::ReturnAdr, oldcall->in( TypeFunc::ReturnAdr ) ); 120 call->init_req( TypeFunc::FramePtr, oldcall->in( TypeFunc::FramePtr ) ); 121 } 122 123 //------------------------------make_slow_call--------------------------------- 124 CallNode* PhaseMacroExpand::make_slow_call(CallNode *oldcall, const TypeFunc* slow_call_type, address slow_call, const char* leaf_name, Node* slow_path, Node* parm0, Node* parm1) { 125 126 // Slow-path call 127 int size = slow_call_type->domain()->cnt(); 128 CallNode *call = leaf_name 129 ? (CallNode*)new (C, size) CallLeafNode ( slow_call_type, slow_call, leaf_name, TypeRawPtr::BOTTOM ) 130 : (CallNode*)new (C, size) CallStaticJavaNode( slow_call_type, slow_call, OptoRuntime::stub_name(slow_call), oldcall->jvms()->bci(), TypeRawPtr::BOTTOM ); 131 132 // Slow path call has no side-effects, uses few values 133 copy_predefined_input_for_runtime_call(slow_path, oldcall, call ); 134 if (parm0 != NULL) call->init_req(TypeFunc::Parms+0, parm0); 135 if (parm1 != NULL) call->init_req(TypeFunc::Parms+1, parm1); 136 copy_call_debug_info(oldcall, call); 137 call->set_cnt(PROB_UNLIKELY_MAG(4)); // Same effect as RC_UNCOMMON. 138 _igvn.replace_node(oldcall, call); 139 transform_later(call); 140 141 return call; 142 } 143 144 void PhaseMacroExpand::extract_call_projections(CallNode *call) { 145 _fallthroughproj = NULL; 146 _fallthroughcatchproj = NULL; 147 _ioproj_fallthrough = NULL; 148 _ioproj_catchall = NULL; 149 _catchallcatchproj = NULL; 150 _memproj_fallthrough = NULL; 151 _memproj_catchall = NULL; 152 _resproj = NULL; 153 for (DUIterator_Fast imax, i = call->fast_outs(imax); i < imax; i++) { 154 ProjNode *pn = call->fast_out(i)->as_Proj(); 155 switch (pn->_con) { 156 case TypeFunc::Control: 157 { 158 // For Control (fallthrough) and I_O (catch_all_index) we have CatchProj -> Catch -> Proj 159 _fallthroughproj = pn; 160 DUIterator_Fast jmax, j = pn->fast_outs(jmax); 161 const Node *cn = pn->fast_out(j); 162 if (cn->is_Catch()) { 163 ProjNode *cpn = NULL; 164 for (DUIterator_Fast kmax, k = cn->fast_outs(kmax); k < kmax; k++) { 165 cpn = cn->fast_out(k)->as_Proj(); 166 assert(cpn->is_CatchProj(), "must be a CatchProjNode"); 167 if (cpn->_con == CatchProjNode::fall_through_index) 168 _fallthroughcatchproj = cpn; 169 else { 170 assert(cpn->_con == CatchProjNode::catch_all_index, "must be correct index."); 171 _catchallcatchproj = cpn; 172 } 173 } 174 } 175 break; 176 } 177 case TypeFunc::I_O: 178 if (pn->_is_io_use) 179 _ioproj_catchall = pn; 180 else 181 _ioproj_fallthrough = pn; 182 break; 183 case TypeFunc::Memory: 184 if (pn->_is_io_use) 185 _memproj_catchall = pn; 186 else 187 _memproj_fallthrough = pn; 188 break; 189 case TypeFunc::Parms: 190 _resproj = pn; 191 break; 192 default: 193 assert(false, "unexpected projection from allocation node."); 194 } 195 } 196 197 } 198 199 // Eliminate a card mark sequence. p2x is a ConvP2XNode 200 void PhaseMacroExpand::eliminate_card_mark(Node* p2x) { 201 assert(p2x->Opcode() == Op_CastP2X, "ConvP2XNode required"); 202 if (!UseG1GC) { 203 // vanilla/CMS post barrier 204 Node *shift = p2x->unique_out(); 205 Node *addp = shift->unique_out(); 206 for (DUIterator_Last jmin, j = addp->last_outs(jmin); j >= jmin; --j) { 207 Node *st = addp->last_out(j); 208 assert(st->is_Store(), "store required"); 209 _igvn.replace_node(st, st->in(MemNode::Memory)); 210 } 211 } else { 212 // G1 pre/post barriers 213 assert(p2x->outcnt() == 2, "expects 2 users: Xor and URShift nodes"); 214 // It could be only one user, URShift node, in Object.clone() instrinsic 215 // but the new allocation is passed to arraycopy stub and it could not 216 // be scalar replaced. So we don't check the case. 217 218 // Remove G1 post barrier. 219 220 // Search for CastP2X->Xor->URShift->Cmp path which 221 // checks if the store done to a different from the value's region. 222 // And replace Cmp with #0 (false) to collapse G1 post barrier. 223 Node* xorx = NULL; 224 for (DUIterator_Fast imax, i = p2x->fast_outs(imax); i < imax; i++) { 225 Node* u = p2x->fast_out(i); 226 if (u->Opcode() == Op_XorX) { 227 xorx = u; 228 break; 229 } 230 } 231 assert(xorx != NULL, "missing G1 post barrier"); 232 Node* shift = xorx->unique_out(); 233 Node* cmpx = shift->unique_out(); 234 assert(cmpx->is_Cmp() && cmpx->unique_out()->is_Bool() && 235 cmpx->unique_out()->as_Bool()->_test._test == BoolTest::ne, 236 "missing region check in G1 post barrier"); 237 _igvn.replace_node(cmpx, makecon(TypeInt::CC_EQ)); 238 239 // Remove G1 pre barrier. 240 241 // Search "if (marking != 0)" check and set it to "false". 242 Node* this_region = p2x->in(0); 243 assert(this_region != NULL, ""); 244 // There is no G1 pre barrier if previous stored value is NULL 245 // (for example, after initialization). 246 if (this_region->is_Region() && this_region->req() == 3) { 247 int ind = 1; 248 if (!this_region->in(ind)->is_IfFalse()) { 249 ind = 2; 250 } 251 if (this_region->in(ind)->is_IfFalse()) { 252 Node* bol = this_region->in(ind)->in(0)->in(1); 253 assert(bol->is_Bool(), ""); 254 cmpx = bol->in(1); 255 if (bol->as_Bool()->_test._test == BoolTest::ne && 256 cmpx->is_Cmp() && cmpx->in(2) == intcon(0) && 257 cmpx->in(1)->is_Load()) { 258 Node* adr = cmpx->in(1)->as_Load()->in(MemNode::Address); 259 const int marking_offset = in_bytes(JavaThread::satb_mark_queue_offset() + 260 PtrQueue::byte_offset_of_active()); 261 if (adr->is_AddP() && adr->in(AddPNode::Base) == top() && 262 adr->in(AddPNode::Address)->Opcode() == Op_ThreadLocal && 263 adr->in(AddPNode::Offset) == MakeConX(marking_offset)) { 264 _igvn.replace_node(cmpx, makecon(TypeInt::CC_EQ)); 265 } 266 } 267 } 268 } 269 // Now CastP2X can be removed since it is used only on dead path 270 // which currently still alive until igvn optimize it. 271 assert(p2x->unique_out()->Opcode() == Op_URShiftX, ""); 272 _igvn.replace_node(p2x, top()); 273 } 274 } 275 276 // Search for a memory operation for the specified memory slice. 277 static Node *scan_mem_chain(Node *mem, int alias_idx, int offset, Node *start_mem, Node *alloc, PhaseGVN *phase) { 278 Node *orig_mem = mem; 279 Node *alloc_mem = alloc->in(TypeFunc::Memory); 280 const TypeOopPtr *tinst = phase->C->get_adr_type(alias_idx)->isa_oopptr(); 281 while (true) { 282 if (mem == alloc_mem || mem == start_mem ) { 283 return mem; // hit one of our sentinels 284 } else if (mem->is_MergeMem()) { 285 mem = mem->as_MergeMem()->memory_at(alias_idx); 286 } else if (mem->is_Proj() && mem->as_Proj()->_con == TypeFunc::Memory) { 287 Node *in = mem->in(0); 288 // we can safely skip over safepoints, calls, locks and membars because we 289 // already know that the object is safe to eliminate. 290 if (in->is_Initialize() && in->as_Initialize()->allocation() == alloc) { 291 return in; 292 } else if (in->is_Call()) { 293 CallNode *call = in->as_Call(); 294 if (!call->may_modify(tinst, phase)) { 295 mem = call->in(TypeFunc::Memory); 296 } 297 mem = in->in(TypeFunc::Memory); 298 } else if (in->is_MemBar()) { 299 mem = in->in(TypeFunc::Memory); 300 } else { 301 assert(false, "unexpected projection"); 302 } 303 } else if (mem->is_Store()) { 304 const TypePtr* atype = mem->as_Store()->adr_type(); 305 int adr_idx = Compile::current()->get_alias_index(atype); 306 if (adr_idx == alias_idx) { 307 assert(atype->isa_oopptr(), "address type must be oopptr"); 308 int adr_offset = atype->offset(); 309 uint adr_iid = atype->is_oopptr()->instance_id(); 310 // Array elements references have the same alias_idx 311 // but different offset and different instance_id. 312 if (adr_offset == offset && adr_iid == alloc->_idx) 313 return mem; 314 } else { 315 assert(adr_idx == Compile::AliasIdxRaw, "address must match or be raw"); 316 } 317 mem = mem->in(MemNode::Memory); 318 } else if (mem->is_ClearArray()) { 319 if (!ClearArrayNode::step_through(&mem, alloc->_idx, phase)) { 320 // Can not bypass initialization of the instance 321 // we are looking. 322 debug_only(intptr_t offset;) 323 assert(alloc == AllocateNode::Ideal_allocation(mem->in(3), phase, offset), "sanity"); 324 InitializeNode* init = alloc->as_Allocate()->initialization(); 325 // We are looking for stored value, return Initialize node 326 // or memory edge from Allocate node. 327 if (init != NULL) 328 return init; 329 else 330 return alloc->in(TypeFunc::Memory); // It will produce zero value (see callers). 331 } 332 // Otherwise skip it (the call updated 'mem' value). 333 } else if (mem->Opcode() == Op_SCMemProj) { 334 assert(mem->in(0)->is_LoadStore(), "sanity"); 335 const TypePtr* atype = mem->in(0)->in(MemNode::Address)->bottom_type()->is_ptr(); 336 int adr_idx = Compile::current()->get_alias_index(atype); 337 if (adr_idx == alias_idx) { 338 assert(false, "Object is not scalar replaceable if a LoadStore node access its field"); 339 return NULL; 340 } 341 mem = mem->in(0)->in(MemNode::Memory); 342 } else { 343 return mem; 344 } 345 assert(mem != orig_mem, "dead memory loop"); 346 } 347 } 348 349 // 350 // Given a Memory Phi, compute a value Phi containing the values from stores 351 // on the input paths. 352 // Note: this function is recursive, its depth is limied by the "level" argument 353 // Returns the computed Phi, or NULL if it cannot compute it. 354 Node *PhaseMacroExpand::value_from_mem_phi(Node *mem, BasicType ft, const Type *phi_type, const TypeOopPtr *adr_t, Node *alloc, Node_Stack *value_phis, int level) { 355 assert(mem->is_Phi(), "sanity"); 356 int alias_idx = C->get_alias_index(adr_t); 357 int offset = adr_t->offset(); 358 int instance_id = adr_t->instance_id(); 359 360 // Check if an appropriate value phi already exists. 361 Node* region = mem->in(0); 362 for (DUIterator_Fast kmax, k = region->fast_outs(kmax); k < kmax; k++) { 363 Node* phi = region->fast_out(k); 364 if (phi->is_Phi() && phi != mem && 365 phi->as_Phi()->is_same_inst_field(phi_type, instance_id, alias_idx, offset)) { 366 return phi; 367 } 368 } 369 // Check if an appropriate new value phi already exists. 370 Node* new_phi = NULL; 371 uint size = value_phis->size(); 372 for (uint i=0; i < size; i++) { 373 if ( mem->_idx == value_phis->index_at(i) ) { 374 return value_phis->node_at(i); 375 } 376 } 377 378 if (level <= 0) { 379 return NULL; // Give up: phi tree too deep 380 } 381 Node *start_mem = C->start()->proj_out(TypeFunc::Memory); 382 Node *alloc_mem = alloc->in(TypeFunc::Memory); 383 384 uint length = mem->req(); 385 GrowableArray <Node *> values(length, length, NULL); 386 387 // create a new Phi for the value 388 PhiNode *phi = new (C, length) PhiNode(mem->in(0), phi_type, NULL, instance_id, alias_idx, offset); 389 transform_later(phi); 390 value_phis->push(phi, mem->_idx); 391 392 for (uint j = 1; j < length; j++) { 393 Node *in = mem->in(j); 394 if (in == NULL || in->is_top()) { 395 values.at_put(j, in); 396 } else { 397 Node *val = scan_mem_chain(in, alias_idx, offset, start_mem, alloc, &_igvn); 398 if (val == start_mem || val == alloc_mem) { 399 // hit a sentinel, return appropriate 0 value 400 values.at_put(j, _igvn.zerocon(ft)); 401 continue; 402 } 403 if (val->is_Initialize()) { 404 val = val->as_Initialize()->find_captured_store(offset, type2aelembytes(ft), &_igvn); 405 } 406 if (val == NULL) { 407 return NULL; // can't find a value on this path 408 } 409 if (val == mem) { 410 values.at_put(j, mem); 411 } else if (val->is_Store()) { 412 values.at_put(j, val->in(MemNode::ValueIn)); 413 } else if(val->is_Proj() && val->in(0) == alloc) { 414 values.at_put(j, _igvn.zerocon(ft)); 415 } else if (val->is_Phi()) { 416 val = value_from_mem_phi(val, ft, phi_type, adr_t, alloc, value_phis, level-1); 417 if (val == NULL) { 418 return NULL; 419 } 420 values.at_put(j, val); 421 } else if (val->Opcode() == Op_SCMemProj) { 422 assert(val->in(0)->is_LoadStore(), "sanity"); 423 assert(false, "Object is not scalar replaceable if a LoadStore node access its field"); 424 return NULL; 425 } else { 426 #ifdef ASSERT 427 val->dump(); 428 assert(false, "unknown node on this path"); 429 #endif 430 return NULL; // unknown node on this path 431 } 432 } 433 } 434 // Set Phi's inputs 435 for (uint j = 1; j < length; j++) { 436 if (values.at(j) == mem) { 437 phi->init_req(j, phi); 438 } else { 439 phi->init_req(j, values.at(j)); 440 } 441 } 442 return phi; 443 } 444 445 // Search the last value stored into the object's field. 446 Node *PhaseMacroExpand::value_from_mem(Node *sfpt_mem, BasicType ft, const Type *ftype, const TypeOopPtr *adr_t, Node *alloc) { 447 assert(adr_t->is_known_instance_field(), "instance required"); 448 int instance_id = adr_t->instance_id(); 449 assert((uint)instance_id == alloc->_idx, "wrong allocation"); 450 451 int alias_idx = C->get_alias_index(adr_t); 452 int offset = adr_t->offset(); 453 Node *start_mem = C->start()->proj_out(TypeFunc::Memory); 454 Node *alloc_ctrl = alloc->in(TypeFunc::Control); 455 Node *alloc_mem = alloc->in(TypeFunc::Memory); 456 Arena *a = Thread::current()->resource_area(); 457 VectorSet visited(a); 458 459 460 bool done = sfpt_mem == alloc_mem; 461 Node *mem = sfpt_mem; 462 while (!done) { 463 if (visited.test_set(mem->_idx)) { 464 return NULL; // found a loop, give up 465 } 466 mem = scan_mem_chain(mem, alias_idx, offset, start_mem, alloc, &_igvn); 467 if (mem == start_mem || mem == alloc_mem) { 468 done = true; // hit a sentinel, return appropriate 0 value 469 } else if (mem->is_Initialize()) { 470 mem = mem->as_Initialize()->find_captured_store(offset, type2aelembytes(ft), &_igvn); 471 if (mem == NULL) { 472 done = true; // Something go wrong. 473 } else if (mem->is_Store()) { 474 const TypePtr* atype = mem->as_Store()->adr_type(); 475 assert(C->get_alias_index(atype) == Compile::AliasIdxRaw, "store is correct memory slice"); 476 done = true; 477 } 478 } else if (mem->is_Store()) { 479 const TypeOopPtr* atype = mem->as_Store()->adr_type()->isa_oopptr(); 480 assert(atype != NULL, "address type must be oopptr"); 481 assert(C->get_alias_index(atype) == alias_idx && 482 atype->is_known_instance_field() && atype->offset() == offset && 483 atype->instance_id() == instance_id, "store is correct memory slice"); 484 done = true; 485 } else if (mem->is_Phi()) { 486 // try to find a phi's unique input 487 Node *unique_input = NULL; 488 Node *top = C->top(); 489 for (uint i = 1; i < mem->req(); i++) { 490 Node *n = scan_mem_chain(mem->in(i), alias_idx, offset, start_mem, alloc, &_igvn); 491 if (n == NULL || n == top || n == mem) { 492 continue; 493 } else if (unique_input == NULL) { 494 unique_input = n; 495 } else if (unique_input != n) { 496 unique_input = top; 497 break; 498 } 499 } 500 if (unique_input != NULL && unique_input != top) { 501 mem = unique_input; 502 } else { 503 done = true; 504 } 505 } else { 506 assert(false, "unexpected node"); 507 } 508 } 509 if (mem != NULL) { 510 if (mem == start_mem || mem == alloc_mem) { 511 // hit a sentinel, return appropriate 0 value 512 return _igvn.zerocon(ft); 513 } else if (mem->is_Store()) { 514 return mem->in(MemNode::ValueIn); 515 } else if (mem->is_Phi()) { 516 // attempt to produce a Phi reflecting the values on the input paths of the Phi 517 Node_Stack value_phis(a, 8); 518 Node * phi = value_from_mem_phi(mem, ft, ftype, adr_t, alloc, &value_phis, ValueSearchLimit); 519 if (phi != NULL) { 520 return phi; 521 } else { 522 // Kill all new Phis 523 while(value_phis.is_nonempty()) { 524 Node* n = value_phis.node(); 525 _igvn.replace_node(n, C->top()); 526 value_phis.pop(); 527 } 528 } 529 } 530 } 531 // Something go wrong. 532 return NULL; 533 } 534 535 // Check the possibility of scalar replacement. 536 bool PhaseMacroExpand::can_eliminate_allocation(AllocateNode *alloc, GrowableArray <SafePointNode *>& safepoints) { 537 // Scan the uses of the allocation to check for anything that would 538 // prevent us from eliminating it. 539 NOT_PRODUCT( const char* fail_eliminate = NULL; ) 540 DEBUG_ONLY( Node* disq_node = NULL; ) 541 bool can_eliminate = true; 542 543 Node* res = alloc->result_cast(); 544 const TypeOopPtr* res_type = NULL; 545 if (res == NULL) { 546 // All users were eliminated. 547 } else if (!res->is_CheckCastPP()) { 548 alloc->_is_scalar_replaceable = false; // don't try again 549 NOT_PRODUCT(fail_eliminate = "Allocation does not have unique CheckCastPP";) 550 can_eliminate = false; 551 } else { 552 res_type = _igvn.type(res)->isa_oopptr(); 553 if (res_type == NULL) { 554 NOT_PRODUCT(fail_eliminate = "Neither instance or array allocation";) 555 can_eliminate = false; 556 } else if (res_type->isa_aryptr()) { 557 int length = alloc->in(AllocateNode::ALength)->find_int_con(-1); 558 if (length < 0) { 559 NOT_PRODUCT(fail_eliminate = "Array's size is not constant";) 560 can_eliminate = false; 561 } 562 } 563 } 564 565 if (can_eliminate && res != NULL) { 566 for (DUIterator_Fast jmax, j = res->fast_outs(jmax); 567 j < jmax && can_eliminate; j++) { 568 Node* use = res->fast_out(j); 569 570 if (use->is_AddP()) { 571 const TypePtr* addp_type = _igvn.type(use)->is_ptr(); 572 int offset = addp_type->offset(); 573 574 if (offset == Type::OffsetTop || offset == Type::OffsetBot) { 575 NOT_PRODUCT(fail_eliminate = "Undefined field referrence";) 576 can_eliminate = false; 577 break; 578 } 579 for (DUIterator_Fast kmax, k = use->fast_outs(kmax); 580 k < kmax && can_eliminate; k++) { 581 Node* n = use->fast_out(k); 582 if (!n->is_Store() && n->Opcode() != Op_CastP2X) { 583 DEBUG_ONLY(disq_node = n;) 584 if (n->is_Load() || n->is_LoadStore()) { 585 NOT_PRODUCT(fail_eliminate = "Field load";) 586 } else { 587 NOT_PRODUCT(fail_eliminate = "Not store field referrence";) 588 } 589 can_eliminate = false; 590 } 591 } 592 } else if (use->is_SafePoint()) { 593 SafePointNode* sfpt = use->as_SafePoint(); 594 if (sfpt->is_Call() && sfpt->as_Call()->has_non_debug_use(res)) { 595 // Object is passed as argument. 596 DEBUG_ONLY(disq_node = use;) 597 NOT_PRODUCT(fail_eliminate = "Object is passed as argument";) 598 can_eliminate = false; 599 } 600 Node* sfptMem = sfpt->memory(); 601 if (sfptMem == NULL || sfptMem->is_top()) { 602 DEBUG_ONLY(disq_node = use;) 603 NOT_PRODUCT(fail_eliminate = "NULL or TOP memory";) 604 can_eliminate = false; 605 } else { 606 safepoints.append_if_missing(sfpt); 607 } 608 } else if (use->Opcode() != Op_CastP2X) { // CastP2X is used by card mark 609 if (use->is_Phi()) { 610 if (use->outcnt() == 1 && use->unique_out()->Opcode() == Op_Return) { 611 NOT_PRODUCT(fail_eliminate = "Object is return value";) 612 } else { 613 NOT_PRODUCT(fail_eliminate = "Object is referenced by Phi";) 614 } 615 DEBUG_ONLY(disq_node = use;) 616 } else { 617 if (use->Opcode() == Op_Return) { 618 NOT_PRODUCT(fail_eliminate = "Object is return value";) 619 }else { 620 NOT_PRODUCT(fail_eliminate = "Object is referenced by node";) 621 } 622 DEBUG_ONLY(disq_node = use;) 623 } 624 can_eliminate = false; 625 } 626 } 627 } 628 629 #ifndef PRODUCT 630 if (PrintEliminateAllocations) { 631 if (can_eliminate) { 632 tty->print("Scalar "); 633 if (res == NULL) 634 alloc->dump(); 635 else 636 res->dump(); 637 } else { 638 tty->print("NotScalar (%s)", fail_eliminate); 639 if (res == NULL) 640 alloc->dump(); 641 else 642 res->dump(); 643 #ifdef ASSERT 644 if (disq_node != NULL) { 645 tty->print(" >>>> "); 646 disq_node->dump(); 647 } 648 #endif /*ASSERT*/ 649 } 650 } 651 #endif 652 return can_eliminate; 653 } 654 655 // Do scalar replacement. 656 bool PhaseMacroExpand::scalar_replacement(AllocateNode *alloc, GrowableArray <SafePointNode *>& safepoints) { 657 GrowableArray <SafePointNode *> safepoints_done; 658 659 ciKlass* klass = NULL; 660 ciInstanceKlass* iklass = NULL; 661 int nfields = 0; 662 int array_base; 663 int element_size; 664 BasicType basic_elem_type; 665 ciType* elem_type; 666 667 Node* res = alloc->result_cast(); 668 const TypeOopPtr* res_type = NULL; 669 if (res != NULL) { // Could be NULL when there are no users 670 res_type = _igvn.type(res)->isa_oopptr(); 671 } 672 673 if (res != NULL) { 674 klass = res_type->klass(); 675 if (res_type->isa_instptr()) { 676 // find the fields of the class which will be needed for safepoint debug information 677 assert(klass->is_instance_klass(), "must be an instance klass."); 678 iklass = klass->as_instance_klass(); 679 nfields = iklass->nof_nonstatic_fields(); 680 } else { 681 // find the array's elements which will be needed for safepoint debug information 682 nfields = alloc->in(AllocateNode::ALength)->find_int_con(-1); 683 assert(klass->is_array_klass() && nfields >= 0, "must be an array klass."); 684 elem_type = klass->as_array_klass()->element_type(); 685 basic_elem_type = elem_type->basic_type(); 686 array_base = arrayOopDesc::base_offset_in_bytes(basic_elem_type); 687 element_size = type2aelembytes(basic_elem_type); 688 } 689 } 690 // 691 // Process the safepoint uses 692 // 693 while (safepoints.length() > 0) { 694 SafePointNode* sfpt = safepoints.pop(); 695 Node* mem = sfpt->memory(); 696 uint first_ind = sfpt->req(); 697 SafePointScalarObjectNode* sobj = new (C, 1) SafePointScalarObjectNode(res_type, 698 #ifdef ASSERT 699 alloc, 700 #endif 701 first_ind, nfields); 702 sobj->init_req(0, sfpt->in(TypeFunc::Control)); 703 transform_later(sobj); 704 705 // Scan object's fields adding an input to the safepoint for each field. 706 for (int j = 0; j < nfields; j++) { 707 intptr_t offset; 708 ciField* field = NULL; 709 if (iklass != NULL) { 710 field = iklass->nonstatic_field_at(j); 711 offset = field->offset(); 712 elem_type = field->type(); 713 basic_elem_type = field->layout_type(); 714 } else { 715 offset = array_base + j * (intptr_t)element_size; 716 } 717 718 const Type *field_type; 719 // The next code is taken from Parse::do_get_xxx(). 720 if (basic_elem_type == T_OBJECT || basic_elem_type == T_ARRAY) { 721 if (!elem_type->is_loaded()) { 722 field_type = TypeInstPtr::BOTTOM; 723 } else if (field != NULL && field->is_constant() && field->is_static()) { 724 // This can happen if the constant oop is non-perm. 725 ciObject* con = field->constant_value().as_object(); 726 // Do not "join" in the previous type; it doesn't add value, 727 // and may yield a vacuous result if the field is of interface type. 728 field_type = TypeOopPtr::make_from_constant(con)->isa_oopptr(); 729 assert(field_type != NULL, "field singleton type must be consistent"); 730 } else { 731 field_type = TypeOopPtr::make_from_klass(elem_type->as_klass()); 732 } 733 if (UseCompressedOops) { 734 field_type = field_type->make_narrowoop(); 735 basic_elem_type = T_NARROWOOP; 736 } 737 } else { 738 field_type = Type::get_const_basic_type(basic_elem_type); 739 } 740 741 const TypeOopPtr *field_addr_type = res_type->add_offset(offset)->isa_oopptr(); 742 743 Node *field_val = value_from_mem(mem, basic_elem_type, field_type, field_addr_type, alloc); 744 if (field_val == NULL) { 745 // we weren't able to find a value for this field, 746 // give up on eliminating this allocation 747 alloc->_is_scalar_replaceable = false; // don't try again 748 // remove any extra entries we added to the safepoint 749 uint last = sfpt->req() - 1; 750 for (int k = 0; k < j; k++) { 751 sfpt->del_req(last--); 752 } 753 // rollback processed safepoints 754 while (safepoints_done.length() > 0) { 755 SafePointNode* sfpt_done = safepoints_done.pop(); 756 // remove any extra entries we added to the safepoint 757 last = sfpt_done->req() - 1; 758 for (int k = 0; k < nfields; k++) { 759 sfpt_done->del_req(last--); 760 } 761 JVMState *jvms = sfpt_done->jvms(); 762 jvms->set_endoff(sfpt_done->req()); 763 // Now make a pass over the debug information replacing any references 764 // to SafePointScalarObjectNode with the allocated object. 765 int start = jvms->debug_start(); 766 int end = jvms->debug_end(); 767 for (int i = start; i < end; i++) { 768 if (sfpt_done->in(i)->is_SafePointScalarObject()) { 769 SafePointScalarObjectNode* scobj = sfpt_done->in(i)->as_SafePointScalarObject(); 770 if (scobj->first_index() == sfpt_done->req() && 771 scobj->n_fields() == (uint)nfields) { 772 assert(scobj->alloc() == alloc, "sanity"); 773 sfpt_done->set_req(i, res); 774 } 775 } 776 } 777 } 778 #ifndef PRODUCT 779 if (PrintEliminateAllocations) { 780 if (field != NULL) { 781 tty->print("=== At SafePoint node %d can't find value of Field: ", 782 sfpt->_idx); 783 field->print(); 784 int field_idx = C->get_alias_index(field_addr_type); 785 tty->print(" (alias_idx=%d)", field_idx); 786 } else { // Array's element 787 tty->print("=== At SafePoint node %d can't find value of array element [%d]", 788 sfpt->_idx, j); 789 } 790 tty->print(", which prevents elimination of: "); 791 if (res == NULL) 792 alloc->dump(); 793 else 794 res->dump(); 795 } 796 #endif 797 return false; 798 } 799 if (UseCompressedOops && field_type->isa_narrowoop()) { 800 // Enable "DecodeN(EncodeP(Allocate)) --> Allocate" transformation 801 // to be able scalar replace the allocation. 802 if (field_val->is_EncodeP()) { 803 field_val = field_val->in(1); 804 } else { 805 field_val = transform_later(new (C, 2) DecodeNNode(field_val, field_val->bottom_type()->make_ptr())); 806 } 807 } 808 sfpt->add_req(field_val); 809 } 810 JVMState *jvms = sfpt->jvms(); 811 jvms->set_endoff(sfpt->req()); 812 // Now make a pass over the debug information replacing any references 813 // to the allocated object with "sobj" 814 int start = jvms->debug_start(); 815 int end = jvms->debug_end(); 816 for (int i = start; i < end; i++) { 817 if (sfpt->in(i) == res) { 818 sfpt->set_req(i, sobj); 819 } 820 } 821 safepoints_done.append_if_missing(sfpt); // keep it for rollback 822 } 823 return true; 824 } 825 826 // Process users of eliminated allocation. 827 void PhaseMacroExpand::process_users_of_allocation(AllocateNode *alloc) { 828 Node* res = alloc->result_cast(); 829 if (res != NULL) { 830 for (DUIterator_Last jmin, j = res->last_outs(jmin); j >= jmin; ) { 831 Node *use = res->last_out(j); 832 uint oc1 = res->outcnt(); 833 834 if (use->is_AddP()) { 835 for (DUIterator_Last kmin, k = use->last_outs(kmin); k >= kmin; ) { 836 Node *n = use->last_out(k); 837 uint oc2 = use->outcnt(); 838 if (n->is_Store()) { 839 #ifdef ASSERT 840 // Verify that there is no dependent MemBarVolatile nodes, 841 // they should be removed during IGVN, see MemBarNode::Ideal(). 842 for (DUIterator_Fast pmax, p = n->fast_outs(pmax); 843 p < pmax; p++) { 844 Node* mb = n->fast_out(p); 845 assert(mb->is_Initialize() || !mb->is_MemBar() || 846 mb->req() <= MemBarNode::Precedent || 847 mb->in(MemBarNode::Precedent) != n, 848 "MemBarVolatile should be eliminated for non-escaping object"); 849 } 850 #endif 851 _igvn.replace_node(n, n->in(MemNode::Memory)); 852 } else { 853 eliminate_card_mark(n); 854 } 855 k -= (oc2 - use->outcnt()); 856 } 857 } else { 858 eliminate_card_mark(use); 859 } 860 j -= (oc1 - res->outcnt()); 861 } 862 assert(res->outcnt() == 0, "all uses of allocated objects must be deleted"); 863 _igvn.remove_dead_node(res); 864 } 865 866 // 867 // Process other users of allocation's projections 868 // 869 if (_resproj != NULL && _resproj->outcnt() != 0) { 870 for (DUIterator_Last jmin, j = _resproj->last_outs(jmin); j >= jmin; ) { 871 Node *use = _resproj->last_out(j); 872 uint oc1 = _resproj->outcnt(); 873 if (use->is_Initialize()) { 874 // Eliminate Initialize node. 875 InitializeNode *init = use->as_Initialize(); 876 assert(init->outcnt() <= 2, "only a control and memory projection expected"); 877 Node *ctrl_proj = init->proj_out(TypeFunc::Control); 878 if (ctrl_proj != NULL) { 879 assert(init->in(TypeFunc::Control) == _fallthroughcatchproj, "allocation control projection"); 880 _igvn.replace_node(ctrl_proj, _fallthroughcatchproj); 881 } 882 Node *mem_proj = init->proj_out(TypeFunc::Memory); 883 if (mem_proj != NULL) { 884 Node *mem = init->in(TypeFunc::Memory); 885 #ifdef ASSERT 886 if (mem->is_MergeMem()) { 887 assert(mem->in(TypeFunc::Memory) == _memproj_fallthrough, "allocation memory projection"); 888 } else { 889 assert(mem == _memproj_fallthrough, "allocation memory projection"); 890 } 891 #endif 892 _igvn.replace_node(mem_proj, mem); 893 } 894 } else if (use->is_AddP()) { 895 // raw memory addresses used only by the initialization 896 _igvn.replace_node(use, C->top()); 897 } else { 898 assert(false, "only Initialize or AddP expected"); 899 } 900 j -= (oc1 - _resproj->outcnt()); 901 } 902 } 903 if (_fallthroughcatchproj != NULL) { 904 _igvn.replace_node(_fallthroughcatchproj, alloc->in(TypeFunc::Control)); 905 } 906 if (_memproj_fallthrough != NULL) { 907 _igvn.replace_node(_memproj_fallthrough, alloc->in(TypeFunc::Memory)); 908 } 909 if (_memproj_catchall != NULL) { 910 _igvn.replace_node(_memproj_catchall, C->top()); 911 } 912 if (_ioproj_fallthrough != NULL) { 913 _igvn.replace_node(_ioproj_fallthrough, alloc->in(TypeFunc::I_O)); 914 } 915 if (_ioproj_catchall != NULL) { 916 _igvn.replace_node(_ioproj_catchall, C->top()); 917 } 918 if (_catchallcatchproj != NULL) { 919 _igvn.replace_node(_catchallcatchproj, C->top()); 920 } 921 } 922 923 bool PhaseMacroExpand::eliminate_allocate_node(AllocateNode *alloc) { 924 925 if (!EliminateAllocations || !alloc->_is_scalar_replaceable) { 926 return false; 927 } 928 929 extract_call_projections(alloc); 930 931 GrowableArray <SafePointNode *> safepoints; 932 if (!can_eliminate_allocation(alloc, safepoints)) { 933 return false; 934 } 935 936 if (!scalar_replacement(alloc, safepoints)) { 937 return false; 938 } 939 940 CompileLog* log = C->log(); 941 if (log != NULL) { 942 Node* klass = alloc->in(AllocateNode::KlassNode); 943 const TypeKlassPtr* tklass = _igvn.type(klass)->is_klassptr(); 944 log->head("eliminate_allocation type='%d'", 945 log->identify(tklass->klass())); 946 JVMState* p = alloc->jvms(); 947 while (p != NULL) { 948 log->elem("jvms bci='%d' method='%d'", p->bci(), log->identify(p->method())); 949 p = p->caller(); 950 } 951 log->tail("eliminate_allocation"); 952 } 953 954 process_users_of_allocation(alloc); 955 956 #ifndef PRODUCT 957 if (PrintEliminateAllocations) { 958 if (alloc->is_AllocateArray()) 959 tty->print_cr("++++ Eliminated: %d AllocateArray", alloc->_idx); 960 else 961 tty->print_cr("++++ Eliminated: %d Allocate", alloc->_idx); 962 } 963 #endif 964 965 return true; 966 } 967 968 969 //---------------------------set_eden_pointers------------------------- 970 void PhaseMacroExpand::set_eden_pointers(Node* &eden_top_adr, Node* &eden_end_adr) { 971 if (UseTLAB) { // Private allocation: load from TLS 972 Node* thread = transform_later(new (C, 1) ThreadLocalNode()); 973 int tlab_top_offset = in_bytes(JavaThread::tlab_top_offset()); 974 int tlab_end_offset = in_bytes(JavaThread::tlab_end_offset()); 975 eden_top_adr = basic_plus_adr(top()/*not oop*/, thread, tlab_top_offset); 976 eden_end_adr = basic_plus_adr(top()/*not oop*/, thread, tlab_end_offset); 977 } else { // Shared allocation: load from globals 978 CollectedHeap* ch = Universe::heap(); 979 address top_adr = (address)ch->top_addr(); 980 address end_adr = (address)ch->end_addr(); 981 eden_top_adr = makecon(TypeRawPtr::make(top_adr)); 982 eden_end_adr = basic_plus_adr(eden_top_adr, end_adr - top_adr); 983 } 984 } 985 986 987 Node* PhaseMacroExpand::make_load(Node* ctl, Node* mem, Node* base, int offset, const Type* value_type, BasicType bt) { 988 Node* adr = basic_plus_adr(base, offset); 989 const TypePtr* adr_type = adr->bottom_type()->is_ptr(); 990 Node* value = LoadNode::make(_igvn, ctl, mem, adr, adr_type, value_type, bt); 991 transform_later(value); 992 return value; 993 } 994 995 996 Node* PhaseMacroExpand::make_store(Node* ctl, Node* mem, Node* base, int offset, Node* value, BasicType bt) { 997 Node* adr = basic_plus_adr(base, offset); 998 mem = StoreNode::make(_igvn, ctl, mem, adr, NULL, value, bt); 999 transform_later(mem); 1000 return mem; 1001 } 1002 1003 //============================================================================= 1004 // 1005 // A L L O C A T I O N 1006 // 1007 // Allocation attempts to be fast in the case of frequent small objects. 1008 // It breaks down like this: 1009 // 1010 // 1) Size in doublewords is computed. This is a constant for objects and 1011 // variable for most arrays. Doubleword units are used to avoid size 1012 // overflow of huge doubleword arrays. We need doublewords in the end for 1013 // rounding. 1014 // 1015 // 2) Size is checked for being 'too large'. Too-large allocations will go 1016 // the slow path into the VM. The slow path can throw any required 1017 // exceptions, and does all the special checks for very large arrays. The 1018 // size test can constant-fold away for objects. For objects with 1019 // finalizers it constant-folds the otherway: you always go slow with 1020 // finalizers. 1021 // 1022 // 3) If NOT using TLABs, this is the contended loop-back point. 1023 // Load-Locked the heap top. If using TLABs normal-load the heap top. 1024 // 1025 // 4) Check that heap top + size*8 < max. If we fail go the slow ` route. 1026 // NOTE: "top+size*8" cannot wrap the 4Gig line! Here's why: for largish 1027 // "size*8" we always enter the VM, where "largish" is a constant picked small 1028 // enough that there's always space between the eden max and 4Gig (old space is 1029 // there so it's quite large) and large enough that the cost of entering the VM 1030 // is dwarfed by the cost to initialize the space. 1031 // 1032 // 5) If NOT using TLABs, Store-Conditional the adjusted heap top back 1033 // down. If contended, repeat at step 3. If using TLABs normal-store 1034 // adjusted heap top back down; there is no contention. 1035 // 1036 // 6) If !ZeroTLAB then Bulk-clear the object/array. Fill in klass & mark 1037 // fields. 1038 // 1039 // 7) Merge with the slow-path; cast the raw memory pointer to the correct 1040 // oop flavor. 1041 // 1042 //============================================================================= 1043 // FastAllocateSizeLimit value is in DOUBLEWORDS. 1044 // Allocations bigger than this always go the slow route. 1045 // This value must be small enough that allocation attempts that need to 1046 // trigger exceptions go the slow route. Also, it must be small enough so 1047 // that heap_top + size_in_bytes does not wrap around the 4Gig limit. 1048 //=============================================================================j// 1049 // %%% Here is an old comment from parseHelper.cpp; is it outdated? 1050 // The allocator will coalesce int->oop copies away. See comment in 1051 // coalesce.cpp about how this works. It depends critically on the exact 1052 // code shape produced here, so if you are changing this code shape 1053 // make sure the GC info for the heap-top is correct in and around the 1054 // slow-path call. 1055 // 1056 1057 void PhaseMacroExpand::expand_allocate_common( 1058 AllocateNode* alloc, // allocation node to be expanded 1059 Node* length, // array length for an array allocation 1060 const TypeFunc* slow_call_type, // Type of slow call 1061 address slow_call_address // Address of slow call 1062 ) 1063 { 1064 1065 Node* ctrl = alloc->in(TypeFunc::Control); 1066 Node* mem = alloc->in(TypeFunc::Memory); 1067 Node* i_o = alloc->in(TypeFunc::I_O); 1068 Node* size_in_bytes = alloc->in(AllocateNode::AllocSize); 1069 Node* klass_node = alloc->in(AllocateNode::KlassNode); 1070 Node* initial_slow_test = alloc->in(AllocateNode::InitialTest); 1071 1072 assert(ctrl != NULL, "must have control"); 1073 // We need a Region and corresponding Phi's to merge the slow-path and fast-path results. 1074 // they will not be used if "always_slow" is set 1075 enum { slow_result_path = 1, fast_result_path = 2 }; 1076 Node *result_region; 1077 Node *result_phi_rawmem; 1078 Node *result_phi_rawoop; 1079 Node *result_phi_i_o; 1080 1081 // The initial slow comparison is a size check, the comparison 1082 // we want to do is a BoolTest::gt 1083 bool always_slow = false; 1084 int tv = _igvn.find_int_con(initial_slow_test, -1); 1085 if (tv >= 0) { 1086 always_slow = (tv == 1); 1087 initial_slow_test = NULL; 1088 } else { 1089 initial_slow_test = BoolNode::make_predicate(initial_slow_test, &_igvn); 1090 } 1091 1092 if (C->env()->dtrace_alloc_probes() || 1093 !UseTLAB && (!Universe::heap()->supports_inline_contig_alloc() || 1094 (UseConcMarkSweepGC && CMSIncrementalMode))) { 1095 // Force slow-path allocation 1096 always_slow = true; 1097 initial_slow_test = NULL; 1098 } 1099 1100 1101 enum { too_big_or_final_path = 1, need_gc_path = 2 }; 1102 Node *slow_region = NULL; 1103 Node *toobig_false = ctrl; 1104 1105 assert (initial_slow_test == NULL || !always_slow, "arguments must be consistent"); 1106 // generate the initial test if necessary 1107 if (initial_slow_test != NULL ) { 1108 slow_region = new (C, 3) RegionNode(3); 1109 1110 // Now make the initial failure test. Usually a too-big test but 1111 // might be a TRUE for finalizers or a fancy class check for 1112 // newInstance0. 1113 IfNode *toobig_iff = new (C, 2) IfNode(ctrl, initial_slow_test, PROB_MIN, COUNT_UNKNOWN); 1114 transform_later(toobig_iff); 1115 // Plug the failing-too-big test into the slow-path region 1116 Node *toobig_true = new (C, 1) IfTrueNode( toobig_iff ); 1117 transform_later(toobig_true); 1118 slow_region ->init_req( too_big_or_final_path, toobig_true ); 1119 toobig_false = new (C, 1) IfFalseNode( toobig_iff ); 1120 transform_later(toobig_false); 1121 } else { // No initial test, just fall into next case 1122 toobig_false = ctrl; 1123 debug_only(slow_region = NodeSentinel); 1124 } 1125 1126 Node *slow_mem = mem; // save the current memory state for slow path 1127 // generate the fast allocation code unless we know that the initial test will always go slow 1128 if (!always_slow) { 1129 // Fast path modifies only raw memory. 1130 if (mem->is_MergeMem()) { 1131 mem = mem->as_MergeMem()->memory_at(Compile::AliasIdxRaw); 1132 } 1133 1134 Node* eden_top_adr; 1135 Node* eden_end_adr; 1136 1137 set_eden_pointers(eden_top_adr, eden_end_adr); 1138 1139 // Load Eden::end. Loop invariant and hoisted. 1140 // 1141 // Note: We set the control input on "eden_end" and "old_eden_top" when using 1142 // a TLAB to work around a bug where these values were being moved across 1143 // a safepoint. These are not oops, so they cannot be include in the oop 1144 // map, but the can be changed by a GC. The proper way to fix this would 1145 // be to set the raw memory state when generating a SafepointNode. However 1146 // this will require extensive changes to the loop optimization in order to 1147 // prevent a degradation of the optimization. 1148 // See comment in memnode.hpp, around line 227 in class LoadPNode. 1149 Node *eden_end = make_load(ctrl, mem, eden_end_adr, 0, TypeRawPtr::BOTTOM, T_ADDRESS); 1150 1151 // allocate the Region and Phi nodes for the result 1152 result_region = new (C, 3) RegionNode(3); 1153 result_phi_rawmem = new (C, 3) PhiNode( result_region, Type::MEMORY, TypeRawPtr::BOTTOM ); 1154 result_phi_rawoop = new (C, 3) PhiNode( result_region, TypeRawPtr::BOTTOM ); 1155 result_phi_i_o = new (C, 3) PhiNode( result_region, Type::ABIO ); // I/O is used for Prefetch 1156 1157 // We need a Region for the loop-back contended case. 1158 enum { fall_in_path = 1, contended_loopback_path = 2 }; 1159 Node *contended_region; 1160 Node *contended_phi_rawmem; 1161 if( UseTLAB ) { 1162 contended_region = toobig_false; 1163 contended_phi_rawmem = mem; 1164 } else { 1165 contended_region = new (C, 3) RegionNode(3); 1166 contended_phi_rawmem = new (C, 3) PhiNode( contended_region, Type::MEMORY, TypeRawPtr::BOTTOM); 1167 // Now handle the passing-too-big test. We fall into the contended 1168 // loop-back merge point. 1169 contended_region ->init_req( fall_in_path, toobig_false ); 1170 contended_phi_rawmem->init_req( fall_in_path, mem ); 1171 transform_later(contended_region); 1172 transform_later(contended_phi_rawmem); 1173 } 1174 1175 // Load(-locked) the heap top. 1176 // See note above concerning the control input when using a TLAB 1177 Node *old_eden_top = UseTLAB 1178 ? new (C, 3) LoadPNode ( ctrl, contended_phi_rawmem, eden_top_adr, TypeRawPtr::BOTTOM, TypeRawPtr::BOTTOM ) 1179 : new (C, 3) LoadPLockedNode( contended_region, contended_phi_rawmem, eden_top_adr ); 1180 1181 transform_later(old_eden_top); 1182 // Add to heap top to get a new heap top 1183 Node *new_eden_top = new (C, 4) AddPNode( top(), old_eden_top, size_in_bytes ); 1184 transform_later(new_eden_top); 1185 // Check for needing a GC; compare against heap end 1186 Node *needgc_cmp = new (C, 3) CmpPNode( new_eden_top, eden_end ); 1187 transform_later(needgc_cmp); 1188 Node *needgc_bol = new (C, 2) BoolNode( needgc_cmp, BoolTest::ge ); 1189 transform_later(needgc_bol); 1190 IfNode *needgc_iff = new (C, 2) IfNode(contended_region, needgc_bol, PROB_UNLIKELY_MAG(4), COUNT_UNKNOWN ); 1191 transform_later(needgc_iff); 1192 1193 // Plug the failing-heap-space-need-gc test into the slow-path region 1194 Node *needgc_true = new (C, 1) IfTrueNode( needgc_iff ); 1195 transform_later(needgc_true); 1196 if( initial_slow_test ) { 1197 slow_region ->init_req( need_gc_path, needgc_true ); 1198 // This completes all paths into the slow merge point 1199 transform_later(slow_region); 1200 } else { // No initial slow path needed! 1201 // Just fall from the need-GC path straight into the VM call. 1202 slow_region = needgc_true; 1203 } 1204 // No need for a GC. Setup for the Store-Conditional 1205 Node *needgc_false = new (C, 1) IfFalseNode( needgc_iff ); 1206 transform_later(needgc_false); 1207 1208 // Grab regular I/O before optional prefetch may change it. 1209 // Slow-path does no I/O so just set it to the original I/O. 1210 result_phi_i_o->init_req( slow_result_path, i_o ); 1211 1212 i_o = prefetch_allocation(i_o, needgc_false, contended_phi_rawmem, 1213 old_eden_top, new_eden_top, length); 1214 1215 // Store (-conditional) the modified eden top back down. 1216 // StorePConditional produces flags for a test PLUS a modified raw 1217 // memory state. 1218 Node *store_eden_top; 1219 Node *fast_oop_ctrl; 1220 if( UseTLAB ) { 1221 store_eden_top = new (C, 4) StorePNode( needgc_false, contended_phi_rawmem, eden_top_adr, TypeRawPtr::BOTTOM, new_eden_top ); 1222 transform_later(store_eden_top); 1223 fast_oop_ctrl = needgc_false; // No contention, so this is the fast path 1224 } else { 1225 store_eden_top = new (C, 5) StorePConditionalNode( needgc_false, contended_phi_rawmem, eden_top_adr, new_eden_top, old_eden_top ); 1226 transform_later(store_eden_top); 1227 Node *contention_check = new (C, 2) BoolNode( store_eden_top, BoolTest::ne ); 1228 transform_later(contention_check); 1229 store_eden_top = new (C, 1) SCMemProjNode(store_eden_top); 1230 transform_later(store_eden_top); 1231 1232 // If not using TLABs, check to see if there was contention. 1233 IfNode *contention_iff = new (C, 2) IfNode ( needgc_false, contention_check, PROB_MIN, COUNT_UNKNOWN ); 1234 transform_later(contention_iff); 1235 Node *contention_true = new (C, 1) IfTrueNode( contention_iff ); 1236 transform_later(contention_true); 1237 // If contention, loopback and try again. 1238 contended_region->init_req( contended_loopback_path, contention_true ); 1239 contended_phi_rawmem->init_req( contended_loopback_path, store_eden_top ); 1240 1241 // Fast-path succeeded with no contention! 1242 Node *contention_false = new (C, 1) IfFalseNode( contention_iff ); 1243 transform_later(contention_false); 1244 fast_oop_ctrl = contention_false; 1245 } 1246 1247 // Rename successful fast-path variables to make meaning more obvious 1248 Node* fast_oop = old_eden_top; 1249 Node* fast_oop_rawmem = store_eden_top; 1250 fast_oop_rawmem = initialize_object(alloc, 1251 fast_oop_ctrl, fast_oop_rawmem, fast_oop, 1252 klass_node, length, size_in_bytes); 1253 1254 if (C->env()->dtrace_extended_probes()) { 1255 // Slow-path call 1256 int size = TypeFunc::Parms + 2; 1257 CallLeafNode *call = new (C, size) CallLeafNode(OptoRuntime::dtrace_object_alloc_Type(), 1258 CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_object_alloc_base), 1259 "dtrace_object_alloc", 1260 TypeRawPtr::BOTTOM); 1261 1262 // Get base of thread-local storage area 1263 Node* thread = new (C, 1) ThreadLocalNode(); 1264 transform_later(thread); 1265 1266 call->init_req(TypeFunc::Parms+0, thread); 1267 call->init_req(TypeFunc::Parms+1, fast_oop); 1268 call->init_req( TypeFunc::Control, fast_oop_ctrl ); 1269 call->init_req( TypeFunc::I_O , top() ) ; // does no i/o 1270 call->init_req( TypeFunc::Memory , fast_oop_rawmem ); 1271 call->init_req( TypeFunc::ReturnAdr, alloc->in(TypeFunc::ReturnAdr) ); 1272 call->init_req( TypeFunc::FramePtr, alloc->in(TypeFunc::FramePtr) ); 1273 transform_later(call); 1274 fast_oop_ctrl = new (C, 1) ProjNode(call,TypeFunc::Control); 1275 transform_later(fast_oop_ctrl); 1276 fast_oop_rawmem = new (C, 1) ProjNode(call,TypeFunc::Memory); 1277 transform_later(fast_oop_rawmem); 1278 } 1279 1280 // Plug in the successful fast-path into the result merge point 1281 result_region ->init_req( fast_result_path, fast_oop_ctrl ); 1282 result_phi_rawoop->init_req( fast_result_path, fast_oop ); 1283 result_phi_i_o ->init_req( fast_result_path, i_o ); 1284 result_phi_rawmem->init_req( fast_result_path, fast_oop_rawmem ); 1285 } else { 1286 slow_region = ctrl; 1287 } 1288 1289 // Generate slow-path call 1290 CallNode *call = new (C, slow_call_type->domain()->cnt()) 1291 CallStaticJavaNode(slow_call_type, slow_call_address, 1292 OptoRuntime::stub_name(slow_call_address), 1293 alloc->jvms()->bci(), 1294 TypePtr::BOTTOM); 1295 call->init_req( TypeFunc::Control, slow_region ); 1296 call->init_req( TypeFunc::I_O , top() ) ; // does no i/o 1297 call->init_req( TypeFunc::Memory , slow_mem ); // may gc ptrs 1298 call->init_req( TypeFunc::ReturnAdr, alloc->in(TypeFunc::ReturnAdr) ); 1299 call->init_req( TypeFunc::FramePtr, alloc->in(TypeFunc::FramePtr) ); 1300 1301 call->init_req(TypeFunc::Parms+0, klass_node); 1302 if (length != NULL) { 1303 call->init_req(TypeFunc::Parms+1, length); 1304 } 1305 1306 // Copy debug information and adjust JVMState information, then replace 1307 // allocate node with the call 1308 copy_call_debug_info((CallNode *) alloc, call); 1309 if (!always_slow) { 1310 call->set_cnt(PROB_UNLIKELY_MAG(4)); // Same effect as RC_UNCOMMON. 1311 } 1312 _igvn.replace_node(alloc, call); 1313 transform_later(call); 1314 1315 // Identify the output projections from the allocate node and 1316 // adjust any references to them. 1317 // The control and io projections look like: 1318 // 1319 // v---Proj(ctrl) <-----+ v---CatchProj(ctrl) 1320 // Allocate Catch 1321 // ^---Proj(io) <-------+ ^---CatchProj(io) 1322 // 1323 // We are interested in the CatchProj nodes. 1324 // 1325 extract_call_projections(call); 1326 1327 // An allocate node has separate memory projections for the uses on the control and i_o paths 1328 // Replace uses of the control memory projection with result_phi_rawmem (unless we are only generating a slow call) 1329 if (!always_slow && _memproj_fallthrough != NULL) { 1330 for (DUIterator_Fast imax, i = _memproj_fallthrough->fast_outs(imax); i < imax; i++) { 1331 Node *use = _memproj_fallthrough->fast_out(i); 1332 _igvn.hash_delete(use); 1333 imax -= replace_input(use, _memproj_fallthrough, result_phi_rawmem); 1334 _igvn._worklist.push(use); 1335 // back up iterator 1336 --i; 1337 } 1338 } 1339 // Now change uses of _memproj_catchall to use _memproj_fallthrough and delete _memproj_catchall so 1340 // we end up with a call that has only 1 memory projection 1341 if (_memproj_catchall != NULL ) { 1342 if (_memproj_fallthrough == NULL) { 1343 _memproj_fallthrough = new (C, 1) ProjNode(call, TypeFunc::Memory); 1344 transform_later(_memproj_fallthrough); 1345 } 1346 for (DUIterator_Fast imax, i = _memproj_catchall->fast_outs(imax); i < imax; i++) { 1347 Node *use = _memproj_catchall->fast_out(i); 1348 _igvn.hash_delete(use); 1349 imax -= replace_input(use, _memproj_catchall, _memproj_fallthrough); 1350 _igvn._worklist.push(use); 1351 // back up iterator 1352 --i; 1353 } 1354 } 1355 1356 // An allocate node has separate i_o projections for the uses on the control and i_o paths 1357 // Replace uses of the control i_o projection with result_phi_i_o (unless we are only generating a slow call) 1358 if (_ioproj_fallthrough == NULL) { 1359 _ioproj_fallthrough = new (C, 1) ProjNode(call, TypeFunc::I_O); 1360 transform_later(_ioproj_fallthrough); 1361 } else if (!always_slow) { 1362 for (DUIterator_Fast imax, i = _ioproj_fallthrough->fast_outs(imax); i < imax; i++) { 1363 Node *use = _ioproj_fallthrough->fast_out(i); 1364 1365 _igvn.hash_delete(use); 1366 imax -= replace_input(use, _ioproj_fallthrough, result_phi_i_o); 1367 _igvn._worklist.push(use); 1368 // back up iterator 1369 --i; 1370 } 1371 } 1372 // Now change uses of _ioproj_catchall to use _ioproj_fallthrough and delete _ioproj_catchall so 1373 // we end up with a call that has only 1 control projection 1374 if (_ioproj_catchall != NULL ) { 1375 for (DUIterator_Fast imax, i = _ioproj_catchall->fast_outs(imax); i < imax; i++) { 1376 Node *use = _ioproj_catchall->fast_out(i); 1377 _igvn.hash_delete(use); 1378 imax -= replace_input(use, _ioproj_catchall, _ioproj_fallthrough); 1379 _igvn._worklist.push(use); 1380 // back up iterator 1381 --i; 1382 } 1383 } 1384 1385 // if we generated only a slow call, we are done 1386 if (always_slow) 1387 return; 1388 1389 1390 if (_fallthroughcatchproj != NULL) { 1391 ctrl = _fallthroughcatchproj->clone(); 1392 transform_later(ctrl); 1393 _igvn.replace_node(_fallthroughcatchproj, result_region); 1394 } else { 1395 ctrl = top(); 1396 } 1397 Node *slow_result; 1398 if (_resproj == NULL) { 1399 // no uses of the allocation result 1400 slow_result = top(); 1401 } else { 1402 slow_result = _resproj->clone(); 1403 transform_later(slow_result); 1404 _igvn.replace_node(_resproj, result_phi_rawoop); 1405 } 1406 1407 // Plug slow-path into result merge point 1408 result_region ->init_req( slow_result_path, ctrl ); 1409 result_phi_rawoop->init_req( slow_result_path, slow_result); 1410 result_phi_rawmem->init_req( slow_result_path, _memproj_fallthrough ); 1411 transform_later(result_region); 1412 transform_later(result_phi_rawoop); 1413 transform_later(result_phi_rawmem); 1414 transform_later(result_phi_i_o); 1415 // This completes all paths into the result merge point 1416 } 1417 1418 1419 // Helper for PhaseMacroExpand::expand_allocate_common. 1420 // Initializes the newly-allocated storage. 1421 Node* 1422 PhaseMacroExpand::initialize_object(AllocateNode* alloc, 1423 Node* control, Node* rawmem, Node* object, 1424 Node* klass_node, Node* length, 1425 Node* size_in_bytes) { 1426 InitializeNode* init = alloc->initialization(); 1427 // Store the klass & mark bits 1428 Node* mark_node = NULL; 1429 // For now only enable fast locking for non-array types 1430 if (UseBiasedLocking && (length == NULL)) { 1431 mark_node = make_load(control, rawmem, klass_node, Klass::prototype_header_offset_in_bytes() + sizeof(oopDesc), TypeRawPtr::BOTTOM, T_ADDRESS); 1432 } else { 1433 mark_node = makecon(TypeRawPtr::make((address)markOopDesc::prototype())); 1434 } 1435 rawmem = make_store(control, rawmem, object, oopDesc::mark_offset_in_bytes(), mark_node, T_ADDRESS); 1436 1437 rawmem = make_store(control, rawmem, object, oopDesc::klass_offset_in_bytes(), klass_node, T_OBJECT); 1438 int header_size = alloc->minimum_header_size(); // conservatively small 1439 1440 // Array length 1441 if (length != NULL) { // Arrays need length field 1442 rawmem = make_store(control, rawmem, object, arrayOopDesc::length_offset_in_bytes(), length, T_INT); 1443 // conservatively small header size: 1444 header_size = arrayOopDesc::base_offset_in_bytes(T_BYTE); 1445 ciKlass* k = _igvn.type(klass_node)->is_klassptr()->klass(); 1446 if (k->is_array_klass()) // we know the exact header size in most cases: 1447 header_size = Klass::layout_helper_header_size(k->layout_helper()); 1448 } 1449 1450 // Clear the object body, if necessary. 1451 if (init == NULL) { 1452 // The init has somehow disappeared; be cautious and clear everything. 1453 // 1454 // This can happen if a node is allocated but an uncommon trap occurs 1455 // immediately. In this case, the Initialize gets associated with the 1456 // trap, and may be placed in a different (outer) loop, if the Allocate 1457 // is in a loop. If (this is rare) the inner loop gets unrolled, then 1458 // there can be two Allocates to one Initialize. The answer in all these 1459 // edge cases is safety first. It is always safe to clear immediately 1460 // within an Allocate, and then (maybe or maybe not) clear some more later. 1461 if (!ZeroTLAB) 1462 rawmem = ClearArrayNode::clear_memory(control, rawmem, object, 1463 header_size, size_in_bytes, 1464 &_igvn); 1465 } else { 1466 if (!init->is_complete()) { 1467 // Try to win by zeroing only what the init does not store. 1468 // We can also try to do some peephole optimizations, 1469 // such as combining some adjacent subword stores. 1470 rawmem = init->complete_stores(control, rawmem, object, 1471 header_size, size_in_bytes, &_igvn); 1472 } 1473 // We have no more use for this link, since the AllocateNode goes away: 1474 init->set_req(InitializeNode::RawAddress, top()); 1475 // (If we keep the link, it just confuses the register allocator, 1476 // who thinks he sees a real use of the address by the membar.) 1477 } 1478 1479 return rawmem; 1480 } 1481 1482 // Generate prefetch instructions for next allocations. 1483 Node* PhaseMacroExpand::prefetch_allocation(Node* i_o, Node*& needgc_false, 1484 Node*& contended_phi_rawmem, 1485 Node* old_eden_top, Node* new_eden_top, 1486 Node* length) { 1487 enum { fall_in_path = 1, pf_path = 2 }; 1488 if( UseTLAB && AllocatePrefetchStyle == 2 ) { 1489 // Generate prefetch allocation with watermark check. 1490 // As an allocation hits the watermark, we will prefetch starting 1491 // at a "distance" away from watermark. 1492 1493 Node *pf_region = new (C, 3) RegionNode(3); 1494 Node *pf_phi_rawmem = new (C, 3) PhiNode( pf_region, Type::MEMORY, 1495 TypeRawPtr::BOTTOM ); 1496 // I/O is used for Prefetch 1497 Node *pf_phi_abio = new (C, 3) PhiNode( pf_region, Type::ABIO ); 1498 1499 Node *thread = new (C, 1) ThreadLocalNode(); 1500 transform_later(thread); 1501 1502 Node *eden_pf_adr = new (C, 4) AddPNode( top()/*not oop*/, thread, 1503 _igvn.MakeConX(in_bytes(JavaThread::tlab_pf_top_offset())) ); 1504 transform_later(eden_pf_adr); 1505 1506 Node *old_pf_wm = new (C, 3) LoadPNode( needgc_false, 1507 contended_phi_rawmem, eden_pf_adr, 1508 TypeRawPtr::BOTTOM, TypeRawPtr::BOTTOM ); 1509 transform_later(old_pf_wm); 1510 1511 // check against new_eden_top 1512 Node *need_pf_cmp = new (C, 3) CmpPNode( new_eden_top, old_pf_wm ); 1513 transform_later(need_pf_cmp); 1514 Node *need_pf_bol = new (C, 2) BoolNode( need_pf_cmp, BoolTest::ge ); 1515 transform_later(need_pf_bol); 1516 IfNode *need_pf_iff = new (C, 2) IfNode( needgc_false, need_pf_bol, 1517 PROB_UNLIKELY_MAG(4), COUNT_UNKNOWN ); 1518 transform_later(need_pf_iff); 1519 1520 // true node, add prefetchdistance 1521 Node *need_pf_true = new (C, 1) IfTrueNode( need_pf_iff ); 1522 transform_later(need_pf_true); 1523 1524 Node *need_pf_false = new (C, 1) IfFalseNode( need_pf_iff ); 1525 transform_later(need_pf_false); 1526 1527 Node *new_pf_wmt = new (C, 4) AddPNode( top(), old_pf_wm, 1528 _igvn.MakeConX(AllocatePrefetchDistance) ); 1529 transform_later(new_pf_wmt ); 1530 new_pf_wmt->set_req(0, need_pf_true); 1531 1532 Node *store_new_wmt = new (C, 4) StorePNode( need_pf_true, 1533 contended_phi_rawmem, eden_pf_adr, 1534 TypeRawPtr::BOTTOM, new_pf_wmt ); 1535 transform_later(store_new_wmt); 1536 1537 // adding prefetches 1538 pf_phi_abio->init_req( fall_in_path, i_o ); 1539 1540 Node *prefetch_adr; 1541 Node *prefetch; 1542 uint lines = AllocatePrefetchDistance / AllocatePrefetchStepSize; 1543 uint step_size = AllocatePrefetchStepSize; 1544 uint distance = 0; 1545 1546 for ( uint i = 0; i < lines; i++ ) { 1547 prefetch_adr = new (C, 4) AddPNode( old_pf_wm, new_pf_wmt, 1548 _igvn.MakeConX(distance) ); 1549 transform_later(prefetch_adr); 1550 prefetch = new (C, 3) PrefetchWriteNode( i_o, prefetch_adr ); 1551 transform_later(prefetch); 1552 distance += step_size; 1553 i_o = prefetch; 1554 } 1555 pf_phi_abio->set_req( pf_path, i_o ); 1556 1557 pf_region->init_req( fall_in_path, need_pf_false ); 1558 pf_region->init_req( pf_path, need_pf_true ); 1559 1560 pf_phi_rawmem->init_req( fall_in_path, contended_phi_rawmem ); 1561 pf_phi_rawmem->init_req( pf_path, store_new_wmt ); 1562 1563 transform_later(pf_region); 1564 transform_later(pf_phi_rawmem); 1565 transform_later(pf_phi_abio); 1566 1567 needgc_false = pf_region; 1568 contended_phi_rawmem = pf_phi_rawmem; 1569 i_o = pf_phi_abio; 1570 } else if( UseTLAB && AllocatePrefetchStyle == 3 ) { 1571 // Insert a prefetch for each allocation only on the fast-path 1572 Node *pf_region = new (C, 3) RegionNode(3); 1573 Node *pf_phi_rawmem = new (C, 3) PhiNode( pf_region, Type::MEMORY, 1574 TypeRawPtr::BOTTOM ); 1575 1576 // Generate several prefetch instructions only for arrays. 1577 uint lines = (length != NULL) ? AllocatePrefetchLines : 1; 1578 uint step_size = AllocatePrefetchStepSize; 1579 uint distance = AllocatePrefetchDistance; 1580 1581 // Next cache address. 1582 Node *cache_adr = new (C, 4) AddPNode(old_eden_top, old_eden_top, 1583 _igvn.MakeConX(distance)); 1584 transform_later(cache_adr); 1585 cache_adr = new (C, 2) CastP2XNode(needgc_false, cache_adr); 1586 transform_later(cache_adr); 1587 Node* mask = _igvn.MakeConX(~(intptr_t)(step_size-1)); 1588 cache_adr = new (C, 3) AndXNode(cache_adr, mask); 1589 transform_later(cache_adr); 1590 cache_adr = new (C, 2) CastX2PNode(cache_adr); 1591 transform_later(cache_adr); 1592 1593 // Prefetch 1594 Node *prefetch = new (C, 3) PrefetchWriteNode( contended_phi_rawmem, cache_adr ); 1595 prefetch->set_req(0, needgc_false); 1596 transform_later(prefetch); 1597 contended_phi_rawmem = prefetch; 1598 Node *prefetch_adr; 1599 distance = step_size; 1600 for ( uint i = 1; i < lines; i++ ) { 1601 prefetch_adr = new (C, 4) AddPNode( cache_adr, cache_adr, 1602 _igvn.MakeConX(distance) ); 1603 transform_later(prefetch_adr); 1604 prefetch = new (C, 3) PrefetchWriteNode( contended_phi_rawmem, prefetch_adr ); 1605 transform_later(prefetch); 1606 distance += step_size; 1607 contended_phi_rawmem = prefetch; 1608 } 1609 } else if( AllocatePrefetchStyle > 0 ) { 1610 // Insert a prefetch for each allocation only on the fast-path 1611 Node *prefetch_adr; 1612 Node *prefetch; 1613 // Generate several prefetch instructions only for arrays. 1614 uint lines = (length != NULL) ? AllocatePrefetchLines : 1; 1615 uint step_size = AllocatePrefetchStepSize; 1616 uint distance = AllocatePrefetchDistance; 1617 for ( uint i = 0; i < lines; i++ ) { 1618 prefetch_adr = new (C, 4) AddPNode( old_eden_top, new_eden_top, 1619 _igvn.MakeConX(distance) ); 1620 transform_later(prefetch_adr); 1621 prefetch = new (C, 3) PrefetchWriteNode( i_o, prefetch_adr ); 1622 // Do not let it float too high, since if eden_top == eden_end, 1623 // both might be null. 1624 if( i == 0 ) { // Set control for first prefetch, next follows it 1625 prefetch->init_req(0, needgc_false); 1626 } 1627 transform_later(prefetch); 1628 distance += step_size; 1629 i_o = prefetch; 1630 } 1631 } 1632 return i_o; 1633 } 1634 1635 1636 void PhaseMacroExpand::expand_allocate(AllocateNode *alloc) { 1637 expand_allocate_common(alloc, NULL, 1638 OptoRuntime::new_instance_Type(), 1639 OptoRuntime::new_instance_Java()); 1640 } 1641 1642 void PhaseMacroExpand::expand_allocate_array(AllocateArrayNode *alloc) { 1643 Node* length = alloc->in(AllocateNode::ALength); 1644 expand_allocate_common(alloc, length, 1645 OptoRuntime::new_array_Type(), 1646 OptoRuntime::new_array_Java()); 1647 } 1648 1649 1650 // we have determined that this lock/unlock can be eliminated, we simply 1651 // eliminate the node without expanding it. 1652 // 1653 // Note: The membar's associated with the lock/unlock are currently not 1654 // eliminated. This should be investigated as a future enhancement. 1655 // 1656 bool PhaseMacroExpand::eliminate_locking_node(AbstractLockNode *alock) { 1657 1658 if (!alock->is_eliminated()) { 1659 return false; 1660 } 1661 if (alock->is_Lock() && !alock->is_coarsened()) { 1662 // Create new "eliminated" BoxLock node and use it 1663 // in monitor debug info for the same object. 1664 BoxLockNode* oldbox = alock->box_node()->as_BoxLock(); 1665 Node* obj = alock->obj_node(); 1666 if (!oldbox->is_eliminated()) { 1667 BoxLockNode* newbox = oldbox->clone()->as_BoxLock(); 1668 newbox->set_eliminated(); 1669 transform_later(newbox); 1670 // Replace old box node with new box for all users 1671 // of the same object. 1672 for (uint i = 0; i < oldbox->outcnt();) { 1673 1674 bool next_edge = true; 1675 Node* u = oldbox->raw_out(i); 1676 if (u == alock) { 1677 i++; 1678 continue; // It will be removed below 1679 } 1680 if (u->is_Lock() && 1681 u->as_Lock()->obj_node() == obj && 1682 // oldbox could be referenced in debug info also 1683 u->as_Lock()->box_node() == oldbox) { 1684 assert(u->as_Lock()->is_eliminated(), "sanity"); 1685 _igvn.hash_delete(u); 1686 u->set_req(TypeFunc::Parms + 1, newbox); 1687 next_edge = false; 1688 #ifdef ASSERT 1689 } else if (u->is_Unlock() && u->as_Unlock()->obj_node() == obj) { 1690 assert(u->as_Unlock()->is_eliminated(), "sanity"); 1691 #endif 1692 } 1693 // Replace old box in monitor debug info. 1694 if (u->is_SafePoint() && u->as_SafePoint()->jvms()) { 1695 SafePointNode* sfn = u->as_SafePoint(); 1696 JVMState* youngest_jvms = sfn->jvms(); 1697 int max_depth = youngest_jvms->depth(); 1698 for (int depth = 1; depth <= max_depth; depth++) { 1699 JVMState* jvms = youngest_jvms->of_depth(depth); 1700 int num_mon = jvms->nof_monitors(); 1701 // Loop over monitors 1702 for (int idx = 0; idx < num_mon; idx++) { 1703 Node* obj_node = sfn->monitor_obj(jvms, idx); 1704 Node* box_node = sfn->monitor_box(jvms, idx); 1705 if (box_node == oldbox && obj_node == obj) { 1706 int j = jvms->monitor_box_offset(idx); 1707 _igvn.hash_delete(u); 1708 u->set_req(j, newbox); 1709 next_edge = false; 1710 } 1711 } // for (int idx = 0; 1712 } // for (int depth = 1; 1713 } // if (u->is_SafePoint() 1714 if (next_edge) i++; 1715 } // for (uint i = 0; i < oldbox->outcnt();) 1716 } // if (!oldbox->is_eliminated()) 1717 } // if (alock->is_Lock() && !lock->is_coarsened()) 1718 1719 CompileLog* log = C->log(); 1720 if (log != NULL) { 1721 log->head("eliminate_lock lock='%d'", 1722 alock->is_Lock()); 1723 JVMState* p = alock->jvms(); 1724 while (p != NULL) { 1725 log->elem("jvms bci='%d' method='%d'", p->bci(), log->identify(p->method())); 1726 p = p->caller(); 1727 } 1728 log->tail("eliminate_lock"); 1729 } 1730 1731 #ifndef PRODUCT 1732 if (PrintEliminateLocks) { 1733 if (alock->is_Lock()) { 1734 tty->print_cr("++++ Eliminating: %d Lock", alock->_idx); 1735 } else { 1736 tty->print_cr("++++ Eliminating: %d Unlock", alock->_idx); 1737 } 1738 } 1739 #endif 1740 1741 Node* mem = alock->in(TypeFunc::Memory); 1742 Node* ctrl = alock->in(TypeFunc::Control); 1743 1744 extract_call_projections(alock); 1745 // There are 2 projections from the lock. The lock node will 1746 // be deleted when its last use is subsumed below. 1747 assert(alock->outcnt() == 2 && 1748 _fallthroughproj != NULL && 1749 _memproj_fallthrough != NULL, 1750 "Unexpected projections from Lock/Unlock"); 1751 1752 Node* fallthroughproj = _fallthroughproj; 1753 Node* memproj_fallthrough = _memproj_fallthrough; 1754 1755 // The memory projection from a lock/unlock is RawMem 1756 // The input to a Lock is merged memory, so extract its RawMem input 1757 // (unless the MergeMem has been optimized away.) 1758 if (alock->is_Lock()) { 1759 // Seach for MemBarAcquire node and delete it also. 1760 MemBarNode* membar = fallthroughproj->unique_ctrl_out()->as_MemBar(); 1761 assert(membar != NULL && membar->Opcode() == Op_MemBarAcquire, ""); 1762 Node* ctrlproj = membar->proj_out(TypeFunc::Control); 1763 Node* memproj = membar->proj_out(TypeFunc::Memory); 1764 _igvn.replace_node(ctrlproj, fallthroughproj); 1765 _igvn.replace_node(memproj, memproj_fallthrough); 1766 1767 // Delete FastLock node also if this Lock node is unique user 1768 // (a loop peeling may clone a Lock node). 1769 Node* flock = alock->as_Lock()->fastlock_node(); 1770 if (flock->outcnt() == 1) { 1771 assert(flock->unique_out() == alock, "sanity"); 1772 _igvn.replace_node(flock, top()); 1773 } 1774 } 1775 1776 // Seach for MemBarRelease node and delete it also. 1777 if (alock->is_Unlock() && ctrl != NULL && ctrl->is_Proj() && 1778 ctrl->in(0)->is_MemBar()) { 1779 MemBarNode* membar = ctrl->in(0)->as_MemBar(); 1780 assert(membar->Opcode() == Op_MemBarRelease && 1781 mem->is_Proj() && membar == mem->in(0), ""); 1782 _igvn.replace_node(fallthroughproj, ctrl); 1783 _igvn.replace_node(memproj_fallthrough, mem); 1784 fallthroughproj = ctrl; 1785 memproj_fallthrough = mem; 1786 ctrl = membar->in(TypeFunc::Control); 1787 mem = membar->in(TypeFunc::Memory); 1788 } 1789 1790 _igvn.replace_node(fallthroughproj, ctrl); 1791 _igvn.replace_node(memproj_fallthrough, mem); 1792 return true; 1793 } 1794 1795 1796 //------------------------------expand_lock_node---------------------- 1797 void PhaseMacroExpand::expand_lock_node(LockNode *lock) { 1798 1799 Node* ctrl = lock->in(TypeFunc::Control); 1800 Node* mem = lock->in(TypeFunc::Memory); 1801 Node* obj = lock->obj_node(); 1802 Node* box = lock->box_node(); 1803 Node* flock = lock->fastlock_node(); 1804 1805 // Make the merge point 1806 Node *region; 1807 Node *mem_phi; 1808 Node *slow_path; 1809 1810 if (UseOptoBiasInlining) { 1811 /* 1812 * See the full description in MacroAssembler::biased_locking_enter(). 1813 * 1814 * if( (mark_word & biased_lock_mask) == biased_lock_pattern ) { 1815 * // The object is biased. 1816 * proto_node = klass->prototype_header; 1817 * o_node = thread | proto_node; 1818 * x_node = o_node ^ mark_word; 1819 * if( (x_node & ~age_mask) == 0 ) { // Biased to the current thread ? 1820 * // Done. 1821 * } else { 1822 * if( (x_node & biased_lock_mask) != 0 ) { 1823 * // The klass's prototype header is no longer biased. 1824 * cas(&mark_word, mark_word, proto_node) 1825 * goto cas_lock; 1826 * } else { 1827 * // The klass's prototype header is still biased. 1828 * if( (x_node & epoch_mask) != 0 ) { // Expired epoch? 1829 * old = mark_word; 1830 * new = o_node; 1831 * } else { 1832 * // Different thread or anonymous biased. 1833 * old = mark_word & (epoch_mask | age_mask | biased_lock_mask); 1834 * new = thread | old; 1835 * } 1836 * // Try to rebias. 1837 * if( cas(&mark_word, old, new) == 0 ) { 1838 * // Done. 1839 * } else { 1840 * goto slow_path; // Failed. 1841 * } 1842 * } 1843 * } 1844 * } else { 1845 * // The object is not biased. 1846 * cas_lock: 1847 * if( FastLock(obj) == 0 ) { 1848 * // Done. 1849 * } else { 1850 * slow_path: 1851 * OptoRuntime::complete_monitor_locking_Java(obj); 1852 * } 1853 * } 1854 */ 1855 1856 region = new (C, 5) RegionNode(5); 1857 // create a Phi for the memory state 1858 mem_phi = new (C, 5) PhiNode( region, Type::MEMORY, TypeRawPtr::BOTTOM); 1859 1860 Node* fast_lock_region = new (C, 3) RegionNode(3); 1861 Node* fast_lock_mem_phi = new (C, 3) PhiNode( fast_lock_region, Type::MEMORY, TypeRawPtr::BOTTOM); 1862 1863 // First, check mark word for the biased lock pattern. 1864 Node* mark_node = make_load(ctrl, mem, obj, oopDesc::mark_offset_in_bytes(), TypeX_X, TypeX_X->basic_type()); 1865 1866 // Get fast path - mark word has the biased lock pattern. 1867 ctrl = opt_bits_test(ctrl, fast_lock_region, 1, mark_node, 1868 markOopDesc::biased_lock_mask_in_place, 1869 markOopDesc::biased_lock_pattern, true); 1870 // fast_lock_region->in(1) is set to slow path. 1871 fast_lock_mem_phi->init_req(1, mem); 1872 1873 // Now check that the lock is biased to the current thread and has 1874 // the same epoch and bias as Klass::_prototype_header. 1875 1876 // Special-case a fresh allocation to avoid building nodes: 1877 Node* klass_node = AllocateNode::Ideal_klass(obj, &_igvn); 1878 if (klass_node == NULL) { 1879 Node* k_adr = basic_plus_adr(obj, oopDesc::klass_offset_in_bytes()); 1880 klass_node = transform_later( LoadKlassNode::make(_igvn, mem, k_adr, _igvn.type(k_adr)->is_ptr()) ); 1881 #ifdef _LP64 1882 if (UseCompressedOops && klass_node->is_DecodeN()) { 1883 assert(klass_node->in(1)->Opcode() == Op_LoadNKlass, "sanity"); 1884 klass_node->in(1)->init_req(0, ctrl); 1885 } else 1886 #endif 1887 klass_node->init_req(0, ctrl); 1888 } 1889 Node *proto_node = make_load(ctrl, mem, klass_node, Klass::prototype_header_offset_in_bytes() + sizeof(oopDesc), TypeX_X, TypeX_X->basic_type()); 1890 1891 Node* thread = transform_later(new (C, 1) ThreadLocalNode()); 1892 Node* cast_thread = transform_later(new (C, 2) CastP2XNode(ctrl, thread)); 1893 Node* o_node = transform_later(new (C, 3) OrXNode(cast_thread, proto_node)); 1894 Node* x_node = transform_later(new (C, 3) XorXNode(o_node, mark_node)); 1895 1896 // Get slow path - mark word does NOT match the value. 1897 Node* not_biased_ctrl = opt_bits_test(ctrl, region, 3, x_node, 1898 (~markOopDesc::age_mask_in_place), 0); 1899 // region->in(3) is set to fast path - the object is biased to the current thread. 1900 mem_phi->init_req(3, mem); 1901 1902 1903 // Mark word does NOT match the value (thread | Klass::_prototype_header). 1904 1905 1906 // First, check biased pattern. 1907 // Get fast path - _prototype_header has the same biased lock pattern. 1908 ctrl = opt_bits_test(not_biased_ctrl, fast_lock_region, 2, x_node, 1909 markOopDesc::biased_lock_mask_in_place, 0, true); 1910 1911 not_biased_ctrl = fast_lock_region->in(2); // Slow path 1912 // fast_lock_region->in(2) - the prototype header is no longer biased 1913 // and we have to revoke the bias on this object. 1914 // We are going to try to reset the mark of this object to the prototype 1915 // value and fall through to the CAS-based locking scheme. 1916 Node* adr = basic_plus_adr(obj, oopDesc::mark_offset_in_bytes()); 1917 Node* cas = new (C, 5) StoreXConditionalNode(not_biased_ctrl, mem, adr, 1918 proto_node, mark_node); 1919 transform_later(cas); 1920 Node* proj = transform_later( new (C, 1) SCMemProjNode(cas)); 1921 fast_lock_mem_phi->init_req(2, proj); 1922 1923 1924 // Second, check epoch bits. 1925 Node* rebiased_region = new (C, 3) RegionNode(3); 1926 Node* old_phi = new (C, 3) PhiNode( rebiased_region, TypeX_X); 1927 Node* new_phi = new (C, 3) PhiNode( rebiased_region, TypeX_X); 1928 1929 // Get slow path - mark word does NOT match epoch bits. 1930 Node* epoch_ctrl = opt_bits_test(ctrl, rebiased_region, 1, x_node, 1931 markOopDesc::epoch_mask_in_place, 0); 1932 // The epoch of the current bias is not valid, attempt to rebias the object 1933 // toward the current thread. 1934 rebiased_region->init_req(2, epoch_ctrl); 1935 old_phi->init_req(2, mark_node); 1936 new_phi->init_req(2, o_node); 1937 1938 // rebiased_region->in(1) is set to fast path. 1939 // The epoch of the current bias is still valid but we know 1940 // nothing about the owner; it might be set or it might be clear. 1941 Node* cmask = MakeConX(markOopDesc::biased_lock_mask_in_place | 1942 markOopDesc::age_mask_in_place | 1943 markOopDesc::epoch_mask_in_place); 1944 Node* old = transform_later(new (C, 3) AndXNode(mark_node, cmask)); 1945 cast_thread = transform_later(new (C, 2) CastP2XNode(ctrl, thread)); 1946 Node* new_mark = transform_later(new (C, 3) OrXNode(cast_thread, old)); 1947 old_phi->init_req(1, old); 1948 new_phi->init_req(1, new_mark); 1949 1950 transform_later(rebiased_region); 1951 transform_later(old_phi); 1952 transform_later(new_phi); 1953 1954 // Try to acquire the bias of the object using an atomic operation. 1955 // If this fails we will go in to the runtime to revoke the object's bias. 1956 cas = new (C, 5) StoreXConditionalNode(rebiased_region, mem, adr, 1957 new_phi, old_phi); 1958 transform_later(cas); 1959 proj = transform_later( new (C, 1) SCMemProjNode(cas)); 1960 1961 // Get slow path - Failed to CAS. 1962 not_biased_ctrl = opt_bits_test(rebiased_region, region, 4, cas, 0, 0); 1963 mem_phi->init_req(4, proj); 1964 // region->in(4) is set to fast path - the object is rebiased to the current thread. 1965 1966 // Failed to CAS. 1967 slow_path = new (C, 3) RegionNode(3); 1968 Node *slow_mem = new (C, 3) PhiNode( slow_path, Type::MEMORY, TypeRawPtr::BOTTOM); 1969 1970 slow_path->init_req(1, not_biased_ctrl); // Capture slow-control 1971 slow_mem->init_req(1, proj); 1972 1973 // Call CAS-based locking scheme (FastLock node). 1974 1975 transform_later(fast_lock_region); 1976 transform_later(fast_lock_mem_phi); 1977 1978 // Get slow path - FastLock failed to lock the object. 1979 ctrl = opt_bits_test(fast_lock_region, region, 2, flock, 0, 0); 1980 mem_phi->init_req(2, fast_lock_mem_phi); 1981 // region->in(2) is set to fast path - the object is locked to the current thread. 1982 1983 slow_path->init_req(2, ctrl); // Capture slow-control 1984 slow_mem->init_req(2, fast_lock_mem_phi); 1985 1986 transform_later(slow_path); 1987 transform_later(slow_mem); 1988 // Reset lock's memory edge. 1989 lock->set_req(TypeFunc::Memory, slow_mem); 1990 1991 } else { 1992 region = new (C, 3) RegionNode(3); 1993 // create a Phi for the memory state 1994 mem_phi = new (C, 3) PhiNode( region, Type::MEMORY, TypeRawPtr::BOTTOM); 1995 1996 // Optimize test; set region slot 2 1997 slow_path = opt_bits_test(ctrl, region, 2, flock, 0, 0); 1998 mem_phi->init_req(2, mem); 1999 } 2000 2001 // Make slow path call 2002 CallNode *call = make_slow_call( (CallNode *) lock, OptoRuntime::complete_monitor_enter_Type(), OptoRuntime::complete_monitor_locking_Java(), NULL, slow_path, obj, box ); 2003 2004 extract_call_projections(call); 2005 2006 // Slow path can only throw asynchronous exceptions, which are always 2007 // de-opted. So the compiler thinks the slow-call can never throw an 2008 // exception. If it DOES throw an exception we would need the debug 2009 // info removed first (since if it throws there is no monitor). 2010 assert ( _ioproj_fallthrough == NULL && _ioproj_catchall == NULL && 2011 _memproj_catchall == NULL && _catchallcatchproj == NULL, "Unexpected projection from Lock"); 2012 2013 // Capture slow path 2014 // disconnect fall-through projection from call and create a new one 2015 // hook up users of fall-through projection to region 2016 Node *slow_ctrl = _fallthroughproj->clone(); 2017 transform_later(slow_ctrl); 2018 _igvn.hash_delete(_fallthroughproj); 2019 _fallthroughproj->disconnect_inputs(NULL); 2020 region->init_req(1, slow_ctrl); 2021 // region inputs are now complete 2022 transform_later(region); 2023 _igvn.replace_node(_fallthroughproj, region); 2024 2025 Node *memproj = transform_later( new(C, 1) ProjNode(call, TypeFunc::Memory) ); 2026 mem_phi->init_req(1, memproj ); 2027 transform_later(mem_phi); 2028 _igvn.replace_node(_memproj_fallthrough, mem_phi); 2029 } 2030 2031 //------------------------------expand_unlock_node---------------------- 2032 void PhaseMacroExpand::expand_unlock_node(UnlockNode *unlock) { 2033 2034 Node* ctrl = unlock->in(TypeFunc::Control); 2035 Node* mem = unlock->in(TypeFunc::Memory); 2036 Node* obj = unlock->obj_node(); 2037 Node* box = unlock->box_node(); 2038 2039 // No need for a null check on unlock 2040 2041 // Make the merge point 2042 Node *region; 2043 Node *mem_phi; 2044 2045 if (UseOptoBiasInlining) { 2046 // Check for biased locking unlock case, which is a no-op. 2047 // See the full description in MacroAssembler::biased_locking_exit(). 2048 region = new (C, 4) RegionNode(4); 2049 // create a Phi for the memory state 2050 mem_phi = new (C, 4) PhiNode( region, Type::MEMORY, TypeRawPtr::BOTTOM); 2051 mem_phi->init_req(3, mem); 2052 2053 Node* mark_node = make_load(ctrl, mem, obj, oopDesc::mark_offset_in_bytes(), TypeX_X, TypeX_X->basic_type()); 2054 ctrl = opt_bits_test(ctrl, region, 3, mark_node, 2055 markOopDesc::biased_lock_mask_in_place, 2056 markOopDesc::biased_lock_pattern); 2057 } else { 2058 region = new (C, 3) RegionNode(3); 2059 // create a Phi for the memory state 2060 mem_phi = new (C, 3) PhiNode( region, Type::MEMORY, TypeRawPtr::BOTTOM); 2061 } 2062 2063 FastUnlockNode *funlock = new (C, 3) FastUnlockNode( ctrl, obj, box ); 2064 funlock = transform_later( funlock )->as_FastUnlock(); 2065 // Optimize test; set region slot 2 2066 Node *slow_path = opt_bits_test(ctrl, region, 2, funlock, 0, 0); 2067 2068 CallNode *call = make_slow_call( (CallNode *) unlock, OptoRuntime::complete_monitor_exit_Type(), CAST_FROM_FN_PTR(address, SharedRuntime::complete_monitor_unlocking_C), "complete_monitor_unlocking_C", slow_path, obj, box ); 2069 2070 extract_call_projections(call); 2071 2072 assert ( _ioproj_fallthrough == NULL && _ioproj_catchall == NULL && 2073 _memproj_catchall == NULL && _catchallcatchproj == NULL, "Unexpected projection from Lock"); 2074 2075 // No exceptions for unlocking 2076 // Capture slow path 2077 // disconnect fall-through projection from call and create a new one 2078 // hook up users of fall-through projection to region 2079 Node *slow_ctrl = _fallthroughproj->clone(); 2080 transform_later(slow_ctrl); 2081 _igvn.hash_delete(_fallthroughproj); 2082 _fallthroughproj->disconnect_inputs(NULL); 2083 region->init_req(1, slow_ctrl); 2084 // region inputs are now complete 2085 transform_later(region); 2086 _igvn.replace_node(_fallthroughproj, region); 2087 2088 Node *memproj = transform_later( new(C, 1) ProjNode(call, TypeFunc::Memory) ); 2089 mem_phi->init_req(1, memproj ); 2090 mem_phi->init_req(2, mem); 2091 transform_later(mem_phi); 2092 _igvn.replace_node(_memproj_fallthrough, mem_phi); 2093 } 2094 2095 //------------------------------expand_macro_nodes---------------------- 2096 // Returns true if a failure occurred. 2097 bool PhaseMacroExpand::expand_macro_nodes() { 2098 if (C->macro_count() == 0) 2099 return false; 2100 // First, attempt to eliminate locks 2101 bool progress = true; 2102 while (progress) { 2103 progress = false; 2104 for (int i = C->macro_count(); i > 0; i--) { 2105 Node * n = C->macro_node(i-1); 2106 bool success = false; 2107 debug_only(int old_macro_count = C->macro_count();); 2108 if (n->is_AbstractLock()) { 2109 success = eliminate_locking_node(n->as_AbstractLock()); 2110 } else if (n->Opcode() == Op_Opaque1 || n->Opcode() == Op_Opaque2) { 2111 _igvn.replace_node(n, n->in(1)); 2112 success = true; 2113 } 2114 assert(success == (C->macro_count() < old_macro_count), "elimination reduces macro count"); 2115 progress = progress || success; 2116 } 2117 } 2118 // Next, attempt to eliminate allocations 2119 progress = true; 2120 while (progress) { 2121 progress = false; 2122 for (int i = C->macro_count(); i > 0; i--) { 2123 Node * n = C->macro_node(i-1); 2124 bool success = false; 2125 debug_only(int old_macro_count = C->macro_count();); 2126 switch (n->class_id()) { 2127 case Node::Class_Allocate: 2128 case Node::Class_AllocateArray: 2129 success = eliminate_allocate_node(n->as_Allocate()); 2130 break; 2131 case Node::Class_Lock: 2132 case Node::Class_Unlock: 2133 assert(!n->as_AbstractLock()->is_eliminated(), "sanity"); 2134 break; 2135 default: 2136 assert(false, "unknown node type in macro list"); 2137 } 2138 assert(success == (C->macro_count() < old_macro_count), "elimination reduces macro count"); 2139 progress = progress || success; 2140 } 2141 } 2142 // Make sure expansion will not cause node limit to be exceeded. 2143 // Worst case is a macro node gets expanded into about 50 nodes. 2144 // Allow 50% more for optimization. 2145 if (C->check_node_count(C->macro_count() * 75, "out of nodes before macro expansion" ) ) 2146 return true; 2147 2148 // expand "macro" nodes 2149 // nodes are removed from the macro list as they are processed 2150 while (C->macro_count() > 0) { 2151 int macro_count = C->macro_count(); 2152 Node * n = C->macro_node(macro_count-1); 2153 assert(n->is_macro(), "only macro nodes expected here"); 2154 if (_igvn.type(n) == Type::TOP || n->in(0)->is_top() ) { 2155 // node is unreachable, so don't try to expand it 2156 C->remove_macro_node(n); 2157 continue; 2158 } 2159 switch (n->class_id()) { 2160 case Node::Class_Allocate: 2161 expand_allocate(n->as_Allocate()); 2162 break; 2163 case Node::Class_AllocateArray: 2164 expand_allocate_array(n->as_AllocateArray()); 2165 break; 2166 case Node::Class_Lock: 2167 expand_lock_node(n->as_Lock()); 2168 break; 2169 case Node::Class_Unlock: 2170 expand_unlock_node(n->as_Unlock()); 2171 break; 2172 default: 2173 assert(false, "unknown node type in macro list"); 2174 } 2175 assert(C->macro_count() < macro_count, "must have deleted a node from macro list"); 2176 if (C->failing()) return true; 2177 } 2178 2179 _igvn.set_delay_transform(false); 2180 _igvn.optimize(); 2181 return false; 2182 }