escape.cpp revision 0
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 * 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 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#
include "incls/_precompiled.incl" 0N/A "P",
// PointsToEdge 0N/A "D",
// DeferredEdge 0N/A // don't add a self-referential edge, this can occur during removal of 0N/A // If we are still collecting we don't know the answer yet 0N/A // if the node was created after the escape computation, return 0N/A // if we have already computed a value, return it 0N/A // compute max escape state of anything this node could point to 0N/A // cache the computed escape state 0N/A // If we have a JavaObject, return just that object 0N/A // we may have a Phi which has not been processed 0N/A // ensure that all inputs of a Phi have been processed 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// 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// Add a deferred edge from node given by "from_i" to any field of adr_i whose offset 0N/A // we have not seen any stores to this field, assume it was set outside this method 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// Adjust the type and inputs of an AddP which computes the 0N/A// address of a field of an instance 0N/A "old type must be non-instance or match new type");
0N/A // ensure an alias index is allocated for the instance type 0N/A // record the allocation in the node map 0N/A // if the Address input is not the appropriate instance type (due to intervening 0N/A // casts,) insert a cast 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 // nothing to do if orig_phi is bottom memory or matches alias_idx 0N/A // have we already created a Phi for this alias index? 0N/A// Return a new version of Memory Phi "orig_phi" with the inputs having the 0N/A// specified alias index. 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 // verify that the new Phi has an input for each input of the original 0N/A // we have finished processing a Phi, see if there are any more to do 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// We start with allocations (and calls which may be allocations) on alloc_worklist. 0N/A// The processing is done in 4 phases: 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// 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// 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// 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// 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// 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// 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// 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// 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// 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 // Phase 1: Process possible allocations from alloc_worklist. Create instance 0N/A // types for the CheckCastPP for allocations where possible. 0N/A // copy escape information to call node 0N/A // find CheckCastPP of call return value 0N/A // we have an allocation or call which returns a Java object, see if it is unescaped 0N/A continue;
// can't make a unique type 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 continue;
// not a TypeInstPtr 0N/A continue;
// already processed 0N/A // push users on appropriate worklist 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 return;
// nothing to do 0N/A // we don't need to do anything, but the users must be pushed if we haven't processed 0N/A continue;
// don't push users 0N/A // get the memory projection 0N/A // push user on appropriate 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 // 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 // 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 // Phase 4: Update the inputs of non-instance memory Phis and the Memory input of memnodes 0N/A // First update the inputs of any non-instance Phi's from 0N/A // which we split out an instance Phi. Note we don't have 0N/A // to recursively process Phi's encounted on the input memory 0N/A // chains as is done in split_memory_phi() since they will 0N/A // also be processed here. 0N/A // Update the memory inputs of MemNodes with the value we computed 0N/A // process Phi nodes from the deferred list, they may not have 0N/A // remove deferred edges from the graph and collect 0N/A // information we will need for type splitting 0N/A continue;
// not a node we are interested in 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 // initialize _escape_state of calls to GlobalEscape 0N/A // push call on alloc_worlist (alocations are calls) 0N/A // for processing by split_unique_types() 0N/A // push all GlobalEscape nodes on the worklist 0N/A // mark all node reachable from GlobalEscape nodes 0N/A // push all ArgEscape nodes on the worklist 0N/A // mark all node reachable from ArgEscape nodes 0N/A // Now use the escape information to create unique types for 0N/A // unescaped objects 0N/A return;
// nothing to do if not an oop 0N/A return;
// no new inputs since the last time this node was processed, 0N/A // the current information is valid 0N/A continue;
// ignore NULL 0N/A continue;
// ignore top or inputs which go back this node 0N/A // arguments to allocation and locking don't escape 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 // The argument global escapes, mark everything it could point to 0N/A // The argument itself doesn't escape, but any fields might 0N/A // fall-through if not a Java method 0N/A // Some other type of call, assume the worst case: all arguments 0N/A // adjust escape state for outgoing arguments 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 // Note: we use isa_ptr() instead of isa_oopptr() here because the 0N/A // _multianewarray functions return a TypeRawPtr. 0N/A break;
// doesn't return a pointer type 0N/A // not a Java method, assume global escape 0N/A // determine whether any arguments are returned 0N/A // Some other type of call, assume the worst case that the 0N/A // returned value, if any, globally escapes. 0N/A // Note: we use isa_ptr() instead of isa_oopptr() here because the 0N/A // _multianewarray functions return a TypeRawPtr. 0N/A // create a field edge to this node from everything adr could point to 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 return;
// nothing to do if not an oop 0N/A // assume that all exception objects globally escape 0N/A // assume all pointer constants globally escape except for null 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 // If ptset is empty, then this value must have been set outside 0N/A // this method, so we add the phantom node 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 // we are only interested in the result projection from a call 0N/A // don't print null pointer node which almost every method has