< prev index next >

src/hotspot/share/ci/ciTypeFlow.cpp

Print this page

   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 objArray meets typeArray, we also get Object.
 323     // And when typeArray meets different typeArray, we again get Object.
 324     // But when objArray meets objArray, we look carefully at element types.
 325     if (k1->is_obj_array_klass() && k2->is_obj_array_klass()) {
 326       ciType* elem1 = k1->as_array_klass()->element_klass();
 327       ciType* elem2 = k2->as_array_klass()->element_klass();
 328       ciType* elem = elem1;
 329       if (elem1 != elem2) {
 330         elem = type_meet_internal(elem1, elem2, analyzer)->as_klass();
 331       }
 332       // Do an easy shortcut if one type is a super of the other.
 333       if (elem == elem1 && !elem->is_inlinetype()) {
 334         assert(k1 == ciArrayKlass::make(elem), "shortcut is OK");
 335         return k1;
 336       } else if (elem == elem2 && !elem->is_inlinetype()) {
 337         assert(k2 == ciArrayKlass::make(elem), "shortcut is OK");
 338         return k2;
 339       } else {
 340         return ciArrayKlass::make(elem);
 341       }
 342     } else {
 343       return object_klass;
 344     }
 345   } else {
 346     // Must be two plain old instance klasses.
 347     assert(k1->is_instance_klass(), "previous cases handle non-instances");
 348     assert(k2->is_instance_klass(), "previous cases handle non-instances");
 349     ciType* result = k1->least_common_ancestor(k2);
 350     if (null_free1 && null_free2 && result->is_inlinetype()) {
 351       result = analyzer->mark_as_null_free(result);
 352     }
 353     if (is_early_larval) {
 354       result = analyzer->mark_as_early_larval(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 (method()->is_object_constructor()) {
 420       if (holder->is_inlinetype() || (holder->is_instance_klass() && !holder->as_instance_klass()->flags().is_identity())) {
 421         // The receiver is early larval (so also null-free)
 422         holder = mark_as_early_larval(holder);
 423       }
 424     } else {
 425       if (holder->is_inlinetype()) {
 426         // The receiver is null-free
 427         holder = mark_as_null_free(holder);
 428       }
 429     }
 430     state->push(holder);
 431     assert(state->tos() == state->local(0), "");
 432   }
 433   for (ciSignatureStream str(method()->signature());
 434        !str.at_return_type();
 435        str.next()) {
 436     state->push_translate(str.type());
 437   }
 438   // Set the rest of the locals to bottom.
 439   assert(state->stack_size() <= 0, "stack size should not be strictly positive");
 440   while (state->stack_size() < 0) {
 441     state->push(state->bottom_type());
 442   }
 443   // Lock an object, if necessary.
 444   state->set_monitor_count(method()->is_synchronized() ? 1 : 0);
 445   return state;
 446 }
 447 
 448 // ------------------------------------------------------------------
 449 // ciTypeFlow::StateVector::copy_into
 450 //

 560 
 561   return different;
 562 }
 563 
 564 // ------------------------------------------------------------------
 565 // ciTypeFlow::StateVector::push_translate
 566 void ciTypeFlow::StateVector::push_translate(ciType* type) {
 567   BasicType basic_type = type->basic_type();
 568   if (basic_type == T_BOOLEAN || basic_type == T_CHAR ||
 569       basic_type == T_BYTE    || basic_type == T_SHORT) {
 570     push_int();
 571   } else {
 572     push(type);
 573     if (type->is_two_word()) {
 574       push(half_type(type));
 575     }
 576   }
 577 }
 578 
 579 // ------------------------------------------------------------------
 580 // ciTypeFlow::StateVector::do_aload
 581 void ciTypeFlow::StateVector::do_aload(ciBytecodeStream* str) {
 582   pop_int();
 583   ciArrayKlass* array_klass = pop_objOrFlatArray();
 584   if (array_klass == nullptr) {
 585     // Did aload on a null reference; push a null and ignore the exception.
 586     // This instruction will never continue normally.  All we have to do
 587     // is report a value that will meet correctly with any downstream
 588     // reference types on paths that will truly be executed.  This null type
 589     // meets with any reference type to yield that same reference type.
 590     // (The compiler will generate an unconditional exception here.)
 591     push(null_type());
 592     return;
 593   }
 594   if (!array_klass->is_loaded()) {
 595     // Only fails for some -Xcomp runs
 596     trap(str, array_klass,
 597          Deoptimization::make_trap_request
 598          (Deoptimization::Reason_unloaded,
 599           Deoptimization::Action_reinterpret));
 600     return;
 601   }
 602   ciKlass* element_klass = array_klass->element_klass();
 603   // TODO 8350865 Can we check that array_klass is null_free and use mark_as_null_free on the result here?
 604   if (!element_klass->is_loaded() && element_klass->is_instance_klass()) {
 605     Untested("unloaded array element class in ciTypeFlow");
 606     trap(str, element_klass,
 607          Deoptimization::make_trap_request
 608          (Deoptimization::Reason_unloaded,
 609           Deoptimization::Action_reinterpret));
 610   } else {
 611     push_object(element_klass);
 612   }
 613 }
 614 
 615 
 616 // ------------------------------------------------------------------
 617 // ciTypeFlow::StateVector::do_checkcast
 618 void ciTypeFlow::StateVector::do_checkcast(ciBytecodeStream* str) {
 619   bool will_link;
 620   ciKlass* klass = str->get_klass(will_link);
 621   if (!will_link) {
 622     // VM's interpreter will not load 'klass' if object is nullptr.
 623     // Type flow after this block may still be needed in two situations:
 624     // 1) C2 uses do_null_assert() and continues compilation for later blocks
 625     // 2) C2 does an OSR compile in a later block (see bug 4778368).
 626     pop_object();
 627     do_null_assert(klass);
 628   } else {
 629     ciType* type = pop_value();
 630     type = type->unwrap();
 631     if (type->is_loaded() && klass->is_loaded() &&
 632         type != klass && type->is_subtype_of(klass)) {
 633       // Useless cast, propagate more precise type of object
 634       klass = type->as_klass();
 635     }
 636     push_object(klass);
 637   }
 638 }
 639 
 640 // ------------------------------------------------------------------
 641 // ciTypeFlow::StateVector::do_getfield
 642 void ciTypeFlow::StateVector::do_getfield(ciBytecodeStream* str) {
 643   // could add assert here for type of object.
 644   pop_object();
 645   do_getstatic(str);
 646 }
 647 
 648 // ------------------------------------------------------------------
 649 // ciTypeFlow::StateVector::do_getstatic
 650 void ciTypeFlow::StateVector::do_getstatic(ciBytecodeStream* str) {
 651   bool will_link;
 652   ciField* field = str->get_field(will_link);
 653   if (!will_link) {
 654     trap(str, field->holder(), str->get_field_holder_index());
 655   } else {
 656     ciType* field_type = field->type();
 657     if (field->is_static() && field->is_null_free() &&
 658         !field_type->as_instance_klass()->is_initialized()) {
 659       // Deoptimize if we load from a static field with an uninitialized inline type
 660       // because we need to throw an exception if initialization of the type failed.
 661       trap(str, field_type->as_klass(),
 662            Deoptimization::make_trap_request
 663            (Deoptimization::Reason_unloaded,
 664             Deoptimization::Action_reinterpret));
 665       return;
 666     } else if (!field_type->is_loaded()) {
 667       // Normally, we need the field's type to be loaded if we are to
 668       // do anything interesting with its value.
 669       // We used to do this:  trap(str, str->get_field_signature_index());
 670       //
 671       // There is one good reason not to trap here.  Execution can
 672       // get past this "getfield" or "getstatic" if the value of
 673       // the field is null.  As long as the value is null, the class
 674       // does not need to be loaded!  The compiler must assume that
 675       // the value of the unloaded class reference is null; if the code
 676       // ever sees a non-null value, loading has occurred.
 677       //
 678       // This actually happens often enough to be annoying.  If the
 679       // compiler throws an uncommon trap at this bytecode, you can
 680       // get an endless loop of recompilations, when all the code
 681       // needs to do is load a series of null values.  Also, a trap
 682       // here can make an OSR entry point unreachable, triggering the
 683       // assert on non_osr_block in ciTypeFlow::get_start_state.
 684       // (See bug 4379915.)
 685       do_null_assert(field_type->as_klass());
 686     } else {
 687       if (field->is_null_free()) {
 688         field_type = outer()->mark_as_null_free(field_type);
 689       }
 690       push_translate(field_type);
 691     }
 692   }
 693 }
 694 
 695 // ------------------------------------------------------------------
 696 // ciTypeFlow::StateVector::do_invoke
 697 void ciTypeFlow::StateVector::do_invoke(ciBytecodeStream* str,
 698                                         bool has_receiver) {
 699   bool will_link;
 700   ciSignature* declared_signature = nullptr;
 701   ciMethod* callee = str->get_method(will_link, &declared_signature);
 702   assert(declared_signature != nullptr, "cannot be null");
 703   if (!will_link) {
 704     // We weren't able to find the method.
 705     if (str->cur_bc() == Bytecodes::_invokedynamic) {
 706       trap(str, nullptr,
 707            Deoptimization::make_trap_request
 708            (Deoptimization::Reason_uninitialized,
 709             Deoptimization::Action_reinterpret));

 717     // invokehandle).
 718     ciSignatureStream sigstr(declared_signature);
 719     const int arg_size = declared_signature->size();
 720     const int stack_base = stack_size() - arg_size;
 721     int i = 0;
 722     for( ; !sigstr.at_return_type(); sigstr.next()) {
 723       ciType* type = sigstr.type();
 724       ciType* stack_type = type_at(stack(stack_base + i++));
 725       // Do I want to check this type?
 726       // assert(stack_type->is_subtype_of(type), "bad type for field value");
 727       if (type->is_two_word()) {
 728         ciType* stack_type2 = type_at(stack(stack_base + i++));
 729         assert(stack_type2->equals(half_type(type)), "must be 2nd half");
 730       }
 731     }
 732     assert(arg_size == i, "must match");
 733     for (int j = 0; j < arg_size; j++) {
 734       pop();
 735     }
 736     if (has_receiver) {
 737       if (type_at_tos()->is_early_larval()) {
 738         // Call with larval receiver accepted by verifier
 739         // => this is <init> and the receiver is no longer larval after that.
 740         Cell limit = limit_cell();
 741         for (Cell c = start_cell(); c < limit; c = next_cell(c)) {
 742           if (type_at(c)->ident() == type_at_tos()->ident()) {
 743             assert(type_at(c) == type_at_tos(), "Sin! Abomination!");
 744             set_type_at(c, type_at_tos()->unwrap());
 745           }
 746         }
 747       }
 748       pop_object();
 749     }
 750     assert(!sigstr.is_done(), "must have return type");
 751     ciType* return_type = sigstr.type();
 752     if (!return_type->is_void()) {
 753       if (!return_type->is_loaded()) {
 754         // As in do_getstatic(), generally speaking, we need the return type to
 755         // be loaded if we are to do anything interesting with its value.
 756         // We used to do this:  trap(str, str->get_method_signature_index());
 757         //
 758         // We do not trap here since execution can get past this invoke if
 759         // the return value is null.  As long as the value is null, the class
 760         // does not need to be loaded!  The compiler must assume that
 761         // the value of the unloaded class reference is null; if the code
 762         // ever sees a non-null value, loading has occurred.
 763         //
 764         // See do_getstatic() for similar explanation, as well as bug 4684993.
 765         do_null_assert(return_type->as_klass());
 766       } else {
 767         push_translate(return_type);

 783     trap(str, nullptr, Deoptimization::make_trap_request(Deoptimization::Reason_unhandled,
 784                                                          Deoptimization::Action_none));
 785     return;
 786   }
 787   ciConstant con = str->get_constant();
 788   if (con.is_valid()) {
 789     int cp_index = str->get_constant_pool_index();
 790     if (!con.is_loaded()) {
 791       trap(str, nullptr, Deoptimization::make_trap_request(Deoptimization::Reason_unloaded,
 792                                                            Deoptimization::Action_reinterpret,
 793                                                            cp_index));
 794       return;
 795     }
 796     BasicType basic_type = str->get_basic_type_for_constant_at(cp_index);
 797     if (is_reference_type(basic_type)) {
 798       ciObject* obj = con.as_object();
 799       if (obj->is_null_object()) {
 800         push_null();
 801       } else {
 802         assert(obj->is_instance() || obj->is_array(), "must be java_mirror of klass");
 803         ciType* type = obj->klass();
 804         if (type->is_inlinetype()) {
 805           type = outer()->mark_as_null_free(type);
 806         }
 807         push(type);
 808       }
 809     } else {
 810       assert(basic_type == con.basic_type() || con.basic_type() == T_OBJECT,
 811              "not a boxed form: %s vs %s", type2name(basic_type), type2name(con.basic_type()));
 812       push_translate(ciType::make(basic_type));
 813     }
 814   } else {
 815     // OutOfMemoryError in the CI while loading a String constant.
 816     push_null();
 817     outer()->record_failure("ldc did not link");
 818   }
 819 }
 820 
 821 // ------------------------------------------------------------------
 822 // ciTypeFlow::StateVector::do_multianewarray
 823 void ciTypeFlow::StateVector::do_multianewarray(ciBytecodeStream* str) {
 824   int dimensions = str->get_dimensions();
 825   bool will_link;
 826   ciArrayKlass* array_klass = str->get_klass(will_link)->as_array_klass();
 827   if (!will_link) {
 828     trap(str, array_klass, str->get_klass_index());
 829   } else {
 830     for (int i = 0; i < dimensions; i++) {
 831       pop_int();
 832     }
 833     push_object(array_klass);
 834   }
 835 }
 836 
 837 // ------------------------------------------------------------------
 838 // ciTypeFlow::StateVector::do_new
 839 void ciTypeFlow::StateVector::do_new(ciBytecodeStream* str) {
 840   bool will_link;
 841   ciKlass* klass = str->get_klass(will_link);
 842   if (!will_link || str->is_unresolved_klass()) {
 843     trap(str, klass, str->get_klass_index());
 844   } else {
 845     if (klass->is_inlinetype()) {
 846       push(outer()->mark_as_early_larval(klass));
 847       return;
 848     }
 849     push_object(klass);
 850   }
 851 }
 852 
 853 // ------------------------------------------------------------------
 854 // ciTypeFlow::StateVector::do_newarray
 855 void ciTypeFlow::StateVector::do_newarray(ciBytecodeStream* str) {
 856   pop_int();
 857   ciKlass* klass = ciTypeArrayKlass::make((BasicType)str->get_index());
 858   push_object(klass);
 859 }
 860 
 861 // ------------------------------------------------------------------
 862 // ciTypeFlow::StateVector::do_putfield
 863 void ciTypeFlow::StateVector::do_putfield(ciBytecodeStream* str) {
 864   do_putstatic(str);
 865   if (_trap_bci != -1)  return;  // unloaded field holder, etc.
 866   // could add assert here for type of object.
 867   pop_object();
 868 }

 938     // class later.
 939     push_null();
 940   }
 941 }
 942 
 943 
 944 // ------------------------------------------------------------------
 945 // ciTypeFlow::StateVector::apply_one_bytecode
 946 //
 947 // Apply the effect of one bytecode to this StateVector
 948 bool ciTypeFlow::StateVector::apply_one_bytecode(ciBytecodeStream* str) {
 949   _trap_bci = -1;
 950   _trap_index = 0;
 951 
 952   if (CITraceTypeFlow) {
 953     tty->print_cr(">> Interpreting bytecode %d:%s", str->cur_bci(),
 954                   Bytecodes::name(str->cur_bc()));
 955   }
 956 
 957   switch(str->cur_bc()) {
 958   case Bytecodes::_aaload: do_aload(str);                           break;
 959 
 960   case Bytecodes::_aastore:
 961     {
 962       pop_object();
 963       pop_int();
 964       pop_objOrFlatArray();
 965       break;
 966     }
 967   case Bytecodes::_aconst_null:
 968     {
 969       push_null();
 970       break;
 971     }
 972   case Bytecodes::_aload:   load_local_object(str->get_index());    break;
 973   case Bytecodes::_aload_0: load_local_object(0);                   break;
 974   case Bytecodes::_aload_1: load_local_object(1);                   break;
 975   case Bytecodes::_aload_2: load_local_object(2);                   break;
 976   case Bytecodes::_aload_3: load_local_object(3);                   break;
 977 
 978   case Bytecodes::_anewarray:
 979     {
 980       pop_int();
 981       bool will_link;
 982       ciKlass* element_klass = str->get_klass(will_link);
 983       if (!will_link) {
 984         trap(str, element_klass, str->get_klass_index());
 985       } else {
 986         push_object(ciArrayKlass::make(element_klass));
 987       }
 988       break;
 989     }
 990   case Bytecodes::_areturn:
 991   case Bytecodes::_ifnonnull:
 992   case Bytecodes::_ifnull:
 993     {
 994       pop_object();
 995       break;
 996     }
 997   case Bytecodes::_monitorenter:
 998     {
 999       pop_object();
1000       set_monitor_count(monitor_count() + 1);
1001       break;
1002     }
1003   case Bytecodes::_monitorexit:
1004     {
1005       pop_object();
1006       assert(monitor_count() > 0, "must be a monitor to exit from");

1525   case Bytecodes::_pop2:
1526     {
1527       pop();
1528       pop();
1529       break;
1530     }
1531 
1532   case Bytecodes::_putfield:       do_putfield(str);                 break;
1533   case Bytecodes::_putstatic:      do_putstatic(str);                break;
1534 
1535   case Bytecodes::_ret: do_ret(str);                                 break;
1536 
1537   case Bytecodes::_swap:
1538     {
1539       ciType* value1 = pop_value();
1540       ciType* value2 = pop_value();
1541       push(value1);
1542       push(value2);
1543       break;
1544     }
1545 
1546   case Bytecodes::_wide:
1547   default:
1548     {
1549       // The iterator should skip this.
1550       ShouldNotReachHere();
1551       break;
1552     }
1553   }
1554 
1555   if (CITraceTypeFlow) {
1556     print_on(tty);
1557   }
1558 
1559   return (_trap_bci != -1);
1560 }
1561 
1562 #ifndef PRODUCT
1563 // ------------------------------------------------------------------
1564 // ciTypeFlow::StateVector::print_cell_on
1565 void ciTypeFlow::StateVector::print_cell_on(outputStream* st, Cell c) const {
1566   ciType* type = type_at(c)->unwrap();
1567   if (type == top_type()) {
1568     st->print("top");
1569   } else if (type == bottom_type()) {
1570     st->print("bottom");
1571   } else if (type == null_type()) {
1572     st->print("null");
1573   } else if (type == long2_type()) {
1574     st->print("long2");
1575   } else if (type == double2_type()) {
1576     st->print("double2");
1577   } else if (is_int(type)) {
1578     st->print("int");
1579   } else if (is_long(type)) {
1580     st->print("long");
1581   } else if (is_float(type)) {
1582     st->print("float");
1583   } else if (is_double(type)) {
1584     st->print("double");
1585   } else if (type->is_return_address()) {
1586     st->print("address(%d)", type->as_return_address()->bci());

1809       case Bytecodes::_lookupswitch: {
1810         Bytecode_lookupswitch lookupswitch(str);
1811 
1812         int npairs = lookupswitch.number_of_pairs();
1813         _successors =
1814           new (arena) GrowableArray<Block*>(arena, npairs+1, 0, nullptr);
1815         int bci = current_bci + lookupswitch.default_offset();
1816         Block* block = analyzer->block_at(bci, jsrs);
1817         assert(_successors->length() == SWITCH_DEFAULT, "");
1818         _successors->append(block);
1819         while(--npairs >= 0) {
1820           LookupswitchPair pair = lookupswitch.pair_at(npairs);
1821           int bci = current_bci + pair.offset();
1822           Block* block = analyzer->block_at(bci, jsrs);
1823           assert(_successors->length() >= SWITCH_CASES, "");
1824           _successors->append_if_missing(block);
1825         }
1826         break;
1827       }
1828 
1829       case Bytecodes::_athrow:
1830       case Bytecodes::_ireturn:
1831       case Bytecodes::_lreturn:
1832       case Bytecodes::_freturn:
1833       case Bytecodes::_dreturn:
1834       case Bytecodes::_areturn:
1835       case Bytecodes::_return:
1836         _successors =
1837           new (arena) GrowableArray<Block*>(arena, 1, 0, nullptr);
1838         // No successors
1839         break;
1840 
1841       case Bytecodes::_ret: {
1842         _successors =
1843           new (arena) GrowableArray<Block*>(arena, 1, 0, nullptr);
1844 
1845         Cell local = state->local(str->get_index());
1846         ciType* return_address = state->type_at(local);
1847         assert(return_address->is_return_address(), "verify: wrong type");
1848         int bci = return_address->as_return_address()->bci();
1849         assert(_successors->length() == GOTO_TARGET, "");
1850         _successors->append(analyzer->block_at(bci, jsrs));
1851         break;
1852       }
1853 
1854       case Bytecodes::_wide:

3207 
3208 // ------------------------------------------------------------------
3209 // ciTypeFlow::record_failure()
3210 // The ciTypeFlow object keeps track of failure reasons separately from the ciEnv.
3211 // This is required because there is not a 1-1 relation between the ciEnv and
3212 // the TypeFlow passes within a compilation task.  For example, if the compiler
3213 // is considering inlining a method, it will request a TypeFlow.  If that fails,
3214 // the compilation as a whole may continue without the inlining.  Some TypeFlow
3215 // requests are not optional; if they fail the requestor is responsible for
3216 // copying the failure reason up to the ciEnv.  (See Parse::Parse.)
3217 void ciTypeFlow::record_failure(const char* reason) {
3218   if (env()->log() != nullptr) {
3219     env()->log()->elem("failure reason='%s' phase='typeflow'", reason);
3220   }
3221   if (_failure_reason == nullptr) {
3222     // Record the first failure reason.
3223     _failure_reason = reason;
3224   }
3225 }
3226 
3227 ciType* ciTypeFlow::mark_as_early_larval(ciType* type) {
3228   // Wrap the type to carry the information that it is null-free
3229   return env()->make_early_larval_wrapper(type);
3230 }
3231 
3232 
3233 ciType* ciTypeFlow::mark_as_null_free(ciType* type) {
3234   // Wrap the type to carry the information that it is null-free
3235   return env()->make_null_free_wrapper(type);
3236 }
3237 
3238 #ifndef PRODUCT
3239 void ciTypeFlow::print() const       { print_on(tty); }
3240 
3241 // ------------------------------------------------------------------
3242 // ciTypeFlow::print_on
3243 void ciTypeFlow::print_on(outputStream* st) const {
3244   // Walk through CI blocks
3245   st->print_cr("********************************************************");
3246   st->print   ("TypeFlow for ");
3247   method()->name()->print_symbol_on(st);
3248   int limit_bci = code_size();
3249   st->print_cr("  %d bytes", limit_bci);
3250   ciMethodBlocks* mblks = _method->get_method_blocks();
3251   ciBlock* current = nullptr;
3252   for (int bci = 0; bci < limit_bci; bci++) {
3253     ciBlock* blk = mblks->block_containing(bci);
3254     if (blk != nullptr && blk != current) {
3255       current = blk;
3256       current->print_on(st);
3257 
< prev index next >