5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "ci/ciMethodData.hpp"
26 #include "classfile/vmSymbols.hpp"
27 #include "compiler/compileLog.hpp"
28 #include "interpreter/linkResolver.hpp"
29 #include "jvm_io.h"
30 #include "memory/resourceArea.hpp"
31 #include "memory/universe.hpp"
32 #include "oops/oop.inline.hpp"
33 #include "opto/addnode.hpp"
34 #include "opto/castnode.hpp"
35 #include "opto/convertnode.hpp"
36 #include "opto/divnode.hpp"
37 #include "opto/idealGraphPrinter.hpp"
38 #include "opto/matcher.hpp"
39 #include "opto/memnode.hpp"
40 #include "opto/mulnode.hpp"
41 #include "opto/opaquenode.hpp"
42 #include "opto/parse.hpp"
43 #include "opto/runtime.hpp"
44 #include "opto/subtypenode.hpp"
45 #include "runtime/deoptimization.hpp"
46 #include "runtime/sharedRuntime.hpp"
47
48 #ifndef PRODUCT
49 extern uint 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();
125 if (el && el->isa_instptr()) {
126 const TypeInstPtr* toop = el->is_instptr();
127 if (toop->instance_klass()->unique_concrete_subklass()) {
128 // If we load from "AbstractClass[]" we must see "ConcreteSubClass".
129 const Type* subklass = Type::get_const_type(toop->instance_klass());
130 elemtype = subklass->join_speculative(el);
131 }
132 }
133 }
134
135 // Check for big class initializers with all constant offsets
136 // feeding into a known-size array.
137 const TypeInt* idxtype = _gvn.type(idx)->is_int();
138 // See if the highest idx value is less than the lowest array bound,
139 // and if the idx value cannot be negative:
140 bool need_range_check = true;
141 if (idxtype->_hi < sizetype->_lo && idxtype->_lo >= 0) {
142 need_range_check = false;
143 if (C->log() != nullptr) C->log()->elem("observe that='!need_range_check'");
144 }
145
146 if (!arytype->is_loaded()) {
147 // Only fails for some -Xcomp runs
148 // The class is unloaded. We have to run this bytecode in the interpreter.
149 ciKlass* klass = arytype->unloaded_klass();
150
151 uncommon_trap(Deoptimization::Reason_unloaded,
152 Deoptimization::Action_reinterpret,
153 klass, "!loaded array");
154 return top();
155 }
156
157 // Do the range check
158 if (need_range_check) {
159 Node* tst;
160 if (sizetype->_hi <= 0) {
161 // The greatest array bound is negative, so we can conclude that we're
162 // compiling unreachable code, but the unsigned compare trick used below
163 // only works with non-negative lengths. Instead, hack "tst" to be zero so
164 // the uncommon_trap path will always be taken.
165 tst = _gvn.intcon(0);
166 } else {
167 // Range is constant in array-oop, so we can use the original state of mem
168 Node* len = load_array_length(ary);
169
170 // Test length vs index (standard trick using unsigned compare)
171 Node* chk = _gvn.transform( new CmpUNode(idx, len) );
172 BoolTest::mask btest = BoolTest::lt;
173 tst = _gvn.transform( new BoolNode(chk, btest) );
174 }
175 RangeCheckNode* rc = new RangeCheckNode(control(), tst, PROB_MAX, COUNT_UNKNOWN);
176 _gvn.set_type(rc, rc->Value(&_gvn));
177 if (!tst->is_Con()) {
178 record_for_igvn(rc);
179 }
180 set_control(_gvn.transform(new IfTrueNode(rc)));
181 // Branch to failure if out of bounds
182 {
183 PreserveJVMState pjvms(this);
184 set_control(_gvn.transform(new IfFalseNode(rc)));
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 nullptr, "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)
225 static const int never_reached = INT_MAX;
226
227 //------------------------------helper for tableswitch-------------------------
228 void Parse::jump_if_true_fork(IfNode *iff, int dest_bci_if_true, bool unc) {
229 // True branch, use existing map info
230 { PreserveJVMState pjvms(this);
231 Node *iftrue = _gvn.transform( new IfTrueNode (iff) );
232 set_control( iftrue );
1450 // False branch
1451 Node* iffalse = _gvn.transform( new IfFalseNode(iff) );
1452 set_control(iffalse);
1453
1454 if (stopped()) { // Path is dead?
1455 NOT_PRODUCT(explicit_null_checks_elided++);
1456 if (C->eliminate_boxing()) {
1457 // Mark the successor block as parsed
1458 next_block->next_path_num();
1459 }
1460 } else { // Path is live.
1461 adjust_map_after_if(BoolTest(btest).negate(), c, 1.0-prob, next_block);
1462 }
1463
1464 if (do_stress_trap) {
1465 stress_trap(iff, counter, incr_store);
1466 }
1467 }
1468
1469 //------------------------------------do_if------------------------------------
1470 void Parse::do_if(BoolTest::mask btest, Node* c) {
1471 int target_bci = iter().get_dest();
1472
1473 Block* branch_block = successor_for_bci(target_bci);
1474 Block* next_block = successor_for_bci(iter().next_bci());
1475
1476 float cnt;
1477 float prob = branch_prediction(cnt, btest, target_bci, c);
1478 float untaken_prob = 1.0 - prob;
1479
1480 if (prob == PROB_UNKNOWN) {
1481 if (PrintOpto && Verbose) {
1482 tty->print_cr("Never-taken edge stops compilation at bci %d", bci());
1483 }
1484 repush_if_args(); // to gather stats on loop
1485 uncommon_trap(Deoptimization::Reason_unreached,
1486 Deoptimization::Action_reinterpret,
1487 nullptr, "cold");
1488 if (C->eliminate_boxing()) {
1489 // Mark the successor blocks as parsed
1490 branch_block->next_path_num();
1541 }
1542
1543 // Generate real control flow
1544 float true_prob = (taken_if_true ? prob : untaken_prob);
1545 IfNode* iff = create_and_map_if(control(), tst, true_prob, cnt);
1546 assert(iff->_prob > 0.0f,"Optimizer made bad probability in parser");
1547 Node* taken_branch = new IfTrueNode(iff);
1548 Node* untaken_branch = new IfFalseNode(iff);
1549 if (!taken_if_true) { // Finish conversion to canonical form
1550 Node* tmp = taken_branch;
1551 taken_branch = untaken_branch;
1552 untaken_branch = tmp;
1553 }
1554
1555 // Branch is taken:
1556 { PreserveJVMState pjvms(this);
1557 taken_branch = _gvn.transform(taken_branch);
1558 set_control(taken_branch);
1559
1560 if (stopped()) {
1561 if (C->eliminate_boxing()) {
1562 // Mark the successor block as parsed
1563 branch_block->next_path_num();
1564 }
1565 } else {
1566 adjust_map_after_if(taken_btest, c, prob, branch_block);
1567 if (!stopped()) {
1568 merge(target_bci);
1569 }
1570 }
1571 }
1572
1573 untaken_branch = _gvn.transform(untaken_branch);
1574 set_control(untaken_branch);
1575
1576 // Branch not taken.
1577 if (stopped()) {
1578 if (C->eliminate_boxing()) {
1579 // Mark the successor block as parsed
1580 next_block->next_path_num();
1581 }
1582 } else {
1583 adjust_map_after_if(untaken_btest, c, untaken_prob, next_block);
1584 }
1585
1586 if (do_stress_trap) {
1587 stress_trap(iff, counter, incr_store);
1588 }
1589 }
1590
1591 // Force unstable if traps to be taken randomly to trigger intermittent bugs such as incorrect debug information.
1592 // Add another if before the unstable if that checks a "random" condition at runtime (a simple shared counter) and
1593 // then either takes the trap or executes the original, unstable if.
1594 void Parse::stress_trap(IfNode* orig_iff, Node* counter, Node* incr_store) {
1595 // Search for an unstable if trap
1596 CallStaticJavaNode* trap = nullptr;
1597 assert(orig_iff->Opcode() == Op_If && orig_iff->outcnt() == 2, "malformed if");
1598 ProjNode* trap_proj = orig_iff->uncommon_trap_proj(trap, Deoptimization::Reason_unstable_if);
1599 if (trap == nullptr || !trap->jvms()->should_reexecute()) {
1600 // No suitable trap found. Remove unused counter load and increment.
1601 C->gvn_replace_by(incr_store, incr_store->in(MemNode::Memory));
1602 return;
1603 }
1604
1605 // Remove trap from optimization list since we add another path to the trap.
1606 bool success = C->remove_unstable_if_trap(trap, true);
1607 assert(success, "Trap already modified");
1608
1609 // Add a check before the original if that will trap with a certain frequency and execute the original if otherwise
1610 int freq_log = (C->random() % 31) + 1; // Random logarithmic frequency in [1, 31]
1643 }
1644
1645 void Parse::maybe_add_predicate_after_if(Block* path) {
1646 if (path->is_SEL_head() && path->preds_parsed() == 0) {
1647 // Add predicates at bci of if dominating the loop so traps can be
1648 // recorded on the if's profile data
1649 int bc_depth = repush_if_args();
1650 add_parse_predicates();
1651 dec_sp(bc_depth);
1652 path->set_has_predicates();
1653 }
1654 }
1655
1656
1657 //----------------------------adjust_map_after_if------------------------------
1658 // Adjust the JVM state to reflect the result of taking this path.
1659 // Basically, it means inspecting the CmpNode controlling this
1660 // branch, seeing how it constrains a tested value, and then
1661 // deciding if it's worth our while to encode this constraint
1662 // as graph nodes in the current abstract interpretation map.
1663 void Parse::adjust_map_after_if(BoolTest::mask btest, Node* c, float prob, Block* path) {
1664 if (!c->is_Cmp()) {
1665 maybe_add_predicate_after_if(path);
1666 return;
1667 }
1668
1669 if (stopped() || btest == BoolTest::illegal) {
1670 return; // nothing to do
1671 }
1672
1673 bool is_fallthrough = (path == successor_for_bci(iter().next_bci()));
1674
1675 if (path_is_suitable_for_uncommon_trap(prob)) {
1676 repush_if_args();
1677 Node* call = uncommon_trap(Deoptimization::Reason_unstable_if,
1678 Deoptimization::Action_reinterpret,
1679 nullptr,
1680 (is_fallthrough ? "taken always" : "taken never"));
1681
1682 if (call != nullptr) {
1683 C->record_unstable_if_trap(new UnstableIfTrap(call->as_CallStaticJava(), path));
1684 }
1685 return;
1686 }
1687
1688 Node* val = c->in(1);
1689 Node* con = c->in(2);
1690 const Type* tcon = _gvn.type(con);
1691 const Type* tval = _gvn.type(val);
1692 bool have_con = tcon->singleton();
1693 if (tval->singleton()) {
1694 if (!have_con) {
1695 // Swap, so constant is in con.
1696 con = val;
1697 tcon = tval;
1698 val = c->in(2);
1699 tval = _gvn.type(val);
1700 btest = BoolTest(btest).commute();
1701 have_con = true;
1702 } else {
1703 // Do we have two constants? Then leave well enough alone.
1704 have_con = false;
1705 }
1706 }
1707 if (!have_con) { // remaining adjustments need a con
1833 &obj, &cast_type)) {
1834 assert(obj != nullptr && cast_type != nullptr, "missing type check info");
1835 const Type* obj_type = _gvn.type(obj);
1836 const Type* tboth = obj_type->filter_speculative(cast_type);
1837 assert(tboth->higher_equal(obj_type) && tboth->higher_equal(cast_type), "sanity");
1838 if (tboth == Type::TOP && KillPathsReachableByDeadTypeNode) {
1839 // Let dead type node cleaning logic prune effectively dead path for us.
1840 // CheckCastPP::Value() == TOP and it will trigger the cleanup during GVN.
1841 // Don't materialize the cast when cleanup is disabled, because
1842 // it kills data and control leaving IR in broken state.
1843 tboth = cast_type;
1844 }
1845 if (tboth != Type::TOP && tboth != obj_type) {
1846 int obj_in_map = map()->find_edge(obj);
1847 if (obj_in_map >= 0 &&
1848 (jvms()->is_loc(obj_in_map) || jvms()->is_stk(obj_in_map))) {
1849 TypeNode* ccast = new CheckCastPPNode(control(), obj, tboth);
1850 // Delay transform() call to allow recovery of pre-cast value at the control merge.
1851 _gvn.set_type_bottom(ccast);
1852 record_for_igvn(ccast);
1853 // Here's the payoff.
1854 replace_in_map(obj, ccast);
1855 }
1856 }
1857 }
1858
1859 int val_in_map = map()->find_edge(val);
1860 if (val_in_map < 0) return; // replace_in_map would be useless
1861 {
1862 JVMState* jvms = this->jvms();
1863 if (!(jvms->is_loc(val_in_map) ||
1864 jvms->is_stk(val_in_map)))
1865 return; // again, it would be useless
1866 }
1867
1868 // Check for a comparison to a constant, and "know" that the compared
1869 // value is constrained on this path.
1870 assert(tcon->singleton(), "");
1871 ConstraintCastNode* ccast = nullptr;
1872 Node* cast = nullptr;
1936 if (c->Opcode() == Op_CmpP &&
1937 (c->in(1)->Opcode() == Op_LoadKlass || c->in(1)->Opcode() == Op_DecodeNKlass) &&
1938 c->in(2)->is_Con()) {
1939 Node* load_klass = nullptr;
1940 Node* decode = nullptr;
1941 if (c->in(1)->Opcode() == Op_DecodeNKlass) {
1942 decode = c->in(1);
1943 load_klass = c->in(1)->in(1);
1944 } else {
1945 load_klass = c->in(1);
1946 }
1947 if (load_klass->in(2)->is_AddP()) {
1948 Node* addp = load_klass->in(2);
1949 Node* obj = addp->in(AddPNode::Address);
1950 const TypeOopPtr* obj_type = _gvn.type(obj)->is_oopptr();
1951 if (obj_type->speculative_type_not_null() != nullptr) {
1952 ciKlass* k = obj_type->speculative_type();
1953 inc_sp(2);
1954 obj = maybe_cast_profiled_obj(obj, k);
1955 dec_sp(2);
1956 // Make the CmpP use the casted obj
1957 addp = basic_plus_adr(obj, addp->in(AddPNode::Offset));
1958 load_klass = load_klass->clone();
1959 load_klass->set_req(2, addp);
1960 load_klass = _gvn.transform(load_klass);
1961 if (decode != nullptr) {
1962 decode = decode->clone();
1963 decode->set_req(1, load_klass);
1964 load_klass = _gvn.transform(decode);
1965 }
1966 c = c->clone();
1967 c->set_req(1, load_klass);
1968 c = _gvn.transform(c);
1969 }
1970 }
1971 }
1972 return c;
1973 }
1974
1975 //------------------------------do_one_bytecode--------------------------------
2678 b = _gvn.transform( new ConvI2DNode(a));
2679 push_pair(b);
2680 break;
2681
2682 case Bytecodes::_iinc: // Increment local
2683 i = iter().get_index(); // Get local index
2684 set_local( i, _gvn.transform( new AddINode( _gvn.intcon(iter().get_iinc_con()), local(i) ) ) );
2685 break;
2686
2687 // Exit points of synchronized methods must have an unlock node
2688 case Bytecodes::_return:
2689 return_current(nullptr);
2690 break;
2691
2692 case Bytecodes::_ireturn:
2693 case Bytecodes::_areturn:
2694 case Bytecodes::_freturn:
2695 return_current(pop());
2696 break;
2697 case Bytecodes::_lreturn:
2698 return_current(pop_pair());
2699 break;
2700 case Bytecodes::_dreturn:
2701 return_current(pop_pair());
2702 break;
2703
2704 case Bytecodes::_athrow:
2705 // null exception oop throws null pointer exception
2706 null_check(peek());
2707 if (stopped()) return;
2708 // Hook the thrown exception directly to subsequent handlers.
2709 if (BailoutToInterpreterForThrows) {
2710 // Keep method interpreted from now on.
2711 uncommon_trap(Deoptimization::Reason_unhandled,
2712 Deoptimization::Action_make_not_compilable);
2713 return;
2714 }
2715 if (env()->jvmti_can_post_on_exceptions()) {
2716 // check if we must post exception events, take uncommon trap if so (with must_throw = false)
2717 uncommon_trap_if_should_post_on_exceptions(Deoptimization::Reason_unhandled, false);
2718 }
2719 // Here if either can_post_on_exceptions or should_post_on_exceptions is false
2733 // See if we can get some profile data and hand it off to the next block
2734 Block *target_block = block()->successor_for_bci(target_bci);
2735 if (target_block->pred_count() != 1) break;
2736 ciMethodData* methodData = method()->method_data();
2737 if (!methodData->is_mature()) break;
2738 ciProfileData* data = methodData->bci_to_data(bci());
2739 assert(data != nullptr && data->is_JumpData(), "need JumpData for taken branch");
2740 int taken = ((ciJumpData*)data)->taken();
2741 taken = method()->scale_count(taken);
2742 target_block->set_count(taken);
2743 break;
2744 }
2745
2746 case Bytecodes::_ifnull: btest = BoolTest::eq; goto handle_if_null;
2747 case Bytecodes::_ifnonnull: btest = BoolTest::ne; goto handle_if_null;
2748 handle_if_null:
2749 // If this is a backwards branch in the bytecodes, add Safepoint
2750 maybe_add_safepoint(iter().get_dest());
2751 a = null();
2752 b = pop();
2753 if (!_gvn.type(b)->speculative_maybe_null() &&
2754 !too_many_traps(Deoptimization::Reason_speculate_null_check)) {
2755 inc_sp(1);
2756 Node* null_ctl = top();
2757 b = null_check_oop(b, &null_ctl, true, true, true);
2758 assert(null_ctl->is_top(), "no null control here");
2759 dec_sp(1);
2760 } else if (_gvn.type(b)->speculative_always_null() &&
2761 !too_many_traps(Deoptimization::Reason_speculate_null_assert)) {
2762 inc_sp(1);
2763 b = null_assert(b);
2764 dec_sp(1);
2765 }
2766 c = _gvn.transform( new CmpPNode(b, a) );
2767 do_ifnull(btest, c);
2768 break;
2769
2770 case Bytecodes::_if_acmpeq: btest = BoolTest::eq; goto handle_if_acmp;
2771 case Bytecodes::_if_acmpne: btest = BoolTest::ne; goto handle_if_acmp;
2772 handle_if_acmp:
2773 // If this is a backwards branch in the bytecodes, add Safepoint
2774 maybe_add_safepoint(iter().get_dest());
2775 a = pop();
2776 b = pop();
2777 c = _gvn.transform( new CmpPNode(b, a) );
2778 c = optimize_cmp_with_klass(c);
2779 do_if(btest, c);
2780 break;
2781
2782 case Bytecodes::_ifeq: btest = BoolTest::eq; goto handle_ifxx;
2783 case Bytecodes::_ifne: btest = BoolTest::ne; goto handle_ifxx;
2784 case Bytecodes::_iflt: btest = BoolTest::lt; goto handle_ifxx;
2785 case Bytecodes::_ifle: btest = BoolTest::le; goto handle_ifxx;
2786 case Bytecodes::_ifgt: btest = BoolTest::gt; goto handle_ifxx;
2787 case Bytecodes::_ifge: btest = BoolTest::ge; goto handle_ifxx;
2788 handle_ifxx:
2789 // If this is a backwards branch in the bytecodes, add Safepoint
2790 maybe_add_safepoint(iter().get_dest());
2791 a = _gvn.intcon(0);
2792 b = pop();
2793 c = _gvn.transform( new CmpINode(b, a) );
2794 do_if(btest, c);
2795 break;
2796
2797 case Bytecodes::_if_icmpeq: btest = BoolTest::eq; goto handle_if_icmp;
2798 case Bytecodes::_if_icmpne: btest = BoolTest::ne; goto handle_if_icmp;
2799 case Bytecodes::_if_icmplt: btest = BoolTest::lt; goto handle_if_icmp;
2814 break;
2815
2816 case Bytecodes::_lookupswitch:
2817 do_lookupswitch();
2818 break;
2819
2820 case Bytecodes::_invokestatic:
2821 case Bytecodes::_invokedynamic:
2822 case Bytecodes::_invokespecial:
2823 case Bytecodes::_invokevirtual:
2824 case Bytecodes::_invokeinterface:
2825 do_call();
2826 break;
2827 case Bytecodes::_checkcast:
2828 do_checkcast();
2829 break;
2830 case Bytecodes::_instanceof:
2831 do_instanceof();
2832 break;
2833 case Bytecodes::_anewarray:
2834 do_anewarray();
2835 break;
2836 case Bytecodes::_newarray:
2837 do_newarray((BasicType)iter().get_index());
2838 break;
2839 case Bytecodes::_multianewarray:
2840 do_multianewarray();
2841 break;
2842 case Bytecodes::_new:
2843 do_new();
2844 break;
2845
2846 case Bytecodes::_jsr:
2847 case Bytecodes::_jsr_w:
2848 do_jsr();
2849 break;
2850
2851 case Bytecodes::_ret:
2852 do_ret();
2853 break;
2854
|
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "ci/ciInlineKlass.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 "opto/subtypenode.hpp"
49 #include "runtime/arguments.hpp"
50 #include "runtime/deoptimization.hpp"
51 #include "runtime/globals.hpp"
52 #include "runtime/sharedRuntime.hpp"
53
54 #ifndef PRODUCT
55 extern uint explicit_null_checks_inserted,
56 explicit_null_checks_elided;
57 #endif
58
59 Node* Parse::record_profile_for_speculation_at_array_load(Node* ld) {
60 // Feed unused profile data to type speculation
61 if (UseTypeSpeculation && UseArrayLoadStoreProfile) {
62 ciKlass* array_type = nullptr;
63 ciKlass* element_type = nullptr;
64 ProfilePtrKind element_ptr = ProfileMaybeNull;
65 bool flat_array = true;
66 bool null_free_array = true;
67 method()->array_access_profiled_type(bci(), array_type, element_type, element_ptr, flat_array, null_free_array);
68 if (element_type != nullptr || element_ptr != ProfileMaybeNull) {
69 ld = record_profile_for_speculation(ld, element_type, element_ptr);
70 }
71 }
72 return ld;
73 }
74
75
76 //---------------------------------array_load----------------------------------
77 void Parse::array_load(BasicType bt) {
78 const Type* elemtype = Type::TOP;
79 Node* prep_array = prepare_array_addressing(bt, 0, elemtype);
80 if (stopped()) return; // guaranteed null or range check
81
82 Node* array_index = pop();
83 Node* array = pop();
84
85 // Handle inline type arrays
86 const TypeOopPtr* element_ptr = elemtype->make_oopptr();
87 const TypeAryPtr* array_type = _gvn.type(array)->is_aryptr();
88
89 if (!array_type->is_not_flat()) {
90 // Cannot statically determine if array is a flat array, emit runtime check
91 assert(UseArrayFlattening && is_reference_type(bt) && element_ptr->can_be_inline_type() &&
92 (!element_ptr->is_inlinetypeptr() || element_ptr->inline_klass()->maybe_flat_in_array()), "array can't be flat");
93 IdealKit ideal(this);
94 IdealVariable res(ideal);
95 ideal.declarations_done();
96 ideal.if_then(flat_array_test(array, /* flat = */ false)); {
97 // Non-flat array
98 sync_kit(ideal);
99 if (!array_type->is_flat()) {
100 assert(array_type->is_flat() || control()->in(0)->as_If()->is_flat_array_check(&_gvn), "Should be found");
101 // Loading from a non-flat array, casting array to not flat.
102 const TypeAryPtr* ary_type = _gvn.type(prep_array)->is_aryptr();
103 ary_type = ary_type->cast_to_not_flat();
104 Node* not_flat_ary = _gvn.transform(new CheckCastPPNode(control(), prep_array, ary_type));
105 Node* adr = get_ptr_to_array_element(not_flat_ary, array_index, bt, ary_type->size(), control());
106 const TypeAryPtr* adr_type = TypeAryPtr::get_array_body_type(bt);
107 DecoratorSet decorator_set = IN_HEAP | IS_ARRAY | C2_CONTROL_DEPENDENT_LOAD;
108 if (needs_range_check(ary_type->size(), array_index)) {
109 // We've emitted a RangeCheck but now insert an additional check between the range check and the actual load.
110 // We cannot pin the load to two separate nodes. Instead, we pin it conservatively here such that it cannot
111 // possibly float above the range check at any point.
112 decorator_set |= C2_UNKNOWN_CONTROL_LOAD;
113 }
114 Node* ld = access_load_at(not_flat_ary, adr, adr_type, element_ptr, bt, decorator_set);
115 if (element_ptr->is_inlinetypeptr()) {
116 ld = InlineTypeNode::make_from_oop(this, ld, element_ptr->inline_klass());
117 }
118 ideal.set(res, ld);
119 }
120 ideal.sync_kit(this);
121 } ideal.else_(); {
122 // Flat array
123 sync_kit(ideal);
124 if (!array_type->is_not_flat()) {
125 if (element_ptr->is_inlinetypeptr()) {
126 ciInlineKlass* vk = element_ptr->inline_klass();
127 Node* flat_array = cast_to_flat_array(array, vk);
128 Node* vt = InlineTypeNode::make_from_flat_array(this, vk, flat_array, array_index);
129 ideal.set(res, vt);
130 } else {
131 // Element type is unknown, and thus we cannot statically determine the exact flat array layout. Emit a
132 // runtime call to correctly load the inline type element from the flat array.
133 Node* inline_type = load_from_unknown_flat_array(array, array_index, element_ptr);
134 bool is_null_free = array_type->is_null_free() ||
135 (!UseNullableAtomicValueFlattening && !UseNullableNonAtomicValueFlattening);
136 if (is_null_free) {
137 inline_type = cast_not_null(inline_type);
138 }
139 ideal.set(res, inline_type);
140 }
141 }
142 ideal.sync_kit(this);
143 } ideal.end_if();
144 sync_kit(ideal);
145 Node* ld = _gvn.transform(ideal.value(res));
146 ld = record_profile_for_speculation_at_array_load(ld);
147 push_node(bt, ld);
148 return;
149 }
150
151 if (elemtype == TypeInt::BOOL) {
152 bt = T_BOOLEAN;
153 }
154 const TypeAryPtr* adr_type = TypeAryPtr::get_array_body_type(bt);
155 Node* adr = get_ptr_to_array_element(prep_array, array_index, bt, array_type->size(), control());
156 Node* ld = access_load_at(array, adr, adr_type, elemtype, bt,
157 IN_HEAP | IS_ARRAY | C2_CONTROL_DEPENDENT_LOAD);
158 ld = record_profile_for_speculation_at_array_load(ld);
159 // Loading an inline type from a non-flat array
160 if (element_ptr != nullptr && element_ptr->is_inlinetypeptr()) {
161 assert(!array_type->is_null_free() || !element_ptr->maybe_null(), "inline type array elements should never be null");
162 ld = InlineTypeNode::make_from_oop(this, ld, element_ptr->inline_klass());
163 }
164 push_node(bt, ld);
165 }
166
167 Node* Parse::load_from_unknown_flat_array(Node* array, Node* array_index, const TypeOopPtr* element_ptr) {
168 // Below membars keep this access to an unknown flat array correctly
169 // ordered with other unknown and known flat array accesses.
170 insert_mem_bar_volatile(Op_MemBarCPUOrder, C->get_alias_index(TypeAryPtr::INLINES));
171
172 Node* call = nullptr;
173 {
174 // Re-execute flat array load if runtime call triggers deoptimization
175 PreserveReexecuteState preexecs(this);
176 jvms()->set_bci(_bci);
177 jvms()->set_should_reexecute(true);
178 inc_sp(2);
179 kill_dead_locals();
180 call = make_runtime_call(RC_NO_LEAF | RC_NO_IO,
181 OptoRuntime::load_unknown_inline_Type(),
182 OptoRuntime::load_unknown_inline_Java(),
183 nullptr, TypeRawPtr::BOTTOM,
184 array, array_index);
185 }
186 make_slow_call_ex(call, env()->Throwable_klass(), false);
187 Node* buffer = _gvn.transform(new ProjNode(call, TypeFunc::Parms));
188
189 insert_mem_bar_volatile(Op_MemBarCPUOrder, C->get_alias_index(TypeAryPtr::INLINES));
190
191 // Keep track of the information that the inline type is in flat arrays
192 const Type* unknown_value = element_ptr->is_instptr()->cast_to_flat_in_array();
193 return _gvn.transform(new CheckCastPPNode(control(), buffer, unknown_value));
194 }
195
196 //--------------------------------array_store----------------------------------
197 void Parse::array_store(BasicType bt) {
198 const Type* elemtype = Type::TOP;
199 Node* prep_array = prepare_array_addressing(bt, type2size[bt], elemtype);
200 if (stopped()) return; // guaranteed null or range check
201
202 Node* adr = get_ptr_to_array_element(prep_array, /* index */peek(0+type2size[bt]), bt,
203 _gvn.type(prep_array)->is_aryptr()->size(), control());
204
205 Node* stored_value_casted = nullptr;
206 if (bt == T_OBJECT) {
207 stored_value_casted = array_store_check(adr, elemtype);
208 if (stopped()) {
209 return;
210 }
211 }
212 Node* const stored_value = pop_node(bt); // Value to store
213 Node* const array_index = pop(); // Index in the array
214 Node* array = pop(); // The array itself
215
216 const TypeAryPtr* array_type = _gvn.type(array)->is_aryptr();
217 const TypeAryPtr* adr_type = TypeAryPtr::get_array_body_type(bt);
218
219 if (elemtype == TypeInt::BOOL) {
220 bt = T_BOOLEAN;
221 } else if (bt == T_OBJECT) {
222 elemtype = elemtype->make_oopptr();
223 const Type* stored_value_casted_type = _gvn.type(stored_value_casted);
224 // Based on the value to be stored, try to determine if the array is not null-free and/or not flat.
225 // This is only legal for non-null stores because the array_store_check always passes for null, even
226 // if the array is null-free. Null stores are handled in GraphKit::inline_array_null_guard().
227 bool not_inline = !stored_value_casted_type->maybe_null() && !stored_value_casted_type->is_oopptr()->can_be_inline_type();
228 bool not_null_free = not_inline;
229 bool not_flat = not_inline || ( stored_value_casted_type->is_inlinetypeptr() &&
230 !stored_value_casted_type->inline_klass()->maybe_flat_in_array());
231 if (!array_type->is_not_null_free() && not_null_free) {
232 // Storing a non-inline type, mark array as not null-free.
233 array_type = array_type->cast_to_not_null_free();
234 Node* cast = _gvn.transform(new CheckCastPPNode(control(), array, array_type));
235 replace_in_map(array, cast);
236 array = cast;
237 }
238 if (!array_type->is_not_flat() && not_flat) {
239 // Storing to a non-flat array, mark array as not flat.
240 array_type = array_type->cast_to_not_flat();
241 Node* cast = _gvn.transform(new CheckCastPPNode(control(), array, array_type));
242 replace_in_map(array, cast);
243 array = cast;
244 }
245
246 if (array_type->is_null_free() && elemtype->is_inlinetypeptr() && elemtype->inline_klass()->is_empty()) {
247 // Array of null-free empty inline type, there is only 1 state for the elements
248 assert(!stored_value_casted_type->maybe_null(), "should be guaranteed by array store check");
249 return;
250 }
251
252 if (!array_type->is_not_flat()) {
253 // Array might be a flat array, emit runtime checks (for null, a simple inline_array_null_guard is sufficient).
254 assert(UseArrayFlattening && !not_flat && elemtype->is_oopptr()->can_be_inline_type() &&
255 (!array_type->klass_is_exact() || array_type->is_flat()), "array can't be a flat array");
256 // TODO 8350865 Depending on the available layouts, we can avoid this check in below flat/not-flat branches. Also the safe_for_replace arg is now always true.
257 array = inline_array_null_guard(array, stored_value_casted, 3, true);
258 IdealKit ideal(this);
259 ideal.if_then(flat_array_test(array, /* flat = */ false)); {
260 // Non-flat array
261 if (!array_type->is_flat()) {
262 sync_kit(ideal);
263 assert(array_type->is_flat() || ideal.ctrl()->in(0)->as_If()->is_flat_array_check(&_gvn), "Should be found");
264 inc_sp(3);
265 access_store_at(array, adr, adr_type, stored_value_casted, elemtype, bt, MO_UNORDERED | IN_HEAP | IS_ARRAY, false);
266 dec_sp(3);
267 ideal.sync_kit(this);
268 }
269 } ideal.else_(); {
270 // Flat array
271 sync_kit(ideal);
272 if (!array_type->is_not_flat()) {
273 // Try to determine the inline klass type of the stored value
274 ciInlineKlass* vk = nullptr;
275 if (stored_value_casted_type->is_inlinetypeptr()) {
276 vk = stored_value_casted_type->inline_klass();
277 } else if (elemtype->is_inlinetypeptr()) {
278 vk = elemtype->inline_klass();
279 }
280
281 if (vk != nullptr) {
282 // Element type is known, cast and store to flat array layout.
283 Node* flat_array = cast_to_flat_array(array, vk);
284
285 // Re-execute flat array store if buffering triggers deoptimization
286 PreserveReexecuteState preexecs(this);
287 jvms()->set_should_reexecute(true);
288 inc_sp(3);
289
290 if (!stored_value_casted->is_InlineType()) {
291 assert(_gvn.type(stored_value_casted) == TypePtr::NULL_PTR, "Unexpected value");
292 stored_value_casted = InlineTypeNode::make_null(_gvn, vk);
293 }
294
295 stored_value_casted->as_InlineType()->store_flat_array(this, flat_array, array_index);
296 } else {
297 // Element type is unknown, emit a runtime call since the flat array layout is not statically known.
298 store_to_unknown_flat_array(array, array_index, stored_value_casted);
299 }
300 }
301 ideal.sync_kit(this);
302 }
303 ideal.end_if();
304 sync_kit(ideal);
305 return;
306 } else if (!array_type->is_not_null_free()) {
307 // Array is not flat but may be null free
308 assert(elemtype->is_oopptr()->can_be_inline_type(), "array can't be null-free");
309 array = inline_array_null_guard(array, stored_value_casted, 3, true);
310 }
311 }
312 inc_sp(3);
313 access_store_at(array, adr, adr_type, stored_value, elemtype, bt, MO_UNORDERED | IN_HEAP | IS_ARRAY);
314 dec_sp(3);
315 }
316
317 // Emit a runtime call to store to a flat array whose element type is either unknown (i.e. we do not know the flat
318 // array layout) or not exact (could have different flat array layouts at runtime).
319 void Parse::store_to_unknown_flat_array(Node* array, Node* const idx, Node* non_null_stored_value) {
320 // Below membars keep this access to an unknown flat array correctly
321 // ordered with other unknown and known flat array accesses.
322 insert_mem_bar_volatile(Op_MemBarCPUOrder, C->get_alias_index(TypeAryPtr::INLINES));
323
324 Node* call = nullptr;
325 {
326 // Re-execute flat array store if runtime call triggers deoptimization
327 PreserveReexecuteState preexecs(this);
328 jvms()->set_bci(_bci);
329 jvms()->set_should_reexecute(true);
330 inc_sp(3);
331 kill_dead_locals();
332 call = make_runtime_call(RC_NO_LEAF | RC_NO_IO,
333 OptoRuntime::store_unknown_inline_Type(),
334 OptoRuntime::store_unknown_inline_Java(),
335 nullptr, TypeRawPtr::BOTTOM,
336 non_null_stored_value, array, idx);
337 }
338 make_slow_call_ex(call, env()->Throwable_klass(), false);
339
340 insert_mem_bar_volatile(Op_MemBarCPUOrder, C->get_alias_index(TypeAryPtr::INLINES));
341 }
342
343 //------------------------------array_addressing-------------------------------
344 // Pull array and index from the stack. Compute pointer-to-element.
345 Node* Parse::prepare_array_addressing(BasicType type, int vals, const Type*& elemtype) {
346 Node *idx = peek(0+vals); // Get from stack without popping
347 Node *ary = peek(1+vals); // in case of exception
348
349 // Null check the array base, with correct stack contents
350 ary = null_check(ary, T_ARRAY);
351 // Compile-time detect of null-exception?
352 if (stopped()) return top();
353
354 const TypeAryPtr* arytype = _gvn.type(ary)->is_aryptr();
355 const TypeInt* sizetype = arytype->size();
356 elemtype = arytype->elem();
357
358 if (UseUniqueSubclasses) {
359 const Type* el = elemtype->make_ptr();
360 if (el && el->isa_instptr()) {
361 const TypeInstPtr* toop = el->is_instptr();
362 if (toop->instance_klass()->unique_concrete_subklass()) {
363 // If we load from "AbstractClass[]" we must see "ConcreteSubClass".
364 const Type* subklass = Type::get_const_type(toop->instance_klass());
365 elemtype = subklass->join_speculative(el);
366 }
367 }
368 }
369
370 if (!arytype->is_loaded()) {
371 // Only fails for some -Xcomp runs
372 // The class is unloaded. We have to run this bytecode in the interpreter.
373 ciKlass* klass = arytype->unloaded_klass();
374
375 uncommon_trap(Deoptimization::Reason_unloaded,
376 Deoptimization::Action_reinterpret,
377 klass, "!loaded array");
378 return top();
379 }
380
381 ary = create_speculative_inline_type_array_checks(ary, arytype, elemtype);
382
383 if (needs_range_check(sizetype, idx)) {
384 create_range_check(idx, ary, sizetype);
385 } else if (C->log() != nullptr) {
386 C->log()->elem("observe that='!need_range_check'");
387 }
388
389 // Check for always knowing you are throwing a range-check exception
390 if (stopped()) return top();
391
392 return ary;
393 }
394
395 Node* Parse::get_ptr_to_array_element(Node* array, Node* idx, BasicType elembt, const TypeInt* sizetype, Node* control) {
396 // Make array address computation control dependent to prevent it
397 // from floating above the range check during loop optimizations.
398 Node* ptr = array_element_address(array, idx, elembt, sizetype, control);
399 assert(ptr != top(), "top should go hand-in-hand with stopped");
400
401 return ptr;
402 }
403
404 // Check if we need a range check for an array access. This is the case if the index is either negative or if it could
405 // be greater or equal the smallest possible array size (i.e. out-of-bounds).
406 bool Parse::needs_range_check(const TypeInt* size_type, const Node* index) const {
407 const TypeInt* index_type = _gvn.type(index)->is_int();
408 return index_type->_hi >= size_type->_lo || index_type->_lo < 0;
409 }
410
411 void Parse::create_range_check(Node* idx, Node* ary, const TypeInt* sizetype) {
412 Node* tst;
413 if (sizetype->_hi <= 0) {
414 // The greatest array bound is negative, so we can conclude that we're
415 // compiling unreachable code, but the unsigned compare trick used below
416 // only works with non-negative lengths. Instead, hack "tst" to be zero so
417 // the uncommon_trap path will always be taken.
418 tst = _gvn.intcon(0);
419 } else {
420 // Range is constant in array-oop, so we can use the original state of mem
421 Node* len = load_array_length(ary);
422
423 // Test length vs index (standard trick using unsigned compare)
424 Node* chk = _gvn.transform(new CmpUNode(idx, len) );
425 BoolTest::mask btest = BoolTest::lt;
426 tst = _gvn.transform(new BoolNode(chk, btest) );
427 }
428 RangeCheckNode* rc = new RangeCheckNode(control(), tst, PROB_MAX, COUNT_UNKNOWN);
429 _gvn.set_type(rc, rc->Value(&_gvn));
430 if (!tst->is_Con()) {
431 record_for_igvn(rc);
432 }
433 set_control(_gvn.transform(new IfTrueNode(rc)));
434 // Branch to failure if out of bounds
435 {
436 PreserveJVMState pjvms(this);
437 set_control(_gvn.transform(new IfFalseNode(rc)));
438 if (C->allow_range_check_smearing()) {
439 // Do not use builtin_throw, since range checks are sometimes
440 // made more stringent by an optimistic transformation.
441 // This creates "tentative" range checks at this point,
442 // which are not guaranteed to throw exceptions.
443 // See IfNode::Ideal, is_range_check, adjust_check.
444 uncommon_trap(Deoptimization::Reason_range_check,
445 Deoptimization::Action_make_not_entrant,
446 nullptr, "range_check");
447 } else {
448 // If we have already recompiled with the range-check-widening
449 // heroic optimization turned off, then we must really be throwing
450 // range check exceptions.
451 builtin_throw(Deoptimization::Reason_range_check);
452 }
453 }
454 }
455
456 // For inline type arrays, we can use the profiling information for array accesses to speculate on the type, flatness,
457 // and null-freeness. We can either prepare the speculative type for later uses or emit explicit speculative checks with
458 // traps now. In the latter case, the speculative type guarantees can avoid additional runtime checks later (e.g.
459 // non-null-free implies non-flat which allows us to remove flatness checks). This makes the graph simpler.
460 Node* Parse::create_speculative_inline_type_array_checks(Node* array, const TypeAryPtr* array_type,
461 const Type*& element_type) {
462 if (!array_type->is_flat() && !array_type->is_not_flat()) {
463 // For arrays that might be flat, speculate that the array has the exact type reported in the profile data such that
464 // we can rely on a fixed memory layout (i.e. either a flat layout or not).
465 array = cast_to_speculative_array_type(array, array_type, element_type);
466 } else if (UseTypeSpeculation && UseArrayLoadStoreProfile) {
467 // Array is known to be either flat or not flat. If possible, update the speculative type by using the profile data
468 // at this bci.
469 array = cast_to_profiled_array_type(array);
470 }
471
472 // Even though the type does not tell us whether we have an inline type array or not, we can still check the profile data
473 // whether we have a non-null-free or non-flat array. Speculating on a non-null-free array doesn't help aaload but could
474 // be profitable for a subsequent aastore.
475 if (!array_type->is_null_free() && !array_type->is_not_null_free()) {
476 array = speculate_non_null_free_array(array, array_type);
477 }
478 if (!array_type->is_flat() && !array_type->is_not_flat()) {
479 array = speculate_non_flat_array(array, array_type);
480 }
481 return array;
482 }
483
484 // Speculate that the array has the exact type reported in the profile data. We emit a trap when this turns out to be
485 // wrong. On the fast path, we add a CheckCastPP to use the exact type.
486 Node* Parse::cast_to_speculative_array_type(Node* const array, const TypeAryPtr*& array_type, const Type*& element_type) {
487 Deoptimization::DeoptReason reason = Deoptimization::Reason_speculate_class_check;
488 ciKlass* speculative_array_type = array_type->speculative_type();
489 if (too_many_traps_or_recompiles(reason) || speculative_array_type == nullptr) {
490 // No speculative type, check profile data at this bci
491 speculative_array_type = nullptr;
492 reason = Deoptimization::Reason_class_check;
493 if (UseArrayLoadStoreProfile && !too_many_traps_or_recompiles(reason)) {
494 ciKlass* profiled_element_type = nullptr;
495 ProfilePtrKind element_ptr = ProfileMaybeNull;
496 bool flat_array = true;
497 bool null_free_array = true;
498 method()->array_access_profiled_type(bci(), speculative_array_type, profiled_element_type, element_ptr, flat_array,
499 null_free_array);
500 }
501 }
502 if (speculative_array_type != nullptr) {
503 // Speculate that this array has the exact type reported by profile data
504 Node* casted_array = nullptr;
505 DEBUG_ONLY(Node* old_control = control();)
506 Node* slow_ctl = type_check_receiver(array, speculative_array_type, 1.0, &casted_array);
507 if (stopped()) {
508 // The check always fails and therefore profile information is incorrect. Don't use it.
509 assert(old_control == slow_ctl, "type check should have been removed");
510 set_control(slow_ctl);
511 } else if (!slow_ctl->is_top()) {
512 { PreserveJVMState pjvms(this);
513 set_control(slow_ctl);
514 uncommon_trap_exact(reason, Deoptimization::Action_maybe_recompile);
515 }
516 replace_in_map(array, casted_array);
517 array_type = _gvn.type(casted_array)->is_aryptr();
518 element_type = array_type->elem();
519 return casted_array;
520 }
521 }
522 return array;
523 }
524
525 // Create a CheckCastPP when the speculative type can improve the current type.
526 Node* Parse::cast_to_profiled_array_type(Node* const array) {
527 ciKlass* array_type = nullptr;
528 ciKlass* element_type = nullptr;
529 ProfilePtrKind element_ptr = ProfileMaybeNull;
530 bool flat_array = true;
531 bool null_free_array = true;
532 method()->array_access_profiled_type(bci(), array_type, element_type, element_ptr, flat_array, null_free_array);
533 if (array_type != nullptr) {
534 return record_profile_for_speculation(array, array_type, ProfileMaybeNull);
535 }
536 return array;
537 }
538
539 // Speculate that the array is non-null-free. We emit a trap when this turns out to be
540 // wrong. On the fast path, we add a CheckCastPP to use the non-null-free type.
541 Node* Parse::speculate_non_null_free_array(Node* const array, const TypeAryPtr*& array_type) {
542 bool null_free_array = true;
543 Deoptimization::DeoptReason reason = Deoptimization::Reason_none;
544 if (array_type->speculative() != nullptr &&
545 array_type->speculative()->is_aryptr()->is_not_null_free() &&
546 !too_many_traps_or_recompiles(Deoptimization::Reason_speculate_class_check)) {
547 null_free_array = false;
548 reason = Deoptimization::Reason_speculate_class_check;
549 } else if (UseArrayLoadStoreProfile && !too_many_traps_or_recompiles(Deoptimization::Reason_class_check)) {
550 ciKlass* profiled_array_type = nullptr;
551 ciKlass* profiled_element_type = nullptr;
552 ProfilePtrKind element_ptr = ProfileMaybeNull;
553 bool flat_array = true;
554 method()->array_access_profiled_type(bci(), profiled_array_type, profiled_element_type, element_ptr, flat_array,
555 null_free_array);
556 reason = Deoptimization::Reason_class_check;
557 }
558 if (!null_free_array) {
559 { // Deoptimize if null-free array
560 BuildCutout unless(this, null_free_array_test(array, /* null_free = */ false), PROB_MAX);
561 uncommon_trap_exact(reason, Deoptimization::Action_maybe_recompile);
562 }
563 assert(!stopped(), "null-free array should have been caught earlier");
564 Node* casted_array = _gvn.transform(new CheckCastPPNode(control(), array, array_type->cast_to_not_null_free()));
565 replace_in_map(array, casted_array);
566 array_type = _gvn.type(casted_array)->is_aryptr();
567 return casted_array;
568 }
569 return array;
570 }
571
572 // Speculate that the array is non-flat. We emit a trap when this turns out to be wrong.
573 // On the fast path, we add a CheckCastPP to use the non-flat type.
574 Node* Parse::speculate_non_flat_array(Node* const array, const TypeAryPtr* const array_type) {
575 bool flat_array = true;
576 Deoptimization::DeoptReason reason = Deoptimization::Reason_none;
577 if (array_type->speculative() != nullptr &&
578 array_type->speculative()->is_aryptr()->is_not_flat() &&
579 !too_many_traps_or_recompiles(Deoptimization::Reason_speculate_class_check)) {
580 flat_array = false;
581 reason = Deoptimization::Reason_speculate_class_check;
582 } else if (UseArrayLoadStoreProfile && !too_many_traps_or_recompiles(reason)) {
583 ciKlass* profiled_array_type = nullptr;
584 ciKlass* profiled_element_type = nullptr;
585 ProfilePtrKind element_ptr = ProfileMaybeNull;
586 bool null_free_array = true;
587 method()->array_access_profiled_type(bci(), profiled_array_type, profiled_element_type, element_ptr, flat_array,
588 null_free_array);
589 reason = Deoptimization::Reason_class_check;
590 }
591 if (!flat_array) {
592 { // Deoptimize if flat array
593 BuildCutout unless(this, flat_array_test(array, /* flat = */ false), PROB_MAX);
594 uncommon_trap_exact(reason, Deoptimization::Action_maybe_recompile);
595 }
596 assert(!stopped(), "flat array should have been caught earlier");
597 Node* casted_array = _gvn.transform(new CheckCastPPNode(control(), array, array_type->cast_to_not_flat()));
598 replace_in_map(array, casted_array);
599 return casted_array;
600 }
601 return array;
602 }
603
604 // returns IfNode
605 IfNode* Parse::jump_if_fork_int(Node* a, Node* b, BoolTest::mask mask, float prob, float cnt) {
606 Node *cmp = _gvn.transform(new CmpINode(a, b)); // two cases: shiftcount > 32 and shiftcount <= 32
607 Node *tst = _gvn.transform(new BoolNode(cmp, mask));
608 IfNode *iff = create_and_map_if(control(), tst, prob, cnt);
609 return iff;
610 }
611
612
613 // sentinel value for the target bci to mark never taken branches
614 // (according to profiling)
615 static const int never_reached = INT_MAX;
616
617 //------------------------------helper for tableswitch-------------------------
618 void Parse::jump_if_true_fork(IfNode *iff, int dest_bci_if_true, bool unc) {
619 // True branch, use existing map info
620 { PreserveJVMState pjvms(this);
621 Node *iftrue = _gvn.transform( new IfTrueNode (iff) );
622 set_control( iftrue );
1840 // False branch
1841 Node* iffalse = _gvn.transform( new IfFalseNode(iff) );
1842 set_control(iffalse);
1843
1844 if (stopped()) { // Path is dead?
1845 NOT_PRODUCT(explicit_null_checks_elided++);
1846 if (C->eliminate_boxing()) {
1847 // Mark the successor block as parsed
1848 next_block->next_path_num();
1849 }
1850 } else { // Path is live.
1851 adjust_map_after_if(BoolTest(btest).negate(), c, 1.0-prob, next_block);
1852 }
1853
1854 if (do_stress_trap) {
1855 stress_trap(iff, counter, incr_store);
1856 }
1857 }
1858
1859 //------------------------------------do_if------------------------------------
1860 void Parse::do_if(BoolTest::mask btest, Node* c, bool can_trap, bool new_path, Node** ctrl_taken, Node** mem_taken, Node** io_taken) {
1861 int target_bci = iter().get_dest();
1862
1863 Block* branch_block = successor_for_bci(target_bci);
1864 Block* next_block = successor_for_bci(iter().next_bci());
1865
1866 float cnt;
1867 float prob = branch_prediction(cnt, btest, target_bci, c);
1868 float untaken_prob = 1.0 - prob;
1869
1870 if (prob == PROB_UNKNOWN) {
1871 if (PrintOpto && Verbose) {
1872 tty->print_cr("Never-taken edge stops compilation at bci %d", bci());
1873 }
1874 repush_if_args(); // to gather stats on loop
1875 uncommon_trap(Deoptimization::Reason_unreached,
1876 Deoptimization::Action_reinterpret,
1877 nullptr, "cold");
1878 if (C->eliminate_boxing()) {
1879 // Mark the successor blocks as parsed
1880 branch_block->next_path_num();
1931 }
1932
1933 // Generate real control flow
1934 float true_prob = (taken_if_true ? prob : untaken_prob);
1935 IfNode* iff = create_and_map_if(control(), tst, true_prob, cnt);
1936 assert(iff->_prob > 0.0f,"Optimizer made bad probability in parser");
1937 Node* taken_branch = new IfTrueNode(iff);
1938 Node* untaken_branch = new IfFalseNode(iff);
1939 if (!taken_if_true) { // Finish conversion to canonical form
1940 Node* tmp = taken_branch;
1941 taken_branch = untaken_branch;
1942 untaken_branch = tmp;
1943 }
1944
1945 // Branch is taken:
1946 { PreserveJVMState pjvms(this);
1947 taken_branch = _gvn.transform(taken_branch);
1948 set_control(taken_branch);
1949
1950 if (stopped()) {
1951 if (C->eliminate_boxing() && !new_path) {
1952 // Mark the successor block as parsed (if we haven't created a new path)
1953 branch_block->next_path_num();
1954 }
1955 } else {
1956 adjust_map_after_if(taken_btest, c, prob, branch_block, can_trap);
1957 if (!stopped()) {
1958 if (new_path) {
1959 // Merge by using a new path
1960 merge_new_path(target_bci);
1961 } else if (ctrl_taken != nullptr) {
1962 // Don't merge but save taken branch to be wired by caller
1963 *ctrl_taken = control();
1964 if (mem_taken != nullptr) {
1965 *mem_taken = reset_memory();
1966 }
1967 if (io_taken != nullptr) {
1968 *io_taken = i_o();
1969 }
1970 } else {
1971 merge(target_bci);
1972 }
1973 }
1974 }
1975 }
1976
1977 untaken_branch = _gvn.transform(untaken_branch);
1978 set_control(untaken_branch);
1979
1980 // Branch not taken.
1981 if (stopped() && ctrl_taken == nullptr) {
1982 if (C->eliminate_boxing()) {
1983 // Mark the successor block as parsed (if caller does not re-wire control flow)
1984 next_block->next_path_num();
1985 }
1986 } else {
1987 adjust_map_after_if(untaken_btest, c, untaken_prob, next_block, can_trap);
1988 }
1989
1990 if (do_stress_trap) {
1991 stress_trap(iff, counter, incr_store);
1992 }
1993 }
1994
1995
1996 static ProfilePtrKind speculative_ptr_kind(const TypeOopPtr* t) {
1997 if (t->speculative() == nullptr) {
1998 return ProfileUnknownNull;
1999 }
2000 if (t->speculative_always_null()) {
2001 return ProfileAlwaysNull;
2002 }
2003 if (t->speculative_maybe_null()) {
2004 return ProfileMaybeNull;
2005 }
2006 return ProfileNeverNull;
2007 }
2008
2009 void Parse::acmp_always_null_input(Node* input, const TypeOopPtr* tinput, BoolTest::mask btest, Node* eq_region) {
2010 if (btest == BoolTest::ne) {
2011 {
2012 PreserveJVMState pjvms(this);
2013 inc_sp(2);
2014 null_check_common(input, T_OBJECT, true, nullptr,
2015 !too_many_traps_or_recompiles(Deoptimization::Reason_speculate_null_check) &&
2016 speculative_ptr_kind(tinput) == ProfileAlwaysNull);
2017 dec_sp(2);
2018 int target_bci = iter().get_dest();
2019 merge(target_bci);
2020 }
2021 record_for_igvn(eq_region);
2022 set_control(_gvn.transform(eq_region));
2023 } else {
2024 inc_sp(2);
2025 null_check_common(input, T_OBJECT, true, nullptr,
2026 !too_many_traps_or_recompiles(Deoptimization::Reason_speculate_null_check) &&
2027 speculative_ptr_kind(tinput) == ProfileAlwaysNull);
2028 dec_sp(2);
2029 }
2030 }
2031
2032 Node* Parse::acmp_null_check(Node* input, const TypeOopPtr* tinput, ProfilePtrKind input_ptr, Node*& null_ctl) {
2033 inc_sp(2);
2034 null_ctl = top();
2035 Node* cast = null_check_oop(input, &null_ctl,
2036 input_ptr == ProfileNeverNull || (input_ptr == ProfileUnknownNull && !too_many_traps_or_recompiles(Deoptimization::Reason_null_check)),
2037 false,
2038 speculative_ptr_kind(tinput) == ProfileNeverNull &&
2039 !too_many_traps_or_recompiles(Deoptimization::Reason_speculate_null_check));
2040 dec_sp(2);
2041 return cast;
2042 }
2043
2044 void Parse::acmp_type_check_or_trap(Node** non_null_input, ciKlass* input_type, Deoptimization::DeoptReason reason) {
2045 Node* slow_ctl = type_check_receiver(*non_null_input, input_type, 1.0, non_null_input);
2046 {
2047 PreserveJVMState pjvms(this);
2048 inc_sp(2);
2049 set_control(slow_ctl);
2050 uncommon_trap_exact(reason, Deoptimization::Action_maybe_recompile);
2051 }
2052 }
2053
2054 void Parse::acmp_type_check(Node* input, const TypeOopPtr* tinput, ProfilePtrKind input_ptr, ciKlass* input_type, BoolTest::mask btest, Node* eq_region) {
2055 Node* null_ctl;
2056 Node* cast = acmp_null_check(input, tinput, input_ptr, null_ctl);
2057
2058 if (input_type != nullptr) {
2059 Deoptimization::DeoptReason reason;
2060 if (tinput->speculative_type() != nullptr && !too_many_traps_or_recompiles(Deoptimization::Reason_speculate_class_check)) {
2061 reason = Deoptimization::Reason_speculate_class_check;
2062 } else {
2063 reason = Deoptimization::Reason_class_check;
2064 }
2065 acmp_type_check_or_trap(&cast, input_type, reason);
2066 } else {
2067 // No specific type, check for inline type
2068 BuildCutout unless(this, inline_type_test(cast, /* is_inline = */ false), PROB_MAX);
2069 inc_sp(2);
2070 uncommon_trap_exact(Deoptimization::Reason_class_check, Deoptimization::Action_maybe_recompile);
2071 }
2072
2073 Node* ne_region = new RegionNode(2);
2074 ne_region->add_req(null_ctl);
2075 ne_region->add_req(control());
2076
2077 record_for_igvn(ne_region);
2078 set_control(_gvn.transform(ne_region));
2079 if (btest == BoolTest::ne) {
2080 {
2081 PreserveJVMState pjvms(this);
2082 if (null_ctl == top()) {
2083 replace_in_map(input, cast);
2084 }
2085 int target_bci = iter().get_dest();
2086 merge(target_bci);
2087 }
2088 record_for_igvn(eq_region);
2089 set_control(_gvn.transform(eq_region));
2090 } else {
2091 if (null_ctl == top()) {
2092 replace_in_map(input, cast);
2093 }
2094 set_control(_gvn.transform(ne_region));
2095 }
2096 }
2097
2098 void Parse::do_acmp(BoolTest::mask btest, Node* left, Node* right) {
2099 ciKlass* left_type = nullptr;
2100 ciKlass* right_type = nullptr;
2101 ProfilePtrKind left_ptr = ProfileUnknownNull;
2102 ProfilePtrKind right_ptr = ProfileUnknownNull;
2103 bool left_inline_type = true;
2104 bool right_inline_type = true;
2105
2106 // Leverage profiling at acmp
2107 if (UseACmpProfile) {
2108 method()->acmp_profiled_type(bci(), left_type, right_type, left_ptr, right_ptr, left_inline_type, right_inline_type);
2109 if (too_many_traps_or_recompiles(Deoptimization::Reason_class_check)) {
2110 left_type = nullptr;
2111 right_type = nullptr;
2112 left_inline_type = true;
2113 right_inline_type = true;
2114 }
2115 if (too_many_traps_or_recompiles(Deoptimization::Reason_null_check)) {
2116 left_ptr = ProfileUnknownNull;
2117 right_ptr = ProfileUnknownNull;
2118 }
2119 }
2120
2121 if (UseTypeSpeculation) {
2122 record_profile_for_speculation(left, left_type, left_ptr);
2123 record_profile_for_speculation(right, right_type, right_ptr);
2124 }
2125
2126 if (!Arguments::is_valhalla_enabled()) {
2127 Node* cmp = CmpP(left, right);
2128 cmp = optimize_cmp_with_klass(cmp);
2129 do_if(btest, cmp);
2130 return;
2131 }
2132
2133 // Check for equality before potentially allocating
2134 if (left == right) {
2135 do_if(btest, makecon(TypeInt::CC_EQ));
2136 return;
2137 }
2138
2139 // Allocate inline type operands and re-execute on deoptimization
2140 if (left->is_InlineType()) {
2141 PreserveReexecuteState preexecs(this);
2142 inc_sp(2);
2143 jvms()->set_should_reexecute(true);
2144 left = left->as_InlineType()->buffer(this);
2145 }
2146 if (right->is_InlineType()) {
2147 PreserveReexecuteState preexecs(this);
2148 inc_sp(2);
2149 jvms()->set_should_reexecute(true);
2150 right = right->as_InlineType()->buffer(this);
2151 }
2152
2153 // First, do a normal pointer comparison
2154 const TypeOopPtr* tleft = _gvn.type(left)->isa_oopptr();
2155 const TypeOopPtr* tright = _gvn.type(right)->isa_oopptr();
2156 Node* cmp = CmpP(left, right);
2157 record_for_igvn(cmp);
2158 cmp = optimize_cmp_with_klass(cmp);
2159 if (tleft == nullptr || !tleft->can_be_inline_type() ||
2160 tright == nullptr || !tright->can_be_inline_type()) {
2161 // This is sufficient, if one of the operands can't be an inline type
2162 do_if(btest, cmp);
2163 return;
2164 }
2165
2166 // Don't add traps to unstable if branches because additional checks are required to
2167 // decide if the operands are equal/substitutable and we therefore shouldn't prune
2168 // branches for one if based on the profiling of the acmp branches.
2169 // Also, OptimizeUnstableIf would set an incorrect re-rexecution state because it
2170 // assumes that there is a 1-1 mapping between the if and the acmp branches and that
2171 // hitting a trap means that we will take the corresponding acmp branch on re-execution.
2172 const bool can_trap = true;
2173
2174 Node* eq_region = nullptr;
2175 if (btest == BoolTest::eq) {
2176 do_if(btest, cmp, !can_trap, true);
2177 if (stopped()) {
2178 // Pointers are equal, operands must be equal
2179 return;
2180 }
2181 } else {
2182 assert(btest == BoolTest::ne, "only eq or ne");
2183 Node* is_not_equal = nullptr;
2184 eq_region = new RegionNode(4);
2185 {
2186 PreserveJVMState pjvms(this);
2187 // Pointers are not equal, but more checks are needed to determine if the operands are (not) substitutable
2188 do_if(btest, cmp, !can_trap, false, &is_not_equal);
2189 if (!stopped()) {
2190 eq_region->init_req(1, control());
2191 }
2192 }
2193 if (is_not_equal == nullptr || is_not_equal->is_top()) {
2194 record_for_igvn(eq_region);
2195 set_control(_gvn.transform(eq_region));
2196 return;
2197 }
2198 set_control(is_not_equal);
2199 }
2200
2201 // Prefer speculative types if available
2202 if (!too_many_traps_or_recompiles(Deoptimization::Reason_speculate_class_check)) {
2203 if (tleft->speculative_type() != nullptr) {
2204 left_type = tleft->speculative_type();
2205 }
2206 if (tright->speculative_type() != nullptr) {
2207 right_type = tright->speculative_type();
2208 }
2209 }
2210
2211 if (speculative_ptr_kind(tleft) != ProfileMaybeNull && speculative_ptr_kind(tleft) != ProfileUnknownNull) {
2212 ProfilePtrKind speculative_left_ptr = speculative_ptr_kind(tleft);
2213 if (speculative_left_ptr == ProfileAlwaysNull && !too_many_traps_or_recompiles(Deoptimization::Reason_speculate_null_assert)) {
2214 left_ptr = speculative_left_ptr;
2215 } else if (speculative_left_ptr == ProfileNeverNull && !too_many_traps_or_recompiles(Deoptimization::Reason_speculate_null_check)) {
2216 left_ptr = speculative_left_ptr;
2217 }
2218 }
2219 if (speculative_ptr_kind(tright) != ProfileMaybeNull && speculative_ptr_kind(tright) != ProfileUnknownNull) {
2220 ProfilePtrKind speculative_right_ptr = speculative_ptr_kind(tright);
2221 if (speculative_right_ptr == ProfileAlwaysNull && !too_many_traps_or_recompiles(Deoptimization::Reason_speculate_null_assert)) {
2222 right_ptr = speculative_right_ptr;
2223 } else if (speculative_right_ptr == ProfileNeverNull && !too_many_traps_or_recompiles(Deoptimization::Reason_speculate_null_check)) {
2224 right_ptr = speculative_right_ptr;
2225 }
2226 }
2227
2228 if (left_ptr == ProfileAlwaysNull) {
2229 // Comparison with null. Assert the input is indeed null and we're done.
2230 acmp_always_null_input(left, tleft, btest, eq_region);
2231 return;
2232 }
2233 if (right_ptr == ProfileAlwaysNull) {
2234 // Comparison with null. Assert the input is indeed null and we're done.
2235 acmp_always_null_input(right, tright, btest, eq_region);
2236 return;
2237 }
2238 if (left_type != nullptr && !left_type->is_inlinetype()) {
2239 // Comparison with an object of known type
2240 acmp_type_check(left, tleft, left_ptr, left_type, btest, eq_region);
2241 return;
2242 }
2243 if (right_type != nullptr && !right_type->is_inlinetype()) {
2244 // Comparison with an object of known type
2245 acmp_type_check(right, tright, right_ptr, right_type, btest, eq_region);
2246 return;
2247 }
2248 if (!left_inline_type) {
2249 // Comparison with an object known not to be an inline type
2250 acmp_type_check(left, tleft, left_ptr, nullptr, btest, eq_region);
2251 return;
2252 }
2253 if (!right_inline_type) {
2254 // Comparison with an object known not to be an inline type
2255 acmp_type_check(right, tright, right_ptr, nullptr, btest, eq_region);
2256 return;
2257 }
2258
2259 // Pointers are not equal, check if first operand is non-null
2260 Node* ne_region = new RegionNode(7);
2261 Node* null_ctl = nullptr;
2262 Node* not_null_left = nullptr;
2263 Node* not_null_right = acmp_null_check(right, tright, right_ptr, null_ctl);
2264 ne_region->init_req(1, null_ctl);
2265
2266 Node* kls_right = nullptr;
2267 if (!stopped()) {
2268 // First operand is non-null, check if it is the speculative inline type if possible
2269 // (which later allows isSubstitutable to be intrinsified), or any inline type if no
2270 // speculation is available.
2271 if (right_type != nullptr && right_type->is_inlinetype()) {
2272 acmp_type_check_or_trap(¬_null_right, right_type, Deoptimization::Reason_speculate_class_check);
2273 } else {
2274 Node* is_value = inline_type_test(not_null_right);
2275 IfNode* is_value_iff = create_and_map_if(control(), is_value, PROB_FAIR, COUNT_UNKNOWN);
2276 Node* not_value = _gvn.transform(new IfFalseNode(is_value_iff));
2277 ne_region->init_req(2, not_value);
2278 set_control(_gvn.transform(new IfTrueNode(is_value_iff)));
2279 }
2280
2281 // The first operand is an inline type, check if the second operand is non-null
2282 not_null_left = acmp_null_check(left, tleft, left_ptr, null_ctl);
2283 ne_region->init_req(3, null_ctl);
2284 if (!stopped()) {
2285 // Check if lhs operand is of a specific speculative inline type (see above).
2286 // If not, we don't need to enforce that the lhs is a value object since we know
2287 // it already for the rhs, and must enforce that they have the same type.
2288 if (left_type != nullptr && left_type->is_inlinetype()) {
2289 acmp_type_check_or_trap(¬_null_left, left_type, Deoptimization::Reason_speculate_class_check);
2290 }
2291 if (!stopped()) {
2292 // Check if both operands are of the same class.
2293 Node* kls_left = load_object_klass(not_null_left);
2294 kls_right = load_object_klass(not_null_right);
2295 Node* kls_cmp = CmpP(kls_left, kls_right);
2296 Node* kls_bol = _gvn.transform(new BoolNode(kls_cmp, BoolTest::ne));
2297 IfNode* kls_iff = create_and_map_if(control(), kls_bol, PROB_FAIR, COUNT_UNKNOWN);
2298 Node* kls_ne = _gvn.transform(new IfTrueNode(kls_iff));
2299 set_control(_gvn.transform(new IfFalseNode(kls_iff)));
2300 ne_region->init_req(4, kls_ne);
2301 }
2302 }
2303 }
2304
2305 if (stopped()) {
2306 record_for_igvn(ne_region);
2307 set_control(_gvn.transform(ne_region));
2308 if (btest == BoolTest::ne) {
2309 {
2310 PreserveJVMState pjvms(this);
2311 int target_bci = iter().get_dest();
2312 merge(target_bci);
2313 }
2314 record_for_igvn(eq_region);
2315 set_control(_gvn.transform(eq_region));
2316 }
2317 return;
2318 }
2319 assert(kls_right != nullptr, "");
2320
2321 IfNode* mask_iff = nullptr;
2322 // If any operand has a precisely known type, isSubstitutable will be intrinsified, so we don't need the fast path
2323 if (UseAcmpFastPath && !_gvn.type(not_null_left)->is_inlinetypeptr() && !_gvn.type(not_null_right)->is_inlinetypeptr()) {
2324 /* Here, we are generating the fast path (the slow path being the call to isSubstitutable)
2325 * See the declarations of _fast_acmp_offset and _fast_acmp_mask in InlineKlass::Members
2326 * for details about the fast path logic, and the meaning of these values.
2327 */
2328 Node* members_addr = off_heap_plus_addr(kls_right, in_bytes(InlineKlass::adr_members_offset()));
2329 Node* members = make_load(control(), members_addr, TypeRawPtr::BOTTOM, T_ADDRESS, MemNode::unordered);
2330 Node* offset_addr = off_heap_plus_addr(members, in_bytes(InlineKlass::fast_acmp_offset_offset()));
2331 Node* offset = make_load(control(), offset_addr, TypeInt::INT, T_INT, MemNode::unordered);
2332
2333 Node* offset_cmp = CmpI(offset, zerocon(T_INT));
2334 Node* offset_bol = _gvn.transform(new BoolNode(offset_cmp, BoolTest::lt));
2335 mask_iff = create_and_map_if(control(), offset_bol, PROB_FAIR, COUNT_UNKNOWN);
2336 Node* slow_path_ctl = _gvn.transform(new IfTrueNode(mask_iff));
2337 Node* fast_path_ctl = _gvn.transform(new IfFalseNode(mask_iff));
2338 set_control(slow_path_ctl);
2339
2340 {
2341 PreserveJVMState jvms(this);
2342 set_control(fast_path_ctl);
2343
2344 Node* offset_l = ConvI2L(offset);
2345 Node* fast_acmp_mask_addr = off_heap_plus_addr(members, in_bytes(InlineKlass::fast_acmp_mask_offset()));
2346 Node* fast_acmp_mask = make_load(control(), fast_acmp_mask_addr, TypeLong::LONG, T_LONG, MemNode::unordered);
2347
2348 // *(left + offset) & mask == *(right + offset) & mask
2349 Node* left_payload_addr = basic_plus_adr(not_null_left, offset_l);
2350 Node* left_payload = make_load(control(), left_payload_addr, TypeLong::LONG, T_LONG, MemNode::unordered, LoadNNode::DependsOnlyOnTest, false, true, true, true);
2351 Node* left_masked = _gvn.transform(new AndLNode(left_payload, fast_acmp_mask));
2352
2353 Node* right_payload_addr = basic_plus_adr(not_null_right, offset_l);
2354 Node* right_payload = make_load(control(), right_payload_addr, TypeLong::LONG, T_LONG, MemNode::unordered, LoadNNode::DependsOnlyOnTest, false, true, true, true);
2355 Node* right_masked = _gvn.transform(new AndLNode(right_payload, fast_acmp_mask));
2356
2357 Node* masked_cmp = CmpL(left_masked, right_masked);
2358
2359 Node* ctl = C->top();
2360 if (btest == BoolTest::eq) {
2361 PreserveJVMState pjvms(this);
2362 do_if(btest, masked_cmp, !can_trap, true, nullptr);
2363 if (!stopped()) {
2364 ctl = control();
2365 }
2366 } else {
2367 assert(btest == BoolTest::ne, "only eq or ne");
2368 PreserveJVMState pjvms(this);
2369 do_if(btest, masked_cmp, !can_trap, false, &ctl);
2370 if (!stopped()) {
2371 eq_region->init_req(3, control());
2372 }
2373 }
2374 ne_region->init_req(6, ctl);
2375 }
2376 }
2377
2378 // Both operands are values types of the same class, we need to perform a
2379 // substitutability test. Delegate to ValueObjectMethods::isSubstitutable().
2380 Node* ne_io_phi = PhiNode::make(ne_region, i_o());
2381 Node* mem = reset_memory();
2382 Node* ne_mem_phi = PhiNode::make(ne_region, mem);
2383
2384 Node* eq_io_phi = nullptr;
2385 Node* eq_mem_phi = nullptr;
2386 if (eq_region != nullptr) {
2387 eq_io_phi = PhiNode::make(eq_region, i_o());
2388 eq_mem_phi = PhiNode::make(eq_region, mem);
2389 }
2390
2391 set_all_memory(mem);
2392
2393 kill_dead_locals();
2394 ciSymbol* subst_method_name = ciSymbols::isSubstitutable_name();
2395 ciMethod* subst_method = ciEnv::current()->ValueObjectMethods_klass()->find_method(subst_method_name, ciSymbols::object_object_boolean_signature());
2396 CallStaticJavaNode* call = new CallStaticJavaNode(C, TypeFunc::make(subst_method), SharedRuntime::get_resolve_static_call_stub(), subst_method);
2397 call->set_override_symbolic_info(true);
2398 call->init_req(TypeFunc::Parms, not_null_left);
2399 call->init_req(TypeFunc::Parms+1, not_null_right);
2400 inc_sp(2);
2401 set_edges_for_java_call(call, false, false);
2402 Node* ret = set_results_for_java_call(call, false, true);
2403 dec_sp(2);
2404
2405 assert(acmp_fast_path_if_from_substitutable_call(&_gvn, call) == mask_iff, "");
2406
2407 // Test the return value of ValueObjectMethods::isSubstitutable()
2408 // This is the last check, do_if can emit traps now.
2409 Node* subst_cmp = _gvn.transform(new CmpINode(ret, intcon(1)));
2410 Node* ctl = C->top();
2411 Node* mem_taken = nullptr;
2412 Node* io_taken = nullptr;
2413 if (btest == BoolTest::eq) {
2414 PreserveJVMState pjvms(this);
2415 do_if(btest, subst_cmp, can_trap, false, nullptr, &mem_taken, &io_taken);
2416 if (!stopped()) {
2417 ctl = control();
2418 mem_taken = reset_memory();
2419 io_taken = i_o();
2420 }
2421 } else {
2422 assert(btest == BoolTest::ne, "only eq or ne");
2423 PreserveJVMState pjvms(this);
2424 do_if(btest, subst_cmp, can_trap, false, &ctl, &mem_taken, &io_taken);
2425 if (!stopped()) {
2426 eq_region->init_req(2, control());
2427 eq_io_phi->init_req(2, i_o());
2428 eq_mem_phi->init_req(2, reset_memory());
2429 }
2430 }
2431 ne_region->init_req(5, ctl);
2432 ne_io_phi->init_req(5, io_taken);
2433 ne_mem_phi->init_req(5, mem_taken);
2434
2435 record_for_igvn(ne_region);
2436 set_control(_gvn.transform(ne_region));
2437 set_i_o(_gvn.transform(ne_io_phi));
2438 set_all_memory(_gvn.transform(ne_mem_phi));
2439
2440 if (btest == BoolTest::ne) {
2441 {
2442 PreserveJVMState pjvms(this);
2443 int target_bci = iter().get_dest();
2444 merge(target_bci);
2445 }
2446
2447 record_for_igvn(eq_region);
2448 set_control(_gvn.transform(eq_region));
2449 set_i_o(_gvn.transform(eq_io_phi));
2450 set_all_memory(_gvn.transform(eq_mem_phi));
2451 }
2452 }
2453
2454 /* Detects whether a call to isSubstitutable is under an IfNode guarding the fast path for acmp.
2455 * If so, returns the IfNode branching between the call and the fast path. Returns null otherwise.
2456 *
2457 * The fast path is a LOT easier to generate at parsing time, but can be later proven useless if further
2458 * optimization narrows down the type of operands and allows intrinsification of the substitutability
2459 * check. In this case, the fast path might still apply, but it comes with various downsides, such as
2460 * mismatch access that may hinder optimizations, or buffering requirement. So, when intrinsifying the call,
2461 * we try to remove the fast path.
2462 *
2463 * This test isn't so bad. Loading the fast acmp offset is pretty unique to the fast acmp path.
2464 *
2465 * Clearly, this is only a step before a proper solution for acmp, such as a macro node.
2466 */
2467 IfNode* Parse::acmp_fast_path_if_from_substitutable_call(PhaseGVN* phase, CallStaticJavaNode* call) {
2468 auto is_con_offset = [](Node* node, ByteSize n) -> bool {
2469 if (!node->is_Con()) return false;
2470 TypeNode* con = node->as_Type();
2471 assert(con->type()->is_intptr_t(), "");
2472 return con->type()->is_intptr_t()->is_con(in_bytes(n));
2473 };
2474
2475 assert(call->in(TypeFunc::Control) != nullptr, "");
2476 if (!call->in(TypeFunc::Control)->is_IfProj()) return nullptr;
2477 IfProjNode* if_proj = call->in(TypeFunc::Control)->as_IfProj();
2478 if (if_proj->_con != 1) return nullptr;
2479
2480 assert(if_proj->in(0) != nullptr, "");
2481 assert(if_proj->in(0)->is_If(), "");
2482 IfNode* iff = if_proj->in(0)->as_If();
2483
2484 assert(iff->in(1) != nullptr, "");
2485 if (!iff->in(1)->is_Bool()) return nullptr;
2486 BoolNode* lt = iff->in(1)->as_Bool();
2487 if (lt->_test._test != BoolTest::lt) return nullptr;
2488
2489 assert(lt->in(1) != nullptr, "");
2490 if (lt->in(1)->Opcode() != Op_CmpI) return nullptr;
2491 CmpNode* cmp_i = lt->in(1)->as_Cmp();
2492
2493 assert(cmp_i->in(1) != nullptr, "");
2494 assert(cmp_i->in(2) != nullptr, "");
2495
2496 if (cmp_i->in(1)->Opcode() != Op_LoadI) return nullptr;
2497 LoadNode* load_offset = cmp_i->in(1)->as_Load();
2498 if (!cmp_i->in(2)->is_ConI()) return nullptr;
2499 ConINode* zero_i = cmp_i->in(2)->as_ConI();
2500 assert(zero_i->type()->is_int() != nullptr, "");
2501 if (!zero_i->type()->is_int()->is_con(0)) return nullptr;
2502
2503 assert(load_offset->in(2) != nullptr, "");
2504 if (!load_offset->in(2)->is_AddP()) return nullptr;
2505 AddPNode* offset_addr_add = load_offset->in(2)->as_AddP();
2506
2507 assert(offset_addr_add->in(AddPNode::Base) != nullptr, "");
2508 assert(offset_addr_add->in(AddPNode::Address) != nullptr, "");
2509 assert(offset_addr_add->in(AddPNode::Offset) != nullptr, "");
2510 if (!offset_addr_add->in(AddPNode::Base)->is_top()) return nullptr;
2511 if (offset_addr_add->in(AddPNode::Address)->Opcode() != Op_LoadP) return nullptr;
2512 LoadNode* load_members = offset_addr_add->in(AddPNode::Address)->as_Load();
2513 if (!is_con_offset(offset_addr_add->in(AddPNode::Offset), InlineKlass::fast_acmp_offset_offset())) return nullptr;
2514
2515 assert(load_members->in(2) != nullptr, "");
2516 if (!load_members->in(2)->is_AddP()) return nullptr;
2517 AddPNode* members_addr_add = load_members->in(2)->as_AddP();
2518
2519 assert(members_addr_add->in(AddPNode::Base) != nullptr, "");
2520 assert(members_addr_add->in(AddPNode::Address) != nullptr, "");
2521 assert(members_addr_add->in(AddPNode::Offset) != nullptr, "");
2522 if (!members_addr_add->in(AddPNode::Base)->is_top()) return nullptr;
2523 if (!phase->type(members_addr_add->in(AddPNode::Address))->isa_instklassptr()) return nullptr;
2524 if (!is_con_offset(members_addr_add->in(AddPNode::Offset), InlineKlass::adr_members_offset())) return nullptr;
2525
2526 return iff;
2527 }
2528
2529 // Force unstable if traps to be taken randomly to trigger intermittent bugs such as incorrect debug information.
2530 // Add another if before the unstable if that checks a "random" condition at runtime (a simple shared counter) and
2531 // then either takes the trap or executes the original, unstable if.
2532 void Parse::stress_trap(IfNode* orig_iff, Node* counter, Node* incr_store) {
2533 // Search for an unstable if trap
2534 CallStaticJavaNode* trap = nullptr;
2535 assert(orig_iff->Opcode() == Op_If && orig_iff->outcnt() == 2, "malformed if");
2536 ProjNode* trap_proj = orig_iff->uncommon_trap_proj(trap, Deoptimization::Reason_unstable_if);
2537 if (trap == nullptr || !trap->jvms()->should_reexecute()) {
2538 // No suitable trap found. Remove unused counter load and increment.
2539 C->gvn_replace_by(incr_store, incr_store->in(MemNode::Memory));
2540 return;
2541 }
2542
2543 // Remove trap from optimization list since we add another path to the trap.
2544 bool success = C->remove_unstable_if_trap(trap, true);
2545 assert(success, "Trap already modified");
2546
2547 // Add a check before the original if that will trap with a certain frequency and execute the original if otherwise
2548 int freq_log = (C->random() % 31) + 1; // Random logarithmic frequency in [1, 31]
2581 }
2582
2583 void Parse::maybe_add_predicate_after_if(Block* path) {
2584 if (path->is_SEL_head() && path->preds_parsed() == 0) {
2585 // Add predicates at bci of if dominating the loop so traps can be
2586 // recorded on the if's profile data
2587 int bc_depth = repush_if_args();
2588 add_parse_predicates();
2589 dec_sp(bc_depth);
2590 path->set_has_predicates();
2591 }
2592 }
2593
2594
2595 //----------------------------adjust_map_after_if------------------------------
2596 // Adjust the JVM state to reflect the result of taking this path.
2597 // Basically, it means inspecting the CmpNode controlling this
2598 // branch, seeing how it constrains a tested value, and then
2599 // deciding if it's worth our while to encode this constraint
2600 // as graph nodes in the current abstract interpretation map.
2601 void Parse::adjust_map_after_if(BoolTest::mask btest, Node* c, float prob, Block* path, bool can_trap) {
2602 if (!c->is_Cmp()) {
2603 maybe_add_predicate_after_if(path);
2604 return;
2605 }
2606
2607 if (stopped() || btest == BoolTest::illegal) {
2608 return; // nothing to do
2609 }
2610
2611 bool is_fallthrough = (path == successor_for_bci(iter().next_bci()));
2612
2613 if (can_trap && path_is_suitable_for_uncommon_trap(prob)) {
2614 repush_if_args();
2615 Node* call = uncommon_trap(Deoptimization::Reason_unstable_if,
2616 Deoptimization::Action_reinterpret,
2617 nullptr,
2618 (is_fallthrough ? "taken always" : "taken never"));
2619
2620 if (call != nullptr) {
2621 C->record_unstable_if_trap(new UnstableIfTrap(call->as_CallStaticJava(), path));
2622 }
2623 return;
2624 }
2625
2626 if (c->is_FlatArrayCheck()) {
2627 maybe_add_predicate_after_if(path);
2628 return;
2629 }
2630
2631 Node* val = c->in(1);
2632 Node* con = c->in(2);
2633 const Type* tcon = _gvn.type(con);
2634 const Type* tval = _gvn.type(val);
2635 bool have_con = tcon->singleton();
2636 if (tval->singleton()) {
2637 if (!have_con) {
2638 // Swap, so constant is in con.
2639 con = val;
2640 tcon = tval;
2641 val = c->in(2);
2642 tval = _gvn.type(val);
2643 btest = BoolTest(btest).commute();
2644 have_con = true;
2645 } else {
2646 // Do we have two constants? Then leave well enough alone.
2647 have_con = false;
2648 }
2649 }
2650 if (!have_con) { // remaining adjustments need a con
2776 &obj, &cast_type)) {
2777 assert(obj != nullptr && cast_type != nullptr, "missing type check info");
2778 const Type* obj_type = _gvn.type(obj);
2779 const Type* tboth = obj_type->filter_speculative(cast_type);
2780 assert(tboth->higher_equal(obj_type) && tboth->higher_equal(cast_type), "sanity");
2781 if (tboth == Type::TOP && KillPathsReachableByDeadTypeNode) {
2782 // Let dead type node cleaning logic prune effectively dead path for us.
2783 // CheckCastPP::Value() == TOP and it will trigger the cleanup during GVN.
2784 // Don't materialize the cast when cleanup is disabled, because
2785 // it kills data and control leaving IR in broken state.
2786 tboth = cast_type;
2787 }
2788 if (tboth != Type::TOP && tboth != obj_type) {
2789 int obj_in_map = map()->find_edge(obj);
2790 if (obj_in_map >= 0 &&
2791 (jvms()->is_loc(obj_in_map) || jvms()->is_stk(obj_in_map))) {
2792 TypeNode* ccast = new CheckCastPPNode(control(), obj, tboth);
2793 // Delay transform() call to allow recovery of pre-cast value at the control merge.
2794 _gvn.set_type_bottom(ccast);
2795 record_for_igvn(ccast);
2796 if (tboth->is_inlinetypeptr()) {
2797 ccast = InlineTypeNode::make_from_oop(this, ccast, tboth->isa_oopptr()->exact_klass(true)->as_inline_klass());
2798 }
2799 // Here's the payoff.
2800 replace_in_map(obj, ccast);
2801 }
2802 }
2803 }
2804
2805 int val_in_map = map()->find_edge(val);
2806 if (val_in_map < 0) return; // replace_in_map would be useless
2807 {
2808 JVMState* jvms = this->jvms();
2809 if (!(jvms->is_loc(val_in_map) ||
2810 jvms->is_stk(val_in_map)))
2811 return; // again, it would be useless
2812 }
2813
2814 // Check for a comparison to a constant, and "know" that the compared
2815 // value is constrained on this path.
2816 assert(tcon->singleton(), "");
2817 ConstraintCastNode* ccast = nullptr;
2818 Node* cast = nullptr;
2882 if (c->Opcode() == Op_CmpP &&
2883 (c->in(1)->Opcode() == Op_LoadKlass || c->in(1)->Opcode() == Op_DecodeNKlass) &&
2884 c->in(2)->is_Con()) {
2885 Node* load_klass = nullptr;
2886 Node* decode = nullptr;
2887 if (c->in(1)->Opcode() == Op_DecodeNKlass) {
2888 decode = c->in(1);
2889 load_klass = c->in(1)->in(1);
2890 } else {
2891 load_klass = c->in(1);
2892 }
2893 if (load_klass->in(2)->is_AddP()) {
2894 Node* addp = load_klass->in(2);
2895 Node* obj = addp->in(AddPNode::Address);
2896 const TypeOopPtr* obj_type = _gvn.type(obj)->is_oopptr();
2897 if (obj_type->speculative_type_not_null() != nullptr) {
2898 ciKlass* k = obj_type->speculative_type();
2899 inc_sp(2);
2900 obj = maybe_cast_profiled_obj(obj, k);
2901 dec_sp(2);
2902 if (obj->is_InlineType()) {
2903 assert(obj->as_InlineType()->is_allocated(&_gvn), "must be allocated");
2904 obj = obj->as_InlineType()->get_oop();
2905 }
2906 // Make the CmpP use the casted obj
2907 addp = basic_plus_adr(obj, addp->in(AddPNode::Offset));
2908 load_klass = load_klass->clone();
2909 load_klass->set_req(2, addp);
2910 load_klass = _gvn.transform(load_klass);
2911 if (decode != nullptr) {
2912 decode = decode->clone();
2913 decode->set_req(1, load_klass);
2914 load_klass = _gvn.transform(decode);
2915 }
2916 c = c->clone();
2917 c->set_req(1, load_klass);
2918 c = _gvn.transform(c);
2919 }
2920 }
2921 }
2922 return c;
2923 }
2924
2925 //------------------------------do_one_bytecode--------------------------------
3628 b = _gvn.transform( new ConvI2DNode(a));
3629 push_pair(b);
3630 break;
3631
3632 case Bytecodes::_iinc: // Increment local
3633 i = iter().get_index(); // Get local index
3634 set_local( i, _gvn.transform( new AddINode( _gvn.intcon(iter().get_iinc_con()), local(i) ) ) );
3635 break;
3636
3637 // Exit points of synchronized methods must have an unlock node
3638 case Bytecodes::_return:
3639 return_current(nullptr);
3640 break;
3641
3642 case Bytecodes::_ireturn:
3643 case Bytecodes::_areturn:
3644 case Bytecodes::_freturn:
3645 return_current(pop());
3646 break;
3647 case Bytecodes::_lreturn:
3648 case Bytecodes::_dreturn:
3649 return_current(pop_pair());
3650 break;
3651
3652 case Bytecodes::_athrow:
3653 // null exception oop throws null pointer exception
3654 null_check(peek());
3655 if (stopped()) return;
3656 // Hook the thrown exception directly to subsequent handlers.
3657 if (BailoutToInterpreterForThrows) {
3658 // Keep method interpreted from now on.
3659 uncommon_trap(Deoptimization::Reason_unhandled,
3660 Deoptimization::Action_make_not_compilable);
3661 return;
3662 }
3663 if (env()->jvmti_can_post_on_exceptions()) {
3664 // check if we must post exception events, take uncommon trap if so (with must_throw = false)
3665 uncommon_trap_if_should_post_on_exceptions(Deoptimization::Reason_unhandled, false);
3666 }
3667 // Here if either can_post_on_exceptions or should_post_on_exceptions is false
3681 // See if we can get some profile data and hand it off to the next block
3682 Block *target_block = block()->successor_for_bci(target_bci);
3683 if (target_block->pred_count() != 1) break;
3684 ciMethodData* methodData = method()->method_data();
3685 if (!methodData->is_mature()) break;
3686 ciProfileData* data = methodData->bci_to_data(bci());
3687 assert(data != nullptr && data->is_JumpData(), "need JumpData for taken branch");
3688 int taken = ((ciJumpData*)data)->taken();
3689 taken = method()->scale_count(taken);
3690 target_block->set_count(taken);
3691 break;
3692 }
3693
3694 case Bytecodes::_ifnull: btest = BoolTest::eq; goto handle_if_null;
3695 case Bytecodes::_ifnonnull: btest = BoolTest::ne; goto handle_if_null;
3696 handle_if_null:
3697 // If this is a backwards branch in the bytecodes, add Safepoint
3698 maybe_add_safepoint(iter().get_dest());
3699 a = null();
3700 b = pop();
3701 if (b->is_InlineType()) {
3702 // Null checking a scalarized but nullable inline type. Check the null marker
3703 // input instead of the oop input to avoid keeping buffer allocations alive
3704 c = _gvn.transform(new CmpINode(b->as_InlineType()->get_null_marker(), zerocon(T_INT)));
3705 } else {
3706 if (!_gvn.type(b)->speculative_maybe_null() &&
3707 !too_many_traps(Deoptimization::Reason_speculate_null_check)) {
3708 inc_sp(1);
3709 Node* null_ctl = top();
3710 b = null_check_oop(b, &null_ctl, true, true, true);
3711 assert(null_ctl->is_top(), "no null control here");
3712 dec_sp(1);
3713 } else if (_gvn.type(b)->speculative_always_null() &&
3714 !too_many_traps(Deoptimization::Reason_speculate_null_assert)) {
3715 inc_sp(1);
3716 b = null_assert(b);
3717 dec_sp(1);
3718 }
3719 c = _gvn.transform( new CmpPNode(b, a) );
3720 }
3721 do_ifnull(btest, c);
3722 break;
3723
3724 case Bytecodes::_if_acmpeq: btest = BoolTest::eq; goto handle_if_acmp;
3725 case Bytecodes::_if_acmpne: btest = BoolTest::ne; goto handle_if_acmp;
3726 handle_if_acmp:
3727 // If this is a backwards branch in the bytecodes, add Safepoint
3728 maybe_add_safepoint(iter().get_dest());
3729 a = pop();
3730 b = pop();
3731 do_acmp(btest, b, a);
3732 break;
3733
3734 case Bytecodes::_ifeq: btest = BoolTest::eq; goto handle_ifxx;
3735 case Bytecodes::_ifne: btest = BoolTest::ne; goto handle_ifxx;
3736 case Bytecodes::_iflt: btest = BoolTest::lt; goto handle_ifxx;
3737 case Bytecodes::_ifle: btest = BoolTest::le; goto handle_ifxx;
3738 case Bytecodes::_ifgt: btest = BoolTest::gt; goto handle_ifxx;
3739 case Bytecodes::_ifge: btest = BoolTest::ge; goto handle_ifxx;
3740 handle_ifxx:
3741 // If this is a backwards branch in the bytecodes, add Safepoint
3742 maybe_add_safepoint(iter().get_dest());
3743 a = _gvn.intcon(0);
3744 b = pop();
3745 c = _gvn.transform( new CmpINode(b, a) );
3746 do_if(btest, c);
3747 break;
3748
3749 case Bytecodes::_if_icmpeq: btest = BoolTest::eq; goto handle_if_icmp;
3750 case Bytecodes::_if_icmpne: btest = BoolTest::ne; goto handle_if_icmp;
3751 case Bytecodes::_if_icmplt: btest = BoolTest::lt; goto handle_if_icmp;
3766 break;
3767
3768 case Bytecodes::_lookupswitch:
3769 do_lookupswitch();
3770 break;
3771
3772 case Bytecodes::_invokestatic:
3773 case Bytecodes::_invokedynamic:
3774 case Bytecodes::_invokespecial:
3775 case Bytecodes::_invokevirtual:
3776 case Bytecodes::_invokeinterface:
3777 do_call();
3778 break;
3779 case Bytecodes::_checkcast:
3780 do_checkcast();
3781 break;
3782 case Bytecodes::_instanceof:
3783 do_instanceof();
3784 break;
3785 case Bytecodes::_anewarray:
3786 do_newarray();
3787 break;
3788 case Bytecodes::_newarray:
3789 do_newarray((BasicType)iter().get_index());
3790 break;
3791 case Bytecodes::_multianewarray:
3792 do_multianewarray();
3793 break;
3794 case Bytecodes::_new:
3795 do_new();
3796 break;
3797
3798 case Bytecodes::_jsr:
3799 case Bytecodes::_jsr_w:
3800 do_jsr();
3801 break;
3802
3803 case Bytecodes::_ret:
3804 do_ret();
3805 break;
3806
|