< prev index next >

src/hotspot/share/opto/parse2.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 "jvm_io.h"
  27 #include "ci/ciMethodData.hpp"

  28 #include "classfile/vmSymbols.hpp"
  29 #include "compiler/compileLog.hpp"
  30 #include "interpreter/linkResolver.hpp"
  31 #include "memory/resourceArea.hpp"
  32 #include "memory/universe.hpp"
  33 #include "oops/oop.inline.hpp"
  34 #include "opto/addnode.hpp"
  35 #include "opto/castnode.hpp"
  36 #include "opto/convertnode.hpp"
  37 #include "opto/divnode.hpp"
  38 #include "opto/idealGraphPrinter.hpp"


  39 #include "opto/matcher.hpp"
  40 #include "opto/memnode.hpp"
  41 #include "opto/mulnode.hpp"
  42 #include "opto/opaquenode.hpp"
  43 #include "opto/parse.hpp"
  44 #include "opto/runtime.hpp"
  45 #include "runtime/deoptimization.hpp"
  46 #include "runtime/sharedRuntime.hpp"
  47 
  48 #ifndef PRODUCT
  49 extern int explicit_null_checks_inserted,
  50            explicit_null_checks_elided;
  51 #endif
  52 

















  53 //---------------------------------array_load----------------------------------
  54 void Parse::array_load(BasicType bt) {
  55   const Type* elemtype = Type::TOP;
  56   bool big_val = bt == T_DOUBLE || bt == T_LONG;
  57   Node* adr = array_addressing(bt, 0, elemtype);
  58   if (stopped())  return;     // guaranteed null or range check
  59 
  60   pop();                      // index (already used)
  61   Node* array = pop();        // the array itself


























































































  62 
  63   if (elemtype == TypeInt::BOOL) {
  64     bt = T_BOOLEAN;
  65   }
  66   const TypeAryPtr* adr_type = TypeAryPtr::get_array_body_type(bt);
  67 
  68   Node* ld = access_load_at(array, adr, adr_type, elemtype, bt,
  69                             IN_HEAP | IS_ARRAY | C2_CONTROL_DEPENDENT_LOAD);
  70   if (big_val) {
  71     push_pair(ld);
  72   } else {
  73     push(ld);

  74   }

  75 }
  76 
  77 
  78 //--------------------------------array_store----------------------------------
  79 void Parse::array_store(BasicType bt) {
  80   const Type* elemtype = Type::TOP;
  81   bool big_val = bt == T_DOUBLE || bt == T_LONG;
  82   Node* adr = array_addressing(bt, big_val ? 2 : 1, elemtype);
  83   if (stopped())  return;     // guaranteed null or range check

  84   if (bt == T_OBJECT) {
  85     array_store_check();
  86     if (stopped()) {
  87       return;
  88     }
  89   }
  90   Node* val;                  // Oop to store
  91   if (big_val) {
  92     val = pop_pair();
  93   } else {
  94     val = pop();
  95   }
  96   pop();                      // index (already used)
  97   Node* array = pop();        // the array itself
  98 
  99   if (elemtype == TypeInt::BOOL) {
 100     bt = T_BOOLEAN;

























































































































 101   }
 102   const TypeAryPtr* adr_type = TypeAryPtr::get_array_body_type(bt);
 103 
 104   access_store_at(array, adr, adr_type, val, elemtype, bt, MO_UNORDERED | IN_HEAP | IS_ARRAY);
 105 }
 106 
 107 
 108 //------------------------------array_addressing-------------------------------
 109 // Pull array and index from the stack.  Compute pointer-to-element.
 110 Node* Parse::array_addressing(BasicType type, int vals, const Type*& elemtype) {
 111   Node *idx   = peek(0+vals);   // Get from stack without popping
 112   Node *ary   = peek(1+vals);   // in case of exception
 113 
 114   // Null check the array base, with correct stack contents
 115   ary = null_check(ary, T_ARRAY);
 116   // Compile-time detect of null-exception?
 117   if (stopped())  return top();
 118 
 119   const TypeAryPtr* arytype  = _gvn.type(ary)->is_aryptr();
 120   const TypeInt*    sizetype = arytype->size();
 121   elemtype = arytype->elem();
 122 
 123   if (UseUniqueSubclasses) {
 124     const Type* el = elemtype->make_ptr();

 185       if (C->allow_range_check_smearing()) {
 186         // Do not use builtin_throw, since range checks are sometimes
 187         // made more stringent by an optimistic transformation.
 188         // This creates "tentative" range checks at this point,
 189         // which are not guaranteed to throw exceptions.
 190         // See IfNode::Ideal, is_range_check, adjust_check.
 191         uncommon_trap(Deoptimization::Reason_range_check,
 192                       Deoptimization::Action_make_not_entrant,
 193                       NULL, "range_check");
 194       } else {
 195         // If we have already recompiled with the range-check-widening
 196         // heroic optimization turned off, then we must really be throwing
 197         // range check exceptions.
 198         builtin_throw(Deoptimization::Reason_range_check);
 199       }
 200     }
 201   }
 202   // Check for always knowing you are throwing a range-check exception
 203   if (stopped())  return top();
 204 




















































































































 205   // Make array address computation control dependent to prevent it
 206   // from floating above the range check during loop optimizations.
 207   Node* ptr = array_element_address(ary, idx, type, sizetype, control());
 208   assert(ptr != top(), "top should go hand-in-hand with stopped");
 209 
 210   return ptr;
 211 }
 212 
 213 
 214 // returns IfNode
 215 IfNode* Parse::jump_if_fork_int(Node* a, Node* b, BoolTest::mask mask, float prob, float cnt) {
 216   Node   *cmp = _gvn.transform(new CmpINode(a, b)); // two cases: shiftcount > 32 and shiftcount <= 32
 217   Node   *tst = _gvn.transform(new BoolNode(cmp, mask));
 218   IfNode *iff = create_and_map_if(control(), tst, prob, cnt);
 219   return iff;
 220 }
 221 
 222 
 223 // sentinel value for the target bci to mark never taken branches
 224 // (according to profiling)

1416       }
1417     }
1418   }
1419 
1420   // False branch
1421   Node* iffalse = _gvn.transform( new IfFalseNode(iff) );
1422   set_control(iffalse);
1423 
1424   if (stopped()) {              // Path is dead?
1425     NOT_PRODUCT(explicit_null_checks_elided++);
1426     if (C->eliminate_boxing()) {
1427       // Mark the successor block as parsed
1428       next_block->next_path_num();
1429     }
1430   } else  {                     // Path is live.
1431     adjust_map_after_if(BoolTest(btest).negate(), c, 1.0-prob, next_block);
1432   }
1433 }
1434 
1435 //------------------------------------do_if------------------------------------
1436 void Parse::do_if(BoolTest::mask btest, Node* c) {
1437   int target_bci = iter().get_dest();
1438 
1439   Block* branch_block = successor_for_bci(target_bci);
1440   Block* next_block   = successor_for_bci(iter().next_bci());
1441 
1442   float cnt;
1443   float prob = branch_prediction(cnt, btest, target_bci, c);
1444   float untaken_prob = 1.0 - prob;
1445 
1446   if (prob == PROB_UNKNOWN) {
1447     if (PrintOpto && Verbose) {
1448       tty->print_cr("Never-taken edge stops compilation at bci %d", bci());
1449     }
1450     repush_if_args(); // to gather stats on loop
1451     uncommon_trap(Deoptimization::Reason_unreached,
1452                   Deoptimization::Action_reinterpret,
1453                   NULL, "cold");
1454     if (C->eliminate_boxing()) {
1455       // Mark the successor blocks as parsed
1456       branch_block->next_path_num();

1500   }
1501 
1502   // Generate real control flow
1503   float true_prob = (taken_if_true ? prob : untaken_prob);
1504   IfNode* iff = create_and_map_if(control(), tst, true_prob, cnt);
1505   assert(iff->_prob > 0.0f,"Optimizer made bad probability in parser");
1506   Node* taken_branch   = new IfTrueNode(iff);
1507   Node* untaken_branch = new IfFalseNode(iff);
1508   if (!taken_if_true) {  // Finish conversion to canonical form
1509     Node* tmp      = taken_branch;
1510     taken_branch   = untaken_branch;
1511     untaken_branch = tmp;
1512   }
1513 
1514   // Branch is taken:
1515   { PreserveJVMState pjvms(this);
1516     taken_branch = _gvn.transform(taken_branch);
1517     set_control(taken_branch);
1518 
1519     if (stopped()) {
1520       if (C->eliminate_boxing()) {
1521         // Mark the successor block as parsed
1522         branch_block->next_path_num();
1523       }
1524     } else {
1525       adjust_map_after_if(taken_btest, c, prob, branch_block);
1526       if (!stopped()) {
1527         merge(target_bci);








1528       }
1529     }
1530   }
1531 
1532   untaken_branch = _gvn.transform(untaken_branch);
1533   set_control(untaken_branch);
1534 
1535   // Branch not taken.
1536   if (stopped()) {
1537     if (C->eliminate_boxing()) {
1538       // Mark the successor block as parsed
1539       next_block->next_path_num();
1540     }
1541   } else {
1542     adjust_map_after_if(untaken_btest, c, untaken_prob, next_block);
1543   }
1544 }
1545 











































































































































































































































































































































































































1546 bool Parse::path_is_suitable_for_uncommon_trap(float prob) const {
1547   // Don't want to speculate on uncommon traps when running with -Xcomp
1548   if (!UseInterpreter) {
1549     return false;
1550   }
1551   return (seems_never_taken(prob) && seems_stable_comparison());
1552 }
1553 
1554 void Parse::maybe_add_predicate_after_if(Block* path) {
1555   if (path->is_SEL_head() && path->preds_parsed() == 0) {
1556     // Add predicates at bci of if dominating the loop so traps can be
1557     // recorded on the if's profile data
1558     int bc_depth = repush_if_args();
1559     add_empty_predicates();
1560     dec_sp(bc_depth);
1561     path->set_has_predicates();
1562   }
1563 }
1564 
1565 

1766   if (c->Opcode() == Op_CmpP &&
1767       (c->in(1)->Opcode() == Op_LoadKlass || c->in(1)->Opcode() == Op_DecodeNKlass) &&
1768       c->in(2)->is_Con()) {
1769     Node* load_klass = NULL;
1770     Node* decode = NULL;
1771     if (c->in(1)->Opcode() == Op_DecodeNKlass) {
1772       decode = c->in(1);
1773       load_klass = c->in(1)->in(1);
1774     } else {
1775       load_klass = c->in(1);
1776     }
1777     if (load_klass->in(2)->is_AddP()) {
1778       Node* addp = load_klass->in(2);
1779       Node* obj = addp->in(AddPNode::Address);
1780       const TypeOopPtr* obj_type = _gvn.type(obj)->is_oopptr();
1781       if (obj_type->speculative_type_not_null() != NULL) {
1782         ciKlass* k = obj_type->speculative_type();
1783         inc_sp(2);
1784         obj = maybe_cast_profiled_obj(obj, k);
1785         dec_sp(2);




1786         // Make the CmpP use the casted obj
1787         addp = basic_plus_adr(obj, addp->in(AddPNode::Offset));
1788         load_klass = load_klass->clone();
1789         load_klass->set_req(2, addp);
1790         load_klass = _gvn.transform(load_klass);
1791         if (decode != NULL) {
1792           decode = decode->clone();
1793           decode->set_req(1, load_klass);
1794           load_klass = _gvn.transform(decode);
1795         }
1796         c = c->clone();
1797         c->set_req(1, load_klass);
1798         c = _gvn.transform(c);
1799       }
1800     }
1801   }
1802   return c;
1803 }
1804 
1805 //------------------------------do_one_bytecode--------------------------------

