annotate src/share/vm/c1/c1_Instruction.cpp @ 0:a61af66fc99e jdk7-b24

Initial load
author duke
date Sat, 01 Dec 2007 00:00:00 +0000
parents
children 3cf667df43ef
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 1999-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 #include "incls/_precompiled.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
26 #include "incls/_c1_Instruction.cpp.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
27
a61af66fc99e Initial load
duke
parents:
diff changeset
28
a61af66fc99e Initial load
duke
parents:
diff changeset
29 // Implementation of Instruction
a61af66fc99e Initial load
duke
parents:
diff changeset
30
a61af66fc99e Initial load
duke
parents:
diff changeset
31
a61af66fc99e Initial load
duke
parents:
diff changeset
32 int Instruction::_next_id = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
33
a61af66fc99e Initial load
duke
parents:
diff changeset
34 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
35 void Instruction::create_hi_word() {
a61af66fc99e Initial load
duke
parents:
diff changeset
36 assert(type()->is_double_word() && _hi_word == NULL, "only double word has high word");
a61af66fc99e Initial load
duke
parents:
diff changeset
37 _hi_word = new HiWord(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
38 }
a61af66fc99e Initial load
duke
parents:
diff changeset
39 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
40
a61af66fc99e Initial load
duke
parents:
diff changeset
41 Instruction::Condition Instruction::mirror(Condition cond) {
a61af66fc99e Initial load
duke
parents:
diff changeset
42 switch (cond) {
a61af66fc99e Initial load
duke
parents:
diff changeset
43 case eql: return eql;
a61af66fc99e Initial load
duke
parents:
diff changeset
44 case neq: return neq;
a61af66fc99e Initial load
duke
parents:
diff changeset
45 case lss: return gtr;
a61af66fc99e Initial load
duke
parents:
diff changeset
46 case leq: return geq;
a61af66fc99e Initial load
duke
parents:
diff changeset
47 case gtr: return lss;
a61af66fc99e Initial load
duke
parents:
diff changeset
48 case geq: return leq;
a61af66fc99e Initial load
duke
parents:
diff changeset
49 }
a61af66fc99e Initial load
duke
parents:
diff changeset
50 ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
51 return eql;
a61af66fc99e Initial load
duke
parents:
diff changeset
52 }
a61af66fc99e Initial load
duke
parents:
diff changeset
53
a61af66fc99e Initial load
duke
parents:
diff changeset
54
a61af66fc99e Initial load
duke
parents:
diff changeset
55 Instruction::Condition Instruction::negate(Condition cond) {
a61af66fc99e Initial load
duke
parents:
diff changeset
56 switch (cond) {
a61af66fc99e Initial load
duke
parents:
diff changeset
57 case eql: return neq;
a61af66fc99e Initial load
duke
parents:
diff changeset
58 case neq: return eql;
a61af66fc99e Initial load
duke
parents:
diff changeset
59 case lss: return geq;
a61af66fc99e Initial load
duke
parents:
diff changeset
60 case leq: return gtr;
a61af66fc99e Initial load
duke
parents:
diff changeset
61 case gtr: return leq;
a61af66fc99e Initial load
duke
parents:
diff changeset
62 case geq: return lss;
a61af66fc99e Initial load
duke
parents:
diff changeset
63 }
a61af66fc99e Initial load
duke
parents:
diff changeset
64 ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
65 return eql;
a61af66fc99e Initial load
duke
parents:
diff changeset
66 }
a61af66fc99e Initial load
duke
parents:
diff changeset
67
a61af66fc99e Initial load
duke
parents:
diff changeset
68
a61af66fc99e Initial load
duke
parents:
diff changeset
69 Instruction* Instruction::prev(BlockBegin* block) {
a61af66fc99e Initial load
duke
parents:
diff changeset
70 Instruction* p = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
71 Instruction* q = block;
a61af66fc99e Initial load
duke
parents:
diff changeset
72 while (q != this) {
a61af66fc99e Initial load
duke
parents:
diff changeset
73 assert(q != NULL, "this is not in the block's instruction list");
a61af66fc99e Initial load
duke
parents:
diff changeset
74 p = q; q = q->next();
a61af66fc99e Initial load
duke
parents:
diff changeset
75 }
a61af66fc99e Initial load
duke
parents:
diff changeset
76 return p;
a61af66fc99e Initial load
duke
parents:
diff changeset
77 }
a61af66fc99e Initial load
duke
parents:
diff changeset
78
a61af66fc99e Initial load
duke
parents:
diff changeset
79
a61af66fc99e Initial load
duke
parents:
diff changeset
80 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
81 void Instruction::print() {
a61af66fc99e Initial load
duke
parents:
diff changeset
82 InstructionPrinter ip;
a61af66fc99e Initial load
duke
parents:
diff changeset
83 print(ip);
a61af66fc99e Initial load
duke
parents:
diff changeset
84 }
a61af66fc99e Initial load
duke
parents:
diff changeset
85
a61af66fc99e Initial load
duke
parents:
diff changeset
86
a61af66fc99e Initial load
duke
parents:
diff changeset
87 void Instruction::print_line() {
a61af66fc99e Initial load
duke
parents:
diff changeset
88 InstructionPrinter ip;
a61af66fc99e Initial load
duke
parents:
diff changeset
89 ip.print_line(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
90 }
a61af66fc99e Initial load
duke
parents:
diff changeset
91
a61af66fc99e Initial load
duke
parents:
diff changeset
92
a61af66fc99e Initial load
duke
parents:
diff changeset
93 void Instruction::print(InstructionPrinter& ip) {
a61af66fc99e Initial load
duke
parents:
diff changeset
94 ip.print_head();
a61af66fc99e Initial load
duke
parents:
diff changeset
95 ip.print_line(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
96 tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
97 }
a61af66fc99e Initial load
duke
parents:
diff changeset
98 #endif // PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
99
a61af66fc99e Initial load
duke
parents:
diff changeset
100
a61af66fc99e Initial load
duke
parents:
diff changeset
101 // perform constant and interval tests on index value
a61af66fc99e Initial load
duke
parents:
diff changeset
102 bool AccessIndexed::compute_needs_range_check() {
a61af66fc99e Initial load
duke
parents:
diff changeset
103 Constant* clength = length()->as_Constant();
a61af66fc99e Initial load
duke
parents:
diff changeset
104 Constant* cindex = index()->as_Constant();
a61af66fc99e Initial load
duke
parents:
diff changeset
105 if (clength && cindex) {
a61af66fc99e Initial load
duke
parents:
diff changeset
106 IntConstant* l = clength->type()->as_IntConstant();
a61af66fc99e Initial load
duke
parents:
diff changeset
107 IntConstant* i = cindex->type()->as_IntConstant();
a61af66fc99e Initial load
duke
parents:
diff changeset
108 if (l && i && i->value() < l->value() && i->value() >= 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
109 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
110 }
a61af66fc99e Initial load
duke
parents:
diff changeset
111 }
a61af66fc99e Initial load
duke
parents:
diff changeset
112 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
113 }
a61af66fc99e Initial load
duke
parents:
diff changeset
114
a61af66fc99e Initial load
duke
parents:
diff changeset
115
a61af66fc99e Initial load
duke
parents:
diff changeset
116 ciType* LoadIndexed::exact_type() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
117 ciType* array_type = array()->exact_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
118 if (array_type == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
119 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
120 }
a61af66fc99e Initial load
duke
parents:
diff changeset
121 assert(array_type->is_array_klass(), "what else?");
a61af66fc99e Initial load
duke
parents:
diff changeset
122 ciArrayKlass* ak = (ciArrayKlass*)array_type;
a61af66fc99e Initial load
duke
parents:
diff changeset
123
a61af66fc99e Initial load
duke
parents:
diff changeset
124 if (ak->element_type()->is_instance_klass()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
125 ciInstanceKlass* ik = (ciInstanceKlass*)ak->element_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
126 if (ik->is_loaded() && ik->is_final()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
127 return ik;
a61af66fc99e Initial load
duke
parents:
diff changeset
128 }
a61af66fc99e Initial load
duke
parents:
diff changeset
129 }
a61af66fc99e Initial load
duke
parents:
diff changeset
130 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
131 }
a61af66fc99e Initial load
duke
parents:
diff changeset
132
a61af66fc99e Initial load
duke
parents:
diff changeset
133
a61af66fc99e Initial load
duke
parents:
diff changeset
134 ciType* LoadIndexed::declared_type() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
135 ciType* array_type = array()->declared_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
136 if (array_type == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
137 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
138 }
a61af66fc99e Initial load
duke
parents:
diff changeset
139 assert(array_type->is_array_klass(), "what else?");
a61af66fc99e Initial load
duke
parents:
diff changeset
140 ciArrayKlass* ak = (ciArrayKlass*)array_type;
a61af66fc99e Initial load
duke
parents:
diff changeset
141 return ak->element_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
142 }
a61af66fc99e Initial load
duke
parents:
diff changeset
143
a61af66fc99e Initial load
duke
parents:
diff changeset
144
a61af66fc99e Initial load
duke
parents:
diff changeset
145 ciType* LoadField::declared_type() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
146 return field()->type();
a61af66fc99e Initial load
duke
parents:
diff changeset
147 }
a61af66fc99e Initial load
duke
parents:
diff changeset
148
a61af66fc99e Initial load
duke
parents:
diff changeset
149
a61af66fc99e Initial load
duke
parents:
diff changeset
150 ciType* LoadField::exact_type() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
151 ciType* type = declared_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
152 // for primitive arrays, the declared type is the exact type
a61af66fc99e Initial load
duke
parents:
diff changeset
153 if (type->is_type_array_klass()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
154 return type;
a61af66fc99e Initial load
duke
parents:
diff changeset
155 }
a61af66fc99e Initial load
duke
parents:
diff changeset
156 if (type->is_instance_klass()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
157 ciInstanceKlass* ik = (ciInstanceKlass*)type;
a61af66fc99e Initial load
duke
parents:
diff changeset
158 if (ik->is_loaded() && ik->is_final()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
159 return type;
a61af66fc99e Initial load
duke
parents:
diff changeset
160 }
a61af66fc99e Initial load
duke
parents:
diff changeset
161 }
a61af66fc99e Initial load
duke
parents:
diff changeset
162 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
163 }
a61af66fc99e Initial load
duke
parents:
diff changeset
164
a61af66fc99e Initial load
duke
parents:
diff changeset
165
a61af66fc99e Initial load
duke
parents:
diff changeset
166 ciType* NewTypeArray::exact_type() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
167 return ciTypeArrayKlass::make(elt_type());
a61af66fc99e Initial load
duke
parents:
diff changeset
168 }
a61af66fc99e Initial load
duke
parents:
diff changeset
169
a61af66fc99e Initial load
duke
parents:
diff changeset
170
a61af66fc99e Initial load
duke
parents:
diff changeset
171 ciType* NewObjectArray::exact_type() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
172 return ciObjArrayKlass::make(klass());
a61af66fc99e Initial load
duke
parents:
diff changeset
173 }
a61af66fc99e Initial load
duke
parents:
diff changeset
174
a61af66fc99e Initial load
duke
parents:
diff changeset
175
a61af66fc99e Initial load
duke
parents:
diff changeset
176 ciType* NewInstance::exact_type() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
177 return klass();
a61af66fc99e Initial load
duke
parents:
diff changeset
178 }
a61af66fc99e Initial load
duke
parents:
diff changeset
179
a61af66fc99e Initial load
duke
parents:
diff changeset
180
a61af66fc99e Initial load
duke
parents:
diff changeset
181 ciType* CheckCast::declared_type() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
182 return klass();
a61af66fc99e Initial load
duke
parents:
diff changeset
183 }
a61af66fc99e Initial load
duke
parents:
diff changeset
184
a61af66fc99e Initial load
duke
parents:
diff changeset
185 ciType* CheckCast::exact_type() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
186 if (klass()->is_instance_klass()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
187 ciInstanceKlass* ik = (ciInstanceKlass*)klass();
a61af66fc99e Initial load
duke
parents:
diff changeset
188 if (ik->is_loaded() && ik->is_final()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
189 return ik;
a61af66fc99e Initial load
duke
parents:
diff changeset
190 }
a61af66fc99e Initial load
duke
parents:
diff changeset
191 }
a61af66fc99e Initial load
duke
parents:
diff changeset
192 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
193 }
a61af66fc99e Initial load
duke
parents:
diff changeset
194
a61af66fc99e Initial load
duke
parents:
diff changeset
195
a61af66fc99e Initial load
duke
parents:
diff changeset
196 void ArithmeticOp::other_values_do(void f(Value*)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
197 if (lock_stack() != NULL) lock_stack()->values_do(f);
a61af66fc99e Initial load
duke
parents:
diff changeset
198 }
a61af66fc99e Initial load
duke
parents:
diff changeset
199
a61af66fc99e Initial load
duke
parents:
diff changeset
200 void NullCheck::other_values_do(void f(Value*)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
201 lock_stack()->values_do(f);
a61af66fc99e Initial load
duke
parents:
diff changeset
202 }
a61af66fc99e Initial load
duke
parents:
diff changeset
203
a61af66fc99e Initial load
duke
parents:
diff changeset
204 void AccessArray::other_values_do(void f(Value*)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
205 if (lock_stack() != NULL) lock_stack()->values_do(f);
a61af66fc99e Initial load
duke
parents:
diff changeset
206 }
a61af66fc99e Initial load
duke
parents:
diff changeset
207
a61af66fc99e Initial load
duke
parents:
diff changeset
208
a61af66fc99e Initial load
duke
parents:
diff changeset
209 // Implementation of AccessField
a61af66fc99e Initial load
duke
parents:
diff changeset
210
a61af66fc99e Initial load
duke
parents:
diff changeset
211 void AccessField::other_values_do(void f(Value*)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
212 if (state_before() != NULL) state_before()->values_do(f);
a61af66fc99e Initial load
duke
parents:
diff changeset
213 if (lock_stack() != NULL) lock_stack()->values_do(f);
a61af66fc99e Initial load
duke
parents:
diff changeset
214 }
a61af66fc99e Initial load
duke
parents:
diff changeset
215
a61af66fc99e Initial load
duke
parents:
diff changeset
216
a61af66fc99e Initial load
duke
parents:
diff changeset
217 // Implementation of StoreIndexed
a61af66fc99e Initial load
duke
parents:
diff changeset
218
a61af66fc99e Initial load
duke
parents:
diff changeset
219 IRScope* StoreIndexed::scope() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
220 return lock_stack()->scope();
a61af66fc99e Initial load
duke
parents:
diff changeset
221 }
a61af66fc99e Initial load
duke
parents:
diff changeset
222
a61af66fc99e Initial load
duke
parents:
diff changeset
223
a61af66fc99e Initial load
duke
parents:
diff changeset
224 // Implementation of ArithmeticOp
a61af66fc99e Initial load
duke
parents:
diff changeset
225
a61af66fc99e Initial load
duke
parents:
diff changeset
226 bool ArithmeticOp::is_commutative() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
227 switch (op()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
228 case Bytecodes::_iadd: // fall through
a61af66fc99e Initial load
duke
parents:
diff changeset
229 case Bytecodes::_ladd: // fall through
a61af66fc99e Initial load
duke
parents:
diff changeset
230 case Bytecodes::_fadd: // fall through
a61af66fc99e Initial load
duke
parents:
diff changeset
231 case Bytecodes::_dadd: // fall through
a61af66fc99e Initial load
duke
parents:
diff changeset
232 case Bytecodes::_imul: // fall through
a61af66fc99e Initial load
duke
parents:
diff changeset
233 case Bytecodes::_lmul: // fall through
a61af66fc99e Initial load
duke
parents:
diff changeset
234 case Bytecodes::_fmul: // fall through
a61af66fc99e Initial load
duke
parents:
diff changeset
235 case Bytecodes::_dmul: return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
236 }
a61af66fc99e Initial load
duke
parents:
diff changeset
237 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
238 }
a61af66fc99e Initial load
duke
parents:
diff changeset
239
a61af66fc99e Initial load
duke
parents:
diff changeset
240
a61af66fc99e Initial load
duke
parents:
diff changeset
241 bool ArithmeticOp::can_trap() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
242 switch (op()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
243 case Bytecodes::_idiv: // fall through
a61af66fc99e Initial load
duke
parents:
diff changeset
244 case Bytecodes::_ldiv: // fall through
a61af66fc99e Initial load
duke
parents:
diff changeset
245 case Bytecodes::_irem: // fall through
a61af66fc99e Initial load
duke
parents:
diff changeset
246 case Bytecodes::_lrem: return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
247 }
a61af66fc99e Initial load
duke
parents:
diff changeset
248 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
249 }
a61af66fc99e Initial load
duke
parents:
diff changeset
250
a61af66fc99e Initial load
duke
parents:
diff changeset
251
a61af66fc99e Initial load
duke
parents:
diff changeset
252 // Implementation of LogicOp
a61af66fc99e Initial load
duke
parents:
diff changeset
253
a61af66fc99e Initial load
duke
parents:
diff changeset
254 bool LogicOp::is_commutative() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
255 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
256 switch (op()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
257 case Bytecodes::_iand: // fall through
a61af66fc99e Initial load
duke
parents:
diff changeset
258 case Bytecodes::_land: // fall through
a61af66fc99e Initial load
duke
parents:
diff changeset
259 case Bytecodes::_ior : // fall through
a61af66fc99e Initial load
duke
parents:
diff changeset
260 case Bytecodes::_lor : // fall through
a61af66fc99e Initial load
duke
parents:
diff changeset
261 case Bytecodes::_ixor: // fall through
a61af66fc99e Initial load
duke
parents:
diff changeset
262 case Bytecodes::_lxor: break;
a61af66fc99e Initial load
duke
parents:
diff changeset
263 default : ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
264 }
a61af66fc99e Initial load
duke
parents:
diff changeset
265 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
266 // all LogicOps are commutative
a61af66fc99e Initial load
duke
parents:
diff changeset
267 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
268 }
a61af66fc99e Initial load
duke
parents:
diff changeset
269
a61af66fc99e Initial load
duke
parents:
diff changeset
270
a61af66fc99e Initial load
duke
parents:
diff changeset
271 // Implementation of CompareOp
a61af66fc99e Initial load
duke
parents:
diff changeset
272
a61af66fc99e Initial load
duke
parents:
diff changeset
273 void CompareOp::other_values_do(void f(Value*)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
274 if (state_before() != NULL) state_before()->values_do(f);
a61af66fc99e Initial load
duke
parents:
diff changeset
275 }
a61af66fc99e Initial load
duke
parents:
diff changeset
276
a61af66fc99e Initial load
duke
parents:
diff changeset
277
a61af66fc99e Initial load
duke
parents:
diff changeset
278 // Implementation of IfOp
a61af66fc99e Initial load
duke
parents:
diff changeset
279
a61af66fc99e Initial load
duke
parents:
diff changeset
280 bool IfOp::is_commutative() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
281 return cond() == eql || cond() == neq;
a61af66fc99e Initial load
duke
parents:
diff changeset
282 }
a61af66fc99e Initial load
duke
parents:
diff changeset
283
a61af66fc99e Initial load
duke
parents:
diff changeset
284
a61af66fc99e Initial load
duke
parents:
diff changeset
285 // Implementation of StateSplit
a61af66fc99e Initial load
duke
parents:
diff changeset
286
a61af66fc99e Initial load
duke
parents:
diff changeset
287 void StateSplit::substitute(BlockList& list, BlockBegin* old_block, BlockBegin* new_block) {
a61af66fc99e Initial load
duke
parents:
diff changeset
288 NOT_PRODUCT(bool assigned = false;)
a61af66fc99e Initial load
duke
parents:
diff changeset
289 for (int i = 0; i < list.length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
290 BlockBegin** b = list.adr_at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
291 if (*b == old_block) {
a61af66fc99e Initial load
duke
parents:
diff changeset
292 *b = new_block;
a61af66fc99e Initial load
duke
parents:
diff changeset
293 NOT_PRODUCT(assigned = true;)
a61af66fc99e Initial load
duke
parents:
diff changeset
294 }
a61af66fc99e Initial load
duke
parents:
diff changeset
295 }
a61af66fc99e Initial load
duke
parents:
diff changeset
296 assert(assigned == true, "should have assigned at least once");
a61af66fc99e Initial load
duke
parents:
diff changeset
297 }
a61af66fc99e Initial load
duke
parents:
diff changeset
298
a61af66fc99e Initial load
duke
parents:
diff changeset
299
a61af66fc99e Initial load
duke
parents:
diff changeset
300 IRScope* StateSplit::scope() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
301 return _state->scope();
a61af66fc99e Initial load
duke
parents:
diff changeset
302 }
a61af66fc99e Initial load
duke
parents:
diff changeset
303
a61af66fc99e Initial load
duke
parents:
diff changeset
304
a61af66fc99e Initial load
duke
parents:
diff changeset
305 void StateSplit::state_values_do(void f(Value*)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
306 if (state() != NULL) state()->values_do(f);
a61af66fc99e Initial load
duke
parents:
diff changeset
307 }
a61af66fc99e Initial load
duke
parents:
diff changeset
308
a61af66fc99e Initial load
duke
parents:
diff changeset
309
a61af66fc99e Initial load
duke
parents:
diff changeset
310 void BlockBegin::state_values_do(void f(Value*)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
311 StateSplit::state_values_do(f);
a61af66fc99e Initial load
duke
parents:
diff changeset
312
a61af66fc99e Initial load
duke
parents:
diff changeset
313 if (is_set(BlockBegin::exception_entry_flag)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
314 for (int i = 0; i < number_of_exception_states(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
315 exception_state_at(i)->values_do(f);
a61af66fc99e Initial load
duke
parents:
diff changeset
316 }
a61af66fc99e Initial load
duke
parents:
diff changeset
317 }
a61af66fc99e Initial load
duke
parents:
diff changeset
318 }
a61af66fc99e Initial load
duke
parents:
diff changeset
319
a61af66fc99e Initial load
duke
parents:
diff changeset
320
a61af66fc99e Initial load
duke
parents:
diff changeset
321 void MonitorEnter::state_values_do(void f(Value*)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
322 StateSplit::state_values_do(f);
a61af66fc99e Initial load
duke
parents:
diff changeset
323 _lock_stack_before->values_do(f);
a61af66fc99e Initial load
duke
parents:
diff changeset
324 }
a61af66fc99e Initial load
duke
parents:
diff changeset
325
a61af66fc99e Initial load
duke
parents:
diff changeset
326
a61af66fc99e Initial load
duke
parents:
diff changeset
327 void Intrinsic::state_values_do(void f(Value*)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
328 StateSplit::state_values_do(f);
a61af66fc99e Initial load
duke
parents:
diff changeset
329 if (lock_stack() != NULL) lock_stack()->values_do(f);
a61af66fc99e Initial load
duke
parents:
diff changeset
330 }
a61af66fc99e Initial load
duke
parents:
diff changeset
331
a61af66fc99e Initial load
duke
parents:
diff changeset
332
a61af66fc99e Initial load
duke
parents:
diff changeset
333 // Implementation of Invoke
a61af66fc99e Initial load
duke
parents:
diff changeset
334
a61af66fc99e Initial load
duke
parents:
diff changeset
335
a61af66fc99e Initial load
duke
parents:
diff changeset
336 Invoke::Invoke(Bytecodes::Code code, ValueType* result_type, Value recv, Values* args,
a61af66fc99e Initial load
duke
parents:
diff changeset
337 int vtable_index, ciMethod* target)
a61af66fc99e Initial load
duke
parents:
diff changeset
338 : StateSplit(result_type)
a61af66fc99e Initial load
duke
parents:
diff changeset
339 , _code(code)
a61af66fc99e Initial load
duke
parents:
diff changeset
340 , _recv(recv)
a61af66fc99e Initial load
duke
parents:
diff changeset
341 , _args(args)
a61af66fc99e Initial load
duke
parents:
diff changeset
342 , _vtable_index(vtable_index)
a61af66fc99e Initial load
duke
parents:
diff changeset
343 , _target(target)
a61af66fc99e Initial load
duke
parents:
diff changeset
344 {
a61af66fc99e Initial load
duke
parents:
diff changeset
345 set_flag(TargetIsLoadedFlag, target->is_loaded());
a61af66fc99e Initial load
duke
parents:
diff changeset
346 set_flag(TargetIsFinalFlag, target_is_loaded() && target->is_final_method());
a61af66fc99e Initial load
duke
parents:
diff changeset
347 set_flag(TargetIsStrictfpFlag, target_is_loaded() && target->is_strict());
a61af66fc99e Initial load
duke
parents:
diff changeset
348
a61af66fc99e Initial load
duke
parents:
diff changeset
349 assert(args != NULL, "args must exist");
a61af66fc99e Initial load
duke
parents:
diff changeset
350 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
351 values_do(assert_value);
a61af66fc99e Initial load
duke
parents:
diff changeset
352 #endif // ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
353
a61af66fc99e Initial load
duke
parents:
diff changeset
354 // provide an initial guess of signature size.
a61af66fc99e Initial load
duke
parents:
diff changeset
355 _signature = new BasicTypeList(number_of_arguments() + (has_receiver() ? 1 : 0));
a61af66fc99e Initial load
duke
parents:
diff changeset
356 if (has_receiver()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
357 _signature->append(as_BasicType(receiver()->type()));
a61af66fc99e Initial load
duke
parents:
diff changeset
358 }
a61af66fc99e Initial load
duke
parents:
diff changeset
359 for (int i = 0; i < number_of_arguments(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
360 ValueType* t = argument_at(i)->type();
a61af66fc99e Initial load
duke
parents:
diff changeset
361 BasicType bt = as_BasicType(t);
a61af66fc99e Initial load
duke
parents:
diff changeset
362 _signature->append(bt);
a61af66fc99e Initial load
duke
parents:
diff changeset
363 }
a61af66fc99e Initial load
duke
parents:
diff changeset
364 }
a61af66fc99e Initial load
duke
parents:
diff changeset
365
a61af66fc99e Initial load
duke
parents:
diff changeset
366
a61af66fc99e Initial load
duke
parents:
diff changeset
367 // Implementation of Contant
a61af66fc99e Initial load
duke
parents:
diff changeset
368 intx Constant::hash() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
369 if (_state == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
370 switch (type()->tag()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
371 case intTag:
a61af66fc99e Initial load
duke
parents:
diff changeset
372 return HASH2(name(), type()->as_IntConstant()->value());
a61af66fc99e Initial load
duke
parents:
diff changeset
373 case longTag:
a61af66fc99e Initial load
duke
parents:
diff changeset
374 {
a61af66fc99e Initial load
duke
parents:
diff changeset
375 jlong temp = type()->as_LongConstant()->value();
a61af66fc99e Initial load
duke
parents:
diff changeset
376 return HASH3(name(), high(temp), low(temp));
a61af66fc99e Initial load
duke
parents:
diff changeset
377 }
a61af66fc99e Initial load
duke
parents:
diff changeset
378 case floatTag:
a61af66fc99e Initial load
duke
parents:
diff changeset
379 return HASH2(name(), jint_cast(type()->as_FloatConstant()->value()));
a61af66fc99e Initial load
duke
parents:
diff changeset
380 case doubleTag:
a61af66fc99e Initial load
duke
parents:
diff changeset
381 {
a61af66fc99e Initial load
duke
parents:
diff changeset
382 jlong temp = jlong_cast(type()->as_DoubleConstant()->value());
a61af66fc99e Initial load
duke
parents:
diff changeset
383 return HASH3(name(), high(temp), low(temp));
a61af66fc99e Initial load
duke
parents:
diff changeset
384 }
a61af66fc99e Initial load
duke
parents:
diff changeset
385 case objectTag:
a61af66fc99e Initial load
duke
parents:
diff changeset
386 assert(type()->as_ObjectType()->is_loaded(), "can't handle unloaded values");
a61af66fc99e Initial load
duke
parents:
diff changeset
387 return HASH2(name(), type()->as_ObjectType()->constant_value());
a61af66fc99e Initial load
duke
parents:
diff changeset
388 }
a61af66fc99e Initial load
duke
parents:
diff changeset
389 }
a61af66fc99e Initial load
duke
parents:
diff changeset
390 return 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
391 }
a61af66fc99e Initial load
duke
parents:
diff changeset
392
a61af66fc99e Initial load
duke
parents:
diff changeset
393 bool Constant::is_equal(Value v) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
394 if (v->as_Constant() == NULL) return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
395
a61af66fc99e Initial load
duke
parents:
diff changeset
396 switch (type()->tag()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
397 case intTag:
a61af66fc99e Initial load
duke
parents:
diff changeset
398 {
a61af66fc99e Initial load
duke
parents:
diff changeset
399 IntConstant* t1 = type()->as_IntConstant();
a61af66fc99e Initial load
duke
parents:
diff changeset
400 IntConstant* t2 = v->type()->as_IntConstant();
a61af66fc99e Initial load
duke
parents:
diff changeset
401 return (t1 != NULL && t2 != NULL &&
a61af66fc99e Initial load
duke
parents:
diff changeset
402 t1->value() == t2->value());
a61af66fc99e Initial load
duke
parents:
diff changeset
403 }
a61af66fc99e Initial load
duke
parents:
diff changeset
404 case longTag:
a61af66fc99e Initial load
duke
parents:
diff changeset
405 {
a61af66fc99e Initial load
duke
parents:
diff changeset
406 LongConstant* t1 = type()->as_LongConstant();
a61af66fc99e Initial load
duke
parents:
diff changeset
407 LongConstant* t2 = v->type()->as_LongConstant();
a61af66fc99e Initial load
duke
parents:
diff changeset
408 return (t1 != NULL && t2 != NULL &&
a61af66fc99e Initial load
duke
parents:
diff changeset
409 t1->value() == t2->value());
a61af66fc99e Initial load
duke
parents:
diff changeset
410 }
a61af66fc99e Initial load
duke
parents:
diff changeset
411 case floatTag:
a61af66fc99e Initial load
duke
parents:
diff changeset
412 {
a61af66fc99e Initial load
duke
parents:
diff changeset
413 FloatConstant* t1 = type()->as_FloatConstant();
a61af66fc99e Initial load
duke
parents:
diff changeset
414 FloatConstant* t2 = v->type()->as_FloatConstant();
a61af66fc99e Initial load
duke
parents:
diff changeset
415 return (t1 != NULL && t2 != NULL &&
a61af66fc99e Initial load
duke
parents:
diff changeset
416 jint_cast(t1->value()) == jint_cast(t2->value()));
a61af66fc99e Initial load
duke
parents:
diff changeset
417 }
a61af66fc99e Initial load
duke
parents:
diff changeset
418 case doubleTag:
a61af66fc99e Initial load
duke
parents:
diff changeset
419 {
a61af66fc99e Initial load
duke
parents:
diff changeset
420 DoubleConstant* t1 = type()->as_DoubleConstant();
a61af66fc99e Initial load
duke
parents:
diff changeset
421 DoubleConstant* t2 = v->type()->as_DoubleConstant();
a61af66fc99e Initial load
duke
parents:
diff changeset
422 return (t1 != NULL && t2 != NULL &&
a61af66fc99e Initial load
duke
parents:
diff changeset
423 jlong_cast(t1->value()) == jlong_cast(t2->value()));
a61af66fc99e Initial load
duke
parents:
diff changeset
424 }
a61af66fc99e Initial load
duke
parents:
diff changeset
425 case objectTag:
a61af66fc99e Initial load
duke
parents:
diff changeset
426 {
a61af66fc99e Initial load
duke
parents:
diff changeset
427 ObjectType* t1 = type()->as_ObjectType();
a61af66fc99e Initial load
duke
parents:
diff changeset
428 ObjectType* t2 = v->type()->as_ObjectType();
a61af66fc99e Initial load
duke
parents:
diff changeset
429 return (t1 != NULL && t2 != NULL &&
a61af66fc99e Initial load
duke
parents:
diff changeset
430 t1->is_loaded() && t2->is_loaded() &&
a61af66fc99e Initial load
duke
parents:
diff changeset
431 t1->constant_value() == t2->constant_value());
a61af66fc99e Initial load
duke
parents:
diff changeset
432 }
a61af66fc99e Initial load
duke
parents:
diff changeset
433 }
a61af66fc99e Initial load
duke
parents:
diff changeset
434 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
435 }
a61af66fc99e Initial load
duke
parents:
diff changeset
436
a61af66fc99e Initial load
duke
parents:
diff changeset
437
a61af66fc99e Initial load
duke
parents:
diff changeset
438 BlockBegin* Constant::compare(Instruction::Condition cond, Value right,
a61af66fc99e Initial load
duke
parents:
diff changeset
439 BlockBegin* true_sux, BlockBegin* false_sux) {
a61af66fc99e Initial load
duke
parents:
diff changeset
440 Constant* rc = right->as_Constant();
a61af66fc99e Initial load
duke
parents:
diff changeset
441 // other is not a constant
a61af66fc99e Initial load
duke
parents:
diff changeset
442 if (rc == NULL) return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
443
a61af66fc99e Initial load
duke
parents:
diff changeset
444 ValueType* lt = type();
a61af66fc99e Initial load
duke
parents:
diff changeset
445 ValueType* rt = rc->type();
a61af66fc99e Initial load
duke
parents:
diff changeset
446 // different types
a61af66fc99e Initial load
duke
parents:
diff changeset
447 if (lt->base() != rt->base()) return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
448 switch (lt->tag()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
449 case intTag: {
a61af66fc99e Initial load
duke
parents:
diff changeset
450 int x = lt->as_IntConstant()->value();
a61af66fc99e Initial load
duke
parents:
diff changeset
451 int y = rt->as_IntConstant()->value();
a61af66fc99e Initial load
duke
parents:
diff changeset
452 switch (cond) {
a61af66fc99e Initial load
duke
parents:
diff changeset
453 case If::eql: return x == y ? true_sux : false_sux;
a61af66fc99e Initial load
duke
parents:
diff changeset
454 case If::neq: return x != y ? true_sux : false_sux;
a61af66fc99e Initial load
duke
parents:
diff changeset
455 case If::lss: return x < y ? true_sux : false_sux;
a61af66fc99e Initial load
duke
parents:
diff changeset
456 case If::leq: return x <= y ? true_sux : false_sux;
a61af66fc99e Initial load
duke
parents:
diff changeset
457 case If::gtr: return x > y ? true_sux : false_sux;
a61af66fc99e Initial load
duke
parents:
diff changeset
458 case If::geq: return x >= y ? true_sux : false_sux;
a61af66fc99e Initial load
duke
parents:
diff changeset
459 }
a61af66fc99e Initial load
duke
parents:
diff changeset
460 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
461 }
a61af66fc99e Initial load
duke
parents:
diff changeset
462 case longTag: {
a61af66fc99e Initial load
duke
parents:
diff changeset
463 jlong x = lt->as_LongConstant()->value();
a61af66fc99e Initial load
duke
parents:
diff changeset
464 jlong y = rt->as_LongConstant()->value();
a61af66fc99e Initial load
duke
parents:
diff changeset
465 switch (cond) {
a61af66fc99e Initial load
duke
parents:
diff changeset
466 case If::eql: return x == y ? true_sux : false_sux;
a61af66fc99e Initial load
duke
parents:
diff changeset
467 case If::neq: return x != y ? true_sux : false_sux;
a61af66fc99e Initial load
duke
parents:
diff changeset
468 case If::lss: return x < y ? true_sux : false_sux;
a61af66fc99e Initial load
duke
parents:
diff changeset
469 case If::leq: return x <= y ? true_sux : false_sux;
a61af66fc99e Initial load
duke
parents:
diff changeset
470 case If::gtr: return x > y ? true_sux : false_sux;
a61af66fc99e Initial load
duke
parents:
diff changeset
471 case If::geq: return x >= y ? true_sux : false_sux;
a61af66fc99e Initial load
duke
parents:
diff changeset
472 }
a61af66fc99e Initial load
duke
parents:
diff changeset
473 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
474 }
a61af66fc99e Initial load
duke
parents:
diff changeset
475 case objectTag: {
a61af66fc99e Initial load
duke
parents:
diff changeset
476 ciObject* xvalue = lt->as_ObjectType()->constant_value();
a61af66fc99e Initial load
duke
parents:
diff changeset
477 ciObject* yvalue = rt->as_ObjectType()->constant_value();
a61af66fc99e Initial load
duke
parents:
diff changeset
478 assert(xvalue != NULL && yvalue != NULL, "not constants");
a61af66fc99e Initial load
duke
parents:
diff changeset
479 if (xvalue->is_loaded() && yvalue->is_loaded()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
480 switch (cond) {
a61af66fc99e Initial load
duke
parents:
diff changeset
481 case If::eql: return xvalue == yvalue ? true_sux : false_sux;
a61af66fc99e Initial load
duke
parents:
diff changeset
482 case If::neq: return xvalue != yvalue ? true_sux : false_sux;
a61af66fc99e Initial load
duke
parents:
diff changeset
483 }
a61af66fc99e Initial load
duke
parents:
diff changeset
484 }
a61af66fc99e Initial load
duke
parents:
diff changeset
485 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
486 }
a61af66fc99e Initial load
duke
parents:
diff changeset
487 }
a61af66fc99e Initial load
duke
parents:
diff changeset
488 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
489 }
a61af66fc99e Initial load
duke
parents:
diff changeset
490
a61af66fc99e Initial load
duke
parents:
diff changeset
491
a61af66fc99e Initial load
duke
parents:
diff changeset
492 void Constant::other_values_do(void f(Value*)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
493 if (state() != NULL) state()->values_do(f);
a61af66fc99e Initial load
duke
parents:
diff changeset
494 }
a61af66fc99e Initial load
duke
parents:
diff changeset
495
a61af66fc99e Initial load
duke
parents:
diff changeset
496
a61af66fc99e Initial load
duke
parents:
diff changeset
497 // Implementation of NewArray
a61af66fc99e Initial load
duke
parents:
diff changeset
498
a61af66fc99e Initial load
duke
parents:
diff changeset
499 void NewArray::other_values_do(void f(Value*)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
500 if (state_before() != NULL) state_before()->values_do(f);
a61af66fc99e Initial load
duke
parents:
diff changeset
501 }
a61af66fc99e Initial load
duke
parents:
diff changeset
502
a61af66fc99e Initial load
duke
parents:
diff changeset
503
a61af66fc99e Initial load
duke
parents:
diff changeset
504 // Implementation of TypeCheck
a61af66fc99e Initial load
duke
parents:
diff changeset
505
a61af66fc99e Initial load
duke
parents:
diff changeset
506 void TypeCheck::other_values_do(void f(Value*)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
507 if (state_before() != NULL) state_before()->values_do(f);
a61af66fc99e Initial load
duke
parents:
diff changeset
508 }
a61af66fc99e Initial load
duke
parents:
diff changeset
509
a61af66fc99e Initial load
duke
parents:
diff changeset
510
a61af66fc99e Initial load
duke
parents:
diff changeset
511 // Implementation of BlockBegin
a61af66fc99e Initial load
duke
parents:
diff changeset
512
a61af66fc99e Initial load
duke
parents:
diff changeset
513 int BlockBegin::_next_block_id = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
514
a61af66fc99e Initial load
duke
parents:
diff changeset
515
a61af66fc99e Initial load
duke
parents:
diff changeset
516 void BlockBegin::set_end(BlockEnd* end) {
a61af66fc99e Initial load
duke
parents:
diff changeset
517 assert(end != NULL, "should not reset block end to NULL");
a61af66fc99e Initial load
duke
parents:
diff changeset
518 BlockEnd* old_end = _end;
a61af66fc99e Initial load
duke
parents:
diff changeset
519 if (end == old_end) {
a61af66fc99e Initial load
duke
parents:
diff changeset
520 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
521 }
a61af66fc99e Initial load
duke
parents:
diff changeset
522 // Must make the predecessors/successors match up with the
a61af66fc99e Initial load
duke
parents:
diff changeset
523 // BlockEnd's notion.
a61af66fc99e Initial load
duke
parents:
diff changeset
524 int i, n;
a61af66fc99e Initial load
duke
parents:
diff changeset
525 if (old_end != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
526 // disconnect from the old end
a61af66fc99e Initial load
duke
parents:
diff changeset
527 old_end->set_begin(NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
528
a61af66fc99e Initial load
duke
parents:
diff changeset
529 // disconnect this block from it's current successors
a61af66fc99e Initial load
duke
parents:
diff changeset
530 for (i = 0; i < _successors.length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
531 _successors.at(i)->remove_predecessor(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
532 }
a61af66fc99e Initial load
duke
parents:
diff changeset
533 }
a61af66fc99e Initial load
duke
parents:
diff changeset
534 _end = end;
a61af66fc99e Initial load
duke
parents:
diff changeset
535
a61af66fc99e Initial load
duke
parents:
diff changeset
536 _successors.clear();
a61af66fc99e Initial load
duke
parents:
diff changeset
537 // Now reset successors list based on BlockEnd
a61af66fc99e Initial load
duke
parents:
diff changeset
538 n = end->number_of_sux();
a61af66fc99e Initial load
duke
parents:
diff changeset
539 for (i = 0; i < n; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
540 BlockBegin* sux = end->sux_at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
541 _successors.append(sux);
a61af66fc99e Initial load
duke
parents:
diff changeset
542 sux->_predecessors.append(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
543 }
a61af66fc99e Initial load
duke
parents:
diff changeset
544 _end->set_begin(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
545 }
a61af66fc99e Initial load
duke
parents:
diff changeset
546
a61af66fc99e Initial load
duke
parents:
diff changeset
547
a61af66fc99e Initial load
duke
parents:
diff changeset
548 void BlockBegin::disconnect_edge(BlockBegin* from, BlockBegin* to) {
a61af66fc99e Initial load
duke
parents:
diff changeset
549 // disconnect any edges between from and to
a61af66fc99e Initial load
duke
parents:
diff changeset
550 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
551 if (PrintIR && Verbose) {
a61af66fc99e Initial load
duke
parents:
diff changeset
552 tty->print_cr("Disconnected edge B%d -> B%d", from->block_id(), to->block_id());
a61af66fc99e Initial load
duke
parents:
diff changeset
553 }
a61af66fc99e Initial load
duke
parents:
diff changeset
554 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
555 for (int s = 0; s < from->number_of_sux();) {
a61af66fc99e Initial load
duke
parents:
diff changeset
556 BlockBegin* sux = from->sux_at(s);
a61af66fc99e Initial load
duke
parents:
diff changeset
557 if (sux == to) {
a61af66fc99e Initial load
duke
parents:
diff changeset
558 int index = sux->_predecessors.index_of(from);
a61af66fc99e Initial load
duke
parents:
diff changeset
559 if (index >= 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
560 sux->_predecessors.remove_at(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
561 }
a61af66fc99e Initial load
duke
parents:
diff changeset
562 from->_successors.remove_at(s);
a61af66fc99e Initial load
duke
parents:
diff changeset
563 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
564 s++;
a61af66fc99e Initial load
duke
parents:
diff changeset
565 }
a61af66fc99e Initial load
duke
parents:
diff changeset
566 }
a61af66fc99e Initial load
duke
parents:
diff changeset
567 }
a61af66fc99e Initial load
duke
parents:
diff changeset
568
a61af66fc99e Initial load
duke
parents:
diff changeset
569
a61af66fc99e Initial load
duke
parents:
diff changeset
570 void BlockBegin::disconnect_from_graph() {
a61af66fc99e Initial load
duke
parents:
diff changeset
571 // disconnect this block from all other blocks
a61af66fc99e Initial load
duke
parents:
diff changeset
572 for (int p = 0; p < number_of_preds(); p++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
573 pred_at(p)->remove_successor(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
574 }
a61af66fc99e Initial load
duke
parents:
diff changeset
575 for (int s = 0; s < number_of_sux(); s++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
576 sux_at(s)->remove_predecessor(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
577 }
a61af66fc99e Initial load
duke
parents:
diff changeset
578 }
a61af66fc99e Initial load
duke
parents:
diff changeset
579
a61af66fc99e Initial load
duke
parents:
diff changeset
580 void BlockBegin::substitute_sux(BlockBegin* old_sux, BlockBegin* new_sux) {
a61af66fc99e Initial load
duke
parents:
diff changeset
581 // modify predecessors before substituting successors
a61af66fc99e Initial load
duke
parents:
diff changeset
582 for (int i = 0; i < number_of_sux(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
583 if (sux_at(i) == old_sux) {
a61af66fc99e Initial load
duke
parents:
diff changeset
584 // remove old predecessor before adding new predecessor
a61af66fc99e Initial load
duke
parents:
diff changeset
585 // otherwise there is a dead predecessor in the list
a61af66fc99e Initial load
duke
parents:
diff changeset
586 new_sux->remove_predecessor(old_sux);
a61af66fc99e Initial load
duke
parents:
diff changeset
587 new_sux->add_predecessor(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
588 }
a61af66fc99e Initial load
duke
parents:
diff changeset
589 }
a61af66fc99e Initial load
duke
parents:
diff changeset
590 old_sux->remove_predecessor(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
591 end()->substitute_sux(old_sux, new_sux);
a61af66fc99e Initial load
duke
parents:
diff changeset
592 }
a61af66fc99e Initial load
duke
parents:
diff changeset
593
a61af66fc99e Initial load
duke
parents:
diff changeset
594
a61af66fc99e Initial load
duke
parents:
diff changeset
595
a61af66fc99e Initial load
duke
parents:
diff changeset
596 // In general it is not possible to calculate a value for the field "depth_first_number"
a61af66fc99e Initial load
duke
parents:
diff changeset
597 // of the inserted block, without recomputing the values of the other blocks
a61af66fc99e Initial load
duke
parents:
diff changeset
598 // in the CFG. Therefore the value of "depth_first_number" in BlockBegin becomes meaningless.
a61af66fc99e Initial load
duke
parents:
diff changeset
599 BlockBegin* BlockBegin::insert_block_between(BlockBegin* sux) {
a61af66fc99e Initial load
duke
parents:
diff changeset
600 // Try to make the bci close to a block with a single pred or sux,
a61af66fc99e Initial load
duke
parents:
diff changeset
601 // since this make the block layout algorithm work better.
a61af66fc99e Initial load
duke
parents:
diff changeset
602 int bci = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
603 if (sux->number_of_preds() == 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
604 bci = sux->bci();
a61af66fc99e Initial load
duke
parents:
diff changeset
605 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
606 bci = end()->bci();
a61af66fc99e Initial load
duke
parents:
diff changeset
607 }
a61af66fc99e Initial load
duke
parents:
diff changeset
608
a61af66fc99e Initial load
duke
parents:
diff changeset
609 BlockBegin* new_sux = new BlockBegin(bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
610
a61af66fc99e Initial load
duke
parents:
diff changeset
611 // mark this block (special treatment when block order is computed)
a61af66fc99e Initial load
duke
parents:
diff changeset
612 new_sux->set(critical_edge_split_flag);
a61af66fc99e Initial load
duke
parents:
diff changeset
613
a61af66fc99e Initial load
duke
parents:
diff changeset
614 // This goto is not a safepoint.
a61af66fc99e Initial load
duke
parents:
diff changeset
615 Goto* e = new Goto(sux, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
616 new_sux->set_next(e, bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
617 new_sux->set_end(e);
a61af66fc99e Initial load
duke
parents:
diff changeset
618 // setup states
a61af66fc99e Initial load
duke
parents:
diff changeset
619 ValueStack* s = end()->state();
a61af66fc99e Initial load
duke
parents:
diff changeset
620 new_sux->set_state(s->copy());
a61af66fc99e Initial load
duke
parents:
diff changeset
621 e->set_state(s->copy());
a61af66fc99e Initial load
duke
parents:
diff changeset
622 assert(new_sux->state()->locals_size() == s->locals_size(), "local size mismatch!");
a61af66fc99e Initial load
duke
parents:
diff changeset
623 assert(new_sux->state()->stack_size() == s->stack_size(), "stack size mismatch!");
a61af66fc99e Initial load
duke
parents:
diff changeset
624 assert(new_sux->state()->locks_size() == s->locks_size(), "locks size mismatch!");
a61af66fc99e Initial load
duke
parents:
diff changeset
625
a61af66fc99e Initial load
duke
parents:
diff changeset
626 // link predecessor to new block
a61af66fc99e Initial load
duke
parents:
diff changeset
627 end()->substitute_sux(sux, new_sux);
a61af66fc99e Initial load
duke
parents:
diff changeset
628
a61af66fc99e Initial load
duke
parents:
diff changeset
629 // The ordering needs to be the same, so remove the link that the
a61af66fc99e Initial load
duke
parents:
diff changeset
630 // set_end call above added and substitute the new_sux for this
a61af66fc99e Initial load
duke
parents:
diff changeset
631 // block.
a61af66fc99e Initial load
duke
parents:
diff changeset
632 sux->remove_predecessor(new_sux);
a61af66fc99e Initial load
duke
parents:
diff changeset
633
a61af66fc99e Initial load
duke
parents:
diff changeset
634 // the successor could be the target of a switch so it might have
a61af66fc99e Initial load
duke
parents:
diff changeset
635 // multiple copies of this predecessor, so substitute the new_sux
a61af66fc99e Initial load
duke
parents:
diff changeset
636 // for the first and delete the rest.
a61af66fc99e Initial load
duke
parents:
diff changeset
637 bool assigned = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
638 BlockList& list = sux->_predecessors;
a61af66fc99e Initial load
duke
parents:
diff changeset
639 for (int i = 0; i < list.length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
640 BlockBegin** b = list.adr_at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
641 if (*b == this) {
a61af66fc99e Initial load
duke
parents:
diff changeset
642 if (assigned) {
a61af66fc99e Initial load
duke
parents:
diff changeset
643 list.remove_at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
644 // reprocess this index
a61af66fc99e Initial load
duke
parents:
diff changeset
645 i--;
a61af66fc99e Initial load
duke
parents:
diff changeset
646 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
647 assigned = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
648 *b = new_sux;
a61af66fc99e Initial load
duke
parents:
diff changeset
649 }
a61af66fc99e Initial load
duke
parents:
diff changeset
650 // link the new block back to it's predecessors.
a61af66fc99e Initial load
duke
parents:
diff changeset
651 new_sux->add_predecessor(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
652 }
a61af66fc99e Initial load
duke
parents:
diff changeset
653 }
a61af66fc99e Initial load
duke
parents:
diff changeset
654 assert(assigned == true, "should have assigned at least once");
a61af66fc99e Initial load
duke
parents:
diff changeset
655 return new_sux;
a61af66fc99e Initial load
duke
parents:
diff changeset
656 }
a61af66fc99e Initial load
duke
parents:
diff changeset
657
a61af66fc99e Initial load
duke
parents:
diff changeset
658
a61af66fc99e Initial load
duke
parents:
diff changeset
659 void BlockBegin::remove_successor(BlockBegin* pred) {
a61af66fc99e Initial load
duke
parents:
diff changeset
660 int idx;
a61af66fc99e Initial load
duke
parents:
diff changeset
661 while ((idx = _successors.index_of(pred)) >= 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
662 _successors.remove_at(idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
663 }
a61af66fc99e Initial load
duke
parents:
diff changeset
664 }
a61af66fc99e Initial load
duke
parents:
diff changeset
665
a61af66fc99e Initial load
duke
parents:
diff changeset
666
a61af66fc99e Initial load
duke
parents:
diff changeset
667 void BlockBegin::add_predecessor(BlockBegin* pred) {
a61af66fc99e Initial load
duke
parents:
diff changeset
668 _predecessors.append(pred);
a61af66fc99e Initial load
duke
parents:
diff changeset
669 }
a61af66fc99e Initial load
duke
parents:
diff changeset
670
a61af66fc99e Initial load
duke
parents:
diff changeset
671
a61af66fc99e Initial load
duke
parents:
diff changeset
672 void BlockBegin::remove_predecessor(BlockBegin* pred) {
a61af66fc99e Initial load
duke
parents:
diff changeset
673 int idx;
a61af66fc99e Initial load
duke
parents:
diff changeset
674 while ((idx = _predecessors.index_of(pred)) >= 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
675 _predecessors.remove_at(idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
676 }
a61af66fc99e Initial load
duke
parents:
diff changeset
677 }
a61af66fc99e Initial load
duke
parents:
diff changeset
678
a61af66fc99e Initial load
duke
parents:
diff changeset
679
a61af66fc99e Initial load
duke
parents:
diff changeset
680 void BlockBegin::add_exception_handler(BlockBegin* b) {
a61af66fc99e Initial load
duke
parents:
diff changeset
681 assert(b != NULL && (b->is_set(exception_entry_flag)), "exception handler must exist");
a61af66fc99e Initial load
duke
parents:
diff changeset
682 // add only if not in the list already
a61af66fc99e Initial load
duke
parents:
diff changeset
683 if (!_exception_handlers.contains(b)) _exception_handlers.append(b);
a61af66fc99e Initial load
duke
parents:
diff changeset
684 }
a61af66fc99e Initial load
duke
parents:
diff changeset
685
a61af66fc99e Initial load
duke
parents:
diff changeset
686 int BlockBegin::add_exception_state(ValueStack* state) {
a61af66fc99e Initial load
duke
parents:
diff changeset
687 assert(is_set(exception_entry_flag), "only for xhandlers");
a61af66fc99e Initial load
duke
parents:
diff changeset
688 if (_exception_states == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
689 _exception_states = new ValueStackStack(4);
a61af66fc99e Initial load
duke
parents:
diff changeset
690 }
a61af66fc99e Initial load
duke
parents:
diff changeset
691 _exception_states->append(state);
a61af66fc99e Initial load
duke
parents:
diff changeset
692 return _exception_states->length() - 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
693 }
a61af66fc99e Initial load
duke
parents:
diff changeset
694
a61af66fc99e Initial load
duke
parents:
diff changeset
695
a61af66fc99e Initial load
duke
parents:
diff changeset
696 void BlockBegin::iterate_preorder(boolArray& mark, BlockClosure* closure) {
a61af66fc99e Initial load
duke
parents:
diff changeset
697 if (!mark.at(block_id())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
698 mark.at_put(block_id(), true);
a61af66fc99e Initial load
duke
parents:
diff changeset
699 closure->block_do(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
700 BlockEnd* e = end(); // must do this after block_do because block_do may change it!
a61af66fc99e Initial load
duke
parents:
diff changeset
701 { for (int i = number_of_exception_handlers() - 1; i >= 0; i--) exception_handler_at(i)->iterate_preorder(mark, closure); }
a61af66fc99e Initial load
duke
parents:
diff changeset
702 { for (int i = e->number_of_sux () - 1; i >= 0; i--) e->sux_at (i)->iterate_preorder(mark, closure); }
a61af66fc99e Initial load
duke
parents:
diff changeset
703 }
a61af66fc99e Initial load
duke
parents:
diff changeset
704 }
a61af66fc99e Initial load
duke
parents:
diff changeset
705
a61af66fc99e Initial load
duke
parents:
diff changeset
706
a61af66fc99e Initial load
duke
parents:
diff changeset
707 void BlockBegin::iterate_postorder(boolArray& mark, BlockClosure* closure) {
a61af66fc99e Initial load
duke
parents:
diff changeset
708 if (!mark.at(block_id())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
709 mark.at_put(block_id(), true);
a61af66fc99e Initial load
duke
parents:
diff changeset
710 BlockEnd* e = end();
a61af66fc99e Initial load
duke
parents:
diff changeset
711 { for (int i = number_of_exception_handlers() - 1; i >= 0; i--) exception_handler_at(i)->iterate_postorder(mark, closure); }
a61af66fc99e Initial load
duke
parents:
diff changeset
712 { for (int i = e->number_of_sux () - 1; i >= 0; i--) e->sux_at (i)->iterate_postorder(mark, closure); }
a61af66fc99e Initial load
duke
parents:
diff changeset
713 closure->block_do(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
714 }
a61af66fc99e Initial load
duke
parents:
diff changeset
715 }
a61af66fc99e Initial load
duke
parents:
diff changeset
716
a61af66fc99e Initial load
duke
parents:
diff changeset
717
a61af66fc99e Initial load
duke
parents:
diff changeset
718 void BlockBegin::iterate_preorder(BlockClosure* closure) {
a61af66fc99e Initial load
duke
parents:
diff changeset
719 boolArray mark(number_of_blocks(), false);
a61af66fc99e Initial load
duke
parents:
diff changeset
720 iterate_preorder(mark, closure);
a61af66fc99e Initial load
duke
parents:
diff changeset
721 }
a61af66fc99e Initial load
duke
parents:
diff changeset
722
a61af66fc99e Initial load
duke
parents:
diff changeset
723
a61af66fc99e Initial load
duke
parents:
diff changeset
724 void BlockBegin::iterate_postorder(BlockClosure* closure) {
a61af66fc99e Initial load
duke
parents:
diff changeset
725 boolArray mark(number_of_blocks(), false);
a61af66fc99e Initial load
duke
parents:
diff changeset
726 iterate_postorder(mark, closure);
a61af66fc99e Initial load
duke
parents:
diff changeset
727 }
a61af66fc99e Initial load
duke
parents:
diff changeset
728
a61af66fc99e Initial load
duke
parents:
diff changeset
729
a61af66fc99e Initial load
duke
parents:
diff changeset
730 void BlockBegin::block_values_do(void f(Value*)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
731 for (Instruction* n = this; n != NULL; n = n->next()) n->values_do(f);
a61af66fc99e Initial load
duke
parents:
diff changeset
732 }
a61af66fc99e Initial load
duke
parents:
diff changeset
733
a61af66fc99e Initial load
duke
parents:
diff changeset
734
a61af66fc99e Initial load
duke
parents:
diff changeset
735 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
736 #define TRACE_PHI(code) if (PrintPhiFunctions) { code; }
a61af66fc99e Initial load
duke
parents:
diff changeset
737 #else
a61af66fc99e Initial load
duke
parents:
diff changeset
738 #define TRACE_PHI(coce)
a61af66fc99e Initial load
duke
parents:
diff changeset
739 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
740
a61af66fc99e Initial load
duke
parents:
diff changeset
741
a61af66fc99e Initial load
duke
parents:
diff changeset
742 bool BlockBegin::try_merge(ValueStack* new_state) {
a61af66fc99e Initial load
duke
parents:
diff changeset
743 TRACE_PHI(tty->print_cr("********** try_merge for block B%d", block_id()));
a61af66fc99e Initial load
duke
parents:
diff changeset
744
a61af66fc99e Initial load
duke
parents:
diff changeset
745 // local variables used for state iteration
a61af66fc99e Initial load
duke
parents:
diff changeset
746 int index;
a61af66fc99e Initial load
duke
parents:
diff changeset
747 Value new_value, existing_value;
a61af66fc99e Initial load
duke
parents:
diff changeset
748
a61af66fc99e Initial load
duke
parents:
diff changeset
749 ValueStack* existing_state = state();
a61af66fc99e Initial load
duke
parents:
diff changeset
750 if (existing_state == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
751 TRACE_PHI(tty->print_cr("first call of try_merge for this block"));
a61af66fc99e Initial load
duke
parents:
diff changeset
752
a61af66fc99e Initial load
duke
parents:
diff changeset
753 if (is_set(BlockBegin::was_visited_flag)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
754 // this actually happens for complicated jsr/ret structures
a61af66fc99e Initial load
duke
parents:
diff changeset
755 return false; // BAILOUT in caller
a61af66fc99e Initial load
duke
parents:
diff changeset
756 }
a61af66fc99e Initial load
duke
parents:
diff changeset
757
a61af66fc99e Initial load
duke
parents:
diff changeset
758 // copy state because it is altered
a61af66fc99e Initial load
duke
parents:
diff changeset
759 new_state = new_state->copy();
a61af66fc99e Initial load
duke
parents:
diff changeset
760
a61af66fc99e Initial load
duke
parents:
diff changeset
761 // Use method liveness to invalidate dead locals
a61af66fc99e Initial load
duke
parents:
diff changeset
762 MethodLivenessResult liveness = new_state->scope()->method()->liveness_at_bci(bci());
a61af66fc99e Initial load
duke
parents:
diff changeset
763 if (liveness.is_valid()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
764 assert((int)liveness.size() == new_state->locals_size(), "error in use of liveness");
a61af66fc99e Initial load
duke
parents:
diff changeset
765
a61af66fc99e Initial load
duke
parents:
diff changeset
766 for_each_local_value(new_state, index, new_value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
767 if (!liveness.at(index) || new_value->type()->is_illegal()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
768 new_state->invalidate_local(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
769 TRACE_PHI(tty->print_cr("invalidating dead local %d", index));
a61af66fc99e Initial load
duke
parents:
diff changeset
770 }
a61af66fc99e Initial load
duke
parents:
diff changeset
771 }
a61af66fc99e Initial load
duke
parents:
diff changeset
772 }
a61af66fc99e Initial load
duke
parents:
diff changeset
773
a61af66fc99e Initial load
duke
parents:
diff changeset
774 if (is_set(BlockBegin::parser_loop_header_flag)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
775 TRACE_PHI(tty->print_cr("loop header block, initializing phi functions"));
a61af66fc99e Initial load
duke
parents:
diff changeset
776
a61af66fc99e Initial load
duke
parents:
diff changeset
777 for_each_stack_value(new_state, index, new_value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
778 new_state->setup_phi_for_stack(this, index);
a61af66fc99e Initial load
duke
parents:
diff changeset
779 TRACE_PHI(tty->print_cr("creating phi-function %c%d for stack %d", new_state->stack_at(index)->type()->tchar(), new_state->stack_at(index)->id(), index));
a61af66fc99e Initial load
duke
parents:
diff changeset
780 }
a61af66fc99e Initial load
duke
parents:
diff changeset
781
a61af66fc99e Initial load
duke
parents:
diff changeset
782 BitMap requires_phi_function = new_state->scope()->requires_phi_function();
a61af66fc99e Initial load
duke
parents:
diff changeset
783
a61af66fc99e Initial load
duke
parents:
diff changeset
784 for_each_local_value(new_state, index, new_value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
785 bool requires_phi = requires_phi_function.at(index) || (new_value->type()->is_double_word() && requires_phi_function.at(index + 1));
a61af66fc99e Initial load
duke
parents:
diff changeset
786 if (requires_phi || !SelectivePhiFunctions) {
a61af66fc99e Initial load
duke
parents:
diff changeset
787 new_state->setup_phi_for_local(this, index);
a61af66fc99e Initial load
duke
parents:
diff changeset
788 TRACE_PHI(tty->print_cr("creating phi-function %c%d for local %d", new_state->local_at(index)->type()->tchar(), new_state->local_at(index)->id(), index));
a61af66fc99e Initial load
duke
parents:
diff changeset
789 }
a61af66fc99e Initial load
duke
parents:
diff changeset
790 }
a61af66fc99e Initial load
duke
parents:
diff changeset
791 }
a61af66fc99e Initial load
duke
parents:
diff changeset
792
a61af66fc99e Initial load
duke
parents:
diff changeset
793 // initialize state of block
a61af66fc99e Initial load
duke
parents:
diff changeset
794 set_state(new_state);
a61af66fc99e Initial load
duke
parents:
diff changeset
795
a61af66fc99e Initial load
duke
parents:
diff changeset
796 } else if (existing_state->is_same_across_scopes(new_state)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
797 TRACE_PHI(tty->print_cr("exisiting state found"));
a61af66fc99e Initial load
duke
parents:
diff changeset
798
a61af66fc99e Initial load
duke
parents:
diff changeset
799 // Inlining may cause the local state not to match up, so walk up
a61af66fc99e Initial load
duke
parents:
diff changeset
800 // the new state until we get to the same scope as the
a61af66fc99e Initial load
duke
parents:
diff changeset
801 // existing and then start processing from there.
a61af66fc99e Initial load
duke
parents:
diff changeset
802 while (existing_state->scope() != new_state->scope()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
803 new_state = new_state->caller_state();
a61af66fc99e Initial load
duke
parents:
diff changeset
804 assert(new_state != NULL, "could not match up scopes");
a61af66fc99e Initial load
duke
parents:
diff changeset
805
a61af66fc99e Initial load
duke
parents:
diff changeset
806 assert(false, "check if this is necessary");
a61af66fc99e Initial load
duke
parents:
diff changeset
807 }
a61af66fc99e Initial load
duke
parents:
diff changeset
808
a61af66fc99e Initial load
duke
parents:
diff changeset
809 assert(existing_state->scope() == new_state->scope(), "not matching");
a61af66fc99e Initial load
duke
parents:
diff changeset
810 assert(existing_state->locals_size() == new_state->locals_size(), "not matching");
a61af66fc99e Initial load
duke
parents:
diff changeset
811 assert(existing_state->stack_size() == new_state->stack_size(), "not matching");
a61af66fc99e Initial load
duke
parents:
diff changeset
812
a61af66fc99e Initial load
duke
parents:
diff changeset
813 if (is_set(BlockBegin::was_visited_flag)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
814 TRACE_PHI(tty->print_cr("loop header block, phis must be present"));
a61af66fc99e Initial load
duke
parents:
diff changeset
815
a61af66fc99e Initial load
duke
parents:
diff changeset
816 if (!is_set(BlockBegin::parser_loop_header_flag)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
817 // this actually happens for complicated jsr/ret structures
a61af66fc99e Initial load
duke
parents:
diff changeset
818 return false; // BAILOUT in caller
a61af66fc99e Initial load
duke
parents:
diff changeset
819 }
a61af66fc99e Initial load
duke
parents:
diff changeset
820
a61af66fc99e Initial load
duke
parents:
diff changeset
821 for_each_local_value(existing_state, index, existing_value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
822 Value new_value = new_state->local_at(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
823 if (new_value == NULL || new_value->type()->tag() != existing_value->type()->tag()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
824 // The old code invalidated the phi function here
a61af66fc99e Initial load
duke
parents:
diff changeset
825 // Because dead locals are replaced with NULL, this is a very rare case now, so simply bail out
a61af66fc99e Initial load
duke
parents:
diff changeset
826 return false; // BAILOUT in caller
a61af66fc99e Initial load
duke
parents:
diff changeset
827 }
a61af66fc99e Initial load
duke
parents:
diff changeset
828 }
a61af66fc99e Initial load
duke
parents:
diff changeset
829
a61af66fc99e Initial load
duke
parents:
diff changeset
830 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
831 // check that all necessary phi functions are present
a61af66fc99e Initial load
duke
parents:
diff changeset
832 for_each_stack_value(existing_state, index, existing_value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
833 assert(existing_value->as_Phi() != NULL && existing_value->as_Phi()->block() == this, "phi function required");
a61af66fc99e Initial load
duke
parents:
diff changeset
834 }
a61af66fc99e Initial load
duke
parents:
diff changeset
835 for_each_local_value(existing_state, index, existing_value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
836 assert(existing_value == new_state->local_at(index) || (existing_value->as_Phi() != NULL && existing_value->as_Phi()->as_Phi()->block() == this), "phi function required");
a61af66fc99e Initial load
duke
parents:
diff changeset
837 }
a61af66fc99e Initial load
duke
parents:
diff changeset
838 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
839
a61af66fc99e Initial load
duke
parents:
diff changeset
840 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
841 TRACE_PHI(tty->print_cr("creating phi functions on demand"));
a61af66fc99e Initial load
duke
parents:
diff changeset
842
a61af66fc99e Initial load
duke
parents:
diff changeset
843 // create necessary phi functions for stack
a61af66fc99e Initial load
duke
parents:
diff changeset
844 for_each_stack_value(existing_state, index, existing_value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
845 Value new_value = new_state->stack_at(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
846 Phi* existing_phi = existing_value->as_Phi();
a61af66fc99e Initial load
duke
parents:
diff changeset
847
a61af66fc99e Initial load
duke
parents:
diff changeset
848 if (new_value != existing_value && (existing_phi == NULL || existing_phi->block() != this)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
849 existing_state->setup_phi_for_stack(this, index);
a61af66fc99e Initial load
duke
parents:
diff changeset
850 TRACE_PHI(tty->print_cr("creating phi-function %c%d for stack %d", existing_state->stack_at(index)->type()->tchar(), existing_state->stack_at(index)->id(), index));
a61af66fc99e Initial load
duke
parents:
diff changeset
851 }
a61af66fc99e Initial load
duke
parents:
diff changeset
852 }
a61af66fc99e Initial load
duke
parents:
diff changeset
853
a61af66fc99e Initial load
duke
parents:
diff changeset
854 // create necessary phi functions for locals
a61af66fc99e Initial load
duke
parents:
diff changeset
855 for_each_local_value(existing_state, index, existing_value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
856 Value new_value = new_state->local_at(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
857 Phi* existing_phi = existing_value->as_Phi();
a61af66fc99e Initial load
duke
parents:
diff changeset
858
a61af66fc99e Initial load
duke
parents:
diff changeset
859 if (new_value == NULL || new_value->type()->tag() != existing_value->type()->tag()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
860 existing_state->invalidate_local(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
861 TRACE_PHI(tty->print_cr("invalidating local %d because of type mismatch", index));
a61af66fc99e Initial load
duke
parents:
diff changeset
862 } else if (new_value != existing_value && (existing_phi == NULL || existing_phi->block() != this)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
863 existing_state->setup_phi_for_local(this, index);
a61af66fc99e Initial load
duke
parents:
diff changeset
864 TRACE_PHI(tty->print_cr("creating phi-function %c%d for local %d", existing_state->local_at(index)->type()->tchar(), existing_state->local_at(index)->id(), index));
a61af66fc99e Initial load
duke
parents:
diff changeset
865 }
a61af66fc99e Initial load
duke
parents:
diff changeset
866 }
a61af66fc99e Initial load
duke
parents:
diff changeset
867 }
a61af66fc99e Initial load
duke
parents:
diff changeset
868
a61af66fc99e Initial load
duke
parents:
diff changeset
869 assert(existing_state->caller_state() == new_state->caller_state(), "caller states must be equal");
a61af66fc99e Initial load
duke
parents:
diff changeset
870
a61af66fc99e Initial load
duke
parents:
diff changeset
871 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
872 assert(false, "stack or locks not matching (invalid bytecodes)");
a61af66fc99e Initial load
duke
parents:
diff changeset
873 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
874 }
a61af66fc99e Initial load
duke
parents:
diff changeset
875
a61af66fc99e Initial load
duke
parents:
diff changeset
876 TRACE_PHI(tty->print_cr("********** try_merge for block B%d successful", block_id()));
a61af66fc99e Initial load
duke
parents:
diff changeset
877
a61af66fc99e Initial load
duke
parents:
diff changeset
878 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
879 }
a61af66fc99e Initial load
duke
parents:
diff changeset
880
a61af66fc99e Initial load
duke
parents:
diff changeset
881
a61af66fc99e Initial load
duke
parents:
diff changeset
882 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
883 void BlockBegin::print_block() {
a61af66fc99e Initial load
duke
parents:
diff changeset
884 InstructionPrinter ip;
a61af66fc99e Initial load
duke
parents:
diff changeset
885 print_block(ip, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
886 }
a61af66fc99e Initial load
duke
parents:
diff changeset
887
a61af66fc99e Initial load
duke
parents:
diff changeset
888
a61af66fc99e Initial load
duke
parents:
diff changeset
889 void BlockBegin::print_block(InstructionPrinter& ip, bool live_only) {
a61af66fc99e Initial load
duke
parents:
diff changeset
890 ip.print_instr(this); tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
891 ip.print_stack(this->state()); tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
892 ip.print_inline_level(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
893 ip.print_head();
a61af66fc99e Initial load
duke
parents:
diff changeset
894 for (Instruction* n = next(); n != NULL; n = n->next()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
895 if (!live_only || n->is_pinned() || n->use_count() > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
896 ip.print_line(n);
a61af66fc99e Initial load
duke
parents:
diff changeset
897 }
a61af66fc99e Initial load
duke
parents:
diff changeset
898 }
a61af66fc99e Initial load
duke
parents:
diff changeset
899 tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
900 }
a61af66fc99e Initial load
duke
parents:
diff changeset
901 #endif // PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
902
a61af66fc99e Initial load
duke
parents:
diff changeset
903
a61af66fc99e Initial load
duke
parents:
diff changeset
904 // Implementation of BlockList
a61af66fc99e Initial load
duke
parents:
diff changeset
905
a61af66fc99e Initial load
duke
parents:
diff changeset
906 void BlockList::iterate_forward (BlockClosure* closure) {
a61af66fc99e Initial load
duke
parents:
diff changeset
907 const int l = length();
a61af66fc99e Initial load
duke
parents:
diff changeset
908 for (int i = 0; i < l; i++) closure->block_do(at(i));
a61af66fc99e Initial load
duke
parents:
diff changeset
909 }
a61af66fc99e Initial load
duke
parents:
diff changeset
910
a61af66fc99e Initial load
duke
parents:
diff changeset
911
a61af66fc99e Initial load
duke
parents:
diff changeset
912 void BlockList::iterate_backward(BlockClosure* closure) {
a61af66fc99e Initial load
duke
parents:
diff changeset
913 for (int i = length() - 1; i >= 0; i--) closure->block_do(at(i));
a61af66fc99e Initial load
duke
parents:
diff changeset
914 }
a61af66fc99e Initial load
duke
parents:
diff changeset
915
a61af66fc99e Initial load
duke
parents:
diff changeset
916
a61af66fc99e Initial load
duke
parents:
diff changeset
917 void BlockList::blocks_do(void f(BlockBegin*)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
918 for (int i = length() - 1; i >= 0; i--) f(at(i));
a61af66fc99e Initial load
duke
parents:
diff changeset
919 }
a61af66fc99e Initial load
duke
parents:
diff changeset
920
a61af66fc99e Initial load
duke
parents:
diff changeset
921
a61af66fc99e Initial load
duke
parents:
diff changeset
922 void BlockList::values_do(void f(Value*)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
923 for (int i = length() - 1; i >= 0; i--) at(i)->block_values_do(f);
a61af66fc99e Initial load
duke
parents:
diff changeset
924 }
a61af66fc99e Initial load
duke
parents:
diff changeset
925
a61af66fc99e Initial load
duke
parents:
diff changeset
926
a61af66fc99e Initial load
duke
parents:
diff changeset
927 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
928 void BlockList::print(bool cfg_only, bool live_only) {
a61af66fc99e Initial load
duke
parents:
diff changeset
929 InstructionPrinter ip;
a61af66fc99e Initial load
duke
parents:
diff changeset
930 for (int i = 0; i < length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
931 BlockBegin* block = at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
932 if (cfg_only) {
a61af66fc99e Initial load
duke
parents:
diff changeset
933 ip.print_instr(block); tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
934 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
935 block->print_block(ip, live_only);
a61af66fc99e Initial load
duke
parents:
diff changeset
936 }
a61af66fc99e Initial load
duke
parents:
diff changeset
937 }
a61af66fc99e Initial load
duke
parents:
diff changeset
938 }
a61af66fc99e Initial load
duke
parents:
diff changeset
939 #endif // PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
940
a61af66fc99e Initial load
duke
parents:
diff changeset
941
a61af66fc99e Initial load
duke
parents:
diff changeset
942 // Implementation of BlockEnd
a61af66fc99e Initial load
duke
parents:
diff changeset
943
a61af66fc99e Initial load
duke
parents:
diff changeset
944 void BlockEnd::set_begin(BlockBegin* begin) {
a61af66fc99e Initial load
duke
parents:
diff changeset
945 BlockList* sux = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
946 if (begin != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
947 sux = begin->successors();
a61af66fc99e Initial load
duke
parents:
diff changeset
948 } else if (_begin != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
949 // copy our sux list
a61af66fc99e Initial load
duke
parents:
diff changeset
950 BlockList* sux = new BlockList(_begin->number_of_sux());
a61af66fc99e Initial load
duke
parents:
diff changeset
951 for (int i = 0; i < _begin->number_of_sux(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
952 sux->append(_begin->sux_at(i));
a61af66fc99e Initial load
duke
parents:
diff changeset
953 }
a61af66fc99e Initial load
duke
parents:
diff changeset
954 }
a61af66fc99e Initial load
duke
parents:
diff changeset
955 _sux = sux;
a61af66fc99e Initial load
duke
parents:
diff changeset
956 _begin = begin;
a61af66fc99e Initial load
duke
parents:
diff changeset
957 }
a61af66fc99e Initial load
duke
parents:
diff changeset
958
a61af66fc99e Initial load
duke
parents:
diff changeset
959
a61af66fc99e Initial load
duke
parents:
diff changeset
960 void BlockEnd::substitute_sux(BlockBegin* old_sux, BlockBegin* new_sux) {
a61af66fc99e Initial load
duke
parents:
diff changeset
961 substitute(*_sux, old_sux, new_sux);
a61af66fc99e Initial load
duke
parents:
diff changeset
962 }
a61af66fc99e Initial load
duke
parents:
diff changeset
963
a61af66fc99e Initial load
duke
parents:
diff changeset
964
a61af66fc99e Initial load
duke
parents:
diff changeset
965 void BlockEnd::other_values_do(void f(Value*)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
966 if (state_before() != NULL) state_before()->values_do(f);
a61af66fc99e Initial load
duke
parents:
diff changeset
967 }
a61af66fc99e Initial load
duke
parents:
diff changeset
968
a61af66fc99e Initial load
duke
parents:
diff changeset
969
a61af66fc99e Initial load
duke
parents:
diff changeset
970 // Implementation of Phi
a61af66fc99e Initial load
duke
parents:
diff changeset
971
a61af66fc99e Initial load
duke
parents:
diff changeset
972 // Normal phi functions take their operands from the last instruction of the
a61af66fc99e Initial load
duke
parents:
diff changeset
973 // predecessor. Special handling is needed for xhanlder entries because there
a61af66fc99e Initial load
duke
parents:
diff changeset
974 // the state of arbitrary instructions are needed.
a61af66fc99e Initial load
duke
parents:
diff changeset
975
a61af66fc99e Initial load
duke
parents:
diff changeset
976 Value Phi::operand_at(int i) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
977 ValueStack* state;
a61af66fc99e Initial load
duke
parents:
diff changeset
978 if (_block->is_set(BlockBegin::exception_entry_flag)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
979 state = _block->exception_state_at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
980 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
981 state = _block->pred_at(i)->end()->state();
a61af66fc99e Initial load
duke
parents:
diff changeset
982 }
a61af66fc99e Initial load
duke
parents:
diff changeset
983 assert(state != NULL, "");
a61af66fc99e Initial load
duke
parents:
diff changeset
984
a61af66fc99e Initial load
duke
parents:
diff changeset
985 if (is_local()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
986 return state->local_at(local_index());
a61af66fc99e Initial load
duke
parents:
diff changeset
987 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
988 return state->stack_at(stack_index());
a61af66fc99e Initial load
duke
parents:
diff changeset
989 }
a61af66fc99e Initial load
duke
parents:
diff changeset
990 }
a61af66fc99e Initial load
duke
parents:
diff changeset
991
a61af66fc99e Initial load
duke
parents:
diff changeset
992
a61af66fc99e Initial load
duke
parents:
diff changeset
993 int Phi::operand_count() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
994 if (_block->is_set(BlockBegin::exception_entry_flag)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
995 return _block->number_of_exception_states();
a61af66fc99e Initial load
duke
parents:
diff changeset
996 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
997 return _block->number_of_preds();
a61af66fc99e Initial load
duke
parents:
diff changeset
998 }
a61af66fc99e Initial load
duke
parents:
diff changeset
999 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1000
a61af66fc99e Initial load
duke
parents:
diff changeset
1001
a61af66fc99e Initial load
duke
parents:
diff changeset
1002 // Implementation of Throw
a61af66fc99e Initial load
duke
parents:
diff changeset
1003
a61af66fc99e Initial load
duke
parents:
diff changeset
1004 void Throw::state_values_do(void f(Value*)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1005 BlockEnd::state_values_do(f);
a61af66fc99e Initial load
duke
parents:
diff changeset
1006 }