duke@435: /* duke@435: * Copyright 2005-2007 Sun Microsystems, Inc. All Rights Reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * duke@435: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, duke@435: * CA 95054 USA or visit www.sun.com if you need additional information or duke@435: * have any questions. duke@435: * duke@435: */ duke@435: duke@435: # include "incls/_precompiled.incl" duke@435: # include "incls/_c1_LIRGenerator.cpp.incl" duke@435: duke@435: #ifdef ASSERT duke@435: #define __ gen()->lir(__FILE__, __LINE__)-> duke@435: #else duke@435: #define __ gen()->lir()-> duke@435: #endif duke@435: duke@435: duke@435: void PhiResolverState::reset(int max_vregs) { duke@435: // Initialize array sizes duke@435: _virtual_operands.at_put_grow(max_vregs - 1, NULL, NULL); duke@435: _virtual_operands.trunc_to(0); duke@435: _other_operands.at_put_grow(max_vregs - 1, NULL, NULL); duke@435: _other_operands.trunc_to(0); duke@435: _vreg_table.at_put_grow(max_vregs - 1, NULL, NULL); duke@435: _vreg_table.trunc_to(0); duke@435: } duke@435: duke@435: duke@435: duke@435: //-------------------------------------------------------------- duke@435: // PhiResolver duke@435: duke@435: // Resolves cycles: duke@435: // duke@435: // r1 := r2 becomes temp := r1 duke@435: // r2 := r1 r1 := r2 duke@435: // r2 := temp duke@435: // and orders moves: duke@435: // duke@435: // r2 := r3 becomes r1 := r2 duke@435: // r1 := r2 r2 := r3 duke@435: duke@435: PhiResolver::PhiResolver(LIRGenerator* gen, int max_vregs) duke@435: : _gen(gen) duke@435: , _state(gen->resolver_state()) duke@435: , _temp(LIR_OprFact::illegalOpr) duke@435: { duke@435: // reinitialize the shared state arrays duke@435: _state.reset(max_vregs); duke@435: } duke@435: duke@435: duke@435: void PhiResolver::emit_move(LIR_Opr src, LIR_Opr dest) { duke@435: assert(src->is_valid(), ""); duke@435: assert(dest->is_valid(), ""); duke@435: __ move(src, dest); duke@435: } duke@435: duke@435: duke@435: void PhiResolver::move_temp_to(LIR_Opr dest) { duke@435: assert(_temp->is_valid(), ""); duke@435: emit_move(_temp, dest); duke@435: NOT_PRODUCT(_temp = LIR_OprFact::illegalOpr); duke@435: } duke@435: duke@435: duke@435: void PhiResolver::move_to_temp(LIR_Opr src) { duke@435: assert(_temp->is_illegal(), ""); duke@435: _temp = _gen->new_register(src->type()); duke@435: emit_move(src, _temp); duke@435: } duke@435: duke@435: duke@435: // Traverse assignment graph in depth first order and generate moves in post order duke@435: // ie. two assignments: b := c, a := b start with node c: duke@435: // Call graph: move(NULL, c) -> move(c, b) -> move(b, a) duke@435: // Generates moves in this order: move b to a and move c to b duke@435: // ie. cycle a := b, b := a start with node a duke@435: // Call graph: move(NULL, a) -> move(a, b) -> move(b, a) duke@435: // Generates moves in this order: move b to temp, move a to b, move temp to a duke@435: void PhiResolver::move(ResolveNode* src, ResolveNode* dest) { duke@435: if (!dest->visited()) { duke@435: dest->set_visited(); duke@435: for (int i = dest->no_of_destinations()-1; i >= 0; i --) { duke@435: move(dest, dest->destination_at(i)); duke@435: } duke@435: } else if (!dest->start_node()) { duke@435: // cylce in graph detected duke@435: assert(_loop == NULL, "only one loop valid!"); duke@435: _loop = dest; duke@435: move_to_temp(src->operand()); duke@435: return; duke@435: } // else dest is a start node duke@435: duke@435: if (!dest->assigned()) { duke@435: if (_loop == dest) { duke@435: move_temp_to(dest->operand()); duke@435: dest->set_assigned(); duke@435: } else if (src != NULL) { duke@435: emit_move(src->operand(), dest->operand()); duke@435: dest->set_assigned(); duke@435: } duke@435: } duke@435: } duke@435: duke@435: duke@435: PhiResolver::~PhiResolver() { duke@435: int i; duke@435: // resolve any cycles in moves from and to virtual registers duke@435: for (i = virtual_operands().length() - 1; i >= 0; i --) { duke@435: ResolveNode* node = virtual_operands()[i]; duke@435: if (!node->visited()) { duke@435: _loop = NULL; duke@435: move(NULL, node); duke@435: node->set_start_node(); duke@435: assert(_temp->is_illegal(), "move_temp_to() call missing"); duke@435: } duke@435: } duke@435: duke@435: // generate move for move from non virtual register to abitrary destination duke@435: for (i = other_operands().length() - 1; i >= 0; i --) { duke@435: ResolveNode* node = other_operands()[i]; duke@435: for (int j = node->no_of_destinations() - 1; j >= 0; j --) { duke@435: emit_move(node->operand(), node->destination_at(j)->operand()); duke@435: } duke@435: } duke@435: } duke@435: duke@435: duke@435: ResolveNode* PhiResolver::create_node(LIR_Opr opr, bool source) { duke@435: ResolveNode* node; duke@435: if (opr->is_virtual()) { duke@435: int vreg_num = opr->vreg_number(); duke@435: node = vreg_table().at_grow(vreg_num, NULL); duke@435: assert(node == NULL || node->operand() == opr, ""); duke@435: if (node == NULL) { duke@435: node = new ResolveNode(opr); duke@435: vreg_table()[vreg_num] = node; duke@435: } duke@435: // Make sure that all virtual operands show up in the list when duke@435: // they are used as the source of a move. duke@435: if (source && !virtual_operands().contains(node)) { duke@435: virtual_operands().append(node); duke@435: } duke@435: } else { duke@435: assert(source, ""); duke@435: node = new ResolveNode(opr); duke@435: other_operands().append(node); duke@435: } duke@435: return node; duke@435: } duke@435: duke@435: duke@435: void PhiResolver::move(LIR_Opr src, LIR_Opr dest) { duke@435: assert(dest->is_virtual(), ""); duke@435: // tty->print("move "); src->print(); tty->print(" to "); dest->print(); tty->cr(); duke@435: assert(src->is_valid(), ""); duke@435: assert(dest->is_valid(), ""); duke@435: ResolveNode* source = source_node(src); duke@435: source->append(destination_node(dest)); duke@435: } duke@435: duke@435: duke@435: //-------------------------------------------------------------- duke@435: // LIRItem duke@435: duke@435: void LIRItem::set_result(LIR_Opr opr) { duke@435: assert(value()->operand()->is_illegal() || value()->operand()->is_constant(), "operand should never change"); duke@435: value()->set_operand(opr); duke@435: duke@435: if (opr->is_virtual()) { duke@435: _gen->_instruction_for_operand.at_put_grow(opr->vreg_number(), value(), NULL); duke@435: } duke@435: duke@435: _result = opr; duke@435: } duke@435: duke@435: void LIRItem::load_item() { duke@435: if (result()->is_illegal()) { duke@435: // update the items result duke@435: _result = value()->operand(); duke@435: } duke@435: if (!result()->is_register()) { duke@435: LIR_Opr reg = _gen->new_register(value()->type()); duke@435: __ move(result(), reg); duke@435: if (result()->is_constant()) { duke@435: _result = reg; duke@435: } else { duke@435: set_result(reg); duke@435: } duke@435: } duke@435: } duke@435: duke@435: duke@435: void LIRItem::load_for_store(BasicType type) { duke@435: if (_gen->can_store_as_constant(value(), type)) { duke@435: _result = value()->operand(); duke@435: if (!_result->is_constant()) { duke@435: _result = LIR_OprFact::value_type(value()->type()); duke@435: } duke@435: } else if (type == T_BYTE || type == T_BOOLEAN) { duke@435: load_byte_item(); duke@435: } else { duke@435: load_item(); duke@435: } duke@435: } duke@435: duke@435: void LIRItem::load_item_force(LIR_Opr reg) { duke@435: LIR_Opr r = result(); duke@435: if (r != reg) { duke@435: if (r->type() != reg->type()) { duke@435: // moves between different types need an intervening spill slot duke@435: LIR_Opr tmp = _gen->force_to_spill(r, reg->type()); duke@435: __ move(tmp, reg); duke@435: } else { duke@435: __ move(r, reg); duke@435: } duke@435: _result = reg; duke@435: } duke@435: } duke@435: duke@435: ciObject* LIRItem::get_jobject_constant() const { duke@435: ObjectType* oc = type()->as_ObjectType(); duke@435: if (oc) { duke@435: return oc->constant_value(); duke@435: } duke@435: return NULL; duke@435: } duke@435: duke@435: duke@435: jint LIRItem::get_jint_constant() const { duke@435: assert(is_constant() && value() != NULL, ""); duke@435: assert(type()->as_IntConstant() != NULL, "type check"); duke@435: return type()->as_IntConstant()->value(); duke@435: } duke@435: duke@435: duke@435: jint LIRItem::get_address_constant() const { duke@435: assert(is_constant() && value() != NULL, ""); duke@435: assert(type()->as_AddressConstant() != NULL, "type check"); duke@435: return type()->as_AddressConstant()->value(); duke@435: } duke@435: duke@435: duke@435: jfloat LIRItem::get_jfloat_constant() const { duke@435: assert(is_constant() && value() != NULL, ""); duke@435: assert(type()->as_FloatConstant() != NULL, "type check"); duke@435: return type()->as_FloatConstant()->value(); duke@435: } duke@435: duke@435: duke@435: jdouble LIRItem::get_jdouble_constant() const { duke@435: assert(is_constant() && value() != NULL, ""); duke@435: assert(type()->as_DoubleConstant() != NULL, "type check"); duke@435: return type()->as_DoubleConstant()->value(); duke@435: } duke@435: duke@435: duke@435: jlong LIRItem::get_jlong_constant() const { duke@435: assert(is_constant() && value() != NULL, ""); duke@435: assert(type()->as_LongConstant() != NULL, "type check"); duke@435: return type()->as_LongConstant()->value(); duke@435: } duke@435: duke@435: duke@435: duke@435: //-------------------------------------------------------------- duke@435: duke@435: duke@435: void LIRGenerator::init() { duke@435: BarrierSet* bs = Universe::heap()->barrier_set(); duke@435: assert(bs->kind() == BarrierSet::CardTableModRef, "Wrong barrier set kind"); duke@435: CardTableModRefBS* ct = (CardTableModRefBS*)bs; duke@435: assert(sizeof(*ct->byte_map_base) == sizeof(jbyte), "adjust this code"); duke@435: duke@435: #ifdef _LP64 duke@435: _card_table_base = new LIR_Const((jlong)ct->byte_map_base); duke@435: #else duke@435: _card_table_base = new LIR_Const((jint)ct->byte_map_base); duke@435: #endif duke@435: } duke@435: duke@435: duke@435: void LIRGenerator::block_do_prolog(BlockBegin* block) { duke@435: #ifndef PRODUCT duke@435: if (PrintIRWithLIR) { duke@435: block->print(); duke@435: } duke@435: #endif duke@435: duke@435: // set up the list of LIR instructions duke@435: assert(block->lir() == NULL, "LIR list already computed for this block"); duke@435: _lir = new LIR_List(compilation(), block); duke@435: block->set_lir(_lir); duke@435: duke@435: __ branch_destination(block->label()); duke@435: duke@435: if (LIRTraceExecution && duke@435: Compilation::current_compilation()->hir()->start()->block_id() != block->block_id() && duke@435: !block->is_set(BlockBegin::exception_entry_flag)) { duke@435: assert(block->lir()->instructions_list()->length() == 1, "should come right after br_dst"); duke@435: trace_block_entry(block); duke@435: } duke@435: } duke@435: duke@435: duke@435: void LIRGenerator::block_do_epilog(BlockBegin* block) { duke@435: #ifndef PRODUCT duke@435: if (PrintIRWithLIR) { duke@435: tty->cr(); duke@435: } duke@435: #endif duke@435: duke@435: // LIR_Opr for unpinned constants shouldn't be referenced by other duke@435: // blocks so clear them out after processing the block. duke@435: for (int i = 0; i < _unpinned_constants.length(); i++) { duke@435: _unpinned_constants.at(i)->clear_operand(); duke@435: } duke@435: _unpinned_constants.trunc_to(0); duke@435: duke@435: // clear our any registers for other local constants duke@435: _constants.trunc_to(0); duke@435: _reg_for_constants.trunc_to(0); duke@435: } duke@435: duke@435: duke@435: void LIRGenerator::block_do(BlockBegin* block) { duke@435: CHECK_BAILOUT(); duke@435: duke@435: block_do_prolog(block); duke@435: set_block(block); duke@435: duke@435: for (Instruction* instr = block; instr != NULL; instr = instr->next()) { duke@435: if (instr->is_pinned()) do_root(instr); duke@435: } duke@435: duke@435: set_block(NULL); duke@435: block_do_epilog(block); duke@435: } duke@435: duke@435: duke@435: //-------------------------LIRGenerator----------------------------- duke@435: duke@435: // This is where the tree-walk starts; instr must be root; duke@435: void LIRGenerator::do_root(Value instr) { duke@435: CHECK_BAILOUT(); duke@435: duke@435: InstructionMark im(compilation(), instr); duke@435: duke@435: assert(instr->is_pinned(), "use only with roots"); duke@435: assert(instr->subst() == instr, "shouldn't have missed substitution"); duke@435: duke@435: instr->visit(this); duke@435: duke@435: assert(!instr->has_uses() || instr->operand()->is_valid() || duke@435: instr->as_Constant() != NULL || bailed_out(), "invalid item set"); duke@435: } duke@435: duke@435: duke@435: // This is called for each node in tree; the walk stops if a root is reached duke@435: void LIRGenerator::walk(Value instr) { duke@435: InstructionMark im(compilation(), instr); duke@435: //stop walk when encounter a root duke@435: if (instr->is_pinned() && instr->as_Phi() == NULL || instr->operand()->is_valid()) { duke@435: assert(instr->operand() != LIR_OprFact::illegalOpr || instr->as_Constant() != NULL, "this root has not yet been visited"); duke@435: } else { duke@435: assert(instr->subst() == instr, "shouldn't have missed substitution"); duke@435: instr->visit(this); duke@435: // assert(instr->use_count() > 0 || instr->as_Phi() != NULL, "leaf instruction must have a use"); duke@435: } duke@435: } duke@435: duke@435: duke@435: CodeEmitInfo* LIRGenerator::state_for(Instruction* x, ValueStack* state, bool ignore_xhandler) { duke@435: int index; duke@435: Value value; duke@435: for_each_stack_value(state, index, value) { duke@435: assert(value->subst() == value, "missed substition"); duke@435: if (!value->is_pinned() && value->as_Constant() == NULL && value->as_Local() == NULL) { duke@435: walk(value); duke@435: assert(value->operand()->is_valid(), "must be evaluated now"); duke@435: } duke@435: } duke@435: ValueStack* s = state; duke@435: int bci = x->bci(); duke@435: for_each_state(s) { duke@435: IRScope* scope = s->scope(); duke@435: ciMethod* method = scope->method(); duke@435: duke@435: MethodLivenessResult liveness = method->liveness_at_bci(bci); duke@435: if (bci == SynchronizationEntryBCI) { duke@435: if (x->as_ExceptionObject() || x->as_Throw()) { duke@435: // all locals are dead on exit from the synthetic unlocker duke@435: liveness.clear(); duke@435: } else { duke@435: assert(x->as_MonitorEnter(), "only other case is MonitorEnter"); duke@435: } duke@435: } duke@435: if (!liveness.is_valid()) { duke@435: // Degenerate or breakpointed method. duke@435: bailout("Degenerate or breakpointed method"); duke@435: } else { duke@435: assert((int)liveness.size() == s->locals_size(), "error in use of liveness"); duke@435: for_each_local_value(s, index, value) { duke@435: assert(value->subst() == value, "missed substition"); duke@435: if (liveness.at(index) && !value->type()->is_illegal()) { duke@435: if (!value->is_pinned() && value->as_Constant() == NULL && value->as_Local() == NULL) { duke@435: walk(value); duke@435: assert(value->operand()->is_valid(), "must be evaluated now"); duke@435: } duke@435: } else { duke@435: // NULL out this local so that linear scan can assume that all non-NULL values are live. duke@435: s->invalidate_local(index); duke@435: } duke@435: } duke@435: } duke@435: bci = scope->caller_bci(); duke@435: } duke@435: duke@435: return new CodeEmitInfo(x->bci(), state, ignore_xhandler ? NULL : x->exception_handlers()); duke@435: } duke@435: duke@435: duke@435: CodeEmitInfo* LIRGenerator::state_for(Instruction* x) { duke@435: return state_for(x, x->lock_stack()); duke@435: } duke@435: duke@435: duke@435: void LIRGenerator::jobject2reg_with_patching(LIR_Opr r, ciObject* obj, CodeEmitInfo* info) { duke@435: if (!obj->is_loaded() || PatchALot) { duke@435: assert(info != NULL, "info must be set if class is not loaded"); duke@435: __ oop2reg_patch(NULL, r, info); duke@435: } else { duke@435: // no patching needed duke@435: __ oop2reg(obj->encoding(), r); duke@435: } duke@435: } duke@435: duke@435: duke@435: void LIRGenerator::array_range_check(LIR_Opr array, LIR_Opr index, duke@435: CodeEmitInfo* null_check_info, CodeEmitInfo* range_check_info) { duke@435: CodeStub* stub = new RangeCheckStub(range_check_info, index); duke@435: if (index->is_constant()) { duke@435: cmp_mem_int(lir_cond_belowEqual, array, arrayOopDesc::length_offset_in_bytes(), duke@435: index->as_jint(), null_check_info); duke@435: __ branch(lir_cond_belowEqual, T_INT, stub); // forward branch duke@435: } else { duke@435: cmp_reg_mem(lir_cond_aboveEqual, index, array, duke@435: arrayOopDesc::length_offset_in_bytes(), T_INT, null_check_info); duke@435: __ branch(lir_cond_aboveEqual, T_INT, stub); // forward branch duke@435: } duke@435: } duke@435: duke@435: duke@435: void LIRGenerator::nio_range_check(LIR_Opr buffer, LIR_Opr index, LIR_Opr result, CodeEmitInfo* info) { duke@435: CodeStub* stub = new RangeCheckStub(info, index, true); duke@435: if (index->is_constant()) { duke@435: cmp_mem_int(lir_cond_belowEqual, buffer, java_nio_Buffer::limit_offset(), index->as_jint(), info); duke@435: __ branch(lir_cond_belowEqual, T_INT, stub); // forward branch duke@435: } else { duke@435: cmp_reg_mem(lir_cond_aboveEqual, index, buffer, duke@435: java_nio_Buffer::limit_offset(), T_INT, info); duke@435: __ branch(lir_cond_aboveEqual, T_INT, stub); // forward branch duke@435: } duke@435: __ move(index, result); duke@435: } duke@435: duke@435: duke@435: // increment a counter returning the incremented value duke@435: LIR_Opr LIRGenerator::increment_and_return_counter(LIR_Opr base, int offset, int increment) { duke@435: LIR_Address* counter = new LIR_Address(base, offset, T_INT); duke@435: LIR_Opr result = new_register(T_INT); duke@435: __ load(counter, result); duke@435: __ add(result, LIR_OprFact::intConst(increment), result); duke@435: __ store(result, counter); duke@435: return result; duke@435: } duke@435: duke@435: duke@435: void LIRGenerator::arithmetic_op(Bytecodes::Code code, LIR_Opr result, LIR_Opr left, LIR_Opr right, bool is_strictfp, LIR_Opr tmp_op, CodeEmitInfo* info) { duke@435: LIR_Opr result_op = result; duke@435: LIR_Opr left_op = left; duke@435: LIR_Opr right_op = right; duke@435: duke@435: if (TwoOperandLIRForm && left_op != result_op) { duke@435: assert(right_op != result_op, "malformed"); duke@435: __ move(left_op, result_op); duke@435: left_op = result_op; duke@435: } duke@435: duke@435: switch(code) { duke@435: case Bytecodes::_dadd: duke@435: case Bytecodes::_fadd: duke@435: case Bytecodes::_ladd: duke@435: case Bytecodes::_iadd: __ add(left_op, right_op, result_op); break; duke@435: case Bytecodes::_fmul: duke@435: case Bytecodes::_lmul: __ mul(left_op, right_op, result_op); break; duke@435: duke@435: case Bytecodes::_dmul: duke@435: { duke@435: if (is_strictfp) { duke@435: __ mul_strictfp(left_op, right_op, result_op, tmp_op); break; duke@435: } else { duke@435: __ mul(left_op, right_op, result_op); break; duke@435: } duke@435: } duke@435: break; duke@435: duke@435: case Bytecodes::_imul: duke@435: { duke@435: bool did_strength_reduce = false; duke@435: duke@435: if (right->is_constant()) { duke@435: int c = right->as_jint(); duke@435: if (is_power_of_2(c)) { duke@435: // do not need tmp here duke@435: __ shift_left(left_op, exact_log2(c), result_op); duke@435: did_strength_reduce = true; duke@435: } else { duke@435: did_strength_reduce = strength_reduce_multiply(left_op, c, result_op, tmp_op); duke@435: } duke@435: } duke@435: // we couldn't strength reduce so just emit the multiply duke@435: if (!did_strength_reduce) { duke@435: __ mul(left_op, right_op, result_op); duke@435: } duke@435: } duke@435: break; duke@435: duke@435: case Bytecodes::_dsub: duke@435: case Bytecodes::_fsub: duke@435: case Bytecodes::_lsub: duke@435: case Bytecodes::_isub: __ sub(left_op, right_op, result_op); break; duke@435: duke@435: case Bytecodes::_fdiv: __ div (left_op, right_op, result_op); break; duke@435: // ldiv and lrem are implemented with a direct runtime call duke@435: duke@435: case Bytecodes::_ddiv: duke@435: { duke@435: if (is_strictfp) { duke@435: __ div_strictfp (left_op, right_op, result_op, tmp_op); break; duke@435: } else { duke@435: __ div (left_op, right_op, result_op); break; duke@435: } duke@435: } duke@435: break; duke@435: duke@435: case Bytecodes::_drem: duke@435: case Bytecodes::_frem: __ rem (left_op, right_op, result_op); break; duke@435: duke@435: default: ShouldNotReachHere(); duke@435: } duke@435: } duke@435: duke@435: duke@435: void LIRGenerator::arithmetic_op_int(Bytecodes::Code code, LIR_Opr result, LIR_Opr left, LIR_Opr right, LIR_Opr tmp) { duke@435: arithmetic_op(code, result, left, right, false, tmp); duke@435: } duke@435: duke@435: duke@435: void LIRGenerator::arithmetic_op_long(Bytecodes::Code code, LIR_Opr result, LIR_Opr left, LIR_Opr right, CodeEmitInfo* info) { duke@435: arithmetic_op(code, result, left, right, false, LIR_OprFact::illegalOpr, info); duke@435: } duke@435: duke@435: duke@435: void LIRGenerator::arithmetic_op_fpu(Bytecodes::Code code, LIR_Opr result, LIR_Opr left, LIR_Opr right, bool is_strictfp, LIR_Opr tmp) { duke@435: arithmetic_op(code, result, left, right, is_strictfp, tmp); duke@435: } duke@435: duke@435: duke@435: void LIRGenerator::shift_op(Bytecodes::Code code, LIR_Opr result_op, LIR_Opr value, LIR_Opr count, LIR_Opr tmp) { duke@435: if (TwoOperandLIRForm && value != result_op) { duke@435: assert(count != result_op, "malformed"); duke@435: __ move(value, result_op); duke@435: value = result_op; duke@435: } duke@435: duke@435: assert(count->is_constant() || count->is_register(), "must be"); duke@435: switch(code) { duke@435: case Bytecodes::_ishl: duke@435: case Bytecodes::_lshl: __ shift_left(value, count, result_op, tmp); break; duke@435: case Bytecodes::_ishr: duke@435: case Bytecodes::_lshr: __ shift_right(value, count, result_op, tmp); break; duke@435: case Bytecodes::_iushr: duke@435: case Bytecodes::_lushr: __ unsigned_shift_right(value, count, result_op, tmp); break; duke@435: default: ShouldNotReachHere(); duke@435: } duke@435: } duke@435: duke@435: duke@435: void LIRGenerator::logic_op (Bytecodes::Code code, LIR_Opr result_op, LIR_Opr left_op, LIR_Opr right_op) { duke@435: if (TwoOperandLIRForm && left_op != result_op) { duke@435: assert(right_op != result_op, "malformed"); duke@435: __ move(left_op, result_op); duke@435: left_op = result_op; duke@435: } duke@435: duke@435: switch(code) { duke@435: case Bytecodes::_iand: duke@435: case Bytecodes::_land: __ logical_and(left_op, right_op, result_op); break; duke@435: duke@435: case Bytecodes::_ior: duke@435: case Bytecodes::_lor: __ logical_or(left_op, right_op, result_op); break; duke@435: duke@435: case Bytecodes::_ixor: duke@435: case Bytecodes::_lxor: __ logical_xor(left_op, right_op, result_op); break; duke@435: duke@435: default: ShouldNotReachHere(); duke@435: } duke@435: } duke@435: duke@435: duke@435: void LIRGenerator::monitor_enter(LIR_Opr object, LIR_Opr lock, LIR_Opr hdr, LIR_Opr scratch, int monitor_no, CodeEmitInfo* info_for_exception, CodeEmitInfo* info) { duke@435: if (!GenerateSynchronizationCode) return; duke@435: // for slow path, use debug info for state after successful locking duke@435: CodeStub* slow_path = new MonitorEnterStub(object, lock, info); duke@435: __ load_stack_address_monitor(monitor_no, lock); duke@435: // for handling NullPointerException, use debug info representing just the lock stack before this monitorenter duke@435: __ lock_object(hdr, object, lock, scratch, slow_path, info_for_exception); duke@435: } duke@435: duke@435: duke@435: void LIRGenerator::monitor_exit(LIR_Opr object, LIR_Opr lock, LIR_Opr new_hdr, int monitor_no) { duke@435: if (!GenerateSynchronizationCode) return; duke@435: // setup registers duke@435: LIR_Opr hdr = lock; duke@435: lock = new_hdr; duke@435: CodeStub* slow_path = new MonitorExitStub(lock, UseFastLocking, monitor_no); duke@435: __ load_stack_address_monitor(monitor_no, lock); duke@435: __ unlock_object(hdr, object, lock, slow_path); duke@435: } duke@435: duke@435: duke@435: void LIRGenerator::new_instance(LIR_Opr dst, ciInstanceKlass* klass, LIR_Opr scratch1, LIR_Opr scratch2, LIR_Opr scratch3, LIR_Opr scratch4, LIR_Opr klass_reg, CodeEmitInfo* info) { duke@435: jobject2reg_with_patching(klass_reg, klass, info); duke@435: // If klass is not loaded we do not know if the klass has finalizers: duke@435: if (UseFastNewInstance && klass->is_loaded() duke@435: && !Klass::layout_helper_needs_slow_path(klass->layout_helper())) { duke@435: duke@435: Runtime1::StubID stub_id = klass->is_initialized() ? Runtime1::fast_new_instance_id : Runtime1::fast_new_instance_init_check_id; duke@435: duke@435: CodeStub* slow_path = new NewInstanceStub(klass_reg, dst, klass, info, stub_id); duke@435: duke@435: assert(klass->is_loaded(), "must be loaded"); duke@435: // allocate space for instance duke@435: assert(klass->size_helper() >= 0, "illegal instance size"); duke@435: const int instance_size = align_object_size(klass->size_helper()); duke@435: __ allocate_object(dst, scratch1, scratch2, scratch3, scratch4, duke@435: oopDesc::header_size(), instance_size, klass_reg, !klass->is_initialized(), slow_path); duke@435: } else { duke@435: CodeStub* slow_path = new NewInstanceStub(klass_reg, dst, klass, info, Runtime1::new_instance_id); duke@435: __ branch(lir_cond_always, T_ILLEGAL, slow_path); duke@435: __ branch_destination(slow_path->continuation()); duke@435: } duke@435: } duke@435: duke@435: duke@435: static bool is_constant_zero(Instruction* inst) { duke@435: IntConstant* c = inst->type()->as_IntConstant(); duke@435: if (c) { duke@435: return (c->value() == 0); duke@435: } duke@435: return false; duke@435: } duke@435: duke@435: duke@435: static bool positive_constant(Instruction* inst) { duke@435: IntConstant* c = inst->type()->as_IntConstant(); duke@435: if (c) { duke@435: return (c->value() >= 0); duke@435: } duke@435: return false; duke@435: } duke@435: duke@435: duke@435: static ciArrayKlass* as_array_klass(ciType* type) { duke@435: if (type != NULL && type->is_array_klass() && type->is_loaded()) { duke@435: return (ciArrayKlass*)type; duke@435: } else { duke@435: return NULL; duke@435: } duke@435: } duke@435: duke@435: void LIRGenerator::arraycopy_helper(Intrinsic* x, int* flagsp, ciArrayKlass** expected_typep) { duke@435: Instruction* src = x->argument_at(0); duke@435: Instruction* src_pos = x->argument_at(1); duke@435: Instruction* dst = x->argument_at(2); duke@435: Instruction* dst_pos = x->argument_at(3); duke@435: Instruction* length = x->argument_at(4); duke@435: duke@435: // first try to identify the likely type of the arrays involved duke@435: ciArrayKlass* expected_type = NULL; duke@435: bool is_exact = false; duke@435: { duke@435: ciArrayKlass* src_exact_type = as_array_klass(src->exact_type()); duke@435: ciArrayKlass* src_declared_type = as_array_klass(src->declared_type()); duke@435: ciArrayKlass* dst_exact_type = as_array_klass(dst->exact_type()); duke@435: ciArrayKlass* dst_declared_type = as_array_klass(dst->declared_type()); duke@435: if (src_exact_type != NULL && src_exact_type == dst_exact_type) { duke@435: // the types exactly match so the type is fully known duke@435: is_exact = true; duke@435: expected_type = src_exact_type; duke@435: } else if (dst_exact_type != NULL && dst_exact_type->is_obj_array_klass()) { duke@435: ciArrayKlass* dst_type = (ciArrayKlass*) dst_exact_type; duke@435: ciArrayKlass* src_type = NULL; duke@435: if (src_exact_type != NULL && src_exact_type->is_obj_array_klass()) { duke@435: src_type = (ciArrayKlass*) src_exact_type; duke@435: } else if (src_declared_type != NULL && src_declared_type->is_obj_array_klass()) { duke@435: src_type = (ciArrayKlass*) src_declared_type; duke@435: } duke@435: if (src_type != NULL) { duke@435: if (src_type->element_type()->is_subtype_of(dst_type->element_type())) { duke@435: is_exact = true; duke@435: expected_type = dst_type; duke@435: } duke@435: } duke@435: } duke@435: // at least pass along a good guess duke@435: if (expected_type == NULL) expected_type = dst_exact_type; duke@435: if (expected_type == NULL) expected_type = src_declared_type; duke@435: if (expected_type == NULL) expected_type = dst_declared_type; duke@435: } duke@435: duke@435: // if a probable array type has been identified, figure out if any duke@435: // of the required checks for a fast case can be elided. duke@435: int flags = LIR_OpArrayCopy::all_flags; duke@435: if (expected_type != NULL) { duke@435: // try to skip null checks duke@435: if (src->as_NewArray() != NULL) duke@435: flags &= ~LIR_OpArrayCopy::src_null_check; duke@435: if (dst->as_NewArray() != NULL) duke@435: flags &= ~LIR_OpArrayCopy::dst_null_check; duke@435: duke@435: // check from incoming constant values duke@435: if (positive_constant(src_pos)) duke@435: flags &= ~LIR_OpArrayCopy::src_pos_positive_check; duke@435: if (positive_constant(dst_pos)) duke@435: flags &= ~LIR_OpArrayCopy::dst_pos_positive_check; duke@435: if (positive_constant(length)) duke@435: flags &= ~LIR_OpArrayCopy::length_positive_check; duke@435: duke@435: // see if the range check can be elided, which might also imply duke@435: // that src or dst is non-null. duke@435: ArrayLength* al = length->as_ArrayLength(); duke@435: if (al != NULL) { duke@435: if (al->array() == src) { duke@435: // it's the length of the source array duke@435: flags &= ~LIR_OpArrayCopy::length_positive_check; duke@435: flags &= ~LIR_OpArrayCopy::src_null_check; duke@435: if (is_constant_zero(src_pos)) duke@435: flags &= ~LIR_OpArrayCopy::src_range_check; duke@435: } duke@435: if (al->array() == dst) { duke@435: // it's the length of the destination array duke@435: flags &= ~LIR_OpArrayCopy::length_positive_check; duke@435: flags &= ~LIR_OpArrayCopy::dst_null_check; duke@435: if (is_constant_zero(dst_pos)) duke@435: flags &= ~LIR_OpArrayCopy::dst_range_check; duke@435: } duke@435: } duke@435: if (is_exact) { duke@435: flags &= ~LIR_OpArrayCopy::type_check; duke@435: } duke@435: } duke@435: duke@435: if (src == dst) { duke@435: // moving within a single array so no type checks are needed duke@435: if (flags & LIR_OpArrayCopy::type_check) { duke@435: flags &= ~LIR_OpArrayCopy::type_check; duke@435: } duke@435: } duke@435: *flagsp = flags; duke@435: *expected_typep = (ciArrayKlass*)expected_type; duke@435: } duke@435: duke@435: duke@435: LIR_Opr LIRGenerator::round_item(LIR_Opr opr) { duke@435: assert(opr->is_register(), "why spill if item is not register?"); duke@435: duke@435: if (RoundFPResults && UseSSE < 1 && opr->is_single_fpu()) { duke@435: LIR_Opr result = new_register(T_FLOAT); duke@435: set_vreg_flag(result, must_start_in_memory); duke@435: assert(opr->is_register(), "only a register can be spilled"); duke@435: assert(opr->value_type()->is_float(), "rounding only for floats available"); duke@435: __ roundfp(opr, LIR_OprFact::illegalOpr, result); duke@435: return result; duke@435: } duke@435: return opr; duke@435: } duke@435: duke@435: duke@435: LIR_Opr LIRGenerator::force_to_spill(LIR_Opr value, BasicType t) { duke@435: assert(type2size[t] == type2size[value->type()], "size mismatch"); duke@435: if (!value->is_register()) { duke@435: // force into a register duke@435: LIR_Opr r = new_register(value->type()); duke@435: __ move(value, r); duke@435: value = r; duke@435: } duke@435: duke@435: // create a spill location duke@435: LIR_Opr tmp = new_register(t); duke@435: set_vreg_flag(tmp, LIRGenerator::must_start_in_memory); duke@435: duke@435: // move from register to spill duke@435: __ move(value, tmp); duke@435: return tmp; duke@435: } duke@435: duke@435: duke@435: void LIRGenerator::profile_branch(If* if_instr, If::Condition cond) { duke@435: if (if_instr->should_profile()) { duke@435: ciMethod* method = if_instr->profiled_method(); duke@435: assert(method != NULL, "method should be set if branch is profiled"); duke@435: ciMethodData* md = method->method_data(); duke@435: if (md == NULL) { duke@435: bailout("out of memory building methodDataOop"); duke@435: return; duke@435: } duke@435: ciProfileData* data = md->bci_to_data(if_instr->profiled_bci()); duke@435: assert(data != NULL, "must have profiling data"); duke@435: assert(data->is_BranchData(), "need BranchData for two-way branches"); duke@435: int taken_count_offset = md->byte_offset_of_slot(data, BranchData::taken_offset()); duke@435: int not_taken_count_offset = md->byte_offset_of_slot(data, BranchData::not_taken_offset()); duke@435: LIR_Opr md_reg = new_register(T_OBJECT); duke@435: __ move(LIR_OprFact::oopConst(md->encoding()), md_reg); duke@435: LIR_Opr data_offset_reg = new_register(T_INT); duke@435: __ cmove(lir_cond(cond), duke@435: LIR_OprFact::intConst(taken_count_offset), duke@435: LIR_OprFact::intConst(not_taken_count_offset), duke@435: data_offset_reg); duke@435: LIR_Opr data_reg = new_register(T_INT); duke@435: LIR_Address* data_addr = new LIR_Address(md_reg, data_offset_reg, T_INT); duke@435: __ move(LIR_OprFact::address(data_addr), data_reg); duke@435: LIR_Address* fake_incr_value = new LIR_Address(data_reg, DataLayout::counter_increment, T_INT); duke@435: // Use leal instead of add to avoid destroying condition codes on x86 duke@435: __ leal(LIR_OprFact::address(fake_incr_value), data_reg); duke@435: __ move(data_reg, LIR_OprFact::address(data_addr)); duke@435: } duke@435: } duke@435: duke@435: duke@435: // Phi technique: duke@435: // This is about passing live values from one basic block to the other. duke@435: // In code generated with Java it is rather rare that more than one duke@435: // value is on the stack from one basic block to the other. duke@435: // We optimize our technique for efficient passing of one value duke@435: // (of type long, int, double..) but it can be extended. duke@435: // When entering or leaving a basic block, all registers and all spill duke@435: // slots are release and empty. We use the released registers duke@435: // and spill slots to pass the live values from one block duke@435: // to the other. The topmost value, i.e., the value on TOS of expression duke@435: // stack is passed in registers. All other values are stored in spilling duke@435: // area. Every Phi has an index which designates its spill slot duke@435: // At exit of a basic block, we fill the register(s) and spill slots. duke@435: // At entry of a basic block, the block_prolog sets up the content of phi nodes duke@435: // and locks necessary registers and spilling slots. duke@435: duke@435: duke@435: // move current value to referenced phi function duke@435: void LIRGenerator::move_to_phi(PhiResolver* resolver, Value cur_val, Value sux_val) { duke@435: Phi* phi = sux_val->as_Phi(); duke@435: // cur_val can be null without phi being null in conjunction with inlining duke@435: if (phi != NULL && cur_val != NULL && cur_val != phi && !phi->is_illegal()) { duke@435: LIR_Opr operand = cur_val->operand(); duke@435: if (cur_val->operand()->is_illegal()) { duke@435: assert(cur_val->as_Constant() != NULL || cur_val->as_Local() != NULL, duke@435: "these can be produced lazily"); duke@435: operand = operand_for_instruction(cur_val); duke@435: } duke@435: resolver->move(operand, operand_for_instruction(phi)); duke@435: } duke@435: } duke@435: duke@435: duke@435: // Moves all stack values into their PHI position duke@435: void LIRGenerator::move_to_phi(ValueStack* cur_state) { duke@435: BlockBegin* bb = block(); duke@435: if (bb->number_of_sux() == 1) { duke@435: BlockBegin* sux = bb->sux_at(0); duke@435: assert(sux->number_of_preds() > 0, "invalid CFG"); duke@435: duke@435: // a block with only one predecessor never has phi functions duke@435: if (sux->number_of_preds() > 1) { duke@435: int max_phis = cur_state->stack_size() + cur_state->locals_size(); duke@435: PhiResolver resolver(this, _virtual_register_number + max_phis * 2); duke@435: duke@435: ValueStack* sux_state = sux->state(); duke@435: Value sux_value; duke@435: int index; duke@435: duke@435: for_each_stack_value(sux_state, index, sux_value) { duke@435: move_to_phi(&resolver, cur_state->stack_at(index), sux_value); duke@435: } duke@435: duke@435: // Inlining may cause the local state not to match up, so walk up duke@435: // the caller state until we get to the same scope as the duke@435: // successor and then start processing from there. duke@435: while (cur_state->scope() != sux_state->scope()) { duke@435: cur_state = cur_state->caller_state(); duke@435: assert(cur_state != NULL, "scopes don't match up"); duke@435: } duke@435: duke@435: for_each_local_value(sux_state, index, sux_value) { duke@435: move_to_phi(&resolver, cur_state->local_at(index), sux_value); duke@435: } duke@435: duke@435: assert(cur_state->caller_state() == sux_state->caller_state(), "caller states must be equal"); duke@435: } duke@435: } duke@435: } duke@435: duke@435: duke@435: LIR_Opr LIRGenerator::new_register(BasicType type) { duke@435: int vreg = _virtual_register_number; duke@435: // add a little fudge factor for the bailout, since the bailout is duke@435: // only checked periodically. This gives a few extra registers to duke@435: // hand out before we really run out, which helps us keep from duke@435: // tripping over assertions. duke@435: if (vreg + 20 >= LIR_OprDesc::vreg_max) { duke@435: bailout("out of virtual registers"); duke@435: if (vreg + 2 >= LIR_OprDesc::vreg_max) { duke@435: // wrap it around duke@435: _virtual_register_number = LIR_OprDesc::vreg_base; duke@435: } duke@435: } duke@435: _virtual_register_number += 1; duke@435: if (type == T_ADDRESS) type = T_INT; duke@435: return LIR_OprFact::virtual_register(vreg, type); duke@435: } duke@435: duke@435: duke@435: // Try to lock using register in hint duke@435: LIR_Opr LIRGenerator::rlock(Value instr) { duke@435: return new_register(instr->type()); duke@435: } duke@435: duke@435: duke@435: // does an rlock and sets result duke@435: LIR_Opr LIRGenerator::rlock_result(Value x) { duke@435: LIR_Opr reg = rlock(x); duke@435: set_result(x, reg); duke@435: return reg; duke@435: } duke@435: duke@435: duke@435: // does an rlock and sets result duke@435: LIR_Opr LIRGenerator::rlock_result(Value x, BasicType type) { duke@435: LIR_Opr reg; duke@435: switch (type) { duke@435: case T_BYTE: duke@435: case T_BOOLEAN: duke@435: reg = rlock_byte(type); duke@435: break; duke@435: default: duke@435: reg = rlock(x); duke@435: break; duke@435: } duke@435: duke@435: set_result(x, reg); duke@435: return reg; duke@435: } duke@435: duke@435: duke@435: //--------------------------------------------------------------------- duke@435: ciObject* LIRGenerator::get_jobject_constant(Value value) { duke@435: ObjectType* oc = value->type()->as_ObjectType(); duke@435: if (oc) { duke@435: return oc->constant_value(); duke@435: } duke@435: return NULL; duke@435: } duke@435: duke@435: duke@435: void LIRGenerator::do_ExceptionObject(ExceptionObject* x) { duke@435: assert(block()->is_set(BlockBegin::exception_entry_flag), "ExceptionObject only allowed in exception handler block"); duke@435: assert(block()->next() == x, "ExceptionObject must be first instruction of block"); duke@435: duke@435: // no moves are created for phi functions at the begin of exception duke@435: // handlers, so assign operands manually here duke@435: for_each_phi_fun(block(), phi, duke@435: operand_for_instruction(phi)); duke@435: duke@435: LIR_Opr thread_reg = getThreadPointer(); duke@435: __ move(new LIR_Address(thread_reg, in_bytes(JavaThread::exception_oop_offset()), T_OBJECT), duke@435: exceptionOopOpr()); duke@435: __ move(LIR_OprFact::oopConst(NULL), duke@435: new LIR_Address(thread_reg, in_bytes(JavaThread::exception_oop_offset()), T_OBJECT)); duke@435: __ move(LIR_OprFact::oopConst(NULL), duke@435: new LIR_Address(thread_reg, in_bytes(JavaThread::exception_pc_offset()), T_OBJECT)); duke@435: duke@435: LIR_Opr result = new_register(T_OBJECT); duke@435: __ move(exceptionOopOpr(), result); duke@435: set_result(x, result); duke@435: } duke@435: duke@435: duke@435: //---------------------------------------------------------------------- duke@435: //---------------------------------------------------------------------- duke@435: //---------------------------------------------------------------------- duke@435: //---------------------------------------------------------------------- duke@435: // visitor functions duke@435: //---------------------------------------------------------------------- duke@435: //---------------------------------------------------------------------- duke@435: //---------------------------------------------------------------------- duke@435: //---------------------------------------------------------------------- duke@435: duke@435: void LIRGenerator::do_Phi(Phi* x) { duke@435: // phi functions are never visited directly duke@435: ShouldNotReachHere(); duke@435: } duke@435: duke@435: duke@435: // Code for a constant is generated lazily unless the constant is frequently used and can't be inlined. duke@435: void LIRGenerator::do_Constant(Constant* x) { duke@435: if (x->state() != NULL) { duke@435: // Any constant with a ValueStack requires patching so emit the patch here duke@435: LIR_Opr reg = rlock_result(x); duke@435: CodeEmitInfo* info = state_for(x, x->state()); duke@435: __ oop2reg_patch(NULL, reg, info); duke@435: } else if (x->use_count() > 1 && !can_inline_as_constant(x)) { duke@435: if (!x->is_pinned()) { duke@435: // unpinned constants are handled specially so that they can be duke@435: // put into registers when they are used multiple times within a duke@435: // block. After the block completes their operand will be duke@435: // cleared so that other blocks can't refer to that register. duke@435: set_result(x, load_constant(x)); duke@435: } else { duke@435: LIR_Opr res = x->operand(); duke@435: if (!res->is_valid()) { duke@435: res = LIR_OprFact::value_type(x->type()); duke@435: } duke@435: if (res->is_constant()) { duke@435: LIR_Opr reg = rlock_result(x); duke@435: __ move(res, reg); duke@435: } else { duke@435: set_result(x, res); duke@435: } duke@435: } duke@435: } else { duke@435: set_result(x, LIR_OprFact::value_type(x->type())); duke@435: } duke@435: } duke@435: duke@435: duke@435: void LIRGenerator::do_Local(Local* x) { duke@435: // operand_for_instruction has the side effect of setting the result duke@435: // so there's no need to do it here. duke@435: operand_for_instruction(x); duke@435: } duke@435: duke@435: duke@435: void LIRGenerator::do_IfInstanceOf(IfInstanceOf* x) { duke@435: Unimplemented(); duke@435: } duke@435: duke@435: duke@435: void LIRGenerator::do_Return(Return* x) { duke@435: if (DTraceMethodProbes) { duke@435: BasicTypeList signature; duke@435: signature.append(T_INT); // thread duke@435: signature.append(T_OBJECT); // methodOop duke@435: LIR_OprList* args = new LIR_OprList(); duke@435: args->append(getThreadPointer()); duke@435: LIR_Opr meth = new_register(T_OBJECT); duke@435: __ oop2reg(method()->encoding(), meth); duke@435: args->append(meth); duke@435: call_runtime(&signature, args, CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_exit), voidType, NULL); duke@435: } duke@435: duke@435: if (x->type()->is_void()) { duke@435: __ return_op(LIR_OprFact::illegalOpr); duke@435: } else { duke@435: LIR_Opr reg = result_register_for(x->type(), /*callee=*/true); duke@435: LIRItem result(x->result(), this); duke@435: duke@435: result.load_item_force(reg); duke@435: __ return_op(result.result()); duke@435: } duke@435: set_no_result(x); duke@435: } duke@435: duke@435: duke@435: // Example: object.getClass () duke@435: void LIRGenerator::do_getClass(Intrinsic* x) { duke@435: assert(x->number_of_arguments() == 1, "wrong type"); duke@435: duke@435: LIRItem rcvr(x->argument_at(0), this); duke@435: rcvr.load_item(); duke@435: LIR_Opr result = rlock_result(x); duke@435: duke@435: // need to perform the null check on the rcvr duke@435: CodeEmitInfo* info = NULL; duke@435: if (x->needs_null_check()) { duke@435: info = state_for(x, x->state()->copy_locks()); duke@435: } duke@435: __ move(new LIR_Address(rcvr.result(), oopDesc::klass_offset_in_bytes(), T_OBJECT), result, info); duke@435: __ move(new LIR_Address(result, Klass::java_mirror_offset_in_bytes() + duke@435: klassOopDesc::klass_part_offset_in_bytes(), T_OBJECT), result); duke@435: } duke@435: duke@435: duke@435: // Example: Thread.currentThread() duke@435: void LIRGenerator::do_currentThread(Intrinsic* x) { duke@435: assert(x->number_of_arguments() == 0, "wrong type"); duke@435: LIR_Opr reg = rlock_result(x); duke@435: __ load(new LIR_Address(getThreadPointer(), in_bytes(JavaThread::threadObj_offset()), T_OBJECT), reg); duke@435: } duke@435: duke@435: duke@435: void LIRGenerator::do_RegisterFinalizer(Intrinsic* x) { duke@435: assert(x->number_of_arguments() == 1, "wrong type"); duke@435: LIRItem receiver(x->argument_at(0), this); duke@435: duke@435: receiver.load_item(); duke@435: BasicTypeList signature; duke@435: signature.append(T_OBJECT); // receiver duke@435: LIR_OprList* args = new LIR_OprList(); duke@435: args->append(receiver.result()); duke@435: CodeEmitInfo* info = state_for(x, x->state()); duke@435: call_runtime(&signature, args, duke@435: CAST_FROM_FN_PTR(address, Runtime1::entry_for(Runtime1::register_finalizer_id)), duke@435: voidType, info); duke@435: duke@435: set_no_result(x); duke@435: } duke@435: duke@435: duke@435: //------------------------local access-------------------------------------- duke@435: duke@435: LIR_Opr LIRGenerator::operand_for_instruction(Instruction* x) { duke@435: if (x->operand()->is_illegal()) { duke@435: Constant* c = x->as_Constant(); duke@435: if (c != NULL) { duke@435: x->set_operand(LIR_OprFact::value_type(c->type())); duke@435: } else { duke@435: assert(x->as_Phi() || x->as_Local() != NULL, "only for Phi and Local"); duke@435: // allocate a virtual register for this local or phi duke@435: x->set_operand(rlock(x)); duke@435: _instruction_for_operand.at_put_grow(x->operand()->vreg_number(), x, NULL); duke@435: } duke@435: } duke@435: return x->operand(); duke@435: } duke@435: duke@435: duke@435: Instruction* LIRGenerator::instruction_for_opr(LIR_Opr opr) { duke@435: if (opr->is_virtual()) { duke@435: return instruction_for_vreg(opr->vreg_number()); duke@435: } duke@435: return NULL; duke@435: } duke@435: duke@435: duke@435: Instruction* LIRGenerator::instruction_for_vreg(int reg_num) { duke@435: if (reg_num < _instruction_for_operand.length()) { duke@435: return _instruction_for_operand.at(reg_num); duke@435: } duke@435: return NULL; duke@435: } duke@435: duke@435: duke@435: void LIRGenerator::set_vreg_flag(int vreg_num, VregFlag f) { duke@435: if (_vreg_flags.size_in_bits() == 0) { duke@435: BitMap2D temp(100, num_vreg_flags); duke@435: temp.clear(); duke@435: _vreg_flags = temp; duke@435: } duke@435: _vreg_flags.at_put_grow(vreg_num, f, true); duke@435: } duke@435: duke@435: bool LIRGenerator::is_vreg_flag_set(int vreg_num, VregFlag f) { duke@435: if (!_vreg_flags.is_valid_index(vreg_num, f)) { duke@435: return false; duke@435: } duke@435: return _vreg_flags.at(vreg_num, f); duke@435: } duke@435: duke@435: duke@435: // Block local constant handling. This code is useful for keeping duke@435: // unpinned constants and constants which aren't exposed in the IR in duke@435: // registers. Unpinned Constant instructions have their operands duke@435: // cleared when the block is finished so that other blocks can't end duke@435: // up referring to their registers. duke@435: duke@435: LIR_Opr LIRGenerator::load_constant(Constant* x) { duke@435: assert(!x->is_pinned(), "only for unpinned constants"); duke@435: _unpinned_constants.append(x); duke@435: return load_constant(LIR_OprFact::value_type(x->type())->as_constant_ptr()); duke@435: } duke@435: duke@435: duke@435: LIR_Opr LIRGenerator::load_constant(LIR_Const* c) { duke@435: BasicType t = c->type(); duke@435: for (int i = 0; i < _constants.length(); i++) { duke@435: LIR_Const* other = _constants.at(i); duke@435: if (t == other->type()) { duke@435: switch (t) { duke@435: case T_INT: duke@435: case T_FLOAT: duke@435: if (c->as_jint_bits() != other->as_jint_bits()) continue; duke@435: break; duke@435: case T_LONG: duke@435: case T_DOUBLE: duke@435: if (c->as_jint_hi_bits() != other->as_jint_lo_bits()) continue; duke@435: if (c->as_jint_lo_bits() != other->as_jint_hi_bits()) continue; duke@435: break; duke@435: case T_OBJECT: duke@435: if (c->as_jobject() != other->as_jobject()) continue; duke@435: break; duke@435: } duke@435: return _reg_for_constants.at(i); duke@435: } duke@435: } duke@435: duke@435: LIR_Opr result = new_register(t); duke@435: __ move((LIR_Opr)c, result); duke@435: _constants.append(c); duke@435: _reg_for_constants.append(result); duke@435: return result; duke@435: } duke@435: duke@435: // Various barriers duke@435: duke@435: void LIRGenerator::post_barrier(LIR_OprDesc* addr, LIR_OprDesc* new_val) { duke@435: switch (Universe::heap()->barrier_set()->kind()) { duke@435: case BarrierSet::CardTableModRef: duke@435: case BarrierSet::CardTableExtension: duke@435: CardTableModRef_post_barrier(addr, new_val); duke@435: break; duke@435: case BarrierSet::ModRef: duke@435: case BarrierSet::Other: duke@435: // No post barriers duke@435: break; duke@435: default : duke@435: ShouldNotReachHere(); duke@435: } duke@435: } duke@435: duke@435: void LIRGenerator::CardTableModRef_post_barrier(LIR_OprDesc* addr, LIR_OprDesc* new_val) { duke@435: duke@435: BarrierSet* bs = Universe::heap()->barrier_set(); duke@435: assert(sizeof(*((CardTableModRefBS*)bs)->byte_map_base) == sizeof(jbyte), "adjust this code"); duke@435: LIR_Const* card_table_base = new LIR_Const(((CardTableModRefBS*)bs)->byte_map_base); duke@435: if (addr->is_address()) { duke@435: LIR_Address* address = addr->as_address_ptr(); duke@435: LIR_Opr ptr = new_register(T_OBJECT); duke@435: if (!address->index()->is_valid() && address->disp() == 0) { duke@435: __ move(address->base(), ptr); duke@435: } else { duke@435: assert(address->disp() != max_jint, "lea doesn't support patched addresses!"); duke@435: __ leal(addr, ptr); duke@435: } duke@435: addr = ptr; duke@435: } duke@435: assert(addr->is_register(), "must be a register at this point"); duke@435: duke@435: LIR_Opr tmp = new_pointer_register(); duke@435: if (TwoOperandLIRForm) { duke@435: __ move(addr, tmp); duke@435: __ unsigned_shift_right(tmp, CardTableModRefBS::card_shift, tmp); duke@435: } else { duke@435: __ unsigned_shift_right(addr, CardTableModRefBS::card_shift, tmp); duke@435: } duke@435: if (can_inline_as_constant(card_table_base)) { duke@435: __ move(LIR_OprFact::intConst(0), duke@435: new LIR_Address(tmp, card_table_base->as_jint(), T_BYTE)); duke@435: } else { duke@435: __ move(LIR_OprFact::intConst(0), duke@435: new LIR_Address(tmp, load_constant(card_table_base), duke@435: T_BYTE)); duke@435: } duke@435: } duke@435: duke@435: duke@435: //------------------------field access-------------------------------------- duke@435: duke@435: // Comment copied form templateTable_i486.cpp duke@435: // ---------------------------------------------------------------------------- duke@435: // Volatile variables demand their effects be made known to all CPU's in duke@435: // order. Store buffers on most chips allow reads & writes to reorder; the duke@435: // JMM's ReadAfterWrite.java test fails in -Xint mode without some kind of duke@435: // memory barrier (i.e., it's not sufficient that the interpreter does not duke@435: // reorder volatile references, the hardware also must not reorder them). duke@435: // duke@435: // According to the new Java Memory Model (JMM): duke@435: // (1) All volatiles are serialized wrt to each other. duke@435: // ALSO reads & writes act as aquire & release, so: duke@435: // (2) A read cannot let unrelated NON-volatile memory refs that happen after duke@435: // the read float up to before the read. It's OK for non-volatile memory refs duke@435: // that happen before the volatile read to float down below it. duke@435: // (3) Similar a volatile write cannot let unrelated NON-volatile memory refs duke@435: // that happen BEFORE the write float down to after the write. It's OK for duke@435: // non-volatile memory refs that happen after the volatile write to float up duke@435: // before it. duke@435: // duke@435: // We only put in barriers around volatile refs (they are expensive), not duke@435: // _between_ memory refs (that would require us to track the flavor of the duke@435: // previous memory refs). Requirements (2) and (3) require some barriers duke@435: // before volatile stores and after volatile loads. These nearly cover duke@435: // requirement (1) but miss the volatile-store-volatile-load case. This final duke@435: // case is placed after volatile-stores although it could just as well go duke@435: // before volatile-loads. duke@435: duke@435: duke@435: void LIRGenerator::do_StoreField(StoreField* x) { duke@435: bool needs_patching = x->needs_patching(); duke@435: bool is_volatile = x->field()->is_volatile(); duke@435: BasicType field_type = x->field_type(); duke@435: bool is_oop = (field_type == T_ARRAY || field_type == T_OBJECT); duke@435: duke@435: CodeEmitInfo* info = NULL; duke@435: if (needs_patching) { duke@435: assert(x->explicit_null_check() == NULL, "can't fold null check into patching field access"); duke@435: info = state_for(x, x->state_before()); duke@435: } else if (x->needs_null_check()) { duke@435: NullCheck* nc = x->explicit_null_check(); duke@435: if (nc == NULL) { duke@435: info = state_for(x, x->lock_stack()); duke@435: } else { duke@435: info = state_for(nc); duke@435: } duke@435: } duke@435: duke@435: duke@435: LIRItem object(x->obj(), this); duke@435: LIRItem value(x->value(), this); duke@435: duke@435: object.load_item(); duke@435: duke@435: if (is_volatile || needs_patching) { duke@435: // load item if field is volatile (fewer special cases for volatiles) duke@435: // load item if field not initialized duke@435: // load item if field not constant duke@435: // because of code patching we cannot inline constants duke@435: if (field_type == T_BYTE || field_type == T_BOOLEAN) { duke@435: value.load_byte_item(); duke@435: } else { duke@435: value.load_item(); duke@435: } duke@435: } else { duke@435: value.load_for_store(field_type); duke@435: } duke@435: duke@435: set_no_result(x); duke@435: duke@435: if (PrintNotLoaded && needs_patching) { duke@435: tty->print_cr(" ###class not loaded at store_%s bci %d", duke@435: x->is_static() ? "static" : "field", x->bci()); duke@435: } duke@435: duke@435: if (x->needs_null_check() && duke@435: (needs_patching || duke@435: MacroAssembler::needs_explicit_null_check(x->offset()))) { duke@435: // emit an explicit null check because the offset is too large duke@435: __ null_check(object.result(), new CodeEmitInfo(info)); duke@435: } duke@435: duke@435: LIR_Address* address; duke@435: if (needs_patching) { duke@435: // we need to patch the offset in the instruction so don't allow duke@435: // generate_address to try to be smart about emitting the -1. duke@435: // Otherwise the patching code won't know how to find the duke@435: // instruction to patch. duke@435: address = new LIR_Address(object.result(), max_jint, field_type); duke@435: } else { duke@435: address = generate_address(object.result(), x->offset(), field_type); duke@435: } duke@435: duke@435: if (is_volatile && os::is_MP()) { duke@435: __ membar_release(); duke@435: } duke@435: duke@435: if (is_volatile) { duke@435: assert(!needs_patching && x->is_loaded(), duke@435: "how do we know it's volatile if it's not loaded"); duke@435: volatile_field_store(value.result(), address, info); duke@435: } else { duke@435: LIR_PatchCode patch_code = needs_patching ? lir_patch_normal : lir_patch_none; duke@435: __ store(value.result(), address, info, patch_code); duke@435: } duke@435: duke@435: if (is_oop) { duke@435: post_barrier(object.result(), value.result()); duke@435: } duke@435: duke@435: if (is_volatile && os::is_MP()) { duke@435: __ membar(); duke@435: } duke@435: } duke@435: duke@435: duke@435: void LIRGenerator::do_LoadField(LoadField* x) { duke@435: bool needs_patching = x->needs_patching(); duke@435: bool is_volatile = x->field()->is_volatile(); duke@435: BasicType field_type = x->field_type(); duke@435: duke@435: CodeEmitInfo* info = NULL; duke@435: if (needs_patching) { duke@435: assert(x->explicit_null_check() == NULL, "can't fold null check into patching field access"); duke@435: info = state_for(x, x->state_before()); duke@435: } else if (x->needs_null_check()) { duke@435: NullCheck* nc = x->explicit_null_check(); duke@435: if (nc == NULL) { duke@435: info = state_for(x, x->lock_stack()); duke@435: } else { duke@435: info = state_for(nc); duke@435: } duke@435: } duke@435: duke@435: LIRItem object(x->obj(), this); duke@435: duke@435: object.load_item(); duke@435: duke@435: if (PrintNotLoaded && needs_patching) { duke@435: tty->print_cr(" ###class not loaded at load_%s bci %d", duke@435: x->is_static() ? "static" : "field", x->bci()); duke@435: } duke@435: duke@435: if (x->needs_null_check() && duke@435: (needs_patching || duke@435: MacroAssembler::needs_explicit_null_check(x->offset()))) { duke@435: // emit an explicit null check because the offset is too large duke@435: __ null_check(object.result(), new CodeEmitInfo(info)); duke@435: } duke@435: duke@435: LIR_Opr reg = rlock_result(x, field_type); duke@435: LIR_Address* address; duke@435: if (needs_patching) { duke@435: // we need to patch the offset in the instruction so don't allow duke@435: // generate_address to try to be smart about emitting the -1. duke@435: // Otherwise the patching code won't know how to find the duke@435: // instruction to patch. duke@435: address = new LIR_Address(object.result(), max_jint, field_type); duke@435: } else { duke@435: address = generate_address(object.result(), x->offset(), field_type); duke@435: } duke@435: duke@435: if (is_volatile) { duke@435: assert(!needs_patching && x->is_loaded(), duke@435: "how do we know it's volatile if it's not loaded"); duke@435: volatile_field_load(address, reg, info); duke@435: } else { duke@435: LIR_PatchCode patch_code = needs_patching ? lir_patch_normal : lir_patch_none; duke@435: __ load(address, reg, info, patch_code); duke@435: } duke@435: duke@435: if (is_volatile && os::is_MP()) { duke@435: __ membar_acquire(); duke@435: } duke@435: } duke@435: duke@435: duke@435: //------------------------java.nio.Buffer.checkIndex------------------------ duke@435: duke@435: // int java.nio.Buffer.checkIndex(int) duke@435: void LIRGenerator::do_NIOCheckIndex(Intrinsic* x) { duke@435: // NOTE: by the time we are in checkIndex() we are guaranteed that duke@435: // the buffer is non-null (because checkIndex is package-private and duke@435: // only called from within other methods in the buffer). duke@435: assert(x->number_of_arguments() == 2, "wrong type"); duke@435: LIRItem buf (x->argument_at(0), this); duke@435: LIRItem index(x->argument_at(1), this); duke@435: buf.load_item(); duke@435: index.load_item(); duke@435: duke@435: LIR_Opr result = rlock_result(x); duke@435: if (GenerateRangeChecks) { duke@435: CodeEmitInfo* info = state_for(x); duke@435: CodeStub* stub = new RangeCheckStub(info, index.result(), true); duke@435: if (index.result()->is_constant()) { duke@435: cmp_mem_int(lir_cond_belowEqual, buf.result(), java_nio_Buffer::limit_offset(), index.result()->as_jint(), info); duke@435: __ branch(lir_cond_belowEqual, T_INT, stub); duke@435: } else { duke@435: cmp_reg_mem(lir_cond_aboveEqual, index.result(), buf.result(), duke@435: java_nio_Buffer::limit_offset(), T_INT, info); duke@435: __ branch(lir_cond_aboveEqual, T_INT, stub); duke@435: } duke@435: __ move(index.result(), result); duke@435: } else { duke@435: // Just load the index into the result register duke@435: __ move(index.result(), result); duke@435: } duke@435: } duke@435: duke@435: duke@435: //------------------------array access-------------------------------------- duke@435: duke@435: duke@435: void LIRGenerator::do_ArrayLength(ArrayLength* x) { duke@435: LIRItem array(x->array(), this); duke@435: array.load_item(); duke@435: LIR_Opr reg = rlock_result(x); duke@435: duke@435: CodeEmitInfo* info = NULL; duke@435: if (x->needs_null_check()) { duke@435: NullCheck* nc = x->explicit_null_check(); duke@435: if (nc == NULL) { duke@435: info = state_for(x); duke@435: } else { duke@435: info = state_for(nc); duke@435: } duke@435: } duke@435: __ load(new LIR_Address(array.result(), arrayOopDesc::length_offset_in_bytes(), T_INT), reg, info, lir_patch_none); duke@435: } duke@435: duke@435: duke@435: void LIRGenerator::do_LoadIndexed(LoadIndexed* x) { duke@435: bool use_length = x->length() != NULL; duke@435: LIRItem array(x->array(), this); duke@435: LIRItem index(x->index(), this); duke@435: LIRItem length(this); duke@435: bool needs_range_check = true; duke@435: duke@435: if (use_length) { duke@435: needs_range_check = x->compute_needs_range_check(); duke@435: if (needs_range_check) { duke@435: length.set_instruction(x->length()); duke@435: length.load_item(); duke@435: } duke@435: } duke@435: duke@435: array.load_item(); duke@435: if (index.is_constant() && can_inline_as_constant(x->index())) { duke@435: // let it be a constant duke@435: index.dont_load_item(); duke@435: } else { duke@435: index.load_item(); duke@435: } duke@435: duke@435: CodeEmitInfo* range_check_info = state_for(x); duke@435: CodeEmitInfo* null_check_info = NULL; duke@435: if (x->needs_null_check()) { duke@435: NullCheck* nc = x->explicit_null_check(); duke@435: if (nc != NULL) { duke@435: null_check_info = state_for(nc); duke@435: } else { duke@435: null_check_info = range_check_info; duke@435: } duke@435: } duke@435: duke@435: // emit array address setup early so it schedules better duke@435: LIR_Address* array_addr = emit_array_address(array.result(), index.result(), x->elt_type(), false); duke@435: duke@435: if (GenerateRangeChecks && needs_range_check) { duke@435: if (use_length) { duke@435: // TODO: use a (modified) version of array_range_check that does not require a duke@435: // constant length to be loaded to a register duke@435: __ cmp(lir_cond_belowEqual, length.result(), index.result()); duke@435: __ branch(lir_cond_belowEqual, T_INT, new RangeCheckStub(range_check_info, index.result())); duke@435: } else { duke@435: array_range_check(array.result(), index.result(), null_check_info, range_check_info); duke@435: // The range check performs the null check, so clear it out for the load duke@435: null_check_info = NULL; duke@435: } duke@435: } duke@435: duke@435: __ move(array_addr, rlock_result(x, x->elt_type()), null_check_info); duke@435: } duke@435: duke@435: duke@435: void LIRGenerator::do_NullCheck(NullCheck* x) { duke@435: if (x->can_trap()) { duke@435: LIRItem value(x->obj(), this); duke@435: value.load_item(); duke@435: CodeEmitInfo* info = state_for(x); duke@435: __ null_check(value.result(), info); duke@435: } duke@435: } duke@435: duke@435: duke@435: void LIRGenerator::do_Throw(Throw* x) { duke@435: LIRItem exception(x->exception(), this); duke@435: exception.load_item(); duke@435: set_no_result(x); duke@435: LIR_Opr exception_opr = exception.result(); duke@435: CodeEmitInfo* info = state_for(x, x->state()); duke@435: duke@435: #ifndef PRODUCT duke@435: if (PrintC1Statistics) { duke@435: increment_counter(Runtime1::throw_count_address()); duke@435: } duke@435: #endif duke@435: duke@435: // check if the instruction has an xhandler in any of the nested scopes duke@435: bool unwind = false; duke@435: if (info->exception_handlers()->length() == 0) { duke@435: // this throw is not inside an xhandler duke@435: unwind = true; duke@435: } else { duke@435: // get some idea of the throw type duke@435: bool type_is_exact = true; duke@435: ciType* throw_type = x->exception()->exact_type(); duke@435: if (throw_type == NULL) { duke@435: type_is_exact = false; duke@435: throw_type = x->exception()->declared_type(); duke@435: } duke@435: if (throw_type != NULL && throw_type->is_instance_klass()) { duke@435: ciInstanceKlass* throw_klass = (ciInstanceKlass*)throw_type; duke@435: unwind = !x->exception_handlers()->could_catch(throw_klass, type_is_exact); duke@435: } duke@435: } duke@435: duke@435: // do null check before moving exception oop into fixed register duke@435: // to avoid a fixed interval with an oop during the null check. duke@435: // Use a copy of the CodeEmitInfo because debug information is duke@435: // different for null_check and throw. duke@435: if (GenerateCompilerNullChecks && duke@435: (x->exception()->as_NewInstance() == NULL && x->exception()->as_ExceptionObject() == NULL)) { duke@435: // if the exception object wasn't created using new then it might be null. duke@435: __ null_check(exception_opr, new CodeEmitInfo(info, true)); duke@435: } duke@435: duke@435: if (JvmtiExport::can_post_exceptions() && duke@435: !block()->is_set(BlockBegin::default_exception_handler_flag)) { duke@435: // we need to go through the exception lookup path to get JVMTI duke@435: // notification done duke@435: unwind = false; duke@435: } duke@435: duke@435: assert(!block()->is_set(BlockBegin::default_exception_handler_flag) || unwind, duke@435: "should be no more handlers to dispatch to"); duke@435: duke@435: if (DTraceMethodProbes && duke@435: block()->is_set(BlockBegin::default_exception_handler_flag)) { duke@435: // notify that this frame is unwinding duke@435: BasicTypeList signature; duke@435: signature.append(T_INT); // thread duke@435: signature.append(T_OBJECT); // methodOop duke@435: LIR_OprList* args = new LIR_OprList(); duke@435: args->append(getThreadPointer()); duke@435: LIR_Opr meth = new_register(T_OBJECT); duke@435: __ oop2reg(method()->encoding(), meth); duke@435: args->append(meth); duke@435: call_runtime(&signature, args, CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_exit), voidType, NULL); duke@435: } duke@435: duke@435: // move exception oop into fixed register duke@435: __ move(exception_opr, exceptionOopOpr()); duke@435: duke@435: if (unwind) { duke@435: __ unwind_exception(LIR_OprFact::illegalOpr, exceptionOopOpr(), info); duke@435: } else { duke@435: __ throw_exception(exceptionPcOpr(), exceptionOopOpr(), info); duke@435: } duke@435: } duke@435: duke@435: duke@435: void LIRGenerator::do_RoundFP(RoundFP* x) { duke@435: LIRItem input(x->input(), this); duke@435: input.load_item(); duke@435: LIR_Opr input_opr = input.result(); duke@435: assert(input_opr->is_register(), "why round if value is not in a register?"); duke@435: assert(input_opr->is_single_fpu() || input_opr->is_double_fpu(), "input should be floating-point value"); duke@435: if (input_opr->is_single_fpu()) { duke@435: set_result(x, round_item(input_opr)); // This code path not currently taken duke@435: } else { duke@435: LIR_Opr result = new_register(T_DOUBLE); duke@435: set_vreg_flag(result, must_start_in_memory); duke@435: __ roundfp(input_opr, LIR_OprFact::illegalOpr, result); duke@435: set_result(x, result); duke@435: } duke@435: } duke@435: duke@435: void LIRGenerator::do_UnsafeGetRaw(UnsafeGetRaw* x) { duke@435: LIRItem base(x->base(), this); duke@435: LIRItem idx(this); duke@435: duke@435: base.load_item(); duke@435: if (x->has_index()) { duke@435: idx.set_instruction(x->index()); duke@435: idx.load_nonconstant(); duke@435: } duke@435: duke@435: LIR_Opr reg = rlock_result(x, x->basic_type()); duke@435: duke@435: int log2_scale = 0; duke@435: if (x->has_index()) { duke@435: assert(x->index()->type()->tag() == intTag, "should not find non-int index"); duke@435: log2_scale = x->log2_scale(); duke@435: } duke@435: duke@435: assert(!x->has_index() || idx.value() == x->index(), "should match"); duke@435: duke@435: LIR_Opr base_op = base.result(); duke@435: #ifndef _LP64 duke@435: if (x->base()->type()->tag() == longTag) { duke@435: base_op = new_register(T_INT); duke@435: __ convert(Bytecodes::_l2i, base.result(), base_op); duke@435: } else { duke@435: assert(x->base()->type()->tag() == intTag, "must be"); duke@435: } duke@435: #endif duke@435: duke@435: BasicType dst_type = x->basic_type(); duke@435: LIR_Opr index_op = idx.result(); duke@435: duke@435: LIR_Address* addr; duke@435: if (index_op->is_constant()) { duke@435: assert(log2_scale == 0, "must not have a scale"); duke@435: addr = new LIR_Address(base_op, index_op->as_jint(), dst_type); duke@435: } else { never@739: #ifdef X86 duke@435: addr = new LIR_Address(base_op, index_op, LIR_Address::Scale(log2_scale), 0, dst_type); duke@435: #else duke@435: if (index_op->is_illegal() || log2_scale == 0) { duke@435: addr = new LIR_Address(base_op, index_op, dst_type); duke@435: } else { duke@435: LIR_Opr tmp = new_register(T_INT); duke@435: __ shift_left(index_op, log2_scale, tmp); duke@435: addr = new LIR_Address(base_op, tmp, dst_type); duke@435: } duke@435: #endif duke@435: } duke@435: duke@435: if (x->may_be_unaligned() && (dst_type == T_LONG || dst_type == T_DOUBLE)) { duke@435: __ unaligned_move(addr, reg); duke@435: } else { duke@435: __ move(addr, reg); duke@435: } duke@435: } duke@435: duke@435: duke@435: void LIRGenerator::do_UnsafePutRaw(UnsafePutRaw* x) { duke@435: int log2_scale = 0; duke@435: BasicType type = x->basic_type(); duke@435: duke@435: if (x->has_index()) { duke@435: assert(x->index()->type()->tag() == intTag, "should not find non-int index"); duke@435: log2_scale = x->log2_scale(); duke@435: } duke@435: duke@435: LIRItem base(x->base(), this); duke@435: LIRItem value(x->value(), this); duke@435: LIRItem idx(this); duke@435: duke@435: base.load_item(); duke@435: if (x->has_index()) { duke@435: idx.set_instruction(x->index()); duke@435: idx.load_item(); duke@435: } duke@435: duke@435: if (type == T_BYTE || type == T_BOOLEAN) { duke@435: value.load_byte_item(); duke@435: } else { duke@435: value.load_item(); duke@435: } duke@435: duke@435: set_no_result(x); duke@435: duke@435: LIR_Opr base_op = base.result(); duke@435: #ifndef _LP64 duke@435: if (x->base()->type()->tag() == longTag) { duke@435: base_op = new_register(T_INT); duke@435: __ convert(Bytecodes::_l2i, base.result(), base_op); duke@435: } else { duke@435: assert(x->base()->type()->tag() == intTag, "must be"); duke@435: } duke@435: #endif duke@435: duke@435: LIR_Opr index_op = idx.result(); duke@435: if (log2_scale != 0) { duke@435: // temporary fix (platform dependent code without shift on Intel would be better) duke@435: index_op = new_register(T_INT); duke@435: __ move(idx.result(), index_op); duke@435: __ shift_left(index_op, log2_scale, index_op); duke@435: } duke@435: duke@435: LIR_Address* addr = new LIR_Address(base_op, index_op, x->basic_type()); duke@435: __ move(value.result(), addr); duke@435: } duke@435: duke@435: duke@435: void LIRGenerator::do_UnsafeGetObject(UnsafeGetObject* x) { duke@435: BasicType type = x->basic_type(); duke@435: LIRItem src(x->object(), this); duke@435: LIRItem off(x->offset(), this); duke@435: duke@435: off.load_item(); duke@435: src.load_item(); duke@435: duke@435: LIR_Opr reg = reg = rlock_result(x, x->basic_type()); duke@435: duke@435: if (x->is_volatile() && os::is_MP()) __ membar_acquire(); duke@435: get_Object_unsafe(reg, src.result(), off.result(), type, x->is_volatile()); duke@435: if (x->is_volatile() && os::is_MP()) __ membar(); duke@435: } duke@435: duke@435: duke@435: void LIRGenerator::do_UnsafePutObject(UnsafePutObject* x) { duke@435: BasicType type = x->basic_type(); duke@435: LIRItem src(x->object(), this); duke@435: LIRItem off(x->offset(), this); duke@435: LIRItem data(x->value(), this); duke@435: duke@435: src.load_item(); duke@435: if (type == T_BOOLEAN || type == T_BYTE) { duke@435: data.load_byte_item(); duke@435: } else { duke@435: data.load_item(); duke@435: } duke@435: off.load_item(); duke@435: duke@435: set_no_result(x); duke@435: duke@435: if (x->is_volatile() && os::is_MP()) __ membar_release(); duke@435: put_Object_unsafe(src.result(), off.result(), data.result(), type, x->is_volatile()); duke@435: } duke@435: duke@435: duke@435: void LIRGenerator::do_UnsafePrefetch(UnsafePrefetch* x, bool is_store) { duke@435: LIRItem src(x->object(), this); duke@435: LIRItem off(x->offset(), this); duke@435: duke@435: src.load_item(); duke@435: if (off.is_constant() && can_inline_as_constant(x->offset())) { duke@435: // let it be a constant duke@435: off.dont_load_item(); duke@435: } else { duke@435: off.load_item(); duke@435: } duke@435: duke@435: set_no_result(x); duke@435: duke@435: LIR_Address* addr = generate_address(src.result(), off.result(), 0, 0, T_BYTE); duke@435: __ prefetch(addr, is_store); duke@435: } duke@435: duke@435: duke@435: void LIRGenerator::do_UnsafePrefetchRead(UnsafePrefetchRead* x) { duke@435: do_UnsafePrefetch(x, false); duke@435: } duke@435: duke@435: duke@435: void LIRGenerator::do_UnsafePrefetchWrite(UnsafePrefetchWrite* x) { duke@435: do_UnsafePrefetch(x, true); duke@435: } duke@435: duke@435: duke@435: void LIRGenerator::do_SwitchRanges(SwitchRangeArray* x, LIR_Opr value, BlockBegin* default_sux) { duke@435: int lng = x->length(); duke@435: duke@435: for (int i = 0; i < lng; i++) { duke@435: SwitchRange* one_range = x->at(i); duke@435: int low_key = one_range->low_key(); duke@435: int high_key = one_range->high_key(); duke@435: BlockBegin* dest = one_range->sux(); duke@435: if (low_key == high_key) { duke@435: __ cmp(lir_cond_equal, value, low_key); duke@435: __ branch(lir_cond_equal, T_INT, dest); duke@435: } else if (high_key - low_key == 1) { duke@435: __ cmp(lir_cond_equal, value, low_key); duke@435: __ branch(lir_cond_equal, T_INT, dest); duke@435: __ cmp(lir_cond_equal, value, high_key); duke@435: __ branch(lir_cond_equal, T_INT, dest); duke@435: } else { duke@435: LabelObj* L = new LabelObj(); duke@435: __ cmp(lir_cond_less, value, low_key); duke@435: __ branch(lir_cond_less, L->label()); duke@435: __ cmp(lir_cond_lessEqual, value, high_key); duke@435: __ branch(lir_cond_lessEqual, T_INT, dest); duke@435: __ branch_destination(L->label()); duke@435: } duke@435: } duke@435: __ jump(default_sux); duke@435: } duke@435: duke@435: duke@435: SwitchRangeArray* LIRGenerator::create_lookup_ranges(TableSwitch* x) { duke@435: SwitchRangeList* res = new SwitchRangeList(); duke@435: int len = x->length(); duke@435: if (len > 0) { duke@435: BlockBegin* sux = x->sux_at(0); duke@435: int key = x->lo_key(); duke@435: BlockBegin* default_sux = x->default_sux(); duke@435: SwitchRange* range = new SwitchRange(key, sux); duke@435: for (int i = 0; i < len; i++, key++) { duke@435: BlockBegin* new_sux = x->sux_at(i); duke@435: if (sux == new_sux) { duke@435: // still in same range duke@435: range->set_high_key(key); duke@435: } else { duke@435: // skip tests which explicitly dispatch to the default duke@435: if (sux != default_sux) { duke@435: res->append(range); duke@435: } duke@435: range = new SwitchRange(key, new_sux); duke@435: } duke@435: sux = new_sux; duke@435: } duke@435: if (res->length() == 0 || res->last() != range) res->append(range); duke@435: } duke@435: return res; duke@435: } duke@435: duke@435: duke@435: // we expect the keys to be sorted by increasing value duke@435: SwitchRangeArray* LIRGenerator::create_lookup_ranges(LookupSwitch* x) { duke@435: SwitchRangeList* res = new SwitchRangeList(); duke@435: int len = x->length(); duke@435: if (len > 0) { duke@435: BlockBegin* default_sux = x->default_sux(); duke@435: int key = x->key_at(0); duke@435: BlockBegin* sux = x->sux_at(0); duke@435: SwitchRange* range = new SwitchRange(key, sux); duke@435: for (int i = 1; i < len; i++) { duke@435: int new_key = x->key_at(i); duke@435: BlockBegin* new_sux = x->sux_at(i); duke@435: if (key+1 == new_key && sux == new_sux) { duke@435: // still in same range duke@435: range->set_high_key(new_key); duke@435: } else { duke@435: // skip tests which explicitly dispatch to the default duke@435: if (range->sux() != default_sux) { duke@435: res->append(range); duke@435: } duke@435: range = new SwitchRange(new_key, new_sux); duke@435: } duke@435: key = new_key; duke@435: sux = new_sux; duke@435: } duke@435: if (res->length() == 0 || res->last() != range) res->append(range); duke@435: } duke@435: return res; duke@435: } duke@435: duke@435: duke@435: void LIRGenerator::do_TableSwitch(TableSwitch* x) { duke@435: LIRItem tag(x->tag(), this); duke@435: tag.load_item(); duke@435: set_no_result(x); duke@435: duke@435: if (x->is_safepoint()) { duke@435: __ safepoint(safepoint_poll_register(), state_for(x, x->state_before())); duke@435: } duke@435: duke@435: // move values into phi locations duke@435: move_to_phi(x->state()); duke@435: duke@435: int lo_key = x->lo_key(); duke@435: int hi_key = x->hi_key(); duke@435: int len = x->length(); duke@435: CodeEmitInfo* info = state_for(x, x->state()); duke@435: LIR_Opr value = tag.result(); duke@435: if (UseTableRanges) { duke@435: do_SwitchRanges(create_lookup_ranges(x), value, x->default_sux()); duke@435: } else { duke@435: for (int i = 0; i < len; i++) { duke@435: __ cmp(lir_cond_equal, value, i + lo_key); duke@435: __ branch(lir_cond_equal, T_INT, x->sux_at(i)); duke@435: } duke@435: __ jump(x->default_sux()); duke@435: } duke@435: } duke@435: duke@435: duke@435: void LIRGenerator::do_LookupSwitch(LookupSwitch* x) { duke@435: LIRItem tag(x->tag(), this); duke@435: tag.load_item(); duke@435: set_no_result(x); duke@435: duke@435: if (x->is_safepoint()) { duke@435: __ safepoint(safepoint_poll_register(), state_for(x, x->state_before())); duke@435: } duke@435: duke@435: // move values into phi locations duke@435: move_to_phi(x->state()); duke@435: duke@435: LIR_Opr value = tag.result(); duke@435: if (UseTableRanges) { duke@435: do_SwitchRanges(create_lookup_ranges(x), value, x->default_sux()); duke@435: } else { duke@435: int len = x->length(); duke@435: for (int i = 0; i < len; i++) { duke@435: __ cmp(lir_cond_equal, value, x->key_at(i)); duke@435: __ branch(lir_cond_equal, T_INT, x->sux_at(i)); duke@435: } duke@435: __ jump(x->default_sux()); duke@435: } duke@435: } duke@435: duke@435: duke@435: void LIRGenerator::do_Goto(Goto* x) { duke@435: set_no_result(x); duke@435: duke@435: if (block()->next()->as_OsrEntry()) { duke@435: // need to free up storage used for OSR entry point duke@435: LIR_Opr osrBuffer = block()->next()->operand(); duke@435: BasicTypeList signature; duke@435: signature.append(T_INT); duke@435: CallingConvention* cc = frame_map()->c_calling_convention(&signature); duke@435: __ move(osrBuffer, cc->args()->at(0)); duke@435: __ call_runtime_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::OSR_migration_end), duke@435: getThreadTemp(), LIR_OprFact::illegalOpr, cc->args()); duke@435: } duke@435: duke@435: if (x->is_safepoint()) { duke@435: ValueStack* state = x->state_before() ? x->state_before() : x->state(); duke@435: duke@435: // increment backedge counter if needed duke@435: increment_backedge_counter(state_for(x, state)); duke@435: duke@435: CodeEmitInfo* safepoint_info = state_for(x, state); duke@435: __ safepoint(safepoint_poll_register(), safepoint_info); duke@435: } duke@435: duke@435: // emit phi-instruction move after safepoint since this simplifies duke@435: // describing the state as the safepoint. duke@435: move_to_phi(x->state()); duke@435: duke@435: __ jump(x->default_sux()); duke@435: } duke@435: duke@435: duke@435: void LIRGenerator::do_Base(Base* x) { duke@435: __ std_entry(LIR_OprFact::illegalOpr); duke@435: // Emit moves from physical registers / stack slots to virtual registers duke@435: CallingConvention* args = compilation()->frame_map()->incoming_arguments(); duke@435: IRScope* irScope = compilation()->hir()->top_scope(); duke@435: int java_index = 0; duke@435: for (int i = 0; i < args->length(); i++) { duke@435: LIR_Opr src = args->at(i); duke@435: assert(!src->is_illegal(), "check"); duke@435: BasicType t = src->type(); duke@435: duke@435: // Types which are smaller than int are passed as int, so duke@435: // correct the type which passed. duke@435: switch (t) { duke@435: case T_BYTE: duke@435: case T_BOOLEAN: duke@435: case T_SHORT: duke@435: case T_CHAR: duke@435: t = T_INT; duke@435: break; duke@435: } duke@435: duke@435: LIR_Opr dest = new_register(t); duke@435: __ move(src, dest); duke@435: duke@435: // Assign new location to Local instruction for this local duke@435: Local* local = x->state()->local_at(java_index)->as_Local(); duke@435: assert(local != NULL, "Locals for incoming arguments must have been created"); duke@435: assert(as_ValueType(t)->tag() == local->type()->tag(), "check"); duke@435: local->set_operand(dest); duke@435: _instruction_for_operand.at_put_grow(dest->vreg_number(), local, NULL); duke@435: java_index += type2size[t]; duke@435: } duke@435: duke@435: if (DTraceMethodProbes) { duke@435: BasicTypeList signature; duke@435: signature.append(T_INT); // thread duke@435: signature.append(T_OBJECT); // methodOop duke@435: LIR_OprList* args = new LIR_OprList(); duke@435: args->append(getThreadPointer()); duke@435: LIR_Opr meth = new_register(T_OBJECT); duke@435: __ oop2reg(method()->encoding(), meth); duke@435: args->append(meth); duke@435: call_runtime(&signature, args, CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_entry), voidType, NULL); duke@435: } duke@435: duke@435: if (method()->is_synchronized()) { duke@435: LIR_Opr obj; duke@435: if (method()->is_static()) { duke@435: obj = new_register(T_OBJECT); duke@435: __ oop2reg(method()->holder()->java_mirror()->encoding(), obj); duke@435: } else { duke@435: Local* receiver = x->state()->local_at(0)->as_Local(); duke@435: assert(receiver != NULL, "must already exist"); duke@435: obj = receiver->operand(); duke@435: } duke@435: assert(obj->is_valid(), "must be valid"); duke@435: duke@435: if (method()->is_synchronized() && GenerateSynchronizationCode) { duke@435: LIR_Opr lock = new_register(T_INT); duke@435: __ load_stack_address_monitor(0, lock); duke@435: duke@435: CodeEmitInfo* info = new CodeEmitInfo(SynchronizationEntryBCI, scope()->start()->state(), NULL); duke@435: CodeStub* slow_path = new MonitorEnterStub(obj, lock, info); duke@435: duke@435: // receiver is guaranteed non-NULL so don't need CodeEmitInfo duke@435: __ lock_object(syncTempOpr(), obj, lock, new_register(T_OBJECT), slow_path, NULL); duke@435: } duke@435: } duke@435: duke@435: // increment invocation counters if needed duke@435: increment_invocation_counter(new CodeEmitInfo(0, scope()->start()->state(), NULL)); duke@435: duke@435: // all blocks with a successor must end with an unconditional jump duke@435: // to the successor even if they are consecutive duke@435: __ jump(x->default_sux()); duke@435: } duke@435: duke@435: duke@435: void LIRGenerator::do_OsrEntry(OsrEntry* x) { duke@435: // construct our frame and model the production of incoming pointer duke@435: // to the OSR buffer. duke@435: __ osr_entry(LIR_Assembler::osrBufferPointer()); duke@435: LIR_Opr result = rlock_result(x); duke@435: __ move(LIR_Assembler::osrBufferPointer(), result); duke@435: } duke@435: duke@435: duke@435: void LIRGenerator::invoke_load_arguments(Invoke* x, LIRItemList* args, const LIR_OprList* arg_list) { duke@435: int i = x->has_receiver() ? 1 : 0; duke@435: for (; i < args->length(); i++) { duke@435: LIRItem* param = args->at(i); duke@435: LIR_Opr loc = arg_list->at(i); duke@435: if (loc->is_register()) { duke@435: param->load_item_force(loc); duke@435: } else { duke@435: LIR_Address* addr = loc->as_address_ptr(); duke@435: param->load_for_store(addr->type()); duke@435: if (addr->type() == T_LONG || addr->type() == T_DOUBLE) { duke@435: __ unaligned_move(param->result(), addr); duke@435: } else { duke@435: __ move(param->result(), addr); duke@435: } duke@435: } duke@435: } duke@435: duke@435: if (x->has_receiver()) { duke@435: LIRItem* receiver = args->at(0); duke@435: LIR_Opr loc = arg_list->at(0); duke@435: if (loc->is_register()) { duke@435: receiver->load_item_force(loc); duke@435: } else { duke@435: assert(loc->is_address(), "just checking"); duke@435: receiver->load_for_store(T_OBJECT); duke@435: __ move(receiver->result(), loc); duke@435: } duke@435: } duke@435: } duke@435: duke@435: duke@435: // Visits all arguments, returns appropriate items without loading them duke@435: LIRItemList* LIRGenerator::invoke_visit_arguments(Invoke* x) { duke@435: LIRItemList* argument_items = new LIRItemList(); duke@435: if (x->has_receiver()) { duke@435: LIRItem* receiver = new LIRItem(x->receiver(), this); duke@435: argument_items->append(receiver); duke@435: } duke@435: int idx = x->has_receiver() ? 1 : 0; duke@435: for (int i = 0; i < x->number_of_arguments(); i++) { duke@435: LIRItem* param = new LIRItem(x->argument_at(i), this); duke@435: argument_items->append(param); duke@435: idx += (param->type()->is_double_word() ? 2 : 1); duke@435: } duke@435: return argument_items; duke@435: } duke@435: duke@435: duke@435: // The invoke with receiver has following phases: duke@435: // a) traverse and load/lock receiver; duke@435: // b) traverse all arguments -> item-array (invoke_visit_argument) duke@435: // c) push receiver on stack duke@435: // d) load each of the items and push on stack duke@435: // e) unlock receiver duke@435: // f) move receiver into receiver-register %o0 duke@435: // g) lock result registers and emit call operation duke@435: // duke@435: // Before issuing a call, we must spill-save all values on stack duke@435: // that are in caller-save register. "spill-save" moves thos registers duke@435: // either in a free callee-save register or spills them if no free duke@435: // callee save register is available. duke@435: // duke@435: // The problem is where to invoke spill-save. duke@435: // - if invoked between e) and f), we may lock callee save duke@435: // register in "spill-save" that destroys the receiver register duke@435: // before f) is executed duke@435: // - if we rearange the f) to be earlier, by loading %o0, it duke@435: // may destroy a value on the stack that is currently in %o0 duke@435: // and is waiting to be spilled duke@435: // - if we keep the receiver locked while doing spill-save, duke@435: // we cannot spill it as it is spill-locked duke@435: // duke@435: void LIRGenerator::do_Invoke(Invoke* x) { duke@435: CallingConvention* cc = frame_map()->java_calling_convention(x->signature(), true); duke@435: duke@435: LIR_OprList* arg_list = cc->args(); duke@435: LIRItemList* args = invoke_visit_arguments(x); duke@435: LIR_Opr receiver = LIR_OprFact::illegalOpr; duke@435: duke@435: // setup result register duke@435: LIR_Opr result_register = LIR_OprFact::illegalOpr; duke@435: if (x->type() != voidType) { duke@435: result_register = result_register_for(x->type()); duke@435: } duke@435: duke@435: CodeEmitInfo* info = state_for(x, x->state()); duke@435: duke@435: invoke_load_arguments(x, args, arg_list); duke@435: duke@435: if (x->has_receiver()) { duke@435: args->at(0)->load_item_force(LIR_Assembler::receiverOpr()); duke@435: receiver = args->at(0)->result(); duke@435: } duke@435: duke@435: // emit invoke code duke@435: bool optimized = x->target_is_loaded() && x->target_is_final(); duke@435: assert(receiver->is_illegal() || receiver->is_equal(LIR_Assembler::receiverOpr()), "must match"); duke@435: duke@435: switch (x->code()) { duke@435: case Bytecodes::_invokestatic: duke@435: __ call_static(x->target(), result_register, duke@435: SharedRuntime::get_resolve_static_call_stub(), duke@435: arg_list, info); duke@435: break; duke@435: case Bytecodes::_invokespecial: duke@435: case Bytecodes::_invokevirtual: duke@435: case Bytecodes::_invokeinterface: duke@435: // for final target we still produce an inline cache, in order duke@435: // to be able to call mixed mode duke@435: if (x->code() == Bytecodes::_invokespecial || optimized) { duke@435: __ call_opt_virtual(x->target(), receiver, result_register, duke@435: SharedRuntime::get_resolve_opt_virtual_call_stub(), duke@435: arg_list, info); duke@435: } else if (x->vtable_index() < 0) { duke@435: __ call_icvirtual(x->target(), receiver, result_register, duke@435: SharedRuntime::get_resolve_virtual_call_stub(), duke@435: arg_list, info); duke@435: } else { duke@435: int entry_offset = instanceKlass::vtable_start_offset() + x->vtable_index() * vtableEntry::size(); duke@435: int vtable_offset = entry_offset * wordSize + vtableEntry::method_offset_in_bytes(); duke@435: __ call_virtual(x->target(), receiver, result_register, vtable_offset, arg_list, info); duke@435: } duke@435: break; duke@435: default: duke@435: ShouldNotReachHere(); duke@435: break; duke@435: } duke@435: duke@435: if (x->type()->is_float() || x->type()->is_double()) { duke@435: // Force rounding of results from non-strictfp when in strictfp duke@435: // scope (or when we don't know the strictness of the callee, to duke@435: // be safe.) duke@435: if (method()->is_strict()) { duke@435: if (!x->target_is_loaded() || !x->target_is_strictfp()) { duke@435: result_register = round_item(result_register); duke@435: } duke@435: } duke@435: } duke@435: duke@435: if (result_register->is_valid()) { duke@435: LIR_Opr result = rlock_result(x); duke@435: __ move(result_register, result); duke@435: } duke@435: } duke@435: duke@435: duke@435: void LIRGenerator::do_FPIntrinsics(Intrinsic* x) { duke@435: assert(x->number_of_arguments() == 1, "wrong type"); duke@435: LIRItem value (x->argument_at(0), this); duke@435: LIR_Opr reg = rlock_result(x); duke@435: value.load_item(); duke@435: LIR_Opr tmp = force_to_spill(value.result(), as_BasicType(x->type())); duke@435: __ move(tmp, reg); duke@435: } duke@435: duke@435: duke@435: duke@435: // Code for : x->x() {x->cond()} x->y() ? x->tval() : x->fval() duke@435: void LIRGenerator::do_IfOp(IfOp* x) { duke@435: #ifdef ASSERT duke@435: { duke@435: ValueTag xtag = x->x()->type()->tag(); duke@435: ValueTag ttag = x->tval()->type()->tag(); duke@435: assert(xtag == intTag || xtag == objectTag, "cannot handle others"); duke@435: assert(ttag == addressTag || ttag == intTag || ttag == objectTag || ttag == longTag, "cannot handle others"); duke@435: assert(ttag == x->fval()->type()->tag(), "cannot handle others"); duke@435: } duke@435: #endif duke@435: duke@435: LIRItem left(x->x(), this); duke@435: LIRItem right(x->y(), this); duke@435: left.load_item(); duke@435: if (can_inline_as_constant(right.value())) { duke@435: right.dont_load_item(); duke@435: } else { duke@435: right.load_item(); duke@435: } duke@435: duke@435: LIRItem t_val(x->tval(), this); duke@435: LIRItem f_val(x->fval(), this); duke@435: t_val.dont_load_item(); duke@435: f_val.dont_load_item(); duke@435: LIR_Opr reg = rlock_result(x); duke@435: duke@435: __ cmp(lir_cond(x->cond()), left.result(), right.result()); duke@435: __ cmove(lir_cond(x->cond()), t_val.result(), f_val.result(), reg); duke@435: } duke@435: duke@435: duke@435: void LIRGenerator::do_Intrinsic(Intrinsic* x) { duke@435: switch (x->id()) { duke@435: case vmIntrinsics::_intBitsToFloat : duke@435: case vmIntrinsics::_doubleToRawLongBits : duke@435: case vmIntrinsics::_longBitsToDouble : duke@435: case vmIntrinsics::_floatToRawIntBits : { duke@435: do_FPIntrinsics(x); duke@435: break; duke@435: } duke@435: duke@435: case vmIntrinsics::_currentTimeMillis: { duke@435: assert(x->number_of_arguments() == 0, "wrong type"); duke@435: LIR_Opr reg = result_register_for(x->type()); duke@435: __ call_runtime_leaf(CAST_FROM_FN_PTR(address, os::javaTimeMillis), getThreadTemp(), duke@435: reg, new LIR_OprList()); duke@435: LIR_Opr result = rlock_result(x); duke@435: __ move(reg, result); duke@435: break; duke@435: } duke@435: duke@435: case vmIntrinsics::_nanoTime: { duke@435: assert(x->number_of_arguments() == 0, "wrong type"); duke@435: LIR_Opr reg = result_register_for(x->type()); duke@435: __ call_runtime_leaf(CAST_FROM_FN_PTR(address, os::javaTimeNanos), getThreadTemp(), duke@435: reg, new LIR_OprList()); duke@435: LIR_Opr result = rlock_result(x); duke@435: __ move(reg, result); duke@435: break; duke@435: } duke@435: duke@435: case vmIntrinsics::_Object_init: do_RegisterFinalizer(x); break; duke@435: case vmIntrinsics::_getClass: do_getClass(x); break; duke@435: case vmIntrinsics::_currentThread: do_currentThread(x); break; duke@435: duke@435: case vmIntrinsics::_dlog: // fall through duke@435: case vmIntrinsics::_dlog10: // fall through duke@435: case vmIntrinsics::_dabs: // fall through duke@435: case vmIntrinsics::_dsqrt: // fall through duke@435: case vmIntrinsics::_dtan: // fall through duke@435: case vmIntrinsics::_dsin : // fall through duke@435: case vmIntrinsics::_dcos : do_MathIntrinsic(x); break; duke@435: case vmIntrinsics::_arraycopy: do_ArrayCopy(x); break; duke@435: duke@435: // java.nio.Buffer.checkIndex duke@435: case vmIntrinsics::_checkIndex: do_NIOCheckIndex(x); break; duke@435: duke@435: case vmIntrinsics::_compareAndSwapObject: duke@435: do_CompareAndSwap(x, objectType); duke@435: break; duke@435: case vmIntrinsics::_compareAndSwapInt: duke@435: do_CompareAndSwap(x, intType); duke@435: break; duke@435: case vmIntrinsics::_compareAndSwapLong: duke@435: do_CompareAndSwap(x, longType); duke@435: break; duke@435: duke@435: // sun.misc.AtomicLongCSImpl.attemptUpdate duke@435: case vmIntrinsics::_attemptUpdate: duke@435: do_AttemptUpdate(x); duke@435: break; duke@435: duke@435: default: ShouldNotReachHere(); break; duke@435: } duke@435: } duke@435: duke@435: duke@435: void LIRGenerator::do_ProfileCall(ProfileCall* x) { duke@435: // Need recv in a temporary register so it interferes with the other temporaries duke@435: LIR_Opr recv = LIR_OprFact::illegalOpr; duke@435: LIR_Opr mdo = new_register(T_OBJECT); duke@435: LIR_Opr tmp = new_register(T_INT); duke@435: if (x->recv() != NULL) { duke@435: LIRItem value(x->recv(), this); duke@435: value.load_item(); duke@435: recv = new_register(T_OBJECT); duke@435: __ move(value.result(), recv); duke@435: } duke@435: __ profile_call(x->method(), x->bci_of_invoke(), mdo, recv, tmp, x->known_holder()); duke@435: } duke@435: duke@435: duke@435: void LIRGenerator::do_ProfileCounter(ProfileCounter* x) { duke@435: LIRItem mdo(x->mdo(), this); duke@435: mdo.load_item(); duke@435: duke@435: increment_counter(new LIR_Address(mdo.result(), x->offset(), T_INT), x->increment()); duke@435: } duke@435: duke@435: duke@435: LIR_Opr LIRGenerator::call_runtime(Value arg1, address entry, ValueType* result_type, CodeEmitInfo* info) { duke@435: LIRItemList args(1); duke@435: LIRItem value(arg1, this); duke@435: args.append(&value); duke@435: BasicTypeList signature; duke@435: signature.append(as_BasicType(arg1->type())); duke@435: duke@435: return call_runtime(&signature, &args, entry, result_type, info); duke@435: } duke@435: duke@435: duke@435: LIR_Opr LIRGenerator::call_runtime(Value arg1, Value arg2, address entry, ValueType* result_type, CodeEmitInfo* info) { duke@435: LIRItemList args(2); duke@435: LIRItem value1(arg1, this); duke@435: LIRItem value2(arg2, this); duke@435: args.append(&value1); duke@435: args.append(&value2); duke@435: BasicTypeList signature; duke@435: signature.append(as_BasicType(arg1->type())); duke@435: signature.append(as_BasicType(arg2->type())); duke@435: duke@435: return call_runtime(&signature, &args, entry, result_type, info); duke@435: } duke@435: duke@435: duke@435: LIR_Opr LIRGenerator::call_runtime(BasicTypeArray* signature, LIR_OprList* args, duke@435: address entry, ValueType* result_type, CodeEmitInfo* info) { duke@435: // get a result register duke@435: LIR_Opr phys_reg = LIR_OprFact::illegalOpr; duke@435: LIR_Opr result = LIR_OprFact::illegalOpr; duke@435: if (result_type->tag() != voidTag) { duke@435: result = new_register(result_type); duke@435: phys_reg = result_register_for(result_type); duke@435: } duke@435: duke@435: // move the arguments into the correct location duke@435: CallingConvention* cc = frame_map()->c_calling_convention(signature); duke@435: assert(cc->length() == args->length(), "argument mismatch"); duke@435: for (int i = 0; i < args->length(); i++) { duke@435: LIR_Opr arg = args->at(i); duke@435: LIR_Opr loc = cc->at(i); duke@435: if (loc->is_register()) { duke@435: __ move(arg, loc); duke@435: } else { duke@435: LIR_Address* addr = loc->as_address_ptr(); duke@435: // if (!can_store_as_constant(arg)) { duke@435: // LIR_Opr tmp = new_register(arg->type()); duke@435: // __ move(arg, tmp); duke@435: // arg = tmp; duke@435: // } duke@435: if (addr->type() == T_LONG || addr->type() == T_DOUBLE) { duke@435: __ unaligned_move(arg, addr); duke@435: } else { duke@435: __ move(arg, addr); duke@435: } duke@435: } duke@435: } duke@435: duke@435: if (info) { duke@435: __ call_runtime(entry, getThreadTemp(), phys_reg, cc->args(), info); duke@435: } else { duke@435: __ call_runtime_leaf(entry, getThreadTemp(), phys_reg, cc->args()); duke@435: } duke@435: if (result->is_valid()) { duke@435: __ move(phys_reg, result); duke@435: } duke@435: return result; duke@435: } duke@435: duke@435: duke@435: LIR_Opr LIRGenerator::call_runtime(BasicTypeArray* signature, LIRItemList* args, duke@435: address entry, ValueType* result_type, CodeEmitInfo* info) { duke@435: // get a result register duke@435: LIR_Opr phys_reg = LIR_OprFact::illegalOpr; duke@435: LIR_Opr result = LIR_OprFact::illegalOpr; duke@435: if (result_type->tag() != voidTag) { duke@435: result = new_register(result_type); duke@435: phys_reg = result_register_for(result_type); duke@435: } duke@435: duke@435: // move the arguments into the correct location duke@435: CallingConvention* cc = frame_map()->c_calling_convention(signature); duke@435: duke@435: assert(cc->length() == args->length(), "argument mismatch"); duke@435: for (int i = 0; i < args->length(); i++) { duke@435: LIRItem* arg = args->at(i); duke@435: LIR_Opr loc = cc->at(i); duke@435: if (loc->is_register()) { duke@435: arg->load_item_force(loc); duke@435: } else { duke@435: LIR_Address* addr = loc->as_address_ptr(); duke@435: arg->load_for_store(addr->type()); duke@435: if (addr->type() == T_LONG || addr->type() == T_DOUBLE) { duke@435: __ unaligned_move(arg->result(), addr); duke@435: } else { duke@435: __ move(arg->result(), addr); duke@435: } duke@435: } duke@435: } duke@435: duke@435: if (info) { duke@435: __ call_runtime(entry, getThreadTemp(), phys_reg, cc->args(), info); duke@435: } else { duke@435: __ call_runtime_leaf(entry, getThreadTemp(), phys_reg, cc->args()); duke@435: } duke@435: if (result->is_valid()) { duke@435: __ move(phys_reg, result); duke@435: } duke@435: return result; duke@435: } duke@435: duke@435: duke@435: duke@435: void LIRGenerator::increment_invocation_counter(CodeEmitInfo* info, bool backedge) { duke@435: #ifdef TIERED duke@435: if (_compilation->env()->comp_level() == CompLevel_fast_compile && duke@435: (method()->code_size() >= Tier1BytecodeLimit || backedge)) { duke@435: int limit = InvocationCounter::Tier1InvocationLimit; duke@435: int offset = in_bytes(methodOopDesc::invocation_counter_offset() + duke@435: InvocationCounter::counter_offset()); duke@435: if (backedge) { duke@435: limit = InvocationCounter::Tier1BackEdgeLimit; duke@435: offset = in_bytes(methodOopDesc::backedge_counter_offset() + duke@435: InvocationCounter::counter_offset()); duke@435: } duke@435: duke@435: LIR_Opr meth = new_register(T_OBJECT); duke@435: __ oop2reg(method()->encoding(), meth); duke@435: LIR_Opr result = increment_and_return_counter(meth, offset, InvocationCounter::count_increment); duke@435: __ cmp(lir_cond_aboveEqual, result, LIR_OprFact::intConst(limit)); duke@435: CodeStub* overflow = new CounterOverflowStub(info, info->bci()); duke@435: __ branch(lir_cond_aboveEqual, T_INT, overflow); duke@435: __ branch_destination(overflow->continuation()); duke@435: } duke@435: #endif duke@435: }