2612     // See if we can get some profile data and hand it off to the next block
2613     Block *target_block = block()->successor_for_bci(target_bci);
2614     if (target_block->pred_count() != 1)  break;
2615     ciMethodData* methodData = method()->method_data();
2616     if (!methodData->is_mature())  break;
2617     ciProfileData* data = methodData->bci_to_data(bci());
2618     assert(data != NULL && data->is_JumpData(), "need JumpData for taken branch");
2619     int taken = ((ciJumpData*)data)->taken();
2620     taken = method()->scale_count(taken);
2621     target_block->set_count(taken);
2622     break;
2623   }
2624 
2625   case Bytecodes::_ifnull:    btest = BoolTest::eq; goto handle_if_null;
2626   case Bytecodes::_ifnonnull: btest = BoolTest::ne; goto handle_if_null;
2627   handle_if_null:
2628     // If this is a backwards branch in the bytecodes, add Safepoint
2629     maybe_add_safepoint(iter().get_dest());
2630     a = null();
2631     b = pop();
2632     if (!_gvn.type(b)->speculative_maybe_null() &&
2633         !too_many_traps(Deoptimization::Reason_speculate_null_check)) {
2634       inc_sp(1);
2635       Node* null_ctl = top();
2636       b = null_check_oop(b, &null_ctl, true, true, true);
2637       assert(null_ctl->is_top(), "no null control here");
2638       dec_sp(1);
2639     } else if (_gvn.type(b)->speculative_always_null() &&
2640                !too_many_traps(Deoptimization::Reason_speculate_null_assert)) {
2641       inc_sp(1);
2642       b = null_assert(b);
2643       dec_sp(1);
2644     }
2645     c = _gvn.transform( new CmpPNode(b, a) );






2646     do_ifnull(btest, c);
2647     break;
2648 
2649   case Bytecodes::_if_acmpeq: btest = BoolTest::eq; goto handle_if_acmp;
2650   case Bytecodes::_if_acmpne: btest = BoolTest::ne; goto handle_if_acmp;
2651   handle_if_acmp:
2652     // If this is a backwards branch in the bytecodes, add Safepoint
2653     maybe_add_safepoint(iter().get_dest());
2654     a = pop();
2655     b = pop();
2656     c = _gvn.transform( new CmpPNode(b, a) );
2657     c = optimize_cmp_with_klass(c);
2658     do_if(btest, c);
2659     break;
2660 
2661   case Bytecodes::_ifeq: btest = BoolTest::eq; goto handle_ifxx;
2662   case Bytecodes::_ifne: btest = BoolTest::ne; goto handle_ifxx;
2663   case Bytecodes::_iflt: btest = BoolTest::lt; goto handle_ifxx;
2664   case Bytecodes::_ifle: btest = BoolTest::le; goto handle_ifxx;
2665   case Bytecodes::_ifgt: btest = BoolTest::gt; goto handle_ifxx;
2666   case Bytecodes::_ifge: btest = BoolTest::ge; goto handle_ifxx;
2667   handle_ifxx:
2668     // If this is a backwards branch in the bytecodes, add Safepoint
2669     maybe_add_safepoint(iter().get_dest());
2670     a = _gvn.intcon(0);
2671     b = pop();
2672     c = _gvn.transform( new CmpINode(b, a) );
2673     do_if(btest, c);
2674     break;
2675 
2676   case Bytecodes::_if_icmpeq: btest = BoolTest::eq; goto handle_if_icmp;
2677   case Bytecodes::_if_icmpne: btest = BoolTest::ne; goto handle_if_icmp;
2678   case Bytecodes::_if_icmplt: btest = BoolTest::lt; goto handle_if_icmp;

2693     break;
2694 
2695   case Bytecodes::_lookupswitch:
2696     do_lookupswitch();
2697     break;
2698 
2699   case Bytecodes::_invokestatic:
2700   case Bytecodes::_invokedynamic:
2701   case Bytecodes::_invokespecial:
2702   case Bytecodes::_invokevirtual:
2703   case Bytecodes::_invokeinterface:
2704     do_call();
2705     break;
2706   case Bytecodes::_checkcast:
2707     do_checkcast();
2708     break;
2709   case Bytecodes::_instanceof:
2710     do_instanceof();
2711     break;
2712   case Bytecodes::_anewarray:
2713     do_anewarray();
2714     break;
2715   case Bytecodes::_newarray:
2716     do_newarray((BasicType)iter().get_index());
2717     break;
2718   case Bytecodes::_multianewarray:
2719     do_multianewarray();
2720     break;
2721   case Bytecodes::_new:
2722     do_new();
2723     break;






