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 "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
257 // ciTypeFlow::StateVector::type_meet
258 //
259 // Meet two types.
260 //
261 // The semi-lattice of types use by this analysis are modeled on those
262 // of the verifier. The lattice is as follows:
263 //
264 // top_type() >= all non-extremal types >= bottom_type
265 // and
266 // Every primitive type is comparable only with itself. The meet of
267 // reference types is determined by their kind: instance class,
268 // interface, or array class. The meet of two types of the same
269 // kind is their least common ancestor. The meet of two types of
270 // different kinds is always java.lang.Object.
271 ciType* ciTypeFlow::StateVector::type_meet_internal(ciType* t1, ciType* t2, ciTypeFlow* analyzer) {
272 assert(t1 != t2, "checked in caller");
273 if (t1->equals(top_type())) {
274 return t2;
275 } else if (t2->equals(top_type())) {
276 return t1;
277 } else if (t1->is_primitive_type() || t2->is_primitive_type()) {
278 // Special case null_type. null_type meet any reference type T
279 // is T. null_type meet null_type is null_type.
280 if (t1->equals(null_type())) {
281 if (!t2->is_primitive_type() || t2->equals(null_type())) {
282 return t2;
283 }
284 } else if (t2->equals(null_type())) {
285 if (!t1->is_primitive_type()) {
286 return t1;
287 }
288 }
289
290 // At least one of the two types is a non-top primitive type.
291 // The other type is not equal to it. Fall to bottom.
292 return bottom_type();
293 } else {
294 // Both types are non-top non-primitive types. That is,
295 // both types are either instanceKlasses or arrayKlasses.
296 ciKlass* object_klass = analyzer->env()->Object_klass();
297 ciKlass* k1 = t1->as_klass();
298 ciKlass* k2 = t2->as_klass();
299 if (k1->equals(object_klass) || k2->equals(object_klass)) {
300 return object_klass;
301 } else if (!k1->is_loaded() || !k2->is_loaded()) {
302 // Unloaded classes fall to java.lang.Object at a merge.
303 return object_klass;
304 } else if (k1->is_interface() != k2->is_interface()) {
305 // When an interface meets a non-interface, we get Object;
306 // This is what the verifier does.
307 return object_klass;
308 } else if (k1->is_array_klass() || k2->is_array_klass()) {
309 // When an array meets a non-array, we get Object.
310 // When objArray meets typeArray, we also get Object.
311 // And when typeArray meets different typeArray, we again get Object.
312 // But when objArray meets objArray, we look carefully at element types.
313 if (k1->is_obj_array_klass() && k2->is_obj_array_klass()) {
314 // Meet the element types, then construct the corresponding array type.
315 ciKlass* elem1 = k1->as_obj_array_klass()->element_klass();
316 ciKlass* elem2 = k2->as_obj_array_klass()->element_klass();
317 ciKlass* elem = type_meet_internal(elem1, elem2, analyzer)->as_klass();
318 // Do an easy shortcut if one type is a super of the other.
319 if (elem == elem1) {
320 assert(k1 == ciObjArrayKlass::make(elem), "shortcut is OK");
321 return k1;
322 } else if (elem == elem2) {
323 assert(k2 == ciObjArrayKlass::make(elem), "shortcut is OK");
324 return k2;
325 } else {
326 return ciObjArrayKlass::make(elem);
327 }
328 } else {
329 return object_klass;
330 }
331 } else {
332 // Must be two plain old instance klasses.
333 assert(k1->is_instance_klass(), "previous cases handle non-instances");
334 assert(k2->is_instance_klass(), "previous cases handle non-instances");
335 return k1->least_common_ancestor(k2);
336 }
337 }
338 }
339
340
341 // ------------------------------------------------------------------
342 // ciTypeFlow::StateVector::StateVector
343 //
344 // Build a new state vector
345 ciTypeFlow::StateVector::StateVector(ciTypeFlow* analyzer) {
346 _outer = analyzer;
347 _stack_size = -1;
348 _monitor_count = -1;
349 // Allocate the _types array
350 int max_cells = analyzer->max_cells();
351 _types = (ciType**)analyzer->arena()->Amalloc(sizeof(ciType*) * max_cells);
352 for (int i=0; i<max_cells; i++) {
353 _types[i] = top_type();
354 }
355 _trap_bci = -1;
356 _trap_index = 0;
378 }
379 // load up the non-OSR state at this point
380 non_osr_block->copy_state_into(state);
381 int non_osr_start = non_osr_block->start();
382 if (non_osr_start != start_bci()) {
383 // must flow forward from it
384 if (CITraceTypeFlow) {
385 tty->print_cr(">> Interpreting pre-OSR block %d:", non_osr_start);
386 }
387 Block* block = block_at(non_osr_start, jsrs);
388 assert(block->limit() == start_bci(), "must flow forward to start");
389 flow_block(block, state, jsrs);
390 }
391 return state;
392 // Note: The code below would be an incorrect for an OSR flow,
393 // even if it were possible for an OSR entry point to be at bci zero.
394 }
395 // "Push" the method signature into the first few locals.
396 state->set_stack_size(-max_locals());
397 if (!method()->is_static()) {
398 state->push(method()->holder());
399 assert(state->tos() == state->local(0), "");
400 }
401 for (ciSignatureStream str(method()->signature());
402 !str.at_return_type();
403 str.next()) {
404 state->push_translate(str.type());
405 }
406 // Set the rest of the locals to bottom.
407 Cell cell = state->next_cell(state->tos());
408 state->set_stack_size(0);
409 int limit = state->limit_cell();
410 for (; cell < limit; cell = state->next_cell(cell)) {
411 state->set_type_at(cell, state->bottom_type());
412 }
413 // Lock an object, if necessary.
414 state->set_monitor_count(method()->is_synchronized() ? 1 : 0);
415 return state;
416 }
417
418 // ------------------------------------------------------------------
419 // ciTypeFlow::StateVector::copy_into
420 //
421 // Copy our value into some other StateVector
422 void ciTypeFlow::StateVector::copy_into(ciTypeFlow::StateVector* copy)
423 const {
424 copy->set_stack_size(stack_size());
530
531 return different;
532 }
533
534 // ------------------------------------------------------------------
535 // ciTypeFlow::StateVector::push_translate
536 void ciTypeFlow::StateVector::push_translate(ciType* type) {
537 BasicType basic_type = type->basic_type();
538 if (basic_type == T_BOOLEAN || basic_type == T_CHAR ||
539 basic_type == T_BYTE || basic_type == T_SHORT) {
540 push_int();
541 } else {
542 push(type);
543 if (type->is_two_word()) {
544 push(half_type(type));
545 }
546 }
547 }
548
549 // ------------------------------------------------------------------
550 // ciTypeFlow::StateVector::do_aaload
551 void ciTypeFlow::StateVector::do_aaload(ciBytecodeStream* str) {
552 pop_int();
553 ciObjArrayKlass* array_klass = pop_objArray();
554 if (array_klass == nullptr) {
555 // Did aaload on a null reference; push a null and ignore the exception.
556 // This instruction will never continue normally. All we have to do
557 // is report a value that will meet correctly with any downstream
558 // reference types on paths that will truly be executed. This null type
559 // meets with any reference type to yield that same reference type.
560 // (The compiler will generate an unconditional exception here.)
561 push(null_type());
562 return;
563 }
564 if (!array_klass->is_loaded()) {
565 // Only fails for some -Xcomp runs
566 trap(str, array_klass,
567 Deoptimization::make_trap_request
568 (Deoptimization::Reason_unloaded,
569 Deoptimization::Action_reinterpret));
570 return;
571 }
572 ciKlass* element_klass = array_klass->element_klass();
573 if (!element_klass->is_loaded() && element_klass->is_instance_klass()) {
574 Untested("unloaded array element class in ciTypeFlow");
575 trap(str, element_klass,
576 Deoptimization::make_trap_request
577 (Deoptimization::Reason_unloaded,
578 Deoptimization::Action_reinterpret));
579 } else {
580 push_object(element_klass);
581 }
582 }
583
584
585 // ------------------------------------------------------------------
586 // ciTypeFlow::StateVector::do_checkcast
587 void ciTypeFlow::StateVector::do_checkcast(ciBytecodeStream* str) {
588 bool will_link;
589 ciKlass* klass = str->get_klass(will_link);
590 if (!will_link) {
591 // VM's interpreter will not load 'klass' if object is null.
592 // Type flow after this block may still be needed in two situations:
593 // 1) C2 uses do_null_assert() and continues compilation for later blocks
594 // 2) C2 does an OSR compile in a later block (see bug 4778368).
595 pop_object();
596 do_null_assert(klass);
597 } else {
598 pop_object();
599 push_object(klass);
600 }
601 }
602
603 // ------------------------------------------------------------------
604 // ciTypeFlow::StateVector::do_getfield
605 void ciTypeFlow::StateVector::do_getfield(ciBytecodeStream* str) {
606 // could add assert here for type of object.
607 pop_object();
608 do_getstatic(str);
609 }
610
611 // ------------------------------------------------------------------
612 // ciTypeFlow::StateVector::do_getstatic
613 void ciTypeFlow::StateVector::do_getstatic(ciBytecodeStream* str) {
614 bool will_link;
615 ciField* field = str->get_field(will_link);
616 if (!will_link) {
617 trap(str, field->holder(), str->get_field_holder_index());
618 } else {
619 ciType* field_type = field->type();
620 if (!field_type->is_loaded()) {
621 // Normally, we need the field's type to be loaded if we are to
622 // do anything interesting with its value.
623 // We used to do this: trap(str, str->get_field_signature_index());
624 //
625 // There is one good reason not to trap here. Execution can
626 // get past this "getfield" or "getstatic" if the value of
627 // the field is null. As long as the value is null, the class
628 // does not need to be loaded! The compiler must assume that
629 // the value of the unloaded class reference is null; if the code
630 // ever sees a non-null value, loading has occurred.
631 //
632 // This actually happens often enough to be annoying. If the
633 // compiler throws an uncommon trap at this bytecode, you can
634 // get an endless loop of recompilations, when all the code
635 // needs to do is load a series of null values. Also, a trap
636 // here can make an OSR entry point unreachable, triggering the
637 // assert on non_osr_block in ciTypeFlow::get_start_state.
638 // (See bug 4379915.)
639 do_null_assert(field_type->as_klass());
640 } else {
641 push_translate(field_type);
642 }
643 }
644 }
645
646 // ------------------------------------------------------------------
647 // ciTypeFlow::StateVector::do_invoke
648 void ciTypeFlow::StateVector::do_invoke(ciBytecodeStream* str,
649 bool has_receiver) {
650 bool will_link;
651 ciSignature* declared_signature = nullptr;
652 ciMethod* callee = str->get_method(will_link, &declared_signature);
653 assert(declared_signature != nullptr, "cannot be null");
654 if (!will_link) {
655 // We weren't able to find the method.
656 if (str->cur_bc() == Bytecodes::_invokedynamic) {
657 trap(str, nullptr,
658 Deoptimization::make_trap_request
659 (Deoptimization::Reason_uninitialized,
660 Deoptimization::Action_reinterpret));
686 }
687 if (has_receiver) {
688 // Check this?
689 pop_object();
690 }
691 assert(!sigstr.is_done(), "must have return type");
692 ciType* return_type = sigstr.type();
693 if (!return_type->is_void()) {
694 if (!return_type->is_loaded()) {
695 // As in do_getstatic(), generally speaking, we need the return type to
696 // be loaded if we are to do anything interesting with its value.
697 // We used to do this: trap(str, str->get_method_signature_index());
698 //
699 // We do not trap here since execution can get past this invoke if
700 // the return value is null. As long as the value is null, the class
701 // does not need to be loaded! The compiler must assume that
702 // the value of the unloaded class reference is null; if the code
703 // ever sees a non-null value, loading has occurred.
704 //
705 // See do_getstatic() for similar explanation, as well as bug 4684993.
706 do_null_assert(return_type->as_klass());
707 } else {
708 push_translate(return_type);
709 }
710 }
711 }
712 }
713
714 // ------------------------------------------------------------------
715 // ciTypeFlow::StateVector::do_jsr
716 void ciTypeFlow::StateVector::do_jsr(ciBytecodeStream* str) {
717 push(ciReturnAddress::make(str->next_bci()));
718 }
719
720 // ------------------------------------------------------------------
721 // ciTypeFlow::StateVector::do_ldc
722 void ciTypeFlow::StateVector::do_ldc(ciBytecodeStream* str) {
723 if (str->is_in_error()) {
724 trap(str, nullptr, Deoptimization::make_trap_request(Deoptimization::Reason_unhandled,
725 Deoptimization::Action_none));
726 return;
727 }
728 ciConstant con = str->get_constant();
729 if (con.is_valid()) {
730 int cp_index = str->get_constant_pool_index();
731 BasicType basic_type = str->get_basic_type_for_constant_at(cp_index);
732 if (is_reference_type(basic_type)) {
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 assert(basic_type == con.basic_type() || con.basic_type() == T_OBJECT,
742 "not a boxed form: %s vs %s", type2name(basic_type), type2name(con.basic_type()));
743 push_translate(ciType::make(basic_type));
744 }
745 } else {
746 // OutOfMemoryError in the CI while loading a String constant.
747 push_null();
748 outer()->record_failure("ldc did not link");
749 }
750 }
751
752 // ------------------------------------------------------------------
753 // ciTypeFlow::StateVector::do_multianewarray
754 void ciTypeFlow::StateVector::do_multianewarray(ciBytecodeStream* str) {
755 int dimensions = str->get_dimensions();
756 bool will_link;
757 ciArrayKlass* array_klass = str->get_klass(will_link)->as_array_klass();
758 if (!will_link) {
759 trap(str, array_klass, str->get_klass_index());
760 } else {
761 for (int i = 0; i < dimensions; i++) {
762 pop_int();
763 }
764 push_object(array_klass);
765 }
766 }
767
768 // ------------------------------------------------------------------
769 // ciTypeFlow::StateVector::do_new
770 void ciTypeFlow::StateVector::do_new(ciBytecodeStream* str) {
771 bool will_link;
772 ciKlass* klass = str->get_klass(will_link);
773 if (!will_link || str->is_unresolved_klass()) {
774 trap(str, klass, str->get_klass_index());
775 } else {
776 push_object(klass);
777 }
778 }
779
780 // ------------------------------------------------------------------
781 // ciTypeFlow::StateVector::do_newarray
782 void ciTypeFlow::StateVector::do_newarray(ciBytecodeStream* str) {
783 pop_int();
784 ciKlass* klass = ciTypeArrayKlass::make((BasicType)str->get_index());
785 push_object(klass);
786 }
787
788 // ------------------------------------------------------------------
789 // ciTypeFlow::StateVector::do_putfield
790 void ciTypeFlow::StateVector::do_putfield(ciBytecodeStream* str) {
791 do_putstatic(str);
792 if (_trap_bci != -1) return; // unloaded field holder, etc.
793 // could add assert here for type of object.
794 pop_object();
795 }
796
797 // ------------------------------------------------------------------
798 // ciTypeFlow::StateVector::do_putstatic
799 void ciTypeFlow::StateVector::do_putstatic(ciBytecodeStream* str) {
865 // class later.
866 push_null();
867 }
868 }
869
870
871 // ------------------------------------------------------------------
872 // ciTypeFlow::StateVector::apply_one_bytecode
873 //
874 // Apply the effect of one bytecode to this StateVector
875 bool ciTypeFlow::StateVector::apply_one_bytecode(ciBytecodeStream* str) {
876 _trap_bci = -1;
877 _trap_index = 0;
878
879 if (CITraceTypeFlow) {
880 tty->print_cr(">> Interpreting bytecode %d:%s", str->cur_bci(),
881 Bytecodes::name(str->cur_bc()));
882 }
883
884 switch(str->cur_bc()) {
885 case Bytecodes::_aaload: do_aaload(str); break;
886
887 case Bytecodes::_aastore:
888 {
889 pop_object();
890 pop_int();
891 pop_objArray();
892 break;
893 }
894 case Bytecodes::_aconst_null:
895 {
896 push_null();
897 break;
898 }
899 case Bytecodes::_aload: load_local_object(str->get_index()); break;
900 case Bytecodes::_aload_0: load_local_object(0); break;
901 case Bytecodes::_aload_1: load_local_object(1); break;
902 case Bytecodes::_aload_2: load_local_object(2); break;
903 case Bytecodes::_aload_3: load_local_object(3); break;
904
905 case Bytecodes::_anewarray:
906 {
907 pop_int();
908 bool will_link;
909 ciKlass* element_klass = str->get_klass(will_link);
910 if (!will_link) {
911 trap(str, element_klass, str->get_klass_index());
912 } else {
913 push_object(ciObjArrayKlass::make(element_klass));
914 }
915 break;
916 }
917 case Bytecodes::_areturn:
918 case Bytecodes::_ifnonnull:
919 case Bytecodes::_ifnull:
920 {
921 pop_object();
922 break;
923 }
924 case Bytecodes::_monitorenter:
925 {
926 pop_object();
927 set_monitor_count(monitor_count() + 1);
928 break;
929 }
930 case Bytecodes::_monitorexit:
931 {
932 pop_object();
933 assert(monitor_count() > 0, "must be a monitor to exit from");
1425 }
1426 case Bytecodes::_lshl:
1427 case Bytecodes::_lshr:
1428 case Bytecodes::_lushr:
1429 {
1430 pop_int();
1431 pop_long();
1432 push_long();
1433 break;
1434 }
1435 case Bytecodes::_lstore: store_local_long(str->get_index()); break;
1436 case Bytecodes::_lstore_0: store_local_long(0); break;
1437 case Bytecodes::_lstore_1: store_local_long(1); break;
1438 case Bytecodes::_lstore_2: store_local_long(2); break;
1439 case Bytecodes::_lstore_3: store_local_long(3); break;
1440
1441 case Bytecodes::_multianewarray: do_multianewarray(str); break;
1442
1443 case Bytecodes::_new: do_new(str); break;
1444
1445 case Bytecodes::_newarray: do_newarray(str); break;
1446
1447 case Bytecodes::_pop:
1448 {
1449 pop();
1450 break;
1451 }
1452 case Bytecodes::_pop2:
1453 {
1454 pop();
1455 pop();
1456 break;
1457 }
1458
1459 case Bytecodes::_putfield: do_putfield(str); break;
1460 case Bytecodes::_putstatic: do_putstatic(str); break;
1461
1462 case Bytecodes::_ret: do_ret(str); break;
1463
1464 case Bytecodes::_swap:
1465 {
1466 ciType* value1 = pop_value();
1467 ciType* value2 = pop_value();
1468 push(value1);
1469 push(value2);
1470 break;
1471 }
1472 case Bytecodes::_wide:
1473 default:
1474 {
1475 // The iterator should skip this.
1476 ShouldNotReachHere();
1477 break;
1478 }
1479 }
1480
1481 if (CITraceTypeFlow) {
1482 print_on(tty);
1483 }
1484
1485 return (_trap_bci != -1);
1486 }
1487
1488 #ifndef PRODUCT
1489 // ------------------------------------------------------------------
1490 // ciTypeFlow::StateVector::print_cell_on
1491 void ciTypeFlow::StateVector::print_cell_on(outputStream* st, Cell c) const {
1492 ciType* type = type_at(c);
1493 if (type == top_type()) {
1494 st->print("top");
1495 } else if (type == bottom_type()) {
1496 st->print("bottom");
1497 } else if (type == null_type()) {
1498 st->print("null");
1499 } else if (type == long2_type()) {
1500 st->print("long2");
1501 } else if (type == double2_type()) {
1502 st->print("double2");
1503 } else if (is_int(type)) {
1504 st->print("int");
1505 } else if (is_long(type)) {
1506 st->print("long");
1507 } else if (is_float(type)) {
1508 st->print("float");
1509 } else if (is_double(type)) {
1510 st->print("double");
1511 } else if (type->is_return_address()) {
1512 st->print("address(%d)", type->as_return_address()->bci());
1735 case Bytecodes::_lookupswitch: {
1736 Bytecode_lookupswitch lookupswitch(str);
1737
1738 int npairs = lookupswitch.number_of_pairs();
1739 _successors =
1740 new (arena) GrowableArray<Block*>(arena, npairs+1, 0, nullptr);
1741 int bci = current_bci + lookupswitch.default_offset();
1742 Block* block = analyzer->block_at(bci, jsrs);
1743 assert(_successors->length() == SWITCH_DEFAULT, "");
1744 _successors->append(block);
1745 while(--npairs >= 0) {
1746 LookupswitchPair pair = lookupswitch.pair_at(npairs);
1747 int bci = current_bci + pair.offset();
1748 Block* block = analyzer->block_at(bci, jsrs);
1749 assert(_successors->length() >= SWITCH_CASES, "");
1750 _successors->append_if_missing(block);
1751 }
1752 break;
1753 }
1754
1755 case Bytecodes::_athrow: case Bytecodes::_ireturn:
1756 case Bytecodes::_lreturn: case Bytecodes::_freturn:
1757 case Bytecodes::_dreturn: case Bytecodes::_areturn:
1758 case Bytecodes::_return:
1759 _successors =
1760 new (arena) GrowableArray<Block*>(arena, 1, 0, nullptr);
1761 // No successors
1762 break;
1763
1764 case Bytecodes::_ret: {
1765 _successors =
1766 new (arena) GrowableArray<Block*>(arena, 1, 0, nullptr);
1767
1768 Cell local = state->local(str->get_index());
1769 ciType* return_address = state->type_at(local);
1770 assert(return_address->is_return_address(), "verify: wrong type");
1771 int bci = return_address->as_return_address()->bci();
1772 assert(_successors->length() == GOTO_TARGET, "");
1773 _successors->append(analyzer->block_at(bci, jsrs));
1774 break;
1775 }
1776
1777 case Bytecodes::_wide:
3131
3132 // ------------------------------------------------------------------
3133 // ciTypeFlow::record_failure()
3134 // The ciTypeFlow object keeps track of failure reasons separately from the ciEnv.
3135 // This is required because there is not a 1-1 relation between the ciEnv and
3136 // the TypeFlow passes within a compilation task. For example, if the compiler
3137 // is considering inlining a method, it will request a TypeFlow. If that fails,
3138 // the compilation as a whole may continue without the inlining. Some TypeFlow
3139 // requests are not optional; if they fail the requestor is responsible for
3140 // copying the failure reason up to the ciEnv. (See Parse::Parse.)
3141 void ciTypeFlow::record_failure(const char* reason) {
3142 if (env()->log() != nullptr) {
3143 env()->log()->elem("failure reason='%s' phase='typeflow'", reason);
3144 }
3145 if (_failure_reason == nullptr) {
3146 // Record the first failure reason.
3147 _failure_reason = reason;
3148 }
3149 }
3150
3151 #ifndef PRODUCT
3152 void ciTypeFlow::print() const { print_on(tty); }
3153
3154 // ------------------------------------------------------------------
3155 // ciTypeFlow::print_on
3156 void ciTypeFlow::print_on(outputStream* st) const {
3157 // Walk through CI blocks
3158 st->print_cr("********************************************************");
3159 st->print ("TypeFlow for ");
3160 method()->name()->print_symbol_on(st);
3161 int limit_bci = code_size();
3162 st->print_cr(" %d bytes", limit_bci);
3163 ciMethodBlocks* mblks = _method->get_method_blocks();
3164 ciBlock* current = nullptr;
3165 for (int bci = 0; bci < limit_bci; bci++) {
3166 ciBlock* blk = mblks->block_containing(bci);
3167 if (blk != nullptr && blk != current) {
3168 current = blk;
3169 current->print_on(st);
3170
|
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 "precompiled.hpp"
26 #include "ci/ciConstant.hpp"
27 #include "ci/ciField.hpp"
28 #include "ci/ciInlineKlass.hpp"
29 #include "ci/ciMethod.hpp"
30 #include "ci/ciMethodData.hpp"
31 #include "ci/ciObjArrayKlass.hpp"
32 #include "ci/ciStreams.hpp"
33 #include "ci/ciTypeArrayKlass.hpp"
34 #include "ci/ciTypeFlow.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
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 }
279 // Unwrap after saving nullness information and handling top meets
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 bool null_free = k1->as_array_klass()->is_elem_null_free() &&
328 k2->as_array_klass()->is_elem_null_free();
329 ciType* elem1 = k1->as_array_klass()->element_klass();
330 ciType* elem2 = k2->as_array_klass()->element_klass();
331 ciType* elem = elem1;
332 if (elem1 != elem2) {
333 elem = type_meet_internal(elem1, elem2, analyzer)->as_klass();
334 }
335 // Do an easy shortcut if one type is a super of the other.
336 if (elem == elem1 && !elem->is_inlinetype()) {
337 assert(k1 == ciArrayKlass::make(elem, null_free), "shortcut is OK");
338 return k1;
339 } else if (elem == elem2 && !elem->is_inlinetype()) {
340 assert(k2 == ciArrayKlass::make(elem, null_free), "shortcut is OK");
341 return k2;
342 } else {
343 return ciArrayKlass::make(elem, null_free);
344 }
345 } else {
346 return object_klass;
347 }
348 } else {
349 // Must be two plain old instance klasses.
350 assert(k1->is_instance_klass(), "previous cases handle non-instances");
351 assert(k2->is_instance_klass(), "previous cases handle non-instances");
352 ciType* result = k1->least_common_ancestor(k2);
353 if (null_free1 && null_free2 && result->is_inlinetype()) {
354 result = analyzer->mark_as_null_free(result);
355 }
356 return result;
357 }
358 }
359
360
361 // ------------------------------------------------------------------
362 // ciTypeFlow::StateVector::StateVector
363 //
364 // Build a new state vector
365 ciTypeFlow::StateVector::StateVector(ciTypeFlow* analyzer) {
366 _outer = analyzer;
367 _stack_size = -1;
368 _monitor_count = -1;
369 // Allocate the _types array
370 int max_cells = analyzer->max_cells();
371 _types = (ciType**)analyzer->arena()->Amalloc(sizeof(ciType*) * max_cells);
372 for (int i=0; i<max_cells; i++) {
373 _types[i] = top_type();
374 }
375 _trap_bci = -1;
376 _trap_index = 0;
398 }
399 // load up the non-OSR state at this point
400 non_osr_block->copy_state_into(state);
401 int non_osr_start = non_osr_block->start();
402 if (non_osr_start != start_bci()) {
403 // must flow forward from it
404 if (CITraceTypeFlow) {
405 tty->print_cr(">> Interpreting pre-OSR block %d:", non_osr_start);
406 }
407 Block* block = block_at(non_osr_start, jsrs);
408 assert(block->limit() == start_bci(), "must flow forward to start");
409 flow_block(block, state, jsrs);
410 }
411 return state;
412 // Note: The code below would be an incorrect for an OSR flow,
413 // even if it were possible for an OSR entry point to be at bci zero.
414 }
415 // "Push" the method signature into the first few locals.
416 state->set_stack_size(-max_locals());
417 if (!method()->is_static()) {
418 ciType* holder = method()->holder();
419 if (holder->is_inlinetype()) {
420 // The receiver is null-free
421 holder = mark_as_null_free(holder);
422 }
423 state->push(holder);
424 assert(state->tos() == state->local(0), "");
425 }
426 for (ciSignatureStream str(method()->signature());
427 !str.at_return_type();
428 str.next()) {
429 ciType* arg = str.type();
430 if (str.is_null_free()) {
431 arg = mark_as_null_free(arg);
432 }
433 state->push_translate(arg);
434 }
435 // Set the rest of the locals to bottom.
436 Cell cell = state->next_cell(state->tos());
437 state->set_stack_size(0);
438 int limit = state->limit_cell();
439 for (; cell < limit; cell = state->next_cell(cell)) {
440 state->set_type_at(cell, state->bottom_type());
441 }
442 // Lock an object, if necessary.
443 state->set_monitor_count(method()->is_synchronized() ? 1 : 0);
444 return state;
445 }
446
447 // ------------------------------------------------------------------
448 // ciTypeFlow::StateVector::copy_into
449 //
450 // Copy our value into some other StateVector
451 void ciTypeFlow::StateVector::copy_into(ciTypeFlow::StateVector* copy)
452 const {
453 copy->set_stack_size(stack_size());
559
560 return different;
561 }
562
563 // ------------------------------------------------------------------
564 // ciTypeFlow::StateVector::push_translate
565 void ciTypeFlow::StateVector::push_translate(ciType* type) {
566 BasicType basic_type = type->basic_type();
567 if (basic_type == T_BOOLEAN || basic_type == T_CHAR ||
568 basic_type == T_BYTE || basic_type == T_SHORT) {
569 push_int();
570 } else {
571 push(type);
572 if (type->is_two_word()) {
573 push(half_type(type));
574 }
575 }
576 }
577
578 // ------------------------------------------------------------------
579 // ciTypeFlow::StateVector::do_aload
580 void ciTypeFlow::StateVector::do_aload(ciBytecodeStream* str) {
581 pop_int();
582 ciArrayKlass* array_klass = pop_objOrFlatArray();
583 if (array_klass == nullptr) {
584 // Did aload on a null reference; push a null and ignore the exception.
585 // This instruction will never continue normally. All we have to do
586 // is report a value that will meet correctly with any downstream
587 // reference types on paths that will truly be executed. This null type
588 // meets with any reference type to yield that same reference type.
589 // (The compiler will generate an unconditional exception here.)
590 push(null_type());
591 return;
592 }
593 if (!array_klass->is_loaded()) {
594 // Only fails for some -Xcomp runs
595 trap(str, array_klass,
596 Deoptimization::make_trap_request
597 (Deoptimization::Reason_unloaded,
598 Deoptimization::Action_reinterpret));
599 return;
600 }
601 ciKlass* element_klass = array_klass->element_klass();
602 if (!element_klass->is_loaded() && element_klass->is_instance_klass()) {
603 Untested("unloaded array element class in ciTypeFlow");
604 trap(str, element_klass,
605 Deoptimization::make_trap_request
606 (Deoptimization::Reason_unloaded,
607 Deoptimization::Action_reinterpret));
608 } else {
609 if (array_klass->is_elem_null_free()) {
610 push(outer()->mark_as_null_free(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 bool null_free = str->has_Q_signature();
624 if (!will_link) {
625 if (null_free) {
626 trap(str, klass,
627 Deoptimization::make_trap_request
628 (Deoptimization::Reason_unloaded,
629 Deoptimization::Action_reinterpret));
630 } else {
631 // VM's interpreter will not load 'klass' if object is nullptr.
632 // Type flow after this block may still be needed in two situations:
633 // 1) C2 uses do_null_assert() and continues compilation for later blocks
634 // 2) C2 does an OSR compile in a later block (see bug 4778368).
635 pop_object();
636 do_null_assert(klass);
637 }
638 } else {
639 ciType* type = pop_value();
640 null_free |= type->is_null_free();
641 type = type->unwrap();
642 if (type->is_loaded() && klass->is_loaded() &&
643 type != klass && type->is_subtype_of(klass)) {
644 // Useless cast, propagate more precise type of object
645 klass = type->as_klass();
646 }
647 if (klass->is_inlinetype() && null_free) {
648 push(outer()->mark_as_null_free(klass));
649 } else {
650 push_object(klass);
651 }
652 }
653 }
654
655 // ------------------------------------------------------------------
656 // ciTypeFlow::StateVector::do_getfield
657 void ciTypeFlow::StateVector::do_getfield(ciBytecodeStream* str) {
658 // could add assert here for type of object.
659 pop_object();
660 do_getstatic(str);
661 }
662
663 // ------------------------------------------------------------------
664 // ciTypeFlow::StateVector::do_getstatic
665 void ciTypeFlow::StateVector::do_getstatic(ciBytecodeStream* str) {
666 bool will_link;
667 ciField* field = str->get_field(will_link);
668 if (!will_link) {
669 trap(str, field->holder(), str->get_field_holder_index());
670 } else {
671 ciType* field_type = field->type();
672 if (field->is_static() && field->is_null_free() &&
673 !field_type->as_instance_klass()->is_initialized()) {
674 // Deoptimize if we load from a static field with an uninitialized inline type
675 // because we need to throw an exception if initialization of the type failed.
676 trap(str, field_type->as_klass(),
677 Deoptimization::make_trap_request
678 (Deoptimization::Reason_unloaded,
679 Deoptimization::Action_reinterpret));
680 return;
681 } else if (!field_type->is_loaded()) {
682 // Normally, we need the field's type to be loaded if we are to
683 // do anything interesting with its value.
684 // We used to do this: trap(str, str->get_field_signature_index());
685 //
686 // There is one good reason not to trap here. Execution can
687 // get past this "getfield" or "getstatic" if the value of
688 // the field is null. As long as the value is null, the class
689 // does not need to be loaded! The compiler must assume that
690 // the value of the unloaded class reference is null; if the code
691 // ever sees a non-null value, loading has occurred.
692 //
693 // This actually happens often enough to be annoying. If the
694 // compiler throws an uncommon trap at this bytecode, you can
695 // get an endless loop of recompilations, when all the code
696 // needs to do is load a series of null values. Also, a trap
697 // here can make an OSR entry point unreachable, triggering the
698 // assert on non_osr_block in ciTypeFlow::get_start_state.
699 // (See bug 4379915.)
700 do_null_assert(field_type->as_klass());
701 } else {
702 if (field->is_null_free()) {
703 field_type = outer()->mark_as_null_free(field_type);
704 }
705 push_translate(field_type);
706 }
707 }
708 }
709
710 // ------------------------------------------------------------------
711 // ciTypeFlow::StateVector::do_invoke
712 void ciTypeFlow::StateVector::do_invoke(ciBytecodeStream* str,
713 bool has_receiver) {
714 bool will_link;
715 ciSignature* declared_signature = nullptr;
716 ciMethod* callee = str->get_method(will_link, &declared_signature);
717 assert(declared_signature != nullptr, "cannot be null");
718 if (!will_link) {
719 // We weren't able to find the method.
720 if (str->cur_bc() == Bytecodes::_invokedynamic) {
721 trap(str, nullptr,
722 Deoptimization::make_trap_request
723 (Deoptimization::Reason_uninitialized,
724 Deoptimization::Action_reinterpret));
750 }
751 if (has_receiver) {
752 // Check this?
753 pop_object();
754 }
755 assert(!sigstr.is_done(), "must have return type");
756 ciType* return_type = sigstr.type();
757 if (!return_type->is_void()) {
758 if (!return_type->is_loaded()) {
759 // As in do_getstatic(), generally speaking, we need the return type to
760 // be loaded if we are to do anything interesting with its value.
761 // We used to do this: trap(str, str->get_method_signature_index());
762 //
763 // We do not trap here since execution can get past this invoke if
764 // the return value is null. As long as the value is null, the class
765 // does not need to be loaded! The compiler must assume that
766 // the value of the unloaded class reference is null; if the code
767 // ever sees a non-null value, loading has occurred.
768 //
769 // See do_getstatic() for similar explanation, as well as bug 4684993.
770 if (InlineTypeReturnedAsFields) {
771 // Return might be in scalarized form but we can't handle it because we
772 // don't know the type. This can happen due to a missing preload attribute.
773 // TODO 8284443 Use PhaseMacroExpand::expand_mh_intrinsic_return for this
774 trap(str, nullptr,
775 Deoptimization::make_trap_request
776 (Deoptimization::Reason_uninitialized,
777 Deoptimization::Action_reinterpret));
778 } else {
779 do_null_assert(return_type->as_klass());
780 }
781 } else {
782 if (sigstr.is_null_free()) {
783 return_type = outer()->mark_as_null_free(return_type);
784 }
785 push_translate(return_type);
786 }
787 }
788 }
789 }
790
791 // ------------------------------------------------------------------
792 // ciTypeFlow::StateVector::do_jsr
793 void ciTypeFlow::StateVector::do_jsr(ciBytecodeStream* str) {
794 push(ciReturnAddress::make(str->next_bci()));
795 }
796
797 // ------------------------------------------------------------------
798 // ciTypeFlow::StateVector::do_ldc
799 void ciTypeFlow::StateVector::do_ldc(ciBytecodeStream* str) {
800 if (str->is_in_error()) {
801 trap(str, nullptr, Deoptimization::make_trap_request(Deoptimization::Reason_unhandled,
802 Deoptimization::Action_none));
803 return;
804 }
805 ciConstant con = str->get_constant();
806 if (con.is_valid()) {
807 int cp_index = str->get_constant_pool_index();
808 BasicType basic_type = str->get_basic_type_for_constant_at(cp_index);
809 if (is_reference_type(basic_type)) {
810 ciObject* obj = con.as_object();
811 if (obj->is_null_object()) {
812 push_null();
813 } else {
814 assert(obj->is_instance() || obj->is_array(), "must be java_mirror of klass");
815 ciType* type = obj->klass();
816 if (type->is_inlinetype()) {
817 type = outer()->mark_as_null_free(type);
818 }
819 push(type);
820 }
821 } else {
822 assert(basic_type == con.basic_type() || con.basic_type() == T_OBJECT,
823 "not a boxed form: %s vs %s", type2name(basic_type), type2name(con.basic_type()));
824 push_translate(ciType::make(basic_type));
825 }
826 } else {
827 // OutOfMemoryError in the CI while loading a String constant.
828 push_null();
829 outer()->record_failure("ldc did not link");
830 }
831 }
832
833 // ------------------------------------------------------------------
834 // ciTypeFlow::StateVector::do_multianewarray
835 void ciTypeFlow::StateVector::do_multianewarray(ciBytecodeStream* str) {
836 int dimensions = str->get_dimensions();
837 bool will_link;
838 ciArrayKlass* array_klass = str->get_klass(will_link)->as_array_klass();
839 if (!will_link) {
840 trap(str, array_klass, str->get_klass_index());
841 } else {
842 for (int i = 0; i < dimensions; i++) {
843 pop_int();
844 }
845 push_object(array_klass);
846 }
847 }
848
849 // ------------------------------------------------------------------
850 // ciTypeFlow::StateVector::do_new
851 void ciTypeFlow::StateVector::do_new(ciBytecodeStream* str) {
852 bool will_link;
853 ciKlass* klass = str->get_klass(will_link);
854 if (!will_link || str->is_unresolved_klass() || klass->is_inlinetype()) {
855 trap(str, klass, str->get_klass_index());
856 } else {
857 push_object(klass);
858 }
859 }
860
861 // ------------------------------------------------------------------
862 // ciTypeFlow::StateVector::do_aconst_init
863 void ciTypeFlow::StateVector::do_aconst_init(ciBytecodeStream* str) {
864 bool will_link;
865 ciKlass* klass = str->get_klass(will_link);
866 if (!will_link || str->is_unresolved_klass() || !klass->is_inlinetype()) {
867 trap(str, klass, str->get_klass_index());
868 } else {
869 push(outer()->mark_as_null_free(klass));
870 }
871 }
872
873 // ------------------------------------------------------------------
874 // ciTypeFlow::StateVector::do_withfield
875 void ciTypeFlow::StateVector::do_withfield(ciBytecodeStream* str) {
876 bool will_link;
877 ciField* field = str->get_field(will_link);
878 ciKlass* klass = field->holder();
879 if (!will_link) {
880 trap(str, klass, str->get_field_holder_index());
881 } else {
882 ciType* type = pop_value();
883 ciType* field_type = field->type();
884 if (field_type->is_two_word()) {
885 ciType* type2 = pop_value();
886 assert(type2->is_two_word(), "must be 2nd half");
887 assert(type == half_type(type2), "must be 2nd half");
888 }
889 pop_object();
890 push(outer()->mark_as_null_free(klass));
891 }
892 }
893
894 // ------------------------------------------------------------------
895 // ciTypeFlow::StateVector::do_newarray
896 void ciTypeFlow::StateVector::do_newarray(ciBytecodeStream* str) {
897 pop_int();
898 ciKlass* klass = ciTypeArrayKlass::make((BasicType)str->get_index());
899 push_object(klass);
900 }
901
902 // ------------------------------------------------------------------
903 // ciTypeFlow::StateVector::do_putfield
904 void ciTypeFlow::StateVector::do_putfield(ciBytecodeStream* str) {
905 do_putstatic(str);
906 if (_trap_bci != -1) return; // unloaded field holder, etc.
907 // could add assert here for type of object.
908 pop_object();
909 }
910
911 // ------------------------------------------------------------------
912 // ciTypeFlow::StateVector::do_putstatic
913 void ciTypeFlow::StateVector::do_putstatic(ciBytecodeStream* str) {
979 // class later.
980 push_null();
981 }
982 }
983
984
985 // ------------------------------------------------------------------
986 // ciTypeFlow::StateVector::apply_one_bytecode
987 //
988 // Apply the effect of one bytecode to this StateVector
989 bool ciTypeFlow::StateVector::apply_one_bytecode(ciBytecodeStream* str) {
990 _trap_bci = -1;
991 _trap_index = 0;
992
993 if (CITraceTypeFlow) {
994 tty->print_cr(">> Interpreting bytecode %d:%s", str->cur_bci(),
995 Bytecodes::name(str->cur_bc()));
996 }
997
998 switch(str->cur_bc()) {
999 case Bytecodes::_aaload: do_aload(str); break;
1000
1001 case Bytecodes::_aastore:
1002 {
1003 pop_object();
1004 pop_int();
1005 pop_objOrFlatArray();
1006 break;
1007 }
1008 case Bytecodes::_aconst_null:
1009 {
1010 push_null();
1011 break;
1012 }
1013 case Bytecodes::_aload: load_local_object(str->get_index()); break;
1014 case Bytecodes::_aload_0: load_local_object(0); break;
1015 case Bytecodes::_aload_1: load_local_object(1); break;
1016 case Bytecodes::_aload_2: load_local_object(2); break;
1017 case Bytecodes::_aload_3: load_local_object(3); break;
1018
1019 case Bytecodes::_anewarray:
1020 {
1021 pop_int();
1022 bool will_link;
1023 ciKlass* element_klass = str->get_klass(will_link);
1024 if (!will_link) {
1025 trap(str, element_klass, str->get_klass_index());
1026 } else {
1027 bool null_free = str->has_Q_signature();
1028 push_object(ciArrayKlass::make(element_klass, null_free));
1029 }
1030 break;
1031 }
1032 case Bytecodes::_areturn:
1033 case Bytecodes::_ifnonnull:
1034 case Bytecodes::_ifnull:
1035 {
1036 pop_object();
1037 break;
1038 }
1039 case Bytecodes::_monitorenter:
1040 {
1041 pop_object();
1042 set_monitor_count(monitor_count() + 1);
1043 break;
1044 }
1045 case Bytecodes::_monitorexit:
1046 {
1047 pop_object();
1048 assert(monitor_count() > 0, "must be a monitor to exit from");
1540 }
1541 case Bytecodes::_lshl:
1542 case Bytecodes::_lshr:
1543 case Bytecodes::_lushr:
1544 {
1545 pop_int();
1546 pop_long();
1547 push_long();
1548 break;
1549 }
1550 case Bytecodes::_lstore: store_local_long(str->get_index()); break;
1551 case Bytecodes::_lstore_0: store_local_long(0); break;
1552 case Bytecodes::_lstore_1: store_local_long(1); break;
1553 case Bytecodes::_lstore_2: store_local_long(2); break;
1554 case Bytecodes::_lstore_3: store_local_long(3); break;
1555
1556 case Bytecodes::_multianewarray: do_multianewarray(str); break;
1557
1558 case Bytecodes::_new: do_new(str); break;
1559
1560 case Bytecodes::_aconst_init: do_aconst_init(str); break;
1561 case Bytecodes::_withfield: do_withfield(str); break;
1562
1563 case Bytecodes::_newarray: do_newarray(str); break;
1564
1565 case Bytecodes::_pop:
1566 {
1567 pop();
1568 break;
1569 }
1570 case Bytecodes::_pop2:
1571 {
1572 pop();
1573 pop();
1574 break;
1575 }
1576
1577 case Bytecodes::_putfield: do_putfield(str); break;
1578 case Bytecodes::_putstatic: do_putstatic(str); break;
1579
1580 case Bytecodes::_ret: do_ret(str); break;
1581
1582 case Bytecodes::_swap:
1583 {
1584 ciType* value1 = pop_value();
1585 ciType* value2 = pop_value();
1586 push(value1);
1587 push(value2);
1588 break;
1589 }
1590
1591 case Bytecodes::_wide:
1592 default:
1593 {
1594 // The iterator should skip this.
1595 ShouldNotReachHere();
1596 break;
1597 }
1598 }
1599
1600 if (CITraceTypeFlow) {
1601 print_on(tty);
1602 }
1603
1604 return (_trap_bci != -1);
1605 }
1606
1607 #ifndef PRODUCT
1608 // ------------------------------------------------------------------
1609 // ciTypeFlow::StateVector::print_cell_on
1610 void ciTypeFlow::StateVector::print_cell_on(outputStream* st, Cell c) const {
1611 ciType* type = type_at(c)->unwrap();
1612 if (type == top_type()) {
1613 st->print("top");
1614 } else if (type == bottom_type()) {
1615 st->print("bottom");
1616 } else if (type == null_type()) {
1617 st->print("null");
1618 } else if (type == long2_type()) {
1619 st->print("long2");
1620 } else if (type == double2_type()) {
1621 st->print("double2");
1622 } else if (is_int(type)) {
1623 st->print("int");
1624 } else if (is_long(type)) {
1625 st->print("long");
1626 } else if (is_float(type)) {
1627 st->print("float");
1628 } else if (is_double(type)) {
1629 st->print("double");
1630 } else if (type->is_return_address()) {
1631 st->print("address(%d)", type->as_return_address()->bci());
1854 case Bytecodes::_lookupswitch: {
1855 Bytecode_lookupswitch lookupswitch(str);
1856
1857 int npairs = lookupswitch.number_of_pairs();
1858 _successors =
1859 new (arena) GrowableArray<Block*>(arena, npairs+1, 0, nullptr);
1860 int bci = current_bci + lookupswitch.default_offset();
1861 Block* block = analyzer->block_at(bci, jsrs);
1862 assert(_successors->length() == SWITCH_DEFAULT, "");
1863 _successors->append(block);
1864 while(--npairs >= 0) {
1865 LookupswitchPair pair = lookupswitch.pair_at(npairs);
1866 int bci = current_bci + pair.offset();
1867 Block* block = analyzer->block_at(bci, jsrs);
1868 assert(_successors->length() >= SWITCH_CASES, "");
1869 _successors->append_if_missing(block);
1870 }
1871 break;
1872 }
1873
1874 case Bytecodes::_athrow:
1875 case Bytecodes::_ireturn:
1876 case Bytecodes::_lreturn:
1877 case Bytecodes::_freturn:
1878 case Bytecodes::_dreturn:
1879 case Bytecodes::_areturn:
1880 case Bytecodes::_return:
1881 _successors =
1882 new (arena) GrowableArray<Block*>(arena, 1, 0, nullptr);
1883 // No successors
1884 break;
1885
1886 case Bytecodes::_ret: {
1887 _successors =
1888 new (arena) GrowableArray<Block*>(arena, 1, 0, nullptr);
1889
1890 Cell local = state->local(str->get_index());
1891 ciType* return_address = state->type_at(local);
1892 assert(return_address->is_return_address(), "verify: wrong type");
1893 int bci = return_address->as_return_address()->bci();
1894 assert(_successors->length() == GOTO_TARGET, "");
1895 _successors->append(analyzer->block_at(bci, jsrs));
1896 break;
1897 }
1898
1899 case Bytecodes::_wide:
3253
3254 // ------------------------------------------------------------------
3255 // ciTypeFlow::record_failure()
3256 // The ciTypeFlow object keeps track of failure reasons separately from the ciEnv.
3257 // This is required because there is not a 1-1 relation between the ciEnv and
3258 // the TypeFlow passes within a compilation task. For example, if the compiler
3259 // is considering inlining a method, it will request a TypeFlow. If that fails,
3260 // the compilation as a whole may continue without the inlining. Some TypeFlow
3261 // requests are not optional; if they fail the requestor is responsible for
3262 // copying the failure reason up to the ciEnv. (See Parse::Parse.)
3263 void ciTypeFlow::record_failure(const char* reason) {
3264 if (env()->log() != nullptr) {
3265 env()->log()->elem("failure reason='%s' phase='typeflow'", reason);
3266 }
3267 if (_failure_reason == nullptr) {
3268 // Record the first failure reason.
3269 _failure_reason = reason;
3270 }
3271 }
3272
3273 ciType* ciTypeFlow::mark_as_null_free(ciType* type) {
3274 // Wrap the type to carry the information that it is null-free
3275 return env()->make_null_free_wrapper(type);
3276 }
3277
3278 #ifndef PRODUCT
3279 void ciTypeFlow::print() const { print_on(tty); }
3280
3281 // ------------------------------------------------------------------
3282 // ciTypeFlow::print_on
3283 void ciTypeFlow::print_on(outputStream* st) const {
3284 // Walk through CI blocks
3285 st->print_cr("********************************************************");
3286 st->print ("TypeFlow for ");
3287 method()->name()->print_symbol_on(st);
3288 int limit_bci = code_size();
3289 st->print_cr(" %d bytes", limit_bci);
3290 ciMethodBlocks* mblks = _method->get_method_blocks();
3291 ciBlock* current = nullptr;
3292 for (int bci = 0; bci < limit_bci; bci++) {
3293 ciBlock* blk = mblks->block_containing(bci);
3294 if (blk != nullptr && blk != current) {
3295 current = blk;
3296 current->print_on(st);
3297
|