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 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "ci/ciConstant.hpp"
27 #include "ci/ciField.hpp"
28 #include "ci/ciMethod.hpp"
29 #include "ci/ciMethodData.hpp"
30 #include "ci/ciObjArrayKlass.hpp"
31 #include "ci/ciStreams.hpp"
32 #include "ci/ciTypeArrayKlass.hpp"
33 #include "ci/ciTypeFlow.hpp"
34 #include "compiler/compileLog.hpp"
35 #include "interpreter/bytecode.hpp"
36 #include "interpreter/bytecodes.hpp"
37 #include "memory/allocation.inline.hpp"
38 #include "memory/resourceArea.hpp"
39 #include "oops/oop.inline.hpp"
40 #include "opto/compile.hpp"
41 #include "opto/node.hpp"
42 #include "runtime/deoptimization.hpp"
43 #include "utilities/growableArray.hpp"
44
45 // ciTypeFlow::JsrSet
46 //
47 // A JsrSet represents some set of JsrRecords. This class
48 // is used to record a set of all jsr routines which we permit
49 // execution to return (ret) from.
50 //
51 // During abstract interpretation, JsrSets are used to determine
52 // whether two paths which reach a given block are unique, and
53 // should be cloned apart, or are compatible, and should merge
254 // A StateVector summarizes the type information at some point in
255 // the program.
256
257 // ------------------------------------------------------------------
258 // ciTypeFlow::StateVector::type_meet
259 //
260 // Meet two types.
261 //
262 // The semi-lattice of types use by this analysis are modeled on those
263 // of the verifier. The lattice is as follows:
264 //
265 // top_type() >= all non-extremal types >= bottom_type
266 // and
267 // Every primitive type is comparable only with itself. The meet of
268 // reference types is determined by their kind: instance class,
269 // interface, or array class. The meet of two types of the same
270 // kind is their least common ancestor. The meet of two types of
271 // different kinds is always java.lang.Object.
272 ciType* ciTypeFlow::StateVector::type_meet_internal(ciType* t1, ciType* t2, ciTypeFlow* analyzer) {
273 assert(t1 != t2, "checked in caller");
274 if (t1->equals(top_type())) {
275 return t2;
276 } else if (t2->equals(top_type())) {
277 return t1;
278 } else if (t1->is_primitive_type() || t2->is_primitive_type()) {
279 // Special case null_type. null_type meet any reference type T
280 // is T. null_type meet null_type is null_type.
281 if (t1->equals(null_type())) {
282 if (!t2->is_primitive_type() || t2->equals(null_type())) {
283 return t2;
284 }
285 } else if (t2->equals(null_type())) {
286 if (!t1->is_primitive_type()) {
287 return t1;
288 }
289 }
290
291 // At least one of the two types is a non-top primitive type.
292 // The other type is not equal to it. Fall to bottom.
293 return bottom_type();
294 } else {
295 // Both types are non-top non-primitive types. That is,
296 // both types are either instanceKlasses or arrayKlasses.
297 ciKlass* object_klass = analyzer->env()->Object_klass();
298 ciKlass* k1 = t1->as_klass();
299 ciKlass* k2 = t2->as_klass();
300 if (k1->equals(object_klass) || k2->equals(object_klass)) {
301 return object_klass;
302 } else if (!k1->is_loaded() || !k2->is_loaded()) {
303 // Unloaded classes fall to java.lang.Object at a merge.
304 return object_klass;
305 } else if (k1->is_interface() != k2->is_interface()) {
306 // When an interface meets a non-interface, we get Object;
307 // This is what the verifier does.
308 return object_klass;
309 } else if (k1->is_array_klass() || k2->is_array_klass()) {
310 // When an array meets a non-array, we get Object.
311 // When objArray meets typeArray, we also get Object.
312 // And when typeArray meets different typeArray, we again get Object.
313 // But when objArray meets objArray, we look carefully at element types.
314 if (k1->is_obj_array_klass() && k2->is_obj_array_klass()) {
315 // Meet the element types, then construct the corresponding array type.
316 ciKlass* elem1 = k1->as_obj_array_klass()->element_klass();
317 ciKlass* elem2 = k2->as_obj_array_klass()->element_klass();
318 ciKlass* elem = type_meet_internal(elem1, elem2, analyzer)->as_klass();
319 // Do an easy shortcut if one type is a super of the other.
320 if (elem == elem1) {
321 assert(k1 == ciObjArrayKlass::make(elem), "shortcut is OK");
322 return k1;
323 } else if (elem == elem2) {
324 assert(k2 == ciObjArrayKlass::make(elem), "shortcut is OK");
325 return k2;
326 } else {
327 return ciObjArrayKlass::make(elem);
328 }
329 } else {
330 return object_klass;
331 }
332 } else {
333 // Must be two plain old instance klasses.
334 assert(k1->is_instance_klass(), "previous cases handle non-instances");
335 assert(k2->is_instance_klass(), "previous cases handle non-instances");
336 return k1->least_common_ancestor(k2);
337 }
338 }
339 }
340
341
342 // ------------------------------------------------------------------
343 // ciTypeFlow::StateVector::StateVector
344 //
345 // Build a new state vector
346 ciTypeFlow::StateVector::StateVector(ciTypeFlow* analyzer) {
347 _outer = analyzer;
348 _stack_size = -1;
349 _monitor_count = -1;
350 // Allocate the _types array
351 int max_cells = analyzer->max_cells();
352 _types = (ciType**)analyzer->arena()->Amalloc(sizeof(ciType*) * max_cells);
353 for (int i=0; i<max_cells; i++) {
354 _types[i] = top_type();
355 }
356 _trap_bci = -1;
357 _trap_index = 0;
379 }
380 // load up the non-OSR state at this point
381 non_osr_block->copy_state_into(state);
382 int non_osr_start = non_osr_block->start();
383 if (non_osr_start != start_bci()) {
384 // must flow forward from it
385 if (CITraceTypeFlow) {
386 tty->print_cr(">> Interpreting pre-OSR block %d:", non_osr_start);
387 }
388 Block* block = block_at(non_osr_start, jsrs);
389 assert(block->limit() == start_bci(), "must flow forward to start");
390 flow_block(block, state, jsrs);
391 }
392 return state;
393 // Note: The code below would be an incorrect for an OSR flow,
394 // even if it were possible for an OSR entry point to be at bci zero.
395 }
396 // "Push" the method signature into the first few locals.
397 state->set_stack_size(-max_locals());
398 if (!method()->is_static()) {
399 state->push(method()->holder());
400 assert(state->tos() == state->local(0), "");
401 }
402 for (ciSignatureStream str(method()->signature());
403 !str.at_return_type();
404 str.next()) {
405 state->push_translate(str.type());
406 }
407 // Set the rest of the locals to bottom.
408 Cell cell = state->next_cell(state->tos());
409 state->set_stack_size(0);
410 int limit = state->limit_cell();
411 for (; cell < limit; cell = state->next_cell(cell)) {
412 state->set_type_at(cell, state->bottom_type());
413 }
414 // Lock an object, if necessary.
415 state->set_monitor_count(method()->is_synchronized() ? 1 : 0);
416 return state;
417 }
418
419 // ------------------------------------------------------------------
420 // ciTypeFlow::StateVector::copy_into
421 //
422 // Copy our value into some other StateVector
423 void ciTypeFlow::StateVector::copy_into(ciTypeFlow::StateVector* copy)
424 const {
425 copy->set_stack_size(stack_size());
531
532 return different;
533 }
534
535 // ------------------------------------------------------------------
536 // ciTypeFlow::StateVector::push_translate
537 void ciTypeFlow::StateVector::push_translate(ciType* type) {
538 BasicType basic_type = type->basic_type();
539 if (basic_type == T_BOOLEAN || basic_type == T_CHAR ||
540 basic_type == T_BYTE || basic_type == T_SHORT) {
541 push_int();
542 } else {
543 push(type);
544 if (type->is_two_word()) {
545 push(half_type(type));
546 }
547 }
548 }
549
550 // ------------------------------------------------------------------
551 // ciTypeFlow::StateVector::do_aaload
552 void ciTypeFlow::StateVector::do_aaload(ciBytecodeStream* str) {
553 pop_int();
554 ciObjArrayKlass* array_klass = pop_objArray();
555 if (array_klass == NULL) {
556 // Did aaload on a null reference; push a null and ignore the exception.
557 // This instruction will never continue normally. All we have to do
558 // is report a value that will meet correctly with any downstream
559 // reference types on paths that will truly be executed. This null type
560 // meets with any reference type to yield that same reference type.
561 // (The compiler will generate an unconditional exception here.)
562 push(null_type());
563 return;
564 }
565 if (!array_klass->is_loaded()) {
566 // Only fails for some -Xcomp runs
567 trap(str, array_klass,
568 Deoptimization::make_trap_request
569 (Deoptimization::Reason_unloaded,
570 Deoptimization::Action_reinterpret));
571 return;
572 }
573 ciKlass* element_klass = array_klass->element_klass();
574 if (!element_klass->is_loaded() && element_klass->is_instance_klass()) {
575 Untested("unloaded array element class in ciTypeFlow");
576 trap(str, element_klass,
577 Deoptimization::make_trap_request
578 (Deoptimization::Reason_unloaded,
579 Deoptimization::Action_reinterpret));
580 } else {
581 push_object(element_klass);
582 }
583 }
584
585
586 // ------------------------------------------------------------------
587 // ciTypeFlow::StateVector::do_checkcast
588 void ciTypeFlow::StateVector::do_checkcast(ciBytecodeStream* str) {
589 bool will_link;
590 ciKlass* klass = str->get_klass(will_link);
591 if (!will_link) {
592 // VM's interpreter will not load 'klass' if object is NULL.
593 // Type flow after this block may still be needed in two situations:
594 // 1) C2 uses do_null_assert() and continues compilation for later blocks
595 // 2) C2 does an OSR compile in a later block (see bug 4778368).
596 pop_object();
597 do_null_assert(klass);
598 } else {
599 pop_object();
600 push_object(klass);
601 }
602 }
603
604 // ------------------------------------------------------------------
605 // ciTypeFlow::StateVector::do_getfield
606 void ciTypeFlow::StateVector::do_getfield(ciBytecodeStream* str) {
607 // could add assert here for type of object.
608 pop_object();
609 do_getstatic(str);
610 }
611
612 // ------------------------------------------------------------------
613 // ciTypeFlow::StateVector::do_getstatic
614 void ciTypeFlow::StateVector::do_getstatic(ciBytecodeStream* str) {
615 bool will_link;
616 ciField* field = str->get_field(will_link);
617 if (!will_link) {
618 trap(str, field->holder(), str->get_field_holder_index());
619 } else {
620 ciType* field_type = field->type();
621 if (!field_type->is_loaded()) {
622 // Normally, we need the field's type to be loaded if we are to
623 // do anything interesting with its value.
624 // We used to do this: trap(str, str->get_field_signature_index());
625 //
626 // There is one good reason not to trap here. Execution can
627 // get past this "getfield" or "getstatic" if the value of
628 // the field is null. As long as the value is null, the class
629 // does not need to be loaded! The compiler must assume that
630 // the value of the unloaded class reference is null; if the code
631 // ever sees a non-null value, loading has occurred.
632 //
633 // This actually happens often enough to be annoying. If the
634 // compiler throws an uncommon trap at this bytecode, you can
635 // get an endless loop of recompilations, when all the code
636 // needs to do is load a series of null values. Also, a trap
637 // here can make an OSR entry point unreachable, triggering the
638 // assert on non_osr_block in ciTypeFlow::get_start_state.
639 // (See bug 4379915.)
640 do_null_assert(field_type->as_klass());
641 } else {
642 push_translate(field_type);
643 }
644 }
645 }
646
647 // ------------------------------------------------------------------
648 // ciTypeFlow::StateVector::do_invoke
649 void ciTypeFlow::StateVector::do_invoke(ciBytecodeStream* str,
650 bool has_receiver) {
651 bool will_link;
652 ciSignature* declared_signature = NULL;
653 ciMethod* callee = str->get_method(will_link, &declared_signature);
654 assert(declared_signature != NULL, "cannot be null");
655 if (!will_link) {
656 // We weren't able to find the method.
657 if (str->cur_bc() == Bytecodes::_invokedynamic) {
658 trap(str, NULL,
659 Deoptimization::make_trap_request
660 (Deoptimization::Reason_uninitialized,
661 Deoptimization::Action_reinterpret));
689 // Check this?
690 pop_object();
691 }
692 assert(!sigstr.is_done(), "must have return type");
693 ciType* return_type = sigstr.type();
694 if (!return_type->is_void()) {
695 if (!return_type->is_loaded()) {
696 // As in do_getstatic(), generally speaking, we need the return type to
697 // be loaded if we are to do anything interesting with its value.
698 // We used to do this: trap(str, str->get_method_signature_index());
699 //
700 // We do not trap here since execution can get past this invoke if
701 // the return value is null. As long as the value is null, the class
702 // does not need to be loaded! The compiler must assume that
703 // the value of the unloaded class reference is null; if the code
704 // ever sees a non-null value, loading has occurred.
705 //
706 // See do_getstatic() for similar explanation, as well as bug 4684993.
707 do_null_assert(return_type->as_klass());
708 } else {
709 push_translate(return_type);
710 }
711 }
712 }
713 }
714
715 // ------------------------------------------------------------------
716 // ciTypeFlow::StateVector::do_jsr
717 void ciTypeFlow::StateVector::do_jsr(ciBytecodeStream* str) {
718 push(ciReturnAddress::make(str->next_bci()));
719 }
720
721 // ------------------------------------------------------------------
722 // ciTypeFlow::StateVector::do_ldc
723 void ciTypeFlow::StateVector::do_ldc(ciBytecodeStream* str) {
724 ciConstant con = str->get_constant();
725 BasicType basic_type = con.basic_type();
726 if (basic_type == T_ILLEGAL) {
727 // OutOfMemoryError in the CI while loading constant
728 push_null();
729 outer()->record_failure("ldc did not link");
730 return;
731 }
732 if (basic_type == T_OBJECT || basic_type == T_ARRAY) {
733 ciObject* obj = con.as_object();
734 if (obj->is_null_object()) {
735 push_null();
736 } else {
737 assert(obj->is_instance() || obj->is_array(), "must be java_mirror of klass");
738 push_object(obj->klass());
739 }
740 } else {
741 push_translate(ciType::make(basic_type));
742 }
743 }
744
745 // ------------------------------------------------------------------
746 // ciTypeFlow::StateVector::do_multianewarray
747 void ciTypeFlow::StateVector::do_multianewarray(ciBytecodeStream* str) {
748 int dimensions = str->get_dimensions();
749 bool will_link;
750 ciArrayKlass* array_klass = str->get_klass(will_link)->as_array_klass();
751 if (!will_link) {
752 trap(str, array_klass, str->get_klass_index());
753 } else {
754 for (int i = 0; i < dimensions; i++) {
755 pop_int();
756 }
757 push_object(array_klass);
758 }
759 }
760
761 // ------------------------------------------------------------------
762 // ciTypeFlow::StateVector::do_new
763 void ciTypeFlow::StateVector::do_new(ciBytecodeStream* str) {
764 bool will_link;
765 ciKlass* klass = str->get_klass(will_link);
766 if (!will_link || str->is_unresolved_klass()) {
767 trap(str, klass, str->get_klass_index());
768 } else {
769 push_object(klass);
770 }
771 }
772
773 // ------------------------------------------------------------------
774 // ciTypeFlow::StateVector::do_newarray
775 void ciTypeFlow::StateVector::do_newarray(ciBytecodeStream* str) {
776 pop_int();
777 ciKlass* klass = ciTypeArrayKlass::make((BasicType)str->get_index());
778 push_object(klass);
779 }
780
781 // ------------------------------------------------------------------
782 // ciTypeFlow::StateVector::do_putfield
783 void ciTypeFlow::StateVector::do_putfield(ciBytecodeStream* str) {
784 do_putstatic(str);
785 if (_trap_bci != -1) return; // unloaded field holder, etc.
786 // could add assert here for type of object.
787 pop_object();
788 }
789
790 // ------------------------------------------------------------------
791 // ciTypeFlow::StateVector::do_putstatic
792 void ciTypeFlow::StateVector::do_putstatic(ciBytecodeStream* str) {
793 bool will_link;
858 // class later.
859 push_null();
860 }
861 }
862
863
864 // ------------------------------------------------------------------
865 // ciTypeFlow::StateVector::apply_one_bytecode
866 //
867 // Apply the effect of one bytecode to this StateVector
868 bool ciTypeFlow::StateVector::apply_one_bytecode(ciBytecodeStream* str) {
869 _trap_bci = -1;
870 _trap_index = 0;
871
872 if (CITraceTypeFlow) {
873 tty->print_cr(">> Interpreting bytecode %d:%s", str->cur_bci(),
874 Bytecodes::name(str->cur_bc()));
875 }
876
877 switch(str->cur_bc()) {
878 case Bytecodes::_aaload: do_aaload(str); break;
879
880 case Bytecodes::_aastore:
881 {
882 pop_object();
883 pop_int();
884 pop_objArray();
885 break;
886 }
887 case Bytecodes::_aconst_null:
888 {
889 push_null();
890 break;
891 }
892 case Bytecodes::_aload: load_local_object(str->get_index()); break;
893 case Bytecodes::_aload_0: load_local_object(0); break;
894 case Bytecodes::_aload_1: load_local_object(1); break;
895 case Bytecodes::_aload_2: load_local_object(2); break;
896 case Bytecodes::_aload_3: load_local_object(3); break;
897
898 case Bytecodes::_anewarray:
899 {
900 pop_int();
901 bool will_link;
902 ciKlass* element_klass = str->get_klass(will_link);
903 if (!will_link) {
904 trap(str, element_klass, str->get_klass_index());
905 } else {
906 push_object(ciObjArrayKlass::make(element_klass));
907 }
908 break;
909 }
910 case Bytecodes::_areturn:
911 case Bytecodes::_ifnonnull:
912 case Bytecodes::_ifnull:
913 {
914 pop_object();
915 break;
916 }
917 case Bytecodes::_monitorenter:
918 {
919 pop_object();
920 set_monitor_count(monitor_count() + 1);
921 break;
922 }
923 case Bytecodes::_monitorexit:
924 {
925 pop_object();
926 assert(monitor_count() > 0, "must be a monitor to exit from");
1418 }
1419 case Bytecodes::_lshl:
1420 case Bytecodes::_lshr:
1421 case Bytecodes::_lushr:
1422 {
1423 pop_int();
1424 pop_long();
1425 push_long();
1426 break;
1427 }
1428 case Bytecodes::_lstore: store_local_long(str->get_index()); break;
1429 case Bytecodes::_lstore_0: store_local_long(0); break;
1430 case Bytecodes::_lstore_1: store_local_long(1); break;
1431 case Bytecodes::_lstore_2: store_local_long(2); break;
1432 case Bytecodes::_lstore_3: store_local_long(3); break;
1433
1434 case Bytecodes::_multianewarray: do_multianewarray(str); break;
1435
1436 case Bytecodes::_new: do_new(str); break;
1437
1438 case Bytecodes::_newarray: do_newarray(str); break;
1439
1440 case Bytecodes::_pop:
1441 {
1442 pop();
1443 break;
1444 }
1445 case Bytecodes::_pop2:
1446 {
1447 pop();
1448 pop();
1449 break;
1450 }
1451
1452 case Bytecodes::_putfield: do_putfield(str); break;
1453 case Bytecodes::_putstatic: do_putstatic(str); break;
1454
1455 case Bytecodes::_ret: do_ret(str); break;
1456
1457 case Bytecodes::_swap:
1458 {
1459 ciType* value1 = pop_value();
1460 ciType* value2 = pop_value();
1461 push(value1);
1462 push(value2);
1463 break;
1464 }
1465 case Bytecodes::_wide:
1466 default:
1467 {
1468 // The iterator should skip this.
1469 ShouldNotReachHere();
1470 break;
1471 }
1472 }
1473
1474 if (CITraceTypeFlow) {
1475 print_on(tty);
1476 }
1477
1478 return (_trap_bci != -1);
1479 }
1480
1481 #ifndef PRODUCT
1482 // ------------------------------------------------------------------
1483 // ciTypeFlow::StateVector::print_cell_on
1484 void ciTypeFlow::StateVector::print_cell_on(outputStream* st, Cell c) const {
1728 case Bytecodes::_lookupswitch: {
1729 Bytecode_lookupswitch lookupswitch(str);
1730
1731 int npairs = lookupswitch.number_of_pairs();
1732 _successors =
1733 new (arena) GrowableArray<Block*>(arena, npairs+1, 0, NULL);
1734 int bci = current_bci + lookupswitch.default_offset();
1735 Block* block = analyzer->block_at(bci, jsrs);
1736 assert(_successors->length() == SWITCH_DEFAULT, "");
1737 _successors->append(block);
1738 while(--npairs >= 0) {
1739 LookupswitchPair pair = lookupswitch.pair_at(npairs);
1740 int bci = current_bci + pair.offset();
1741 Block* block = analyzer->block_at(bci, jsrs);
1742 assert(_successors->length() >= SWITCH_CASES, "");
1743 _successors->append_if_missing(block);
1744 }
1745 break;
1746 }
1747
1748 case Bytecodes::_athrow: case Bytecodes::_ireturn:
1749 case Bytecodes::_lreturn: case Bytecodes::_freturn:
1750 case Bytecodes::_dreturn: case Bytecodes::_areturn:
1751 case Bytecodes::_return:
1752 _successors =
1753 new (arena) GrowableArray<Block*>(arena, 1, 0, NULL);
1754 // No successors
1755 break;
1756
1757 case Bytecodes::_ret: {
1758 _successors =
1759 new (arena) GrowableArray<Block*>(arena, 1, 0, NULL);
1760
1761 Cell local = state->local(str->get_index());
1762 ciType* return_address = state->type_at(local);
1763 assert(return_address->is_return_address(), "verify: wrong type");
1764 int bci = return_address->as_return_address()->bci();
1765 assert(_successors->length() == GOTO_TARGET, "");
1766 _successors->append(analyzer->block_at(bci, jsrs));
1767 break;
1768 }
1769
1770 case Bytecodes::_wide:
2959 return dominated[block->rpo()];
2960 }
2961
2962 // ------------------------------------------------------------------
2963 // ciTypeFlow::record_failure()
2964 // The ciTypeFlow object keeps track of failure reasons separately from the ciEnv.
2965 // This is required because there is not a 1-1 relation between the ciEnv and
2966 // the TypeFlow passes within a compilation task. For example, if the compiler
2967 // is considering inlining a method, it will request a TypeFlow. If that fails,
2968 // the compilation as a whole may continue without the inlining. Some TypeFlow
2969 // requests are not optional; if they fail the requestor is responsible for
2970 // copying the failure reason up to the ciEnv. (See Parse::Parse.)
2971 void ciTypeFlow::record_failure(const char* reason) {
2972 if (env()->log() != NULL) {
2973 env()->log()->elem("failure reason='%s' phase='typeflow'", reason);
2974 }
2975 if (_failure_reason == NULL) {
2976 // Record the first failure reason.
2977 _failure_reason = reason;
2978 }
2979 }
2980
2981 #ifndef PRODUCT
2982 // ------------------------------------------------------------------
2983 // ciTypeFlow::print_on
2984 void ciTypeFlow::print_on(outputStream* st) const {
2985 // Walk through CI blocks
2986 st->print_cr("********************************************************");
2987 st->print ("TypeFlow for ");
2988 method()->name()->print_symbol_on(st);
2989 int limit_bci = code_size();
2990 st->print_cr(" %d bytes", limit_bci);
2991 ciMethodBlocks *mblks = _methodBlocks;
2992 ciBlock* current = NULL;
2993 for (int bci = 0; bci < limit_bci; bci++) {
2994 ciBlock* blk = mblks->block_containing(bci);
2995 if (blk != NULL && blk != current) {
2996 current = blk;
2997 current->print_on(st);
2998
|
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 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "ci/ciConstant.hpp"
27 #include "ci/ciField.hpp"
28 #include "ci/ciMethod.hpp"
29 #include "ci/ciMethodData.hpp"
30 #include "ci/ciObjArrayKlass.hpp"
31 #include "ci/ciStreams.hpp"
32 #include "ci/ciTypeArrayKlass.hpp"
33 #include "ci/ciTypeFlow.hpp"
34 #include "ci/ciValueKlass.hpp"
35 #include "compiler/compileLog.hpp"
36 #include "interpreter/bytecode.hpp"
37 #include "interpreter/bytecodes.hpp"
38 #include "memory/allocation.inline.hpp"
39 #include "memory/resourceArea.hpp"
40 #include "oops/oop.inline.hpp"
41 #include "opto/compile.hpp"
42 #include "opto/node.hpp"
43 #include "runtime/deoptimization.hpp"
44 #include "utilities/growableArray.hpp"
45
46 // ciTypeFlow::JsrSet
47 //
48 // A JsrSet represents some set of JsrRecords. This class
49 // is used to record a set of all jsr routines which we permit
50 // execution to return (ret) from.
51 //
52 // During abstract interpretation, JsrSets are used to determine
53 // whether two paths which reach a given block are unique, and
54 // should be cloned apart, or are compatible, and should merge
255 // A StateVector summarizes the type information at some point in
256 // the program.
257
258 // ------------------------------------------------------------------
259 // ciTypeFlow::StateVector::type_meet
260 //
261 // Meet two types.
262 //
263 // The semi-lattice of types use by this analysis are modeled on those
264 // of the verifier. The lattice is as follows:
265 //
266 // top_type() >= all non-extremal types >= bottom_type
267 // and
268 // Every primitive type is comparable only with itself. The meet of
269 // reference types is determined by their kind: instance class,
270 // interface, or array class. The meet of two types of the same
271 // kind is their least common ancestor. The meet of two types of
272 // different kinds is always java.lang.Object.
273 ciType* ciTypeFlow::StateVector::type_meet_internal(ciType* t1, ciType* t2, ciTypeFlow* analyzer) {
274 assert(t1 != t2, "checked in caller");
275
276 if (t1->equals(top_type())) {
277 return t2;
278 } else if (t2->equals(top_type())) {
279 return t1;
280 } else if (t1->is_primitive_type() || t2->is_primitive_type()) {
281 // Special case null_type. null_type meet any reference type T
282 // is T. null_type meet null_type is null_type.
283 if (t1->equals(null_type())) {
284 if (!t2->is_primitive_type() || t2->equals(null_type())) {
285 return t2;
286 }
287 } else if (t2->equals(null_type())) {
288 if (!t1->is_primitive_type()) {
289 return t1;
290 }
291 }
292
293 // At least one of the two types is a non-top primitive type.
294 // The other type is not equal to it. Fall to bottom.
295 return bottom_type();
296 }
297
298 // Unwrap the types after gathering nullness information
299 bool never_null1 = t1->is_never_null();
300 bool never_null2 = t2->is_never_null();
301 t1 = t1->unwrap();
302 t2 = t2->unwrap();
303
304 // Both types are non-top non-primitive types. That is,
305 // both types are either instanceKlasses or arrayKlasses.
306 ciKlass* object_klass = analyzer->env()->Object_klass();
307 ciKlass* k1 = t1->as_klass();
308 ciKlass* k2 = t2->as_klass();
309 if (k1->equals(object_klass) || k2->equals(object_klass)) {
310 return object_klass;
311 } else if (!k1->is_loaded() || !k2->is_loaded()) {
312 // Unloaded classes fall to java.lang.Object at a merge.
313 return object_klass;
314 } else if (k1->is_interface() != k2->is_interface()) {
315 // When an interface meets a non-interface, we get Object;
316 // This is what the verifier does.
317 return object_klass;
318 } else if (k1->is_array_klass() || k2->is_array_klass()) {
319 // When an array meets a non-array, we get Object.
320 // When objArray meets typeArray, we also get Object.
321 // And when typeArray meets different typeArray, we again get Object.
322 // But when objArray meets objArray, we look carefully at element types.
323 if (k1->is_obj_array_klass() && k2->is_obj_array_klass()) {
324 // Meet the element types, then construct the corresponding array type.
325 ciKlass* elem1 = k1->as_obj_array_klass()->element_klass();
326 ciKlass* elem2 = k2->as_obj_array_klass()->element_klass();
327 ciKlass* elem = type_meet_internal(elem1, elem2, analyzer)->as_klass();
328 // Do an easy shortcut if one type is a super of the other.
329 if (elem == elem1) {
330 assert(k1 == ciObjArrayKlass::make(elem), "shortcut is OK");
331 return k1;
332 } else if (elem == elem2) {
333 assert(k2 == ciObjArrayKlass::make(elem), "shortcut is OK");
334 return k2;
335 } else {
336 return ciObjArrayKlass::make(elem);
337 }
338 } else if (k1->is_value_array_klass() || k2->is_value_array_klass()) {
339 ciKlass* elem1 = k1->as_array_klass()->element_klass();
340 ciKlass* elem2 = k2->as_array_klass()->element_klass();
341 ciKlass* elem = type_meet_internal(elem1, elem2, analyzer)->as_klass();
342 return ciArrayKlass::make(elem);
343 } else {
344 return object_klass;
345 }
346 } else {
347 // Must be two plain old instance klasses.
348 assert(k1->is_instance_klass(), "previous cases handle non-instances");
349 assert(k2->is_instance_klass(), "previous cases handle non-instances");
350 ciType* result = k1->least_common_ancestor(k2);
351 if (never_null1 && never_null2 && result->is_valuetype()) {
352 // Both value types are never null, mark the result as never null
353 result = analyzer->mark_as_never_null(result);
354 }
355 return result;
356 }
357 }
358
359
360 // ------------------------------------------------------------------
361 // ciTypeFlow::StateVector::StateVector
362 //
363 // Build a new state vector
364 ciTypeFlow::StateVector::StateVector(ciTypeFlow* analyzer) {
365 _outer = analyzer;
366 _stack_size = -1;
367 _monitor_count = -1;
368 // Allocate the _types array
369 int max_cells = analyzer->max_cells();
370 _types = (ciType**)analyzer->arena()->Amalloc(sizeof(ciType*) * max_cells);
371 for (int i=0; i<max_cells; i++) {
372 _types[i] = top_type();
373 }
374 _trap_bci = -1;
375 _trap_index = 0;
397 }
398 // load up the non-OSR state at this point
399 non_osr_block->copy_state_into(state);
400 int non_osr_start = non_osr_block->start();
401 if (non_osr_start != start_bci()) {
402 // must flow forward from it
403 if (CITraceTypeFlow) {
404 tty->print_cr(">> Interpreting pre-OSR block %d:", non_osr_start);
405 }
406 Block* block = block_at(non_osr_start, jsrs);
407 assert(block->limit() == start_bci(), "must flow forward to start");
408 flow_block(block, state, jsrs);
409 }
410 return state;
411 // Note: The code below would be an incorrect for an OSR flow,
412 // even if it were possible for an OSR entry point to be at bci zero.
413 }
414 // "Push" the method signature into the first few locals.
415 state->set_stack_size(-max_locals());
416 if (!method()->is_static()) {
417 ciType* holder = method()->holder();
418 if (holder->is_valuetype()) {
419 // The receiver is never null
420 holder = mark_as_never_null(holder);
421 }
422 state->push(holder);
423 assert(state->tos() == state->local(0), "");
424 }
425 for (ciSignatureStream str(method()->signature());
426 !str.at_return_type();
427 str.next()) {
428 ciType* arg = str.type();
429 if (str.is_never_null()) {
430 arg = mark_as_never_null(arg);
431 }
432 state->push_translate(arg);
433 }
434 // Set the rest of the locals to bottom.
435 Cell cell = state->next_cell(state->tos());
436 state->set_stack_size(0);
437 int limit = state->limit_cell();
438 for (; cell < limit; cell = state->next_cell(cell)) {
439 state->set_type_at(cell, state->bottom_type());
440 }
441 // Lock an object, if necessary.
442 state->set_monitor_count(method()->is_synchronized() ? 1 : 0);
443 return state;
444 }
445
446 // ------------------------------------------------------------------
447 // ciTypeFlow::StateVector::copy_into
448 //
449 // Copy our value into some other StateVector
450 void ciTypeFlow::StateVector::copy_into(ciTypeFlow::StateVector* copy)
451 const {
452 copy->set_stack_size(stack_size());
558
559 return different;
560 }
561
562 // ------------------------------------------------------------------
563 // ciTypeFlow::StateVector::push_translate
564 void ciTypeFlow::StateVector::push_translate(ciType* type) {
565 BasicType basic_type = type->basic_type();
566 if (basic_type == T_BOOLEAN || basic_type == T_CHAR ||
567 basic_type == T_BYTE || basic_type == T_SHORT) {
568 push_int();
569 } else {
570 push(type);
571 if (type->is_two_word()) {
572 push(half_type(type));
573 }
574 }
575 }
576
577 // ------------------------------------------------------------------
578 // ciTypeFlow::StateVector::do_aload
579 void ciTypeFlow::StateVector::do_aload(ciBytecodeStream* str) {
580 pop_int();
581 ciArrayKlass* array_klass = pop_objOrValueArray();
582 if (array_klass == NULL) {
583 // Did aload on a null reference; push a null and ignore the exception.
584 // This instruction will never continue normally. All we have to do
585 // is report a value that will meet correctly with any downstream
586 // reference types on paths that will truly be executed. This null type
587 // meets with any reference type to yield that same reference type.
588 // (The compiler will generate an unconditional exception here.)
589 push(null_type());
590 return;
591 }
592 if (!array_klass->is_loaded()) {
593 // Only fails for some -Xcomp runs
594 trap(str, array_klass,
595 Deoptimization::make_trap_request
596 (Deoptimization::Reason_unloaded,
597 Deoptimization::Action_reinterpret));
598 return;
599 }
600 ciKlass* element_klass = array_klass->element_klass();
601 if (!element_klass->is_loaded() && element_klass->is_instance_klass()) {
602 Untested("unloaded array element class in ciTypeFlow");
603 trap(str, element_klass,
604 Deoptimization::make_trap_request
605 (Deoptimization::Reason_unloaded,
606 Deoptimization::Action_reinterpret));
607 } else {
608 if (element_klass->is_valuetype()) {
609 // Value type array elements are never null
610 push(outer()->mark_as_never_null(element_klass));
611 } else {
612 push_object(element_klass);
613 }
614 }
615 }
616
617
618 // ------------------------------------------------------------------
619 // ciTypeFlow::StateVector::do_checkcast
620 void ciTypeFlow::StateVector::do_checkcast(ciBytecodeStream* str) {
621 bool will_link;
622 ciKlass* klass = str->get_klass(will_link);
623 if (!will_link) {
624 // VM's interpreter will not load 'klass' if object is NULL.
625 // Type flow after this block may still be needed in two situations:
626 // 1) C2 uses do_null_assert() and continues compilation for later blocks
627 // 2) C2 does an OSR compile in a later block (see bug 4778368).
628 pop_object();
629 do_null_assert(klass);
630 } else {
631 pop_object();
632 if (str->is_klass_never_null()) {
633 // Casting to a Q-Type contains a NULL check
634 assert(klass->is_valuetype(), "must be a value type");
635 push(outer()->mark_as_never_null(klass));
636 } else {
637 push_object(klass);
638 }
639 }
640 }
641
642 // ------------------------------------------------------------------
643 // ciTypeFlow::StateVector::do_getfield
644 void ciTypeFlow::StateVector::do_getfield(ciBytecodeStream* str) {
645 // could add assert here for type of object.
646 pop_object();
647 do_getstatic(str);
648 }
649
650 // ------------------------------------------------------------------
651 // ciTypeFlow::StateVector::do_getstatic
652 void ciTypeFlow::StateVector::do_getstatic(ciBytecodeStream* str) {
653 bool will_link;
654 ciField* field = str->get_field(will_link);
655 if (!will_link) {
656 trap(str, field->holder(), str->get_field_holder_index());
657 } else {
658 ciType* field_type = field->type();
659 if (!field_type->is_loaded()) {
660 // Normally, we need the field's type to be loaded if we are to
661 // do anything interesting with its value.
662 // We used to do this: trap(str, str->get_field_signature_index());
663 //
664 // There is one good reason not to trap here. Execution can
665 // get past this "getfield" or "getstatic" if the value of
666 // the field is null. As long as the value is null, the class
667 // does not need to be loaded! The compiler must assume that
668 // the value of the unloaded class reference is null; if the code
669 // ever sees a non-null value, loading has occurred.
670 //
671 // This actually happens often enough to be annoying. If the
672 // compiler throws an uncommon trap at this bytecode, you can
673 // get an endless loop of recompilations, when all the code
674 // needs to do is load a series of null values. Also, a trap
675 // here can make an OSR entry point unreachable, triggering the
676 // assert on non_osr_block in ciTypeFlow::get_start_state.
677 // (See bug 4379915.)
678 do_null_assert(field_type->as_klass());
679 } else {
680 if (field->is_flattenable()) {
681 // A flattenable field is never null
682 field_type = outer()->mark_as_never_null(field_type);
683 }
684 push_translate(field_type);
685 }
686 }
687 }
688
689 // ------------------------------------------------------------------
690 // ciTypeFlow::StateVector::do_invoke
691 void ciTypeFlow::StateVector::do_invoke(ciBytecodeStream* str,
692 bool has_receiver) {
693 bool will_link;
694 ciSignature* declared_signature = NULL;
695 ciMethod* callee = str->get_method(will_link, &declared_signature);
696 assert(declared_signature != NULL, "cannot be null");
697 if (!will_link) {
698 // We weren't able to find the method.
699 if (str->cur_bc() == Bytecodes::_invokedynamic) {
700 trap(str, NULL,
701 Deoptimization::make_trap_request
702 (Deoptimization::Reason_uninitialized,
703 Deoptimization::Action_reinterpret));
731 // Check this?
732 pop_object();
733 }
734 assert(!sigstr.is_done(), "must have return type");
735 ciType* return_type = sigstr.type();
736 if (!return_type->is_void()) {
737 if (!return_type->is_loaded()) {
738 // As in do_getstatic(), generally speaking, we need the return type to
739 // be loaded if we are to do anything interesting with its value.
740 // We used to do this: trap(str, str->get_method_signature_index());
741 //
742 // We do not trap here since execution can get past this invoke if
743 // the return value is null. As long as the value is null, the class
744 // does not need to be loaded! The compiler must assume that
745 // the value of the unloaded class reference is null; if the code
746 // ever sees a non-null value, loading has occurred.
747 //
748 // See do_getstatic() for similar explanation, as well as bug 4684993.
749 do_null_assert(return_type->as_klass());
750 } else {
751 if (sigstr.is_never_null()) {
752 return_type = outer()->mark_as_never_null(return_type);
753 }
754 push_translate(return_type);
755 }
756 }
757 }
758 }
759
760 // ------------------------------------------------------------------
761 // ciTypeFlow::StateVector::do_jsr
762 void ciTypeFlow::StateVector::do_jsr(ciBytecodeStream* str) {
763 push(ciReturnAddress::make(str->next_bci()));
764 }
765
766 // ------------------------------------------------------------------
767 // ciTypeFlow::StateVector::do_ldc
768 void ciTypeFlow::StateVector::do_ldc(ciBytecodeStream* str) {
769 ciConstant con = str->get_constant();
770 BasicType basic_type = con.basic_type();
771 if (basic_type == T_ILLEGAL) {
772 // OutOfMemoryError in the CI while loading constant
773 push_null();
774 outer()->record_failure("ldc did not link");
775 return;
776 }
777 if (basic_type == T_OBJECT || basic_type == T_VALUETYPE || basic_type == T_ARRAY) {
778 ciObject* obj = con.as_object();
779 if (obj->is_null_object()) {
780 push_null();
781 } else {
782 assert(obj->is_instance() || obj->is_array(), "must be java_mirror of klass");
783 ciType* type = obj->klass();
784 if (type->is_valuetype()) {
785 type = outer()->mark_as_never_null(type);
786 }
787 push(type);
788 }
789 } else {
790 push_translate(ciType::make(basic_type));
791 }
792 }
793
794 // ------------------------------------------------------------------
795 // ciTypeFlow::StateVector::do_multianewarray
796 void ciTypeFlow::StateVector::do_multianewarray(ciBytecodeStream* str) {
797 int dimensions = str->get_dimensions();
798 bool will_link;
799 ciArrayKlass* array_klass = str->get_klass(will_link)->as_array_klass();
800 if (!will_link) {
801 trap(str, array_klass, str->get_klass_index());
802 } else {
803 for (int i = 0; i < dimensions; i++) {
804 pop_int();
805 }
806 push_object(array_klass);
807 }
808 }
809
810 // ------------------------------------------------------------------
811 // ciTypeFlow::StateVector::do_new
812 void ciTypeFlow::StateVector::do_new(ciBytecodeStream* str) {
813 bool will_link;
814 ciKlass* klass = str->get_klass(will_link);
815 if (!will_link || str->is_unresolved_klass()) {
816 trap(str, klass, str->get_klass_index());
817 } else {
818 push_object(klass);
819 }
820 }
821
822 // ------------------------------------------------------------------
823 // ciTypeFlow::StateVector::do_defaultvalue
824 void ciTypeFlow::StateVector::do_defaultvalue(ciBytecodeStream* str) {
825 bool will_link;
826 ciKlass* klass = str->get_klass(will_link);
827 if (!will_link) {
828 trap(str, klass, str->get_klass_index());
829 } else {
830 // The default value type is never null
831 push(outer()->mark_as_never_null(klass));
832 }
833 }
834
835 // ------------------------------------------------------------------
836 // ciTypeFlow::StateVector::do_withfield
837 void ciTypeFlow::StateVector::do_withfield(ciBytecodeStream* str) {
838 bool will_link;
839 ciField* field = str->get_field(will_link);
840 ciKlass* klass = field->holder();
841 if (!will_link) {
842 trap(str, klass, str->get_field_holder_index());
843 } else {
844 ciType* type = pop_value();
845 ciType* field_type = field->type();
846 assert(field_type->is_loaded(), "field type must be loaded");
847 if (field_type->is_two_word()) {
848 ciType* type2 = pop_value();
849 assert(type2->is_two_word(), "must be 2nd half");
850 assert(type == half_type(type2), "must be 2nd half");
851 }
852 pop_object();
853 // The newly created value type can never be null
854 push(outer()->mark_as_never_null(klass));
855 }
856 }
857
858 // ------------------------------------------------------------------
859 // ciTypeFlow::StateVector::do_newarray
860 void ciTypeFlow::StateVector::do_newarray(ciBytecodeStream* str) {
861 pop_int();
862 ciKlass* klass = ciTypeArrayKlass::make((BasicType)str->get_index());
863 push_object(klass);
864 }
865
866 // ------------------------------------------------------------------
867 // ciTypeFlow::StateVector::do_putfield
868 void ciTypeFlow::StateVector::do_putfield(ciBytecodeStream* str) {
869 do_putstatic(str);
870 if (_trap_bci != -1) return; // unloaded field holder, etc.
871 // could add assert here for type of object.
872 pop_object();
873 }
874
875 // ------------------------------------------------------------------
876 // ciTypeFlow::StateVector::do_putstatic
877 void ciTypeFlow::StateVector::do_putstatic(ciBytecodeStream* str) {
878 bool will_link;
943 // class later.
944 push_null();
945 }
946 }
947
948
949 // ------------------------------------------------------------------
950 // ciTypeFlow::StateVector::apply_one_bytecode
951 //
952 // Apply the effect of one bytecode to this StateVector
953 bool ciTypeFlow::StateVector::apply_one_bytecode(ciBytecodeStream* str) {
954 _trap_bci = -1;
955 _trap_index = 0;
956
957 if (CITraceTypeFlow) {
958 tty->print_cr(">> Interpreting bytecode %d:%s", str->cur_bci(),
959 Bytecodes::name(str->cur_bc()));
960 }
961
962 switch(str->cur_bc()) {
963 case Bytecodes::_aaload: do_aload(str); break;
964
965 case Bytecodes::_aastore:
966 {
967 pop_object();
968 pop_int();
969 pop_objOrValueArray();
970 break;
971 }
972 case Bytecodes::_aconst_null:
973 {
974 push_null();
975 break;
976 }
977 case Bytecodes::_aload: load_local_object(str->get_index()); break;
978 case Bytecodes::_aload_0: load_local_object(0); break;
979 case Bytecodes::_aload_1: load_local_object(1); break;
980 case Bytecodes::_aload_2: load_local_object(2); break;
981 case Bytecodes::_aload_3: load_local_object(3); break;
982
983 case Bytecodes::_anewarray:
984 {
985 pop_int();
986 bool will_link;
987 ciKlass* element_klass = str->get_klass(will_link);
988 if (!will_link) {
989 trap(str, element_klass, str->get_klass_index());
990 } else {
991 push_object(ciArrayKlass::make(element_klass));
992 }
993 break;
994 }
995 case Bytecodes::_areturn:
996 case Bytecodes::_ifnonnull:
997 case Bytecodes::_ifnull:
998 {
999 pop_object();
1000 break;
1001 }
1002 case Bytecodes::_monitorenter:
1003 {
1004 pop_object();
1005 set_monitor_count(monitor_count() + 1);
1006 break;
1007 }
1008 case Bytecodes::_monitorexit:
1009 {
1010 pop_object();
1011 assert(monitor_count() > 0, "must be a monitor to exit from");
1503 }
1504 case Bytecodes::_lshl:
1505 case Bytecodes::_lshr:
1506 case Bytecodes::_lushr:
1507 {
1508 pop_int();
1509 pop_long();
1510 push_long();
1511 break;
1512 }
1513 case Bytecodes::_lstore: store_local_long(str->get_index()); break;
1514 case Bytecodes::_lstore_0: store_local_long(0); break;
1515 case Bytecodes::_lstore_1: store_local_long(1); break;
1516 case Bytecodes::_lstore_2: store_local_long(2); break;
1517 case Bytecodes::_lstore_3: store_local_long(3); break;
1518
1519 case Bytecodes::_multianewarray: do_multianewarray(str); break;
1520
1521 case Bytecodes::_new: do_new(str); break;
1522
1523 case Bytecodes::_defaultvalue: do_defaultvalue(str); break;
1524 case Bytecodes::_withfield: do_withfield(str); break;
1525
1526 case Bytecodes::_newarray: do_newarray(str); break;
1527
1528 case Bytecodes::_pop:
1529 {
1530 pop();
1531 break;
1532 }
1533 case Bytecodes::_pop2:
1534 {
1535 pop();
1536 pop();
1537 break;
1538 }
1539
1540 case Bytecodes::_putfield: do_putfield(str); break;
1541 case Bytecodes::_putstatic: do_putstatic(str); break;
1542
1543 case Bytecodes::_ret: do_ret(str); break;
1544
1545 case Bytecodes::_swap:
1546 {
1547 ciType* value1 = pop_value();
1548 ciType* value2 = pop_value();
1549 push(value1);
1550 push(value2);
1551 break;
1552 }
1553
1554 case Bytecodes::_wide:
1555 default:
1556 {
1557 // The iterator should skip this.
1558 ShouldNotReachHere();
1559 break;
1560 }
1561 }
1562
1563 if (CITraceTypeFlow) {
1564 print_on(tty);
1565 }
1566
1567 return (_trap_bci != -1);
1568 }
1569
1570 #ifndef PRODUCT
1571 // ------------------------------------------------------------------
1572 // ciTypeFlow::StateVector::print_cell_on
1573 void ciTypeFlow::StateVector::print_cell_on(outputStream* st, Cell c) const {
1817 case Bytecodes::_lookupswitch: {
1818 Bytecode_lookupswitch lookupswitch(str);
1819
1820 int npairs = lookupswitch.number_of_pairs();
1821 _successors =
1822 new (arena) GrowableArray<Block*>(arena, npairs+1, 0, NULL);
1823 int bci = current_bci + lookupswitch.default_offset();
1824 Block* block = analyzer->block_at(bci, jsrs);
1825 assert(_successors->length() == SWITCH_DEFAULT, "");
1826 _successors->append(block);
1827 while(--npairs >= 0) {
1828 LookupswitchPair pair = lookupswitch.pair_at(npairs);
1829 int bci = current_bci + pair.offset();
1830 Block* block = analyzer->block_at(bci, jsrs);
1831 assert(_successors->length() >= SWITCH_CASES, "");
1832 _successors->append_if_missing(block);
1833 }
1834 break;
1835 }
1836
1837 case Bytecodes::_athrow:
1838 case Bytecodes::_ireturn:
1839 case Bytecodes::_lreturn:
1840 case Bytecodes::_freturn:
1841 case Bytecodes::_dreturn:
1842 case Bytecodes::_areturn:
1843 case Bytecodes::_return:
1844 _successors =
1845 new (arena) GrowableArray<Block*>(arena, 1, 0, NULL);
1846 // No successors
1847 break;
1848
1849 case Bytecodes::_ret: {
1850 _successors =
1851 new (arena) GrowableArray<Block*>(arena, 1, 0, NULL);
1852
1853 Cell local = state->local(str->get_index());
1854 ciType* return_address = state->type_at(local);
1855 assert(return_address->is_return_address(), "verify: wrong type");
1856 int bci = return_address->as_return_address()->bci();
1857 assert(_successors->length() == GOTO_TARGET, "");
1858 _successors->append(analyzer->block_at(bci, jsrs));
1859 break;
1860 }
1861
1862 case Bytecodes::_wide:
3051 return dominated[block->rpo()];
3052 }
3053
3054 // ------------------------------------------------------------------
3055 // ciTypeFlow::record_failure()
3056 // The ciTypeFlow object keeps track of failure reasons separately from the ciEnv.
3057 // This is required because there is not a 1-1 relation between the ciEnv and
3058 // the TypeFlow passes within a compilation task. For example, if the compiler
3059 // is considering inlining a method, it will request a TypeFlow. If that fails,
3060 // the compilation as a whole may continue without the inlining. Some TypeFlow
3061 // requests are not optional; if they fail the requestor is responsible for
3062 // copying the failure reason up to the ciEnv. (See Parse::Parse.)
3063 void ciTypeFlow::record_failure(const char* reason) {
3064 if (env()->log() != NULL) {
3065 env()->log()->elem("failure reason='%s' phase='typeflow'", reason);
3066 }
3067 if (_failure_reason == NULL) {
3068 // Record the first failure reason.
3069 _failure_reason = reason;
3070 }
3071 }
3072
3073 ciType* ciTypeFlow::mark_as_never_null(ciType* type) {
3074 // Wrap the type to carry the information that it is never null
3075 return env()->make_never_null_wrapper(type);
3076 }
3077
3078 #ifndef PRODUCT
3079 // ------------------------------------------------------------------
3080 // ciTypeFlow::print_on
3081 void ciTypeFlow::print_on(outputStream* st) const {
3082 // Walk through CI blocks
3083 st->print_cr("********************************************************");
3084 st->print ("TypeFlow for ");
3085 method()->name()->print_symbol_on(st);
3086 int limit_bci = code_size();
3087 st->print_cr(" %d bytes", limit_bci);
3088 ciMethodBlocks *mblks = _methodBlocks;
3089 ciBlock* current = NULL;
3090 for (int bci = 0; bci < limit_bci; bci++) {
3091 ciBlock* blk = mblks->block_containing(bci);
3092 if (blk != NULL && blk != current) {
3093 current = blk;
3094 current->print_on(st);
3095
|