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