escape.cpp revision 1841
0N/A/*
1472N/A * Copyright (c) 2005, 2009, 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
0N/A#include "incls/_precompiled.incl"
0N/A#include "incls/_escape.cpp.incl"
0N/A
0N/Avoid PointsToNode::add_edge(uint targIdx, PointsToNode::EdgeType et) {
0N/A uint v = (targIdx << EdgeShift) + ((uint) et);
0N/A if (_edges == NULL) {
0N/A Arena *a = Compile::current()->comp_arena();
0N/A _edges = new(a) GrowableArray<uint>(a, INITIAL_EDGE_COUNT, 0, 0);
0N/A }
0N/A _edges->append_if_missing(v);
0N/A}
0N/A
0N/Avoid PointsToNode::remove_edge(uint targIdx, PointsToNode::EdgeType et) {
0N/A uint v = (targIdx << EdgeShift) + ((uint) et);
0N/A
0N/A _edges->remove(v);
0N/A}
0N/A
0N/A#ifndef PRODUCT
77N/Astatic const char *node_type_names[] = {
0N/A "UnknownType",
0N/A "JavaObject",
0N/A "LocalVar",
0N/A "Field"
0N/A};
0N/A
77N/Astatic const char *esc_names[] = {
0N/A "UnknownEscape",
65N/A "NoEscape",
65N/A "ArgEscape",
65N/A "GlobalEscape"
0N/A};
0N/A
77N/Astatic const char *edge_type_suffix[] = {
0N/A "?", // UnknownEdge
0N/A "P", // PointsToEdge
0N/A "D", // DeferredEdge
0N/A "F" // FieldEdge
0N/A};
0N/A
253N/Avoid PointsToNode::dump(bool print_state) const {
0N/A NodeType nt = node_type();
253N/A tty->print("%s ", node_type_names[(int) nt]);
253N/A if (print_state) {
253N/A EscapeState es = escape_state();
253N/A tty->print("%s %s ", esc_names[(int) es], _scalar_replaceable ? "":"NSR");
253N/A }
253N/A tty->print("[[");
0N/A for (uint i = 0; i < edge_count(); i++) {
0N/A tty->print(" %d%s", edge_target(i), edge_type_suffix[(int) edge_type(i)]);
0N/A }
0N/A tty->print("]] ");
0N/A if (_node == NULL)
0N/A tty->print_cr("<null>");
0N/A else
0N/A _node->dump();
0N/A}
0N/A#endif
0N/A
1554N/AConnectionGraph::ConnectionGraph(Compile * C, PhaseIterGVN *igvn) :
244N/A _nodes(C->comp_arena(), C->unique(), C->unique(), PointsToNode()),
244N/A _processed(C->comp_arena()),
244N/A _collecting(true),
1841N/A _progress(false),
244N/A _compile(C),
1554N/A _igvn(igvn),
244N/A _node_map(C->comp_arena()) {
244N/A
253N/A _phantom_object = C->top()->_idx,
253N/A add_node(C->top(), PointsToNode::JavaObject, PointsToNode::GlobalEscape,true);
253N/A
253N/A // Add ConP(#NULL) and ConN(#NULL) nodes.
253N/A Node* oop_null = igvn->zerocon(T_OBJECT);
253N/A _oop_null = oop_null->_idx;
253N/A assert(_oop_null < C->unique(), "should be created already");
253N/A add_node(oop_null, PointsToNode::JavaObject, PointsToNode::NoEscape, true);
253N/A
253N/A if (UseCompressedOops) {
253N/A Node* noop_null = igvn->zerocon(T_NARROWOOP);
253N/A _noop_null = noop_null->_idx;
253N/A assert(_noop_null < C->unique(), "should be created already");
253N/A add_node(noop_null, PointsToNode::JavaObject, PointsToNode::NoEscape, true);
253N/A }
0N/A}
0N/A
0N/Avoid ConnectionGraph::add_pointsto_edge(uint from_i, uint to_i) {
0N/A PointsToNode *f = ptnode_adr(from_i);
0N/A PointsToNode *t = ptnode_adr(to_i);
0N/A
0N/A assert(f->node_type() != PointsToNode::UnknownType && t->node_type() != PointsToNode::UnknownType, "node types must be set");
0N/A assert(f->node_type() == PointsToNode::LocalVar || f->node_type() == PointsToNode::Field, "invalid source of PointsTo edge");
0N/A assert(t->node_type() == PointsToNode::JavaObject, "invalid destination of PointsTo edge");
1841N/A add_edge(f, to_i, PointsToNode::PointsToEdge);
0N/A}
0N/A
0N/Avoid ConnectionGraph::add_deferred_edge(uint from_i, uint to_i) {
0N/A PointsToNode *f = ptnode_adr(from_i);
0N/A PointsToNode *t = ptnode_adr(to_i);
0N/A
0N/A assert(f->node_type() != PointsToNode::UnknownType && t->node_type() != PointsToNode::UnknownType, "node types must be set");
0N/A assert(f->node_type() == PointsToNode::LocalVar || f->node_type() == PointsToNode::Field, "invalid source of Deferred edge");
0N/A assert(t->node_type() == PointsToNode::LocalVar || t->node_type() == PointsToNode::Field, "invalid destination of Deferred edge");
0N/A // don't add a self-referential edge, this can occur during removal of
0N/A // deferred edges
0N/A if (from_i != to_i)
1841N/A add_edge(f, to_i, PointsToNode::DeferredEdge);
0N/A}
0N/A
65N/Aint ConnectionGraph::address_offset(Node* adr, PhaseTransform *phase) {
65N/A const Type *adr_type = phase->type(adr);
65N/A if (adr->is_AddP() && adr_type->isa_oopptr() == NULL &&
65N/A adr->in(AddPNode::Address)->is_Proj() &&
65N/A adr->in(AddPNode::Address)->in(0)->is_Allocate()) {
65N/A // We are computing a raw address for a store captured by an Initialize
65N/A // compute an appropriate address type. AddP cases #3 and #5 (see below).
65N/A int offs = (int)phase->find_intptr_t_con(adr->in(AddPNode::Offset), Type::OffsetBot);
65N/A assert(offs != Type::OffsetBot ||
65N/A adr->in(AddPNode::Address)->in(0)->is_AllocateArray(),
65N/A "offset must be a constant or it is initialization of array");
65N/A return offs;
65N/A }
65N/A const TypePtr *t_ptr = adr_type->isa_ptr();
0N/A assert(t_ptr != NULL, "must be a pointer type");
0N/A return t_ptr->offset();
0N/A}
0N/A
0N/Avoid ConnectionGraph::add_field_edge(uint from_i, uint to_i, int offset) {
0N/A PointsToNode *f = ptnode_adr(from_i);
0N/A PointsToNode *t = ptnode_adr(to_i);
0N/A
0N/A assert(f->node_type() != PointsToNode::UnknownType && t->node_type() != PointsToNode::UnknownType, "node types must be set");
0N/A assert(f->node_type() == PointsToNode::JavaObject, "invalid destination of Field edge");
0N/A assert(t->node_type() == PointsToNode::Field, "invalid destination of Field edge");
0N/A assert (t->offset() == -1 || t->offset() == offset, "conflicting field offsets");
0N/A t->set_offset(offset);
0N/A
1841N/A add_edge(f, to_i, PointsToNode::FieldEdge);
0N/A}
0N/A
0N/Avoid ConnectionGraph::set_escape_state(uint ni, PointsToNode::EscapeState es) {
0N/A PointsToNode *npt = ptnode_adr(ni);
0N/A PointsToNode::EscapeState old_es = npt->escape_state();
0N/A if (es > old_es)
0N/A npt->set_escape_state(es);
0N/A}
0N/A
65N/Avoid ConnectionGraph::add_node(Node *n, PointsToNode::NodeType nt,
65N/A PointsToNode::EscapeState es, bool done) {
65N/A PointsToNode* ptadr = ptnode_adr(n->_idx);
65N/A ptadr->_node = n;
65N/A ptadr->set_node_type(nt);
65N/A
65N/A // inline set_escape_state(idx, es);
65N/A PointsToNode::EscapeState old_es = ptadr->escape_state();
65N/A if (es > old_es)
65N/A ptadr->set_escape_state(es);
65N/A
65N/A if (done)
65N/A _processed.set(n->_idx);
65N/A}
65N/A
1554N/APointsToNode::EscapeState ConnectionGraph::escape_state(Node *n) {
0N/A uint idx = n->_idx;
0N/A PointsToNode::EscapeState es;
0N/A
65N/A // If we are still collecting or there were no non-escaping allocations
65N/A // we don't know the answer yet
244N/A if (_collecting)
0N/A return PointsToNode::UnknownEscape;
0N/A
0N/A // if the node was created after the escape computation, return
0N/A // UnknownEscape
244N/A if (idx >= nodes_size())
0N/A return PointsToNode::UnknownEscape;
0N/A
244N/A es = ptnode_adr(idx)->escape_state();
0N/A
0N/A // if we have already computed a value, return it
460N/A if (es != PointsToNode::UnknownEscape &&
460N/A ptnode_adr(idx)->node_type() == PointsToNode::JavaObject)
0N/A return es;
0N/A
244N/A // PointsTo() calls n->uncast() which can return a new ideal node.
244N/A if (n->uncast()->_idx >= nodes_size())
244N/A return PointsToNode::UnknownEscape;
244N/A
1554N/A PointsToNode::EscapeState orig_es = es;
1554N/A
0N/A // compute max escape state of anything this node could point to
0N/A VectorSet ptset(Thread::current()->resource_area());
1554N/A PointsTo(ptset, n);
65N/A for(VectorSetI i(&ptset); i.test() && es != PointsToNode::GlobalEscape; ++i) {
0N/A uint pt = i.elem;
244N/A PointsToNode::EscapeState pes = ptnode_adr(pt)->escape_state();
0N/A if (pes > es)
0N/A es = pes;
0N/A }
1554N/A if (orig_es != es) {
1554N/A // cache the computed escape state
1554N/A assert(es != PointsToNode::UnknownEscape, "should have computed an escape state");
1554N/A ptnode_adr(idx)->set_escape_state(es);
1554N/A } // orig_es could be PointsToNode::UnknownEscape
0N/A return es;
0N/A}
0N/A
1554N/Avoid ConnectionGraph::PointsTo(VectorSet &ptset, Node * n) {
0N/A VectorSet visited(Thread::current()->resource_area());
0N/A GrowableArray<uint> worklist;
0N/A
124N/A#ifdef ASSERT
124N/A Node *orig_n = n;
124N/A#endif
124N/A
65N/A n = n->uncast();
244N/A PointsToNode* npt = ptnode_adr(n->_idx);
0N/A
0N/A // If we have a JavaObject, return just that object
244N/A if (npt->node_type() == PointsToNode::JavaObject) {
0N/A ptset.set(n->_idx);
0N/A return;
0N/A }
124N/A#ifdef ASSERT
244N/A if (npt->_node == NULL) {
124N/A if (orig_n != n)
124N/A orig_n->dump();
124N/A n->dump();
244N/A assert(npt->_node != NULL, "unregistered node");
124N/A }
124N/A#endif
0N/A worklist.push(n->_idx);
0N/A while(worklist.length() > 0) {
0N/A int ni = worklist.pop();
244N/A if (visited.test_set(ni))
244N/A continue;
244N/A
244N/A PointsToNode* pn = ptnode_adr(ni);
244N/A // ensure that all inputs of a Phi have been processed
244N/A assert(!_collecting || !pn->_node->is_Phi() || _processed.test(ni),"");
0N/A
244N/A int edges_processed = 0;
244N/A uint e_cnt = pn->edge_count();
244N/A for (uint e = 0; e < e_cnt; e++) {
244N/A uint etgt = pn->edge_target(e);
244N/A PointsToNode::EdgeType et = pn->edge_type(e);
244N/A if (et == PointsToNode::PointsToEdge) {
244N/A ptset.set(etgt);
244N/A edges_processed++;
244N/A } else if (et == PointsToNode::DeferredEdge) {
244N/A worklist.push(etgt);
244N/A edges_processed++;
244N/A } else {
244N/A assert(false,"neither PointsToEdge or DeferredEdge");
0N/A }
244N/A }
244N/A if (edges_processed == 0) {
244N/A // no deferred or pointsto edges found. Assume the value was set
244N/A // outside this method. Add the phantom object to the pointsto set.
244N/A ptset.set(_phantom_object);
0N/A }
0N/A }
0N/A}
0N/A
101N/Avoid ConnectionGraph::remove_deferred(uint ni, GrowableArray<uint>* deferred_edges, VectorSet* visited) {
101N/A // This method is most expensive during ConnectionGraph construction.
101N/A // Reuse vectorSet and an additional growable array for deferred edges.
101N/A deferred_edges->clear();
101N/A visited->Clear();
0N/A
244N/A visited->set(ni);
0N/A PointsToNode *ptn = ptnode_adr(ni);
0N/A
101N/A // Mark current edges as visited and move deferred edges to separate array.
244N/A for (uint i = 0; i < ptn->edge_count(); ) {
65N/A uint t = ptn->edge_target(i);
101N/A#ifdef ASSERT
101N/A assert(!visited->test_set(t), "expecting no duplications");
101N/A#else
101N/A visited->set(t);
101N/A#endif
101N/A if (ptn->edge_type(i) == PointsToNode::DeferredEdge) {
0N/A ptn->remove_edge(t, PointsToNode::DeferredEdge);
101N/A deferred_edges->append(t);
124N/A } else {
124N/A i++;
101N/A }
101N/A }
101N/A for (int next = 0; next < deferred_edges->length(); ++next) {
101N/A uint t = deferred_edges->at(next);
101N/A PointsToNode *ptt = ptnode_adr(t);
244N/A uint e_cnt = ptt->edge_count();
244N/A for (uint e = 0; e < e_cnt; e++) {
244N/A uint etgt = ptt->edge_target(e);
244N/A if (visited->test_set(etgt))
101N/A continue;
244N/A
244N/A PointsToNode::EdgeType et = ptt->edge_type(e);
244N/A if (et == PointsToNode::PointsToEdge) {
244N/A add_pointsto_edge(ni, etgt);
244N/A if(etgt == _phantom_object) {
244N/A // Special case - field set outside (globally escaping).
244N/A ptn->set_escape_state(PointsToNode::GlobalEscape);
244N/A }
244N/A } else if (et == PointsToNode::DeferredEdge) {
244N/A deferred_edges->append(etgt);
244N/A } else {
244N/A assert(false,"invalid connection graph");
0N/A }
0N/A }
0N/A }
0N/A}
0N/A
0N/A
0N/A// Add an edge to node given by "to_i" from any field of adr_i whose offset
0N/A// matches "offset" A deferred edge is added if to_i is a LocalVar, and
0N/A// a pointsto edge is added if it is a JavaObject
0N/A
0N/Avoid ConnectionGraph::add_edge_from_fields(uint adr_i, uint to_i, int offs) {
244N/A PointsToNode* an = ptnode_adr(adr_i);
244N/A PointsToNode* to = ptnode_adr(to_i);
244N/A bool deferred = (to->node_type() == PointsToNode::LocalVar);
0N/A
244N/A for (uint fe = 0; fe < an->edge_count(); fe++) {
244N/A assert(an->edge_type(fe) == PointsToNode::FieldEdge, "expecting a field edge");
244N/A int fi = an->edge_target(fe);
244N/A PointsToNode* pf = ptnode_adr(fi);
244N/A int po = pf->offset();
0N/A if (po == offs || po == Type::OffsetBot || offs == Type::OffsetBot) {
0N/A if (deferred)
0N/A add_deferred_edge(fi, to_i);
0N/A else
0N/A add_pointsto_edge(fi, to_i);
0N/A }
0N/A }
0N/A}
0N/A
65N/A// Add a deferred edge from node given by "from_i" to any field of adr_i
65N/A// whose offset matches "offset".
0N/Avoid ConnectionGraph::add_deferred_edge_to_fields(uint from_i, uint adr_i, int offs) {
244N/A PointsToNode* an = ptnode_adr(adr_i);
244N/A for (uint fe = 0; fe < an->edge_count(); fe++) {
244N/A assert(an->edge_type(fe) == PointsToNode::FieldEdge, "expecting a field edge");
244N/A int fi = an->edge_target(fe);
244N/A PointsToNode* pf = ptnode_adr(fi);
244N/A int po = pf->offset();
244N/A if (pf->edge_count() == 0) {
0N/A // we have not seen any stores to this field, assume it was set outside this method
0N/A add_pointsto_edge(fi, _phantom_object);
0N/A }
0N/A if (po == offs || po == Type::OffsetBot || offs == Type::OffsetBot) {
0N/A add_deferred_edge(from_i, fi);
0N/A }
0N/A }
0N/A}
0N/A
65N/A// Helper functions
65N/A
65N/Astatic Node* get_addp_base(Node *addp) {
65N/A assert(addp->is_AddP(), "must be AddP");
65N/A //
65N/A // AddP cases for Base and Address inputs:
65N/A // case #1. Direct object's field reference:
65N/A // Allocate
65N/A // |
65N/A // Proj #5 ( oop result )
65N/A // |
65N/A // CheckCastPP (cast to instance type)
65N/A // | |
65N/A // AddP ( base == address )
65N/A //
65N/A // case #2. Indirect object's field reference:
65N/A // Phi
65N/A // |
65N/A // CastPP (cast to instance type)
65N/A // | |
65N/A // AddP ( base == address )
65N/A //
65N/A // case #3. Raw object's field reference for Initialize node:
65N/A // Allocate
65N/A // |
65N/A // Proj #5 ( oop result )
65N/A // top |
65N/A // \ |
65N/A // AddP ( base == top )
65N/A //
65N/A // case #4. Array's element reference:
65N/A // {CheckCastPP | CastPP}
65N/A // | | |
65N/A // | AddP ( array's element offset )
65N/A // | |
65N/A // AddP ( array's offset )
65N/A //
65N/A // case #5. Raw object's field reference for arraycopy stub call:
65N/A // The inline_native_clone() case when the arraycopy stub is called
65N/A // after the allocation before Initialize and CheckCastPP nodes.
65N/A // Allocate
65N/A // |
65N/A // Proj #5 ( oop result )
65N/A // | |
65N/A // AddP ( base == address )
65N/A //
77N/A // case #6. Constant Pool, ThreadLocal, CastX2P or
77N/A // Raw object's field reference:
77N/A // {ConP, ThreadLocal, CastX2P, raw Load}
65N/A // top |
65N/A // \ |
65N/A // AddP ( base == top )
65N/A //
77N/A // case #7. Klass's field reference.
77N/A // LoadKlass
77N/A // | |
77N/A // AddP ( base == address )
77N/A //
164N/A // case #8. narrow Klass's field reference.
164N/A // LoadNKlass
164N/A // |
164N/A // DecodeN
164N/A // | |
164N/A // AddP ( base == address )
164N/A //
65N/A Node *base = addp->in(AddPNode::Base)->uncast();
65N/A if (base->is_top()) { // The AddP case #3 and #6.
65N/A base = addp->in(AddPNode::Address)->uncast();
957N/A while (base->is_AddP()) {
957N/A // Case #6 (unsafe access) may have several chained AddP nodes.
957N/A assert(base->in(AddPNode::Base)->is_top(), "expected unsafe access address only");
957N/A base = base->in(AddPNode::Address)->uncast();
957N/A }
65N/A assert(base->Opcode() == Op_ConP || base->Opcode() == Op_ThreadLocal ||
168N/A base->Opcode() == Op_CastX2P || base->is_DecodeN() ||
77N/A (base->is_Mem() && base->bottom_type() == TypeRawPtr::NOTNULL) ||
77N/A (base->is_Proj() && base->in(0)->is_Allocate()), "sanity");
0N/A }
65N/A return base;
65N/A}
65N/A
65N/Astatic Node* find_second_addp(Node* addp, Node* n) {
65N/A assert(addp->is_AddP() && addp->outcnt() > 0, "Don't process dead nodes");
65N/A
65N/A Node* addp2 = addp->raw_out(0);
65N/A if (addp->outcnt() == 1 && addp2->is_AddP() &&
65N/A addp2->in(AddPNode::Base) == n &&
65N/A addp2->in(AddPNode::Address) == addp) {
65N/A
65N/A assert(addp->in(AddPNode::Base) == n, "expecting the same base");
65N/A //
65N/A // Find array's offset to push it on worklist first and
65N/A // as result process an array's element offset first (pushed second)
65N/A // to avoid CastPP for the array's offset.
65N/A // Otherwise the inserted CastPP (LocalVar) will point to what
65N/A // the AddP (Field) points to. Which would be wrong since
65N/A // the algorithm expects the CastPP has the same point as
65N/A // as AddP's base CheckCastPP (LocalVar).
65N/A //
65N/A // ArrayAllocation
65N/A // |
65N/A // CheckCastPP
65N/A // |
65N/A // memProj (from ArrayAllocation CheckCastPP)
65N/A // | ||
65N/A // | || Int (element index)
65N/A // | || | ConI (log(element size))
65N/A // | || | /
65N/A // | || LShift
65N/A // | || /
65N/A // | AddP (array's element offset)
65N/A // | |
65N/A // | | ConI (array's offset: #12(32-bits) or #24(64-bits))
65N/A // | / /
65N/A // AddP (array's offset)
65N/A // |
65N/A // Load/Store (memory operation on array's element)
65N/A //
65N/A return addp2;
65N/A }
65N/A return NULL;
0N/A}
0N/A
0N/A//
0N/A// Adjust the type and inputs of an AddP which computes the
0N/A// address of a field of an instance
0N/A//
293N/Abool ConnectionGraph::split_AddP(Node *addp, Node *base, PhaseGVN *igvn) {
65N/A const TypeOopPtr *base_t = igvn->type(base)->isa_oopptr();
223N/A assert(base_t != NULL && base_t->is_known_instance(), "expecting instance oopptr");
0N/A const TypeOopPtr *t = igvn->type(addp)->isa_oopptr();
65N/A if (t == NULL) {
65N/A // We are computing a raw address for a store captured by an Initialize
293N/A // compute an appropriate address type (cases #3 and #5).
65N/A assert(igvn->type(addp) == TypeRawPtr::NOTNULL, "must be raw pointer");
65N/A assert(addp->in(AddPNode::Address)->is_Proj(), "base of raw address must be result projection from allocation");
306N/A intptr_t offs = (int)igvn->find_intptr_t_con(addp->in(AddPNode::Offset), Type::OffsetBot);
65N/A assert(offs != Type::OffsetBot, "offset must be a constant");
65N/A t = base_t->add_offset(offs)->is_oopptr();
65N/A }
223N/A int inst_id = base_t->instance_id();
223N/A assert(!t->is_known_instance() || t->instance_id() == inst_id,
0N/A "old type must be non-instance or match new type");
293N/A
293N/A // The type 't' could be subclass of 'base_t'.
293N/A // As result t->offset() could be large then base_t's size and it will
293N/A // cause the failure in add_offset() with narrow oops since TypeOopPtr()
293N/A // constructor verifies correctness of the offset.
293N/A //
605N/A // It could happened on subclass's branch (from the type profiling
293N/A // inlining) which was not eliminated during parsing since the exactness
293N/A // of the allocation type was not propagated to the subclass type check.
293N/A //
988N/A // Or the type 't' could be not related to 'base_t' at all.
988N/A // It could happened when CHA type is different from MDO type on a dead path
988N/A // (for example, from instanceof check) which is not collapsed during parsing.
988N/A //
293N/A // Do nothing for such AddP node and don't process its users since
293N/A // this code branch will go away.
293N/A //
293N/A if (!t->is_known_instance() &&
988N/A !base_t->klass()->is_subtype_of(t->klass())) {
293N/A return false; // bail out
293N/A }
293N/A
0N/A const TypeOopPtr *tinst = base_t->add_offset(t->offset())->is_oopptr();
1062N/A // Do NOT remove the next line: ensure a new alias index is allocated
1062N/A // for the instance type. Note: C++ will not remove it since the call
1062N/A // has side effect.
0N/A int alias_idx = _compile->get_alias_index(tinst);
0N/A igvn->set_type(addp, tinst);
0N/A // record the allocation in the node map
1101N/A assert(ptnode_adr(addp->_idx)->_node != NULL, "should be registered");
0N/A set_map(addp->_idx, get_map(base->_idx));
253N/A
253N/A // Set addp's Base and Address to 'base'.
253N/A Node *abase = addp->in(AddPNode::Base);
253N/A Node *adr = addp->in(AddPNode::Address);
253N/A if (adr->is_Proj() && adr->in(0)->is_Allocate() &&
253N/A adr->in(0)->_idx == (uint)inst_id) {
253N/A // Skip AddP cases #3 and #5.
253N/A } else {
253N/A assert(!abase->is_top(), "sanity"); // AddP case #3
253N/A if (abase != base) {
253N/A igvn->hash_delete(addp);
253N/A addp->set_req(AddPNode::Base, base);
253N/A if (abase == adr) {
253N/A addp->set_req(AddPNode::Address, base);
253N/A } else {
253N/A // AddP case #4 (adr is array's element offset AddP node)
253N/A#ifdef ASSERT
253N/A const TypeOopPtr *atype = igvn->type(adr)->isa_oopptr();
253N/A assert(adr->is_AddP() && atype != NULL &&
253N/A atype->instance_id() == inst_id, "array's element offset should be processed first");
253N/A#endif
253N/A }
253N/A igvn->hash_insert(addp);
0N/A }
0N/A }
65N/A // Put on IGVN worklist since at least addp's type was changed above.
65N/A record_for_optimizer(addp);
293N/A return true;
0N/A}
0N/A
0N/A//
0N/A// Create a new version of orig_phi if necessary. Returns either the newly
0N/A// created phi or an existing phi. Sets create_new to indicate wheter a new
0N/A// phi was created. Cache the last newly created phi in the node map.
0N/A//
0N/APhiNode *ConnectionGraph::create_split_phi(PhiNode *orig_phi, int alias_idx, GrowableArray<PhiNode *> &orig_phi_worklist, PhaseGVN *igvn, bool &new_created) {
0N/A Compile *C = _compile;
0N/A new_created = false;
0N/A int phi_alias_idx = C->get_alias_index(orig_phi->adr_type());
0N/A // nothing to do if orig_phi is bottom memory or matches alias_idx
65N/A if (phi_alias_idx == alias_idx) {
0N/A return orig_phi;
0N/A }
851N/A // Have we recently created a Phi for this alias index?
0N/A PhiNode *result = get_map_phi(orig_phi->_idx);
0N/A if (result != NULL && C->get_alias_index(result->adr_type()) == alias_idx) {
0N/A return result;
0N/A }
851N/A // Previous check may fail when the same wide memory Phi was split into Phis
851N/A // for different memory slices. Search all Phis for this region.
851N/A if (result != NULL) {
851N/A Node* region = orig_phi->in(0);
851N/A for (DUIterator_Fast imax, i = region->fast_outs(imax); i < imax; i++) {
851N/A Node* phi = region->fast_out(i);
851N/A if (phi->is_Phi() &&
851N/A C->get_alias_index(phi->as_Phi()->adr_type()) == alias_idx) {
851N/A assert(phi->_idx >= nodes_size(), "only new Phi per instance memory slice");
851N/A return phi->as_Phi();
851N/A }
851N/A }
851N/A }
38N/A if ((int)C->unique() + 2*NodeLimitFudgeFactor > MaxNodeLimit) {
38N/A if (C->do_escape_analysis() == true && !C->failing()) {
38N/A // Retry compilation without escape analysis.
38N/A // If this is the first failure, the sentinel string will "stick"
38N/A // to the Compile object, and the C2Compiler will see it and retry.
38N/A C->record_failure(C2Compiler::retry_no_escape_analysis());
38N/A }
38N/A return NULL;
38N/A }
0N/A orig_phi_worklist.append_if_missing(orig_phi);
65N/A const TypePtr *atype = C->get_adr_type(alias_idx);
0N/A result = PhiNode::make(orig_phi->in(0), NULL, Type::MEMORY, atype);
851N/A C->copy_node_notes_to(result, orig_phi);
0N/A igvn->set_type(result, result->bottom_type());
0N/A record_for_optimizer(result);
1101N/A
1101N/A debug_only(Node* pn = ptnode_adr(orig_phi->_idx)->_node;)
1101N/A assert(pn == NULL || pn == orig_phi, "wrong node");
1101N/A set_map(orig_phi->_idx, result);
1101N/A ptnode_adr(orig_phi->_idx)->_node = orig_phi;
1101N/A
0N/A new_created = true;
0N/A return result;
0N/A}
0N/A
0N/A//
0N/A// Return a new version of Memory Phi "orig_phi" with the inputs having the
0N/A// specified alias index.
0N/A//
0N/APhiNode *ConnectionGraph::split_memory_phi(PhiNode *orig_phi, int alias_idx, GrowableArray<PhiNode *> &orig_phi_worklist, PhaseGVN *igvn) {
0N/A
0N/A assert(alias_idx != Compile::AliasIdxBot, "can't split out bottom memory");
0N/A Compile *C = _compile;
0N/A bool new_phi_created;
65N/A PhiNode *result = create_split_phi(orig_phi, alias_idx, orig_phi_worklist, igvn, new_phi_created);
0N/A if (!new_phi_created) {
0N/A return result;
0N/A }
0N/A
0N/A GrowableArray<PhiNode *> phi_list;
0N/A GrowableArray<uint> cur_input;
0N/A
0N/A PhiNode *phi = orig_phi;
0N/A uint idx = 1;
0N/A bool finished = false;
0N/A while(!finished) {
0N/A while (idx < phi->req()) {
65N/A Node *mem = find_inst_mem(phi->in(idx), alias_idx, orig_phi_worklist, igvn);
0N/A if (mem != NULL && mem->is_Phi()) {
65N/A PhiNode *newphi = create_split_phi(mem->as_Phi(), alias_idx, orig_phi_worklist, igvn, new_phi_created);
0N/A if (new_phi_created) {
0N/A // found an phi for which we created a new split, push current one on worklist and begin
0N/A // processing new one
0N/A phi_list.push(phi);
0N/A cur_input.push(idx);
0N/A phi = mem->as_Phi();
65N/A result = newphi;
0N/A idx = 1;
0N/A continue;
0N/A } else {
65N/A mem = newphi;
0N/A }
0N/A }
38N/A if (C->failing()) {
38N/A return NULL;
38N/A }
0N/A result->set_req(idx++, mem);
0N/A }
0N/A#ifdef ASSERT
0N/A // verify that the new Phi has an input for each input of the original
0N/A assert( phi->req() == result->req(), "must have same number of inputs.");
0N/A assert( result->in(0) != NULL && result->in(0) == phi->in(0), "regions must match");
65N/A#endif
65N/A // Check if all new phi's inputs have specified alias index.
65N/A // Otherwise use old phi.
0N/A for (uint i = 1; i < phi->req(); i++) {
65N/A Node* in = result->in(i);
65N/A assert((phi->in(i) == NULL) == (in == NULL), "inputs must correspond.");
0N/A }
0N/A // we have finished processing a Phi, see if there are any more to do
0N/A finished = (phi_list.length() == 0 );
0N/A if (!finished) {
0N/A phi = phi_list.pop();
0N/A idx = cur_input.pop();
65N/A PhiNode *prev_result = get_map_phi(phi->_idx);
65N/A prev_result->set_req(idx++, result);
65N/A result = prev_result;
0N/A }
0N/A }
0N/A return result;
0N/A}
0N/A
65N/A
65N/A//
65N/A// The next methods are derived from methods in MemNode.
65N/A//
1735N/Astatic Node *step_through_mergemem(MergeMemNode *mmem, int alias_idx, const TypeOopPtr *toop) {
65N/A Node *mem = mmem;
1735N/A // TypeOopPtr::NOTNULL+any is an OOP with unknown offset - generally
65N/A // means an array I have not precisely typed yet. Do not do any
65N/A // alias stuff with it any time soon.
1735N/A if( toop->base() != Type::AnyPtr &&
1735N/A !(toop->klass() != NULL &&
1735N/A toop->klass()->is_java_lang_Object() &&
1735N/A toop->offset() == Type::OffsetBot) ) {
65N/A mem = mmem->memory_at(alias_idx);
65N/A // Update input if it is progress over what we have now
65N/A }
65N/A return mem;
65N/A}
65N/A
65N/A//
1101N/A// Move memory users to their memory slices.
1101N/A//
1101N/Avoid ConnectionGraph::move_inst_mem(Node* n, GrowableArray<PhiNode *> &orig_phis, PhaseGVN *igvn) {
1101N/A Compile* C = _compile;
1101N/A
1101N/A const TypePtr* tp = igvn->type(n->in(MemNode::Address))->isa_ptr();
1101N/A assert(tp != NULL, "ptr type");
1101N/A int alias_idx = C->get_alias_index(tp);
1101N/A int general_idx = C->get_general_index(alias_idx);
1101N/A
1101N/A // Move users first
1101N/A for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
1101N/A Node* use = n->fast_out(i);
1101N/A if (use->is_MergeMem()) {
1101N/A MergeMemNode* mmem = use->as_MergeMem();
1101N/A assert(n == mmem->memory_at(alias_idx), "should be on instance memory slice");
1101N/A if (n != mmem->memory_at(general_idx) || alias_idx == general_idx) {
1101N/A continue; // Nothing to do
1101N/A }
1101N/A // Replace previous general reference to mem node.
1101N/A uint orig_uniq = C->unique();
1101N/A Node* m = find_inst_mem(n, general_idx, orig_phis, igvn);
1101N/A assert(orig_uniq == C->unique(), "no new nodes");
1101N/A mmem->set_memory_at(general_idx, m);
1101N/A --imax;
1101N/A --i;
1101N/A } else if (use->is_MemBar()) {
1101N/A assert(!use->is_Initialize(), "initializing stores should not be moved");
1101N/A if (use->req() > MemBarNode::Precedent &&
1101N/A use->in(MemBarNode::Precedent) == n) {
1101N/A // Don't move related membars.
1101N/A record_for_optimizer(use);
1101N/A continue;
1101N/A }
1101N/A tp = use->as_MemBar()->adr_type()->isa_ptr();
1101N/A if (tp != NULL && C->get_alias_index(tp) == alias_idx ||
1101N/A alias_idx == general_idx) {
1101N/A continue; // Nothing to do
1101N/A }
1101N/A // Move to general memory slice.
1101N/A uint orig_uniq = C->unique();
1101N/A Node* m = find_inst_mem(n, general_idx, orig_phis, igvn);
1101N/A assert(orig_uniq == C->unique(), "no new nodes");
1101N/A igvn->hash_delete(use);
1101N/A imax -= use->replace_edge(n, m);
1101N/A igvn->hash_insert(use);
1101N/A record_for_optimizer(use);
1101N/A --i;
1101N/A#ifdef ASSERT
1101N/A } else if (use->is_Mem()) {
1101N/A if (use->Opcode() == Op_StoreCM && use->in(MemNode::OopStore) == n) {
1101N/A // Don't move related cardmark.
1101N/A continue;
1101N/A }
1101N/A // Memory nodes should have new memory input.
1101N/A tp = igvn->type(use->in(MemNode::Address))->isa_ptr();
1101N/A assert(tp != NULL, "ptr type");
1101N/A int idx = C->get_alias_index(tp);
1101N/A assert(get_map(use->_idx) != NULL || idx == alias_idx,
1101N/A "Following memory nodes should have new memory input or be on the same memory slice");
1101N/A } else if (use->is_Phi()) {
1101N/A // Phi nodes should be split and moved already.
1101N/A tp = use->as_Phi()->adr_type()->isa_ptr();
1101N/A assert(tp != NULL, "ptr type");
1101N/A int idx = C->get_alias_index(tp);
1101N/A assert(idx == alias_idx, "Following Phi nodes should be on the same memory slice");
1101N/A } else {
1101N/A use->dump();
1101N/A assert(false, "should not be here");
1101N/A#endif
1101N/A }
1101N/A }
1101N/A}
1101N/A
1101N/A//
65N/A// Search memory chain of "mem" to find a MemNode whose address
65N/A// is the specified alias index.
65N/A//
65N/ANode* ConnectionGraph::find_inst_mem(Node *orig_mem, int alias_idx, GrowableArray<PhiNode *> &orig_phis, PhaseGVN *phase) {
65N/A if (orig_mem == NULL)
65N/A return orig_mem;
65N/A Compile* C = phase->C;
1735N/A const TypeOopPtr *toop = C->get_adr_type(alias_idx)->isa_oopptr();
1735N/A bool is_instance = (toop != NULL) && toop->is_known_instance();
253N/A Node *start_mem = C->start()->proj_out(TypeFunc::Memory);
65N/A Node *prev = NULL;
65N/A Node *result = orig_mem;
65N/A while (prev != result) {
65N/A prev = result;
253N/A if (result == start_mem)
605N/A break; // hit one of our sentinels
65N/A if (result->is_Mem()) {
253N/A const Type *at = phase->type(result->in(MemNode::Address));
65N/A if (at != Type::TOP) {
65N/A assert (at->isa_ptr() != NULL, "pointer type required.");
65N/A int idx = C->get_alias_index(at->is_ptr());
65N/A if (idx == alias_idx)
65N/A break;
65N/A }
253N/A result = result->in(MemNode::Memory);
65N/A }
65N/A if (!is_instance)
65N/A continue; // don't search further for non-instance types
65N/A // skip over a call which does not affect this memory slice
65N/A if (result->is_Proj() && result->as_Proj()->_con == TypeFunc::Memory) {
65N/A Node *proj_in = result->in(0);
1735N/A if (proj_in->is_Allocate() && proj_in->_idx == (uint)toop->instance_id()) {
605N/A break; // hit one of our sentinels
253N/A } else if (proj_in->is_Call()) {
65N/A CallNode *call = proj_in->as_Call();
1735N/A if (!call->may_modify(toop, phase)) {
65N/A result = call->in(TypeFunc::Memory);
65N/A }
65N/A } else if (proj_in->is_Initialize()) {
65N/A AllocateNode* alloc = proj_in->as_Initialize()->allocation();
65N/A // Stop if this is the initialization for the object instance which
65N/A // which contains this memory slice, otherwise skip over it.
1735N/A if (alloc == NULL || alloc->_idx != (uint)toop->instance_id()) {
65N/A result = proj_in->in(TypeFunc::Memory);
65N/A }
65N/A } else if (proj_in->is_MemBar()) {
65N/A result = proj_in->in(TypeFunc::Memory);
65N/A }
65N/A } else if (result->is_MergeMem()) {
65N/A MergeMemNode *mmem = result->as_MergeMem();
1735N/A result = step_through_mergemem(mmem, alias_idx, toop);
65N/A if (result == mmem->base_memory()) {
65N/A // Didn't find instance memory, search through general slice recursively.
65N/A result = mmem->memory_at(C->get_general_index(alias_idx));
65N/A result = find_inst_mem(result, alias_idx, orig_phis, phase);
65N/A if (C->failing()) {
65N/A return NULL;
65N/A }
65N/A mmem->set_memory_at(alias_idx, result);
65N/A }
65N/A } else if (result->is_Phi() &&
65N/A C->get_alias_index(result->as_Phi()->adr_type()) != alias_idx) {
65N/A Node *un = result->as_Phi()->unique_input(phase);
65N/A if (un != NULL) {
1101N/A orig_phis.append_if_missing(result->as_Phi());
65N/A result = un;
65N/A } else {
65N/A break;
65N/A }
1100N/A } else if (result->is_ClearArray()) {
1735N/A if (!ClearArrayNode::step_through(&result, (uint)toop->instance_id(), phase)) {
1100N/A // Can not bypass initialization of the instance
1100N/A // we are looking for.
1100N/A break;
1100N/A }
1100N/A // Otherwise skip it (the call updated 'result' value).
584N/A } else if (result->Opcode() == Op_SCMemProj) {
584N/A assert(result->in(0)->is_LoadStore(), "sanity");
584N/A const Type *at = phase->type(result->in(0)->in(MemNode::Address));
584N/A if (at != Type::TOP) {
584N/A assert (at->isa_ptr() != NULL, "pointer type required.");
584N/A int idx = C->get_alias_index(at->is_ptr());
584N/A assert(idx != alias_idx, "Object is not scalar replaceable if a LoadStore node access its field");
584N/A break;
584N/A }
584N/A result = result->in(0)->in(MemNode::Memory);
65N/A }
65N/A }
247N/A if (result->is_Phi()) {
65N/A PhiNode *mphi = result->as_Phi();
65N/A assert(mphi->bottom_type() == Type::MEMORY, "memory phi required");
65N/A const TypePtr *t = mphi->adr_type();
65N/A if (C->get_alias_index(t) != alias_idx) {
247N/A // Create a new Phi with the specified alias index type.
65N/A result = split_memory_phi(mphi, alias_idx, orig_phis, phase);
247N/A } else if (!is_instance) {
247N/A // Push all non-instance Phis on the orig_phis worklist to update inputs
247N/A // during Phase 4 if needed.
247N/A orig_phis.append_if_missing(mphi);
65N/A }
65N/A }
65N/A // the result is either MemNode, PhiNode, InitializeNode.
65N/A return result;
65N/A}
65N/A
0N/A//
0N/A// Convert the types of unescaped object to instance types where possible,
0N/A// propagate the new type information through the graph, and update memory
0N/A// edges and MergeMem inputs to reflect the new type.
0N/A//
0N/A// We start with allocations (and calls which may be allocations) on alloc_worklist.
0N/A// The processing is done in 4 phases:
0N/A//
0N/A// Phase 1: Process possible allocations from alloc_worklist. Create instance
0N/A// types for the CheckCastPP for allocations where possible.
0N/A// Propagate the the new types through users as follows:
0N/A// casts and Phi: push users on alloc_worklist
0N/A// AddP: cast Base and Address inputs to the instance type
0N/A// push any AddP users on alloc_worklist and push any memnode
0N/A// users onto memnode_worklist.
0N/A// Phase 2: Process MemNode's from memnode_worklist. compute new address type and
0N/A// search the Memory chain for a store with the appropriate type
0N/A// address type. If a Phi is found, create a new version with
605N/A// the appropriate memory slices from each of the Phi inputs.
0N/A// For stores, process the users as follows:
0N/A// MemNode: push on memnode_worklist
0N/A// MergeMem: push on mergemem_worklist
0N/A// Phase 3: Process MergeMem nodes from mergemem_worklist. Walk each memory slice
0N/A// moving the first node encountered of each instance type to the
0N/A// the input corresponding to its alias index.
0N/A// appropriate memory slice.
0N/A// Phase 4: Update the inputs of non-instance memory Phis and the Memory input of memnodes.
0N/A//
0N/A// In the following example, the CheckCastPP nodes are the cast of allocation
0N/A// results and the allocation of node 29 is unescaped and eligible to be an
0N/A// instance type.
0N/A//
0N/A// We start with:
0N/A//
0N/A// 7 Parm #memory
0N/A// 10 ConI "12"
0N/A// 19 CheckCastPP "Foo"
0N/A// 20 AddP _ 19 19 10 Foo+12 alias_index=4
0N/A// 29 CheckCastPP "Foo"
0N/A// 30 AddP _ 29 29 10 Foo+12 alias_index=4
0N/A//
0N/A// 40 StoreP 25 7 20 ... alias_index=4
0N/A// 50 StoreP 35 40 30 ... alias_index=4
0N/A// 60 StoreP 45 50 20 ... alias_index=4
0N/A// 70 LoadP _ 60 30 ... alias_index=4
0N/A// 80 Phi 75 50 60 Memory alias_index=4
0N/A// 90 LoadP _ 80 30 ... alias_index=4
0N/A// 100 LoadP _ 80 20 ... alias_index=4
0N/A//
0N/A//
0N/A// Phase 1 creates an instance type for node 29 assigning it an instance id of 24
0N/A// and creating a new alias index for node 30. This gives:
0N/A//
0N/A// 7 Parm #memory
0N/A// 10 ConI "12"
0N/A// 19 CheckCastPP "Foo"
0N/A// 20 AddP _ 19 19 10 Foo+12 alias_index=4
0N/A// 29 CheckCastPP "Foo" iid=24
0N/A// 30 AddP _ 29 29 10 Foo+12 alias_index=6 iid=24
0N/A//
0N/A// 40 StoreP 25 7 20 ... alias_index=4
0N/A// 50 StoreP 35 40 30 ... alias_index=6
0N/A// 60 StoreP 45 50 20 ... alias_index=4
0N/A// 70 LoadP _ 60 30 ... alias_index=6
0N/A// 80 Phi 75 50 60 Memory alias_index=4
0N/A// 90 LoadP _ 80 30 ... alias_index=6
0N/A// 100 LoadP _ 80 20 ... alias_index=4
0N/A//
0N/A// In phase 2, new memory inputs are computed for the loads and stores,
0N/A// And a new version of the phi is created. In phase 4, the inputs to
0N/A// node 80 are updated and then the memory nodes are updated with the
0N/A// values computed in phase 2. This results in:
0N/A//
0N/A// 7 Parm #memory
0N/A// 10 ConI "12"
0N/A// 19 CheckCastPP "Foo"
0N/A// 20 AddP _ 19 19 10 Foo+12 alias_index=4
0N/A// 29 CheckCastPP "Foo" iid=24
0N/A// 30 AddP _ 29 29 10 Foo+12 alias_index=6 iid=24
0N/A//
0N/A// 40 StoreP 25 7 20 ... alias_index=4
0N/A// 50 StoreP 35 7 30 ... alias_index=6
0N/A// 60 StoreP 45 40 20 ... alias_index=4
0N/A// 70 LoadP _ 50 30 ... alias_index=6
0N/A// 80 Phi 75 40 60 Memory alias_index=4
0N/A// 120 Phi 75 50 50 Memory alias_index=6
0N/A// 90 LoadP _ 120 30 ... alias_index=6
0N/A// 100 LoadP _ 80 20 ... alias_index=4
0N/A//
0N/Avoid ConnectionGraph::split_unique_types(GrowableArray<Node *> &alloc_worklist) {
0N/A GrowableArray<Node *> memnode_worklist;
0N/A GrowableArray<PhiNode *> orig_phis;
1101N/A
1841N/A PhaseIterGVN *igvn = _igvn;
0N/A uint new_index_start = (uint) _compile->num_alias_types();
1101N/A Arena* arena = Thread::current()->resource_area();
1101N/A VectorSet visited(arena);
1101N/A VectorSet ptset(arena);
0N/A
65N/A
65N/A // Phase 1: Process possible allocations from alloc_worklist.
65N/A // Create instance types for the CheckCastPP for allocations where possible.
244N/A //
244N/A // (Note: don't forget to change the order of the second AddP node on
244N/A // the alloc_worklist if the order of the worklist processing is changed,
244N/A // see the comment in find_second_addp().)
244N/A //
0N/A while (alloc_worklist.length() != 0) {
0N/A Node *n = alloc_worklist.pop();
0N/A uint ni = n->_idx;
65N/A const TypeOopPtr* tinst = NULL;
0N/A if (n->is_Call()) {
0N/A CallNode *alloc = n->as_Call();
0N/A // copy escape information to call node
244N/A PointsToNode* ptn = ptnode_adr(alloc->_idx);
1554N/A PointsToNode::EscapeState es = escape_state(alloc);
65N/A // We have an allocation or call which returns a Java object,
65N/A // see if it is unescaped.
65N/A if (es != PointsToNode::NoEscape || !ptn->_scalar_replaceable)
0N/A continue;
784N/A
784N/A // Find CheckCastPP for the allocate or for the return value of a call
784N/A n = alloc->result_cast();
784N/A if (n == NULL) { // No uses except Initialize node
784N/A if (alloc->is_Allocate()) {
784N/A // Set the scalar_replaceable flag for allocation
784N/A // so it could be eliminated if it has no uses.
784N/A alloc->as_Allocate()->_is_scalar_replaceable = true;
784N/A }
784N/A continue;
39N/A }
784N/A if (!n->is_CheckCastPP()) { // not unique CheckCastPP.
784N/A assert(!alloc->is_Allocate(), "allocation should have unique type");
65N/A continue;
784N/A }
784N/A
65N/A // The inline code for Object.clone() casts the allocation result to
247N/A // java.lang.Object and then to the actual type of the allocated
65N/A // object. Detect this case and use the second cast.
247N/A // Also detect j.l.reflect.Array.newInstance(jobject, jint) case when
247N/A // the allocation result is cast to java.lang.Object and then
247N/A // to the actual Array type.
65N/A if (alloc->is_Allocate() && n->as_Type()->type() == TypeInstPtr::NOTNULL
247N/A && (alloc->is_AllocateArray() ||
247N/A igvn->type(alloc->in(AllocateNode::KlassNode)) != TypeKlassPtr::OBJECT)) {
65N/A Node *cast2 = NULL;
65N/A for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
65N/A Node *use = n->fast_out(i);
65N/A if (use->is_CheckCastPP()) {
65N/A cast2 = use;
65N/A break;
65N/A }
65N/A }
65N/A if (cast2 != NULL) {
65N/A n = cast2;
65N/A } else {
784N/A // Non-scalar replaceable if the allocation type is unknown statically
784N/A // (reflection allocation), the object can't be restored during
784N/A // deoptimization without precise type.
65N/A continue;
65N/A }
65N/A }
784N/A if (alloc->is_Allocate()) {
784N/A // Set the scalar_replaceable flag for allocation
784N/A // so it could be eliminated.
784N/A alloc->as_Allocate()->_is_scalar_replaceable = true;
784N/A }
65N/A set_escape_state(n->_idx, es);
247N/A // in order for an object to be scalar-replaceable, it must be:
65N/A // - a direct allocation (not a call returning an object)
65N/A // - non-escaping
65N/A // - eligible to be a unique type
65N/A // - not determined to be ineligible by escape analysis
1101N/A assert(ptnode_adr(alloc->_idx)->_node != NULL &&
1101N/A ptnode_adr(n->_idx)->_node != NULL, "should be registered");
0N/A set_map(alloc->_idx, n);
0N/A set_map(n->_idx, alloc);
65N/A const TypeOopPtr *t = igvn->type(n)->isa_oopptr();
65N/A if (t == NULL)
0N/A continue; // not a TypeInstPtr
247N/A tinst = t->cast_to_exactness(true)->is_oopptr()->cast_to_instance_id(ni);
0N/A igvn->hash_delete(n);
0N/A igvn->set_type(n, tinst);
0N/A n->raise_bottom_type(tinst);
0N/A igvn->hash_insert(n);
65N/A record_for_optimizer(n);
65N/A if (alloc->is_Allocate() && ptn->_scalar_replaceable &&
65N/A (t->isa_instptr() || t->isa_aryptr())) {
163N/A
163N/A // First, put on the worklist all Field edges from Connection Graph
163N/A // which is more accurate then putting immediate users from Ideal Graph.
163N/A for (uint e = 0; e < ptn->edge_count(); e++) {
244N/A Node *use = ptnode_adr(ptn->edge_target(e))->_node;
163N/A assert(ptn->edge_type(e) == PointsToNode::FieldEdge && use->is_AddP(),
163N/A "only AddP nodes are Field edges in CG");
163N/A if (use->outcnt() > 0) { // Don't process dead nodes
163N/A Node* addp2 = find_second_addp(use, use->in(AddPNode::Base));
163N/A if (addp2 != NULL) {
163N/A assert(alloc->is_AllocateArray(),"array allocation was expected");
163N/A alloc_worklist.append_if_missing(addp2);
163N/A }
163N/A alloc_worklist.append_if_missing(use);
163N/A }
163N/A }
163N/A
65N/A // An allocation may have an Initialize which has raw stores. Scan
65N/A // the users of the raw allocation result and push AddP users
65N/A // on alloc_worklist.
65N/A Node *raw_result = alloc->proj_out(TypeFunc::Parms);
65N/A assert (raw_result != NULL, "must have an allocation result");
65N/A for (DUIterator_Fast imax, i = raw_result->fast_outs(imax); i < imax; i++) {
65N/A Node *use = raw_result->fast_out(i);
65N/A if (use->is_AddP() && use->outcnt() > 0) { // Don't process dead nodes
65N/A Node* addp2 = find_second_addp(use, raw_result);
65N/A if (addp2 != NULL) {
65N/A assert(alloc->is_AllocateArray(),"array allocation was expected");
65N/A alloc_worklist.append_if_missing(addp2);
65N/A }
65N/A alloc_worklist.append_if_missing(use);
1100N/A } else if (use->is_MemBar()) {
65N/A memnode_worklist.append_if_missing(use);
65N/A }
65N/A }
65N/A }
0N/A } else if (n->is_AddP()) {
0N/A ptset.Clear();
1554N/A PointsTo(ptset, get_addp_base(n));
0N/A assert(ptset.Size() == 1, "AddP address is unique");
65N/A uint elem = ptset.getelem(); // Allocation node's index
1100N/A if (elem == _phantom_object) {
1100N/A assert(false, "escaped allocation");
65N/A continue; // Assume the value was set outside this method.
1100N/A }
65N/A Node *base = get_map(elem); // CheckCastPP node
1100N/A if (!split_AddP(n, base, igvn)) continue; // wrong type from dead path
65N/A tinst = igvn->type(base)->isa_oopptr();
65N/A } else if (n->is_Phi() ||
65N/A n->is_CheckCastPP() ||
168N/A n->is_EncodeP() ||
168N/A n->is_DecodeN() ||
65N/A (n->is_ConstraintCast() && n->Opcode() == Op_CastPP)) {
0N/A if (visited.test_set(n->_idx)) {
0N/A assert(n->is_Phi(), "loops only through Phi's");
0N/A continue; // already processed
0N/A }
0N/A ptset.Clear();
1554N/A PointsTo(ptset, n);
0N/A if (ptset.Size() == 1) {
65N/A uint elem = ptset.getelem(); // Allocation node's index
1100N/A if (elem == _phantom_object) {
1100N/A assert(false, "escaped allocation");
65N/A continue; // Assume the value was set outside this method.
1100N/A }
65N/A Node *val = get_map(elem); // CheckCastPP node
0N/A TypeNode *tn = n->as_Type();
65N/A tinst = igvn->type(val)->isa_oopptr();
223N/A assert(tinst != NULL && tinst->is_known_instance() &&
223N/A (uint)tinst->instance_id() == elem , "instance type expected.");
163N/A
163N/A const Type *tn_type = igvn->type(tn);
223N/A const TypeOopPtr *tn_t;
223N/A if (tn_type->isa_narrowoop()) {
223N/A tn_t = tn_type->make_ptr()->isa_oopptr();
223N/A } else {
223N/A tn_t = tn_type->isa_oopptr();
223N/A }
0N/A
1100N/A if (tn_t != NULL && tinst->klass()->is_subtype_of(tn_t->klass())) {
163N/A if (tn_type->isa_narrowoop()) {
163N/A tn_type = tinst->make_narrowoop();
163N/A } else {
163N/A tn_type = tinst;
163N/A }
0N/A igvn->hash_delete(tn);
163N/A igvn->set_type(tn, tn_type);
163N/A tn->set_type(tn_type);
0N/A igvn->hash_insert(tn);
65N/A record_for_optimizer(n);
293N/A } else {
1100N/A assert(tn_type == TypePtr::NULL_PTR ||
1100N/A tn_t != NULL && !tinst->klass()->is_subtype_of(tn_t->klass()),
1100N/A "unexpected type");
1100N/A continue; // Skip dead path with different type
0N/A }
0N/A }
0N/A } else {
1100N/A debug_only(n->dump();)
1100N/A assert(false, "EA: unexpected node");
0N/A continue;
0N/A }
1100N/A // push allocation's users on appropriate worklist
0N/A for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
0N/A Node *use = n->fast_out(i);
0N/A if(use->is_Mem() && use->in(MemNode::Address) == n) {
1100N/A // Load/store to instance's field
65N/A memnode_worklist.append_if_missing(use);
1100N/A } else if (use->is_MemBar()) {
1100N/A memnode_worklist.append_if_missing(use);
65N/A } else if (use->is_AddP() && use->outcnt() > 0) { // No dead nodes
65N/A Node* addp2 = find_second_addp(use, n);
65N/A if (addp2 != NULL) {
65N/A alloc_worklist.append_if_missing(addp2);
65N/A }
65N/A alloc_worklist.append_if_missing(use);
65N/A } else if (use->is_Phi() ||
65N/A use->is_CheckCastPP() ||
168N/A use->is_EncodeP() ||
168N/A use->is_DecodeN() ||
65N/A (use->is_ConstraintCast() && use->Opcode() == Op_CastPP)) {
65N/A alloc_worklist.append_if_missing(use);
1100N/A#ifdef ASSERT
1100N/A } else if (use->is_Mem()) {
1100N/A assert(use->in(MemNode::Address) != n, "EA: missing allocation reference path");
1100N/A } else if (use->is_MergeMem()) {
1100N/A assert(_mergemem_worklist.contains(use->as_MergeMem()), "EA: missing MergeMem node in the worklist");
1100N/A } else if (use->is_SafePoint()) {
1100N/A // Look for MergeMem nodes for calls which reference unique allocation
1100N/A // (through CheckCastPP nodes) even for debug info.
1100N/A Node* m = use->in(TypeFunc::Memory);
1100N/A if (m->is_MergeMem()) {
1100N/A assert(_mergemem_worklist.contains(m->as_MergeMem()), "EA: missing MergeMem node in the worklist");
1100N/A }
1100N/A } else {
1100N/A uint op = use->Opcode();
1100N/A if (!(op == Op_CmpP || op == Op_Conv2B ||
1100N/A op == Op_CastP2X || op == Op_StoreCM ||
1100N/A op == Op_FastLock || op == Op_AryEq || op == Op_StrComp ||
1100N/A op == Op_StrEquals || op == Op_StrIndexOf)) {
1100N/A n->dump();
1100N/A use->dump();
1100N/A assert(false, "EA: missing allocation reference path");
1100N/A }
1100N/A#endif
0N/A }
0N/A }
0N/A
0N/A }
65N/A // New alias types were created in split_AddP().
0N/A uint new_index_end = (uint) _compile->num_alias_types();
0N/A
0N/A // Phase 2: Process MemNode's from memnode_worklist. compute new address type and
0N/A // compute new values for Memory inputs (the Memory inputs are not
0N/A // actually updated until phase 4.)
0N/A if (memnode_worklist.length() == 0)
0N/A return; // nothing to do
0N/A
0N/A while (memnode_worklist.length() != 0) {
0N/A Node *n = memnode_worklist.pop();
65N/A if (visited.test_set(n->_idx))
65N/A continue;
1100N/A if (n->is_Phi() || n->is_ClearArray()) {
1100N/A // we don't need to do anything, but the users must be pushed
1100N/A } else if (n->is_MemBar()) { // Initialize, MemBar nodes
1100N/A // we don't need to do anything, but the users must be pushed
1100N/A n = n->as_MemBar()->proj_out(TypeFunc::Memory);
65N/A if (n == NULL)
0N/A continue;
0N/A } else {
0N/A assert(n->is_Mem(), "memory node required.");
0N/A Node *addr = n->in(MemNode::Address);
0N/A const Type *addr_t = igvn->type(addr);
0N/A if (addr_t == Type::TOP)
0N/A continue;
0N/A assert (addr_t->isa_ptr() != NULL, "pointer type required.");
0N/A int alias_idx = _compile->get_alias_index(addr_t->is_ptr());
65N/A assert ((uint)alias_idx < new_index_end, "wrong alias index");
65N/A Node *mem = find_inst_mem(n->in(MemNode::Memory), alias_idx, orig_phis, igvn);
38N/A if (_compile->failing()) {
38N/A return;
38N/A }
65N/A if (mem != n->in(MemNode::Memory)) {
1101N/A // We delay the memory edge update since we need old one in
1101N/A // MergeMem code below when instances memory slices are separated.
1101N/A debug_only(Node* pn = ptnode_adr(n->_idx)->_node;)
1101N/A assert(pn == NULL || pn == n, "wrong node");
0N/A set_map(n->_idx, mem);
244N/A ptnode_adr(n->_idx)->_node = n;
65N/A }
0N/A if (n->is_Load()) {
0N/A continue; // don't push users
0N/A } else if (n->is_LoadStore()) {
0N/A // get the memory projection
0N/A for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
0N/A Node *use = n->fast_out(i);
0N/A if (use->Opcode() == Op_SCMemProj) {
0N/A n = use;
0N/A break;
0N/A }
0N/A }
0N/A assert(n->Opcode() == Op_SCMemProj, "memory projection required");
0N/A }
0N/A }
0N/A // push user on appropriate worklist
0N/A for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
0N/A Node *use = n->fast_out(i);
1100N/A if (use->is_Phi() || use->is_ClearArray()) {
65N/A memnode_worklist.append_if_missing(use);
0N/A } else if(use->is_Mem() && use->in(MemNode::Memory) == n) {
1100N/A if (use->Opcode() == Op_StoreCM) // Ignore cardmark stores
1100N/A continue;
65N/A memnode_worklist.append_if_missing(use);
1100N/A } else if (use->is_MemBar()) {
65N/A memnode_worklist.append_if_missing(use);
1100N/A#ifdef ASSERT
1100N/A } else if(use->is_Mem()) {
1100N/A assert(use->in(MemNode::Memory) != n, "EA: missing memory path");
0N/A } else if (use->is_MergeMem()) {
1100N/A assert(_mergemem_worklist.contains(use->as_MergeMem()), "EA: missing MergeMem node in the worklist");
1100N/A } else {
1100N/A uint op = use->Opcode();
1100N/A if (!(op == Op_StoreCM ||
1100N/A (op == Op_CallLeaf && use->as_CallLeaf()->_name != NULL &&
1100N/A strcmp(use->as_CallLeaf()->_name, "g1_wb_pre") == 0) ||
1100N/A op == Op_AryEq || op == Op_StrComp ||
1100N/A op == Op_StrEquals || op == Op_StrIndexOf)) {
1100N/A n->dump();
1100N/A use->dump();
1100N/A assert(false, "EA: missing memory path");
1100N/A }
1100N/A#endif
0N/A }
0N/A }
0N/A }
0N/A
65N/A // Phase 3: Process MergeMem nodes from mergemem_worklist.
1100N/A // Walk each memory slice moving the first node encountered of each
65N/A // instance type to the the input corresponding to its alias index.
1100N/A uint length = _mergemem_worklist.length();
1100N/A for( uint next = 0; next < length; ++next ) {
1100N/A MergeMemNode* nmm = _mergemem_worklist.at(next);
1100N/A assert(!visited.test_set(nmm->_idx), "should not be visited before");
0N/A // Note: we don't want to use MergeMemStream here because we only want to
1100N/A // scan inputs which exist at the start, not ones we add during processing.
1100N/A // Note 2: MergeMem may already contains instance memory slices added
1100N/A // during find_inst_mem() call when memory nodes were processed above.
1100N/A igvn->hash_delete(nmm);
0N/A uint nslices = nmm->req();
0N/A for (uint i = Compile::AliasIdxRaw+1; i < nslices; i++) {
65N/A Node* mem = nmm->in(i);
65N/A Node* cur = NULL;
0N/A if (mem == NULL || mem->is_top())
0N/A continue;
1101N/A // First, update mergemem by moving memory nodes to corresponding slices
1101N/A // if their type became more precise since this mergemem was created.
0N/A while (mem->is_Mem()) {
0N/A const Type *at = igvn->type(mem->in(MemNode::Address));
0N/A if (at != Type::TOP) {
0N/A assert (at->isa_ptr() != NULL, "pointer type required.");
0N/A uint idx = (uint)_compile->get_alias_index(at->is_ptr());
0N/A if (idx == i) {
0N/A if (cur == NULL)
0N/A cur = mem;
0N/A } else {
0N/A if (idx >= nmm->req() || nmm->is_empty_memory(nmm->in(idx))) {
0N/A nmm->set_memory_at(idx, mem);
0N/A }
0N/A }
0N/A }
0N/A mem = mem->in(MemNode::Memory);
0N/A }
0N/A nmm->set_memory_at(i, (cur != NULL) ? cur : mem);
65N/A // Find any instance of the current type if we haven't encountered
1101N/A // already a memory slice of the instance along the memory chain.
65N/A for (uint ni = new_index_start; ni < new_index_end; ni++) {
65N/A if((uint)_compile->get_general_index(ni) == i) {
65N/A Node *m = (ni >= nmm->req()) ? nmm->empty_memory() : nmm->in(ni);
65N/A if (nmm->is_empty_memory(m)) {
65N/A Node* result = find_inst_mem(mem, ni, orig_phis, igvn);
65N/A if (_compile->failing()) {
65N/A return;
65N/A }
65N/A nmm->set_memory_at(ni, result);
65N/A }
65N/A }
65N/A }
65N/A }
65N/A // Find the rest of instances values
65N/A for (uint ni = new_index_start; ni < new_index_end; ni++) {
1101N/A const TypeOopPtr *tinst = _compile->get_adr_type(ni)->isa_oopptr();
65N/A Node* result = step_through_mergemem(nmm, ni, tinst);
65N/A if (result == nmm->base_memory()) {
65N/A // Didn't find instance memory, search through general slice recursively.
1101N/A result = nmm->memory_at(_compile->get_general_index(ni));
65N/A result = find_inst_mem(result, ni, orig_phis, igvn);
65N/A if (_compile->failing()) {
65N/A return;
65N/A }
65N/A nmm->set_memory_at(ni, result);
65N/A }
65N/A }
65N/A igvn->hash_insert(nmm);
65N/A record_for_optimizer(nmm);
0N/A }
0N/A
65N/A // Phase 4: Update the inputs of non-instance memory Phis and
65N/A // the Memory input of memnodes
0N/A // First update the inputs of any non-instance Phi's from
0N/A // which we split out an instance Phi. Note we don't have
0N/A // to recursively process Phi's encounted on the input memory
0N/A // chains as is done in split_memory_phi() since they will
0N/A // also be processed here.
247N/A for (int j = 0; j < orig_phis.length(); j++) {
247N/A PhiNode *phi = orig_phis.at(j);
0N/A int alias_idx = _compile->get_alias_index(phi->adr_type());
0N/A igvn->hash_delete(phi);
0N/A for (uint i = 1; i < phi->req(); i++) {
0N/A Node *mem = phi->in(i);
65N/A Node *new_mem = find_inst_mem(mem, alias_idx, orig_phis, igvn);
65N/A if (_compile->failing()) {
65N/A return;
65N/A }
0N/A if (mem != new_mem) {
0N/A phi->set_req(i, new_mem);
0N/A }
0N/A }
0N/A igvn->hash_insert(phi);
0N/A record_for_optimizer(phi);
0N/A }
0N/A
0N/A // Update the memory inputs of MemNodes with the value we computed
1101N/A // in Phase 2 and move stores memory users to corresponding memory slices.
1101N/A#ifdef ASSERT
1101N/A visited.Clear();
1101N/A Node_Stack old_mems(arena, _compile->unique() >> 2);
1101N/A#endif
244N/A for (uint i = 0; i < nodes_size(); i++) {
0N/A Node *nmem = get_map(i);
0N/A if (nmem != NULL) {
244N/A Node *n = ptnode_adr(i)->_node;
1101N/A assert(n != NULL, "sanity");
1101N/A if (n->is_Mem()) {
1101N/A#ifdef ASSERT
1101N/A Node* old_mem = n->in(MemNode::Memory);
1101N/A if (!visited.test_set(old_mem->_idx)) {
1101N/A old_mems.push(old_mem, old_mem->outcnt());
1101N/A }
1101N/A#endif
1101N/A assert(n->in(MemNode::Memory) != nmem, "sanity");
1101N/A if (!n->is_Load()) {
1101N/A // Move memory users of a store first.
1101N/A move_inst_mem(n, orig_phis, igvn);
1101N/A }
1101N/A // Now update memory input
0N/A igvn->hash_delete(n);
0N/A n->set_req(MemNode::Memory, nmem);
0N/A igvn->hash_insert(n);
0N/A record_for_optimizer(n);
1101N/A } else {
1101N/A assert(n->is_Allocate() || n->is_CheckCastPP() ||
1101N/A n->is_AddP() || n->is_Phi(), "unknown node used for set_map()");
0N/A }
0N/A }
0N/A }
1101N/A#ifdef ASSERT
1101N/A // Verify that memory was split correctly
1101N/A while (old_mems.is_nonempty()) {
1101N/A Node* old_mem = old_mems.node();
1101N/A uint old_cnt = old_mems.index();
1101N/A old_mems.pop();
1101N/A assert(old_cnt = old_mem->outcnt(), "old mem could be lost");
1101N/A }
1101N/A#endif
0N/A}
0N/A
244N/Abool ConnectionGraph::has_candidates(Compile *C) {
244N/A // EA brings benefits only when the code has allocations and/or locks which
244N/A // are represented by ideal Macro nodes.
244N/A int cnt = C->macro_count();
244N/A for( int i=0; i < cnt; i++ ) {
244N/A Node *n = C->macro_node(i);
244N/A if ( n->is_Allocate() )
244N/A return true;
244N/A if( n->is_Lock() ) {
244N/A Node* obj = n->as_Lock()->obj_node()->uncast();
244N/A if( !(obj->is_Parm() || obj->is_Con()) )
244N/A return true;
244N/A }
244N/A }
244N/A return false;
244N/A}
244N/A
1554N/Avoid ConnectionGraph::do_analysis(Compile *C, PhaseIterGVN *igvn) {
1554N/A // Add ConP#NULL and ConN#NULL nodes before ConnectionGraph construction
1554N/A // to create space for them in ConnectionGraph::_nodes[].
1554N/A Node* oop_null = igvn->zerocon(T_OBJECT);
1554N/A Node* noop_null = igvn->zerocon(T_NARROWOOP);
1554N/A
1554N/A ConnectionGraph* congraph = new(C->comp_arena()) ConnectionGraph(C, igvn);
1554N/A // Perform escape analysis
1554N/A if (congraph->compute_escape()) {
1554N/A // There are non escaping objects.
1554N/A C->set_congraph(congraph);
1554N/A }
1554N/A
1554N/A // Cleanup.
1554N/A if (oop_null->outcnt() == 0)
1554N/A igvn->hash_delete(oop_null);
1554N/A if (noop_null->outcnt() == 0)
1554N/A igvn->hash_delete(noop_null);
1554N/A}
1554N/A
244N/Abool ConnectionGraph::compute_escape() {
244N/A Compile* C = _compile;
65N/A
163N/A // 1. Populate Connection Graph (CG) with Ideal nodes.
65N/A
65N/A Unique_Node_List worklist_init;
244N/A worklist_init.map(C->unique(), NULL); // preallocate space
65N/A
65N/A // Initialize worklist
244N/A if (C->root() != NULL) {
244N/A worklist_init.push(C->root());
65N/A }
65N/A
65N/A GrowableArray<int> cg_worklist;
1554N/A PhaseGVN* igvn = _igvn;
65N/A bool has_allocations = false;
65N/A
65N/A // Push all useful nodes onto CG list and set their type.
65N/A for( uint next = 0; next < worklist_init.size(); ++next ) {
65N/A Node* n = worklist_init.at(next);
65N/A record_for_escape_analysis(n, igvn);
244N/A // Only allocations and java static calls results are checked
244N/A // for an escape status. See process_call_result() below.
244N/A if (n->is_Allocate() || n->is_CallStaticJava() &&
244N/A ptnode_adr(n->_idx)->node_type() == PointsToNode::JavaObject) {
65N/A has_allocations = true;
65N/A }
1100N/A if(n->is_AddP()) {
1841N/A // Collect address nodes. Use them during stage 3 below
1841N/A // to build initial connection graph field edges.
1841N/A cg_worklist.append(n->_idx);
1100N/A } else if (n->is_MergeMem()) {
1100N/A // Collect all MergeMem nodes to add memory slices for
1100N/A // scalar replaceable objects in split_unique_types().
1100N/A _mergemem_worklist.append(n->as_MergeMem());
1100N/A }
65N/A for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
65N/A Node* m = n->fast_out(i); // Get user
65N/A worklist_init.push(m);
65N/A }
65N/A }
0N/A
244N/A if (!has_allocations) {
65N/A _collecting = false;
244N/A return false; // Nothing to do.
65N/A }
65N/A
65N/A // 2. First pass to create simple CG edges (doesn't require to walk CG).
244N/A uint delayed_size = _delayed_worklist.size();
244N/A for( uint next = 0; next < delayed_size; ++next ) {
65N/A Node* n = _delayed_worklist.at(next);
65N/A build_connection_graph(n, igvn);
65N/A }
0N/A
1841N/A // 3. Pass to create initial fields edges (JavaObject -F-> AddP)
1841N/A // to reduce number of iterations during stage 4 below.
244N/A uint cg_length = cg_worklist.length();
244N/A for( uint next = 0; next < cg_length; ++next ) {
65N/A int ni = cg_worklist.at(next);
1841N/A Node* n = ptnode_adr(ni)->_node;
1841N/A Node* base = get_addp_base(n);
1841N/A if (base->is_Proj())
1841N/A base = base->in(0);
1841N/A PointsToNode::NodeType nt = ptnode_adr(base->_idx)->node_type();
1841N/A if (nt == PointsToNode::JavaObject) {
1841N/A build_connection_graph(n, igvn);
1841N/A }
65N/A }
65N/A
65N/A cg_worklist.clear();
65N/A cg_worklist.append(_phantom_object);
1841N/A GrowableArray<uint> worklist;
65N/A
65N/A // 4. Build Connection Graph which need
65N/A // to walk the connection graph.
1841N/A _progress = false;
244N/A for (uint ni = 0; ni < nodes_size(); ni++) {
244N/A PointsToNode* ptn = ptnode_adr(ni);
65N/A Node *n = ptn->_node;
65N/A if (n != NULL) { // Call, AddP, LoadP, StoreP
65N/A build_connection_graph(n, igvn);
65N/A if (ptn->node_type() != PointsToNode::UnknownType)
65N/A cg_worklist.append(n->_idx); // Collect CG nodes
1841N/A if (!_processed.test(n->_idx))
1841N/A worklist.append(n->_idx); // Collect C/A/L/S nodes
65N/A }
0N/A }
0N/A
1841N/A // After IGVN user nodes may have smaller _idx than
1841N/A // their inputs so they will be processed first in
1841N/A // previous loop. Because of that not all Graph
1841N/A // edges will be created. Walk over interesting
1841N/A // nodes again until no new edges are created.
1841N/A //
1841N/A // Normally only 1-3 passes needed to build
1841N/A // Connection Graph depending on graph complexity.
1841N/A // Set limit to 10 to catch situation when something
1841N/A // did go wrong and recompile the method without EA.
1841N/A
1841N/A#define CG_BUILD_ITER_LIMIT 10
1841N/A
1841N/A uint length = worklist.length();
1841N/A int iterations = 0;
1841N/A while(_progress && (iterations++ < CG_BUILD_ITER_LIMIT)) {
1841N/A _progress = false;
1841N/A for( uint next = 0; next < length; ++next ) {
1841N/A int ni = worklist.at(next);
1841N/A PointsToNode* ptn = ptnode_adr(ni);
1841N/A Node* n = ptn->_node;
1841N/A assert(n != NULL, "should be known node");
1841N/A build_connection_graph(n, igvn);
1841N/A }
1841N/A }
1841N/A if (iterations >= CG_BUILD_ITER_LIMIT) {
1841N/A assert(iterations < CG_BUILD_ITER_LIMIT,
1841N/A err_msg("infinite EA connection graph build with %d nodes and worklist size %d",
1841N/A nodes_size(), length));
1841N/A // Possible infinite build_connection_graph loop,
1841N/A // retry compilation without escape analysis.
1841N/A C->record_failure(C2Compiler::retry_no_escape_analysis());
1841N/A _collecting = false;
1841N/A return false;
1841N/A }
1841N/A#undef CG_BUILD_ITER_LIMIT
1841N/A
1100N/A Arena* arena = Thread::current()->resource_area();
1100N/A VectorSet ptset(arena);
1100N/A VectorSet visited(arena);
1841N/A worklist.clear();
0N/A
1100N/A // 5. Remove deferred edges from the graph and adjust
1100N/A // escape state of nonescaping objects.
244N/A cg_length = cg_worklist.length();
244N/A for( uint next = 0; next < cg_length; ++next ) {
65N/A int ni = cg_worklist.at(next);
244N/A PointsToNode* ptn = ptnode_adr(ni);
0N/A PointsToNode::NodeType nt = ptn->node_type();
0N/A if (nt == PointsToNode::LocalVar || nt == PointsToNode::Field) {
1841N/A remove_deferred(ni, &worklist, &visited);
244N/A Node *n = ptn->_node;
0N/A if (n->is_AddP()) {
1100N/A // Search for objects which are not scalar replaceable
1100N/A // and adjust their escape state.
1100N/A verify_escape_state(ni, ptset, igvn);
0N/A }
0N/A }
0N/A }
65N/A
244N/A // 6. Propagate escape states.
1841N/A worklist.clear();
244N/A bool has_non_escaping_obj = false;
244N/A
0N/A // push all GlobalEscape nodes on the worklist
244N/A for( uint next = 0; next < cg_length; ++next ) {
65N/A int nk = cg_worklist.at(next);
244N/A if (ptnode_adr(nk)->escape_state() == PointsToNode::GlobalEscape)
244N/A worklist.push(nk);
0N/A }
244N/A // mark all nodes reachable from GlobalEscape nodes
0N/A while(worklist.length() > 0) {
244N/A PointsToNode* ptn = ptnode_adr(worklist.pop());
244N/A uint e_cnt = ptn->edge_count();
244N/A for (uint ei = 0; ei < e_cnt; ei++) {
244N/A uint npi = ptn->edge_target(ei);
0N/A PointsToNode *np = ptnode_adr(npi);
65N/A if (np->escape_state() < PointsToNode::GlobalEscape) {
0N/A np->set_escape_state(PointsToNode::GlobalEscape);
244N/A worklist.push(npi);
0N/A }
0N/A }
0N/A }
0N/A
0N/A // push all ArgEscape nodes on the worklist
244N/A for( uint next = 0; next < cg_length; ++next ) {
65N/A int nk = cg_worklist.at(next);
244N/A if (ptnode_adr(nk)->escape_state() == PointsToNode::ArgEscape)
0N/A worklist.push(nk);
0N/A }
244N/A // mark all nodes reachable from ArgEscape nodes
0N/A while(worklist.length() > 0) {
244N/A PointsToNode* ptn = ptnode_adr(worklist.pop());
244N/A if (ptn->node_type() == PointsToNode::JavaObject)
244N/A has_non_escaping_obj = true; // Non GlobalEscape
244N/A uint e_cnt = ptn->edge_count();
244N/A for (uint ei = 0; ei < e_cnt; ei++) {
244N/A uint npi = ptn->edge_target(ei);
0N/A PointsToNode *np = ptnode_adr(npi);
65N/A if (np->escape_state() < PointsToNode::ArgEscape) {
0N/A np->set_escape_state(PointsToNode::ArgEscape);
244N/A worklist.push(npi);
0N/A }
0N/A }
0N/A }
65N/A
244N/A GrowableArray<Node*> alloc_worklist;
244N/A
65N/A // push all NoEscape nodes on the worklist
244N/A for( uint next = 0; next < cg_length; ++next ) {
65N/A int nk = cg_worklist.at(next);
244N/A if (ptnode_adr(nk)->escape_state() == PointsToNode::NoEscape)
65N/A worklist.push(nk);
65N/A }
244N/A // mark all nodes reachable from NoEscape nodes
65N/A while(worklist.length() > 0) {
244N/A PointsToNode* ptn = ptnode_adr(worklist.pop());
244N/A if (ptn->node_type() == PointsToNode::JavaObject)
244N/A has_non_escaping_obj = true; // Non GlobalEscape
244N/A Node* n = ptn->_node;
244N/A if (n->is_Allocate() && ptn->_scalar_replaceable ) {
605N/A // Push scalar replaceable allocations on alloc_worklist
244N/A // for processing in split_unique_types().
244N/A alloc_worklist.append(n);
244N/A }
244N/A uint e_cnt = ptn->edge_count();
244N/A for (uint ei = 0; ei < e_cnt; ei++) {
244N/A uint npi = ptn->edge_target(ei);
65N/A PointsToNode *np = ptnode_adr(npi);
65N/A if (np->escape_state() < PointsToNode::NoEscape) {
65N/A np->set_escape_state(PointsToNode::NoEscape);
244N/A worklist.push(npi);
65N/A }
65N/A }
65N/A }
65N/A
0N/A _collecting = false;
244N/A assert(C->unique() == nodes_size(), "there should be no new ideal nodes during ConnectionGraph build");
0N/A
1554N/A#ifndef PRODUCT
1554N/A if (PrintEscapeAnalysis) {
1554N/A dump(); // Dump ConnectionGraph
1554N/A }
1554N/A#endif
1554N/A
244N/A bool has_scalar_replaceable_candidates = alloc_worklist.length() > 0;
244N/A if ( has_scalar_replaceable_candidates &&
244N/A C->AliasLevel() >= 3 && EliminateAllocations ) {
0N/A
244N/A // Now use the escape information to create unique types for
244N/A // scalar replaceable objects.
244N/A split_unique_types(alloc_worklist);
0N/A
244N/A if (C->failing()) return false;
0N/A
244N/A C->print_method("After Escape Analysis", 2);
0N/A
65N/A#ifdef ASSERT
244N/A } else if (Verbose && (PrintEscapeAnalysis || PrintEliminateAllocations)) {
65N/A tty->print("=== No allocations eliminated for ");
244N/A C->method()->print_short_name();
65N/A if(!EliminateAllocations) {
65N/A tty->print(" since EliminateAllocations is off ===");
244N/A } else if(!has_scalar_replaceable_candidates) {
244N/A tty->print(" since there are no scalar replaceable candidates ===");
244N/A } else if(C->AliasLevel() < 3) {
65N/A tty->print(" since AliasLevel < 3 ===");
0N/A }
65N/A tty->cr();
65N/A#endif
0N/A }
244N/A return has_non_escaping_obj;
0N/A}
0N/A
1100N/A// Search for objects which are not scalar replaceable.
1100N/Avoid ConnectionGraph::verify_escape_state(int nidx, VectorSet& ptset, PhaseTransform* phase) {
1100N/A PointsToNode* ptn = ptnode_adr(nidx);
1100N/A Node* n = ptn->_node;
1100N/A assert(n->is_AddP(), "Should be called for AddP nodes only");
1100N/A // Search for objects which are not scalar replaceable.
1100N/A // Mark their escape state as ArgEscape to propagate the state
1100N/A // to referenced objects.
1100N/A // Note: currently there are no difference in compiler optimizations
1100N/A // for ArgEscape objects and NoEscape objects which are not
1100N/A // scalar replaceable.
1100N/A
1100N/A Compile* C = _compile;
1100N/A
1100N/A int offset = ptn->offset();
1100N/A Node* base = get_addp_base(n);
1100N/A ptset.Clear();
1554N/A PointsTo(ptset, base);
1100N/A int ptset_size = ptset.Size();
1100N/A
1100N/A // Check if a oop field's initializing value is recorded and add
1100N/A // a corresponding NULL field's value if it is not recorded.
1100N/A // Connection Graph does not record a default initialization by NULL
1100N/A // captured by Initialize node.
1100N/A //
1100N/A // Note: it will disable scalar replacement in some cases:
1100N/A //
1100N/A // Point p[] = new Point[1];
1100N/A // p[0] = new Point(); // Will be not scalar replaced
1100N/A //
1100N/A // but it will save us from incorrect optimizations in next cases:
1100N/A //
1100N/A // Point p[] = new Point[1];
1100N/A // if ( x ) p[0] = new Point(); // Will be not scalar replaced
1100N/A //
1100N/A // Do a simple control flow analysis to distinguish above cases.
1100N/A //
1100N/A if (offset != Type::OffsetBot && ptset_size == 1) {
1100N/A uint elem = ptset.getelem(); // Allocation node's index
1100N/A // It does not matter if it is not Allocation node since
1100N/A // only non-escaping allocations are scalar replaced.
1100N/A if (ptnode_adr(elem)->_node->is_Allocate() &&
1100N/A ptnode_adr(elem)->escape_state() == PointsToNode::NoEscape) {
1100N/A AllocateNode* alloc = ptnode_adr(elem)->_node->as_Allocate();
1100N/A InitializeNode* ini = alloc->initialization();
1100N/A
1100N/A // Check only oop fields.
1100N/A const Type* adr_type = n->as_AddP()->bottom_type();
1100N/A BasicType basic_field_type = T_INT;
1100N/A if (adr_type->isa_instptr()) {
1100N/A ciField* field = C->alias_type(adr_type->isa_instptr())->field();
1100N/A if (field != NULL) {
1100N/A basic_field_type = field->layout_type();
1100N/A } else {
1100N/A // Ignore non field load (for example, klass load)
1100N/A }
1100N/A } else if (adr_type->isa_aryptr()) {
1100N/A const Type* elemtype = adr_type->isa_aryptr()->elem();
1100N/A basic_field_type = elemtype->array_element_basic_type();
1100N/A } else {
1100N/A // Raw pointers are used for initializing stores so skip it.
1100N/A assert(adr_type->isa_rawptr() && base->is_Proj() &&
1100N/A (base->in(0) == alloc),"unexpected pointer type");
1100N/A }
1100N/A if (basic_field_type == T_OBJECT ||
1100N/A basic_field_type == T_NARROWOOP ||
1100N/A basic_field_type == T_ARRAY) {
1100N/A Node* value = NULL;
1100N/A if (ini != NULL) {
1100N/A BasicType ft = UseCompressedOops ? T_NARROWOOP : T_OBJECT;
1100N/A Node* store = ini->find_captured_store(offset, type2aelembytes(ft), phase);
1100N/A if (store != NULL && store->is_Store()) {
1100N/A value = store->in(MemNode::ValueIn);
1100N/A } else if (ptn->edge_count() > 0) { // Are there oop stores?
1100N/A // Check for a store which follows allocation without branches.
1100N/A // For example, a volatile field store is not collected
1100N/A // by Initialize node. TODO: it would be nice to use idom() here.
1100N/A for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
1100N/A store = n->fast_out(i);
1100N/A if (store->is_Store() && store->in(0) != NULL) {
1100N/A Node* ctrl = store->in(0);
1100N/A while(!(ctrl == ini || ctrl == alloc || ctrl == NULL ||
1100N/A ctrl == C->root() || ctrl == C->top() || ctrl->is_Region() ||
1100N/A ctrl->is_IfTrue() || ctrl->is_IfFalse())) {
1100N/A ctrl = ctrl->in(0);
1100N/A }
1100N/A if (ctrl == ini || ctrl == alloc) {
1100N/A value = store->in(MemNode::ValueIn);
1100N/A break;
1100N/A }
1100N/A }
1100N/A }
1100N/A }
1100N/A }
1100N/A if (value == NULL || value != ptnode_adr(value->_idx)->_node) {
1100N/A // A field's initializing value was not recorded. Add NULL.
1100N/A uint null_idx = UseCompressedOops ? _noop_null : _oop_null;
1100N/A add_pointsto_edge(nidx, null_idx);
1100N/A }
1100N/A }
1100N/A }
1100N/A }
1100N/A
1100N/A // An object is not scalar replaceable if the field which may point
1100N/A // to it has unknown offset (unknown element of an array of objects).
1100N/A //
1100N/A if (offset == Type::OffsetBot) {
1100N/A uint e_cnt = ptn->edge_count();
1100N/A for (uint ei = 0; ei < e_cnt; ei++) {
1100N/A uint npi = ptn->edge_target(ei);
1100N/A set_escape_state(npi, PointsToNode::ArgEscape);
1100N/A ptnode_adr(npi)->_scalar_replaceable = false;
1100N/A }
1100N/A }
1100N/A
1100N/A // Currently an object is not scalar replaceable if a LoadStore node
1100N/A // access its field since the field value is unknown after it.
1100N/A //
1100N/A bool has_LoadStore = false;
1100N/A for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
1100N/A Node *use = n->fast_out(i);
1100N/A if (use->is_LoadStore()) {
1100N/A has_LoadStore = true;
1100N/A break;
1100N/A }
1100N/A }
1100N/A // An object is not scalar replaceable if the address points
1100N/A // to unknown field (unknown element for arrays, offset is OffsetBot).
1100N/A //
1100N/A // Or the address may point to more then one object. This may produce
1100N/A // the false positive result (set scalar_replaceable to false)
1100N/A // since the flow-insensitive escape analysis can't separate
1100N/A // the case when stores overwrite the field's value from the case
1100N/A // when stores happened on different control branches.
1100N/A //
1100N/A if (ptset_size > 1 || ptset_size != 0 &&
1100N/A (has_LoadStore || offset == Type::OffsetBot)) {
1100N/A for( VectorSetI j(&ptset); j.test(); ++j ) {
1100N/A set_escape_state(j.elem, PointsToNode::ArgEscape);
1100N/A ptnode_adr(j.elem)->_scalar_replaceable = false;
1100N/A }
1100N/A }
1100N/A}
1100N/A
0N/Avoid ConnectionGraph::process_call_arguments(CallNode *call, PhaseTransform *phase) {
0N/A
0N/A switch (call->Opcode()) {
65N/A#ifdef ASSERT
0N/A case Op_Allocate:
0N/A case Op_AllocateArray:
0N/A case Op_Lock:
0N/A case Op_Unlock:
65N/A assert(false, "should be done already");
0N/A break;
65N/A#endif
1100N/A case Op_CallLeaf:
65N/A case Op_CallLeafNoFP:
65N/A {
65N/A // Stub calls, objects do not escape but they are not scale replaceable.
65N/A // Adjust escape state for outgoing arguments.
65N/A const TypeTuple * d = call->tf()->domain();
65N/A VectorSet ptset(Thread::current()->resource_area());
65N/A for (uint i = TypeFunc::Parms; i < d->cnt(); i++) {
65N/A const Type* at = d->field_at(i);
65N/A Node *arg = call->in(i)->uncast();
65N/A const Type *aat = phase->type(arg);
1100N/A if (!arg->is_top() && at->isa_ptr() && aat->isa_ptr() &&
1100N/A ptnode_adr(arg->_idx)->escape_state() < PointsToNode::ArgEscape) {
1100N/A
65N/A assert(aat == Type::TOP || aat == TypePtr::NULL_PTR ||
65N/A aat->isa_ptr() != NULL, "expecting an Ptr");
1100N/A#ifdef ASSERT
1100N/A if (!(call->Opcode() == Op_CallLeafNoFP &&
1100N/A call->as_CallLeaf()->_name != NULL &&
1100N/A (strstr(call->as_CallLeaf()->_name, "arraycopy") != 0) ||
1100N/A call->as_CallLeaf()->_name != NULL &&
1100N/A (strcmp(call->as_CallLeaf()->_name, "g1_wb_pre") == 0 ||
1100N/A strcmp(call->as_CallLeaf()->_name, "g1_wb_post") == 0 ))
1100N/A ) {
1100N/A call->dump();
1100N/A assert(false, "EA: unexpected CallLeaf");
1100N/A }
1100N/A#endif
65N/A set_escape_state(arg->_idx, PointsToNode::ArgEscape);
65N/A if (arg->is_AddP()) {
65N/A //
65N/A // The inline_native_clone() case when the arraycopy stub is called
65N/A // after the allocation before Initialize and CheckCastPP nodes.
65N/A //
65N/A // Set AddP's base (Allocate) as not scalar replaceable since
65N/A // pointer to the base (with offset) is passed as argument.
65N/A //
65N/A arg = get_addp_base(arg);
65N/A }
65N/A ptset.Clear();
1554N/A PointsTo(ptset, arg);
65N/A for( VectorSetI j(&ptset); j.test(); ++j ) {
65N/A uint pt = j.elem;
65N/A set_escape_state(pt, PointsToNode::ArgEscape);
65N/A }
65N/A }
65N/A }
65N/A break;
65N/A }
0N/A
0N/A case Op_CallStaticJava:
0N/A // For a static call, we know exactly what method is being called.
0N/A // Use bytecode estimator to record the call's escape affects
0N/A {
0N/A ciMethod *meth = call->as_CallJava()->method();
65N/A BCEscapeAnalyzer *call_analyzer = (meth !=NULL) ? meth->get_bcea() : NULL;
65N/A // fall-through if not a Java method or no analyzer information
65N/A if (call_analyzer != NULL) {
0N/A const TypeTuple * d = call->tf()->domain();
0N/A VectorSet ptset(Thread::current()->resource_area());
65N/A bool copy_dependencies = false;
0N/A for (uint i = TypeFunc::Parms; i < d->cnt(); i++) {
0N/A const Type* at = d->field_at(i);
0N/A int k = i - TypeFunc::Parms;
1100N/A Node *arg = call->in(i)->uncast();
0N/A
1100N/A if (at->isa_oopptr() != NULL &&
1136N/A ptnode_adr(arg->_idx)->escape_state() < PointsToNode::GlobalEscape) {
0N/A
65N/A bool global_escapes = false;
65N/A bool fields_escapes = false;
65N/A if (!call_analyzer->is_arg_stack(k)) {
65N/A // The argument global escapes, mark everything it could point to
65N/A set_escape_state(arg->_idx, PointsToNode::GlobalEscape);
65N/A global_escapes = true;
65N/A } else {
65N/A if (!call_analyzer->is_arg_local(k)) {
65N/A // The argument itself doesn't escape, but any fields might
65N/A fields_escapes = true;
0N/A }
65N/A set_escape_state(arg->_idx, PointsToNode::ArgEscape);
65N/A copy_dependencies = true;
65N/A }
65N/A
65N/A ptset.Clear();
1554N/A PointsTo(ptset, arg);
65N/A for( VectorSetI j(&ptset); j.test(); ++j ) {
65N/A uint pt = j.elem;
65N/A if (global_escapes) {
65N/A //The argument global escapes, mark everything it could point to
65N/A set_escape_state(pt, PointsToNode::GlobalEscape);
65N/A } else {
65N/A if (fields_escapes) {
65N/A // The argument itself doesn't escape, but any fields might
65N/A add_edge_from_fields(pt, _phantom_object, Type::OffsetBot);
65N/A }
65N/A set_escape_state(pt, PointsToNode::ArgEscape);
0N/A }
0N/A }
0N/A }
0N/A }
65N/A if (copy_dependencies)
244N/A call_analyzer->copy_dependencies(_compile->dependencies());
0N/A break;
0N/A }
0N/A }
0N/A
0N/A default:
65N/A // Fall-through here if not a Java method or no analyzer information
65N/A // or some other type of call, assume the worst case: all arguments
0N/A // globally escape.
0N/A {
0N/A // adjust escape state for outgoing arguments
0N/A const TypeTuple * d = call->tf()->domain();
0N/A VectorSet ptset(Thread::current()->resource_area());
0N/A for (uint i = TypeFunc::Parms; i < d->cnt(); i++) {
0N/A const Type* at = d->field_at(i);
0N/A if (at->isa_oopptr() != NULL) {
65N/A Node *arg = call->in(i)->uncast();
65N/A set_escape_state(arg->_idx, PointsToNode::GlobalEscape);
0N/A ptset.Clear();
1554N/A PointsTo(ptset, arg);
0N/A for( VectorSetI j(&ptset); j.test(); ++j ) {
0N/A uint pt = j.elem;
0N/A set_escape_state(pt, PointsToNode::GlobalEscape);
0N/A }
0N/A }
0N/A }
0N/A }
0N/A }
0N/A}
0N/Avoid ConnectionGraph::process_call_result(ProjNode *resproj, PhaseTransform *phase) {
244N/A CallNode *call = resproj->in(0)->as_Call();
244N/A uint call_idx = call->_idx;
244N/A uint resproj_idx = resproj->_idx;
0N/A
0N/A switch (call->Opcode()) {
0N/A case Op_Allocate:
0N/A {
0N/A Node *k = call->in(AllocateNode::KlassNode);
1459N/A const TypeKlassPtr *kt = k->bottom_type()->isa_klassptr();
0N/A assert(kt != NULL, "TypeKlassPtr required.");
0N/A ciKlass* cik = kt->klass();
0N/A
65N/A PointsToNode::EscapeState es;
65N/A uint edge_to;
1459N/A if (cik->is_subclass_of(_compile->env()->Thread_klass()) ||
1459N/A !cik->is_instance_klass() || // StressReflectiveCode
1459N/A cik->as_instance_klass()->has_finalizer()) {
65N/A es = PointsToNode::GlobalEscape;
65N/A edge_to = _phantom_object; // Could not be worse
0N/A } else {
65N/A es = PointsToNode::NoEscape;
244N/A edge_to = call_idx;
0N/A }
244N/A set_escape_state(call_idx, es);
244N/A add_pointsto_edge(resproj_idx, edge_to);
244N/A _processed.set(resproj_idx);
0N/A break;
0N/A }
0N/A
0N/A case Op_AllocateArray:
0N/A {
1459N/A
1459N/A Node *k = call->in(AllocateNode::KlassNode);
1459N/A const TypeKlassPtr *kt = k->bottom_type()->isa_klassptr();
1459N/A assert(kt != NULL, "TypeKlassPtr required.");
1459N/A ciKlass* cik = kt->klass();
1459N/A
1459N/A PointsToNode::EscapeState es;
1459N/A uint edge_to;
1459N/A if (!cik->is_array_klass()) { // StressReflectiveCode
1459N/A es = PointsToNode::GlobalEscape;
1459N/A edge_to = _phantom_object;
1459N/A } else {
1459N/A es = PointsToNode::NoEscape;
1459N/A edge_to = call_idx;
1459N/A int length = call->in(AllocateNode::ALength)->find_int_con(-1);
1459N/A if (length < 0 || length > EliminateAllocationArraySizeLimit) {
1459N/A // Not scalar replaceable if the length is not constant or too big.
1459N/A ptnode_adr(call_idx)->_scalar_replaceable = false;
1459N/A }
65N/A }
1459N/A set_escape_state(call_idx, es);
1459N/A add_pointsto_edge(resproj_idx, edge_to);
244N/A _processed.set(resproj_idx);
0N/A break;
0N/A }
0N/A
0N/A case Op_CallStaticJava:
0N/A // For a static call, we know exactly what method is being called.
0N/A // Use bytecode estimator to record whether the call's return value escapes
0N/A {
65N/A bool done = true;
0N/A const TypeTuple *r = call->tf()->range();
0N/A const Type* ret_type = NULL;
0N/A
0N/A if (r->cnt() > TypeFunc::Parms)
0N/A ret_type = r->field_at(TypeFunc::Parms);
0N/A
0N/A // Note: we use isa_ptr() instead of isa_oopptr() here because the
0N/A // _multianewarray functions return a TypeRawPtr.
65N/A if (ret_type == NULL || ret_type->isa_ptr() == NULL) {
244N/A _processed.set(resproj_idx);
0N/A break; // doesn't return a pointer type
65N/A }
0N/A ciMethod *meth = call->as_CallJava()->method();
65N/A const TypeTuple * d = call->tf()->domain();
0N/A if (meth == NULL) {
0N/A // not a Java method, assume global escape
244N/A set_escape_state(call_idx, PointsToNode::GlobalEscape);
244N/A add_pointsto_edge(resproj_idx, _phantom_object);
0N/A } else {
65N/A BCEscapeAnalyzer *call_analyzer = meth->get_bcea();
65N/A bool copy_dependencies = false;
0N/A
65N/A if (call_analyzer->is_return_allocated()) {
65N/A // Returns a newly allocated unescaped object, simply
65N/A // update dependency information.
65N/A // Mark it as NoEscape so that objects referenced by
65N/A // it's fields will be marked as NoEscape at least.
244N/A set_escape_state(call_idx, PointsToNode::NoEscape);
244N/A add_pointsto_edge(resproj_idx, call_idx);
65N/A copy_dependencies = true;
244N/A } else if (call_analyzer->is_return_local()) {
0N/A // determine whether any arguments are returned
244N/A set_escape_state(call_idx, PointsToNode::NoEscape);
307N/A bool ret_arg = false;
0N/A for (uint i = TypeFunc::Parms; i < d->cnt(); i++) {
0N/A const Type* at = d->field_at(i);
0N/A
0N/A if (at->isa_oopptr() != NULL) {
65N/A Node *arg = call->in(i)->uncast();
0N/A
65N/A if (call_analyzer->is_arg_returned(i - TypeFunc::Parms)) {
307N/A ret_arg = true;
244N/A PointsToNode *arg_esp = ptnode_adr(arg->_idx);
65N/A if (arg_esp->node_type() == PointsToNode::UnknownType)
65N/A done = false;
65N/A else if (arg_esp->node_type() == PointsToNode::JavaObject)
244N/A add_pointsto_edge(resproj_idx, arg->_idx);
0N/A else
244N/A add_deferred_edge(resproj_idx, arg->_idx);
0N/A arg_esp->_hidden_alias = true;
0N/A }
0N/A }
0N/A }
307N/A if (done && !ret_arg) {
307N/A // Returns unknown object.
307N/A set_escape_state(call_idx, PointsToNode::GlobalEscape);
307N/A add_pointsto_edge(resproj_idx, _phantom_object);
307N/A }
65N/A copy_dependencies = true;
0N/A } else {
244N/A set_escape_state(call_idx, PointsToNode::GlobalEscape);
244N/A add_pointsto_edge(resproj_idx, _phantom_object);
65N/A for (uint i = TypeFunc::Parms; i < d->cnt(); i++) {
65N/A const Type* at = d->field_at(i);
65N/A if (at->isa_oopptr() != NULL) {
65N/A Node *arg = call->in(i)->uncast();
244N/A PointsToNode *arg_esp = ptnode_adr(arg->_idx);
65N/A arg_esp->_hidden_alias = true;
65N/A }
65N/A }
0N/A }
65N/A if (copy_dependencies)
244N/A call_analyzer->copy_dependencies(_compile->dependencies());
0N/A }
65N/A if (done)
244N/A _processed.set(resproj_idx);
0N/A break;
0N/A }
0N/A
0N/A default:
0N/A // Some other type of call, assume the worst case that the
0N/A // returned value, if any, globally escapes.
0N/A {
0N/A const TypeTuple *r = call->tf()->range();
0N/A if (r->cnt() > TypeFunc::Parms) {
0N/A const Type* ret_type = r->field_at(TypeFunc::Parms);
0N/A
0N/A // Note: we use isa_ptr() instead of isa_oopptr() here because the
0N/A // _multianewarray functions return a TypeRawPtr.
0N/A if (ret_type->isa_ptr() != NULL) {
244N/A set_escape_state(call_idx, PointsToNode::GlobalEscape);
244N/A add_pointsto_edge(resproj_idx, _phantom_object);
0N/A }
0N/A }
244N/A _processed.set(resproj_idx);
0N/A }
0N/A }
0N/A}
0N/A
65N/A// Populate Connection Graph with Ideal nodes and create simple
65N/A// connection graph edges (do not need to check the node_type of inputs
65N/A// or to call PointsTo() to walk the connection graph).
65N/Avoid ConnectionGraph::record_for_escape_analysis(Node *n, PhaseTransform *phase) {
65N/A if (_processed.test(n->_idx))
65N/A return; // No need to redefine node's state.
65N/A
65N/A if (n->is_Call()) {
65N/A // Arguments to allocation and locking don't escape.
65N/A if (n->is_Allocate()) {
65N/A add_node(n, PointsToNode::JavaObject, PointsToNode::UnknownEscape, true);
65N/A record_for_optimizer(n);
65N/A } else if (n->is_Lock() || n->is_Unlock()) {
65N/A // Put Lock and Unlock nodes on IGVN worklist to process them during
65N/A // the first IGVN optimization when escape information is still available.
65N/A record_for_optimizer(n);
65N/A _processed.set(n->_idx);
65N/A } else {
1100N/A // Don't mark as processed since call's arguments have to be processed.
65N/A PointsToNode::NodeType nt = PointsToNode::UnknownType;
1100N/A PointsToNode::EscapeState es = PointsToNode::UnknownEscape;
65N/A
65N/A // Check if a call returns an object.
65N/A const TypeTuple *r = n->as_Call()->tf()->range();
1100N/A if (r->cnt() > TypeFunc::Parms &&
1100N/A r->field_at(TypeFunc::Parms)->isa_ptr() &&
65N/A n->as_Call()->proj_out(TypeFunc::Parms) != NULL) {
1100N/A nt = PointsToNode::JavaObject;
1100N/A if (!n->is_CallStaticJava()) {
1100N/A // Since the called mathod is statically unknown assume
1100N/A // the worst case that the returned value globally escapes.
1100N/A es = PointsToNode::GlobalEscape;
65N/A }
65N/A }
1100N/A add_node(n, nt, es, false);
65N/A }
65N/A return;
65N/A }
65N/A
65N/A // Using isa_ptr() instead of isa_oopptr() for LoadP and Phi because
65N/A // ThreadLocal has RawPrt type.
65N/A switch (n->Opcode()) {
65N/A case Op_AddP:
65N/A {
65N/A add_node(n, PointsToNode::Field, PointsToNode::UnknownEscape, false);
65N/A break;
65N/A }
65N/A case Op_CastX2P:
65N/A { // "Unsafe" memory access.
65N/A add_node(n, PointsToNode::JavaObject, PointsToNode::GlobalEscape, true);
65N/A break;
65N/A }
65N/A case Op_CastPP:
65N/A case Op_CheckCastPP:
124N/A case Op_EncodeP:
124N/A case Op_DecodeN:
65N/A {
65N/A add_node(n, PointsToNode::LocalVar, PointsToNode::UnknownEscape, false);
65N/A int ti = n->in(1)->_idx;
244N/A PointsToNode::NodeType nt = ptnode_adr(ti)->node_type();
65N/A if (nt == PointsToNode::UnknownType) {
65N/A _delayed_worklist.push(n); // Process it later.
65N/A break;
65N/A } else if (nt == PointsToNode::JavaObject) {
65N/A add_pointsto_edge(n->_idx, ti);
65N/A } else {
65N/A add_deferred_edge(n->_idx, ti);
65N/A }
65N/A _processed.set(n->_idx);
65N/A break;
65N/A }
65N/A case Op_ConP:
65N/A {
65N/A // assume all pointer constants globally escape except for null
65N/A PointsToNode::EscapeState es;
65N/A if (phase->type(n) == TypePtr::NULL_PTR)
65N/A es = PointsToNode::NoEscape;
65N/A else
65N/A es = PointsToNode::GlobalEscape;
0N/A
65N/A add_node(n, PointsToNode::JavaObject, es, true);
65N/A break;
65N/A }
113N/A case Op_ConN:
113N/A {
113N/A // assume all narrow oop constants globally escape except for null
113N/A PointsToNode::EscapeState es;
113N/A if (phase->type(n) == TypeNarrowOop::NULL_PTR)
113N/A es = PointsToNode::NoEscape;
113N/A else
113N/A es = PointsToNode::GlobalEscape;
113N/A
113N/A add_node(n, PointsToNode::JavaObject, es, true);
113N/A break;
113N/A }
124N/A case Op_CreateEx:
124N/A {
124N/A // assume that all exception objects globally escape
124N/A add_node(n, PointsToNode::JavaObject, PointsToNode::GlobalEscape, true);
124N/A break;
124N/A }
65N/A case Op_LoadKlass:
164N/A case Op_LoadNKlass:
65N/A {
65N/A add_node(n, PointsToNode::JavaObject, PointsToNode::GlobalEscape, true);
65N/A break;
65N/A }
65N/A case Op_LoadP:
113N/A case Op_LoadN:
65N/A {
65N/A const Type *t = phase->type(n);
253N/A if (t->make_ptr() == NULL) {
65N/A _processed.set(n->_idx);
65N/A return;
65N/A }
65N/A add_node(n, PointsToNode::LocalVar, PointsToNode::UnknownEscape, false);
65N/A break;
65N/A }
65N/A case Op_Parm:
65N/A {
65N/A _processed.set(n->_idx); // No need to redefine it state.
65N/A uint con = n->as_Proj()->_con;
65N/A if (con < TypeFunc::Parms)
65N/A return;
65N/A const Type *t = n->in(0)->as_Start()->_domain->field_at(con);
65N/A if (t->isa_ptr() == NULL)
65N/A return;
65N/A // We have to assume all input parameters globally escape
65N/A // (Note: passing 'false' since _processed is already set).
65N/A add_node(n, PointsToNode::JavaObject, PointsToNode::GlobalEscape, false);
65N/A break;
65N/A }
65N/A case Op_Phi:
65N/A {
253N/A const Type *t = n->as_Phi()->type();
253N/A if (t->make_ptr() == NULL) {
253N/A // nothing to do if not an oop or narrow oop
65N/A _processed.set(n->_idx);
65N/A return;
65N/A }
65N/A add_node(n, PointsToNode::LocalVar, PointsToNode::UnknownEscape, false);
65N/A uint i;
65N/A for (i = 1; i < n->req() ; i++) {
65N/A Node* in = n->in(i);
65N/A if (in == NULL)
65N/A continue; // ignore NULL
65N/A in = in->uncast();
65N/A if (in->is_top() || in == n)
65N/A continue; // ignore top or inputs which go back this node
65N/A int ti = in->_idx;
244N/A PointsToNode::NodeType nt = ptnode_adr(ti)->node_type();
65N/A if (nt == PointsToNode::UnknownType) {
65N/A break;
65N/A } else if (nt == PointsToNode::JavaObject) {
65N/A add_pointsto_edge(n->_idx, ti);
65N/A } else {
65N/A add_deferred_edge(n->_idx, ti);
65N/A }
65N/A }
65N/A if (i >= n->req())
65N/A _processed.set(n->_idx);
65N/A else
65N/A _delayed_worklist.push(n);
65N/A break;
65N/A }
65N/A case Op_Proj:
65N/A {
1100N/A // we are only interested in the oop result projection from a call
65N/A if (n->as_Proj()->_con == TypeFunc::Parms && n->in(0)->is_Call() ) {
1100N/A const TypeTuple *r = n->in(0)->as_Call()->tf()->range();
1100N/A assert(r->cnt() > TypeFunc::Parms, "sanity");
1100N/A if (r->field_at(TypeFunc::Parms)->isa_ptr() != NULL) {
1100N/A add_node(n, PointsToNode::LocalVar, PointsToNode::UnknownEscape, false);
1100N/A int ti = n->in(0)->_idx;
1100N/A // The call may not be registered yet (since not all its inputs are registered)
1100N/A // if this is the projection from backbranch edge of Phi.
1100N/A if (ptnode_adr(ti)->node_type() != PointsToNode::UnknownType) {
1100N/A process_call_result(n->as_Proj(), phase);
1100N/A }
1100N/A if (!_processed.test(n->_idx)) {
1100N/A // The call's result may need to be processed later if the call
1100N/A // returns it's argument and the argument is not processed yet.
1100N/A _delayed_worklist.push(n);
1100N/A }
1100N/A break;
65N/A }
65N/A }
1100N/A _processed.set(n->_idx);
65N/A break;
65N/A }
65N/A case Op_Return:
65N/A {
65N/A if( n->req() > TypeFunc::Parms &&
65N/A phase->type(n->in(TypeFunc::Parms))->isa_oopptr() ) {
65N/A // Treat Return value as LocalVar with GlobalEscape escape state.
65N/A add_node(n, PointsToNode::LocalVar, PointsToNode::GlobalEscape, false);
65N/A int ti = n->in(TypeFunc::Parms)->_idx;
244N/A PointsToNode::NodeType nt = ptnode_adr(ti)->node_type();
65N/A if (nt == PointsToNode::UnknownType) {
65N/A _delayed_worklist.push(n); // Process it later.
65N/A break;
65N/A } else if (nt == PointsToNode::JavaObject) {
65N/A add_pointsto_edge(n->_idx, ti);
65N/A } else {
65N/A add_deferred_edge(n->_idx, ti);
65N/A }
65N/A }
65N/A _processed.set(n->_idx);
65N/A break;
65N/A }
65N/A case Op_StoreP:
113N/A case Op_StoreN:
65N/A {
65N/A const Type *adr_type = phase->type(n->in(MemNode::Address));
221N/A adr_type = adr_type->make_ptr();
65N/A if (adr_type->isa_oopptr()) {
65N/A add_node(n, PointsToNode::UnknownType, PointsToNode::UnknownEscape, false);
65N/A } else {
65N/A Node* adr = n->in(MemNode::Address);
65N/A if (adr->is_AddP() && phase->type(adr) == TypeRawPtr::NOTNULL &&
65N/A adr->in(AddPNode::Address)->is_Proj() &&
65N/A adr->in(AddPNode::Address)->in(0)->is_Allocate()) {
65N/A add_node(n, PointsToNode::UnknownType, PointsToNode::UnknownEscape, false);
65N/A // We are computing a raw address for a store captured
65N/A // by an Initialize compute an appropriate address type.
65N/A int offs = (int)phase->find_intptr_t_con(adr->in(AddPNode::Offset), Type::OffsetBot);
65N/A assert(offs != Type::OffsetBot, "offset must be a constant");
65N/A } else {
65N/A _processed.set(n->_idx);
65N/A return;
65N/A }
65N/A }
65N/A break;
65N/A }
65N/A case Op_StorePConditional:
65N/A case Op_CompareAndSwapP:
113N/A case Op_CompareAndSwapN:
65N/A {
65N/A const Type *adr_type = phase->type(n->in(MemNode::Address));
221N/A adr_type = adr_type->make_ptr();
65N/A if (adr_type->isa_oopptr()) {
65N/A add_node(n, PointsToNode::UnknownType, PointsToNode::UnknownEscape, false);
65N/A } else {
65N/A _processed.set(n->_idx);
65N/A return;
65N/A }
65N/A break;
65N/A }
1100N/A case Op_AryEq:
1100N/A case Op_StrComp:
1100N/A case Op_StrEquals:
1100N/A case Op_StrIndexOf:
1100N/A {
1100N/A // char[] arrays passed to string intrinsics are not scalar replaceable.
1100N/A add_node(n, PointsToNode::UnknownType, PointsToNode::UnknownEscape, false);
1100N/A break;
1100N/A }
65N/A case Op_ThreadLocal:
65N/A {
65N/A add_node(n, PointsToNode::JavaObject, PointsToNode::ArgEscape, true);
65N/A break;
65N/A }
65N/A default:
65N/A ;
65N/A // nothing to do
65N/A }
65N/A return;
65N/A}
65N/A
65N/Avoid ConnectionGraph::build_connection_graph(Node *n, PhaseTransform *phase) {
244N/A uint n_idx = n->_idx;
1100N/A assert(ptnode_adr(n_idx)->_node != NULL, "node should be registered");
244N/A
65N/A // Don't set processed bit for AddP, LoadP, StoreP since
65N/A // they may need more then one pass to process.
1841N/A // Also don't mark as processed Call nodes since their
1841N/A // arguments may need more then one pass to process.
244N/A if (_processed.test(n_idx))
65N/A return; // No need to redefine node's state.
65N/A
0N/A if (n->is_Call()) {
0N/A CallNode *call = n->as_Call();
0N/A process_call_arguments(call, phase);
0N/A return;
0N/A }
0N/A
65N/A switch (n->Opcode()) {
0N/A case Op_AddP:
0N/A {
65N/A Node *base = get_addp_base(n);
65N/A // Create a field edge to this node from everything base could point to.
0N/A VectorSet ptset(Thread::current()->resource_area());
1554N/A PointsTo(ptset, base);
0N/A for( VectorSetI i(&ptset); i.test(); ++i ) {
0N/A uint pt = i.elem;
244N/A add_field_edge(pt, n_idx, address_offset(n, phase));
65N/A }
65N/A break;
65N/A }
65N/A case Op_CastX2P:
65N/A {
65N/A assert(false, "Op_CastX2P");
65N/A break;
65N/A }
65N/A case Op_CastPP:
65N/A case Op_CheckCastPP:
113N/A case Op_EncodeP:
113N/A case Op_DecodeN:
65N/A {
65N/A int ti = n->in(1)->_idx;
1100N/A assert(ptnode_adr(ti)->node_type() != PointsToNode::UnknownType, "all nodes should be registered");
244N/A if (ptnode_adr(ti)->node_type() == PointsToNode::JavaObject) {
244N/A add_pointsto_edge(n_idx, ti);
65N/A } else {
244N/A add_deferred_edge(n_idx, ti);
65N/A }
244N/A _processed.set(n_idx);
65N/A break;
65N/A }
65N/A case Op_ConP:
65N/A {
65N/A assert(false, "Op_ConP");
65N/A break;
65N/A }
163N/A case Op_ConN:
163N/A {
163N/A assert(false, "Op_ConN");
163N/A break;
163N/A }
65N/A case Op_CreateEx:
65N/A {
65N/A assert(false, "Op_CreateEx");
65N/A break;
65N/A }
65N/A case Op_LoadKlass:
164N/A case Op_LoadNKlass:
65N/A {
65N/A assert(false, "Op_LoadKlass");
65N/A break;
65N/A }
65N/A case Op_LoadP:
124N/A case Op_LoadN:
65N/A {
65N/A const Type *t = phase->type(n);
65N/A#ifdef ASSERT
253N/A if (t->make_ptr() == NULL)
65N/A assert(false, "Op_LoadP");
65N/A#endif
65N/A
65N/A Node* adr = n->in(MemNode::Address)->uncast();
65N/A Node* adr_base;
65N/A if (adr->is_AddP()) {
65N/A adr_base = get_addp_base(adr);
65N/A } else {
65N/A adr_base = adr;
65N/A }
65N/A
65N/A // For everything "adr_base" could point to, create a deferred edge from
65N/A // this node to each field with the same offset.
65N/A VectorSet ptset(Thread::current()->resource_area());
1554N/A PointsTo(ptset, adr_base);
65N/A int offset = address_offset(adr, phase);
65N/A for( VectorSetI i(&ptset); i.test(); ++i ) {
65N/A uint pt = i.elem;
244N/A add_deferred_edge_to_fields(n_idx, pt, offset);
0N/A }
0N/A break;
0N/A }
0N/A case Op_Parm:
0N/A {
65N/A assert(false, "Op_Parm");
0N/A break;
0N/A }
0N/A case Op_Phi:
0N/A {
65N/A#ifdef ASSERT
253N/A const Type *t = n->as_Phi()->type();
253N/A if (t->make_ptr() == NULL)
65N/A assert(false, "Op_Phi");
65N/A#endif
65N/A for (uint i = 1; i < n->req() ; i++) {
65N/A Node* in = n->in(i);
65N/A if (in == NULL)
65N/A continue; // ignore NULL
65N/A in = in->uncast();
65N/A if (in->is_top() || in == n)
65N/A continue; // ignore top or inputs which go back this node
65N/A int ti = in->_idx;
307N/A PointsToNode::NodeType nt = ptnode_adr(ti)->node_type();
307N/A assert(nt != PointsToNode::UnknownType, "all nodes should be known");
307N/A if (nt == PointsToNode::JavaObject) {
244N/A add_pointsto_edge(n_idx, ti);
65N/A } else {
244N/A add_deferred_edge(n_idx, ti);
65N/A }
65N/A }
244N/A _processed.set(n_idx);
0N/A break;
0N/A }
65N/A case Op_Proj:
0N/A {
1100N/A // we are only interested in the oop result projection from a call
65N/A if (n->as_Proj()->_con == TypeFunc::Parms && n->in(0)->is_Call() ) {
1100N/A assert(ptnode_adr(n->in(0)->_idx)->node_type() != PointsToNode::UnknownType,
1100N/A "all nodes should be registered");
1100N/A const TypeTuple *r = n->in(0)->as_Call()->tf()->range();
1100N/A assert(r->cnt() > TypeFunc::Parms, "sanity");
1100N/A if (r->field_at(TypeFunc::Parms)->isa_ptr() != NULL) {
1100N/A process_call_result(n->as_Proj(), phase);
1100N/A assert(_processed.test(n_idx), "all call results should be processed");
1100N/A break;
1100N/A }
65N/A }
1100N/A assert(false, "Op_Proj");
0N/A break;
0N/A }
65N/A case Op_Return:
0N/A {
65N/A#ifdef ASSERT
65N/A if( n->req() <= TypeFunc::Parms ||
65N/A !phase->type(n->in(TypeFunc::Parms))->isa_oopptr() ) {
65N/A assert(false, "Op_Return");
0N/A }
65N/A#endif
65N/A int ti = n->in(TypeFunc::Parms)->_idx;
1100N/A assert(ptnode_adr(ti)->node_type() != PointsToNode::UnknownType, "node should be registered");
244N/A if (ptnode_adr(ti)->node_type() == PointsToNode::JavaObject) {
244N/A add_pointsto_edge(n_idx, ti);
65N/A } else {
244N/A add_deferred_edge(n_idx, ti);
65N/A }
244N/A _processed.set(n_idx);
0N/A break;
0N/A }
0N/A case Op_StoreP:
124N/A case Op_StoreN:
0N/A case Op_StorePConditional:
0N/A case Op_CompareAndSwapP:
124N/A case Op_CompareAndSwapN:
0N/A {
0N/A Node *adr = n->in(MemNode::Address);
221N/A const Type *adr_type = phase->type(adr)->make_ptr();
65N/A#ifdef ASSERT
0N/A if (!adr_type->isa_oopptr())
65N/A assert(phase->type(adr) == TypeRawPtr::NOTNULL, "Op_StoreP");
65N/A#endif
0N/A
65N/A assert(adr->is_AddP(), "expecting an AddP");
65N/A Node *adr_base = get_addp_base(adr);
65N/A Node *val = n->in(MemNode::ValueIn)->uncast();
65N/A // For everything "adr_base" could point to, create a deferred edge
65N/A // to "val" from each field with the same offset.
0N/A VectorSet ptset(Thread::current()->resource_area());
1554N/A PointsTo(ptset, adr_base);
0N/A for( VectorSetI i(&ptset); i.test(); ++i ) {
0N/A uint pt = i.elem;
65N/A add_edge_from_fields(pt, val->_idx, address_offset(adr, phase));
0N/A }
0N/A break;
0N/A }
1100N/A case Op_AryEq:
1100N/A case Op_StrComp:
1100N/A case Op_StrEquals:
1100N/A case Op_StrIndexOf:
1100N/A {
1100N/A // char[] arrays passed to string intrinsic do not escape but
1100N/A // they are not scalar replaceable. Adjust escape state for them.
1100N/A // Start from in(2) edge since in(1) is memory edge.
1100N/A for (uint i = 2; i < n->req(); i++) {
1100N/A Node* adr = n->in(i)->uncast();
1100N/A const Type *at = phase->type(adr);
1100N/A if (!adr->is_top() && at->isa_ptr()) {
1100N/A assert(at == Type::TOP || at == TypePtr::NULL_PTR ||
1100N/A at->isa_ptr() != NULL, "expecting an Ptr");
1100N/A if (adr->is_AddP()) {
1100N/A adr = get_addp_base(adr);
1100N/A }
1100N/A // Mark as ArgEscape everything "adr" could point to.
1100N/A set_escape_state(adr->_idx, PointsToNode::ArgEscape);
1100N/A }
1100N/A }
1100N/A _processed.set(n_idx);
1100N/A break;
1100N/A }
65N/A case Op_ThreadLocal:
0N/A {
65N/A assert(false, "Op_ThreadLocal");
0N/A break;
0N/A }
0N/A default:
1100N/A // This method should be called only for EA specific nodes.
1100N/A ShouldNotReachHere();
0N/A }
0N/A}
0N/A
0N/A#ifndef PRODUCT
0N/Avoid ConnectionGraph::dump() {
0N/A bool first = true;
0N/A
244N/A uint size = nodes_size();
65N/A for (uint ni = 0; ni < size; ni++) {
244N/A PointsToNode *ptn = ptnode_adr(ni);
65N/A PointsToNode::NodeType ptn_type = ptn->node_type();
65N/A
65N/A if (ptn_type != PointsToNode::JavaObject || ptn->_node == NULL)
0N/A continue;
1554N/A PointsToNode::EscapeState es = escape_state(ptn->_node);
65N/A if (ptn->_node->is_Allocate() && (es == PointsToNode::NoEscape || Verbose)) {
65N/A if (first) {
65N/A tty->cr();
65N/A tty->print("======== Connection graph for ");
244N/A _compile->method()->print_short_name();
65N/A tty->cr();
65N/A first = false;
65N/A }
65N/A tty->print("%6d ", ni);
65N/A ptn->dump();
65N/A // Print all locals which reference this allocation
65N/A for (uint li = ni; li < size; li++) {
244N/A PointsToNode *ptn_loc = ptnode_adr(li);
65N/A PointsToNode::NodeType ptn_loc_type = ptn_loc->node_type();
65N/A if ( ptn_loc_type == PointsToNode::LocalVar && ptn_loc->_node != NULL &&
65N/A ptn_loc->edge_count() == 1 && ptn_loc->edge_target(0) == ni ) {
253N/A ptnode_adr(li)->dump(false);
0N/A }
0N/A }
65N/A if (Verbose) {
65N/A // Print all fields which reference this allocation
65N/A for (uint i = 0; i < ptn->edge_count(); i++) {
65N/A uint ei = ptn->edge_target(i);
253N/A ptnode_adr(ei)->dump(false);
65N/A }
65N/A }
65N/A tty->cr();
0N/A }
0N/A }
0N/A}
0N/A#endif