< prev index next >

src/hotspot/share/ci/ciTypeFlow.cpp

Print this page

   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 == NULL) {
 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 = NULL;
 652   ciMethod* callee = str->get_method(will_link, &declared_signature);
 653   assert(declared_signature != NULL, "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, NULL,
 658            Deoptimization::make_trap_request
 659            (Deoptimization::Reason_uninitialized,
 660             Deoptimization::Action_reinterpret));

 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   ciConstant con = str->get_constant();
 724   if (con.is_valid()) {
 725     BasicType basic_type = con.basic_type();
 726     if (is_reference_type(basic_type)) {
 727       ciObject* obj = con.as_object();
 728       if (obj->is_null_object()) {
 729         push_null();
 730       } else {
 731         assert(obj->is_instance() || obj->is_array(), "must be java_mirror of klass");
 732         push_object(obj->klass());




 733       }
 734     } else {
 735       push_translate(ciType::make(basic_type));
 736     }
 737   } else {
 738     if (str->is_unresolved_klass_in_error()) {
 739       trap(str, NULL, Deoptimization::make_trap_request(Deoptimization::Reason_unhandled,
 740                                                         Deoptimization::Action_none));
 741     } else {
 742       // OutOfMemoryError in the CI while loading constant
 743       push_null();
 744       outer()->record_failure("ldc did not link");
 745     }
 746   }
 747 }
 748 
 749 // ------------------------------------------------------------------
 750 // ciTypeFlow::StateVector::do_multianewarray
 751 void ciTypeFlow::StateVector::do_multianewarray(ciBytecodeStream* str) {
 752   int dimensions = str->get_dimensions();
 753   bool will_link;
 754   ciArrayKlass* array_klass = str->get_klass(will_link)->as_array_klass();
 755   if (!will_link) {
 756     trap(str, array_klass, str->get_klass_index());
 757   } else {
 758     for (int i = 0; i < dimensions; i++) {
 759       pop_int();
 760     }
 761     push_object(array_klass);
 762   }
 763 }
 764 
 765 // ------------------------------------------------------------------
 766 // ciTypeFlow::StateVector::do_new
 767 void ciTypeFlow::StateVector::do_new(ciBytecodeStream* str) {
 768   bool will_link;
 769   ciKlass* klass = str->get_klass(will_link);
 770   if (!will_link || str->is_unresolved_klass()) {
 771     trap(str, klass, str->get_klass_index());
 772   } else {
 773     push_object(klass);
 774   }
 775 }
 776 

































 777 // ------------------------------------------------------------------
 778 // ciTypeFlow::StateVector::do_newarray
 779 void ciTypeFlow::StateVector::do_newarray(ciBytecodeStream* str) {
 780   pop_int();
 781   ciKlass* klass = ciTypeArrayKlass::make((BasicType)str->get_index());
 782   push_object(klass);
 783 }
 784 
 785 // ------------------------------------------------------------------
 786 // ciTypeFlow::StateVector::do_putfield
 787 void ciTypeFlow::StateVector::do_putfield(ciBytecodeStream* str) {
 788   do_putstatic(str);
 789   if (_trap_bci != -1)  return;  // unloaded field holder, etc.
 790   // could add assert here for type of object.
 791   pop_object();
 792 }
 793 
 794 // ------------------------------------------------------------------
 795 // ciTypeFlow::StateVector::do_putstatic
 796 void ciTypeFlow::StateVector::do_putstatic(ciBytecodeStream* str) {

 862     // class later.
 863     push_null();
 864   }
 865 }
 866 
 867 
 868 // ------------------------------------------------------------------
 869 // ciTypeFlow::StateVector::apply_one_bytecode
 870 //
 871 // Apply the effect of one bytecode to this StateVector
 872 bool ciTypeFlow::StateVector::apply_one_bytecode(ciBytecodeStream* str) {
 873   _trap_bci = -1;
 874   _trap_index = 0;
 875 
 876   if (CITraceTypeFlow) {
 877     tty->print_cr(">> Interpreting bytecode %d:%s", str->cur_bci(),
 878                   Bytecodes::name(str->cur_bc()));
 879   }
 880 
 881   switch(str->cur_bc()) {
 882   case Bytecodes::_aaload: do_aaload(str);                       break;
 883 
 884   case Bytecodes::_aastore:
 885     {
 886       pop_object();
 887       pop_int();
 888       pop_objArray();
 889       break;
 890     }
 891   case Bytecodes::_aconst_null:
 892     {
 893       push_null();
 894       break;
 895     }
 896   case Bytecodes::_aload:   load_local_object(str->get_index());    break;
 897   case Bytecodes::_aload_0: load_local_object(0);                   break;
 898   case Bytecodes::_aload_1: load_local_object(1);                   break;
 899   case Bytecodes::_aload_2: load_local_object(2);                   break;
 900   case Bytecodes::_aload_3: load_local_object(3);                   break;
 901 
 902   case Bytecodes::_anewarray:
 903     {
 904       pop_int();
 905       bool will_link;
 906       ciKlass* element_klass = str->get_klass(will_link);
 907       if (!will_link) {
 908         trap(str, element_klass, str->get_klass_index());
 909       } else {
 910         push_object(ciObjArrayKlass::make(element_klass));

 911       }
 912       break;
 913     }
 914   case Bytecodes::_areturn:
 915   case Bytecodes::_ifnonnull:
 916   case Bytecodes::_ifnull:
 917     {
 918       pop_object();
 919       break;
 920     }
 921   case Bytecodes::_monitorenter:
 922     {
 923       pop_object();
 924       set_monitor_count(monitor_count() + 1);
 925       break;
 926     }
 927   case Bytecodes::_monitorexit:
 928     {
 929       pop_object();
 930       assert(monitor_count() > 0, "must be a monitor to exit from");

1422     }
1423   case Bytecodes::_lshl:
1424   case Bytecodes::_lshr:
1425   case Bytecodes::_lushr:
1426     {
1427       pop_int();
1428       pop_long();
1429       push_long();
1430       break;
1431     }
1432   case Bytecodes::_lstore:   store_local_long(str->get_index());    break;
1433   case Bytecodes::_lstore_0: store_local_long(0);                   break;
1434   case Bytecodes::_lstore_1: store_local_long(1);                   break;
1435   case Bytecodes::_lstore_2: store_local_long(2);                   break;
1436   case Bytecodes::_lstore_3: store_local_long(3);                   break;
1437 
1438   case Bytecodes::_multianewarray: do_multianewarray(str);          break;
1439 
1440   case Bytecodes::_new:      do_new(str);                           break;
1441 



1442   case Bytecodes::_newarray: do_newarray(str);                      break;
1443 
1444   case Bytecodes::_pop:
1445     {
1446       pop();
1447       break;
1448     }
1449   case Bytecodes::_pop2:
1450     {
1451       pop();
1452       pop();
1453       break;
1454     }
1455 
1456   case Bytecodes::_putfield:       do_putfield(str);                 break;
1457   case Bytecodes::_putstatic:      do_putstatic(str);                break;
1458 
1459   case Bytecodes::_ret: do_ret(str);                                 break;
1460 
1461   case Bytecodes::_swap:
1462     {
1463       ciType* value1 = pop_value();
1464       ciType* value2 = pop_value();
1465       push(value1);
1466       push(value2);
1467       break;
1468     }

1469   case Bytecodes::_wide:
1470   default:
1471     {
1472       // The iterator should skip this.
1473       ShouldNotReachHere();
1474       break;
1475     }
1476   }
1477 
1478   if (CITraceTypeFlow) {
1479     print_on(tty);
1480   }
1481 
1482   return (_trap_bci != -1);
1483 }
1484 
1485 #ifndef PRODUCT
1486 // ------------------------------------------------------------------
1487 // ciTypeFlow::StateVector::print_cell_on
1488 void ciTypeFlow::StateVector::print_cell_on(outputStream* st, Cell c) const {
1489   ciType* type = type_at(c);
1490   if (type == top_type()) {
1491     st->print("top");
1492   } else if (type == bottom_type()) {
1493     st->print("bottom");
1494   } else if (type == null_type()) {
1495     st->print("null");
1496   } else if (type == long2_type()) {
1497     st->print("long2");
1498   } else if (type == double2_type()) {
1499     st->print("double2");
1500   } else if (is_int(type)) {
1501     st->print("int");
1502   } else if (is_long(type)) {
1503     st->print("long");
1504   } else if (is_float(type)) {
1505     st->print("float");
1506   } else if (is_double(type)) {
1507     st->print("double");
1508   } else if (type->is_return_address()) {
1509     st->print("address(%d)", type->as_return_address()->bci());

1731       case Bytecodes::_lookupswitch: {
1732         Bytecode_lookupswitch lookupswitch(str);
1733 
1734         int npairs = lookupswitch.number_of_pairs();
1735         _successors =
1736           new (arena) GrowableArray<Block*>(arena, npairs+1, 0, NULL);
1737         int bci = current_bci + lookupswitch.default_offset();
1738         Block* block = analyzer->block_at(bci, jsrs);
1739         assert(_successors->length() == SWITCH_DEFAULT, "");
1740         _successors->append(block);
1741         while(--npairs >= 0) {
1742           LookupswitchPair pair = lookupswitch.pair_at(npairs);
1743           int bci = current_bci + pair.offset();
1744           Block* block = analyzer->block_at(bci, jsrs);
1745           assert(_successors->length() >= SWITCH_CASES, "");
1746           _successors->append_if_missing(block);
1747         }
1748         break;
1749       }
1750 
1751       case Bytecodes::_athrow:     case Bytecodes::_ireturn:
1752       case Bytecodes::_lreturn:    case Bytecodes::_freturn:
1753       case Bytecodes::_dreturn:    case Bytecodes::_areturn:



1754       case Bytecodes::_return:
1755         _successors =
1756           new (arena) GrowableArray<Block*>(arena, 1, 0, NULL);
1757         // No successors
1758         break;
1759 
1760       case Bytecodes::_ret: {
1761         _successors =
1762           new (arena) GrowableArray<Block*>(arena, 1, 0, NULL);
1763 
1764         Cell local = state->local(str->get_index());
1765         ciType* return_address = state->type_at(local);
1766         assert(return_address->is_return_address(), "verify: wrong type");
1767         int bci = return_address->as_return_address()->bci();
1768         assert(_successors->length() == GOTO_TARGET, "");
1769         _successors->append(analyzer->block_at(bci, jsrs));
1770         break;
1771       }
1772 
1773       case Bytecodes::_wide:

2961 
2962 // ------------------------------------------------------------------
2963 // ciTypeFlow::record_failure()
2964 // The ciTypeFlow object keeps track of failure reasons separately from the ciEnv.
2965 // This is required because there is not a 1-1 relation between the ciEnv and
2966 // the TypeFlow passes within a compilation task.  For example, if the compiler
2967 // is considering inlining a method, it will request a TypeFlow.  If that fails,
2968 // the compilation as a whole may continue without the inlining.  Some TypeFlow
2969 // requests are not optional; if they fail the requestor is responsible for
2970 // copying the failure reason up to the ciEnv.  (See Parse::Parse.)
2971 void ciTypeFlow::record_failure(const char* reason) {
2972   if (env()->log() != NULL) {
2973     env()->log()->elem("failure reason='%s' phase='typeflow'", reason);
2974   }
2975   if (_failure_reason == NULL) {
2976     // Record the first failure reason.
2977     _failure_reason = reason;
2978   }
2979 }
2980 





2981 #ifndef PRODUCT
2982 // ------------------------------------------------------------------
2983 // ciTypeFlow::print_on
2984 void ciTypeFlow::print_on(outputStream* st) const {
2985   // Walk through CI blocks
2986   st->print_cr("********************************************************");
2987   st->print   ("TypeFlow for ");
2988   method()->name()->print_symbol_on(st);
2989   int limit_bci = code_size();
2990   st->print_cr("  %d bytes", limit_bci);
2991   ciMethodBlocks* mblks = _method->get_method_blocks();
2992   ciBlock* current = NULL;
2993   for (int bci = 0; bci < limit_bci; bci++) {
2994     ciBlock* blk = mblks->block_containing(bci);
2995     if (blk != NULL && blk != current) {
2996       current = blk;
2997       current->print_on(st);
2998 
2999       GrowableArray<Block*>* blocks = _idx_to_blocklist[blk->index()];
3000       int num_blocks = (blocks == NULL) ? 0 : blocks->length();

   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 == NULL) {
 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 NULL.
 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 = NULL;
 716   ciMethod* callee = str->get_method(will_link, &declared_signature);
 717   assert(declared_signature != NULL, "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, NULL,
 722            Deoptimization::make_trap_request
 723            (Deoptimization::Reason_uninitialized,
 724             Deoptimization::Action_reinterpret));

 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         do_null_assert(return_type->as_klass());
 771       } else {
 772         if (sigstr.is_null_free()) {
 773           return_type = outer()->mark_as_null_free(return_type);
 774         }
 775         push_translate(return_type);
 776       }
 777     }
 778   }
 779 }
 780 
 781 // ------------------------------------------------------------------
 782 // ciTypeFlow::StateVector::do_jsr
 783 void ciTypeFlow::StateVector::do_jsr(ciBytecodeStream* str) {
 784   push(ciReturnAddress::make(str->next_bci()));
 785 }
 786 
 787 // ------------------------------------------------------------------
 788 // ciTypeFlow::StateVector::do_ldc
 789 void ciTypeFlow::StateVector::do_ldc(ciBytecodeStream* str) {
 790   ciConstant con = str->get_constant();
 791   if (con.is_valid()) {
 792     BasicType basic_type = con.basic_type();
 793     if (is_reference_type(basic_type)) {
 794       ciObject* obj = con.as_object();
 795       if (obj->is_null_object()) {
 796         push_null();
 797       } else {
 798         assert(obj->is_instance() || obj->is_array(), "must be java_mirror of klass");
 799         ciType* type = obj->klass();
 800         if (type->is_inlinetype()) {
 801           type = outer()->mark_as_null_free(type);
 802         }
 803         push(type);
 804       }
 805     } else {
 806       push_translate(ciType::make(basic_type));
 807     }
 808   } else {
 809     if (str->is_unresolved_klass_in_error()) {
 810       trap(str, NULL, Deoptimization::make_trap_request(Deoptimization::Reason_unhandled,
 811                                                         Deoptimization::Action_none));
 812     } else {
 813       // OutOfMemoryError in the CI while loading constant
 814       push_null();
 815       outer()->record_failure("ldc did not link");
 816     }
 817   }
 818 }
 819 
 820 // ------------------------------------------------------------------
 821 // ciTypeFlow::StateVector::do_multianewarray
 822 void ciTypeFlow::StateVector::do_multianewarray(ciBytecodeStream* str) {
 823   int dimensions = str->get_dimensions();
 824   bool will_link;
 825   ciArrayKlass* array_klass = str->get_klass(will_link)->as_array_klass();
 826   if (!will_link) {
 827     trap(str, array_klass, str->get_klass_index());
 828   } else {
 829     for (int i = 0; i < dimensions; i++) {
 830       pop_int();
 831     }
 832     push_object(array_klass);
 833   }
 834 }
 835 
 836 // ------------------------------------------------------------------
 837 // ciTypeFlow::StateVector::do_new
 838 void ciTypeFlow::StateVector::do_new(ciBytecodeStream* str) {
 839   bool will_link;
 840   ciKlass* klass = str->get_klass(will_link);
 841   if (!will_link || str->is_unresolved_klass() || klass->is_inlinetype()) {
 842     trap(str, klass, str->get_klass_index());
 843   } else {
 844     push_object(klass);
 845   }
 846 }
 847 
 848 // ------------------------------------------------------------------
 849 // ciTypeFlow::StateVector::do_defaultvalue
 850 void ciTypeFlow::StateVector::do_defaultvalue(ciBytecodeStream* str) {
 851   bool will_link;
 852   ciKlass* klass = str->get_klass(will_link);
 853   if (!will_link || str->is_unresolved_klass() || !klass->is_inlinetype()) {
 854     trap(str, klass, str->get_klass_index());
 855   } else {
 856     push(outer()->mark_as_null_free(klass));
 857   }
 858 }
 859 
 860 // ------------------------------------------------------------------
 861 // ciTypeFlow::StateVector::do_withfield
 862 void ciTypeFlow::StateVector::do_withfield(ciBytecodeStream* str) {
 863   bool will_link;
 864   ciField* field = str->get_field(will_link);
 865   ciKlass* klass = field->holder();
 866   if (!will_link) {
 867     trap(str, klass, str->get_field_holder_index());
 868   } else {
 869     ciType* type = pop_value();
 870     ciType* field_type = field->type();
 871     if (field_type->is_two_word()) {
 872       ciType* type2 = pop_value();
 873       assert(type2->is_two_word(), "must be 2nd half");
 874       assert(type == half_type(type2), "must be 2nd half");
 875     }
 876     pop_object();
 877     push(outer()->mark_as_null_free(klass));
 878   }
 879 }
 880 
 881 // ------------------------------------------------------------------
 882 // ciTypeFlow::StateVector::do_newarray
 883 void ciTypeFlow::StateVector::do_newarray(ciBytecodeStream* str) {
 884   pop_int();
 885   ciKlass* klass = ciTypeArrayKlass::make((BasicType)str->get_index());
 886   push_object(klass);
 887 }
 888 
 889 // ------------------------------------------------------------------
 890 // ciTypeFlow::StateVector::do_putfield
 891 void ciTypeFlow::StateVector::do_putfield(ciBytecodeStream* str) {
 892   do_putstatic(str);
 893   if (_trap_bci != -1)  return;  // unloaded field holder, etc.
 894   // could add assert here for type of object.
 895   pop_object();
 896 }
 897 
 898 // ------------------------------------------------------------------
 899 // ciTypeFlow::StateVector::do_putstatic
 900 void ciTypeFlow::StateVector::do_putstatic(ciBytecodeStream* str) {

 966     // class later.
 967     push_null();
 968   }
 969 }
 970 
 971 
 972 // ------------------------------------------------------------------
 973 // ciTypeFlow::StateVector::apply_one_bytecode
 974 //
 975 // Apply the effect of one bytecode to this StateVector
 976 bool ciTypeFlow::StateVector::apply_one_bytecode(ciBytecodeStream* str) {
 977   _trap_bci = -1;
 978   _trap_index = 0;
 979 
 980   if (CITraceTypeFlow) {
 981     tty->print_cr(">> Interpreting bytecode %d:%s", str->cur_bci(),
 982                   Bytecodes::name(str->cur_bc()));
 983   }
 984 
 985   switch(str->cur_bc()) {
 986   case Bytecodes::_aaload: do_aload(str);                           break;
 987 
 988   case Bytecodes::_aastore:
 989     {
 990       pop_object();
 991       pop_int();
 992       pop_objOrFlatArray();
 993       break;
 994     }
 995   case Bytecodes::_aconst_null:
 996     {
 997       push_null();
 998       break;
 999     }
1000   case Bytecodes::_aload:   load_local_object(str->get_index());    break;
1001   case Bytecodes::_aload_0: load_local_object(0);                   break;
1002   case Bytecodes::_aload_1: load_local_object(1);                   break;
1003   case Bytecodes::_aload_2: load_local_object(2);                   break;
1004   case Bytecodes::_aload_3: load_local_object(3);                   break;
1005 
1006   case Bytecodes::_anewarray:
1007     {
1008       pop_int();
1009       bool will_link;
1010       ciKlass* element_klass = str->get_klass(will_link);
1011       if (!will_link) {
1012         trap(str, element_klass, str->get_klass_index());
1013       } else {
1014         bool null_free = str->has_Q_signature();
1015         push_object(ciArrayKlass::make(element_klass, null_free));
1016       }
1017       break;
1018     }
1019   case Bytecodes::_areturn:
1020   case Bytecodes::_ifnonnull:
1021   case Bytecodes::_ifnull:
1022     {
1023       pop_object();
1024       break;
1025     }
1026   case Bytecodes::_monitorenter:
1027     {
1028       pop_object();
1029       set_monitor_count(monitor_count() + 1);
1030       break;
1031     }
1032   case Bytecodes::_monitorexit:
1033     {
1034       pop_object();
1035       assert(monitor_count() > 0, "must be a monitor to exit from");

1527     }
1528   case Bytecodes::_lshl:
1529   case Bytecodes::_lshr:
1530   case Bytecodes::_lushr:
1531     {
1532       pop_int();
1533       pop_long();
1534       push_long();
1535       break;
1536     }
1537   case Bytecodes::_lstore:   store_local_long(str->get_index());    break;
1538   case Bytecodes::_lstore_0: store_local_long(0);                   break;
1539   case Bytecodes::_lstore_1: store_local_long(1);                   break;
1540   case Bytecodes::_lstore_2: store_local_long(2);                   break;
1541   case Bytecodes::_lstore_3: store_local_long(3);                   break;
1542 
1543   case Bytecodes::_multianewarray: do_multianewarray(str);          break;
1544 
1545   case Bytecodes::_new:      do_new(str);                           break;
1546 
1547   case Bytecodes::_defaultvalue: do_defaultvalue(str);              break;
1548   case Bytecodes::_withfield: do_withfield(str);                    break;
1549 
1550   case Bytecodes::_newarray: do_newarray(str);                      break;
1551 
1552   case Bytecodes::_pop:
1553     {
1554       pop();
1555       break;
1556     }
1557   case Bytecodes::_pop2:
1558     {
1559       pop();
1560       pop();
1561       break;
1562     }
1563 
1564   case Bytecodes::_putfield:       do_putfield(str);                 break;
1565   case Bytecodes::_putstatic:      do_putstatic(str);                break;
1566 
1567   case Bytecodes::_ret: do_ret(str);                                 break;
1568 
1569   case Bytecodes::_swap:
1570     {
1571       ciType* value1 = pop_value();
1572       ciType* value2 = pop_value();
1573       push(value1);
1574       push(value2);
1575       break;
1576     }
1577 
1578   case Bytecodes::_wide:
1579   default:
1580     {
1581       // The iterator should skip this.
1582       ShouldNotReachHere();
1583       break;
1584     }
1585   }
1586 
1587   if (CITraceTypeFlow) {
1588     print_on(tty);
1589   }
1590 
1591   return (_trap_bci != -1);
1592 }
1593 
1594 #ifndef PRODUCT
1595 // ------------------------------------------------------------------
1596 // ciTypeFlow::StateVector::print_cell_on
1597 void ciTypeFlow::StateVector::print_cell_on(outputStream* st, Cell c) const {
1598   ciType* type = type_at(c)->unwrap();
1599   if (type == top_type()) {
1600     st->print("top");
1601   } else if (type == bottom_type()) {
1602     st->print("bottom");
1603   } else if (type == null_type()) {
1604     st->print("null");
1605   } else if (type == long2_type()) {
1606     st->print("long2");
1607   } else if (type == double2_type()) {
1608     st->print("double2");
1609   } else if (is_int(type)) {
1610     st->print("int");
1611   } else if (is_long(type)) {
1612     st->print("long");
1613   } else if (is_float(type)) {
1614     st->print("float");
1615   } else if (is_double(type)) {
1616     st->print("double");
1617   } else if (type->is_return_address()) {
1618     st->print("address(%d)", type->as_return_address()->bci());

1840       case Bytecodes::_lookupswitch: {
1841         Bytecode_lookupswitch lookupswitch(str);
1842 
1843         int npairs = lookupswitch.number_of_pairs();
1844         _successors =
1845           new (arena) GrowableArray<Block*>(arena, npairs+1, 0, NULL);
1846         int bci = current_bci + lookupswitch.default_offset();
1847         Block* block = analyzer->block_at(bci, jsrs);
1848         assert(_successors->length() == SWITCH_DEFAULT, "");
1849         _successors->append(block);
1850         while(--npairs >= 0) {
1851           LookupswitchPair pair = lookupswitch.pair_at(npairs);
1852           int bci = current_bci + pair.offset();
1853           Block* block = analyzer->block_at(bci, jsrs);
1854           assert(_successors->length() >= SWITCH_CASES, "");
1855           _successors->append_if_missing(block);
1856         }
1857         break;
1858       }
1859 
1860       case Bytecodes::_athrow:
1861       case Bytecodes::_ireturn:
1862       case Bytecodes::_lreturn:
1863       case Bytecodes::_freturn:
1864       case Bytecodes::_dreturn:
1865       case Bytecodes::_areturn:
1866       case Bytecodes::_return:
1867         _successors =
1868           new (arena) GrowableArray<Block*>(arena, 1, 0, NULL);
1869         // No successors
1870         break;
1871 
1872       case Bytecodes::_ret: {
1873         _successors =
1874           new (arena) GrowableArray<Block*>(arena, 1, 0, NULL);
1875 
1876         Cell local = state->local(str->get_index());
1877         ciType* return_address = state->type_at(local);
1878         assert(return_address->is_return_address(), "verify: wrong type");
1879         int bci = return_address->as_return_address()->bci();
1880         assert(_successors->length() == GOTO_TARGET, "");
1881         _successors->append(analyzer->block_at(bci, jsrs));
1882         break;
1883       }
1884 
1885       case Bytecodes::_wide:

3073 
3074 // ------------------------------------------------------------------
3075 // ciTypeFlow::record_failure()
3076 // The ciTypeFlow object keeps track of failure reasons separately from the ciEnv.
3077 // This is required because there is not a 1-1 relation between the ciEnv and
3078 // the TypeFlow passes within a compilation task.  For example, if the compiler
3079 // is considering inlining a method, it will request a TypeFlow.  If that fails,
3080 // the compilation as a whole may continue without the inlining.  Some TypeFlow
3081 // requests are not optional; if they fail the requestor is responsible for
3082 // copying the failure reason up to the ciEnv.  (See Parse::Parse.)
3083 void ciTypeFlow::record_failure(const char* reason) {
3084   if (env()->log() != NULL) {
3085     env()->log()->elem("failure reason='%s' phase='typeflow'", reason);
3086   }
3087   if (_failure_reason == NULL) {
3088     // Record the first failure reason.
3089     _failure_reason = reason;
3090   }
3091 }
3092 
3093 ciType* ciTypeFlow::mark_as_null_free(ciType* type) {
3094   // Wrap the type to carry the information that it is null-free
3095   return env()->make_null_free_wrapper(type);
3096 }
3097 
3098 #ifndef PRODUCT
3099 // ------------------------------------------------------------------
3100 // ciTypeFlow::print_on
3101 void ciTypeFlow::print_on(outputStream* st) const {
3102   // Walk through CI blocks
3103   st->print_cr("********************************************************");
3104   st->print   ("TypeFlow for ");
3105   method()->name()->print_symbol_on(st);
3106   int limit_bci = code_size();
3107   st->print_cr("  %d bytes", limit_bci);
3108   ciMethodBlocks* mblks = _method->get_method_blocks();
3109   ciBlock* current = NULL;
3110   for (int bci = 0; bci < limit_bci; bci++) {
3111     ciBlock* blk = mblks->block_containing(bci);
3112     if (blk != NULL && blk != current) {
3113       current = blk;
3114       current->print_on(st);
3115 
3116       GrowableArray<Block*>* blocks = _idx_to_blocklist[blk->index()];
3117       int num_blocks = (blocks == NULL) ? 0 : blocks->length();
< prev index next >