escape.cpp revision 0
0N/A/*
0N/A * Copyright 2005-2006 Sun Microsystems, Inc. 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 *
0N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
0N/A * CA 95054 USA or visit www.sun.com if you need additional information or
0N/A * have any questions.
0N/A *
0N/A */
0N/A
0N/A#include "incls/_precompiled.incl"
0N/A#include "incls/_escape.cpp.incl"
0N/A
0N/Auint PointsToNode::edge_target(uint e) const {
0N/A assert(_edges != NULL && e < (uint)_edges->length(), "valid edge index");
0N/A return (_edges->at(e) >> EdgeShift);
0N/A}
0N/A
0N/APointsToNode::EdgeType PointsToNode::edge_type(uint e) const {
0N/A assert(_edges != NULL && e < (uint)_edges->length(), "valid edge index");
0N/A return (EdgeType) (_edges->at(e) & EdgeMask);
0N/A}
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
0N/Astatic char *node_type_names[] = {
0N/A "UnknownType",
0N/A "JavaObject",
0N/A "LocalVar",
0N/A "Field"
0N/A};
0N/A
0N/Astatic char *esc_names[] = {
0N/A "UnknownEscape",
0N/A "NoEscape ",
0N/A "ArgEscape ",
0N/A "GlobalEscape "
0N/A};
0N/A
0N/Astatic char *edge_type_suffix[] = {
0N/A "?", // UnknownEdge
0N/A "P", // PointsToEdge
0N/A "D", // DeferredEdge
0N/A "F" // FieldEdge
0N/A};
0N/A
0N/Avoid PointsToNode::dump() const {
0N/A NodeType nt = node_type();
0N/A EscapeState es = escape_state();
0N/A tty->print("%s %s [[", node_type_names[(int) nt], esc_names[(int) es]);
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
0N/AConnectionGraph::ConnectionGraph(Compile * C) : _processed(C->comp_arena()), _node_map(C->comp_arena()) {
0N/A _collecting = true;
0N/A this->_compile = C;
0N/A const PointsToNode &dummy = PointsToNode();
0N/A _nodes = new(C->comp_arena()) GrowableArray<PointsToNode>(C->comp_arena(), (int) INITIAL_NODE_COUNT, 0, dummy);
0N/A _phantom_object = C->top()->_idx;
0N/A PointsToNode *phn = ptnode_adr(_phantom_object);
0N/A phn->set_node_type(PointsToNode::JavaObject);
0N/A phn->set_escape_state(PointsToNode::GlobalEscape);
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");
0N/A f->add_edge(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)
0N/A f->add_edge(to_i, PointsToNode::DeferredEdge);
0N/A}
0N/A
0N/Aint ConnectionGraph::type_to_offset(const Type *t) {
0N/A const TypePtr *t_ptr = t->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
0N/A f->add_edge(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
0N/APointsToNode::EscapeState ConnectionGraph::escape_state(Node *n, PhaseTransform *phase) {
0N/A uint idx = n->_idx;
0N/A PointsToNode::EscapeState es;
0N/A
0N/A // If we are still collecting we don't know the answer yet
0N/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
0N/A if (idx >= (uint)_nodes->length())
0N/A return PointsToNode::UnknownEscape;
0N/A
0N/A es = _nodes->at_grow(idx).escape_state();
0N/A
0N/A // if we have already computed a value, return it
0N/A if (es != PointsToNode::UnknownEscape)
0N/A return es;
0N/A
0N/A // compute max escape state of anything this node could point to
0N/A VectorSet ptset(Thread::current()->resource_area());
0N/A PointsTo(ptset, n, phase);
0N/A for( VectorSetI i(&ptset); i.test() && es != PointsToNode::GlobalEscape; ++i ) {
0N/A uint pt = i.elem;
0N/A PointsToNode::EscapeState pes = _nodes->at(pt).escape_state();
0N/A if (pes > es)
0N/A es = pes;
0N/A }
0N/A // cache the computed escape state
0N/A assert(es != PointsToNode::UnknownEscape, "should have computed an escape state");
0N/A _nodes->adr_at(idx)->set_escape_state(es);
0N/A return es;
0N/A}
0N/A
0N/Avoid ConnectionGraph::PointsTo(VectorSet &ptset, Node * n, PhaseTransform *phase) {
0N/A VectorSet visited(Thread::current()->resource_area());
0N/A GrowableArray<uint> worklist;
0N/A
0N/A n = skip_casts(n);
0N/A PointsToNode npt = _nodes->at_grow(n->_idx);
0N/A
0N/A // If we have a JavaObject, return just that object
0N/A if (npt.node_type() == PointsToNode::JavaObject) {
0N/A ptset.set(n->_idx);
0N/A return;
0N/A }
0N/A // we may have a Phi which has not been processed
0N/A if (npt._node == NULL) {
0N/A assert(n->is_Phi(), "unprocessed node must be a Phi");
0N/A record_for_escape_analysis(n);
0N/A npt = _nodes->at(n->_idx);
0N/A }
0N/A worklist.push(n->_idx);
0N/A while(worklist.length() > 0) {
0N/A int ni = worklist.pop();
0N/A PointsToNode pn = _nodes->at_grow(ni);
0N/A if (!visited.test(ni)) {
0N/A visited.set(ni);
0N/A
0N/A // ensure that all inputs of a Phi have been processed
0N/A if (_collecting && pn._node->is_Phi()) {
0N/A PhiNode *phi = pn._node->as_Phi();
0N/A process_phi_escape(phi, phase);
0N/A }
0N/A
0N/A int edges_processed = 0;
0N/A for (uint e = 0; e < pn.edge_count(); e++) {
0N/A PointsToNode::EdgeType et = pn.edge_type(e);
0N/A if (et == PointsToNode::PointsToEdge) {
0N/A ptset.set(pn.edge_target(e));
0N/A edges_processed++;
0N/A } else if (et == PointsToNode::DeferredEdge) {
0N/A worklist.push(pn.edge_target(e));
0N/A edges_processed++;
0N/A }
0N/A }
0N/A if (edges_processed == 0) {
0N/A // no deferred or pointsto edges found. Assume the value was set outside
0N/A // this method. Add the phantom object to the pointsto set.
0N/A ptset.set(_phantom_object);
0N/A }
0N/A }
0N/A }
0N/A}
0N/A
0N/Avoid ConnectionGraph::remove_deferred(uint ni) {
0N/A VectorSet visited(Thread::current()->resource_area());
0N/A
0N/A uint i = 0;
0N/A PointsToNode *ptn = ptnode_adr(ni);
0N/A
0N/A while(i < ptn->edge_count()) {
0N/A if (ptn->edge_type(i) != PointsToNode::DeferredEdge) {
0N/A i++;
0N/A } else {
0N/A uint t = ptn->edge_target(i);
0N/A PointsToNode *ptt = ptnode_adr(t);
0N/A ptn->remove_edge(t, PointsToNode::DeferredEdge);
0N/A if(!visited.test(t)) {
0N/A visited.set(t);
0N/A for (uint j = 0; j < ptt->edge_count(); j++) {
0N/A uint n1 = ptt->edge_target(j);
0N/A PointsToNode *pt1 = ptnode_adr(n1);
0N/A switch(ptt->edge_type(j)) {
0N/A case PointsToNode::PointsToEdge:
0N/A add_pointsto_edge(ni, n1);
0N/A break;
0N/A case PointsToNode::DeferredEdge:
0N/A add_deferred_edge(ni, n1);
0N/A break;
0N/A case PointsToNode::FieldEdge:
0N/A assert(false, "invalid connection graph");
0N/A break;
0N/A }
0N/A }
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) {
0N/A PointsToNode an = _nodes->at_grow(adr_i);
0N/A PointsToNode to = _nodes->at_grow(to_i);
0N/A bool deferred = (to.node_type() == PointsToNode::LocalVar);
0N/A
0N/A for (uint fe = 0; fe < an.edge_count(); fe++) {
0N/A assert(an.edge_type(fe) == PointsToNode::FieldEdge, "expecting a field edge");
0N/A int fi = an.edge_target(fe);
0N/A PointsToNode pf = _nodes->at_grow(fi);
0N/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
0N/A// Add a deferred edge from node given by "from_i" to any field of adr_i whose offset
0N/A// matches "offset"
0N/Avoid ConnectionGraph::add_deferred_edge_to_fields(uint from_i, uint adr_i, int offs) {
0N/A PointsToNode an = _nodes->at_grow(adr_i);
0N/A for (uint fe = 0; fe < an.edge_count(); fe++) {
0N/A assert(an.edge_type(fe) == PointsToNode::FieldEdge, "expecting a field edge");
0N/A int fi = an.edge_target(fe);
0N/A PointsToNode pf = _nodes->at_grow(fi);
0N/A int po = pf.offset();
0N/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
0N/A//
0N/A// Search memory chain of "mem" to find a MemNode whose address
0N/A// is the specified alias index. Returns the MemNode found or the
0N/A// first non-MemNode encountered.
0N/A//
0N/ANode *ConnectionGraph::find_mem(Node *mem, int alias_idx, PhaseGVN *igvn) {
0N/A if (mem == NULL)
0N/A return mem;
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 int idx = _compile->get_alias_index(at->is_ptr());
0N/A if (idx == alias_idx)
0N/A break;
0N/A }
0N/A mem = mem->in(MemNode::Memory);
0N/A }
0N/A return mem;
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//
0N/Avoid ConnectionGraph::split_AddP(Node *addp, Node *base, PhaseGVN *igvn) {
0N/A const TypeOopPtr *t = igvn->type(addp)->isa_oopptr();
0N/A const TypeOopPtr *base_t = igvn->type(base)->isa_oopptr();
0N/A assert(t != NULL, "expecting oopptr");
0N/A assert(base_t != NULL && base_t->is_instance(), "expecting instance oopptr");
0N/A uint inst_id = base_t->instance_id();
0N/A assert(!t->is_instance() || t->instance_id() == inst_id,
0N/A "old type must be non-instance or match new type");
0N/A const TypeOopPtr *tinst = base_t->add_offset(t->offset())->is_oopptr();
0N/A // ensure an alias index is allocated for the instance type
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
0N/A set_map(addp->_idx, get_map(base->_idx));
0N/A // if the Address input is not the appropriate instance type (due to intervening
0N/A // casts,) insert a cast
0N/A Node *adr = addp->in(AddPNode::Address);
0N/A const TypeOopPtr *atype = igvn->type(adr)->isa_oopptr();
0N/A if (atype->instance_id() != inst_id) {
0N/A assert(!atype->is_instance(), "no conflicting instances");
0N/A const TypeOopPtr *new_atype = base_t->add_offset(atype->offset())->isa_oopptr();
0N/A Node *acast = new (_compile, 2) CastPPNode(adr, new_atype);
0N/A acast->set_req(0, adr->in(0));
0N/A igvn->set_type(acast, new_atype);
0N/A record_for_optimizer(acast);
0N/A Node *bcast = acast;
0N/A Node *abase = addp->in(AddPNode::Base);
0N/A if (abase != adr) {
0N/A bcast = new (_compile, 2) CastPPNode(abase, base_t);
0N/A bcast->set_req(0, abase->in(0));
0N/A igvn->set_type(bcast, base_t);
0N/A record_for_optimizer(bcast);
0N/A }
0N/A igvn->hash_delete(addp);
0N/A addp->set_req(AddPNode::Base, bcast);
0N/A addp->set_req(AddPNode::Address, acast);
0N/A igvn->hash_insert(addp);
0N/A record_for_optimizer(addp);
0N/A }
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
0N/A if (phi_alias_idx == Compile::AliasIdxBot || phi_alias_idx == alias_idx) {
0N/A return orig_phi;
0N/A }
0N/A // have we already created a Phi for this alias index?
0N/A PhiNode *result = get_map_phi(orig_phi->_idx);
0N/A const TypePtr *atype = C->get_adr_type(alias_idx);
0N/A if (result != NULL && C->get_alias_index(result->adr_type()) == alias_idx) {
0N/A return result;
0N/A }
0N/A
0N/A orig_phi_worklist.append_if_missing(orig_phi);
0N/A result = PhiNode::make(orig_phi->in(0), NULL, Type::MEMORY, atype);
0N/A set_map_phi(orig_phi->_idx, result);
0N/A igvn->set_type(result, result->bottom_type());
0N/A record_for_optimizer(result);
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;
0N/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()) {
0N/A Node *mem = find_mem(phi->in(idx), alias_idx, igvn);
0N/A if (mem != NULL && mem->is_Phi()) {
0N/A PhiNode *nphi = 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();
0N/A result = nphi;
0N/A idx = 1;
0N/A continue;
0N/A } else {
0N/A mem = nphi;
0N/A }
0N/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");
0N/A for (uint i = 1; i < phi->req(); i++) {
0N/A assert((phi->in(i) == NULL) == (result->in(i) == NULL), "inputs must correspond.");
0N/A }
0N/A#endif
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();
0N/A PhiNode *prev_phi = get_map_phi(phi->_idx);
0N/A prev_phi->set_req(idx++, result);
0N/A result = prev_phi;
0N/A }
0N/A }
0N/A return result;
0N/A}
0N/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
0N/A// the approriate 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<Node *> mergemem_worklist;
0N/A GrowableArray<PhiNode *> orig_phis;
0N/A PhaseGVN *igvn = _compile->initial_gvn();
0N/A uint new_index_start = (uint) _compile->num_alias_types();
0N/A VectorSet visited(Thread::current()->resource_area());
0N/A VectorSet ptset(Thread::current()->resource_area());
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 while (alloc_worklist.length() != 0) {
0N/A Node *n = alloc_worklist.pop();
0N/A uint ni = n->_idx;
0N/A if (n->is_Call()) {
0N/A CallNode *alloc = n->as_Call();
0N/A // copy escape information to call node
0N/A PointsToNode ptn = _nodes->at(alloc->_idx);
0N/A PointsToNode::EscapeState es = escape_state(alloc, igvn);
0N/A alloc->_escape_state = es;
0N/A // find CheckCastPP of call return value
0N/A n = alloc->proj_out(TypeFunc::Parms);
0N/A if (n != NULL && n->outcnt() == 1) {
0N/A n = n->unique_out();
0N/A if (n->Opcode() != Op_CheckCastPP) {
0N/A continue;
0N/A }
0N/A } else {
0N/A continue;
0N/A }
0N/A // we have an allocation or call which returns a Java object, see if it is unescaped
0N/A if (es != PointsToNode::NoEscape || !ptn._unique_type) {
0N/A continue; // can't make a unique type
0N/A }
0N/A set_map(alloc->_idx, n);
0N/A set_map(n->_idx, alloc);
0N/A const TypeInstPtr *t = igvn->type(n)->isa_instptr();
0N/A // Unique types which are arrays are not currently supported.
0N/A // The check for AllocateArray is needed in case an array
0N/A // allocation is immediately cast to Object
0N/A if (t == NULL || alloc->is_AllocateArray())
0N/A continue; // not a TypeInstPtr
0N/A const TypeOopPtr *tinst = t->cast_to_instance(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);
0N/A } else if (n->is_AddP()) {
0N/A ptset.Clear();
0N/A PointsTo(ptset, n->in(AddPNode::Address), igvn);
0N/A assert(ptset.Size() == 1, "AddP address is unique");
0N/A Node *base = get_map(ptset.getelem());
0N/A split_AddP(n, base, igvn);
0N/A } else if (n->is_Phi() || n->Opcode() == Op_CastPP || n->Opcode() == Op_CheckCastPP) {
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();
0N/A PointsTo(ptset, n, igvn);
0N/A if (ptset.Size() == 1) {
0N/A TypeNode *tn = n->as_Type();
0N/A Node *val = get_map(ptset.getelem());
0N/A const TypeInstPtr *val_t = igvn->type(val)->isa_instptr();;
0N/A assert(val_t != NULL && val_t->is_instance(), "instance type expected.");
0N/A const TypeInstPtr *tn_t = igvn->type(tn)->isa_instptr();;
0N/A
0N/A if (tn_t != NULL && val_t->cast_to_instance(TypeOopPtr::UNKNOWN_INSTANCE)->higher_equal(tn_t)) {
0N/A igvn->hash_delete(tn);
0N/A igvn->set_type(tn, val_t);
0N/A tn->set_type(val_t);
0N/A igvn->hash_insert(tn);
0N/A }
0N/A }
0N/A } else {
0N/A continue;
0N/A }
0N/A // push 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) {
0N/A memnode_worklist.push(use);
0N/A } else if (use->is_AddP() || use->is_Phi() || use->Opcode() == Op_CastPP || use->Opcode() == Op_CheckCastPP) {
0N/A alloc_worklist.push(use);
0N/A }
0N/A }
0N/A
0N/A }
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
0N/A while (memnode_worklist.length() != 0) {
0N/A Node *n = memnode_worklist.pop();
0N/A if (n->is_Phi()) {
0N/A assert(n->as_Phi()->adr_type() != TypePtr::BOTTOM, "narrow memory slice required");
0N/A // we don't need to do anything, but the users must be pushed if we haven't processed
0N/A // this Phi before
0N/A if (visited.test_set(n->_idx))
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());
0N/A Node *mem = find_mem(n->in(MemNode::Memory), alias_idx, igvn);
0N/A if (mem->is_Phi()) {
0N/A mem = split_memory_phi(mem->as_Phi(), alias_idx, orig_phis, igvn);
0N/A }
0N/A if (mem != n->in(MemNode::Memory))
0N/A set_map(n->_idx, mem);
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);
0N/A if (use->is_Phi()) {
0N/A memnode_worklist.push(use);
0N/A } else if(use->is_Mem() && use->in(MemNode::Memory) == n) {
0N/A memnode_worklist.push(use);
0N/A } else if (use->is_MergeMem()) {
0N/A mergemem_worklist.push(use);
0N/A }
0N/A }
0N/A }
0N/A
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 while (mergemem_worklist.length() != 0) {
0N/A Node *n = mergemem_worklist.pop();
0N/A assert(n->is_MergeMem(), "MergeMem node required.");
0N/A MergeMemNode *nmm = n->as_MergeMem();
0N/A // Note: we don't want to use MergeMemStream here because we only want to
0N/A // scan inputs which exist at the start, not ones we add during processing
0N/A uint nslices = nmm->req();
0N/A igvn->hash_delete(nmm);
0N/A for (uint i = Compile::AliasIdxRaw+1; i < nslices; i++) {
0N/A Node * mem = nmm->in(i);
0N/A Node * cur = NULL;
0N/A if (mem == NULL || mem->is_top())
0N/A continue;
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);
0N/A if (mem->is_Phi()) {
0N/A // We have encountered a Phi, we need to split the Phi for
0N/A // any instance of the current type if we haven't encountered
0N/A // a value of the instance along the chain.
0N/A for (uint ni = new_index_start; ni < new_index_end; ni++) {
0N/A if((uint)_compile->get_general_index(ni) == i) {
0N/A Node *m = (ni >= nmm->req()) ? nmm->empty_memory() : nmm->in(ni);
0N/A if (nmm->is_empty_memory(m)) {
0N/A nmm->set_memory_at(ni, split_memory_phi(mem->as_Phi(), ni, orig_phis, igvn));
0N/A }
0N/A }
0N/A }
0N/A }
0N/A }
0N/A igvn->hash_insert(nmm);
0N/A record_for_optimizer(nmm);
0N/A }
0N/A
0N/A // Phase 4: Update the inputs of non-instance memory Phis and the Memory input of memnodes
0N/A //
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.
0N/A while (orig_phis.length() != 0) {
0N/A PhiNode *phi = orig_phis.pop();
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);
0N/A Node *new_mem = find_mem(mem, alias_idx, igvn);
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
0N/A // in Phase 2.
0N/A for (int i = 0; i < _nodes->length(); i++) {
0N/A Node *nmem = get_map(i);
0N/A if (nmem != NULL) {
0N/A Node *n = _nodes->at(i)._node;
0N/A if (n != NULL && n->is_Mem()) {
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);
0N/A }
0N/A }
0N/A }
0N/A}
0N/A
0N/Avoid ConnectionGraph::compute_escape() {
0N/A GrowableArray<int> worklist;
0N/A GrowableArray<Node *> alloc_worklist;
0N/A VectorSet visited(Thread::current()->resource_area());
0N/A PhaseGVN *igvn = _compile->initial_gvn();
0N/A
0N/A // process Phi nodes from the deferred list, they may not have
0N/A while(_deferred.size() > 0) {
0N/A Node * n = _deferred.pop();
0N/A PhiNode * phi = n->as_Phi();
0N/A
0N/A process_phi_escape(phi, igvn);
0N/A }
0N/A
0N/A VectorSet ptset(Thread::current()->resource_area());
0N/A
0N/A // remove deferred edges from the graph and collect
0N/A // information we will need for type splitting
0N/A for (uint ni = 0; ni < (uint)_nodes->length(); ni++) {
0N/A PointsToNode * ptn = _nodes->adr_at(ni);
0N/A PointsToNode::NodeType nt = ptn->node_type();
0N/A
0N/A if (nt == PointsToNode::UnknownType) {
0N/A continue; // not a node we are interested in
0N/A }
0N/A Node *n = ptn->_node;
0N/A if (nt == PointsToNode::LocalVar || nt == PointsToNode::Field) {
0N/A remove_deferred(ni);
0N/A if (n->is_AddP()) {
0N/A // if this AddP computes an address which may point to more that one
0N/A // object, nothing the address points to can be a unique type.
0N/A Node *base = n->in(AddPNode::Base);
0N/A ptset.Clear();
0N/A PointsTo(ptset, base, igvn);
0N/A if (ptset.Size() > 1) {
0N/A for( VectorSetI j(&ptset); j.test(); ++j ) {
0N/A PointsToNode *ptaddr = _nodes->adr_at(j.elem);
0N/A ptaddr->_unique_type = false;
0N/A }
0N/A }
0N/A }
0N/A } else if (n->is_Call()) {
0N/A // initialize _escape_state of calls to GlobalEscape
0N/A n->as_Call()->_escape_state = PointsToNode::GlobalEscape;
0N/A // push call on alloc_worlist (alocations are calls)
0N/A // for processing by split_unique_types()
0N/A alloc_worklist.push(n);
0N/A }
0N/A }
0N/A // push all GlobalEscape nodes on the worklist
0N/A for (uint nj = 0; nj < (uint)_nodes->length(); nj++) {
0N/A if (_nodes->at(nj).escape_state() == PointsToNode::GlobalEscape) {
0N/A worklist.append(nj);
0N/A }
0N/A }
0N/A // mark all node reachable from GlobalEscape nodes
0N/A while(worklist.length() > 0) {
0N/A PointsToNode n = _nodes->at(worklist.pop());
0N/A for (uint ei = 0; ei < n.edge_count(); ei++) {
0N/A uint npi = n.edge_target(ei);
0N/A PointsToNode *np = ptnode_adr(npi);
0N/A if (np->escape_state() != PointsToNode::GlobalEscape) {
0N/A np->set_escape_state(PointsToNode::GlobalEscape);
0N/A worklist.append_if_missing(npi);
0N/A }
0N/A }
0N/A }
0N/A
0N/A // push all ArgEscape nodes on the worklist
0N/A for (uint nk = 0; nk < (uint)_nodes->length(); nk++) {
0N/A if (_nodes->at(nk).escape_state() == PointsToNode::ArgEscape)
0N/A worklist.push(nk);
0N/A }
0N/A // mark all node reachable from ArgEscape nodes
0N/A while(worklist.length() > 0) {
0N/A PointsToNode n = _nodes->at(worklist.pop());
0N/A
0N/A for (uint ei = 0; ei < n.edge_count(); ei++) {
0N/A uint npi = n.edge_target(ei);
0N/A PointsToNode *np = ptnode_adr(npi);
0N/A if (np->escape_state() != PointsToNode::ArgEscape) {
0N/A np->set_escape_state(PointsToNode::ArgEscape);
0N/A worklist.append_if_missing(npi);
0N/A }
0N/A }
0N/A }
0N/A _collecting = false;
0N/A
0N/A // Now use the escape information to create unique types for
0N/A // unescaped objects
0N/A split_unique_types(alloc_worklist);
0N/A}
0N/A
0N/ANode * ConnectionGraph::skip_casts(Node *n) {
0N/A while(n->Opcode() == Op_CastPP || n->Opcode() == Op_CheckCastPP) {
0N/A n = n->in(1);
0N/A }
0N/A return n;
0N/A}
0N/A
0N/Avoid ConnectionGraph::process_phi_escape(PhiNode *phi, PhaseTransform *phase) {
0N/A
0N/A if (phi->type()->isa_oopptr() == NULL)
0N/A return; // nothing to do if not an oop
0N/A
0N/A PointsToNode *ptadr = ptnode_adr(phi->_idx);
0N/A int incount = phi->req();
0N/A int non_null_inputs = 0;
0N/A
0N/A for (int i = 1; i < incount ; i++) {
0N/A if (phi->in(i) != NULL)
0N/A non_null_inputs++;
0N/A }
0N/A if (non_null_inputs == ptadr->_inputs_processed)
0N/A return; // no new inputs since the last time this node was processed,
0N/A // the current information is valid
0N/A
0N/A ptadr->_inputs_processed = non_null_inputs; // prevent recursive processing of this node
0N/A for (int j = 1; j < incount ; j++) {
0N/A Node * n = phi->in(j);
0N/A if (n == NULL)
0N/A continue; // ignore NULL
0N/A n = skip_casts(n);
0N/A if (n->is_top() || n == phi)
0N/A continue; // ignore top or inputs which go back this node
0N/A int nopc = n->Opcode();
0N/A PointsToNode npt = _nodes->at(n->_idx);
0N/A if (_nodes->at(n->_idx).node_type() == PointsToNode::JavaObject) {
0N/A add_pointsto_edge(phi->_idx, n->_idx);
0N/A } else {
0N/A add_deferred_edge(phi->_idx, n->_idx);
0N/A }
0N/A }
0N/A}
0N/A
0N/Avoid ConnectionGraph::process_call_arguments(CallNode *call, PhaseTransform *phase) {
0N/A
0N/A _processed.set(call->_idx);
0N/A switch (call->Opcode()) {
0N/A
0N/A // arguments to allocation and locking don't escape
0N/A case Op_Allocate:
0N/A case Op_AllocateArray:
0N/A case Op_Lock:
0N/A case Op_Unlock:
0N/A break;
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();
0N/A if (meth != NULL) {
0N/A const TypeTuple * d = call->tf()->domain();
0N/A BCEscapeAnalyzer call_analyzer(meth);
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 int k = i - TypeFunc::Parms;
0N/A
0N/A if (at->isa_oopptr() != NULL) {
0N/A Node *arg = skip_casts(call->in(i));
0N/A
0N/A if (!call_analyzer.is_arg_stack(k)) {
0N/A // The argument global escapes, mark everything it could point to
0N/A ptset.Clear();
0N/A PointsTo(ptset, arg, phase);
0N/A for( VectorSetI j(&ptset); j.test(); ++j ) {
0N/A uint pt = j.elem;
0N/A
0N/A set_escape_state(pt, PointsToNode::GlobalEscape);
0N/A }
0N/A } else if (!call_analyzer.is_arg_local(k)) {
0N/A // The argument itself doesn't escape, but any fields might
0N/A ptset.Clear();
0N/A PointsTo(ptset, arg, phase);
0N/A for( VectorSetI j(&ptset); j.test(); ++j ) {
0N/A uint pt = j.elem;
0N/A add_edge_from_fields(pt, _phantom_object, Type::OffsetBot);
0N/A }
0N/A }
0N/A }
0N/A }
0N/A call_analyzer.copy_dependencies(C()->dependencies());
0N/A break;
0N/A }
0N/A // fall-through if not a Java method
0N/A }
0N/A
0N/A default:
0N/A // 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
0N/A if (at->isa_oopptr() != NULL) {
0N/A Node *arg = skip_casts(call->in(i));
0N/A ptset.Clear();
0N/A PointsTo(ptset, arg, phase);
0N/A for( VectorSetI j(&ptset); j.test(); ++j ) {
0N/A uint pt = j.elem;
0N/A
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) {
0N/A CallNode *call = resproj->in(0)->as_Call();
0N/A
0N/A PointsToNode *ptadr = ptnode_adr(resproj->_idx);
0N/A
0N/A ptadr->_node = resproj;
0N/A ptadr->set_node_type(PointsToNode::LocalVar);
0N/A set_escape_state(resproj->_idx, PointsToNode::UnknownEscape);
0N/A _processed.set(resproj->_idx);
0N/A
0N/A switch (call->Opcode()) {
0N/A case Op_Allocate:
0N/A {
0N/A Node *k = call->in(AllocateNode::KlassNode);
0N/A const TypeKlassPtr *kt;
0N/A if (k->Opcode() == Op_LoadKlass) {
0N/A kt = k->as_Load()->type()->isa_klassptr();
0N/A } else {
0N/A kt = k->as_Type()->type()->isa_klassptr();
0N/A }
0N/A assert(kt != NULL, "TypeKlassPtr required.");
0N/A ciKlass* cik = kt->klass();
0N/A ciInstanceKlass* ciik = cik->as_instance_klass();
0N/A
0N/A PointsToNode *ptadr = ptnode_adr(call->_idx);
0N/A ptadr->set_node_type(PointsToNode::JavaObject);
0N/A if (cik->is_subclass_of(_compile->env()->Thread_klass()) || ciik->has_finalizer()) {
0N/A set_escape_state(call->_idx, PointsToNode::GlobalEscape);
0N/A add_pointsto_edge(resproj->_idx, _phantom_object);
0N/A } else {
0N/A set_escape_state(call->_idx, PointsToNode::NoEscape);
0N/A add_pointsto_edge(resproj->_idx, call->_idx);
0N/A }
0N/A _processed.set(call->_idx);
0N/A break;
0N/A }
0N/A
0N/A case Op_AllocateArray:
0N/A {
0N/A PointsToNode *ptadr = ptnode_adr(call->_idx);
0N/A ptadr->set_node_type(PointsToNode::JavaObject);
0N/A set_escape_state(call->_idx, PointsToNode::NoEscape);
0N/A _processed.set(call->_idx);
0N/A add_pointsto_edge(resproj->_idx, call->_idx);
0N/A break;
0N/A }
0N/A
0N/A case Op_Lock:
0N/A case Op_Unlock:
0N/A break;
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 {
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.
0N/A if (ret_type == NULL || ret_type->isa_ptr() == NULL)
0N/A break; // doesn't return a pointer type
0N/A
0N/A ciMethod *meth = call->as_CallJava()->method();
0N/A if (meth == NULL) {
0N/A // not a Java method, assume global escape
0N/A set_escape_state(call->_idx, PointsToNode::GlobalEscape);
0N/A if (resproj != NULL)
0N/A add_pointsto_edge(resproj->_idx, _phantom_object);
0N/A } else {
0N/A BCEscapeAnalyzer call_analyzer(meth);
0N/A VectorSet ptset(Thread::current()->resource_area());
0N/A
0N/A if (call_analyzer.is_return_local() && resproj != NULL) {
0N/A // determine whether any arguments are returned
0N/A const TypeTuple * d = call->tf()->domain();
0N/A set_escape_state(call->_idx, PointsToNode::NoEscape);
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) {
0N/A Node *arg = skip_casts(call->in(i));
0N/A
0N/A if (call_analyzer.is_arg_returned(i - TypeFunc::Parms)) {
0N/A PointsToNode *arg_esp = _nodes->adr_at(arg->_idx);
0N/A if (arg_esp->node_type() == PointsToNode::JavaObject)
0N/A add_pointsto_edge(resproj->_idx, arg->_idx);
0N/A else
0N/A add_deferred_edge(resproj->_idx, arg->_idx);
0N/A arg_esp->_hidden_alias = true;
0N/A }
0N/A }
0N/A }
0N/A } else {
0N/A set_escape_state(call->_idx, PointsToNode::GlobalEscape);
0N/A if (resproj != NULL)
0N/A add_pointsto_edge(resproj->_idx, _phantom_object);
0N/A }
0N/A call_analyzer.copy_dependencies(C()->dependencies());
0N/A }
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
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) {
0N/A PointsToNode *ptadr = ptnode_adr(call->_idx);
0N/A ptadr->set_node_type(PointsToNode::JavaObject);
0N/A set_escape_state(call->_idx, PointsToNode::GlobalEscape);
0N/A if (resproj != NULL)
0N/A add_pointsto_edge(resproj->_idx, _phantom_object);
0N/A }
0N/A }
0N/A }
0N/A }
0N/A}
0N/A
0N/Avoid ConnectionGraph::record_for_escape_analysis(Node *n) {
0N/A if (_collecting) {
0N/A if (n->is_Phi()) {
0N/A PhiNode *phi = n->as_Phi();
0N/A const Type *pt = phi->type();
0N/A if ((pt->isa_oopptr() != NULL) || pt == TypePtr::NULL_PTR) {
0N/A PointsToNode *ptn = ptnode_adr(phi->_idx);
0N/A ptn->set_node_type(PointsToNode::LocalVar);
0N/A ptn->_node = n;
0N/A _deferred.push(n);
0N/A }
0N/A }
0N/A }
0N/A}
0N/A
0N/Avoid ConnectionGraph::record_escape_work(Node *n, PhaseTransform *phase) {
0N/A
0N/A int opc = n->Opcode();
0N/A PointsToNode *ptadr = ptnode_adr(n->_idx);
0N/A
0N/A if (_processed.test(n->_idx))
0N/A return;
0N/A
0N/A ptadr->_node = n;
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
0N/A switch (opc) {
0N/A case Op_AddP:
0N/A {
0N/A Node *base = skip_casts(n->in(AddPNode::Base));
0N/A ptadr->set_node_type(PointsToNode::Field);
0N/A
0N/A // create a field edge to this node from everything adr could point to
0N/A VectorSet ptset(Thread::current()->resource_area());
0N/A PointsTo(ptset, base, phase);
0N/A for( VectorSetI i(&ptset); i.test(); ++i ) {
0N/A uint pt = i.elem;
0N/A add_field_edge(pt, n->_idx, type_to_offset(phase->type(n)));
0N/A }
0N/A break;
0N/A }
0N/A case Op_Parm:
0N/A {
0N/A ProjNode *nproj = n->as_Proj();
0N/A uint con = nproj->_con;
0N/A if (con < TypeFunc::Parms)
0N/A return;
0N/A const Type *t = nproj->in(0)->as_Start()->_domain->field_at(con);
0N/A if (t->isa_ptr() == NULL)
0N/A return;
0N/A ptadr->set_node_type(PointsToNode::JavaObject);
0N/A if (t->isa_oopptr() != NULL) {
0N/A set_escape_state(n->_idx, PointsToNode::ArgEscape);
0N/A } else {
0N/A // this must be the incoming state of an OSR compile, we have to assume anything
0N/A // passed in globally escapes
0N/A assert(_compile->is_osr_compilation(), "bad argument type for non-osr compilation");
0N/A set_escape_state(n->_idx, PointsToNode::GlobalEscape);
0N/A }
0N/A _processed.set(n->_idx);
0N/A break;
0N/A }
0N/A case Op_Phi:
0N/A {
0N/A PhiNode *phi = n->as_Phi();
0N/A if (phi->type()->isa_oopptr() == NULL)
0N/A return; // nothing to do if not an oop
0N/A ptadr->set_node_type(PointsToNode::LocalVar);
0N/A process_phi_escape(phi, phase);
0N/A break;
0N/A }
0N/A case Op_CreateEx:
0N/A {
0N/A // assume that all exception objects globally escape
0N/A ptadr->set_node_type(PointsToNode::JavaObject);
0N/A set_escape_state(n->_idx, PointsToNode::GlobalEscape);
0N/A _processed.set(n->_idx);
0N/A break;
0N/A }
0N/A case Op_ConP:
0N/A {
0N/A const Type *t = phase->type(n);
0N/A ptadr->set_node_type(PointsToNode::JavaObject);
0N/A // assume all pointer constants globally escape except for null
0N/A if (t == TypePtr::NULL_PTR)
0N/A set_escape_state(n->_idx, PointsToNode::NoEscape);
0N/A else
0N/A set_escape_state(n->_idx, PointsToNode::GlobalEscape);
0N/A _processed.set(n->_idx);
0N/A break;
0N/A }
0N/A case Op_LoadKlass:
0N/A {
0N/A ptadr->set_node_type(PointsToNode::JavaObject);
0N/A set_escape_state(n->_idx, PointsToNode::GlobalEscape);
0N/A _processed.set(n->_idx);
0N/A break;
0N/A }
0N/A case Op_LoadP:
0N/A {
0N/A const Type *t = phase->type(n);
0N/A if (!t->isa_oopptr())
0N/A return;
0N/A ptadr->set_node_type(PointsToNode::LocalVar);
0N/A set_escape_state(n->_idx, PointsToNode::UnknownEscape);
0N/A
0N/A Node *adr = skip_casts(n->in(MemNode::Address));
0N/A const Type *adr_type = phase->type(adr);
0N/A Node *adr_base = skip_casts((adr->Opcode() == Op_AddP) ? adr->in(AddPNode::Base) : adr);
0N/A
0N/A // For everything "adr" could point to, create a deferred edge from
0N/A // this node to each field with the same offset as "adr_type"
0N/A VectorSet ptset(Thread::current()->resource_area());
0N/A PointsTo(ptset, adr_base, phase);
0N/A // If ptset is empty, then this value must have been set outside
0N/A // this method, so we add the phantom node
0N/A if (ptset.Size() == 0)
0N/A ptset.set(_phantom_object);
0N/A for( VectorSetI i(&ptset); i.test(); ++i ) {
0N/A uint pt = i.elem;
0N/A add_deferred_edge_to_fields(n->_idx, pt, type_to_offset(adr_type));
0N/A }
0N/A break;
0N/A }
0N/A case Op_StoreP:
0N/A case Op_StorePConditional:
0N/A case Op_CompareAndSwapP:
0N/A {
0N/A Node *adr = n->in(MemNode::Address);
0N/A Node *val = skip_casts(n->in(MemNode::ValueIn));
0N/A const Type *adr_type = phase->type(adr);
0N/A if (!adr_type->isa_oopptr())
0N/A return;
0N/A
0N/A assert(adr->Opcode() == Op_AddP, "expecting an AddP");
0N/A Node *adr_base = adr->in(AddPNode::Base);
0N/A
0N/A // For everything "adr_base" could point to, create a deferred edge to "val" from each field
0N/A // with the same offset as "adr_type"
0N/A VectorSet ptset(Thread::current()->resource_area());
0N/A PointsTo(ptset, adr_base, phase);
0N/A for( VectorSetI i(&ptset); i.test(); ++i ) {
0N/A uint pt = i.elem;
0N/A add_edge_from_fields(pt, val->_idx, type_to_offset(adr_type));
0N/A }
0N/A break;
0N/A }
0N/A case Op_Proj:
0N/A {
0N/A ProjNode *nproj = n->as_Proj();
0N/A Node *n0 = nproj->in(0);
0N/A // we are only interested in the result projection from a call
0N/A if (nproj->_con == TypeFunc::Parms && n0->is_Call() ) {
0N/A process_call_result(nproj, phase);
0N/A }
0N/A
0N/A break;
0N/A }
0N/A case Op_CastPP:
0N/A case Op_CheckCastPP:
0N/A {
0N/A ptadr->set_node_type(PointsToNode::LocalVar);
0N/A int ti = n->in(1)->_idx;
0N/A if (_nodes->at(ti).node_type() == PointsToNode::JavaObject) {
0N/A add_pointsto_edge(n->_idx, ti);
0N/A } else {
0N/A add_deferred_edge(n->_idx, ti);
0N/A }
0N/A break;
0N/A }
0N/A default:
0N/A ;
0N/A // nothing to do
0N/A }
0N/A}
0N/A
0N/Avoid ConnectionGraph::record_escape(Node *n, PhaseTransform *phase) {
0N/A if (_collecting)
0N/A record_escape_work(n, phase);
0N/A}
0N/A
0N/A#ifndef PRODUCT
0N/Avoid ConnectionGraph::dump() {
0N/A PhaseGVN *igvn = _compile->initial_gvn();
0N/A bool first = true;
0N/A
0N/A for (uint ni = 0; ni < (uint)_nodes->length(); ni++) {
0N/A PointsToNode *esp = _nodes->adr_at(ni);
0N/A if (esp->node_type() == PointsToNode::UnknownType || esp->_node == NULL)
0N/A continue;
0N/A PointsToNode::EscapeState es = escape_state(esp->_node, igvn);
0N/A if (es == PointsToNode::NoEscape || (Verbose &&
0N/A (es != PointsToNode::UnknownEscape || esp->edge_count() != 0))) {
0N/A // don't print null pointer node which almost every method has
0N/A if (esp->_node->Opcode() != Op_ConP || igvn->type(esp->_node) != TypePtr::NULL_PTR) {
0N/A if (first) {
0N/A tty->print("======== Connection graph for ");
0N/A C()->method()->print_short_name();
0N/A tty->cr();
0N/A first = false;
0N/A }
0N/A tty->print("%4d ", ni);
0N/A esp->dump();
0N/A }
0N/A }
0N/A }
0N/A}
0N/A#endif