2724 
2725   case Bytecodes::_jsr:
2726   case Bytecodes::_jsr_w:
2727     do_jsr();
2728     break;
2729 
2730   case Bytecodes::_ret:
2731     do_ret();
2732     break;
2733 
2734 
2735   case Bytecodes::_monitorenter:
2736     do_monitor_enter();
2737     break;
2738 
2739   case Bytecodes::_monitorexit:
2740     do_monitor_exit();
2741     break;
2742 
2743   case Bytecodes::_breakpoint:

   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 "jvm_io.h"
  27 #include "ci/ciMethodData.hpp"
  28 #include "ci/ciSymbols.hpp"
  29 #include "classfile/vmSymbols.hpp"
  30 #include "compiler/compileLog.hpp"
  31 #include "interpreter/linkResolver.hpp"
  32 #include "memory/resourceArea.hpp"
  33 #include "memory/universe.hpp"
  34 #include "oops/oop.inline.hpp"
  35 #include "opto/addnode.hpp"
  36 #include "opto/castnode.hpp"
  37 #include "opto/convertnode.hpp"
  38 #include "opto/divnode.hpp"
  39 #include "opto/idealGraphPrinter.hpp"
  40 #include "opto/idealKit.hpp"
  41 #include "opto/inlinetypenode.hpp"
  42 #include "opto/matcher.hpp"
  43 #include "opto/memnode.hpp"
  44 #include "opto/mulnode.hpp"
  45 #include "opto/opaquenode.hpp"
  46 #include "opto/parse.hpp"
  47 #include "opto/runtime.hpp"
  48 #include "runtime/deoptimization.hpp"
  49 #include "runtime/sharedRuntime.hpp"
  50 
  51 #ifndef PRODUCT
  52 extern int explicit_null_checks_inserted,
  53            explicit_null_checks_elided;
  54 #endif
  55 
  56 Node* Parse::record_profile_for_speculation_at_array_load(Node* ld) {
  57   // Feed unused profile data to type speculation
  58   if (UseTypeSpeculation && UseArrayLoadStoreProfile) {
  59     ciKlass* array_type = NULL;
  60     ciKlass* element_type = NULL;
  61     ProfilePtrKind element_ptr = ProfileMaybeNull;
  62     bool flat_array = true;
  63     bool null_free_array = true;
  64     method()->array_access_profiled_type(bci(), array_type, element_type, element_ptr, flat_array, null_free_array);
  65     if (element_type != NULL || element_ptr != ProfileMaybeNull) {
  66       ld = record_profile_for_speculation(ld, element_type, element_ptr);
  67     }
  68   }
  69   return ld;
  70 }
  71 
  72 
  73 //---------------------------------array_load----------------------------------
  74 void Parse::array_load(BasicType bt) {
  75   const Type* elemtype = Type::TOP;

  76   Node* adr = array_addressing(bt, 0, elemtype);
  77   if (stopped())  return;     // guaranteed null or range check
  78 
  79   Node* idx = pop();
  80   Node* ary = pop();
  81 
  82   // Handle inline type arrays
  83   const TypeOopPtr* elemptr = elemtype->make_oopptr();
  84   const TypeAryPtr* ary_t = _gvn.type(ary)->is_aryptr();
  85   if (ary_t->is_flat()) {
  86     // Load from flattened inline type array
  87     Node* vt = InlineTypeNode::make_from_flattened(this, elemtype->inline_klass(), ary, adr);
  88     push(vt);
  89     return;
  90   } else if (ary_t->is_null_free()) {
  91     // Load from non-flattened inline type array (elements can never be null)
  92     bt = T_PRIMITIVE_OBJECT;
  93   } else if (!ary_t->is_not_flat()) {
  94     // Cannot statically determine if array is flattened, emit runtime check
  95     assert(UseFlatArray && is_reference_type(bt) && elemptr->can_be_inline_type() && !ary_t->klass_is_exact() && !ary_t->is_not_null_free() &&
  96            (!elemptr->is_inlinetypeptr() || elemptr->inline_klass()->flatten_array()), "array can't be flattened");
  97     IdealKit ideal(this);
  98     IdealVariable res(ideal);
  99     ideal.declarations_done();
 100     ideal.if_then(flat_array_test(ary, /* flat = */ false)); {
 101       // non-flattened
 102       assert(ideal.ctrl()->in(0)->as_If()->is_flat_array_check(&_gvn), "Should be found");
 103       sync_kit(ideal);
 104       const TypeAryPtr* adr_type = TypeAryPtr::get_array_body_type(bt);
 105       Node* ld = access_load_at(ary, adr, adr_type, elemptr, bt,
 106                                 IN_HEAP | IS_ARRAY | C2_CONTROL_DEPENDENT_LOAD);
 107       if (elemptr->is_inlinetypeptr()) {
 108         assert(elemptr->maybe_null(), "null free array should be handled above");
 109         ld = InlineTypeNode::make_from_oop(this, ld, elemptr->inline_klass(), false);
 110       }
 111       ideal.sync_kit(this);
 112       ideal.set(res, ld);
 113     } ideal.else_(); {
 114       // flattened
 115       sync_kit(ideal);
 116       if (elemptr->is_inlinetypeptr()) {
 117         // Element type is known, cast and load from flattened representation
 118         ciInlineKlass* vk = elemptr->inline_klass();
 119         assert(vk->flatten_array() && elemptr->maybe_null(), "never/always flat - should be optimized");
 120         ciArrayKlass* array_klass = ciArrayKlass::make(vk, /* null_free */ true);
 121         const TypeAryPtr* arytype = TypeOopPtr::make_from_klass(array_klass)->isa_aryptr();
 122         Node* cast = _gvn.transform(new CheckCastPPNode(control(), ary, arytype));
 123         Node* casted_adr = array_element_address(cast, idx, T_PRIMITIVE_OBJECT, ary_t->size(), control());
 124         // Re-execute flattened array load if buffering triggers deoptimization
 125         PreserveReexecuteState preexecs(this);
 126         jvms()->set_should_reexecute(true);
 127         inc_sp(2);
 128         Node* vt = InlineTypeNode::make_from_flattened(this, vk, cast, casted_adr)->buffer(this, false);
 129         ideal.set(res, vt);
 130         ideal.sync_kit(this);
 131       } else {
 132         // Element type is unknown, emit runtime call
 133 
 134         // Below membars keep this access to an unknown flattened array correctly
 135         // ordered with other unknown and known flattened array accesses.
 136         insert_mem_bar_volatile(Op_MemBarCPUOrder, C->get_alias_index(TypeAryPtr::INLINES));
 137 
 138         Node* call = NULL;
 139         {
 140           // Re-execute flattened array load if runtime call triggers deoptimization
 141           PreserveReexecuteState preexecs(this);
 142           jvms()->set_bci(_bci);
 143           jvms()->set_should_reexecute(true);
 144           inc_sp(2);
 145           kill_dead_locals();
 146           call = make_runtime_call(RC_NO_LEAF | RC_NO_IO,
 147                                    OptoRuntime::load_unknown_inline_type(),
 148                                    OptoRuntime::load_unknown_inline_Java(),
 149                                    NULL, TypeRawPtr::BOTTOM,
 150                                    ary, idx);
 151         }
 152         make_slow_call_ex(call, env()->Throwable_klass(), false);
 153         Node* buffer = _gvn.transform(new ProjNode(call, TypeFunc::Parms));
 154 
 155         insert_mem_bar_volatile(Op_MemBarCPUOrder, C->get_alias_index(TypeAryPtr::INLINES));
 156 
 157         // Keep track of the information that the inline type is flattened in arrays
 158         const Type* unknown_value = elemptr->is_instptr()->cast_to_flatten_array();
 159         buffer = _gvn.transform(new CheckCastPPNode(control(), buffer, unknown_value));
 160 
 161         ideal.sync_kit(this);
 162         ideal.set(res, buffer);
 163       }
 164     } ideal.end_if();
 165     sync_kit(ideal);
 166     Node* ld = _gvn.transform(ideal.value(res));
 167     ld = record_profile_for_speculation_at_array_load(ld);
 168     push_node(bt, ld);
 169     return;
 170   }
 171 
 172   if (elemtype == TypeInt::BOOL) {
 173     bt = T_BOOLEAN;
 174   }
 175   const TypeAryPtr* adr_type = TypeAryPtr::get_array_body_type(bt);
 176   Node* ld = access_load_at(ary, adr, adr_type, elemtype, bt,

 177                             IN_HEAP | IS_ARRAY | C2_CONTROL_DEPENDENT_LOAD);
 178   ld = record_profile_for_speculation_at_array_load(ld);
 179   // Loading a non-flattened inline type
 180   if (elemptr != NULL && elemptr->is_inlinetypeptr()) {
 181     assert(!ary_t->is_null_free() || !elemptr->maybe_null(), "inline type array elements should never be null");
 182     ld = InlineTypeNode::make_from_oop(this, ld, elemptr->inline_klass(), !elemptr->maybe_null());
 183   }
 184   push_node(bt, ld);
 185 }
 186 
 187 
 188 //--------------------------------array_store----------------------------------
 189 void Parse::array_store(BasicType bt) {
 190   const Type* elemtype = Type::TOP;
 191   Node* adr = array_addressing(bt, type2size[bt], elemtype);

 192   if (stopped())  return;     // guaranteed null or range check
 193   Node* cast_val = NULL;
 194   if (bt == T_OBJECT) {
 195     cast_val = array_store_check(adr, elemtype);
 196     if (stopped()) return;


 197   }
 198   Node* val = pop_node(bt); // Value to store
 199   Node* idx = pop();        // Index in the array
 200   Node* ary = pop();        // The array itself
 201 
 202   const TypeAryPtr* ary_t = _gvn.type(ary)->is_aryptr();
 203   const TypeAryPtr* adr_type = TypeAryPtr::get_array_body_type(bt);
 204   assert(adr->as_AddP()->in(AddPNode::Base) == ary, "inconsistent address base");

 205 
 206   if (elemtype == TypeInt::BOOL) {
 207     bt = T_BOOLEAN;
 208   } else if (bt == T_OBJECT) {
 209     elemtype = elemtype->make_oopptr();
 210     const Type* tval = _gvn.type(cast_val);
 211     // We may have lost type information for 'val' here due to the casts
 212     // emitted by the array_store_check code (see JDK-6312651)
 213     // TODO Remove this code once JDK-6312651 is in.
 214     const Type* tval_init = _gvn.type(val);
 215     // Based on the value to be stored, try to determine if the array is not null-free and/or not flat.
 216     // This is only legal for non-null stores because the array_store_check always passes for null, even
 217     // if the array is null-free. Null stores are handled in GraphKit::gen_inline_array_null_guard().
 218     bool not_inline = !tval->isa_inlinetype() &&
 219                       ((!tval_init->maybe_null() && !tval_init->is_oopptr()->can_be_inline_type()) ||
 220                        (!tval->maybe_null() && !tval->is_oopptr()->can_be_inline_type()));
 221     bool not_flattened = not_inline || ((tval_init->is_inlinetypeptr() || tval_init->isa_inlinetype()) && !tval_init->inline_klass()->flatten_array());
 222     if (!ary_t->is_not_null_free() && not_inline) {
 223       // Storing a non-inline type, mark array as not null-free (-> not flat).
 224       ary_t = ary_t->cast_to_not_null_free();
 225       Node* cast = _gvn.transform(new CheckCastPPNode(control(), ary, ary_t));
 226       replace_in_map(ary, cast);
 227       ary = cast;
 228     } else if (!ary_t->is_not_flat() && not_flattened) {
 229       // Storing a non-flattened value, mark array as not flat.
 230       ary_t = ary_t->cast_to_not_flat();
 231       Node* cast = _gvn.transform(new CheckCastPPNode(control(), ary, ary_t));
 232       replace_in_map(ary, cast);
 233       ary = cast;
 234     }
 235 
 236     if (ary_t->is_flat()) {
 237       // Store to flattened inline type array
 238       assert(!tval->maybe_null(), "should be guaranteed by array store check");
 239       // Re-execute flattened array store if buffering triggers deoptimization
 240       PreserveReexecuteState preexecs(this);
 241       inc_sp(3);
 242       jvms()->set_should_reexecute(true);
 243       cast_val->as_InlineTypeBase()->store_flattened(this, ary, adr, NULL, 0, MO_UNORDERED | IN_HEAP | IS_ARRAY);
 244       return;
 245     } else if (ary_t->is_null_free()) {
 246       // Store to non-flattened inline type array (elements can never be null)
 247       assert(!tval->maybe_null(), "should be guaranteed by array store check");
 248       if (elemtype->inline_klass()->is_empty()) {
 249         // Ignore empty inline stores, array is already initialized.
 250         return;
 251       }
 252     } else if (!ary_t->is_not_flat() && (tval != TypePtr::NULL_PTR || StressReflectiveCode)) {
 253       // Array might be flattened, emit runtime checks (for NULL, a simple inline_array_null_guard is sufficient).
 254       assert(UseFlatArray && !not_flattened && elemtype->is_oopptr()->can_be_inline_type() &&
 255              !ary_t->klass_is_exact() && !ary_t->is_not_null_free(), "array can't be flattened");
 256       IdealKit ideal(this);
 257       ideal.if_then(flat_array_test(ary, /* flat = */ false)); {
 258         // non-flattened
 259         assert(ideal.ctrl()->in(0)->as_If()->is_flat_array_check(&_gvn), "Should be found");
 260         sync_kit(ideal);
 261         Node* cast_ary = inline_array_null_guard(ary, cast_val, 3);
 262         inc_sp(3);
 263         access_store_at(cast_ary, adr, adr_type, cast_val, elemtype, bt, MO_UNORDERED | IN_HEAP | IS_ARRAY, false);
 264         dec_sp(3);
 265         ideal.sync_kit(this);
 266       } ideal.else_(); {
 267         sync_kit(ideal);
 268         // flattened
 269         Node* null_ctl = top();
 270         Node* val = null_check_oop(cast_val, &null_ctl);
 271         if (null_ctl != top()) {
 272           PreserveJVMState pjvms(this);
 273           inc_sp(3);
 274           set_control(null_ctl);
 275           uncommon_trap(Deoptimization::Reason_null_check, Deoptimization::Action_none);
 276           dec_sp(3);
 277         }
 278         // Try to determine the inline klass
 279         ciInlineKlass* vk = NULL;
 280         if (tval->isa_inlinetype() || tval->is_inlinetypeptr()) {
 281           vk = tval->inline_klass();
 282         } else if (tval_init->isa_inlinetype() || tval_init->is_inlinetypeptr()) {
 283           vk = tval_init->inline_klass();
 284         } else if (elemtype->is_inlinetypeptr()) {
 285           vk = elemtype->inline_klass();
 286         }
 287         Node* casted_ary = ary;
 288         if (vk != NULL && !stopped()) {
 289           // Element type is known, cast and store to flattened representation
 290           assert(vk->flatten_array() && elemtype->maybe_null(), "never/always flat - should be optimized");
 291           ciArrayKlass* array_klass = ciArrayKlass::make(vk, /* null_free */ true);
 292           const TypeAryPtr* arytype = TypeOopPtr::make_from_klass(array_klass)->isa_aryptr();
 293           casted_ary = _gvn.transform(new CheckCastPPNode(control(), casted_ary, arytype));
 294           Node* casted_adr = array_element_address(casted_ary, idx, T_OBJECT, arytype->size(), control());
 295           if (!val->is_InlineType()) {
 296             assert(!gvn().type(val)->maybe_null(), "inline type array elements should never be null");
 297             val = InlineTypeNode::make_from_oop(this, val, vk);
 298           }
 299           // Re-execute flattened array store if buffering triggers deoptimization
 300           PreserveReexecuteState preexecs(this);
 301           inc_sp(3);
 302           jvms()->set_should_reexecute(true);
 303           val->as_InlineTypeBase()->store_flattened(this, casted_ary, casted_adr, NULL, 0, MO_UNORDERED | IN_HEAP | IS_ARRAY);
 304         } else if (!stopped()) {
 305           // Element type is unknown, emit runtime call
 306 
 307           // Below membars keep this access to an unknown flattened array correctly
 308           // ordered with other unknown and known flattened array accesses.
 309           insert_mem_bar_volatile(Op_MemBarCPUOrder, C->get_alias_index(TypeAryPtr::INLINES));
 310 
 311           make_runtime_call(RC_LEAF,
 312                             OptoRuntime::store_unknown_inline_type(),
 313                             CAST_FROM_FN_PTR(address, OptoRuntime::store_unknown_inline),
 314                             "store_unknown_inline", TypeRawPtr::BOTTOM,
 315                             val, casted_ary, idx);
 316 
 317           insert_mem_bar_volatile(Op_MemBarCPUOrder, C->get_alias_index(TypeAryPtr::INLINES));
 318         }
 319         ideal.sync_kit(this);
 320       }
 321       ideal.end_if();
 322       sync_kit(ideal);
 323       return;
 324     } else if (!ary_t->is_not_null_free()) {
 325       // Array is not flattened but may be null free
 326       assert(elemtype->is_oopptr()->can_be_inline_type() && !ary_t->klass_is_exact(), "array can't be null-free");
 327       ary = inline_array_null_guard(ary, cast_val, 3, true);
 328     }
 329   }
 330   inc_sp(3);
 331   access_store_at(ary, adr, adr_type, val, elemtype, bt, MO_UNORDERED | IN_HEAP | IS_ARRAY);
 332   dec_sp(3);
 333 }
 334 
 335 
 336 //------------------------------array_addressing-------------------------------
 337 // Pull array and index from the stack.  Compute pointer-to-element.
 338 Node* Parse::array_addressing(BasicType type, int vals, const Type*& elemtype) {
 339   Node *idx   = peek(0+vals);   // Get from stack without popping
 340   Node *ary   = peek(1+vals);   // in case of exception
 341 
 342   // Null check the array base, with correct stack contents
 343   ary = null_check(ary, T_ARRAY);
 344   // Compile-time detect of null-exception?
 345   if (stopped())  return top();
 346 
 347   const TypeAryPtr* arytype  = _gvn.type(ary)->is_aryptr();
 348   const TypeInt*    sizetype = arytype->size();
 349   elemtype = arytype->elem();
 350 
 351   if (UseUniqueSubclasses) {
 352     const Type* el = elemtype->make_ptr();

 413       if (C->allow_range_check_smearing()) {
 414         // Do not use builtin_throw, since range checks are sometimes
 415         // made more stringent by an optimistic transformation.
 416         // This creates "tentative" range checks at this point,
 417         // which are not guaranteed to throw exceptions.
 418         // See IfNode::Ideal, is_range_check, adjust_check.
 419         uncommon_trap(Deoptimization::Reason_range_check,
 420                       Deoptimization::Action_make_not_entrant,
 421                       NULL, "range_check");
 422       } else {
 423         // If we have already recompiled with the range-check-widening
 424         // heroic optimization turned off, then we must really be throwing
 425         // range check exceptions.
 426         builtin_throw(Deoptimization::Reason_range_check);
 427       }
 428     }
 429   }
 430   // Check for always knowing you are throwing a range-check exception
 431   if (stopped())  return top();
 432 
 433   // This could be an access to an inline type array. We can't tell if it's
 434   // flat or not. Knowing the exact type avoids runtime checks and leads to
 435   // a much simpler graph shape. Check profile information.
 436   if (!arytype->is_flat() && !arytype->is_not_flat()) {
 437     // First check the speculative type
 438     Deoptimization::DeoptReason reason = Deoptimization::Reason_speculate_class_check;
 439     ciKlass* array_type = arytype->speculative_type();
 440     if (too_many_traps_or_recompiles(reason) || array_type == NULL) {
 441       // No speculative type, check profile data at this bci
 442       array_type = NULL;
 443       reason = Deoptimization::Reason_class_check;
 444       if (UseArrayLoadStoreProfile && !too_many_traps_or_recompiles(reason)) {
 445         ciKlass* element_type = NULL;
 446         ProfilePtrKind element_ptr = ProfileMaybeNull;
 447         bool flat_array = true;
 448         bool null_free_array = true;
 449         method()->array_access_profiled_type(bci(), array_type, element_type, element_ptr, flat_array, null_free_array);
 450       }
 451     }
 452     if (array_type != NULL) {
 453       // Speculate that this array has the exact type reported by profile data
 454       Node* better_ary = NULL;
 455       DEBUG_ONLY(Node* old_control = control();)
 456       Node* slow_ctl = type_check_receiver(ary, array_type, 1.0, &better_ary);
 457       if (stopped()) {
 458         // The check always fails and therefore profile information is incorrect. Don't use it.
 459         assert(old_control == slow_ctl, "type check should have been removed");
 460         set_control(slow_ctl);
 461       } else if (!slow_ctl->is_top()) {
 462         { PreserveJVMState pjvms(this);
 463           set_control(slow_ctl);
 464           uncommon_trap_exact(reason, Deoptimization::Action_maybe_recompile);
 465         }
 466         replace_in_map(ary, better_ary);
 467         ary = better_ary;
 468         arytype  = _gvn.type(ary)->is_aryptr();
 469         elemtype = arytype->elem();
 470       }
 471     }
 472   } else if (UseTypeSpeculation && UseArrayLoadStoreProfile) {
 473     // No need to speculate: feed profile data at this bci for the
 474     // array to type speculation
 475     ciKlass* array_type = NULL;
 476     ciKlass* element_type = NULL;
 477     ProfilePtrKind element_ptr = ProfileMaybeNull;
 478     bool flat_array = true;
 479     bool null_free_array = true;
 480     method()->array_access_profiled_type(bci(), array_type, element_type, element_ptr, flat_array, null_free_array);
 481     if (array_type != NULL) {
 482       ary = record_profile_for_speculation(ary, array_type, ProfileMaybeNull);
 483     }
 484   }
 485 
 486   // We have no exact array type from profile data. Check profile data
 487   // for a non null-free or non flat array. Non null-free implies non
 488   // flat so check this one first. Speculating on a non null-free
 489   // array doesn't help aaload but could be profitable for a
 490   // subsequent aastore.
 491   if (!arytype->is_null_free() && !arytype->is_not_null_free()) {
 492     bool null_free_array = true;
 493     Deoptimization::DeoptReason reason = Deoptimization::Reason_none;
 494     if (arytype->speculative() != NULL &&
 495         arytype->speculative()->is_aryptr()->is_not_null_free() &&
 496         !too_many_traps_or_recompiles(Deoptimization::Reason_speculate_class_check)) {
 497       null_free_array = false;
 498       reason = Deoptimization::Reason_speculate_class_check;
 499     } else if (UseArrayLoadStoreProfile && !too_many_traps_or_recompiles(Deoptimization::Reason_class_check)) {
 500       ciKlass* array_type = NULL;
 501       ciKlass* element_type = NULL;
 502       ProfilePtrKind element_ptr = ProfileMaybeNull;
 503       bool flat_array = true;
 504       method()->array_access_profiled_type(bci(), array_type, element_type, element_ptr, flat_array, null_free_array);
 505       reason = Deoptimization::Reason_class_check;
 506     }
 507     if (!null_free_array) {
 508       { // Deoptimize if null-free array
 509         BuildCutout unless(this, null_free_array_test(load_object_klass(ary), /* null_free = */ false), PROB_MAX);
 510         uncommon_trap_exact(reason, Deoptimization::Action_maybe_recompile);
 511       }
 512       assert(!stopped(), "null-free array should have been caught earlier");
 513       Node* better_ary = _gvn.transform(new CheckCastPPNode(control(), ary, arytype->cast_to_not_null_free()));
 514       replace_in_map(ary, better_ary);
 515       ary = better_ary;
 516       arytype = _gvn.type(ary)->is_aryptr();
 517     }
 518   }
 519 
 520   if (!arytype->is_flat() && !arytype->is_not_flat()) {
 521     bool flat_array = true;
 522     Deoptimization::DeoptReason reason = Deoptimization::Reason_none;
 523     if (arytype->speculative() != NULL &&
 524         arytype->speculative()->is_aryptr()->is_not_flat() &&
 525         !too_many_traps_or_recompiles(Deoptimization::Reason_speculate_class_check)) {
 526       flat_array = false;
 527       reason = Deoptimization::Reason_speculate_class_check;
 528     } else if (UseArrayLoadStoreProfile && !too_many_traps_or_recompiles(reason)) {
 529       ciKlass* array_type = NULL;
 530       ciKlass* element_type = NULL;
 531       ProfilePtrKind element_ptr = ProfileMaybeNull;
 532       bool null_free_array = true;
 533       method()->array_access_profiled_type(bci(), array_type, element_type, element_ptr, flat_array, null_free_array);
 534       reason = Deoptimization::Reason_class_check;
 535     }
 536     if (!flat_array) {
 537       { // Deoptimize if flat array
 538         BuildCutout unless(this, flat_array_test(ary, /* flat = */ false), PROB_MAX);
 539         uncommon_trap_exact(reason, Deoptimization::Action_maybe_recompile);
 540       }
 541       assert(!stopped(), "flat array should have been caught earlier");
 542       Node* better_ary = _gvn.transform(new CheckCastPPNode(control(), ary, arytype->cast_to_not_flat()));
 543       replace_in_map(ary, better_ary);
 544       ary = better_ary;
 545       arytype = _gvn.type(ary)->is_aryptr();
 546     }
 547   }
 548 
 549   // Make array address computation control dependent to prevent it
 550   // from floating above the range check during loop optimizations.
 551   Node* ptr = array_element_address(ary, idx, type, sizetype, control());
 552   assert(ptr != top(), "top should go hand-in-hand with stopped");
 553 
 554   return ptr;
 555 }
 556 
 557 
 558 // returns IfNode
 559 IfNode* Parse::jump_if_fork_int(Node* a, Node* b, BoolTest::mask mask, float prob, float cnt) {
 560   Node   *cmp = _gvn.transform(new CmpINode(a, b)); // two cases: shiftcount > 32 and shiftcount <= 32
 561   Node   *tst = _gvn.transform(new BoolNode(cmp, mask));
 562   IfNode *iff = create_and_map_if(control(), tst, prob, cnt);
 563   return iff;
 564 }
 565 
 566 
 567 // sentinel value for the target bci to mark never taken branches
 568 // (according to profiling)

