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) {
4022N/A Node* and_node = transform_later(new (C) AndXNode(word, MakeConX(mask)));
4022N/A cmp = transform_later(new (C) CmpXNode(and_node, MakeConX(bits)));
420N/A } else {
420N/A cmp = word;
420N/A }
4022N/A Node* bol = transform_later(new (C) BoolNode(cmp, BoolTest::ne));
4022N/A IfNode* iff = new (C) IfNode( ctrl, bol, PROB_MIN, COUNT_UNKNOWN );
420N/A transform_later(iff);
0N/A
420N/A // Fast path taken.
4022N/A Node *fast_taken = transform_later( new (C) IfFalseNode(iff) );
0N/A
0N/A // Fast path not-taken, i.e. slow path
4022N/A Node *slow_taken = transform_later( new (C) 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 CallNode *call = leaf_name
4022N/A ? (CallNode*)new (C) CallLeafNode ( slow_call_type, slow_call, leaf_name, TypeRawPtr::BOTTOM )
4022N/A : (CallNode*)new (C) 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
3181N/A assert(p2x->outcnt() <= 2, "expects 1 or 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
3181N/A // An other case of only one user (Xor) is when the value check for NULL
3181N/A // in G1 post barrier is folded after CCP so the code which used URShift
3181N/A // is removed.
3181N/A
3181N/A // Take Region node before eliminating post barrier since it also
3181N/A // eliminates CastP2X node when it has only one user.
3181N/A Node* this_region = p2x->in(0);
3181N/A assert(this_region != NULL, "");
3181N/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 // 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.
3181N/A assert(p2x->outcnt() == 0 || 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();
3863N/A GrowableArray <Node *> values(length, length, NULL, false);
73N/A
247N/A // create a new Phi for the value
4022N/A PhiNode *phi = new (C) 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();
4022N/A SafePointScalarObjectNode* sobj = new (C) 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 {
4505N/A field_val = transform_later(new (C) DecodeNNode(field_val, field_val->get_ptr_type()));
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
4022N/A Node* thread = transform_later(new (C) 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 ) {
4022N/A slow_region = new (C) 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.
4022N/A IfNode *toobig_iff = new (C) 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
4022N/A Node *toobig_true = new (C) IfTrueNode( toobig_iff );
0N/A transform_later(toobig_true);
0N/A slow_region ->init_req( too_big_or_final_path, toobig_true );
4022N/A toobig_false = new (C) 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
4022N/A result_region = new (C) RegionNode(3);
4022N/A result_phi_rawmem = new (C) PhiNode(result_region, Type::MEMORY, TypeRawPtr::BOTTOM);
4022N/A result_phi_rawoop = new (C) PhiNode(result_region, TypeRawPtr::BOTTOM);
4022N/A result_phi_i_o = new (C) 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 {
4022N/A contended_region = new (C) RegionNode(3);
4022N/A contended_phi_rawmem = new (C) 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
4022N/A ? new (C) LoadPNode (ctrl, contended_phi_rawmem, eden_top_adr, TypeRawPtr::BOTTOM, TypeRawPtr::BOTTOM)
4022N/A : new (C) 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
4022N/A Node *new_eden_top = new (C) 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
4022N/A Node *needgc_cmp = new (C) CmpPNode(new_eden_top, eden_end);
0N/A transform_later(needgc_cmp);
4022N/A Node *needgc_bol = new (C) BoolNode(needgc_cmp, BoolTest::ge);
0N/A transform_later(needgc_bol);
4022N/A IfNode *needgc_iff = new (C) 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
4022N/A Node *needgc_true = new (C) 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
4022N/A Node *needgc_false = new (C) 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 =
4022N/A new (C) 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 =
4022N/A new (C) 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);
4022N/A Node *contention_check = new (C) BoolNode(store_eden_top, BoolTest::ne);
0N/A transform_later(contention_check);
4022N/A store_eden_top = new (C) 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.
4022N/A IfNode *contention_iff = new (C) IfNode (needgc_false, contention_check, PROB_MIN, COUNT_UNKNOWN);
0N/A transform_later(contention_iff);
4022N/A Node *contention_true = new (C) 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!
4022N/A Node *contention_false = new (C) 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
4022N/A Node* thread = new (C) 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
4022N/A Node* alloc_size = new (C) ConvI2LNode(size_in_bytes);
1988N/A transform_later(alloc_size);
1988N/A#endif
4022N/A Node* new_alloc_bytes = new (C) 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
3043N/A InitializeNode* init = alloc->initialization();
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
3043N/A // If initialization is performed by an array copy, any required
3043N/A // MemBarStoreStore was already added. If the object does not
3043N/A // escape no need for a MemBarStoreStore. Otherwise we need a
3043N/A // MemBarStoreStore so that stores that initialize this object
3043N/A // can't be reordered with a subsequent store that makes this
3043N/A // object accessible by other threads.
3043N/A if (init == NULL || (!init->is_complete_with_arraycopy() && !init->does_not_escape())) {
3043N/A if (init == NULL || init->req() < InitializeNode::RawStores) {
3043N/A // No InitializeNode or no stores captured by zeroing
3043N/A // elimination. Simply add the MemBarStoreStore after object
3043N/A // initialization.
4347N/A MemBarNode* mb = MemBarNode::make(C, Op_MemBarStoreStore, Compile::AliasIdxBot);
3043N/A transform_later(mb);
3043N/A
3043N/A mb->init_req(TypeFunc::Memory, fast_oop_rawmem);
3043N/A mb->init_req(TypeFunc::Control, fast_oop_ctrl);
4022N/A fast_oop_ctrl = new (C) ProjNode(mb,TypeFunc::Control);
3043N/A transform_later(fast_oop_ctrl);
4022N/A fast_oop_rawmem = new (C) ProjNode(mb,TypeFunc::Memory);
3043N/A transform_later(fast_oop_rawmem);
3043N/A } else {
3043N/A // Add the MemBarStoreStore after the InitializeNode so that
3043N/A // all stores performing the initialization that were moved
3043N/A // before the InitializeNode happen before the storestore
3043N/A // barrier.
3043N/A
3043N/A Node* init_ctrl = init->proj_out(TypeFunc::Control);
3043N/A Node* init_mem = init->proj_out(TypeFunc::Memory);
3043N/A
3043N/A MemBarNode* mb = MemBarNode::make(C, Op_MemBarStoreStore, Compile::AliasIdxBot);
3043N/A transform_later(mb);
3043N/A
4022N/A Node* ctrl = new (C) ProjNode(init,TypeFunc::Control);
3043N/A transform_later(ctrl);
4022N/A Node* mem = new (C) ProjNode(init,TypeFunc::Memory);
3043N/A transform_later(mem);
3043N/A
3043N/A // The MemBarStoreStore depends on control and memory coming
3043N/A // from the InitializeNode
3043N/A mb->init_req(TypeFunc::Memory, mem);
3043N/A mb->init_req(TypeFunc::Control, ctrl);
3043N/A
4022N/A ctrl = new (C) ProjNode(mb,TypeFunc::Control);
3043N/A transform_later(ctrl);
4022N/A mem = new (C) ProjNode(mb,TypeFunc::Memory);
3043N/A transform_later(mem);
3043N/A
3043N/A // All nodes that depended on the InitializeNode for control
3043N/A // and memory must now depend on the MemBarNode that itself
3043N/A // depends on the InitializeNode
3043N/A _igvn.replace_node(init_ctrl, ctrl);
3043N/A _igvn.replace_node(init_mem, mem);
3043N/A }
3043N/A }
3043N/A
780N/A if (C->env()->dtrace_extended_probes()) {
0N/A // Slow-path call
0N/A int size = TypeFunc::Parms + 2;
4022N/A CallLeafNode *call = new (C) CallLeafNode(OptoRuntime::dtrace_object_alloc_Type(),
4022N/A CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_object_alloc_base),
4022N/A "dtrace_object_alloc",
4022N/A TypeRawPtr::BOTTOM);
0N/A
0N/A // Get base of thread-local storage area
4022N/A Node* thread = new (C) 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);
4022N/A fast_oop_ctrl = new (C) ProjNode(call,TypeFunc::Control);
0N/A transform_later(fast_oop_ctrl);
4022N/A fast_oop_rawmem = new (C) 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;
3047N/A result_phi_i_o = i_o; // Rename it to use in the following code.
0N/A }
0N/A
0N/A // Generate slow-path call
4022N/A CallNode *call = new (C) CallStaticJavaNode(slow_call_type, slow_call_address,
4022N/A OptoRuntime::stub_name(slow_call_address),
4022N/A alloc->jvms()->bci(),
4022N/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.
3047N/A } else {
3047N/A // Hook i_o projection to avoid its elimination during allocation
3047N/A // replacement (when only a slow call is generated).
3047N/A call->set_req(TypeFunc::I_O, result_phi_i_o);
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
3047N/A // An allocate node has separate memory projections for the uses on
3047N/A // the control and i_o paths. Replace the control memory projection with
3047N/A // result_phi_rawmem (unless we are only generating a slow call when
3047N/A // both memory projections are combined)
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);
3811N/A _igvn.rehash_node_delayed(use);
0N/A imax -= replace_input(use, _memproj_fallthrough, result_phi_rawmem);
0N/A // back up iterator
0N/A --i;
0N/A }
0N/A }
3047N/A // Now change uses of _memproj_catchall to use _memproj_fallthrough and delete
3047N/A // _memproj_catchall so we end up with a call that has only 1 memory projection.
0N/A if (_memproj_catchall != NULL ) {
0N/A if (_memproj_fallthrough == NULL) {
4022N/A _memproj_fallthrough = new (C) 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);
3811N/A _igvn.rehash_node_delayed(use);
0N/A imax -= replace_input(use, _memproj_catchall, _memproj_fallthrough);
0N/A // back up iterator
0N/A --i;
0N/A }
3047N/A assert(_memproj_catchall->outcnt() == 0, "all uses must be deleted");
3047N/A _igvn.remove_dead_node(_memproj_catchall);
0N/A }
0N/A
3047N/A // An allocate node has separate i_o projections for the uses on the control
3047N/A // and i_o paths. Always replace the control i_o projection with result i_o
3047N/A // otherwise incoming i_o become dead when only a slow call is generated
3047N/A // (it is different from memory projections where both projections are
3047N/A // combined in such case).
3047N/A if (_ioproj_fallthrough != NULL) {
0N/A for (DUIterator_Fast imax, i = _ioproj_fallthrough->fast_outs(imax); i < imax; i++) {
0N/A Node *use = _ioproj_fallthrough->fast_out(i);
3811N/A _igvn.rehash_node_delayed(use);
0N/A imax -= replace_input(use, _ioproj_fallthrough, result_phi_i_o);
0N/A // back up iterator
0N/A --i;
0N/A }
0N/A }
3047N/A // Now change uses of _ioproj_catchall to use _ioproj_fallthrough and delete
3047N/A // _ioproj_catchall so we end up with a call that has only 1 i_o projection.
0N/A if (_ioproj_catchall != NULL ) {
3047N/A if (_ioproj_fallthrough == NULL) {
4022N/A _ioproj_fallthrough = new (C) ProjNode(call, TypeFunc::I_O);
3047N/A transform_later(_ioproj_fallthrough);
3047N/A }
0N/A for (DUIterator_Fast imax, i = _ioproj_catchall->fast_outs(imax); i < imax; i++) {
0N/A Node *use = _ioproj_catchall->fast_out(i);
3811N/A _igvn.rehash_node_delayed(use);
0N/A imax -= replace_input(use, _ioproj_catchall, _ioproj_fallthrough);
0N/A // back up iterator
0N/A --i;
0N/A }
3047N/A assert(_ioproj_catchall->outcnt() == 0, "all uses must be deleted");
3047N/A _igvn.remove_dead_node(_ioproj_catchall);
0N/A }
0N/A
0N/A // if we generated only a slow call, we are done
3047N/A if (always_slow) {
3047N/A // Now we can unhook i_o.
3049N/A if (result_phi_i_o->outcnt() > 1) {
3049N/A call->set_req(TypeFunc::I_O, top());
3049N/A } else {
3049N/A assert(result_phi_i_o->unique_ctrl_out() == call, "");
3049N/A // Case of new array with negative size known during compilation.
3049N/A // AllocateArrayNode::Ideal() optimization disconnect unreachable
3049N/A // following code since call to runtime will throw exception.
3049N/A // As result there will be no users of i_o after the call.
3049N/A // Leave i_o attached to this call to avoid problems in preceding graph.
3049N/A }
0N/A return;
3047N/A }
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
4022N/A Node *pf_region = new (C) RegionNode(3);
4022N/A Node *pf_phi_rawmem = new (C) PhiNode( pf_region, Type::MEMORY,
0N/A TypeRawPtr::BOTTOM );
0N/A // I/O is used for Prefetch
4022N/A Node *pf_phi_abio = new (C) PhiNode( pf_region, Type::ABIO );
0N/A
4022N/A Node *thread = new (C) ThreadLocalNode();
0N/A transform_later(thread);
0N/A
4022N/A Node *eden_pf_adr = new (C) 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
4022N/A Node *old_pf_wm = new (C) 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
4022N/A Node *need_pf_cmp = new (C) CmpPNode( new_eden_top, old_pf_wm );
0N/A transform_later(need_pf_cmp);
4022N/A Node *need_pf_bol = new (C) BoolNode( need_pf_cmp, BoolTest::ge );
0N/A transform_later(need_pf_bol);
4022N/A IfNode *need_pf_iff = new (C) 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
4022N/A Node *need_pf_true = new (C) IfTrueNode( need_pf_iff );
0N/A transform_later(need_pf_true);
0N/A
4022N/A Node *need_pf_false = new (C) IfFalseNode( need_pf_iff );
0N/A transform_later(need_pf_false);
0N/A
4022N/A Node *new_pf_wmt = new (C) 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
4022N/A Node *store_new_wmt = new (C) 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++ ) {
4022N/A prefetch_adr = new (C) AddPNode( old_pf_wm, new_pf_wmt,
0N/A _igvn.MakeConX(distance) );
0N/A transform_later(prefetch_adr);
4022N/A prefetch = new (C) 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.
4022N/A Node *pf_region = new (C) RegionNode(3);
4022N/A Node *pf_phi_rawmem = new (C) PhiNode( pf_region, Type::MEMORY,
4022N/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.
4022N/A Node *cache_adr = new (C) AddPNode(old_eden_top, old_eden_top,
1367N/A _igvn.MakeConX(distance));
1367N/A transform_later(cache_adr);
4022N/A cache_adr = new (C) CastP2XNode(needgc_false, cache_adr);
1367N/A transform_later(cache_adr);
1367N/A Node* mask = _igvn.MakeConX(~(intptr_t)(step_size-1));
4022N/A cache_adr = new (C) AndXNode(cache_adr, mask);
1367N/A transform_later(cache_adr);
4022N/A cache_adr = new (C) CastX2PNode(cache_adr);
1367N/A transform_later(cache_adr);
1367N/A
1367N/A // Prefetch
4022N/A Node *prefetch = new (C) 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++ ) {
4022N/A prefetch_adr = new (C) AddPNode( cache_adr, cache_adr,
1367N/A _igvn.MakeConX(distance) );
1367N/A transform_later(prefetch_adr);
4022N/A prefetch = new (C) 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++ ) {
4022N/A prefetch_adr = new (C) AddPNode( old_eden_top, new_eden_top,
0N/A _igvn.MakeConX(distance) );
0N/A transform_later(prefetch_adr);
4022N/A prefetch = new (C) 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(),
2797 Error!

 

There was an error!

null

java.lang.NullPointerException