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