duke@435: /* mikael@6198: * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: stefank@2314: #include "precompiled.hpp" stefank@2314: #include "ci/ciMethodData.hpp" stefank@2314: #include "classfile/systemDictionary.hpp" stefank@2314: #include "classfile/vmSymbols.hpp" stefank@2314: #include "compiler/compileLog.hpp" stefank@2314: #include "interpreter/linkResolver.hpp" stefank@2314: #include "memory/universe.inline.hpp" stefank@2314: #include "opto/addnode.hpp" stefank@2314: #include "opto/divnode.hpp" stefank@2314: #include "opto/idealGraphPrinter.hpp" stefank@2314: #include "opto/matcher.hpp" stefank@2314: #include "opto/memnode.hpp" stefank@2314: #include "opto/mulnode.hpp" stefank@2314: #include "opto/parse.hpp" stefank@2314: #include "opto/runtime.hpp" stefank@2314: #include "runtime/deoptimization.hpp" stefank@2314: #include "runtime/sharedRuntime.hpp" duke@435: duke@435: extern int explicit_null_checks_inserted, duke@435: explicit_null_checks_elided; duke@435: duke@435: //---------------------------------array_load---------------------------------- duke@435: void Parse::array_load(BasicType elem_type) { duke@435: const Type* elem = Type::TOP; duke@435: Node* adr = array_addressing(elem_type, 0, &elem); twisti@1040: if (stopped()) return; // guaranteed null or range check twisti@4313: dec_sp(2); // Pop array and index duke@435: const TypeAryPtr* adr_type = TypeAryPtr::get_array_body_type(elem_type); goetz@6479: Node* ld = make_load(control(), adr, elem, elem_type, adr_type, MemNode::unordered); duke@435: push(ld); duke@435: } duke@435: duke@435: duke@435: //--------------------------------array_store---------------------------------- duke@435: void Parse::array_store(BasicType elem_type) { duke@435: Node* adr = array_addressing(elem_type, 1); twisti@1040: if (stopped()) return; // guaranteed null or range check duke@435: Node* val = pop(); twisti@4313: dec_sp(2); // Pop array and index duke@435: const TypeAryPtr* adr_type = TypeAryPtr::get_array_body_type(elem_type); goetz@6479: store_to_memory(control(), adr, val, elem_type, adr_type, StoreNode::release_if_reference(elem_type)); duke@435: } duke@435: duke@435: duke@435: //------------------------------array_addressing------------------------------- duke@435: // Pull array and index from the stack. Compute pointer-to-element. duke@435: Node* Parse::array_addressing(BasicType type, int vals, const Type* *result2) { duke@435: Node *idx = peek(0+vals); // Get from stack without popping duke@435: Node *ary = peek(1+vals); // in case of exception duke@435: duke@435: // Null check the array base, with correct stack contents twisti@4313: ary = null_check(ary, T_ARRAY); duke@435: // Compile-time detect of null-exception? duke@435: if (stopped()) return top(); duke@435: duke@435: const TypeAryPtr* arytype = _gvn.type(ary)->is_aryptr(); duke@435: const TypeInt* sizetype = arytype->size(); duke@435: const Type* elemtype = arytype->elem(); duke@435: duke@435: if (UseUniqueSubclasses && result2 != NULL) { kvn@656: const Type* el = elemtype->make_ptr(); kvn@656: if (el && el->isa_instptr()) { kvn@656: const TypeInstPtr* toop = el->is_instptr(); duke@435: if (toop->klass()->as_instance_klass()->unique_concrete_subklass()) { duke@435: // If we load from "AbstractClass[]" we must see "ConcreteSubClass". duke@435: const Type* subklass = Type::get_const_type(toop->klass()); roland@6313: elemtype = subklass->join_speculative(el); duke@435: } duke@435: } duke@435: } duke@435: duke@435: // Check for big class initializers with all constant offsets duke@435: // feeding into a known-size array. duke@435: const TypeInt* idxtype = _gvn.type(idx)->is_int(); duke@435: // See if the highest idx value is less than the lowest array bound, duke@435: // and if the idx value cannot be negative: duke@435: bool need_range_check = true; duke@435: if (idxtype->_hi < sizetype->_lo && idxtype->_lo >= 0) { duke@435: need_range_check = false; duke@435: if (C->log() != NULL) C->log()->elem("observe that='!need_range_check'"); duke@435: } duke@435: bharadwaj@4862: ciKlass * arytype_klass = arytype->klass(); bharadwaj@4862: if ((arytype_klass != NULL) && (!arytype_klass->is_loaded())) { duke@435: // Only fails for some -Xcomp runs duke@435: // The class is unloaded. We have to run this bytecode in the interpreter. duke@435: uncommon_trap(Deoptimization::Reason_unloaded, duke@435: Deoptimization::Action_reinterpret, duke@435: arytype->klass(), "!loaded array"); duke@435: return top(); duke@435: } duke@435: duke@435: // Do the range check duke@435: if (GenerateRangeChecks && need_range_check) { rasbold@564: Node* tst; rasbold@564: if (sizetype->_hi <= 0) { rasbold@801: // The greatest array bound is negative, so we can conclude that we're rasbold@564: // compiling unreachable code, but the unsigned compare trick used below rasbold@564: // only works with non-negative lengths. Instead, hack "tst" to be zero so rasbold@564: // the uncommon_trap path will always be taken. rasbold@564: tst = _gvn.intcon(0); rasbold@564: } else { rasbold@801: // Range is constant in array-oop, so we can use the original state of mem rasbold@801: Node* len = load_array_length(ary); rasbold@801: rasbold@564: // Test length vs index (standard trick using unsigned compare) kvn@4115: Node* chk = _gvn.transform( new (C) CmpUNode(idx, len) ); rasbold@564: BoolTest::mask btest = BoolTest::lt; kvn@4115: tst = _gvn.transform( new (C) BoolNode(chk, btest) ); rasbold@564: } duke@435: // Branch to failure if out of bounds duke@435: { BuildCutout unless(this, tst, PROB_MAX); duke@435: if (C->allow_range_check_smearing()) { duke@435: // Do not use builtin_throw, since range checks are sometimes duke@435: // made more stringent by an optimistic transformation. duke@435: // This creates "tentative" range checks at this point, duke@435: // which are not guaranteed to throw exceptions. duke@435: // See IfNode::Ideal, is_range_check, adjust_check. duke@435: uncommon_trap(Deoptimization::Reason_range_check, duke@435: Deoptimization::Action_make_not_entrant, duke@435: NULL, "range_check"); duke@435: } else { duke@435: // If we have already recompiled with the range-check-widening duke@435: // heroic optimization turned off, then we must really be throwing duke@435: // range check exceptions. duke@435: builtin_throw(Deoptimization::Reason_range_check, idx); duke@435: } duke@435: } duke@435: } duke@435: // Check for always knowing you are throwing a range-check exception duke@435: if (stopped()) return top(); duke@435: rasbold@801: Node* ptr = array_element_address(ary, idx, type, sizetype); duke@435: duke@435: if (result2 != NULL) *result2 = elemtype; rasbold@801: rasbold@801: assert(ptr != top(), "top should go hand-in-hand with stopped"); rasbold@801: duke@435: return ptr; duke@435: } duke@435: duke@435: duke@435: // returns IfNode duke@435: IfNode* Parse::jump_if_fork_int(Node* a, Node* b, BoolTest::mask mask) { kvn@4115: Node *cmp = _gvn.transform( new (C) CmpINode( a, b)); // two cases: shiftcount > 32 and shiftcount <= 32 kvn@4115: Node *tst = _gvn.transform( new (C) BoolNode( cmp, mask)); duke@435: IfNode *iff = create_and_map_if( control(), tst, ((mask == BoolTest::eq) ? PROB_STATIC_INFREQUENT : PROB_FAIR), COUNT_UNKNOWN ); duke@435: return iff; duke@435: } duke@435: duke@435: // return Region node duke@435: Node* Parse::jump_if_join(Node* iffalse, Node* iftrue) { kvn@4115: Node *region = new (C) RegionNode(3); // 2 results duke@435: record_for_igvn(region); duke@435: region->init_req(1, iffalse); duke@435: region->init_req(2, iftrue ); duke@435: _gvn.set_type(region, Type::CONTROL); duke@435: region = _gvn.transform(region); duke@435: set_control (region); duke@435: return region; duke@435: } duke@435: duke@435: duke@435: //------------------------------helper for tableswitch------------------------- duke@435: void Parse::jump_if_true_fork(IfNode *iff, int dest_bci_if_true, int prof_table_index) { duke@435: // True branch, use existing map info duke@435: { PreserveJVMState pjvms(this); kvn@4115: Node *iftrue = _gvn.transform( new (C) IfTrueNode (iff) ); duke@435: set_control( iftrue ); duke@435: profile_switch_case(prof_table_index); duke@435: merge_new_path(dest_bci_if_true); duke@435: } duke@435: duke@435: // False branch kvn@4115: Node *iffalse = _gvn.transform( new (C) IfFalseNode(iff) ); duke@435: set_control( iffalse ); duke@435: } duke@435: duke@435: void Parse::jump_if_false_fork(IfNode *iff, int dest_bci_if_true, int prof_table_index) { duke@435: // True branch, use existing map info duke@435: { PreserveJVMState pjvms(this); kvn@4115: Node *iffalse = _gvn.transform( new (C) IfFalseNode (iff) ); duke@435: set_control( iffalse ); duke@435: profile_switch_case(prof_table_index); duke@435: merge_new_path(dest_bci_if_true); duke@435: } duke@435: duke@435: // False branch kvn@4115: Node *iftrue = _gvn.transform( new (C) IfTrueNode(iff) ); duke@435: set_control( iftrue ); duke@435: } duke@435: duke@435: void Parse::jump_if_always_fork(int dest_bci, int prof_table_index) { duke@435: // False branch, use existing map and control() duke@435: profile_switch_case(prof_table_index); duke@435: merge_new_path(dest_bci); duke@435: } duke@435: duke@435: duke@435: extern "C" { duke@435: static int jint_cmp(const void *i, const void *j) { duke@435: int a = *(jint *)i; duke@435: int b = *(jint *)j; duke@435: return a > b ? 1 : a < b ? -1 : 0; duke@435: } duke@435: } duke@435: duke@435: duke@435: // Default value for methodData switch indexing. Must be a negative value to avoid duke@435: // conflict with any legal switch index. duke@435: #define NullTableIndex -1 duke@435: duke@435: class SwitchRange : public StackObj { duke@435: // a range of integers coupled with a bci destination duke@435: jint _lo; // inclusive lower limit duke@435: jint _hi; // inclusive upper limit duke@435: int _dest; duke@435: int _table_index; // index into method data table duke@435: duke@435: public: duke@435: jint lo() const { return _lo; } duke@435: jint hi() const { return _hi; } duke@435: int dest() const { return _dest; } duke@435: int table_index() const { return _table_index; } duke@435: bool is_singleton() const { return _lo == _hi; } duke@435: duke@435: void setRange(jint lo, jint hi, int dest, int table_index) { duke@435: assert(lo <= hi, "must be a non-empty range"); duke@435: _lo = lo, _hi = hi; _dest = dest; _table_index = table_index; duke@435: } duke@435: bool adjoinRange(jint lo, jint hi, int dest, int table_index) { duke@435: assert(lo <= hi, "must be a non-empty range"); duke@435: if (lo == _hi+1 && dest == _dest && table_index == _table_index) { duke@435: _hi = hi; duke@435: return true; duke@435: } duke@435: return false; duke@435: } duke@435: duke@435: void set (jint value, int dest, int table_index) { duke@435: setRange(value, value, dest, table_index); duke@435: } duke@435: bool adjoin(jint value, int dest, int table_index) { duke@435: return adjoinRange(value, value, dest, table_index); duke@435: } duke@435: vlivanov@5905: void print() { duke@435: if (is_singleton()) duke@435: tty->print(" {%d}=>%d", lo(), dest()); duke@435: else if (lo() == min_jint) duke@435: tty->print(" {..%d}=>%d", hi(), dest()); duke@435: else if (hi() == max_jint) duke@435: tty->print(" {%d..}=>%d", lo(), dest()); duke@435: else duke@435: tty->print(" {%d..%d}=>%d", lo(), hi(), dest()); duke@435: } duke@435: }; duke@435: duke@435: duke@435: //-------------------------------do_tableswitch-------------------------------- duke@435: void Parse::do_tableswitch() { duke@435: Node* lookup = pop(); duke@435: duke@435: // Get information about tableswitch duke@435: int default_dest = iter().get_dest_table(0); duke@435: int lo_index = iter().get_int_table(1); duke@435: int hi_index = iter().get_int_table(2); duke@435: int len = hi_index - lo_index + 1; duke@435: duke@435: if (len < 1) { duke@435: // If this is a backward branch, add safepoint duke@435: maybe_add_safepoint(default_dest); duke@435: merge(default_dest); duke@435: return; duke@435: } duke@435: duke@435: // generate decision tree, using trichotomy when possible duke@435: int rnum = len+2; duke@435: bool makes_backward_branch = false; duke@435: SwitchRange* ranges = NEW_RESOURCE_ARRAY(SwitchRange, rnum); duke@435: int rp = -1; duke@435: if (lo_index != min_jint) { duke@435: ranges[++rp].setRange(min_jint, lo_index-1, default_dest, NullTableIndex); duke@435: } duke@435: for (int j = 0; j < len; j++) { duke@435: jint match_int = lo_index+j; duke@435: int dest = iter().get_dest_table(j+3); duke@435: makes_backward_branch |= (dest <= bci()); duke@435: int table_index = method_data_update() ? j : NullTableIndex; duke@435: if (rp < 0 || !ranges[rp].adjoin(match_int, dest, table_index)) { duke@435: ranges[++rp].set(match_int, dest, table_index); duke@435: } duke@435: } duke@435: jint highest = lo_index+(len-1); duke@435: assert(ranges[rp].hi() == highest, ""); duke@435: if (highest != max_jint duke@435: && !ranges[rp].adjoinRange(highest+1, max_jint, default_dest, NullTableIndex)) { duke@435: ranges[++rp].setRange(highest+1, max_jint, default_dest, NullTableIndex); duke@435: } duke@435: assert(rp < len+2, "not too many ranges"); duke@435: duke@435: // Safepoint in case if backward branch observed duke@435: if( makes_backward_branch && UseLoopSafepoints ) duke@435: add_safepoint(); duke@435: duke@435: jump_switch_ranges(lookup, &ranges[0], &ranges[rp]); duke@435: } duke@435: duke@435: duke@435: //------------------------------do_lookupswitch-------------------------------- duke@435: void Parse::do_lookupswitch() { duke@435: Node *lookup = pop(); // lookup value duke@435: // Get information about lookupswitch duke@435: int default_dest = iter().get_dest_table(0); duke@435: int len = iter().get_int_table(1); duke@435: duke@435: if (len < 1) { // If this is a backward branch, add safepoint duke@435: maybe_add_safepoint(default_dest); duke@435: merge(default_dest); duke@435: return; duke@435: } duke@435: duke@435: // generate decision tree, using trichotomy when possible duke@435: jint* table = NEW_RESOURCE_ARRAY(jint, len*2); duke@435: { duke@435: for( int j = 0; j < len; j++ ) { duke@435: table[j+j+0] = iter().get_int_table(2+j+j); duke@435: table[j+j+1] = iter().get_dest_table(2+j+j+1); duke@435: } duke@435: qsort( table, len, 2*sizeof(table[0]), jint_cmp ); duke@435: } duke@435: duke@435: int rnum = len*2+1; duke@435: bool makes_backward_branch = false; duke@435: SwitchRange* ranges = NEW_RESOURCE_ARRAY(SwitchRange, rnum); duke@435: int rp = -1; duke@435: for( int j = 0; j < len; j++ ) { duke@435: jint match_int = table[j+j+0]; duke@435: int dest = table[j+j+1]; duke@435: int next_lo = rp < 0 ? min_jint : ranges[rp].hi()+1; duke@435: int table_index = method_data_update() ? j : NullTableIndex; duke@435: makes_backward_branch |= (dest <= bci()); duke@435: if( match_int != next_lo ) { duke@435: ranges[++rp].setRange(next_lo, match_int-1, default_dest, NullTableIndex); duke@435: } duke@435: if( rp < 0 || !ranges[rp].adjoin(match_int, dest, table_index) ) { duke@435: ranges[++rp].set(match_int, dest, table_index); duke@435: } duke@435: } duke@435: jint highest = table[2*(len-1)]; duke@435: assert(ranges[rp].hi() == highest, ""); duke@435: if( highest != max_jint duke@435: && !ranges[rp].adjoinRange(highest+1, max_jint, default_dest, NullTableIndex) ) { duke@435: ranges[++rp].setRange(highest+1, max_jint, default_dest, NullTableIndex); duke@435: } duke@435: assert(rp < rnum, "not too many ranges"); duke@435: duke@435: // Safepoint in case backward branch observed duke@435: if( makes_backward_branch && UseLoopSafepoints ) duke@435: add_safepoint(); duke@435: duke@435: jump_switch_ranges(lookup, &ranges[0], &ranges[rp]); duke@435: } duke@435: duke@435: //----------------------------create_jump_tables------------------------------- duke@435: bool Parse::create_jump_tables(Node* key_val, SwitchRange* lo, SwitchRange* hi) { duke@435: // Are jumptables enabled duke@435: if (!UseJumpTables) return false; duke@435: duke@435: // Are jumptables supported duke@435: if (!Matcher::has_match_rule(Op_Jump)) return false; duke@435: duke@435: // Don't make jump table if profiling duke@435: if (method_data_update()) return false; duke@435: duke@435: // Decide if a guard is needed to lop off big ranges at either (or duke@435: // both) end(s) of the input set. We'll call this the default target duke@435: // even though we can't be sure that it is the true "default". duke@435: duke@435: bool needs_guard = false; duke@435: int default_dest; duke@435: int64 total_outlier_size = 0; duke@435: int64 hi_size = ((int64)hi->hi()) - ((int64)hi->lo()) + 1; duke@435: int64 lo_size = ((int64)lo->hi()) - ((int64)lo->lo()) + 1; duke@435: duke@435: if (lo->dest() == hi->dest()) { duke@435: total_outlier_size = hi_size + lo_size; duke@435: default_dest = lo->dest(); duke@435: } else if (lo_size > hi_size) { duke@435: total_outlier_size = lo_size; duke@435: default_dest = lo->dest(); duke@435: } else { duke@435: total_outlier_size = hi_size; duke@435: default_dest = hi->dest(); duke@435: } duke@435: duke@435: // If a guard test will eliminate very sparse end ranges, then duke@435: // it is worth the cost of an extra jump. duke@435: if (total_outlier_size > (MaxJumpTableSparseness * 4)) { duke@435: needs_guard = true; duke@435: if (default_dest == lo->dest()) lo++; duke@435: if (default_dest == hi->dest()) hi--; duke@435: } duke@435: duke@435: // Find the total number of cases and ranges duke@435: int64 num_cases = ((int64)hi->hi()) - ((int64)lo->lo()) + 1; duke@435: int num_range = hi - lo + 1; duke@435: duke@435: // Don't create table if: too large, too small, or too sparse. duke@435: if (num_cases < MinJumpTableSize || num_cases > MaxJumpTableSize) duke@435: return false; duke@435: if (num_cases > (MaxJumpTableSparseness * num_range)) duke@435: return false; duke@435: duke@435: // Normalize table lookups to zero duke@435: int lowval = lo->lo(); kvn@4115: key_val = _gvn.transform( new (C) SubINode(key_val, _gvn.intcon(lowval)) ); duke@435: duke@435: // Generate a guard to protect against input keyvals that aren't duke@435: // in the switch domain. duke@435: if (needs_guard) { duke@435: Node* size = _gvn.intcon(num_cases); kvn@4115: Node* cmp = _gvn.transform( new (C) CmpUNode(key_val, size) ); kvn@4115: Node* tst = _gvn.transform( new (C) BoolNode(cmp, BoolTest::ge) ); duke@435: IfNode* iff = create_and_map_if( control(), tst, PROB_FAIR, COUNT_UNKNOWN); duke@435: jump_if_true_fork(iff, default_dest, NullTableIndex); duke@435: } duke@435: duke@435: // Create an ideal node JumpTable that has projections duke@435: // of all possible ranges for a switch statement duke@435: // The key_val input must be converted to a pointer offset and scaled. duke@435: // Compare Parse::array_addressing above. duke@435: #ifdef _LP64 duke@435: // Clean the 32-bit int into a real 64-bit offset. duke@435: // Otherwise, the jint value 0 might turn into an offset of 0x0800000000. duke@435: const TypeLong* lkeytype = TypeLong::make(CONST64(0), num_cases-1, Type::WidenMin); kvn@4115: key_val = _gvn.transform( new (C) ConvI2LNode(key_val, lkeytype) ); duke@435: #endif duke@435: // Shift the value by wordsize so we have an index into the table, rather duke@435: // than a switch value duke@435: Node *shiftWord = _gvn.MakeConX(wordSize); kvn@4115: key_val = _gvn.transform( new (C) MulXNode( key_val, shiftWord)); duke@435: duke@435: // Create the JumpNode kvn@4115: Node* jtn = _gvn.transform( new (C) JumpNode(control(), key_val, num_cases) ); duke@435: duke@435: // These are the switch destinations hanging off the jumpnode duke@435: int i = 0; duke@435: for (SwitchRange* r = lo; r <= hi; r++) { vlivanov@5905: for (int64 j = r->lo(); j <= r->hi(); j++, i++) { vlivanov@5905: Node* input = _gvn.transform(new (C) JumpProjNode(jtn, i, r->dest(), (int)(j - lowval))); duke@435: { duke@435: PreserveJVMState pjvms(this); duke@435: set_control(input); duke@435: jump_if_always_fork(r->dest(), r->table_index()); duke@435: } duke@435: } duke@435: } duke@435: assert(i == num_cases, "miscount of cases"); duke@435: stop_and_kill_map(); // no more uses for this JVMS duke@435: return true; duke@435: } duke@435: duke@435: //----------------------------jump_switch_ranges------------------------------- duke@435: void Parse::jump_switch_ranges(Node* key_val, SwitchRange *lo, SwitchRange *hi, int switch_depth) { duke@435: Block* switch_block = block(); duke@435: duke@435: if (switch_depth == 0) { duke@435: // Do special processing for the top-level call. duke@435: assert(lo->lo() == min_jint, "initial range must exhaust Type::INT"); duke@435: assert(hi->hi() == max_jint, "initial range must exhaust Type::INT"); duke@435: duke@435: // Decrement pred-numbers for the unique set of nodes. duke@435: #ifdef ASSERT duke@435: // Ensure that the block's successors are a (duplicate-free) set. duke@435: int successors_counted = 0; // block occurrences in [hi..lo] duke@435: int unique_successors = switch_block->num_successors(); duke@435: for (int i = 0; i < unique_successors; i++) { duke@435: Block* target = switch_block->successor_at(i); duke@435: duke@435: // Check that the set of successors is the same in both places. duke@435: int successors_found = 0; duke@435: for (SwitchRange* p = lo; p <= hi; p++) { duke@435: if (p->dest() == target->start()) successors_found++; duke@435: } duke@435: assert(successors_found > 0, "successor must be known"); duke@435: successors_counted += successors_found; duke@435: } duke@435: assert(successors_counted == (hi-lo)+1, "no unexpected successors"); duke@435: #endif duke@435: duke@435: // Maybe prune the inputs, based on the type of key_val. duke@435: jint min_val = min_jint; duke@435: jint max_val = max_jint; duke@435: const TypeInt* ti = key_val->bottom_type()->isa_int(); duke@435: if (ti != NULL) { duke@435: min_val = ti->_lo; duke@435: max_val = ti->_hi; duke@435: assert(min_val <= max_val, "invalid int type"); duke@435: } duke@435: while (lo->hi() < min_val) lo++; duke@435: if (lo->lo() < min_val) lo->setRange(min_val, lo->hi(), lo->dest(), lo->table_index()); duke@435: while (hi->lo() > max_val) hi--; duke@435: if (hi->hi() > max_val) hi->setRange(hi->lo(), max_val, hi->dest(), hi->table_index()); duke@435: } duke@435: duke@435: #ifndef PRODUCT duke@435: if (switch_depth == 0) { duke@435: _max_switch_depth = 0; duke@435: _est_switch_depth = log2_intptr((hi-lo+1)-1)+1; duke@435: } duke@435: #endif duke@435: duke@435: assert(lo <= hi, "must be a non-empty set of ranges"); duke@435: if (lo == hi) { duke@435: jump_if_always_fork(lo->dest(), lo->table_index()); duke@435: } else { duke@435: assert(lo->hi() == (lo+1)->lo()-1, "contiguous ranges"); duke@435: assert(hi->lo() == (hi-1)->hi()+1, "contiguous ranges"); duke@435: duke@435: if (create_jump_tables(key_val, lo, hi)) return; duke@435: duke@435: int nr = hi - lo + 1; duke@435: duke@435: SwitchRange* mid = lo + nr/2; duke@435: // if there is an easy choice, pivot at a singleton: duke@435: if (nr > 3 && !mid->is_singleton() && (mid-1)->is_singleton()) mid--; duke@435: duke@435: assert(lo < mid && mid <= hi, "good pivot choice"); duke@435: assert(nr != 2 || mid == hi, "should pick higher of 2"); duke@435: assert(nr != 3 || mid == hi-1, "should pick middle of 3"); duke@435: duke@435: Node *test_val = _gvn.intcon(mid->lo()); duke@435: duke@435: if (mid->is_singleton()) { duke@435: IfNode *iff_ne = jump_if_fork_int(key_val, test_val, BoolTest::ne); duke@435: jump_if_false_fork(iff_ne, mid->dest(), mid->table_index()); duke@435: duke@435: // Special Case: If there are exactly three ranges, and the high duke@435: // and low range each go to the same place, omit the "gt" test, duke@435: // since it will not discriminate anything. duke@435: bool eq_test_only = (hi == lo+2 && hi->dest() == lo->dest()); duke@435: if (eq_test_only) { duke@435: assert(mid == hi-1, ""); duke@435: } duke@435: duke@435: // if there is a higher range, test for it and process it: duke@435: if (mid < hi && !eq_test_only) { duke@435: // two comparisons of same values--should enable 1 test for 2 branches duke@435: // Use BoolTest::le instead of BoolTest::gt duke@435: IfNode *iff_le = jump_if_fork_int(key_val, test_val, BoolTest::le); kvn@4115: Node *iftrue = _gvn.transform( new (C) IfTrueNode(iff_le) ); kvn@4115: Node *iffalse = _gvn.transform( new (C) IfFalseNode(iff_le) ); duke@435: { PreserveJVMState pjvms(this); duke@435: set_control(iffalse); duke@435: jump_switch_ranges(key_val, mid+1, hi, switch_depth+1); duke@435: } duke@435: set_control(iftrue); duke@435: } duke@435: duke@435: } else { duke@435: // mid is a range, not a singleton, so treat mid..hi as a unit duke@435: IfNode *iff_ge = jump_if_fork_int(key_val, test_val, BoolTest::ge); duke@435: duke@435: // if there is a higher range, test for it and process it: duke@435: if (mid == hi) { duke@435: jump_if_true_fork(iff_ge, mid->dest(), mid->table_index()); duke@435: } else { kvn@4115: Node *iftrue = _gvn.transform( new (C) IfTrueNode(iff_ge) ); kvn@4115: Node *iffalse = _gvn.transform( new (C) IfFalseNode(iff_ge) ); duke@435: { PreserveJVMState pjvms(this); duke@435: set_control(iftrue); duke@435: jump_switch_ranges(key_val, mid, hi, switch_depth+1); duke@435: } duke@435: set_control(iffalse); duke@435: } duke@435: } duke@435: duke@435: // in any case, process the lower range duke@435: jump_switch_ranges(key_val, lo, mid-1, switch_depth+1); duke@435: } duke@435: duke@435: // Decrease pred_count for each successor after all is done. duke@435: if (switch_depth == 0) { duke@435: int unique_successors = switch_block->num_successors(); duke@435: for (int i = 0; i < unique_successors; i++) { duke@435: Block* target = switch_block->successor_at(i); duke@435: // Throw away the pre-allocated path for each unique successor. duke@435: target->next_path_num(); duke@435: } duke@435: } duke@435: duke@435: #ifndef PRODUCT duke@435: _max_switch_depth = MAX2(switch_depth, _max_switch_depth); duke@435: if (TraceOptoParse && Verbose && WizardMode && switch_depth == 0) { duke@435: SwitchRange* r; duke@435: int nsing = 0; duke@435: for( r = lo; r <= hi; r++ ) { duke@435: if( r->is_singleton() ) nsing++; duke@435: } duke@435: tty->print(">>> "); duke@435: _method->print_short_name(); duke@435: tty->print_cr(" switch decision tree"); duke@435: tty->print_cr(" %d ranges (%d singletons), max_depth=%d, est_depth=%d", duke@435: hi-lo+1, nsing, _max_switch_depth, _est_switch_depth); duke@435: if (_max_switch_depth > _est_switch_depth) { duke@435: tty->print_cr("******** BAD SWITCH DEPTH ********"); duke@435: } duke@435: tty->print(" "); duke@435: for( r = lo; r <= hi; r++ ) { vlivanov@5905: r->print(); duke@435: } duke@435: tty->print_cr(""); duke@435: } duke@435: #endif duke@435: } duke@435: duke@435: void Parse::modf() { duke@435: Node *f2 = pop(); duke@435: Node *f1 = pop(); duke@435: Node* c = make_runtime_call(RC_LEAF, OptoRuntime::modf_Type(), duke@435: CAST_FROM_FN_PTR(address, SharedRuntime::frem), duke@435: "frem", NULL, //no memory effects duke@435: f1, f2); kvn@4115: Node* res = _gvn.transform(new (C) ProjNode(c, TypeFunc::Parms + 0)); duke@435: duke@435: push(res); duke@435: } duke@435: duke@435: void Parse::modd() { duke@435: Node *d2 = pop_pair(); duke@435: Node *d1 = pop_pair(); duke@435: Node* c = make_runtime_call(RC_LEAF, OptoRuntime::Math_DD_D_Type(), duke@435: CAST_FROM_FN_PTR(address, SharedRuntime::drem), duke@435: "drem", NULL, //no memory effects duke@435: d1, top(), d2, top()); kvn@4115: Node* res_d = _gvn.transform(new (C) ProjNode(c, TypeFunc::Parms + 0)); duke@435: duke@435: #ifdef ASSERT kvn@4115: Node* res_top = _gvn.transform(new (C) ProjNode(c, TypeFunc::Parms + 1)); duke@435: assert(res_top == top(), "second value must be top"); duke@435: #endif duke@435: duke@435: push_pair(res_d); duke@435: } duke@435: duke@435: void Parse::l2f() { duke@435: Node* f2 = pop(); duke@435: Node* f1 = pop(); duke@435: Node* c = make_runtime_call(RC_LEAF, OptoRuntime::l2f_Type(), duke@435: CAST_FROM_FN_PTR(address, SharedRuntime::l2f), duke@435: "l2f", NULL, //no memory effects duke@435: f1, f2); kvn@4115: Node* res = _gvn.transform(new (C) ProjNode(c, TypeFunc::Parms + 0)); duke@435: duke@435: push(res); duke@435: } duke@435: duke@435: void Parse::do_irem() { duke@435: // Must keep both values on the expression-stack during null-check twisti@4313: zero_check_int(peek()); duke@435: // Compile-time detect of null-exception? duke@435: if (stopped()) return; duke@435: duke@435: Node* b = pop(); duke@435: Node* a = pop(); duke@435: duke@435: const Type *t = _gvn.type(b); duke@435: if (t != Type::TOP) { duke@435: const TypeInt *ti = t->is_int(); duke@435: if (ti->is_con()) { duke@435: int divisor = ti->get_con(); duke@435: // check for positive power of 2 duke@435: if (divisor > 0 && duke@435: (divisor & ~(divisor-1)) == divisor) { duke@435: // yes ! duke@435: Node *mask = _gvn.intcon((divisor - 1)); duke@435: // Sigh, must handle negative dividends duke@435: Node *zero = _gvn.intcon(0); duke@435: IfNode *ifff = jump_if_fork_int(a, zero, BoolTest::lt); kvn@4115: Node *iff = _gvn.transform( new (C) IfFalseNode(ifff) ); kvn@4115: Node *ift = _gvn.transform( new (C) IfTrueNode (ifff) ); duke@435: Node *reg = jump_if_join(ift, iff); duke@435: Node *phi = PhiNode::make(reg, NULL, TypeInt::INT); duke@435: // Negative path; negate/and/negate kvn@4115: Node *neg = _gvn.transform( new (C) SubINode(zero, a) ); kvn@4115: Node *andn= _gvn.transform( new (C) AndINode(neg, mask) ); kvn@4115: Node *negn= _gvn.transform( new (C) SubINode(zero, andn) ); duke@435: phi->init_req(1, negn); duke@435: // Fast positive case kvn@4115: Node *andx = _gvn.transform( new (C) AndINode(a, mask) ); duke@435: phi->init_req(2, andx); duke@435: // Push the merge duke@435: push( _gvn.transform(phi) ); duke@435: return; duke@435: } duke@435: } duke@435: } duke@435: // Default case kvn@4115: push( _gvn.transform( new (C) ModINode(control(),a,b) ) ); duke@435: } duke@435: duke@435: // Handle jsr and jsr_w bytecode duke@435: void Parse::do_jsr() { duke@435: assert(bc() == Bytecodes::_jsr || bc() == Bytecodes::_jsr_w, "wrong bytecode"); duke@435: duke@435: // Store information about current state, tagged with new _jsr_bci duke@435: int return_bci = iter().next_bci(); duke@435: int jsr_bci = (bc() == Bytecodes::_jsr) ? iter().get_dest() : iter().get_far_dest(); duke@435: duke@435: // Update method data duke@435: profile_taken_branch(jsr_bci); duke@435: duke@435: // The way we do things now, there is only one successor block duke@435: // for the jsr, because the target code is cloned by ciTypeFlow. duke@435: Block* target = successor_for_bci(jsr_bci); duke@435: duke@435: // What got pushed? duke@435: const Type* ret_addr = target->peek(); duke@435: assert(ret_addr->singleton(), "must be a constant (cloned jsr body)"); duke@435: duke@435: // Effect on jsr on stack duke@435: push(_gvn.makecon(ret_addr)); duke@435: duke@435: // Flow to the jsr. duke@435: merge(jsr_bci); duke@435: } duke@435: duke@435: // Handle ret bytecode duke@435: void Parse::do_ret() { duke@435: // Find to whom we return. duke@435: assert(block()->num_successors() == 1, "a ret can only go one place now"); duke@435: Block* target = block()->successor_at(0); duke@435: assert(!target->is_ready(), "our arrival must be expected"); duke@435: profile_ret(target->flow()->start()); duke@435: int pnum = target->next_path_num(); duke@435: merge_common(target, pnum); duke@435: } duke@435: duke@435: //--------------------------dynamic_branch_prediction-------------------------- duke@435: // Try to gather dynamic branch prediction behavior. Return a probability duke@435: // of the branch being taken and set the "cnt" field. Returns a -1.0 duke@435: // if we need to use static prediction for some reason. duke@435: float Parse::dynamic_branch_prediction(float &cnt) { duke@435: ResourceMark rm; duke@435: duke@435: cnt = COUNT_UNKNOWN; duke@435: duke@435: // Use MethodData information if it is available duke@435: // FIXME: free the ProfileData structure duke@435: ciMethodData* methodData = method()->method_data(); duke@435: if (!methodData->is_mature()) return PROB_UNKNOWN; duke@435: ciProfileData* data = methodData->bci_to_data(bci()); duke@435: if (!data->is_JumpData()) return PROB_UNKNOWN; duke@435: duke@435: // get taken and not taken values duke@435: int taken = data->as_JumpData()->taken(); duke@435: int not_taken = 0; duke@435: if (data->is_BranchData()) { duke@435: not_taken = data->as_BranchData()->not_taken(); duke@435: } duke@435: duke@435: // scale the counts to be commensurate with invocation counts: duke@435: taken = method()->scale_count(taken); duke@435: not_taken = method()->scale_count(not_taken); duke@435: iveresov@2763: // Give up if too few (or too many, in which case the sum will overflow) counts to be meaningful. iveresov@2763: // We also check that individual counters are positive first, overwise the sum can become positive. iveresov@2763: if (taken < 0 || not_taken < 0 || taken + not_taken < 40) { duke@435: if (C->log() != NULL) { duke@435: C->log()->elem("branch target_bci='%d' taken='%d' not_taken='%d'", iter().get_dest(), taken, not_taken); duke@435: } duke@435: return PROB_UNKNOWN; duke@435: } duke@435: duke@435: // Compute frequency that we arrive here iveresov@2763: float sum = taken + not_taken; duke@435: // Adjust, if this block is a cloned private block but the duke@435: // Jump counts are shared. Taken the private counts for duke@435: // just this path instead of the shared counts. duke@435: if( block()->count() > 0 ) duke@435: sum = block()->count(); iveresov@2763: cnt = sum / FreqCountInvocations; duke@435: duke@435: // Pin probability to sane limits duke@435: float prob; duke@435: if( !taken ) duke@435: prob = (0+PROB_MIN) / 2; duke@435: else if( !not_taken ) duke@435: prob = (1+PROB_MAX) / 2; duke@435: else { // Compute probability of true path duke@435: prob = (float)taken / (float)(taken + not_taken); duke@435: if (prob > PROB_MAX) prob = PROB_MAX; duke@435: if (prob < PROB_MIN) prob = PROB_MIN; duke@435: } duke@435: duke@435: assert((cnt > 0.0f) && (prob > 0.0f), duke@435: "Bad frequency assignment in if"); duke@435: duke@435: if (C->log() != NULL) { duke@435: const char* prob_str = NULL; duke@435: if (prob >= PROB_MAX) prob_str = (prob == PROB_MAX) ? "max" : "always"; duke@435: if (prob <= PROB_MIN) prob_str = (prob == PROB_MIN) ? "min" : "never"; duke@435: char prob_str_buf[30]; duke@435: if (prob_str == NULL) { duke@435: sprintf(prob_str_buf, "%g", prob); duke@435: prob_str = prob_str_buf; duke@435: } duke@435: C->log()->elem("branch target_bci='%d' taken='%d' not_taken='%d' cnt='%g' prob='%s'", duke@435: iter().get_dest(), taken, not_taken, cnt, prob_str); duke@435: } duke@435: return prob; duke@435: } duke@435: duke@435: //-----------------------------branch_prediction------------------------------- duke@435: float Parse::branch_prediction(float& cnt, duke@435: BoolTest::mask btest, duke@435: int target_bci) { duke@435: float prob = dynamic_branch_prediction(cnt); duke@435: // If prob is unknown, switch to static prediction duke@435: if (prob != PROB_UNKNOWN) return prob; duke@435: duke@435: prob = PROB_FAIR; // Set default value duke@435: if (btest == BoolTest::eq) // Exactly equal test? duke@435: prob = PROB_STATIC_INFREQUENT; // Assume its relatively infrequent duke@435: else if (btest == BoolTest::ne) duke@435: prob = PROB_STATIC_FREQUENT; // Assume its relatively frequent duke@435: duke@435: // If this is a conditional test guarding a backwards branch, duke@435: // assume its a loop-back edge. Make it a likely taken branch. duke@435: if (target_bci < bci()) { duke@435: if (is_osr_parse()) { // Could be a hot OSR'd loop; force deopt duke@435: // Since it's an OSR, we probably have profile data, but since duke@435: // branch_prediction returned PROB_UNKNOWN, the counts are too small. duke@435: // Let's make a special check here for completely zero counts. duke@435: ciMethodData* methodData = method()->method_data(); duke@435: if (!methodData->is_empty()) { duke@435: ciProfileData* data = methodData->bci_to_data(bci()); duke@435: // Only stop for truly zero counts, which mean an unknown part duke@435: // of the OSR-ed method, and we want to deopt to gather more stats. duke@435: // If you have ANY counts, then this loop is simply 'cold' relative duke@435: // to the OSR loop. duke@435: if (data->as_BranchData()->taken() + duke@435: data->as_BranchData()->not_taken() == 0 ) { duke@435: // This is the only way to return PROB_UNKNOWN: duke@435: return PROB_UNKNOWN; duke@435: } duke@435: } duke@435: } duke@435: prob = PROB_STATIC_FREQUENT; // Likely to take backwards branch duke@435: } duke@435: duke@435: assert(prob != PROB_UNKNOWN, "must have some guess at this point"); duke@435: return prob; duke@435: } duke@435: duke@435: // The magic constants are chosen so as to match the output of duke@435: // branch_prediction() when the profile reports a zero taken count. duke@435: // It is important to distinguish zero counts unambiguously, because duke@435: // some branches (e.g., _213_javac.Assembler.eliminate) validly produce duke@435: // very small but nonzero probabilities, which if confused with zero duke@435: // counts would keep the program recompiling indefinitely. duke@435: bool Parse::seems_never_taken(float prob) { duke@435: return prob < PROB_MIN; duke@435: } duke@435: jrose@2101: // True if the comparison seems to be the kind that will not change its jrose@2101: // statistics from true to false. See comments in adjust_map_after_if. jrose@2101: // This question is only asked along paths which are already jrose@2101: // classifed as untaken (by seems_never_taken), so really, jrose@2101: // if a path is never taken, its controlling comparison is jrose@2101: // already acting in a stable fashion. If the comparison jrose@2101: // seems stable, we will put an expensive uncommon trap jrose@2101: // on the untaken path. To be conservative, and to allow jrose@2101: // partially executed counted loops to be compiled fully, jrose@2101: // we will plant uncommon traps only after pointer comparisons. jrose@2101: bool Parse::seems_stable_comparison(BoolTest::mask btest, Node* cmp) { jrose@2101: for (int depth = 4; depth > 0; depth--) { jrose@2101: // The following switch can find CmpP here over half the time for jrose@2101: // dynamic language code rich with type tests. jrose@2101: // Code using counted loops or array manipulations (typical jrose@2101: // of benchmarks) will have many (>80%) CmpI instructions. jrose@2101: switch (cmp->Opcode()) { jrose@2101: case Op_CmpP: jrose@2101: // A never-taken null check looks like CmpP/BoolTest::eq. jrose@2101: // These certainly should be closed off as uncommon traps. jrose@2101: if (btest == BoolTest::eq) jrose@2101: return true; jrose@2101: // A never-failed type check looks like CmpP/BoolTest::ne. jrose@2101: // Let's put traps on those, too, so that we don't have to compile jrose@2101: // unused paths with indeterminate dynamic type information. jrose@2101: if (ProfileDynamicTypes) jrose@2101: return true; jrose@2101: return false; jrose@2101: jrose@2101: case Op_CmpI: jrose@2101: // A small minority (< 10%) of CmpP are masked as CmpI, jrose@2101: // as if by boolean conversion ((p == q? 1: 0) != 0). jrose@2101: // Detect that here, even if it hasn't optimized away yet. jrose@2101: // Specifically, this covers the 'instanceof' operator. jrose@2101: if (btest == BoolTest::ne || btest == BoolTest::eq) { jrose@2101: if (_gvn.type(cmp->in(2))->singleton() && jrose@2101: cmp->in(1)->is_Phi()) { jrose@2101: PhiNode* phi = cmp->in(1)->as_Phi(); jrose@2101: int true_path = phi->is_diamond_phi(); jrose@2101: if (true_path > 0 && jrose@2101: _gvn.type(phi->in(1))->singleton() && jrose@2101: _gvn.type(phi->in(2))->singleton()) { jrose@2101: // phi->region->if_proj->ifnode->bool->cmp jrose@2101: BoolNode* bol = phi->in(0)->in(1)->in(0)->in(1)->as_Bool(); jrose@2101: btest = bol->_test._test; jrose@2101: cmp = bol->in(1); jrose@2101: continue; jrose@2101: } jrose@2101: } jrose@2101: } jrose@2101: return false; jrose@2101: } jrose@2101: } jrose@2101: return false; jrose@2101: } jrose@2101: rasbold@681: //-------------------------------repush_if_args-------------------------------- rasbold@681: // Push arguments of an "if" bytecode back onto the stack by adjusting _sp. cfang@1607: inline int Parse::repush_if_args() { duke@435: #ifndef PRODUCT duke@435: if (PrintOpto && WizardMode) { duke@435: tty->print("defending against excessive implicit null exceptions on %s @%d in ", duke@435: Bytecodes::name(iter().cur_bc()), iter().cur_bci()); duke@435: method()->print_name(); tty->cr(); duke@435: } duke@435: #endif duke@435: int bc_depth = - Bytecodes::depth(iter().cur_bc()); duke@435: assert(bc_depth == 1 || bc_depth == 2, "only two kinds of branches"); duke@435: DEBUG_ONLY(sync_jvms()); // argument(n) requires a synced jvms duke@435: assert(argument(0) != NULL, "must exist"); duke@435: assert(bc_depth == 1 || argument(1) != NULL, "two must exist"); twisti@4313: inc_sp(bc_depth); cfang@1607: return bc_depth; duke@435: } duke@435: duke@435: //----------------------------------do_ifnull---------------------------------- rasbold@683: void Parse::do_ifnull(BoolTest::mask btest, Node *c) { duke@435: int target_bci = iter().get_dest(); duke@435: never@452: Block* branch_block = successor_for_bci(target_bci); never@452: Block* next_block = successor_for_bci(iter().next_bci()); never@452: duke@435: float cnt; duke@435: float prob = branch_prediction(cnt, btest, target_bci); duke@435: if (prob == PROB_UNKNOWN) { duke@435: // (An earlier version of do_ifnull omitted this trap for OSR methods.) duke@435: #ifndef PRODUCT duke@435: if (PrintOpto && Verbose) rasbold@683: tty->print_cr("Never-taken edge stops compilation at bci %d",bci()); duke@435: #endif rasbold@683: repush_if_args(); // to gather stats on loop duke@435: // We need to mark this branch as taken so that if we recompile we will duke@435: // see that it is possible. In the tiered system the interpreter doesn't duke@435: // do profiling and by the time we get to the lower tier from the interpreter duke@435: // the path may be cold again. Make sure it doesn't look untaken duke@435: profile_taken_branch(target_bci, !ProfileInterpreter); duke@435: uncommon_trap(Deoptimization::Reason_unreached, duke@435: Deoptimization::Action_reinterpret, duke@435: NULL, "cold"); kvn@5110: if (C->eliminate_boxing()) { never@452: // Mark the successor blocks as parsed never@452: branch_block->next_path_num(); never@452: next_block->next_path_num(); never@452: } duke@435: return; duke@435: } duke@435: duke@435: explicit_null_checks_inserted++; duke@435: duke@435: // Generate real control flow kvn@4115: Node *tst = _gvn.transform( new (C) BoolNode( c, btest ) ); duke@435: duke@435: // Sanity check the probability value duke@435: assert(prob > 0.0f,"Bad probability in Parser"); duke@435: // Need xform to put node in hash table duke@435: IfNode *iff = create_and_xform_if( control(), tst, prob, cnt ); duke@435: assert(iff->_prob > 0.0f,"Optimizer made bad probability in parser"); duke@435: // True branch duke@435: { PreserveJVMState pjvms(this); kvn@4115: Node* iftrue = _gvn.transform( new (C) IfTrueNode (iff) ); duke@435: set_control(iftrue); duke@435: duke@435: if (stopped()) { // Path is dead? duke@435: explicit_null_checks_elided++; kvn@5110: if (C->eliminate_boxing()) { never@452: // Mark the successor block as parsed never@452: branch_block->next_path_num(); never@452: } duke@435: } else { // Path is live. duke@435: // Update method data duke@435: profile_taken_branch(target_bci); duke@435: adjust_map_after_if(btest, c, prob, branch_block, next_block); cfang@1607: if (!stopped()) { duke@435: merge(target_bci); cfang@1607: } duke@435: } duke@435: } duke@435: duke@435: // False branch kvn@4115: Node* iffalse = _gvn.transform( new (C) IfFalseNode(iff) ); duke@435: set_control(iffalse); duke@435: duke@435: if (stopped()) { // Path is dead? duke@435: explicit_null_checks_elided++; kvn@5110: if (C->eliminate_boxing()) { never@452: // Mark the successor block as parsed never@452: next_block->next_path_num(); never@452: } duke@435: } else { // Path is live. duke@435: // Update method data duke@435: profile_not_taken_branch(); duke@435: adjust_map_after_if(BoolTest(btest).negate(), c, 1.0-prob, duke@435: next_block, branch_block); duke@435: } duke@435: } duke@435: duke@435: //------------------------------------do_if------------------------------------ duke@435: void Parse::do_if(BoolTest::mask btest, Node* c) { duke@435: int target_bci = iter().get_dest(); duke@435: never@452: Block* branch_block = successor_for_bci(target_bci); never@452: Block* next_block = successor_for_bci(iter().next_bci()); never@452: duke@435: float cnt; duke@435: float prob = branch_prediction(cnt, btest, target_bci); duke@435: float untaken_prob = 1.0 - prob; duke@435: duke@435: if (prob == PROB_UNKNOWN) { duke@435: #ifndef PRODUCT duke@435: if (PrintOpto && Verbose) rasbold@683: tty->print_cr("Never-taken edge stops compilation at bci %d",bci()); duke@435: #endif duke@435: repush_if_args(); // to gather stats on loop duke@435: // We need to mark this branch as taken so that if we recompile we will duke@435: // see that it is possible. In the tiered system the interpreter doesn't duke@435: // do profiling and by the time we get to the lower tier from the interpreter duke@435: // the path may be cold again. Make sure it doesn't look untaken duke@435: profile_taken_branch(target_bci, !ProfileInterpreter); duke@435: uncommon_trap(Deoptimization::Reason_unreached, duke@435: Deoptimization::Action_reinterpret, duke@435: NULL, "cold"); kvn@5110: if (C->eliminate_boxing()) { never@452: // Mark the successor blocks as parsed never@452: branch_block->next_path_num(); never@452: next_block->next_path_num(); never@452: } duke@435: return; duke@435: } duke@435: duke@435: // Sanity check the probability value duke@435: assert(0.0f < prob && prob < 1.0f,"Bad probability in Parser"); duke@435: duke@435: bool taken_if_true = true; duke@435: // Convert BoolTest to canonical form: duke@435: if (!BoolTest(btest).is_canonical()) { duke@435: btest = BoolTest(btest).negate(); duke@435: taken_if_true = false; duke@435: // prob is NOT updated here; it remains the probability of the taken duke@435: // path (as opposed to the prob of the path guarded by an 'IfTrueNode'). duke@435: } duke@435: assert(btest != BoolTest::eq, "!= is the only canonical exact test"); duke@435: kvn@4115: Node* tst0 = new (C) BoolNode(c, btest); duke@435: Node* tst = _gvn.transform(tst0); duke@435: BoolTest::mask taken_btest = BoolTest::illegal; duke@435: BoolTest::mask untaken_btest = BoolTest::illegal; kvn@472: kvn@472: if (tst->is_Bool()) { kvn@472: // Refresh c from the transformed bool node, since it may be kvn@472: // simpler than the original c. Also re-canonicalize btest. kvn@472: // This wins when (Bool ne (Conv2B p) 0) => (Bool ne (CmpP p NULL)). kvn@472: // That can arise from statements like: if (x instanceof C) ... kvn@472: if (tst != tst0) { kvn@472: // Canonicalize one more time since transform can change it. kvn@472: btest = tst->as_Bool()->_test._test; kvn@472: if (!BoolTest(btest).is_canonical()) { kvn@472: // Reverse edges one more time... kvn@472: tst = _gvn.transform( tst->as_Bool()->negate(&_gvn) ); kvn@472: btest = tst->as_Bool()->_test._test; kvn@472: assert(BoolTest(btest).is_canonical(), "sanity"); kvn@472: taken_if_true = !taken_if_true; kvn@472: } kvn@472: c = tst->in(1); kvn@472: } kvn@472: BoolTest::mask neg_btest = BoolTest(btest).negate(); kvn@472: taken_btest = taken_if_true ? btest : neg_btest; kvn@472: untaken_btest = taken_if_true ? neg_btest : btest; duke@435: } duke@435: duke@435: // Generate real control flow duke@435: float true_prob = (taken_if_true ? prob : untaken_prob); duke@435: IfNode* iff = create_and_map_if(control(), tst, true_prob, cnt); duke@435: assert(iff->_prob > 0.0f,"Optimizer made bad probability in parser"); kvn@4115: Node* taken_branch = new (C) IfTrueNode(iff); kvn@4115: Node* untaken_branch = new (C) IfFalseNode(iff); duke@435: if (!taken_if_true) { // Finish conversion to canonical form duke@435: Node* tmp = taken_branch; duke@435: taken_branch = untaken_branch; duke@435: untaken_branch = tmp; duke@435: } duke@435: duke@435: // Branch is taken: duke@435: { PreserveJVMState pjvms(this); duke@435: taken_branch = _gvn.transform(taken_branch); duke@435: set_control(taken_branch); duke@435: never@452: if (stopped()) { kvn@5110: if (C->eliminate_boxing()) { never@452: // Mark the successor block as parsed never@452: branch_block->next_path_num(); never@452: } never@452: } else { duke@435: // Update method data duke@435: profile_taken_branch(target_bci); duke@435: adjust_map_after_if(taken_btest, c, prob, branch_block, next_block); cfang@1607: if (!stopped()) { duke@435: merge(target_bci); cfang@1607: } duke@435: } duke@435: } duke@435: duke@435: untaken_branch = _gvn.transform(untaken_branch); duke@435: set_control(untaken_branch); duke@435: duke@435: // Branch not taken. never@452: if (stopped()) { kvn@5110: if (C->eliminate_boxing()) { never@452: // Mark the successor block as parsed never@452: next_block->next_path_num(); never@452: } never@452: } else { duke@435: // Update method data duke@435: profile_not_taken_branch(); duke@435: adjust_map_after_if(untaken_btest, c, untaken_prob, duke@435: next_block, branch_block); duke@435: } duke@435: } duke@435: duke@435: //----------------------------adjust_map_after_if------------------------------ duke@435: // Adjust the JVM state to reflect the result of taking this path. duke@435: // Basically, it means inspecting the CmpNode controlling this duke@435: // branch, seeing how it constrains a tested value, and then duke@435: // deciding if it's worth our while to encode this constraint duke@435: // as graph nodes in the current abstract interpretation map. duke@435: void Parse::adjust_map_after_if(BoolTest::mask btest, Node* c, float prob, duke@435: Block* path, Block* other_path) { duke@435: if (stopped() || !c->is_Cmp() || btest == BoolTest::illegal) duke@435: return; // nothing to do duke@435: duke@435: bool is_fallthrough = (path == successor_for_bci(iter().next_bci())); duke@435: jrose@2101: if (seems_never_taken(prob) && seems_stable_comparison(btest, c)) { duke@435: // If this might possibly turn into an implicit null check, duke@435: // and the null has never yet been seen, we need to generate duke@435: // an uncommon trap, so as to recompile instead of suffering duke@435: // with very slow branches. (We'll get the slow branches if duke@435: // the program ever changes phase and starts seeing nulls here.) duke@435: // jrose@2101: // We do not inspect for a null constant, since a node may duke@435: // optimize to 'null' later on. jrose@2101: // jrose@2101: // Null checks, and other tests which expect inequality, jrose@2101: // show btest == BoolTest::eq along the non-taken branch. jrose@2101: // On the other hand, type tests, must-be-null tests, jrose@2101: // and other tests which expect pointer equality, jrose@2101: // show btest == BoolTest::ne along the non-taken branch. jrose@2101: // We prune both types of branches if they look unused. duke@435: repush_if_args(); duke@435: // We need to mark this branch as taken so that if we recompile we will duke@435: // see that it is possible. In the tiered system the interpreter doesn't duke@435: // do profiling and by the time we get to the lower tier from the interpreter duke@435: // the path may be cold again. Make sure it doesn't look untaken duke@435: if (is_fallthrough) { duke@435: profile_not_taken_branch(!ProfileInterpreter); duke@435: } else { duke@435: profile_taken_branch(iter().get_dest(), !ProfileInterpreter); duke@435: } duke@435: uncommon_trap(Deoptimization::Reason_unreached, duke@435: Deoptimization::Action_reinterpret, duke@435: NULL, duke@435: (is_fallthrough ? "taken always" : "taken never")); duke@435: return; duke@435: } duke@435: duke@435: Node* val = c->in(1); duke@435: Node* con = c->in(2); duke@435: const Type* tcon = _gvn.type(con); duke@435: const Type* tval = _gvn.type(val); duke@435: bool have_con = tcon->singleton(); duke@435: if (tval->singleton()) { duke@435: if (!have_con) { duke@435: // Swap, so constant is in con. duke@435: con = val; duke@435: tcon = tval; duke@435: val = c->in(2); duke@435: tval = _gvn.type(val); duke@435: btest = BoolTest(btest).commute(); duke@435: have_con = true; duke@435: } else { duke@435: // Do we have two constants? Then leave well enough alone. duke@435: have_con = false; duke@435: } duke@435: } duke@435: if (!have_con) // remaining adjustments need a con duke@435: return; duke@435: kvn@3834: sharpen_type_after_if(btest, con, tcon, val, tval); kvn@3834: } kvn@3834: kvn@3834: kvn@3834: static Node* extract_obj_from_klass_load(PhaseGVN* gvn, Node* n) { kvn@3834: Node* ldk; roland@4159: if (n->is_DecodeNKlass()) { kvn@3834: if (n->in(1)->Opcode() != Op_LoadNKlass) { kvn@3834: return NULL; kvn@3834: } else { kvn@3834: ldk = n->in(1); kvn@3834: } kvn@3834: } else if (n->Opcode() != Op_LoadKlass) { kvn@3834: return NULL; kvn@3834: } else { kvn@3834: ldk = n; kvn@3834: } kvn@3834: assert(ldk != NULL && ldk->is_Load(), "should have found a LoadKlass or LoadNKlass node"); kvn@3834: kvn@3834: Node* adr = ldk->in(MemNode::Address); kvn@3834: intptr_t off = 0; kvn@3834: Node* obj = AddPNode::Ideal_base_and_offset(adr, gvn, off); kvn@3834: if (obj == NULL || off != oopDesc::klass_offset_in_bytes()) // loading oopDesc::_klass? kvn@3834: return NULL; kvn@3834: const TypePtr* tp = gvn->type(obj)->is_ptr(); kvn@3834: if (tp == NULL || !(tp->isa_instptr() || tp->isa_aryptr())) // is obj a Java object ptr? kvn@3834: return NULL; kvn@3834: kvn@3834: return obj; kvn@3834: } kvn@3834: kvn@3834: void Parse::sharpen_type_after_if(BoolTest::mask btest, kvn@3834: Node* con, const Type* tcon, kvn@3834: Node* val, const Type* tval) { kvn@3834: // Look for opportunities to sharpen the type of a node kvn@3834: // whose klass is compared with a constant klass. kvn@3834: if (btest == BoolTest::eq && tcon->isa_klassptr()) { kvn@3834: Node* obj = extract_obj_from_klass_load(&_gvn, val); kvn@3834: const TypeOopPtr* con_type = tcon->isa_klassptr()->as_instance_type(); kvn@3834: if (obj != NULL && (con_type->isa_instptr() || con_type->isa_aryptr())) { kvn@3834: // Found: kvn@3834: // Bool(CmpP(LoadKlass(obj._klass), ConP(Foo.klass)), [eq]) kvn@3834: // or the narrowOop equivalent. kvn@3834: const Type* obj_type = _gvn.type(obj); roland@6313: const TypeOopPtr* tboth = obj_type->join_speculative(con_type)->isa_oopptr(); kvn@3909: if (tboth != NULL && tboth->klass_is_exact() && tboth != obj_type && kvn@3909: tboth->higher_equal(obj_type)) { kvn@3834: // obj has to be of the exact type Foo if the CmpP succeeds. kvn@3834: int obj_in_map = map()->find_edge(obj); kvn@3834: JVMState* jvms = this->jvms(); kvn@3834: if (obj_in_map >= 0 && kvn@3834: (jvms->is_loc(obj_in_map) || jvms->is_stk(obj_in_map))) { kvn@4115: TypeNode* ccast = new (C) CheckCastPPNode(control(), obj, tboth); kvn@3834: const Type* tcc = ccast->as_Type()->type(); roland@6313: assert(tcc != obj_type && tcc->higher_equal_speculative(obj_type), "must improve"); kvn@3834: // Delay transform() call to allow recovery of pre-cast value kvn@3834: // at the control merge. kvn@3834: _gvn.set_type_bottom(ccast); kvn@3834: record_for_igvn(ccast); kvn@3834: // Here's the payoff. kvn@3834: replace_in_map(obj, ccast); kvn@3834: } kvn@3834: } kvn@3834: } kvn@3834: } duke@435: duke@435: int val_in_map = map()->find_edge(val); duke@435: if (val_in_map < 0) return; // replace_in_map would be useless duke@435: { duke@435: JVMState* jvms = this->jvms(); duke@435: if (!(jvms->is_loc(val_in_map) || duke@435: jvms->is_stk(val_in_map))) duke@435: return; // again, it would be useless duke@435: } duke@435: duke@435: // Check for a comparison to a constant, and "know" that the compared duke@435: // value is constrained on this path. duke@435: assert(tcon->singleton(), ""); duke@435: ConstraintCastNode* ccast = NULL; duke@435: Node* cast = NULL; duke@435: duke@435: switch (btest) { duke@435: case BoolTest::eq: // Constant test? duke@435: { roland@6313: const Type* tboth = tcon->join_speculative(tval); duke@435: if (tboth == tval) break; // Nothing to gain. duke@435: if (tcon->isa_int()) { kvn@4115: ccast = new (C) CastIINode(val, tboth); duke@435: } else if (tcon == TypePtr::NULL_PTR) { duke@435: // Cast to null, but keep the pointer identity temporarily live. kvn@4115: ccast = new (C) CastPPNode(val, tboth); duke@435: } else { duke@435: const TypeF* tf = tcon->isa_float_constant(); duke@435: const TypeD* td = tcon->isa_double_constant(); duke@435: // Exclude tests vs float/double 0 as these could be duke@435: // either +0 or -0. Just because you are equal to +0 duke@435: // doesn't mean you ARE +0! kvn@3834: // Note, following code also replaces Long and Oop values. duke@435: if ((!tf || tf->_f != 0.0) && duke@435: (!td || td->_d != 0.0)) duke@435: cast = con; // Replace non-constant val by con. duke@435: } duke@435: } duke@435: break; duke@435: duke@435: case BoolTest::ne: duke@435: if (tcon == TypePtr::NULL_PTR) { duke@435: cast = cast_not_null(val, false); duke@435: } duke@435: break; duke@435: duke@435: default: duke@435: // (At this point we could record int range types with CastII.) duke@435: break; duke@435: } duke@435: duke@435: if (ccast != NULL) { duke@435: const Type* tcc = ccast->as_Type()->type(); roland@6313: assert(tcc != tval && tcc->higher_equal_speculative(tval), "must improve"); duke@435: // Delay transform() call to allow recovery of pre-cast value duke@435: // at the control merge. duke@435: ccast->set_req(0, control()); duke@435: _gvn.set_type_bottom(ccast); duke@435: record_for_igvn(ccast); duke@435: cast = ccast; duke@435: } duke@435: duke@435: if (cast != NULL) { // Here's the payoff. duke@435: replace_in_map(val, cast); duke@435: } duke@435: } duke@435: roland@5991: /** roland@5991: * Use speculative type to optimize CmpP node: if comparison is roland@5991: * against the low level class, cast the object to the speculative roland@5991: * type if any. CmpP should then go away. roland@5991: * roland@5991: * @param c expected CmpP node roland@5991: * @return result of CmpP on object casted to speculative type roland@5991: * roland@5991: */ roland@5991: Node* Parse::optimize_cmp_with_klass(Node* c) { roland@5991: // If this is transformed by the _gvn to a comparison with the low roland@5991: // level klass then we may be able to use speculation roland@5991: if (c->Opcode() == Op_CmpP && roland@5991: (c->in(1)->Opcode() == Op_LoadKlass || c->in(1)->Opcode() == Op_DecodeNKlass) && roland@5991: c->in(2)->is_Con()) { roland@5991: Node* load_klass = NULL; roland@5991: Node* decode = NULL; roland@5991: if (c->in(1)->Opcode() == Op_DecodeNKlass) { roland@5991: decode = c->in(1); roland@5991: load_klass = c->in(1)->in(1); roland@5991: } else { roland@5991: load_klass = c->in(1); roland@5991: } roland@5991: if (load_klass->in(2)->is_AddP()) { roland@5991: Node* addp = load_klass->in(2); roland@5991: Node* obj = addp->in(AddPNode::Address); roland@5991: const TypeOopPtr* obj_type = _gvn.type(obj)->is_oopptr(); roland@5991: if (obj_type->speculative_type() != NULL) { roland@5991: ciKlass* k = obj_type->speculative_type(); roland@5991: inc_sp(2); roland@5991: obj = maybe_cast_profiled_obj(obj, k); roland@5991: dec_sp(2); roland@5991: // Make the CmpP use the casted obj roland@5991: addp = basic_plus_adr(obj, addp->in(AddPNode::Offset)); roland@5991: load_klass = load_klass->clone(); roland@5991: load_klass->set_req(2, addp); roland@5991: load_klass = _gvn.transform(load_klass); roland@5991: if (decode != NULL) { roland@5991: decode = decode->clone(); roland@5991: decode->set_req(1, load_klass); roland@5991: load_klass = _gvn.transform(decode); roland@5991: } roland@5991: c = c->clone(); roland@5991: c->set_req(1, load_klass); roland@5991: c = _gvn.transform(c); roland@5991: } roland@5991: } roland@5991: } roland@5991: return c; roland@5991: } duke@435: duke@435: //------------------------------do_one_bytecode-------------------------------- duke@435: // Parse this bytecode, and alter the Parsers JVM->Node mapping duke@435: void Parse::do_one_bytecode() { duke@435: Node *a, *b, *c, *d; // Handy temps duke@435: BoolTest::mask btest; duke@435: int i; duke@435: duke@435: assert(!has_exceptions(), "bytecode entry state must be clear of throws"); duke@435: duke@435: if (C->check_node_count(NodeLimitFudgeFactor * 5, duke@435: "out of nodes parsing method")) { duke@435: return; duke@435: } duke@435: duke@435: #ifdef ASSERT duke@435: // for setting breakpoints duke@435: if (TraceOptoParse) { duke@435: tty->print(" @"); duke@435: dump_bci(bci()); bharadwaj@4862: tty->cr(); duke@435: } duke@435: #endif duke@435: duke@435: switch (bc()) { duke@435: case Bytecodes::_nop: duke@435: // do nothing duke@435: break; duke@435: case Bytecodes::_lconst_0: duke@435: push_pair(longcon(0)); duke@435: break; duke@435: duke@435: case Bytecodes::_lconst_1: duke@435: push_pair(longcon(1)); duke@435: break; duke@435: duke@435: case Bytecodes::_fconst_0: duke@435: push(zerocon(T_FLOAT)); duke@435: break; duke@435: duke@435: case Bytecodes::_fconst_1: duke@435: push(makecon(TypeF::ONE)); duke@435: break; duke@435: duke@435: case Bytecodes::_fconst_2: duke@435: push(makecon(TypeF::make(2.0f))); duke@435: break; duke@435: duke@435: case Bytecodes::_dconst_0: duke@435: push_pair(zerocon(T_DOUBLE)); duke@435: break; duke@435: duke@435: case Bytecodes::_dconst_1: duke@435: push_pair(makecon(TypeD::ONE)); duke@435: break; duke@435: duke@435: case Bytecodes::_iconst_m1:push(intcon(-1)); break; duke@435: case Bytecodes::_iconst_0: push(intcon( 0)); break; duke@435: case Bytecodes::_iconst_1: push(intcon( 1)); break; duke@435: case Bytecodes::_iconst_2: push(intcon( 2)); break; duke@435: case Bytecodes::_iconst_3: push(intcon( 3)); break; duke@435: case Bytecodes::_iconst_4: push(intcon( 4)); break; duke@435: case Bytecodes::_iconst_5: push(intcon( 5)); break; jrose@1920: case Bytecodes::_bipush: push(intcon(iter().get_constant_u1())); break; jrose@1920: case Bytecodes::_sipush: push(intcon(iter().get_constant_u2())); break; duke@435: case Bytecodes::_aconst_null: push(null()); break; duke@435: case Bytecodes::_ldc: duke@435: case Bytecodes::_ldc_w: duke@435: case Bytecodes::_ldc2_w: duke@435: // If the constant is unresolved, run this BC once in the interpreter. jrose@1957: { duke@435: ciConstant constant = iter().get_constant(); jrose@1957: if (constant.basic_type() == T_OBJECT && jrose@1957: !constant.as_object()->is_loaded()) { jrose@1957: int index = iter().get_constant_pool_index(); jrose@1957: constantTag tag = iter().get_constant_pool_tag(index); jrose@1957: uncommon_trap(Deoptimization::make_trap_request jrose@1957: (Deoptimization::Reason_unloaded, jrose@1957: Deoptimization::Action_reinterpret, jrose@1957: index), jrose@1957: NULL, tag.internal_name()); jrose@1957: break; duke@435: } coleenp@4037: assert(constant.basic_type() != T_OBJECT || constant.as_object()->is_instance(), jrose@1957: "must be java_mirror of klass"); jrose@1424: bool pushed = push_constant(constant, true); jrose@1424: guarantee(pushed, "must be possible to push this constant"); duke@435: } duke@435: duke@435: break; duke@435: duke@435: case Bytecodes::_aload_0: duke@435: push( local(0) ); duke@435: break; duke@435: case Bytecodes::_aload_1: duke@435: push( local(1) ); duke@435: break; duke@435: case Bytecodes::_aload_2: duke@435: push( local(2) ); duke@435: break; duke@435: case Bytecodes::_aload_3: duke@435: push( local(3) ); duke@435: break; duke@435: case Bytecodes::_aload: duke@435: push( local(iter().get_index()) ); duke@435: break; duke@435: duke@435: case Bytecodes::_fload_0: duke@435: case Bytecodes::_iload_0: duke@435: push( local(0) ); duke@435: break; duke@435: case Bytecodes::_fload_1: duke@435: case Bytecodes::_iload_1: duke@435: push( local(1) ); duke@435: break; duke@435: case Bytecodes::_fload_2: duke@435: case Bytecodes::_iload_2: duke@435: push( local(2) ); duke@435: break; duke@435: case Bytecodes::_fload_3: duke@435: case Bytecodes::_iload_3: duke@435: push( local(3) ); duke@435: break; duke@435: case Bytecodes::_fload: duke@435: case Bytecodes::_iload: duke@435: push( local(iter().get_index()) ); duke@435: break; duke@435: case Bytecodes::_lload_0: duke@435: push_pair_local( 0 ); duke@435: break; duke@435: case Bytecodes::_lload_1: duke@435: push_pair_local( 1 ); duke@435: break; duke@435: case Bytecodes::_lload_2: duke@435: push_pair_local( 2 ); duke@435: break; duke@435: case Bytecodes::_lload_3: duke@435: push_pair_local( 3 ); duke@435: break; duke@435: case Bytecodes::_lload: duke@435: push_pair_local( iter().get_index() ); duke@435: break; duke@435: duke@435: case Bytecodes::_dload_0: duke@435: push_pair_local(0); duke@435: break; duke@435: case Bytecodes::_dload_1: duke@435: push_pair_local(1); duke@435: break; duke@435: case Bytecodes::_dload_2: duke@435: push_pair_local(2); duke@435: break; duke@435: case Bytecodes::_dload_3: duke@435: push_pair_local(3); duke@435: break; duke@435: case Bytecodes::_dload: duke@435: push_pair_local(iter().get_index()); duke@435: break; duke@435: case Bytecodes::_fstore_0: duke@435: case Bytecodes::_istore_0: duke@435: case Bytecodes::_astore_0: duke@435: set_local( 0, pop() ); duke@435: break; duke@435: case Bytecodes::_fstore_1: duke@435: case Bytecodes::_istore_1: duke@435: case Bytecodes::_astore_1: duke@435: set_local( 1, pop() ); duke@435: break; duke@435: case Bytecodes::_fstore_2: duke@435: case Bytecodes::_istore_2: duke@435: case Bytecodes::_astore_2: duke@435: set_local( 2, pop() ); duke@435: break; duke@435: case Bytecodes::_fstore_3: duke@435: case Bytecodes::_istore_3: duke@435: case Bytecodes::_astore_3: duke@435: set_local( 3, pop() ); duke@435: break; duke@435: case Bytecodes::_fstore: duke@435: case Bytecodes::_istore: duke@435: case Bytecodes::_astore: duke@435: set_local( iter().get_index(), pop() ); duke@435: break; duke@435: // long stores duke@435: case Bytecodes::_lstore_0: duke@435: set_pair_local( 0, pop_pair() ); duke@435: break; duke@435: case Bytecodes::_lstore_1: duke@435: set_pair_local( 1, pop_pair() ); duke@435: break; duke@435: case Bytecodes::_lstore_2: duke@435: set_pair_local( 2, pop_pair() ); duke@435: break; duke@435: case Bytecodes::_lstore_3: duke@435: set_pair_local( 3, pop_pair() ); duke@435: break; duke@435: case Bytecodes::_lstore: duke@435: set_pair_local( iter().get_index(), pop_pair() ); duke@435: break; duke@435: duke@435: // double stores duke@435: case Bytecodes::_dstore_0: duke@435: set_pair_local( 0, dstore_rounding(pop_pair()) ); duke@435: break; duke@435: case Bytecodes::_dstore_1: duke@435: set_pair_local( 1, dstore_rounding(pop_pair()) ); duke@435: break; duke@435: case Bytecodes::_dstore_2: duke@435: set_pair_local( 2, dstore_rounding(pop_pair()) ); duke@435: break; duke@435: case Bytecodes::_dstore_3: duke@435: set_pair_local( 3, dstore_rounding(pop_pair()) ); duke@435: break; duke@435: case Bytecodes::_dstore: duke@435: set_pair_local( iter().get_index(), dstore_rounding(pop_pair()) ); duke@435: break; duke@435: twisti@4313: case Bytecodes::_pop: dec_sp(1); break; twisti@4313: case Bytecodes::_pop2: dec_sp(2); break; duke@435: case Bytecodes::_swap: duke@435: a = pop(); duke@435: b = pop(); duke@435: push(a); duke@435: push(b); duke@435: break; duke@435: case Bytecodes::_dup: duke@435: a = pop(); duke@435: push(a); duke@435: push(a); duke@435: break; duke@435: case Bytecodes::_dup_x1: duke@435: a = pop(); duke@435: b = pop(); duke@435: push( a ); duke@435: push( b ); duke@435: push( a ); duke@435: break; duke@435: case Bytecodes::_dup_x2: duke@435: a = pop(); duke@435: b = pop(); duke@435: c = pop(); duke@435: push( a ); duke@435: push( c ); duke@435: push( b ); duke@435: push( a ); duke@435: break; duke@435: case Bytecodes::_dup2: duke@435: a = pop(); duke@435: b = pop(); duke@435: push( b ); duke@435: push( a ); duke@435: push( b ); duke@435: push( a ); duke@435: break; duke@435: duke@435: case Bytecodes::_dup2_x1: duke@435: // before: .. c, b, a duke@435: // after: .. b, a, c, b, a duke@435: // not tested duke@435: a = pop(); duke@435: b = pop(); duke@435: c = pop(); duke@435: push( b ); duke@435: push( a ); duke@435: push( c ); duke@435: push( b ); duke@435: push( a ); duke@435: break; duke@435: case Bytecodes::_dup2_x2: duke@435: // before: .. d, c, b, a duke@435: // after: .. b, a, d, c, b, a duke@435: // not tested duke@435: a = pop(); duke@435: b = pop(); duke@435: c = pop(); duke@435: d = pop(); duke@435: push( b ); duke@435: push( a ); duke@435: push( d ); duke@435: push( c ); duke@435: push( b ); duke@435: push( a ); duke@435: break; duke@435: duke@435: case Bytecodes::_arraylength: { duke@435: // Must do null-check with value on expression stack twisti@4313: Node *ary = null_check(peek(), T_ARRAY); duke@435: // Compile-time detect of null-exception? duke@435: if (stopped()) return; duke@435: a = pop(); duke@435: push(load_array_length(a)); duke@435: break; duke@435: } duke@435: duke@435: case Bytecodes::_baload: array_load(T_BYTE); break; duke@435: case Bytecodes::_caload: array_load(T_CHAR); break; duke@435: case Bytecodes::_iaload: array_load(T_INT); break; duke@435: case Bytecodes::_saload: array_load(T_SHORT); break; duke@435: case Bytecodes::_faload: array_load(T_FLOAT); break; duke@435: case Bytecodes::_aaload: array_load(T_OBJECT); break; duke@435: case Bytecodes::_laload: { duke@435: a = array_addressing(T_LONG, 0); twisti@1040: if (stopped()) return; // guaranteed null or range check twisti@4313: dec_sp(2); // Pop array and index goetz@6479: push_pair(make_load(control(), a, TypeLong::LONG, T_LONG, TypeAryPtr::LONGS, MemNode::unordered)); duke@435: break; duke@435: } duke@435: case Bytecodes::_daload: { duke@435: a = array_addressing(T_DOUBLE, 0); twisti@1040: if (stopped()) return; // guaranteed null or range check twisti@4313: dec_sp(2); // Pop array and index goetz@6479: push_pair(make_load(control(), a, Type::DOUBLE, T_DOUBLE, TypeAryPtr::DOUBLES, MemNode::unordered)); duke@435: break; duke@435: } duke@435: case Bytecodes::_bastore: array_store(T_BYTE); break; duke@435: case Bytecodes::_castore: array_store(T_CHAR); break; duke@435: case Bytecodes::_iastore: array_store(T_INT); break; duke@435: case Bytecodes::_sastore: array_store(T_SHORT); break; duke@435: case Bytecodes::_fastore: array_store(T_FLOAT); break; duke@435: case Bytecodes::_aastore: { duke@435: d = array_addressing(T_OBJECT, 1); twisti@1040: if (stopped()) return; // guaranteed null or range check duke@435: array_store_check(); duke@435: c = pop(); // Oop to store duke@435: b = pop(); // index (already used) duke@435: a = pop(); // the array itself never@1262: const TypeOopPtr* elemtype = _gvn.type(a)->is_aryptr()->elem()->make_oopptr(); duke@435: const TypeAryPtr* adr_type = TypeAryPtr::OOPS; goetz@6479: Node* store = store_oop_to_array(control(), a, d, adr_type, c, elemtype, T_OBJECT, MemNode::release); duke@435: break; duke@435: } duke@435: case Bytecodes::_lastore: { duke@435: a = array_addressing(T_LONG, 2); twisti@1040: if (stopped()) return; // guaranteed null or range check duke@435: c = pop_pair(); twisti@4313: dec_sp(2); // Pop array and index goetz@6479: store_to_memory(control(), a, c, T_LONG, TypeAryPtr::LONGS, MemNode::unordered); duke@435: break; duke@435: } duke@435: case Bytecodes::_dastore: { duke@435: a = array_addressing(T_DOUBLE, 2); twisti@1040: if (stopped()) return; // guaranteed null or range check duke@435: c = pop_pair(); twisti@4313: dec_sp(2); // Pop array and index duke@435: c = dstore_rounding(c); goetz@6479: store_to_memory(control(), a, c, T_DOUBLE, TypeAryPtr::DOUBLES, MemNode::unordered); duke@435: break; duke@435: } duke@435: case Bytecodes::_getfield: duke@435: do_getfield(); duke@435: break; duke@435: duke@435: case Bytecodes::_getstatic: duke@435: do_getstatic(); duke@435: break; duke@435: duke@435: case Bytecodes::_putfield: duke@435: do_putfield(); duke@435: break; duke@435: duke@435: case Bytecodes::_putstatic: duke@435: do_putstatic(); duke@435: break; duke@435: duke@435: case Bytecodes::_irem: duke@435: do_irem(); duke@435: break; duke@435: case Bytecodes::_idiv: duke@435: // Must keep both values on the expression-stack during null-check twisti@4313: zero_check_int(peek()); duke@435: // Compile-time detect of null-exception? duke@435: if (stopped()) return; duke@435: b = pop(); duke@435: a = pop(); kvn@4115: push( _gvn.transform( new (C) DivINode(control(),a,b) ) ); duke@435: break; duke@435: case Bytecodes::_imul: duke@435: b = pop(); a = pop(); kvn@4115: push( _gvn.transform( new (C) MulINode(a,b) ) ); duke@435: break; duke@435: case Bytecodes::_iadd: duke@435: b = pop(); a = pop(); kvn@4115: push( _gvn.transform( new (C) AddINode(a,b) ) ); duke@435: break; duke@435: case Bytecodes::_ineg: duke@435: a = pop(); kvn@4115: push( _gvn.transform( new (C) SubINode(_gvn.intcon(0),a)) ); duke@435: break; duke@435: case Bytecodes::_isub: duke@435: b = pop(); a = pop(); kvn@4115: push( _gvn.transform( new (C) SubINode(a,b) ) ); duke@435: break; duke@435: case Bytecodes::_iand: duke@435: b = pop(); a = pop(); kvn@4115: push( _gvn.transform( new (C) AndINode(a,b) ) ); duke@435: break; duke@435: case Bytecodes::_ior: duke@435: b = pop(); a = pop(); kvn@4115: push( _gvn.transform( new (C) OrINode(a,b) ) ); duke@435: break; duke@435: case Bytecodes::_ixor: duke@435: b = pop(); a = pop(); kvn@4115: push( _gvn.transform( new (C) XorINode(a,b) ) ); duke@435: break; duke@435: case Bytecodes::_ishl: duke@435: b = pop(); a = pop(); kvn@4115: push( _gvn.transform( new (C) LShiftINode(a,b) ) ); duke@435: break; duke@435: case Bytecodes::_ishr: duke@435: b = pop(); a = pop(); kvn@4115: push( _gvn.transform( new (C) RShiftINode(a,b) ) ); duke@435: break; duke@435: case Bytecodes::_iushr: duke@435: b = pop(); a = pop(); kvn@4115: push( _gvn.transform( new (C) URShiftINode(a,b) ) ); duke@435: break; duke@435: duke@435: case Bytecodes::_fneg: duke@435: a = pop(); kvn@4115: b = _gvn.transform(new (C) NegFNode (a)); duke@435: push(b); duke@435: break; duke@435: duke@435: case Bytecodes::_fsub: duke@435: b = pop(); duke@435: a = pop(); kvn@4115: c = _gvn.transform( new (C) SubFNode(a,b) ); duke@435: d = precision_rounding(c); duke@435: push( d ); duke@435: break; duke@435: duke@435: case Bytecodes::_fadd: duke@435: b = pop(); duke@435: a = pop(); kvn@4115: c = _gvn.transform( new (C) AddFNode(a,b) ); duke@435: d = precision_rounding(c); duke@435: push( d ); duke@435: break; duke@435: duke@435: case Bytecodes::_fmul: duke@435: b = pop(); duke@435: a = pop(); kvn@4115: c = _gvn.transform( new (C) MulFNode(a,b) ); duke@435: d = precision_rounding(c); duke@435: push( d ); duke@435: break; duke@435: duke@435: case Bytecodes::_fdiv: duke@435: b = pop(); duke@435: a = pop(); kvn@4115: c = _gvn.transform( new (C) DivFNode(0,a,b) ); duke@435: d = precision_rounding(c); duke@435: push( d ); duke@435: break; duke@435: duke@435: case Bytecodes::_frem: duke@435: if (Matcher::has_match_rule(Op_ModF)) { duke@435: // Generate a ModF node. duke@435: b = pop(); duke@435: a = pop(); kvn@4115: c = _gvn.transform( new (C) ModFNode(0,a,b) ); duke@435: d = precision_rounding(c); duke@435: push( d ); duke@435: } duke@435: else { duke@435: // Generate a call. duke@435: modf(); duke@435: } duke@435: break; duke@435: duke@435: case Bytecodes::_fcmpl: duke@435: b = pop(); duke@435: a = pop(); kvn@4115: c = _gvn.transform( new (C) CmpF3Node( a, b)); duke@435: push(c); duke@435: break; duke@435: case Bytecodes::_fcmpg: duke@435: b = pop(); duke@435: a = pop(); duke@435: duke@435: // Same as fcmpl but need to flip the unordered case. Swap the inputs, duke@435: // which negates the result sign except for unordered. Flip the unordered duke@435: // as well by using CmpF3 which implements unordered-lesser instead of duke@435: // unordered-greater semantics. Finally, commute the result bits. Result duke@435: // is same as using a CmpF3Greater except we did it with CmpF3 alone. kvn@4115: c = _gvn.transform( new (C) CmpF3Node( b, a)); kvn@4115: c = _gvn.transform( new (C) SubINode(_gvn.intcon(0),c) ); duke@435: push(c); duke@435: break; duke@435: duke@435: case Bytecodes::_f2i: duke@435: a = pop(); kvn@4115: push(_gvn.transform(new (C) ConvF2INode(a))); duke@435: break; duke@435: duke@435: case Bytecodes::_d2i: duke@435: a = pop_pair(); kvn@4115: b = _gvn.transform(new (C) ConvD2INode(a)); duke@435: push( b ); duke@435: break; duke@435: duke@435: case Bytecodes::_f2d: duke@435: a = pop(); kvn@4115: b = _gvn.transform( new (C) ConvF2DNode(a)); duke@435: push_pair( b ); duke@435: break; duke@435: duke@435: case Bytecodes::_d2f: duke@435: a = pop_pair(); kvn@4115: b = _gvn.transform( new (C) ConvD2FNode(a)); duke@435: // This breaks _227_mtrt (speed & correctness) and _222_mpegaudio (speed) kvn@4115: //b = _gvn.transform(new (C) RoundFloatNode(0, b) ); duke@435: push( b ); duke@435: break; duke@435: duke@435: case Bytecodes::_l2f: duke@435: if (Matcher::convL2FSupported()) { duke@435: a = pop_pair(); kvn@4115: b = _gvn.transform( new (C) ConvL2FNode(a)); duke@435: // For i486.ad, FILD doesn't restrict precision to 24 or 53 bits. duke@435: // Rather than storing the result into an FP register then pushing duke@435: // out to memory to round, the machine instruction that implements duke@435: // ConvL2D is responsible for rounding. duke@435: // c = precision_rounding(b); duke@435: c = _gvn.transform(b); duke@435: push(c); duke@435: } else { duke@435: l2f(); duke@435: } duke@435: break; duke@435: duke@435: case Bytecodes::_l2d: duke@435: a = pop_pair(); kvn@4115: b = _gvn.transform( new (C) ConvL2DNode(a)); duke@435: // For i486.ad, rounding is always necessary (see _l2f above). duke@435: // c = dprecision_rounding(b); duke@435: c = _gvn.transform(b); duke@435: push_pair(c); duke@435: break; duke@435: duke@435: case Bytecodes::_f2l: duke@435: a = pop(); kvn@4115: b = _gvn.transform( new (C) ConvF2LNode(a)); duke@435: push_pair(b); duke@435: break; duke@435: duke@435: case Bytecodes::_d2l: duke@435: a = pop_pair(); kvn@4115: b = _gvn.transform( new (C) ConvD2LNode(a)); duke@435: push_pair(b); duke@435: break; duke@435: duke@435: case Bytecodes::_dsub: duke@435: b = pop_pair(); duke@435: a = pop_pair(); kvn@4115: c = _gvn.transform( new (C) SubDNode(a,b) ); duke@435: d = dprecision_rounding(c); duke@435: push_pair( d ); duke@435: break; duke@435: duke@435: case Bytecodes::_dadd: duke@435: b = pop_pair(); duke@435: a = pop_pair(); kvn@4115: c = _gvn.transform( new (C) AddDNode(a,b) ); duke@435: d = dprecision_rounding(c); duke@435: push_pair( d ); duke@435: break; duke@435: duke@435: case Bytecodes::_dmul: duke@435: b = pop_pair(); duke@435: a = pop_pair(); kvn@4115: c = _gvn.transform( new (C) MulDNode(a,b) ); duke@435: d = dprecision_rounding(c); duke@435: push_pair( d ); duke@435: break; duke@435: duke@435: case Bytecodes::_ddiv: duke@435: b = pop_pair(); duke@435: a = pop_pair(); kvn@4115: c = _gvn.transform( new (C) DivDNode(0,a,b) ); duke@435: d = dprecision_rounding(c); duke@435: push_pair( d ); duke@435: break; duke@435: duke@435: case Bytecodes::_dneg: duke@435: a = pop_pair(); kvn@4115: b = _gvn.transform(new (C) NegDNode (a)); duke@435: push_pair(b); duke@435: break; duke@435: duke@435: case Bytecodes::_drem: duke@435: if (Matcher::has_match_rule(Op_ModD)) { duke@435: // Generate a ModD node. duke@435: b = pop_pair(); duke@435: a = pop_pair(); duke@435: // a % b duke@435: kvn@4115: c = _gvn.transform( new (C) ModDNode(0,a,b) ); duke@435: d = dprecision_rounding(c); duke@435: push_pair( d ); duke@435: } duke@435: else { duke@435: // Generate a call. duke@435: modd(); duke@435: } duke@435: break; duke@435: duke@435: case Bytecodes::_dcmpl: duke@435: b = pop_pair(); duke@435: a = pop_pair(); kvn@4115: c = _gvn.transform( new (C) CmpD3Node( a, b)); duke@435: push(c); duke@435: break; duke@435: duke@435: case Bytecodes::_dcmpg: duke@435: b = pop_pair(); duke@435: a = pop_pair(); duke@435: // Same as dcmpl but need to flip the unordered case. duke@435: // Commute the inputs, which negates the result sign except for unordered. duke@435: // Flip the unordered as well by using CmpD3 which implements duke@435: // unordered-lesser instead of unordered-greater semantics. duke@435: // Finally, negate the result bits. Result is same as using a duke@435: // CmpD3Greater except we did it with CmpD3 alone. kvn@4115: c = _gvn.transform( new (C) CmpD3Node( b, a)); kvn@4115: c = _gvn.transform( new (C) SubINode(_gvn.intcon(0),c) ); duke@435: push(c); duke@435: break; duke@435: duke@435: duke@435: // Note for longs -> lo word is on TOS, hi word is on TOS - 1 duke@435: case Bytecodes::_land: duke@435: b = pop_pair(); duke@435: a = pop_pair(); kvn@4115: c = _gvn.transform( new (C) AndLNode(a,b) ); duke@435: push_pair(c); duke@435: break; duke@435: case Bytecodes::_lor: duke@435: b = pop_pair(); duke@435: a = pop_pair(); kvn@4115: c = _gvn.transform( new (C) OrLNode(a,b) ); duke@435: push_pair(c); duke@435: break; duke@435: case Bytecodes::_lxor: duke@435: b = pop_pair(); duke@435: a = pop_pair(); kvn@4115: c = _gvn.transform( new (C) XorLNode(a,b) ); duke@435: push_pair(c); duke@435: break; duke@435: duke@435: case Bytecodes::_lshl: duke@435: b = pop(); // the shift count duke@435: a = pop_pair(); // value to be shifted kvn@4115: c = _gvn.transform( new (C) LShiftLNode(a,b) ); duke@435: push_pair(c); duke@435: break; duke@435: case Bytecodes::_lshr: duke@435: b = pop(); // the shift count duke@435: a = pop_pair(); // value to be shifted kvn@4115: c = _gvn.transform( new (C) RShiftLNode(a,b) ); duke@435: push_pair(c); duke@435: break; duke@435: case Bytecodes::_lushr: duke@435: b = pop(); // the shift count duke@435: a = pop_pair(); // value to be shifted kvn@4115: c = _gvn.transform( new (C) URShiftLNode(a,b) ); duke@435: push_pair(c); duke@435: break; duke@435: case Bytecodes::_lmul: duke@435: b = pop_pair(); duke@435: a = pop_pair(); kvn@4115: c = _gvn.transform( new (C) MulLNode(a,b) ); duke@435: push_pair(c); duke@435: break; duke@435: duke@435: case Bytecodes::_lrem: duke@435: // Must keep both values on the expression-stack during null-check duke@435: assert(peek(0) == top(), "long word order"); twisti@4313: zero_check_long(peek(1)); duke@435: // Compile-time detect of null-exception? duke@435: if (stopped()) return; duke@435: b = pop_pair(); duke@435: a = pop_pair(); kvn@4115: c = _gvn.transform( new (C) ModLNode(control(),a,b) ); duke@435: push_pair(c); duke@435: break; duke@435: duke@435: case Bytecodes::_ldiv: duke@435: // Must keep both values on the expression-stack during null-check duke@435: assert(peek(0) == top(), "long word order"); twisti@4313: zero_check_long(peek(1)); duke@435: // Compile-time detect of null-exception? duke@435: if (stopped()) return; duke@435: b = pop_pair(); duke@435: a = pop_pair(); kvn@4115: c = _gvn.transform( new (C) DivLNode(control(),a,b) ); duke@435: push_pair(c); duke@435: break; duke@435: duke@435: case Bytecodes::_ladd: duke@435: b = pop_pair(); duke@435: a = pop_pair(); kvn@4115: c = _gvn.transform( new (C) AddLNode(a,b) ); duke@435: push_pair(c); duke@435: break; duke@435: case Bytecodes::_lsub: duke@435: b = pop_pair(); duke@435: a = pop_pair(); kvn@4115: c = _gvn.transform( new (C) SubLNode(a,b) ); duke@435: push_pair(c); duke@435: break; duke@435: case Bytecodes::_lcmp: duke@435: // Safepoints are now inserted _before_ branches. The long-compare duke@435: // bytecode painfully produces a 3-way value (-1,0,+1) which requires a duke@435: // slew of control flow. These are usually followed by a CmpI vs zero and duke@435: // a branch; this pattern then optimizes to the obvious long-compare and duke@435: // branch. However, if the branch is backwards there's a Safepoint duke@435: // inserted. The inserted Safepoint captures the JVM state at the duke@435: // pre-branch point, i.e. it captures the 3-way value. Thus if a duke@435: // long-compare is used to control a loop the debug info will force duke@435: // computation of the 3-way value, even though the generated code uses a duke@435: // long-compare and branch. We try to rectify the situation by inserting duke@435: // a SafePoint here and have it dominate and kill the safepoint added at a duke@435: // following backwards branch. At this point the JVM state merely holds 2 duke@435: // longs but not the 3-way value. duke@435: if( UseLoopSafepoints ) { duke@435: switch( iter().next_bc() ) { duke@435: case Bytecodes::_ifgt: duke@435: case Bytecodes::_iflt: duke@435: case Bytecodes::_ifge: duke@435: case Bytecodes::_ifle: duke@435: case Bytecodes::_ifne: duke@435: case Bytecodes::_ifeq: duke@435: // If this is a backwards branch in the bytecodes, add Safepoint duke@435: maybe_add_safepoint(iter().next_get_dest()); duke@435: } duke@435: } duke@435: b = pop_pair(); duke@435: a = pop_pair(); kvn@4115: c = _gvn.transform( new (C) CmpL3Node( a, b )); duke@435: push(c); duke@435: break; duke@435: duke@435: case Bytecodes::_lneg: duke@435: a = pop_pair(); kvn@4115: b = _gvn.transform( new (C) SubLNode(longcon(0),a)); duke@435: push_pair(b); duke@435: break; duke@435: case Bytecodes::_l2i: duke@435: a = pop_pair(); kvn@4115: push( _gvn.transform( new (C) ConvL2INode(a))); duke@435: break; duke@435: case Bytecodes::_i2l: duke@435: a = pop(); kvn@4115: b = _gvn.transform( new (C) ConvI2LNode(a)); duke@435: push_pair(b); duke@435: break; duke@435: case Bytecodes::_i2b: duke@435: // Sign extend duke@435: a = pop(); kvn@4115: a = _gvn.transform( new (C) LShiftINode(a,_gvn.intcon(24)) ); kvn@4115: a = _gvn.transform( new (C) RShiftINode(a,_gvn.intcon(24)) ); duke@435: push( a ); duke@435: break; duke@435: case Bytecodes::_i2s: duke@435: a = pop(); kvn@4115: a = _gvn.transform( new (C) LShiftINode(a,_gvn.intcon(16)) ); kvn@4115: a = _gvn.transform( new (C) RShiftINode(a,_gvn.intcon(16)) ); duke@435: push( a ); duke@435: break; duke@435: case Bytecodes::_i2c: duke@435: a = pop(); kvn@4115: push( _gvn.transform( new (C) AndINode(a,_gvn.intcon(0xFFFF)) ) ); duke@435: break; duke@435: duke@435: case Bytecodes::_i2f: duke@435: a = pop(); kvn@4115: b = _gvn.transform( new (C) ConvI2FNode(a) ) ; duke@435: c = precision_rounding(b); duke@435: push (b); duke@435: break; duke@435: duke@435: case Bytecodes::_i2d: duke@435: a = pop(); kvn@4115: b = _gvn.transform( new (C) ConvI2DNode(a)); duke@435: push_pair(b); duke@435: break; duke@435: duke@435: case Bytecodes::_iinc: // Increment local duke@435: i = iter().get_index(); // Get local index kvn@4115: set_local( i, _gvn.transform( new (C) AddINode( _gvn.intcon(iter().get_iinc_con()), local(i) ) ) ); duke@435: break; duke@435: duke@435: // Exit points of synchronized methods must have an unlock node duke@435: case Bytecodes::_return: duke@435: return_current(NULL); duke@435: break; duke@435: duke@435: case Bytecodes::_ireturn: duke@435: case Bytecodes::_areturn: duke@435: case Bytecodes::_freturn: duke@435: return_current(pop()); duke@435: break; duke@435: case Bytecodes::_lreturn: duke@435: return_current(pop_pair()); duke@435: break; duke@435: case Bytecodes::_dreturn: duke@435: return_current(pop_pair()); duke@435: break; duke@435: duke@435: case Bytecodes::_athrow: duke@435: // null exception oop throws NULL pointer exception twisti@4313: null_check(peek()); duke@435: if (stopped()) return; duke@435: // Hook the thrown exception directly to subsequent handlers. duke@435: if (BailoutToInterpreterForThrows) { duke@435: // Keep method interpreted from now on. duke@435: uncommon_trap(Deoptimization::Reason_unhandled, duke@435: Deoptimization::Action_make_not_compilable); duke@435: return; duke@435: } dcubed@1648: if (env()->jvmti_can_post_on_exceptions()) { dcubed@1648: // check if we must post exception events, take uncommon trap if so (with must_throw = false) dcubed@1648: uncommon_trap_if_should_post_on_exceptions(Deoptimization::Reason_unhandled, false); dcubed@1648: } dcubed@1648: // Here if either can_post_on_exceptions or should_post_on_exceptions is false duke@435: add_exception_state(make_exception_state(peek())); duke@435: break; duke@435: duke@435: case Bytecodes::_goto: // fall through duke@435: case Bytecodes::_goto_w: { duke@435: int target_bci = (bc() == Bytecodes::_goto) ? iter().get_dest() : iter().get_far_dest(); duke@435: duke@435: // If this is a backwards branch in the bytecodes, add Safepoint duke@435: maybe_add_safepoint(target_bci); duke@435: duke@435: // Update method data duke@435: profile_taken_branch(target_bci); duke@435: duke@435: // Merge the current control into the target basic block duke@435: merge(target_bci); duke@435: duke@435: // See if we can get some profile data and hand it off to the next block duke@435: Block *target_block = block()->successor_for_bci(target_bci); duke@435: if (target_block->pred_count() != 1) break; duke@435: ciMethodData* methodData = method()->method_data(); duke@435: if (!methodData->is_mature()) break; duke@435: ciProfileData* data = methodData->bci_to_data(bci()); duke@435: assert( data->is_JumpData(), "" ); duke@435: int taken = ((ciJumpData*)data)->taken(); duke@435: taken = method()->scale_count(taken); duke@435: target_block->set_count(taken); duke@435: break; duke@435: } duke@435: rasbold@683: case Bytecodes::_ifnull: btest = BoolTest::eq; goto handle_if_null; rasbold@683: case Bytecodes::_ifnonnull: btest = BoolTest::ne; goto handle_if_null; rasbold@683: handle_if_null: rasbold@689: // If this is a backwards branch in the bytecodes, add Safepoint rasbold@689: maybe_add_safepoint(iter().get_dest()); rasbold@683: a = null(); rasbold@683: b = pop(); kvn@4115: c = _gvn.transform( new (C) CmpPNode(b, a) ); rasbold@683: do_ifnull(btest, c); duke@435: break; duke@435: duke@435: case Bytecodes::_if_acmpeq: btest = BoolTest::eq; goto handle_if_acmp; duke@435: case Bytecodes::_if_acmpne: btest = BoolTest::ne; goto handle_if_acmp; duke@435: handle_if_acmp: rasbold@689: // If this is a backwards branch in the bytecodes, add Safepoint rasbold@689: maybe_add_safepoint(iter().get_dest()); duke@435: a = pop(); duke@435: b = pop(); kvn@4115: c = _gvn.transform( new (C) CmpPNode(b, a) ); roland@5991: c = optimize_cmp_with_klass(c); duke@435: do_if(btest, c); duke@435: break; duke@435: duke@435: case Bytecodes::_ifeq: btest = BoolTest::eq; goto handle_ifxx; duke@435: case Bytecodes::_ifne: btest = BoolTest::ne; goto handle_ifxx; duke@435: case Bytecodes::_iflt: btest = BoolTest::lt; goto handle_ifxx; duke@435: case Bytecodes::_ifle: btest = BoolTest::le; goto handle_ifxx; duke@435: case Bytecodes::_ifgt: btest = BoolTest::gt; goto handle_ifxx; duke@435: case Bytecodes::_ifge: btest = BoolTest::ge; goto handle_ifxx; duke@435: handle_ifxx: rasbold@689: // If this is a backwards branch in the bytecodes, add Safepoint rasbold@689: maybe_add_safepoint(iter().get_dest()); duke@435: a = _gvn.intcon(0); duke@435: b = pop(); kvn@4115: c = _gvn.transform( new (C) CmpINode(b, a) ); duke@435: do_if(btest, c); duke@435: break; duke@435: duke@435: case Bytecodes::_if_icmpeq: btest = BoolTest::eq; goto handle_if_icmp; duke@435: case Bytecodes::_if_icmpne: btest = BoolTest::ne; goto handle_if_icmp; duke@435: case Bytecodes::_if_icmplt: btest = BoolTest::lt; goto handle_if_icmp; duke@435: case Bytecodes::_if_icmple: btest = BoolTest::le; goto handle_if_icmp; duke@435: case Bytecodes::_if_icmpgt: btest = BoolTest::gt; goto handle_if_icmp; duke@435: case Bytecodes::_if_icmpge: btest = BoolTest::ge; goto handle_if_icmp; duke@435: handle_if_icmp: rasbold@689: // If this is a backwards branch in the bytecodes, add Safepoint rasbold@689: maybe_add_safepoint(iter().get_dest()); duke@435: a = pop(); duke@435: b = pop(); kvn@4115: c = _gvn.transform( new (C) CmpINode( b, a ) ); duke@435: do_if(btest, c); duke@435: break; duke@435: duke@435: case Bytecodes::_tableswitch: duke@435: do_tableswitch(); duke@435: break; duke@435: duke@435: case Bytecodes::_lookupswitch: duke@435: do_lookupswitch(); duke@435: break; duke@435: duke@435: case Bytecodes::_invokestatic: jrose@1161: case Bytecodes::_invokedynamic: duke@435: case Bytecodes::_invokespecial: duke@435: case Bytecodes::_invokevirtual: duke@435: case Bytecodes::_invokeinterface: duke@435: do_call(); duke@435: break; duke@435: case Bytecodes::_checkcast: duke@435: do_checkcast(); duke@435: break; duke@435: case Bytecodes::_instanceof: duke@435: do_instanceof(); duke@435: break; duke@435: case Bytecodes::_anewarray: duke@435: do_anewarray(); duke@435: break; duke@435: case Bytecodes::_newarray: duke@435: do_newarray((BasicType)iter().get_index()); duke@435: break; duke@435: case Bytecodes::_multianewarray: duke@435: do_multianewarray(); duke@435: break; duke@435: case Bytecodes::_new: duke@435: do_new(); duke@435: break; duke@435: duke@435: case Bytecodes::_jsr: duke@435: case Bytecodes::_jsr_w: duke@435: do_jsr(); duke@435: break; duke@435: duke@435: case Bytecodes::_ret: duke@435: do_ret(); duke@435: break; duke@435: duke@435: duke@435: case Bytecodes::_monitorenter: duke@435: do_monitor_enter(); duke@435: break; duke@435: duke@435: case Bytecodes::_monitorexit: duke@435: do_monitor_exit(); duke@435: break; duke@435: duke@435: case Bytecodes::_breakpoint: duke@435: // Breakpoint set concurrently to compile duke@435: // %%% use an uncommon trap? duke@435: C->record_failure("breakpoint in method"); duke@435: return; duke@435: duke@435: default: duke@435: #ifndef PRODUCT duke@435: map()->dump(99); duke@435: #endif duke@435: tty->print("\nUnhandled bytecode %s\n", Bytecodes::name(bc()) ); duke@435: ShouldNotReachHere(); duke@435: } duke@435: duke@435: #ifndef PRODUCT duke@435: IdealGraphPrinter *printer = IdealGraphPrinter::printer(); duke@435: if(printer) { duke@435: char buffer[256]; duke@435: sprintf(buffer, "Bytecode %d: %s", bci(), Bytecodes::name(bc())); duke@435: bool old = printer->traverse_outs(); duke@435: printer->set_traverse_outs(true); never@657: printer->print_method(C, buffer, 4); duke@435: printer->set_traverse_outs(old); duke@435: } duke@435: #endif duke@435: }