escape.hpp revision 3619
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * This code is free software; you can redistribute it and/or modify it
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * under the terms of the GNU General Public License version 2 only, as
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * published by the Free Software Foundation.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * This code is distributed in the hope that it will be useful, but WITHOUT
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * version 2 for more details (a copy is included in the LICENSE file that
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * accompanied this code).
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * You should have received a copy of the GNU General Public License version
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * 2 along with this work; if not, write to the Free Software Foundation,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * or visit www.oracle.com if you need additional information or have any
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * questions.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
c586600796766c83eb9485c446886fd9ed2359a9Keyur Desai */
68b2bbf26c7040fea4281dcb58b81e7627e46f34Gordon Ross
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#ifndef SHARE_VM_OPTO_ESCAPE_HPP
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define SHARE_VM_OPTO_ESCAPE_HPP
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include "opto/addnode.hpp"
3db3f65c6274eb042354801a308c8e9bc4994553amw#include "opto/node.hpp"
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown#include "utilities/growableArray.hpp"
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw//
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross// Adaptation for C2 of the escape analysis algorithm described in:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw//
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw// [Choi99] Jong-Deok Shoi, Manish Gupta, Mauricio Seffano,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw// Vugranam C. Sreedhar, Sam Midkiff,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw// "Escape Analysis for Java", Procedings of ACM SIGPLAN
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw// OOPSLA Conference, November 1, 1999
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw//
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw// The flow-insensitive analysis described in the paper has been implemented.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw//
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw// The analysis requires construction of a "connection graph" (CG) for
b1352070d318187b41b088da3533692976f3f225Alan Wright// the method being analyzed. The nodes of the connection graph are:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw//
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw// - Java objects (JO)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw// - Local variables (LV)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw// - Fields of an object (OF), these also include array elements
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw//
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw// The CG contains 3 types of edges:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw//
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States// - PointsTo (-P>) {LV, OF} to JO
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States// - Deferred (-D>) from {LV, OF} to {LV, OF}
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States// - Field (-F>) from JO to OF
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw//
7b59d02d2a384be9a08087b14defadd214b3c1ddjb// The following utility functions is used by the algorithm:
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb//
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb// PointsTo(n) - n is any CG node, it returns the set of JO that n could
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb// point to.
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb//
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb// The algorithm describes how to construct the connection graph
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb// in the following 4 cases:
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb//
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb// Case Edges Created
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb//
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb// (1) p = new T() LV -P> JO
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb// (2) p = q LV -D> LV
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb// (3) p.f = q JO -F> OF, OF -D> LV
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb// (4) p = q.f JO -F> OF, LV -D> OF
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb//
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw// In all these cases, p and q are local variables. For static field
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw// references, we can construct a local variable containing a reference
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw// to the static memory.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw//
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw// C2 does not have local variables. However for the purposes of constructing
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw// the connection graph, the following IR nodes are treated as local variables:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw// Phi (pointer values)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw// LoadP, LoadN
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw// Proj#5 (value returned from callnodes including allocations)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw// CheckCastPP, CastPP
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross//
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross// The LoadP, Proj and CheckCastPP behave like variables assigned to only once.
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross// Only a Phi can have multiple assignments. Each input to a Phi is treated
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross// as an assignment to it.
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross//
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw// The following node types are JavaObject:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw//
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw// phantom_object (general globally escaped object)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw// Allocate
7b59d02d2a384be9a08087b14defadd214b3c1ddjb// AllocateArray
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb// Parm (for incoming arguments)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw// CastX2P ("unsafe" operations)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw// CreateEx
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw// ConP
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw// LoadKlass
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as// ThreadLocal
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb// CallStaticJava (which returns Object)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw//
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw// AddP nodes are fields.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw//
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw// After building the graph, a pass is made over the nodes, deleting deferred
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw// nodes and copying the edges from the target of the deferred edge to the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw// source. This results in a graph with no deferred edges, only:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw//
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw// LV -P> JO
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw// OF -P> JO (the object whose oop is stored in the field)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw// JO -F> OF
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb//
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw// Then, for each node which is GlobalEscape, anything it could point to
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw// is marked GlobalEscape. Finally, for any node marked ArgEscape, anything
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States// it could point to is marked ArgEscape.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw//
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwclass Compile;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwclass Node;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwclass CallNode;
7f3ef643e446c82e27a9386991b140b128baf22cGordon Rossclass PhiNode;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwclass PhaseTransform;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwclass PointsToNode;
dc20a3024900c47dd2ee44b9707e6df38f7d62a5asclass Type;
faa1795a28a5c712eed6d0a3f84d98c368a316c6jbclass TypePtr;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwclass VectorSet;
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwclass JavaObjectNode;
dc20a3024900c47dd2ee44b9707e6df38f7d62a5asclass LocalVarNode;
faa1795a28a5c712eed6d0a3f84d98c368a316c6jbclass FieldNode;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwclass ArraycopyNode;
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw// ConnectionGraph nodes
dc20a3024900c47dd2ee44b9707e6df38f7d62a5asclass PointsToNode : public ResourceObj {
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb GrowableArray<PointsToNode*> _edges; // List of nodes this node points to
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw GrowableArray<PointsToNode*> _uses; // List of nodes which point to this node
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw const u1 _type; // NodeType
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw u1 _flags; // NodeFlags
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw u1 _escape; // EscapeState of object
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw u1 _fields_escape; // EscapeState of object's fields
ccc71be50bb49efb4e31004c77fb3e065e9c0596Gordon Ross
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb Node* const _node; // Ideal node corresponding to this PointsTo node.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw const int _idx; // Cached ideal node's _idx
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwpublic:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw typedef enum {
7b59d02d2a384be9a08087b14defadd214b3c1ddjb UnknownType = 0,
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb JavaObject = 1,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw LocalVar = 2,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw Field = 3,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw Arraycopy = 4
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw } NodeType;
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb typedef enum {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw UnknownEscape = 0,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw NoEscape = 1, // An object does not escape method or thread and it is
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw // not passed to call. It could be replaced with scalar.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ArgEscape = 2, // An object does not escape method or thread but it is
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw // passed as argument to call or referenced by argument
7b59d02d2a384be9a08087b14defadd214b3c1ddjb // and it does not escape during call.
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb GlobalEscape = 3 // An object escapes the method or thread.
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb } EscapeState;
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb typedef enum {
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb ScalarReplaceable = 1, // Not escaped object could be replaced with scalar
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb PointsToUnknown = 2, // Has edge to phantom_object
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb ArraycopySrc = 4, // Has edge from Arraycopy node
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb ArraycopyDst = 8 // Has edge to Arraycopy node
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb } NodeFlags;
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb PointsToNode(Compile *C, Node* n, EscapeState es, NodeType type):
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb _edges(C->comp_arena(), 2, 0, NULL),
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb _uses (C->comp_arena(), 2, 0, NULL),
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw _node(n),
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw _idx(n->_idx),
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw _type((u1)type),
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw _escape((u1)es),
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw _fields_escape((u1)es),
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw _flags(ScalarReplaceable) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw assert(n != NULL && es != UnknownEscape, "sanity");
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as }
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw Node* ideal_node() const { return _node; }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int idx() const { return _idx; }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw bool is_JavaObject() const { return _type == (u1)JavaObject; }
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as bool is_LocalVar() const { return _type == (u1)LocalVar; }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw bool is_Field() const { return _type == (u1)Field; }
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb bool is_Arraycopy() const { return _type == (u1)Arraycopy; }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw JavaObjectNode* as_JavaObject() { assert(is_JavaObject(),""); return (JavaObjectNode*)this; }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw LocalVarNode* as_LocalVar() { assert(is_LocalVar(),""); return (LocalVarNode*)this; }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw FieldNode* as_Field() { assert(is_Field(),""); return (FieldNode*)this; }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ArraycopyNode* as_Arraycopy() { assert(is_Arraycopy(),""); return (ArraycopyNode*)this; }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw EscapeState escape_state() const { return (EscapeState)_escape; }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw void set_escape_state(EscapeState state) { _escape = (u1)state; }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw EscapeState fields_escape_state() const { return (EscapeState)_fields_escape; }
7b59d02d2a384be9a08087b14defadd214b3c1ddjb void set_fields_escape_state(EscapeState state) { _fields_escape = (u1)state; }
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw bool has_unknown_ptr() const { return (_flags & PointsToUnknown) != 0; }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw void set_has_unknown_ptr() { _flags |= PointsToUnknown; }
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross bool arraycopy_src() const { return (_flags & ArraycopySrc) != 0; }
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross void set_arraycopy_src() { _flags |= ArraycopySrc; }
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross bool arraycopy_dst() const { return (_flags & ArraycopyDst) != 0; }
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross void set_arraycopy_dst() { _flags |= ArraycopyDst; }
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross bool scalar_replaceable() const { return (_flags & ScalarReplaceable) != 0;}
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross void set_scalar_replaceable(bool v) {
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross if (v)
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross _flags |= ScalarReplaceable;
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross else
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross _flags &= ~ScalarReplaceable;
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross }
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross int edge_count() const { return _edges.length(); }
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross PointsToNode* edge(int e) const { return _edges.at(e); }
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross bool add_edge(PointsToNode* edge) { return _edges.append_if_missing(edge); }
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross int use_count() const { return _uses.length(); }
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross PointsToNode* use(int e) const { return _uses.at(e); }
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross bool add_use(PointsToNode* use) { return _uses.append_if_missing(use); }
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross // Mark base edge use to distinguish from stored value edge.
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross bool add_base_use(FieldNode* use) { return _uses.append_if_missing((PointsToNode*)((intptr_t)use + 1)); }
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross static bool is_base_use(PointsToNode* use) { return (((intptr_t)use) & 1); }
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross static PointsToNode* get_use_node(PointsToNode* use) { return (PointsToNode*)(((intptr_t)use) & ~1); }
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross // Return true if this node points to specified node or nodes it points to.
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross bool points_to(JavaObjectNode* ptn) const;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross // Return true if this node points only to non-escaping allocations.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw bool non_escaping_allocation();
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as // Return true if one node points to an other.
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb bool meet(PointsToNode* ptn);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross#ifndef PRODUCT
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw NodeType node_type() const { return (NodeType)_type;}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw void dump(bool print_state=true) const;
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as#endif
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw};
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwclass LocalVarNode: public PointsToNode {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwpublic:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw LocalVarNode(Compile *C, Node* n, EscapeState es):
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw PointsToNode(C, n, es, LocalVar) {}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw};
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwclass JavaObjectNode: public PointsToNode {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwpublic:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw JavaObjectNode(Compile *C, Node* n, EscapeState es):
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw PointsToNode(C, n, es, JavaObject) {
7b59d02d2a384be9a08087b14defadd214b3c1ddjb if (es > NoEscape)
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb set_scalar_replaceable(false);
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb }
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb};
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb
faa1795a28a5c712eed6d0a3f84d98c368a316c6jbclass FieldNode: public PointsToNode {
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb GrowableArray<PointsToNode*> _bases; // List of JavaObject nodes which point to this node
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb const int _offset; // Field's offset.
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb const bool _is_oop; // Field points to object
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb bool _has_unknown_base; // Has phantom_object base
faa1795a28a5c712eed6d0a3f84d98c368a316c6jbpublic:
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb FieldNode(Compile *C, Node* n, EscapeState es, int offs, bool is_oop):
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb PointsToNode(C, n, es, Field),
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb _offset(offs), _is_oop(is_oop),
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb _has_unknown_base(false) {}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int offset() const { return _offset;}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw bool is_oop() const { return _is_oop;}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw bool has_unknown_base() const { return _has_unknown_base; }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw void set_has_unknown_base() { _has_unknown_base = true; }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int base_count() const { return _bases.length(); }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw PointsToNode* base(int e) const { return _bases.at(e); }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw bool add_base(PointsToNode* base) { return _bases.append_if_missing(base); }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#ifdef ASSERT
7b59d02d2a384be9a08087b14defadd214b3c1ddjb // Return true if bases points to this java object.
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb bool has_base(JavaObjectNode* ptn) const;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#endif
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw};
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
faa1795a28a5c712eed6d0a3f84d98c368a316c6jbclass ArraycopyNode: public PointsToNode {
faa1795a28a5c712eed6d0a3f84d98c368a316c6jbpublic:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ArraycopyNode(Compile *C, Node* n, EscapeState es):
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb PointsToNode(C, n, es, Arraycopy) {}
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb};
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb// Iterators for PointsTo node's edges:
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb// for (EdgeIterator i(n); i.has_next(); i.next()) {
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb// PointsToNode* u = i.get();
faa1795a28a5c712eed6d0a3f84d98c368a316c6jbclass PointsToIterator: public StackObj {
faa1795a28a5c712eed6d0a3f84d98c368a316c6jbprotected:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw const PointsToNode* node;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw const int cnt;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb int i;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwpublic:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw inline PointsToIterator(const PointsToNode* n, int cnt) : node(n), cnt(cnt), i(0) { }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw inline bool has_next() const { return i < cnt; }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw inline void next() { i++; }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw PointsToNode* get() const { ShouldNotCallThis(); return NULL; }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw};
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwclass EdgeIterator: public PointsToIterator {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwpublic:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw inline EdgeIterator(const PointsToNode* n) : PointsToIterator(n, n->edge_count()) { }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw inline PointsToNode* get() const { return node->edge(i); }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw};
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwclass UseIterator: public PointsToIterator {
7b59d02d2a384be9a08087b14defadd214b3c1ddjbpublic:
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb inline UseIterator(const PointsToNode* n) : PointsToIterator(n, n->use_count()) { }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw inline PointsToNode* get() const { return node->use(i); }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw};
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwclass BaseIterator: public PointsToIterator {
dc20a3024900c47dd2ee44b9707e6df38f7d62a5aspublic:
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb inline BaseIterator(const FieldNode* n) : PointsToIterator(n, n->base_count()) { }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw inline PointsToNode* get() const { return ((PointsToNode*)node)->as_Field()->base(i); }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw};
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwclass ConnectionGraph: public ResourceObj {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwprivate:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw GrowableArray<PointsToNode*> _nodes; // Map from ideal nodes to
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross // ConnectionGraph nodes.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw GrowableArray<PointsToNode*> _worklist; // Nodes to be processed
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb bool _collecting; // Indicates whether escape information
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw // is still being collected. If false,
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross // no new nodes will be processed.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as bool _verify; // verify graph
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw JavaObjectNode* phantom_obj; // Unknown object
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross JavaObjectNode* null_obj;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw Node* _pcmp_neq; // ConI(#CC_GT)
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as Node* _pcmp_eq; // ConI(#CC_EQ)
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw Compile* _compile; // Compile object for current compilation
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw PhaseIterGVN* _igvn; // Value numbering
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw Unique_Node_List ideal_nodes; // Used by CG construction and types splitting.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw // Address of an element in _nodes. Used when the element is to be modified
ccc71be50bb49efb4e31004c77fb3e065e9c0596Gordon Ross PointsToNode* ptnode_adr(int idx) const {
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb // There should be no new ideal nodes during ConnectionGraph build,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw // growableArray::at() will throw assert otherwise.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return _nodes.at(idx);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw uint nodes_size() const { return _nodes.length(); }
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb // Add nodes to ConnectionGraph.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw void add_local_var(Node* n, PointsToNode::EscapeState es);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw void add_java_object(Node* n, PointsToNode::EscapeState es);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw void add_field(Node* n, PointsToNode::EscapeState es, int offset);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw void add_arraycopy(Node* n, PointsToNode::EscapeState es, PointsToNode* src, PointsToNode* dst);
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb // Compute the escape state for arguments to a call.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw void process_call_arguments(CallNode *call);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw // Add PointsToNode node corresponding to a call
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw void add_call_node(CallNode* call);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
7b59d02d2a384be9a08087b14defadd214b3c1ddjb // Map ideal node to existing PointsTo node (usually phantom_object).
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb void map_ideal_node(Node *n, PointsToNode* ptn) {
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb assert(ptn != NULL, "only existing PointsTo node");
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb _nodes.at_put(n->_idx, ptn);
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb }
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb // Create PointsToNode node and add it to Connection Graph.
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb void add_node_to_connection_graph(Node *n, Unique_Node_List *delayed_worklist);
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb // Add final simple edges to graph.
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb void add_final_edges(Node *n);
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb // Finish Graph construction.
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb bool complete_connection_graph(GrowableArray<PointsToNode*>& ptnodes_worklist,
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb GrowableArray<JavaObjectNode*>& non_escaped_worklist,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw GrowableArray<JavaObjectNode*>& java_objects_worklist,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw GrowableArray<FieldNode*>& oop_fields_worklist);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#ifdef ASSERT
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw void verify_connection_graph(GrowableArray<PointsToNode*>& ptnodes_worklist,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw GrowableArray<JavaObjectNode*>& non_escaped_worklist,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw GrowableArray<JavaObjectNode*>& java_objects_worklist,
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as GrowableArray<Node*>& addp_worklist);
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb#endif
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw // Add all references to this JavaObject node.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int add_java_object_edges(JavaObjectNode* jobj, bool populate_worklist);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as // Put node on worklist if it is (or was) not there.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw void add_to_worklist(PointsToNode* pt) {
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb _worklist.push(pt);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw // Put on worklist all uses of this node.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw void add_uses_to_worklist(PointsToNode* pt) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw for (UseIterator i(pt); i.has_next(); i.next())
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw _worklist.push(i.get());
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw // Put on worklist all field's uses and related field nodes.
7b59d02d2a384be9a08087b14defadd214b3c1ddjb void add_field_uses_to_worklist(FieldNode* field);
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw // Put on worklist all related field nodes.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw void add_fields_to_worklist(FieldNode* field, PointsToNode* base);
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross // Find fields which have unknown value.
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross int find_field_value(FieldNode* field);
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross // Find fields initializing values for allocations.
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross int find_init_values(JavaObjectNode* ptn, PointsToNode* init_val, PhaseTransform* phase);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw // Set the escape state of an object and its fields.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw void set_escape_state(PointsToNode* ptn, PointsToNode::EscapeState esc) {
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross // Don't change non-escaping state of NULL pointer.
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross if (ptn != null_obj) {
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross if (ptn->escape_state() < esc)
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross ptn->set_escape_state(esc);
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross if (ptn->fields_escape_state() < esc)
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross ptn->set_fields_escape_state(esc);
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross }
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross }
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross void set_fields_escape_state(PointsToNode* ptn, PointsToNode::EscapeState esc) {
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross // Don't change non-escaping state of NULL pointer.
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross if (ptn != null_obj) {
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross if (ptn->fields_escape_state() < esc)
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross ptn->set_fields_escape_state(esc);
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross }
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw // Propagate GlobalEscape and ArgEscape escape states to all nodes
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as // and check that we still have non-escaping java objects.
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb bool find_non_escaped_objects(GrowableArray<PointsToNode*>& ptnodes_worklist,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw GrowableArray<JavaObjectNode*>& non_escaped_worklist);
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw // Adjust scalar_replaceable state after Connection Graph is built.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw void adjust_scalar_replaceable_state(JavaObjectNode* jobj);
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb // Optimize ideal graph.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw void optimize_ideal_graph(GrowableArray<Node*>& ptr_cmp_worklist,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw GrowableArray<Node*>& storestore_worklist);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw // Optimize objects compare.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw Node* optimize_ptr_compare(Node* n);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw // Returns unique corresponding java object or NULL.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw JavaObjectNode* unique_java_object(Node *n);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw // Add an edge of the specified type pointing to the specified target.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw bool add_edge(PointsToNode* from, PointsToNode* to) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw assert(!from->is_Field() || from->as_Field()->is_oop(), "sanity");
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
7b59d02d2a384be9a08087b14defadd214b3c1ddjb if (to == phantom_obj) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (from->has_unknown_ptr()) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return false; // already points to phantom_obj
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw from->set_has_unknown_ptr();
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw bool is_new = from->add_edge(to);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw assert(to != phantom_obj || is_new, "sanity");
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb if (is_new) { // New edge?
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb assert(!_verify, "graph is incomplete");
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb is_new = to->add_use(from);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw assert(is_new, "use should be also new");
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return is_new;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw // Add an edge from Field node to its base and back.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw bool add_base(FieldNode* from, PointsToNode* to) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw assert(!to->is_Arraycopy(), "sanity");
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (to == phantom_obj) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (from->has_unknown_base()) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return false; // already has phantom_obj base
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw from->set_has_unknown_base();
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States bool is_new = from->add_base(to);
b1352070d318187b41b088da3533692976f3f225Alan Wright assert(to != phantom_obj || is_new, "sanity");
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (is_new) { // New edge?
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States assert(!_verify, "graph is incomplete");
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States if (to == null_obj)
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown return is_new; // Don't add fields to NULL pointer.
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown if (to->is_JavaObject()) {
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown is_new = to->add_edge(from);
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown } else {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw is_new = to->add_base_use(from);
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as }
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb assert(is_new, "use should be also new");
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return is_new;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw // Add LocalVar node and edge if possible
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw void add_local_var_and_edge(Node* n, PointsToNode::EscapeState es, Node* to,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw Unique_Node_List *delayed_worklist) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw PointsToNode* ptn = ptnode_adr(to->_idx);
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb if (delayed_worklist != NULL) { // First iteration of CG construction
59229f98006fc8ee5e568078d81b6ce572071e0bjose borrego add_local_var(n, es);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (ptn == NULL) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw delayed_worklist->push(n);
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb return; // Process it later.
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as }
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb } else {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw assert(ptn != NULL, "node should be registered");
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw add_edge(ptnode_adr(n->_idx), ptn);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw // Helper functions
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw bool is_oop_field(Node* n, int offset);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw static Node* get_addp_base(Node *addp);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw static Node* find_second_addp(Node* addp, Node* n);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw // offset of a field reference
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int address_offset(Node* adr, PhaseTransform *phase);
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw // Propagate unique types created for unescaped allocated objects
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw // through the graph
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw void split_unique_types(GrowableArray<Node *> &alloc_worklist);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw // Helper methods for unique types split.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw bool split_AddP(Node *addp, Node *base);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw PhiNode *create_split_phi(PhiNode *orig_phi, int alias_idx, GrowableArray<PhiNode *> &orig_phi_worklist, bool &new_created);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw PhiNode *split_memory_phi(PhiNode *orig_phi, int alias_idx, GrowableArray<PhiNode *> &orig_phi_worklist);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw void move_inst_mem(Node* n, GrowableArray<PhiNode *> &orig_phis);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb Node* find_inst_mem(Node* mem, int alias_idx,GrowableArray<PhiNode *> &orig_phi_worklist);
3db3f65c6274eb042354801a308c8e9bc4994553amw Node* step_through_mergemem(MergeMemNode *mmem, int alias_idx, const TypeOopPtr *toop);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw GrowableArray<MergeMemNode*> _mergemem_worklist; // List of all MergeMem nodes
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw Node_Array _node_map; // used for bookeeping during type splitting
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw // Used for the following purposes:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw // Memory Phi - most recent unique Phi split out
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw // from this Phi
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw // MemNode - new memory input for this node
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw // ChecCastPP - allocation that this is a cast of
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw // allocation - CheckCastPP of the allocation
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw // manage entries in _node_map
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw void set_map(Node* from, Node* to) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ideal_nodes.push(from);
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb _node_map.map(from->_idx, to);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb Node* get_map(int idx) { return _node_map[idx]; }
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb PhiNode* get_map_phi(int idx) {
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb Node* phi = _node_map[idx];
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb return (phi == NULL) ? NULL : phi->as_Phi();
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb // Notify optimizer that a node has been modified
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb void record_for_optimizer(Node *n) {
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb _igvn->_worklist.push(n);
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb _igvn->add_users_to_worklist(n);
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
7b59d02d2a384be9a08087b14defadd214b3c1ddjb // Compute the escape information
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw bool compute_escape();
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwpublic:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ConnectionGraph(Compile *C, PhaseIterGVN *igvn);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw // Check for non-escaping candidates
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw static bool has_candidates(Compile *C);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw // Perform escape analysis
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw static void do_analysis(Compile *C, PhaseIterGVN *igvn);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw bool not_global_escape(Node *n);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#ifndef PRODUCT
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw void dump(GrowableArray<PointsToNode*>& ptnodes_worklist);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#endif
7b59d02d2a384be9a08087b14defadd214b3c1ddjb};
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#endif // SHARE_VM_OPTO_ESCAPE_HPP
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw