< 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   if (str->is_in_error()) {
 724     trap(str, NULL, Deoptimization::make_trap_request(Deoptimization::Reason_unhandled,
 725                                                       Deoptimization::Action_none));
 726     return;
 727   }
 728   ciConstant con = str->get_constant();
 729   if (con.is_valid()) {
 730     int index = str->get_constant_pool_index();
 731     BasicType basic_type = str->get_basic_type_for_constant_at(index);
 732     if (is_reference_type(basic_type)) {
 733       ciObject* obj = con.as_object();
 734       if (obj->is_null_object()) {
 735         push_null();
 736       } else {
 737         assert(obj->is_instance() || obj->is_array(), "must be java_mirror of klass");
 738         push_object(obj->klass());




 739       }
 740     } else {
 741       assert(basic_type == con.basic_type() || con.basic_type() == T_OBJECT,
 742              "not a boxed form: %s vs %s", type2name(basic_type), type2name(con.basic_type()));
 743       push_translate(ciType::make(basic_type));
 744     }
 745   } else {
 746     // OutOfMemoryError in the CI while loading a String constant.
 747     push_null();
 748     outer()->record_failure("ldc did not link");
 749   }
 750 }
 751 
 752 // ------------------------------------------------------------------
 753 // ciTypeFlow::StateVector::do_multianewarray
 754 void ciTypeFlow::StateVector::do_multianewarray(ciBytecodeStream* str) {
 755   int dimensions = str->get_dimensions();
 756   bool will_link;
 757   ciArrayKlass* array_klass = str->get_klass(will_link)->as_array_klass();
 758   if (!will_link) {
 759     trap(str, array_klass, str->get_klass_index());
 760   } else {
 761     for (int i = 0; i < dimensions; i++) {
 762       pop_int();
 763     }
 764     push_object(array_klass);
 765   }
 766 }
 767 
 768 // ------------------------------------------------------------------
 769 // ciTypeFlow::StateVector::do_new
 770 void ciTypeFlow::StateVector::do_new(ciBytecodeStream* str) {
 771   bool will_link;
 772   ciKlass* klass = str->get_klass(will_link);
 773   if (!will_link || str->is_unresolved_klass()) {
 774     trap(str, klass, str->get_klass_index());
 775   } else {
 776     push_object(klass);
 777   }
 778 }
 779 

































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

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

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

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



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

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

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



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

3094 
3095 // ------------------------------------------------------------------
3096 // ciTypeFlow::record_failure()
3097 // The ciTypeFlow object keeps track of failure reasons separately from the ciEnv.
3098 // This is required because there is not a 1-1 relation between the ciEnv and
3099 // the TypeFlow passes within a compilation task.  For example, if the compiler
3100 // is considering inlining a method, it will request a TypeFlow.  If that fails,
3101 // the compilation as a whole may continue without the inlining.  Some TypeFlow
3102 // requests are not optional; if they fail the requestor is responsible for
3103 // copying the failure reason up to the ciEnv.  (See Parse::Parse.)
3104 void ciTypeFlow::record_failure(const char* reason) {
3105   if (env()->log() != NULL) {
3106     env()->log()->elem("failure reason='%s' phase='typeflow'", reason);
3107   }
3108   if (_failure_reason == NULL) {
3109     // Record the first failure reason.
3110     _failure_reason = reason;
3111   }
3112 }
3113 





3114 #ifndef PRODUCT
3115 void ciTypeFlow::print() const       { print_on(tty); }
3116 
3117 // ------------------------------------------------------------------
3118 // ciTypeFlow::print_on
3119 void ciTypeFlow::print_on(outputStream* st) const {
3120   // Walk through CI blocks
3121   st->print_cr("********************************************************");
3122   st->print   ("TypeFlow for ");
3123   method()->name()->print_symbol_on(st);
3124   int limit_bci = code_size();
3125   st->print_cr("  %d bytes", limit_bci);
3126   ciMethodBlocks* mblks = _method->get_method_blocks();
3127   ciBlock* current = NULL;
3128   for (int bci = 0; bci < limit_bci; bci++) {
3129     ciBlock* blk = mblks->block_containing(bci);
3130     if (blk != NULL && blk != current) {
3131       current = blk;
3132       current->print_on(st);
3133 

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

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

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

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

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