Mercurial > hg > graal-compiler
annotate src/share/vm/c1/c1_ValueStack.hpp @ 1819:f02a8bbe6ed4
6986046: C1 valuestack cleanup
Summary: fixes an historical oddity in C1 with inlining where all of the expression stacks are kept in the topmost ValueStack instead of being in their respective ValueStacks.
Reviewed-by: never
Contributed-by: Christian Wimmer <cwimmer@uci.edu>
author | roland |
---|---|
date | Tue, 29 Dec 2009 19:08:54 +0100 |
parents | b812ff5abc73 |
children | 1375bc8922e4 |
rev | line source |
---|---|
0 | 1 /* |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
0
diff
changeset
|
2 * Copyright (c) 1999, 2006, Oracle and/or its affiliates. All rights reserved. |
0 | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
0
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
0
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
0
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
25 class ValueStack: public CompilationResourceObj { | |
1819 | 26 public: |
27 enum Kind { | |
28 Parsing, // During abstract interpretation in GraphBuilder | |
29 CallerState, // Caller state when inlining | |
30 StateBefore, // Before before execution of instruction | |
31 StateAfter, // After execution of instruction | |
32 ExceptionState, // Exception handling of instruction | |
33 EmptyExceptionState, // Exception handling of instructions not covered by an xhandler | |
34 BlockBeginState // State of BlockBegin instruction with phi functions of this block | |
35 }; | |
36 | |
0 | 37 private: |
38 IRScope* _scope; // the enclosing scope | |
1819 | 39 ValueStack* _caller_state; |
40 int _bci; | |
41 Kind _kind; | |
42 | |
0 | 43 Values _locals; // the locals |
44 Values _stack; // the expression stack | |
45 Values _locks; // the monitor stack (holding the locked values) | |
46 | |
47 Value check(ValueTag tag, Value t) { | |
48 assert(tag == t->type()->tag() || tag == objectTag && t->type()->tag() == addressTag, "types must correspond"); | |
49 return t; | |
50 } | |
51 | |
52 Value check(ValueTag tag, Value t, Value h) { | |
1819 | 53 assert(h == NULL, "hi-word of doubleword value must be NULL"); |
0 | 54 return check(tag, t); |
55 } | |
56 | |
57 // helper routine | |
1584 | 58 static void apply(Values list, ValueVisitor* f); |
0 | 59 |
1819 | 60 // for simplified copying |
61 ValueStack(ValueStack* copy_from, Kind kind, int bci); | |
62 | |
0 | 63 public: |
64 // creation | |
1819 | 65 ValueStack(IRScope* scope, ValueStack* caller_state); |
0 | 66 |
1819 | 67 ValueStack* copy() { return new ValueStack(this, _kind, _bci); } |
68 ValueStack* copy(Kind new_kind, int new_bci) { return new ValueStack(this, new_kind, new_bci); } | |
69 ValueStack* copy_for_parsing() { return new ValueStack(this, Parsing, -99); } | |
70 | |
71 void set_caller_state(ValueStack* s) { assert(kind() == EmptyExceptionState, "only EmptyExceptionStates can be modified"); _caller_state = s; } | |
72 | |
0 | 73 bool is_same(ValueStack* s); // returns true if this & s's types match (w/o checking locals) |
74 | |
75 // accessors | |
76 IRScope* scope() const { return _scope; } | |
1819 | 77 ValueStack* caller_state() const { return _caller_state; } |
78 int bci() const { return _bci; } | |
79 Kind kind() const { return _kind; } | |
80 | |
0 | 81 int locals_size() const { return _locals.length(); } |
82 int stack_size() const { return _stack.length(); } | |
83 int locks_size() const { return _locks.length(); } | |
84 bool stack_is_empty() const { return _stack.is_empty(); } | |
85 bool no_active_locks() const { return _locks.is_empty(); } | |
1819 | 86 int total_locks_size() const; |
0 | 87 |
88 // locals access | |
89 void clear_locals(); // sets all locals to NULL; | |
90 | |
91 void invalidate_local(int i) { | |
1819 | 92 assert(_locals.at(i)->type()->is_single_word() || |
93 _locals.at(i + 1) == NULL, "hi-word of doubleword value must be NULL"); | |
0 | 94 _locals.at_put(i, NULL); |
95 } | |
96 | |
1819 | 97 Value local_at(int i) const { |
0 | 98 Value x = _locals.at(i); |
1819 | 99 assert(x == NULL || x->type()->is_single_word() || |
100 _locals.at(i + 1) == NULL, "hi-word of doubleword value must be NULL"); | |
0 | 101 return x; |
102 } | |
103 | |
104 void store_local(int i, Value x) { | |
1819 | 105 // When overwriting local i, check if i - 1 was the start of a |
106 // double word local and kill it. | |
0 | 107 if (i > 0) { |
108 Value prev = _locals.at(i - 1); | |
109 if (prev != NULL && prev->type()->is_double_word()) { | |
110 _locals.at_put(i - 1, NULL); | |
111 } | |
112 } | |
1819 | 113 |
114 _locals.at_put(i, x); | |
115 if (x->type()->is_double_word()) { | |
116 // hi-word of doubleword value is always NULL | |
117 _locals.at_put(i + 1, NULL); | |
118 } | |
0 | 119 } |
120 | |
121 // stack access | |
122 Value stack_at(int i) const { | |
123 Value x = _stack.at(i); | |
124 assert(x->type()->is_single_word() || | |
1819 | 125 _stack.at(i + 1) == NULL, "hi-word of doubleword value must be NULL"); |
0 | 126 return x; |
127 } | |
128 | |
129 Value stack_at_inc(int& i) const { | |
130 Value x = stack_at(i); | |
131 i += x->type()->size(); | |
132 return x; | |
133 } | |
134 | |
135 // pinning support | |
136 void pin_stack_for_linear_scan(); | |
137 | |
138 // iteration | |
1584 | 139 void values_do(ValueVisitor* f); |
0 | 140 |
141 // untyped manipulation (for dup_x1, etc.) | |
142 void truncate_stack(int size) { _stack.trunc_to(size); } | |
143 void raw_push(Value t) { _stack.push(t); } | |
144 Value raw_pop() { return _stack.pop(); } | |
145 | |
146 // typed manipulation | |
147 void ipush(Value t) { _stack.push(check(intTag , t)); } | |
148 void fpush(Value t) { _stack.push(check(floatTag , t)); } | |
149 void apush(Value t) { _stack.push(check(objectTag , t)); } | |
150 void rpush(Value t) { _stack.push(check(addressTag, t)); } | |
151 void lpush(Value t) { _stack.push(check(longTag , t)); _stack.push(NULL); } | |
152 void dpush(Value t) { _stack.push(check(doubleTag , t)); _stack.push(NULL); } | |
153 | |
154 void push(ValueType* type, Value t) { | |
155 switch (type->tag()) { | |
156 case intTag : ipush(t); return; | |
157 case longTag : lpush(t); return; | |
158 case floatTag : fpush(t); return; | |
159 case doubleTag : dpush(t); return; | |
160 case objectTag : apush(t); return; | |
161 case addressTag: rpush(t); return; | |
162 } | |
163 ShouldNotReachHere(); | |
164 } | |
165 | |
166 Value ipop() { return check(intTag , _stack.pop()); } | |
167 Value fpop() { return check(floatTag , _stack.pop()); } | |
168 Value apop() { return check(objectTag , _stack.pop()); } | |
169 Value rpop() { return check(addressTag, _stack.pop()); } | |
170 Value lpop() { Value h = _stack.pop(); return check(longTag , _stack.pop(), h); } | |
171 Value dpop() { Value h = _stack.pop(); return check(doubleTag, _stack.pop(), h); } | |
172 | |
173 Value pop(ValueType* type) { | |
174 switch (type->tag()) { | |
175 case intTag : return ipop(); | |
176 case longTag : return lpop(); | |
177 case floatTag : return fpop(); | |
178 case doubleTag : return dpop(); | |
179 case objectTag : return apop(); | |
180 case addressTag: return rpop(); | |
181 } | |
182 ShouldNotReachHere(); | |
183 return NULL; | |
184 } | |
185 | |
186 Values* pop_arguments(int argument_size); | |
187 | |
188 // locks access | |
1819 | 189 int lock (Value obj); |
0 | 190 int unlock(); |
191 Value lock_at(int i) const { return _locks.at(i); } | |
192 | |
193 // SSA form IR support | |
194 void setup_phi_for_stack(BlockBegin* b, int index); | |
195 void setup_phi_for_local(BlockBegin* b, int index); | |
196 | |
197 // debugging | |
198 void print() PRODUCT_RETURN; | |
199 void verify() PRODUCT_RETURN; | |
200 }; | |
201 | |
202 | |
203 | |
204 // Macro definitions for simple iteration of stack and local values of a ValueStack | |
205 // The macros can be used like a for-loop. All variables (state, index and value) | |
206 // must be defined before the loop. | |
207 // When states are nested because of inlining, the stack of the innermost state | |
208 // cumulates also the stack of the nested states. In contrast, the locals of all | |
209 // states must be iterated each. | |
210 // Use the following code pattern to iterate all stack values and all nested local values: | |
211 // | |
212 // ValueStack* state = ... // state that is iterated | |
213 // int index; // current loop index (overwritten in loop) | |
214 // Value value; // value at current loop index (overwritten in loop) | |
215 // | |
216 // for_each_stack_value(state, index, value { | |
217 // do something with value and index | |
218 // } | |
219 // | |
220 // for_each_state(state) { | |
221 // for_each_local_value(state, index, value) { | |
222 // do something with value and index | |
223 // } | |
224 // } | |
225 // as an invariant, state is NULL now | |
226 | |
227 | |
228 // construct a unique variable name with the line number where the macro is used | |
229 #define temp_var3(x) temp__ ## x | |
230 #define temp_var2(x) temp_var3(x) | |
231 #define temp_var temp_var2(__LINE__) | |
232 | |
233 #define for_each_state(state) \ | |
234 for (; state != NULL; state = state->caller_state()) | |
235 | |
236 #define for_each_local_value(state, index, value) \ | |
237 int temp_var = state->locals_size(); \ | |
238 for (index = 0; \ | |
239 index < temp_var && (value = state->local_at(index), true); \ | |
240 index += (value == NULL || value->type()->is_illegal() ? 1 : value->type()->size())) \ | |
241 if (value != NULL) | |
242 | |
243 | |
244 #define for_each_stack_value(state, index, value) \ | |
245 int temp_var = state->stack_size(); \ | |
246 for (index = 0; \ | |
247 index < temp_var && (value = state->stack_at(index), true); \ | |
248 index += value->type()->size()) | |
249 | |
250 | |
251 #define for_each_lock_value(state, index, value) \ | |
252 int temp_var = state->locks_size(); \ | |
253 for (index = 0; \ | |
254 index < temp_var && (value = state->lock_at(index), true); \ | |
255 index++) \ | |
256 if (value != NULL) | |
257 | |
258 | |
259 // Macro definition for simple iteration of all state values of a ValueStack | |
260 // Because the code cannot be executed in a single loop, the code must be passed | |
261 // as a macro parameter. | |
262 // Use the following code pattern to iterate all stack values and all nested local values: | |
263 // | |
264 // ValueStack* state = ... // state that is iterated | |
265 // for_each_state_value(state, value, | |
266 // do something with value (note that this is a macro parameter) | |
267 // ); | |
268 | |
269 #define for_each_state_value(v_state, v_value, v_code) \ | |
270 { \ | |
271 int cur_index; \ | |
272 ValueStack* cur_state = v_state; \ | |
1819 | 273 Value v_value; \ |
274 for_each_state(cur_state) { \ | |
275 { \ | |
276 for_each_local_value(cur_state, cur_index, v_value) { \ | |
277 v_code; \ | |
278 } \ | |
0 | 279 } \ |
1819 | 280 { \ |
281 for_each_stack_value(cur_state, cur_index, v_value) { \ | |
282 v_code; \ | |
283 } \ | |
284 } \ | |
0 | 285 } \ |
286 } | |
287 | |
288 | |
289 // Macro definition for simple iteration of all phif functions of a block, i.e all | |
290 // phi functions of the ValueStack where the block matches. | |
291 // Use the following code pattern to iterate all phi functions of a block: | |
292 // | |
293 // BlockBegin* block = ... // block that is iterated | |
294 // for_each_phi_function(block, phi, | |
295 // do something with the phi function phi (note that this is a macro parameter) | |
296 // ); | |
297 | |
298 #define for_each_phi_fun(v_block, v_phi, v_code) \ | |
299 { \ | |
300 int cur_index; \ | |
301 ValueStack* cur_state = v_block->state(); \ | |
302 Value value; \ | |
303 { \ | |
304 for_each_stack_value(cur_state, cur_index, value) { \ | |
305 Phi* v_phi = value->as_Phi(); \ | |
306 if (v_phi != NULL && v_phi->block() == v_block) { \ | |
307 v_code; \ | |
308 } \ | |
309 } \ | |
310 } \ | |
311 { \ | |
312 for_each_local_value(cur_state, cur_index, value) { \ | |
313 Phi* v_phi = value->as_Phi(); \ | |
314 if (v_phi != NULL && v_phi->block() == v_block) { \ | |
315 v_code; \ | |
316 } \ | |
317 } \ | |
318 } \ | |
319 } |