escape.cpp revision 4049
196N/A * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 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 * 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 * 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 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 0N/A // Add unknown java object. 0N/A // Add ConP(#NULL) and ConN(#NULL) nodes. 0N/A // EA brings benefits only when the code has allocations and/or locks which 0N/A // are represented by ideal Macro nodes. 0N/A for(
int i=0; i <
cnt; i++ ) {
0N/A // Add ConP#NULL and ConN#NULL nodes before ConnectionGraph construction 244N/A // to create space for them in ConnectionGraph::_nodes[]. 244N/A // Perform escape analysis 244N/A // There are non escaping objects. 253N/A // Worklists used by EA. 0N/A // 1. Populate Connection Graph (CG) with PointsTo nodes. 0N/A // Initialize worklist 0N/A // Create PointsTo nodes and add them to Connection Graph. Called 0N/A // only once per ideal node since ideal_nodes is Unique_Node list. 65N/A // Only allocations and java static calls results are interesting. 65N/A // Collect all MergeMem nodes to add memory slices for 65N/A // scalar replaceable objects in split_unique_types(). 0N/A // Collect compare pointers nodes. 0N/A // Collect all MemBarStoreStore nodes so that depending on the 0N/A // escape status of the associated Allocate node some of them 0N/A // may be eliminated. 0N/A // Collect address nodes for graph verification. 0N/A return false;
// Nothing to do. 65N/A // Add final simple edges to graph. 65N/A // Verify that no new simple edges could be created and all 65N/A // local vars has edges. 0N/A // 2. Finish Graph construction by propagating references to all 0N/A // java objects through graph. 0N/A // All objects escaped or hit time or iterations limits. 0N/A // 3. Adjust scalar_replaceable state of nonescaping objects and push 0N/A // scalar replaceable allocations on alloc_worklist for processing 244N/A // in split_unique_types(). 244N/A // Verify that graph is complete - no new edges could be added or needed. 244N/A }
// TracePhase t3("connectionGraph") 0N/A // 4. Optimize ideal graph based on EA information. 244N/A // 5. Separate memory graph for scalar replaceable allcations. 244N/A // Now use the escape information to create unique types for 244N/A // scalar replaceable objects. 244N/A tty->
print(
" since there are no scalar replaceable candidates ===");
101N/A// Utility function for nodes that load an object 244N/A // Using isa_ptr() instead of isa_oopptr() for LoadP and Phi because 0N/A // ThreadLocal has RawPtr type. 101N/A// Populate Connection Graph with PointsTo nodes and create simple 101N/A// connection graph edges. 244N/A return;
// No need to redefine PointsTo node during first iteration. 244N/A // Arguments to allocation and locking don't escape. 244N/A // Put Lock and Unlock nodes on IGVN worklist to process them during 244N/A // first IGVN optimization when escape information is still available. 0N/A return;
// Skip uncommon traps 0N/A // Don't mark as processed since call's arguments have to be processed. 0N/A // Check if a call returns an object. 244N/A // Put this check here to process call arguments since some call nodes 244N/A // point to phantom_obj. 244N/A return;
// Skip predefined nodes. 0N/A // Field nodes are created for all field types. They are used in 0N/A // adjust_scalar_replaceable_state() and split_unique_types(). 0N/A // Note, non-oop fields will have only base edges in Connection 0N/A // Graph because such fields are not used for oop loads and stores. 65N/A // Do not add edges during first iteration because some could be 65N/A // not defined yet. 65N/A // assume all oop constants globally escape except for null 65N/A // assume that all exception objects globally escape 65N/A // Unknown class is loaded 65N/A // Produces Null or notNull and is used in only in CmpP so 77N/A // phantom_obj could be used. 65N/A // Using isa_ptr() instead of isa_oopptr() for LoadP and Phi because 65N/A // ThreadLocal has RawPtr type. 77N/A // Do not add edges during first iteration because some could be 77N/A // not defined yet. 164N/A // we are only interested in the oop result projection from a call 65N/A // Treat Return value as LocalVar with GlobalEscape escape state. 65N/A // Verify a raw address for a store captured by Initialize node. 65N/A // Ignore copy the displaced header to the BoxNode (OSR compilation). 65N/A // Stored value escapes in unsafe access. 65N/A // Pointer stores in G1 barriers looks like unsafe access. 65N/A // Ignore such stores to be able scalar replace non-escaping 65N/A break;
// G1 pre barier previous oop value store. 65N/A break;
// G1 post barier card address store. 0N/A assert(
false,
"not unsafe or G1 barrier raw StoreP");
253N/A ;
// Do nothing for nodes not related to EA. 253N/A /* Should not be called for not pointer type. */ \
0N/A// Add final simple edges to graph. 0N/A return;
// This method does not change graph for JavaObject. 0N/A "node should be registered already");
0N/A continue;
// ignore NULL 0N/A continue;
// ignore top or inputs which go back this node 0N/A // Using isa_ptr() instead of isa_oopptr() for LoadP and Phi because 0N/A // ThreadLocal has RawPtr type. 65N/A // Using isa_ptr() instead of isa_oopptr() for LoadP and Phi because 0N/A // ThreadLocal has RawPtr type. 65N/A continue;
// ignore NULL 0N/A continue;
// ignore top or inputs which go back this node 0N/A // we are only interested in the oop result projection from a call 0N/A // Treat Return value as LocalVar with GlobalEscape escape state. 65N/A // Point Address to Value 223N/A // Stored value escapes in unsafe access. 65N/A // Add edge to object for unsafe access with offset. 65N/A // char[] arrays passed to string intrinsic do not escape but 65N/A // they are not scalar replaceable. Adjust escape state for them. 65N/A // Start from in(2) edge since in(1) is memory edge. 65N/A // This method should be called only for EA specific nodes which may 65N/A // miss some edges when they were created. 247N/A // Not scalar replaceable if the length is not constant or too big. 247N/A }
else {
// Allocate instance 0N/A // Call nodes could be different types: 0N/A // 1. CallDynamicJavaNode (what happened during call is unknown): 0N/A // - mapped to GlobalEscape JavaObject node if oop is returned; 0N/A // - all oop arguments are escaping globally; 0N/A // 2. CallStaticJavaNode (execute bytecode analysis if possible): 0N/A // - the same as CallDynamicJavaNode if can't do bytecode analysis; 0N/A // - mapped to GlobalEscape JavaObject node if unknown oop is returned; 0N/A // - mapped to NoEscape JavaObject node if non-escaping object allocated 0N/A // during call is returned; 0N/A // - mapped to ArgEscape LocalVar node pointed to object arguments 0N/A // which are returned and does not escape during call; 0N/A // - oop arguments escaping status is defined by bytecode analysis; 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 // Returns a newly allocated unescaped object. 0N/A // Returns a newly allocated unescaped object, simply 0N/A // update dependency information. 0N/A // Mark it as NoEscape so that objects referenced by 0N/A // it's fields will be marked as NoEscape at least. 0N/A // Determine whether any arguments are returned. 0N/A // Returns unknown object. 0N/A // An other type of call, assume the worst case: 0N/A // returned value is unknown and globally escapes. 0N/A // Stub calls, objects do not escape but they are not scale replaceable. 0N/A // Adjust escape state for outgoing arguments. 65N/A // The inline_native_clone() case when the arraycopy stub is called 65N/A // after the allocation before Initialize and CheckCastPP nodes. 65N/A // Or normal arraycopy for object arrays case. 244N/A // Set AddP's base (Allocate) as not scalar replaceable since 244N/A // pointer to the base (with offset) is passed as argument. 39N/A // src or dst could be j.l.Object when other is basic type array: 39N/A // arraycopy(char[],0,Object*,0,size); 65N/A // arraycopy(Object*,0,char[],0,size); 65N/A // Don't add edges in such cases. 65N/A // Always process arraycopy's destination object since 65N/A // we need to add all possible edges to references in 65N/A // Special arraycopy edge: 65N/A // A destination object's field can't have the source object 0N/A // as base since objects escape states are not related. 0N/A // Only escape state of destination object's fields affects 65N/A // escape state of fields in source object. 65N/A // For a static call, we know exactly what method is being called. 65N/A // Use bytecode estimator to record the call's escape affects 163N/A // fall-through if not a Java method or no analyzer information 65N/A // The call returns arguments. 65N/A // The argument global escapes 65N/A // The argument itself doesn't escape, but any fields might 0N/A // The call returns arguments. 65N/A // Returns also unknown object. 65N/A // Fall-through here if not a Java method or no analyzer information 0N/A // or some other type of call, assume the worst case: all arguments 223N/A// Finish Graph construction. 223N/A // Normally only 1-3 passes needed to build Connection Graph depending 163N/A // Set limit to 20 to catch situation when something did go wrong and 163N/A // bailout Escape Analysis. 163N/A // Also limit build time to 30 sec (60 in debug VM). 0N/A // Propagate GlobalEscape and ArgEscape escape states and check that 0N/A // we still have non-escaping objects. The method pushs on _worklist 0N/A // Field nodes which reference phantom_object. 0N/A return false;
// Nothing to do. 0N/A // Now propagate references to all JavaObject nodes. 65N/A // Propagate references to phantom_object for nodes pushed on _worklist 253N/A // by find_non_escaped_objects() and find_field_value(). 65N/A // Update escape states on each iteration if graph was updated. 65N/A return false;
// Nothing to do. 65N/A // Find fields which have unknown value. 65N/A // This code may added new edges to phantom_object. 0N/A // Need an other cycle to propagate references to phantom_object. 0N/A // Bailout if passed limits. 0N/A // Possible infinite build_connection_graph loop, 0N/A // bailout (no changes to ideal graph were made). 0N/A tty->
print_cr(
"EA: %d iterations to build connection graph with %d nodes and worklist size %d",
38N/A // Find fields initialized by NULL for non-escaping Allocations. 0N/A // Adding references to NULL object does not change escape states 0N/A // since it does not escape. Also no fields are added to NULL object. 0N/A // The object allocated by this Allocate node will never be 0N/A // seen by an other thread. Mark it so that when it is 0N/A // expanded no MemBarStoreStore is added. 65N/A return true;
// Finished graph construction. 65N/A// Propagate GlobalEscape and ArgEscape escape states to all nodes 65N/A// and check that we still have non-escaping java objects. 0N/A // First, put all nodes with GlobalEscape and ArgEscape states on worklist. 65N/A // Set escape states to referenced nodes (edges list). 0N/A // GlobalEscape or ArgEscape state of field means it has unknown value. 65N/A // New edge was added 0N/A // Propagate only fields escape state through arraycopy edge. 0N/A // fields_escape_state is also set to 'es' if it is less than 'es'. 65N/A // Propagate field escape state. 65N/A // Change escape state of referenced fileds. 65N/A // Remove escaped objects from non_escaped list. 65N/A // Find fields in non-escaped allocations which have unknown value. 65N/A// Add all references to JavaObject node by walking over all uses. 65N/A // Populate _worklist by uses of jobj's uses. 65N/A // Put on worklist all field's uses (loads) and 65N/A // related field nodes (same base and offset). 65N/A // Add reference from jobj to field and from field to jobj (field's base). 0N/A // Added edge from Arraycopy node to arraycopy's source java object 247N/A continue;
// No new edge added, there was such edge already. 0N/A // Add edge from arraycopy's destination java object to Arraycopy node. 244N/A // Added new edge to stored in field values. 0N/A // Put on worklist all field's uses (loads) and 0N/A // related field nodes (same base and offset). 0N/A// Put on worklist all related field nodes. 244N/A // Loop over all bases of this field and push on worklist Field nodes 244N/A // with the same offset and base (since they may reference the same field). 244N/A // Check if the base was source object of arraycopy and go over arraycopy's 244N/A // destination objects since values stored to a field of source object are 244N/A // accessable by uses (loads) of fields of destination objects. 244N/A // Look for the same arracopy reference. 65N/A// Put on worklist all related field nodes. 65N/A if (
// Skip phantom_object since it is only used to indicate that 65N/A // this field's content globally escapes. 65N/A // NULL object node does not have fields. 65N/A // Skip arraycopy edge since store to destination object field 0N/A // does not update value in source object field. 65N/A// Find fields which have unknown value. 65N/A // Escaped fields should have init value already. 65N/A // Skip Allocate's fields which will be processed later. 65N/A // New edge was added 0N/A// Find fields initializing values for allocations. 244N/A // Do nothing for Allocate nodes since its fields values are "known". 253N/A // Non-escaped allocation returned from Java or runtime call have 253N/A // unknown values in fields. 0N/A // New edge was added 253N/A // Do nothing for Call nodes since its fields values are unknown. 253N/A // Check if an oop field's initializing value is recorded and add 253N/A // a corresponding NULL if field's value if it is not recorded. 253N/A // Connection Graph does not record a default initialization by NULL 253N/A // captured by Initialize node. 253N/A continue;
// Not oop field 253N/A // OffsetBot is used to reference array's element, 253N/A // always add reference to NULL to all Field nodes since we don't 253N/A // known which element is referenced. 253N/A // Check only oop fields. 253N/A // Raw pointers are used for initializing stores so skip it 253N/A // since it should be recorded already 253N/A // StoreP::memory_type() == T_ADDRESS 253N/A // Make sure initializing store has the same type as this AddP. 253N/A // This AddP may reference non existing field because it is on a 253N/A // dead branch of bimorphic call which is not eliminated yet. 253N/A // Verify that AddP already points to all objects the value points to. 0N/A // There could be initializing stores which follow allocation. 0N/A // For example, a volatile field store is not collected 0N/A // by Initialize node. 0N/A // Need to check for dependent loads to separate such stores from 244N/A // stores which follow loads. For now, add initial value NULL so 65N/A // that compare pointers optimization works correctly. 244N/A // A field's initializing value was not recorded. Add NULL. 0N/A// Adjust scalar_replaceable state after Connection Graph is built. 65N/A // Search for non-escaping objects which are not scalar replaceable 244N/A // and mark them to propagate the state to referenced objects. 65N/A // 1. An object is not scalar replaceable if the field into which it is 244N/A // stored has unknown offset (stored into unknown element of an array). 244N/A // 2. An object is not scalar replaceable if it is merged with other objects. 65N/A // Mark all objects. 244N/A // Non-escaping object node should point only to field nodes. 244N/A // 3. An object is not scalar replaceable if it has a field with unknown 244N/A // offset (array's element is accessed in loop). 65N/A // 4. Currently an object is not scalar replaceable if a LoadStore node 65N/A // access its field since the field value is unknown after it. 65N/A // 5. Or the address may point to more then one object. This may produce 244N/A // the false positive result (set not scalar replaceable) 244N/A // since the flow-insensitive escape analysis can't separate 244N/A // the case when stores overwrite the field's value from the case 65N/A // when stores happened on different control branches. 65N/A // Note: it will disable scalar replacement in some cases: 0N/A // Point p[] = new Point[1]; 244N/A // p[0] = new Point(); // Will be not scalar replaced 0N/A // but it will save us from incorrect optimizations in next cases: 0N/A // Point p[] = new Point[1]; 0N/A // if ( x ) p[0] = new Point(); // Will be not scalar replaced 0N/A // Don't take into account LocalVar nodes which 65N/A // may point to only one object which should be also 0N/A // this field's base by now. 65N/A // Verify that graph is complete - no new edges could be added. 65N/A // Verify that escape state is final. 65N/A // Verify fields information. 0N/A // Verify that field has all bases 65N/A // Verify that all fields have initializing values. 65N/A// Optimize ideal graph. 244N/A // Mark locks before changing ideal graph. 0N/A for(
int i=0; i <
cnt; i++ ) {
0N/A // The lock could be marked eliminated by lock coarsening 0N/A // code during first IGVN before EA. Replace coarsened flag 0N/A // Add ConI(#CC_GT) and ConI(#CC_EQ). 0N/A // Optimize objects compare. 0N/A // escape status of associated AllocateNode and optimize out 0N/A // MemBarStoreStore node if the allocated object never escapes. 0N/A// Optimize objects compare. 0N/A // Check simple cases first. 0N/A // Comparing the same not escaping object. 0N/A // Comparing not escaping allocation. 0N/A // Comparing not escaping allocation. 0N/A // Klass or String constants compare. Need to be careful with 65N/A // compressed pointers - compare types of ConN and ConP instead of nodes. 0N/A return NULL;
// Sets are not disjoint 0N/A // Sets are disjoint. 65N/A // Check nullness of unknown object. 0N/A // Disjointness by itself is not sufficient since 0N/A // alias analysis is not complete for escaped objects. 0N/A // Disjoint sets are definitely unrelated only when 0N/A // at least one set has only not escaping allocations. 65N/A// Connection Graph constuction functions. 65N/A // Add edge from arraycopy node to source object. 65N/A // Add edge from destination object to arraycopy node. 65N/A // Check only oop fields. 65N/A // OffsetBot is used to reference array's element. Ignore first AddP. 124N/A // Check for unsafe oop field access 65N/A // Ignore array length load. 65N/A // Ignore first AddP. 65N/A // Allocation initialization, ThreadLocal field access, unsafe access 113N/A// Returns unique pointed java object or NULL. 113N/A // If the node was created after the escape computation we can't answer. 164N/A // Check all java objects it points to. 65N/A// Return true if this node points only to non-escaping allocations. 65N/A // Check all java objects it points to. 65N/A// Return true if we know the node does not escape globally. 65N/A // If the node was created after the escape computation we can't answer. 65N/A // If we have already computed a value, return it. 65N/A return true;
// (es < PointsToNode::GlobalEscape); 65N/A // Check all java objects it points to. 65N/A// Return true if this node points to specified node or nodes it points to. 65N/A// Return true if one node points to an other. 221N/A// Return true if bases point to this java object. 65N/A // We are computing a raw address for a store captured by an Initialize 65N/A // compute an appropriate address type. AddP cases #3 and #5 (see below). 65N/A "offset must be a constant or it is initialization of array");
65N/A // AddP cases for Base and Address inputs: 65N/A // case #1. Direct object's field reference: 65N/A // Proj #5 ( oop result ) 65N/A // CheckCastPP (cast to instance type) 65N/A // AddP ( base == address ) 65N/A // case #2. Indirect object's field reference: 65N/A // CastPP (cast to instance type) 65N/A // AddP ( base == address ) 244N/A // case #3. Raw object's field reference for Initialize node: 244N/A // Proj #5 ( oop result ) 0N/A // AddP ( base == top ) 0N/A // case #4. Array's element reference: 244N/A // {CheckCastPP | CastPP} 0N/A // | AddP ( array's element offset ) 65N/A // AddP ( array's offset ) 0N/A // case #5. Raw object's field reference for arraycopy stub call: 65N/A // The inline_native_clone() case when the arraycopy stub is called 65N/A // after the allocation before Initialize and CheckCastPP nodes. 0N/A // Proj #5 ( oop result ) 244N/A // AddP ( base == address ) 65N/A // case #6. Constant Pool, ThreadLocal, CastX2P or 65N/A // Raw object's field reference: 65N/A // {ConP, ThreadLocal, CastX2P, raw Load} 65N/A // AddP ( base == top ) 65N/A // case #7. Klass's field reference. 113N/A // AddP ( base == address ) 65N/A // case #8. narrow Klass's field reference. 65N/A // AddP ( base == address ) 65N/A // Case #6 (unsafe access) may have several chained AddP nodes. 65N/A // Find array's offset to push it on worklist first and 65N/A // as result process an array's element offset first (pushed second) 253N/A // to avoid CastPP for the array's offset. 65N/A // Otherwise the inserted CastPP (LocalVar) will point to what 65N/A // the AddP (Field) points to. Which would be wrong since 65N/A // the algorithm expects the CastPP has the same point as 65N/A // as AddP's base CheckCastPP (LocalVar). 65N/A // memProj (from ArrayAllocation CheckCastPP) 65N/A // | || Int (element index) 65N/A // | || | ConI (log(element size)) 65N/A // | AddP (array's element offset) 65N/A // | | ConI (array's offset: #12(32-bits) or #24(64-bits)) 0N/A // AddP (array's offset) 65N/A// Adjust the type and inputs of an AddP which computes the 253N/A// address of a field of an instance 65N/A // We are computing a raw address for a store captured by an Initialize 65N/A // compute an appropriate address type (cases #3 and #5). 244N/A "old type must be non-instance or match new type");
0N/A // The type 't' could be subclass of 'base_t'. 65N/A // As result t->offset() could be large then base_t's size and it will 0N/A // cause the failure in add_offset() with narrow oops since TypeOopPtr() 65N/A // constructor verifies correctness of the offset. 65N/A // It could happened on subclass's branch (from the type profiling 244N/A // inlining) which was not eliminated during parsing since the exactness 65N/A // of the allocation type was not propagated to the subclass type check. 65N/A // Or the type 't' could be not related to 'base_t' at all. 0N/A // It could happened when CHA type is different from MDO type on a dead path 0N/A // (for example, from instanceof check) which is not collapsed during parsing. 0N/A // Do nothing for such AddP node and don't process its users since 65N/A // this code branch will go away. 0N/A return false;
// bail out 244N/A // Do NOT remove the next line: ensure a new alias index is allocated 244N/A // for the instance type. Note: C++ will not remove it since the call 65N/A // has side effect. 244N/A // record the allocation in the node map 0N/A // Set addp's Base and Address to 'base'. 124N/A // Skip AddP cases #3 and #5. 65N/A // AddP case #4 (adr is array's element offset AddP node) 0N/A // Put on IGVN worklist since at least addp's type was changed above. 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 whether a new 0N/A// phi was created. Cache the last newly created phi in the node map. 0N/A // nothing to do if orig_phi is bottom memory or matches alias_idx 244N/A // Have we recently created a Phi for this alias index? 65N/A // Previous check may fail when the same wide memory Phi was split into Phis 0N/A // for different memory slices. Search all Phis for this region. 244N/A // Retry compilation without escape analysis. 65N/A // If this is the first failure, the sentinel string will "stick" 65N/A // to the Compile object, and the C2Compiler will see it and retry. // Return a new version of Memory Phi "orig_phi" with the inputs having the // specified alias index. // found an phi for which we created a new split, push current one on worklist and begin // verify that the new Phi has an input for each input of the original // Check if all new phi's inputs have specified alias index. // Otherwise use old phi. // we have finished processing a Phi, see if there are any more to do // The next methods are derived from methods in MemNode. // TypeOopPtr::NOTNULL+any is an OOP with unknown offset - generally // means an array I have not precisely typed yet. Do not do any // alias stuff with it any time soon. // Update input if it is progress over what we have now // Move memory users to their memory slices. continue;
// Nothing to do // Replace previous general reference to mem node. // Don't move related membars. continue;
// Nothing to do // Move to general memory slice. // Don't move related cardmark. // Memory nodes should have new memory input. "Following memory nodes should have new memory input or be on the same memory slice");
// Phi nodes should be split and moved already. assert(
false,
"should not be here");
// Search memory chain of "mem" to find a MemNode whose address // is the specified alias index. break;
// hit one of our sentinels break;
// Do not skip store to general memory slice. continue;
// don't search further for non-instance types // skip over a call which does not affect this memory slice break;
// hit one of our sentinels // Stop if this is the initialization for the object instance which // which contains this memory slice, otherwise skip over it. // Didn't find instance memory, search through general slice recursively. // Can not bypass initialization of the instance // Otherwise skip it (the call updated 'result' value). assert(
idx !=
alias_idx,
"Object is not scalar replaceable if a LoadStore node access its field");
// Push all non-instance Phis on the orig_phis worklist to update inputs // during Phase 4 if needed. // Create a new Phi with the specified alias index type. // the result is either MemNode, PhiNode, InitializeNode. // Convert the types of unescaped object to instance types where possible, // propagate the new type information through the graph, and update memory // edges and MergeMem inputs to reflect the new type. // We start with allocations (and calls which may be allocations) on alloc_worklist. // The processing is done in 4 phases: // Phase 1: Process possible allocations from alloc_worklist. Create instance // types for the CheckCastPP for allocations where possible. // Propagate the the new types through users as follows: // casts and Phi: push users on alloc_worklist // AddP: cast Base and Address inputs to the instance type // push any AddP users on alloc_worklist and push any memnode // users onto memnode_worklist. // Phase 2: Process MemNode's from memnode_worklist. compute new address type and // search the Memory chain for a store with the appropriate type // address type. If a Phi is found, create a new version with // the appropriate memory slices from each of the Phi inputs. // For stores, process the users as follows: // MemNode: push on memnode_worklist // MergeMem: push on mergemem_worklist // Phase 3: Process MergeMem nodes from mergemem_worklist. Walk each memory slice // moving the first node encountered of each instance type to the // the input corresponding to its alias index. // appropriate memory slice. // Phase 4: Update the inputs of non-instance memory Phis and the Memory input of memnodes. // In the following example, the CheckCastPP nodes are the cast of allocation // results and the allocation of node 29 is unescaped and eligible to be an // 20 AddP _ 19 19 10 Foo+12 alias_index=4 // 30 AddP _ 29 29 10 Foo+12 alias_index=4 // 40 StoreP 25 7 20 ... alias_index=4 // 50 StoreP 35 40 30 ... alias_index=4 // 60 StoreP 45 50 20 ... alias_index=4 // 70 LoadP _ 60 30 ... alias_index=4 // 80 Phi 75 50 60 Memory alias_index=4 // 90 LoadP _ 80 30 ... alias_index=4 // 100 LoadP _ 80 20 ... alias_index=4 // Phase 1 creates an instance type for node 29 assigning it an instance id of 24 // and creating a new alias index for node 30. This gives: // 20 AddP _ 19 19 10 Foo+12 alias_index=4 // 29 CheckCastPP "Foo" iid=24 // 30 AddP _ 29 29 10 Foo+12 alias_index=6 iid=24 // 40 StoreP 25 7 20 ... alias_index=4 // 50 StoreP 35 40 30 ... alias_index=6 // 60 StoreP 45 50 20 ... alias_index=4 // 70 LoadP _ 60 30 ... alias_index=6 // 80 Phi 75 50 60 Memory alias_index=4 // 90 LoadP _ 80 30 ... alias_index=6 // 100 LoadP _ 80 20 ... alias_index=4 // In phase 2, new memory inputs are computed for the loads and stores, // And a new version of the phi is created. In phase 4, the inputs to // node 80 are updated and then the memory nodes are updated with the // values computed in phase 2. This results in: // 20 AddP _ 19 19 10 Foo+12 alias_index=4 // 29 CheckCastPP "Foo" iid=24 // 30 AddP _ 29 29 10 Foo+12 alias_index=6 iid=24 // 40 StoreP 25 7 20 ... alias_index=4 // 50 StoreP 35 7 30 ... alias_index=6 // 60 StoreP 45 40 20 ... alias_index=4 // 70 LoadP _ 50 30 ... alias_index=6 // 80 Phi 75 40 60 Memory alias_index=4 // 120 Phi 75 50 50 Memory alias_index=6 // 90 LoadP _ 120 30 ... alias_index=6 // 100 LoadP _ 80 20 ... alias_index=4 // Phase 1: Process possible allocations from alloc_worklist. // Create instance types for the CheckCastPP for allocations where possible. // (Note: don't forget to change the order of the second AddP node on // the alloc_worklist if the order of the worklist processing is changed, // see the comment in find_second_addp().) // copy escape information to call node // We have an allocation or call which returns a Java object, // see if it is unescaped. // Find CheckCastPP for the allocate or for the return value of a call if (n ==
NULL) {
// No uses except Initialize node // Set the scalar_replaceable flag for allocation // so it could be eliminated if it has no uses. // The inline code for Object.clone() casts the allocation result to // java.lang.Object and then to the actual type of the allocated // object. Detect this case and use the second cast. // Also detect j.l.reflect.Array.newInstance(jobject, jint) case when // the allocation result is cast to java.lang.Object and then // to the actual Array type. // Non-scalar replaceable if the allocation type is unknown statically // (reflection allocation), the object can't be restored during // deoptimization without precise type. // Set the scalar_replaceable flag for allocation // so it could be eliminated. // in order for an object to be scalar-replaceable, it must be: // - a direct allocation (not a call returning an object) // - eligible to be a unique type // - not determined to be ineligible by escape analysis continue;
// not a TypeOopPtr // First, put on the worklist all Field edges from Connection Graph // which is more accurate then putting immediate users from Ideal Graph. "only AddP nodes are Field edges in CG");
if (
use->
outcnt() > 0) {
// Don't process dead nodes // An allocation may have an Initialize which has raw stores. Scan // the users of the raw allocation result and push AddP users continue;
// already processed continue;
// Skip dead path with different type assert(
false,
"EA: unexpected node");
// push allocation's users on appropriate worklist // Look for MergeMem nodes for calls which reference unique allocation // (through CheckCastPP nodes) even for debug info. assert(
false,
"EA: missing allocation reference path");
// New alias types were created in split_AddP(). // Phase 2: Process MemNode's from memnode_worklist. compute new address type and // compute new values for Memory inputs (the Memory inputs are not // actually updated until phase 4.) // we don't need to do anything, but the users must be pushed }
else if (n->
is_MemBar()) {
// Initialize, MemBar nodes // we don't need to do anything, but the users must be pushed // We delay the memory edge update since we need old one in // MergeMem code below when instances memory slices are separated. continue;
// don't push users // get the memory projection // push user on appropriate worklist assert(
false,
"EA: missing memory path");
// Phase 3: Process MergeMem nodes from mergemem_worklist. // Walk each memory slice moving the first node encountered of each // instance type to the the input corresponding to its alias index. // Note: we don't want to use MergeMemStream here because we only want to // scan inputs which exist at the start, not ones we add during processing. // Note 2: MergeMem may already contains instance memory slices added // during find_inst_mem() call when memory nodes were processed above. // First, update mergemem by moving memory nodes to corresponding slices // if their type became more precise since this mergemem was created. // Find any instance of the current type if we haven't encountered // already a memory slice of the instance along the memory chain. // Find the rest of instances values // Didn't find instance memory, search through general slice recursively. // Phase 4: Update the inputs of non-instance memory Phis and // the Memory input of memnodes // First update the inputs of any non-instance Phi's from // which we split out an instance Phi. Note we don't have // to recursively process Phi's encounted on the input memory // chains as is done in split_memory_phi() since they will // also be processed here. // Update the memory inputs of MemNodes with the value we computed // in Phase 2 and move stores memory users to corresponding memory slices. // Disable memory split verification code until the fix for 6984348. // Currently it produces false negative results since it does not cover all cases. // Move memory users of a store first. // Now update memory input // Verify that memory was split correctly tty->
print(
"======== Connection graph for ");
// Print all locals and fields which reference this allocation