1760       }
1761     }
1762   }
1763 
1764   // False branch
1765   Node* iffalse = _gvn.transform( new IfFalseNode(iff) );
1766   set_control(iffalse);
1767 
1768   if (stopped()) {              // Path is dead?
1769     NOT_PRODUCT(explicit_null_checks_elided++);
1770     if (C->eliminate_boxing()) {
1771       // Mark the successor block as parsed
1772       next_block->next_path_num();
1773     }
1774   } else  {                     // Path is live.
1775     adjust_map_after_if(BoolTest(btest).negate(), c, 1.0-prob, next_block);
1776   }
1777 }
1778 
1779 //------------------------------------do_if------------------------------------
1780 void Parse::do_if(BoolTest::mask btest, Node* c, bool new_path, Node** ctrl_taken) {
1781   int target_bci = iter().get_dest();
1782 
1783   Block* branch_block = successor_for_bci(target_bci);
1784   Block* next_block   = successor_for_bci(iter().next_bci());
1785 
1786   float cnt;
1787   float prob = branch_prediction(cnt, btest, target_bci, c);
1788   float untaken_prob = 1.0 - prob;
1789 
1790   if (prob == PROB_UNKNOWN) {
1791     if (PrintOpto && Verbose) {
1792       tty->print_cr("Never-taken edge stops compilation at bci %d", bci());
1793     }
1794     repush_if_args(); // to gather stats on loop
1795     uncommon_trap(Deoptimization::Reason_unreached,
1796                   Deoptimization::Action_reinterpret,
1797                   NULL, "cold");
1798     if (C->eliminate_boxing()) {
1799       // Mark the successor blocks as parsed
1800       branch_block->next_path_num();

1844   }
1845 
1846   // Generate real control flow
1847   float true_prob = (taken_if_true ? prob : untaken_prob);
1848   IfNode* iff = create_and_map_if(control(), tst, true_prob, cnt);
1849   assert(iff->_prob > 0.0f,"Optimizer made bad probability in parser");
1850   Node* taken_branch   = new IfTrueNode(iff);
1851   Node* untaken_branch = new IfFalseNode(iff);
1852   if (!taken_if_true) {  // Finish conversion to canonical form
1853     Node* tmp      = taken_branch;
1854     taken_branch   = untaken_branch;
1855     untaken_branch = tmp;
1856   }
1857 
1858   // Branch is taken:
1859   { PreserveJVMState pjvms(this);
1860     taken_branch = _gvn.transform(taken_branch);
1861     set_control(taken_branch);
1862 
1863     if (stopped()) {
1864       if (C->eliminate_boxing() && !new_path) {
1865         // Mark the successor block as parsed (if we haven't created a new path)
1866         branch_block->next_path_num();
1867       }
1868     } else {
1869       adjust_map_after_if(taken_btest, c, prob, branch_block);
1870       if (!stopped()) {
1871         if (new_path) {
1872           // Merge by using a new path
1873           merge_new_path(target_bci);
1874         } else if (ctrl_taken != NULL) {
1875           // Don't merge but save taken branch to be wired by caller
1876           *ctrl_taken = control();
1877         } else {
1878           merge(target_bci);
1879         }
1880       }
1881     }
1882   }
1883 
1884   untaken_branch = _gvn.transform(untaken_branch);
1885   set_control(untaken_branch);
1886 
1887   // Branch not taken.
1888   if (stopped() && ctrl_taken == NULL) {
1889     if (C->eliminate_boxing()) {
1890       // Mark the successor block as parsed (if caller does not re-wire control flow)
1891       next_block->next_path_num();
1892     }
1893   } else {
1894     adjust_map_after_if(untaken_btest, c, untaken_prob, next_block);
1895   }
1896 }
1897 
1898 
1899 static ProfilePtrKind speculative_ptr_kind(const TypeOopPtr* t) {
1900   if (t->speculative() == NULL) {
1901     return ProfileUnknownNull;
1902   }
1903   if (t->speculative_always_null()) {
1904     return ProfileAlwaysNull;
1905   }
1906   if (t->speculative_maybe_null()) {
1907     return ProfileMaybeNull;
1908   }
1909   return ProfileNeverNull;
1910 }
1911 
1912 void Parse::acmp_always_null_input(Node* input, const TypeOopPtr* tinput, BoolTest::mask btest, Node* eq_region) {
1913   inc_sp(2);
1914   Node* cast = null_check_common(input, T_OBJECT, true, NULL,
1915                                  !too_many_traps_or_recompiles(Deoptimization::Reason_speculate_null_check) &&
1916                                  speculative_ptr_kind(tinput) == ProfileAlwaysNull);
1917   dec_sp(2);
1918   if (btest == BoolTest::ne) {
1919     {
1920       PreserveJVMState pjvms(this);
1921       replace_in_map(input, cast);
1922       int target_bci = iter().get_dest();
1923       merge(target_bci);
1924     }
1925     record_for_igvn(eq_region);
1926     set_control(_gvn.transform(eq_region));
1927   } else {
1928     replace_in_map(input, cast);
1929   }
1930 }
1931 
1932 Node* Parse::acmp_null_check(Node* input, const TypeOopPtr* tinput, ProfilePtrKind input_ptr, Node*& null_ctl) {
1933   inc_sp(2);
1934   null_ctl = top();
1935   Node* cast = null_check_oop(input, &null_ctl,
1936                               input_ptr == ProfileNeverNull || (input_ptr == ProfileUnknownNull && !too_many_traps_or_recompiles(Deoptimization::Reason_null_check)),
1937                               false,
1938                               speculative_ptr_kind(tinput) == ProfileNeverNull &&
1939                               !too_many_traps_or_recompiles(Deoptimization::Reason_speculate_null_check));
1940   dec_sp(2);
1941   assert(!stopped(), "null input should have been caught earlier");
1942   if (cast->is_InlineType()) {
1943     cast = cast->as_InlineType()->get_oop();
1944   }
1945   return cast;
1946 }
1947 
1948 void Parse::acmp_known_non_inline_type_input(Node* input, const TypeOopPtr* tinput, ProfilePtrKind input_ptr, ciKlass* input_type, BoolTest::mask btest, Node* eq_region) {
1949   Node* ne_region = new RegionNode(1);
1950   Node* null_ctl;
1951   Node* cast = acmp_null_check(input, tinput, input_ptr, null_ctl);
1952   ne_region->add_req(null_ctl);
1953 
1954   Node* slow_ctl = type_check_receiver(cast, input_type, 1.0, &cast);
1955   {
1956     PreserveJVMState pjvms(this);
1957     inc_sp(2);
1958     set_control(slow_ctl);
1959     Deoptimization::DeoptReason reason;
1960     if (tinput->speculative_type() != NULL && !too_many_traps_or_recompiles(Deoptimization::Reason_speculate_class_check)) {
1961       reason = Deoptimization::Reason_speculate_class_check;
1962     } else {
1963       reason = Deoptimization::Reason_class_check;
1964     }
1965     uncommon_trap_exact(reason, Deoptimization::Action_maybe_recompile);
1966   }
1967   ne_region->add_req(control());
1968 
1969   record_for_igvn(ne_region);
1970   set_control(_gvn.transform(ne_region));
1971   if (btest == BoolTest::ne) {
1972     {
1973       PreserveJVMState pjvms(this);
1974       if (null_ctl == top()) {
1975         replace_in_map(input, cast);
1976       }
1977       int target_bci = iter().get_dest();
1978       merge(target_bci);
1979     }
1980     record_for_igvn(eq_region);
1981     set_control(_gvn.transform(eq_region));
1982   } else {
1983     if (null_ctl == top()) {
1984       replace_in_map(input, cast);
1985     }
1986     set_control(_gvn.transform(ne_region));
1987   }
1988 }
1989 
1990 void Parse::acmp_unknown_non_inline_type_input(Node* input, const TypeOopPtr* tinput, ProfilePtrKind input_ptr, BoolTest::mask btest, Node* eq_region) {
1991   Node* ne_region = new RegionNode(1);
1992   Node* null_ctl;
1993   Node* cast = acmp_null_check(input, tinput, input_ptr, null_ctl);
1994   ne_region->add_req(null_ctl);
1995 
1996   {
1997     BuildCutout unless(this, inline_type_test(cast, /* is_inline = */ false), PROB_MAX);
1998     inc_sp(2);
1999     uncommon_trap_exact(Deoptimization::Reason_class_check, Deoptimization::Action_maybe_recompile);
2000   }
2001 
2002   ne_region->add_req(control());
2003 
2004   record_for_igvn(ne_region);
2005   set_control(_gvn.transform(ne_region));
2006   if (btest == BoolTest::ne) {
2007     {
2008       PreserveJVMState pjvms(this);
2009       if (null_ctl == top()) {
2010         replace_in_map(input, cast);
2011       }
2012       int target_bci = iter().get_dest();
2013       merge(target_bci);
2014     }
2015     record_for_igvn(eq_region);
2016     set_control(_gvn.transform(eq_region));
2017   } else {
2018     if (null_ctl == top()) {
2019       replace_in_map(input, cast);
2020     }
2021     set_control(_gvn.transform(ne_region));
2022   }
2023 }
2024 
2025 void Parse::do_acmp(BoolTest::mask btest, Node* left, Node* right) {
2026   ciKlass* left_type = NULL;
2027   ciKlass* right_type = NULL;
2028   ProfilePtrKind left_ptr = ProfileUnknownNull;
2029   ProfilePtrKind right_ptr = ProfileUnknownNull;
2030   bool left_inline_type = true;
2031   bool right_inline_type = true;
2032 
2033   // Leverage profiling at acmp
2034   if (UseACmpProfile) {
2035     method()->acmp_profiled_type(bci(), left_type, right_type, left_ptr, right_ptr, left_inline_type, right_inline_type);
2036     if (too_many_traps_or_recompiles(Deoptimization::Reason_class_check)) {
2037       left_type = NULL;
2038       right_type = NULL;
2039       left_inline_type = true;
2040       right_inline_type = true;
2041     }
2042     if (too_many_traps_or_recompiles(Deoptimization::Reason_null_check)) {
2043       left_ptr = ProfileUnknownNull;
2044       right_ptr = ProfileUnknownNull;
2045     }
2046   }
2047 
2048   if (UseTypeSpeculation) {
2049     record_profile_for_speculation(left, left_type, left_ptr);
2050     record_profile_for_speculation(right, right_type, right_ptr);
2051   }
2052 
2053   if (!EnableValhalla) {
2054     Node* cmp = CmpP(left, right);
2055     cmp = optimize_cmp_with_klass(cmp);
2056     do_if(btest, cmp);
2057     return;
2058   }
2059 
2060   // Check for equality before potentially allocating
2061   if (left == right) {
2062     do_if(btest, makecon(TypeInt::CC_EQ));
2063     return;
2064   }
2065 
2066   // Allocate inline type operands and re-execute on deoptimization
2067   if (left->is_InlineTypeBase()) {
2068     if (_gvn.type(right)->is_zero_type() ||
2069         (right->is_InlineTypeBase() && _gvn.type(right->as_InlineTypeBase()->get_is_init())->is_zero_type())) {
2070       // Null checking a scalarized but nullable inline type. Check the IsInit
2071       // input instead of the oop input to avoid keeping buffer allocations alive.
2072       Node* cmp = CmpI(left->as_InlineTypeBase()->get_is_init(), intcon(0));
2073       do_if(btest, cmp);
2074       return;
2075     } else if (left->is_InlineType()){
2076       PreserveReexecuteState preexecs(this);
2077       inc_sp(2);
2078       jvms()->set_should_reexecute(true);
2079       left = left->as_InlineType()->buffer(this)->get_oop();
2080     }
2081   }
2082   if (right->is_InlineType()) {
2083     PreserveReexecuteState preexecs(this);
2084     inc_sp(2);
2085     jvms()->set_should_reexecute(true);
2086     right = right->as_InlineType()->buffer(this)->get_oop();
2087   }
2088 
2089   // First, do a normal pointer comparison
2090   const TypeOopPtr* tleft = _gvn.type(left)->isa_oopptr();
2091   const TypeOopPtr* tright = _gvn.type(right)->isa_oopptr();
2092   Node* cmp = CmpP(left, right);
2093   cmp = optimize_cmp_with_klass(cmp);
2094   if (tleft == NULL || !tleft->can_be_inline_type() ||
2095       tright == NULL || !tright->can_be_inline_type()) {
2096     // This is sufficient, if one of the operands can't be an inline type
2097     do_if(btest, cmp);
2098     return;
2099   }
2100   Node* eq_region = NULL;
2101   if (btest == BoolTest::eq) {
2102     do_if(btest, cmp, true);
2103     if (stopped()) {
2104       return;
2105     }
2106   } else {
2107     assert(btest == BoolTest::ne, "only eq or ne");
2108     Node* is_not_equal = NULL;
2109     eq_region = new RegionNode(3);
2110     {
2111       PreserveJVMState pjvms(this);
2112       do_if(btest, cmp, false, &is_not_equal);
2113       if (!stopped()) {
2114         eq_region->init_req(1, control());
2115       }
2116     }
2117     if (is_not_equal == NULL || is_not_equal->is_top()) {
2118       record_for_igvn(eq_region);
2119       set_control(_gvn.transform(eq_region));
2120       return;
2121     }
2122     set_control(is_not_equal);
2123   }
2124 
2125   // Prefer speculative types if available
2126   if (!too_many_traps_or_recompiles(Deoptimization::Reason_speculate_class_check)) {
2127     if (tleft->speculative_type() != NULL) {
2128       left_type = tleft->speculative_type();
2129     }
2130     if (tright->speculative_type() != NULL) {
2131       right_type = tright->speculative_type();
2132     }
2133   }
2134 
2135   if (speculative_ptr_kind(tleft) != ProfileMaybeNull && speculative_ptr_kind(tleft) != ProfileUnknownNull) {
2136     ProfilePtrKind speculative_left_ptr = speculative_ptr_kind(tleft);
2137     if (speculative_left_ptr == ProfileAlwaysNull && !too_many_traps_or_recompiles(Deoptimization::Reason_speculate_null_assert)) {
2138       left_ptr = speculative_left_ptr;
2139     } else if (speculative_left_ptr == ProfileNeverNull && !too_many_traps_or_recompiles(Deoptimization::Reason_speculate_null_check)) {
2140       left_ptr = speculative_left_ptr;
2141     }
2142   }
2143   if (speculative_ptr_kind(tright) != ProfileMaybeNull && speculative_ptr_kind(tright) != ProfileUnknownNull) {
2144     ProfilePtrKind speculative_right_ptr = speculative_ptr_kind(tright);
2145     if (speculative_right_ptr == ProfileAlwaysNull && !too_many_traps_or_recompiles(Deoptimization::Reason_speculate_null_assert)) {
2146       right_ptr = speculative_right_ptr;
2147     } else if (speculative_right_ptr == ProfileNeverNull && !too_many_traps_or_recompiles(Deoptimization::Reason_speculate_null_check)) {
2148       right_ptr = speculative_right_ptr;
2149     }
2150   }
2151 
2152   if (left_ptr == ProfileAlwaysNull) {
2153     // Comparison with null. Assert the input is indeed null and we're done.
2154     acmp_always_null_input(left, tleft, btest, eq_region);
2155     return;
2156   }
2157   if (right_ptr == ProfileAlwaysNull) {
2158     // Comparison with null. Assert the input is indeed null and we're done.
2159     acmp_always_null_input(right, tright, btest, eq_region);
2160     return;
2161   }
2162   if (left_type != NULL && !left_type->is_inlinetype()) {
2163     // Comparison with an object of known type
2164     acmp_known_non_inline_type_input(left, tleft, left_ptr, left_type, btest, eq_region);
2165     return;
2166   }
2167   if (right_type != NULL && !right_type->is_inlinetype()) {
2168     // Comparison with an object of known type
2169     acmp_known_non_inline_type_input(right, tright, right_ptr, right_type, btest, eq_region);
2170     return;
2171   }
2172   if (!left_inline_type) {
2173     // Comparison with an object known not to be an inline type
2174     acmp_unknown_non_inline_type_input(left, tleft, left_ptr, btest, eq_region);
2175     return;
2176   }
2177   if (!right_inline_type) {
2178     // Comparison with an object known not to be an inline type
2179     acmp_unknown_non_inline_type_input(right, tright, right_ptr, btest, eq_region);
2180     return;
2181   }
2182 
2183   // Pointers are not equal, check if first operand is non-null
2184   Node* ne_region = new RegionNode(6);
2185   Node* null_ctl;
2186   Node* not_null_right = acmp_null_check(right, tright, right_ptr, null_ctl);
2187   ne_region->init_req(1, null_ctl);
2188 
2189   // First operand is non-null, check if it is an inline type
2190   Node* is_value = inline_type_test(not_null_right);
2191   IfNode* is_value_iff = create_and_map_if(control(), is_value, PROB_FAIR, COUNT_UNKNOWN);
2192   Node* not_value = _gvn.transform(new IfFalseNode(is_value_iff));
2193   ne_region->init_req(2, not_value);
2194   set_control(_gvn.transform(new IfTrueNode(is_value_iff)));
2195 
2196   // The first operand is an inline type, check if the second operand is non-null
2197   Node* not_null_left = acmp_null_check(left, tleft, left_ptr, null_ctl);
2198   ne_region->init_req(3, null_ctl);
2199 
2200   // Check if both operands are of the same class.
2201   Node* kls_left = load_object_klass(not_null_left);
2202   Node* kls_right = load_object_klass(not_null_right);
2203   Node* kls_cmp = CmpP(kls_left, kls_right);
2204   Node* kls_bol = _gvn.transform(new BoolNode(kls_cmp, BoolTest::ne));
2205   IfNode* kls_iff = create_and_map_if(control(), kls_bol, PROB_FAIR, COUNT_UNKNOWN);
2206   Node* kls_ne = _gvn.transform(new IfTrueNode(kls_iff));
2207   set_control(_gvn.transform(new IfFalseNode(kls_iff)));
2208   ne_region->init_req(4, kls_ne);
2209 
2210   if (stopped()) {
2211     record_for_igvn(ne_region);
2212     set_control(_gvn.transform(ne_region));
2213     if (btest == BoolTest::ne) {
2214       {
2215         PreserveJVMState pjvms(this);
2216         int target_bci = iter().get_dest();
2217         merge(target_bci);
2218       }
2219       record_for_igvn(eq_region);
2220       set_control(_gvn.transform(eq_region));
2221     }
2222     return;
2223   }
2224 
2225   // Both operands are values types of the same class, we need to perform a
2226   // substitutability test. Delegate to PrimitiveObjectMethods::isSubstitutable().
2227   Node* ne_io_phi = PhiNode::make(ne_region, i_o());
2228   Node* mem = reset_memory();
2229   Node* ne_mem_phi = PhiNode::make(ne_region, mem);
2230 
2231   Node* eq_io_phi = NULL;
2232   Node* eq_mem_phi = NULL;
2233   if (eq_region != NULL) {
2234     eq_io_phi = PhiNode::make(eq_region, i_o());
2235     eq_mem_phi = PhiNode::make(eq_region, mem);
2236   }
2237 
2238   set_all_memory(mem);
2239 
2240   kill_dead_locals();
2241   ciMethod* subst_method = ciEnv::current()->PrimitiveObjectMethods_klass()->find_method(ciSymbols::isSubstitutable_name(), ciSymbols::object_object_boolean_signature());
2242   CallStaticJavaNode *call = new CallStaticJavaNode(C, TypeFunc::make(subst_method), SharedRuntime::get_resolve_static_call_stub(), subst_method);
2243   call->set_override_symbolic_info(true);
2244   call->init_req(TypeFunc::Parms, not_null_left);
2245   call->init_req(TypeFunc::Parms+1, not_null_right);
2246   inc_sp(2);
2247   set_edges_for_java_call(call, false, false);
2248   Node* ret = set_results_for_java_call(call, false, true);
2249   dec_sp(2);
2250 
2251   // Test the return value of PrimitiveObjectMethods::isSubstitutable()
2252   Node* subst_cmp = _gvn.transform(new CmpINode(ret, intcon(1)));
2253   Node* ctl = C->top();
2254   if (btest == BoolTest::eq) {
2255     PreserveJVMState pjvms(this);
2256     do_if(btest, subst_cmp);
2257     if (!stopped()) {
2258       ctl = control();
2259     }
2260   } else {
2261     assert(btest == BoolTest::ne, "only eq or ne");
2262     PreserveJVMState pjvms(this);
2263     do_if(btest, subst_cmp, false, &ctl);
2264     if (!stopped()) {
2265       eq_region->init_req(2, control());
2266       eq_io_phi->init_req(2, i_o());
2267       eq_mem_phi->init_req(2, reset_memory());
2268     }
2269   }
2270   ne_region->init_req(5, ctl);
2271   ne_io_phi->init_req(5, i_o());
2272   ne_mem_phi->init_req(5, reset_memory());
2273 
2274   record_for_igvn(ne_region);
2275   set_control(_gvn.transform(ne_region));
2276   set_i_o(_gvn.transform(ne_io_phi));
2277   set_all_memory(_gvn.transform(ne_mem_phi));
2278 
2279   if (btest == BoolTest::ne) {
2280     {
2281       PreserveJVMState pjvms(this);
2282       int target_bci = iter().get_dest();
2283       merge(target_bci);
2284     }
2285 
2286     record_for_igvn(eq_region);
2287     set_control(_gvn.transform(eq_region));
2288     set_i_o(_gvn.transform(eq_io_phi));
2289     set_all_memory(_gvn.transform(eq_mem_phi));
2290   }
2291 }
2292 
2293 bool Parse::path_is_suitable_for_uncommon_trap(float prob) const {
2294   // Don't want to speculate on uncommon traps when running with -Xcomp
2295   if (!UseInterpreter) {
2296     return false;
2297   }
2298   return (seems_never_taken(prob) && seems_stable_comparison());
2299 }
2300 
2301 void Parse::maybe_add_predicate_after_if(Block* path) {
2302   if (path->is_SEL_head() && path->preds_parsed() == 0) {
2303     // Add predicates at bci of if dominating the loop so traps can be
2304     // recorded on the if's profile data
2305     int bc_depth = repush_if_args();
2306     add_empty_predicates();
2307     dec_sp(bc_depth);
2308     path->set_has_predicates();
2309   }
2310 }
2311 
2312 

2513   if (c->Opcode() == Op_CmpP &&
2514       (c->in(1)->Opcode() == Op_LoadKlass || c->in(1)->Opcode() == Op_DecodeNKlass) &&
2515       c->in(2)->is_Con()) {
2516     Node* load_klass = NULL;
2517     Node* decode = NULL;
2518     if (c->in(1)->Opcode() == Op_DecodeNKlass) {
2519       decode = c->in(1);
2520       load_klass = c->in(1)->in(1);
2521     } else {
2522       load_klass = c->in(1);
2523     }
2524     if (load_klass->in(2)->is_AddP()) {
2525       Node* addp = load_klass->in(2);
2526       Node* obj = addp->in(AddPNode::Address);
2527       const TypeOopPtr* obj_type = _gvn.type(obj)->is_oopptr();
2528       if (obj_type->speculative_type_not_null() != NULL) {
2529         ciKlass* k = obj_type->speculative_type();
2530         inc_sp(2);
2531         obj = maybe_cast_profiled_obj(obj, k);
2532         dec_sp(2);
2533         if (obj->is_InlineType()) {
2534           assert(obj->as_InlineType()->is_allocated(&_gvn), "must be allocated");
2535           obj = obj->as_InlineType()->get_oop();
2536         }
2537         // Make the CmpP use the casted obj
2538         addp = basic_plus_adr(obj, addp->in(AddPNode::Offset));
2539         load_klass = load_klass->clone();
2540         load_klass->set_req(2, addp);
2541         load_klass = _gvn.transform(load_klass);
2542         if (decode != NULL) {
2543           decode = decode->clone();
2544           decode->set_req(1, load_klass);
2545           load_klass = _gvn.transform(decode);
2546         }
2547         c = c->clone();
2548         c->set_req(1, load_klass);
2549         c = _gvn.transform(c);
2550       }
2551     }
2552   }
2553   return c;
2554 }
2555 
2556 //------------------------------do_one_bytecode--------------------------------

