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 *
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 "ci/ciConstant.hpp"
26 #include "ci/ciField.hpp"
27 #include "ci/ciMethod.hpp"
28 #include "ci/ciMethodData.hpp"
29 #include "ci/ciObjArrayKlass.hpp"
30 #include "ci/ciStreams.hpp"
31 #include "ci/ciTypeArrayKlass.hpp"
32 #include "ci/ciTypeFlow.hpp"
33 #include "compiler/compileLog.hpp"
34 #include "interpreter/bytecode.hpp"
35 #include "interpreter/bytecodes.hpp"
36 #include "memory/allocation.inline.hpp"
37 #include "memory/resourceArea.hpp"
38 #include "oops/oop.inline.hpp"
39 #include "opto/compile.hpp"
40 #include "runtime/deoptimization.hpp"
41 #include "utilities/growableArray.hpp"
42
43 // ciTypeFlow::JsrSet
44 //
45 // A JsrSet represents some set of JsrRecords. This class
46 // is used to record a set of all jsr routines which we permit
255 // ciTypeFlow::StateVector::type_meet
256 //
257 // Meet two types.
258 //
259 // The semi-lattice of types use by this analysis are modeled on those
260 // of the verifier. The lattice is as follows:
261 //
262 // top_type() >= all non-extremal types >= bottom_type
263 // and
264 // Every primitive type is comparable only with itself. The meet of
265 // reference types is determined by their kind: instance class,
266 // interface, or array class. The meet of two types of the same
267 // kind is their least common ancestor. The meet of two types of
268 // different kinds is always java.lang.Object.
269 ciType* ciTypeFlow::StateVector::type_meet_internal(ciType* t1, ciType* t2, ciTypeFlow* analyzer) {
270 assert(t1 != t2, "checked in caller");
271 if (t1->equals(top_type())) {
272 return t2;
273 } else if (t2->equals(top_type())) {
274 return t1;
275 } else if (t1->is_primitive_type() || t2->is_primitive_type()) {
276 // Special case null_type. null_type meet any reference type T
277 // is T. null_type meet null_type is null_type.
278 if (t1->equals(null_type())) {
279 if (!t2->is_primitive_type() || t2->equals(null_type())) {
280 return t2;
281 }
282 } else if (t2->equals(null_type())) {
283 if (!t1->is_primitive_type()) {
284 return t1;
285 }
286 }
287
288 // At least one of the two types is a non-top primitive type.
289 // The other type is not equal to it. Fall to bottom.
290 return bottom_type();
291 } else {
292 // Both types are non-top non-primitive types. That is,
293 // both types are either instanceKlasses or arrayKlasses.
294 ciKlass* object_klass = analyzer->env()->Object_klass();
295 ciKlass* k1 = t1->as_klass();
296 ciKlass* k2 = t2->as_klass();
297 if (k1->equals(object_klass) || k2->equals(object_klass)) {
298 return object_klass;
299 } else if (!k1->is_loaded() || !k2->is_loaded()) {
300 // Unloaded classes fall to java.lang.Object at a merge.
301 return object_klass;
302 } else if (k1->is_interface() != k2->is_interface()) {
303 // When an interface meets a non-interface, we get Object;
304 // This is what the verifier does.
305 return object_klass;
306 } else if (k1->is_array_klass() || k2->is_array_klass()) {
307 // When an array meets a non-array, we get Object.
308 // When objArray meets typeArray, we also get Object.
309 // And when typeArray meets different typeArray, we again get Object.
310 // But when objArray meets objArray, we look carefully at element types.
311 if (k1->is_obj_array_klass() && k2->is_obj_array_klass()) {
312 // Meet the element types, then construct the corresponding array type.
313 ciKlass* elem1 = k1->as_obj_array_klass()->element_klass();
314 ciKlass* elem2 = k2->as_obj_array_klass()->element_klass();
315 ciKlass* elem = type_meet_internal(elem1, elem2, analyzer)->as_klass();
316 // Do an easy shortcut if one type is a super of the other.
317 if (elem == elem1) {
318 assert(k1 == ciObjArrayKlass::make(elem), "shortcut is OK");
319 return k1;
320 } else if (elem == elem2) {
321 assert(k2 == ciObjArrayKlass::make(elem), "shortcut is OK");
322 return k2;
323 } else {
324 return ciObjArrayKlass::make(elem);
325 }
326 } else {
327 return object_klass;
328 }
329 } else {
330 // Must be two plain old instance klasses.
331 assert(k1->is_instance_klass(), "previous cases handle non-instances");
332 assert(k2->is_instance_klass(), "previous cases handle non-instances");
333 return k1->least_common_ancestor(k2);
334 }
335 }
336 }
337
338
339 // ------------------------------------------------------------------
340 // ciTypeFlow::StateVector::StateVector
341 //
342 // Build a new state vector
343 ciTypeFlow::StateVector::StateVector(ciTypeFlow* analyzer) {
344 _outer = analyzer;
345 _stack_size = -1;
346 _monitor_count = -1;
347 // Allocate the _types array
348 int max_cells = analyzer->max_cells();
349 _types = (ciType**)analyzer->arena()->Amalloc(sizeof(ciType*) * max_cells);
350 for (int i=0; i<max_cells; i++) {
351 _types[i] = top_type();
352 }
353 _trap_bci = -1;
354 _trap_index = 0;
376 }
377 // load up the non-OSR state at this point
378 non_osr_block->copy_state_into(state);
379 int non_osr_start = non_osr_block->start();
380 if (non_osr_start != start_bci()) {
381 // must flow forward from it
382 if (CITraceTypeFlow) {
383 tty->print_cr(">> Interpreting pre-OSR block %d:", non_osr_start);
384 }
385 Block* block = block_at(non_osr_start, jsrs);
386 assert(block->limit() == start_bci(), "must flow forward to start");
387 flow_block(block, state, jsrs);
388 }
389 return state;
390 // Note: The code below would be an incorrect for an OSR flow,
391 // even if it were possible for an OSR entry point to be at bci zero.
392 }
393 // "Push" the method signature into the first few locals.
394 state->set_stack_size(-max_locals());
395 if (!method()->is_static()) {
396 state->push(method()->holder());
397 assert(state->tos() == state->local(0), "");
398 }
399 for (ciSignatureStream str(method()->signature());
400 !str.at_return_type();
401 str.next()) {
402 state->push_translate(str.type());
403 }
404 // Set the rest of the locals to bottom.
405 assert(state->stack_size() <= 0, "stack size should not be strictly positive");
406 while (state->stack_size() < 0) {
407 state->push(state->bottom_type());
408 }
409 // Lock an object, if necessary.
410 state->set_monitor_count(method()->is_synchronized() ? 1 : 0);
411 return state;
412 }
413
414 // ------------------------------------------------------------------
415 // ciTypeFlow::StateVector::copy_into
416 //
526
527 return different;
528 }
529
530 // ------------------------------------------------------------------
531 // ciTypeFlow::StateVector::push_translate
532 void ciTypeFlow::StateVector::push_translate(ciType* type) {
533 BasicType basic_type = type->basic_type();
534 if (basic_type == T_BOOLEAN || basic_type == T_CHAR ||
535 basic_type == T_BYTE || basic_type == T_SHORT) {
536 push_int();
537 } else {
538 push(type);
539 if (type->is_two_word()) {
540 push(half_type(type));
541 }
542 }
543 }
544
545 // ------------------------------------------------------------------
546 // ciTypeFlow::StateVector::do_aaload
547 void ciTypeFlow::StateVector::do_aaload(ciBytecodeStream* str) {
548 pop_int();
549 ciObjArrayKlass* array_klass = pop_objArray();
550 if (array_klass == nullptr) {
551 // Did aaload on a null reference; push a null and ignore the exception.
552 // This instruction will never continue normally. All we have to do
553 // is report a value that will meet correctly with any downstream
554 // reference types on paths that will truly be executed. This null type
555 // meets with any reference type to yield that same reference type.
556 // (The compiler will generate an unconditional exception here.)
557 push(null_type());
558 return;
559 }
560 if (!array_klass->is_loaded()) {
561 // Only fails for some -Xcomp runs
562 trap(str, array_klass,
563 Deoptimization::make_trap_request
564 (Deoptimization::Reason_unloaded,
565 Deoptimization::Action_reinterpret));
566 return;
567 }
568 ciKlass* element_klass = array_klass->element_klass();
569 if (!element_klass->is_loaded() && element_klass->is_instance_klass()) {
570 Untested("unloaded array element class in ciTypeFlow");
571 trap(str, element_klass,
572 Deoptimization::make_trap_request
573 (Deoptimization::Reason_unloaded,
574 Deoptimization::Action_reinterpret));
575 } else {
576 push_object(element_klass);
577 }
578 }
579
580
581 // ------------------------------------------------------------------
582 // ciTypeFlow::StateVector::do_checkcast
583 void ciTypeFlow::StateVector::do_checkcast(ciBytecodeStream* str) {
584 bool will_link;
585 ciKlass* klass = str->get_klass(will_link);
586 if (!will_link) {
587 // VM's interpreter will not load 'klass' if object is null.
588 // Type flow after this block may still be needed in two situations:
589 // 1) C2 uses do_null_assert() and continues compilation for later blocks
590 // 2) C2 does an OSR compile in a later block (see bug 4778368).
591 pop_object();
592 do_null_assert(klass);
593 } else {
594 pop_object();
595 push_object(klass);
596 }
597 }
598
599 // ------------------------------------------------------------------
600 // ciTypeFlow::StateVector::do_getfield
601 void ciTypeFlow::StateVector::do_getfield(ciBytecodeStream* str) {
602 // could add assert here for type of object.
603 pop_object();
604 do_getstatic(str);
605 }
606
607 // ------------------------------------------------------------------
608 // ciTypeFlow::StateVector::do_getstatic
609 void ciTypeFlow::StateVector::do_getstatic(ciBytecodeStream* str) {
610 bool will_link;
611 ciField* field = str->get_field(will_link);
612 if (!will_link) {
613 trap(str, field->holder(), str->get_field_holder_index());
614 } else {
615 ciType* field_type = field->type();
616 if (!field_type->is_loaded()) {
617 // Normally, we need the field's type to be loaded if we are to
618 // do anything interesting with its value.
619 // We used to do this: trap(str, str->get_field_signature_index());
620 //
621 // There is one good reason not to trap here. Execution can
622 // get past this "getfield" or "getstatic" if the value of
623 // the field is null. As long as the value is null, the class
624 // does not need to be loaded! The compiler must assume that
625 // the value of the unloaded class reference is null; if the code
626 // ever sees a non-null value, loading has occurred.
627 //
628 // This actually happens often enough to be annoying. If the
629 // compiler throws an uncommon trap at this bytecode, you can
630 // get an endless loop of recompilations, when all the code
631 // needs to do is load a series of null values. Also, a trap
632 // here can make an OSR entry point unreachable, triggering the
633 // assert on non_osr_block in ciTypeFlow::get_start_state.
634 // (See bug 4379915.)
635 do_null_assert(field_type->as_klass());
636 } else {
637 push_translate(field_type);
638 }
639 }
640 }
641
642 // ------------------------------------------------------------------
643 // ciTypeFlow::StateVector::do_invoke
644 void ciTypeFlow::StateVector::do_invoke(ciBytecodeStream* str,
645 bool has_receiver) {
646 bool will_link;
647 ciSignature* declared_signature = nullptr;
648 ciMethod* callee = str->get_method(will_link, &declared_signature);
649 assert(declared_signature != nullptr, "cannot be null");
650 if (!will_link) {
651 // We weren't able to find the method.
652 if (str->cur_bc() == Bytecodes::_invokedynamic) {
653 trap(str, nullptr,
654 Deoptimization::make_trap_request
655 (Deoptimization::Reason_uninitialized,
656 Deoptimization::Action_reinterpret));
664 // invokehandle).
665 ciSignatureStream sigstr(declared_signature);
666 const int arg_size = declared_signature->size();
667 const int stack_base = stack_size() - arg_size;
668 int i = 0;
669 for( ; !sigstr.at_return_type(); sigstr.next()) {
670 ciType* type = sigstr.type();
671 ciType* stack_type = type_at(stack(stack_base + i++));
672 // Do I want to check this type?
673 // assert(stack_type->is_subtype_of(type), "bad type for field value");
674 if (type->is_two_word()) {
675 ciType* stack_type2 = type_at(stack(stack_base + i++));
676 assert(stack_type2->equals(half_type(type)), "must be 2nd half");
677 }
678 }
679 assert(arg_size == i, "must match");
680 for (int j = 0; j < arg_size; j++) {
681 pop();
682 }
683 if (has_receiver) {
684 // Check this?
685 pop_object();
686 }
687 assert(!sigstr.is_done(), "must have return type");
688 ciType* return_type = sigstr.type();
689 if (!return_type->is_void()) {
690 if (!return_type->is_loaded()) {
691 // As in do_getstatic(), generally speaking, we need the return type to
692 // be loaded if we are to do anything interesting with its value.
693 // We used to do this: trap(str, str->get_method_signature_index());
694 //
695 // We do not trap here since execution can get past this invoke if
696 // the return value is null. As long as the value is null, the class
697 // does not need to be loaded! The compiler must assume that
698 // the value of the unloaded class reference is null; if the code
699 // ever sees a non-null value, loading has occurred.
700 //
701 // See do_getstatic() for similar explanation, as well as bug 4684993.
702 do_null_assert(return_type->as_klass());
703 } else {
704 push_translate(return_type);
720 trap(str, nullptr, Deoptimization::make_trap_request(Deoptimization::Reason_unhandled,
721 Deoptimization::Action_none));
722 return;
723 }
724 ciConstant con = str->get_constant();
725 if (con.is_valid()) {
726 int cp_index = str->get_constant_pool_index();
727 if (!con.is_loaded()) {
728 trap(str, nullptr, Deoptimization::make_trap_request(Deoptimization::Reason_unloaded,
729 Deoptimization::Action_reinterpret,
730 cp_index));
731 return;
732 }
733 BasicType basic_type = str->get_basic_type_for_constant_at(cp_index);
734 if (is_reference_type(basic_type)) {
735 ciObject* obj = con.as_object();
736 if (obj->is_null_object()) {
737 push_null();
738 } else {
739 assert(obj->is_instance() || obj->is_array(), "must be java_mirror of klass");
740 push_object(obj->klass());
741 }
742 } else {
743 assert(basic_type == con.basic_type() || con.basic_type() == T_OBJECT,
744 "not a boxed form: %s vs %s", type2name(basic_type), type2name(con.basic_type()));
745 push_translate(ciType::make(basic_type));
746 }
747 } else {
748 // OutOfMemoryError in the CI while loading a String constant.
749 push_null();
750 outer()->record_failure("ldc did not link");
751 }
752 }
753
754 // ------------------------------------------------------------------
755 // ciTypeFlow::StateVector::do_multianewarray
756 void ciTypeFlow::StateVector::do_multianewarray(ciBytecodeStream* str) {
757 int dimensions = str->get_dimensions();
758 bool will_link;
759 ciArrayKlass* array_klass = str->get_klass(will_link)->as_array_klass();
760 if (!will_link) {
761 trap(str, array_klass, str->get_klass_index());
762 } else {
763 for (int i = 0; i < dimensions; i++) {
764 pop_int();
765 }
766 push_object(array_klass);
767 }
768 }
769
770 // ------------------------------------------------------------------
771 // ciTypeFlow::StateVector::do_new
772 void ciTypeFlow::StateVector::do_new(ciBytecodeStream* str) {
773 bool will_link;
774 ciKlass* klass = str->get_klass(will_link);
775 if (!will_link || str->is_unresolved_klass()) {
776 trap(str, klass, str->get_klass_index());
777 } else {
778 push_object(klass);
779 }
780 }
781
782 // ------------------------------------------------------------------
783 // ciTypeFlow::StateVector::do_newarray
784 void ciTypeFlow::StateVector::do_newarray(ciBytecodeStream* str) {
785 pop_int();
786 ciKlass* klass = ciTypeArrayKlass::make((BasicType)str->get_index());
787 push_object(klass);
788 }
789
790 // ------------------------------------------------------------------
791 // ciTypeFlow::StateVector::do_putfield
792 void ciTypeFlow::StateVector::do_putfield(ciBytecodeStream* str) {
793 do_putstatic(str);
794 if (_trap_bci != -1) return; // unloaded field holder, etc.
795 // could add assert here for type of object.
796 pop_object();
797 }
867 // class later.
868 push_null();
869 }
870 }
871
872
873 // ------------------------------------------------------------------
874 // ciTypeFlow::StateVector::apply_one_bytecode
875 //
876 // Apply the effect of one bytecode to this StateVector
877 bool ciTypeFlow::StateVector::apply_one_bytecode(ciBytecodeStream* str) {
878 _trap_bci = -1;
879 _trap_index = 0;
880
881 if (CITraceTypeFlow) {
882 tty->print_cr(">> Interpreting bytecode %d:%s", str->cur_bci(),
883 Bytecodes::name(str->cur_bc()));
884 }
885
886 switch(str->cur_bc()) {
887 case Bytecodes::_aaload: do_aaload(str); break;
888
889 case Bytecodes::_aastore:
890 {
891 pop_object();
892 pop_int();
893 pop_objArray();
894 break;
895 }
896 case Bytecodes::_aconst_null:
897 {
898 push_null();
899 break;
900 }
901 case Bytecodes::_aload: load_local_object(str->get_index()); break;
902 case Bytecodes::_aload_0: load_local_object(0); break;
903 case Bytecodes::_aload_1: load_local_object(1); break;
904 case Bytecodes::_aload_2: load_local_object(2); break;
905 case Bytecodes::_aload_3: load_local_object(3); break;
906
907 case Bytecodes::_anewarray:
908 {
909 pop_int();
910 bool will_link;
911 ciKlass* element_klass = str->get_klass(will_link);
912 if (!will_link) {
913 trap(str, element_klass, str->get_klass_index());
914 } else {
915 push_object(ciObjArrayKlass::make(element_klass));
916 }
917 break;
918 }
919 case Bytecodes::_areturn:
920 case Bytecodes::_ifnonnull:
921 case Bytecodes::_ifnull:
922 {
923 pop_object();
924 break;
925 }
926 case Bytecodes::_monitorenter:
927 {
928 pop_object();
929 set_monitor_count(monitor_count() + 1);
930 break;
931 }
932 case Bytecodes::_monitorexit:
933 {
934 pop_object();
935 assert(monitor_count() > 0, "must be a monitor to exit from");
1454 case Bytecodes::_pop2:
1455 {
1456 pop();
1457 pop();
1458 break;
1459 }
1460
1461 case Bytecodes::_putfield: do_putfield(str); break;
1462 case Bytecodes::_putstatic: do_putstatic(str); break;
1463
1464 case Bytecodes::_ret: do_ret(str); break;
1465
1466 case Bytecodes::_swap:
1467 {
1468 ciType* value1 = pop_value();
1469 ciType* value2 = pop_value();
1470 push(value1);
1471 push(value2);
1472 break;
1473 }
1474 case Bytecodes::_wide:
1475 default:
1476 {
1477 // The iterator should skip this.
1478 ShouldNotReachHere();
1479 break;
1480 }
1481 }
1482
1483 if (CITraceTypeFlow) {
1484 print_on(tty);
1485 }
1486
1487 return (_trap_bci != -1);
1488 }
1489
1490 #ifndef PRODUCT
1491 // ------------------------------------------------------------------
1492 // ciTypeFlow::StateVector::print_cell_on
1493 void ciTypeFlow::StateVector::print_cell_on(outputStream* st, Cell c) const {
1494 ciType* type = type_at(c);
1495 if (type == top_type()) {
1496 st->print("top");
1497 } else if (type == bottom_type()) {
1498 st->print("bottom");
1499 } else if (type == null_type()) {
1500 st->print("null");
1501 } else if (type == long2_type()) {
1502 st->print("long2");
1503 } else if (type == double2_type()) {
1504 st->print("double2");
1505 } else if (is_int(type)) {
1506 st->print("int");
1507 } else if (is_long(type)) {
1508 st->print("long");
1509 } else if (is_float(type)) {
1510 st->print("float");
1511 } else if (is_double(type)) {
1512 st->print("double");
1513 } else if (type->is_return_address()) {
1514 st->print("address(%d)", type->as_return_address()->bci());
1737 case Bytecodes::_lookupswitch: {
1738 Bytecode_lookupswitch lookupswitch(str);
1739
1740 int npairs = lookupswitch.number_of_pairs();
1741 _successors =
1742 new (arena) GrowableArray<Block*>(arena, npairs+1, 0, nullptr);
1743 int bci = current_bci + lookupswitch.default_offset();
1744 Block* block = analyzer->block_at(bci, jsrs);
1745 assert(_successors->length() == SWITCH_DEFAULT, "");
1746 _successors->append(block);
1747 while(--npairs >= 0) {
1748 LookupswitchPair pair = lookupswitch.pair_at(npairs);
1749 int bci = current_bci + pair.offset();
1750 Block* block = analyzer->block_at(bci, jsrs);
1751 assert(_successors->length() >= SWITCH_CASES, "");
1752 _successors->append_if_missing(block);
1753 }
1754 break;
1755 }
1756
1757 case Bytecodes::_athrow: case Bytecodes::_ireturn:
1758 case Bytecodes::_lreturn: case Bytecodes::_freturn:
1759 case Bytecodes::_dreturn: case Bytecodes::_areturn:
1760 case Bytecodes::_return:
1761 _successors =
1762 new (arena) GrowableArray<Block*>(arena, 1, 0, nullptr);
1763 // No successors
1764 break;
1765
1766 case Bytecodes::_ret: {
1767 _successors =
1768 new (arena) GrowableArray<Block*>(arena, 1, 0, nullptr);
1769
1770 Cell local = state->local(str->get_index());
1771 ciType* return_address = state->type_at(local);
1772 assert(return_address->is_return_address(), "verify: wrong type");
1773 int bci = return_address->as_return_address()->bci();
1774 assert(_successors->length() == GOTO_TARGET, "");
1775 _successors->append(analyzer->block_at(bci, jsrs));
1776 break;
1777 }
1778
1779 case Bytecodes::_wide:
3132
3133 // ------------------------------------------------------------------
3134 // ciTypeFlow::record_failure()
3135 // The ciTypeFlow object keeps track of failure reasons separately from the ciEnv.
3136 // This is required because there is not a 1-1 relation between the ciEnv and
3137 // the TypeFlow passes within a compilation task. For example, if the compiler
3138 // is considering inlining a method, it will request a TypeFlow. If that fails,
3139 // the compilation as a whole may continue without the inlining. Some TypeFlow
3140 // requests are not optional; if they fail the requestor is responsible for
3141 // copying the failure reason up to the ciEnv. (See Parse::Parse.)
3142 void ciTypeFlow::record_failure(const char* reason) {
3143 if (env()->log() != nullptr) {
3144 env()->log()->elem("failure reason='%s' phase='typeflow'", reason);
3145 }
3146 if (_failure_reason == nullptr) {
3147 // Record the first failure reason.
3148 _failure_reason = reason;
3149 }
3150 }
3151
3152 #ifndef PRODUCT
3153 void ciTypeFlow::print() const { print_on(tty); }
3154
3155 // ------------------------------------------------------------------
3156 // ciTypeFlow::print_on
3157 void ciTypeFlow::print_on(outputStream* st) const {
3158 // Walk through CI blocks
3159 st->print_cr("********************************************************");
3160 st->print ("TypeFlow for ");
3161 method()->name()->print_symbol_on(st);
3162 int limit_bci = code_size();
3163 st->print_cr(" %d bytes", limit_bci);
3164 ciMethodBlocks* mblks = _method->get_method_blocks();
3165 ciBlock* current = nullptr;
3166 for (int bci = 0; bci < limit_bci; bci++) {
3167 ciBlock* blk = mblks->block_containing(bci);
3168 if (blk != nullptr && blk != current) {
3169 current = blk;
3170 current->print_on(st);
3171
|
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 *
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 "ci/ciConstant.hpp"
26 #include "ci/ciField.hpp"
27 #include "ci/ciInlineKlass.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 "runtime/deoptimization.hpp"
42 #include "utilities/growableArray.hpp"
43
44 // ciTypeFlow::JsrSet
45 //
46 // A JsrSet represents some set of JsrRecords. This class
47 // is used to record a set of all jsr routines which we permit
256 // ciTypeFlow::StateVector::type_meet
257 //
258 // Meet two types.
259 //
260 // The semi-lattice of types use by this analysis are modeled on those
261 // of the verifier. The lattice is as follows:
262 //
263 // top_type() >= all non-extremal types >= bottom_type
264 // and
265 // Every primitive type is comparable only with itself. The meet of
266 // reference types is determined by their kind: instance class,
267 // interface, or array class. The meet of two types of the same
268 // kind is their least common ancestor. The meet of two types of
269 // different kinds is always java.lang.Object.
270 ciType* ciTypeFlow::StateVector::type_meet_internal(ciType* t1, ciType* t2, ciTypeFlow* analyzer) {
271 assert(t1 != t2, "checked in caller");
272 if (t1->equals(top_type())) {
273 return t2;
274 } else if (t2->equals(top_type())) {
275 return t1;
276 }
277 // Unwrap after saving nullness information and handling top meets
278 assert(t1->is_early_larval() == t2->is_early_larval(), "States should be compatible.");
279 bool is_early_larval = t1->is_early_larval();
280 bool null_free1 = t1->is_null_free();
281 bool null_free2 = t2->is_null_free();
282 if (t1->unwrap() == t2->unwrap() && null_free1 == null_free2) {
283 return t1;
284 }
285 t1 = t1->unwrap();
286 t2 = t2->unwrap();
287
288 if (t1->is_primitive_type() || t2->is_primitive_type()) {
289 // Special case null_type. null_type meet any reference type T
290 // is T. null_type meet null_type is null_type.
291 if (t1->equals(null_type())) {
292 if (!t2->is_primitive_type() || t2->equals(null_type())) {
293 return t2;
294 }
295 } else if (t2->equals(null_type())) {
296 if (!t1->is_primitive_type()) {
297 return t1;
298 }
299 }
300
301 // At least one of the two types is a non-top primitive type.
302 // The other type is not equal to it. Fall to bottom.
303 return bottom_type();
304 }
305
306 // Both types are non-top non-primitive types. That is,
307 // both types are either instanceKlasses or arrayKlasses.
308 ciKlass* object_klass = analyzer->env()->Object_klass();
309 ciKlass* k1 = t1->as_klass();
310 ciKlass* k2 = t2->as_klass();
311 if (k1->equals(object_klass) || k2->equals(object_klass)) {
312 return object_klass;
313 } else if (!k1->is_loaded() || !k2->is_loaded()) {
314 // Unloaded classes fall to java.lang.Object at a merge.
315 return object_klass;
316 } else if (k1->is_interface() != k2->is_interface()) {
317 // When an interface meets a non-interface, we get Object;
318 // This is what the verifier does.
319 return object_klass;
320 } else if (k1->is_array_klass() || k2->is_array_klass()) {
321 // When an array meets a non-array, we get Object.
322 // When (obj/flat)Array meets typeArray, we also get Object.
323 // And when typeArray meets different typeArray, we again get Object.
324 // But when (obj/flat)Array meets (obj/flat)Array, we look carefully at element types.
325 if ((k1->is_obj_array_klass() || k1->is_flat_array_klass()) &&
326 (k2->is_obj_array_klass() || k2->is_flat_array_klass())) {
327 ciType* elem1 = k1->as_array_klass()->element_klass();
328 ciType* elem2 = k2->as_array_klass()->element_klass();
329 ciType* elem = elem1;
330 if (elem1 != elem2) {
331 elem = type_meet_internal(elem1, elem2, analyzer)->as_klass();
332 }
333 // Do an easy shortcut if one type is a super of the other.
334 if (elem == elem1 && !elem->is_inlinetype()) {
335 assert(k1 == ciArrayKlass::make(elem), "shortcut is OK");
336 return k1;
337 } else if (elem == elem2 && !elem->is_inlinetype()) {
338 assert(k2 == ciArrayKlass::make(elem), "shortcut is OK");
339 return k2;
340 } else {
341 return ciArrayKlass::make(elem);
342 }
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 (null_free1 && null_free2 && result->is_inlinetype()) {
352 result = analyzer->mark_as_null_free(result);
353 }
354 if (is_early_larval) {
355 result = analyzer->mark_as_early_larval(result);
356 }
357 return result;
358 }
359 }
360
361
362 // ------------------------------------------------------------------
363 // ciTypeFlow::StateVector::StateVector
364 //
365 // Build a new state vector
366 ciTypeFlow::StateVector::StateVector(ciTypeFlow* analyzer) {
367 _outer = analyzer;
368 _stack_size = -1;
369 _monitor_count = -1;
370 // Allocate the _types array
371 int max_cells = analyzer->max_cells();
372 _types = (ciType**)analyzer->arena()->Amalloc(sizeof(ciType*) * max_cells);
373 for (int i=0; i<max_cells; i++) {
374 _types[i] = top_type();
375 }
376 _trap_bci = -1;
377 _trap_index = 0;
399 }
400 // load up the non-OSR state at this point
401 non_osr_block->copy_state_into(state);
402 int non_osr_start = non_osr_block->start();
403 if (non_osr_start != start_bci()) {
404 // must flow forward from it
405 if (CITraceTypeFlow) {
406 tty->print_cr(">> Interpreting pre-OSR block %d:", non_osr_start);
407 }
408 Block* block = block_at(non_osr_start, jsrs);
409 assert(block->limit() == start_bci(), "must flow forward to start");
410 flow_block(block, state, jsrs);
411 }
412 return state;
413 // Note: The code below would be an incorrect for an OSR flow,
414 // even if it were possible for an OSR entry point to be at bci zero.
415 }
416 // "Push" the method signature into the first few locals.
417 state->set_stack_size(-max_locals());
418 if (!method()->is_static()) {
419 ciType* holder = method()->holder();
420 if (method()->is_object_constructor()) {
421 if (holder->is_inlinetype() || (holder->is_instance_klass() && !holder->as_instance_klass()->flags().is_identity())) {
422 // The receiver is early larval (so also null-free)
423 holder = mark_as_early_larval(holder);
424 }
425 } else {
426 if (holder->is_inlinetype()) {
427 // The receiver is null-free
428 holder = mark_as_null_free(holder);
429 }
430 }
431 state->push(holder);
432 assert(state->tos() == state->local(0), "");
433 }
434 for (ciSignatureStream str(method()->signature());
435 !str.at_return_type();
436 str.next()) {
437 state->push_translate(str.type());
438 }
439 // Set the rest of the locals to bottom.
440 assert(state->stack_size() <= 0, "stack size should not be strictly positive");
441 while (state->stack_size() < 0) {
442 state->push(state->bottom_type());
443 }
444 // Lock an object, if necessary.
445 state->set_monitor_count(method()->is_synchronized() ? 1 : 0);
446 return state;
447 }
448
449 // ------------------------------------------------------------------
450 // ciTypeFlow::StateVector::copy_into
451 //
561
562 return different;
563 }
564
565 // ------------------------------------------------------------------
566 // ciTypeFlow::StateVector::push_translate
567 void ciTypeFlow::StateVector::push_translate(ciType* type) {
568 BasicType basic_type = type->basic_type();
569 if (basic_type == T_BOOLEAN || basic_type == T_CHAR ||
570 basic_type == T_BYTE || basic_type == T_SHORT) {
571 push_int();
572 } else {
573 push(type);
574 if (type->is_two_word()) {
575 push(half_type(type));
576 }
577 }
578 }
579
580 // ------------------------------------------------------------------
581 // ciTypeFlow::StateVector::do_aload
582 void ciTypeFlow::StateVector::do_aload(ciBytecodeStream* str) {
583 pop_int();
584 ciArrayKlass* array_klass = pop_objOrFlatArray();
585 if (array_klass == nullptr) {
586 // Did aload on a null reference; push a null and ignore the exception.
587 // This instruction will never continue normally. All we have to do
588 // is report a value that will meet correctly with any downstream
589 // reference types on paths that will truly be executed. This null type
590 // meets with any reference type to yield that same reference type.
591 // (The compiler will generate an unconditional exception here.)
592 push(null_type());
593 return;
594 }
595 if (!array_klass->is_loaded()) {
596 // Only fails for some -Xcomp runs
597 trap(str, array_klass,
598 Deoptimization::make_trap_request
599 (Deoptimization::Reason_unloaded,
600 Deoptimization::Action_reinterpret));
601 return;
602 }
603 ciKlass* element_klass = array_klass->element_klass();
604 // TODO 8350865 Can we check that array_klass is null_free and use mark_as_null_free on the result here?
605 if (!element_klass->is_loaded() && element_klass->is_instance_klass()) {
606 Untested("unloaded array element class in ciTypeFlow");
607 trap(str, element_klass,
608 Deoptimization::make_trap_request
609 (Deoptimization::Reason_unloaded,
610 Deoptimization::Action_reinterpret));
611 } else {
612 push_object(element_klass);
613 }
614 }
615
616
617 // ------------------------------------------------------------------
618 // ciTypeFlow::StateVector::do_checkcast
619 void ciTypeFlow::StateVector::do_checkcast(ciBytecodeStream* str) {
620 bool will_link;
621 ciKlass* klass = str->get_klass(will_link);
622 if (!will_link) {
623 // VM's interpreter will not load 'klass' if object is nullptr.
624 // Type flow after this block may still be needed in two situations:
625 // 1) C2 uses do_null_assert() and continues compilation for later blocks
626 // 2) C2 does an OSR compile in a later block (see bug 4778368).
627 pop_object();
628 do_null_assert(klass);
629 } else {
630 ciType* type = pop_value();
631 type = type->unwrap();
632 if (type->is_loaded() && klass->is_loaded() &&
633 type != klass && type->is_subtype_of(klass)) {
634 // Useless cast, propagate more precise type of object
635 klass = type->as_klass();
636 }
637 push_object(klass);
638 }
639 }
640
641 // ------------------------------------------------------------------
642 // ciTypeFlow::StateVector::do_getfield
643 void ciTypeFlow::StateVector::do_getfield(ciBytecodeStream* str) {
644 // could add assert here for type of object.
645 pop_object();
646 do_getstatic(str);
647 }
648
649 // ------------------------------------------------------------------
650 // ciTypeFlow::StateVector::do_getstatic
651 void ciTypeFlow::StateVector::do_getstatic(ciBytecodeStream* str) {
652 bool will_link;
653 ciField* field = str->get_field(will_link);
654 if (!will_link) {
655 trap(str, field->holder(), str->get_field_holder_index());
656 } else {
657 ciType* field_type = field->type();
658 if (field->is_static() && field->is_null_free() &&
659 !field_type->as_instance_klass()->is_initialized()) {
660 // Deoptimize if we load from a static field with an uninitialized inline type
661 // because we need to throw an exception if initialization of the type failed.
662 trap(str, field_type->as_klass(),
663 Deoptimization::make_trap_request
664 (Deoptimization::Reason_unloaded,
665 Deoptimization::Action_reinterpret));
666 return;
667 } else if (!field_type->is_loaded()) {
668 // Normally, we need the field's type to be loaded if we are to
669 // do anything interesting with its value.
670 // We used to do this: trap(str, str->get_field_signature_index());
671 //
672 // There is one good reason not to trap here. Execution can
673 // get past this "getfield" or "getstatic" if the value of
674 // the field is null. As long as the value is null, the class
675 // does not need to be loaded! The compiler must assume that
676 // the value of the unloaded class reference is null; if the code
677 // ever sees a non-null value, loading has occurred.
678 //
679 // This actually happens often enough to be annoying. If the
680 // compiler throws an uncommon trap at this bytecode, you can
681 // get an endless loop of recompilations, when all the code
682 // needs to do is load a series of null values. Also, a trap
683 // here can make an OSR entry point unreachable, triggering the
684 // assert on non_osr_block in ciTypeFlow::get_start_state.
685 // (See bug 4379915.)
686 do_null_assert(field_type->as_klass());
687 } else {
688 if (field->is_null_free()) {
689 field_type = outer()->mark_as_null_free(field_type);
690 }
691 push_translate(field_type);
692 }
693 }
694 }
695
696 // ------------------------------------------------------------------
697 // ciTypeFlow::StateVector::do_invoke
698 void ciTypeFlow::StateVector::do_invoke(ciBytecodeStream* str,
699 bool has_receiver) {
700 bool will_link;
701 ciSignature* declared_signature = nullptr;
702 ciMethod* callee = str->get_method(will_link, &declared_signature);
703 assert(declared_signature != nullptr, "cannot be null");
704 if (!will_link) {
705 // We weren't able to find the method.
706 if (str->cur_bc() == Bytecodes::_invokedynamic) {
707 trap(str, nullptr,
708 Deoptimization::make_trap_request
709 (Deoptimization::Reason_uninitialized,
710 Deoptimization::Action_reinterpret));
718 // invokehandle).
719 ciSignatureStream sigstr(declared_signature);
720 const int arg_size = declared_signature->size();
721 const int stack_base = stack_size() - arg_size;
722 int i = 0;
723 for( ; !sigstr.at_return_type(); sigstr.next()) {
724 ciType* type = sigstr.type();
725 ciType* stack_type = type_at(stack(stack_base + i++));
726 // Do I want to check this type?
727 // assert(stack_type->is_subtype_of(type), "bad type for field value");
728 if (type->is_two_word()) {
729 ciType* stack_type2 = type_at(stack(stack_base + i++));
730 assert(stack_type2->equals(half_type(type)), "must be 2nd half");
731 }
732 }
733 assert(arg_size == i, "must match");
734 for (int j = 0; j < arg_size; j++) {
735 pop();
736 }
737 if (has_receiver) {
738 if (type_at_tos()->is_early_larval()) {
739 // Call with larval receiver accepted by verifier
740 // => this is <init> and the receiver is no longer larval after that.
741 Cell limit = limit_cell();
742 for (Cell c = start_cell(); c < limit; c = next_cell(c)) {
743 if (type_at(c)->ident() == type_at_tos()->ident()) {
744 assert(type_at(c) == type_at_tos(), "Sin! Abomination!");
745 set_type_at(c, type_at_tos()->unwrap());
746 }
747 }
748 }
749 pop_object();
750 }
751 assert(!sigstr.is_done(), "must have return type");
752 ciType* return_type = sigstr.type();
753 if (!return_type->is_void()) {
754 if (!return_type->is_loaded()) {
755 // As in do_getstatic(), generally speaking, we need the return type to
756 // be loaded if we are to do anything interesting with its value.
757 // We used to do this: trap(str, str->get_method_signature_index());
758 //
759 // We do not trap here since execution can get past this invoke if
760 // the return value is null. As long as the value is null, the class
761 // does not need to be loaded! The compiler must assume that
762 // the value of the unloaded class reference is null; if the code
763 // ever sees a non-null value, loading has occurred.
764 //
765 // See do_getstatic() for similar explanation, as well as bug 4684993.
766 do_null_assert(return_type->as_klass());
767 } else {
768 push_translate(return_type);
784 trap(str, nullptr, Deoptimization::make_trap_request(Deoptimization::Reason_unhandled,
785 Deoptimization::Action_none));
786 return;
787 }
788 ciConstant con = str->get_constant();
789 if (con.is_valid()) {
790 int cp_index = str->get_constant_pool_index();
791 if (!con.is_loaded()) {
792 trap(str, nullptr, Deoptimization::make_trap_request(Deoptimization::Reason_unloaded,
793 Deoptimization::Action_reinterpret,
794 cp_index));
795 return;
796 }
797 BasicType basic_type = str->get_basic_type_for_constant_at(cp_index);
798 if (is_reference_type(basic_type)) {
799 ciObject* obj = con.as_object();
800 if (obj->is_null_object()) {
801 push_null();
802 } else {
803 assert(obj->is_instance() || obj->is_array(), "must be java_mirror of klass");
804 ciType* type = obj->klass();
805 if (type->is_inlinetype()) {
806 type = outer()->mark_as_null_free(type);
807 }
808 push(type);
809 }
810 } else {
811 assert(basic_type == con.basic_type() || con.basic_type() == T_OBJECT,
812 "not a boxed form: %s vs %s", type2name(basic_type), type2name(con.basic_type()));
813 push_translate(ciType::make(basic_type));
814 }
815 } else {
816 // OutOfMemoryError in the CI while loading a String constant.
817 push_null();
818 outer()->record_failure("ldc did not link");
819 }
820 }
821
822 // ------------------------------------------------------------------
823 // ciTypeFlow::StateVector::do_multianewarray
824 void ciTypeFlow::StateVector::do_multianewarray(ciBytecodeStream* str) {
825 int dimensions = str->get_dimensions();
826 bool will_link;
827 ciArrayKlass* array_klass = str->get_klass(will_link)->as_array_klass();
828 if (!will_link) {
829 trap(str, array_klass, str->get_klass_index());
830 } else {
831 for (int i = 0; i < dimensions; i++) {
832 pop_int();
833 }
834 push_object(array_klass);
835 }
836 }
837
838 // ------------------------------------------------------------------
839 // ciTypeFlow::StateVector::do_new
840 void ciTypeFlow::StateVector::do_new(ciBytecodeStream* str) {
841 bool will_link;
842 ciKlass* klass = str->get_klass(will_link);
843 if (!will_link || str->is_unresolved_klass()) {
844 trap(str, klass, str->get_klass_index());
845 } else {
846 if (klass->is_inlinetype()) {
847 push(outer()->mark_as_early_larval(klass));
848 return;
849 }
850 push_object(klass);
851 }
852 }
853
854 // ------------------------------------------------------------------
855 // ciTypeFlow::StateVector::do_newarray
856 void ciTypeFlow::StateVector::do_newarray(ciBytecodeStream* str) {
857 pop_int();
858 ciKlass* klass = ciTypeArrayKlass::make((BasicType)str->get_index());
859 push_object(klass);
860 }
861
862 // ------------------------------------------------------------------
863 // ciTypeFlow::StateVector::do_putfield
864 void ciTypeFlow::StateVector::do_putfield(ciBytecodeStream* str) {
865 do_putstatic(str);
866 if (_trap_bci != -1) return; // unloaded field holder, etc.
867 // could add assert here for type of object.
868 pop_object();
869 }
939 // class later.
940 push_null();
941 }
942 }
943
944
945 // ------------------------------------------------------------------
946 // ciTypeFlow::StateVector::apply_one_bytecode
947 //
948 // Apply the effect of one bytecode to this StateVector
949 bool ciTypeFlow::StateVector::apply_one_bytecode(ciBytecodeStream* str) {
950 _trap_bci = -1;
951 _trap_index = 0;
952
953 if (CITraceTypeFlow) {
954 tty->print_cr(">> Interpreting bytecode %d:%s", str->cur_bci(),
955 Bytecodes::name(str->cur_bc()));
956 }
957
958 switch(str->cur_bc()) {
959 case Bytecodes::_aaload: do_aload(str); break;
960
961 case Bytecodes::_aastore:
962 {
963 pop_object();
964 pop_int();
965 pop_objOrFlatArray();
966 break;
967 }
968 case Bytecodes::_aconst_null:
969 {
970 push_null();
971 break;
972 }
973 case Bytecodes::_aload: load_local_object(str->get_index()); break;
974 case Bytecodes::_aload_0: load_local_object(0); break;
975 case Bytecodes::_aload_1: load_local_object(1); break;
976 case Bytecodes::_aload_2: load_local_object(2); break;
977 case Bytecodes::_aload_3: load_local_object(3); break;
978
979 case Bytecodes::_anewarray:
980 {
981 pop_int();
982 bool will_link;
983 ciKlass* element_klass = str->get_klass(will_link);
984 if (!will_link) {
985 trap(str, element_klass, str->get_klass_index());
986 } else {
987 push_object(ciArrayKlass::make(element_klass));
988 }
989 break;
990 }
991 case Bytecodes::_areturn:
992 case Bytecodes::_ifnonnull:
993 case Bytecodes::_ifnull:
994 {
995 pop_object();
996 break;
997 }
998 case Bytecodes::_monitorenter:
999 {
1000 pop_object();
1001 set_monitor_count(monitor_count() + 1);
1002 break;
1003 }
1004 case Bytecodes::_monitorexit:
1005 {
1006 pop_object();
1007 assert(monitor_count() > 0, "must be a monitor to exit from");
1526 case Bytecodes::_pop2:
1527 {
1528 pop();
1529 pop();
1530 break;
1531 }
1532
1533 case Bytecodes::_putfield: do_putfield(str); break;
1534 case Bytecodes::_putstatic: do_putstatic(str); break;
1535
1536 case Bytecodes::_ret: do_ret(str); break;
1537
1538 case Bytecodes::_swap:
1539 {
1540 ciType* value1 = pop_value();
1541 ciType* value2 = pop_value();
1542 push(value1);
1543 push(value2);
1544 break;
1545 }
1546
1547 case Bytecodes::_wide:
1548 default:
1549 {
1550 // The iterator should skip this.
1551 ShouldNotReachHere();
1552 break;
1553 }
1554 }
1555
1556 if (CITraceTypeFlow) {
1557 print_on(tty);
1558 }
1559
1560 return (_trap_bci != -1);
1561 }
1562
1563 #ifndef PRODUCT
1564 // ------------------------------------------------------------------
1565 // ciTypeFlow::StateVector::print_cell_on
1566 void ciTypeFlow::StateVector::print_cell_on(outputStream* st, Cell c) const {
1567 ciType* type = type_at(c)->unwrap();
1568 if (type == top_type()) {
1569 st->print("top");
1570 } else if (type == bottom_type()) {
1571 st->print("bottom");
1572 } else if (type == null_type()) {
1573 st->print("null");
1574 } else if (type == long2_type()) {
1575 st->print("long2");
1576 } else if (type == double2_type()) {
1577 st->print("double2");
1578 } else if (is_int(type)) {
1579 st->print("int");
1580 } else if (is_long(type)) {
1581 st->print("long");
1582 } else if (is_float(type)) {
1583 st->print("float");
1584 } else if (is_double(type)) {
1585 st->print("double");
1586 } else if (type->is_return_address()) {
1587 st->print("address(%d)", type->as_return_address()->bci());
1810 case Bytecodes::_lookupswitch: {
1811 Bytecode_lookupswitch lookupswitch(str);
1812
1813 int npairs = lookupswitch.number_of_pairs();
1814 _successors =
1815 new (arena) GrowableArray<Block*>(arena, npairs+1, 0, nullptr);
1816 int bci = current_bci + lookupswitch.default_offset();
1817 Block* block = analyzer->block_at(bci, jsrs);
1818 assert(_successors->length() == SWITCH_DEFAULT, "");
1819 _successors->append(block);
1820 while(--npairs >= 0) {
1821 LookupswitchPair pair = lookupswitch.pair_at(npairs);
1822 int bci = current_bci + pair.offset();
1823 Block* block = analyzer->block_at(bci, jsrs);
1824 assert(_successors->length() >= SWITCH_CASES, "");
1825 _successors->append_if_missing(block);
1826 }
1827 break;
1828 }
1829
1830 case Bytecodes::_athrow:
1831 case Bytecodes::_ireturn:
1832 case Bytecodes::_lreturn:
1833 case Bytecodes::_freturn:
1834 case Bytecodes::_dreturn:
1835 case Bytecodes::_areturn:
1836 case Bytecodes::_return:
1837 _successors =
1838 new (arena) GrowableArray<Block*>(arena, 1, 0, nullptr);
1839 // No successors
1840 break;
1841
1842 case Bytecodes::_ret: {
1843 _successors =
1844 new (arena) GrowableArray<Block*>(arena, 1, 0, nullptr);
1845
1846 Cell local = state->local(str->get_index());
1847 ciType* return_address = state->type_at(local);
1848 assert(return_address->is_return_address(), "verify: wrong type");
1849 int bci = return_address->as_return_address()->bci();
1850 assert(_successors->length() == GOTO_TARGET, "");
1851 _successors->append(analyzer->block_at(bci, jsrs));
1852 break;
1853 }
1854
1855 case Bytecodes::_wide:
3208
3209 // ------------------------------------------------------------------
3210 // ciTypeFlow::record_failure()
3211 // The ciTypeFlow object keeps track of failure reasons separately from the ciEnv.
3212 // This is required because there is not a 1-1 relation between the ciEnv and
3213 // the TypeFlow passes within a compilation task. For example, if the compiler
3214 // is considering inlining a method, it will request a TypeFlow. If that fails,
3215 // the compilation as a whole may continue without the inlining. Some TypeFlow
3216 // requests are not optional; if they fail the requestor is responsible for
3217 // copying the failure reason up to the ciEnv. (See Parse::Parse.)
3218 void ciTypeFlow::record_failure(const char* reason) {
3219 if (env()->log() != nullptr) {
3220 env()->log()->elem("failure reason='%s' phase='typeflow'", reason);
3221 }
3222 if (_failure_reason == nullptr) {
3223 // Record the first failure reason.
3224 _failure_reason = reason;
3225 }
3226 }
3227
3228 ciType* ciTypeFlow::mark_as_early_larval(ciType* type) {
3229 // Wrap the type to carry the information that it is null-free
3230 return env()->make_early_larval_wrapper(type);
3231 }
3232
3233
3234 ciType* ciTypeFlow::mark_as_null_free(ciType* type) {
3235 // Wrap the type to carry the information that it is null-free
3236 return env()->make_null_free_wrapper(type);
3237 }
3238
3239 #ifndef PRODUCT
3240 void ciTypeFlow::print() const { print_on(tty); }
3241
3242 // ------------------------------------------------------------------
3243 // ciTypeFlow::print_on
3244 void ciTypeFlow::print_on(outputStream* st) const {
3245 // Walk through CI blocks
3246 st->print_cr("********************************************************");
3247 st->print ("TypeFlow for ");
3248 method()->name()->print_symbol_on(st);
3249 int limit_bci = code_size();
3250 st->print_cr(" %d bytes", limit_bci);
3251 ciMethodBlocks* mblks = _method->get_method_blocks();
3252 ciBlock* current = nullptr;
3253 for (int bci = 0; bci < limit_bci; bci++) {
3254 ciBlock* blk = mblks->block_containing(bci);
3255 if (blk != nullptr && blk != current) {
3256 current = blk;
3257 current->print_on(st);
3258
|