src/share/vm/opto/macro.cpp

Tue, 08 Aug 2017 15:57:29 +0800

author
aoqi
date
Tue, 08 Aug 2017 15:57:29 +0800
changeset 6876
710a3c8b516e
parent 6518
62c54fcc0a35
parent 0
f90c822e73f8
child 7535
7ae4e26cb1e0
permissions
-rw-r--r--

merge

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

mercurial