3363     // See if we can get some profile data and hand it off to the next block
3364     Block *target_block = block()->successor_for_bci(target_bci);
3365     if (target_block->pred_count() != 1)  break;
3366     ciMethodData* methodData = method()->method_data();
3367     if (!methodData->is_mature())  break;
3368     ciProfileData* data = methodData->bci_to_data(bci());
3369     assert(data != NULL && data->is_JumpData(), "need JumpData for taken branch");
3370     int taken = ((ciJumpData*)data)->taken();
3371     taken = method()->scale_count(taken);
3372     target_block->set_count(taken);
3373     break;
3374   }
3375 
3376   case Bytecodes::_ifnull:    btest = BoolTest::eq; goto handle_if_null;
3377   case Bytecodes::_ifnonnull: btest = BoolTest::ne; goto handle_if_null;
3378   handle_if_null:
3379     // If this is a backwards branch in the bytecodes, add Safepoint
3380     maybe_add_safepoint(iter().get_dest());
3381     a = null();
3382     b = pop();
3383     if (b->is_InlineType()) {
3384       // Null checking a scalarized but nullable inline type. Check the IsInit
3385       // input instead of the oop input to avoid keeping buffer allocations alive
3386       c = _gvn.transform(new CmpINode(b->as_InlineType()->get_is_init(), zerocon(T_INT)));
3387     } else {
3388       if (!_gvn.type(b)->speculative_maybe_null() &&
3389           !too_many_traps(Deoptimization::Reason_speculate_null_check)) {
3390         inc_sp(1);
3391         Node* null_ctl = top();
3392         b = null_check_oop(b, &null_ctl, true, true, true);
3393         assert(null_ctl->is_top(), "no null control here");
3394         dec_sp(1);
3395       } else if (_gvn.type(b)->speculative_always_null() &&
3396                  !too_many_traps(Deoptimization::Reason_speculate_null_assert)) {
3397         inc_sp(1);
3398         b = null_assert(b);
3399         dec_sp(1);
3400       }
3401       c = _gvn.transform( new CmpPNode(b, a) );
3402     }
3403     do_ifnull(btest, c);
3404     break;
3405 
3406   case Bytecodes::_if_acmpeq: btest = BoolTest::eq; goto handle_if_acmp;
3407   case Bytecodes::_if_acmpne: btest = BoolTest::ne; goto handle_if_acmp;
3408   handle_if_acmp:
3409     // If this is a backwards branch in the bytecodes, add Safepoint
3410     maybe_add_safepoint(iter().get_dest());
3411     a = pop();
3412     b = pop();
3413     do_acmp(btest, b, a);


