annotate src/share/vm/ci/bcEscapeAnalyzer.hpp @ 0:a61af66fc99e jdk7-b24

Initial load
author duke
date Sat, 01 Dec 2007 00:00:00 +0000
parents
children 48a3fa21394b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
2 * Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved.
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 define_array(ciObjectArray, ciObject*);
a61af66fc99e Initial load
duke
parents:
diff changeset
26 define_stack(ciObjectList, ciObjectArray);
a61af66fc99e Initial load
duke
parents:
diff changeset
27
a61af66fc99e Initial load
duke
parents:
diff changeset
28 // This class implements a fast, conservative analysis of effect of methods
a61af66fc99e Initial load
duke
parents:
diff changeset
29 // on the escape state of their arguments. The analysis is at the bytecode
a61af66fc99e Initial load
duke
parents:
diff changeset
30 // level.
a61af66fc99e Initial load
duke
parents:
diff changeset
31
a61af66fc99e Initial load
duke
parents:
diff changeset
32 class ciMethodBlocks;
a61af66fc99e Initial load
duke
parents:
diff changeset
33 class ciBlock;
a61af66fc99e Initial load
duke
parents:
diff changeset
34
a61af66fc99e Initial load
duke
parents:
diff changeset
35 class BCEscapeAnalyzer : public ResourceObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
36 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
37 bool _conservative; // If true, return maximally
a61af66fc99e Initial load
duke
parents:
diff changeset
38 // conservative results.
a61af66fc99e Initial load
duke
parents:
diff changeset
39 ciMethod* _method;
a61af66fc99e Initial load
duke
parents:
diff changeset
40 ciMethodData* _methodData;
a61af66fc99e Initial load
duke
parents:
diff changeset
41 int _arg_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
42
a61af66fc99e Initial load
duke
parents:
diff changeset
43 intStack _stack;
a61af66fc99e Initial load
duke
parents:
diff changeset
44
a61af66fc99e Initial load
duke
parents:
diff changeset
45 BitMap _arg_local;
a61af66fc99e Initial load
duke
parents:
diff changeset
46 BitMap _arg_stack;
a61af66fc99e Initial load
duke
parents:
diff changeset
47 BitMap _arg_returned;
a61af66fc99e Initial load
duke
parents:
diff changeset
48 BitMap _dirty;
a61af66fc99e Initial load
duke
parents:
diff changeset
49
a61af66fc99e Initial load
duke
parents:
diff changeset
50 bool _return_local;
a61af66fc99e Initial load
duke
parents:
diff changeset
51 bool _allocated_escapes;
a61af66fc99e Initial load
duke
parents:
diff changeset
52 bool _return_allocated;
a61af66fc99e Initial load
duke
parents:
diff changeset
53
a61af66fc99e Initial load
duke
parents:
diff changeset
54 ciObjectList _dependencies;
a61af66fc99e Initial load
duke
parents:
diff changeset
55
a61af66fc99e Initial load
duke
parents:
diff changeset
56 ciMethodBlocks *_methodBlocks;
a61af66fc99e Initial load
duke
parents:
diff changeset
57
a61af66fc99e Initial load
duke
parents:
diff changeset
58 BCEscapeAnalyzer* _parent;
a61af66fc99e Initial load
duke
parents:
diff changeset
59 int _level;
a61af66fc99e Initial load
duke
parents:
diff changeset
60
a61af66fc99e Initial load
duke
parents:
diff changeset
61 class ArgumentMap;
a61af66fc99e Initial load
duke
parents:
diff changeset
62 class StateInfo;
a61af66fc99e Initial load
duke
parents:
diff changeset
63
a61af66fc99e Initial load
duke
parents:
diff changeset
64 // helper functions
a61af66fc99e Initial load
duke
parents:
diff changeset
65 bool is_argument(int i) { return i >= 0 && i < _arg_size; }
a61af66fc99e Initial load
duke
parents:
diff changeset
66
a61af66fc99e Initial load
duke
parents:
diff changeset
67 void raw_push(int i) { _stack.push(i); }
a61af66fc99e Initial load
duke
parents:
diff changeset
68 int raw_pop() { return _stack.is_empty() ? -1 : _stack.pop(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
69 void apush(int i) { raw_push(i); }
a61af66fc99e Initial load
duke
parents:
diff changeset
70 void spush() { raw_push(-1); }
a61af66fc99e Initial load
duke
parents:
diff changeset
71 void lpush() { spush(); spush(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
72 int apop() { return raw_pop(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
73 void spop() { assert(_stack.is_empty() || _stack.top() == -1, ""); raw_pop(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
74 void lpop() { spop(); spop(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
75
a61af66fc99e Initial load
duke
parents:
diff changeset
76 void set_returned(ArgumentMap vars);
a61af66fc99e Initial load
duke
parents:
diff changeset
77 bool is_argument(ArgumentMap vars);
a61af66fc99e Initial load
duke
parents:
diff changeset
78 bool is_arg_stack(ArgumentMap vars);
a61af66fc99e Initial load
duke
parents:
diff changeset
79 void clear_bits(ArgumentMap vars, BitMap &bs);
a61af66fc99e Initial load
duke
parents:
diff changeset
80 void set_method_escape(ArgumentMap vars);
a61af66fc99e Initial load
duke
parents:
diff changeset
81 void set_global_escape(ArgumentMap vars);
a61af66fc99e Initial load
duke
parents:
diff changeset
82 void set_dirty(ArgumentMap vars);
a61af66fc99e Initial load
duke
parents:
diff changeset
83
a61af66fc99e Initial load
duke
parents:
diff changeset
84 bool is_recursive_call(ciMethod* callee);
a61af66fc99e Initial load
duke
parents:
diff changeset
85 void add_dependence(ciKlass *klass, ciMethod *meth);
a61af66fc99e Initial load
duke
parents:
diff changeset
86 void propagate_dependencies(ciMethod *meth);
a61af66fc99e Initial load
duke
parents:
diff changeset
87 void invoke(StateInfo &state, Bytecodes::Code code, ciMethod* target, ciKlass* holder);
a61af66fc99e Initial load
duke
parents:
diff changeset
88
a61af66fc99e Initial load
duke
parents:
diff changeset
89 void iterate_one_block(ciBlock *blk, StateInfo &state, GrowableArray<ciBlock *> &successors);
a61af66fc99e Initial load
duke
parents:
diff changeset
90 void iterate_blocks(Arena *);
a61af66fc99e Initial load
duke
parents:
diff changeset
91 void merge_block_states(StateInfo *blockstates, ciBlock *dest, StateInfo *s_state);
a61af66fc99e Initial load
duke
parents:
diff changeset
92
a61af66fc99e Initial load
duke
parents:
diff changeset
93 // analysis
a61af66fc99e Initial load
duke
parents:
diff changeset
94 void initialize();
a61af66fc99e Initial load
duke
parents:
diff changeset
95 void clear_escape_info();
a61af66fc99e Initial load
duke
parents:
diff changeset
96 void compute_escape_info();
a61af66fc99e Initial load
duke
parents:
diff changeset
97 vmIntrinsics::ID known_intrinsic();
a61af66fc99e Initial load
duke
parents:
diff changeset
98 bool compute_escape_for_intrinsic(vmIntrinsics::ID iid);
a61af66fc99e Initial load
duke
parents:
diff changeset
99 bool do_analysis();
a61af66fc99e Initial load
duke
parents:
diff changeset
100
a61af66fc99e Initial load
duke
parents:
diff changeset
101 void read_escape_info();
a61af66fc99e Initial load
duke
parents:
diff changeset
102
a61af66fc99e Initial load
duke
parents:
diff changeset
103 bool contains(uint arg_set1, uint arg_set2);
a61af66fc99e Initial load
duke
parents:
diff changeset
104
a61af66fc99e Initial load
duke
parents:
diff changeset
105 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
106 BCEscapeAnalyzer(ciMethod* method, BCEscapeAnalyzer* parent = NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
107
a61af66fc99e Initial load
duke
parents:
diff changeset
108 // accessors
a61af66fc99e Initial load
duke
parents:
diff changeset
109 ciMethod* method() const { return _method; }
a61af66fc99e Initial load
duke
parents:
diff changeset
110 ciMethodData* methodData() const { return _methodData; }
a61af66fc99e Initial load
duke
parents:
diff changeset
111 BCEscapeAnalyzer* parent() const { return _parent; }
a61af66fc99e Initial load
duke
parents:
diff changeset
112 int level() const { return _level; }
a61af66fc99e Initial load
duke
parents:
diff changeset
113 ciObjectList* dependencies() { return &_dependencies; }
a61af66fc99e Initial load
duke
parents:
diff changeset
114 bool has_dependencies() const { return !_dependencies.is_empty(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
115
a61af66fc99e Initial load
duke
parents:
diff changeset
116 // retrieval of interprocedural escape information
a61af66fc99e Initial load
duke
parents:
diff changeset
117
a61af66fc99e Initial load
duke
parents:
diff changeset
118 // The given argument does not escape the callee.
a61af66fc99e Initial load
duke
parents:
diff changeset
119 bool is_arg_local(int i) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
120 return !_conservative && _arg_local.at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
121 }
a61af66fc99e Initial load
duke
parents:
diff changeset
122
a61af66fc99e Initial load
duke
parents:
diff changeset
123 // The given argument escapes the callee, but does not become globally
a61af66fc99e Initial load
duke
parents:
diff changeset
124 // reachable.
a61af66fc99e Initial load
duke
parents:
diff changeset
125 bool is_arg_stack(int i) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
126 return !_conservative && _arg_stack.at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
127 }
a61af66fc99e Initial load
duke
parents:
diff changeset
128
a61af66fc99e Initial load
duke
parents:
diff changeset
129 // The given argument does not escape globally, and may be returned.
a61af66fc99e Initial load
duke
parents:
diff changeset
130 bool is_arg_returned(int i) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
131 return !_conservative && _arg_returned.at(i); }
a61af66fc99e Initial load
duke
parents:
diff changeset
132
a61af66fc99e Initial load
duke
parents:
diff changeset
133 // True iff only input arguments are returned.
a61af66fc99e Initial load
duke
parents:
diff changeset
134 bool is_return_local() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
135 return !_conservative && _return_local;
a61af66fc99e Initial load
duke
parents:
diff changeset
136 }
a61af66fc99e Initial load
duke
parents:
diff changeset
137
a61af66fc99e Initial load
duke
parents:
diff changeset
138 // True iff only newly allocated unescaped objects are returned.
a61af66fc99e Initial load
duke
parents:
diff changeset
139 bool is_return_allocated() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
140 return !_conservative && _return_allocated && !_allocated_escapes;
a61af66fc99e Initial load
duke
parents:
diff changeset
141 }
a61af66fc99e Initial load
duke
parents:
diff changeset
142
a61af66fc99e Initial load
duke
parents:
diff changeset
143 // Copy dependencies from this analysis into "deps"
a61af66fc99e Initial load
duke
parents:
diff changeset
144 void copy_dependencies(Dependencies *deps);
a61af66fc99e Initial load
duke
parents:
diff changeset
145 };