Mercurial > hg > graal-jvmci-8
annotate src/share/vm/c1/c1_Instruction.cpp @ 6266:1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
6984705: JSR 292 method handle creation should not go through JNI
Summary: remove assembly code for JDK 7 chained method handles
Reviewed-by: jrose, twisti, kvn, mhaupt
Contributed-by: John Rose <john.r.rose@oracle.com>, Christian Thalinger <christian.thalinger@oracle.com>, Michael Haupt <michael.haupt@oracle.com>
author | twisti |
---|---|
date | Tue, 24 Jul 2012 10:51:00 -0700 |
parents | a32de5085326 |
children | 7a302948f5a4 |
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())); | |
1295 | 372 } else if (is_invokedynamic()) { |
373 // Add the synthetic MethodHandle argument to the signature. | |
374 _signature->append(T_OBJECT); | |
0 | 375 } |
376 for (int i = 0; i < number_of_arguments(); i++) { | |
377 ValueType* t = argument_at(i)->type(); | |
378 BasicType bt = as_BasicType(t); | |
379 _signature->append(bt); | |
380 } | |
381 } | |
382 | |
383 | |
1584 | 384 void Invoke::state_values_do(ValueVisitor* f) { |
1295 | 385 StateSplit::state_values_do(f); |
386 if (state_before() != NULL) state_before()->values_do(f); | |
387 if (state() != NULL) state()->values_do(f); | |
388 } | |
389 | |
2446 | 390 ciType* Invoke::declared_type() const { |
391 ciType *t = _target->signature()->return_type(); | |
392 assert(t->basic_type() != T_VOID, "need return value of void method?"); | |
393 return t; | |
394 } | |
1295 | 395 |
0 | 396 // Implementation of Contant |
397 intx Constant::hash() const { | |
1819 | 398 if (state_before() == NULL) { |
0 | 399 switch (type()->tag()) { |
400 case intTag: | |
401 return HASH2(name(), type()->as_IntConstant()->value()); | |
402 case longTag: | |
403 { | |
404 jlong temp = type()->as_LongConstant()->value(); | |
405 return HASH3(name(), high(temp), low(temp)); | |
406 } | |
407 case floatTag: | |
408 return HASH2(name(), jint_cast(type()->as_FloatConstant()->value())); | |
409 case doubleTag: | |
410 { | |
411 jlong temp = jlong_cast(type()->as_DoubleConstant()->value()); | |
412 return HASH3(name(), high(temp), low(temp)); | |
413 } | |
414 case objectTag: | |
415 assert(type()->as_ObjectType()->is_loaded(), "can't handle unloaded values"); | |
416 return HASH2(name(), type()->as_ObjectType()->constant_value()); | |
417 } | |
418 } | |
419 return 0; | |
420 } | |
421 | |
422 bool Constant::is_equal(Value v) const { | |
423 if (v->as_Constant() == NULL) return false; | |
424 | |
425 switch (type()->tag()) { | |
426 case intTag: | |
427 { | |
428 IntConstant* t1 = type()->as_IntConstant(); | |
429 IntConstant* t2 = v->type()->as_IntConstant(); | |
430 return (t1 != NULL && t2 != NULL && | |
431 t1->value() == t2->value()); | |
432 } | |
433 case longTag: | |
434 { | |
435 LongConstant* t1 = type()->as_LongConstant(); | |
436 LongConstant* t2 = v->type()->as_LongConstant(); | |
437 return (t1 != NULL && t2 != NULL && | |
438 t1->value() == t2->value()); | |
439 } | |
440 case floatTag: | |
441 { | |
442 FloatConstant* t1 = type()->as_FloatConstant(); | |
443 FloatConstant* t2 = v->type()->as_FloatConstant(); | |
444 return (t1 != NULL && t2 != NULL && | |
445 jint_cast(t1->value()) == jint_cast(t2->value())); | |
446 } | |
447 case doubleTag: | |
448 { | |
449 DoubleConstant* t1 = type()->as_DoubleConstant(); | |
450 DoubleConstant* t2 = v->type()->as_DoubleConstant(); | |
451 return (t1 != NULL && t2 != NULL && | |
452 jlong_cast(t1->value()) == jlong_cast(t2->value())); | |
453 } | |
454 case objectTag: | |
455 { | |
456 ObjectType* t1 = type()->as_ObjectType(); | |
457 ObjectType* t2 = v->type()->as_ObjectType(); | |
458 return (t1 != NULL && t2 != NULL && | |
459 t1->is_loaded() && t2->is_loaded() && | |
460 t1->constant_value() == t2->constant_value()); | |
461 } | |
462 } | |
463 return false; | |
464 } | |
465 | |
1899 | 466 Constant::CompareResult Constant::compare(Instruction::Condition cond, Value right) const { |
0 | 467 Constant* rc = right->as_Constant(); |
468 // other is not a constant | |
1899 | 469 if (rc == NULL) return not_comparable; |
0 | 470 |
471 ValueType* lt = type(); | |
472 ValueType* rt = rc->type(); | |
473 // different types | |
1899 | 474 if (lt->base() != rt->base()) return not_comparable; |
0 | 475 switch (lt->tag()) { |
476 case intTag: { | |
477 int x = lt->as_IntConstant()->value(); | |
478 int y = rt->as_IntConstant()->value(); | |
479 switch (cond) { | |
1899 | 480 case If::eql: return x == y ? cond_true : cond_false; |
481 case If::neq: return x != y ? cond_true : cond_false; | |
482 case If::lss: return x < y ? cond_true : cond_false; | |
483 case If::leq: return x <= y ? cond_true : cond_false; | |
484 case If::gtr: return x > y ? cond_true : cond_false; | |
485 case If::geq: return x >= y ? cond_true : cond_false; | |
0 | 486 } |
487 break; | |
488 } | |
489 case longTag: { | |
490 jlong x = lt->as_LongConstant()->value(); | |
491 jlong y = rt->as_LongConstant()->value(); | |
492 switch (cond) { | |
1899 | 493 case If::eql: return x == y ? cond_true : cond_false; |
494 case If::neq: return x != y ? cond_true : cond_false; | |
495 case If::lss: return x < y ? cond_true : cond_false; | |
496 case If::leq: return x <= y ? cond_true : cond_false; | |
497 case If::gtr: return x > y ? cond_true : cond_false; | |
498 case If::geq: return x >= y ? cond_true : cond_false; | |
0 | 499 } |
500 break; | |
501 } | |
502 case objectTag: { | |
503 ciObject* xvalue = lt->as_ObjectType()->constant_value(); | |
504 ciObject* yvalue = rt->as_ObjectType()->constant_value(); | |
505 assert(xvalue != NULL && yvalue != NULL, "not constants"); | |
506 if (xvalue->is_loaded() && yvalue->is_loaded()) { | |
507 switch (cond) { | |
1899 | 508 case If::eql: return xvalue == yvalue ? cond_true : cond_false; |
509 case If::neq: return xvalue != yvalue ? cond_true : cond_false; | |
0 | 510 } |
511 } | |
512 break; | |
513 } | |
514 } | |
1899 | 515 return not_comparable; |
0 | 516 } |
517 | |
518 | |
519 // Implementation of BlockBegin | |
520 | |
521 void BlockBegin::set_end(BlockEnd* end) { | |
522 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
|
523 if (end == _end) { |
0 | 524 return; |
525 } | |
3900
a32de5085326
7079673: JSR 292: C1 should inline bytecoded method handle adapters
twisti
parents:
3243
diff
changeset
|
526 clear_end(); |
0 | 527 |
3900
a32de5085326
7079673: JSR 292: C1 should inline bytecoded method handle adapters
twisti
parents:
3243
diff
changeset
|
528 // Set the new end |
0 | 529 _end = end; |
530 | |
531 _successors.clear(); | |
532 // Now reset successors list based on BlockEnd | |
3900
a32de5085326
7079673: JSR 292: C1 should inline bytecoded method handle adapters
twisti
parents:
3243
diff
changeset
|
533 for (int i = 0; i < end->number_of_sux(); i++) { |
0 | 534 BlockBegin* sux = end->sux_at(i); |
535 _successors.append(sux); | |
536 sux->_predecessors.append(this); | |
537 } | |
538 _end->set_begin(this); | |
539 } | |
540 | |
541 | |
3900
a32de5085326
7079673: JSR 292: C1 should inline bytecoded method handle adapters
twisti
parents:
3243
diff
changeset
|
542 void BlockBegin::clear_end() { |
a32de5085326
7079673: JSR 292: C1 should inline bytecoded method handle adapters
twisti
parents:
3243
diff
changeset
|
543 // 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
|
544 // BlockEnd's notion. |
a32de5085326
7079673: JSR 292: C1 should inline bytecoded method handle adapters
twisti
parents:
3243
diff
changeset
|
545 if (_end != NULL) { |
a32de5085326
7079673: JSR 292: C1 should inline bytecoded method handle adapters
twisti
parents:
3243
diff
changeset
|
546 // disconnect from the old end |
a32de5085326
7079673: JSR 292: C1 should inline bytecoded method handle adapters
twisti
parents:
3243
diff
changeset
|
547 _end->set_begin(NULL); |
a32de5085326
7079673: JSR 292: C1 should inline bytecoded method handle adapters
twisti
parents:
3243
diff
changeset
|
548 |
a32de5085326
7079673: JSR 292: C1 should inline bytecoded method handle adapters
twisti
parents:
3243
diff
changeset
|
549 // disconnect this block from it's current successors |
a32de5085326
7079673: JSR 292: C1 should inline bytecoded method handle adapters
twisti
parents:
3243
diff
changeset
|
550 for (int i = 0; i < _successors.length(); i++) { |
a32de5085326
7079673: JSR 292: C1 should inline bytecoded method handle adapters
twisti
parents:
3243
diff
changeset
|
551 _successors.at(i)->remove_predecessor(this); |
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 _end = NULL; |
a32de5085326
7079673: JSR 292: C1 should inline bytecoded method handle adapters
twisti
parents:
3243
diff
changeset
|
554 } |
a32de5085326
7079673: JSR 292: C1 should inline bytecoded method handle adapters
twisti
parents:
3243
diff
changeset
|
555 } |
a32de5085326
7079673: JSR 292: C1 should inline bytecoded method handle adapters
twisti
parents:
3243
diff
changeset
|
556 |
a32de5085326
7079673: JSR 292: C1 should inline bytecoded method handle adapters
twisti
parents:
3243
diff
changeset
|
557 |
0 | 558 void BlockBegin::disconnect_edge(BlockBegin* from, BlockBegin* to) { |
559 // disconnect any edges between from and to | |
560 #ifndef PRODUCT | |
561 if (PrintIR && Verbose) { | |
562 tty->print_cr("Disconnected edge B%d -> B%d", from->block_id(), to->block_id()); | |
563 } | |
564 #endif | |
565 for (int s = 0; s < from->number_of_sux();) { | |
566 BlockBegin* sux = from->sux_at(s); | |
567 if (sux == to) { | |
568 int index = sux->_predecessors.index_of(from); | |
569 if (index >= 0) { | |
570 sux->_predecessors.remove_at(index); | |
571 } | |
572 from->_successors.remove_at(s); | |
573 } else { | |
574 s++; | |
575 } | |
576 } | |
577 } | |
578 | |
579 | |
580 void BlockBegin::disconnect_from_graph() { | |
581 // disconnect this block from all other blocks | |
582 for (int p = 0; p < number_of_preds(); p++) { | |
583 pred_at(p)->remove_successor(this); | |
584 } | |
585 for (int s = 0; s < number_of_sux(); s++) { | |
586 sux_at(s)->remove_predecessor(this); | |
587 } | |
588 } | |
589 | |
590 void BlockBegin::substitute_sux(BlockBegin* old_sux, BlockBegin* new_sux) { | |
591 // modify predecessors before substituting successors | |
592 for (int i = 0; i < number_of_sux(); i++) { | |
593 if (sux_at(i) == old_sux) { | |
594 // remove old predecessor before adding new predecessor | |
595 // otherwise there is a dead predecessor in the list | |
596 new_sux->remove_predecessor(old_sux); | |
597 new_sux->add_predecessor(this); | |
598 } | |
599 } | |
600 old_sux->remove_predecessor(this); | |
601 end()->substitute_sux(old_sux, new_sux); | |
602 } | |
603 | |
604 | |
605 | |
606 // In general it is not possible to calculate a value for the field "depth_first_number" | |
607 // of the inserted block, without recomputing the values of the other blocks | |
608 // in the CFG. Therefore the value of "depth_first_number" in BlockBegin becomes meaningless. | |
609 BlockBegin* BlockBegin::insert_block_between(BlockBegin* sux) { | |
3241 | 610 BlockBegin* new_sux = new BlockBegin(end()->state()->bci()); |
0 | 611 |
612 // mark this block (special treatment when block order is computed) | |
613 new_sux->set(critical_edge_split_flag); | |
614 | |
615 // This goto is not a safepoint. | |
616 Goto* e = new Goto(sux, false); | |
1819 | 617 new_sux->set_next(e, end()->state()->bci()); |
0 | 618 new_sux->set_end(e); |
619 // setup states | |
620 ValueStack* s = end()->state(); | |
621 new_sux->set_state(s->copy()); | |
622 e->set_state(s->copy()); | |
623 assert(new_sux->state()->locals_size() == s->locals_size(), "local size mismatch!"); | |
624 assert(new_sux->state()->stack_size() == s->stack_size(), "stack size mismatch!"); | |
625 assert(new_sux->state()->locks_size() == s->locks_size(), "locks size mismatch!"); | |
626 | |
627 // link predecessor to new block | |
628 end()->substitute_sux(sux, new_sux); | |
629 | |
630 // The ordering needs to be the same, so remove the link that the | |
631 // set_end call above added and substitute the new_sux for this | |
632 // block. | |
633 sux->remove_predecessor(new_sux); | |
634 | |
635 // the successor could be the target of a switch so it might have | |
636 // multiple copies of this predecessor, so substitute the new_sux | |
637 // for the first and delete the rest. | |
638 bool assigned = false; | |
639 BlockList& list = sux->_predecessors; | |
640 for (int i = 0; i < list.length(); i++) { | |
641 BlockBegin** b = list.adr_at(i); | |
642 if (*b == this) { | |
643 if (assigned) { | |
644 list.remove_at(i); | |
645 // reprocess this index | |
646 i--; | |
647 } else { | |
648 assigned = true; | |
649 *b = new_sux; | |
650 } | |
651 // link the new block back to it's predecessors. | |
652 new_sux->add_predecessor(this); | |
653 } | |
654 } | |
655 assert(assigned == true, "should have assigned at least once"); | |
656 return new_sux; | |
657 } | |
658 | |
659 | |
660 void BlockBegin::remove_successor(BlockBegin* pred) { | |
661 int idx; | |
662 while ((idx = _successors.index_of(pred)) >= 0) { | |
663 _successors.remove_at(idx); | |
664 } | |
665 } | |
666 | |
667 | |
668 void BlockBegin::add_predecessor(BlockBegin* pred) { | |
669 _predecessors.append(pred); | |
670 } | |
671 | |
672 | |
673 void BlockBegin::remove_predecessor(BlockBegin* pred) { | |
674 int idx; | |
675 while ((idx = _predecessors.index_of(pred)) >= 0) { | |
676 _predecessors.remove_at(idx); | |
677 } | |
678 } | |
679 | |
680 | |
681 void BlockBegin::add_exception_handler(BlockBegin* b) { | |
682 assert(b != NULL && (b->is_set(exception_entry_flag)), "exception handler must exist"); | |
683 // add only if not in the list already | |
684 if (!_exception_handlers.contains(b)) _exception_handlers.append(b); | |
685 } | |
686 | |
687 int BlockBegin::add_exception_state(ValueStack* state) { | |
688 assert(is_set(exception_entry_flag), "only for xhandlers"); | |
689 if (_exception_states == NULL) { | |
690 _exception_states = new ValueStackStack(4); | |
691 } | |
692 _exception_states->append(state); | |
693 return _exception_states->length() - 1; | |
694 } | |
695 | |
696 | |
697 void BlockBegin::iterate_preorder(boolArray& mark, BlockClosure* closure) { | |
698 if (!mark.at(block_id())) { | |
699 mark.at_put(block_id(), true); | |
700 closure->block_do(this); | |
701 BlockEnd* e = end(); // must do this after block_do because block_do may change it! | |
702 { for (int i = number_of_exception_handlers() - 1; i >= 0; i--) exception_handler_at(i)->iterate_preorder(mark, closure); } | |
703 { for (int i = e->number_of_sux () - 1; i >= 0; i--) e->sux_at (i)->iterate_preorder(mark, closure); } | |
704 } | |
705 } | |
706 | |
707 | |
708 void BlockBegin::iterate_postorder(boolArray& mark, BlockClosure* closure) { | |
709 if (!mark.at(block_id())) { | |
710 mark.at_put(block_id(), true); | |
711 BlockEnd* e = end(); | |
712 { for (int i = number_of_exception_handlers() - 1; i >= 0; i--) exception_handler_at(i)->iterate_postorder(mark, closure); } | |
713 { for (int i = e->number_of_sux () - 1; i >= 0; i--) e->sux_at (i)->iterate_postorder(mark, closure); } | |
714 closure->block_do(this); | |
715 } | |
716 } | |
717 | |
718 | |
719 void BlockBegin::iterate_preorder(BlockClosure* closure) { | |
720 boolArray mark(number_of_blocks(), false); | |
721 iterate_preorder(mark, closure); | |
722 } | |
723 | |
724 | |
725 void BlockBegin::iterate_postorder(BlockClosure* closure) { | |
726 boolArray mark(number_of_blocks(), false); | |
727 iterate_postorder(mark, closure); | |
728 } | |
729 | |
730 | |
1584 | 731 void BlockBegin::block_values_do(ValueVisitor* f) { |
0 | 732 for (Instruction* n = this; n != NULL; n = n->next()) n->values_do(f); |
733 } | |
734 | |
735 | |
736 #ifndef PRODUCT | |
1783 | 737 #define TRACE_PHI(code) if (PrintPhiFunctions) { code; } |
0 | 738 #else |
1783 | 739 #define TRACE_PHI(coce) |
0 | 740 #endif |
741 | |
742 | |
743 bool BlockBegin::try_merge(ValueStack* new_state) { | |
744 TRACE_PHI(tty->print_cr("********** try_merge for block B%d", block_id())); | |
745 | |
746 // local variables used for state iteration | |
747 int index; | |
748 Value new_value, existing_value; | |
749 | |
750 ValueStack* existing_state = state(); | |
751 if (existing_state == NULL) { | |
752 TRACE_PHI(tty->print_cr("first call of try_merge for this block")); | |
753 | |
754 if (is_set(BlockBegin::was_visited_flag)) { | |
755 // this actually happens for complicated jsr/ret structures | |
756 return false; // BAILOUT in caller | |
757 } | |
758 | |
759 // copy state because it is altered | |
1819 | 760 new_state = new_state->copy(ValueStack::BlockBeginState, bci()); |
0 | 761 |
762 // Use method liveness to invalidate dead locals | |
763 MethodLivenessResult liveness = new_state->scope()->method()->liveness_at_bci(bci()); | |
764 if (liveness.is_valid()) { | |
765 assert((int)liveness.size() == new_state->locals_size(), "error in use of liveness"); | |
766 | |
767 for_each_local_value(new_state, index, new_value) { | |
768 if (!liveness.at(index) || new_value->type()->is_illegal()) { | |
769 new_state->invalidate_local(index); | |
770 TRACE_PHI(tty->print_cr("invalidating dead local %d", index)); | |
771 } | |
772 } | |
773 } | |
774 | |
775 if (is_set(BlockBegin::parser_loop_header_flag)) { | |
776 TRACE_PHI(tty->print_cr("loop header block, initializing phi functions")); | |
777 | |
778 for_each_stack_value(new_state, index, new_value) { | |
779 new_state->setup_phi_for_stack(this, index); | |
780 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)); | |
781 } | |
782 | |
783 BitMap requires_phi_function = new_state->scope()->requires_phi_function(); | |
784 | |
785 for_each_local_value(new_state, index, new_value) { | |
786 bool requires_phi = requires_phi_function.at(index) || (new_value->type()->is_double_word() && requires_phi_function.at(index + 1)); | |
787 if (requires_phi || !SelectivePhiFunctions) { | |
788 new_state->setup_phi_for_local(this, index); | |
789 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)); | |
790 } | |
791 } | |
792 } | |
793 | |
794 // initialize state of block | |
795 set_state(new_state); | |
796 | |
1819 | 797 } else if (existing_state->is_same(new_state)) { |
0 | 798 TRACE_PHI(tty->print_cr("exisiting state found")); |
799 | |
800 assert(existing_state->scope() == new_state->scope(), "not matching"); | |
801 assert(existing_state->locals_size() == new_state->locals_size(), "not matching"); | |
802 assert(existing_state->stack_size() == new_state->stack_size(), "not matching"); | |
803 | |
804 if (is_set(BlockBegin::was_visited_flag)) { | |
805 TRACE_PHI(tty->print_cr("loop header block, phis must be present")); | |
806 | |
807 if (!is_set(BlockBegin::parser_loop_header_flag)) { | |
808 // this actually happens for complicated jsr/ret structures | |
809 return false; // BAILOUT in caller | |
810 } | |
811 | |
812 for_each_local_value(existing_state, index, existing_value) { | |
813 Value new_value = new_state->local_at(index); | |
814 if (new_value == NULL || new_value->type()->tag() != existing_value->type()->tag()) { | |
815 // The old code invalidated the phi function here | |
816 // Because dead locals are replaced with NULL, this is a very rare case now, so simply bail out | |
817 return false; // BAILOUT in caller | |
818 } | |
819 } | |
820 | |
821 #ifdef ASSERT | |
822 // check that all necessary phi functions are present | |
823 for_each_stack_value(existing_state, index, existing_value) { | |
824 assert(existing_value->as_Phi() != NULL && existing_value->as_Phi()->block() == this, "phi function required"); | |
825 } | |
826 for_each_local_value(existing_state, index, existing_value) { | |
827 assert(existing_value == new_state->local_at(index) || (existing_value->as_Phi() != NULL && existing_value->as_Phi()->as_Phi()->block() == this), "phi function required"); | |
828 } | |
829 #endif | |
830 | |
831 } else { | |
832 TRACE_PHI(tty->print_cr("creating phi functions on demand")); | |
833 | |
834 // create necessary phi functions for stack | |
835 for_each_stack_value(existing_state, index, existing_value) { | |
836 Value new_value = new_state->stack_at(index); | |
837 Phi* existing_phi = existing_value->as_Phi(); | |
838 | |
839 if (new_value != existing_value && (existing_phi == NULL || existing_phi->block() != this)) { | |
840 existing_state->setup_phi_for_stack(this, index); | |
841 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)); | |
842 } | |
843 } | |
844 | |
845 // create necessary phi functions for locals | |
846 for_each_local_value(existing_state, index, existing_value) { | |
847 Value new_value = new_state->local_at(index); | |
848 Phi* existing_phi = existing_value->as_Phi(); | |
849 | |
850 if (new_value == NULL || new_value->type()->tag() != existing_value->type()->tag()) { | |
851 existing_state->invalidate_local(index); | |
852 TRACE_PHI(tty->print_cr("invalidating local %d because of type mismatch", index)); | |
853 } else if (new_value != existing_value && (existing_phi == NULL || existing_phi->block() != this)) { | |
854 existing_state->setup_phi_for_local(this, index); | |
855 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)); | |
856 } | |
857 } | |
858 } | |
859 | |
860 assert(existing_state->caller_state() == new_state->caller_state(), "caller states must be equal"); | |
861 | |
862 } else { | |
863 assert(false, "stack or locks not matching (invalid bytecodes)"); | |
864 return false; | |
865 } | |
866 | |
867 TRACE_PHI(tty->print_cr("********** try_merge for block B%d successful", block_id())); | |
868 | |
869 return true; | |
870 } | |
871 | |
872 | |
873 #ifndef PRODUCT | |
874 void BlockBegin::print_block() { | |
875 InstructionPrinter ip; | |
876 print_block(ip, false); | |
877 } | |
878 | |
879 | |
880 void BlockBegin::print_block(InstructionPrinter& ip, bool live_only) { | |
881 ip.print_instr(this); tty->cr(); | |
882 ip.print_stack(this->state()); tty->cr(); | |
883 ip.print_inline_level(this); | |
884 ip.print_head(); | |
885 for (Instruction* n = next(); n != NULL; n = n->next()) { | |
886 if (!live_only || n->is_pinned() || n->use_count() > 0) { | |
887 ip.print_line(n); | |
888 } | |
889 } | |
890 tty->cr(); | |
891 } | |
892 #endif // PRODUCT | |
893 | |
894 | |
895 // Implementation of BlockList | |
896 | |
897 void BlockList::iterate_forward (BlockClosure* closure) { | |
898 const int l = length(); | |
899 for (int i = 0; i < l; i++) closure->block_do(at(i)); | |
900 } | |
901 | |
902 | |
903 void BlockList::iterate_backward(BlockClosure* closure) { | |
904 for (int i = length() - 1; i >= 0; i--) closure->block_do(at(i)); | |
905 } | |
906 | |
907 | |
908 void BlockList::blocks_do(void f(BlockBegin*)) { | |
909 for (int i = length() - 1; i >= 0; i--) f(at(i)); | |
910 } | |
911 | |
912 | |
1584 | 913 void BlockList::values_do(ValueVisitor* f) { |
0 | 914 for (int i = length() - 1; i >= 0; i--) at(i)->block_values_do(f); |
915 } | |
916 | |
917 | |
918 #ifndef PRODUCT | |
919 void BlockList::print(bool cfg_only, bool live_only) { | |
920 InstructionPrinter ip; | |
921 for (int i = 0; i < length(); i++) { | |
922 BlockBegin* block = at(i); | |
923 if (cfg_only) { | |
924 ip.print_instr(block); tty->cr(); | |
925 } else { | |
926 block->print_block(ip, live_only); | |
927 } | |
928 } | |
929 } | |
930 #endif // PRODUCT | |
931 | |
932 | |
933 // Implementation of BlockEnd | |
934 | |
935 void BlockEnd::set_begin(BlockBegin* begin) { | |
936 BlockList* sux = NULL; | |
937 if (begin != NULL) { | |
938 sux = begin->successors(); | |
939 } else if (_begin != NULL) { | |
940 // copy our sux list | |
941 BlockList* sux = new BlockList(_begin->number_of_sux()); | |
942 for (int i = 0; i < _begin->number_of_sux(); i++) { | |
943 sux->append(_begin->sux_at(i)); | |
944 } | |
945 } | |
946 _sux = sux; | |
947 _begin = begin; | |
948 } | |
949 | |
950 | |
951 void BlockEnd::substitute_sux(BlockBegin* old_sux, BlockBegin* new_sux) { | |
952 substitute(*_sux, old_sux, new_sux); | |
953 } | |
954 | |
955 | |
956 // Implementation of Phi | |
957 | |
958 // Normal phi functions take their operands from the last instruction of the | |
959 // predecessor. Special handling is needed for xhanlder entries because there | |
960 // the state of arbitrary instructions are needed. | |
961 | |
962 Value Phi::operand_at(int i) const { | |
963 ValueStack* state; | |
964 if (_block->is_set(BlockBegin::exception_entry_flag)) { | |
965 state = _block->exception_state_at(i); | |
966 } else { | |
967 state = _block->pred_at(i)->end()->state(); | |
968 } | |
969 assert(state != NULL, ""); | |
970 | |
971 if (is_local()) { | |
972 return state->local_at(local_index()); | |
973 } else { | |
974 return state->stack_at(stack_index()); | |
975 } | |
976 } | |
977 | |
978 | |
979 int Phi::operand_count() const { | |
980 if (_block->is_set(BlockBegin::exception_entry_flag)) { | |
981 return _block->number_of_exception_states(); | |
982 } else { | |
983 return _block->number_of_preds(); | |
984 } | |
985 } | |
986 | |
987 | |
1783 | 988 |
989 void ProfileInvoke::state_values_do(ValueVisitor* f) { | |
990 if (state() != NULL) state()->values_do(f); | |
991 } |