3414     break;
3415 
3416   case Bytecodes::_ifeq: btest = BoolTest::eq; goto handle_ifxx;
3417   case Bytecodes::_ifne: btest = BoolTest::ne; goto handle_ifxx;
3418   case Bytecodes::_iflt: btest = BoolTest::lt; goto handle_ifxx;
3419   case Bytecodes::_ifle: btest = BoolTest::le; goto handle_ifxx;
3420   case Bytecodes::_ifgt: btest = BoolTest::gt; goto handle_ifxx;
3421   case Bytecodes::_ifge: btest = BoolTest::ge; goto handle_ifxx;
3422   handle_ifxx:
3423     // If this is a backwards branch in the bytecodes, add Safepoint
3424     maybe_add_safepoint(iter().get_dest());
3425     a = _gvn.intcon(0);
3426     b = pop();
3427     c = _gvn.transform( new CmpINode(b, a) );
3428     do_if(btest, c);
3429     break;
3430 
3431   case Bytecodes::_if_icmpeq: btest = BoolTest::eq; goto handle_if_icmp;
3432   case Bytecodes::_if_icmpne: btest = BoolTest::ne; goto handle_if_icmp;
3433   case Bytecodes::_if_icmplt: btest = BoolTest::lt; goto handle_if_icmp;

