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