duke@435: /* xdono@631: * Copyright 1997-2008 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/_interp_masm_sparc.cpp.incl" duke@435: duke@435: #ifndef CC_INTERP duke@435: #ifndef FAST_DISPATCH duke@435: #define FAST_DISPATCH 1 duke@435: #endif duke@435: #undef FAST_DISPATCH duke@435: duke@435: // Implementation of InterpreterMacroAssembler duke@435: duke@435: // This file specializes the assember with interpreter-specific macros duke@435: duke@435: const Address InterpreterMacroAssembler::l_tmp( FP, 0, (frame::interpreter_frame_l_scratch_fp_offset * wordSize ) + STACK_BIAS); duke@435: const Address InterpreterMacroAssembler::d_tmp( FP, 0, (frame::interpreter_frame_d_scratch_fp_offset * wordSize) + STACK_BIAS); duke@435: duke@435: #else // CC_INTERP duke@435: #ifndef STATE duke@435: #define STATE(field_name) Lstate, in_bytes(byte_offset_of(BytecodeInterpreter, field_name)) duke@435: #endif // STATE duke@435: duke@435: #endif // CC_INTERP duke@435: duke@435: void InterpreterMacroAssembler::compute_extra_locals_size_in_bytes(Register args_size, Register locals_size, Register delta) { duke@435: // Note: this algorithm is also used by C1's OSR entry sequence. duke@435: // Any changes should also be applied to CodeEmitter::emit_osr_entry(). duke@435: assert_different_registers(args_size, locals_size); duke@435: // max_locals*2 for TAGS. Assumes that args_size has already been adjusted. duke@435: if (TaggedStackInterpreter) sll(locals_size, 1, locals_size); duke@435: subcc(locals_size, args_size, delta);// extra space for non-arguments locals in words duke@435: // Use br/mov combination because it works on both V8 and V9 and is duke@435: // faster. duke@435: Label skip_move; duke@435: br(Assembler::negative, true, Assembler::pt, skip_move); duke@435: delayed()->mov(G0, delta); duke@435: bind(skip_move); duke@435: round_to(delta, WordsPerLong); // make multiple of 2 (SP must be 2-word aligned) duke@435: sll(delta, LogBytesPerWord, delta); // extra space for locals in bytes duke@435: } duke@435: duke@435: #ifndef CC_INTERP duke@435: duke@435: // Dispatch code executed in the prolog of a bytecode which does not do it's duke@435: // own dispatch. The dispatch address is computed and placed in IdispatchAddress duke@435: void InterpreterMacroAssembler::dispatch_prolog(TosState state, int bcp_incr) { duke@435: assert_not_delayed(); duke@435: #ifdef FAST_DISPATCH duke@435: // FAST_DISPATCH and ProfileInterpreter are mutually exclusive since duke@435: // they both use I2. duke@435: assert(!ProfileInterpreter, "FAST_DISPATCH and +ProfileInterpreter are mutually exclusive"); duke@435: ldub(Lbcp, bcp_incr, Lbyte_code); // load next bytecode duke@435: add(Lbyte_code, Interpreter::distance_from_dispatch_table(state), Lbyte_code); duke@435: // add offset to correct dispatch table duke@435: sll(Lbyte_code, LogBytesPerWord, Lbyte_code); // multiply by wordSize duke@435: ld_ptr(IdispatchTables, Lbyte_code, IdispatchAddress);// get entry addr duke@435: #else duke@435: ldub( Lbcp, bcp_incr, Lbyte_code); // load next bytecode duke@435: // dispatch table to use duke@435: Address tbl(G3_scratch, (address)Interpreter::dispatch_table(state)); duke@435: duke@435: sethi(tbl); duke@435: sll(Lbyte_code, LogBytesPerWord, Lbyte_code); // multiply by wordSize duke@435: add(tbl, tbl.base(), 0); duke@435: ld_ptr( G3_scratch, Lbyte_code, IdispatchAddress); // get entry addr duke@435: #endif duke@435: } duke@435: duke@435: duke@435: // Dispatch code executed in the epilog of a bytecode which does not do it's duke@435: // own dispatch. The dispatch address in IdispatchAddress is used for the duke@435: // dispatch. duke@435: void InterpreterMacroAssembler::dispatch_epilog(TosState state, int bcp_incr) { duke@435: assert_not_delayed(); duke@435: verify_FPU(1, state); duke@435: interp_verify_oop(Otos_i, state, __FILE__, __LINE__); duke@435: jmp( IdispatchAddress, 0 ); duke@435: if (bcp_incr != 0) delayed()->inc(Lbcp, bcp_incr); duke@435: else delayed()->nop(); duke@435: } duke@435: duke@435: duke@435: void InterpreterMacroAssembler::dispatch_next(TosState state, int bcp_incr) { duke@435: // %%%% consider branching to a single shared dispatch stub (for each bcp_incr) duke@435: assert_not_delayed(); duke@435: ldub( Lbcp, bcp_incr, Lbyte_code); // load next bytecode duke@435: dispatch_Lbyte_code(state, Interpreter::dispatch_table(state), bcp_incr); duke@435: } duke@435: duke@435: duke@435: void InterpreterMacroAssembler::dispatch_next_noverify_oop(TosState state, int bcp_incr) { duke@435: // %%%% consider branching to a single shared dispatch stub (for each bcp_incr) duke@435: assert_not_delayed(); duke@435: ldub( Lbcp, bcp_incr, Lbyte_code); // load next bytecode duke@435: dispatch_Lbyte_code(state, Interpreter::dispatch_table(state), bcp_incr, false); duke@435: } duke@435: duke@435: duke@435: void InterpreterMacroAssembler::dispatch_via(TosState state, address* table) { duke@435: // load current bytecode duke@435: assert_not_delayed(); duke@435: ldub( Lbcp, 0, Lbyte_code); // load next bytecode duke@435: dispatch_base(state, table); duke@435: } duke@435: duke@435: duke@435: void InterpreterMacroAssembler::call_VM_leaf_base( duke@435: Register java_thread, duke@435: address entry_point, duke@435: int number_of_arguments duke@435: ) { duke@435: if (!java_thread->is_valid()) duke@435: java_thread = L7_thread_cache; duke@435: // super call duke@435: MacroAssembler::call_VM_leaf_base(java_thread, entry_point, number_of_arguments); duke@435: } duke@435: duke@435: duke@435: void InterpreterMacroAssembler::call_VM_base( duke@435: Register oop_result, duke@435: Register java_thread, duke@435: Register last_java_sp, duke@435: address entry_point, duke@435: int number_of_arguments, duke@435: bool check_exception duke@435: ) { duke@435: if (!java_thread->is_valid()) duke@435: java_thread = L7_thread_cache; duke@435: // See class ThreadInVMfromInterpreter, which assumes that the interpreter duke@435: // takes responsibility for setting its own thread-state on call-out. duke@435: // However, ThreadInVMfromInterpreter resets the state to "in_Java". duke@435: duke@435: //save_bcp(); // save bcp duke@435: MacroAssembler::call_VM_base(oop_result, java_thread, last_java_sp, entry_point, number_of_arguments, check_exception); duke@435: //restore_bcp(); // restore bcp duke@435: //restore_locals(); // restore locals pointer duke@435: } duke@435: duke@435: duke@435: void InterpreterMacroAssembler::check_and_handle_popframe(Register scratch_reg) { duke@435: if (JvmtiExport::can_pop_frame()) { duke@435: Label L; duke@435: duke@435: // Check the "pending popframe condition" flag in the current thread duke@435: Address popframe_condition_addr(G2_thread, 0, in_bytes(JavaThread::popframe_condition_offset())); duke@435: ld(popframe_condition_addr, scratch_reg); duke@435: duke@435: // Initiate popframe handling only if it is not already being processed. If the flag duke@435: // has the popframe_processing bit set, it means that this code is called *during* popframe duke@435: // handling - we don't want to reenter. duke@435: btst(JavaThread::popframe_pending_bit, scratch_reg); duke@435: br(zero, false, pt, L); duke@435: delayed()->nop(); duke@435: btst(JavaThread::popframe_processing_bit, scratch_reg); duke@435: br(notZero, false, pt, L); duke@435: delayed()->nop(); duke@435: duke@435: // Call Interpreter::remove_activation_preserving_args_entry() to get the duke@435: // address of the same-named entrypoint in the generated interpreter code. duke@435: call_VM_leaf(noreg, CAST_FROM_FN_PTR(address, Interpreter::remove_activation_preserving_args_entry)); duke@435: duke@435: // Jump to Interpreter::_remove_activation_preserving_args_entry duke@435: jmpl(O0, G0, G0); duke@435: delayed()->nop(); duke@435: bind(L); duke@435: } duke@435: } duke@435: duke@435: duke@435: void InterpreterMacroAssembler::load_earlyret_value(TosState state) { duke@435: Register thr_state = G4_scratch; duke@435: ld_ptr(Address(G2_thread, 0, in_bytes(JavaThread::jvmti_thread_state_offset())), duke@435: thr_state); duke@435: const Address tos_addr(thr_state, 0, in_bytes(JvmtiThreadState::earlyret_tos_offset())); duke@435: const Address oop_addr(thr_state, 0, in_bytes(JvmtiThreadState::earlyret_oop_offset())); duke@435: const Address val_addr(thr_state, 0, in_bytes(JvmtiThreadState::earlyret_value_offset())); duke@435: switch (state) { duke@435: case ltos: ld_long(val_addr, Otos_l); break; duke@435: case atos: ld_ptr(oop_addr, Otos_l); duke@435: st_ptr(G0, oop_addr); break; duke@435: case btos: // fall through duke@435: case ctos: // fall through duke@435: case stos: // fall through duke@435: case itos: ld(val_addr, Otos_l1); break; duke@435: case ftos: ldf(FloatRegisterImpl::S, val_addr, Ftos_f); break; duke@435: case dtos: ldf(FloatRegisterImpl::D, val_addr, Ftos_d); break; duke@435: case vtos: /* nothing to do */ break; duke@435: default : ShouldNotReachHere(); duke@435: } duke@435: // Clean up tos value in the jvmti thread state duke@435: or3(G0, ilgl, G3_scratch); duke@435: stw(G3_scratch, tos_addr); duke@435: st_long(G0, val_addr); duke@435: interp_verify_oop(Otos_i, state, __FILE__, __LINE__); duke@435: } duke@435: duke@435: duke@435: void InterpreterMacroAssembler::check_and_handle_earlyret(Register scratch_reg) { duke@435: if (JvmtiExport::can_force_early_return()) { duke@435: Label L; duke@435: Register thr_state = G3_scratch; duke@435: ld_ptr(Address(G2_thread, 0, in_bytes(JavaThread::jvmti_thread_state_offset())), duke@435: thr_state); duke@435: tst(thr_state); duke@435: br(zero, false, pt, L); // if (thread->jvmti_thread_state() == NULL) exit; duke@435: delayed()->nop(); duke@435: duke@435: // Initiate earlyret handling only if it is not already being processed. duke@435: // If the flag has the earlyret_processing bit set, it means that this code duke@435: // is called *during* earlyret handling - we don't want to reenter. duke@435: ld(Address(thr_state, 0, in_bytes(JvmtiThreadState::earlyret_state_offset())), duke@435: G4_scratch); duke@435: cmp(G4_scratch, JvmtiThreadState::earlyret_pending); duke@435: br(Assembler::notEqual, false, pt, L); duke@435: delayed()->nop(); duke@435: duke@435: // Call Interpreter::remove_activation_early_entry() to get the address of the duke@435: // same-named entrypoint in the generated interpreter code duke@435: Address tos_addr(thr_state, 0, in_bytes(JvmtiThreadState::earlyret_tos_offset())); duke@435: ld(tos_addr, Otos_l1); duke@435: call_VM_leaf(noreg, CAST_FROM_FN_PTR(address, Interpreter::remove_activation_early_entry), Otos_l1); duke@435: duke@435: // Jump to Interpreter::_remove_activation_early_entry duke@435: jmpl(O0, G0, G0); duke@435: delayed()->nop(); duke@435: bind(L); duke@435: } duke@435: } duke@435: duke@435: duke@435: void InterpreterMacroAssembler::super_call_VM_leaf(Register thread_cache, address entry_point, Register arg_1) { duke@435: mov(arg_1, O0); duke@435: MacroAssembler::call_VM_leaf_base(thread_cache, entry_point, 1); duke@435: } duke@435: #endif /* CC_INTERP */ duke@435: duke@435: duke@435: #ifndef CC_INTERP duke@435: duke@435: void InterpreterMacroAssembler::dispatch_base(TosState state, address* table) { duke@435: assert_not_delayed(); duke@435: dispatch_Lbyte_code(state, table); duke@435: } duke@435: duke@435: duke@435: void InterpreterMacroAssembler::dispatch_normal(TosState state) { duke@435: dispatch_base(state, Interpreter::normal_table(state)); duke@435: } duke@435: duke@435: duke@435: void InterpreterMacroAssembler::dispatch_only(TosState state) { duke@435: dispatch_base(state, Interpreter::dispatch_table(state)); duke@435: } duke@435: duke@435: duke@435: // common code to dispatch and dispatch_only duke@435: // dispatch value in Lbyte_code and increment Lbcp duke@435: duke@435: void InterpreterMacroAssembler::dispatch_Lbyte_code(TosState state, address* table, int bcp_incr, bool verify) { duke@435: verify_FPU(1, state); duke@435: // %%%%% maybe implement +VerifyActivationFrameSize here duke@435: //verify_thread(); //too slow; we will just verify on method entry & exit duke@435: if (verify) interp_verify_oop(Otos_i, state, __FILE__, __LINE__); duke@435: #ifdef FAST_DISPATCH duke@435: if (table == Interpreter::dispatch_table(state)) { duke@435: // use IdispatchTables duke@435: add(Lbyte_code, Interpreter::distance_from_dispatch_table(state), Lbyte_code); duke@435: // add offset to correct dispatch table duke@435: sll(Lbyte_code, LogBytesPerWord, Lbyte_code); // multiply by wordSize duke@435: ld_ptr(IdispatchTables, Lbyte_code, G3_scratch); // get entry addr duke@435: } else { duke@435: #endif duke@435: // dispatch table to use duke@435: Address tbl(G3_scratch, (address)table); duke@435: duke@435: sll(Lbyte_code, LogBytesPerWord, Lbyte_code); // multiply by wordSize duke@435: load_address(tbl); // compute addr of table duke@435: ld_ptr(G3_scratch, Lbyte_code, G3_scratch); // get entry addr duke@435: #ifdef FAST_DISPATCH duke@435: } duke@435: #endif duke@435: jmp( G3_scratch, 0 ); duke@435: if (bcp_incr != 0) delayed()->inc(Lbcp, bcp_incr); duke@435: else delayed()->nop(); duke@435: } duke@435: duke@435: duke@435: // Helpers for expression stack duke@435: duke@435: // Longs and doubles are Category 2 computational types in the duke@435: // JVM specification (section 3.11.1) and take 2 expression stack or duke@435: // local slots. duke@435: // Aligning them on 32 bit with tagged stacks is hard because the code generated duke@435: // for the dup* bytecodes depends on what types are already on the stack. duke@435: // If the types are split into the two stack/local slots, that is much easier duke@435: // (and we can use 0 for non-reference tags). duke@435: duke@435: // Known good alignment in _LP64 but unknown otherwise duke@435: void InterpreterMacroAssembler::load_unaligned_double(Register r1, int offset, FloatRegister d) { duke@435: assert_not_delayed(); duke@435: duke@435: #ifdef _LP64 duke@435: ldf(FloatRegisterImpl::D, r1, offset, d); duke@435: #else duke@435: ldf(FloatRegisterImpl::S, r1, offset, d); duke@435: ldf(FloatRegisterImpl::S, r1, offset + Interpreter::stackElementSize(), d->successor()); duke@435: #endif duke@435: } duke@435: duke@435: // Known good alignment in _LP64 but unknown otherwise duke@435: void InterpreterMacroAssembler::store_unaligned_double(FloatRegister d, Register r1, int offset) { duke@435: assert_not_delayed(); duke@435: duke@435: #ifdef _LP64 duke@435: stf(FloatRegisterImpl::D, d, r1, offset); duke@435: // store something more useful here duke@435: debug_only(stx(G0, r1, offset+Interpreter::stackElementSize());) duke@435: #else duke@435: stf(FloatRegisterImpl::S, d, r1, offset); duke@435: stf(FloatRegisterImpl::S, d->successor(), r1, offset + Interpreter::stackElementSize()); duke@435: #endif duke@435: } duke@435: duke@435: duke@435: // Known good alignment in _LP64 but unknown otherwise duke@435: void InterpreterMacroAssembler::load_unaligned_long(Register r1, int offset, Register rd) { duke@435: assert_not_delayed(); duke@435: #ifdef _LP64 duke@435: ldx(r1, offset, rd); duke@435: #else duke@435: ld(r1, offset, rd); duke@435: ld(r1, offset + Interpreter::stackElementSize(), rd->successor()); duke@435: #endif duke@435: } duke@435: duke@435: // Known good alignment in _LP64 but unknown otherwise duke@435: void InterpreterMacroAssembler::store_unaligned_long(Register l, Register r1, int offset) { duke@435: assert_not_delayed(); duke@435: duke@435: #ifdef _LP64 duke@435: stx(l, r1, offset); duke@435: // store something more useful here duke@435: debug_only(stx(G0, r1, offset+Interpreter::stackElementSize());) duke@435: #else duke@435: st(l, r1, offset); duke@435: st(l->successor(), r1, offset + Interpreter::stackElementSize()); duke@435: #endif duke@435: } duke@435: duke@435: #ifdef ASSERT duke@435: void InterpreterMacroAssembler::verify_stack_tag(frame::Tag t, duke@435: Register r, duke@435: Register scratch) { duke@435: if (TaggedStackInterpreter) { duke@435: Label ok, long_ok; duke@435: ld_ptr(Lesp, Interpreter::expr_tag_offset_in_bytes(0), r); duke@435: if (t == frame::TagCategory2) { duke@435: cmp(r, G0); duke@435: brx(Assembler::equal, false, Assembler::pt, long_ok); duke@435: delayed()->ld_ptr(Lesp, Interpreter::expr_tag_offset_in_bytes(1), r); duke@435: stop("stack long/double tag value bad"); duke@435: bind(long_ok); duke@435: cmp(r, G0); duke@435: } else if (t == frame::TagValue) { duke@435: cmp(r, G0); duke@435: } else { duke@435: assert_different_registers(r, scratch); duke@435: mov(t, scratch); duke@435: cmp(r, scratch); duke@435: } duke@435: brx(Assembler::equal, false, Assembler::pt, ok); duke@435: delayed()->nop(); duke@435: // Also compare if the stack value is zero, then the tag might duke@435: // not have been set coming from deopt. duke@435: ld_ptr(Lesp, Interpreter::expr_offset_in_bytes(0), r); duke@435: cmp(r, G0); duke@435: brx(Assembler::equal, false, Assembler::pt, ok); duke@435: delayed()->nop(); duke@435: stop("Stack tag value is bad"); duke@435: bind(ok); duke@435: } duke@435: } duke@435: #endif // ASSERT duke@435: duke@435: void InterpreterMacroAssembler::pop_i(Register r) { duke@435: assert_not_delayed(); duke@435: // Uses destination register r for scratch duke@435: debug_only(verify_stack_tag(frame::TagValue, r)); duke@435: ld(Lesp, Interpreter::expr_offset_in_bytes(0), r); duke@435: inc(Lesp, Interpreter::stackElementSize()); duke@435: debug_only(verify_esp(Lesp)); duke@435: } duke@435: duke@435: void InterpreterMacroAssembler::pop_ptr(Register r, Register scratch) { duke@435: assert_not_delayed(); duke@435: // Uses destination register r for scratch duke@435: debug_only(verify_stack_tag(frame::TagReference, r, scratch)); duke@435: ld_ptr(Lesp, Interpreter::expr_offset_in_bytes(0), r); duke@435: inc(Lesp, Interpreter::stackElementSize()); duke@435: debug_only(verify_esp(Lesp)); duke@435: } duke@435: duke@435: void InterpreterMacroAssembler::pop_l(Register r) { duke@435: assert_not_delayed(); duke@435: // Uses destination register r for scratch duke@435: debug_only(verify_stack_tag(frame::TagCategory2, r)); duke@435: load_unaligned_long(Lesp, Interpreter::expr_offset_in_bytes(0), r); duke@435: inc(Lesp, 2*Interpreter::stackElementSize()); duke@435: debug_only(verify_esp(Lesp)); duke@435: } duke@435: duke@435: duke@435: void InterpreterMacroAssembler::pop_f(FloatRegister f, Register scratch) { duke@435: assert_not_delayed(); duke@435: debug_only(verify_stack_tag(frame::TagValue, scratch)); duke@435: ldf(FloatRegisterImpl::S, Lesp, Interpreter::expr_offset_in_bytes(0), f); duke@435: inc(Lesp, Interpreter::stackElementSize()); duke@435: debug_only(verify_esp(Lesp)); duke@435: } duke@435: duke@435: duke@435: void InterpreterMacroAssembler::pop_d(FloatRegister f, Register scratch) { duke@435: assert_not_delayed(); duke@435: debug_only(verify_stack_tag(frame::TagCategory2, scratch)); duke@435: load_unaligned_double(Lesp, Interpreter::expr_offset_in_bytes(0), f); duke@435: inc(Lesp, 2*Interpreter::stackElementSize()); duke@435: debug_only(verify_esp(Lesp)); duke@435: } duke@435: duke@435: duke@435: // (Note use register first, then decrement so dec can be done during store stall) duke@435: void InterpreterMacroAssembler::tag_stack(Register r) { duke@435: if (TaggedStackInterpreter) { duke@435: st_ptr(r, Lesp, Interpreter::tag_offset_in_bytes()); duke@435: } duke@435: } duke@435: duke@435: void InterpreterMacroAssembler::tag_stack(frame::Tag t, Register r) { duke@435: if (TaggedStackInterpreter) { duke@435: assert (frame::TagValue == 0, "TagValue must be zero"); duke@435: if (t == frame::TagValue) { duke@435: st_ptr(G0, Lesp, Interpreter::tag_offset_in_bytes()); duke@435: } else if (t == frame::TagCategory2) { duke@435: st_ptr(G0, Lesp, Interpreter::tag_offset_in_bytes()); duke@435: // Tag next slot down too duke@435: st_ptr(G0, Lesp, -Interpreter::stackElementSize() + Interpreter::tag_offset_in_bytes()); duke@435: } else { duke@435: assert_different_registers(r, O3); duke@435: mov(t, O3); duke@435: st_ptr(O3, Lesp, Interpreter::tag_offset_in_bytes()); duke@435: } duke@435: } duke@435: } duke@435: duke@435: void InterpreterMacroAssembler::push_i(Register r) { duke@435: assert_not_delayed(); duke@435: debug_only(verify_esp(Lesp)); duke@435: tag_stack(frame::TagValue, r); duke@435: st( r, Lesp, Interpreter::value_offset_in_bytes()); duke@435: dec( Lesp, Interpreter::stackElementSize()); duke@435: } duke@435: duke@435: void InterpreterMacroAssembler::push_ptr(Register r) { duke@435: assert_not_delayed(); duke@435: tag_stack(frame::TagReference, r); duke@435: st_ptr( r, Lesp, Interpreter::value_offset_in_bytes()); duke@435: dec( Lesp, Interpreter::stackElementSize()); duke@435: } duke@435: duke@435: void InterpreterMacroAssembler::push_ptr(Register r, Register tag) { duke@435: assert_not_delayed(); duke@435: tag_stack(tag); duke@435: st_ptr(r, Lesp, Interpreter::value_offset_in_bytes()); duke@435: dec( Lesp, Interpreter::stackElementSize()); duke@435: } duke@435: duke@435: // remember: our convention for longs in SPARC is: duke@435: // O0 (Otos_l1) has high-order part in first word, duke@435: // O1 (Otos_l2) has low-order part in second word duke@435: duke@435: void InterpreterMacroAssembler::push_l(Register r) { duke@435: assert_not_delayed(); duke@435: debug_only(verify_esp(Lesp)); duke@435: tag_stack(frame::TagCategory2, r); duke@435: // Longs are in stored in memory-correct order, even if unaligned. duke@435: // and may be separated by stack tags. duke@435: int offset = -Interpreter::stackElementSize() + Interpreter::value_offset_in_bytes(); duke@435: store_unaligned_long(r, Lesp, offset); duke@435: dec(Lesp, 2 * Interpreter::stackElementSize()); duke@435: } duke@435: duke@435: duke@435: void InterpreterMacroAssembler::push_f(FloatRegister f) { duke@435: assert_not_delayed(); duke@435: debug_only(verify_esp(Lesp)); duke@435: tag_stack(frame::TagValue, Otos_i); duke@435: stf(FloatRegisterImpl::S, f, Lesp, Interpreter::value_offset_in_bytes()); duke@435: dec(Lesp, Interpreter::stackElementSize()); duke@435: } duke@435: duke@435: duke@435: void InterpreterMacroAssembler::push_d(FloatRegister d) { duke@435: assert_not_delayed(); duke@435: debug_only(verify_esp(Lesp)); duke@435: tag_stack(frame::TagCategory2, Otos_i); duke@435: // Longs are in stored in memory-correct order, even if unaligned. duke@435: // and may be separated by stack tags. duke@435: int offset = -Interpreter::stackElementSize() + Interpreter::value_offset_in_bytes(); duke@435: store_unaligned_double(d, Lesp, offset); duke@435: dec(Lesp, 2 * Interpreter::stackElementSize()); duke@435: } duke@435: duke@435: duke@435: void InterpreterMacroAssembler::push(TosState state) { duke@435: interp_verify_oop(Otos_i, state, __FILE__, __LINE__); duke@435: switch (state) { duke@435: case atos: push_ptr(); break; duke@435: case btos: push_i(); break; duke@435: case ctos: duke@435: case stos: push_i(); break; duke@435: case itos: push_i(); break; duke@435: case ltos: push_l(); break; duke@435: case ftos: push_f(); break; duke@435: case dtos: push_d(); break; duke@435: case vtos: /* nothing to do */ break; duke@435: default : ShouldNotReachHere(); duke@435: } duke@435: } duke@435: duke@435: duke@435: void InterpreterMacroAssembler::pop(TosState state) { duke@435: switch (state) { duke@435: case atos: pop_ptr(); break; duke@435: case btos: pop_i(); break; duke@435: case ctos: duke@435: case stos: pop_i(); break; duke@435: case itos: pop_i(); break; duke@435: case ltos: pop_l(); break; duke@435: case ftos: pop_f(); break; duke@435: case dtos: pop_d(); break; duke@435: case vtos: /* nothing to do */ break; duke@435: default : ShouldNotReachHere(); duke@435: } duke@435: interp_verify_oop(Otos_i, state, __FILE__, __LINE__); duke@435: } duke@435: duke@435: duke@435: // Tagged stack helpers for swap and dup duke@435: void InterpreterMacroAssembler::load_ptr_and_tag(int n, Register val, duke@435: Register tag) { duke@435: ld_ptr(Lesp, Interpreter::expr_offset_in_bytes(n), val); duke@435: if (TaggedStackInterpreter) { duke@435: ld_ptr(Lesp, Interpreter::expr_tag_offset_in_bytes(n), tag); duke@435: } duke@435: } duke@435: void InterpreterMacroAssembler::store_ptr_and_tag(int n, Register val, duke@435: Register tag) { duke@435: st_ptr(val, Lesp, Interpreter::expr_offset_in_bytes(n)); duke@435: if (TaggedStackInterpreter) { duke@435: st_ptr(tag, Lesp, Interpreter::expr_tag_offset_in_bytes(n)); duke@435: } duke@435: } duke@435: duke@435: duke@435: void InterpreterMacroAssembler::load_receiver(Register param_count, duke@435: Register recv) { duke@435: duke@435: sll(param_count, Interpreter::logStackElementSize(), param_count); duke@435: if (TaggedStackInterpreter) { duke@435: add(param_count, Interpreter::value_offset_in_bytes(), param_count); // get obj address duke@435: } duke@435: ld_ptr(Lesp, param_count, recv); // gets receiver Oop duke@435: } duke@435: duke@435: void InterpreterMacroAssembler::empty_expression_stack() { duke@435: // Reset Lesp. duke@435: sub( Lmonitors, wordSize, Lesp ); duke@435: duke@435: // Reset SP by subtracting more space from Lesp. duke@435: Label done; duke@435: duke@435: const Address max_stack (Lmethod, 0, in_bytes(methodOopDesc::max_stack_offset())); duke@435: const Address access_flags(Lmethod, 0, in_bytes(methodOopDesc::access_flags_offset())); duke@435: duke@435: verify_oop(Lmethod); duke@435: duke@435: duke@435: assert( G4_scratch != Gframe_size, duke@435: "Only you can prevent register aliasing!"); duke@435: duke@435: // A native does not need to do this, since its callee does not change SP. duke@435: ld(access_flags, Gframe_size); duke@435: btst(JVM_ACC_NATIVE, Gframe_size); duke@435: br(Assembler::notZero, false, Assembler::pt, done); duke@435: delayed()->nop(); duke@435: duke@435: // duke@435: // Compute max expression stack+register save area duke@435: // duke@435: lduh( max_stack, Gframe_size ); duke@435: if (TaggedStackInterpreter) sll ( Gframe_size, 1, Gframe_size); // max_stack * 2 for TAGS duke@435: add( Gframe_size, frame::memory_parameter_word_sp_offset, Gframe_size ); duke@435: duke@435: // duke@435: // now set up a stack frame with the size computed above duke@435: // duke@435: //round_to( Gframe_size, WordsPerLong ); // -- moved down to the "and" below duke@435: sll( Gframe_size, LogBytesPerWord, Gframe_size ); duke@435: sub( Lesp, Gframe_size, Gframe_size ); duke@435: and3( Gframe_size, -(2 * wordSize), Gframe_size ); // align SP (downwards) to an 8/16-byte boundary duke@435: debug_only(verify_sp(Gframe_size, G4_scratch)); duke@435: #ifdef _LP64 duke@435: sub(Gframe_size, STACK_BIAS, Gframe_size ); duke@435: #endif duke@435: mov(Gframe_size, SP); duke@435: duke@435: bind(done); duke@435: } duke@435: duke@435: duke@435: #ifdef ASSERT duke@435: void InterpreterMacroAssembler::verify_sp(Register Rsp, Register Rtemp) { duke@435: Label Bad, OK; duke@435: duke@435: // Saved SP must be aligned. duke@435: #ifdef _LP64 duke@435: btst(2*BytesPerWord-1, Rsp); duke@435: #else duke@435: btst(LongAlignmentMask, Rsp); duke@435: #endif duke@435: br(Assembler::notZero, false, Assembler::pn, Bad); duke@435: delayed()->nop(); duke@435: duke@435: // Saved SP, plus register window size, must not be above FP. duke@435: add(Rsp, frame::register_save_words * wordSize, Rtemp); duke@435: #ifdef _LP64 duke@435: sub(Rtemp, STACK_BIAS, Rtemp); // Bias Rtemp before cmp to FP duke@435: #endif duke@435: cmp(Rtemp, FP); duke@435: brx(Assembler::greaterUnsigned, false, Assembler::pn, Bad); duke@435: delayed()->nop(); duke@435: duke@435: // Saved SP must not be ridiculously below current SP. duke@435: size_t maxstack = MAX2(JavaThread::stack_size_at_create(), (size_t) 4*K*K); duke@435: set(maxstack, Rtemp); duke@435: sub(SP, Rtemp, Rtemp); duke@435: #ifdef _LP64 duke@435: add(Rtemp, STACK_BIAS, Rtemp); // Unbias Rtemp before cmp to Rsp duke@435: #endif duke@435: cmp(Rsp, Rtemp); duke@435: brx(Assembler::lessUnsigned, false, Assembler::pn, Bad); duke@435: delayed()->nop(); duke@435: duke@435: br(Assembler::always, false, Assembler::pn, OK); duke@435: delayed()->nop(); duke@435: duke@435: bind(Bad); duke@435: stop("on return to interpreted call, restored SP is corrupted"); duke@435: duke@435: bind(OK); duke@435: } duke@435: duke@435: duke@435: void InterpreterMacroAssembler::verify_esp(Register Resp) { duke@435: // about to read or write Resp[0] duke@435: // make sure it is not in the monitors or the register save area duke@435: Label OK1, OK2; duke@435: duke@435: cmp(Resp, Lmonitors); duke@435: brx(Assembler::lessUnsigned, true, Assembler::pt, OK1); duke@435: delayed()->sub(Resp, frame::memory_parameter_word_sp_offset * wordSize, Resp); duke@435: stop("too many pops: Lesp points into monitor area"); duke@435: bind(OK1); duke@435: #ifdef _LP64 duke@435: sub(Resp, STACK_BIAS, Resp); duke@435: #endif duke@435: cmp(Resp, SP); duke@435: brx(Assembler::greaterEqualUnsigned, false, Assembler::pt, OK2); duke@435: delayed()->add(Resp, STACK_BIAS + frame::memory_parameter_word_sp_offset * wordSize, Resp); duke@435: stop("too many pushes: Lesp points into register window"); duke@435: bind(OK2); duke@435: } duke@435: #endif // ASSERT duke@435: duke@435: // Load compiled (i2c) or interpreter entry when calling from interpreted and duke@435: // do the call. Centralized so that all interpreter calls will do the same actions. duke@435: // If jvmti single stepping is on for a thread we must not call compiled code. duke@435: void InterpreterMacroAssembler::call_from_interpreter(Register target, Register scratch, Register Rret) { duke@435: duke@435: // Assume we want to go compiled if available duke@435: duke@435: ld_ptr(G5_method, in_bytes(methodOopDesc::from_interpreted_offset()), target); duke@435: duke@435: if (JvmtiExport::can_post_interpreter_events()) { duke@435: // JVMTI events, such as single-stepping, are implemented partly by avoiding running duke@435: // compiled code in threads for which the event is enabled. Check here for duke@435: // interp_only_mode if these events CAN be enabled. duke@435: verify_thread(); duke@435: Label skip_compiled_code; duke@435: duke@435: const Address interp_only (G2_thread, 0, in_bytes(JavaThread::interp_only_mode_offset())); duke@435: duke@435: ld(interp_only, scratch); duke@435: tst(scratch); duke@435: br(Assembler::notZero, true, Assembler::pn, skip_compiled_code); duke@435: delayed()->ld_ptr(G5_method, in_bytes(methodOopDesc::interpreter_entry_offset()), target); duke@435: bind(skip_compiled_code); duke@435: } duke@435: duke@435: // the i2c_adapters need methodOop in G5_method (right? %%%) duke@435: // do the call duke@435: #ifdef ASSERT duke@435: { duke@435: Label ok; duke@435: br_notnull(target, false, Assembler::pt, ok); duke@435: delayed()->nop(); duke@435: stop("null entry point"); duke@435: bind(ok); duke@435: } duke@435: #endif // ASSERT duke@435: duke@435: // Adjust Rret first so Llast_SP can be same as Rret duke@435: add(Rret, -frame::pc_return_offset, O7); duke@435: add(Lesp, BytesPerWord, Gargs); // setup parameter pointer duke@435: // Record SP so we can remove any stack space allocated by adapter transition duke@435: jmp(target, 0); duke@435: delayed()->mov(SP, Llast_SP); duke@435: } duke@435: duke@435: void InterpreterMacroAssembler::if_cmp(Condition cc, bool ptr_compare) { duke@435: assert_not_delayed(); duke@435: duke@435: Label not_taken; duke@435: if (ptr_compare) brx(cc, false, Assembler::pn, not_taken); duke@435: else br (cc, false, Assembler::pn, not_taken); duke@435: delayed()->nop(); duke@435: duke@435: TemplateTable::branch(false,false); duke@435: duke@435: bind(not_taken); duke@435: duke@435: profile_not_taken_branch(G3_scratch); duke@435: } duke@435: duke@435: duke@435: void InterpreterMacroAssembler::get_2_byte_integer_at_bcp( duke@435: int bcp_offset, duke@435: Register Rtmp, duke@435: Register Rdst, duke@435: signedOrNot is_signed, duke@435: setCCOrNot should_set_CC ) { duke@435: assert(Rtmp != Rdst, "need separate temp register"); duke@435: assert_not_delayed(); duke@435: switch (is_signed) { duke@435: default: ShouldNotReachHere(); duke@435: duke@435: case Signed: ldsb( Lbcp, bcp_offset, Rdst ); break; // high byte duke@435: case Unsigned: ldub( Lbcp, bcp_offset, Rdst ); break; // high byte duke@435: } duke@435: ldub( Lbcp, bcp_offset + 1, Rtmp ); // low byte duke@435: sll( Rdst, BitsPerByte, Rdst); duke@435: switch (should_set_CC ) { duke@435: default: ShouldNotReachHere(); duke@435: duke@435: case set_CC: orcc( Rdst, Rtmp, Rdst ); break; duke@435: case dont_set_CC: or3( Rdst, Rtmp, Rdst ); break; duke@435: } duke@435: } duke@435: duke@435: duke@435: void InterpreterMacroAssembler::get_4_byte_integer_at_bcp( duke@435: int bcp_offset, duke@435: Register Rtmp, duke@435: Register Rdst, duke@435: setCCOrNot should_set_CC ) { duke@435: assert(Rtmp != Rdst, "need separate temp register"); duke@435: assert_not_delayed(); duke@435: add( Lbcp, bcp_offset, Rtmp); duke@435: andcc( Rtmp, 3, G0); duke@435: Label aligned; duke@435: switch (should_set_CC ) { duke@435: default: ShouldNotReachHere(); duke@435: duke@435: case set_CC: break; duke@435: case dont_set_CC: break; duke@435: } duke@435: duke@435: br(Assembler::zero, true, Assembler::pn, aligned); duke@435: #ifdef _LP64 duke@435: delayed()->ldsw(Rtmp, 0, Rdst); duke@435: #else duke@435: delayed()->ld(Rtmp, 0, Rdst); duke@435: #endif duke@435: duke@435: ldub(Lbcp, bcp_offset + 3, Rdst); duke@435: ldub(Lbcp, bcp_offset + 2, Rtmp); sll(Rtmp, 8, Rtmp); or3(Rtmp, Rdst, Rdst); duke@435: ldub(Lbcp, bcp_offset + 1, Rtmp); sll(Rtmp, 16, Rtmp); or3(Rtmp, Rdst, Rdst); duke@435: #ifdef _LP64 duke@435: ldsb(Lbcp, bcp_offset + 0, Rtmp); sll(Rtmp, 24, Rtmp); duke@435: #else duke@435: // Unsigned load is faster than signed on some implementations duke@435: ldub(Lbcp, bcp_offset + 0, Rtmp); sll(Rtmp, 24, Rtmp); duke@435: #endif duke@435: or3(Rtmp, Rdst, Rdst ); duke@435: duke@435: bind(aligned); duke@435: if (should_set_CC == set_CC) tst(Rdst); duke@435: } duke@435: duke@435: duke@435: void InterpreterMacroAssembler::get_cache_and_index_at_bcp(Register cache, Register tmp, int bcp_offset) { duke@435: assert(bcp_offset > 0, "bcp is still pointing to start of bytecode"); duke@435: assert_different_registers(cache, tmp); duke@435: assert_not_delayed(); duke@435: get_2_byte_integer_at_bcp(bcp_offset, cache, tmp, Unsigned); duke@435: // convert from field index to ConstantPoolCacheEntry index duke@435: // and from word index to byte offset duke@435: sll(tmp, exact_log2(in_words(ConstantPoolCacheEntry::size()) * BytesPerWord), tmp); duke@435: add(LcpoolCache, tmp, cache); duke@435: } duke@435: duke@435: duke@435: void InterpreterMacroAssembler::get_cache_entry_pointer_at_bcp(Register cache, Register tmp, int bcp_offset) { duke@435: assert(bcp_offset > 0, "bcp is still pointing to start of bytecode"); duke@435: assert_different_registers(cache, tmp); duke@435: assert_not_delayed(); duke@435: get_2_byte_integer_at_bcp(bcp_offset, cache, tmp, Unsigned); duke@435: // convert from field index to ConstantPoolCacheEntry index duke@435: // and from word index to byte offset duke@435: sll(tmp, exact_log2(in_words(ConstantPoolCacheEntry::size()) * BytesPerWord), tmp); duke@435: // skip past the header duke@435: add(tmp, in_bytes(constantPoolCacheOopDesc::base_offset()), tmp); duke@435: // construct pointer to cache entry duke@435: add(LcpoolCache, tmp, cache); duke@435: } duke@435: duke@435: duke@435: // Generate a subtype check: branch to ok_is_subtype if sub_klass is coleenp@548: // a subtype of super_klass. Blows registers Rsuper_klass, Rsub_klass, tmp1, tmp2. duke@435: void InterpreterMacroAssembler::gen_subtype_check(Register Rsub_klass, duke@435: Register Rsuper_klass, duke@435: Register Rtmp1, duke@435: Register Rtmp2, duke@435: Register Rtmp3, duke@435: Label &ok_is_subtype ) { duke@435: Label not_subtype, loop; duke@435: duke@435: // Profile the not-null value's klass. duke@435: profile_typecheck(Rsub_klass, Rtmp1); duke@435: duke@435: // Load the super-klass's check offset into Rtmp1 duke@435: ld( Rsuper_klass, sizeof(oopDesc) + Klass::super_check_offset_offset_in_bytes(), Rtmp1 ); duke@435: // Load from the sub-klass's super-class display list, or a 1-word cache of duke@435: // the secondary superclass list, or a failing value with a sentinel offset duke@435: // if the super-klass is an interface or exceptionally deep in the Java duke@435: // hierarchy and we have to scan the secondary superclass list the hard way. duke@435: ld_ptr( Rsub_klass, Rtmp1, Rtmp2 ); duke@435: // See if we get an immediate positive hit duke@435: cmp( Rtmp2, Rsuper_klass ); duke@435: brx( Assembler::equal, false, Assembler::pt, ok_is_subtype ); duke@435: // In the delay slot, check for immediate negative hit duke@435: delayed()->cmp( Rtmp1, sizeof(oopDesc) + Klass::secondary_super_cache_offset_in_bytes() ); duke@435: br( Assembler::notEqual, false, Assembler::pt, not_subtype ); duke@435: // In the delay slot, check for self duke@435: delayed()->cmp( Rsub_klass, Rsuper_klass ); duke@435: brx( Assembler::equal, false, Assembler::pt, ok_is_subtype ); duke@435: duke@435: // Now do a linear scan of the secondary super-klass chain. duke@435: delayed()->ld_ptr( Rsub_klass, sizeof(oopDesc) + Klass::secondary_supers_offset_in_bytes(), Rtmp2 ); duke@435: coleenp@548: // compress superclass coleenp@548: if (UseCompressedOops) encode_heap_oop(Rsuper_klass); coleenp@548: duke@435: // Rtmp2 holds the objArrayOop of secondary supers. duke@435: ld( Rtmp2, arrayOopDesc::length_offset_in_bytes(), Rtmp1 );// Load the array length duke@435: // Check for empty secondary super list duke@435: tst(Rtmp1); duke@435: duke@435: // Top of search loop duke@435: bind( loop ); duke@435: br( Assembler::equal, false, Assembler::pn, not_subtype ); duke@435: delayed()->nop(); coleenp@548: duke@435: // load next super to check coleenp@548: if (UseCompressedOops) { coleenp@857: lduw( Rtmp2, arrayOopDesc::base_offset_in_bytes(T_OBJECT), Rtmp3); coleenp@548: // Bump array pointer forward one oop coleenp@548: add( Rtmp2, 4, Rtmp2 ); coleenp@548: } else { coleenp@548: ld_ptr( Rtmp2, arrayOopDesc::base_offset_in_bytes(T_OBJECT), Rtmp3); coleenp@548: // Bump array pointer forward one oop coleenp@548: add( Rtmp2, wordSize, Rtmp2); coleenp@548: } duke@435: // Look for Rsuper_klass on Rsub_klass's secondary super-class-overflow list duke@435: cmp( Rtmp3, Rsuper_klass ); duke@435: // A miss means we are NOT a subtype and need to keep looping duke@435: brx( Assembler::notEqual, false, Assembler::pt, loop ); duke@435: delayed()->deccc( Rtmp1 ); // dec trip counter in delay slot duke@435: // Falling out the bottom means we found a hit; we ARE a subtype coleenp@548: if (UseCompressedOops) decode_heap_oop(Rsuper_klass); duke@435: br( Assembler::always, false, Assembler::pt, ok_is_subtype ); duke@435: // Update the cache coleenp@548: delayed()->st_ptr( Rsuper_klass, Rsub_klass, coleenp@548: sizeof(oopDesc) + Klass::secondary_super_cache_offset_in_bytes() ); duke@435: duke@435: bind(not_subtype); duke@435: profile_typecheck_failed(Rtmp1); duke@435: } duke@435: duke@435: // Separate these two to allow for delay slot in middle duke@435: // These are used to do a test and full jump to exception-throwing code. duke@435: duke@435: // %%%%% Could possibly reoptimize this by testing to see if could use duke@435: // a single conditional branch (i.e. if span is small enough. duke@435: // If you go that route, than get rid of the split and give up duke@435: // on the delay-slot hack. duke@435: duke@435: void InterpreterMacroAssembler::throw_if_not_1_icc( Condition ok_condition, duke@435: Label& ok ) { duke@435: assert_not_delayed(); duke@435: br(ok_condition, true, pt, ok); duke@435: // DELAY SLOT duke@435: } duke@435: duke@435: void InterpreterMacroAssembler::throw_if_not_1_xcc( Condition ok_condition, duke@435: Label& ok ) { duke@435: assert_not_delayed(); duke@435: bp( ok_condition, true, Assembler::xcc, pt, ok); duke@435: // DELAY SLOT duke@435: } duke@435: duke@435: void InterpreterMacroAssembler::throw_if_not_1_x( Condition ok_condition, duke@435: Label& ok ) { duke@435: assert_not_delayed(); duke@435: brx(ok_condition, true, pt, ok); duke@435: // DELAY SLOT duke@435: } duke@435: duke@435: void InterpreterMacroAssembler::throw_if_not_2( address throw_entry_point, duke@435: Register Rscratch, duke@435: Label& ok ) { duke@435: assert(throw_entry_point != NULL, "entry point must be generated by now"); duke@435: Address dest(Rscratch, throw_entry_point); duke@435: jump_to(dest); duke@435: delayed()->nop(); duke@435: bind(ok); duke@435: } duke@435: duke@435: duke@435: // And if you cannot use the delay slot, here is a shorthand: duke@435: duke@435: void InterpreterMacroAssembler::throw_if_not_icc( Condition ok_condition, duke@435: address throw_entry_point, duke@435: Register Rscratch ) { duke@435: Label ok; duke@435: if (ok_condition != never) { duke@435: throw_if_not_1_icc( ok_condition, ok); duke@435: delayed()->nop(); duke@435: } duke@435: throw_if_not_2( throw_entry_point, Rscratch, ok); duke@435: } duke@435: void InterpreterMacroAssembler::throw_if_not_xcc( Condition ok_condition, duke@435: address throw_entry_point, duke@435: Register Rscratch ) { duke@435: Label ok; duke@435: if (ok_condition != never) { duke@435: throw_if_not_1_xcc( ok_condition, ok); duke@435: delayed()->nop(); duke@435: } duke@435: throw_if_not_2( throw_entry_point, Rscratch, ok); duke@435: } duke@435: void InterpreterMacroAssembler::throw_if_not_x( Condition ok_condition, duke@435: address throw_entry_point, duke@435: Register Rscratch ) { duke@435: Label ok; duke@435: if (ok_condition != never) { duke@435: throw_if_not_1_x( ok_condition, ok); duke@435: delayed()->nop(); duke@435: } duke@435: throw_if_not_2( throw_entry_point, Rscratch, ok); duke@435: } duke@435: duke@435: // Check that index is in range for array, then shift index by index_shift, and put arrayOop + shifted_index into res duke@435: // Note: res is still shy of address by array offset into object. duke@435: duke@435: void InterpreterMacroAssembler::index_check_without_pop(Register array, Register index, int index_shift, Register tmp, Register res) { duke@435: assert_not_delayed(); duke@435: duke@435: verify_oop(array); duke@435: #ifdef _LP64 duke@435: // sign extend since tos (index) can be a 32bit value duke@435: sra(index, G0, index); duke@435: #endif // _LP64 duke@435: duke@435: // check array duke@435: Label ptr_ok; duke@435: tst(array); duke@435: throw_if_not_1_x( notZero, ptr_ok ); duke@435: delayed()->ld( array, arrayOopDesc::length_offset_in_bytes(), tmp ); // check index duke@435: throw_if_not_2( Interpreter::_throw_NullPointerException_entry, G3_scratch, ptr_ok); duke@435: duke@435: Label index_ok; duke@435: cmp(index, tmp); duke@435: throw_if_not_1_icc( lessUnsigned, index_ok ); duke@435: if (index_shift > 0) delayed()->sll(index, index_shift, index); duke@435: else delayed()->add(array, index, res); // addr - const offset in index duke@435: // convention: move aberrant index into G3_scratch for exception message duke@435: mov(index, G3_scratch); duke@435: throw_if_not_2( Interpreter::_throw_ArrayIndexOutOfBoundsException_entry, G4_scratch, index_ok); duke@435: duke@435: // add offset if didn't do it in delay slot duke@435: if (index_shift > 0) add(array, index, res); // addr - const offset in index duke@435: } duke@435: duke@435: duke@435: void InterpreterMacroAssembler::index_check(Register array, Register index, int index_shift, Register tmp, Register res) { duke@435: assert_not_delayed(); duke@435: duke@435: // pop array duke@435: pop_ptr(array); duke@435: duke@435: // check array duke@435: index_check_without_pop(array, index, index_shift, tmp, res); duke@435: } duke@435: duke@435: duke@435: void InterpreterMacroAssembler::get_constant_pool(Register Rdst) { duke@435: ld_ptr(Lmethod, in_bytes(methodOopDesc::constants_offset()), Rdst); duke@435: } duke@435: duke@435: duke@435: void InterpreterMacroAssembler::get_constant_pool_cache(Register Rdst) { duke@435: get_constant_pool(Rdst); duke@435: ld_ptr(Rdst, constantPoolOopDesc::cache_offset_in_bytes(), Rdst); duke@435: } duke@435: duke@435: duke@435: void InterpreterMacroAssembler::get_cpool_and_tags(Register Rcpool, Register Rtags) { duke@435: get_constant_pool(Rcpool); duke@435: ld_ptr(Rcpool, constantPoolOopDesc::tags_offset_in_bytes(), Rtags); duke@435: } duke@435: duke@435: duke@435: // unlock if synchronized method duke@435: // duke@435: // Unlock the receiver if this is a synchronized method. duke@435: // Unlock any Java monitors from syncronized blocks. duke@435: // duke@435: // If there are locked Java monitors duke@435: // If throw_monitor_exception duke@435: // throws IllegalMonitorStateException duke@435: // Else if install_monitor_exception duke@435: // installs IllegalMonitorStateException duke@435: // Else duke@435: // no error processing duke@435: void InterpreterMacroAssembler::unlock_if_synchronized_method(TosState state, duke@435: bool throw_monitor_exception, duke@435: bool install_monitor_exception) { duke@435: Label unlocked, unlock, no_unlock; duke@435: duke@435: // get the value of _do_not_unlock_if_synchronized into G1_scratch duke@435: const Address do_not_unlock_if_synchronized(G2_thread, 0, duke@435: in_bytes(JavaThread::do_not_unlock_if_synchronized_offset())); duke@435: ldbool(do_not_unlock_if_synchronized, G1_scratch); duke@435: stbool(G0, do_not_unlock_if_synchronized); // reset the flag duke@435: duke@435: // check if synchronized method duke@435: const Address access_flags(Lmethod, 0, in_bytes(methodOopDesc::access_flags_offset())); duke@435: interp_verify_oop(Otos_i, state, __FILE__, __LINE__); duke@435: push(state); // save tos duke@435: ld(access_flags, G3_scratch); duke@435: btst(JVM_ACC_SYNCHRONIZED, G3_scratch); duke@435: br( zero, false, pt, unlocked); duke@435: delayed()->nop(); duke@435: duke@435: // Don't unlock anything if the _do_not_unlock_if_synchronized flag duke@435: // is set. duke@435: tstbool(G1_scratch); duke@435: br(Assembler::notZero, false, pn, no_unlock); duke@435: delayed()->nop(); duke@435: duke@435: // BasicObjectLock will be first in list, since this is a synchronized method. However, need duke@435: // to check that the object has not been unlocked by an explicit monitorexit bytecode. duke@435: duke@435: //Intel: if (throw_monitor_exception) ... else ... duke@435: // Entry already unlocked, need to throw exception duke@435: //... duke@435: duke@435: // pass top-most monitor elem duke@435: add( top_most_monitor(), O1 ); duke@435: duke@435: ld_ptr(O1, BasicObjectLock::obj_offset_in_bytes(), G3_scratch); duke@435: br_notnull(G3_scratch, false, pt, unlock); duke@435: delayed()->nop(); duke@435: duke@435: if (throw_monitor_exception) { duke@435: // Entry already unlocked need to throw an exception duke@435: MacroAssembler::call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_illegal_monitor_state_exception)); duke@435: should_not_reach_here(); duke@435: } else { duke@435: // Monitor already unlocked during a stack unroll. duke@435: // If requested, install an illegal_monitor_state_exception. duke@435: // Continue with stack unrolling. duke@435: if (install_monitor_exception) { duke@435: MacroAssembler::call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::new_illegal_monitor_state_exception)); duke@435: } duke@435: ba(false, unlocked); duke@435: delayed()->nop(); duke@435: } duke@435: duke@435: bind(unlock); duke@435: duke@435: unlock_object(O1); duke@435: duke@435: bind(unlocked); duke@435: duke@435: // I0, I1: Might contain return value duke@435: duke@435: // Check that all monitors are unlocked duke@435: { Label loop, exception, entry, restart; duke@435: duke@435: Register Rmptr = O0; duke@435: Register Rtemp = O1; duke@435: Register Rlimit = Lmonitors; duke@435: const jint delta = frame::interpreter_frame_monitor_size() * wordSize; duke@435: assert( (delta & LongAlignmentMask) == 0, duke@435: "sizeof BasicObjectLock must be even number of doublewords"); duke@435: duke@435: #ifdef ASSERT duke@435: add(top_most_monitor(), Rmptr, delta); duke@435: { Label L; duke@435: // ensure that Rmptr starts out above (or at) Rlimit duke@435: cmp(Rmptr, Rlimit); duke@435: brx(Assembler::greaterEqualUnsigned, false, pn, L); duke@435: delayed()->nop(); duke@435: stop("monitor stack has negative size"); duke@435: bind(L); duke@435: } duke@435: #endif duke@435: bind(restart); duke@435: ba(false, entry); duke@435: delayed()-> duke@435: add(top_most_monitor(), Rmptr, delta); // points to current entry, starting with bottom-most entry duke@435: duke@435: // Entry is still locked, need to throw exception duke@435: bind(exception); duke@435: if (throw_monitor_exception) { duke@435: MacroAssembler::call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_illegal_monitor_state_exception)); duke@435: should_not_reach_here(); duke@435: } else { duke@435: // Stack unrolling. Unlock object and if requested, install illegal_monitor_exception. duke@435: // Unlock does not block, so don't have to worry about the frame duke@435: unlock_object(Rmptr); duke@435: if (install_monitor_exception) { duke@435: MacroAssembler::call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::new_illegal_monitor_state_exception)); duke@435: } duke@435: ba(false, restart); duke@435: delayed()->nop(); duke@435: } duke@435: duke@435: bind(loop); duke@435: cmp(Rtemp, G0); // check if current entry is used duke@435: brx(Assembler::notEqual, false, pn, exception); duke@435: delayed()-> duke@435: dec(Rmptr, delta); // otherwise advance to next entry duke@435: #ifdef ASSERT duke@435: { Label L; duke@435: // ensure that Rmptr has not somehow stepped below Rlimit duke@435: cmp(Rmptr, Rlimit); duke@435: brx(Assembler::greaterEqualUnsigned, false, pn, L); duke@435: delayed()->nop(); duke@435: stop("ran off the end of the monitor stack"); duke@435: bind(L); duke@435: } duke@435: #endif duke@435: bind(entry); duke@435: cmp(Rmptr, Rlimit); // check if bottom reached duke@435: brx(Assembler::notEqual, true, pn, loop); // if not at bottom then check this entry duke@435: delayed()-> duke@435: ld_ptr(Rmptr, BasicObjectLock::obj_offset_in_bytes() - delta, Rtemp); duke@435: } duke@435: duke@435: bind(no_unlock); duke@435: pop(state); duke@435: interp_verify_oop(Otos_i, state, __FILE__, __LINE__); duke@435: } duke@435: duke@435: duke@435: // remove activation duke@435: // duke@435: // Unlock the receiver if this is a synchronized method. duke@435: // Unlock any Java monitors from syncronized blocks. duke@435: // Remove the activation from the stack. duke@435: // duke@435: // If there are locked Java monitors duke@435: // If throw_monitor_exception duke@435: // throws IllegalMonitorStateException duke@435: // Else if install_monitor_exception duke@435: // installs IllegalMonitorStateException duke@435: // Else duke@435: // no error processing duke@435: void InterpreterMacroAssembler::remove_activation(TosState state, duke@435: bool throw_monitor_exception, duke@435: bool install_monitor_exception) { duke@435: duke@435: unlock_if_synchronized_method(state, throw_monitor_exception, install_monitor_exception); duke@435: duke@435: // save result (push state before jvmti call and pop it afterwards) and notify jvmti duke@435: notify_method_exit(false, state, NotifyJVMTI); duke@435: duke@435: interp_verify_oop(Otos_i, state, __FILE__, __LINE__); duke@435: verify_oop(Lmethod); duke@435: verify_thread(); duke@435: duke@435: // return tos duke@435: assert(Otos_l1 == Otos_i, "adjust code below"); duke@435: switch (state) { duke@435: #ifdef _LP64 duke@435: case ltos: mov(Otos_l, Otos_l->after_save()); break; // O0 -> I0 duke@435: #else duke@435: case ltos: mov(Otos_l2, Otos_l2->after_save()); // fall through // O1 -> I1 duke@435: #endif duke@435: case btos: // fall through duke@435: case ctos: duke@435: case stos: // fall through duke@435: case atos: // fall through duke@435: case itos: mov(Otos_l1, Otos_l1->after_save()); break; // O0 -> I0 duke@435: case ftos: // fall through duke@435: case dtos: // fall through duke@435: case vtos: /* nothing to do */ break; duke@435: default : ShouldNotReachHere(); duke@435: } duke@435: duke@435: #if defined(COMPILER2) && !defined(_LP64) duke@435: if (state == ltos) { duke@435: // C2 expects long results in G1 we can't tell if we're returning to interpreted duke@435: // or compiled so just be safe use G1 and O0/O1 duke@435: duke@435: // Shift bits into high (msb) of G1 duke@435: sllx(Otos_l1->after_save(), 32, G1); duke@435: // Zero extend low bits duke@435: srl (Otos_l2->after_save(), 0, Otos_l2->after_save()); duke@435: or3 (Otos_l2->after_save(), G1, G1); duke@435: } duke@435: #endif /* COMPILER2 */ duke@435: duke@435: } duke@435: #endif /* CC_INTERP */ duke@435: duke@435: duke@435: // Lock object duke@435: // duke@435: // Argument - lock_reg points to the BasicObjectLock to be used for locking, duke@435: // it must be initialized with the object to lock duke@435: void InterpreterMacroAssembler::lock_object(Register lock_reg, Register Object) { duke@435: if (UseHeavyMonitors) { duke@435: call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter), lock_reg); duke@435: } duke@435: else { duke@435: Register obj_reg = Object; duke@435: Register mark_reg = G4_scratch; duke@435: Register temp_reg = G1_scratch; duke@435: Address lock_addr = Address(lock_reg, 0, BasicObjectLock::lock_offset_in_bytes()); duke@435: Address mark_addr = Address(obj_reg, 0, oopDesc::mark_offset_in_bytes()); duke@435: Label done; duke@435: duke@435: Label slow_case; duke@435: duke@435: assert_different_registers(lock_reg, obj_reg, mark_reg, temp_reg); duke@435: duke@435: // load markOop from object into mark_reg duke@435: ld_ptr(mark_addr, mark_reg); duke@435: duke@435: if (UseBiasedLocking) { duke@435: biased_locking_enter(obj_reg, mark_reg, temp_reg, done, &slow_case); duke@435: } duke@435: duke@435: // get the address of basicLock on stack that will be stored in the object duke@435: // we need a temporary register here as we do not want to clobber lock_reg duke@435: // (cas clobbers the destination register) duke@435: mov(lock_reg, temp_reg); duke@435: // set mark reg to be (markOop of object | UNLOCK_VALUE) duke@435: or3(mark_reg, markOopDesc::unlocked_value, mark_reg); duke@435: // initialize the box (Must happen before we update the object mark!) duke@435: st_ptr(mark_reg, lock_addr, BasicLock::displaced_header_offset_in_bytes()); duke@435: // compare and exchange object_addr, markOop | 1, stack address of basicLock duke@435: assert(mark_addr.disp() == 0, "cas must take a zero displacement"); duke@435: casx_under_lock(mark_addr.base(), mark_reg, temp_reg, duke@435: (address)StubRoutines::Sparc::atomic_memory_operation_lock_addr()); duke@435: duke@435: // if the compare and exchange succeeded we are done (we saw an unlocked object) duke@435: cmp(mark_reg, temp_reg); duke@435: brx(Assembler::equal, true, Assembler::pt, done); duke@435: delayed()->nop(); duke@435: duke@435: // We did not see an unlocked object so try the fast recursive case duke@435: duke@435: // Check if owner is self by comparing the value in the markOop of object duke@435: // with the stack pointer duke@435: sub(temp_reg, SP, temp_reg); duke@435: #ifdef _LP64 duke@435: sub(temp_reg, STACK_BIAS, temp_reg); duke@435: #endif duke@435: assert(os::vm_page_size() > 0xfff, "page size too small - change the constant"); duke@435: duke@435: // Composite "andcc" test: duke@435: // (a) %sp -vs- markword proximity check, and, duke@435: // (b) verify mark word LSBs == 0 (Stack-locked). duke@435: // duke@435: // FFFFF003/FFFFFFFFFFFF003 is (markOopDesc::lock_mask_in_place | -os::vm_page_size()) duke@435: // Note that the page size used for %sp proximity testing is arbitrary and is duke@435: // unrelated to the actual MMU page size. We use a 'logical' page size of duke@435: // 4096 bytes. F..FFF003 is designed to fit conveniently in the SIMM13 immediate duke@435: // field of the andcc instruction. duke@435: andcc (temp_reg, 0xFFFFF003, G0) ; duke@435: duke@435: // if condition is true we are done and hence we can store 0 in the displaced duke@435: // header indicating it is a recursive lock and be done duke@435: brx(Assembler::zero, true, Assembler::pt, done); duke@435: delayed()->st_ptr(G0, lock_addr, BasicLock::displaced_header_offset_in_bytes()); duke@435: duke@435: // none of the above fast optimizations worked so we have to get into the duke@435: // slow case of monitor enter duke@435: bind(slow_case); duke@435: call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter), lock_reg); duke@435: duke@435: bind(done); duke@435: } duke@435: } duke@435: duke@435: // Unlocks an object. Used in monitorexit bytecode and remove_activation. duke@435: // duke@435: // Argument - lock_reg points to the BasicObjectLock for lock duke@435: // Throw IllegalMonitorException if object is not locked by current thread duke@435: void InterpreterMacroAssembler::unlock_object(Register lock_reg) { duke@435: if (UseHeavyMonitors) { duke@435: call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), lock_reg); duke@435: } else { duke@435: Register obj_reg = G3_scratch; duke@435: Register mark_reg = G4_scratch; duke@435: Register displaced_header_reg = G1_scratch; duke@435: Address lock_addr = Address(lock_reg, 0, BasicObjectLock::lock_offset_in_bytes()); duke@435: Address lockobj_addr = Address(lock_reg, 0, BasicObjectLock::obj_offset_in_bytes()); duke@435: Address mark_addr = Address(obj_reg, 0, oopDesc::mark_offset_in_bytes()); duke@435: Label done; duke@435: duke@435: if (UseBiasedLocking) { duke@435: // load the object out of the BasicObjectLock duke@435: ld_ptr(lockobj_addr, obj_reg); duke@435: biased_locking_exit(mark_addr, mark_reg, done, true); duke@435: st_ptr(G0, lockobj_addr); // free entry duke@435: } duke@435: duke@435: // Test first if we are in the fast recursive case duke@435: ld_ptr(lock_addr, displaced_header_reg, BasicLock::displaced_header_offset_in_bytes()); duke@435: br_null(displaced_header_reg, true, Assembler::pn, done); duke@435: delayed()->st_ptr(G0, lockobj_addr); // free entry duke@435: duke@435: // See if it is still a light weight lock, if so we just unlock duke@435: // the object and we are done duke@435: duke@435: if (!UseBiasedLocking) { duke@435: // load the object out of the BasicObjectLock duke@435: ld_ptr(lockobj_addr, obj_reg); duke@435: } duke@435: duke@435: // we have the displaced header in displaced_header_reg duke@435: // we expect to see the stack address of the basicLock in case the duke@435: // lock is still a light weight lock (lock_reg) duke@435: assert(mark_addr.disp() == 0, "cas must take a zero displacement"); duke@435: casx_under_lock(mark_addr.base(), lock_reg, displaced_header_reg, duke@435: (address)StubRoutines::Sparc::atomic_memory_operation_lock_addr()); duke@435: cmp(lock_reg, displaced_header_reg); duke@435: brx(Assembler::equal, true, Assembler::pn, done); duke@435: delayed()->st_ptr(G0, lockobj_addr); // free entry duke@435: duke@435: // The lock has been converted into a heavy lock and hence duke@435: // we need to get into the slow case duke@435: duke@435: call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), lock_reg); duke@435: duke@435: bind(done); duke@435: } duke@435: } duke@435: duke@435: #ifndef CC_INTERP duke@435: duke@435: // Get the method data pointer from the methodOop and set the duke@435: // specified register to its value. duke@435: duke@435: void InterpreterMacroAssembler::set_method_data_pointer_offset(Register Roff) { duke@435: assert(ProfileInterpreter, "must be profiling interpreter"); duke@435: Label get_continue; duke@435: duke@435: ld_ptr(Lmethod, in_bytes(methodOopDesc::method_data_offset()), ImethodDataPtr); duke@435: test_method_data_pointer(get_continue); duke@435: add(ImethodDataPtr, in_bytes(methodDataOopDesc::data_offset()), ImethodDataPtr); duke@435: if (Roff != noreg) duke@435: // Roff contains a method data index ("mdi"). It defaults to zero. duke@435: add(ImethodDataPtr, Roff, ImethodDataPtr); duke@435: bind(get_continue); duke@435: } duke@435: duke@435: // Set the method data pointer for the current bcp. duke@435: duke@435: void InterpreterMacroAssembler::set_method_data_pointer_for_bcp() { duke@435: assert(ProfileInterpreter, "must be profiling interpreter"); duke@435: Label zero_continue; duke@435: duke@435: // Test MDO to avoid the call if it is NULL. duke@435: ld_ptr(Lmethod, in_bytes(methodOopDesc::method_data_offset()), ImethodDataPtr); duke@435: test_method_data_pointer(zero_continue); duke@435: call_VM_leaf(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::bcp_to_di), Lmethod, Lbcp); duke@435: set_method_data_pointer_offset(O0); duke@435: bind(zero_continue); duke@435: } duke@435: duke@435: // Test ImethodDataPtr. If it is null, continue at the specified label duke@435: duke@435: void InterpreterMacroAssembler::test_method_data_pointer(Label& zero_continue) { duke@435: assert(ProfileInterpreter, "must be profiling interpreter"); duke@435: #ifdef _LP64 duke@435: bpr(Assembler::rc_z, false, Assembler::pn, ImethodDataPtr, zero_continue); duke@435: #else duke@435: tst(ImethodDataPtr); duke@435: br(Assembler::zero, false, Assembler::pn, zero_continue); duke@435: #endif duke@435: delayed()->nop(); duke@435: } duke@435: duke@435: void InterpreterMacroAssembler::verify_method_data_pointer() { duke@435: assert(ProfileInterpreter, "must be profiling interpreter"); duke@435: #ifdef ASSERT duke@435: Label verify_continue; duke@435: test_method_data_pointer(verify_continue); duke@435: duke@435: // If the mdp is valid, it will point to a DataLayout header which is duke@435: // consistent with the bcp. The converse is highly probable also. duke@435: lduh(ImethodDataPtr, in_bytes(DataLayout::bci_offset()), G3_scratch); duke@435: ld_ptr(Address(Lmethod, 0, in_bytes(methodOopDesc::const_offset())), O5); duke@435: add(G3_scratch, in_bytes(constMethodOopDesc::codes_offset()), G3_scratch); duke@435: add(G3_scratch, O5, G3_scratch); duke@435: cmp(Lbcp, G3_scratch); duke@435: brx(Assembler::equal, false, Assembler::pt, verify_continue); duke@435: duke@435: Register temp_reg = O5; duke@435: delayed()->mov(ImethodDataPtr, temp_reg); duke@435: // %%% should use call_VM_leaf here? duke@435: //call_VM_leaf(noreg, ..., Lmethod, Lbcp, ImethodDataPtr); duke@435: save_frame_and_mov(sizeof(jdouble) / wordSize, Lmethod, O0, Lbcp, O1); duke@435: Address d_save(FP, 0, -sizeof(jdouble) + STACK_BIAS); duke@435: stf(FloatRegisterImpl::D, Ftos_d, d_save); duke@435: mov(temp_reg->after_save(), O2); duke@435: save_thread(L7_thread_cache); duke@435: call(CAST_FROM_FN_PTR(address, InterpreterRuntime::verify_mdp), relocInfo::none); duke@435: delayed()->nop(); duke@435: restore_thread(L7_thread_cache); duke@435: ldf(FloatRegisterImpl::D, d_save, Ftos_d); duke@435: restore(); duke@435: bind(verify_continue); duke@435: #endif // ASSERT duke@435: } duke@435: duke@435: void InterpreterMacroAssembler::test_invocation_counter_for_mdp(Register invocation_count, duke@435: Register cur_bcp, duke@435: Register Rtmp, duke@435: Label &profile_continue) { duke@435: assert(ProfileInterpreter, "must be profiling interpreter"); duke@435: // Control will flow to "profile_continue" if the counter is less than the duke@435: // limit or if we call profile_method() duke@435: duke@435: Label done; duke@435: duke@435: // if no method data exists, and the counter is high enough, make one duke@435: #ifdef _LP64 duke@435: bpr(Assembler::rc_nz, false, Assembler::pn, ImethodDataPtr, done); duke@435: #else duke@435: tst(ImethodDataPtr); duke@435: br(Assembler::notZero, false, Assembler::pn, done); duke@435: #endif duke@435: duke@435: // Test to see if we should create a method data oop duke@435: Address profile_limit(Rtmp, (address)&InvocationCounter::InterpreterProfileLimit); duke@435: #ifdef _LP64 duke@435: delayed()->nop(); duke@435: sethi(profile_limit); duke@435: #else duke@435: delayed()->sethi(profile_limit); duke@435: #endif duke@435: ld(profile_limit, Rtmp); duke@435: cmp(invocation_count, Rtmp); duke@435: br(Assembler::lessUnsigned, false, Assembler::pn, profile_continue); duke@435: delayed()->nop(); duke@435: duke@435: // Build it now. duke@435: call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::profile_method), cur_bcp); duke@435: set_method_data_pointer_offset(O0); duke@435: ba(false, profile_continue); duke@435: delayed()->nop(); duke@435: bind(done); duke@435: } duke@435: duke@435: // Store a value at some constant offset from the method data pointer. duke@435: duke@435: void InterpreterMacroAssembler::set_mdp_data_at(int constant, Register value) { duke@435: assert(ProfileInterpreter, "must be profiling interpreter"); duke@435: st_ptr(value, ImethodDataPtr, constant); duke@435: } duke@435: duke@435: void InterpreterMacroAssembler::increment_mdp_data_at(Address counter, duke@435: Register bumped_count, duke@435: bool decrement) { duke@435: assert(ProfileInterpreter, "must be profiling interpreter"); duke@435: duke@435: // Load the counter. duke@435: ld_ptr(counter, bumped_count); duke@435: duke@435: if (decrement) { duke@435: // Decrement the register. Set condition codes. duke@435: subcc(bumped_count, DataLayout::counter_increment, bumped_count); duke@435: duke@435: // If the decrement causes the counter to overflow, stay negative duke@435: Label L; duke@435: brx(Assembler::negative, true, Assembler::pn, L); duke@435: duke@435: // Store the decremented counter, if it is still negative. duke@435: delayed()->st_ptr(bumped_count, counter); duke@435: bind(L); duke@435: } else { duke@435: // Increment the register. Set carry flag. duke@435: addcc(bumped_count, DataLayout::counter_increment, bumped_count); duke@435: duke@435: // If the increment causes the counter to overflow, pull back by 1. duke@435: assert(DataLayout::counter_increment == 1, "subc works"); duke@435: subc(bumped_count, G0, bumped_count); duke@435: duke@435: // Store the incremented counter. duke@435: st_ptr(bumped_count, counter); duke@435: } duke@435: } duke@435: duke@435: // Increment the value at some constant offset from the method data pointer. duke@435: duke@435: void InterpreterMacroAssembler::increment_mdp_data_at(int constant, duke@435: Register bumped_count, duke@435: bool decrement) { duke@435: // Locate the counter at a fixed offset from the mdp: duke@435: Address counter(ImethodDataPtr, 0, constant); duke@435: increment_mdp_data_at(counter, bumped_count, decrement); duke@435: } duke@435: duke@435: // Increment the value at some non-fixed (reg + constant) offset from duke@435: // the method data pointer. duke@435: duke@435: void InterpreterMacroAssembler::increment_mdp_data_at(Register reg, duke@435: int constant, duke@435: Register bumped_count, duke@435: Register scratch2, duke@435: bool decrement) { duke@435: // Add the constant to reg to get the offset. duke@435: add(ImethodDataPtr, reg, scratch2); duke@435: Address counter(scratch2, 0, constant); duke@435: increment_mdp_data_at(counter, bumped_count, decrement); duke@435: } duke@435: duke@435: // Set a flag value at the current method data pointer position. duke@435: // Updates a single byte of the header, to avoid races with other header bits. duke@435: duke@435: void InterpreterMacroAssembler::set_mdp_flag_at(int flag_constant, duke@435: Register scratch) { duke@435: assert(ProfileInterpreter, "must be profiling interpreter"); duke@435: // Load the data header duke@435: ldub(ImethodDataPtr, in_bytes(DataLayout::flags_offset()), scratch); duke@435: duke@435: // Set the flag duke@435: or3(scratch, flag_constant, scratch); duke@435: duke@435: // Store the modified header. duke@435: stb(scratch, ImethodDataPtr, in_bytes(DataLayout::flags_offset())); duke@435: } duke@435: duke@435: // Test the location at some offset from the method data pointer. duke@435: // If it is not equal to value, branch to the not_equal_continue Label. duke@435: // Set condition codes to match the nullness of the loaded value. duke@435: duke@435: void InterpreterMacroAssembler::test_mdp_data_at(int offset, duke@435: Register value, duke@435: Label& not_equal_continue, duke@435: Register scratch) { duke@435: assert(ProfileInterpreter, "must be profiling interpreter"); duke@435: ld_ptr(ImethodDataPtr, offset, scratch); duke@435: cmp(value, scratch); duke@435: brx(Assembler::notEqual, false, Assembler::pn, not_equal_continue); duke@435: delayed()->tst(scratch); duke@435: } duke@435: duke@435: // Update the method data pointer by the displacement located at some fixed duke@435: // offset from the method data pointer. duke@435: duke@435: void InterpreterMacroAssembler::update_mdp_by_offset(int offset_of_disp, duke@435: Register scratch) { duke@435: assert(ProfileInterpreter, "must be profiling interpreter"); duke@435: ld_ptr(ImethodDataPtr, offset_of_disp, scratch); duke@435: add(ImethodDataPtr, scratch, ImethodDataPtr); duke@435: } duke@435: duke@435: // Update the method data pointer by the displacement located at the duke@435: // offset (reg + offset_of_disp). duke@435: duke@435: void InterpreterMacroAssembler::update_mdp_by_offset(Register reg, duke@435: int offset_of_disp, duke@435: Register scratch) { duke@435: assert(ProfileInterpreter, "must be profiling interpreter"); duke@435: add(reg, offset_of_disp, scratch); duke@435: ld_ptr(ImethodDataPtr, scratch, scratch); duke@435: add(ImethodDataPtr, scratch, ImethodDataPtr); duke@435: } duke@435: duke@435: // Update the method data pointer by a simple constant displacement. duke@435: duke@435: void InterpreterMacroAssembler::update_mdp_by_constant(int constant) { duke@435: assert(ProfileInterpreter, "must be profiling interpreter"); duke@435: add(ImethodDataPtr, constant, ImethodDataPtr); duke@435: } duke@435: duke@435: // Update the method data pointer for a _ret bytecode whose target duke@435: // was not among our cached targets. duke@435: duke@435: void InterpreterMacroAssembler::update_mdp_for_ret(TosState state, duke@435: Register return_bci) { duke@435: assert(ProfileInterpreter, "must be profiling interpreter"); duke@435: push(state); duke@435: st_ptr(return_bci, l_tmp); // protect return_bci, in case it is volatile duke@435: call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::update_mdp_for_ret), return_bci); duke@435: ld_ptr(l_tmp, return_bci); duke@435: pop(state); duke@435: } duke@435: duke@435: // Count a taken branch in the bytecodes. duke@435: duke@435: void InterpreterMacroAssembler::profile_taken_branch(Register scratch, Register bumped_count) { duke@435: if (ProfileInterpreter) { duke@435: Label profile_continue; duke@435: duke@435: // If no method data exists, go to profile_continue. duke@435: test_method_data_pointer(profile_continue); duke@435: duke@435: // We are taking a branch. Increment the taken count. duke@435: increment_mdp_data_at(in_bytes(JumpData::taken_offset()), bumped_count); duke@435: duke@435: // The method data pointer needs to be updated to reflect the new target. duke@435: update_mdp_by_offset(in_bytes(JumpData::displacement_offset()), scratch); duke@435: bind (profile_continue); duke@435: } duke@435: } duke@435: duke@435: duke@435: // Count a not-taken branch in the bytecodes. duke@435: duke@435: void InterpreterMacroAssembler::profile_not_taken_branch(Register scratch) { duke@435: if (ProfileInterpreter) { duke@435: Label profile_continue; duke@435: duke@435: // If no method data exists, go to profile_continue. duke@435: test_method_data_pointer(profile_continue); duke@435: duke@435: // We are taking a branch. Increment the not taken count. duke@435: increment_mdp_data_at(in_bytes(BranchData::not_taken_offset()), scratch); duke@435: duke@435: // The method data pointer needs to be updated to correspond to the duke@435: // next bytecode. duke@435: update_mdp_by_constant(in_bytes(BranchData::branch_data_size())); duke@435: bind (profile_continue); duke@435: } duke@435: } duke@435: duke@435: duke@435: // Count a non-virtual call in the bytecodes. duke@435: duke@435: void InterpreterMacroAssembler::profile_call(Register scratch) { duke@435: if (ProfileInterpreter) { duke@435: Label profile_continue; duke@435: duke@435: // If no method data exists, go to profile_continue. duke@435: test_method_data_pointer(profile_continue); duke@435: duke@435: // We are making a call. Increment the count. duke@435: increment_mdp_data_at(in_bytes(CounterData::count_offset()), scratch); duke@435: duke@435: // The method data pointer needs to be updated to reflect the new target. duke@435: update_mdp_by_constant(in_bytes(CounterData::counter_data_size())); duke@435: bind (profile_continue); duke@435: } duke@435: } duke@435: duke@435: duke@435: // Count a final call in the bytecodes. duke@435: duke@435: void InterpreterMacroAssembler::profile_final_call(Register scratch) { duke@435: if (ProfileInterpreter) { duke@435: Label profile_continue; duke@435: duke@435: // If no method data exists, go to profile_continue. duke@435: test_method_data_pointer(profile_continue); duke@435: duke@435: // We are making a call. Increment the count. duke@435: increment_mdp_data_at(in_bytes(CounterData::count_offset()), scratch); duke@435: duke@435: // The method data pointer needs to be updated to reflect the new target. duke@435: update_mdp_by_constant(in_bytes(VirtualCallData::virtual_call_data_size())); duke@435: bind (profile_continue); duke@435: } duke@435: } duke@435: duke@435: duke@435: // Count a virtual call in the bytecodes. duke@435: duke@435: void InterpreterMacroAssembler::profile_virtual_call(Register receiver, duke@435: Register scratch) { duke@435: if (ProfileInterpreter) { duke@435: Label profile_continue; duke@435: duke@435: // If no method data exists, go to profile_continue. duke@435: test_method_data_pointer(profile_continue); duke@435: duke@435: // We are making a call. Increment the count. duke@435: increment_mdp_data_at(in_bytes(CounterData::count_offset()), scratch); duke@435: duke@435: // Record the receiver type. duke@435: record_klass_in_profile(receiver, scratch); duke@435: duke@435: // The method data pointer needs to be updated to reflect the new target. duke@435: update_mdp_by_constant(in_bytes(VirtualCallData::virtual_call_data_size())); duke@435: bind (profile_continue); duke@435: } duke@435: } duke@435: duke@435: void InterpreterMacroAssembler::record_klass_in_profile_helper( duke@435: Register receiver, Register scratch, duke@435: int start_row, Label& done) { duke@435: int last_row = VirtualCallData::row_limit() - 1; duke@435: assert(start_row <= last_row, "must be work left to do"); duke@435: // Test this row for both the receiver and for null. duke@435: // Take any of three different outcomes: duke@435: // 1. found receiver => increment count and goto done duke@435: // 2. found null => keep looking for case 1, maybe allocate this cell duke@435: // 3. found something else => keep looking for cases 1 and 2 duke@435: // Case 3 is handled by a recursive call. duke@435: for (int row = start_row; row <= last_row; row++) { duke@435: Label next_test; duke@435: bool test_for_null_also = (row == start_row); duke@435: duke@435: // See if the receiver is receiver[n]. duke@435: int recvr_offset = in_bytes(VirtualCallData::receiver_offset(row)); duke@435: test_mdp_data_at(recvr_offset, receiver, next_test, scratch); duke@435: duke@435: // The receiver is receiver[n]. Increment count[n]. duke@435: int count_offset = in_bytes(VirtualCallData::receiver_count_offset(row)); duke@435: increment_mdp_data_at(count_offset, scratch); duke@435: ba(false, done); duke@435: delayed()->nop(); duke@435: bind(next_test); duke@435: duke@435: if (test_for_null_also) { duke@435: // Failed the equality check on receiver[n]... Test for null. duke@435: if (start_row == last_row) { duke@435: // The only thing left to do is handle the null case. duke@435: brx(Assembler::notZero, false, Assembler::pt, done); duke@435: delayed()->nop(); duke@435: break; duke@435: } duke@435: // Since null is rare, make it be the branch-taken case. duke@435: Label found_null; duke@435: brx(Assembler::zero, false, Assembler::pn, found_null); duke@435: delayed()->nop(); duke@435: duke@435: // Put all the "Case 3" tests here. duke@435: record_klass_in_profile_helper(receiver, scratch, start_row + 1, done); duke@435: duke@435: // Found a null. Keep searching for a matching receiver, duke@435: // but remember that this is an empty (unused) slot. duke@435: bind(found_null); duke@435: } duke@435: } duke@435: duke@435: // In the fall-through case, we found no matching receiver, but we duke@435: // observed the receiver[start_row] is NULL. duke@435: duke@435: // Fill in the receiver field and increment the count. duke@435: int recvr_offset = in_bytes(VirtualCallData::receiver_offset(start_row)); duke@435: set_mdp_data_at(recvr_offset, receiver); duke@435: int count_offset = in_bytes(VirtualCallData::receiver_count_offset(start_row)); duke@435: mov(DataLayout::counter_increment, scratch); duke@435: set_mdp_data_at(count_offset, scratch); duke@435: ba(false, done); duke@435: delayed()->nop(); duke@435: } duke@435: duke@435: void InterpreterMacroAssembler::record_klass_in_profile(Register receiver, duke@435: Register scratch) { duke@435: assert(ProfileInterpreter, "must be profiling"); duke@435: Label done; duke@435: duke@435: record_klass_in_profile_helper(receiver, scratch, 0, done); duke@435: duke@435: bind (done); duke@435: } duke@435: duke@435: duke@435: // Count a ret in the bytecodes. duke@435: duke@435: void InterpreterMacroAssembler::profile_ret(TosState state, duke@435: Register return_bci, duke@435: Register scratch) { duke@435: if (ProfileInterpreter) { duke@435: Label profile_continue; duke@435: uint row; duke@435: duke@435: // If no method data exists, go to profile_continue. duke@435: test_method_data_pointer(profile_continue); duke@435: duke@435: // Update the total ret count. duke@435: increment_mdp_data_at(in_bytes(CounterData::count_offset()), scratch); duke@435: duke@435: for (row = 0; row < RetData::row_limit(); row++) { duke@435: Label next_test; duke@435: duke@435: // See if return_bci is equal to bci[n]: duke@435: test_mdp_data_at(in_bytes(RetData::bci_offset(row)), duke@435: return_bci, next_test, scratch); duke@435: duke@435: // return_bci is equal to bci[n]. Increment the count. duke@435: increment_mdp_data_at(in_bytes(RetData::bci_count_offset(row)), scratch); duke@435: duke@435: // The method data pointer needs to be updated to reflect the new target. duke@435: update_mdp_by_offset(in_bytes(RetData::bci_displacement_offset(row)), scratch); duke@435: ba(false, profile_continue); duke@435: delayed()->nop(); duke@435: bind(next_test); duke@435: } duke@435: duke@435: update_mdp_for_ret(state, return_bci); duke@435: duke@435: bind (profile_continue); duke@435: } duke@435: } duke@435: duke@435: // Profile an unexpected null in the bytecodes. duke@435: void InterpreterMacroAssembler::profile_null_seen(Register scratch) { duke@435: if (ProfileInterpreter) { duke@435: Label profile_continue; duke@435: duke@435: // If no method data exists, go to profile_continue. duke@435: test_method_data_pointer(profile_continue); duke@435: duke@435: set_mdp_flag_at(BitData::null_seen_byte_constant(), scratch); duke@435: duke@435: // The method data pointer needs to be updated. duke@435: int mdp_delta = in_bytes(BitData::bit_data_size()); duke@435: if (TypeProfileCasts) { duke@435: mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size()); duke@435: } duke@435: update_mdp_by_constant(mdp_delta); duke@435: duke@435: bind (profile_continue); duke@435: } duke@435: } duke@435: duke@435: void InterpreterMacroAssembler::profile_typecheck(Register klass, duke@435: Register scratch) { duke@435: if (ProfileInterpreter) { duke@435: Label profile_continue; duke@435: duke@435: // If no method data exists, go to profile_continue. duke@435: test_method_data_pointer(profile_continue); duke@435: duke@435: int mdp_delta = in_bytes(BitData::bit_data_size()); duke@435: if (TypeProfileCasts) { duke@435: mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size()); duke@435: duke@435: // Record the object type. duke@435: record_klass_in_profile(klass, scratch); duke@435: } duke@435: duke@435: // The method data pointer needs to be updated. duke@435: update_mdp_by_constant(mdp_delta); duke@435: duke@435: bind (profile_continue); duke@435: } duke@435: } duke@435: duke@435: void InterpreterMacroAssembler::profile_typecheck_failed(Register scratch) { duke@435: if (ProfileInterpreter && TypeProfileCasts) { duke@435: Label profile_continue; duke@435: duke@435: // If no method data exists, go to profile_continue. duke@435: test_method_data_pointer(profile_continue); duke@435: duke@435: int count_offset = in_bytes(CounterData::count_offset()); duke@435: // Back up the address, since we have already bumped the mdp. duke@435: count_offset -= in_bytes(VirtualCallData::virtual_call_data_size()); duke@435: duke@435: // *Decrement* the counter. We expect to see zero or small negatives. duke@435: increment_mdp_data_at(count_offset, scratch, true); duke@435: duke@435: bind (profile_continue); duke@435: } duke@435: } duke@435: duke@435: // Count the default case of a switch construct. duke@435: duke@435: void InterpreterMacroAssembler::profile_switch_default(Register scratch) { duke@435: if (ProfileInterpreter) { duke@435: Label profile_continue; duke@435: duke@435: // If no method data exists, go to profile_continue. duke@435: test_method_data_pointer(profile_continue); duke@435: duke@435: // Update the default case count duke@435: increment_mdp_data_at(in_bytes(MultiBranchData::default_count_offset()), duke@435: scratch); duke@435: duke@435: // The method data pointer needs to be updated. duke@435: update_mdp_by_offset( duke@435: in_bytes(MultiBranchData::default_displacement_offset()), duke@435: scratch); duke@435: duke@435: bind (profile_continue); duke@435: } duke@435: } duke@435: duke@435: // Count the index'th case of a switch construct. duke@435: duke@435: void InterpreterMacroAssembler::profile_switch_case(Register index, duke@435: Register scratch, duke@435: Register scratch2, duke@435: Register scratch3) { duke@435: if (ProfileInterpreter) { duke@435: Label profile_continue; duke@435: duke@435: // If no method data exists, go to profile_continue. duke@435: test_method_data_pointer(profile_continue); duke@435: duke@435: // Build the base (index * per_case_size_in_bytes()) + case_array_offset_in_bytes() duke@435: set(in_bytes(MultiBranchData::per_case_size()), scratch); duke@435: smul(index, scratch, scratch); duke@435: add(scratch, in_bytes(MultiBranchData::case_array_offset()), scratch); duke@435: duke@435: // Update the case count duke@435: increment_mdp_data_at(scratch, duke@435: in_bytes(MultiBranchData::relative_count_offset()), duke@435: scratch2, duke@435: scratch3); duke@435: duke@435: // The method data pointer needs to be updated. duke@435: update_mdp_by_offset(scratch, duke@435: in_bytes(MultiBranchData::relative_displacement_offset()), duke@435: scratch2); duke@435: duke@435: bind (profile_continue); duke@435: } duke@435: } duke@435: duke@435: // add a InterpMonitorElem to stack (see frame_sparc.hpp) duke@435: duke@435: void InterpreterMacroAssembler::add_monitor_to_stack( bool stack_is_empty, duke@435: Register Rtemp, duke@435: Register Rtemp2 ) { duke@435: duke@435: Register Rlimit = Lmonitors; duke@435: const jint delta = frame::interpreter_frame_monitor_size() * wordSize; duke@435: assert( (delta & LongAlignmentMask) == 0, duke@435: "sizeof BasicObjectLock must be even number of doublewords"); duke@435: duke@435: sub( SP, delta, SP); duke@435: sub( Lesp, delta, Lesp); duke@435: sub( Lmonitors, delta, Lmonitors); duke@435: duke@435: if (!stack_is_empty) { duke@435: duke@435: // must copy stack contents down duke@435: duke@435: Label start_copying, next; duke@435: duke@435: // untested("monitor stack expansion"); duke@435: compute_stack_base(Rtemp); duke@435: ba( false, start_copying ); duke@435: delayed()->cmp( Rtemp, Rlimit); // done? duplicated below duke@435: duke@435: // note: must copy from low memory upwards duke@435: // On entry to loop, duke@435: // Rtemp points to new base of stack, Lesp points to new end of stack (1 past TOS) duke@435: // Loop mutates Rtemp duke@435: duke@435: bind( next); duke@435: duke@435: st_ptr(Rtemp2, Rtemp, 0); duke@435: inc(Rtemp, wordSize); duke@435: cmp(Rtemp, Rlimit); // are we done? (duplicated above) duke@435: duke@435: bind( start_copying ); duke@435: duke@435: brx( notEqual, true, pn, next ); duke@435: delayed()->ld_ptr( Rtemp, delta, Rtemp2 ); duke@435: duke@435: // done copying stack duke@435: } duke@435: } duke@435: duke@435: // Locals duke@435: #ifdef ASSERT duke@435: void InterpreterMacroAssembler::verify_local_tag(frame::Tag t, duke@435: Register base, duke@435: Register scratch, duke@435: int n) { duke@435: if (TaggedStackInterpreter) { duke@435: Label ok, long_ok; duke@435: // Use dst for scratch duke@435: assert_different_registers(base, scratch); duke@435: ld_ptr(base, Interpreter::local_tag_offset_in_bytes(n), scratch); duke@435: if (t == frame::TagCategory2) { duke@435: cmp(scratch, G0); duke@435: brx(Assembler::equal, false, Assembler::pt, long_ok); duke@435: delayed()->ld_ptr(base, Interpreter::local_tag_offset_in_bytes(n+1), scratch); duke@435: stop("local long/double tag value bad"); duke@435: bind(long_ok); duke@435: // compare second half tag duke@435: cmp(scratch, G0); duke@435: } else if (t == frame::TagValue) { duke@435: cmp(scratch, G0); duke@435: } else { duke@435: assert_different_registers(O3, base, scratch); duke@435: mov(t, O3); duke@435: cmp(scratch, O3); duke@435: } duke@435: brx(Assembler::equal, false, Assembler::pt, ok); duke@435: delayed()->nop(); duke@435: // Also compare if the local value is zero, then the tag might duke@435: // not have been set coming from deopt. duke@435: ld_ptr(base, Interpreter::local_offset_in_bytes(n), scratch); duke@435: cmp(scratch, G0); duke@435: brx(Assembler::equal, false, Assembler::pt, ok); duke@435: delayed()->nop(); duke@435: stop("Local tag value is bad"); duke@435: bind(ok); duke@435: } duke@435: } duke@435: #endif // ASSERT duke@435: duke@435: void InterpreterMacroAssembler::access_local_ptr( Register index, Register dst ) { duke@435: assert_not_delayed(); duke@435: sll(index, Interpreter::logStackElementSize(), index); duke@435: sub(Llocals, index, index); duke@435: debug_only(verify_local_tag(frame::TagReference, index, dst)); duke@435: ld_ptr(index, Interpreter::value_offset_in_bytes(), dst); duke@435: // Note: index must hold the effective address--the iinc template uses it duke@435: } duke@435: duke@435: // Just like access_local_ptr but the tag is a returnAddress duke@435: void InterpreterMacroAssembler::access_local_returnAddress(Register index, duke@435: Register dst ) { duke@435: assert_not_delayed(); duke@435: sll(index, Interpreter::logStackElementSize(), index); duke@435: sub(Llocals, index, index); duke@435: debug_only(verify_local_tag(frame::TagValue, index, dst)); duke@435: ld_ptr(index, Interpreter::value_offset_in_bytes(), dst); duke@435: } duke@435: duke@435: void InterpreterMacroAssembler::access_local_int( Register index, Register dst ) { duke@435: assert_not_delayed(); duke@435: sll(index, Interpreter::logStackElementSize(), index); duke@435: sub(Llocals, index, index); duke@435: debug_only(verify_local_tag(frame::TagValue, index, dst)); duke@435: ld(index, Interpreter::value_offset_in_bytes(), dst); duke@435: // Note: index must hold the effective address--the iinc template uses it duke@435: } duke@435: duke@435: duke@435: void InterpreterMacroAssembler::access_local_long( Register index, Register dst ) { duke@435: assert_not_delayed(); duke@435: sll(index, Interpreter::logStackElementSize(), index); duke@435: sub(Llocals, index, index); duke@435: debug_only(verify_local_tag(frame::TagCategory2, index, dst)); duke@435: // First half stored at index n+1 (which grows down from Llocals[n]) duke@435: load_unaligned_long(index, Interpreter::local_offset_in_bytes(1), dst); duke@435: } duke@435: duke@435: duke@435: void InterpreterMacroAssembler::access_local_float( Register index, FloatRegister dst ) { duke@435: assert_not_delayed(); duke@435: sll(index, Interpreter::logStackElementSize(), index); duke@435: sub(Llocals, index, index); duke@435: debug_only(verify_local_tag(frame::TagValue, index, G1_scratch)); duke@435: ldf(FloatRegisterImpl::S, index, Interpreter::value_offset_in_bytes(), dst); duke@435: } duke@435: duke@435: duke@435: void InterpreterMacroAssembler::access_local_double( Register index, FloatRegister dst ) { duke@435: assert_not_delayed(); duke@435: sll(index, Interpreter::logStackElementSize(), index); duke@435: sub(Llocals, index, index); duke@435: debug_only(verify_local_tag(frame::TagCategory2, index, G1_scratch)); duke@435: load_unaligned_double(index, Interpreter::local_offset_in_bytes(1), dst); duke@435: } duke@435: duke@435: duke@435: #ifdef ASSERT duke@435: void InterpreterMacroAssembler::check_for_regarea_stomp(Register Rindex, int offset, Register Rlimit, Register Rscratch, Register Rscratch1) { duke@435: Label L; duke@435: duke@435: assert(Rindex != Rscratch, "Registers cannot be same"); duke@435: assert(Rindex != Rscratch1, "Registers cannot be same"); duke@435: assert(Rlimit != Rscratch, "Registers cannot be same"); duke@435: assert(Rlimit != Rscratch1, "Registers cannot be same"); duke@435: assert(Rscratch1 != Rscratch, "Registers cannot be same"); duke@435: duke@435: // untested("reg area corruption"); duke@435: add(Rindex, offset, Rscratch); duke@435: add(Rlimit, 64 + STACK_BIAS, Rscratch1); duke@435: cmp(Rscratch, Rscratch1); duke@435: brx(Assembler::greaterEqualUnsigned, false, pn, L); duke@435: delayed()->nop(); duke@435: stop("regsave area is being clobbered"); duke@435: bind(L); duke@435: } duke@435: #endif // ASSERT duke@435: duke@435: void InterpreterMacroAssembler::tag_local(frame::Tag t, duke@435: Register base, duke@435: Register src, duke@435: int n) { duke@435: if (TaggedStackInterpreter) { duke@435: // have to store zero because local slots can be reused (rats!) duke@435: if (t == frame::TagValue) { duke@435: st_ptr(G0, base, Interpreter::local_tag_offset_in_bytes(n)); duke@435: } else if (t == frame::TagCategory2) { duke@435: st_ptr(G0, base, Interpreter::local_tag_offset_in_bytes(n)); duke@435: st_ptr(G0, base, Interpreter::local_tag_offset_in_bytes(n+1)); duke@435: } else { duke@435: // assert that we don't stomp the value in 'src' duke@435: // O3 is arbitrary because it's not used. duke@435: assert_different_registers(src, base, O3); duke@435: mov( t, O3); duke@435: st_ptr(O3, base, Interpreter::local_tag_offset_in_bytes(n)); duke@435: } duke@435: } duke@435: } duke@435: duke@435: duke@435: void InterpreterMacroAssembler::store_local_int( Register index, Register src ) { duke@435: assert_not_delayed(); duke@435: sll(index, Interpreter::logStackElementSize(), index); duke@435: sub(Llocals, index, index); duke@435: debug_only(check_for_regarea_stomp(index, Interpreter::value_offset_in_bytes(), FP, G1_scratch, G4_scratch);) duke@435: tag_local(frame::TagValue, index, src); duke@435: st(src, index, Interpreter::value_offset_in_bytes()); duke@435: } duke@435: duke@435: void InterpreterMacroAssembler::store_local_ptr( Register index, Register src, duke@435: Register tag ) { duke@435: assert_not_delayed(); duke@435: sll(index, Interpreter::logStackElementSize(), index); duke@435: sub(Llocals, index, index); duke@435: #ifdef ASSERT duke@435: check_for_regarea_stomp(index, Interpreter::value_offset_in_bytes(), FP, G1_scratch, G4_scratch); duke@435: #endif duke@435: st_ptr(src, index, Interpreter::value_offset_in_bytes()); duke@435: // Store tag register directly duke@435: if (TaggedStackInterpreter) { duke@435: st_ptr(tag, index, Interpreter::tag_offset_in_bytes()); duke@435: } duke@435: } duke@435: duke@435: duke@435: duke@435: void InterpreterMacroAssembler::store_local_ptr( int n, Register src, duke@435: Register tag ) { duke@435: st_ptr(src, Llocals, Interpreter::local_offset_in_bytes(n)); duke@435: if (TaggedStackInterpreter) { duke@435: st_ptr(tag, Llocals, Interpreter::local_tag_offset_in_bytes(n)); duke@435: } duke@435: } duke@435: duke@435: void InterpreterMacroAssembler::store_local_long( Register index, Register src ) { duke@435: assert_not_delayed(); duke@435: sll(index, Interpreter::logStackElementSize(), index); duke@435: sub(Llocals, index, index); duke@435: #ifdef ASSERT duke@435: check_for_regarea_stomp(index, Interpreter::local_offset_in_bytes(1), FP, G1_scratch, G4_scratch); duke@435: #endif duke@435: tag_local(frame::TagCategory2, index, src); duke@435: store_unaligned_long(src, index, Interpreter::local_offset_in_bytes(1)); // which is n+1 duke@435: } duke@435: duke@435: duke@435: void InterpreterMacroAssembler::store_local_float( Register index, FloatRegister src ) { duke@435: assert_not_delayed(); duke@435: sll(index, Interpreter::logStackElementSize(), index); duke@435: sub(Llocals, index, index); duke@435: #ifdef ASSERT duke@435: check_for_regarea_stomp(index, Interpreter::value_offset_in_bytes(), FP, G1_scratch, G4_scratch); duke@435: #endif duke@435: tag_local(frame::TagValue, index, G1_scratch); duke@435: stf(FloatRegisterImpl::S, src, index, Interpreter::value_offset_in_bytes()); duke@435: } duke@435: duke@435: duke@435: void InterpreterMacroAssembler::store_local_double( Register index, FloatRegister src ) { duke@435: assert_not_delayed(); duke@435: sll(index, Interpreter::logStackElementSize(), index); duke@435: sub(Llocals, index, index); duke@435: #ifdef ASSERT duke@435: check_for_regarea_stomp(index, Interpreter::local_offset_in_bytes(1), FP, G1_scratch, G4_scratch); duke@435: #endif duke@435: tag_local(frame::TagCategory2, index, G1_scratch); duke@435: store_unaligned_double(src, index, Interpreter::local_offset_in_bytes(1)); duke@435: } duke@435: duke@435: duke@435: int InterpreterMacroAssembler::top_most_monitor_byte_offset() { duke@435: const jint delta = frame::interpreter_frame_monitor_size() * wordSize; duke@435: int rounded_vm_local_words = ::round_to(frame::interpreter_frame_vm_local_words, WordsPerLong); duke@435: return ((-rounded_vm_local_words * wordSize) - delta ) + STACK_BIAS; duke@435: } duke@435: duke@435: duke@435: Address InterpreterMacroAssembler::top_most_monitor() { duke@435: return Address(FP, 0, top_most_monitor_byte_offset()); duke@435: } duke@435: duke@435: duke@435: void InterpreterMacroAssembler::compute_stack_base( Register Rdest ) { duke@435: add( Lesp, wordSize, Rdest ); duke@435: } duke@435: duke@435: #endif /* CC_INTERP */ duke@435: duke@435: void InterpreterMacroAssembler::increment_invocation_counter( Register Rtmp, Register Rtmp2 ) { duke@435: assert(UseCompiler, "incrementing must be useful"); duke@435: #ifdef CC_INTERP duke@435: Address inv_counter(G5_method, 0, in_bytes(methodOopDesc::invocation_counter_offset() duke@435: + InvocationCounter::counter_offset())); duke@435: Address be_counter(G5_method, 0, in_bytes(methodOopDesc::backedge_counter_offset() duke@435: + InvocationCounter::counter_offset())); duke@435: #else duke@435: Address inv_counter(Lmethod, 0, in_bytes(methodOopDesc::invocation_counter_offset() duke@435: + InvocationCounter::counter_offset())); duke@435: Address be_counter(Lmethod, 0, in_bytes(methodOopDesc::backedge_counter_offset() duke@435: + InvocationCounter::counter_offset())); duke@435: #endif /* CC_INTERP */ duke@435: int delta = InvocationCounter::count_increment; duke@435: duke@435: // Load each counter in a register duke@435: ld( inv_counter, Rtmp ); duke@435: ld( be_counter, Rtmp2 ); duke@435: duke@435: assert( is_simm13( delta ), " delta too large."); duke@435: duke@435: // Add the delta to the invocation counter and store the result duke@435: add( Rtmp, delta, Rtmp ); duke@435: duke@435: // Mask the backedge counter duke@435: and3( Rtmp2, InvocationCounter::count_mask_value, Rtmp2 ); duke@435: duke@435: // Store value duke@435: st( Rtmp, inv_counter); duke@435: duke@435: // Add invocation counter + backedge counter duke@435: add( Rtmp, Rtmp2, Rtmp); duke@435: duke@435: // Note that this macro must leave the backedge_count + invocation_count in Rtmp! duke@435: } duke@435: duke@435: void InterpreterMacroAssembler::increment_backedge_counter( Register Rtmp, Register Rtmp2 ) { duke@435: assert(UseCompiler, "incrementing must be useful"); duke@435: #ifdef CC_INTERP duke@435: Address be_counter(G5_method, 0, in_bytes(methodOopDesc::backedge_counter_offset() duke@435: + InvocationCounter::counter_offset())); duke@435: Address inv_counter(G5_method, 0, in_bytes(methodOopDesc::invocation_counter_offset() duke@435: + InvocationCounter::counter_offset())); duke@435: #else duke@435: Address be_counter(Lmethod, 0, in_bytes(methodOopDesc::backedge_counter_offset() duke@435: + InvocationCounter::counter_offset())); duke@435: Address inv_counter(Lmethod, 0, in_bytes(methodOopDesc::invocation_counter_offset() duke@435: + InvocationCounter::counter_offset())); duke@435: #endif /* CC_INTERP */ duke@435: int delta = InvocationCounter::count_increment; duke@435: // Load each counter in a register duke@435: ld( be_counter, Rtmp ); duke@435: ld( inv_counter, Rtmp2 ); duke@435: duke@435: // Add the delta to the backedge counter duke@435: add( Rtmp, delta, Rtmp ); duke@435: duke@435: // Mask the invocation counter, add to backedge counter duke@435: and3( Rtmp2, InvocationCounter::count_mask_value, Rtmp2 ); duke@435: duke@435: // and store the result to memory duke@435: st( Rtmp, be_counter ); duke@435: duke@435: // Add backedge + invocation counter duke@435: add( Rtmp, Rtmp2, Rtmp ); duke@435: duke@435: // Note that this macro must leave backedge_count + invocation_count in Rtmp! duke@435: } duke@435: duke@435: #ifndef CC_INTERP duke@435: void InterpreterMacroAssembler::test_backedge_count_for_osr( Register backedge_count, duke@435: Register branch_bcp, duke@435: Register Rtmp ) { duke@435: Label did_not_overflow; duke@435: Label overflow_with_error; duke@435: assert_different_registers(backedge_count, Rtmp, branch_bcp); duke@435: assert(UseOnStackReplacement,"Must UseOnStackReplacement to test_backedge_count_for_osr"); duke@435: duke@435: Address limit(Rtmp, address(&InvocationCounter::InterpreterBackwardBranchLimit)); duke@435: load_contents(limit, Rtmp); duke@435: cmp(backedge_count, Rtmp); duke@435: br(Assembler::lessUnsigned, false, Assembler::pt, did_not_overflow); duke@435: delayed()->nop(); duke@435: duke@435: // When ProfileInterpreter is on, the backedge_count comes from the duke@435: // methodDataOop, which value does not get reset on the call to duke@435: // frequency_counter_overflow(). To avoid excessive calls to the overflow duke@435: // routine while the method is being compiled, add a second test to make sure duke@435: // the overflow function is called only once every overflow_frequency. duke@435: if (ProfileInterpreter) { duke@435: const int overflow_frequency = 1024; duke@435: andcc(backedge_count, overflow_frequency-1, Rtmp); duke@435: brx(Assembler::notZero, false, Assembler::pt, did_not_overflow); duke@435: delayed()->nop(); duke@435: } duke@435: duke@435: // overflow in loop, pass branch bytecode duke@435: set(6,Rtmp); duke@435: call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::frequency_counter_overflow), branch_bcp, Rtmp); duke@435: duke@435: // Was an OSR adapter generated? duke@435: // O0 = osr nmethod duke@435: tst(O0); duke@435: brx(Assembler::zero, false, Assembler::pn, overflow_with_error); duke@435: delayed()->nop(); duke@435: duke@435: // Has the nmethod been invalidated already? duke@435: ld(O0, nmethod::entry_bci_offset(), O2); duke@435: cmp(O2, InvalidOSREntryBci); duke@435: br(Assembler::equal, false, Assembler::pn, overflow_with_error); duke@435: delayed()->nop(); duke@435: duke@435: // migrate the interpreter frame off of the stack duke@435: duke@435: mov(G2_thread, L7); duke@435: // save nmethod duke@435: mov(O0, L6); duke@435: set_last_Java_frame(SP, noreg); duke@435: call_VM_leaf(noreg, CAST_FROM_FN_PTR(address, SharedRuntime::OSR_migration_begin), L7); duke@435: reset_last_Java_frame(); duke@435: mov(L7, G2_thread); duke@435: duke@435: // move OSR nmethod to I1 duke@435: mov(L6, I1); duke@435: duke@435: // OSR buffer to I0 duke@435: mov(O0, I0); duke@435: duke@435: // remove the interpreter frame duke@435: restore(I5_savedSP, 0, SP); duke@435: duke@435: // Jump to the osr code. duke@435: ld_ptr(O1, nmethod::osr_entry_point_offset(), O2); duke@435: jmp(O2, G0); duke@435: delayed()->nop(); duke@435: duke@435: bind(overflow_with_error); duke@435: duke@435: bind(did_not_overflow); duke@435: } duke@435: duke@435: duke@435: duke@435: void InterpreterMacroAssembler::interp_verify_oop(Register reg, TosState state, const char * file, int line) { duke@435: if (state == atos) { MacroAssembler::_verify_oop(reg, "broken oop ", file, line); } duke@435: } duke@435: duke@435: duke@435: // local helper function for the verify_oop_or_return_address macro duke@435: static bool verify_return_address(methodOopDesc* m, int bci) { duke@435: #ifndef PRODUCT duke@435: address pc = (address)(m->constMethod()) duke@435: + in_bytes(constMethodOopDesc::codes_offset()) + bci; duke@435: // assume it is a valid return address if it is inside m and is preceded by a jsr duke@435: if (!m->contains(pc)) return false; duke@435: address jsr_pc; duke@435: jsr_pc = pc - Bytecodes::length_for(Bytecodes::_jsr); duke@435: if (*jsr_pc == Bytecodes::_jsr && jsr_pc >= m->code_base()) return true; duke@435: jsr_pc = pc - Bytecodes::length_for(Bytecodes::_jsr_w); duke@435: if (*jsr_pc == Bytecodes::_jsr_w && jsr_pc >= m->code_base()) return true; duke@435: #endif // PRODUCT duke@435: return false; duke@435: } duke@435: duke@435: duke@435: void InterpreterMacroAssembler::verify_oop_or_return_address(Register reg, Register Rtmp) { duke@435: if (!VerifyOops) return; duke@435: // the VM documentation for the astore[_wide] bytecode allows duke@435: // the TOS to be not only an oop but also a return address duke@435: Label test; duke@435: Label skip; duke@435: // See if it is an address (in the current method): duke@435: duke@435: mov(reg, Rtmp); duke@435: const int log2_bytecode_size_limit = 16; duke@435: srl(Rtmp, log2_bytecode_size_limit, Rtmp); duke@435: br_notnull( Rtmp, false, pt, test ); duke@435: delayed()->nop(); duke@435: duke@435: // %%% should use call_VM_leaf here? duke@435: save_frame_and_mov(0, Lmethod, O0, reg, O1); duke@435: save_thread(L7_thread_cache); duke@435: call(CAST_FROM_FN_PTR(address,verify_return_address), relocInfo::none); duke@435: delayed()->nop(); duke@435: restore_thread(L7_thread_cache); duke@435: br_notnull( O0, false, pt, skip ); duke@435: delayed()->restore(); duke@435: duke@435: // Perform a more elaborate out-of-line call duke@435: // Not an address; verify it: duke@435: bind(test); duke@435: verify_oop(reg); duke@435: bind(skip); duke@435: } duke@435: duke@435: duke@435: void InterpreterMacroAssembler::verify_FPU(int stack_depth, TosState state) { duke@435: if (state == ftos || state == dtos) MacroAssembler::verify_FPU(stack_depth); duke@435: } duke@435: #endif /* CC_INTERP */ duke@435: duke@435: // Inline assembly for: duke@435: // duke@435: // if (thread is in interp_only_mode) { duke@435: // InterpreterRuntime::post_method_entry(); duke@435: // } duke@435: // if (DTraceMethodProbes) { dcubed@1045: // SharedRuntime::dtrace_method_entry(method, receiver); dcubed@1045: // } dcubed@1045: // if (RC_TRACE_IN_RANGE(0x00001000, 0x00002000)) { dcubed@1045: // SharedRuntime::rc_trace_method_entry(method, receiver); duke@435: // } duke@435: duke@435: void InterpreterMacroAssembler::notify_method_entry() { duke@435: duke@435: // C++ interpreter only uses this for native methods. duke@435: duke@435: // Whenever JVMTI puts a thread in interp_only_mode, method duke@435: // entry/exit events are sent for that thread to track stack duke@435: // depth. If it is possible to enter interp_only_mode we add duke@435: // the code to check if the event should be sent. duke@435: if (JvmtiExport::can_post_interpreter_events()) { duke@435: Label L; duke@435: Register temp_reg = O5; duke@435: duke@435: const Address interp_only (G2_thread, 0, in_bytes(JavaThread::interp_only_mode_offset())); duke@435: duke@435: ld(interp_only, temp_reg); duke@435: tst(temp_reg); duke@435: br(zero, false, pt, L); duke@435: delayed()->nop(); duke@435: call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_method_entry)); duke@435: bind(L); duke@435: } duke@435: duke@435: { duke@435: Register temp_reg = O5; duke@435: SkipIfEqual skip_if(this, temp_reg, &DTraceMethodProbes, zero); duke@435: call_VM_leaf(noreg, duke@435: CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_entry), duke@435: G2_thread, Lmethod); duke@435: } dcubed@1045: dcubed@1045: // RedefineClasses() tracing support for obsolete method entry dcubed@1045: if (RC_TRACE_IN_RANGE(0x00001000, 0x00002000)) { dcubed@1045: call_VM_leaf(noreg, dcubed@1045: CAST_FROM_FN_PTR(address, SharedRuntime::rc_trace_method_entry), dcubed@1045: G2_thread, Lmethod); dcubed@1045: } duke@435: } duke@435: duke@435: duke@435: // Inline assembly for: duke@435: // duke@435: // if (thread is in interp_only_mode) { duke@435: // // save result duke@435: // InterpreterRuntime::post_method_exit(); duke@435: // // restore result duke@435: // } duke@435: // if (DTraceMethodProbes) { duke@435: // SharedRuntime::dtrace_method_exit(thread, method); duke@435: // } duke@435: // duke@435: // Native methods have their result stored in d_tmp and l_tmp duke@435: // Java methods have their result stored in the expression stack duke@435: duke@435: void InterpreterMacroAssembler::notify_method_exit(bool is_native_method, duke@435: TosState state, duke@435: NotifyMethodExitMode mode) { duke@435: // C++ interpreter only uses this for native methods. duke@435: duke@435: // Whenever JVMTI puts a thread in interp_only_mode, method duke@435: // entry/exit events are sent for that thread to track stack duke@435: // depth. If it is possible to enter interp_only_mode we add duke@435: // the code to check if the event should be sent. duke@435: if (mode == NotifyJVMTI && JvmtiExport::can_post_interpreter_events()) { duke@435: Label L; duke@435: Register temp_reg = O5; duke@435: duke@435: const Address interp_only (G2_thread, 0, in_bytes(JavaThread::interp_only_mode_offset())); duke@435: duke@435: ld(interp_only, temp_reg); duke@435: tst(temp_reg); duke@435: br(zero, false, pt, L); duke@435: delayed()->nop(); duke@435: duke@435: // Note: frame::interpreter_frame_result has a dependency on how the duke@435: // method result is saved across the call to post_method_exit. For duke@435: // native methods it assumes the result registers are saved to duke@435: // l_scratch and d_scratch. If this changes then the interpreter_frame_result duke@435: // implementation will need to be updated too. duke@435: duke@435: save_return_value(state, is_native_method); duke@435: call_VM(noreg, duke@435: CAST_FROM_FN_PTR(address, InterpreterRuntime::post_method_exit)); duke@435: restore_return_value(state, is_native_method); duke@435: bind(L); duke@435: } duke@435: duke@435: { duke@435: Register temp_reg = O5; duke@435: // Dtrace notification duke@435: SkipIfEqual skip_if(this, temp_reg, &DTraceMethodProbes, zero); duke@435: save_return_value(state, is_native_method); duke@435: call_VM_leaf( duke@435: noreg, duke@435: CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_exit), duke@435: G2_thread, Lmethod); duke@435: restore_return_value(state, is_native_method); duke@435: } duke@435: } duke@435: duke@435: void InterpreterMacroAssembler::save_return_value(TosState state, bool is_native_call) { duke@435: #ifdef CC_INTERP duke@435: // result potentially in O0/O1: save it across calls duke@435: stf(FloatRegisterImpl::D, F0, STATE(_native_fresult)); duke@435: #ifdef _LP64 duke@435: stx(O0, STATE(_native_lresult)); duke@435: #else duke@435: std(O0, STATE(_native_lresult)); duke@435: #endif duke@435: #else // CC_INTERP duke@435: if (is_native_call) { duke@435: stf(FloatRegisterImpl::D, F0, d_tmp); duke@435: #ifdef _LP64 duke@435: stx(O0, l_tmp); duke@435: #else duke@435: std(O0, l_tmp); duke@435: #endif duke@435: } else { duke@435: push(state); duke@435: } duke@435: #endif // CC_INTERP duke@435: } duke@435: duke@435: void InterpreterMacroAssembler::restore_return_value( TosState state, bool is_native_call) { duke@435: #ifdef CC_INTERP duke@435: ldf(FloatRegisterImpl::D, STATE(_native_fresult), F0); duke@435: #ifdef _LP64 duke@435: ldx(STATE(_native_lresult), O0); duke@435: #else duke@435: ldd(STATE(_native_lresult), O0); duke@435: #endif duke@435: #else // CC_INTERP duke@435: if (is_native_call) { duke@435: ldf(FloatRegisterImpl::D, d_tmp, F0); duke@435: #ifdef _LP64 duke@435: ldx(l_tmp, O0); duke@435: #else duke@435: ldd(l_tmp, O0); duke@435: #endif duke@435: } else { duke@435: pop(state); duke@435: } duke@435: #endif // CC_INTERP duke@435: }