< prev index next >

src/hotspot/share/opto/parse2.cpp

Print this page

   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "ci/ciMethodData.hpp"

  27 #include "classfile/vmSymbols.hpp"
  28 #include "compiler/compileLog.hpp"
  29 #include "interpreter/linkResolver.hpp"
  30 #include "jvm_io.h"
  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:

   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "ci/ciMethodData.hpp"
  27 #include "ci/ciSymbols.hpp"
  28 #include "classfile/vmSymbols.hpp"
  29 #include "compiler/compileLog.hpp"
  30 #include "interpreter/linkResolver.hpp"
  31 #include "jvm_io.h"
  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 
 205   if (elemtype == TypeInt::BOOL) {
 206     bt = T_BOOLEAN;
 207   } else if (bt == T_OBJECT) {
 208     elemtype = elemtype->make_oopptr();
 209     const Type* tval = _gvn.type(cast_val);
 210     // Based on the value to be stored, try to determine if the array is not null-free and/or not flat.
 211     // This is only legal for non-null stores because the array_store_check always passes for null, even
 212     // if the array is null-free. Null stores are handled in GraphKit::gen_inline_array_null_guard().
 213     bool not_null_free = !tval->maybe_null() && !tval->is_oopptr()->can_be_inline_type();
 214     bool not_flattened = not_null_free || (tval->is_inlinetypeptr() && !tval->inline_klass()->flatten_array());
 215     if (!ary_t->is_not_null_free() && not_null_free) {
 216       // Storing a non-inline type, mark array as not null-free (-> not flat).
 217       ary_t = ary_t->cast_to_not_null_free();
 218       Node* cast = _gvn.transform(new CheckCastPPNode(control(), ary, ary_t));
 219       replace_in_map(ary, cast);
 220       ary = cast;
 221     } else if (!ary_t->is_not_flat() && not_flattened) {
 222       // Storing a non-flattened value, mark array as not flat.
 223       ary_t = ary_t->cast_to_not_flat();
 224       Node* cast = _gvn.transform(new CheckCastPPNode(control(), ary, ary_t));
 225       replace_in_map(ary, cast);
 226       ary = cast;
 227     }
 228 
 229     if (ary_t->is_flat()) {
 230       // Store to flattened inline type array
 231       assert(!tval->maybe_null(), "should be guaranteed by array store check");
 232       // Re-execute flattened array store if buffering triggers deoptimization
 233       PreserveReexecuteState preexecs(this);
 234       inc_sp(3);
 235       jvms()->set_should_reexecute(true);
 236       cast_val->as_InlineType()->store_flattened(this, ary, adr, NULL, 0, MO_UNORDERED | IN_HEAP | IS_ARRAY);
 237       return;
 238     } else if (ary_t->is_null_free()) {
 239       // Store to non-flattened inline type array (elements can never be null)
 240       assert(!tval->maybe_null(), "should be guaranteed by array store check");
 241       if (elemtype->inline_klass()->is_empty()) {
 242         // Ignore empty inline stores, array is already initialized.
 243         return;
 244       }
 245     } else if (!ary_t->is_not_flat() && (tval != TypePtr::NULL_PTR || StressReflectiveCode)) {
 246       // Array might be flattened, emit runtime checks (for NULL, a simple inline_array_null_guard is sufficient).
 247       assert(UseFlatArray && !not_flattened && elemtype->is_oopptr()->can_be_inline_type() &&
 248              !ary_t->klass_is_exact() && !ary_t->is_not_null_free(), "array can't be flattened");
 249       IdealKit ideal(this);
 250       ideal.if_then(flat_array_test(ary, /* flat = */ false)); {
 251         // non-flattened
 252         assert(ideal.ctrl()->in(0)->as_If()->is_flat_array_check(&_gvn), "Should be found");
 253         sync_kit(ideal);
 254         Node* cast_ary = inline_array_null_guard(ary, cast_val, 3);
 255         inc_sp(3);
 256         access_store_at(cast_ary, adr, adr_type, cast_val, elemtype, bt, MO_UNORDERED | IN_HEAP | IS_ARRAY, false);
 257         dec_sp(3);
 258         ideal.sync_kit(this);
 259       } ideal.else_(); {
 260         sync_kit(ideal);
 261         // flattened
 262         Node* null_ctl = top();
 263         Node* val = null_check_oop(cast_val, &null_ctl);
 264         if (null_ctl != top()) {
 265           PreserveJVMState pjvms(this);
 266           inc_sp(3);
 267           set_control(null_ctl);
 268           uncommon_trap(Deoptimization::Reason_null_check, Deoptimization::Action_none);
 269           dec_sp(3);
 270         }
 271         // Try to determine the inline klass
 272         ciInlineKlass* vk = NULL;
 273         if (tval->is_inlinetypeptr()) {
 274           vk = tval->inline_klass();
 275         } else if (elemtype->is_inlinetypeptr()) {
 276           vk = elemtype->inline_klass();
 277         }
 278         Node* casted_ary = ary;
 279         if (vk != NULL && !stopped()) {
 280           // Element type is known, cast and store to flattened representation
 281           assert(vk->flatten_array() && elemtype->maybe_null(), "never/always flat - should be optimized");
 282           ciArrayKlass* array_klass = ciArrayKlass::make(vk, /* null_free */ true);
 283           const TypeAryPtr* arytype = TypeOopPtr::make_from_klass(array_klass)->isa_aryptr();
 284           casted_ary = _gvn.transform(new CheckCastPPNode(control(), casted_ary, arytype));
 285           Node* casted_adr = array_element_address(casted_ary, idx, T_OBJECT, arytype->size(), control());
 286           if (!val->is_InlineType()) {
 287             assert(!gvn().type(val)->maybe_null(), "inline type array elements should never be null");
 288             val = InlineTypeNode::make_from_oop(this, val, vk);
 289           }
 290           // Re-execute flattened array store if buffering triggers deoptimization
 291           PreserveReexecuteState preexecs(this);
 292           inc_sp(3);
 293           jvms()->set_should_reexecute(true);
 294           val->as_InlineType()->store_flattened(this, casted_ary, casted_adr, NULL, 0, MO_UNORDERED | IN_HEAP | IS_ARRAY);
 295         } else if (!stopped()) {
 296           // Element type is unknown, emit runtime call
 297 
 298           // Below membars keep this access to an unknown flattened array correctly
 299           // ordered with other unknown and known flattened array accesses.
 300           insert_mem_bar_volatile(Op_MemBarCPUOrder, C->get_alias_index(TypeAryPtr::INLINES));
 301 
 302           make_runtime_call(RC_LEAF,
 303                             OptoRuntime::store_unknown_inline_type(),
 304                             CAST_FROM_FN_PTR(address, OptoRuntime::store_unknown_inline),
 305                             "store_unknown_inline", TypeRawPtr::BOTTOM,
 306                             val, casted_ary, idx);
 307 
 308           insert_mem_bar_volatile(Op_MemBarCPUOrder, C->get_alias_index(TypeAryPtr::INLINES));
 309         }
 310         ideal.sync_kit(this);
 311       }
 312       ideal.end_if();
 313       sync_kit(ideal);
 314       return;
 315     } else if (!ary_t->is_not_null_free()) {
 316       // Array is not flattened but may be null free
 317       assert(elemtype->is_oopptr()->can_be_inline_type() && !ary_t->klass_is_exact(), "array can't be null-free");
 318       ary = inline_array_null_guard(ary, cast_val, 3, true);
 319     }
 320   }
 321   inc_sp(3);
 322   access_store_at(ary, adr, adr_type, val, elemtype, bt, MO_UNORDERED | IN_HEAP | IS_ARRAY);
 323   dec_sp(3);
 324 }
 325 
 326 
 327 //------------------------------array_addressing-------------------------------
 328 // Pull array and index from the stack.  Compute pointer-to-element.
 329 Node* Parse::array_addressing(BasicType type, int vals, const Type*& elemtype) {
 330   Node *idx   = peek(0+vals);   // Get from stack without popping
 331   Node *ary   = peek(1+vals);   // in case of exception
 332 
 333   // Null check the array base, with correct stack contents
 334   ary = null_check(ary, T_ARRAY);
 335   // Compile-time detect of null-exception?
 336   if (stopped())  return top();
 337 
 338   const TypeAryPtr* arytype  = _gvn.type(ary)->is_aryptr();
 339   const TypeInt*    sizetype = arytype->size();
 340   elemtype = arytype->elem();
 341 
 342   if (UseUniqueSubclasses) {
 343     const Type* el = elemtype->make_ptr();

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

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

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

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

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


3402     break;
3403 
3404   case Bytecodes::_ifeq: btest = BoolTest::eq; goto handle_ifxx;
3405   case Bytecodes::_ifne: btest = BoolTest::ne; goto handle_ifxx;
3406   case Bytecodes::_iflt: btest = BoolTest::lt; goto handle_ifxx;
3407   case Bytecodes::_ifle: btest = BoolTest::le; goto handle_ifxx;
3408   case Bytecodes::_ifgt: btest = BoolTest::gt; goto handle_ifxx;
3409   case Bytecodes::_ifge: btest = BoolTest::ge; goto handle_ifxx;
3410   handle_ifxx:
3411     // If this is a backwards branch in the bytecodes, add Safepoint
3412     maybe_add_safepoint(iter().get_dest());
3413     a = _gvn.intcon(0);
3414     b = pop();
3415     c = _gvn.transform( new CmpINode(b, a) );
3416     do_if(btest, c);
3417     break;
3418 
3419   case Bytecodes::_if_icmpeq: btest = BoolTest::eq; goto handle_if_icmp;
3420   case Bytecodes::_if_icmpne: btest = BoolTest::ne; goto handle_if_icmp;
3421   case Bytecodes::_if_icmplt: btest = BoolTest::lt; goto handle_if_icmp;

3436     break;
3437 
3438   case Bytecodes::_lookupswitch:
3439     do_lookupswitch();
3440     break;
3441 
3442   case Bytecodes::_invokestatic:
3443   case Bytecodes::_invokedynamic:
3444   case Bytecodes::_invokespecial:
3445   case Bytecodes::_invokevirtual:
3446   case Bytecodes::_invokeinterface:
3447     do_call();
3448     break;
3449   case Bytecodes::_checkcast:
3450     do_checkcast();
3451     break;
3452   case Bytecodes::_instanceof:
3453     do_instanceof();
3454     break;
3455   case Bytecodes::_anewarray:
3456     do_newarray();
3457     break;
3458   case Bytecodes::_newarray:
3459     do_newarray((BasicType)iter().get_index());
3460     break;
3461   case Bytecodes::_multianewarray:
3462     do_multianewarray();
3463     break;
3464   case Bytecodes::_new:
3465     do_new();
3466     break;
3467   case Bytecodes::_aconst_init:
3468     do_aconst_init();
3469     break;
3470   case Bytecodes::_withfield:
3471     do_withfield();
3472     break;
3473 
3474   case Bytecodes::_jsr:
3475   case Bytecodes::_jsr_w:
3476     do_jsr();
3477     break;
3478 
3479   case Bytecodes::_ret:
3480     do_ret();
3481     break;
3482 
3483 
3484   case Bytecodes::_monitorenter:
3485     do_monitor_enter();
3486     break;
3487 
3488   case Bytecodes::_monitorexit:
3489     do_monitor_exit();
3490     break;
3491 
3492   case Bytecodes::_breakpoint:
< prev index next >