1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/ci/bcEscapeAnalyzer.hpp Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,145 @@ 1.4 +/* 1.5 + * Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.24 + * have any questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +define_array(ciObjectArray, ciObject*); 1.29 +define_stack(ciObjectList, ciObjectArray); 1.30 + 1.31 +// This class implements a fast, conservative analysis of effect of methods 1.32 +// on the escape state of their arguments. The analysis is at the bytecode 1.33 +// level. 1.34 + 1.35 +class ciMethodBlocks; 1.36 +class ciBlock; 1.37 + 1.38 +class BCEscapeAnalyzer : public ResourceObj { 1.39 + private: 1.40 + bool _conservative; // If true, return maximally 1.41 + // conservative results. 1.42 + ciMethod* _method; 1.43 + ciMethodData* _methodData; 1.44 + int _arg_size; 1.45 + 1.46 + intStack _stack; 1.47 + 1.48 + BitMap _arg_local; 1.49 + BitMap _arg_stack; 1.50 + BitMap _arg_returned; 1.51 + BitMap _dirty; 1.52 + 1.53 + bool _return_local; 1.54 + bool _allocated_escapes; 1.55 + bool _return_allocated; 1.56 + 1.57 + ciObjectList _dependencies; 1.58 + 1.59 + ciMethodBlocks *_methodBlocks; 1.60 + 1.61 + BCEscapeAnalyzer* _parent; 1.62 + int _level; 1.63 + 1.64 + class ArgumentMap; 1.65 + class StateInfo; 1.66 + 1.67 + // helper functions 1.68 + bool is_argument(int i) { return i >= 0 && i < _arg_size; } 1.69 + 1.70 + void raw_push(int i) { _stack.push(i); } 1.71 + int raw_pop() { return _stack.is_empty() ? -1 : _stack.pop(); } 1.72 + void apush(int i) { raw_push(i); } 1.73 + void spush() { raw_push(-1); } 1.74 + void lpush() { spush(); spush(); } 1.75 + int apop() { return raw_pop(); } 1.76 + void spop() { assert(_stack.is_empty() || _stack.top() == -1, ""); raw_pop(); } 1.77 + void lpop() { spop(); spop(); } 1.78 + 1.79 + void set_returned(ArgumentMap vars); 1.80 + bool is_argument(ArgumentMap vars); 1.81 + bool is_arg_stack(ArgumentMap vars); 1.82 + void clear_bits(ArgumentMap vars, BitMap &bs); 1.83 + void set_method_escape(ArgumentMap vars); 1.84 + void set_global_escape(ArgumentMap vars); 1.85 + void set_dirty(ArgumentMap vars); 1.86 + 1.87 + bool is_recursive_call(ciMethod* callee); 1.88 + void add_dependence(ciKlass *klass, ciMethod *meth); 1.89 + void propagate_dependencies(ciMethod *meth); 1.90 + void invoke(StateInfo &state, Bytecodes::Code code, ciMethod* target, ciKlass* holder); 1.91 + 1.92 + void iterate_one_block(ciBlock *blk, StateInfo &state, GrowableArray<ciBlock *> &successors); 1.93 + void iterate_blocks(Arena *); 1.94 + void merge_block_states(StateInfo *blockstates, ciBlock *dest, StateInfo *s_state); 1.95 + 1.96 + // analysis 1.97 + void initialize(); 1.98 + void clear_escape_info(); 1.99 + void compute_escape_info(); 1.100 + vmIntrinsics::ID known_intrinsic(); 1.101 + bool compute_escape_for_intrinsic(vmIntrinsics::ID iid); 1.102 + bool do_analysis(); 1.103 + 1.104 + void read_escape_info(); 1.105 + 1.106 + bool contains(uint arg_set1, uint arg_set2); 1.107 + 1.108 + public: 1.109 + BCEscapeAnalyzer(ciMethod* method, BCEscapeAnalyzer* parent = NULL); 1.110 + 1.111 + // accessors 1.112 + ciMethod* method() const { return _method; } 1.113 + ciMethodData* methodData() const { return _methodData; } 1.114 + BCEscapeAnalyzer* parent() const { return _parent; } 1.115 + int level() const { return _level; } 1.116 + ciObjectList* dependencies() { return &_dependencies; } 1.117 + bool has_dependencies() const { return !_dependencies.is_empty(); } 1.118 + 1.119 + // retrieval of interprocedural escape information 1.120 + 1.121 + // The given argument does not escape the callee. 1.122 + bool is_arg_local(int i) const { 1.123 + return !_conservative && _arg_local.at(i); 1.124 + } 1.125 + 1.126 + // The given argument escapes the callee, but does not become globally 1.127 + // reachable. 1.128 + bool is_arg_stack(int i) const { 1.129 + return !_conservative && _arg_stack.at(i); 1.130 + } 1.131 + 1.132 + // The given argument does not escape globally, and may be returned. 1.133 + bool is_arg_returned(int i) const { 1.134 + return !_conservative && _arg_returned.at(i); } 1.135 + 1.136 + // True iff only input arguments are returned. 1.137 + bool is_return_local() const { 1.138 + return !_conservative && _return_local; 1.139 + } 1.140 + 1.141 + // True iff only newly allocated unescaped objects are returned. 1.142 + bool is_return_allocated() const { 1.143 + return !_conservative && _return_allocated && !_allocated_escapes; 1.144 + } 1.145 + 1.146 + // Copy dependencies from this analysis into "deps" 1.147 + void copy_dependencies(Dependencies *deps); 1.148 +};