3448     break;
3449 
3450   case Bytecodes::_lookupswitch:
3451     do_lookupswitch();
3452     break;
3453 
3454   case Bytecodes::_invokestatic:
3455   case Bytecodes::_invokedynamic:
3456   case Bytecodes::_invokespecial:
3457   case Bytecodes::_invokevirtual:
3458   case Bytecodes::_invokeinterface:
3459     do_call();
3460     break;
3461   case Bytecodes::_checkcast:
3462     do_checkcast();
3463     break;
3464   case Bytecodes::_instanceof:
3465     do_instanceof();
3466     break;
3467   case Bytecodes::_anewarray:
3468     do_newarray();
3469     break;
3470   case Bytecodes::_newarray:
3471     do_newarray((BasicType)iter().get_index());
3472     break;
3473   case Bytecodes::_multianewarray:
3474     do_multianewarray();
3475     break;
3476   case Bytecodes::_new:
3477     do_new();
3478     break;
3479   case Bytecodes::_aconst_init:
3480     do_aconst_init();
3481     break;
3482   case Bytecodes::_withfield:
3483     do_withfield();
3484     break;
3485 
3486   case Bytecodes::_jsr:
3487   case Bytecodes::_jsr_w:
3488     do_jsr();
3489     break;
3490 
3491   case Bytecodes::_ret:
3492     do_ret();
3493     break;
3494 
3495 
3496   case Bytecodes::_monitorenter:
3497     do_monitor_enter();
3498     break;
3499 
3500   case Bytecodes::_monitorexit:
3501     do_monitor_exit();
3502     break;
3503 
3504   case Bytecodes::_breakpoint:
< prev index next >