duke@435: /* twisti@1730: * Copyright 1999-2010 Sun Microsystems, Inc. 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: * duke@435: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, duke@435: * CA 95054 USA or visit www.sun.com if you need additional information or duke@435: * have any questions. duke@435: * duke@435: */ duke@435: duke@435: #include "incls/_precompiled.incl" duke@435: #include "incls/_c1_GraphBuilder.cpp.incl" duke@435: duke@435: class BlockListBuilder VALUE_OBJ_CLASS_SPEC { duke@435: private: duke@435: Compilation* _compilation; duke@435: IRScope* _scope; duke@435: duke@435: BlockList _blocks; // internal list of all blocks duke@435: BlockList* _bci2block; // mapping from bci to blocks for GraphBuilder duke@435: duke@435: // fields used by mark_loops duke@435: BitMap _active; // for iteration of control flow graph duke@435: BitMap _visited; // for iteration of control flow graph duke@435: intArray _loop_map; // caches the information if a block is contained in a loop duke@435: int _next_loop_index; // next free loop number duke@435: int _next_block_number; // for reverse postorder numbering of blocks duke@435: duke@435: // accessors duke@435: Compilation* compilation() const { return _compilation; } duke@435: IRScope* scope() const { return _scope; } duke@435: ciMethod* method() const { return scope()->method(); } duke@435: XHandlers* xhandlers() const { return scope()->xhandlers(); } duke@435: duke@435: // unified bailout support duke@435: void bailout(const char* msg) const { compilation()->bailout(msg); } duke@435: bool bailed_out() const { return compilation()->bailed_out(); } duke@435: duke@435: // helper functions duke@435: BlockBegin* make_block_at(int bci, BlockBegin* predecessor); duke@435: void handle_exceptions(BlockBegin* current, int cur_bci); duke@435: void handle_jsr(BlockBegin* current, int sr_bci, int next_bci); duke@435: void store_one(BlockBegin* current, int local); duke@435: void store_two(BlockBegin* current, int local); duke@435: void set_entries(int osr_bci); duke@435: void set_leaders(); duke@435: duke@435: void make_loop_header(BlockBegin* block); duke@435: void mark_loops(); duke@435: int mark_loops(BlockBegin* b, bool in_subroutine); duke@435: duke@435: // debugging duke@435: #ifndef PRODUCT duke@435: void print(); duke@435: #endif duke@435: duke@435: public: duke@435: // creation duke@435: BlockListBuilder(Compilation* compilation, IRScope* scope, int osr_bci); duke@435: duke@435: // accessors for GraphBuilder duke@435: BlockList* bci2block() const { return _bci2block; } duke@435: }; duke@435: duke@435: duke@435: // Implementation of BlockListBuilder duke@435: duke@435: BlockListBuilder::BlockListBuilder(Compilation* compilation, IRScope* scope, int osr_bci) duke@435: : _compilation(compilation) duke@435: , _scope(scope) duke@435: , _blocks(16) duke@435: , _bci2block(new BlockList(scope->method()->code_size(), NULL)) duke@435: , _next_block_number(0) duke@435: , _active() // size not known yet duke@435: , _visited() // size not known yet duke@435: , _next_loop_index(0) duke@435: , _loop_map() // size not known yet duke@435: { duke@435: set_entries(osr_bci); duke@435: set_leaders(); duke@435: CHECK_BAILOUT(); duke@435: duke@435: mark_loops(); duke@435: NOT_PRODUCT(if (PrintInitialBlockList) print()); duke@435: duke@435: #ifndef PRODUCT duke@435: if (PrintCFGToFile) { duke@435: stringStream title; duke@435: title.print("BlockListBuilder "); duke@435: scope->method()->print_name(&title); duke@435: CFGPrinter::print_cfg(_bci2block, title.as_string(), false, false); duke@435: } duke@435: #endif duke@435: } duke@435: duke@435: duke@435: void BlockListBuilder::set_entries(int osr_bci) { duke@435: // generate start blocks duke@435: BlockBegin* std_entry = make_block_at(0, NULL); duke@435: if (scope()->caller() == NULL) { duke@435: std_entry->set(BlockBegin::std_entry_flag); duke@435: } duke@435: if (osr_bci != -1) { duke@435: BlockBegin* osr_entry = make_block_at(osr_bci, NULL); duke@435: osr_entry->set(BlockBegin::osr_entry_flag); duke@435: } duke@435: duke@435: // generate exception entry blocks duke@435: XHandlers* list = xhandlers(); duke@435: const int n = list->length(); duke@435: for (int i = 0; i < n; i++) { duke@435: XHandler* h = list->handler_at(i); duke@435: BlockBegin* entry = make_block_at(h->handler_bci(), NULL); duke@435: entry->set(BlockBegin::exception_entry_flag); duke@435: h->set_entry_block(entry); duke@435: } duke@435: } duke@435: duke@435: duke@435: BlockBegin* BlockListBuilder::make_block_at(int cur_bci, BlockBegin* predecessor) { duke@435: assert(method()->bci_block_start().at(cur_bci), "wrong block starts of MethodLivenessAnalyzer"); duke@435: duke@435: BlockBegin* block = _bci2block->at(cur_bci); duke@435: if (block == NULL) { duke@435: block = new BlockBegin(cur_bci); duke@435: block->init_stores_to_locals(method()->max_locals()); duke@435: _bci2block->at_put(cur_bci, block); duke@435: _blocks.append(block); duke@435: duke@435: assert(predecessor == NULL || predecessor->bci() < cur_bci, "targets for backward branches must already exist"); duke@435: } duke@435: duke@435: if (predecessor != NULL) { duke@435: if (block->is_set(BlockBegin::exception_entry_flag)) { duke@435: BAILOUT_("Exception handler can be reached by both normal and exceptional control flow", block); duke@435: } duke@435: duke@435: predecessor->add_successor(block); duke@435: block->increment_total_preds(); duke@435: } duke@435: duke@435: return block; duke@435: } duke@435: duke@435: duke@435: inline void BlockListBuilder::store_one(BlockBegin* current, int local) { duke@435: current->stores_to_locals().set_bit(local); duke@435: } duke@435: inline void BlockListBuilder::store_two(BlockBegin* current, int local) { duke@435: store_one(current, local); duke@435: store_one(current, local + 1); duke@435: } duke@435: duke@435: duke@435: void BlockListBuilder::handle_exceptions(BlockBegin* current, int cur_bci) { duke@435: // Draws edges from a block to its exception handlers duke@435: XHandlers* list = xhandlers(); duke@435: const int n = list->length(); duke@435: duke@435: for (int i = 0; i < n; i++) { duke@435: XHandler* h = list->handler_at(i); duke@435: duke@435: if (h->covers(cur_bci)) { duke@435: BlockBegin* entry = h->entry_block(); duke@435: assert(entry != NULL && entry == _bci2block->at(h->handler_bci()), "entry must be set"); duke@435: assert(entry->is_set(BlockBegin::exception_entry_flag), "flag must be set"); duke@435: duke@435: // add each exception handler only once duke@435: if (!current->is_successor(entry)) { duke@435: current->add_successor(entry); duke@435: entry->increment_total_preds(); duke@435: } duke@435: duke@435: // stop when reaching catchall duke@435: if (h->catch_type() == 0) break; duke@435: } duke@435: } duke@435: } duke@435: duke@435: void BlockListBuilder::handle_jsr(BlockBegin* current, int sr_bci, int next_bci) { duke@435: // start a new block after jsr-bytecode and link this block into cfg duke@435: make_block_at(next_bci, current); duke@435: duke@435: // start a new block at the subroutine entry at mark it with special flag duke@435: BlockBegin* sr_block = make_block_at(sr_bci, current); duke@435: if (!sr_block->is_set(BlockBegin::subroutine_entry_flag)) { duke@435: sr_block->set(BlockBegin::subroutine_entry_flag); duke@435: } duke@435: } duke@435: duke@435: duke@435: void BlockListBuilder::set_leaders() { duke@435: bool has_xhandlers = xhandlers()->has_handlers(); duke@435: BlockBegin* current = NULL; duke@435: duke@435: // The information which bci starts a new block simplifies the analysis duke@435: // Without it, backward branches could jump to a bci where no block was created duke@435: // during bytecode iteration. This would require the creation of a new block at the duke@435: // branch target and a modification of the successor lists. duke@435: BitMap bci_block_start = method()->bci_block_start(); duke@435: duke@435: ciBytecodeStream s(method()); duke@435: while (s.next() != ciBytecodeStream::EOBC()) { duke@435: int cur_bci = s.cur_bci(); duke@435: duke@435: if (bci_block_start.at(cur_bci)) { duke@435: current = make_block_at(cur_bci, current); duke@435: } duke@435: assert(current != NULL, "must have current block"); duke@435: duke@435: if (has_xhandlers && GraphBuilder::can_trap(method(), s.cur_bc())) { duke@435: handle_exceptions(current, cur_bci); duke@435: } duke@435: duke@435: switch (s.cur_bc()) { duke@435: // track stores to local variables for selective creation of phi functions duke@435: case Bytecodes::_iinc: store_one(current, s.get_index()); break; duke@435: case Bytecodes::_istore: store_one(current, s.get_index()); break; duke@435: case Bytecodes::_lstore: store_two(current, s.get_index()); break; duke@435: case Bytecodes::_fstore: store_one(current, s.get_index()); break; duke@435: case Bytecodes::_dstore: store_two(current, s.get_index()); break; duke@435: case Bytecodes::_astore: store_one(current, s.get_index()); break; duke@435: case Bytecodes::_istore_0: store_one(current, 0); break; duke@435: case Bytecodes::_istore_1: store_one(current, 1); break; duke@435: case Bytecodes::_istore_2: store_one(current, 2); break; duke@435: case Bytecodes::_istore_3: store_one(current, 3); break; duke@435: case Bytecodes::_lstore_0: store_two(current, 0); break; duke@435: case Bytecodes::_lstore_1: store_two(current, 1); break; duke@435: case Bytecodes::_lstore_2: store_two(current, 2); break; duke@435: case Bytecodes::_lstore_3: store_two(current, 3); break; duke@435: case Bytecodes::_fstore_0: store_one(current, 0); break; duke@435: case Bytecodes::_fstore_1: store_one(current, 1); break; duke@435: case Bytecodes::_fstore_2: store_one(current, 2); break; duke@435: case Bytecodes::_fstore_3: store_one(current, 3); break; duke@435: case Bytecodes::_dstore_0: store_two(current, 0); break; duke@435: case Bytecodes::_dstore_1: store_two(current, 1); break; duke@435: case Bytecodes::_dstore_2: store_two(current, 2); break; duke@435: case Bytecodes::_dstore_3: store_two(current, 3); break; duke@435: case Bytecodes::_astore_0: store_one(current, 0); break; duke@435: case Bytecodes::_astore_1: store_one(current, 1); break; duke@435: case Bytecodes::_astore_2: store_one(current, 2); break; duke@435: case Bytecodes::_astore_3: store_one(current, 3); break; duke@435: duke@435: // track bytecodes that affect the control flow duke@435: case Bytecodes::_athrow: // fall through duke@435: case Bytecodes::_ret: // fall through duke@435: case Bytecodes::_ireturn: // fall through duke@435: case Bytecodes::_lreturn: // fall through duke@435: case Bytecodes::_freturn: // fall through duke@435: case Bytecodes::_dreturn: // fall through duke@435: case Bytecodes::_areturn: // fall through duke@435: case Bytecodes::_return: duke@435: current = NULL; duke@435: break; duke@435: duke@435: case Bytecodes::_ifeq: // fall through duke@435: case Bytecodes::_ifne: // fall through duke@435: case Bytecodes::_iflt: // fall through duke@435: case Bytecodes::_ifge: // fall through duke@435: case Bytecodes::_ifgt: // fall through duke@435: case Bytecodes::_ifle: // fall through duke@435: case Bytecodes::_if_icmpeq: // fall through duke@435: case Bytecodes::_if_icmpne: // fall through duke@435: case Bytecodes::_if_icmplt: // fall through duke@435: case Bytecodes::_if_icmpge: // fall through duke@435: case Bytecodes::_if_icmpgt: // fall through duke@435: case Bytecodes::_if_icmple: // fall through duke@435: case Bytecodes::_if_acmpeq: // fall through duke@435: case Bytecodes::_if_acmpne: // fall through duke@435: case Bytecodes::_ifnull: // fall through duke@435: case Bytecodes::_ifnonnull: duke@435: make_block_at(s.next_bci(), current); duke@435: make_block_at(s.get_dest(), current); duke@435: current = NULL; duke@435: break; duke@435: duke@435: case Bytecodes::_goto: duke@435: make_block_at(s.get_dest(), current); duke@435: current = NULL; duke@435: break; duke@435: duke@435: case Bytecodes::_goto_w: duke@435: make_block_at(s.get_far_dest(), current); duke@435: current = NULL; duke@435: break; duke@435: duke@435: case Bytecodes::_jsr: duke@435: handle_jsr(current, s.get_dest(), s.next_bci()); duke@435: current = NULL; duke@435: break; duke@435: duke@435: case Bytecodes::_jsr_w: duke@435: handle_jsr(current, s.get_far_dest(), s.next_bci()); duke@435: current = NULL; duke@435: break; duke@435: duke@435: case Bytecodes::_tableswitch: { duke@435: // set block for each case duke@435: Bytecode_tableswitch *switch_ = Bytecode_tableswitch_at(s.cur_bcp()); duke@435: int l = switch_->length(); duke@435: for (int i = 0; i < l; i++) { duke@435: make_block_at(cur_bci + switch_->dest_offset_at(i), current); duke@435: } duke@435: make_block_at(cur_bci + switch_->default_offset(), current); duke@435: current = NULL; duke@435: break; duke@435: } duke@435: duke@435: case Bytecodes::_lookupswitch: { duke@435: // set block for each case duke@435: Bytecode_lookupswitch *switch_ = Bytecode_lookupswitch_at(s.cur_bcp()); duke@435: int l = switch_->number_of_pairs(); duke@435: for (int i = 0; i < l; i++) { duke@435: make_block_at(cur_bci + switch_->pair_at(i)->offset(), current); duke@435: } duke@435: make_block_at(cur_bci + switch_->default_offset(), current); duke@435: current = NULL; duke@435: break; duke@435: } duke@435: } duke@435: } duke@435: } duke@435: duke@435: duke@435: void BlockListBuilder::mark_loops() { duke@435: ResourceMark rm; duke@435: duke@435: _active = BitMap(BlockBegin::number_of_blocks()); _active.clear(); duke@435: _visited = BitMap(BlockBegin::number_of_blocks()); _visited.clear(); duke@435: _loop_map = intArray(BlockBegin::number_of_blocks(), 0); duke@435: _next_loop_index = 0; duke@435: _next_block_number = _blocks.length(); duke@435: duke@435: // recursively iterate the control flow graph duke@435: mark_loops(_bci2block->at(0), false); duke@435: assert(_next_block_number >= 0, "invalid block numbers"); duke@435: } duke@435: duke@435: void BlockListBuilder::make_loop_header(BlockBegin* block) { duke@435: if (block->is_set(BlockBegin::exception_entry_flag)) { duke@435: // exception edges may look like loops but don't mark them as such duke@435: // since it screws up block ordering. duke@435: return; duke@435: } duke@435: if (!block->is_set(BlockBegin::parser_loop_header_flag)) { duke@435: block->set(BlockBegin::parser_loop_header_flag); duke@435: duke@435: assert(_loop_map.at(block->block_id()) == 0, "must not be set yet"); duke@435: assert(0 <= _next_loop_index && _next_loop_index < BitsPerInt, "_next_loop_index is used as a bit-index in integer"); duke@435: _loop_map.at_put(block->block_id(), 1 << _next_loop_index); duke@435: if (_next_loop_index < 31) _next_loop_index++; duke@435: } else { duke@435: // block already marked as loop header roland@1495: assert(is_power_of_2((unsigned int)_loop_map.at(block->block_id())), "exactly one bit must be set"); duke@435: } duke@435: } duke@435: duke@435: int BlockListBuilder::mark_loops(BlockBegin* block, bool in_subroutine) { duke@435: int block_id = block->block_id(); duke@435: duke@435: if (_visited.at(block_id)) { duke@435: if (_active.at(block_id)) { duke@435: // reached block via backward branch duke@435: make_loop_header(block); duke@435: } duke@435: // return cached loop information for this block duke@435: return _loop_map.at(block_id); duke@435: } duke@435: duke@435: if (block->is_set(BlockBegin::subroutine_entry_flag)) { duke@435: in_subroutine = true; duke@435: } duke@435: duke@435: // set active and visited bits before successors are processed duke@435: _visited.set_bit(block_id); duke@435: _active.set_bit(block_id); duke@435: duke@435: intptr_t loop_state = 0; duke@435: for (int i = block->number_of_sux() - 1; i >= 0; i--) { duke@435: // recursively process all successors duke@435: loop_state |= mark_loops(block->sux_at(i), in_subroutine); duke@435: } duke@435: duke@435: // clear active-bit after all successors are processed duke@435: _active.clear_bit(block_id); duke@435: duke@435: // reverse-post-order numbering of all blocks duke@435: block->set_depth_first_number(_next_block_number); duke@435: _next_block_number--; duke@435: duke@435: if (loop_state != 0 || in_subroutine ) { duke@435: // block is contained at least in one loop, so phi functions are necessary duke@435: // phi functions are also necessary for all locals stored in a subroutine duke@435: scope()->requires_phi_function().set_union(block->stores_to_locals()); duke@435: } duke@435: duke@435: if (block->is_set(BlockBegin::parser_loop_header_flag)) { duke@435: int header_loop_state = _loop_map.at(block_id); duke@435: assert(is_power_of_2((unsigned)header_loop_state), "exactly one bit must be set"); duke@435: duke@435: // If the highest bit is set (i.e. when integer value is negative), the method duke@435: // has 32 or more loops. This bit is never cleared because it is used for multiple loops duke@435: if (header_loop_state >= 0) { duke@435: clear_bits(loop_state, header_loop_state); duke@435: } duke@435: } duke@435: duke@435: // cache and return loop information for this block duke@435: _loop_map.at_put(block_id, loop_state); duke@435: return loop_state; duke@435: } duke@435: duke@435: duke@435: #ifndef PRODUCT duke@435: duke@435: int compare_depth_first(BlockBegin** a, BlockBegin** b) { duke@435: return (*a)->depth_first_number() - (*b)->depth_first_number(); duke@435: } duke@435: duke@435: void BlockListBuilder::print() { duke@435: tty->print("----- initial block list of BlockListBuilder for method "); duke@435: method()->print_short_name(); duke@435: tty->cr(); duke@435: duke@435: // better readability if blocks are sorted in processing order duke@435: _blocks.sort(compare_depth_first); duke@435: duke@435: for (int i = 0; i < _blocks.length(); i++) { duke@435: BlockBegin* cur = _blocks.at(i); duke@435: tty->print("%4d: B%-4d bci: %-4d preds: %-4d ", cur->depth_first_number(), cur->block_id(), cur->bci(), cur->total_preds()); duke@435: duke@435: tty->print(cur->is_set(BlockBegin::std_entry_flag) ? " std" : " "); duke@435: tty->print(cur->is_set(BlockBegin::osr_entry_flag) ? " osr" : " "); duke@435: tty->print(cur->is_set(BlockBegin::exception_entry_flag) ? " ex" : " "); duke@435: tty->print(cur->is_set(BlockBegin::subroutine_entry_flag) ? " sr" : " "); duke@435: tty->print(cur->is_set(BlockBegin::parser_loop_header_flag) ? " lh" : " "); duke@435: duke@435: if (cur->number_of_sux() > 0) { duke@435: tty->print(" sux: "); duke@435: for (int j = 0; j < cur->number_of_sux(); j++) { duke@435: BlockBegin* sux = cur->sux_at(j); duke@435: tty->print("B%d ", sux->block_id()); duke@435: } duke@435: } duke@435: tty->cr(); duke@435: } duke@435: } duke@435: duke@435: #endif duke@435: duke@435: duke@435: // A simple growable array of Values indexed by ciFields duke@435: class FieldBuffer: public CompilationResourceObj { duke@435: private: duke@435: GrowableArray _values; duke@435: duke@435: public: duke@435: FieldBuffer() {} duke@435: duke@435: void kill() { duke@435: _values.trunc_to(0); duke@435: } duke@435: duke@435: Value at(ciField* field) { duke@435: assert(field->holder()->is_loaded(), "must be a loaded field"); duke@435: int offset = field->offset(); duke@435: if (offset < _values.length()) { duke@435: return _values.at(offset); duke@435: } else { duke@435: return NULL; duke@435: } duke@435: } duke@435: duke@435: void at_put(ciField* field, Value value) { duke@435: assert(field->holder()->is_loaded(), "must be a loaded field"); duke@435: int offset = field->offset(); duke@435: _values.at_put_grow(offset, value, NULL); duke@435: } duke@435: duke@435: }; duke@435: duke@435: duke@435: // MemoryBuffer is fairly simple model of the current state of memory. duke@435: // It partitions memory into several pieces. The first piece is duke@435: // generic memory where little is known about the owner of the memory. duke@435: // This is conceptually represented by the tuple which says duke@435: // that the field F of object O has value V. This is flattened so duke@435: // that F is represented by the offset of the field and the parallel duke@435: // arrays _objects and _values are used for O and V. Loads of O.F can duke@435: // simply use V. Newly allocated objects are kept in a separate list duke@435: // along with a parallel array for each object which represents the duke@435: // current value of its fields. Stores of the default value to fields duke@435: // which have never been stored to before are eliminated since they duke@435: // are redundant. Once newly allocated objects are stored into duke@435: // another object or they are passed out of the current compile they duke@435: // are treated like generic memory. duke@435: duke@435: class MemoryBuffer: public CompilationResourceObj { duke@435: private: duke@435: FieldBuffer _values; duke@435: GrowableArray _objects; duke@435: GrowableArray _newobjects; duke@435: GrowableArray _fields; duke@435: duke@435: public: duke@435: MemoryBuffer() {} duke@435: duke@435: StoreField* store(StoreField* st) { duke@435: if (!EliminateFieldAccess) { duke@435: return st; duke@435: } duke@435: duke@435: Value object = st->obj(); duke@435: Value value = st->value(); duke@435: ciField* field = st->field(); duke@435: if (field->holder()->is_loaded()) { duke@435: int offset = field->offset(); duke@435: int index = _newobjects.find(object); duke@435: if (index != -1) { duke@435: // newly allocated object with no other stores performed on this field duke@435: FieldBuffer* buf = _fields.at(index); duke@435: if (buf->at(field) == NULL && is_default_value(value)) { duke@435: #ifndef PRODUCT duke@435: if (PrintIRDuringConstruction && Verbose) { duke@435: tty->print_cr("Eliminated store for object %d:", index); duke@435: st->print_line(); duke@435: } duke@435: #endif duke@435: return NULL; duke@435: } else { duke@435: buf->at_put(field, value); duke@435: } duke@435: } else { duke@435: _objects.at_put_grow(offset, object, NULL); duke@435: _values.at_put(field, value); duke@435: } duke@435: duke@435: store_value(value); duke@435: } else { duke@435: // if we held onto field names we could alias based on names but duke@435: // we don't know what's being stored to so kill it all. duke@435: kill(); duke@435: } duke@435: return st; duke@435: } duke@435: duke@435: duke@435: // return true if this value correspond to the default value of a field. duke@435: bool is_default_value(Value value) { duke@435: Constant* con = value->as_Constant(); duke@435: if (con) { duke@435: switch (con->type()->tag()) { duke@435: case intTag: return con->type()->as_IntConstant()->value() == 0; duke@435: case longTag: return con->type()->as_LongConstant()->value() == 0; duke@435: case floatTag: return jint_cast(con->type()->as_FloatConstant()->value()) == 0; duke@435: case doubleTag: return jlong_cast(con->type()->as_DoubleConstant()->value()) == jlong_cast(0); duke@435: case objectTag: return con->type() == objectNull; duke@435: default: ShouldNotReachHere(); duke@435: } duke@435: } duke@435: return false; duke@435: } duke@435: duke@435: duke@435: // return either the actual value of a load or the load itself duke@435: Value load(LoadField* load) { duke@435: if (!EliminateFieldAccess) { duke@435: return load; duke@435: } duke@435: duke@435: if (RoundFPResults && UseSSE < 2 && load->type()->is_float_kind()) { duke@435: // can't skip load since value might get rounded as a side effect duke@435: return load; duke@435: } duke@435: duke@435: ciField* field = load->field(); duke@435: Value object = load->obj(); duke@435: if (field->holder()->is_loaded() && !field->is_volatile()) { duke@435: int offset = field->offset(); duke@435: Value result = NULL; duke@435: int index = _newobjects.find(object); duke@435: if (index != -1) { duke@435: result = _fields.at(index)->at(field); duke@435: } else if (_objects.at_grow(offset, NULL) == object) { duke@435: result = _values.at(field); duke@435: } duke@435: if (result != NULL) { duke@435: #ifndef PRODUCT duke@435: if (PrintIRDuringConstruction && Verbose) { duke@435: tty->print_cr("Eliminated load: "); duke@435: load->print_line(); duke@435: } duke@435: #endif duke@435: assert(result->type()->tag() == load->type()->tag(), "wrong types"); duke@435: return result; duke@435: } duke@435: } duke@435: return load; duke@435: } duke@435: duke@435: // Record this newly allocated object duke@435: void new_instance(NewInstance* object) { duke@435: int index = _newobjects.length(); duke@435: _newobjects.append(object); duke@435: if (_fields.at_grow(index, NULL) == NULL) { duke@435: _fields.at_put(index, new FieldBuffer()); duke@435: } else { duke@435: _fields.at(index)->kill(); duke@435: } duke@435: } duke@435: duke@435: void store_value(Value value) { duke@435: int index = _newobjects.find(value); duke@435: if (index != -1) { duke@435: // stored a newly allocated object into another object. duke@435: // Assume we've lost track of it as separate slice of memory. duke@435: // We could do better by keeping track of whether individual duke@435: // fields could alias each other. duke@435: _newobjects.remove_at(index); duke@435: // pull out the field info and store it at the end up the list duke@435: // of field info list to be reused later. duke@435: _fields.append(_fields.at(index)); duke@435: _fields.remove_at(index); duke@435: } duke@435: } duke@435: duke@435: void kill() { duke@435: _newobjects.trunc_to(0); duke@435: _objects.trunc_to(0); duke@435: _values.kill(); duke@435: } duke@435: }; duke@435: duke@435: duke@435: // Implementation of GraphBuilder's ScopeData duke@435: duke@435: GraphBuilder::ScopeData::ScopeData(ScopeData* parent) duke@435: : _parent(parent) duke@435: , _bci2block(NULL) duke@435: , _scope(NULL) duke@435: , _has_handler(false) duke@435: , _stream(NULL) duke@435: , _work_list(NULL) duke@435: , _parsing_jsr(false) duke@435: , _jsr_xhandlers(NULL) duke@435: , _caller_stack_size(-1) duke@435: , _continuation(NULL) duke@435: , _continuation_state(NULL) duke@435: , _num_returns(0) duke@435: , _cleanup_block(NULL) duke@435: , _cleanup_return_prev(NULL) duke@435: , _cleanup_state(NULL) duke@435: { duke@435: if (parent != NULL) { duke@435: _max_inline_size = (intx) ((float) NestedInliningSizeRatio * (float) parent->max_inline_size() / 100.0f); duke@435: } else { duke@435: _max_inline_size = MaxInlineSize; duke@435: } duke@435: if (_max_inline_size < MaxTrivialSize) { duke@435: _max_inline_size = MaxTrivialSize; duke@435: } duke@435: } duke@435: duke@435: duke@435: void GraphBuilder::kill_all() { duke@435: if (UseLocalValueNumbering) { duke@435: vmap()->kill_all(); duke@435: } duke@435: _memory->kill(); duke@435: } duke@435: duke@435: duke@435: BlockBegin* GraphBuilder::ScopeData::block_at(int bci) { duke@435: if (parsing_jsr()) { duke@435: // It is necessary to clone all blocks associated with a duke@435: // subroutine, including those for exception handlers in the scope duke@435: // of the method containing the jsr (because those exception duke@435: // handlers may contain ret instructions in some cases). duke@435: BlockBegin* block = bci2block()->at(bci); duke@435: if (block != NULL && block == parent()->bci2block()->at(bci)) { duke@435: BlockBegin* new_block = new BlockBegin(block->bci()); duke@435: #ifndef PRODUCT duke@435: if (PrintInitialBlockList) { duke@435: tty->print_cr("CFG: cloned block %d (bci %d) as block %d for jsr", duke@435: block->block_id(), block->bci(), new_block->block_id()); duke@435: } duke@435: #endif duke@435: // copy data from cloned blocked duke@435: new_block->set_depth_first_number(block->depth_first_number()); duke@435: if (block->is_set(BlockBegin::parser_loop_header_flag)) new_block->set(BlockBegin::parser_loop_header_flag); duke@435: // Preserve certain flags for assertion checking duke@435: if (block->is_set(BlockBegin::subroutine_entry_flag)) new_block->set(BlockBegin::subroutine_entry_flag); duke@435: if (block->is_set(BlockBegin::exception_entry_flag)) new_block->set(BlockBegin::exception_entry_flag); duke@435: duke@435: // copy was_visited_flag to allow early detection of bailouts duke@435: // if a block that is used in a jsr has already been visited before, duke@435: // it is shared between the normal control flow and a subroutine duke@435: // BlockBegin::try_merge returns false when the flag is set, this leads duke@435: // to a compilation bailout duke@435: if (block->is_set(BlockBegin::was_visited_flag)) new_block->set(BlockBegin::was_visited_flag); duke@435: duke@435: bci2block()->at_put(bci, new_block); duke@435: block = new_block; duke@435: } duke@435: return block; duke@435: } else { duke@435: return bci2block()->at(bci); duke@435: } duke@435: } duke@435: duke@435: duke@435: XHandlers* GraphBuilder::ScopeData::xhandlers() const { duke@435: if (_jsr_xhandlers == NULL) { duke@435: assert(!parsing_jsr(), ""); duke@435: return scope()->xhandlers(); duke@435: } duke@435: assert(parsing_jsr(), ""); duke@435: return _jsr_xhandlers; duke@435: } duke@435: duke@435: duke@435: void GraphBuilder::ScopeData::set_scope(IRScope* scope) { duke@435: _scope = scope; duke@435: bool parent_has_handler = false; duke@435: if (parent() != NULL) { duke@435: parent_has_handler = parent()->has_handler(); duke@435: } duke@435: _has_handler = parent_has_handler || scope->xhandlers()->has_handlers(); duke@435: } duke@435: duke@435: duke@435: void GraphBuilder::ScopeData::set_inline_cleanup_info(BlockBegin* block, duke@435: Instruction* return_prev, duke@435: ValueStack* return_state) { duke@435: _cleanup_block = block; duke@435: _cleanup_return_prev = return_prev; duke@435: _cleanup_state = return_state; duke@435: } duke@435: duke@435: duke@435: void GraphBuilder::ScopeData::add_to_work_list(BlockBegin* block) { duke@435: if (_work_list == NULL) { duke@435: _work_list = new BlockList(); duke@435: } duke@435: duke@435: if (!block->is_set(BlockBegin::is_on_work_list_flag)) { duke@435: // Do not start parsing the continuation block while in a duke@435: // sub-scope duke@435: if (parsing_jsr()) { duke@435: if (block == jsr_continuation()) { duke@435: return; duke@435: } duke@435: } else { duke@435: if (block == continuation()) { duke@435: return; duke@435: } duke@435: } duke@435: block->set(BlockBegin::is_on_work_list_flag); duke@435: _work_list->push(block); duke@435: duke@435: sort_top_into_worklist(_work_list, block); duke@435: } duke@435: } duke@435: duke@435: duke@435: void GraphBuilder::sort_top_into_worklist(BlockList* worklist, BlockBegin* top) { duke@435: assert(worklist->top() == top, ""); duke@435: // sort block descending into work list duke@435: const int dfn = top->depth_first_number(); duke@435: assert(dfn != -1, "unknown depth first number"); duke@435: int i = worklist->length()-2; duke@435: while (i >= 0) { duke@435: BlockBegin* b = worklist->at(i); duke@435: if (b->depth_first_number() < dfn) { duke@435: worklist->at_put(i+1, b); duke@435: } else { duke@435: break; duke@435: } duke@435: i --; duke@435: } duke@435: if (i >= -1) worklist->at_put(i + 1, top); duke@435: } duke@435: duke@435: int GraphBuilder::ScopeData::caller_stack_size() const { duke@435: ValueStack* state = scope()->caller_state(); duke@435: if (state == NULL) { duke@435: return 0; duke@435: } duke@435: return state->stack_size(); duke@435: } duke@435: duke@435: duke@435: BlockBegin* GraphBuilder::ScopeData::remove_from_work_list() { duke@435: if (is_work_list_empty()) { duke@435: return NULL; duke@435: } duke@435: return _work_list->pop(); duke@435: } duke@435: duke@435: duke@435: bool GraphBuilder::ScopeData::is_work_list_empty() const { duke@435: return (_work_list == NULL || _work_list->length() == 0); duke@435: } duke@435: duke@435: duke@435: void GraphBuilder::ScopeData::setup_jsr_xhandlers() { duke@435: assert(parsing_jsr(), ""); duke@435: // clone all the exception handlers from the scope duke@435: XHandlers* handlers = new XHandlers(scope()->xhandlers()); duke@435: const int n = handlers->length(); duke@435: for (int i = 0; i < n; i++) { duke@435: // The XHandlers need to be adjusted to dispatch to the cloned duke@435: // handler block instead of the default one but the synthetic duke@435: // unlocker needs to be handled specially. The synthetic unlocker duke@435: // should be left alone since there can be only one and all code duke@435: // should dispatch to the same one. duke@435: XHandler* h = handlers->handler_at(i); never@1813: assert(h->handler_bci() != SynchronizationEntryBCI, "must be real"); never@1813: h->set_entry_block(block_at(h->handler_bci())); duke@435: } duke@435: _jsr_xhandlers = handlers; duke@435: } duke@435: duke@435: duke@435: int GraphBuilder::ScopeData::num_returns() { duke@435: if (parsing_jsr()) { duke@435: return parent()->num_returns(); duke@435: } duke@435: return _num_returns; duke@435: } duke@435: duke@435: duke@435: void GraphBuilder::ScopeData::incr_num_returns() { duke@435: if (parsing_jsr()) { duke@435: parent()->incr_num_returns(); duke@435: } else { duke@435: ++_num_returns; duke@435: } duke@435: } duke@435: duke@435: duke@435: // Implementation of GraphBuilder duke@435: duke@435: #define INLINE_BAILOUT(msg) { inline_bailout(msg); return false; } duke@435: duke@435: duke@435: void GraphBuilder::load_constant() { duke@435: ciConstant con = stream()->get_constant(); duke@435: if (con.basic_type() == T_ILLEGAL) { duke@435: BAILOUT("could not resolve a constant"); duke@435: } else { duke@435: ValueType* t = illegalType; duke@435: ValueStack* patch_state = NULL; duke@435: switch (con.basic_type()) { duke@435: case T_BOOLEAN: t = new IntConstant (con.as_boolean()); break; duke@435: case T_BYTE : t = new IntConstant (con.as_byte ()); break; duke@435: case T_CHAR : t = new IntConstant (con.as_char ()); break; duke@435: case T_SHORT : t = new IntConstant (con.as_short ()); break; duke@435: case T_INT : t = new IntConstant (con.as_int ()); break; duke@435: case T_LONG : t = new LongConstant (con.as_long ()); break; duke@435: case T_FLOAT : t = new FloatConstant (con.as_float ()); break; duke@435: case T_DOUBLE : t = new DoubleConstant (con.as_double ()); break; duke@435: case T_ARRAY : t = new ArrayConstant (con.as_object ()->as_array ()); break; duke@435: case T_OBJECT : duke@435: { duke@435: ciObject* obj = con.as_object(); duke@435: if (obj->is_klass()) { duke@435: ciKlass* klass = obj->as_klass(); duke@435: if (!klass->is_loaded() || PatchALot) { duke@435: patch_state = state()->copy(); duke@435: t = new ObjectConstant(obj); duke@435: } else { duke@435: t = new InstanceConstant(klass->java_mirror()); duke@435: } duke@435: } else { duke@435: t = new InstanceConstant(obj->as_instance()); duke@435: } duke@435: break; duke@435: } duke@435: default : ShouldNotReachHere(); duke@435: } duke@435: Value x; duke@435: if (patch_state != NULL) { duke@435: x = new Constant(t, patch_state); duke@435: } else { duke@435: x = new Constant(t); duke@435: } duke@435: push(t, append(x)); duke@435: } duke@435: } duke@435: duke@435: duke@435: void GraphBuilder::load_local(ValueType* type, int index) { duke@435: Value x = state()->load_local(index); duke@435: push(type, x); duke@435: } duke@435: duke@435: duke@435: void GraphBuilder::store_local(ValueType* type, int index) { duke@435: Value x = pop(type); duke@435: store_local(state(), x, type, index); duke@435: } duke@435: duke@435: duke@435: void GraphBuilder::store_local(ValueStack* state, Value x, ValueType* type, int index) { duke@435: if (parsing_jsr()) { duke@435: // We need to do additional tracking of the location of the return duke@435: // address for jsrs since we don't handle arbitrary jsr/ret duke@435: // constructs. Here we are figuring out in which circumstances we duke@435: // need to bail out. duke@435: if (x->type()->is_address()) { duke@435: scope_data()->set_jsr_return_address_local(index); duke@435: duke@435: // Also check parent jsrs (if any) at this time to see whether duke@435: // they are using this local. We don't handle skipping over a duke@435: // ret. duke@435: for (ScopeData* cur_scope_data = scope_data()->parent(); duke@435: cur_scope_data != NULL && cur_scope_data->parsing_jsr() && cur_scope_data->scope() == scope(); duke@435: cur_scope_data = cur_scope_data->parent()) { duke@435: if (cur_scope_data->jsr_return_address_local() == index) { duke@435: BAILOUT("subroutine overwrites return address from previous subroutine"); duke@435: } duke@435: } duke@435: } else if (index == scope_data()->jsr_return_address_local()) { duke@435: scope_data()->set_jsr_return_address_local(-1); duke@435: } duke@435: } duke@435: duke@435: state->store_local(index, round_fp(x)); duke@435: } duke@435: duke@435: duke@435: void GraphBuilder::load_indexed(BasicType type) { duke@435: Value index = ipop(); duke@435: Value array = apop(); duke@435: Value length = NULL; duke@435: if (CSEArrayLength || duke@435: (array->as_AccessField() && array->as_AccessField()->field()->is_constant()) || duke@435: (array->as_NewArray() && array->as_NewArray()->length() && array->as_NewArray()->length()->type()->is_constant())) { duke@435: length = append(new ArrayLength(array, lock_stack())); duke@435: } duke@435: push(as_ValueType(type), append(new LoadIndexed(array, index, length, type, lock_stack()))); duke@435: } duke@435: duke@435: duke@435: void GraphBuilder::store_indexed(BasicType type) { duke@435: Value value = pop(as_ValueType(type)); duke@435: Value index = ipop(); duke@435: Value array = apop(); duke@435: Value length = NULL; duke@435: if (CSEArrayLength || duke@435: (array->as_AccessField() && array->as_AccessField()->field()->is_constant()) || duke@435: (array->as_NewArray() && array->as_NewArray()->length() && array->as_NewArray()->length()->type()->is_constant())) { duke@435: length = append(new ArrayLength(array, lock_stack())); duke@435: } duke@435: StoreIndexed* result = new StoreIndexed(array, index, length, type, value, lock_stack()); duke@435: append(result); never@894: _memory->store_value(value); duke@435: } duke@435: duke@435: duke@435: void GraphBuilder::stack_op(Bytecodes::Code code) { duke@435: switch (code) { duke@435: case Bytecodes::_pop: duke@435: { state()->raw_pop(); duke@435: } duke@435: break; duke@435: case Bytecodes::_pop2: duke@435: { state()->raw_pop(); duke@435: state()->raw_pop(); duke@435: } duke@435: break; duke@435: case Bytecodes::_dup: duke@435: { Value w = state()->raw_pop(); duke@435: state()->raw_push(w); duke@435: state()->raw_push(w); duke@435: } duke@435: break; duke@435: case Bytecodes::_dup_x1: duke@435: { Value w1 = state()->raw_pop(); duke@435: Value w2 = state()->raw_pop(); duke@435: state()->raw_push(w1); duke@435: state()->raw_push(w2); duke@435: state()->raw_push(w1); duke@435: } duke@435: break; duke@435: case Bytecodes::_dup_x2: duke@435: { Value w1 = state()->raw_pop(); duke@435: Value w2 = state()->raw_pop(); duke@435: Value w3 = state()->raw_pop(); duke@435: state()->raw_push(w1); duke@435: state()->raw_push(w3); duke@435: state()->raw_push(w2); duke@435: state()->raw_push(w1); duke@435: } duke@435: break; duke@435: case Bytecodes::_dup2: duke@435: { Value w1 = state()->raw_pop(); duke@435: Value w2 = state()->raw_pop(); duke@435: state()->raw_push(w2); duke@435: state()->raw_push(w1); duke@435: state()->raw_push(w2); duke@435: state()->raw_push(w1); duke@435: } duke@435: break; duke@435: case Bytecodes::_dup2_x1: duke@435: { Value w1 = state()->raw_pop(); duke@435: Value w2 = state()->raw_pop(); duke@435: Value w3 = state()->raw_pop(); duke@435: state()->raw_push(w2); duke@435: state()->raw_push(w1); duke@435: state()->raw_push(w3); duke@435: state()->raw_push(w2); duke@435: state()->raw_push(w1); duke@435: } duke@435: break; duke@435: case Bytecodes::_dup2_x2: duke@435: { Value w1 = state()->raw_pop(); duke@435: Value w2 = state()->raw_pop(); duke@435: Value w3 = state()->raw_pop(); duke@435: Value w4 = state()->raw_pop(); duke@435: state()->raw_push(w2); duke@435: state()->raw_push(w1); duke@435: state()->raw_push(w4); duke@435: state()->raw_push(w3); duke@435: state()->raw_push(w2); duke@435: state()->raw_push(w1); duke@435: } duke@435: break; duke@435: case Bytecodes::_swap: duke@435: { Value w1 = state()->raw_pop(); duke@435: Value w2 = state()->raw_pop(); duke@435: state()->raw_push(w1); duke@435: state()->raw_push(w2); duke@435: } duke@435: break; duke@435: default: duke@435: ShouldNotReachHere(); duke@435: break; duke@435: } duke@435: } duke@435: duke@435: duke@435: void GraphBuilder::arithmetic_op(ValueType* type, Bytecodes::Code code, ValueStack* stack) { duke@435: Value y = pop(type); duke@435: Value x = pop(type); duke@435: // NOTE: strictfp can be queried from current method since we don't duke@435: // inline methods with differing strictfp bits duke@435: Value res = new ArithmeticOp(code, x, y, method()->is_strict(), stack); duke@435: // Note: currently single-precision floating-point rounding on Intel is handled at the LIRGenerator level duke@435: res = append(res); duke@435: if (method()->is_strict()) { duke@435: res = round_fp(res); duke@435: } duke@435: push(type, res); duke@435: } duke@435: duke@435: duke@435: void GraphBuilder::negate_op(ValueType* type) { duke@435: push(type, append(new NegateOp(pop(type)))); duke@435: } duke@435: duke@435: duke@435: void GraphBuilder::shift_op(ValueType* type, Bytecodes::Code code) { duke@435: Value s = ipop(); duke@435: Value x = pop(type); duke@435: // try to simplify duke@435: // Note: This code should go into the canonicalizer as soon as it can duke@435: // can handle canonicalized forms that contain more than one node. duke@435: if (CanonicalizeNodes && code == Bytecodes::_iushr) { duke@435: // pattern: x >>> s duke@435: IntConstant* s1 = s->type()->as_IntConstant(); duke@435: if (s1 != NULL) { duke@435: // pattern: x >>> s1, with s1 constant duke@435: ShiftOp* l = x->as_ShiftOp(); duke@435: if (l != NULL && l->op() == Bytecodes::_ishl) { duke@435: // pattern: (a << b) >>> s1 duke@435: IntConstant* s0 = l->y()->type()->as_IntConstant(); duke@435: if (s0 != NULL) { duke@435: // pattern: (a << s0) >>> s1 duke@435: const int s0c = s0->value() & 0x1F; // only the low 5 bits are significant for shifts duke@435: const int s1c = s1->value() & 0x1F; // only the low 5 bits are significant for shifts duke@435: if (s0c == s1c) { duke@435: if (s0c == 0) { duke@435: // pattern: (a << 0) >>> 0 => simplify to: a duke@435: ipush(l->x()); duke@435: } else { duke@435: // pattern: (a << s0c) >>> s0c => simplify to: a & m, with m constant duke@435: assert(0 < s0c && s0c < BitsPerInt, "adjust code below to handle corner cases"); duke@435: const int m = (1 << (BitsPerInt - s0c)) - 1; duke@435: Value s = append(new Constant(new IntConstant(m))); duke@435: ipush(append(new LogicOp(Bytecodes::_iand, l->x(), s))); duke@435: } duke@435: return; duke@435: } duke@435: } duke@435: } duke@435: } duke@435: } duke@435: // could not simplify duke@435: push(type, append(new ShiftOp(code, x, s))); duke@435: } duke@435: duke@435: duke@435: void GraphBuilder::logic_op(ValueType* type, Bytecodes::Code code) { duke@435: Value y = pop(type); duke@435: Value x = pop(type); duke@435: push(type, append(new LogicOp(code, x, y))); duke@435: } duke@435: duke@435: duke@435: void GraphBuilder::compare_op(ValueType* type, Bytecodes::Code code) { duke@435: ValueStack* state_before = state()->copy(); duke@435: Value y = pop(type); duke@435: Value x = pop(type); duke@435: ipush(append(new CompareOp(code, x, y, state_before))); duke@435: } duke@435: duke@435: duke@435: void GraphBuilder::convert(Bytecodes::Code op, BasicType from, BasicType to) { duke@435: push(as_ValueType(to), append(new Convert(op, pop(as_ValueType(from)), as_ValueType(to)))); duke@435: } duke@435: duke@435: duke@435: void GraphBuilder::increment() { duke@435: int index = stream()->get_index(); duke@435: int delta = stream()->is_wide() ? (signed short)Bytes::get_Java_u2(stream()->cur_bcp() + 4) : (signed char)(stream()->cur_bcp()[2]); duke@435: load_local(intType, index); duke@435: ipush(append(new Constant(new IntConstant(delta)))); duke@435: arithmetic_op(intType, Bytecodes::_iadd); duke@435: store_local(intType, index); duke@435: } duke@435: duke@435: duke@435: void GraphBuilder::_goto(int from_bci, int to_bci) { duke@435: profile_bci(from_bci); duke@435: append(new Goto(block_at(to_bci), to_bci <= from_bci)); duke@435: } duke@435: duke@435: duke@435: void GraphBuilder::if_node(Value x, If::Condition cond, Value y, ValueStack* state_before) { duke@435: BlockBegin* tsux = block_at(stream()->get_dest()); duke@435: BlockBegin* fsux = block_at(stream()->next_bci()); duke@435: bool is_bb = tsux->bci() < stream()->cur_bci() || fsux->bci() < stream()->cur_bci(); duke@435: If* if_node = append(new If(x, cond, false, y, tsux, fsux, is_bb ? state_before : NULL, is_bb))->as_If(); duke@435: if (profile_branches() && (if_node != NULL)) { duke@435: if_node->set_profiled_method(method()); duke@435: if_node->set_profiled_bci(bci()); duke@435: if_node->set_should_profile(true); duke@435: } duke@435: } duke@435: duke@435: duke@435: void GraphBuilder::if_zero(ValueType* type, If::Condition cond) { duke@435: Value y = append(new Constant(intZero)); duke@435: ValueStack* state_before = state()->copy(); duke@435: Value x = ipop(); duke@435: if_node(x, cond, y, state_before); duke@435: } duke@435: duke@435: duke@435: void GraphBuilder::if_null(ValueType* type, If::Condition cond) { duke@435: Value y = append(new Constant(objectNull)); duke@435: ValueStack* state_before = state()->copy(); duke@435: Value x = apop(); duke@435: if_node(x, cond, y, state_before); duke@435: } duke@435: duke@435: duke@435: void GraphBuilder::if_same(ValueType* type, If::Condition cond) { duke@435: ValueStack* state_before = state()->copy(); duke@435: Value y = pop(type); duke@435: Value x = pop(type); duke@435: if_node(x, cond, y, state_before); duke@435: } duke@435: duke@435: duke@435: void GraphBuilder::jsr(int dest) { duke@435: // We only handle well-formed jsrs (those which are "block-structured"). duke@435: // If the bytecodes are strange (jumping out of a jsr block) then we duke@435: // might end up trying to re-parse a block containing a jsr which duke@435: // has already been activated. Watch for this case and bail out. duke@435: for (ScopeData* cur_scope_data = scope_data(); duke@435: cur_scope_data != NULL && cur_scope_data->parsing_jsr() && cur_scope_data->scope() == scope(); duke@435: cur_scope_data = cur_scope_data->parent()) { duke@435: if (cur_scope_data->jsr_entry_bci() == dest) { duke@435: BAILOUT("too-complicated jsr/ret structure"); duke@435: } duke@435: } duke@435: duke@435: push(addressType, append(new Constant(new AddressConstant(next_bci())))); duke@435: if (!try_inline_jsr(dest)) { duke@435: return; // bailed out while parsing and inlining subroutine duke@435: } duke@435: } duke@435: duke@435: duke@435: void GraphBuilder::ret(int local_index) { duke@435: if (!parsing_jsr()) BAILOUT("ret encountered while not parsing subroutine"); duke@435: duke@435: if (local_index != scope_data()->jsr_return_address_local()) { duke@435: BAILOUT("can not handle complicated jsr/ret constructs"); duke@435: } duke@435: duke@435: // Rets simply become (NON-SAFEPOINT) gotos to the jsr continuation duke@435: append(new Goto(scope_data()->jsr_continuation(), false)); duke@435: } duke@435: duke@435: duke@435: void GraphBuilder::table_switch() { duke@435: Bytecode_tableswitch* switch_ = Bytecode_tableswitch_at(method()->code() + bci()); duke@435: const int l = switch_->length(); duke@435: if (CanonicalizeNodes && l == 1) { duke@435: // total of 2 successors => use If instead of switch duke@435: // Note: This code should go into the canonicalizer as soon as it can duke@435: // can handle canonicalized forms that contain more than one node. duke@435: Value key = append(new Constant(new IntConstant(switch_->low_key()))); duke@435: BlockBegin* tsux = block_at(bci() + switch_->dest_offset_at(0)); duke@435: BlockBegin* fsux = block_at(bci() + switch_->default_offset()); duke@435: bool is_bb = tsux->bci() < bci() || fsux->bci() < bci(); duke@435: ValueStack* state_before = is_bb ? state() : NULL; duke@435: append(new If(ipop(), If::eql, true, key, tsux, fsux, state_before, is_bb)); duke@435: } else { duke@435: // collect successors duke@435: BlockList* sux = new BlockList(l + 1, NULL); duke@435: int i; duke@435: bool has_bb = false; duke@435: for (i = 0; i < l; i++) { duke@435: sux->at_put(i, block_at(bci() + switch_->dest_offset_at(i))); duke@435: if (switch_->dest_offset_at(i) < 0) has_bb = true; duke@435: } duke@435: // add default successor duke@435: sux->at_put(i, block_at(bci() + switch_->default_offset())); duke@435: ValueStack* state_before = has_bb ? state() : NULL; duke@435: append(new TableSwitch(ipop(), sux, switch_->low_key(), state_before, has_bb)); duke@435: } duke@435: } duke@435: duke@435: duke@435: void GraphBuilder::lookup_switch() { duke@435: Bytecode_lookupswitch* switch_ = Bytecode_lookupswitch_at(method()->code() + bci()); duke@435: const int l = switch_->number_of_pairs(); duke@435: if (CanonicalizeNodes && l == 1) { duke@435: // total of 2 successors => use If instead of switch duke@435: // Note: This code should go into the canonicalizer as soon as it can duke@435: // can handle canonicalized forms that contain more than one node. duke@435: // simplify to If duke@435: LookupswitchPair* pair = switch_->pair_at(0); duke@435: Value key = append(new Constant(new IntConstant(pair->match()))); duke@435: BlockBegin* tsux = block_at(bci() + pair->offset()); duke@435: BlockBegin* fsux = block_at(bci() + switch_->default_offset()); duke@435: bool is_bb = tsux->bci() < bci() || fsux->bci() < bci(); duke@435: ValueStack* state_before = is_bb ? state() : NULL; duke@435: append(new If(ipop(), If::eql, true, key, tsux, fsux, state_before, is_bb)); duke@435: } else { duke@435: // collect successors & keys duke@435: BlockList* sux = new BlockList(l + 1, NULL); duke@435: intArray* keys = new intArray(l, 0); duke@435: int i; duke@435: bool has_bb = false; duke@435: for (i = 0; i < l; i++) { duke@435: LookupswitchPair* pair = switch_->pair_at(i); duke@435: if (pair->offset() < 0) has_bb = true; duke@435: sux->at_put(i, block_at(bci() + pair->offset())); duke@435: keys->at_put(i, pair->match()); duke@435: } duke@435: // add default successor duke@435: sux->at_put(i, block_at(bci() + switch_->default_offset())); duke@435: ValueStack* state_before = has_bb ? state() : NULL; duke@435: append(new LookupSwitch(ipop(), sux, keys, state_before, has_bb)); duke@435: } duke@435: } duke@435: duke@435: void GraphBuilder::call_register_finalizer() { duke@435: // If the receiver requires finalization then emit code to perform duke@435: // the registration on return. duke@435: duke@435: // Gather some type information about the receiver duke@435: Value receiver = state()->load_local(0); duke@435: assert(receiver != NULL, "must have a receiver"); duke@435: ciType* declared_type = receiver->declared_type(); duke@435: ciType* exact_type = receiver->exact_type(); duke@435: if (exact_type == NULL && duke@435: receiver->as_Local() && duke@435: receiver->as_Local()->java_index() == 0) { duke@435: ciInstanceKlass* ik = compilation()->method()->holder(); duke@435: if (ik->is_final()) { duke@435: exact_type = ik; duke@435: } else if (UseCHA && !(ik->has_subklass() || ik->is_interface())) { duke@435: // test class is leaf class duke@435: compilation()->dependency_recorder()->assert_leaf_type(ik); duke@435: exact_type = ik; duke@435: } else { duke@435: declared_type = ik; duke@435: } duke@435: } duke@435: duke@435: // see if we know statically that registration isn't required duke@435: bool needs_check = true; duke@435: if (exact_type != NULL) { duke@435: needs_check = exact_type->as_instance_klass()->has_finalizer(); duke@435: } else if (declared_type != NULL) { duke@435: ciInstanceKlass* ik = declared_type->as_instance_klass(); duke@435: if (!Dependencies::has_finalizable_subclass(ik)) { duke@435: compilation()->dependency_recorder()->assert_has_no_finalizable_subclasses(ik); duke@435: needs_check = false; duke@435: } duke@435: } duke@435: duke@435: if (needs_check) { duke@435: // Perform the registration of finalizable objects. duke@435: load_local(objectType, 0); duke@435: append_split(new Intrinsic(voidType, vmIntrinsics::_Object_init, duke@435: state()->pop_arguments(1), duke@435: true, lock_stack(), true)); duke@435: } duke@435: } duke@435: duke@435: duke@435: void GraphBuilder::method_return(Value x) { duke@435: if (RegisterFinalizersAtInit && duke@435: method()->intrinsic_id() == vmIntrinsics::_Object_init) { duke@435: call_register_finalizer(); duke@435: } duke@435: duke@435: // Check to see whether we are inlining. If so, Return duke@435: // instructions become Gotos to the continuation point. duke@435: if (continuation() != NULL) { duke@435: assert(!method()->is_synchronized() || InlineSynchronizedMethods, "can not inline synchronized methods yet"); duke@435: duke@435: // If the inlined method is synchronized, the monitor must be duke@435: // released before we jump to the continuation block. duke@435: if (method()->is_synchronized()) { duke@435: int i = state()->caller_state()->locks_size(); duke@435: assert(state()->locks_size() == i + 1, "receiver must be locked here"); duke@435: monitorexit(state()->lock_at(i), SynchronizationEntryBCI); duke@435: } duke@435: duke@435: state()->truncate_stack(caller_stack_size()); duke@435: if (x != NULL) { duke@435: state()->push(x->type(), x); duke@435: } duke@435: Goto* goto_callee = new Goto(continuation(), false); duke@435: duke@435: // See whether this is the first return; if so, store off some duke@435: // of the state for later examination duke@435: if (num_returns() == 0) { duke@435: set_inline_cleanup_info(_block, _last, state()); duke@435: } duke@435: duke@435: // State at end of inlined method is the state of the caller duke@435: // without the method parameters on stack, including the duke@435: // return value, if any, of the inlined method on operand stack. duke@435: set_state(scope_data()->continuation_state()->copy()); duke@435: if (x) { duke@435: state()->push(x->type(), x); duke@435: } duke@435: duke@435: // The current bci() is in the wrong scope, so use the bci() of duke@435: // the continuation point. duke@435: append_with_bci(goto_callee, scope_data()->continuation()->bci()); duke@435: incr_num_returns(); duke@435: duke@435: return; duke@435: } duke@435: duke@435: state()->truncate_stack(0); duke@435: if (method()->is_synchronized()) { duke@435: // perform the unlocking before exiting the method duke@435: Value receiver; duke@435: if (!method()->is_static()) { duke@435: receiver = _initial_state->local_at(0); duke@435: } else { duke@435: receiver = append(new Constant(new ClassConstant(method()->holder()))); duke@435: } duke@435: append_split(new MonitorExit(receiver, state()->unlock())); duke@435: } duke@435: duke@435: append(new Return(x)); duke@435: } duke@435: duke@435: duke@435: void GraphBuilder::access_field(Bytecodes::Code code) { duke@435: bool will_link; duke@435: ciField* field = stream()->get_field(will_link); duke@435: ciInstanceKlass* holder = field->holder(); duke@435: BasicType field_type = field->type()->basic_type(); duke@435: ValueType* type = as_ValueType(field_type); duke@435: // call will_link again to determine if the field is valid. duke@435: const bool is_loaded = holder->is_loaded() && duke@435: field->will_link(method()->holder(), code); duke@435: const bool is_initialized = is_loaded && holder->is_initialized(); duke@435: duke@435: ValueStack* state_copy = NULL; duke@435: if (!is_initialized || PatchALot) { duke@435: // save state before instruction for debug info when duke@435: // deoptimization happens during patching duke@435: state_copy = state()->copy(); duke@435: } duke@435: duke@435: Value obj = NULL; duke@435: if (code == Bytecodes::_getstatic || code == Bytecodes::_putstatic) { duke@435: // commoning of class constants should only occur if the class is duke@435: // fully initialized and resolved in this constant pool. The will_link test duke@435: // above essentially checks if this class is resolved in this constant pool duke@435: // so, the is_initialized flag should be suffiect. duke@435: if (state_copy != NULL) { duke@435: // build a patching constant duke@435: obj = new Constant(new ClassConstant(holder), state_copy); duke@435: } else { duke@435: obj = new Constant(new ClassConstant(holder)); duke@435: } duke@435: } duke@435: duke@435: duke@435: const int offset = is_loaded ? field->offset() : -1; duke@435: switch (code) { duke@435: case Bytecodes::_getstatic: { duke@435: // check for compile-time constants, i.e., initialized static final fields duke@435: Instruction* constant = NULL; duke@435: if (field->is_constant() && !PatchALot) { duke@435: ciConstant field_val = field->constant_value(); duke@435: BasicType field_type = field_val.basic_type(); duke@435: switch (field_type) { duke@435: case T_ARRAY: duke@435: case T_OBJECT: jrose@1424: if (field_val.as_object()->should_be_constant()) { duke@435: constant = new Constant(as_ValueType(field_val)); duke@435: } duke@435: break; duke@435: duke@435: default: duke@435: constant = new Constant(as_ValueType(field_val)); duke@435: } duke@435: } duke@435: if (constant != NULL) { duke@435: push(type, append(constant)); duke@435: state_copy = NULL; // Not a potential deoptimization point (see set_state_before logic below) duke@435: } else { duke@435: push(type, append(new LoadField(append(obj), offset, field, true, duke@435: lock_stack(), state_copy, is_loaded, is_initialized))); duke@435: } duke@435: break; duke@435: } duke@435: case Bytecodes::_putstatic: duke@435: { Value val = pop(type); duke@435: append(new StoreField(append(obj), offset, field, val, true, lock_stack(), state_copy, is_loaded, is_initialized)); duke@435: } duke@435: break; duke@435: case Bytecodes::_getfield : duke@435: { duke@435: LoadField* load = new LoadField(apop(), offset, field, false, lock_stack(), state_copy, is_loaded, true); duke@435: Value replacement = is_loaded ? _memory->load(load) : load; duke@435: if (replacement != load) { duke@435: assert(replacement->bci() != -99 || replacement->as_Phi() || replacement->as_Local(), duke@435: "should already by linked"); duke@435: push(type, replacement); duke@435: } else { duke@435: push(type, append(load)); duke@435: } duke@435: break; duke@435: } duke@435: duke@435: case Bytecodes::_putfield : duke@435: { Value val = pop(type); duke@435: StoreField* store = new StoreField(apop(), offset, field, val, false, lock_stack(), state_copy, is_loaded, true); duke@435: if (is_loaded) store = _memory->store(store); duke@435: if (store != NULL) { duke@435: append(store); duke@435: } duke@435: } duke@435: break; duke@435: default : duke@435: ShouldNotReachHere(); duke@435: break; duke@435: } duke@435: } duke@435: duke@435: duke@435: Dependencies* GraphBuilder::dependency_recorder() const { duke@435: assert(DeoptC1, "need debug information"); duke@435: return compilation()->dependency_recorder(); duke@435: } duke@435: duke@435: duke@435: void GraphBuilder::invoke(Bytecodes::Code code) { duke@435: bool will_link; duke@435: ciMethod* target = stream()->get_method(will_link); duke@435: // we have to make sure the argument size (incl. the receiver) duke@435: // is correct for compilation (the call would fail later during duke@435: // linkage anyway) - was bug (gri 7/28/99) duke@435: if (target->is_loaded() && target->is_static() != (code == Bytecodes::_invokestatic)) BAILOUT("will cause link error"); duke@435: ciInstanceKlass* klass = target->holder(); duke@435: duke@435: // check if CHA possible: if so, change the code to invoke_special duke@435: ciInstanceKlass* calling_klass = method()->holder(); duke@435: ciKlass* holder = stream()->get_declared_method_holder(); duke@435: ciInstanceKlass* callee_holder = ciEnv::get_instance_klass_for_declared_method_holder(holder); duke@435: ciInstanceKlass* actual_recv = callee_holder; duke@435: duke@435: // some methods are obviously bindable without any type checks so duke@435: // convert them directly to an invokespecial. duke@435: if (target->is_loaded() && !target->is_abstract() && duke@435: target->can_be_statically_bound() && code == Bytecodes::_invokevirtual) { duke@435: code = Bytecodes::_invokespecial; duke@435: } duke@435: duke@435: // NEEDS_CLEANUP duke@435: // I've added the target-is_loaded() test below but I don't really understand duke@435: // how klass->is_loaded() can be true and yet target->is_loaded() is false. duke@435: // this happened while running the JCK invokevirtual tests under doit. TKR duke@435: ciMethod* cha_monomorphic_target = NULL; duke@435: ciMethod* exact_target = NULL; twisti@1730: if (UseCHA && DeoptC1 && klass->is_loaded() && target->is_loaded() && twisti@1730: !target->is_method_handle_invoke()) { duke@435: Value receiver = NULL; duke@435: ciInstanceKlass* receiver_klass = NULL; duke@435: bool type_is_exact = false; duke@435: // try to find a precise receiver type duke@435: if (will_link && !target->is_static()) { duke@435: int index = state()->stack_size() - (target->arg_size_no_receiver() + 1); duke@435: receiver = state()->stack_at(index); duke@435: ciType* type = receiver->exact_type(); duke@435: if (type != NULL && type->is_loaded() && duke@435: type->is_instance_klass() && !type->as_instance_klass()->is_interface()) { duke@435: receiver_klass = (ciInstanceKlass*) type; duke@435: type_is_exact = true; duke@435: } duke@435: if (type == NULL) { duke@435: type = receiver->declared_type(); duke@435: if (type != NULL && type->is_loaded() && duke@435: type->is_instance_klass() && !type->as_instance_klass()->is_interface()) { duke@435: receiver_klass = (ciInstanceKlass*) type; duke@435: if (receiver_klass->is_leaf_type() && !receiver_klass->is_final()) { duke@435: // Insert a dependency on this type since duke@435: // find_monomorphic_target may assume it's already done. duke@435: dependency_recorder()->assert_leaf_type(receiver_klass); duke@435: type_is_exact = true; duke@435: } duke@435: } duke@435: } duke@435: } duke@435: if (receiver_klass != NULL && type_is_exact && duke@435: receiver_klass->is_loaded() && code != Bytecodes::_invokespecial) { duke@435: // If we have the exact receiver type we can bind directly to duke@435: // the method to call. duke@435: exact_target = target->resolve_invoke(calling_klass, receiver_klass); duke@435: if (exact_target != NULL) { duke@435: target = exact_target; duke@435: code = Bytecodes::_invokespecial; duke@435: } duke@435: } duke@435: if (receiver_klass != NULL && duke@435: receiver_klass->is_subtype_of(actual_recv) && duke@435: actual_recv->is_initialized()) { duke@435: actual_recv = receiver_klass; duke@435: } duke@435: duke@435: if ((code == Bytecodes::_invokevirtual && callee_holder->is_initialized()) || duke@435: (code == Bytecodes::_invokeinterface && callee_holder->is_initialized() && !actual_recv->is_interface())) { duke@435: // Use CHA on the receiver to select a more precise method. duke@435: cha_monomorphic_target = target->find_monomorphic_target(calling_klass, callee_holder, actual_recv); duke@435: } else if (code == Bytecodes::_invokeinterface && callee_holder->is_loaded() && receiver != NULL) { duke@435: // if there is only one implementor of this interface then we duke@435: // may be able bind this invoke directly to the implementing duke@435: // klass but we need both a dependence on the single interface duke@435: // and on the method we bind to. Additionally since all we know duke@435: // about the receiver type is the it's supposed to implement the duke@435: // interface we have to insert a check that it's the class we duke@435: // expect. Interface types are not checked by the verifier so duke@435: // they are roughly equivalent to Object. duke@435: ciInstanceKlass* singleton = NULL; duke@435: if (target->holder()->nof_implementors() == 1) { duke@435: singleton = target->holder()->implementor(0); duke@435: } duke@435: if (singleton) { duke@435: cha_monomorphic_target = target->find_monomorphic_target(calling_klass, target->holder(), singleton); duke@435: if (cha_monomorphic_target != NULL) { duke@435: // If CHA is able to bind this invoke then update the class duke@435: // to match that class, otherwise klass will refer to the duke@435: // interface. duke@435: klass = cha_monomorphic_target->holder(); duke@435: actual_recv = target->holder(); duke@435: duke@435: // insert a check it's really the expected class. duke@435: CheckCast* c = new CheckCast(klass, receiver, NULL); duke@435: c->set_incompatible_class_change_check(); duke@435: c->set_direct_compare(klass->is_final()); duke@435: append_split(c); duke@435: } duke@435: } duke@435: } duke@435: } duke@435: duke@435: if (cha_monomorphic_target != NULL) { duke@435: if (cha_monomorphic_target->is_abstract()) { duke@435: // Do not optimize for abstract methods duke@435: cha_monomorphic_target = NULL; duke@435: } duke@435: } duke@435: duke@435: if (cha_monomorphic_target != NULL) { duke@435: if (!(target->is_final_method())) { duke@435: // If we inlined because CHA revealed only a single target method, duke@435: // then we are dependent on that target method not getting overridden duke@435: // by dynamic class loading. Be sure to test the "static" receiver duke@435: // dest_method here, as opposed to the actual receiver, which may duke@435: // falsely lead us to believe that the receiver is final or private. duke@435: dependency_recorder()->assert_unique_concrete_method(actual_recv, cha_monomorphic_target); duke@435: } duke@435: code = Bytecodes::_invokespecial; duke@435: } duke@435: // check if we could do inlining duke@435: if (!PatchALot && Inline && klass->is_loaded() && duke@435: (klass->is_initialized() || klass->is_interface() && target->holder()->is_initialized()) duke@435: && target->will_link(klass, callee_holder, code)) { duke@435: // callee is known => check if we have static binding duke@435: assert(target->is_loaded(), "callee must be known"); duke@435: if (code == Bytecodes::_invokestatic duke@435: || code == Bytecodes::_invokespecial duke@435: || code == Bytecodes::_invokevirtual && target->is_final_method() duke@435: ) { duke@435: // static binding => check if callee is ok duke@435: ciMethod* inline_target = (cha_monomorphic_target != NULL) duke@435: ? cha_monomorphic_target duke@435: : target; duke@435: bool res = try_inline(inline_target, (cha_monomorphic_target != NULL) || (exact_target != NULL)); duke@435: CHECK_BAILOUT(); duke@435: duke@435: #ifndef PRODUCT duke@435: // printing duke@435: if (PrintInlining && !res) { duke@435: // if it was successfully inlined, then it was already printed. duke@435: print_inline_result(inline_target, res); duke@435: } duke@435: #endif duke@435: clear_inline_bailout(); duke@435: if (res) { duke@435: // Register dependence if JVMTI has either breakpoint duke@435: // setting or hotswapping of methods capabilities since they may duke@435: // cause deoptimization. kvn@1215: if (compilation()->env()->jvmti_can_hotswap_or_post_breakpoint()) { duke@435: dependency_recorder()->assert_evol_method(inline_target); duke@435: } duke@435: return; duke@435: } duke@435: } duke@435: } duke@435: // If we attempted an inline which did not succeed because of a duke@435: // bailout during construction of the callee graph, the entire duke@435: // compilation has to be aborted. This is fairly rare and currently duke@435: // seems to only occur for jasm-generated classes which contain duke@435: // jsr/ret pairs which are not associated with finally clauses and duke@435: // do not have exception handlers in the containing method, and are duke@435: // therefore not caught early enough to abort the inlining without duke@435: // corrupting the graph. (We currently bail out with a non-empty duke@435: // stack at a ret in these situations.) duke@435: CHECK_BAILOUT(); duke@435: duke@435: // inlining not successful => standard invoke twisti@1730: bool is_loaded = target->is_loaded(); twisti@1730: bool has_receiver = twisti@1730: code == Bytecodes::_invokespecial || twisti@1730: code == Bytecodes::_invokevirtual || twisti@1730: code == Bytecodes::_invokeinterface; twisti@1730: bool is_invokedynamic = code == Bytecodes::_invokedynamic; duke@435: ValueType* result_type = as_ValueType(target->return_type()); twisti@1730: twisti@1730: // We require the debug info to be the "state before" because twisti@1730: // invokedynamics may deoptimize. twisti@1730: ValueStack* state_before = is_invokedynamic ? state()->copy() : NULL; twisti@1730: duke@435: Values* args = state()->pop_arguments(target->arg_size_no_receiver()); twisti@1730: Value recv = has_receiver ? apop() : NULL; duke@435: int vtable_index = methodOopDesc::invalid_vtable_index; duke@435: duke@435: #ifdef SPARC duke@435: // Currently only supported on Sparc. duke@435: // The UseInlineCaches only controls dispatch to invokevirtuals for duke@435: // loaded classes which we weren't able to statically bind. duke@435: if (!UseInlineCaches && is_loaded && code == Bytecodes::_invokevirtual duke@435: && !target->can_be_statically_bound()) { duke@435: // Find a vtable index if one is available duke@435: vtable_index = target->resolve_vtable_index(calling_klass, callee_holder); duke@435: } duke@435: #endif duke@435: duke@435: if (recv != NULL && duke@435: (code == Bytecodes::_invokespecial || duke@435: !is_loaded || target->is_final() || duke@435: profile_calls())) { duke@435: // invokespecial always needs a NULL check. invokevirtual where duke@435: // the target is final or where it's not known that whether the duke@435: // target is final requires a NULL check. Otherwise normal duke@435: // invokevirtual will perform the null check during the lookup duke@435: // logic or the unverified entry point. Profiling of calls duke@435: // requires that the null check is performed in all cases. duke@435: null_check(recv); duke@435: } duke@435: duke@435: if (profile_calls()) { duke@435: assert(cha_monomorphic_target == NULL || exact_target == NULL, "both can not be set"); duke@435: ciKlass* target_klass = NULL; duke@435: if (cha_monomorphic_target != NULL) { duke@435: target_klass = cha_monomorphic_target->holder(); duke@435: } else if (exact_target != NULL) { duke@435: target_klass = exact_target->holder(); duke@435: } duke@435: profile_call(recv, target_klass); duke@435: } duke@435: twisti@1730: Invoke* result = new Invoke(code, result_type, recv, args, vtable_index, target, state_before); duke@435: // push result duke@435: append_split(result); duke@435: duke@435: if (result_type != voidType) { duke@435: if (method()->is_strict()) { duke@435: push(result_type, round_fp(result)); duke@435: } else { duke@435: push(result_type, result); duke@435: } duke@435: } duke@435: } duke@435: duke@435: duke@435: void GraphBuilder::new_instance(int klass_index) { duke@435: bool will_link; duke@435: ciKlass* klass = stream()->get_klass(will_link); duke@435: assert(klass->is_instance_klass(), "must be an instance klass"); duke@435: NewInstance* new_instance = new NewInstance(klass->as_instance_klass()); duke@435: _memory->new_instance(new_instance); duke@435: apush(append_split(new_instance)); duke@435: } duke@435: duke@435: duke@435: void GraphBuilder::new_type_array() { duke@435: apush(append_split(new NewTypeArray(ipop(), (BasicType)stream()->get_index()))); duke@435: } duke@435: duke@435: duke@435: void GraphBuilder::new_object_array() { duke@435: bool will_link; duke@435: ciKlass* klass = stream()->get_klass(will_link); duke@435: ValueStack* state_before = !klass->is_loaded() || PatchALot ? state()->copy() : NULL; duke@435: NewArray* n = new NewObjectArray(klass, ipop(), state_before); duke@435: apush(append_split(n)); duke@435: } duke@435: duke@435: duke@435: bool GraphBuilder::direct_compare(ciKlass* k) { duke@435: if (k->is_loaded() && k->is_instance_klass() && !UseSlowPath) { duke@435: ciInstanceKlass* ik = k->as_instance_klass(); duke@435: if (ik->is_final()) { duke@435: return true; duke@435: } else { duke@435: if (DeoptC1 && UseCHA && !(ik->has_subklass() || ik->is_interface())) { duke@435: // test class is leaf class duke@435: dependency_recorder()->assert_leaf_type(ik); duke@435: return true; duke@435: } duke@435: } duke@435: } duke@435: return false; duke@435: } duke@435: duke@435: duke@435: void GraphBuilder::check_cast(int klass_index) { duke@435: bool will_link; duke@435: ciKlass* klass = stream()->get_klass(will_link); duke@435: ValueStack* state_before = !klass->is_loaded() || PatchALot ? state()->copy() : NULL; duke@435: CheckCast* c = new CheckCast(klass, apop(), state_before); duke@435: apush(append_split(c)); duke@435: c->set_direct_compare(direct_compare(klass)); duke@435: if (profile_checkcasts()) { duke@435: c->set_profiled_method(method()); duke@435: c->set_profiled_bci(bci()); duke@435: c->set_should_profile(true); duke@435: } duke@435: } duke@435: duke@435: duke@435: void GraphBuilder::instance_of(int klass_index) { duke@435: bool will_link; duke@435: ciKlass* klass = stream()->get_klass(will_link); duke@435: ValueStack* state_before = !klass->is_loaded() || PatchALot ? state()->copy() : NULL; duke@435: InstanceOf* i = new InstanceOf(klass, apop(), state_before); duke@435: ipush(append_split(i)); duke@435: i->set_direct_compare(direct_compare(klass)); duke@435: } duke@435: duke@435: duke@435: void GraphBuilder::monitorenter(Value x, int bci) { duke@435: // save state before locking in case of deoptimization after a NullPointerException duke@435: ValueStack* lock_stack_before = lock_stack(); duke@435: append_with_bci(new MonitorEnter(x, state()->lock(scope(), x), lock_stack_before), bci); duke@435: kill_all(); duke@435: } duke@435: duke@435: duke@435: void GraphBuilder::monitorexit(Value x, int bci) { duke@435: // Note: the comment below is only relevant for the case where we do duke@435: // not deoptimize due to asynchronous exceptions (!(DeoptC1 && duke@435: // DeoptOnAsyncException), which is not used anymore) duke@435: duke@435: // Note: Potentially, the monitor state in an exception handler duke@435: // can be wrong due to wrong 'initialization' of the handler duke@435: // via a wrong asynchronous exception path. This can happen, duke@435: // if the exception handler range for asynchronous exceptions duke@435: // is too long (see also java bug 4327029, and comment in duke@435: // GraphBuilder::handle_exception()). This may cause 'under- duke@435: // flow' of the monitor stack => bailout instead. duke@435: if (state()->locks_size() < 1) BAILOUT("monitor stack underflow"); duke@435: append_with_bci(new MonitorExit(x, state()->unlock()), bci); duke@435: kill_all(); duke@435: } duke@435: duke@435: duke@435: void GraphBuilder::new_multi_array(int dimensions) { duke@435: bool will_link; duke@435: ciKlass* klass = stream()->get_klass(will_link); duke@435: ValueStack* state_before = !klass->is_loaded() || PatchALot ? state()->copy() : NULL; duke@435: duke@435: Values* dims = new Values(dimensions, NULL); duke@435: // fill in all dimensions duke@435: int i = dimensions; duke@435: while (i-- > 0) dims->at_put(i, ipop()); duke@435: // create array duke@435: NewArray* n = new NewMultiArray(klass, dims, state_before); duke@435: apush(append_split(n)); duke@435: } duke@435: duke@435: duke@435: void GraphBuilder::throw_op(int bci) { duke@435: // We require that the debug info for a Throw be the "state before" duke@435: // the Throw (i.e., exception oop is still on TOS) duke@435: ValueStack* state_before = state()->copy(); duke@435: Throw* t = new Throw(apop(), state_before); duke@435: append_with_bci(t, bci); duke@435: } duke@435: duke@435: duke@435: Value GraphBuilder::round_fp(Value fp_value) { duke@435: // no rounding needed if SSE2 is used duke@435: if (RoundFPResults && UseSSE < 2) { duke@435: // Must currently insert rounding node for doubleword values that duke@435: // are results of expressions (i.e., not loads from memory or duke@435: // constants) duke@435: if (fp_value->type()->tag() == doubleTag && duke@435: fp_value->as_Constant() == NULL && duke@435: fp_value->as_Local() == NULL && // method parameters need no rounding duke@435: fp_value->as_RoundFP() == NULL) { duke@435: return append(new RoundFP(fp_value)); duke@435: } duke@435: } duke@435: return fp_value; duke@435: } duke@435: duke@435: duke@435: Instruction* GraphBuilder::append_with_bci(Instruction* instr, int bci) { duke@435: Canonicalizer canon(instr, bci); duke@435: Instruction* i1 = canon.canonical(); duke@435: if (i1->bci() != -99) { duke@435: // Canonicalizer returned an instruction which was already duke@435: // appended so simply return it. duke@435: return i1; duke@435: } else if (UseLocalValueNumbering) { duke@435: // Lookup the instruction in the ValueMap and add it to the map if duke@435: // it's not found. duke@435: Instruction* i2 = vmap()->find_insert(i1); duke@435: if (i2 != i1) { duke@435: // found an entry in the value map, so just return it. duke@435: assert(i2->bci() != -1, "should already be linked"); duke@435: return i2; duke@435: } never@894: ValueNumberingEffects vne(vmap()); never@894: i1->visit(&vne); duke@435: } duke@435: duke@435: if (i1->as_Phi() == NULL && i1->as_Local() == NULL) { duke@435: // i1 was not eliminated => append it duke@435: assert(i1->next() == NULL, "shouldn't already be linked"); duke@435: _last = _last->set_next(i1, canon.bci()); duke@435: if (++_instruction_count >= InstructionCountCutoff duke@435: && !bailed_out()) { duke@435: // set the bailout state but complete normal processing. We duke@435: // might do a little more work before noticing the bailout so we duke@435: // want processing to continue normally until it's noticed. duke@435: bailout("Method and/or inlining is too large"); duke@435: } duke@435: duke@435: #ifndef PRODUCT duke@435: if (PrintIRDuringConstruction) { duke@435: InstructionPrinter ip; duke@435: ip.print_line(i1); duke@435: if (Verbose) { duke@435: state()->print(); duke@435: } duke@435: } duke@435: #endif duke@435: assert(_last == i1, "adjust code below"); duke@435: StateSplit* s = i1->as_StateSplit(); duke@435: if (s != NULL && i1->as_BlockEnd() == NULL) { duke@435: if (EliminateFieldAccess) { never@894: Intrinsic* intrinsic = s->as_Intrinsic(); duke@435: if (s->as_Invoke() != NULL || (intrinsic && !intrinsic->preserves_state())) { duke@435: _memory->kill(); duke@435: } duke@435: } duke@435: s->set_state(state()->copy()); duke@435: } duke@435: // set up exception handlers for this instruction if necessary duke@435: if (i1->can_trap()) { duke@435: assert(exception_state() != NULL || !has_handler(), "must have setup exception state"); duke@435: i1->set_exception_handlers(handle_exception(bci)); duke@435: } duke@435: } duke@435: return i1; duke@435: } duke@435: duke@435: duke@435: Instruction* GraphBuilder::append(Instruction* instr) { duke@435: assert(instr->as_StateSplit() == NULL || instr->as_BlockEnd() != NULL, "wrong append used"); duke@435: return append_with_bci(instr, bci()); duke@435: } duke@435: duke@435: duke@435: Instruction* GraphBuilder::append_split(StateSplit* instr) { duke@435: return append_with_bci(instr, bci()); duke@435: } duke@435: duke@435: duke@435: void GraphBuilder::null_check(Value value) { duke@435: if (value->as_NewArray() != NULL || value->as_NewInstance() != NULL) { duke@435: return; duke@435: } else { duke@435: Constant* con = value->as_Constant(); duke@435: if (con) { duke@435: ObjectType* c = con->type()->as_ObjectType(); duke@435: if (c && c->is_loaded()) { duke@435: ObjectConstant* oc = c->as_ObjectConstant(); duke@435: if (!oc || !oc->value()->is_null_object()) { duke@435: return; duke@435: } duke@435: } duke@435: } duke@435: } duke@435: append(new NullCheck(value, lock_stack())); duke@435: } duke@435: duke@435: duke@435: duke@435: XHandlers* GraphBuilder::handle_exception(int cur_bci) { duke@435: // fast path if it is guaranteed that no exception handlers are present duke@435: if (!has_handler()) { duke@435: // TODO: check if return NULL is possible (avoids empty lists) duke@435: return new XHandlers(); duke@435: } duke@435: duke@435: XHandlers* exception_handlers = new XHandlers(); duke@435: ScopeData* cur_scope_data = scope_data(); duke@435: ValueStack* s = exception_state(); duke@435: int scope_count = 0; duke@435: duke@435: assert(s != NULL, "exception state must be set"); duke@435: do { duke@435: assert(cur_scope_data->scope() == s->scope(), "scopes do not match"); duke@435: assert(cur_bci == SynchronizationEntryBCI || cur_bci == cur_scope_data->stream()->cur_bci(), "invalid bci"); duke@435: duke@435: // join with all potential exception handlers duke@435: XHandlers* list = cur_scope_data->xhandlers(); duke@435: const int n = list->length(); duke@435: for (int i = 0; i < n; i++) { duke@435: XHandler* h = list->handler_at(i); duke@435: if (h->covers(cur_bci)) { duke@435: // h is a potential exception handler => join it duke@435: compilation()->set_has_exception_handlers(true); duke@435: duke@435: BlockBegin* entry = h->entry_block(); duke@435: if (entry == block()) { duke@435: // It's acceptable for an exception handler to cover itself duke@435: // but we don't handle that in the parser currently. It's duke@435: // very rare so we bailout instead of trying to handle it. duke@435: BAILOUT_("exception handler covers itself", exception_handlers); duke@435: } duke@435: assert(entry->bci() == h->handler_bci(), "must match"); duke@435: assert(entry->bci() == -1 || entry == cur_scope_data->block_at(entry->bci()), "blocks must correspond"); duke@435: duke@435: // previously this was a BAILOUT, but this is not necessary duke@435: // now because asynchronous exceptions are not handled this way. duke@435: assert(entry->state() == NULL || s->locks_size() == entry->state()->locks_size(), "locks do not match"); duke@435: duke@435: // xhandler start with an empty expression stack duke@435: s->truncate_stack(cur_scope_data->caller_stack_size()); duke@435: duke@435: // Note: Usually this join must work. However, very duke@435: // complicated jsr-ret structures where we don't ret from duke@435: // the subroutine can cause the objects on the monitor duke@435: // stacks to not match because blocks can be parsed twice. duke@435: // The only test case we've seen so far which exhibits this duke@435: // problem is caught by the infinite recursion test in duke@435: // GraphBuilder::jsr() if the join doesn't work. duke@435: if (!entry->try_merge(s)) { duke@435: BAILOUT_("error while joining with exception handler, prob. due to complicated jsr/rets", exception_handlers); duke@435: } duke@435: duke@435: // add current state for correct handling of phi functions at begin of xhandler duke@435: int phi_operand = entry->add_exception_state(s); duke@435: duke@435: // add entry to the list of xhandlers of this block duke@435: _block->add_exception_handler(entry); duke@435: duke@435: // add back-edge from xhandler entry to this block duke@435: if (!entry->is_predecessor(_block)) { duke@435: entry->add_predecessor(_block); duke@435: } duke@435: duke@435: // clone XHandler because phi_operand and scope_count can not be shared duke@435: XHandler* new_xhandler = new XHandler(h); duke@435: new_xhandler->set_phi_operand(phi_operand); duke@435: new_xhandler->set_scope_count(scope_count); duke@435: exception_handlers->append(new_xhandler); duke@435: duke@435: // fill in exception handler subgraph lazily duke@435: assert(!entry->is_set(BlockBegin::was_visited_flag), "entry must not be visited yet"); duke@435: cur_scope_data->add_to_work_list(entry); duke@435: duke@435: // stop when reaching catchall duke@435: if (h->catch_type() == 0) { duke@435: return exception_handlers; duke@435: } duke@435: } duke@435: } duke@435: duke@435: // Set up iteration for next time. duke@435: // If parsing a jsr, do not grab exception handlers from the duke@435: // parent scopes for this method (already got them, and they duke@435: // needed to be cloned) duke@435: if (cur_scope_data->parsing_jsr()) { duke@435: IRScope* tmp_scope = cur_scope_data->scope(); duke@435: while (cur_scope_data->parent() != NULL && duke@435: cur_scope_data->parent()->scope() == tmp_scope) { duke@435: cur_scope_data = cur_scope_data->parent(); duke@435: } duke@435: } duke@435: if (cur_scope_data != NULL) { duke@435: if (cur_scope_data->parent() != NULL) { duke@435: // must use pop_scope instead of caller_state to preserve all monitors duke@435: s = s->pop_scope(); duke@435: } duke@435: cur_bci = cur_scope_data->scope()->caller_bci(); duke@435: cur_scope_data = cur_scope_data->parent(); duke@435: scope_count++; duke@435: } duke@435: } while (cur_scope_data != NULL); duke@435: duke@435: return exception_handlers; duke@435: } duke@435: duke@435: duke@435: // Helper class for simplifying Phis. duke@435: class PhiSimplifier : public BlockClosure { duke@435: private: duke@435: bool _has_substitutions; duke@435: Value simplify(Value v); duke@435: duke@435: public: duke@435: PhiSimplifier(BlockBegin* start) : _has_substitutions(false) { duke@435: start->iterate_preorder(this); duke@435: if (_has_substitutions) { duke@435: SubstitutionResolver sr(start); duke@435: } duke@435: } duke@435: void block_do(BlockBegin* b); duke@435: bool has_substitutions() const { return _has_substitutions; } duke@435: }; duke@435: duke@435: duke@435: Value PhiSimplifier::simplify(Value v) { duke@435: Phi* phi = v->as_Phi(); duke@435: duke@435: if (phi == NULL) { duke@435: // no phi function duke@435: return v; duke@435: } else if (v->has_subst()) { duke@435: // already substituted; subst can be phi itself -> simplify duke@435: return simplify(v->subst()); duke@435: } else if (phi->is_set(Phi::cannot_simplify)) { duke@435: // already tried to simplify phi before duke@435: return phi; duke@435: } else if (phi->is_set(Phi::visited)) { duke@435: // break cycles in phi functions duke@435: return phi; duke@435: } else if (phi->type()->is_illegal()) { duke@435: // illegal phi functions are ignored anyway duke@435: return phi; duke@435: duke@435: } else { duke@435: // mark phi function as processed to break cycles in phi functions duke@435: phi->set(Phi::visited); duke@435: duke@435: // simplify x = [y, x] and x = [y, y] to y duke@435: Value subst = NULL; duke@435: int opd_count = phi->operand_count(); duke@435: for (int i = 0; i < opd_count; i++) { duke@435: Value opd = phi->operand_at(i); duke@435: assert(opd != NULL, "Operand must exist!"); duke@435: duke@435: if (opd->type()->is_illegal()) { duke@435: // if one operand is illegal, the entire phi function is illegal duke@435: phi->make_illegal(); duke@435: phi->clear(Phi::visited); duke@435: return phi; duke@435: } duke@435: duke@435: Value new_opd = simplify(opd); duke@435: assert(new_opd != NULL, "Simplified operand must exist!"); duke@435: duke@435: if (new_opd != phi && new_opd != subst) { duke@435: if (subst == NULL) { duke@435: subst = new_opd; duke@435: } else { duke@435: // no simplification possible duke@435: phi->set(Phi::cannot_simplify); duke@435: phi->clear(Phi::visited); duke@435: return phi; duke@435: } duke@435: } duke@435: } duke@435: duke@435: // sucessfully simplified phi function duke@435: assert(subst != NULL, "illegal phi function"); duke@435: _has_substitutions = true; duke@435: phi->clear(Phi::visited); duke@435: phi->set_subst(subst); duke@435: duke@435: #ifndef PRODUCT duke@435: if (PrintPhiFunctions) { duke@435: tty->print_cr("simplified phi function %c%d to %c%d (Block B%d)", phi->type()->tchar(), phi->id(), subst->type()->tchar(), subst->id(), phi->block()->block_id()); duke@435: } duke@435: #endif duke@435: duke@435: return subst; duke@435: } duke@435: } duke@435: duke@435: duke@435: void PhiSimplifier::block_do(BlockBegin* b) { duke@435: for_each_phi_fun(b, phi, duke@435: simplify(phi); duke@435: ); duke@435: duke@435: #ifdef ASSERT duke@435: for_each_phi_fun(b, phi, duke@435: assert(phi->operand_count() != 1 || phi->subst() != phi, "missed trivial simplification"); duke@435: ); duke@435: duke@435: ValueStack* state = b->state()->caller_state(); duke@435: int index; duke@435: Value value; duke@435: for_each_state(state) { duke@435: for_each_local_value(state, index, value) { duke@435: Phi* phi = value->as_Phi(); duke@435: assert(phi == NULL || phi->block() != b, "must not have phi function to simplify in caller state"); duke@435: } duke@435: } duke@435: #endif duke@435: } duke@435: duke@435: // This method is called after all blocks are filled with HIR instructions duke@435: // It eliminates all Phi functions of the form x = [y, y] and x = [y, x] duke@435: void GraphBuilder::eliminate_redundant_phis(BlockBegin* start) { duke@435: PhiSimplifier simplifier(start); duke@435: } duke@435: duke@435: duke@435: void GraphBuilder::connect_to_end(BlockBegin* beg) { duke@435: // setup iteration duke@435: kill_all(); duke@435: _block = beg; duke@435: _state = beg->state()->copy(); duke@435: _last = beg; duke@435: iterate_bytecodes_for_block(beg->bci()); duke@435: } duke@435: duke@435: duke@435: BlockEnd* GraphBuilder::iterate_bytecodes_for_block(int bci) { duke@435: #ifndef PRODUCT duke@435: if (PrintIRDuringConstruction) { duke@435: tty->cr(); duke@435: InstructionPrinter ip; duke@435: ip.print_instr(_block); tty->cr(); duke@435: ip.print_stack(_block->state()); tty->cr(); duke@435: ip.print_inline_level(_block); duke@435: ip.print_head(); duke@435: tty->print_cr("locals size: %d stack size: %d", state()->locals_size(), state()->stack_size()); duke@435: } duke@435: #endif duke@435: _skip_block = false; duke@435: assert(state() != NULL, "ValueStack missing!"); duke@435: ciBytecodeStream s(method()); duke@435: s.reset_to_bci(bci); duke@435: int prev_bci = bci; duke@435: scope_data()->set_stream(&s); duke@435: // iterate duke@435: Bytecodes::Code code = Bytecodes::_illegal; duke@435: bool push_exception = false; duke@435: duke@435: if (block()->is_set(BlockBegin::exception_entry_flag) && block()->next() == NULL) { duke@435: // first thing in the exception entry block should be the exception object. duke@435: push_exception = true; duke@435: } duke@435: duke@435: while (!bailed_out() && last()->as_BlockEnd() == NULL && duke@435: (code = stream()->next()) != ciBytecodeStream::EOBC() && duke@435: (block_at(s.cur_bci()) == NULL || block_at(s.cur_bci()) == block())) { duke@435: duke@435: if (has_handler() && can_trap(method(), code)) { duke@435: // copy the state because it is modified before handle_exception is called duke@435: set_exception_state(state()->copy()); duke@435: } else { duke@435: // handle_exception is not called for this bytecode duke@435: set_exception_state(NULL); duke@435: } duke@435: duke@435: // Check for active jsr during OSR compilation duke@435: if (compilation()->is_osr_compile() duke@435: && scope()->is_top_scope() duke@435: && parsing_jsr() duke@435: && s.cur_bci() == compilation()->osr_bci()) { duke@435: bailout("OSR not supported while a jsr is active"); duke@435: } duke@435: duke@435: if (push_exception) { duke@435: apush(append(new ExceptionObject())); duke@435: push_exception = false; duke@435: } duke@435: duke@435: // handle bytecode duke@435: switch (code) { duke@435: case Bytecodes::_nop : /* nothing to do */ break; duke@435: case Bytecodes::_aconst_null : apush(append(new Constant(objectNull ))); break; duke@435: case Bytecodes::_iconst_m1 : ipush(append(new Constant(new IntConstant (-1)))); break; duke@435: case Bytecodes::_iconst_0 : ipush(append(new Constant(intZero ))); break; duke@435: case Bytecodes::_iconst_1 : ipush(append(new Constant(intOne ))); break; duke@435: case Bytecodes::_iconst_2 : ipush(append(new Constant(new IntConstant ( 2)))); break; duke@435: case Bytecodes::_iconst_3 : ipush(append(new Constant(new IntConstant ( 3)))); break; duke@435: case Bytecodes::_iconst_4 : ipush(append(new Constant(new IntConstant ( 4)))); break; duke@435: case Bytecodes::_iconst_5 : ipush(append(new Constant(new IntConstant ( 5)))); break; duke@435: case Bytecodes::_lconst_0 : lpush(append(new Constant(new LongConstant ( 0)))); break; duke@435: case Bytecodes::_lconst_1 : lpush(append(new Constant(new LongConstant ( 1)))); break; duke@435: case Bytecodes::_fconst_0 : fpush(append(new Constant(new FloatConstant ( 0)))); break; duke@435: case Bytecodes::_fconst_1 : fpush(append(new Constant(new FloatConstant ( 1)))); break; duke@435: case Bytecodes::_fconst_2 : fpush(append(new Constant(new FloatConstant ( 2)))); break; duke@435: case Bytecodes::_dconst_0 : dpush(append(new Constant(new DoubleConstant( 0)))); break; duke@435: case Bytecodes::_dconst_1 : dpush(append(new Constant(new DoubleConstant( 1)))); break; duke@435: case Bytecodes::_bipush : ipush(append(new Constant(new IntConstant(((signed char*)s.cur_bcp())[1])))); break; duke@435: case Bytecodes::_sipush : ipush(append(new Constant(new IntConstant((short)Bytes::get_Java_u2(s.cur_bcp()+1))))); break; duke@435: case Bytecodes::_ldc : // fall through duke@435: case Bytecodes::_ldc_w : // fall through duke@435: case Bytecodes::_ldc2_w : load_constant(); break; duke@435: case Bytecodes::_iload : load_local(intType , s.get_index()); break; duke@435: case Bytecodes::_lload : load_local(longType , s.get_index()); break; duke@435: case Bytecodes::_fload : load_local(floatType , s.get_index()); break; duke@435: case Bytecodes::_dload : load_local(doubleType , s.get_index()); break; duke@435: case Bytecodes::_aload : load_local(instanceType, s.get_index()); break; duke@435: case Bytecodes::_iload_0 : load_local(intType , 0); break; duke@435: case Bytecodes::_iload_1 : load_local(intType , 1); break; duke@435: case Bytecodes::_iload_2 : load_local(intType , 2); break; duke@435: case Bytecodes::_iload_3 : load_local(intType , 3); break; duke@435: case Bytecodes::_lload_0 : load_local(longType , 0); break; duke@435: case Bytecodes::_lload_1 : load_local(longType , 1); break; duke@435: case Bytecodes::_lload_2 : load_local(longType , 2); break; duke@435: case Bytecodes::_lload_3 : load_local(longType , 3); break; duke@435: case Bytecodes::_fload_0 : load_local(floatType , 0); break; duke@435: case Bytecodes::_fload_1 : load_local(floatType , 1); break; duke@435: case Bytecodes::_fload_2 : load_local(floatType , 2); break; duke@435: case Bytecodes::_fload_3 : load_local(floatType , 3); break; duke@435: case Bytecodes::_dload_0 : load_local(doubleType, 0); break; duke@435: case Bytecodes::_dload_1 : load_local(doubleType, 1); break; duke@435: case Bytecodes::_dload_2 : load_local(doubleType, 2); break; duke@435: case Bytecodes::_dload_3 : load_local(doubleType, 3); break; duke@435: case Bytecodes::_aload_0 : load_local(objectType, 0); break; duke@435: case Bytecodes::_aload_1 : load_local(objectType, 1); break; duke@435: case Bytecodes::_aload_2 : load_local(objectType, 2); break; duke@435: case Bytecodes::_aload_3 : load_local(objectType, 3); break; duke@435: case Bytecodes::_iaload : load_indexed(T_INT ); break; duke@435: case Bytecodes::_laload : load_indexed(T_LONG ); break; duke@435: case Bytecodes::_faload : load_indexed(T_FLOAT ); break; duke@435: case Bytecodes::_daload : load_indexed(T_DOUBLE); break; duke@435: case Bytecodes::_aaload : load_indexed(T_OBJECT); break; duke@435: case Bytecodes::_baload : load_indexed(T_BYTE ); break; duke@435: case Bytecodes::_caload : load_indexed(T_CHAR ); break; duke@435: case Bytecodes::_saload : load_indexed(T_SHORT ); break; duke@435: case Bytecodes::_istore : store_local(intType , s.get_index()); break; duke@435: case Bytecodes::_lstore : store_local(longType , s.get_index()); break; duke@435: case Bytecodes::_fstore : store_local(floatType , s.get_index()); break; duke@435: case Bytecodes::_dstore : store_local(doubleType, s.get_index()); break; duke@435: case Bytecodes::_astore : store_local(objectType, s.get_index()); break; duke@435: case Bytecodes::_istore_0 : store_local(intType , 0); break; duke@435: case Bytecodes::_istore_1 : store_local(intType , 1); break; duke@435: case Bytecodes::_istore_2 : store_local(intType , 2); break; duke@435: case Bytecodes::_istore_3 : store_local(intType , 3); break; duke@435: case Bytecodes::_lstore_0 : store_local(longType , 0); break; duke@435: case Bytecodes::_lstore_1 : store_local(longType , 1); break; duke@435: case Bytecodes::_lstore_2 : store_local(longType , 2); break; duke@435: case Bytecodes::_lstore_3 : store_local(longType , 3); break; duke@435: case Bytecodes::_fstore_0 : store_local(floatType , 0); break; duke@435: case Bytecodes::_fstore_1 : store_local(floatType , 1); break; duke@435: case Bytecodes::_fstore_2 : store_local(floatType , 2); break; duke@435: case Bytecodes::_fstore_3 : store_local(floatType , 3); break; duke@435: case Bytecodes::_dstore_0 : store_local(doubleType, 0); break; duke@435: case Bytecodes::_dstore_1 : store_local(doubleType, 1); break; duke@435: case Bytecodes::_dstore_2 : store_local(doubleType, 2); break; duke@435: case Bytecodes::_dstore_3 : store_local(doubleType, 3); break; duke@435: case Bytecodes::_astore_0 : store_local(objectType, 0); break; duke@435: case Bytecodes::_astore_1 : store_local(objectType, 1); break; duke@435: case Bytecodes::_astore_2 : store_local(objectType, 2); break; duke@435: case Bytecodes::_astore_3 : store_local(objectType, 3); break; duke@435: case Bytecodes::_iastore : store_indexed(T_INT ); break; duke@435: case Bytecodes::_lastore : store_indexed(T_LONG ); break; duke@435: case Bytecodes::_fastore : store_indexed(T_FLOAT ); break; duke@435: case Bytecodes::_dastore : store_indexed(T_DOUBLE); break; duke@435: case Bytecodes::_aastore : store_indexed(T_OBJECT); break; duke@435: case Bytecodes::_bastore : store_indexed(T_BYTE ); break; duke@435: case Bytecodes::_castore : store_indexed(T_CHAR ); break; duke@435: case Bytecodes::_sastore : store_indexed(T_SHORT ); break; duke@435: case Bytecodes::_pop : // fall through duke@435: case Bytecodes::_pop2 : // fall through duke@435: case Bytecodes::_dup : // fall through duke@435: case Bytecodes::_dup_x1 : // fall through duke@435: case Bytecodes::_dup_x2 : // fall through duke@435: case Bytecodes::_dup2 : // fall through duke@435: case Bytecodes::_dup2_x1 : // fall through duke@435: case Bytecodes::_dup2_x2 : // fall through duke@435: case Bytecodes::_swap : stack_op(code); break; duke@435: case Bytecodes::_iadd : arithmetic_op(intType , code); break; duke@435: case Bytecodes::_ladd : arithmetic_op(longType , code); break; duke@435: case Bytecodes::_fadd : arithmetic_op(floatType , code); break; duke@435: case Bytecodes::_dadd : arithmetic_op(doubleType, code); break; duke@435: case Bytecodes::_isub : arithmetic_op(intType , code); break; duke@435: case Bytecodes::_lsub : arithmetic_op(longType , code); break; duke@435: case Bytecodes::_fsub : arithmetic_op(floatType , code); break; duke@435: case Bytecodes::_dsub : arithmetic_op(doubleType, code); break; duke@435: case Bytecodes::_imul : arithmetic_op(intType , code); break; duke@435: case Bytecodes::_lmul : arithmetic_op(longType , code); break; duke@435: case Bytecodes::_fmul : arithmetic_op(floatType , code); break; duke@435: case Bytecodes::_dmul : arithmetic_op(doubleType, code); break; duke@435: case Bytecodes::_idiv : arithmetic_op(intType , code, lock_stack()); break; duke@435: case Bytecodes::_ldiv : arithmetic_op(longType , code, lock_stack()); break; duke@435: case Bytecodes::_fdiv : arithmetic_op(floatType , code); break; duke@435: case Bytecodes::_ddiv : arithmetic_op(doubleType, code); break; duke@435: case Bytecodes::_irem : arithmetic_op(intType , code, lock_stack()); break; duke@435: case Bytecodes::_lrem : arithmetic_op(longType , code, lock_stack()); break; duke@435: case Bytecodes::_frem : arithmetic_op(floatType , code); break; duke@435: case Bytecodes::_drem : arithmetic_op(doubleType, code); break; duke@435: case Bytecodes::_ineg : negate_op(intType ); break; duke@435: case Bytecodes::_lneg : negate_op(longType ); break; duke@435: case Bytecodes::_fneg : negate_op(floatType ); break; duke@435: case Bytecodes::_dneg : negate_op(doubleType); break; duke@435: case Bytecodes::_ishl : shift_op(intType , code); break; duke@435: case Bytecodes::_lshl : shift_op(longType, code); break; duke@435: case Bytecodes::_ishr : shift_op(intType , code); break; duke@435: case Bytecodes::_lshr : shift_op(longType, code); break; duke@435: case Bytecodes::_iushr : shift_op(intType , code); break; duke@435: case Bytecodes::_lushr : shift_op(longType, code); break; duke@435: case Bytecodes::_iand : logic_op(intType , code); break; duke@435: case Bytecodes::_land : logic_op(longType, code); break; duke@435: case Bytecodes::_ior : logic_op(intType , code); break; duke@435: case Bytecodes::_lor : logic_op(longType, code); break; duke@435: case Bytecodes::_ixor : logic_op(intType , code); break; duke@435: case Bytecodes::_lxor : logic_op(longType, code); break; duke@435: case Bytecodes::_iinc : increment(); break; duke@435: case Bytecodes::_i2l : convert(code, T_INT , T_LONG ); break; duke@435: case Bytecodes::_i2f : convert(code, T_INT , T_FLOAT ); break; duke@435: case Bytecodes::_i2d : convert(code, T_INT , T_DOUBLE); break; duke@435: case Bytecodes::_l2i : convert(code, T_LONG , T_INT ); break; duke@435: case Bytecodes::_l2f : convert(code, T_LONG , T_FLOAT ); break; duke@435: case Bytecodes::_l2d : convert(code, T_LONG , T_DOUBLE); break; duke@435: case Bytecodes::_f2i : convert(code, T_FLOAT , T_INT ); break; duke@435: case Bytecodes::_f2l : convert(code, T_FLOAT , T_LONG ); break; duke@435: case Bytecodes::_f2d : convert(code, T_FLOAT , T_DOUBLE); break; duke@435: case Bytecodes::_d2i : convert(code, T_DOUBLE, T_INT ); break; duke@435: case Bytecodes::_d2l : convert(code, T_DOUBLE, T_LONG ); break; duke@435: case Bytecodes::_d2f : convert(code, T_DOUBLE, T_FLOAT ); break; duke@435: case Bytecodes::_i2b : convert(code, T_INT , T_BYTE ); break; duke@435: case Bytecodes::_i2c : convert(code, T_INT , T_CHAR ); break; duke@435: case Bytecodes::_i2s : convert(code, T_INT , T_SHORT ); break; duke@435: case Bytecodes::_lcmp : compare_op(longType , code); break; duke@435: case Bytecodes::_fcmpl : compare_op(floatType , code); break; duke@435: case Bytecodes::_fcmpg : compare_op(floatType , code); break; duke@435: case Bytecodes::_dcmpl : compare_op(doubleType, code); break; duke@435: case Bytecodes::_dcmpg : compare_op(doubleType, code); break; duke@435: case Bytecodes::_ifeq : if_zero(intType , If::eql); break; duke@435: case Bytecodes::_ifne : if_zero(intType , If::neq); break; duke@435: case Bytecodes::_iflt : if_zero(intType , If::lss); break; duke@435: case Bytecodes::_ifge : if_zero(intType , If::geq); break; duke@435: case Bytecodes::_ifgt : if_zero(intType , If::gtr); break; duke@435: case Bytecodes::_ifle : if_zero(intType , If::leq); break; duke@435: case Bytecodes::_if_icmpeq : if_same(intType , If::eql); break; duke@435: case Bytecodes::_if_icmpne : if_same(intType , If::neq); break; duke@435: case Bytecodes::_if_icmplt : if_same(intType , If::lss); break; duke@435: case Bytecodes::_if_icmpge : if_same(intType , If::geq); break; duke@435: case Bytecodes::_if_icmpgt : if_same(intType , If::gtr); break; duke@435: case Bytecodes::_if_icmple : if_same(intType , If::leq); break; duke@435: case Bytecodes::_if_acmpeq : if_same(objectType, If::eql); break; duke@435: case Bytecodes::_if_acmpne : if_same(objectType, If::neq); break; duke@435: case Bytecodes::_goto : _goto(s.cur_bci(), s.get_dest()); break; duke@435: case Bytecodes::_jsr : jsr(s.get_dest()); break; duke@435: case Bytecodes::_ret : ret(s.get_index()); break; duke@435: case Bytecodes::_tableswitch : table_switch(); break; duke@435: case Bytecodes::_lookupswitch : lookup_switch(); break; duke@435: case Bytecodes::_ireturn : method_return(ipop()); break; duke@435: case Bytecodes::_lreturn : method_return(lpop()); break; duke@435: case Bytecodes::_freturn : method_return(fpop()); break; duke@435: case Bytecodes::_dreturn : method_return(dpop()); break; duke@435: case Bytecodes::_areturn : method_return(apop()); break; duke@435: case Bytecodes::_return : method_return(NULL ); break; duke@435: case Bytecodes::_getstatic : // fall through duke@435: case Bytecodes::_putstatic : // fall through duke@435: case Bytecodes::_getfield : // fall through duke@435: case Bytecodes::_putfield : access_field(code); break; duke@435: case Bytecodes::_invokevirtual : // fall through duke@435: case Bytecodes::_invokespecial : // fall through duke@435: case Bytecodes::_invokestatic : // fall through jrose@1161: case Bytecodes::_invokedynamic : // fall through duke@435: case Bytecodes::_invokeinterface: invoke(code); break; jrose@1920: case Bytecodes::_new : new_instance(s.get_index_u2()); break; duke@435: case Bytecodes::_newarray : new_type_array(); break; duke@435: case Bytecodes::_anewarray : new_object_array(); break; duke@435: case Bytecodes::_arraylength : ipush(append(new ArrayLength(apop(), lock_stack()))); break; duke@435: case Bytecodes::_athrow : throw_op(s.cur_bci()); break; jrose@1920: case Bytecodes::_checkcast : check_cast(s.get_index_u2()); break; jrose@1920: case Bytecodes::_instanceof : instance_of(s.get_index_u2()); break; duke@435: // Note: we do not have special handling for the monitorenter bytecode if DeoptC1 && DeoptOnAsyncException duke@435: case Bytecodes::_monitorenter : monitorenter(apop(), s.cur_bci()); break; duke@435: case Bytecodes::_monitorexit : monitorexit (apop(), s.cur_bci()); break; duke@435: case Bytecodes::_wide : ShouldNotReachHere(); break; duke@435: case Bytecodes::_multianewarray : new_multi_array(s.cur_bcp()[3]); break; duke@435: case Bytecodes::_ifnull : if_null(objectType, If::eql); break; duke@435: case Bytecodes::_ifnonnull : if_null(objectType, If::neq); break; duke@435: case Bytecodes::_goto_w : _goto(s.cur_bci(), s.get_far_dest()); break; duke@435: case Bytecodes::_jsr_w : jsr(s.get_far_dest()); break; duke@435: case Bytecodes::_breakpoint : BAILOUT_("concurrent setting of breakpoint", NULL); duke@435: default : ShouldNotReachHere(); break; duke@435: } duke@435: // save current bci to setup Goto at the end duke@435: prev_bci = s.cur_bci(); duke@435: } duke@435: CHECK_BAILOUT_(NULL); duke@435: // stop processing of this block (see try_inline_full) duke@435: if (_skip_block) { duke@435: _skip_block = false; duke@435: assert(_last && _last->as_BlockEnd(), ""); duke@435: return _last->as_BlockEnd(); duke@435: } duke@435: // if there are any, check if last instruction is a BlockEnd instruction duke@435: BlockEnd* end = last()->as_BlockEnd(); duke@435: if (end == NULL) { duke@435: // all blocks must end with a BlockEnd instruction => add a Goto duke@435: end = new Goto(block_at(s.cur_bci()), false); duke@435: _last = _last->set_next(end, prev_bci); duke@435: } duke@435: assert(end == last()->as_BlockEnd(), "inconsistency"); duke@435: duke@435: // if the method terminates, we don't need the stack anymore duke@435: if (end->as_Return() != NULL) { duke@435: state()->clear_stack(); duke@435: } else if (end->as_Throw() != NULL) { duke@435: // May have exception handler in caller scopes duke@435: state()->truncate_stack(scope()->lock_stack_size()); duke@435: } duke@435: duke@435: // connect to begin & set state duke@435: // NOTE that inlining may have changed the block we are parsing duke@435: block()->set_end(end); duke@435: end->set_state(state()); duke@435: // propagate state duke@435: for (int i = end->number_of_sux() - 1; i >= 0; i--) { duke@435: BlockBegin* sux = end->sux_at(i); duke@435: assert(sux->is_predecessor(block()), "predecessor missing"); duke@435: // be careful, bailout if bytecodes are strange duke@435: if (!sux->try_merge(state())) BAILOUT_("block join failed", NULL); duke@435: scope_data()->add_to_work_list(end->sux_at(i)); duke@435: } duke@435: duke@435: scope_data()->set_stream(NULL); duke@435: duke@435: // done duke@435: return end; duke@435: } duke@435: duke@435: duke@435: void GraphBuilder::iterate_all_blocks(bool start_in_current_block_for_inlining) { duke@435: do { duke@435: if (start_in_current_block_for_inlining && !bailed_out()) { duke@435: iterate_bytecodes_for_block(0); duke@435: start_in_current_block_for_inlining = false; duke@435: } else { duke@435: BlockBegin* b; duke@435: while ((b = scope_data()->remove_from_work_list()) != NULL) { duke@435: if (!b->is_set(BlockBegin::was_visited_flag)) { duke@435: if (b->is_set(BlockBegin::osr_entry_flag)) { duke@435: // we're about to parse the osr entry block, so make sure duke@435: // we setup the OSR edge leading into this block so that duke@435: // Phis get setup correctly. duke@435: setup_osr_entry_block(); duke@435: // this is no longer the osr entry block, so clear it. duke@435: b->clear(BlockBegin::osr_entry_flag); duke@435: } duke@435: b->set(BlockBegin::was_visited_flag); duke@435: connect_to_end(b); duke@435: } duke@435: } duke@435: } duke@435: } while (!bailed_out() && !scope_data()->is_work_list_empty()); duke@435: } duke@435: duke@435: duke@435: bool GraphBuilder::_is_initialized = false; duke@435: bool GraphBuilder::_can_trap [Bytecodes::number_of_java_codes]; duke@435: bool GraphBuilder::_is_async[Bytecodes::number_of_java_codes]; duke@435: duke@435: void GraphBuilder::initialize() { duke@435: // make sure initialization happens only once (need a duke@435: // lock here, if we allow the compiler to be re-entrant) duke@435: if (is_initialized()) return; duke@435: _is_initialized = true; duke@435: duke@435: // the following bytecodes are assumed to potentially duke@435: // throw exceptions in compiled code - note that e.g. duke@435: // monitorexit & the return bytecodes do not throw duke@435: // exceptions since monitor pairing proved that they duke@435: // succeed (if monitor pairing succeeded) duke@435: Bytecodes::Code can_trap_list[] = duke@435: { Bytecodes::_ldc duke@435: , Bytecodes::_ldc_w duke@435: , Bytecodes::_ldc2_w duke@435: , Bytecodes::_iaload duke@435: , Bytecodes::_laload duke@435: , Bytecodes::_faload duke@435: , Bytecodes::_daload duke@435: , Bytecodes::_aaload duke@435: , Bytecodes::_baload duke@435: , Bytecodes::_caload duke@435: , Bytecodes::_saload duke@435: , Bytecodes::_iastore duke@435: , Bytecodes::_lastore duke@435: , Bytecodes::_fastore duke@435: , Bytecodes::_dastore duke@435: , Bytecodes::_aastore duke@435: , Bytecodes::_bastore duke@435: , Bytecodes::_castore duke@435: , Bytecodes::_sastore duke@435: , Bytecodes::_idiv duke@435: , Bytecodes::_ldiv duke@435: , Bytecodes::_irem duke@435: , Bytecodes::_lrem duke@435: , Bytecodes::_getstatic duke@435: , Bytecodes::_putstatic duke@435: , Bytecodes::_getfield duke@435: , Bytecodes::_putfield duke@435: , Bytecodes::_invokevirtual duke@435: , Bytecodes::_invokespecial duke@435: , Bytecodes::_invokestatic jrose@1161: , Bytecodes::_invokedynamic duke@435: , Bytecodes::_invokeinterface duke@435: , Bytecodes::_new duke@435: , Bytecodes::_newarray duke@435: , Bytecodes::_anewarray duke@435: , Bytecodes::_arraylength duke@435: , Bytecodes::_athrow duke@435: , Bytecodes::_checkcast duke@435: , Bytecodes::_instanceof duke@435: , Bytecodes::_monitorenter duke@435: , Bytecodes::_multianewarray duke@435: }; duke@435: duke@435: // the following bytecodes are assumed to potentially duke@435: // throw asynchronous exceptions in compiled code due duke@435: // to safepoints (note: these entries could be merged duke@435: // with the can_trap_list - however, we need to know duke@435: // which ones are asynchronous for now - see also the duke@435: // comment in GraphBuilder::handle_exception) duke@435: Bytecodes::Code is_async_list[] = duke@435: { Bytecodes::_ifeq duke@435: , Bytecodes::_ifne duke@435: , Bytecodes::_iflt duke@435: , Bytecodes::_ifge duke@435: , Bytecodes::_ifgt duke@435: , Bytecodes::_ifle duke@435: , Bytecodes::_if_icmpeq duke@435: , Bytecodes::_if_icmpne duke@435: , Bytecodes::_if_icmplt duke@435: , Bytecodes::_if_icmpge duke@435: , Bytecodes::_if_icmpgt duke@435: , Bytecodes::_if_icmple duke@435: , Bytecodes::_if_acmpeq duke@435: , Bytecodes::_if_acmpne duke@435: , Bytecodes::_goto duke@435: , Bytecodes::_jsr duke@435: , Bytecodes::_ret duke@435: , Bytecodes::_tableswitch duke@435: , Bytecodes::_lookupswitch duke@435: , Bytecodes::_ireturn duke@435: , Bytecodes::_lreturn duke@435: , Bytecodes::_freturn duke@435: , Bytecodes::_dreturn duke@435: , Bytecodes::_areturn duke@435: , Bytecodes::_return duke@435: , Bytecodes::_ifnull duke@435: , Bytecodes::_ifnonnull duke@435: , Bytecodes::_goto_w duke@435: , Bytecodes::_jsr_w duke@435: }; duke@435: duke@435: // inititialize trap tables duke@435: for (int i = 0; i < Bytecodes::number_of_java_codes; i++) { duke@435: _can_trap[i] = false; duke@435: _is_async[i] = false; duke@435: } duke@435: // set standard trap info duke@435: for (uint j = 0; j < ARRAY_SIZE(can_trap_list); j++) { duke@435: _can_trap[can_trap_list[j]] = true; duke@435: } duke@435: duke@435: // We now deoptimize if an asynchronous exception is thrown. This duke@435: // considerably cleans up corner case issues related to javac's duke@435: // incorrect exception handler ranges for async exceptions and duke@435: // allows us to precisely analyze the types of exceptions from duke@435: // certain bytecodes. duke@435: if (!(DeoptC1 && DeoptOnAsyncException)) { duke@435: // set asynchronous trap info duke@435: for (uint k = 0; k < ARRAY_SIZE(is_async_list); k++) { duke@435: assert(!_can_trap[is_async_list[k]], "can_trap_list and is_async_list should be disjoint"); duke@435: _can_trap[is_async_list[k]] = true; duke@435: _is_async[is_async_list[k]] = true; duke@435: } duke@435: } duke@435: } duke@435: duke@435: duke@435: BlockBegin* GraphBuilder::header_block(BlockBegin* entry, BlockBegin::Flag f, ValueStack* state) { duke@435: assert(entry->is_set(f), "entry/flag mismatch"); duke@435: // create header block duke@435: BlockBegin* h = new BlockBegin(entry->bci()); duke@435: h->set_depth_first_number(0); duke@435: duke@435: Value l = h; duke@435: if (profile_branches()) { duke@435: // Increment the invocation count on entry to the method. We duke@435: // can't use profile_invocation here because append isn't setup to duke@435: // work properly at this point. The instruction have to be duke@435: // appended to the instruction stream by hand. duke@435: Value m = new Constant(new ObjectConstant(compilation()->method())); duke@435: h->set_next(m, 0); duke@435: Value p = new ProfileCounter(m, methodOopDesc::interpreter_invocation_counter_offset_in_bytes(), 1); duke@435: m->set_next(p, 0); duke@435: l = p; duke@435: } duke@435: duke@435: BlockEnd* g = new Goto(entry, false); duke@435: l->set_next(g, entry->bci()); duke@435: h->set_end(g); duke@435: h->set(f); duke@435: // setup header block end state duke@435: ValueStack* s = state->copy(); // can use copy since stack is empty (=> no phis) duke@435: assert(s->stack_is_empty(), "must have empty stack at entry point"); duke@435: g->set_state(s); duke@435: return h; duke@435: } duke@435: duke@435: duke@435: duke@435: BlockBegin* GraphBuilder::setup_start_block(int osr_bci, BlockBegin* std_entry, BlockBegin* osr_entry, ValueStack* state) { duke@435: BlockBegin* start = new BlockBegin(0); duke@435: duke@435: // This code eliminates the empty start block at the beginning of duke@435: // each method. Previously, each method started with the duke@435: // start-block created below, and this block was followed by the duke@435: // header block that was always empty. This header block is only duke@435: // necesary if std_entry is also a backward branch target because duke@435: // then phi functions may be necessary in the header block. It's duke@435: // also necessary when profiling so that there's a single block that duke@435: // can increment the interpreter_invocation_count. duke@435: BlockBegin* new_header_block; duke@435: if (std_entry->number_of_preds() == 0 && !profile_branches()) { duke@435: new_header_block = std_entry; duke@435: } else { duke@435: new_header_block = header_block(std_entry, BlockBegin::std_entry_flag, state); duke@435: } duke@435: duke@435: // setup start block (root for the IR graph) duke@435: Base* base = duke@435: new Base( duke@435: new_header_block, duke@435: osr_entry duke@435: ); duke@435: start->set_next(base, 0); duke@435: start->set_end(base); duke@435: // create & setup state for start block duke@435: start->set_state(state->copy()); duke@435: base->set_state(state->copy()); duke@435: duke@435: if (base->std_entry()->state() == NULL) { duke@435: // setup states for header blocks duke@435: base->std_entry()->merge(state); duke@435: } duke@435: duke@435: assert(base->std_entry()->state() != NULL, ""); duke@435: return start; duke@435: } duke@435: duke@435: duke@435: void GraphBuilder::setup_osr_entry_block() { duke@435: assert(compilation()->is_osr_compile(), "only for osrs"); duke@435: duke@435: int osr_bci = compilation()->osr_bci(); duke@435: ciBytecodeStream s(method()); duke@435: s.reset_to_bci(osr_bci); duke@435: s.next(); duke@435: scope_data()->set_stream(&s); duke@435: duke@435: // create a new block to be the osr setup code duke@435: _osr_entry = new BlockBegin(osr_bci); duke@435: _osr_entry->set(BlockBegin::osr_entry_flag); duke@435: _osr_entry->set_depth_first_number(0); duke@435: BlockBegin* target = bci2block()->at(osr_bci); duke@435: assert(target != NULL && target->is_set(BlockBegin::osr_entry_flag), "must be there"); duke@435: // the osr entry has no values for locals duke@435: ValueStack* state = target->state()->copy(); duke@435: _osr_entry->set_state(state); duke@435: duke@435: kill_all(); duke@435: _block = _osr_entry; duke@435: _state = _osr_entry->state()->copy(); duke@435: _last = _osr_entry; duke@435: Value e = append(new OsrEntry()); duke@435: e->set_needs_null_check(false); duke@435: duke@435: // OSR buffer is duke@435: // duke@435: // locals[nlocals-1..0] duke@435: // monitors[number_of_locks-1..0] duke@435: // duke@435: // locals is a direct copy of the interpreter frame so in the osr buffer duke@435: // so first slot in the local array is the last local from the interpreter duke@435: // and last slot is local[0] (receiver) from the interpreter duke@435: // duke@435: // Similarly with locks. The first lock slot in the osr buffer is the nth lock duke@435: // from the interpreter frame, the nth lock slot in the osr buffer is 0th lock duke@435: // in the interpreter frame (the method lock if a sync method) duke@435: duke@435: // Initialize monitors in the compiled activation. duke@435: duke@435: int index; duke@435: Value local; duke@435: duke@435: // find all the locals that the interpreter thinks contain live oops duke@435: const BitMap live_oops = method()->live_local_oops_at_bci(osr_bci); duke@435: duke@435: // compute the offset into the locals so that we can treat the buffer duke@435: // as if the locals were still in the interpreter frame duke@435: int locals_offset = BytesPerWord * (method()->max_locals() - 1); duke@435: for_each_local_value(state, index, local) { duke@435: int offset = locals_offset - (index + local->type()->size() - 1) * BytesPerWord; duke@435: Value get; duke@435: if (local->type()->is_object_kind() && !live_oops.at(index)) { duke@435: // The interpreter thinks this local is dead but the compiler duke@435: // doesn't so pretend that the interpreter passed in null. duke@435: get = append(new Constant(objectNull)); duke@435: } else { duke@435: get = append(new UnsafeGetRaw(as_BasicType(local->type()), e, duke@435: append(new Constant(new IntConstant(offset))), duke@435: 0, duke@435: true)); duke@435: } duke@435: _state->store_local(index, get); duke@435: } duke@435: duke@435: // the storage for the OSR buffer is freed manually in the LIRGenerator. duke@435: duke@435: assert(state->caller_state() == NULL, "should be top scope"); duke@435: state->clear_locals(); duke@435: Goto* g = new Goto(target, false); duke@435: g->set_state(_state->copy()); duke@435: append(g); duke@435: _osr_entry->set_end(g); duke@435: target->merge(_osr_entry->end()->state()); duke@435: duke@435: scope_data()->set_stream(NULL); duke@435: } duke@435: duke@435: duke@435: ValueStack* GraphBuilder::state_at_entry() { duke@435: ValueStack* state = new ValueStack(scope(), method()->max_locals(), method()->max_stack()); duke@435: duke@435: // Set up locals for receiver duke@435: int idx = 0; duke@435: if (!method()->is_static()) { duke@435: // we should always see the receiver duke@435: state->store_local(idx, new Local(objectType, idx)); duke@435: idx = 1; duke@435: } duke@435: duke@435: // Set up locals for incoming arguments duke@435: ciSignature* sig = method()->signature(); duke@435: for (int i = 0; i < sig->count(); i++) { duke@435: ciType* type = sig->type_at(i); duke@435: BasicType basic_type = type->basic_type(); duke@435: // don't allow T_ARRAY to propagate into locals types duke@435: if (basic_type == T_ARRAY) basic_type = T_OBJECT; duke@435: ValueType* vt = as_ValueType(basic_type); duke@435: state->store_local(idx, new Local(vt, idx)); duke@435: idx += type->size(); duke@435: } duke@435: duke@435: // lock synchronized method duke@435: if (method()->is_synchronized()) { duke@435: state->lock(scope(), NULL); duke@435: } duke@435: duke@435: return state; duke@435: } duke@435: duke@435: duke@435: GraphBuilder::GraphBuilder(Compilation* compilation, IRScope* scope) duke@435: : _scope_data(NULL) duke@435: , _exception_state(NULL) duke@435: , _instruction_count(0) duke@435: , _osr_entry(NULL) duke@435: , _memory(new MemoryBuffer()) duke@435: , _compilation(compilation) duke@435: , _inline_bailout_msg(NULL) duke@435: { duke@435: int osr_bci = compilation->osr_bci(); duke@435: duke@435: // determine entry points and bci2block mapping duke@435: BlockListBuilder blm(compilation, scope, osr_bci); duke@435: CHECK_BAILOUT(); duke@435: duke@435: BlockList* bci2block = blm.bci2block(); duke@435: BlockBegin* start_block = bci2block->at(0); duke@435: duke@435: assert(is_initialized(), "GraphBuilder must have been initialized"); duke@435: push_root_scope(scope, bci2block, start_block); duke@435: duke@435: // setup state for std entry duke@435: _initial_state = state_at_entry(); duke@435: start_block->merge(_initial_state); duke@435: duke@435: // complete graph duke@435: _vmap = new ValueMap(); duke@435: scope->compute_lock_stack_size(); duke@435: switch (scope->method()->intrinsic_id()) { duke@435: case vmIntrinsics::_dabs : // fall through duke@435: case vmIntrinsics::_dsqrt : // fall through duke@435: case vmIntrinsics::_dsin : // fall through duke@435: case vmIntrinsics::_dcos : // fall through duke@435: case vmIntrinsics::_dtan : // fall through duke@435: case vmIntrinsics::_dlog : // fall through duke@435: case vmIntrinsics::_dlog10 : // fall through duke@435: { duke@435: // Compiles where the root method is an intrinsic need a special duke@435: // compilation environment because the bytecodes for the method duke@435: // shouldn't be parsed during the compilation, only the special duke@435: // Intrinsic node should be emitted. If this isn't done the the duke@435: // code for the inlined version will be different than the root duke@435: // compiled version which could lead to monotonicity problems on duke@435: // intel. duke@435: duke@435: // Set up a stream so that appending instructions works properly. duke@435: ciBytecodeStream s(scope->method()); duke@435: s.reset_to_bci(0); duke@435: scope_data()->set_stream(&s); duke@435: s.next(); duke@435: duke@435: // setup the initial block state duke@435: _block = start_block; duke@435: _state = start_block->state()->copy(); duke@435: _last = start_block; duke@435: load_local(doubleType, 0); duke@435: duke@435: // Emit the intrinsic node. duke@435: bool result = try_inline_intrinsics(scope->method()); duke@435: if (!result) BAILOUT("failed to inline intrinsic"); duke@435: method_return(dpop()); duke@435: duke@435: // connect the begin and end blocks and we're all done. duke@435: BlockEnd* end = last()->as_BlockEnd(); duke@435: block()->set_end(end); duke@435: end->set_state(state()); duke@435: break; duke@435: } duke@435: default: duke@435: scope_data()->add_to_work_list(start_block); duke@435: iterate_all_blocks(); duke@435: break; duke@435: } duke@435: CHECK_BAILOUT(); duke@435: duke@435: _start = setup_start_block(osr_bci, start_block, _osr_entry, _initial_state); duke@435: duke@435: eliminate_redundant_phis(_start); duke@435: duke@435: NOT_PRODUCT(if (PrintValueNumbering && Verbose) print_stats()); duke@435: // for osr compile, bailout if some requirements are not fulfilled duke@435: if (osr_bci != -1) { duke@435: BlockBegin* osr_block = blm.bci2block()->at(osr_bci); duke@435: assert(osr_block->is_set(BlockBegin::was_visited_flag),"osr entry must have been visited for osr compile"); duke@435: duke@435: // check if osr entry point has empty stack - we cannot handle non-empty stacks at osr entry points duke@435: if (!osr_block->state()->stack_is_empty()) { duke@435: BAILOUT("stack not empty at OSR entry point"); duke@435: } duke@435: } duke@435: #ifndef PRODUCT duke@435: if (PrintCompilation && Verbose) tty->print_cr("Created %d Instructions", _instruction_count); duke@435: #endif duke@435: } duke@435: duke@435: duke@435: ValueStack* GraphBuilder::lock_stack() { duke@435: // return a new ValueStack representing just the current lock stack duke@435: // (for debug info at safepoints in exception throwing or handling) duke@435: ValueStack* new_stack = state()->copy_locks(); duke@435: return new_stack; duke@435: } duke@435: duke@435: duke@435: int GraphBuilder::recursive_inline_level(ciMethod* cur_callee) const { duke@435: int recur_level = 0; duke@435: for (IRScope* s = scope(); s != NULL; s = s->caller()) { duke@435: if (s->method() == cur_callee) { duke@435: ++recur_level; duke@435: } duke@435: } duke@435: return recur_level; duke@435: } duke@435: duke@435: duke@435: bool GraphBuilder::try_inline(ciMethod* callee, bool holder_known) { duke@435: // Clear out any existing inline bailout condition duke@435: clear_inline_bailout(); duke@435: duke@435: if (callee->should_exclude()) { duke@435: // callee is excluded duke@435: INLINE_BAILOUT("excluded by CompilerOracle") duke@435: } else if (!callee->can_be_compiled()) { duke@435: // callee is not compilable (prob. has breakpoints) duke@435: INLINE_BAILOUT("not compilable") duke@435: } else if (callee->intrinsic_id() != vmIntrinsics::_none && try_inline_intrinsics(callee)) { duke@435: // intrinsics can be native or not duke@435: return true; duke@435: } else if (callee->is_native()) { duke@435: // non-intrinsic natives cannot be inlined duke@435: INLINE_BAILOUT("non-intrinsic native") duke@435: } else if (callee->is_abstract()) { duke@435: INLINE_BAILOUT("abstract") duke@435: } else { duke@435: return try_inline_full(callee, holder_known); duke@435: } duke@435: } duke@435: duke@435: duke@435: bool GraphBuilder::try_inline_intrinsics(ciMethod* callee) { duke@435: if (!InlineNatives ) INLINE_BAILOUT("intrinsic method inlining disabled"); never@1895: if (callee->is_synchronized()) { never@1895: // We don't currently support any synchronized intrinsics never@1895: return false; never@1895: } never@1895: duke@435: // callee seems like a good candidate duke@435: // determine id duke@435: bool preserves_state = false; duke@435: bool cantrap = true; duke@435: vmIntrinsics::ID id = callee->intrinsic_id(); duke@435: switch (id) { duke@435: case vmIntrinsics::_arraycopy : duke@435: if (!InlineArrayCopy) return false; duke@435: break; duke@435: duke@435: case vmIntrinsics::_currentTimeMillis: duke@435: case vmIntrinsics::_nanoTime: duke@435: preserves_state = true; duke@435: cantrap = false; duke@435: break; duke@435: duke@435: case vmIntrinsics::_floatToRawIntBits : duke@435: case vmIntrinsics::_intBitsToFloat : duke@435: case vmIntrinsics::_doubleToRawLongBits : duke@435: case vmIntrinsics::_longBitsToDouble : duke@435: if (!InlineMathNatives) return false; duke@435: preserves_state = true; duke@435: cantrap = false; duke@435: break; duke@435: duke@435: case vmIntrinsics::_getClass : duke@435: if (!InlineClassNatives) return false; duke@435: preserves_state = true; duke@435: break; duke@435: duke@435: case vmIntrinsics::_currentThread : duke@435: if (!InlineThreadNatives) return false; duke@435: preserves_state = true; duke@435: cantrap = false; duke@435: break; duke@435: duke@435: case vmIntrinsics::_dabs : // fall through duke@435: case vmIntrinsics::_dsqrt : // fall through duke@435: case vmIntrinsics::_dsin : // fall through duke@435: case vmIntrinsics::_dcos : // fall through duke@435: case vmIntrinsics::_dtan : // fall through duke@435: case vmIntrinsics::_dlog : // fall through duke@435: case vmIntrinsics::_dlog10 : // fall through duke@435: if (!InlineMathNatives) return false; duke@435: cantrap = false; duke@435: preserves_state = true; duke@435: break; duke@435: duke@435: // sun/misc/AtomicLong.attemptUpdate duke@435: case vmIntrinsics::_attemptUpdate : duke@435: if (!VM_Version::supports_cx8()) return false; duke@435: if (!InlineAtomicLong) return false; duke@435: preserves_state = true; duke@435: break; duke@435: duke@435: // Use special nodes for Unsafe instructions so we can more easily duke@435: // perform an address-mode optimization on the raw variants duke@435: case vmIntrinsics::_getObject : return append_unsafe_get_obj(callee, T_OBJECT, false); duke@435: case vmIntrinsics::_getBoolean: return append_unsafe_get_obj(callee, T_BOOLEAN, false); duke@435: case vmIntrinsics::_getByte : return append_unsafe_get_obj(callee, T_BYTE, false); duke@435: case vmIntrinsics::_getShort : return append_unsafe_get_obj(callee, T_SHORT, false); duke@435: case vmIntrinsics::_getChar : return append_unsafe_get_obj(callee, T_CHAR, false); duke@435: case vmIntrinsics::_getInt : return append_unsafe_get_obj(callee, T_INT, false); duke@435: case vmIntrinsics::_getLong : return append_unsafe_get_obj(callee, T_LONG, false); duke@435: case vmIntrinsics::_getFloat : return append_unsafe_get_obj(callee, T_FLOAT, false); duke@435: case vmIntrinsics::_getDouble : return append_unsafe_get_obj(callee, T_DOUBLE, false); duke@435: duke@435: case vmIntrinsics::_putObject : return append_unsafe_put_obj(callee, T_OBJECT, false); duke@435: case vmIntrinsics::_putBoolean: return append_unsafe_put_obj(callee, T_BOOLEAN, false); duke@435: case vmIntrinsics::_putByte : return append_unsafe_put_obj(callee, T_BYTE, false); duke@435: case vmIntrinsics::_putShort : return append_unsafe_put_obj(callee, T_SHORT, false); duke@435: case vmIntrinsics::_putChar : return append_unsafe_put_obj(callee, T_CHAR, false); duke@435: case vmIntrinsics::_putInt : return append_unsafe_put_obj(callee, T_INT, false); duke@435: case vmIntrinsics::_putLong : return append_unsafe_put_obj(callee, T_LONG, false); duke@435: case vmIntrinsics::_putFloat : return append_unsafe_put_obj(callee, T_FLOAT, false); duke@435: case vmIntrinsics::_putDouble : return append_unsafe_put_obj(callee, T_DOUBLE, false); duke@435: duke@435: case vmIntrinsics::_getObjectVolatile : return append_unsafe_get_obj(callee, T_OBJECT, true); duke@435: case vmIntrinsics::_getBooleanVolatile: return append_unsafe_get_obj(callee, T_BOOLEAN, true); duke@435: case vmIntrinsics::_getByteVolatile : return append_unsafe_get_obj(callee, T_BYTE, true); duke@435: case vmIntrinsics::_getShortVolatile : return append_unsafe_get_obj(callee, T_SHORT, true); duke@435: case vmIntrinsics::_getCharVolatile : return append_unsafe_get_obj(callee, T_CHAR, true); duke@435: case vmIntrinsics::_getIntVolatile : return append_unsafe_get_obj(callee, T_INT, true); duke@435: case vmIntrinsics::_getLongVolatile : return append_unsafe_get_obj(callee, T_LONG, true); duke@435: case vmIntrinsics::_getFloatVolatile : return append_unsafe_get_obj(callee, T_FLOAT, true); duke@435: case vmIntrinsics::_getDoubleVolatile : return append_unsafe_get_obj(callee, T_DOUBLE, true); duke@435: duke@435: case vmIntrinsics::_putObjectVolatile : return append_unsafe_put_obj(callee, T_OBJECT, true); duke@435: case vmIntrinsics::_putBooleanVolatile: return append_unsafe_put_obj(callee, T_BOOLEAN, true); duke@435: case vmIntrinsics::_putByteVolatile : return append_unsafe_put_obj(callee, T_BYTE, true); duke@435: case vmIntrinsics::_putShortVolatile : return append_unsafe_put_obj(callee, T_SHORT, true); duke@435: case vmIntrinsics::_putCharVolatile : return append_unsafe_put_obj(callee, T_CHAR, true); duke@435: case vmIntrinsics::_putIntVolatile : return append_unsafe_put_obj(callee, T_INT, true); duke@435: case vmIntrinsics::_putLongVolatile : return append_unsafe_put_obj(callee, T_LONG, true); duke@435: case vmIntrinsics::_putFloatVolatile : return append_unsafe_put_obj(callee, T_FLOAT, true); duke@435: case vmIntrinsics::_putDoubleVolatile : return append_unsafe_put_obj(callee, T_DOUBLE, true); duke@435: duke@435: case vmIntrinsics::_getByte_raw : return append_unsafe_get_raw(callee, T_BYTE); duke@435: case vmIntrinsics::_getShort_raw : return append_unsafe_get_raw(callee, T_SHORT); duke@435: case vmIntrinsics::_getChar_raw : return append_unsafe_get_raw(callee, T_CHAR); duke@435: case vmIntrinsics::_getInt_raw : return append_unsafe_get_raw(callee, T_INT); duke@435: case vmIntrinsics::_getLong_raw : return append_unsafe_get_raw(callee, T_LONG); duke@435: case vmIntrinsics::_getFloat_raw : return append_unsafe_get_raw(callee, T_FLOAT); duke@435: case vmIntrinsics::_getDouble_raw : return append_unsafe_get_raw(callee, T_DOUBLE); duke@435: duke@435: case vmIntrinsics::_putByte_raw : return append_unsafe_put_raw(callee, T_BYTE); duke@435: case vmIntrinsics::_putShort_raw : return append_unsafe_put_raw(callee, T_SHORT); duke@435: case vmIntrinsics::_putChar_raw : return append_unsafe_put_raw(callee, T_CHAR); duke@435: case vmIntrinsics::_putInt_raw : return append_unsafe_put_raw(callee, T_INT); duke@435: case vmIntrinsics::_putLong_raw : return append_unsafe_put_raw(callee, T_LONG); duke@435: case vmIntrinsics::_putFloat_raw : return append_unsafe_put_raw(callee, T_FLOAT); duke@435: case vmIntrinsics::_putDouble_raw : return append_unsafe_put_raw(callee, T_DOUBLE); duke@435: duke@435: case vmIntrinsics::_prefetchRead : return append_unsafe_prefetch(callee, false, false); duke@435: case vmIntrinsics::_prefetchWrite : return append_unsafe_prefetch(callee, false, true); duke@435: case vmIntrinsics::_prefetchReadStatic : return append_unsafe_prefetch(callee, true, false); duke@435: case vmIntrinsics::_prefetchWriteStatic : return append_unsafe_prefetch(callee, true, true); duke@435: duke@435: case vmIntrinsics::_checkIndex : duke@435: if (!InlineNIOCheckIndex) return false; duke@435: preserves_state = true; duke@435: break; duke@435: case vmIntrinsics::_putOrderedObject : return append_unsafe_put_obj(callee, T_OBJECT, true); duke@435: case vmIntrinsics::_putOrderedInt : return append_unsafe_put_obj(callee, T_INT, true); duke@435: case vmIntrinsics::_putOrderedLong : return append_unsafe_put_obj(callee, T_LONG, true); duke@435: duke@435: case vmIntrinsics::_compareAndSwapLong: duke@435: if (!VM_Version::supports_cx8()) return false; duke@435: // fall through duke@435: case vmIntrinsics::_compareAndSwapInt: duke@435: case vmIntrinsics::_compareAndSwapObject: duke@435: append_unsafe_CAS(callee); duke@435: return true; duke@435: duke@435: default : return false; // do not inline duke@435: } duke@435: // create intrinsic node duke@435: const bool has_receiver = !callee->is_static(); duke@435: ValueType* result_type = as_ValueType(callee->return_type()); duke@435: duke@435: Values* args = state()->pop_arguments(callee->arg_size()); duke@435: ValueStack* locks = lock_stack(); duke@435: if (profile_calls()) { duke@435: // Don't profile in the special case where the root method duke@435: // is the intrinsic duke@435: if (callee != method()) { duke@435: Value recv = NULL; duke@435: if (has_receiver) { duke@435: recv = args->at(0); duke@435: null_check(recv); duke@435: } duke@435: profile_call(recv, NULL); duke@435: } duke@435: } duke@435: duke@435: Intrinsic* result = new Intrinsic(result_type, id, args, has_receiver, lock_stack(), duke@435: preserves_state, cantrap); duke@435: // append instruction & push result duke@435: Value value = append_split(result); duke@435: if (result_type != voidType) push(result_type, value); duke@435: duke@435: #ifndef PRODUCT duke@435: // printing duke@435: if (PrintInlining) { duke@435: print_inline_result(callee, true); duke@435: } duke@435: #endif duke@435: duke@435: // done duke@435: return true; duke@435: } duke@435: duke@435: duke@435: bool GraphBuilder::try_inline_jsr(int jsr_dest_bci) { duke@435: // Introduce a new callee continuation point - all Ret instructions duke@435: // will be replaced with Gotos to this point. duke@435: BlockBegin* cont = block_at(next_bci()); duke@435: assert(cont != NULL, "continuation must exist (BlockListBuilder starts a new block after a jsr"); duke@435: duke@435: // Note: can not assign state to continuation yet, as we have to duke@435: // pick up the state from the Ret instructions. duke@435: duke@435: // Push callee scope duke@435: push_scope_for_jsr(cont, jsr_dest_bci); duke@435: duke@435: // Temporarily set up bytecode stream so we can append instructions duke@435: // (only using the bci of this stream) duke@435: scope_data()->set_stream(scope_data()->parent()->stream()); duke@435: duke@435: BlockBegin* jsr_start_block = block_at(jsr_dest_bci); duke@435: assert(jsr_start_block != NULL, "jsr start block must exist"); duke@435: assert(!jsr_start_block->is_set(BlockBegin::was_visited_flag), "should not have visited jsr yet"); duke@435: Goto* goto_sub = new Goto(jsr_start_block, false); duke@435: goto_sub->set_state(state()); duke@435: // Must copy state to avoid wrong sharing when parsing bytecodes duke@435: assert(jsr_start_block->state() == NULL, "should have fresh jsr starting block"); duke@435: jsr_start_block->set_state(state()->copy()); duke@435: append(goto_sub); duke@435: _block->set_end(goto_sub); duke@435: _last = _block = jsr_start_block; duke@435: duke@435: // Clear out bytecode stream duke@435: scope_data()->set_stream(NULL); duke@435: duke@435: scope_data()->add_to_work_list(jsr_start_block); duke@435: duke@435: // Ready to resume parsing in subroutine duke@435: iterate_all_blocks(); duke@435: duke@435: // If we bailed out during parsing, return immediately (this is bad news) duke@435: CHECK_BAILOUT_(false); duke@435: duke@435: // Detect whether the continuation can actually be reached. If not, duke@435: // it has not had state set by the join() operations in duke@435: // iterate_bytecodes_for_block()/ret() and we should not touch the duke@435: // iteration state. The calling activation of duke@435: // iterate_bytecodes_for_block will then complete normally. duke@435: if (cont->state() != NULL) { duke@435: if (!cont->is_set(BlockBegin::was_visited_flag)) { duke@435: // add continuation to work list instead of parsing it immediately duke@435: scope_data()->parent()->add_to_work_list(cont); duke@435: } duke@435: } duke@435: duke@435: assert(jsr_continuation() == cont, "continuation must not have changed"); duke@435: assert(!jsr_continuation()->is_set(BlockBegin::was_visited_flag) || duke@435: jsr_continuation()->is_set(BlockBegin::parser_loop_header_flag), duke@435: "continuation can only be visited in case of backward branches"); duke@435: assert(_last && _last->as_BlockEnd(), "block must have end"); duke@435: duke@435: // continuation is in work list, so end iteration of current block duke@435: _skip_block = true; duke@435: pop_scope_for_jsr(); duke@435: duke@435: return true; duke@435: } duke@435: duke@435: duke@435: // Inline the entry of a synchronized method as a monitor enter and duke@435: // register the exception handler which releases the monitor if an duke@435: // exception is thrown within the callee. Note that the monitor enter duke@435: // cannot throw an exception itself, because the receiver is duke@435: // guaranteed to be non-null by the explicit null check at the duke@435: // beginning of inlining. duke@435: void GraphBuilder::inline_sync_entry(Value lock, BlockBegin* sync_handler) { duke@435: assert(lock != NULL && sync_handler != NULL, "lock or handler missing"); duke@435: duke@435: set_exception_state(state()->copy()); duke@435: monitorenter(lock, SynchronizationEntryBCI); duke@435: assert(_last->as_MonitorEnter() != NULL, "monitor enter expected"); duke@435: _last->set_needs_null_check(false); duke@435: duke@435: sync_handler->set(BlockBegin::exception_entry_flag); duke@435: sync_handler->set(BlockBegin::is_on_work_list_flag); duke@435: duke@435: ciExceptionHandler* desc = new ciExceptionHandler(method()->holder(), 0, method()->code_size(), -1, 0); duke@435: XHandler* h = new XHandler(desc); duke@435: h->set_entry_block(sync_handler); duke@435: scope_data()->xhandlers()->append(h); duke@435: scope_data()->set_has_handler(); duke@435: } duke@435: duke@435: duke@435: // If an exception is thrown and not handled within an inlined duke@435: // synchronized method, the monitor must be released before the duke@435: // exception is rethrown in the outer scope. Generate the appropriate duke@435: // instructions here. duke@435: void GraphBuilder::fill_sync_handler(Value lock, BlockBegin* sync_handler, bool default_handler) { duke@435: BlockBegin* orig_block = _block; duke@435: ValueStack* orig_state = _state; duke@435: Instruction* orig_last = _last; duke@435: _last = _block = sync_handler; duke@435: _state = sync_handler->state()->copy(); duke@435: duke@435: assert(sync_handler != NULL, "handler missing"); duke@435: assert(!sync_handler->is_set(BlockBegin::was_visited_flag), "is visited here"); duke@435: duke@435: assert(lock != NULL || default_handler, "lock or handler missing"); duke@435: duke@435: XHandler* h = scope_data()->xhandlers()->remove_last(); duke@435: assert(h->entry_block() == sync_handler, "corrupt list of handlers"); duke@435: duke@435: block()->set(BlockBegin::was_visited_flag); duke@435: Value exception = append_with_bci(new ExceptionObject(), SynchronizationEntryBCI); duke@435: assert(exception->is_pinned(), "must be"); duke@435: duke@435: int bci = SynchronizationEntryBCI; duke@435: if (lock) { duke@435: assert(state()->locks_size() > 0 && state()->lock_at(state()->locks_size() - 1) == lock, "lock is missing"); duke@435: if (lock->bci() == -99) { duke@435: lock = append_with_bci(lock, -1); duke@435: } duke@435: duke@435: // exit the monitor in the context of the synchronized method duke@435: monitorexit(lock, SynchronizationEntryBCI); duke@435: duke@435: // exit the context of the synchronized method duke@435: if (!default_handler) { duke@435: pop_scope(); duke@435: _state = _state->copy(); duke@435: bci = _state->scope()->caller_bci(); duke@435: _state = _state->pop_scope()->copy(); duke@435: } duke@435: } duke@435: duke@435: // perform the throw as if at the the call site duke@435: apush(exception); duke@435: duke@435: set_exception_state(state()->copy()); duke@435: throw_op(bci); duke@435: duke@435: BlockEnd* end = last()->as_BlockEnd(); duke@435: block()->set_end(end); duke@435: end->set_state(state()); duke@435: duke@435: _block = orig_block; duke@435: _state = orig_state; duke@435: _last = orig_last; duke@435: } duke@435: duke@435: duke@435: bool GraphBuilder::try_inline_full(ciMethod* callee, bool holder_known) { duke@435: assert(!callee->is_native(), "callee must not be native"); duke@435: duke@435: // first perform tests of things it's not possible to inline duke@435: if (callee->has_exception_handlers() && duke@435: !InlineMethodsWithExceptionHandlers) INLINE_BAILOUT("callee has exception handlers"); duke@435: if (callee->is_synchronized() && duke@435: !InlineSynchronizedMethods ) INLINE_BAILOUT("callee is synchronized"); duke@435: if (!callee->holder()->is_initialized()) INLINE_BAILOUT("callee's klass not initialized yet"); duke@435: if (!callee->has_balanced_monitors()) INLINE_BAILOUT("callee's monitors do not match"); duke@435: duke@435: // Proper inlining of methods with jsrs requires a little more work. duke@435: if (callee->has_jsrs() ) INLINE_BAILOUT("jsrs not handled properly by inliner yet"); duke@435: duke@435: // now perform tests that are based on flag settings duke@435: if (inline_level() > MaxInlineLevel ) INLINE_BAILOUT("too-deep inlining"); duke@435: if (recursive_inline_level(callee) > MaxRecursiveInlineLevel) INLINE_BAILOUT("too-deep recursive inlining"); duke@435: if (callee->code_size() > max_inline_size() ) INLINE_BAILOUT("callee is too large"); duke@435: duke@435: // don't inline throwable methods unless the inlining tree is rooted in a throwable class duke@435: if (callee->name() == ciSymbol::object_initializer_name() && duke@435: callee->holder()->is_subclass_of(ciEnv::current()->Throwable_klass())) { duke@435: // Throwable constructor call duke@435: IRScope* top = scope(); duke@435: while (top->caller() != NULL) { duke@435: top = top->caller(); duke@435: } duke@435: if (!top->method()->holder()->is_subclass_of(ciEnv::current()->Throwable_klass())) { duke@435: INLINE_BAILOUT("don't inline Throwable constructors"); duke@435: } duke@435: } duke@435: duke@435: // When SSE2 is used on intel, then no special handling is needed duke@435: // for strictfp because the enum-constant is fixed at compile time, duke@435: // the check for UseSSE2 is needed here duke@435: if (strict_fp_requires_explicit_rounding && UseSSE < 2 && method()->is_strict() != callee->is_strict()) { duke@435: INLINE_BAILOUT("caller and callee have different strict fp requirements"); duke@435: } duke@435: duke@435: if (compilation()->env()->num_inlined_bytecodes() > DesiredMethodLimit) { duke@435: INLINE_BAILOUT("total inlining greater than DesiredMethodLimit"); duke@435: } duke@435: duke@435: #ifndef PRODUCT duke@435: // printing duke@435: if (PrintInlining) { duke@435: print_inline_result(callee, true); duke@435: } duke@435: #endif duke@435: duke@435: // NOTE: Bailouts from this point on, which occur at the duke@435: // GraphBuilder level, do not cause bailout just of the inlining but duke@435: // in fact of the entire compilation. duke@435: duke@435: BlockBegin* orig_block = block(); duke@435: duke@435: const int args_base = state()->stack_size() - callee->arg_size(); duke@435: assert(args_base >= 0, "stack underflow during inlining"); duke@435: duke@435: // Insert null check if necessary duke@435: Value recv = NULL; duke@435: if (code() != Bytecodes::_invokestatic) { duke@435: // note: null check must happen even if first instruction of callee does duke@435: // an implicit null check since the callee is in a different scope duke@435: // and we must make sure exception handling does the right thing duke@435: assert(!callee->is_static(), "callee must not be static"); duke@435: assert(callee->arg_size() > 0, "must have at least a receiver"); duke@435: recv = state()->stack_at(args_base); duke@435: null_check(recv); duke@435: } duke@435: duke@435: if (profile_inlined_calls()) { duke@435: profile_call(recv, holder_known ? callee->holder() : NULL); duke@435: } duke@435: duke@435: profile_invocation(callee); duke@435: duke@435: // Introduce a new callee continuation point - if the callee has duke@435: // more than one return instruction or the return does not allow duke@435: // fall-through of control flow, all return instructions of the duke@435: // callee will need to be replaced by Goto's pointing to this duke@435: // continuation point. duke@435: BlockBegin* cont = block_at(next_bci()); duke@435: bool continuation_existed = true; duke@435: if (cont == NULL) { duke@435: cont = new BlockBegin(next_bci()); duke@435: // low number so that continuation gets parsed as early as possible duke@435: cont->set_depth_first_number(0); duke@435: #ifndef PRODUCT duke@435: if (PrintInitialBlockList) { duke@435: tty->print_cr("CFG: created block %d (bci %d) as continuation for inline at bci %d", duke@435: cont->block_id(), cont->bci(), bci()); duke@435: } duke@435: #endif duke@435: continuation_existed = false; duke@435: } duke@435: // Record number of predecessors of continuation block before duke@435: // inlining, to detect if inlined method has edges to its duke@435: // continuation after inlining. duke@435: int continuation_preds = cont->number_of_preds(); duke@435: duke@435: // Push callee scope duke@435: push_scope(callee, cont); duke@435: duke@435: // the BlockListBuilder for the callee could have bailed out duke@435: CHECK_BAILOUT_(false); duke@435: duke@435: // Temporarily set up bytecode stream so we can append instructions duke@435: // (only using the bci of this stream) duke@435: scope_data()->set_stream(scope_data()->parent()->stream()); duke@435: duke@435: // Pass parameters into callee state: add assignments duke@435: // note: this will also ensure that all arguments are computed before being passed duke@435: ValueStack* callee_state = state(); duke@435: ValueStack* caller_state = scope()->caller_state(); duke@435: { int i = args_base; duke@435: while (i < caller_state->stack_size()) { duke@435: const int par_no = i - args_base; duke@435: Value arg = caller_state->stack_at_inc(i); duke@435: // NOTE: take base() of arg->type() to avoid problems storing duke@435: // constants duke@435: store_local(callee_state, arg, arg->type()->base(), par_no); duke@435: } duke@435: } duke@435: duke@435: // Remove args from stack. duke@435: // Note that we preserve locals state in case we can use it later duke@435: // (see use of pop_scope() below) duke@435: caller_state->truncate_stack(args_base); duke@435: callee_state->truncate_stack(args_base); duke@435: duke@435: // Setup state that is used at returns form the inlined method. duke@435: // This is essentially the state of the continuation block, duke@435: // but without the return value on stack, if any, this will duke@435: // be pushed at the return instruction (see method_return). duke@435: scope_data()->set_continuation_state(caller_state->copy()); duke@435: duke@435: // Compute lock stack size for callee scope now that args have been passed duke@435: scope()->compute_lock_stack_size(); duke@435: duke@435: Value lock; duke@435: BlockBegin* sync_handler; duke@435: duke@435: // Inline the locking of the receiver if the callee is synchronized duke@435: if (callee->is_synchronized()) { duke@435: lock = callee->is_static() ? append(new Constant(new InstanceConstant(callee->holder()->java_mirror()))) duke@435: : state()->local_at(0); duke@435: sync_handler = new BlockBegin(-1); duke@435: inline_sync_entry(lock, sync_handler); duke@435: duke@435: // recompute the lock stack size duke@435: scope()->compute_lock_stack_size(); duke@435: } duke@435: duke@435: duke@435: BlockBegin* callee_start_block = block_at(0); duke@435: if (callee_start_block != NULL) { duke@435: assert(callee_start_block->is_set(BlockBegin::parser_loop_header_flag), "must be loop header"); duke@435: Goto* goto_callee = new Goto(callee_start_block, false); duke@435: goto_callee->set_state(state()); duke@435: // The state for this goto is in the scope of the callee, so use duke@435: // the entry bci for the callee instead of the call site bci. duke@435: append_with_bci(goto_callee, 0); duke@435: _block->set_end(goto_callee); duke@435: callee_start_block->merge(callee_state); duke@435: duke@435: _last = _block = callee_start_block; duke@435: duke@435: scope_data()->add_to_work_list(callee_start_block); duke@435: } duke@435: duke@435: // Clear out bytecode stream duke@435: scope_data()->set_stream(NULL); duke@435: duke@435: // Ready to resume parsing in callee (either in the same block we duke@435: // were in before or in the callee's start block) duke@435: iterate_all_blocks(callee_start_block == NULL); duke@435: duke@435: // If we bailed out during parsing, return immediately (this is bad news) duke@435: if (bailed_out()) return false; duke@435: duke@435: // iterate_all_blocks theoretically traverses in random order; in duke@435: // practice, we have only traversed the continuation if we are duke@435: // inlining into a subroutine duke@435: assert(continuation_existed || duke@435: !continuation()->is_set(BlockBegin::was_visited_flag), duke@435: "continuation should not have been parsed yet if we created it"); duke@435: duke@435: // If we bailed out during parsing, return immediately (this is bad news) duke@435: CHECK_BAILOUT_(false); duke@435: duke@435: // At this point we are almost ready to return and resume parsing of duke@435: // the caller back in the GraphBuilder. The only thing we want to do duke@435: // first is an optimization: during parsing of the callee we duke@435: // generated at least one Goto to the continuation block. If we duke@435: // generated exactly one, and if the inlined method spanned exactly duke@435: // one block (and we didn't have to Goto its entry), then we snip duke@435: // off the Goto to the continuation, allowing control to fall duke@435: // through back into the caller block and effectively performing duke@435: // block merging. This allows load elimination and CSE to take place duke@435: // across multiple callee scopes if they are relatively simple, and duke@435: // is currently essential to making inlining profitable. duke@435: if ( num_returns() == 1 duke@435: && block() == orig_block duke@435: && block() == inline_cleanup_block()) { duke@435: _last = inline_cleanup_return_prev(); duke@435: _state = inline_cleanup_state()->pop_scope(); duke@435: } else if (continuation_preds == cont->number_of_preds()) { duke@435: // Inlining caused that the instructions after the invoke in the duke@435: // caller are not reachable any more. So skip filling this block duke@435: // with instructions! duke@435: assert (cont == continuation(), ""); duke@435: assert(_last && _last->as_BlockEnd(), ""); duke@435: _skip_block = true; duke@435: } else { duke@435: // Resume parsing in continuation block unless it was already parsed. duke@435: // Note that if we don't change _last here, iteration in duke@435: // iterate_bytecodes_for_block will stop when we return. duke@435: if (!continuation()->is_set(BlockBegin::was_visited_flag)) { duke@435: // add continuation to work list instead of parsing it immediately duke@435: assert(_last && _last->as_BlockEnd(), ""); duke@435: scope_data()->parent()->add_to_work_list(continuation()); duke@435: _skip_block = true; duke@435: } duke@435: } duke@435: duke@435: // Fill the exception handler for synchronized methods with instructions duke@435: if (callee->is_synchronized() && sync_handler->state() != NULL) { duke@435: fill_sync_handler(lock, sync_handler); duke@435: } else { duke@435: pop_scope(); duke@435: } duke@435: duke@435: compilation()->notice_inlined_method(callee); duke@435: duke@435: return true; duke@435: } duke@435: duke@435: duke@435: void GraphBuilder::inline_bailout(const char* msg) { duke@435: assert(msg != NULL, "inline bailout msg must exist"); duke@435: _inline_bailout_msg = msg; duke@435: } duke@435: duke@435: duke@435: void GraphBuilder::clear_inline_bailout() { duke@435: _inline_bailout_msg = NULL; duke@435: } duke@435: duke@435: duke@435: void GraphBuilder::push_root_scope(IRScope* scope, BlockList* bci2block, BlockBegin* start) { duke@435: ScopeData* data = new ScopeData(NULL); duke@435: data->set_scope(scope); duke@435: data->set_bci2block(bci2block); duke@435: _scope_data = data; duke@435: _block = start; duke@435: } duke@435: duke@435: duke@435: void GraphBuilder::push_scope(ciMethod* callee, BlockBegin* continuation) { duke@435: IRScope* callee_scope = new IRScope(compilation(), scope(), bci(), callee, -1, false); duke@435: scope()->add_callee(callee_scope); duke@435: duke@435: BlockListBuilder blb(compilation(), callee_scope, -1); duke@435: CHECK_BAILOUT(); duke@435: duke@435: if (!blb.bci2block()->at(0)->is_set(BlockBegin::parser_loop_header_flag)) { duke@435: // this scope can be inlined directly into the caller so remove duke@435: // the block at bci 0. duke@435: blb.bci2block()->at_put(0, NULL); duke@435: } duke@435: duke@435: callee_scope->set_caller_state(state()); duke@435: set_state(state()->push_scope(callee_scope)); duke@435: duke@435: ScopeData* data = new ScopeData(scope_data()); duke@435: data->set_scope(callee_scope); duke@435: data->set_bci2block(blb.bci2block()); duke@435: data->set_continuation(continuation); duke@435: _scope_data = data; duke@435: } duke@435: duke@435: duke@435: void GraphBuilder::push_scope_for_jsr(BlockBegin* jsr_continuation, int jsr_dest_bci) { duke@435: ScopeData* data = new ScopeData(scope_data()); duke@435: data->set_parsing_jsr(); duke@435: data->set_jsr_entry_bci(jsr_dest_bci); duke@435: data->set_jsr_return_address_local(-1); duke@435: // Must clone bci2block list as we will be mutating it in order to duke@435: // properly clone all blocks in jsr region as well as exception duke@435: // handlers containing rets duke@435: BlockList* new_bci2block = new BlockList(bci2block()->length()); duke@435: new_bci2block->push_all(bci2block()); duke@435: data->set_bci2block(new_bci2block); duke@435: data->set_scope(scope()); duke@435: data->setup_jsr_xhandlers(); duke@435: data->set_continuation(continuation()); duke@435: if (continuation() != NULL) { duke@435: assert(continuation_state() != NULL, ""); duke@435: data->set_continuation_state(continuation_state()->copy()); duke@435: } duke@435: data->set_jsr_continuation(jsr_continuation); duke@435: _scope_data = data; duke@435: } duke@435: duke@435: duke@435: void GraphBuilder::pop_scope() { duke@435: int number_of_locks = scope()->number_of_locks(); duke@435: _scope_data = scope_data()->parent(); duke@435: // accumulate minimum number of monitor slots to be reserved duke@435: scope()->set_min_number_of_locks(number_of_locks); duke@435: } duke@435: duke@435: duke@435: void GraphBuilder::pop_scope_for_jsr() { duke@435: _scope_data = scope_data()->parent(); duke@435: } duke@435: duke@435: bool GraphBuilder::append_unsafe_get_obj(ciMethod* callee, BasicType t, bool is_volatile) { duke@435: if (InlineUnsafeOps) { duke@435: Values* args = state()->pop_arguments(callee->arg_size()); duke@435: null_check(args->at(0)); duke@435: Instruction* offset = args->at(2); duke@435: #ifndef _LP64 duke@435: offset = append(new Convert(Bytecodes::_l2i, offset, as_ValueType(T_INT))); duke@435: #endif duke@435: Instruction* op = append(new UnsafeGetObject(t, args->at(1), offset, is_volatile)); duke@435: push(op->type(), op); duke@435: compilation()->set_has_unsafe_access(true); duke@435: } duke@435: return InlineUnsafeOps; duke@435: } duke@435: duke@435: duke@435: bool GraphBuilder::append_unsafe_put_obj(ciMethod* callee, BasicType t, bool is_volatile) { duke@435: if (InlineUnsafeOps) { duke@435: Values* args = state()->pop_arguments(callee->arg_size()); duke@435: null_check(args->at(0)); duke@435: Instruction* offset = args->at(2); duke@435: #ifndef _LP64 duke@435: offset = append(new Convert(Bytecodes::_l2i, offset, as_ValueType(T_INT))); duke@435: #endif duke@435: Instruction* op = append(new UnsafePutObject(t, args->at(1), offset, args->at(3), is_volatile)); duke@435: compilation()->set_has_unsafe_access(true); duke@435: kill_all(); duke@435: } duke@435: return InlineUnsafeOps; duke@435: } duke@435: duke@435: duke@435: bool GraphBuilder::append_unsafe_get_raw(ciMethod* callee, BasicType t) { duke@435: if (InlineUnsafeOps) { duke@435: Values* args = state()->pop_arguments(callee->arg_size()); duke@435: null_check(args->at(0)); duke@435: Instruction* op = append(new UnsafeGetRaw(t, args->at(1), false)); duke@435: push(op->type(), op); duke@435: compilation()->set_has_unsafe_access(true); duke@435: } duke@435: return InlineUnsafeOps; duke@435: } duke@435: duke@435: duke@435: bool GraphBuilder::append_unsafe_put_raw(ciMethod* callee, BasicType t) { duke@435: if (InlineUnsafeOps) { duke@435: Values* args = state()->pop_arguments(callee->arg_size()); duke@435: null_check(args->at(0)); duke@435: Instruction* op = append(new UnsafePutRaw(t, args->at(1), args->at(2))); duke@435: compilation()->set_has_unsafe_access(true); duke@435: } duke@435: return InlineUnsafeOps; duke@435: } duke@435: duke@435: duke@435: bool GraphBuilder::append_unsafe_prefetch(ciMethod* callee, bool is_static, bool is_store) { duke@435: if (InlineUnsafeOps) { duke@435: Values* args = state()->pop_arguments(callee->arg_size()); duke@435: int obj_arg_index = 1; // Assume non-static case duke@435: if (is_static) { duke@435: obj_arg_index = 0; duke@435: } else { duke@435: null_check(args->at(0)); duke@435: } duke@435: Instruction* offset = args->at(obj_arg_index + 1); duke@435: #ifndef _LP64 duke@435: offset = append(new Convert(Bytecodes::_l2i, offset, as_ValueType(T_INT))); duke@435: #endif duke@435: Instruction* op = is_store ? append(new UnsafePrefetchWrite(args->at(obj_arg_index), offset)) duke@435: : append(new UnsafePrefetchRead (args->at(obj_arg_index), offset)); duke@435: compilation()->set_has_unsafe_access(true); duke@435: } duke@435: return InlineUnsafeOps; duke@435: } duke@435: duke@435: duke@435: void GraphBuilder::append_unsafe_CAS(ciMethod* callee) { duke@435: ValueType* result_type = as_ValueType(callee->return_type()); duke@435: assert(result_type->is_int(), "int result"); duke@435: Values* args = state()->pop_arguments(callee->arg_size()); duke@435: duke@435: // Pop off some args to speically handle, then push back duke@435: Value newval = args->pop(); duke@435: Value cmpval = args->pop(); duke@435: Value offset = args->pop(); duke@435: Value src = args->pop(); duke@435: Value unsafe_obj = args->pop(); duke@435: duke@435: // Separately handle the unsafe arg. It is not needed for code duke@435: // generation, but must be null checked duke@435: null_check(unsafe_obj); duke@435: duke@435: #ifndef _LP64 duke@435: offset = append(new Convert(Bytecodes::_l2i, offset, as_ValueType(T_INT))); duke@435: #endif duke@435: duke@435: args->push(src); duke@435: args->push(offset); duke@435: args->push(cmpval); duke@435: args->push(newval); duke@435: duke@435: // An unsafe CAS can alias with other field accesses, but we don't duke@435: // know which ones so mark the state as no preserved. This will duke@435: // cause CSE to invalidate memory across it. duke@435: bool preserves_state = false; duke@435: Intrinsic* result = new Intrinsic(result_type, callee->intrinsic_id(), args, false, lock_stack(), preserves_state); duke@435: append_split(result); duke@435: push(result_type, result); duke@435: compilation()->set_has_unsafe_access(true); duke@435: } duke@435: duke@435: duke@435: #ifndef PRODUCT duke@435: void GraphBuilder::print_inline_result(ciMethod* callee, bool res) { duke@435: const char sync_char = callee->is_synchronized() ? 's' : ' '; duke@435: const char exception_char = callee->has_exception_handlers() ? '!' : ' '; duke@435: const char monitors_char = callee->has_monitor_bytecodes() ? 'm' : ' '; duke@435: tty->print(" %c%c%c ", sync_char, exception_char, monitors_char); duke@435: for (int i = 0; i < scope()->level(); i++) tty->print(" "); duke@435: if (res) { duke@435: tty->print(" "); duke@435: } else { duke@435: tty->print("- "); duke@435: } duke@435: tty->print("@ %d ", bci()); duke@435: callee->print_short_name(); duke@435: tty->print(" (%d bytes)", callee->code_size()); duke@435: if (_inline_bailout_msg) { duke@435: tty->print(" %s", _inline_bailout_msg); duke@435: } duke@435: tty->cr(); duke@435: duke@435: if (res && CIPrintMethodCodes) { duke@435: callee->print_codes(); duke@435: } duke@435: } duke@435: duke@435: duke@435: void GraphBuilder::print_stats() { duke@435: vmap()->print(); duke@435: } duke@435: #endif // PRODUCT duke@435: duke@435: duke@435: void GraphBuilder::profile_call(Value recv, ciKlass* known_holder) { duke@435: append(new ProfileCall(method(), bci(), recv, known_holder)); duke@435: } duke@435: duke@435: duke@435: void GraphBuilder::profile_invocation(ciMethod* callee) { duke@435: if (profile_calls()) { duke@435: // increment the interpreter_invocation_count for the inlinee duke@435: Value m = append(new Constant(new ObjectConstant(callee))); duke@435: append(new ProfileCounter(m, methodOopDesc::interpreter_invocation_counter_offset_in_bytes(), 1)); duke@435: } duke@435: } duke@435: duke@435: duke@435: void GraphBuilder::profile_bci(int bci) { duke@435: if (profile_branches()) { duke@435: ciMethodData* md = method()->method_data(); duke@435: if (md == NULL) { duke@435: BAILOUT("out of memory building methodDataOop"); duke@435: } duke@435: ciProfileData* data = md->bci_to_data(bci); duke@435: assert(data != NULL && data->is_JumpData(), "need JumpData for goto"); duke@435: Value mdo = append(new Constant(new ObjectConstant(md))); duke@435: append(new ProfileCounter(mdo, md->byte_offset_of_slot(data, JumpData::taken_offset()), 1)); duke@435: } duke@435: }