macro.cpp revision 3042
0N/A/*
1988N/A * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
1879N/A#include "precompiled.hpp"
1879N/A#include "compiler/compileLog.hpp"
1879N/A#include "libadt/vectset.hpp"
1879N/A#include "opto/addnode.hpp"
1879N/A#include "opto/callnode.hpp"
1879N/A#include "opto/cfgnode.hpp"
1879N/A#include "opto/compile.hpp"
1879N/A#include "opto/connode.hpp"
1879N/A#include "opto/locknode.hpp"
1879N/A#include "opto/loopnode.hpp"
1879N/A#include "opto/macro.hpp"
1879N/A#include "opto/memnode.hpp"
1879N/A#include "opto/node.hpp"
1879N/A#include "opto/phaseX.hpp"
1879N/A#include "opto/rootnode.hpp"
1879N/A#include "opto/runtime.hpp"
1879N/A#include "opto/subnode.hpp"
1879N/A#include "opto/type.hpp"
1879N/A#include "runtime/sharedRuntime.hpp"
0N/A
0N/A
0N/A//
0N/A// Replace any references to "oldref" in inputs to "use" with "newref".
0N/A// Returns the number of replacements made.
0N/A//
0N/Aint PhaseMacroExpand::replace_input(Node *use, Node *oldref, Node *newref) {
0N/A int nreplacements = 0;
0N/A uint req = use->req();
0N/A for (uint j = 0; j < use->len(); j++) {
0N/A Node *uin = use->in(j);
0N/A if (uin == oldref) {
0N/A if (j < req)
0N/A use->set_req(j, newref);
0N/A else
0N/A use->set_prec(j, newref);
0N/A nreplacements++;
0N/A } else if (j >= req && uin == NULL) {
0N/A break;
0N/A }
0N/A }
0N/A return nreplacements;
0N/A}
0N/A
0N/Avoid PhaseMacroExpand::copy_call_debug_info(CallNode *oldcall, CallNode * newcall) {
0N/A // Copy debug information and adjust JVMState information
0N/A uint old_dbg_start = oldcall->tf()->domain()->cnt();
0N/A uint new_dbg_start = newcall->tf()->domain()->cnt();
0N/A int jvms_adj = new_dbg_start - old_dbg_start;
0N/A assert (new_dbg_start == newcall->req(), "argument count mismatch");
63N/A
63N/A Dict* sosn_map = new Dict(cmpkey,hashkey);
0N/A for (uint i = old_dbg_start; i < oldcall->req(); i++) {
63N/A Node* old_in = oldcall->in(i);
63N/A // Clone old SafePointScalarObjectNodes, adjusting their field contents.
460N/A if (old_in != NULL && old_in->is_SafePointScalarObject()) {
63N/A SafePointScalarObjectNode* old_sosn = old_in->as_SafePointScalarObject();
63N/A uint old_unique = C->unique();
63N/A Node* new_in = old_sosn->clone(jvms_adj, sosn_map);
63N/A if (old_unique != C->unique()) {
2958N/A new_in->set_req(0, C->root()); // reset control edge
63N/A new_in = transform_later(new_in); // Register new node.
63N/A }
63N/A old_in = new_in;
63N/A }
63N/A newcall->add_req(old_in);
0N/A }
63N/A
0N/A newcall->set_jvms(oldcall->jvms());
0N/A for (JVMState *jvms = newcall->jvms(); jvms != NULL; jvms = jvms->caller()) {
0N/A jvms->set_map(newcall);
0N/A jvms->set_locoff(jvms->locoff()+jvms_adj);
0N/A jvms->set_stkoff(jvms->stkoff()+jvms_adj);
0N/A jvms->set_monoff(jvms->monoff()+jvms_adj);
63N/A jvms->set_scloff(jvms->scloff()+jvms_adj);
0N/A jvms->set_endoff(jvms->endoff()+jvms_adj);
0N/A }
0N/A}
0N/A
420N/ANode* PhaseMacroExpand::opt_bits_test(Node* ctrl, Node* region, int edge, Node* word, int mask, int bits, bool return_fast_path) {
420N/A Node* cmp;
420N/A if (mask != 0) {
420N/A Node* and_node = transform_later(new (C, 3) AndXNode(word, MakeConX(mask)));
420N/A cmp = transform_later(new (C, 3) CmpXNode(and_node, MakeConX(bits)));
420N/A } else {
420N/A cmp = word;
420N/A }
420N/A Node* bol = transform_later(new (C, 2) BoolNode(cmp, BoolTest::ne));
420N/A IfNode* iff = new (C, 2) IfNode( ctrl, bol, PROB_MIN, COUNT_UNKNOWN );
420N/A transform_later(iff);
0N/A
420N/A // Fast path taken.
420N/A Node *fast_taken = transform_later( new (C, 1) IfFalseNode(iff) );
0N/A
0N/A // Fast path not-taken, i.e. slow path
420N/A Node *slow_taken = transform_later( new (C, 1) IfTrueNode(iff) );
420N/A
420N/A if (return_fast_path) {
420N/A region->init_req(edge, slow_taken); // Capture slow-control
420N/A return fast_taken;
420N/A } else {
420N/A region->init_req(edge, fast_taken); // Capture fast-control
420N/A return slow_taken;
420N/A }
0N/A}
0N/A
0N/A//--------------------copy_predefined_input_for_runtime_call--------------------
0N/Avoid PhaseMacroExpand::copy_predefined_input_for_runtime_call(Node * ctrl, CallNode* oldcall, CallNode* call) {
0N/A // Set fixed predefined input arguments
0N/A call->init_req( TypeFunc::Control, ctrl );
0N/A call->init_req( TypeFunc::I_O , oldcall->in( TypeFunc::I_O) );
0N/A call->init_req( TypeFunc::Memory , oldcall->in( TypeFunc::Memory ) ); // ?????
0N/A call->init_req( TypeFunc::ReturnAdr, oldcall->in( TypeFunc::ReturnAdr ) );
0N/A call->init_req( TypeFunc::FramePtr, oldcall->in( TypeFunc::FramePtr ) );
0N/A}
0N/A
0N/A//------------------------------make_slow_call---------------------------------
0N/ACallNode* 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) {
0N/A
0N/A // Slow-path call
0N/A int size = slow_call_type->domain()->cnt();
0N/A CallNode *call = leaf_name
0N/A ? (CallNode*)new (C, size) CallLeafNode ( slow_call_type, slow_call, leaf_name, TypeRawPtr::BOTTOM )
0N/A : (CallNode*)new (C, size) CallStaticJavaNode( slow_call_type, slow_call, OptoRuntime::stub_name(slow_call), oldcall->jvms()->bci(), TypeRawPtr::BOTTOM );
0N/A
0N/A // Slow path call has no side-effects, uses few values
0N/A copy_predefined_input_for_runtime_call(slow_path, oldcall, call );
0N/A if (parm0 != NULL) call->init_req(TypeFunc::Parms+0, parm0);
0N/A if (parm1 != NULL) call->init_req(TypeFunc::Parms+1, parm1);
0N/A copy_call_debug_info(oldcall, call);
0N/A call->set_cnt(PROB_UNLIKELY_MAG(4)); // Same effect as RC_UNCOMMON.
1541N/A _igvn.replace_node(oldcall, call);
0N/A transform_later(call);
0N/A
0N/A return call;
0N/A}
0N/A
0N/Avoid PhaseMacroExpand::extract_call_projections(CallNode *call) {
0N/A _fallthroughproj = NULL;
0N/A _fallthroughcatchproj = NULL;
0N/A _ioproj_fallthrough = NULL;
0N/A _ioproj_catchall = NULL;
0N/A _catchallcatchproj = NULL;
0N/A _memproj_fallthrough = NULL;
0N/A _memproj_catchall = NULL;
0N/A _resproj = NULL;
0N/A for (DUIterator_Fast imax, i = call->fast_outs(imax); i < imax; i++) {
0N/A ProjNode *pn = call->fast_out(i)->as_Proj();
0N/A switch (pn->_con) {
0N/A case TypeFunc::Control:
0N/A {
0N/A // For Control (fallthrough) and I_O (catch_all_index) we have CatchProj -> Catch -> Proj
0N/A _fallthroughproj = pn;
0N/A DUIterator_Fast jmax, j = pn->fast_outs(jmax);
0N/A const Node *cn = pn->fast_out(j);
0N/A if (cn->is_Catch()) {
0N/A ProjNode *cpn = NULL;
0N/A for (DUIterator_Fast kmax, k = cn->fast_outs(kmax); k < kmax; k++) {
0N/A cpn = cn->fast_out(k)->as_Proj();
0N/A assert(cpn->is_CatchProj(), "must be a CatchProjNode");
0N/A if (cpn->_con == CatchProjNode::fall_through_index)
0N/A _fallthroughcatchproj = cpn;
0N/A else {
0N/A assert(cpn->_con == CatchProjNode::catch_all_index, "must be correct index.");
0N/A _catchallcatchproj = cpn;
0N/A }
0N/A }
0N/A }
0N/A break;
0N/A }
0N/A case TypeFunc::I_O:
0N/A if (pn->_is_io_use)
0N/A _ioproj_catchall = pn;
0N/A else
0N/A _ioproj_fallthrough = pn;
0N/A break;
0N/A case TypeFunc::Memory:
0N/A if (pn->_is_io_use)
0N/A _memproj_catchall = pn;
0N/A else
0N/A _memproj_fallthrough = pn;
0N/A break;
0N/A case TypeFunc::Parms:
0N/A _resproj = pn;
0N/A break;
0N/A default:
0N/A assert(false, "unexpected projection from allocation node.");
0N/A }
0N/A }
0N/A
0N/A}
0N/A
73N/A// Eliminate a card mark sequence. p2x is a ConvP2XNode
851N/Avoid PhaseMacroExpand::eliminate_card_mark(Node* p2x) {
73N/A assert(p2x->Opcode() == Op_CastP2X, "ConvP2XNode required");
851N/A if (!UseG1GC) {
851N/A // vanilla/CMS post barrier
851N/A Node *shift = p2x->unique_out();
851N/A Node *addp = shift->unique_out();
851N/A for (DUIterator_Last jmin, j = addp->last_outs(jmin); j >= jmin; --j) {
2379N/A Node *mem = addp->last_out(j);
2379N/A if (UseCondCardMark && mem->is_Load()) {
2379N/A assert(mem->Opcode() == Op_LoadB, "unexpected code shape");
2379N/A // The load is checking if the card has been written so
2379N/A // replace it with zero to fold the test.
2379N/A _igvn.replace_node(mem, intcon(0));
2379N/A continue;
2379N/A }
2379N/A assert(mem->is_Store(), "store required");
2379N/A _igvn.replace_node(mem, mem->in(MemNode::Memory));
851N/A }
851N/A } else {
851N/A // G1 pre/post barriers
851N/A assert(p2x->outcnt() == 2, "expects 2 users: Xor and URShift nodes");
851N/A // It could be only one user, URShift node, in Object.clone() instrinsic
851N/A // but the new allocation is passed to arraycopy stub and it could not
851N/A // be scalar replaced. So we don't check the case.
851N/A
851N/A // Remove G1 post barrier.
851N/A
851N/A // Search for CastP2X->Xor->URShift->Cmp path which
851N/A // checks if the store done to a different from the value's region.
851N/A // And replace Cmp with #0 (false) to collapse G1 post barrier.
851N/A Node* xorx = NULL;
851N/A for (DUIterator_Fast imax, i = p2x->fast_outs(imax); i < imax; i++) {
851N/A Node* u = p2x->fast_out(i);
851N/A if (u->Opcode() == Op_XorX) {
851N/A xorx = u;
851N/A break;
851N/A }
851N/A }
851N/A assert(xorx != NULL, "missing G1 post barrier");
851N/A Node* shift = xorx->unique_out();
851N/A Node* cmpx = shift->unique_out();
851N/A assert(cmpx->is_Cmp() && cmpx->unique_out()->is_Bool() &&
851N/A cmpx->unique_out()->as_Bool()->_test._test == BoolTest::ne,
851N/A "missing region check in G1 post barrier");
851N/A _igvn.replace_node(cmpx, makecon(TypeInt::CC_EQ));
851N/A
851N/A // Remove G1 pre barrier.
851N/A
851N/A // Search "if (marking != 0)" check and set it to "false".
851N/A Node* this_region = p2x->in(0);
851N/A assert(this_region != NULL, "");
851N/A // There is no G1 pre barrier if previous stored value is NULL
851N/A // (for example, after initialization).
851N/A if (this_region->is_Region() && this_region->req() == 3) {
851N/A int ind = 1;
851N/A if (!this_region->in(ind)->is_IfFalse()) {
851N/A ind = 2;
851N/A }
851N/A if (this_region->in(ind)->is_IfFalse()) {
851N/A Node* bol = this_region->in(ind)->in(0)->in(1);
851N/A assert(bol->is_Bool(), "");
851N/A cmpx = bol->in(1);
851N/A if (bol->as_Bool()->_test._test == BoolTest::ne &&
851N/A cmpx->is_Cmp() && cmpx->in(2) == intcon(0) &&
851N/A cmpx->in(1)->is_Load()) {
851N/A Node* adr = cmpx->in(1)->as_Load()->in(MemNode::Address);
851N/A const int marking_offset = in_bytes(JavaThread::satb_mark_queue_offset() +
851N/A PtrQueue::byte_offset_of_active());
851N/A if (adr->is_AddP() && adr->in(AddPNode::Base) == top() &&
851N/A adr->in(AddPNode::Address)->Opcode() == Op_ThreadLocal &&
851N/A adr->in(AddPNode::Offset) == MakeConX(marking_offset)) {
851N/A _igvn.replace_node(cmpx, makecon(TypeInt::CC_EQ));
851N/A }
851N/A }
851N/A }
851N/A }
851N/A // Now CastP2X can be removed since it is used only on dead path
851N/A // which currently still alive until igvn optimize it.
851N/A assert(p2x->unique_out()->Opcode() == Op_URShiftX, "");
851N/A _igvn.replace_node(p2x, top());
73N/A }
73N/A}
73N/A
73N/A// Search for a memory operation for the specified memory slice.
253N/Astatic Node *scan_mem_chain(Node *mem, int alias_idx, int offset, Node *start_mem, Node *alloc, PhaseGVN *phase) {
73N/A Node *orig_mem = mem;
73N/A Node *alloc_mem = alloc->in(TypeFunc::Memory);
253N/A const TypeOopPtr *tinst = phase->C->get_adr_type(alias_idx)->isa_oopptr();
73N/A while (true) {
73N/A if (mem == alloc_mem || mem == start_mem ) {
605N/A return mem; // hit one of our sentinels
73N/A } else if (mem->is_MergeMem()) {
73N/A mem = mem->as_MergeMem()->memory_at(alias_idx);
73N/A } else if (mem->is_Proj() && mem->as_Proj()->_con == TypeFunc::Memory) {
73N/A Node *in = mem->in(0);
73N/A // we can safely skip over safepoints, calls, locks and membars because we
73N/A // already know that the object is safe to eliminate.
73N/A if (in->is_Initialize() && in->as_Initialize()->allocation() == alloc) {
73N/A return in;
253N/A } else if (in->is_Call()) {
253N/A CallNode *call = in->as_Call();
253N/A if (!call->may_modify(tinst, phase)) {
253N/A mem = call->in(TypeFunc::Memory);
253N/A }
253N/A mem = in->in(TypeFunc::Memory);
253N/A } else if (in->is_MemBar()) {
73N/A mem = in->in(TypeFunc::Memory);
73N/A } else {
73N/A assert(false, "unexpected projection");
73N/A }
73N/A } else if (mem->is_Store()) {
73N/A const TypePtr* atype = mem->as_Store()->adr_type();
73N/A int adr_idx = Compile::current()->get_alias_index(atype);
73N/A if (adr_idx == alias_idx) {
73N/A assert(atype->isa_oopptr(), "address type must be oopptr");
73N/A int adr_offset = atype->offset();
73N/A uint adr_iid = atype->is_oopptr()->instance_id();
73N/A // Array elements references have the same alias_idx
73N/A // but different offset and different instance_id.
73N/A if (adr_offset == offset && adr_iid == alloc->_idx)
73N/A return mem;
73N/A } else {
73N/A assert(adr_idx == Compile::AliasIdxRaw, "address must match or be raw");
73N/A }
73N/A mem = mem->in(MemNode::Memory);
1100N/A } else if (mem->is_ClearArray()) {
1100N/A if (!ClearArrayNode::step_through(&mem, alloc->_idx, phase)) {
1100N/A // Can not bypass initialization of the instance
1100N/A // we are looking.
1100N/A debug_only(intptr_t offset;)
1100N/A assert(alloc == AllocateNode::Ideal_allocation(mem->in(3), phase, offset), "sanity");
1100N/A InitializeNode* init = alloc->as_Allocate()->initialization();
1100N/A // We are looking for stored value, return Initialize node
1100N/A // or memory edge from Allocate node.
1100N/A if (init != NULL)
1100N/A return init;
1100N/A else
1100N/A return alloc->in(TypeFunc::Memory); // It will produce zero value (see callers).
1100N/A }
1100N/A // Otherwise skip it (the call updated 'mem' value).
584N/A } else if (mem->Opcode() == Op_SCMemProj) {
584N/A assert(mem->in(0)->is_LoadStore(), "sanity");
584N/A const TypePtr* atype = mem->in(0)->in(MemNode::Address)->bottom_type()->is_ptr();
584N/A int adr_idx = Compile::current()->get_alias_index(atype);
584N/A if (adr_idx == alias_idx) {
584N/A assert(false, "Object is not scalar replaceable if a LoadStore node access its field");
584N/A return NULL;
584N/A }
584N/A mem = mem->in(0)->in(MemNode::Memory);
73N/A } else {
73N/A return mem;
73N/A }
247N/A assert(mem != orig_mem, "dead memory loop");
73N/A }
73N/A}
73N/A
73N/A//
73N/A// Given a Memory Phi, compute a value Phi containing the values from stores
73N/A// on the input paths.
73N/A// Note: this function is recursive, its depth is limied by the "level" argument
73N/A// Returns the computed Phi, or NULL if it cannot compute it.
247N/ANode *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) {
247N/A assert(mem->is_Phi(), "sanity");
247N/A int alias_idx = C->get_alias_index(adr_t);
247N/A int offset = adr_t->offset();
247N/A int instance_id = adr_t->instance_id();
247N/A
247N/A // Check if an appropriate value phi already exists.
247N/A Node* region = mem->in(0);
247N/A for (DUIterator_Fast kmax, k = region->fast_outs(kmax); k < kmax; k++) {
247N/A Node* phi = region->fast_out(k);
247N/A if (phi->is_Phi() && phi != mem &&
247N/A phi->as_Phi()->is_same_inst_field(phi_type, instance_id, alias_idx, offset)) {
247N/A return phi;
247N/A }
247N/A }
247N/A // Check if an appropriate new value phi already exists.
2613N/A Node* new_phi = value_phis->find(mem->_idx);
2613N/A if (new_phi != NULL)
2613N/A return new_phi;
73N/A
73N/A if (level <= 0) {
253N/A return NULL; // Give up: phi tree too deep
73N/A }
73N/A Node *start_mem = C->start()->proj_out(TypeFunc::Memory);
73N/A Node *alloc_mem = alloc->in(TypeFunc::Memory);
73N/A
73N/A uint length = mem->req();
73N/A GrowableArray <Node *> values(length, length, NULL);
73N/A
247N/A // create a new Phi for the value
247N/A PhiNode *phi = new (C, length) PhiNode(mem->in(0), phi_type, NULL, instance_id, alias_idx, offset);
247N/A transform_later(phi);
247N/A value_phis->push(phi, mem->_idx);
247N/A
73N/A for (uint j = 1; j < length; j++) {
73N/A Node *in = mem->in(j);
73N/A if (in == NULL || in->is_top()) {
73N/A values.at_put(j, in);
73N/A } else {
253N/A Node *val = scan_mem_chain(in, alias_idx, offset, start_mem, alloc, &_igvn);
73N/A if (val == start_mem || val == alloc_mem) {
73N/A // hit a sentinel, return appropriate 0 value
73N/A values.at_put(j, _igvn.zerocon(ft));
73N/A continue;
73N/A }
73N/A if (val->is_Initialize()) {
73N/A val = val->as_Initialize()->find_captured_store(offset, type2aelembytes(ft), &_igvn);
73N/A }
73N/A if (val == NULL) {
73N/A return NULL; // can't find a value on this path
73N/A }
73N/A if (val == mem) {
73N/A values.at_put(j, mem);
73N/A } else if (val->is_Store()) {
73N/A values.at_put(j, val->in(MemNode::ValueIn));
73N/A } else if(val->is_Proj() && val->in(0) == alloc) {
73N/A values.at_put(j, _igvn.zerocon(ft));
73N/A } else if (val->is_Phi()) {
247N/A val = value_from_mem_phi(val, ft, phi_type, adr_t, alloc, value_phis, level-1);
247N/A if (val == NULL) {
247N/A return NULL;
73N/A }
247N/A values.at_put(j, val);
584N/A } else if (val->Opcode() == Op_SCMemProj) {
584N/A assert(val->in(0)->is_LoadStore(), "sanity");
584N/A assert(false, "Object is not scalar replaceable if a LoadStore node access its field");
584N/A return NULL;
73N/A } else {
584N/A#ifdef ASSERT
584N/A val->dump();
253N/A assert(false, "unknown node on this path");
584N/A#endif
253N/A return NULL; // unknown node on this path
73N/A }
73N/A }
73N/A }
247N/A // Set Phi's inputs
73N/A for (uint j = 1; j < length; j++) {
73N/A if (values.at(j) == mem) {
73N/A phi->init_req(j, phi);
73N/A } else {
73N/A phi->init_req(j, values.at(j));
73N/A }
73N/A }
73N/A return phi;
73N/A}
73N/A
73N/A// Search the last value stored into the object's field.
73N/ANode *PhaseMacroExpand::value_from_mem(Node *sfpt_mem, BasicType ft, const Type *ftype, const TypeOopPtr *adr_t, Node *alloc) {
223N/A assert(adr_t->is_known_instance_field(), "instance required");
223N/A int instance_id = adr_t->instance_id();
223N/A assert((uint)instance_id == alloc->_idx, "wrong allocation");
73N/A
73N/A int alias_idx = C->get_alias_index(adr_t);
73N/A int offset = adr_t->offset();
73N/A Node *start_mem = C->start()->proj_out(TypeFunc::Memory);
73N/A Node *alloc_ctrl = alloc->in(TypeFunc::Control);
73N/A Node *alloc_mem = alloc->in(TypeFunc::Memory);
247N/A Arena *a = Thread::current()->resource_area();
247N/A VectorSet visited(a);
73N/A
73N/A
73N/A bool done = sfpt_mem == alloc_mem;
73N/A Node *mem = sfpt_mem;
73N/A while (!done) {
73N/A if (visited.test_set(mem->_idx)) {
73N/A return NULL; // found a loop, give up
73N/A }
253N/A mem = scan_mem_chain(mem, alias_idx, offset, start_mem, alloc, &_igvn);
73N/A if (mem == start_mem || mem == alloc_mem) {
73N/A done = true; // hit a sentinel, return appropriate 0 value
73N/A } else if (mem->is_Initialize()) {
73N/A mem = mem->as_Initialize()->find_captured_store(offset, type2aelembytes(ft), &_igvn);
73N/A if (mem == NULL) {
73N/A done = true; // Something go wrong.
73N/A } else if (mem->is_Store()) {
73N/A const TypePtr* atype = mem->as_Store()->adr_type();
73N/A assert(C->get_alias_index(atype) == Compile::AliasIdxRaw, "store is correct memory slice");
73N/A done = true;
73N/A }
73N/A } else if (mem->is_Store()) {
73N/A const TypeOopPtr* atype = mem->as_Store()->adr_type()->isa_oopptr();
73N/A assert(atype != NULL, "address type must be oopptr");
73N/A assert(C->get_alias_index(atype) == alias_idx &&
223N/A atype->is_known_instance_field() && atype->offset() == offset &&
73N/A atype->instance_id() == instance_id, "store is correct memory slice");
73N/A done = true;
73N/A } else if (mem->is_Phi()) {
73N/A // try to find a phi's unique input
73N/A Node *unique_input = NULL;
73N/A Node *top = C->top();
73N/A for (uint i = 1; i < mem->req(); i++) {
253N/A Node *n = scan_mem_chain(mem->in(i), alias_idx, offset, start_mem, alloc, &_igvn);
73N/A if (n == NULL || n == top || n == mem) {
73N/A continue;
73N/A } else if (unique_input == NULL) {
73N/A unique_input = n;
73N/A } else if (unique_input != n) {
73N/A unique_input = top;
73N/A break;
73N/A }
73N/A }
73N/A if (unique_input != NULL && unique_input != top) {
73N/A mem = unique_input;
73N/A } else {
73N/A done = true;
73N/A }
73N/A } else {
73N/A assert(false, "unexpected node");
73N/A }
73N/A }
73N/A if (mem != NULL) {
73N/A if (mem == start_mem || mem == alloc_mem) {
73N/A // hit a sentinel, return appropriate 0 value
73N/A return _igvn.zerocon(ft);
73N/A } else if (mem->is_Store()) {
73N/A return mem->in(MemNode::ValueIn);
73N/A } else if (mem->is_Phi()) {
73N/A // attempt to produce a Phi reflecting the values on the input paths of the Phi
247N/A Node_Stack value_phis(a, 8);
253N/A Node * phi = value_from_mem_phi(mem, ft, ftype, adr_t, alloc, &value_phis, ValueSearchLimit);
73N/A if (phi != NULL) {
73N/A return phi;
247N/A } else {
247N/A // Kill all new Phis
247N/A while(value_phis.is_nonempty()) {
247N/A Node* n = value_phis.node();
1541N/A _igvn.replace_node(n, C->top());
247N/A value_phis.pop();
247N/A }
73N/A }
73N/A }
73N/A }
73N/A // Something go wrong.
73N/A return NULL;
73N/A}
73N/A
73N/A// Check the possibility of scalar replacement.
73N/Abool PhaseMacroExpand::can_eliminate_allocation(AllocateNode *alloc, GrowableArray <SafePointNode *>& safepoints) {
73N/A // Scan the uses of the allocation to check for anything that would
73N/A // prevent us from eliminating it.
73N/A NOT_PRODUCT( const char* fail_eliminate = NULL; )
73N/A DEBUG_ONLY( Node* disq_node = NULL; )
73N/A bool can_eliminate = true;
73N/A
73N/A Node* res = alloc->result_cast();
73N/A const TypeOopPtr* res_type = NULL;
73N/A if (res == NULL) {
73N/A // All users were eliminated.
73N/A } else if (!res->is_CheckCastPP()) {
73N/A NOT_PRODUCT(fail_eliminate = "Allocation does not have unique CheckCastPP";)
73N/A can_eliminate = false;
73N/A } else {
73N/A res_type = _igvn.type(res)->isa_oopptr();
73N/A if (res_type == NULL) {
73N/A NOT_PRODUCT(fail_eliminate = "Neither instance or array allocation";)
73N/A can_eliminate = false;
73N/A } else if (res_type->isa_aryptr()) {
73N/A int length = alloc->in(AllocateNode::ALength)->find_int_con(-1);
73N/A if (length < 0) {
73N/A NOT_PRODUCT(fail_eliminate = "Array's size is not constant";)
73N/A can_eliminate = false;
73N/A }
73N/A }
73N/A }
73N/A
73N/A if (can_eliminate && res != NULL) {
73N/A for (DUIterator_Fast jmax, j = res->fast_outs(jmax);
73N/A j < jmax && can_eliminate; j++) {
73N/A Node* use = res->fast_out(j);
73N/A
73N/A if (use->is_AddP()) {
73N/A const TypePtr* addp_type = _igvn.type(use)->is_ptr();
73N/A int offset = addp_type->offset();
73N/A
73N/A if (offset == Type::OffsetTop || offset == Type::OffsetBot) {
73N/A NOT_PRODUCT(fail_eliminate = "Undefined field referrence";)
73N/A can_eliminate = false;
73N/A break;
73N/A }
73N/A for (DUIterator_Fast kmax, k = use->fast_outs(kmax);
73N/A k < kmax && can_eliminate; k++) {
73N/A Node* n = use->fast_out(k);
73N/A if (!n->is_Store() && n->Opcode() != Op_CastP2X) {
73N/A DEBUG_ONLY(disq_node = n;)
253N/A if (n->is_Load() || n->is_LoadStore()) {
73N/A NOT_PRODUCT(fail_eliminate = "Field load";)
73N/A } else {
73N/A NOT_PRODUCT(fail_eliminate = "Not store field referrence";)
73N/A }
73N/A can_eliminate = false;
73N/A }
73N/A }
73N/A } else if (use->is_SafePoint()) {
73N/A SafePointNode* sfpt = use->as_SafePoint();
168N/A if (sfpt->is_Call() && sfpt->as_Call()->has_non_debug_use(res)) {
73N/A // Object is passed as argument.
73N/A DEBUG_ONLY(disq_node = use;)
73N/A NOT_PRODUCT(fail_eliminate = "Object is passed as argument";)
73N/A can_eliminate = false;
73N/A }
73N/A Node* sfptMem = sfpt->memory();
73N/A if (sfptMem == NULL || sfptMem->is_top()) {
73N/A DEBUG_ONLY(disq_node = use;)
73N/A NOT_PRODUCT(fail_eliminate = "NULL or TOP memory";)
73N/A can_eliminate = false;
73N/A } else {
73N/A safepoints.append_if_missing(sfpt);
73N/A }
73N/A } else if (use->Opcode() != Op_CastP2X) { // CastP2X is used by card mark
73N/A if (use->is_Phi()) {
73N/A if (use->outcnt() == 1 && use->unique_out()->Opcode() == Op_Return) {
73N/A NOT_PRODUCT(fail_eliminate = "Object is return value";)
73N/A } else {
73N/A NOT_PRODUCT(fail_eliminate = "Object is referenced by Phi";)
73N/A }
73N/A DEBUG_ONLY(disq_node = use;)
73N/A } else {
73N/A if (use->Opcode() == Op_Return) {
73N/A NOT_PRODUCT(fail_eliminate = "Object is return value";)
73N/A }else {
73N/A NOT_PRODUCT(fail_eliminate = "Object is referenced by node";)
73N/A }
73N/A DEBUG_ONLY(disq_node = use;)
73N/A }
73N/A can_eliminate = false;
73N/A }
73N/A }
73N/A }
73N/A
73N/A#ifndef PRODUCT
73N/A if (PrintEliminateAllocations) {
73N/A if (can_eliminate) {
73N/A tty->print("Scalar ");
73N/A if (res == NULL)
73N/A alloc->dump();
73N/A else
73N/A res->dump();
73N/A } else {
73N/A tty->print("NotScalar (%s)", fail_eliminate);
73N/A if (res == NULL)
73N/A alloc->dump();
73N/A else
73N/A res->dump();
73N/A#ifdef ASSERT
73N/A if (disq_node != NULL) {
73N/A tty->print(" >>>> ");
73N/A disq_node->dump();
73N/A }
73N/A#endif /*ASSERT*/
73N/A }
73N/A }
73N/A#endif
73N/A return can_eliminate;
73N/A}
73N/A
73N/A// Do scalar replacement.
73N/Abool PhaseMacroExpand::scalar_replacement(AllocateNode *alloc, GrowableArray <SafePointNode *>& safepoints) {
73N/A GrowableArray <SafePointNode *> safepoints_done;
73N/A
73N/A ciKlass* klass = NULL;
73N/A ciInstanceKlass* iklass = NULL;
73N/A int nfields = 0;
73N/A int array_base;
73N/A int element_size;
73N/A BasicType basic_elem_type;
73N/A ciType* elem_type;
73N/A
73N/A Node* res = alloc->result_cast();
73N/A const TypeOopPtr* res_type = NULL;
73N/A if (res != NULL) { // Could be NULL when there are no users
73N/A res_type = _igvn.type(res)->isa_oopptr();
73N/A }
73N/A
73N/A if (res != NULL) {
73N/A klass = res_type->klass();
73N/A if (res_type->isa_instptr()) {
73N/A // find the fields of the class which will be needed for safepoint debug information
73N/A assert(klass->is_instance_klass(), "must be an instance klass.");
73N/A iklass = klass->as_instance_klass();
73N/A nfields = iklass->nof_nonstatic_fields();
73N/A } else {
73N/A // find the array's elements which will be needed for safepoint debug information
73N/A nfields = alloc->in(AllocateNode::ALength)->find_int_con(-1);
73N/A assert(klass->is_array_klass() && nfields >= 0, "must be an array klass.");
73N/A elem_type = klass->as_array_klass()->element_type();
73N/A basic_elem_type = elem_type->basic_type();
73N/A array_base = arrayOopDesc::base_offset_in_bytes(basic_elem_type);
73N/A element_size = type2aelembytes(basic_elem_type);
73N/A }
73N/A }
73N/A //
73N/A // Process the safepoint uses
73N/A //
73N/A while (safepoints.length() > 0) {
73N/A SafePointNode* sfpt = safepoints.pop();
73N/A Node* mem = sfpt->memory();
73N/A uint first_ind = sfpt->req();
73N/A SafePointScalarObjectNode* sobj = new (C, 1) SafePointScalarObjectNode(res_type,
73N/A#ifdef ASSERT
73N/A alloc,
73N/A#endif
73N/A first_ind, nfields);
2958N/A sobj->init_req(0, C->root());
73N/A transform_later(sobj);
73N/A
73N/A // Scan object's fields adding an input to the safepoint for each field.
73N/A for (int j = 0; j < nfields; j++) {
306N/A intptr_t offset;
73N/A ciField* field = NULL;
73N/A if (iklass != NULL) {
73N/A field = iklass->nonstatic_field_at(j);
73N/A offset = field->offset();
73N/A elem_type = field->type();
73N/A basic_elem_type = field->layout_type();
73N/A } else {
306N/A offset = array_base + j * (intptr_t)element_size;
73N/A }
73N/A
73N/A const Type *field_type;
73N/A // The next code is taken from Parse::do_get_xxx().
124N/A if (basic_elem_type == T_OBJECT || basic_elem_type == T_ARRAY) {
73N/A if (!elem_type->is_loaded()) {
73N/A field_type = TypeInstPtr::BOTTOM;
1602N/A } else if (field != NULL && field->is_constant() && field->is_static()) {
73N/A // This can happen if the constant oop is non-perm.
73N/A ciObject* con = field->constant_value().as_object();
73N/A // Do not "join" in the previous type; it doesn't add value,
73N/A // and may yield a vacuous result if the field is of interface type.
73N/A field_type = TypeOopPtr::make_from_constant(con)->isa_oopptr();
73N/A assert(field_type != NULL, "field singleton type must be consistent");
73N/A } else {
73N/A field_type = TypeOopPtr::make_from_klass(elem_type->as_klass());
73N/A }
124N/A if (UseCompressedOops) {
221N/A field_type = field_type->make_narrowoop();
124N/A basic_elem_type = T_NARROWOOP;
124N/A }
73N/A } else {
73N/A field_type = Type::get_const_basic_type(basic_elem_type);
73N/A }
73N/A
73N/A const TypeOopPtr *field_addr_type = res_type->add_offset(offset)->isa_oopptr();
73N/A
73N/A Node *field_val = value_from_mem(mem, basic_elem_type, field_type, field_addr_type, alloc);
73N/A if (field_val == NULL) {
2958N/A // We weren't able to find a value for this field,
2958N/A // give up on eliminating this allocation.
2958N/A
2958N/A // Remove any extra entries we added to the safepoint.
73N/A uint last = sfpt->req() - 1;
73N/A for (int k = 0; k < j; k++) {
73N/A sfpt->del_req(last--);
73N/A }
73N/A // rollback processed safepoints
73N/A while (safepoints_done.length() > 0) {
73N/A SafePointNode* sfpt_done = safepoints_done.pop();
73N/A // remove any extra entries we added to the safepoint
73N/A last = sfpt_done->req() - 1;
73N/A for (int k = 0; k < nfields; k++) {
73N/A sfpt_done->del_req(last--);
73N/A }
73N/A JVMState *jvms = sfpt_done->jvms();
73N/A jvms->set_endoff(sfpt_done->req());
73N/A // Now make a pass over the debug information replacing any references
73N/A // to SafePointScalarObjectNode with the allocated object.
73N/A int start = jvms->debug_start();
73N/A int end = jvms->debug_end();
73N/A for (int i = start; i < end; i++) {
73N/A if (sfpt_done->in(i)->is_SafePointScalarObject()) {
73N/A SafePointScalarObjectNode* scobj = sfpt_done->in(i)->as_SafePointScalarObject();
73N/A if (scobj->first_index() == sfpt_done->req() &&
73N/A scobj->n_fields() == (uint)nfields) {
73N/A assert(scobj->alloc() == alloc, "sanity");
73N/A sfpt_done->set_req(i, res);
73N/A }
73N/A }
73N/A }
73N/A }
73N/A#ifndef PRODUCT
73N/A if (PrintEliminateAllocations) {
73N/A if (field != NULL) {
73N/A tty->print("=== At SafePoint node %d can't find value of Field: ",
73N/A sfpt->_idx);
73N/A field->print();
73N/A int field_idx = C->get_alias_index(field_addr_type);
73N/A tty->print(" (alias_idx=%d)", field_idx);
73N/A } else { // Array's element
73N/A tty->print("=== At SafePoint node %d can't find value of array element [%d]",
73N/A sfpt->_idx, j);
73N/A }
73N/A tty->print(", which prevents elimination of: ");
73N/A if (res == NULL)
73N/A alloc->dump();
73N/A else
73N/A res->dump();
73N/A }
73N/A#endif
73N/A return false;
73N/A }
124N/A if (UseCompressedOops && field_type->isa_narrowoop()) {
124N/A // Enable "DecodeN(EncodeP(Allocate)) --> Allocate" transformation
124N/A // to be able scalar replace the allocation.
221N/A if (field_val->is_EncodeP()) {
221N/A field_val = field_val->in(1);
221N/A } else {
221N/A field_val = transform_later(new (C, 2) DecodeNNode(field_val, field_val->bottom_type()->make_ptr()));
221N/A }
124N/A }
73N/A sfpt->add_req(field_val);
73N/A }
73N/A JVMState *jvms = sfpt->jvms();
73N/A jvms->set_endoff(sfpt->req());
73N/A // Now make a pass over the debug information replacing any references
73N/A // to the allocated object with "sobj"
73N/A int start = jvms->debug_start();
73N/A int end = jvms->debug_end();
73N/A for (int i = start; i < end; i++) {
73N/A if (sfpt->in(i) == res) {
73N/A sfpt->set_req(i, sobj);
73N/A }
73N/A }
73N/A safepoints_done.append_if_missing(sfpt); // keep it for rollback
73N/A }
73N/A return true;
73N/A}
73N/A
73N/A// Process users of eliminated allocation.
73N/Avoid PhaseMacroExpand::process_users_of_allocation(AllocateNode *alloc) {
73N/A Node* res = alloc->result_cast();
73N/A if (res != NULL) {
73N/A for (DUIterator_Last jmin, j = res->last_outs(jmin); j >= jmin; ) {
73N/A Node *use = res->last_out(j);
73N/A uint oc1 = res->outcnt();
73N/A
73N/A if (use->is_AddP()) {
73N/A for (DUIterator_Last kmin, k = use->last_outs(kmin); k >= kmin; ) {
73N/A Node *n = use->last_out(k);
73N/A uint oc2 = use->outcnt();
73N/A if (n->is_Store()) {
1100N/A#ifdef ASSERT
1100N/A // Verify that there is no dependent MemBarVolatile nodes,
1100N/A // they should be removed during IGVN, see MemBarNode::Ideal().
1100N/A for (DUIterator_Fast pmax, p = n->fast_outs(pmax);
1100N/A p < pmax; p++) {
1100N/A Node* mb = n->fast_out(p);
1100N/A assert(mb->is_Initialize() || !mb->is_MemBar() ||
1100N/A mb->req() <= MemBarNode::Precedent ||
1100N/A mb->in(MemBarNode::Precedent) != n,
1100N/A "MemBarVolatile should be eliminated for non-escaping object");
1100N/A }
1100N/A#endif
73N/A _igvn.replace_node(n, n->in(MemNode::Memory));
73N/A } else {
73N/A eliminate_card_mark(n);
73N/A }
73N/A k -= (oc2 - use->outcnt());
73N/A }
73N/A } else {
73N/A eliminate_card_mark(use);
73N/A }
73N/A j -= (oc1 - res->outcnt());
73N/A }
73N/A assert(res->outcnt() == 0, "all uses of allocated objects must be deleted");
73N/A _igvn.remove_dead_node(res);
73N/A }
73N/A
73N/A //
73N/A // Process other users of allocation's projections
73N/A //
73N/A if (_resproj != NULL && _resproj->outcnt() != 0) {
73N/A for (DUIterator_Last jmin, j = _resproj->last_outs(jmin); j >= jmin; ) {
73N/A Node *use = _resproj->last_out(j);
73N/A uint oc1 = _resproj->outcnt();
73N/A if (use->is_Initialize()) {
73N/A // Eliminate Initialize node.
73N/A InitializeNode *init = use->as_Initialize();
73N/A assert(init->outcnt() <= 2, "only a control and memory projection expected");
73N/A Node *ctrl_proj = init->proj_out(TypeFunc::Control);
73N/A if (ctrl_proj != NULL) {
73N/A assert(init->in(TypeFunc::Control) == _fallthroughcatchproj, "allocation control projection");
73N/A _igvn.replace_node(ctrl_proj, _fallthroughcatchproj);
73N/A }
73N/A Node *mem_proj = init->proj_out(TypeFunc::Memory);
73N/A if (mem_proj != NULL) {
73N/A Node *mem = init->in(TypeFunc::Memory);
73N/A#ifdef ASSERT
73N/A if (mem->is_MergeMem()) {
73N/A assert(mem->in(TypeFunc::Memory) == _memproj_fallthrough, "allocation memory projection");
73N/A } else {
73N/A assert(mem == _memproj_fallthrough, "allocation memory projection");
73N/A }
73N/A#endif
73N/A _igvn.replace_node(mem_proj, mem);
73N/A }
73N/A } else if (use->is_AddP()) {
73N/A // raw memory addresses used only by the initialization
708N/A _igvn.replace_node(use, C->top());
73N/A } else {
73N/A assert(false, "only Initialize or AddP expected");
73N/A }
73N/A j -= (oc1 - _resproj->outcnt());
73N/A }
73N/A }
73N/A if (_fallthroughcatchproj != NULL) {
73N/A _igvn.replace_node(_fallthroughcatchproj, alloc->in(TypeFunc::Control));
73N/A }
73N/A if (_memproj_fallthrough != NULL) {
73N/A _igvn.replace_node(_memproj_fallthrough, alloc->in(TypeFunc::Memory));
73N/A }
73N/A if (_memproj_catchall != NULL) {
73N/A _igvn.replace_node(_memproj_catchall, C->top());
73N/A }
73N/A if (_ioproj_fallthrough != NULL) {
73N/A _igvn.replace_node(_ioproj_fallthrough, alloc->in(TypeFunc::I_O));
73N/A }
73N/A if (_ioproj_catchall != NULL) {
73N/A _igvn.replace_node(_ioproj_catchall, C->top());
73N/A }
73N/A if (_catchallcatchproj != NULL) {
73N/A _igvn.replace_node(_catchallcatchproj, C->top());
73N/A }
73N/A}
73N/A
73N/Abool PhaseMacroExpand::eliminate_allocate_node(AllocateNode *alloc) {
73N/A
73N/A if (!EliminateAllocations || !alloc->_is_scalar_replaceable) {
73N/A return false;
73N/A }
73N/A
73N/A extract_call_projections(alloc);
73N/A
73N/A GrowableArray <SafePointNode *> safepoints;
73N/A if (!can_eliminate_allocation(alloc, safepoints)) {
73N/A return false;
73N/A }
73N/A
73N/A if (!scalar_replacement(alloc, safepoints)) {
73N/A return false;
73N/A }
73N/A
1080N/A CompileLog* log = C->log();
1080N/A if (log != NULL) {
1080N/A Node* klass = alloc->in(AllocateNode::KlassNode);
1080N/A const TypeKlassPtr* tklass = _igvn.type(klass)->is_klassptr();
1080N/A log->head("eliminate_allocation type='%d'",
1080N/A log->identify(tklass->klass()));
1080N/A JVMState* p = alloc->jvms();
1080N/A while (p != NULL) {
1080N/A log->elem("jvms bci='%d' method='%d'", p->bci(), log->identify(p->method()));
1080N/A p = p->caller();
1080N/A }
1080N/A log->tail("eliminate_allocation");
1080N/A }
1080N/A
73N/A process_users_of_allocation(alloc);
73N/A
73N/A#ifndef PRODUCT
1080N/A if (PrintEliminateAllocations) {
1080N/A if (alloc->is_AllocateArray())
1080N/A tty->print_cr("++++ Eliminated: %d AllocateArray", alloc->_idx);
1080N/A else
1080N/A tty->print_cr("++++ Eliminated: %d Allocate", alloc->_idx);
1080N/A }
73N/A#endif
73N/A
73N/A return true;
73N/A}
73N/A
0N/A
0N/A//---------------------------set_eden_pointers-------------------------
0N/Avoid PhaseMacroExpand::set_eden_pointers(Node* &eden_top_adr, Node* &eden_end_adr) {
0N/A if (UseTLAB) { // Private allocation: load from TLS
0N/A Node* thread = transform_later(new (C, 1) ThreadLocalNode());
0N/A int tlab_top_offset = in_bytes(JavaThread::tlab_top_offset());
0N/A int tlab_end_offset = in_bytes(JavaThread::tlab_end_offset());
0N/A eden_top_adr = basic_plus_adr(top()/*not oop*/, thread, tlab_top_offset);
0N/A eden_end_adr = basic_plus_adr(top()/*not oop*/, thread, tlab_end_offset);
0N/A } else { // Shared allocation: load from globals
0N/A CollectedHeap* ch = Universe::heap();
0N/A address top_adr = (address)ch->top_addr();
0N/A address end_adr = (address)ch->end_addr();
0N/A eden_top_adr = makecon(TypeRawPtr::make(top_adr));
0N/A eden_end_adr = basic_plus_adr(eden_top_adr, end_adr - top_adr);
0N/A }
0N/A}
0N/A
0N/A
0N/ANode* PhaseMacroExpand::make_load(Node* ctl, Node* mem, Node* base, int offset, const Type* value_type, BasicType bt) {
0N/A Node* adr = basic_plus_adr(base, offset);
420N/A const TypePtr* adr_type = adr->bottom_type()->is_ptr();
113N/A Node* value = LoadNode::make(_igvn, ctl, mem, adr, adr_type, value_type, bt);
0N/A transform_later(value);
0N/A return value;
0N/A}
0N/A
0N/A
0N/ANode* PhaseMacroExpand::make_store(Node* ctl, Node* mem, Node* base, int offset, Node* value, BasicType bt) {
0N/A Node* adr = basic_plus_adr(base, offset);
113N/A mem = StoreNode::make(_igvn, ctl, mem, adr, NULL, value, bt);
0N/A transform_later(mem);
0N/A return mem;
0N/A}
0N/A
0N/A//=============================================================================
0N/A//
0N/A// A L L O C A T I O N
0N/A//
0N/A// Allocation attempts to be fast in the case of frequent small objects.
0N/A// It breaks down like this:
0N/A//
0N/A// 1) Size in doublewords is computed. This is a constant for objects and
0N/A// variable for most arrays. Doubleword units are used to avoid size
0N/A// overflow of huge doubleword arrays. We need doublewords in the end for
0N/A// rounding.
0N/A//
0N/A// 2) Size is checked for being 'too large'. Too-large allocations will go
0N/A// the slow path into the VM. The slow path can throw any required
0N/A// exceptions, and does all the special checks for very large arrays. The
0N/A// size test can constant-fold away for objects. For objects with
0N/A// finalizers it constant-folds the otherway: you always go slow with
0N/A// finalizers.
0N/A//
0N/A// 3) If NOT using TLABs, this is the contended loop-back point.
0N/A// Load-Locked the heap top. If using TLABs normal-load the heap top.
0N/A//
0N/A// 4) Check that heap top + size*8 < max. If we fail go the slow ` route.
0N/A// NOTE: "top+size*8" cannot wrap the 4Gig line! Here's why: for largish
0N/A// "size*8" we always enter the VM, where "largish" is a constant picked small
0N/A// enough that there's always space between the eden max and 4Gig (old space is
0N/A// there so it's quite large) and large enough that the cost of entering the VM
0N/A// is dwarfed by the cost to initialize the space.
0N/A//
0N/A// 5) If NOT using TLABs, Store-Conditional the adjusted heap top back
0N/A// down. If contended, repeat at step 3. If using TLABs normal-store
0N/A// adjusted heap top back down; there is no contention.
0N/A//
0N/A// 6) If !ZeroTLAB then Bulk-clear the object/array. Fill in klass & mark
0N/A// fields.
0N/A//
0N/A// 7) Merge with the slow-path; cast the raw memory pointer to the correct
0N/A// oop flavor.
0N/A//
0N/A//=============================================================================
0N/A// FastAllocateSizeLimit value is in DOUBLEWORDS.
0N/A// Allocations bigger than this always go the slow route.
0N/A// This value must be small enough that allocation attempts that need to
0N/A// trigger exceptions go the slow route. Also, it must be small enough so
0N/A// that heap_top + size_in_bytes does not wrap around the 4Gig limit.
0N/A//=============================================================================j//
0N/A// %%% Here is an old comment from parseHelper.cpp; is it outdated?
0N/A// The allocator will coalesce int->oop copies away. See comment in
0N/A// coalesce.cpp about how this works. It depends critically on the exact
0N/A// code shape produced here, so if you are changing this code shape
0N/A// make sure the GC info for the heap-top is correct in and around the
0N/A// slow-path call.
0N/A//
0N/A
0N/Avoid PhaseMacroExpand::expand_allocate_common(
0N/A AllocateNode* alloc, // allocation node to be expanded
0N/A Node* length, // array length for an array allocation
0N/A const TypeFunc* slow_call_type, // Type of slow call
0N/A address slow_call_address // Address of slow call
0N/A )
0N/A{
0N/A
0N/A Node* ctrl = alloc->in(TypeFunc::Control);
0N/A Node* mem = alloc->in(TypeFunc::Memory);
0N/A Node* i_o = alloc->in(TypeFunc::I_O);
0N/A Node* size_in_bytes = alloc->in(AllocateNode::AllocSize);
0N/A Node* klass_node = alloc->in(AllocateNode::KlassNode);
0N/A Node* initial_slow_test = alloc->in(AllocateNode::InitialTest);
0N/A
0N/A assert(ctrl != NULL, "must have control");
0N/A // We need a Region and corresponding Phi's to merge the slow-path and fast-path results.
0N/A // they will not be used if "always_slow" is set
0N/A enum { slow_result_path = 1, fast_result_path = 2 };
0N/A Node *result_region;
0N/A Node *result_phi_rawmem;
0N/A Node *result_phi_rawoop;
0N/A Node *result_phi_i_o;
0N/A
0N/A // The initial slow comparison is a size check, the comparison
0N/A // we want to do is a BoolTest::gt
0N/A bool always_slow = false;
0N/A int tv = _igvn.find_int_con(initial_slow_test, -1);
0N/A if (tv >= 0) {
0N/A always_slow = (tv == 1);
0N/A initial_slow_test = NULL;
0N/A } else {
0N/A initial_slow_test = BoolNode::make_predicate(initial_slow_test, &_igvn);
0N/A }
0N/A
780N/A if (C->env()->dtrace_alloc_probes() ||
342N/A !UseTLAB && (!Universe::heap()->supports_inline_contig_alloc() ||
342N/A (UseConcMarkSweepGC && CMSIncrementalMode))) {
0N/A // Force slow-path allocation
0N/A always_slow = true;
0N/A initial_slow_test = NULL;
0N/A }
0N/A
342N/A
0N/A enum { too_big_or_final_path = 1, need_gc_path = 2 };
0N/A Node *slow_region = NULL;
0N/A Node *toobig_false = ctrl;
0N/A
0N/A assert (initial_slow_test == NULL || !always_slow, "arguments must be consistent");
0N/A // generate the initial test if necessary
0N/A if (initial_slow_test != NULL ) {
0N/A slow_region = new (C, 3) RegionNode(3);
0N/A
0N/A // Now make the initial failure test. Usually a too-big test but
0N/A // might be a TRUE for finalizers or a fancy class check for
0N/A // newInstance0.
0N/A IfNode *toobig_iff = new (C, 2) IfNode(ctrl, initial_slow_test, PROB_MIN, COUNT_UNKNOWN);
0N/A transform_later(toobig_iff);
0N/A // Plug the failing-too-big test into the slow-path region
0N/A Node *toobig_true = new (C, 1) IfTrueNode( toobig_iff );
0N/A transform_later(toobig_true);
0N/A slow_region ->init_req( too_big_or_final_path, toobig_true );
0N/A toobig_false = new (C, 1) IfFalseNode( toobig_iff );
0N/A transform_later(toobig_false);
0N/A } else { // No initial test, just fall into next case
0N/A toobig_false = ctrl;
0N/A debug_only(slow_region = NodeSentinel);
0N/A }
0N/A
0N/A Node *slow_mem = mem; // save the current memory state for slow path
0N/A // generate the fast allocation code unless we know that the initial test will always go slow
0N/A if (!always_slow) {
565N/A // Fast path modifies only raw memory.
565N/A if (mem->is_MergeMem()) {
565N/A mem = mem->as_MergeMem()->memory_at(Compile::AliasIdxRaw);
565N/A }
565N/A
342N/A Node* eden_top_adr;
342N/A Node* eden_end_adr;
342N/A
342N/A set_eden_pointers(eden_top_adr, eden_end_adr);
342N/A
342N/A // Load Eden::end. Loop invariant and hoisted.
342N/A //
342N/A // Note: We set the control input on "eden_end" and "old_eden_top" when using
342N/A // a TLAB to work around a bug where these values were being moved across
342N/A // a safepoint. These are not oops, so they cannot be include in the oop
1988N/A // map, but they can be changed by a GC. The proper way to fix this would
342N/A // be to set the raw memory state when generating a SafepointNode. However
342N/A // this will require extensive changes to the loop optimization in order to
342N/A // prevent a degradation of the optimization.
342N/A // See comment in memnode.hpp, around line 227 in class LoadPNode.
342N/A Node *eden_end = make_load(ctrl, mem, eden_end_adr, 0, TypeRawPtr::BOTTOM, T_ADDRESS);
342N/A
0N/A // allocate the Region and Phi nodes for the result
0N/A result_region = new (C, 3) RegionNode(3);
1988N/A result_phi_rawmem = new (C, 3) PhiNode(result_region, Type::MEMORY, TypeRawPtr::BOTTOM);
1988N/A result_phi_rawoop = new (C, 3) PhiNode(result_region, TypeRawPtr::BOTTOM);
1988N/A result_phi_i_o = new (C, 3) PhiNode(result_region, Type::ABIO); // I/O is used for Prefetch
0N/A
0N/A // We need a Region for the loop-back contended case.
0N/A enum { fall_in_path = 1, contended_loopback_path = 2 };
0N/A Node *contended_region;
0N/A Node *contended_phi_rawmem;
1988N/A if (UseTLAB) {
0N/A contended_region = toobig_false;
0N/A contended_phi_rawmem = mem;
0N/A } else {
0N/A contended_region = new (C, 3) RegionNode(3);
1988N/A contended_phi_rawmem = new (C, 3) PhiNode(contended_region, Type::MEMORY, TypeRawPtr::BOTTOM);
0N/A // Now handle the passing-too-big test. We fall into the contended
0N/A // loop-back merge point.
1988N/A contended_region ->init_req(fall_in_path, toobig_false);
1988N/A contended_phi_rawmem->init_req(fall_in_path, mem);
0N/A transform_later(contended_region);
0N/A transform_later(contended_phi_rawmem);
0N/A }
0N/A
0N/A // Load(-locked) the heap top.
0N/A // See note above concerning the control input when using a TLAB
0N/A Node *old_eden_top = UseTLAB
1988N/A ? new (C, 3) LoadPNode (ctrl, contended_phi_rawmem, eden_top_adr, TypeRawPtr::BOTTOM, TypeRawPtr::BOTTOM)
1988N/A : new (C, 3) LoadPLockedNode(contended_region, contended_phi_rawmem, eden_top_adr);
0N/A
0N/A transform_later(old_eden_top);
0N/A // Add to heap top to get a new heap top
1988N/A Node *new_eden_top = new (C, 4) AddPNode(top(), old_eden_top, size_in_bytes);
0N/A transform_later(new_eden_top);
0N/A // Check for needing a GC; compare against heap end
1988N/A Node *needgc_cmp = new (C, 3) CmpPNode(new_eden_top, eden_end);
0N/A transform_later(needgc_cmp);
1988N/A Node *needgc_bol = new (C, 2) BoolNode(needgc_cmp, BoolTest::ge);
0N/A transform_later(needgc_bol);
1988N/A IfNode *needgc_iff = new (C, 2) IfNode(contended_region, needgc_bol, PROB_UNLIKELY_MAG(4), COUNT_UNKNOWN);
0N/A transform_later(needgc_iff);
0N/A
0N/A // Plug the failing-heap-space-need-gc test into the slow-path region
1988N/A Node *needgc_true = new (C, 1) IfTrueNode(needgc_iff);
0N/A transform_later(needgc_true);
1988N/A if (initial_slow_test) {
1988N/A slow_region->init_req(need_gc_path, needgc_true);
0N/A // This completes all paths into the slow merge point
0N/A transform_later(slow_region);
0N/A } else { // No initial slow path needed!
0N/A // Just fall from the need-GC path straight into the VM call.
1988N/A slow_region = needgc_true;
0N/A }
0N/A // No need for a GC. Setup for the Store-Conditional
1988N/A Node *needgc_false = new (C, 1) IfFalseNode(needgc_iff);
0N/A transform_later(needgc_false);
0N/A
0N/A // Grab regular I/O before optional prefetch may change it.
0N/A // Slow-path does no I/O so just set it to the original I/O.
1988N/A result_phi_i_o->init_req(slow_result_path, i_o);
0N/A
0N/A i_o = prefetch_allocation(i_o, needgc_false, contended_phi_rawmem,
0N/A old_eden_top, new_eden_top, length);
0N/A
1988N/A // Name successful fast-path variables
1988N/A Node* fast_oop = old_eden_top;
1988N/A Node* fast_oop_ctrl;
1988N/A Node* fast_oop_rawmem;
1988N/A
0N/A // Store (-conditional) the modified eden top back down.
0N/A // StorePConditional produces flags for a test PLUS a modified raw
0N/A // memory state.
1988N/A if (UseTLAB) {
1988N/A Node* store_eden_top =
1988N/A new (C, 4) StorePNode(needgc_false, contended_phi_rawmem, eden_top_adr,
1988N/A TypeRawPtr::BOTTOM, new_eden_top);
0N/A transform_later(store_eden_top);
0N/A fast_oop_ctrl = needgc_false; // No contention, so this is the fast path
1988N/A fast_oop_rawmem = store_eden_top;
0N/A } else {
1988N/A Node* store_eden_top =
1988N/A new (C, 5) StorePConditionalNode(needgc_false, contended_phi_rawmem, eden_top_adr,
1988N/A new_eden_top, fast_oop/*old_eden_top*/);
0N/A transform_later(store_eden_top);
1988N/A Node *contention_check = new (C, 2) BoolNode(store_eden_top, BoolTest::ne);
0N/A transform_later(contention_check);
0N/A store_eden_top = new (C, 1) SCMemProjNode(store_eden_top);
0N/A transform_later(store_eden_top);
0N/A
0N/A // If not using TLABs, check to see if there was contention.
1988N/A IfNode *contention_iff = new (C, 2) IfNode (needgc_false, contention_check, PROB_MIN, COUNT_UNKNOWN);
0N/A transform_later(contention_iff);
1988N/A Node *contention_true = new (C, 1) IfTrueNode(contention_iff);
0N/A transform_later(contention_true);
0N/A // If contention, loopback and try again.
1988N/A contended_region->init_req(contended_loopback_path, contention_true);
1988N/A contended_phi_rawmem->init_req(contended_loopback_path, store_eden_top);
0N/A
0N/A // Fast-path succeeded with no contention!
1988N/A Node *contention_false = new (C, 1) IfFalseNode(contention_iff);
0N/A transform_later(contention_false);
0N/A fast_oop_ctrl = contention_false;
1988N/A
1988N/A // Bump total allocated bytes for this thread
1988N/A Node* thread = new (C, 1) ThreadLocalNode();
1988N/A transform_later(thread);
1988N/A Node* alloc_bytes_adr = basic_plus_adr(top()/*not oop*/, thread,
1988N/A in_bytes(JavaThread::allocated_bytes_offset()));
1988N/A Node* alloc_bytes = make_load(fast_oop_ctrl, store_eden_top, alloc_bytes_adr,
1988N/A 0, TypeLong::LONG, T_LONG);
1988N/A#ifdef _LP64
1988N/A Node* alloc_size = size_in_bytes;
1988N/A#else
1988N/A Node* alloc_size = new (C, 2) ConvI2LNode(size_in_bytes);
1988N/A transform_later(alloc_size);
1988N/A#endif
1988N/A Node* new_alloc_bytes = new (C, 3) AddLNode(alloc_bytes, alloc_size);
1988N/A transform_later(new_alloc_bytes);
1988N/A fast_oop_rawmem = make_store(fast_oop_ctrl, store_eden_top, alloc_bytes_adr,
1988N/A 0, new_alloc_bytes, T_LONG);
0N/A }
0N/A
0N/A fast_oop_rawmem = initialize_object(alloc,
0N/A fast_oop_ctrl, fast_oop_rawmem, fast_oop,
0N/A klass_node, length, size_in_bytes);
0N/A
780N/A if (C->env()->dtrace_extended_probes()) {
0N/A // Slow-path call
0N/A int size = TypeFunc::Parms + 2;
0N/A CallLeafNode *call = new (C, size) CallLeafNode(OptoRuntime::dtrace_object_alloc_Type(),
0N/A CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_object_alloc_base),
0N/A "dtrace_object_alloc",
0N/A TypeRawPtr::BOTTOM);
0N/A
0N/A // Get base of thread-local storage area
0N/A Node* thread = new (C, 1) ThreadLocalNode();
0N/A transform_later(thread);
0N/A
0N/A call->init_req(TypeFunc::Parms+0, thread);
0N/A call->init_req(TypeFunc::Parms+1, fast_oop);
1988N/A call->init_req(TypeFunc::Control, fast_oop_ctrl);
1988N/A call->init_req(TypeFunc::I_O , top()); // does no i/o
1988N/A call->init_req(TypeFunc::Memory , fast_oop_rawmem);
1988N/A call->init_req(TypeFunc::ReturnAdr, alloc->in(TypeFunc::ReturnAdr));
1988N/A call->init_req(TypeFunc::FramePtr, alloc->in(TypeFunc::FramePtr));
0N/A transform_later(call);
0N/A fast_oop_ctrl = new (C, 1) ProjNode(call,TypeFunc::Control);
0N/A transform_later(fast_oop_ctrl);
0N/A fast_oop_rawmem = new (C, 1) ProjNode(call,TypeFunc::Memory);
0N/A transform_later(fast_oop_rawmem);
0N/A }
0N/A
0N/A // Plug in the successful fast-path into the result merge point
1988N/A result_region ->init_req(fast_result_path, fast_oop_ctrl);
1988N/A result_phi_rawoop->init_req(fast_result_path, fast_oop);
1988N/A result_phi_i_o ->init_req(fast_result_path, i_o);
1988N/A result_phi_rawmem->init_req(fast_result_path, fast_oop_rawmem);
0N/A } else {
0N/A slow_region = ctrl;
0N/A }
0N/A
0N/A // Generate slow-path call
0N/A CallNode *call = new (C, slow_call_type->domain()->cnt())
0N/A CallStaticJavaNode(slow_call_type, slow_call_address,
0N/A OptoRuntime::stub_name(slow_call_address),
0N/A alloc->jvms()->bci(),
0N/A TypePtr::BOTTOM);
0N/A call->init_req( TypeFunc::Control, slow_region );
0N/A call->init_req( TypeFunc::I_O , top() ) ; // does no i/o
0N/A call->init_req( TypeFunc::Memory , slow_mem ); // may gc ptrs
0N/A call->init_req( TypeFunc::ReturnAdr, alloc->in(TypeFunc::ReturnAdr) );
0N/A call->init_req( TypeFunc::FramePtr, alloc->in(TypeFunc::FramePtr) );
0N/A
0N/A call->init_req(TypeFunc::Parms+0, klass_node);
0N/A if (length != NULL) {
0N/A call->init_req(TypeFunc::Parms+1, length);
0N/A }
0N/A
0N/A // Copy debug information and adjust JVMState information, then replace
0N/A // allocate node with the call
0N/A copy_call_debug_info((CallNode *) alloc, call);
0N/A if (!always_slow) {
0N/A call->set_cnt(PROB_UNLIKELY_MAG(4)); // Same effect as RC_UNCOMMON.
0N/A }
1541N/A _igvn.replace_node(alloc, call);
0N/A transform_later(call);
0N/A
0N/A // Identify the output projections from the allocate node and
0N/A // adjust any references to them.
0N/A // The control and io projections look like:
0N/A //
0N/A // v---Proj(ctrl) <-----+ v---CatchProj(ctrl)
0N/A // Allocate Catch
0N/A // ^---Proj(io) <-------+ ^---CatchProj(io)
0N/A //
0N/A // We are interested in the CatchProj nodes.
0N/A //
0N/A extract_call_projections(call);
0N/A
0N/A // An allocate node has separate memory projections for the uses on the control and i_o paths
0N/A // Replace uses of the control memory projection with result_phi_rawmem (unless we are only generating a slow call)
0N/A if (!always_slow && _memproj_fallthrough != NULL) {
0N/A for (DUIterator_Fast imax, i = _memproj_fallthrough->fast_outs(imax); i < imax; i++) {
0N/A Node *use = _memproj_fallthrough->fast_out(i);
0N/A _igvn.hash_delete(use);
0N/A imax -= replace_input(use, _memproj_fallthrough, result_phi_rawmem);
0N/A _igvn._worklist.push(use);
0N/A // back up iterator
0N/A --i;
0N/A }
0N/A }
0N/A // Now change uses of _memproj_catchall to use _memproj_fallthrough and delete _memproj_catchall so
0N/A // we end up with a call that has only 1 memory projection
0N/A if (_memproj_catchall != NULL ) {
0N/A if (_memproj_fallthrough == NULL) {
0N/A _memproj_fallthrough = new (C, 1) ProjNode(call, TypeFunc::Memory);
0N/A transform_later(_memproj_fallthrough);
0N/A }
0N/A for (DUIterator_Fast imax, i = _memproj_catchall->fast_outs(imax); i < imax; i++) {
0N/A Node *use = _memproj_catchall->fast_out(i);
0N/A _igvn.hash_delete(use);
0N/A imax -= replace_input(use, _memproj_catchall, _memproj_fallthrough);
0N/A _igvn._worklist.push(use);
0N/A // back up iterator
0N/A --i;
0N/A }
0N/A }
0N/A
0N/A // An allocate node has separate i_o projections for the uses on the control and i_o paths
0N/A // Replace uses of the control i_o projection with result_phi_i_o (unless we are only generating a slow call)
0N/A if (_ioproj_fallthrough == NULL) {
0N/A _ioproj_fallthrough = new (C, 1) ProjNode(call, TypeFunc::I_O);
0N/A transform_later(_ioproj_fallthrough);
0N/A } else if (!always_slow) {
0N/A for (DUIterator_Fast imax, i = _ioproj_fallthrough->fast_outs(imax); i < imax; i++) {
0N/A Node *use = _ioproj_fallthrough->fast_out(i);
0N/A
0N/A _igvn.hash_delete(use);
0N/A imax -= replace_input(use, _ioproj_fallthrough, result_phi_i_o);
0N/A _igvn._worklist.push(use);
0N/A // back up iterator
0N/A --i;
0N/A }
0N/A }
0N/A // Now change uses of _ioproj_catchall to use _ioproj_fallthrough and delete _ioproj_catchall so
0N/A // we end up with a call that has only 1 control projection
0N/A if (_ioproj_catchall != NULL ) {
0N/A for (DUIterator_Fast imax, i = _ioproj_catchall->fast_outs(imax); i < imax; i++) {
0N/A Node *use = _ioproj_catchall->fast_out(i);
0N/A _igvn.hash_delete(use);
0N/A imax -= replace_input(use, _ioproj_catchall, _ioproj_fallthrough);
0N/A _igvn._worklist.push(use);
0N/A // back up iterator
0N/A --i;
0N/A }
0N/A }
0N/A
0N/A // if we generated only a slow call, we are done
0N/A if (always_slow)
0N/A return;
0N/A
0N/A
0N/A if (_fallthroughcatchproj != NULL) {
0N/A ctrl = _fallthroughcatchproj->clone();
0N/A transform_later(ctrl);
708N/A _igvn.replace_node(_fallthroughcatchproj, result_region);
0N/A } else {
0N/A ctrl = top();
0N/A }
0N/A Node *slow_result;
0N/A if (_resproj == NULL) {
0N/A // no uses of the allocation result
0N/A slow_result = top();
0N/A } else {
0N/A slow_result = _resproj->clone();
0N/A transform_later(slow_result);
708N/A _igvn.replace_node(_resproj, result_phi_rawoop);
0N/A }
0N/A
0N/A // Plug slow-path into result merge point
0N/A result_region ->init_req( slow_result_path, ctrl );
0N/A result_phi_rawoop->init_req( slow_result_path, slow_result);
0N/A result_phi_rawmem->init_req( slow_result_path, _memproj_fallthrough );
0N/A transform_later(result_region);
0N/A transform_later(result_phi_rawoop);
0N/A transform_later(result_phi_rawmem);
0N/A transform_later(result_phi_i_o);
0N/A // This completes all paths into the result merge point
0N/A}
0N/A
0N/A
0N/A// Helper for PhaseMacroExpand::expand_allocate_common.
0N/A// Initializes the newly-allocated storage.
0N/ANode*
0N/APhaseMacroExpand::initialize_object(AllocateNode* alloc,
0N/A Node* control, Node* rawmem, Node* object,
0N/A Node* klass_node, Node* length,
0N/A Node* size_in_bytes) {
0N/A InitializeNode* init = alloc->initialization();
0N/A // Store the klass & mark bits
0N/A Node* mark_node = NULL;
0N/A // For now only enable fast locking for non-array types
0N/A if (UseBiasedLocking && (length == NULL)) {
3042N/A mark_node = make_load(control, rawmem, klass_node, in_bytes(Klass::prototype_header_offset()), TypeRawPtr::BOTTOM, T_ADDRESS);
0N/A } else {
0N/A mark_node = makecon(TypeRawPtr::make((address)markOopDesc::prototype()));
0N/A }
0N/A rawmem = make_store(control, rawmem, object, oopDesc::mark_offset_in_bytes(), mark_node, T_ADDRESS);
113N/A
0N/A rawmem = make_store(control, rawmem, object, oopDesc::klass_offset_in_bytes(), klass_node, T_OBJECT);
0N/A int header_size = alloc->minimum_header_size(); // conservatively small
0N/A
0N/A // Array length
0N/A if (length != NULL) { // Arrays need length field
0N/A rawmem = make_store(control, rawmem, object, arrayOopDesc::length_offset_in_bytes(), length, T_INT);
0N/A // conservatively small header size:
113N/A header_size = arrayOopDesc::base_offset_in_bytes(T_BYTE);
0N/A ciKlass* k = _igvn.type(klass_node)->is_klassptr()->klass();
0N/A if (k->is_array_klass()) // we know the exact header size in most cases:
0N/A header_size = Klass::layout_helper_header_size(k->layout_helper());
0N/A }
0N/A
0N/A // Clear the object body, if necessary.
0N/A if (init == NULL) {
0N/A // The init has somehow disappeared; be cautious and clear everything.
0N/A //
0N/A // This can happen if a node is allocated but an uncommon trap occurs
0N/A // immediately. In this case, the Initialize gets associated with the
0N/A // trap, and may be placed in a different (outer) loop, if the Allocate
0N/A // is in a loop. If (this is rare) the inner loop gets unrolled, then
0N/A // there can be two Allocates to one Initialize. The answer in all these
0N/A // edge cases is safety first. It is always safe to clear immediately
0N/A // within an Allocate, and then (maybe or maybe not) clear some more later.
0N/A if (!ZeroTLAB)
0N/A rawmem = ClearArrayNode::clear_memory(control, rawmem, object,
0N/A header_size, size_in_bytes,
0N/A &_igvn);
0N/A } else {
0N/A if (!init->is_complete()) {
0N/A // Try to win by zeroing only what the init does not store.
0N/A // We can also try to do some peephole optimizations,
0N/A // such as combining some adjacent subword stores.
0N/A rawmem = init->complete_stores(control, rawmem, object,
0N/A header_size, size_in_bytes, &_igvn);
0N/A }
0N/A // We have no more use for this link, since the AllocateNode goes away:
0N/A init->set_req(InitializeNode::RawAddress, top());
0N/A // (If we keep the link, it just confuses the register allocator,
0N/A // who thinks he sees a real use of the address by the membar.)
0N/A }
0N/A
0N/A return rawmem;
0N/A}
0N/A
0N/A// Generate prefetch instructions for next allocations.
0N/ANode* PhaseMacroExpand::prefetch_allocation(Node* i_o, Node*& needgc_false,
0N/A Node*& contended_phi_rawmem,
0N/A Node* old_eden_top, Node* new_eden_top,
0N/A Node* length) {
1367N/A enum { fall_in_path = 1, pf_path = 2 };
0N/A if( UseTLAB && AllocatePrefetchStyle == 2 ) {
0N/A // Generate prefetch allocation with watermark check.
0N/A // As an allocation hits the watermark, we will prefetch starting
0N/A // at a "distance" away from watermark.
0N/A
0N/A Node *pf_region = new (C, 3) RegionNode(3);
0N/A Node *pf_phi_rawmem = new (C, 3) PhiNode( pf_region, Type::MEMORY,
0N/A TypeRawPtr::BOTTOM );
0N/A // I/O is used for Prefetch
0N/A Node *pf_phi_abio = new (C, 3) PhiNode( pf_region, Type::ABIO );
0N/A
0N/A Node *thread = new (C, 1) ThreadLocalNode();
0N/A transform_later(thread);
0N/A
0N/A Node *eden_pf_adr = new (C, 4) AddPNode( top()/*not oop*/, thread,
0N/A _igvn.MakeConX(in_bytes(JavaThread::tlab_pf_top_offset())) );
0N/A transform_later(eden_pf_adr);
0N/A
0N/A Node *old_pf_wm = new (C, 3) LoadPNode( needgc_false,
0N/A contended_phi_rawmem, eden_pf_adr,
0N/A TypeRawPtr::BOTTOM, TypeRawPtr::BOTTOM );
0N/A transform_later(old_pf_wm);
0N/A
0N/A // check against new_eden_top
0N/A Node *need_pf_cmp = new (C, 3) CmpPNode( new_eden_top, old_pf_wm );
0N/A transform_later(need_pf_cmp);
0N/A Node *need_pf_bol = new (C, 2) BoolNode( need_pf_cmp, BoolTest::ge );
0N/A transform_later(need_pf_bol);
0N/A IfNode *need_pf_iff = new (C, 2) IfNode( needgc_false, need_pf_bol,
0N/A PROB_UNLIKELY_MAG(4), COUNT_UNKNOWN );
0N/A transform_later(need_pf_iff);
0N/A
0N/A // true node, add prefetchdistance
0N/A Node *need_pf_true = new (C, 1) IfTrueNode( need_pf_iff );
0N/A transform_later(need_pf_true);
0N/A
0N/A Node *need_pf_false = new (C, 1) IfFalseNode( need_pf_iff );
0N/A transform_later(need_pf_false);
0N/A
0N/A Node *new_pf_wmt = new (C, 4) AddPNode( top(), old_pf_wm,
0N/A _igvn.MakeConX(AllocatePrefetchDistance) );
0N/A transform_later(new_pf_wmt );
0N/A new_pf_wmt->set_req(0, need_pf_true);
0N/A
0N/A Node *store_new_wmt = new (C, 4) StorePNode( need_pf_true,
0N/A contended_phi_rawmem, eden_pf_adr,
0N/A TypeRawPtr::BOTTOM, new_pf_wmt );
0N/A transform_later(store_new_wmt);
0N/A
0N/A // adding prefetches
0N/A pf_phi_abio->init_req( fall_in_path, i_o );
0N/A
0N/A Node *prefetch_adr;
0N/A Node *prefetch;
0N/A uint lines = AllocatePrefetchDistance / AllocatePrefetchStepSize;
0N/A uint step_size = AllocatePrefetchStepSize;
0N/A uint distance = 0;
0N/A
0N/A for ( uint i = 0; i < lines; i++ ) {
0N/A prefetch_adr = new (C, 4) AddPNode( old_pf_wm, new_pf_wmt,
0N/A _igvn.MakeConX(distance) );
0N/A transform_later(prefetch_adr);
2679N/A prefetch = new (C, 3) PrefetchAllocationNode( i_o, prefetch_adr );
0N/A transform_later(prefetch);
0N/A distance += step_size;
0N/A i_o = prefetch;
0N/A }
0N/A pf_phi_abio->set_req( pf_path, i_o );
0N/A
0N/A pf_region->init_req( fall_in_path, need_pf_false );
0N/A pf_region->init_req( pf_path, need_pf_true );
0N/A
0N/A pf_phi_rawmem->init_req( fall_in_path, contended_phi_rawmem );
0N/A pf_phi_rawmem->init_req( pf_path, store_new_wmt );
0N/A
0N/A transform_later(pf_region);
0N/A transform_later(pf_phi_rawmem);
0N/A transform_later(pf_phi_abio);
0N/A
0N/A needgc_false = pf_region;
0N/A contended_phi_rawmem = pf_phi_rawmem;
0N/A i_o = pf_phi_abio;
1367N/A } else if( UseTLAB && AllocatePrefetchStyle == 3 ) {
2679N/A // Insert a prefetch for each allocation.
2679N/A // This code is used for Sparc with BIS.
1367N/A Node *pf_region = new (C, 3) RegionNode(3);
1367N/A Node *pf_phi_rawmem = new (C, 3) PhiNode( pf_region, Type::MEMORY,
1367N/A TypeRawPtr::BOTTOM );
1367N/A
2679N/A // Generate several prefetch instructions.
2679N/A uint lines = (length != NULL) ? AllocatePrefetchLines : AllocateInstancePrefetchLines;
1367N/A uint step_size = AllocatePrefetchStepSize;
1367N/A uint distance = AllocatePrefetchDistance;
1367N/A
1367N/A // Next cache address.
1367N/A Node *cache_adr = new (C, 4) AddPNode(old_eden_top, old_eden_top,
1367N/A _igvn.MakeConX(distance));
1367N/A transform_later(cache_adr);
1367N/A cache_adr = new (C, 2) CastP2XNode(needgc_false, cache_adr);
1367N/A transform_later(cache_adr);
1367N/A Node* mask = _igvn.MakeConX(~(intptr_t)(step_size-1));
1367N/A cache_adr = new (C, 3) AndXNode(cache_adr, mask);
1367N/A transform_later(cache_adr);
1367N/A cache_adr = new (C, 2) CastX2PNode(cache_adr);
1367N/A transform_later(cache_adr);
1367N/A
1367N/A // Prefetch
2679N/A Node *prefetch = new (C, 3) PrefetchAllocationNode( contended_phi_rawmem, cache_adr );
1367N/A prefetch->set_req(0, needgc_false);
1367N/A transform_later(prefetch);
1367N/A contended_phi_rawmem = prefetch;
1367N/A Node *prefetch_adr;
1367N/A distance = step_size;
1367N/A for ( uint i = 1; i < lines; i++ ) {
1367N/A prefetch_adr = new (C, 4) AddPNode( cache_adr, cache_adr,
1367N/A _igvn.MakeConX(distance) );
1367N/A transform_later(prefetch_adr);
2679N/A prefetch = new (C, 3) PrefetchAllocationNode( contended_phi_rawmem, prefetch_adr );
1367N/A transform_later(prefetch);
1367N/A distance += step_size;
1367N/A contended_phi_rawmem = prefetch;
1367N/A }
0N/A } else if( AllocatePrefetchStyle > 0 ) {
0N/A // Insert a prefetch for each allocation only on the fast-path
0N/A Node *prefetch_adr;
0N/A Node *prefetch;
2679N/A // Generate several prefetch instructions.
2679N/A uint lines = (length != NULL) ? AllocatePrefetchLines : AllocateInstancePrefetchLines;
0N/A uint step_size = AllocatePrefetchStepSize;
0N/A uint distance = AllocatePrefetchDistance;
0N/A for ( uint i = 0; i < lines; i++ ) {
0N/A prefetch_adr = new (C, 4) AddPNode( old_eden_top, new_eden_top,
0N/A _igvn.MakeConX(distance) );
0N/A transform_later(prefetch_adr);
2679N/A prefetch = new (C, 3) PrefetchAllocationNode( i_o, prefetch_adr );
0N/A // Do not let it float too high, since if eden_top == eden_end,
0N/A // both might be null.
0N/A if( i == 0 ) { // Set control for first prefetch, next follows it
0N/A prefetch->init_req(0, needgc_false);
0N/A }
0N/A transform_later(prefetch);
0N/A distance += step_size;
0N/A i_o = prefetch;
0N/A }
0N/A }
0N/A return i_o;
0N/A}
0N/A
0N/A
0N/Avoid PhaseMacroExpand::expand_allocate(AllocateNode *alloc) {
0N/A expand_allocate_common(alloc, NULL,
0N/A OptoRuntime::new_instance_Type(),
0N/A OptoRuntime::new_instance_Java());
0N/A}
0N/A
0N/Avoid PhaseMacroExpand::expand_allocate_array(AllocateArrayNode *alloc) {
0N/A Node* length = alloc->in(AllocateNode::ALength);
2797N/A InitializeNode* init = alloc->initialization();
2797N/A Node* klass_node = alloc->in(AllocateNode::KlassNode);
2797N/A ciKlass* k = _igvn.type(klass_node)->is_klassptr()->klass();
2797N/A address slow_call_address; // Address of slow call
2797N/A if (init != NULL && init->is_complete_with_arraycopy() &&
2797N/A k->is_type_array_klass()) {
2797N/A // Don't zero type array during slow allocation in VM since
2797N/A // it will be initialized later by arraycopy in compiled code.
2797N/A slow_call_address = OptoRuntime::new_array_nozero_Java();
2797N/A } else {
2797N/A slow_call_address = OptoRuntime::new_array_Java();
2797N/A }
0N/A expand_allocate_common(alloc, length,
0N/A OptoRuntime::new_array_Type(),
2797N/A slow_call_address);
0N/A}
0N/A
2579N/A//-----------------------mark_eliminated_locking_nodes-----------------------
2579N/A// During EA obj may point to several objects but after few ideal graph
2579N/A// transformations (CCP) it may point to only one non escaping object
2579N/A// (but still using phi), corresponding locks and unlocks will be marked
2579N/A// for elimination. Later obj could be replaced with a new node (new phi)
2579N/A// and which does not have escape information. And later after some graph
2579N/A// reshape other locks and unlocks (which were not marked for elimination
2579N/A// before) are connected to this new obj (phi) but they still will not be
2579N/A// marked for elimination since new obj has no escape information.
2579N/A// Mark all associated (same box and obj) lock and unlock nodes for
2579N/A// elimination if some of them marked already.
2579N/Avoid PhaseMacroExpand::mark_eliminated_locking_nodes(AbstractLockNode *alock) {
66N/A if (!alock->is_eliminated()) {
2579N/A return;
66N/A }
2579N/A if (!alock->is_coarsened()) { // Eliminated by EA
460N/A // Create new "eliminated" BoxLock node and use it
460N/A // in monitor debug info for the same object.
460N/A BoxLockNode* oldbox = alock->box_node()->as_BoxLock();
460N/A Node* obj = alock->obj_node();
460N/A if (!oldbox->is_eliminated()) {
460N/A BoxLockNode* newbox = oldbox->clone()->as_BoxLock();
2579N/A // Note: BoxLock node is marked eliminated only here
2579N/A // and it is used to indicate that all associated lock
2579N/A // and unlock nodes are marked for elimination.
460N/A newbox->set_eliminated();
460N/A transform_later(newbox);
460N/A // Replace old box node with new box for all users
460N/A // of the same object.
460N/A for (uint i = 0; i < oldbox->outcnt();) {
460N/A
460N/A bool next_edge = true;
460N/A Node* u = oldbox->raw_out(i);
2579N/A if (u->is_AbstractLock() &&
2579N/A u->as_AbstractLock()->obj_node() == obj &&
2579N/A u->as_AbstractLock()->box_node() == oldbox) {
2579N/A // Mark all associated locks and unlocks.
2579N/A u->as_AbstractLock()->set_eliminated();
460N/A _igvn.hash_delete(u);
460N/A u->set_req(TypeFunc::Parms + 1, newbox);
460N/A next_edge = false;
460N/A }
460N/A // Replace old box in monitor debug info.
460N/A if (u->is_SafePoint() && u->as_SafePoint()->jvms()) {
460N/A SafePointNode* sfn = u->as_SafePoint();
460N/A JVMState* youngest_jvms = sfn->jvms();
460N/A int max_depth = youngest_jvms->depth();
460N/A for (int depth = 1; depth <= max_depth; depth++) {
460N/A JVMState* jvms = youngest_jvms->of_depth(depth);
460N/A int num_mon = jvms->nof_monitors();
460N/A // Loop over monitors
460N/A for (int idx = 0; idx < num_mon; idx++) {
460N/A Node* obj_node = sfn->monitor_obj(jvms, idx);
460N/A Node* box_node = sfn->monitor_box(jvms, idx);
460N/A if (box_node == oldbox && obj_node == obj) {
460N/A int j = jvms->monitor_box_offset(idx);
460N/A _igvn.hash_delete(u);
460N/A u->set_req(j, newbox);
460N/A next_edge = false;
460N/A }
460N/A } // for (int idx = 0;
460N/A } // for (int depth = 1;
460N/A } // if (u->is_SafePoint()
460N/A if (next_edge) i++;
460N/A } // for (uint i = 0; i < oldbox->outcnt();)
460N/A } // if (!oldbox->is_eliminated())
2579N/A } // if (!alock->is_coarsened())
2579N/A}
2579N/A
2579N/A// we have determined that this lock/unlock can be eliminated, we simply
2579N/A// eliminate the node without expanding it.
2579N/A//
2579N/A// Note: The membar's associated with the lock/unlock are currently not
2579N/A// eliminated. This should be investigated as a future enhancement.
2579N/A//
2579N/Abool PhaseMacroExpand::eliminate_locking_node(AbstractLockNode *alock) {
66N/A
2579N/A if (!alock->is_eliminated()) {
2579N/A return false;
2579N/A }
2579N/A#ifdef ASSERT
2579N/A if (alock->is_Lock() && !alock->is_coarsened()) {
2579N/A // Check that new "eliminated" BoxLock node is created.
2579N/A BoxLockNode* oldbox = alock->box_node()->as_BoxLock();
2579N/A assert(oldbox->is_eliminated(), "should be done already");
2579N/A }
2579N/A#endif
1080N/A CompileLog* log = C->log();
1080N/A if (log != NULL) {
1080N/A log->head("eliminate_lock lock='%d'",
1080N/A alock->is_Lock());
1080N/A JVMState* p = alock->jvms();
1080N/A while (p != NULL) {
1080N/A log->elem("jvms bci='%d' method='%d'", p->bci(), log->identify(p->method()));
1080N/A p = p->caller();
1080N/A }
1080N/A log->tail("eliminate_lock");
1080N/A }
1080N/A
66N/A #ifndef PRODUCT
66N/A if (PrintEliminateLocks) {
66N/A if (alock->is_Lock()) {
2958N/A tty->print_cr("++++ Eliminated: %d Lock", alock->_idx);
66N/A } else {
2958N/A tty->print_cr("++++ Eliminated: %d Unlock", alock->_idx);
66N/A }
66N/A }
66N/A #endif
66N/A
66N/A Node* mem = alock->in(TypeFunc::Memory);
66N/A Node* ctrl = alock->in(TypeFunc::Control);
66N/A
66N/A extract_call_projections(alock);
66N/A // There are 2 projections from the lock. The lock node will
66N/A // be deleted when its last use is subsumed below.
66N/A assert(alock->outcnt() == 2 &&
66N/A _fallthroughproj != NULL &&
66N/A _memproj_fallthrough != NULL,
66N/A "Unexpected projections from Lock/Unlock");
66N/A
66N/A Node* fallthroughproj = _fallthroughproj;
66N/A Node* memproj_fallthrough = _memproj_fallthrough;
0N/A
0N/A // The memory projection from a lock/unlock is RawMem
0N/A // The input to a Lock is merged memory, so extract its RawMem input
0N/A // (unless the MergeMem has been optimized away.)
0N/A if (alock->is_Lock()) {
2674N/A // Seach for MemBarAcquireLock node and delete it also.
66N/A MemBarNode* membar = fallthroughproj->unique_ctrl_out()->as_MemBar();
2674N/A assert(membar != NULL && membar->Opcode() == Op_MemBarAcquireLock, "");
66N/A Node* ctrlproj = membar->proj_out(TypeFunc::Control);
66N/A Node* memproj = membar->proj_out(TypeFunc::Memory);
708N/A _igvn.replace_node(ctrlproj, fallthroughproj);
708N/A _igvn.replace_node(memproj, memproj_fallthrough);
460N/A
460N/A // Delete FastLock node also if this Lock node is unique user
460N/A // (a loop peeling may clone a Lock node).
460N/A Node* flock = alock->as_Lock()->fastlock_node();
460N/A if (flock->outcnt() == 1) {
460N/A assert(flock->unique_out() == alock, "sanity");
708N/A _igvn.replace_node(flock, top());
460N/A }
0N/A }
0N/A
2674N/A // Seach for MemBarReleaseLock node and delete it also.
66N/A if (alock->is_Unlock() && ctrl != NULL && ctrl->is_Proj() &&
66N/A ctrl->in(0)->is_MemBar()) {
66N/A MemBarNode* membar = ctrl->in(0)->as_MemBar();
2674N/A assert(membar->Opcode() == Op_MemBarReleaseLock &&
66N/A mem->is_Proj() && membar == mem->in(0), "");
708N/A _igvn.replace_node(fallthroughproj, ctrl);
708N/A _igvn.replace_node(memproj_fallthrough, mem);
66N/A fallthroughproj = ctrl;
66N/A memproj_fallthrough = mem;
66N/A ctrl = membar->in(TypeFunc::Control);
66N/A mem = membar->in(TypeFunc::Memory);
66N/A }
66N/A
708N/A _igvn.replace_node(fallthroughproj, ctrl);
708N/A _igvn.replace_node(memproj_fallthrough, mem);
66N/A return true;
0N/A}
0N/A
0N/A
0N/A//------------------------------expand_lock_node----------------------
0N/Avoid PhaseMacroExpand::expand_lock_node(LockNode *lock) {
0N/A
0N/A Node* ctrl = lock->in(TypeFunc::Control);
0N/A Node* mem = lock->in(TypeFunc::Memory);
0N/A Node* obj = lock->obj_node();
0N/A Node* box = lock->box_node();
66N/A Node* flock = lock->fastlock_node();
0N/A
0N/A // Make the merge point
420N/A Node *region;
420N/A Node *mem_phi;
420N/A Node *slow_path;
420N/A
420N/A if (UseOptoBiasInlining) {
420N/A /*
605N/A * See the full description in MacroAssembler::biased_locking_enter().
420N/A *
420N/A * if( (mark_word & biased_lock_mask) == biased_lock_pattern ) {
420N/A * // The object is biased.
420N/A * proto_node = klass->prototype_header;
420N/A * o_node = thread | proto_node;
420N/A * x_node = o_node ^ mark_word;
420N/A * if( (x_node & ~age_mask) == 0 ) { // Biased to the current thread ?
420N/A * // Done.
420N/A * } else {
420N/A * if( (x_node & biased_lock_mask) != 0 ) {
420N/A * // The klass's prototype header is no longer biased.
420N/A * cas(&mark_word, mark_word, proto_node)
420N/A * goto cas_lock;
420N/A * } else {
420N/A * // The klass's prototype header is still biased.
420N/A * if( (x_node & epoch_mask) != 0 ) { // Expired epoch?
420N/A * old = mark_word;
420N/A * new = o_node;
420N/A * } else {
420N/A * // Different thread or anonymous biased.
420N/A * old = mark_word & (epoch_mask | age_mask | biased_lock_mask);
420N/A * new = thread | old;
420N/A * }
420N/A * // Try to rebias.
420N/A * if( cas(&mark_word, old, new) == 0 ) {
420N/A * // Done.
420N/A * } else {
420N/A * goto slow_path; // Failed.
420N/A * }
420N/A * }
420N/A * }
420N/A * } else {
420N/A * // The object is not biased.
420N/A * cas_lock:
420N/A * if( FastLock(obj) == 0 ) {
420N/A * // Done.
420N/A * } else {
420N/A * slow_path:
420N/A * OptoRuntime::complete_monitor_locking_Java(obj);
420N/A * }
420N/A * }
420N/A */
420N/A
420N/A region = new (C, 5) RegionNode(5);
420N/A // create a Phi for the memory state
420N/A mem_phi = new (C, 5) PhiNode( region, Type::MEMORY, TypeRawPtr::BOTTOM);
420N/A
420N/A Node* fast_lock_region = new (C, 3) RegionNode(3);
420N/A Node* fast_lock_mem_phi = new (C, 3) PhiNode( fast_lock_region, Type::MEMORY, TypeRawPtr::BOTTOM);
420N/A
420N/A // First, check mark word for the biased lock pattern.
420N/A Node* mark_node = make_load(ctrl, mem, obj, oopDesc::mark_offset_in_bytes(), TypeX_X, TypeX_X->basic_type());
420N/A
420N/A // Get fast path - mark word has the biased lock pattern.
420N/A ctrl = opt_bits_test(ctrl, fast_lock_region, 1, mark_node,
420N/A markOopDesc::biased_lock_mask_in_place,
420N/A markOopDesc::biased_lock_pattern, true);
420N/A // fast_lock_region->in(1) is set to slow path.
420N/A fast_lock_mem_phi->init_req(1, mem);
420N/A
420N/A // Now check that the lock is biased to the current thread and has
420N/A // the same epoch and bias as Klass::_prototype_header.
420N/A
420N/A // Special-case a fresh allocation to avoid building nodes:
420N/A Node* klass_node = AllocateNode::Ideal_klass(obj, &_igvn);
420N/A if (klass_node == NULL) {
420N/A Node* k_adr = basic_plus_adr(obj, oopDesc::klass_offset_in_bytes());
420N/A klass_node = transform_later( LoadKlassNode::make(_igvn, mem, k_adr, _igvn.type(k_adr)->is_ptr()) );
490N/A#ifdef _LP64
490N/A if (UseCompressedOops && klass_node->is_DecodeN()) {
490N/A assert(klass_node->in(1)->Opcode() == Op_LoadNKlass, "sanity");
490N/A klass_node->in(1)->init_req(0, ctrl);
490N/A } else
490N/A#endif
490N/A klass_node->init_req(0, ctrl);
420N/A }
3042N/A Node *proto_node = make_load(ctrl, mem, klass_node, in_bytes(Klass::prototype_header_offset()), TypeX_X, TypeX_X->basic_type());
420N/A
420N/A Node* thread = transform_later(new (C, 1) ThreadLocalNode());
420N/A Node* cast_thread = transform_later(new (C, 2) CastP2XNode(ctrl, thread));
420N/A Node* o_node = transform_later(new (C, 3) OrXNode(cast_thread, proto_node));
420N/A Node* x_node = transform_later(new (C, 3) XorXNode(o_node, mark_node));
420N/A
420N/A // Get slow path - mark word does NOT match the value.
420N/A Node* not_biased_ctrl = opt_bits_test(ctrl, region, 3, x_node,
420N/A (~markOopDesc::age_mask_in_place), 0);
420N/A // region->in(3) is set to fast path - the object is biased to the current thread.
420N/A mem_phi->init_req(3, mem);
420N/A
420N/A
420N/A // Mark word does NOT match the value (thread | Klass::_prototype_header).
420N/A
0N/A
420N/A // First, check biased pattern.
420N/A // Get fast path - _prototype_header has the same biased lock pattern.
420N/A ctrl = opt_bits_test(not_biased_ctrl, fast_lock_region, 2, x_node,
420N/A markOopDesc::biased_lock_mask_in_place, 0, true);
420N/A
420N/A not_biased_ctrl = fast_lock_region->in(2); // Slow path
420N/A // fast_lock_region->in(2) - the prototype header is no longer biased
420N/A // and we have to revoke the bias on this object.
420N/A // We are going to try to reset the mark of this object to the prototype
420N/A // value and fall through to the CAS-based locking scheme.
420N/A Node* adr = basic_plus_adr(obj, oopDesc::mark_offset_in_bytes());
420N/A Node* cas = new (C, 5) StoreXConditionalNode(not_biased_ctrl, mem, adr,
420N/A proto_node, mark_node);
420N/A transform_later(cas);
420N/A Node* proj = transform_later( new (C, 1) SCMemProjNode(cas));
420N/A fast_lock_mem_phi->init_req(2, proj);
420N/A
420N/A
420N/A // Second, check epoch bits.
420N/A Node* rebiased_region = new (C, 3) RegionNode(3);
420N/A Node* old_phi = new (C, 3) PhiNode( rebiased_region, TypeX_X);
420N/A Node* new_phi = new (C, 3) PhiNode( rebiased_region, TypeX_X);
420N/A
420N/A // Get slow path - mark word does NOT match epoch bits.
420N/A Node* epoch_ctrl = opt_bits_test(ctrl, rebiased_region, 1, x_node,
420N/A markOopDesc::epoch_mask_in_place, 0);
420N/A // The epoch of the current bias is not valid, attempt to rebias the object
420N/A // toward the current thread.
420N/A rebiased_region->init_req(2, epoch_ctrl);
420N/A old_phi->init_req(2, mark_node);
420N/A new_phi->init_req(2, o_node);
420N/A
420N/A // rebiased_region->in(1) is set to fast path.
420N/A // The epoch of the current bias is still valid but we know
420N/A // nothing about the owner; it might be set or it might be clear.
420N/A Node* cmask = MakeConX(markOopDesc::biased_lock_mask_in_place |
420N/A markOopDesc::age_mask_in_place |
420N/A markOopDesc::epoch_mask_in_place);
420N/A Node* old = transform_later(new (C, 3) AndXNode(mark_node, cmask));
420N/A cast_thread = transform_later(new (C, 2) CastP2XNode(ctrl, thread));
420N/A Node* new_mark = transform_later(new (C, 3) OrXNode(cast_thread, old));
420N/A old_phi->init_req(1, old);
420N/A new_phi->init_req(1, new_mark);
420N/A
420N/A transform_later(rebiased_region);
420N/A transform_later(old_phi);
420N/A transform_later(new_phi);
420N/A
420N/A // Try to acquire the bias of the object using an atomic operation.
420N/A // If this fails we will go in to the runtime to revoke the object's bias.
420N/A cas = new (C, 5) StoreXConditionalNode(rebiased_region, mem, adr,
420N/A new_phi, old_phi);
420N/A transform_later(cas);
420N/A proj = transform_later( new (C, 1) SCMemProjNode(cas));
420N/A
420N/A // Get slow path - Failed to CAS.
420N/A not_biased_ctrl = opt_bits_test(rebiased_region, region, 4, cas, 0, 0);
420N/A mem_phi->init_req(4, proj);
420N/A // region->in(4) is set to fast path - the object is rebiased to the current thread.
420N/A
420N/A // Failed to CAS.
420N/A slow_path = new (C, 3) RegionNode(3);
420N/A Node *slow_mem = new (C, 3) PhiNode( slow_path, Type::MEMORY, TypeRawPtr::BOTTOM);
420N/A
420N/A slow_path->init_req(1, not_biased_ctrl); // Capture slow-control
420N/A slow_mem->init_req(1, proj);
420N/A
420N/A // Call CAS-based locking scheme (FastLock node).
420N/A
420N/A transform_later(fast_lock_region);
420N/A transform_later(fast_lock_mem_phi);
420N/A
420N/A // Get slow path - FastLock failed to lock the object.
420N/A ctrl = opt_bits_test(fast_lock_region, region, 2, flock, 0, 0);
420N/A mem_phi->init_req(2, fast_lock_mem_phi);
420N/A // region->in(2) is set to fast path - the object is locked to the current thread.
420N/A
420N/A slow_path->init_req(2, ctrl); // Capture slow-control
420N/A slow_mem->init_req(2, fast_lock_mem_phi);
420N/A
420N/A transform_later(slow_path);
420N/A transform_later(slow_mem);
420N/A // Reset lock's memory edge.
420N/A lock->set_req(TypeFunc::Memory, slow_mem);
420N/A
420N/A } else {
420N/A region = new (C, 3) RegionNode(3);
420N/A // create a Phi for the memory state
420N/A mem_phi = new (C, 3) PhiNode( region, Type::MEMORY, TypeRawPtr::BOTTOM);
420N/A
420N/A // Optimize test; set region slot 2
420N/A slow_path = opt_bits_test(ctrl, region, 2, flock, 0, 0);
420N/A mem_phi->init_req(2, mem);
420N/A }
0N/A
0N/A // Make slow path call
0N/A CallNode *call = make_slow_call( (CallNode *) lock, OptoRuntime::complete_monitor_enter_Type(), OptoRuntime::complete_monitor_locking_Java(), NULL, slow_path, obj, box );
0N/A
0N/A extract_call_projections(call);
0N/A
0N/A // Slow path can only throw asynchronous exceptions, which are always
0N/A // de-opted. So the compiler thinks the slow-call can never throw an
0N/A // exception. If it DOES throw an exception we would need the debug
0N/A // info removed first (since if it throws there is no monitor).
0N/A assert ( _ioproj_fallthrough == NULL && _ioproj_catchall == NULL &&
0N/A _memproj_catchall == NULL && _catchallcatchproj == NULL, "Unexpected projection from Lock");
0N/A
0N/A // Capture slow path
0N/A // disconnect fall-through projection from call and create a new one
0N/A // hook up users of fall-through projection to region
0N/A Node *slow_ctrl = _fallthroughproj->clone();
0N/A transform_later(slow_ctrl);
0N/A _igvn.hash_delete(_fallthroughproj);
0N/A _fallthroughproj->disconnect_inputs(NULL);
0N/A region->init_req(1, slow_ctrl);
0N/A // region inputs are now complete
0N/A transform_later(region);
708N/A _igvn.replace_node(_fallthroughproj, region);
0N/A
420N/A Node *memproj = transform_later( new(C, 1) ProjNode(call, TypeFunc::Memory) );
0N/A mem_phi->init_req(1, memproj );
0N/A transform_later(mem_phi);
708N/A _igvn.replace_node(_memproj_fallthrough, mem_phi);
0N/A}
0N/A
0N/A//------------------------------expand_unlock_node----------------------
0N/Avoid PhaseMacroExpand::expand_unlock_node(UnlockNode *unlock) {
0N/A
66N/A Node* ctrl = unlock->in(TypeFunc::Control);
0N/A Node* mem = unlock->in(TypeFunc::Memory);
0N/A Node* obj = unlock->obj_node();
0N/A Node* box = unlock->box_node();
0N/A
0N/A // No need for a null check on unlock
0N/A
0N/A // Make the merge point
420N/A Node *region;
420N/A Node *mem_phi;
420N/A
420N/A if (UseOptoBiasInlining) {
420N/A // Check for biased locking unlock case, which is a no-op.
605N/A // See the full description in MacroAssembler::biased_locking_exit().
420N/A region = new (C, 4) RegionNode(4);
420N/A // create a Phi for the memory state
420N/A mem_phi = new (C, 4) PhiNode( region, Type::MEMORY, TypeRawPtr::BOTTOM);
420N/A mem_phi->init_req(3, mem);
420N/A
420N/A Node* mark_node = make_load(ctrl, mem, obj, oopDesc::mark_offset_in_bytes(), TypeX_X, TypeX_X->basic_type());
420N/A ctrl = opt_bits_test(ctrl, region, 3, mark_node,
420N/A markOopDesc::biased_lock_mask_in_place,
420N/A markOopDesc::biased_lock_pattern);
420N/A } else {
420N/A region = new (C, 3) RegionNode(3);
420N/A // create a Phi for the memory state
420N/A mem_phi = new (C, 3) PhiNode( region, Type::MEMORY, TypeRawPtr::BOTTOM);
420N/A }
0N/A
0N/A FastUnlockNode *funlock = new (C, 3) FastUnlockNode( ctrl, obj, box );
0N/A funlock = transform_later( funlock )->as_FastUnlock();
0N/A // Optimize test; set region slot 2
420N/A Node *slow_path = opt_bits_test(ctrl, region, 2, funlock, 0, 0);
0N/A
0N/A 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 );
0N/A
0N/A extract_call_projections(call);
0N/A
0N/A assert ( _ioproj_fallthrough == NULL && _ioproj_catchall == NULL &&
0N/A _memproj_catchall == NULL && _catchallcatchproj == NULL, "Unexpected projection from Lock");
0N/A
0N/A // No exceptions for unlocking
0N/A // Capture slow path
0N/A // disconnect fall-through projection from call and create a new one
0N/A // hook up users of fall-through projection to region
0N/A Node *slow_ctrl = _fallthroughproj->clone();
0N/A transform_later(slow_ctrl);
0N/A _igvn.hash_delete(_fallthroughproj);
0N/A _fallthroughproj->disconnect_inputs(NULL);
0N/A region->init_req(1, slow_ctrl);
0N/A // region inputs are now complete
0N/A transform_later(region);
708N/A _igvn.replace_node(_fallthroughproj, region);
0N/A
0N/A Node *memproj = transform_later( new(C, 1) ProjNode(call, TypeFunc::Memory) );
0N/A mem_phi->init_req(1, memproj );
0N/A mem_phi->init_req(2, mem);
0N/A transform_later(mem_phi);
708N/A _igvn.replace_node(_memproj_fallthrough, mem_phi);
0N/A}
0N/A
2958N/A//---------------------------eliminate_macro_nodes----------------------
2958N/A// Eliminate scalar replaced allocations and associated locks.
2958N/Avoid PhaseMacroExpand::eliminate_macro_nodes() {
0N/A if (C->macro_count() == 0)
2958N/A return;
2958N/A
460N/A // First, attempt to eliminate locks
2579N/A int cnt = C->macro_count();
2579N/A for (int i=0; i < cnt; i++) {
2579N/A Node *n = C->macro_node(i);
2579N/A if (n->is_AbstractLock()) { // Lock and Unlock nodes
2579N/A // Before elimination mark all associated (same box and obj)
2579N/A // lock and unlock nodes.
2579N/A mark_eliminated_locking_nodes(n->as_AbstractLock());
2579N/A }
2579N/A }
73N/A bool progress = true;
73N/A while (progress) {
73N/A progress = false;
73N/A for (int i = C->macro_count(); i > 0; i--) {
73N/A Node * n = C->macro_node(i-1);
73N/A bool success = false;
73N/A debug_only(int old_macro_count = C->macro_count(););
460N/A if (n->is_AbstractLock()) {
460N/A success = eliminate_locking_node(n->as_AbstractLock());
460N/A }
460N/A assert(success == (C->macro_count() < old_macro_count), "elimination reduces macro count");
460N/A progress = progress || success;
460N/A }
460N/A }
460N/A // Next, attempt to eliminate allocations
460N/A progress = true;
460N/A while (progress) {
460N/A progress = false;
460N/A for (int i = C->macro_count(); i > 0; i--) {
460N/A Node * n = C->macro_node(i-1);
460N/A bool success = false;
460N/A debug_only(int old_macro_count = C->macro_count(););
73N/A switch (n->class_id()) {
73N/A case Node::Class_Allocate:
73N/A case Node::Class_AllocateArray:
73N/A success = eliminate_allocate_node(n->as_Allocate());
73N/A break;
73N/A case Node::Class_Lock:
73N/A case Node::Class_Unlock:
460N/A assert(!n->as_AbstractLock()->is_eliminated(), "sanity");
73N/A break;
73N/A default:
2958N/A assert(n->Opcode() == Op_LoopLimit ||
2958N/A n->Opcode() == Op_Opaque1 ||
2958N/A n->Opcode() == Op_Opaque2, "unknown node type in macro list");
73N/A }
73N/A assert(success == (C->macro_count() < old_macro_count), "elimination reduces macro count");
73N/A progress = progress || success;
73N/A }
73N/A }
2958N/A}
2958N/A
2958N/A//------------------------------expand_macro_nodes----------------------
2958N/A// Returns true if a failure occurred.
2958N/Abool PhaseMacroExpand::expand_macro_nodes() {
2958N/A // Last attempt to eliminate macro nodes.
2958N/A eliminate_macro_nodes();
2958N/A
73N/A // Make sure expansion will not cause node limit to be exceeded.
73N/A // Worst case is a macro node gets expanded into about 50 nodes.
73N/A // Allow 50% more for optimization.
0N/A if (C->check_node_count(C->macro_count() * 75, "out of nodes before macro expansion" ) )
0N/A return true;
73N/A
2958N/A // Eliminate Opaque and LoopLimit nodes. Do it after all loop optimizations.
2958N/A bool progress = true;
2958N/A while (progress) {
2958N/A progress = false;
2958N/A for (int i = C->macro_count(); i > 0; i--) {
2958N/A Node * n = C->macro_node(i-1);
2958N/A bool success = false;
2958N/A debug_only(int old_macro_count = C->macro_count(););
2958N/A if (n->Opcode() == Op_LoopLimit) {
2958N/A // Remove it from macro list and put on IGVN worklist to optimize.
2958N/A C->remove_macro_node(n);
2958N/A _igvn._worklist.push(n);
2958N/A success = true;
2958N/A } else if (n->Opcode() == Op_Opaque1 || n->Opcode() == Op_Opaque2) {
2958N/A _igvn.replace_node(n, n->in(1));
2958N/A success = true;
2958N/A }
2958N/A assert(success == (C->macro_count() < old_macro_count), "elimination reduces macro count");
2958N/A progress = progress || success;
2958N/A }
2958N/A }
2958N/A
0N/A // expand "macro" nodes
0N/A // nodes are removed from the macro list as they are processed
0N/A while (C->macro_count() > 0) {
73N/A int macro_count = C->macro_count();
73N/A Node * n = C->macro_node(macro_count-1);
0N/A assert(n->is_macro(), "only macro nodes expected here");
0N/A if (_igvn.type(n) == Type::TOP || n->in(0)->is_top() ) {
0N/A // node is unreachable, so don't try to expand it
0N/A C->remove_macro_node(n);
0N/A continue;
0N/A }
0N/A switch (n->class_id()) {
0N/A case Node::Class_Allocate:
0N/A expand_allocate(n->as_Allocate());
0N/A break;
0N/A case Node::Class_AllocateArray:
0N/A expand_allocate_array(n->as_AllocateArray());
0N/A break;
0N/A case Node::Class_Lock:
0N/A expand_lock_node(n->as_Lock());
0N/A break;
0N/A case Node::Class_Unlock:
0N/A expand_unlock_node(n->as_Unlock());
0N/A break;
0N/A default:
0N/A assert(false, "unknown node type in macro list");
0N/A }
73N/A assert(C->macro_count() < macro_count, "must have deleted a node from macro list");
0N/A if (C->failing()) return true;
0N/A }
113N/A
113N/A _igvn.set_delay_transform(false);
0N/A _igvn.optimize();
2958N/A if (C->failing()) return true;
0N/A return false;
0N/A}