Mercurial > hg > truffle
annotate src/share/vm/c1/c1_Instruction.cpp @ 1994:6cd6d394f280
7001033: assert(gch->gc_cause() == GCCause::_scavenge_alot || !gch->incremental_collection_failed())
7002546: regression on SpecJbb2005 on 7b118 comparing to 7b117 on small heaps
Summary: Relaxed assertion checking related to incremental_collection_failed flag to allow for ExplicitGCInvokesConcurrent behaviour where we do not want a failing scavenge to bail to a stop-world collection. Parameterized incremental_collection_will_fail() so we can selectively use, or not use, as appropriate, the statistical prediction at specific use sites. This essentially reverts the scavenge bail-out logic to what it was prior to some recent changes that had inadvertently started using the statistical prediction which can be noisy in the presence of bursty loads. Added some associated verbose non-product debugging messages.
Reviewed-by: johnc, tonyp
author | ysr |
---|---|
date | Tue, 07 Dec 2010 21:55:53 -0800 |
parents | f95d63e2154a |
children | 13bc79b5c9c8 6c9cec219ce4 |
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 | |
138 ciType* LoadIndexed::exact_type() const { | |
139 ciType* array_type = array()->exact_type(); | |
140 if (array_type == NULL) { | |
141 return NULL; | |
142 } | |
143 assert(array_type->is_array_klass(), "what else?"); | |
144 ciArrayKlass* ak = (ciArrayKlass*)array_type; | |
145 | |
146 if (ak->element_type()->is_instance_klass()) { | |
147 ciInstanceKlass* ik = (ciInstanceKlass*)ak->element_type(); | |
148 if (ik->is_loaded() && ik->is_final()) { | |
149 return ik; | |
150 } | |
151 } | |
152 return NULL; | |
153 } | |
154 | |
155 | |
156 ciType* LoadIndexed::declared_type() const { | |
157 ciType* array_type = array()->declared_type(); | |
158 if (array_type == NULL) { | |
159 return NULL; | |
160 } | |
161 assert(array_type->is_array_klass(), "what else?"); | |
162 ciArrayKlass* ak = (ciArrayKlass*)array_type; | |
163 return ak->element_type(); | |
164 } | |
165 | |
166 | |
167 ciType* LoadField::declared_type() const { | |
168 return field()->type(); | |
169 } | |
170 | |
171 | |
172 ciType* LoadField::exact_type() const { | |
173 ciType* type = declared_type(); | |
174 // for primitive arrays, the declared type is the exact type | |
175 if (type->is_type_array_klass()) { | |
176 return type; | |
177 } | |
178 if (type->is_instance_klass()) { | |
179 ciInstanceKlass* ik = (ciInstanceKlass*)type; | |
180 if (ik->is_loaded() && ik->is_final()) { | |
181 return type; | |
182 } | |
183 } | |
184 return NULL; | |
185 } | |
186 | |
187 | |
188 ciType* NewTypeArray::exact_type() const { | |
189 return ciTypeArrayKlass::make(elt_type()); | |
190 } | |
191 | |
192 | |
193 ciType* NewObjectArray::exact_type() const { | |
194 return ciObjArrayKlass::make(klass()); | |
195 } | |
196 | |
197 | |
198 ciType* NewInstance::exact_type() const { | |
199 return klass(); | |
200 } | |
201 | |
202 | |
203 ciType* CheckCast::declared_type() const { | |
204 return klass(); | |
205 } | |
206 | |
207 ciType* CheckCast::exact_type() const { | |
208 if (klass()->is_instance_klass()) { | |
209 ciInstanceKlass* ik = (ciInstanceKlass*)klass(); | |
210 if (ik->is_loaded() && ik->is_final()) { | |
211 return ik; | |
212 } | |
213 } | |
214 return NULL; | |
215 } | |
216 | |
217 // Implementation of ArithmeticOp | |
218 | |
219 bool ArithmeticOp::is_commutative() const { | |
220 switch (op()) { | |
221 case Bytecodes::_iadd: // fall through | |
222 case Bytecodes::_ladd: // fall through | |
223 case Bytecodes::_fadd: // fall through | |
224 case Bytecodes::_dadd: // fall through | |
225 case Bytecodes::_imul: // fall through | |
226 case Bytecodes::_lmul: // fall through | |
227 case Bytecodes::_fmul: // fall through | |
228 case Bytecodes::_dmul: return true; | |
229 } | |
230 return false; | |
231 } | |
232 | |
233 | |
234 bool ArithmeticOp::can_trap() const { | |
235 switch (op()) { | |
236 case Bytecodes::_idiv: // fall through | |
237 case Bytecodes::_ldiv: // fall through | |
238 case Bytecodes::_irem: // fall through | |
239 case Bytecodes::_lrem: return true; | |
240 } | |
241 return false; | |
242 } | |
243 | |
244 | |
245 // Implementation of LogicOp | |
246 | |
247 bool LogicOp::is_commutative() const { | |
248 #ifdef ASSERT | |
249 switch (op()) { | |
250 case Bytecodes::_iand: // fall through | |
251 case Bytecodes::_land: // fall through | |
252 case Bytecodes::_ior : // fall through | |
253 case Bytecodes::_lor : // fall through | |
254 case Bytecodes::_ixor: // fall through | |
255 case Bytecodes::_lxor: break; | |
256 default : ShouldNotReachHere(); | |
257 } | |
258 #endif | |
259 // all LogicOps are commutative | |
260 return true; | |
261 } | |
262 | |
263 | |
264 // Implementation of IfOp | |
265 | |
266 bool IfOp::is_commutative() const { | |
267 return cond() == eql || cond() == neq; | |
268 } | |
269 | |
270 | |
271 // Implementation of StateSplit | |
272 | |
273 void StateSplit::substitute(BlockList& list, BlockBegin* old_block, BlockBegin* new_block) { | |
274 NOT_PRODUCT(bool assigned = false;) | |
275 for (int i = 0; i < list.length(); i++) { | |
276 BlockBegin** b = list.adr_at(i); | |
277 if (*b == old_block) { | |
278 *b = new_block; | |
279 NOT_PRODUCT(assigned = true;) | |
280 } | |
281 } | |
282 assert(assigned == true, "should have assigned at least once"); | |
283 } | |
284 | |
285 | |
286 IRScope* StateSplit::scope() const { | |
287 return _state->scope(); | |
288 } | |
289 | |
290 | |
1584 | 291 void StateSplit::state_values_do(ValueVisitor* f) { |
1819 | 292 Instruction::state_values_do(f); |
0 | 293 if (state() != NULL) state()->values_do(f); |
294 } | |
295 | |
296 | |
1584 | 297 void BlockBegin::state_values_do(ValueVisitor* f) { |
0 | 298 StateSplit::state_values_do(f); |
299 | |
300 if (is_set(BlockBegin::exception_entry_flag)) { | |
301 for (int i = 0; i < number_of_exception_states(); i++) { | |
302 exception_state_at(i)->values_do(f); | |
303 } | |
304 } | |
305 } | |
306 | |
307 | |
308 // Implementation of Invoke | |
309 | |
310 | |
311 Invoke::Invoke(Bytecodes::Code code, ValueType* result_type, Value recv, Values* args, | |
1295 | 312 int vtable_index, ciMethod* target, ValueStack* state_before) |
1819 | 313 : StateSplit(result_type, state_before) |
0 | 314 , _code(code) |
315 , _recv(recv) | |
316 , _args(args) | |
317 , _vtable_index(vtable_index) | |
318 , _target(target) | |
319 { | |
320 set_flag(TargetIsLoadedFlag, target->is_loaded()); | |
321 set_flag(TargetIsFinalFlag, target_is_loaded() && target->is_final_method()); | |
322 set_flag(TargetIsStrictfpFlag, target_is_loaded() && target->is_strict()); | |
323 | |
324 assert(args != NULL, "args must exist"); | |
325 #ifdef ASSERT | |
1584 | 326 AssertValues assert_value; |
327 values_do(&assert_value); | |
328 #endif | |
0 | 329 |
330 // provide an initial guess of signature size. | |
331 _signature = new BasicTypeList(number_of_arguments() + (has_receiver() ? 1 : 0)); | |
332 if (has_receiver()) { | |
333 _signature->append(as_BasicType(receiver()->type())); | |
1295 | 334 } else if (is_invokedynamic()) { |
335 // Add the synthetic MethodHandle argument to the signature. | |
336 _signature->append(T_OBJECT); | |
0 | 337 } |
338 for (int i = 0; i < number_of_arguments(); i++) { | |
339 ValueType* t = argument_at(i)->type(); | |
340 BasicType bt = as_BasicType(t); | |
341 _signature->append(bt); | |
342 } | |
343 } | |
344 | |
345 | |
1584 | 346 void Invoke::state_values_do(ValueVisitor* f) { |
1295 | 347 StateSplit::state_values_do(f); |
348 if (state_before() != NULL) state_before()->values_do(f); | |
349 if (state() != NULL) state()->values_do(f); | |
350 } | |
351 | |
352 | |
0 | 353 // Implementation of Contant |
354 intx Constant::hash() const { | |
1819 | 355 if (state_before() == NULL) { |
0 | 356 switch (type()->tag()) { |
357 case intTag: | |
358 return HASH2(name(), type()->as_IntConstant()->value()); | |
359 case longTag: | |
360 { | |
361 jlong temp = type()->as_LongConstant()->value(); | |
362 return HASH3(name(), high(temp), low(temp)); | |
363 } | |
364 case floatTag: | |
365 return HASH2(name(), jint_cast(type()->as_FloatConstant()->value())); | |
366 case doubleTag: | |
367 { | |
368 jlong temp = jlong_cast(type()->as_DoubleConstant()->value()); | |
369 return HASH3(name(), high(temp), low(temp)); | |
370 } | |
371 case objectTag: | |
372 assert(type()->as_ObjectType()->is_loaded(), "can't handle unloaded values"); | |
373 return HASH2(name(), type()->as_ObjectType()->constant_value()); | |
374 } | |
375 } | |
376 return 0; | |
377 } | |
378 | |
379 bool Constant::is_equal(Value v) const { | |
380 if (v->as_Constant() == NULL) return false; | |
381 | |
382 switch (type()->tag()) { | |
383 case intTag: | |
384 { | |
385 IntConstant* t1 = type()->as_IntConstant(); | |
386 IntConstant* t2 = v->type()->as_IntConstant(); | |
387 return (t1 != NULL && t2 != NULL && | |
388 t1->value() == t2->value()); | |
389 } | |
390 case longTag: | |
391 { | |
392 LongConstant* t1 = type()->as_LongConstant(); | |
393 LongConstant* t2 = v->type()->as_LongConstant(); | |
394 return (t1 != NULL && t2 != NULL && | |
395 t1->value() == t2->value()); | |
396 } | |
397 case floatTag: | |
398 { | |
399 FloatConstant* t1 = type()->as_FloatConstant(); | |
400 FloatConstant* t2 = v->type()->as_FloatConstant(); | |
401 return (t1 != NULL && t2 != NULL && | |
402 jint_cast(t1->value()) == jint_cast(t2->value())); | |
403 } | |
404 case doubleTag: | |
405 { | |
406 DoubleConstant* t1 = type()->as_DoubleConstant(); | |
407 DoubleConstant* t2 = v->type()->as_DoubleConstant(); | |
408 return (t1 != NULL && t2 != NULL && | |
409 jlong_cast(t1->value()) == jlong_cast(t2->value())); | |
410 } | |
411 case objectTag: | |
412 { | |
413 ObjectType* t1 = type()->as_ObjectType(); | |
414 ObjectType* t2 = v->type()->as_ObjectType(); | |
415 return (t1 != NULL && t2 != NULL && | |
416 t1->is_loaded() && t2->is_loaded() && | |
417 t1->constant_value() == t2->constant_value()); | |
418 } | |
419 } | |
420 return false; | |
421 } | |
422 | |
1899 | 423 Constant::CompareResult Constant::compare(Instruction::Condition cond, Value right) const { |
0 | 424 Constant* rc = right->as_Constant(); |
425 // other is not a constant | |
1899 | 426 if (rc == NULL) return not_comparable; |
0 | 427 |
428 ValueType* lt = type(); | |
429 ValueType* rt = rc->type(); | |
430 // different types | |
1899 | 431 if (lt->base() != rt->base()) return not_comparable; |
0 | 432 switch (lt->tag()) { |
433 case intTag: { | |
434 int x = lt->as_IntConstant()->value(); | |
435 int y = rt->as_IntConstant()->value(); | |
436 switch (cond) { | |
1899 | 437 case If::eql: return x == y ? cond_true : cond_false; |
438 case If::neq: return x != y ? cond_true : cond_false; | |
439 case If::lss: return x < y ? cond_true : cond_false; | |
440 case If::leq: return x <= y ? cond_true : cond_false; | |
441 case If::gtr: return x > y ? cond_true : cond_false; | |
442 case If::geq: return x >= y ? cond_true : cond_false; | |
0 | 443 } |
444 break; | |
445 } | |
446 case longTag: { | |
447 jlong x = lt->as_LongConstant()->value(); | |
448 jlong y = rt->as_LongConstant()->value(); | |
449 switch (cond) { | |
1899 | 450 case If::eql: return x == y ? cond_true : cond_false; |
451 case If::neq: return x != y ? cond_true : cond_false; | |
452 case If::lss: return x < y ? cond_true : cond_false; | |
453 case If::leq: return x <= y ? cond_true : cond_false; | |
454 case If::gtr: return x > y ? cond_true : cond_false; | |
455 case If::geq: return x >= y ? cond_true : cond_false; | |
0 | 456 } |
457 break; | |
458 } | |
459 case objectTag: { | |
460 ciObject* xvalue = lt->as_ObjectType()->constant_value(); | |
461 ciObject* yvalue = rt->as_ObjectType()->constant_value(); | |
462 assert(xvalue != NULL && yvalue != NULL, "not constants"); | |
463 if (xvalue->is_loaded() && yvalue->is_loaded()) { | |
464 switch (cond) { | |
1899 | 465 case If::eql: return xvalue == yvalue ? cond_true : cond_false; |
466 case If::neq: return xvalue != yvalue ? cond_true : cond_false; | |
0 | 467 } |
468 } | |
469 break; | |
470 } | |
471 } | |
1899 | 472 return not_comparable; |
0 | 473 } |
474 | |
475 | |
476 // Implementation of BlockBegin | |
477 | |
478 void BlockBegin::set_end(BlockEnd* end) { | |
479 assert(end != NULL, "should not reset block end to NULL"); | |
480 BlockEnd* old_end = _end; | |
481 if (end == old_end) { | |
482 return; | |
483 } | |
484 // Must make the predecessors/successors match up with the | |
485 // BlockEnd's notion. | |
486 int i, n; | |
487 if (old_end != NULL) { | |
488 // disconnect from the old end | |
489 old_end->set_begin(NULL); | |
490 | |
491 // disconnect this block from it's current successors | |
492 for (i = 0; i < _successors.length(); i++) { | |
493 _successors.at(i)->remove_predecessor(this); | |
494 } | |
495 } | |
496 _end = end; | |
497 | |
498 _successors.clear(); | |
499 // Now reset successors list based on BlockEnd | |
500 n = end->number_of_sux(); | |
501 for (i = 0; i < n; i++) { | |
502 BlockBegin* sux = end->sux_at(i); | |
503 _successors.append(sux); | |
504 sux->_predecessors.append(this); | |
505 } | |
506 _end->set_begin(this); | |
507 } | |
508 | |
509 | |
510 void BlockBegin::disconnect_edge(BlockBegin* from, BlockBegin* to) { | |
511 // disconnect any edges between from and to | |
512 #ifndef PRODUCT | |
513 if (PrintIR && Verbose) { | |
514 tty->print_cr("Disconnected edge B%d -> B%d", from->block_id(), to->block_id()); | |
515 } | |
516 #endif | |
517 for (int s = 0; s < from->number_of_sux();) { | |
518 BlockBegin* sux = from->sux_at(s); | |
519 if (sux == to) { | |
520 int index = sux->_predecessors.index_of(from); | |
521 if (index >= 0) { | |
522 sux->_predecessors.remove_at(index); | |
523 } | |
524 from->_successors.remove_at(s); | |
525 } else { | |
526 s++; | |
527 } | |
528 } | |
529 } | |
530 | |
531 | |
532 void BlockBegin::disconnect_from_graph() { | |
533 // disconnect this block from all other blocks | |
534 for (int p = 0; p < number_of_preds(); p++) { | |
535 pred_at(p)->remove_successor(this); | |
536 } | |
537 for (int s = 0; s < number_of_sux(); s++) { | |
538 sux_at(s)->remove_predecessor(this); | |
539 } | |
540 } | |
541 | |
542 void BlockBegin::substitute_sux(BlockBegin* old_sux, BlockBegin* new_sux) { | |
543 // modify predecessors before substituting successors | |
544 for (int i = 0; i < number_of_sux(); i++) { | |
545 if (sux_at(i) == old_sux) { | |
546 // remove old predecessor before adding new predecessor | |
547 // otherwise there is a dead predecessor in the list | |
548 new_sux->remove_predecessor(old_sux); | |
549 new_sux->add_predecessor(this); | |
550 } | |
551 } | |
552 old_sux->remove_predecessor(this); | |
553 end()->substitute_sux(old_sux, new_sux); | |
554 } | |
555 | |
556 | |
557 | |
558 // In general it is not possible to calculate a value for the field "depth_first_number" | |
559 // of the inserted block, without recomputing the values of the other blocks | |
560 // in the CFG. Therefore the value of "depth_first_number" in BlockBegin becomes meaningless. | |
561 BlockBegin* BlockBegin::insert_block_between(BlockBegin* sux) { | |
1819 | 562 BlockBegin* new_sux = new BlockBegin(-99); |
0 | 563 |
564 // mark this block (special treatment when block order is computed) | |
565 new_sux->set(critical_edge_split_flag); | |
566 | |
567 // This goto is not a safepoint. | |
568 Goto* e = new Goto(sux, false); | |
1819 | 569 new_sux->set_next(e, end()->state()->bci()); |
0 | 570 new_sux->set_end(e); |
571 // setup states | |
572 ValueStack* s = end()->state(); | |
573 new_sux->set_state(s->copy()); | |
574 e->set_state(s->copy()); | |
575 assert(new_sux->state()->locals_size() == s->locals_size(), "local size mismatch!"); | |
576 assert(new_sux->state()->stack_size() == s->stack_size(), "stack size mismatch!"); | |
577 assert(new_sux->state()->locks_size() == s->locks_size(), "locks size mismatch!"); | |
578 | |
579 // link predecessor to new block | |
580 end()->substitute_sux(sux, new_sux); | |
581 | |
582 // The ordering needs to be the same, so remove the link that the | |
583 // set_end call above added and substitute the new_sux for this | |
584 // block. | |
585 sux->remove_predecessor(new_sux); | |
586 | |
587 // the successor could be the target of a switch so it might have | |
588 // multiple copies of this predecessor, so substitute the new_sux | |
589 // for the first and delete the rest. | |
590 bool assigned = false; | |
591 BlockList& list = sux->_predecessors; | |
592 for (int i = 0; i < list.length(); i++) { | |
593 BlockBegin** b = list.adr_at(i); | |
594 if (*b == this) { | |
595 if (assigned) { | |
596 list.remove_at(i); | |
597 // reprocess this index | |
598 i--; | |
599 } else { | |
600 assigned = true; | |
601 *b = new_sux; | |
602 } | |
603 // link the new block back to it's predecessors. | |
604 new_sux->add_predecessor(this); | |
605 } | |
606 } | |
607 assert(assigned == true, "should have assigned at least once"); | |
608 return new_sux; | |
609 } | |
610 | |
611 | |
612 void BlockBegin::remove_successor(BlockBegin* pred) { | |
613 int idx; | |
614 while ((idx = _successors.index_of(pred)) >= 0) { | |
615 _successors.remove_at(idx); | |
616 } | |
617 } | |
618 | |
619 | |
620 void BlockBegin::add_predecessor(BlockBegin* pred) { | |
621 _predecessors.append(pred); | |
622 } | |
623 | |
624 | |
625 void BlockBegin::remove_predecessor(BlockBegin* pred) { | |
626 int idx; | |
627 while ((idx = _predecessors.index_of(pred)) >= 0) { | |
628 _predecessors.remove_at(idx); | |
629 } | |
630 } | |
631 | |
632 | |
633 void BlockBegin::add_exception_handler(BlockBegin* b) { | |
634 assert(b != NULL && (b->is_set(exception_entry_flag)), "exception handler must exist"); | |
635 // add only if not in the list already | |
636 if (!_exception_handlers.contains(b)) _exception_handlers.append(b); | |
637 } | |
638 | |
639 int BlockBegin::add_exception_state(ValueStack* state) { | |
640 assert(is_set(exception_entry_flag), "only for xhandlers"); | |
641 if (_exception_states == NULL) { | |
642 _exception_states = new ValueStackStack(4); | |
643 } | |
644 _exception_states->append(state); | |
645 return _exception_states->length() - 1; | |
646 } | |
647 | |
648 | |
649 void BlockBegin::iterate_preorder(boolArray& mark, BlockClosure* closure) { | |
650 if (!mark.at(block_id())) { | |
651 mark.at_put(block_id(), true); | |
652 closure->block_do(this); | |
653 BlockEnd* e = end(); // must do this after block_do because block_do may change it! | |
654 { for (int i = number_of_exception_handlers() - 1; i >= 0; i--) exception_handler_at(i)->iterate_preorder(mark, closure); } | |
655 { for (int i = e->number_of_sux () - 1; i >= 0; i--) e->sux_at (i)->iterate_preorder(mark, closure); } | |
656 } | |
657 } | |
658 | |
659 | |
660 void BlockBegin::iterate_postorder(boolArray& mark, BlockClosure* closure) { | |
661 if (!mark.at(block_id())) { | |
662 mark.at_put(block_id(), true); | |
663 BlockEnd* e = end(); | |
664 { for (int i = number_of_exception_handlers() - 1; i >= 0; i--) exception_handler_at(i)->iterate_postorder(mark, closure); } | |
665 { for (int i = e->number_of_sux () - 1; i >= 0; i--) e->sux_at (i)->iterate_postorder(mark, closure); } | |
666 closure->block_do(this); | |
667 } | |
668 } | |
669 | |
670 | |
671 void BlockBegin::iterate_preorder(BlockClosure* closure) { | |
672 boolArray mark(number_of_blocks(), false); | |
673 iterate_preorder(mark, closure); | |
674 } | |
675 | |
676 | |
677 void BlockBegin::iterate_postorder(BlockClosure* closure) { | |
678 boolArray mark(number_of_blocks(), false); | |
679 iterate_postorder(mark, closure); | |
680 } | |
681 | |
682 | |
1584 | 683 void BlockBegin::block_values_do(ValueVisitor* f) { |
0 | 684 for (Instruction* n = this; n != NULL; n = n->next()) n->values_do(f); |
685 } | |
686 | |
687 | |
688 #ifndef PRODUCT | |
1783 | 689 #define TRACE_PHI(code) if (PrintPhiFunctions) { code; } |
0 | 690 #else |
1783 | 691 #define TRACE_PHI(coce) |
0 | 692 #endif |
693 | |
694 | |
695 bool BlockBegin::try_merge(ValueStack* new_state) { | |
696 TRACE_PHI(tty->print_cr("********** try_merge for block B%d", block_id())); | |
697 | |
698 // local variables used for state iteration | |
699 int index; | |
700 Value new_value, existing_value; | |
701 | |
702 ValueStack* existing_state = state(); | |
703 if (existing_state == NULL) { | |
704 TRACE_PHI(tty->print_cr("first call of try_merge for this block")); | |
705 | |
706 if (is_set(BlockBegin::was_visited_flag)) { | |
707 // this actually happens for complicated jsr/ret structures | |
708 return false; // BAILOUT in caller | |
709 } | |
710 | |
711 // copy state because it is altered | |
1819 | 712 new_state = new_state->copy(ValueStack::BlockBeginState, bci()); |
0 | 713 |
714 // Use method liveness to invalidate dead locals | |
715 MethodLivenessResult liveness = new_state->scope()->method()->liveness_at_bci(bci()); | |
716 if (liveness.is_valid()) { | |
717 assert((int)liveness.size() == new_state->locals_size(), "error in use of liveness"); | |
718 | |
719 for_each_local_value(new_state, index, new_value) { | |
720 if (!liveness.at(index) || new_value->type()->is_illegal()) { | |
721 new_state->invalidate_local(index); | |
722 TRACE_PHI(tty->print_cr("invalidating dead local %d", index)); | |
723 } | |
724 } | |
725 } | |
726 | |
727 if (is_set(BlockBegin::parser_loop_header_flag)) { | |
728 TRACE_PHI(tty->print_cr("loop header block, initializing phi functions")); | |
729 | |
730 for_each_stack_value(new_state, index, new_value) { | |
731 new_state->setup_phi_for_stack(this, index); | |
732 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)); | |
733 } | |
734 | |
735 BitMap requires_phi_function = new_state->scope()->requires_phi_function(); | |
736 | |
737 for_each_local_value(new_state, index, new_value) { | |
738 bool requires_phi = requires_phi_function.at(index) || (new_value->type()->is_double_word() && requires_phi_function.at(index + 1)); | |
739 if (requires_phi || !SelectivePhiFunctions) { | |
740 new_state->setup_phi_for_local(this, index); | |
741 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)); | |
742 } | |
743 } | |
744 } | |
745 | |
746 // initialize state of block | |
747 set_state(new_state); | |
748 | |
1819 | 749 } else if (existing_state->is_same(new_state)) { |
0 | 750 TRACE_PHI(tty->print_cr("exisiting state found")); |
751 | |
752 assert(existing_state->scope() == new_state->scope(), "not matching"); | |
753 assert(existing_state->locals_size() == new_state->locals_size(), "not matching"); | |
754 assert(existing_state->stack_size() == new_state->stack_size(), "not matching"); | |
755 | |
756 if (is_set(BlockBegin::was_visited_flag)) { | |
757 TRACE_PHI(tty->print_cr("loop header block, phis must be present")); | |
758 | |
759 if (!is_set(BlockBegin::parser_loop_header_flag)) { | |
760 // this actually happens for complicated jsr/ret structures | |
761 return false; // BAILOUT in caller | |
762 } | |
763 | |
764 for_each_local_value(existing_state, index, existing_value) { | |
765 Value new_value = new_state->local_at(index); | |
766 if (new_value == NULL || new_value->type()->tag() != existing_value->type()->tag()) { | |
767 // The old code invalidated the phi function here | |
768 // Because dead locals are replaced with NULL, this is a very rare case now, so simply bail out | |
769 return false; // BAILOUT in caller | |
770 } | |
771 } | |
772 | |
773 #ifdef ASSERT | |
774 // check that all necessary phi functions are present | |
775 for_each_stack_value(existing_state, index, existing_value) { | |
776 assert(existing_value->as_Phi() != NULL && existing_value->as_Phi()->block() == this, "phi function required"); | |
777 } | |
778 for_each_local_value(existing_state, index, existing_value) { | |
779 assert(existing_value == new_state->local_at(index) || (existing_value->as_Phi() != NULL && existing_value->as_Phi()->as_Phi()->block() == this), "phi function required"); | |
780 } | |
781 #endif | |
782 | |
783 } else { | |
784 TRACE_PHI(tty->print_cr("creating phi functions on demand")); | |
785 | |
786 // create necessary phi functions for stack | |
787 for_each_stack_value(existing_state, index, existing_value) { | |
788 Value new_value = new_state->stack_at(index); | |
789 Phi* existing_phi = existing_value->as_Phi(); | |
790 | |
791 if (new_value != existing_value && (existing_phi == NULL || existing_phi->block() != this)) { | |
792 existing_state->setup_phi_for_stack(this, index); | |
793 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)); | |
794 } | |
795 } | |
796 | |
797 // create necessary phi functions for locals | |
798 for_each_local_value(existing_state, index, existing_value) { | |
799 Value new_value = new_state->local_at(index); | |
800 Phi* existing_phi = existing_value->as_Phi(); | |
801 | |
802 if (new_value == NULL || new_value->type()->tag() != existing_value->type()->tag()) { | |
803 existing_state->invalidate_local(index); | |
804 TRACE_PHI(tty->print_cr("invalidating local %d because of type mismatch", index)); | |
805 } else if (new_value != existing_value && (existing_phi == NULL || existing_phi->block() != this)) { | |
806 existing_state->setup_phi_for_local(this, index); | |
807 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)); | |
808 } | |
809 } | |
810 } | |
811 | |
812 assert(existing_state->caller_state() == new_state->caller_state(), "caller states must be equal"); | |
813 | |
814 } else { | |
815 assert(false, "stack or locks not matching (invalid bytecodes)"); | |
816 return false; | |
817 } | |
818 | |
819 TRACE_PHI(tty->print_cr("********** try_merge for block B%d successful", block_id())); | |
820 | |
821 return true; | |
822 } | |
823 | |
824 | |
825 #ifndef PRODUCT | |
826 void BlockBegin::print_block() { | |
827 InstructionPrinter ip; | |
828 print_block(ip, false); | |
829 } | |
830 | |
831 | |
832 void BlockBegin::print_block(InstructionPrinter& ip, bool live_only) { | |
833 ip.print_instr(this); tty->cr(); | |
834 ip.print_stack(this->state()); tty->cr(); | |
835 ip.print_inline_level(this); | |
836 ip.print_head(); | |
837 for (Instruction* n = next(); n != NULL; n = n->next()) { | |
838 if (!live_only || n->is_pinned() || n->use_count() > 0) { | |
839 ip.print_line(n); | |
840 } | |
841 } | |
842 tty->cr(); | |
843 } | |
844 #endif // PRODUCT | |
845 | |
846 | |
847 // Implementation of BlockList | |
848 | |
849 void BlockList::iterate_forward (BlockClosure* closure) { | |
850 const int l = length(); | |
851 for (int i = 0; i < l; i++) closure->block_do(at(i)); | |
852 } | |
853 | |
854 | |
855 void BlockList::iterate_backward(BlockClosure* closure) { | |
856 for (int i = length() - 1; i >= 0; i--) closure->block_do(at(i)); | |
857 } | |
858 | |
859 | |
860 void BlockList::blocks_do(void f(BlockBegin*)) { | |
861 for (int i = length() - 1; i >= 0; i--) f(at(i)); | |
862 } | |
863 | |
864 | |
1584 | 865 void BlockList::values_do(ValueVisitor* f) { |
0 | 866 for (int i = length() - 1; i >= 0; i--) at(i)->block_values_do(f); |
867 } | |
868 | |
869 | |
870 #ifndef PRODUCT | |
871 void BlockList::print(bool cfg_only, bool live_only) { | |
872 InstructionPrinter ip; | |
873 for (int i = 0; i < length(); i++) { | |
874 BlockBegin* block = at(i); | |
875 if (cfg_only) { | |
876 ip.print_instr(block); tty->cr(); | |
877 } else { | |
878 block->print_block(ip, live_only); | |
879 } | |
880 } | |
881 } | |
882 #endif // PRODUCT | |
883 | |
884 | |
885 // Implementation of BlockEnd | |
886 | |
887 void BlockEnd::set_begin(BlockBegin* begin) { | |
888 BlockList* sux = NULL; | |
889 if (begin != NULL) { | |
890 sux = begin->successors(); | |
891 } else if (_begin != NULL) { | |
892 // copy our sux list | |
893 BlockList* sux = new BlockList(_begin->number_of_sux()); | |
894 for (int i = 0; i < _begin->number_of_sux(); i++) { | |
895 sux->append(_begin->sux_at(i)); | |
896 } | |
897 } | |
898 _sux = sux; | |
899 _begin = begin; | |
900 } | |
901 | |
902 | |
903 void BlockEnd::substitute_sux(BlockBegin* old_sux, BlockBegin* new_sux) { | |
904 substitute(*_sux, old_sux, new_sux); | |
905 } | |
906 | |
907 | |
908 // Implementation of Phi | |
909 | |
910 // Normal phi functions take their operands from the last instruction of the | |
911 // predecessor. Special handling is needed for xhanlder entries because there | |
912 // the state of arbitrary instructions are needed. | |
913 | |
914 Value Phi::operand_at(int i) const { | |
915 ValueStack* state; | |
916 if (_block->is_set(BlockBegin::exception_entry_flag)) { | |
917 state = _block->exception_state_at(i); | |
918 } else { | |
919 state = _block->pred_at(i)->end()->state(); | |
920 } | |
921 assert(state != NULL, ""); | |
922 | |
923 if (is_local()) { | |
924 return state->local_at(local_index()); | |
925 } else { | |
926 return state->stack_at(stack_index()); | |
927 } | |
928 } | |
929 | |
930 | |
931 int Phi::operand_count() const { | |
932 if (_block->is_set(BlockBegin::exception_entry_flag)) { | |
933 return _block->number_of_exception_states(); | |
934 } else { | |
935 return _block->number_of_preds(); | |
936 } | |
937 } | |
938 | |
939 | |
1783 | 940 |
941 void ProfileInvoke::state_values_do(ValueVisitor* f) { | |
942 if (state() != NULL) state()->values_do(f); | |
943 } |