duke@435: /* phh@9604: * Copyright (c) 1997, 2018, Oracle and/or its affiliates. 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: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: stefank@2314: #include "precompiled.hpp" twisti@4318: #include "asm/macroAssembler.hpp" stefank@2314: #include "interpreter/interpreter.hpp" stefank@2314: #include "interpreter/interpreterRuntime.hpp" stefank@2314: #include "interpreter/templateTable.hpp" stefank@2314: #include "memory/universe.inline.hpp" coleenp@4037: #include "oops/methodData.hpp" stefank@2314: #include "oops/objArrayKlass.hpp" stefank@2314: #include "oops/oop.inline.hpp" stefank@2314: #include "prims/methodHandles.hpp" stefank@2314: #include "runtime/sharedRuntime.hpp" stefank@2314: #include "runtime/stubRoutines.hpp" stefank@2314: #include "runtime/synchronizer.hpp" jprovino@4542: #include "utilities/macros.hpp" duke@435: duke@435: #ifndef CC_INTERP duke@435: #define __ _masm-> duke@435: duke@435: //---------------------------------------------------------------------------------------------------- duke@435: // Platform-dependent initialization duke@435: duke@435: void TemplateTable::pd_initialize() { duke@435: // No i486 specific initialization duke@435: } duke@435: duke@435: //---------------------------------------------------------------------------------------------------- duke@435: // Address computation duke@435: duke@435: // local variables duke@435: static inline Address iaddress(int n) { duke@435: return Address(rdi, Interpreter::local_offset_in_bytes(n)); duke@435: } duke@435: duke@435: static inline Address laddress(int n) { return iaddress(n + 1); } duke@435: static inline Address haddress(int n) { return iaddress(n + 0); } duke@435: static inline Address faddress(int n) { return iaddress(n); } duke@435: static inline Address daddress(int n) { return laddress(n); } duke@435: static inline Address aaddress(int n) { return iaddress(n); } duke@435: duke@435: static inline Address iaddress(Register r) { twisti@1861: return Address(rdi, r, Interpreter::stackElementScale()); duke@435: } duke@435: static inline Address laddress(Register r) { duke@435: return Address(rdi, r, Interpreter::stackElementScale(), Interpreter::local_offset_in_bytes(1)); duke@435: } duke@435: static inline Address haddress(Register r) { duke@435: return Address(rdi, r, Interpreter::stackElementScale(), Interpreter::local_offset_in_bytes(0)); duke@435: } duke@435: twisti@1861: static inline Address faddress(Register r) { return iaddress(r); } twisti@1861: static inline Address daddress(Register r) { return laddress(r); } twisti@1861: static inline Address aaddress(Register r) { return iaddress(r); } duke@435: duke@435: // expression stack duke@435: // (Note: Must not use symmetric equivalents at_rsp_m1/2 since they store duke@435: // data beyond the rsp which is potentially unsafe in an MT environment; duke@435: // an interrupt may overwrite that data.) duke@435: static inline Address at_rsp () { duke@435: return Address(rsp, 0); duke@435: } duke@435: duke@435: // At top of Java expression stack which may be different than rsp(). It duke@435: // isn't for category 1 objects. duke@435: static inline Address at_tos () { duke@435: Address tos = Address(rsp, Interpreter::expr_offset_in_bytes(0)); duke@435: return tos; duke@435: } duke@435: duke@435: static inline Address at_tos_p1() { duke@435: return Address(rsp, Interpreter::expr_offset_in_bytes(1)); duke@435: } duke@435: duke@435: static inline Address at_tos_p2() { duke@435: return Address(rsp, Interpreter::expr_offset_in_bytes(2)); duke@435: } duke@435: duke@435: // Condition conversion duke@435: static Assembler::Condition j_not(TemplateTable::Condition cc) { duke@435: switch (cc) { duke@435: case TemplateTable::equal : return Assembler::notEqual; duke@435: case TemplateTable::not_equal : return Assembler::equal; duke@435: case TemplateTable::less : return Assembler::greaterEqual; duke@435: case TemplateTable::less_equal : return Assembler::greater; duke@435: case TemplateTable::greater : return Assembler::lessEqual; duke@435: case TemplateTable::greater_equal: return Assembler::less; duke@435: } duke@435: ShouldNotReachHere(); duke@435: return Assembler::zero; duke@435: } duke@435: duke@435: duke@435: //---------------------------------------------------------------------------------------------------- duke@435: // Miscelaneous helper routines duke@435: ysr@777: // Store an oop (or NULL) at the address described by obj. ysr@777: // If val == noreg this means store a NULL ysr@777: ysr@777: static void do_oop_store(InterpreterMacroAssembler* _masm, ysr@777: Address obj, ysr@777: Register val, ysr@777: BarrierSet::Name barrier, ysr@777: bool precise) { ysr@777: assert(val == noreg || val == rax, "parameter is just for looks"); ysr@777: switch (barrier) { jprovino@4542: #if INCLUDE_ALL_GCS ysr@777: case BarrierSet::G1SATBCT: ysr@777: case BarrierSet::G1SATBCTLogging: ysr@777: { ysr@777: // flatten object address if needed ysr@777: // We do it regardless of precise because we need the registers ysr@777: if (obj.index() == noreg && obj.disp() == 0) { ysr@777: if (obj.base() != rdx) { ysr@777: __ movl(rdx, obj.base()); ysr@777: } ysr@777: } else { ysr@777: __ leal(rdx, obj); ysr@777: } ysr@777: __ get_thread(rcx); ysr@777: __ save_bcp(); johnc@2781: __ g1_write_barrier_pre(rdx /* obj */, johnc@2781: rbx /* pre_val */, johnc@2781: rcx /* thread */, johnc@2781: rsi /* tmp */, johnc@2781: val != noreg /* tosca_live */, johnc@2781: false /* expand_call */); ysr@777: ysr@777: // Do the actual store ysr@777: // noreg means NULL ysr@777: if (val == noreg) { xlu@968: __ movptr(Address(rdx, 0), NULL_WORD); ysr@777: // No post barrier for NULL ysr@777: } else { ysr@777: __ movl(Address(rdx, 0), val); johnc@2781: __ g1_write_barrier_post(rdx /* store_adr */, johnc@2781: val /* new_val */, johnc@2781: rcx /* thread */, johnc@2781: rbx /* tmp */, johnc@2781: rsi /* tmp2 */); ysr@777: } ysr@777: __ restore_bcp(); ysr@777: ysr@777: } ysr@777: break; jprovino@4542: #endif // INCLUDE_ALL_GCS ysr@777: case BarrierSet::CardTableModRef: ysr@777: case BarrierSet::CardTableExtension: ysr@777: { ysr@777: if (val == noreg) { xlu@968: __ movptr(obj, NULL_WORD); ysr@777: } else { ysr@777: __ movl(obj, val); ysr@777: // flatten object address if needed ysr@777: if (!precise || (obj.index() == noreg && obj.disp() == 0)) { ysr@777: __ store_check(obj.base()); ysr@777: } else { ysr@777: __ leal(rdx, obj); ysr@777: __ store_check(rdx); ysr@777: } ysr@777: } ysr@777: } ysr@777: break; ysr@777: case BarrierSet::ModRef: ysr@777: case BarrierSet::Other: ysr@777: if (val == noreg) { xlu@968: __ movptr(obj, NULL_WORD); ysr@777: } else { ysr@777: __ movl(obj, val); ysr@777: } ysr@777: break; ysr@777: default : ysr@777: ShouldNotReachHere(); ysr@777: ysr@777: } ysr@777: } ysr@777: duke@435: Address TemplateTable::at_bcp(int offset) { duke@435: assert(_desc->uses_bcp(), "inconsistent uses_bcp information"); duke@435: return Address(rsi, offset); duke@435: } duke@435: duke@435: twisti@3050: void TemplateTable::patch_bytecode(Bytecodes::Code bc, Register bc_reg, twisti@3050: Register temp_reg, bool load_bc_into_bc_reg/*=true*/, twisti@3050: int byte_no) { twisti@3050: if (!RewriteBytecodes) return; twisti@3050: Label L_patch_done; twisti@3050: twisti@3050: switch (bc) { twisti@3050: case Bytecodes::_fast_aputfield: twisti@3050: case Bytecodes::_fast_bputfield: kevinw@8368: case Bytecodes::_fast_zputfield: twisti@3050: case Bytecodes::_fast_cputfield: twisti@3050: case Bytecodes::_fast_dputfield: twisti@3050: case Bytecodes::_fast_fputfield: twisti@3050: case Bytecodes::_fast_iputfield: twisti@3050: case Bytecodes::_fast_lputfield: twisti@3050: case Bytecodes::_fast_sputfield: twisti@3050: { twisti@3050: // We skip bytecode quickening for putfield instructions when twisti@3050: // the put_code written to the constant pool cache is zero. twisti@3050: // This is required so that every execution of this instruction twisti@3050: // calls out to InterpreterRuntime::resolve_get_put to do twisti@3050: // additional, required work. twisti@3050: assert(byte_no == f1_byte || byte_no == f2_byte, "byte_no out of range"); twisti@3050: assert(load_bc_into_bc_reg, "we use bc_reg as temp"); twisti@3050: __ get_cache_and_index_and_bytecode_at_bcp(bc_reg, temp_reg, temp_reg, byte_no, 1); twisti@3050: __ movl(bc_reg, bc); twisti@3050: __ cmpl(temp_reg, (int) 0); twisti@3050: __ jcc(Assembler::zero, L_patch_done); // don't patch twisti@3050: } twisti@3050: break; twisti@3050: default: twisti@3050: assert(byte_no == -1, "sanity"); twisti@3050: // the pair bytecodes have already done the load. twisti@3050: if (load_bc_into_bc_reg) { twisti@3050: __ movl(bc_reg, bc); twisti@3050: } never@739: } twisti@3050: duke@435: if (JvmtiExport::can_post_breakpoint()) { twisti@3050: Label L_fast_patch; duke@435: // if a breakpoint is present we can't rewrite the stream directly twisti@3050: __ movzbl(temp_reg, at_bcp(0)); twisti@3050: __ cmpl(temp_reg, Bytecodes::_breakpoint); twisti@3050: __ jcc(Assembler::notEqual, L_fast_patch); twisti@3050: __ get_method(temp_reg); duke@435: // Let breakpoint table handling rewrite to quicker bytecode twisti@3050: __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::set_original_bytecode_at), temp_reg, rsi, bc_reg); duke@435: #ifndef ASSERT twisti@3050: __ jmpb(L_patch_done); jrose@1161: #else twisti@3050: __ jmp(L_patch_done); jrose@1161: #endif twisti@3050: __ bind(L_fast_patch); duke@435: } twisti@3050: jrose@1161: #ifdef ASSERT twisti@3050: Label L_okay; twisti@3050: __ load_unsigned_byte(temp_reg, at_bcp(0)); twisti@3050: __ cmpl(temp_reg, (int)Bytecodes::java_code(bc)); twisti@3050: __ jccb(Assembler::equal, L_okay); twisti@3050: __ cmpl(temp_reg, bc_reg); twisti@3050: __ jcc(Assembler::equal, L_okay); duke@435: __ stop("patching the wrong bytecode"); twisti@3050: __ bind(L_okay); duke@435: #endif twisti@3050: duke@435: // patch bytecode twisti@3050: __ movb(at_bcp(0), bc_reg); twisti@3050: __ bind(L_patch_done); duke@435: } duke@435: duke@435: //---------------------------------------------------------------------------------------------------- duke@435: // Individual instructions duke@435: duke@435: void TemplateTable::nop() { duke@435: transition(vtos, vtos); duke@435: // nothing to do duke@435: } duke@435: duke@435: void TemplateTable::shouldnotreachhere() { duke@435: transition(vtos, vtos); duke@435: __ stop("shouldnotreachhere bytecode"); duke@435: } duke@435: duke@435: duke@435: duke@435: void TemplateTable::aconst_null() { duke@435: transition(vtos, atos); never@739: __ xorptr(rax, rax); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::iconst(int value) { duke@435: transition(vtos, itos); duke@435: if (value == 0) { never@739: __ xorptr(rax, rax); duke@435: } else { never@739: __ movptr(rax, value); duke@435: } duke@435: } duke@435: duke@435: duke@435: void TemplateTable::lconst(int value) { duke@435: transition(vtos, ltos); duke@435: if (value == 0) { never@739: __ xorptr(rax, rax); duke@435: } else { never@739: __ movptr(rax, value); duke@435: } duke@435: assert(value >= 0, "check this code"); never@739: __ xorptr(rdx, rdx); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::fconst(int value) { duke@435: transition(vtos, ftos); duke@435: if (value == 0) { __ fldz(); duke@435: } else if (value == 1) { __ fld1(); duke@435: } else if (value == 2) { __ fld1(); __ fld1(); __ faddp(); // should do a better solution here duke@435: } else { ShouldNotReachHere(); duke@435: } duke@435: } duke@435: duke@435: duke@435: void TemplateTable::dconst(int value) { duke@435: transition(vtos, dtos); duke@435: if (value == 0) { __ fldz(); duke@435: } else if (value == 1) { __ fld1(); duke@435: } else { ShouldNotReachHere(); duke@435: } duke@435: } duke@435: duke@435: duke@435: void TemplateTable::bipush() { duke@435: transition(vtos, itos); duke@435: __ load_signed_byte(rax, at_bcp(1)); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::sipush() { duke@435: transition(vtos, itos); jrose@1057: __ load_unsigned_short(rax, at_bcp(1)); never@739: __ bswapl(rax); duke@435: __ sarl(rax, 16); duke@435: } duke@435: duke@435: void TemplateTable::ldc(bool wide) { duke@435: transition(vtos, vtos); duke@435: Label call_ldc, notFloat, notClass, Done; duke@435: duke@435: if (wide) { duke@435: __ get_unsigned_2_byte_index_at_bcp(rbx, 1); duke@435: } else { duke@435: __ load_unsigned_byte(rbx, at_bcp(1)); duke@435: } duke@435: __ get_cpool_and_tags(rcx, rax); coleenp@4037: const int base_offset = ConstantPool::header_size() * wordSize; coleenp@4037: const int tags_offset = Array::base_offset_in_bytes(); duke@435: duke@435: // get type never@739: __ xorptr(rdx, rdx); duke@435: __ movb(rdx, Address(rax, rbx, Address::times_1, tags_offset)); duke@435: duke@435: // unresolved class - get the resolved class duke@435: __ cmpl(rdx, JVM_CONSTANT_UnresolvedClass); duke@435: __ jccb(Assembler::equal, call_ldc); duke@435: duke@435: // unresolved class in error (resolution failed) - call into runtime duke@435: // so that the same error from first resolution attempt is thrown. duke@435: __ cmpl(rdx, JVM_CONSTANT_UnresolvedClassInError); duke@435: __ jccb(Assembler::equal, call_ldc); duke@435: duke@435: // resolved class - need to call vm to get java mirror of the class duke@435: __ cmpl(rdx, JVM_CONSTANT_Class); duke@435: __ jcc(Assembler::notEqual, notClass); duke@435: duke@435: __ bind(call_ldc); duke@435: __ movl(rcx, wide); duke@435: call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::ldc), rcx); duke@435: __ push(atos); duke@435: __ jmp(Done); duke@435: duke@435: __ bind(notClass); duke@435: __ cmpl(rdx, JVM_CONSTANT_Float); duke@435: __ jccb(Assembler::notEqual, notFloat); duke@435: // ftos never@739: __ fld_s( Address(rcx, rbx, Address::times_ptr, base_offset)); duke@435: __ push(ftos); duke@435: __ jmp(Done); duke@435: duke@435: __ bind(notFloat); duke@435: #ifdef ASSERT duke@435: { Label L; duke@435: __ cmpl(rdx, JVM_CONSTANT_Integer); duke@435: __ jcc(Assembler::equal, L); coleenp@4037: // String and Object are rewritten to fast_aldc duke@435: __ stop("unexpected tag type in ldc"); duke@435: __ bind(L); duke@435: } duke@435: #endif coleenp@4037: // itos JVM_CONSTANT_Integer only never@739: __ movl(rax, Address(rcx, rbx, Address::times_ptr, base_offset)); duke@435: __ push(itos); duke@435: __ bind(Done); duke@435: } duke@435: jrose@1957: // Fast path for caching oop constants. jrose@1957: void TemplateTable::fast_aldc(bool wide) { jrose@1957: transition(vtos, atos); jrose@1957: coleenp@4037: Register result = rax; coleenp@4037: Register tmp = rdx; coleenp@4037: int index_size = wide ? sizeof(u2) : sizeof(u1); coleenp@4037: coleenp@4037: Label resolved; coleenp@4037: coleenp@4037: // We are resolved if the resolved reference cache entry contains a coleenp@4037: // non-null object (String, MethodType, etc.) coleenp@4037: assert_different_registers(result, tmp); coleenp@4037: __ get_cache_index_at_bcp(tmp, 1, index_size); coleenp@4037: __ load_resolved_reference_at_index(result, tmp); coleenp@4037: __ testl(result, result); coleenp@4037: __ jcc(Assembler::notZero, resolved); coleenp@4037: coleenp@4037: address entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_ldc); coleenp@4037: coleenp@4037: // first time invocation - must resolve first coleenp@4037: __ movl(tmp, (int)bytecode()); coleenp@4037: __ call_VM(result, entry, tmp); coleenp@4037: coleenp@4037: __ bind(resolved); coleenp@4037: coleenp@4037: if (VerifyOops) { coleenp@4037: __ verify_oop(result); jrose@1957: } jrose@1957: } jrose@1957: duke@435: void TemplateTable::ldc2_w() { duke@435: transition(vtos, vtos); duke@435: Label Long, Done; duke@435: __ get_unsigned_2_byte_index_at_bcp(rbx, 1); duke@435: duke@435: __ get_cpool_and_tags(rcx, rax); coleenp@4037: const int base_offset = ConstantPool::header_size() * wordSize; coleenp@4037: const int tags_offset = Array::base_offset_in_bytes(); duke@435: duke@435: // get type duke@435: __ cmpb(Address(rax, rbx, Address::times_1, tags_offset), JVM_CONSTANT_Double); duke@435: __ jccb(Assembler::notEqual, Long); duke@435: // dtos never@739: __ fld_d( Address(rcx, rbx, Address::times_ptr, base_offset)); duke@435: __ push(dtos); duke@435: __ jmpb(Done); duke@435: duke@435: __ bind(Long); duke@435: // ltos never@739: __ movptr(rax, Address(rcx, rbx, Address::times_ptr, base_offset + 0 * wordSize)); never@739: NOT_LP64(__ movptr(rdx, Address(rcx, rbx, Address::times_ptr, base_offset + 1 * wordSize))); duke@435: duke@435: __ push(ltos); duke@435: duke@435: __ bind(Done); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::locals_index(Register reg, int offset) { duke@435: __ load_unsigned_byte(reg, at_bcp(offset)); never@739: __ negptr(reg); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::iload() { duke@435: transition(vtos, itos); duke@435: if (RewriteFrequentPairs) { duke@435: Label rewrite, done; duke@435: duke@435: // get next byte duke@435: __ load_unsigned_byte(rbx, at_bcp(Bytecodes::length_for(Bytecodes::_iload))); duke@435: // if _iload, wait to rewrite to iload2. We only want to rewrite the duke@435: // last two iloads in a pair. Comparing against fast_iload means that duke@435: // the next bytecode is neither an iload or a caload, and therefore duke@435: // an iload pair. duke@435: __ cmpl(rbx, Bytecodes::_iload); duke@435: __ jcc(Assembler::equal, done); duke@435: duke@435: __ cmpl(rbx, Bytecodes::_fast_iload); duke@435: __ movl(rcx, Bytecodes::_fast_iload2); duke@435: __ jccb(Assembler::equal, rewrite); duke@435: duke@435: // if _caload, rewrite to fast_icaload duke@435: __ cmpl(rbx, Bytecodes::_caload); duke@435: __ movl(rcx, Bytecodes::_fast_icaload); duke@435: __ jccb(Assembler::equal, rewrite); duke@435: duke@435: // rewrite so iload doesn't check again. duke@435: __ movl(rcx, Bytecodes::_fast_iload); duke@435: duke@435: // rewrite duke@435: // rcx: fast bytecode duke@435: __ bind(rewrite); duke@435: patch_bytecode(Bytecodes::_iload, rcx, rbx, false); duke@435: __ bind(done); duke@435: } duke@435: duke@435: // Get the local value into tos duke@435: locals_index(rbx); duke@435: __ movl(rax, iaddress(rbx)); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::fast_iload2() { duke@435: transition(vtos, itos); duke@435: locals_index(rbx); duke@435: __ movl(rax, iaddress(rbx)); duke@435: __ push(itos); duke@435: locals_index(rbx, 3); duke@435: __ movl(rax, iaddress(rbx)); duke@435: } duke@435: duke@435: void TemplateTable::fast_iload() { duke@435: transition(vtos, itos); duke@435: locals_index(rbx); duke@435: __ movl(rax, iaddress(rbx)); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::lload() { duke@435: transition(vtos, ltos); duke@435: locals_index(rbx); never@739: __ movptr(rax, laddress(rbx)); never@739: NOT_LP64(__ movl(rdx, haddress(rbx))); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::fload() { duke@435: transition(vtos, ftos); duke@435: locals_index(rbx); duke@435: __ fld_s(faddress(rbx)); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::dload() { duke@435: transition(vtos, dtos); duke@435: locals_index(rbx); twisti@1861: __ fld_d(daddress(rbx)); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::aload() { duke@435: transition(vtos, atos); duke@435: locals_index(rbx); never@739: __ movptr(rax, aaddress(rbx)); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::locals_index_wide(Register reg) { mgerdin@6059: __ load_unsigned_short(reg, at_bcp(2)); never@739: __ bswapl(reg); duke@435: __ shrl(reg, 16); never@739: __ negptr(reg); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::wide_iload() { duke@435: transition(vtos, itos); duke@435: locals_index_wide(rbx); duke@435: __ movl(rax, iaddress(rbx)); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::wide_lload() { duke@435: transition(vtos, ltos); duke@435: locals_index_wide(rbx); never@739: __ movptr(rax, laddress(rbx)); never@739: NOT_LP64(__ movl(rdx, haddress(rbx))); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::wide_fload() { duke@435: transition(vtos, ftos); duke@435: locals_index_wide(rbx); duke@435: __ fld_s(faddress(rbx)); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::wide_dload() { duke@435: transition(vtos, dtos); duke@435: locals_index_wide(rbx); twisti@1861: __ fld_d(daddress(rbx)); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::wide_aload() { duke@435: transition(vtos, atos); duke@435: locals_index_wide(rbx); never@739: __ movptr(rax, aaddress(rbx)); duke@435: } duke@435: duke@435: void TemplateTable::index_check(Register array, Register index) { duke@435: // Pop ptr into array duke@435: __ pop_ptr(array); duke@435: index_check_without_pop(array, index); duke@435: } duke@435: duke@435: void TemplateTable::index_check_without_pop(Register array, Register index) { duke@435: // destroys rbx, duke@435: // check array duke@435: __ null_check(array, arrayOopDesc::length_offset_in_bytes()); never@739: LP64_ONLY(__ movslq(index, index)); duke@435: // check index duke@435: __ cmpl(index, Address(array, arrayOopDesc::length_offset_in_bytes())); duke@435: if (index != rbx) { duke@435: // ??? convention: move aberrant index into rbx, for exception message duke@435: assert(rbx != array, "different registers"); never@739: __ mov(rbx, index); duke@435: } duke@435: __ jump_cc(Assembler::aboveEqual, duke@435: ExternalAddress(Interpreter::_throw_ArrayIndexOutOfBoundsException_entry)); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::iaload() { duke@435: transition(itos, itos); duke@435: // rdx: array duke@435: index_check(rdx, rax); // kills rbx, duke@435: // rax,: index duke@435: __ movl(rax, Address(rdx, rax, Address::times_4, arrayOopDesc::base_offset_in_bytes(T_INT))); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::laload() { duke@435: transition(itos, ltos); duke@435: // rax,: index duke@435: // rdx: array duke@435: index_check(rdx, rax); never@739: __ mov(rbx, rax); duke@435: // rbx,: index never@739: __ movptr(rax, Address(rdx, rbx, Address::times_8, arrayOopDesc::base_offset_in_bytes(T_LONG) + 0 * wordSize)); never@739: NOT_LP64(__ movl(rdx, Address(rdx, rbx, Address::times_8, arrayOopDesc::base_offset_in_bytes(T_LONG) + 1 * wordSize))); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::faload() { duke@435: transition(itos, ftos); duke@435: // rdx: array duke@435: index_check(rdx, rax); // kills rbx, duke@435: // rax,: index duke@435: __ fld_s(Address(rdx, rax, Address::times_4, arrayOopDesc::base_offset_in_bytes(T_FLOAT))); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::daload() { duke@435: transition(itos, dtos); duke@435: // rdx: array duke@435: index_check(rdx, rax); // kills rbx, duke@435: // rax,: index duke@435: __ fld_d(Address(rdx, rax, Address::times_8, arrayOopDesc::base_offset_in_bytes(T_DOUBLE))); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::aaload() { duke@435: transition(itos, atos); duke@435: // rdx: array duke@435: index_check(rdx, rax); // kills rbx, duke@435: // rax,: index never@739: __ movptr(rax, Address(rdx, rax, Address::times_ptr, arrayOopDesc::base_offset_in_bytes(T_OBJECT))); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::baload() { duke@435: transition(itos, itos); duke@435: // rdx: array duke@435: index_check(rdx, rax); // kills rbx, duke@435: // rax,: index duke@435: // can do better code for P5 - fix this at some point duke@435: __ load_signed_byte(rbx, Address(rdx, rax, Address::times_1, arrayOopDesc::base_offset_in_bytes(T_BYTE))); never@739: __ mov(rax, rbx); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::caload() { duke@435: transition(itos, itos); duke@435: // rdx: array duke@435: index_check(rdx, rax); // kills rbx, duke@435: // rax,: index duke@435: // can do better code for P5 - may want to improve this at some point jrose@1057: __ load_unsigned_short(rbx, Address(rdx, rax, Address::times_2, arrayOopDesc::base_offset_in_bytes(T_CHAR))); never@739: __ mov(rax, rbx); duke@435: } duke@435: duke@435: // iload followed by caload frequent pair duke@435: void TemplateTable::fast_icaload() { duke@435: transition(vtos, itos); duke@435: // load index out of locals duke@435: locals_index(rbx); duke@435: __ movl(rax, iaddress(rbx)); duke@435: duke@435: // rdx: array duke@435: index_check(rdx, rax); duke@435: // rax,: index jrose@1057: __ load_unsigned_short(rbx, Address(rdx, rax, Address::times_2, arrayOopDesc::base_offset_in_bytes(T_CHAR))); never@739: __ mov(rax, rbx); duke@435: } duke@435: duke@435: void TemplateTable::saload() { duke@435: transition(itos, itos); duke@435: // rdx: array duke@435: index_check(rdx, rax); // kills rbx, duke@435: // rax,: index duke@435: // can do better code for P5 - may want to improve this at some point jrose@1057: __ load_signed_short(rbx, Address(rdx, rax, Address::times_2, arrayOopDesc::base_offset_in_bytes(T_SHORT))); never@739: __ mov(rax, rbx); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::iload(int n) { duke@435: transition(vtos, itos); duke@435: __ movl(rax, iaddress(n)); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::lload(int n) { duke@435: transition(vtos, ltos); never@739: __ movptr(rax, laddress(n)); never@739: NOT_LP64(__ movptr(rdx, haddress(n))); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::fload(int n) { duke@435: transition(vtos, ftos); duke@435: __ fld_s(faddress(n)); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::dload(int n) { duke@435: transition(vtos, dtos); twisti@1861: __ fld_d(daddress(n)); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::aload(int n) { duke@435: transition(vtos, atos); never@739: __ movptr(rax, aaddress(n)); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::aload_0() { duke@435: transition(vtos, atos); duke@435: // According to bytecode histograms, the pairs: duke@435: // duke@435: // _aload_0, _fast_igetfield duke@435: // _aload_0, _fast_agetfield duke@435: // _aload_0, _fast_fgetfield duke@435: // duke@435: // occur frequently. If RewriteFrequentPairs is set, the (slow) _aload_0 duke@435: // bytecode checks if the next bytecode is either _fast_igetfield, duke@435: // _fast_agetfield or _fast_fgetfield and then rewrites the duke@435: // current bytecode into a pair bytecode; otherwise it rewrites the current duke@435: // bytecode into _fast_aload_0 that doesn't do the pair check anymore. duke@435: // duke@435: // Note: If the next bytecode is _getfield, the rewrite must be delayed, duke@435: // otherwise we may miss an opportunity for a pair. duke@435: // duke@435: // Also rewrite frequent pairs duke@435: // aload_0, aload_1 duke@435: // aload_0, iload_1 duke@435: // These bytecodes with a small amount of code are most profitable to rewrite duke@435: if (RewriteFrequentPairs) { duke@435: Label rewrite, done; duke@435: // get next byte duke@435: __ load_unsigned_byte(rbx, at_bcp(Bytecodes::length_for(Bytecodes::_aload_0))); duke@435: duke@435: // do actual aload_0 duke@435: aload(0); duke@435: duke@435: // if _getfield then wait with rewrite duke@435: __ cmpl(rbx, Bytecodes::_getfield); duke@435: __ jcc(Assembler::equal, done); duke@435: duke@435: // if _igetfield then reqrite to _fast_iaccess_0 duke@435: assert(Bytecodes::java_code(Bytecodes::_fast_iaccess_0) == Bytecodes::_aload_0, "fix bytecode definition"); duke@435: __ cmpl(rbx, Bytecodes::_fast_igetfield); duke@435: __ movl(rcx, Bytecodes::_fast_iaccess_0); duke@435: __ jccb(Assembler::equal, rewrite); duke@435: duke@435: // if _agetfield then reqrite to _fast_aaccess_0 duke@435: assert(Bytecodes::java_code(Bytecodes::_fast_aaccess_0) == Bytecodes::_aload_0, "fix bytecode definition"); duke@435: __ cmpl(rbx, Bytecodes::_fast_agetfield); duke@435: __ movl(rcx, Bytecodes::_fast_aaccess_0); duke@435: __ jccb(Assembler::equal, rewrite); duke@435: duke@435: // if _fgetfield then reqrite to _fast_faccess_0 duke@435: assert(Bytecodes::java_code(Bytecodes::_fast_faccess_0) == Bytecodes::_aload_0, "fix bytecode definition"); duke@435: __ cmpl(rbx, Bytecodes::_fast_fgetfield); duke@435: __ movl(rcx, Bytecodes::_fast_faccess_0); duke@435: __ jccb(Assembler::equal, rewrite); duke@435: duke@435: // else rewrite to _fast_aload0 duke@435: assert(Bytecodes::java_code(Bytecodes::_fast_aload_0) == Bytecodes::_aload_0, "fix bytecode definition"); duke@435: __ movl(rcx, Bytecodes::_fast_aload_0); duke@435: duke@435: // rewrite duke@435: // rcx: fast bytecode duke@435: __ bind(rewrite); duke@435: patch_bytecode(Bytecodes::_aload_0, rcx, rbx, false); duke@435: duke@435: __ bind(done); duke@435: } else { duke@435: aload(0); duke@435: } duke@435: } duke@435: duke@435: void TemplateTable::istore() { duke@435: transition(itos, vtos); duke@435: locals_index(rbx); duke@435: __ movl(iaddress(rbx), rax); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::lstore() { duke@435: transition(ltos, vtos); duke@435: locals_index(rbx); never@739: __ movptr(laddress(rbx), rax); never@739: NOT_LP64(__ movptr(haddress(rbx), rdx)); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::fstore() { duke@435: transition(ftos, vtos); duke@435: locals_index(rbx); duke@435: __ fstp_s(faddress(rbx)); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::dstore() { duke@435: transition(dtos, vtos); duke@435: locals_index(rbx); twisti@1861: __ fstp_d(daddress(rbx)); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::astore() { duke@435: transition(vtos, vtos); twisti@1861: __ pop_ptr(rax); duke@435: locals_index(rbx); never@739: __ movptr(aaddress(rbx), rax); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::wide_istore() { duke@435: transition(vtos, vtos); duke@435: __ pop_i(rax); duke@435: locals_index_wide(rbx); duke@435: __ movl(iaddress(rbx), rax); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::wide_lstore() { duke@435: transition(vtos, vtos); duke@435: __ pop_l(rax, rdx); duke@435: locals_index_wide(rbx); never@739: __ movptr(laddress(rbx), rax); never@739: NOT_LP64(__ movl(haddress(rbx), rdx)); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::wide_fstore() { duke@435: wide_istore(); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::wide_dstore() { duke@435: wide_lstore(); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::wide_astore() { duke@435: transition(vtos, vtos); twisti@1861: __ pop_ptr(rax); duke@435: locals_index_wide(rbx); never@739: __ movptr(aaddress(rbx), rax); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::iastore() { duke@435: transition(itos, vtos); duke@435: __ pop_i(rbx); duke@435: // rax,: value duke@435: // rdx: array duke@435: index_check(rdx, rbx); // prefer index in rbx, duke@435: // rbx,: index duke@435: __ movl(Address(rdx, rbx, Address::times_4, arrayOopDesc::base_offset_in_bytes(T_INT)), rax); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::lastore() { duke@435: transition(ltos, vtos); duke@435: __ pop_i(rbx); duke@435: // rax,: low(value) duke@435: // rcx: array duke@435: // rdx: high(value) duke@435: index_check(rcx, rbx); // prefer index in rbx, duke@435: // rbx,: index never@739: __ movptr(Address(rcx, rbx, Address::times_8, arrayOopDesc::base_offset_in_bytes(T_LONG) + 0 * wordSize), rax); never@739: NOT_LP64(__ movl(Address(rcx, rbx, Address::times_8, arrayOopDesc::base_offset_in_bytes(T_LONG) + 1 * wordSize), rdx)); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::fastore() { duke@435: transition(ftos, vtos); duke@435: __ pop_i(rbx); duke@435: // rdx: array duke@435: // st0: value duke@435: index_check(rdx, rbx); // prefer index in rbx, duke@435: // rbx,: index duke@435: __ fstp_s(Address(rdx, rbx, Address::times_4, arrayOopDesc::base_offset_in_bytes(T_FLOAT))); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::dastore() { duke@435: transition(dtos, vtos); duke@435: __ pop_i(rbx); duke@435: // rdx: array duke@435: // st0: value duke@435: index_check(rdx, rbx); // prefer index in rbx, duke@435: // rbx,: index duke@435: __ fstp_d(Address(rdx, rbx, Address::times_8, arrayOopDesc::base_offset_in_bytes(T_DOUBLE))); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::aastore() { duke@435: Label is_null, ok_is_subtype, done; duke@435: transition(vtos, vtos); duke@435: // stack: ..., array, index, value never@739: __ movptr(rax, at_tos()); // Value duke@435: __ movl(rcx, at_tos_p1()); // Index never@739: __ movptr(rdx, at_tos_p2()); // Array ysr@777: ysr@777: Address element_address(rdx, rcx, Address::times_4, arrayOopDesc::base_offset_in_bytes(T_OBJECT)); duke@435: index_check_without_pop(rdx, rcx); // kills rbx, duke@435: // do array store check - check for NULL value first never@739: __ testptr(rax, rax); duke@435: __ jcc(Assembler::zero, is_null); duke@435: duke@435: // Move subklass into EBX twisti@2807: __ load_klass(rbx, rax); duke@435: // Move superklass into EAX twisti@2807: __ load_klass(rax, rdx); coleenp@4142: __ movptr(rax, Address(rax, ObjArrayKlass::element_klass_offset())); never@739: // Compress array+index*wordSize+12 into a single register. Frees ECX. apetrusenko@797: __ lea(rdx, element_address); duke@435: duke@435: // Generate subtype check. Blows ECX. Resets EDI to locals. duke@435: // Superklass in EAX. Subklass in EBX. duke@435: __ gen_subtype_check( rbx, ok_is_subtype ); duke@435: duke@435: // Come here on failure duke@435: // object is at TOS duke@435: __ jump(ExternalAddress(Interpreter::_throw_ArrayStoreException_entry)); duke@435: duke@435: // Come here on success duke@435: __ bind(ok_is_subtype); ysr@777: ysr@777: // Get the value to store apetrusenko@797: __ movptr(rax, at_rsp()); ysr@777: // and store it with appropriate barrier ysr@777: do_oop_store(_masm, Address(rdx, 0), rax, _bs->kind(), true); ysr@777: ysr@777: __ jmp(done); duke@435: duke@435: // Have a NULL in EAX, EDX=array, ECX=index. Store NULL at ary[idx] duke@435: __ bind(is_null); duke@435: __ profile_null_seen(rbx); ysr@777: ysr@777: // Store NULL, (noreg means NULL to do_oop_store) ysr@777: do_oop_store(_masm, element_address, noreg, _bs->kind(), true); duke@435: duke@435: // Pop stack arguments duke@435: __ bind(done); twisti@1861: __ addptr(rsp, 3 * Interpreter::stackElementSize); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::bastore() { duke@435: transition(itos, vtos); duke@435: __ pop_i(rbx); kevinw@8368: // rax: value kevinw@8368: // rbx: index duke@435: // rdx: array kevinw@8368: index_check(rdx, rbx); // prefer index in rbx kevinw@8368: // Need to check whether array is boolean or byte kevinw@8368: // since both types share the bastore bytecode. kevinw@8368: __ load_klass(rcx, rdx); kevinw@8368: __ movl(rcx, Address(rcx, Klass::layout_helper_offset())); kevinw@8368: int diffbit = Klass::layout_helper_boolean_diffbit(); kevinw@8368: __ testl(rcx, diffbit); kevinw@8368: Label L_skip; kevinw@8368: __ jccb(Assembler::zero, L_skip); kevinw@8368: __ andl(rax, 1); // if it is a T_BOOLEAN array, mask the stored value to 0/1 kevinw@8368: __ bind(L_skip); kevinw@8368: __ movb(Address(rdx, rbx, Address::times_1, arrayOopDesc::base_offset_in_bytes(T_BYTE)), rax); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::castore() { duke@435: transition(itos, vtos); duke@435: __ pop_i(rbx); duke@435: // rax,: value duke@435: // rdx: array duke@435: index_check(rdx, rbx); // prefer index in rbx, duke@435: // rbx,: index duke@435: __ movw(Address(rdx, rbx, Address::times_2, arrayOopDesc::base_offset_in_bytes(T_CHAR)), rax); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::sastore() { duke@435: castore(); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::istore(int n) { duke@435: transition(itos, vtos); duke@435: __ movl(iaddress(n), rax); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::lstore(int n) { duke@435: transition(ltos, vtos); never@739: __ movptr(laddress(n), rax); never@739: NOT_LP64(__ movptr(haddress(n), rdx)); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::fstore(int n) { duke@435: transition(ftos, vtos); duke@435: __ fstp_s(faddress(n)); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::dstore(int n) { duke@435: transition(dtos, vtos); twisti@1861: __ fstp_d(daddress(n)); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::astore(int n) { duke@435: transition(vtos, vtos); twisti@1861: __ pop_ptr(rax); never@739: __ movptr(aaddress(n), rax); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::pop() { duke@435: transition(vtos, vtos); twisti@1861: __ addptr(rsp, Interpreter::stackElementSize); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::pop2() { duke@435: transition(vtos, vtos); twisti@1861: __ addptr(rsp, 2*Interpreter::stackElementSize); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::dup() { duke@435: transition(vtos, vtos); duke@435: // stack: ..., a twisti@1861: __ load_ptr(0, rax); twisti@1861: __ push_ptr(rax); duke@435: // stack: ..., a, a duke@435: } duke@435: duke@435: duke@435: void TemplateTable::dup_x1() { duke@435: transition(vtos, vtos); duke@435: // stack: ..., a, b twisti@1861: __ load_ptr( 0, rax); // load b twisti@1861: __ load_ptr( 1, rcx); // load a twisti@1861: __ store_ptr(1, rax); // store b twisti@1861: __ store_ptr(0, rcx); // store a twisti@1861: __ push_ptr(rax); // push b duke@435: // stack: ..., b, a, b duke@435: } duke@435: duke@435: duke@435: void TemplateTable::dup_x2() { duke@435: transition(vtos, vtos); duke@435: // stack: ..., a, b, c twisti@1861: __ load_ptr( 0, rax); // load c twisti@1861: __ load_ptr( 2, rcx); // load a twisti@1861: __ store_ptr(2, rax); // store c in a twisti@1861: __ push_ptr(rax); // push c duke@435: // stack: ..., c, b, c, c twisti@1861: __ load_ptr( 2, rax); // load b twisti@1861: __ store_ptr(2, rcx); // store a in b duke@435: // stack: ..., c, a, c, c twisti@1861: __ store_ptr(1, rax); // store b in c duke@435: // stack: ..., c, a, b, c duke@435: } duke@435: duke@435: duke@435: void TemplateTable::dup2() { duke@435: transition(vtos, vtos); duke@435: // stack: ..., a, b twisti@1861: __ load_ptr(1, rax); // load a twisti@1861: __ push_ptr(rax); // push a twisti@1861: __ load_ptr(1, rax); // load b twisti@1861: __ push_ptr(rax); // push b duke@435: // stack: ..., a, b, a, b duke@435: } duke@435: duke@435: duke@435: void TemplateTable::dup2_x1() { duke@435: transition(vtos, vtos); duke@435: // stack: ..., a, b, c twisti@1861: __ load_ptr( 0, rcx); // load c twisti@1861: __ load_ptr( 1, rax); // load b twisti@1861: __ push_ptr(rax); // push b twisti@1861: __ push_ptr(rcx); // push c duke@435: // stack: ..., a, b, c, b, c twisti@1861: __ store_ptr(3, rcx); // store c in b duke@435: // stack: ..., a, c, c, b, c twisti@1861: __ load_ptr( 4, rcx); // load a twisti@1861: __ store_ptr(2, rcx); // store a in 2nd c duke@435: // stack: ..., a, c, a, b, c twisti@1861: __ store_ptr(4, rax); // store b in a duke@435: // stack: ..., b, c, a, b, c duke@435: // stack: ..., b, c, a, b, c duke@435: } duke@435: duke@435: duke@435: void TemplateTable::dup2_x2() { duke@435: transition(vtos, vtos); duke@435: // stack: ..., a, b, c, d twisti@1861: __ load_ptr( 0, rcx); // load d twisti@1861: __ load_ptr( 1, rax); // load c twisti@1861: __ push_ptr(rax); // push c twisti@1861: __ push_ptr(rcx); // push d duke@435: // stack: ..., a, b, c, d, c, d twisti@1861: __ load_ptr( 4, rax); // load b twisti@1861: __ store_ptr(2, rax); // store b in d twisti@1861: __ store_ptr(4, rcx); // store d in b duke@435: // stack: ..., a, d, c, b, c, d twisti@1861: __ load_ptr( 5, rcx); // load a twisti@1861: __ load_ptr( 3, rax); // load c twisti@1861: __ store_ptr(3, rcx); // store a in c twisti@1861: __ store_ptr(5, rax); // store c in a duke@435: // stack: ..., c, d, a, b, c, d duke@435: // stack: ..., c, d, a, b, c, d duke@435: } duke@435: duke@435: duke@435: void TemplateTable::swap() { duke@435: transition(vtos, vtos); duke@435: // stack: ..., a, b twisti@1861: __ load_ptr( 1, rcx); // load a twisti@1861: __ load_ptr( 0, rax); // load b twisti@1861: __ store_ptr(0, rcx); // store a in b twisti@1861: __ store_ptr(1, rax); // store b in a duke@435: // stack: ..., b, a duke@435: } duke@435: duke@435: duke@435: void TemplateTable::iop2(Operation op) { duke@435: transition(itos, itos); duke@435: switch (op) { twisti@1861: case add : __ pop_i(rdx); __ addl (rax, rdx); break; never@739: case sub : __ mov(rdx, rax); __ pop_i(rax); __ subl (rax, rdx); break; twisti@1861: case mul : __ pop_i(rdx); __ imull(rax, rdx); break; twisti@1861: case _and : __ pop_i(rdx); __ andl (rax, rdx); break; twisti@1861: case _or : __ pop_i(rdx); __ orl (rax, rdx); break; twisti@1861: case _xor : __ pop_i(rdx); __ xorl (rax, rdx); break; never@739: case shl : __ mov(rcx, rax); __ pop_i(rax); __ shll (rax); break; // implicit masking of lower 5 bits by Intel shift instr. never@739: case shr : __ mov(rcx, rax); __ pop_i(rax); __ sarl (rax); break; // implicit masking of lower 5 bits by Intel shift instr. never@739: case ushr : __ mov(rcx, rax); __ pop_i(rax); __ shrl (rax); break; // implicit masking of lower 5 bits by Intel shift instr. duke@435: default : ShouldNotReachHere(); duke@435: } duke@435: } duke@435: duke@435: duke@435: void TemplateTable::lop2(Operation op) { duke@435: transition(ltos, ltos); duke@435: __ pop_l(rbx, rcx); duke@435: switch (op) { twisti@1861: case add : __ addl(rax, rbx); __ adcl(rdx, rcx); break; twisti@1861: case sub : __ subl(rbx, rax); __ sbbl(rcx, rdx); twisti@1861: __ mov (rax, rbx); __ mov (rdx, rcx); break; twisti@1861: case _and : __ andl(rax, rbx); __ andl(rdx, rcx); break; twisti@1861: case _or : __ orl (rax, rbx); __ orl (rdx, rcx); break; twisti@1861: case _xor : __ xorl(rax, rbx); __ xorl(rdx, rcx); break; twisti@1861: default : ShouldNotReachHere(); duke@435: } duke@435: } duke@435: duke@435: duke@435: void TemplateTable::idiv() { duke@435: transition(itos, itos); never@739: __ mov(rcx, rax); duke@435: __ pop_i(rax); duke@435: // Note: could xor rax, and rcx and compare with (-1 ^ min_int). If duke@435: // they are not equal, one could do a normal division (no correction duke@435: // needed), which may speed up this implementation for the common case. duke@435: // (see also JVM spec., p.243 & p.271) duke@435: __ corrected_idivl(rcx); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::irem() { duke@435: transition(itos, itos); never@739: __ mov(rcx, rax); duke@435: __ pop_i(rax); duke@435: // Note: could xor rax, and rcx and compare with (-1 ^ min_int). If duke@435: // they are not equal, one could do a normal division (no correction duke@435: // needed), which may speed up this implementation for the common case. duke@435: // (see also JVM spec., p.243 & p.271) duke@435: __ corrected_idivl(rcx); never@739: __ mov(rax, rdx); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::lmul() { duke@435: transition(ltos, ltos); duke@435: __ pop_l(rbx, rcx); never@739: __ push(rcx); __ push(rbx); never@739: __ push(rdx); __ push(rax); duke@435: __ lmul(2 * wordSize, 0); never@739: __ addptr(rsp, 4 * wordSize); // take off temporaries duke@435: } duke@435: duke@435: duke@435: void TemplateTable::ldiv() { duke@435: transition(ltos, ltos); duke@435: __ pop_l(rbx, rcx); never@739: __ push(rcx); __ push(rbx); never@739: __ push(rdx); __ push(rax); duke@435: // check if y = 0 duke@435: __ orl(rax, rdx); duke@435: __ jump_cc(Assembler::zero, duke@435: ExternalAddress(Interpreter::_throw_ArithmeticException_entry)); duke@435: __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::ldiv)); never@739: __ addptr(rsp, 4 * wordSize); // take off temporaries duke@435: } duke@435: duke@435: duke@435: void TemplateTable::lrem() { duke@435: transition(ltos, ltos); duke@435: __ pop_l(rbx, rcx); never@739: __ push(rcx); __ push(rbx); never@739: __ push(rdx); __ push(rax); duke@435: // check if y = 0 duke@435: __ orl(rax, rdx); duke@435: __ jump_cc(Assembler::zero, duke@435: ExternalAddress(Interpreter::_throw_ArithmeticException_entry)); duke@435: __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::lrem)); never@739: __ addptr(rsp, 4 * wordSize); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::lshl() { duke@435: transition(itos, ltos); duke@435: __ movl(rcx, rax); // get shift count duke@435: __ pop_l(rax, rdx); // get shift value duke@435: __ lshl(rdx, rax); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::lshr() { duke@435: transition(itos, ltos); never@739: __ mov(rcx, rax); // get shift count duke@435: __ pop_l(rax, rdx); // get shift value duke@435: __ lshr(rdx, rax, true); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::lushr() { duke@435: transition(itos, ltos); never@739: __ mov(rcx, rax); // get shift count duke@435: __ pop_l(rax, rdx); // get shift value duke@435: __ lshr(rdx, rax); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::fop2(Operation op) { duke@435: transition(ftos, ftos); duke@435: switch (op) { duke@435: case add: __ fadd_s (at_rsp()); break; duke@435: case sub: __ fsubr_s(at_rsp()); break; duke@435: case mul: __ fmul_s (at_rsp()); break; duke@435: case div: __ fdivr_s(at_rsp()); break; duke@435: case rem: __ fld_s (at_rsp()); __ fremr(rax); break; duke@435: default : ShouldNotReachHere(); duke@435: } duke@435: __ f2ieee(); never@739: __ pop(rax); // pop float thing off duke@435: } duke@435: duke@435: duke@435: void TemplateTable::dop2(Operation op) { duke@435: transition(dtos, dtos); duke@435: duke@435: switch (op) { duke@435: case add: __ fadd_d (at_rsp()); break; duke@435: case sub: __ fsubr_d(at_rsp()); break; duke@435: case mul: { duke@435: Label L_strict; duke@435: Label L_join; coleenp@4037: const Address access_flags (rcx, Method::access_flags_offset()); duke@435: __ get_method(rcx); duke@435: __ movl(rcx, access_flags); duke@435: __ testl(rcx, JVM_ACC_STRICT); duke@435: __ jccb(Assembler::notZero, L_strict); duke@435: __ fmul_d (at_rsp()); duke@435: __ jmpb(L_join); duke@435: __ bind(L_strict); duke@435: __ fld_x(ExternalAddress(StubRoutines::addr_fpu_subnormal_bias1())); duke@435: __ fmulp(); duke@435: __ fmul_d (at_rsp()); duke@435: __ fld_x(ExternalAddress(StubRoutines::addr_fpu_subnormal_bias2())); duke@435: __ fmulp(); duke@435: __ bind(L_join); duke@435: break; duke@435: } duke@435: case div: { duke@435: Label L_strict; duke@435: Label L_join; coleenp@4037: const Address access_flags (rcx, Method::access_flags_offset()); duke@435: __ get_method(rcx); duke@435: __ movl(rcx, access_flags); duke@435: __ testl(rcx, JVM_ACC_STRICT); duke@435: __ jccb(Assembler::notZero, L_strict); duke@435: __ fdivr_d(at_rsp()); duke@435: __ jmp(L_join); duke@435: __ bind(L_strict); duke@435: __ fld_x(ExternalAddress(StubRoutines::addr_fpu_subnormal_bias1())); duke@435: __ fmul_d (at_rsp()); duke@435: __ fdivrp(); duke@435: __ fld_x(ExternalAddress(StubRoutines::addr_fpu_subnormal_bias2())); duke@435: __ fmulp(); duke@435: __ bind(L_join); duke@435: break; duke@435: } duke@435: case rem: __ fld_d (at_rsp()); __ fremr(rax); break; duke@435: default : ShouldNotReachHere(); duke@435: } duke@435: __ d2ieee(); duke@435: // Pop double precision number from rsp. never@739: __ pop(rax); never@739: __ pop(rdx); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::ineg() { duke@435: transition(itos, itos); duke@435: __ negl(rax); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::lneg() { duke@435: transition(ltos, ltos); duke@435: __ lneg(rdx, rax); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::fneg() { duke@435: transition(ftos, ftos); duke@435: __ fchs(); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::dneg() { duke@435: transition(dtos, dtos); duke@435: __ fchs(); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::iinc() { duke@435: transition(vtos, vtos); duke@435: __ load_signed_byte(rdx, at_bcp(2)); // get constant duke@435: locals_index(rbx); duke@435: __ addl(iaddress(rbx), rdx); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::wide_iinc() { duke@435: transition(vtos, vtos); duke@435: __ movl(rdx, at_bcp(4)); // get constant duke@435: locals_index_wide(rbx); never@739: __ bswapl(rdx); // swap bytes & sign-extend constant duke@435: __ sarl(rdx, 16); duke@435: __ addl(iaddress(rbx), rdx); duke@435: // Note: should probably use only one movl to get both duke@435: // the index and the constant -> fix this duke@435: } duke@435: duke@435: duke@435: void TemplateTable::convert() { duke@435: // Checking duke@435: #ifdef ASSERT duke@435: { TosState tos_in = ilgl; duke@435: TosState tos_out = ilgl; duke@435: switch (bytecode()) { duke@435: case Bytecodes::_i2l: // fall through duke@435: case Bytecodes::_i2f: // fall through duke@435: case Bytecodes::_i2d: // fall through duke@435: case Bytecodes::_i2b: // fall through duke@435: case Bytecodes::_i2c: // fall through duke@435: case Bytecodes::_i2s: tos_in = itos; break; duke@435: case Bytecodes::_l2i: // fall through duke@435: case Bytecodes::_l2f: // fall through duke@435: case Bytecodes::_l2d: tos_in = ltos; break; duke@435: case Bytecodes::_f2i: // fall through duke@435: case Bytecodes::_f2l: // fall through duke@435: case Bytecodes::_f2d: tos_in = ftos; break; duke@435: case Bytecodes::_d2i: // fall through duke@435: case Bytecodes::_d2l: // fall through duke@435: case Bytecodes::_d2f: tos_in = dtos; break; duke@435: default : ShouldNotReachHere(); duke@435: } duke@435: switch (bytecode()) { duke@435: case Bytecodes::_l2i: // fall through duke@435: case Bytecodes::_f2i: // fall through duke@435: case Bytecodes::_d2i: // fall through duke@435: case Bytecodes::_i2b: // fall through duke@435: case Bytecodes::_i2c: // fall through duke@435: case Bytecodes::_i2s: tos_out = itos; break; duke@435: case Bytecodes::_i2l: // fall through duke@435: case Bytecodes::_f2l: // fall through duke@435: case Bytecodes::_d2l: tos_out = ltos; break; duke@435: case Bytecodes::_i2f: // fall through duke@435: case Bytecodes::_l2f: // fall through duke@435: case Bytecodes::_d2f: tos_out = ftos; break; duke@435: case Bytecodes::_i2d: // fall through duke@435: case Bytecodes::_l2d: // fall through duke@435: case Bytecodes::_f2d: tos_out = dtos; break; duke@435: default : ShouldNotReachHere(); duke@435: } duke@435: transition(tos_in, tos_out); duke@435: } duke@435: #endif // ASSERT duke@435: duke@435: // Conversion never@739: // (Note: use push(rcx)/pop(rcx) for 1/2-word stack-ptr manipulation) duke@435: switch (bytecode()) { duke@435: case Bytecodes::_i2l: duke@435: __ extend_sign(rdx, rax); duke@435: break; duke@435: case Bytecodes::_i2f: never@739: __ push(rax); // store int on tos duke@435: __ fild_s(at_rsp()); // load int to ST0 duke@435: __ f2ieee(); // truncate to float size never@739: __ pop(rcx); // adjust rsp duke@435: break; duke@435: case Bytecodes::_i2d: never@739: __ push(rax); // add one slot for d2ieee() never@739: __ push(rax); // store int on tos duke@435: __ fild_s(at_rsp()); // load int to ST0 duke@435: __ d2ieee(); // truncate to double size never@739: __ pop(rcx); // adjust rsp never@739: __ pop(rcx); duke@435: break; duke@435: case Bytecodes::_i2b: duke@435: __ shll(rax, 24); // truncate upper 24 bits duke@435: __ sarl(rax, 24); // and sign-extend byte never@739: LP64_ONLY(__ movsbl(rax, rax)); duke@435: break; duke@435: case Bytecodes::_i2c: duke@435: __ andl(rax, 0xFFFF); // truncate upper 16 bits never@739: LP64_ONLY(__ movzwl(rax, rax)); duke@435: break; duke@435: case Bytecodes::_i2s: duke@435: __ shll(rax, 16); // truncate upper 16 bits duke@435: __ sarl(rax, 16); // and sign-extend short never@739: LP64_ONLY(__ movswl(rax, rax)); duke@435: break; duke@435: case Bytecodes::_l2i: duke@435: /* nothing to do */ duke@435: break; duke@435: case Bytecodes::_l2f: never@739: __ push(rdx); // store long on tos never@739: __ push(rax); duke@435: __ fild_d(at_rsp()); // load long to ST0 duke@435: __ f2ieee(); // truncate to float size never@739: __ pop(rcx); // adjust rsp never@739: __ pop(rcx); duke@435: break; duke@435: case Bytecodes::_l2d: never@739: __ push(rdx); // store long on tos never@739: __ push(rax); duke@435: __ fild_d(at_rsp()); // load long to ST0 duke@435: __ d2ieee(); // truncate to double size never@739: __ pop(rcx); // adjust rsp never@739: __ pop(rcx); duke@435: break; duke@435: case Bytecodes::_f2i: never@739: __ push(rcx); // reserve space for argument duke@435: __ fstp_s(at_rsp()); // pass float argument on stack duke@435: __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::f2i), 1); duke@435: break; duke@435: case Bytecodes::_f2l: never@739: __ push(rcx); // reserve space for argument duke@435: __ fstp_s(at_rsp()); // pass float argument on stack duke@435: __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::f2l), 1); duke@435: break; duke@435: case Bytecodes::_f2d: duke@435: /* nothing to do */ duke@435: break; duke@435: case Bytecodes::_d2i: never@739: __ push(rcx); // reserve space for argument never@739: __ push(rcx); duke@435: __ fstp_d(at_rsp()); // pass double argument on stack duke@435: __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::d2i), 2); duke@435: break; duke@435: case Bytecodes::_d2l: never@739: __ push(rcx); // reserve space for argument never@739: __ push(rcx); duke@435: __ fstp_d(at_rsp()); // pass double argument on stack duke@435: __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::d2l), 2); duke@435: break; duke@435: case Bytecodes::_d2f: never@739: __ push(rcx); // reserve space for f2ieee() duke@435: __ f2ieee(); // truncate to float size never@739: __ pop(rcx); // adjust rsp duke@435: break; duke@435: default : duke@435: ShouldNotReachHere(); duke@435: } duke@435: } duke@435: duke@435: duke@435: void TemplateTable::lcmp() { duke@435: transition(ltos, itos); duke@435: // y = rdx:rax duke@435: __ pop_l(rbx, rcx); // get x = rcx:rbx duke@435: __ lcmp2int(rcx, rbx, rdx, rax);// rcx := cmp(x, y) never@739: __ mov(rax, rcx); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::float_cmp(bool is_float, int unordered_result) { duke@435: if (is_float) { duke@435: __ fld_s(at_rsp()); duke@435: } else { duke@435: __ fld_d(at_rsp()); never@739: __ pop(rdx); duke@435: } never@739: __ pop(rcx); duke@435: __ fcmp2int(rax, unordered_result < 0); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::branch(bool is_jsr, bool is_wide) { duke@435: __ get_method(rcx); // ECX holds method duke@435: __ profile_taken_branch(rax,rbx); // EAX holds updated MDP, EBX holds bumped taken count duke@435: jiangli@4936: const ByteSize be_offset = MethodCounters::backedge_counter_offset() + jiangli@4936: InvocationCounter::counter_offset(); jiangli@4936: const ByteSize inv_offset = MethodCounters::invocation_counter_offset() + jiangli@4936: InvocationCounter::counter_offset(); duke@435: duke@435: // Load up EDX with the branch displacement mgerdin@6059: if (is_wide) { mgerdin@6059: __ movl(rdx, at_bcp(1)); mgerdin@6059: } else { mgerdin@6059: __ load_signed_short(rdx, at_bcp(1)); mgerdin@6059: } never@739: __ bswapl(rdx); duke@435: if (!is_wide) __ sarl(rdx, 16); never@739: LP64_ONLY(__ movslq(rdx, rdx)); never@739: duke@435: duke@435: // Handle all the JSR stuff here, then exit. duke@435: // It's much shorter and cleaner than intermingling with the twisti@1040: // non-JSR normal-branch stuff occurring below. duke@435: if (is_jsr) { duke@435: // Pre-load the next target bytecode into EBX duke@435: __ load_unsigned_byte(rbx, Address(rsi, rdx, Address::times_1, 0)); duke@435: duke@435: // compute return address as bci in rax, coleenp@4037: __ lea(rax, at_bcp((is_wide ? 5 : 3) - in_bytes(ConstMethod::codes_offset()))); coleenp@4037: __ subptr(rax, Address(rcx, Method::const_offset())); apetrusenko@797: // Adjust the bcp in RSI by the displacement in EDX never@739: __ addptr(rsi, rdx); duke@435: // Push return address duke@435: __ push_i(rax); duke@435: // jsr returns vtos duke@435: __ dispatch_only_noverify(vtos); duke@435: return; duke@435: } duke@435: duke@435: // Normal (non-jsr) branch handling duke@435: apetrusenko@797: // Adjust the bcp in RSI by the displacement in EDX never@739: __ addptr(rsi, rdx); duke@435: duke@435: assert(UseLoopCounter || !UseOnStackReplacement, "on-stack-replacement requires loop counters"); duke@435: Label backedge_counter_overflow; duke@435: Label profile_method; duke@435: Label dispatch; duke@435: if (UseLoopCounter) { duke@435: // increment backedge counter for backward branches duke@435: // rax,: MDO duke@435: // rbx,: MDO bumped taken-count duke@435: // rcx: method duke@435: // rdx: target offset duke@435: // rsi: target bcp duke@435: // rdi: locals pointer duke@435: __ testl(rdx, rdx); // check if forward or backward branch duke@435: __ jcc(Assembler::positive, dispatch); // count only if backward branch duke@435: jiangli@4936: // check if MethodCounters exists jiangli@4936: Label has_counters; jiangli@4936: __ movptr(rax, Address(rcx, Method::method_counters_offset())); jiangli@4936: __ testptr(rax, rax); jiangli@4936: __ jcc(Assembler::notZero, has_counters); jiangli@4936: __ push(rdx); jiangli@4936: __ push(rcx); jiangli@4936: __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::build_method_counters), jiangli@4936: rcx); jiangli@4936: __ pop(rcx); jiangli@4936: __ pop(rdx); jiangli@4936: __ movptr(rax, Address(rcx, Method::method_counters_offset())); jiangli@4936: __ testptr(rax, rax); jiangli@4936: __ jcc(Assembler::zero, dispatch); jiangli@4936: __ bind(has_counters); jiangli@4936: iveresov@2138: if (TieredCompilation) { iveresov@2138: Label no_mdo; iveresov@2138: int increment = InvocationCounter::count_increment; iveresov@2138: int mask = ((1 << Tier0BackedgeNotifyFreqLog) - 1) << InvocationCounter::count_shift; iveresov@2138: if (ProfileInterpreter) { iveresov@2138: // Are we profiling? coleenp@4037: __ movptr(rbx, Address(rcx, in_bytes(Method::method_data_offset()))); iveresov@2138: __ testptr(rbx, rbx); iveresov@2138: __ jccb(Assembler::zero, no_mdo); iveresov@2138: // Increment the MDO backedge counter coleenp@4037: const Address mdo_backedge_counter(rbx, in_bytes(MethodData::backedge_counter_offset()) + iveresov@2138: in_bytes(InvocationCounter::counter_offset())); phh@9604: __ increment_mask_and_jump(mdo_backedge_counter, increment, mask, rax, false, Assembler::zero, phh@9604: UseOnStackReplacement ? &backedge_counter_overflow : NULL); iveresov@2138: __ jmp(dispatch); duke@435: } iveresov@2138: __ bind(no_mdo); jiangli@4936: // Increment backedge counter in MethodCounters* jiangli@4936: __ movptr(rcx, Address(rcx, Method::method_counters_offset())); iveresov@2138: __ increment_mask_and_jump(Address(rcx, be_offset), increment, mask, phh@9604: rax, false, Assembler::zero, phh@9604: UseOnStackReplacement ? &backedge_counter_overflow : NULL); duke@435: } else { iveresov@2138: // increment counter jiangli@4936: __ movptr(rcx, Address(rcx, Method::method_counters_offset())); iveresov@2138: __ movl(rax, Address(rcx, be_offset)); // load backedge counter iveresov@2138: __ incrementl(rax, InvocationCounter::count_increment); // increment counter iveresov@2138: __ movl(Address(rcx, be_offset), rax); // store counter iveresov@2138: iveresov@2138: __ movl(rax, Address(rcx, inv_offset)); // load invocation counter jiangli@4936: iveresov@2138: __ andl(rax, InvocationCounter::count_mask_value); // and the status bits iveresov@2138: __ addl(rax, Address(rcx, be_offset)); // add both counters iveresov@2138: iveresov@2138: if (ProfileInterpreter) { iveresov@2138: // Test to see if we should create a method data oop duke@435: __ cmp32(rax, iveresov@2138: ExternalAddress((address) &InvocationCounter::InterpreterProfileLimit)); iveresov@2138: __ jcc(Assembler::less, dispatch); iveresov@2138: iveresov@2138: // if no method data exists, go to profile method iveresov@2138: __ test_method_data_pointer(rax, profile_method); iveresov@2138: iveresov@2138: if (UseOnStackReplacement) { iveresov@2138: // check for overflow against rbx, which is the MDO taken count iveresov@2138: __ cmp32(rbx, iveresov@2138: ExternalAddress((address) &InvocationCounter::InterpreterBackwardBranchLimit)); iveresov@2138: __ jcc(Assembler::below, dispatch); iveresov@2138: iveresov@2138: // When ProfileInterpreter is on, the backedge_count comes from the coleenp@4037: // MethodData*, which value does not get reset on the call to iveresov@2138: // frequency_counter_overflow(). To avoid excessive calls to the overflow iveresov@2138: // routine while the method is being compiled, add a second test to make iveresov@2138: // sure the overflow function is called only once every overflow_frequency. iveresov@2138: const int overflow_frequency = 1024; iveresov@2138: __ andptr(rbx, overflow_frequency-1); iveresov@2138: __ jcc(Assembler::zero, backedge_counter_overflow); iveresov@2138: } iveresov@2138: } else { iveresov@2138: if (UseOnStackReplacement) { iveresov@2138: // check for overflow against rax, which is the sum of the counters iveresov@2138: __ cmp32(rax, iveresov@2138: ExternalAddress((address) &InvocationCounter::InterpreterBackwardBranchLimit)); iveresov@2138: __ jcc(Assembler::aboveEqual, backedge_counter_overflow); iveresov@2138: iveresov@2138: } duke@435: } duke@435: } duke@435: __ bind(dispatch); duke@435: } duke@435: duke@435: // Pre-load the next target bytecode into EBX duke@435: __ load_unsigned_byte(rbx, Address(rsi, 0)); duke@435: duke@435: // continue with the bytecode @ target duke@435: // rax,: return bci for jsr's, unused otherwise duke@435: // rbx,: target bytecode duke@435: // rsi: target bcp duke@435: __ dispatch_only(vtos); duke@435: duke@435: if (UseLoopCounter) { duke@435: if (ProfileInterpreter) { duke@435: // Out-of-line code to allocate method data oop. duke@435: __ bind(profile_method); iveresov@2438: __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::profile_method)); duke@435: __ load_unsigned_byte(rbx, Address(rsi, 0)); // restore target bytecode iveresov@2438: __ set_method_data_pointer_for_bcp(); duke@435: __ jmp(dispatch); duke@435: } duke@435: duke@435: if (UseOnStackReplacement) { duke@435: duke@435: // invocation counter overflow duke@435: __ bind(backedge_counter_overflow); never@739: __ negptr(rdx); never@739: __ addptr(rdx, rsi); // branch bcp duke@435: call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::frequency_counter_overflow), rdx); duke@435: __ load_unsigned_byte(rbx, Address(rsi, 0)); // restore target bytecode duke@435: duke@435: // rax,: osr nmethod (osr ok) or NULL (osr not possible) duke@435: // rbx,: target bytecode duke@435: // rdx: scratch duke@435: // rdi: locals pointer duke@435: // rsi: bcp never@739: __ testptr(rax, rax); // test result duke@435: __ jcc(Assembler::zero, dispatch); // no osr if null duke@435: // nmethod may have been invalidated (VM may block upon call_VM return) duke@435: __ movl(rcx, Address(rax, nmethod::entry_bci_offset())); duke@435: __ cmpl(rcx, InvalidOSREntryBci); duke@435: __ jcc(Assembler::equal, dispatch); duke@435: duke@435: // We have the address of an on stack replacement routine in rax, duke@435: // We need to prepare to execute the OSR method. First we must duke@435: // migrate the locals and monitors off of the stack. duke@435: never@739: __ mov(rbx, rax); // save the nmethod duke@435: duke@435: const Register thread = rcx; duke@435: __ get_thread(thread); duke@435: call_VM(noreg, CAST_FROM_FN_PTR(address, SharedRuntime::OSR_migration_begin)); duke@435: // rax, is OSR buffer, move it to expected parameter location never@739: __ mov(rcx, rax); duke@435: duke@435: // pop the interpreter frame never@739: __ movptr(rdx, Address(rbp, frame::interpreter_frame_sender_sp_offset * wordSize)); // get sender sp duke@435: __ leave(); // remove frame anchor never@739: __ pop(rdi); // get return address never@739: __ mov(rsp, rdx); // set sp to sender sp duke@435: duke@435: // Align stack pointer for compiled code (note that caller is duke@435: // responsible for undoing this fixup by remembering the old SP duke@435: // in an rbp,-relative location) never@739: __ andptr(rsp, -(StackAlignmentInBytes)); duke@435: duke@435: // push the (possibly adjusted) return address never@739: __ push(rdi); duke@435: duke@435: // and begin the OSR nmethod sgoldman@542: __ jmp(Address(rbx, nmethod::osr_entry_point_offset())); duke@435: } duke@435: } duke@435: } duke@435: duke@435: duke@435: void TemplateTable::if_0cmp(Condition cc) { duke@435: transition(itos, vtos); duke@435: // assume branch is more often taken than not (loops use backward branches) duke@435: Label not_taken; duke@435: __ testl(rax, rax); duke@435: __ jcc(j_not(cc), not_taken); duke@435: branch(false, false); duke@435: __ bind(not_taken); duke@435: __ profile_not_taken_branch(rax); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::if_icmp(Condition cc) { duke@435: transition(itos, vtos); duke@435: // assume branch is more often taken than not (loops use backward branches) duke@435: Label not_taken; duke@435: __ pop_i(rdx); duke@435: __ cmpl(rdx, rax); duke@435: __ jcc(j_not(cc), not_taken); duke@435: branch(false, false); duke@435: __ bind(not_taken); duke@435: __ profile_not_taken_branch(rax); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::if_nullcmp(Condition cc) { duke@435: transition(atos, vtos); duke@435: // assume branch is more often taken than not (loops use backward branches) duke@435: Label not_taken; never@739: __ testptr(rax, rax); duke@435: __ jcc(j_not(cc), not_taken); duke@435: branch(false, false); duke@435: __ bind(not_taken); duke@435: __ profile_not_taken_branch(rax); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::if_acmp(Condition cc) { duke@435: transition(atos, vtos); duke@435: // assume branch is more often taken than not (loops use backward branches) duke@435: Label not_taken; duke@435: __ pop_ptr(rdx); never@739: __ cmpptr(rdx, rax); duke@435: __ jcc(j_not(cc), not_taken); duke@435: branch(false, false); duke@435: __ bind(not_taken); duke@435: __ profile_not_taken_branch(rax); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::ret() { duke@435: transition(vtos, vtos); duke@435: locals_index(rbx); never@739: __ movptr(rbx, iaddress(rbx)); // get return bci, compute return bcp duke@435: __ profile_ret(rbx, rcx); duke@435: __ get_method(rax); coleenp@4037: __ movptr(rsi, Address(rax, Method::const_offset())); never@739: __ lea(rsi, Address(rsi, rbx, Address::times_1, coleenp@4037: ConstMethod::codes_offset())); duke@435: __ dispatch_next(vtos); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::wide_ret() { duke@435: transition(vtos, vtos); duke@435: locals_index_wide(rbx); never@739: __ movptr(rbx, iaddress(rbx)); // get return bci, compute return bcp duke@435: __ profile_ret(rbx, rcx); duke@435: __ get_method(rax); coleenp@4037: __ movptr(rsi, Address(rax, Method::const_offset())); coleenp@4037: __ lea(rsi, Address(rsi, rbx, Address::times_1, ConstMethod::codes_offset())); duke@435: __ dispatch_next(vtos); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::tableswitch() { duke@435: Label default_case, continue_execution; duke@435: transition(itos, vtos); duke@435: // align rsi never@739: __ lea(rbx, at_bcp(wordSize)); never@739: __ andptr(rbx, -wordSize); duke@435: // load lo & hi duke@435: __ movl(rcx, Address(rbx, 1 * wordSize)); duke@435: __ movl(rdx, Address(rbx, 2 * wordSize)); never@739: __ bswapl(rcx); never@739: __ bswapl(rdx); duke@435: // check against lo & hi duke@435: __ cmpl(rax, rcx); duke@435: __ jccb(Assembler::less, default_case); duke@435: __ cmpl(rax, rdx); duke@435: __ jccb(Assembler::greater, default_case); duke@435: // lookup dispatch offset duke@435: __ subl(rax, rcx); never@739: __ movl(rdx, Address(rbx, rax, Address::times_4, 3 * BytesPerInt)); duke@435: __ profile_switch_case(rax, rbx, rcx); duke@435: // continue execution duke@435: __ bind(continue_execution); never@739: __ bswapl(rdx); duke@435: __ load_unsigned_byte(rbx, Address(rsi, rdx, Address::times_1)); never@739: __ addptr(rsi, rdx); duke@435: __ dispatch_only(vtos); duke@435: // handle default duke@435: __ bind(default_case); duke@435: __ profile_switch_default(rax); duke@435: __ movl(rdx, Address(rbx, 0)); duke@435: __ jmp(continue_execution); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::lookupswitch() { duke@435: transition(itos, itos); duke@435: __ stop("lookupswitch bytecode should have been rewritten"); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::fast_linearswitch() { duke@435: transition(itos, vtos); duke@435: Label loop_entry, loop, found, continue_execution; never@739: // bswapl rax, so we can avoid bswapping the table entries never@739: __ bswapl(rax); duke@435: // align rsi never@739: __ lea(rbx, at_bcp(wordSize)); // btw: should be able to get rid of this instruction (change offsets below) never@739: __ andptr(rbx, -wordSize); duke@435: // set counter duke@435: __ movl(rcx, Address(rbx, wordSize)); never@739: __ bswapl(rcx); duke@435: __ jmpb(loop_entry); duke@435: // table search duke@435: __ bind(loop); duke@435: __ cmpl(rax, Address(rbx, rcx, Address::times_8, 2 * wordSize)); duke@435: __ jccb(Assembler::equal, found); duke@435: __ bind(loop_entry); never@739: __ decrementl(rcx); duke@435: __ jcc(Assembler::greaterEqual, loop); duke@435: // default case duke@435: __ profile_switch_default(rax); duke@435: __ movl(rdx, Address(rbx, 0)); duke@435: __ jmpb(continue_execution); duke@435: // entry found -> get offset duke@435: __ bind(found); duke@435: __ movl(rdx, Address(rbx, rcx, Address::times_8, 3 * wordSize)); duke@435: __ profile_switch_case(rcx, rax, rbx); duke@435: // continue execution duke@435: __ bind(continue_execution); never@739: __ bswapl(rdx); duke@435: __ load_unsigned_byte(rbx, Address(rsi, rdx, Address::times_1)); never@739: __ addptr(rsi, rdx); duke@435: __ dispatch_only(vtos); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::fast_binaryswitch() { duke@435: transition(itos, vtos); duke@435: // Implementation using the following core algorithm: duke@435: // duke@435: // int binary_search(int key, LookupswitchPair* array, int n) { duke@435: // // Binary search according to "Methodik des Programmierens" by duke@435: // // Edsger W. Dijkstra and W.H.J. Feijen, Addison Wesley Germany 1985. duke@435: // int i = 0; duke@435: // int j = n; duke@435: // while (i+1 < j) { duke@435: // // invariant P: 0 <= i < j <= n and (a[i] <= key < a[j] or Q) duke@435: // // with Q: for all i: 0 <= i < n: key < a[i] duke@435: // // where a stands for the array and assuming that the (inexisting) duke@435: // // element a[n] is infinitely big. duke@435: // int h = (i + j) >> 1; duke@435: // // i < h < j duke@435: // if (key < array[h].fast_match()) { duke@435: // j = h; duke@435: // } else { duke@435: // i = h; duke@435: // } duke@435: // } duke@435: // // R: a[i] <= key < a[i+1] or Q duke@435: // // (i.e., if key is within array, i is the correct index) duke@435: // return i; duke@435: // } duke@435: duke@435: // register allocation duke@435: const Register key = rax; // already set (tosca) duke@435: const Register array = rbx; duke@435: const Register i = rcx; duke@435: const Register j = rdx; duke@435: const Register h = rdi; // needs to be restored duke@435: const Register temp = rsi; duke@435: // setup array duke@435: __ save_bcp(); duke@435: never@739: __ lea(array, at_bcp(3*wordSize)); // btw: should be able to get rid of this instruction (change offsets below) never@739: __ andptr(array, -wordSize); duke@435: // initialize i & j duke@435: __ xorl(i, i); // i = 0; duke@435: __ movl(j, Address(array, -wordSize)); // j = length(array); duke@435: // Convert j into native byteordering never@739: __ bswapl(j); duke@435: // and start duke@435: Label entry; duke@435: __ jmp(entry); duke@435: duke@435: // binary search loop duke@435: { Label loop; duke@435: __ bind(loop); duke@435: // int h = (i + j) >> 1; duke@435: __ leal(h, Address(i, j, Address::times_1)); // h = i + j; duke@435: __ sarl(h, 1); // h = (i + j) >> 1; duke@435: // if (key < array[h].fast_match()) { duke@435: // j = h; duke@435: // } else { duke@435: // i = h; duke@435: // } duke@435: // Convert array[h].match to native byte-ordering before compare duke@435: __ movl(temp, Address(array, h, Address::times_8, 0*wordSize)); never@739: __ bswapl(temp); duke@435: __ cmpl(key, temp); twisti@2697: // j = h if (key < array[h].fast_match()) twisti@2697: __ cmov32(Assembler::less , j, h); twisti@2697: // i = h if (key >= array[h].fast_match()) twisti@2697: __ cmov32(Assembler::greaterEqual, i, h); duke@435: // while (i+1 < j) duke@435: __ bind(entry); duke@435: __ leal(h, Address(i, 1)); // i+1 duke@435: __ cmpl(h, j); // i+1 < j duke@435: __ jcc(Assembler::less, loop); duke@435: } duke@435: duke@435: // end of binary search, result index is i (must check again!) duke@435: Label default_case; duke@435: // Convert array[i].match to native byte-ordering before compare duke@435: __ movl(temp, Address(array, i, Address::times_8, 0*wordSize)); never@739: __ bswapl(temp); duke@435: __ cmpl(key, temp); duke@435: __ jcc(Assembler::notEqual, default_case); duke@435: duke@435: // entry found -> j = offset duke@435: __ movl(j , Address(array, i, Address::times_8, 1*wordSize)); duke@435: __ profile_switch_case(i, key, array); never@739: __ bswapl(j); never@739: LP64_ONLY(__ movslq(j, j)); duke@435: __ restore_bcp(); duke@435: __ restore_locals(); // restore rdi duke@435: __ load_unsigned_byte(rbx, Address(rsi, j, Address::times_1)); duke@435: never@739: __ addptr(rsi, j); duke@435: __ dispatch_only(vtos); duke@435: duke@435: // default case -> j = default offset duke@435: __ bind(default_case); duke@435: __ profile_switch_default(i); duke@435: __ movl(j, Address(array, -2*wordSize)); never@739: __ bswapl(j); never@739: LP64_ONLY(__ movslq(j, j)); duke@435: __ restore_bcp(); duke@435: __ restore_locals(); // restore rdi duke@435: __ load_unsigned_byte(rbx, Address(rsi, j, Address::times_1)); never@739: __ addptr(rsi, j); duke@435: __ dispatch_only(vtos); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::_return(TosState state) { duke@435: transition(state, state); duke@435: assert(_desc->calls_vm(), "inconsistent calls_vm information"); // call in remove_activation duke@435: duke@435: if (_desc->bytecode() == Bytecodes::_return_register_finalizer) { duke@435: assert(state == vtos, "only valid state"); never@739: __ movptr(rax, aaddress(0)); twisti@2807: __ load_klass(rdi, rax); stefank@3391: __ movl(rdi, Address(rdi, Klass::access_flags_offset())); duke@435: __ testl(rdi, JVM_ACC_HAS_FINALIZER); duke@435: Label skip_register_finalizer; duke@435: __ jcc(Assembler::zero, skip_register_finalizer); duke@435: duke@435: __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::register_finalizer), rax); duke@435: duke@435: __ bind(skip_register_finalizer); duke@435: } duke@435: kevinw@8368: // Narrow result if state is itos but result type is smaller. kevinw@8368: // Need to narrow in the return bytecode rather than in generate_return_entry kevinw@8368: // since compiled code callers expect the result to already be narrowed. kevinw@8368: if (state == itos) { kevinw@8368: __ narrow(rax); kevinw@8368: } duke@435: __ remove_activation(state, rsi); kevinw@8368: duke@435: __ jmp(rsi); duke@435: } duke@435: duke@435: duke@435: // ---------------------------------------------------------------------------- duke@435: // Volatile variables demand their effects be made known to all CPU's in duke@435: // order. Store buffers on most chips allow reads & writes to reorder; the duke@435: // JMM's ReadAfterWrite.java test fails in -Xint mode without some kind of duke@435: // memory barrier (i.e., it's not sufficient that the interpreter does not duke@435: // reorder volatile references, the hardware also must not reorder them). duke@435: // duke@435: // According to the new Java Memory Model (JMM): duke@435: // (1) All volatiles are serialized wrt to each other. duke@435: // ALSO reads & writes act as aquire & release, so: duke@435: // (2) A read cannot let unrelated NON-volatile memory refs that happen after duke@435: // the read float up to before the read. It's OK for non-volatile memory refs duke@435: // that happen before the volatile read to float down below it. duke@435: // (3) Similar a volatile write cannot let unrelated NON-volatile memory refs duke@435: // that happen BEFORE the write float down to after the write. It's OK for duke@435: // non-volatile memory refs that happen after the volatile write to float up duke@435: // before it. duke@435: // duke@435: // We only put in barriers around volatile refs (they are expensive), not duke@435: // _between_ memory refs (that would require us to track the flavor of the duke@435: // previous memory refs). Requirements (2) and (3) require some barriers duke@435: // before volatile stores and after volatile loads. These nearly cover duke@435: // requirement (1) but miss the volatile-store-volatile-load case. This final duke@435: // case is placed after volatile-stores although it could just as well go duke@435: // before volatile-loads. never@739: void TemplateTable::volatile_barrier(Assembler::Membar_mask_bits order_constraint ) { duke@435: // Helper function to insert a is-volatile test and memory barrier duke@435: if( !os::is_MP() ) return; // Not needed on single CPU never@739: __ membar(order_constraint); duke@435: } duke@435: jrose@1920: void TemplateTable::resolve_cache_and_index(int byte_no, jrose@1920: Register Rcache, jrose@1920: Register index, jrose@1920: size_t index_size) { twisti@3969: const Register temp = rbx; coleenp@4037: assert_different_registers(Rcache, index, temp); jrose@1920: duke@435: Label resolved; jrose@1920: assert(byte_no == f1_byte || byte_no == f2_byte, "byte_no out of range"); twisti@3050: __ get_cache_and_index_and_bytecode_at_bcp(Rcache, index, temp, byte_no, 1, index_size); twisti@3050: __ cmpl(temp, (int) bytecode()); // have we resolved this bytecode? jrose@1161: __ jcc(Assembler::equal, resolved); duke@435: duke@435: // resolve first time through duke@435: address entry; duke@435: switch (bytecode()) { duke@435: case Bytecodes::_getstatic : // fall through duke@435: case Bytecodes::_putstatic : // fall through duke@435: case Bytecodes::_getfield : // fall through twisti@3969: case Bytecodes::_putfield : entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_get_put); break; duke@435: case Bytecodes::_invokevirtual : // fall through duke@435: case Bytecodes::_invokespecial : // fall through duke@435: case Bytecodes::_invokestatic : // fall through twisti@3969: case Bytecodes::_invokeinterface: entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_invoke); break; twisti@3969: case Bytecodes::_invokehandle : entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_invokehandle); break; twisti@3969: case Bytecodes::_invokedynamic : entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_invokedynamic); break; twisti@3969: default: twisti@3969: fatal(err_msg("unexpected bytecode: %s", Bytecodes::name(bytecode()))); twisti@3969: break; duke@435: } duke@435: __ movl(temp, (int)bytecode()); duke@435: __ call_VM(noreg, entry, temp); duke@435: // Update registers with resolved info jrose@1920: __ get_cache_and_index_at_bcp(Rcache, index, 1, index_size); duke@435: __ bind(resolved); duke@435: } duke@435: duke@435: duke@435: // The cache and index registers must be set before call duke@435: void TemplateTable::load_field_cp_cache_entry(Register obj, duke@435: Register cache, duke@435: Register index, duke@435: Register off, duke@435: Register flags, duke@435: bool is_static = false) { duke@435: assert_different_registers(cache, index, flags, off); duke@435: coleenp@4037: ByteSize cp_base_offset = ConstantPoolCache::base_offset(); duke@435: // Field offset never@739: __ movptr(off, Address(cache, index, Address::times_ptr, never@739: in_bytes(cp_base_offset + ConstantPoolCacheEntry::f2_offset()))); duke@435: // Flags never@739: __ movl(flags, Address(cache, index, Address::times_ptr, duke@435: in_bytes(cp_base_offset + ConstantPoolCacheEntry::flags_offset()))); duke@435: twisti@3969: // klass overwrite register duke@435: if (is_static) { never@739: __ movptr(obj, Address(cache, index, Address::times_ptr, never@739: in_bytes(cp_base_offset + ConstantPoolCacheEntry::f1_offset()))); coleenp@4037: const int mirror_offset = in_bytes(Klass::java_mirror_offset()); coleenp@4037: __ movptr(obj, Address(obj, mirror_offset)); duke@435: } duke@435: } duke@435: duke@435: void TemplateTable::load_invoke_cp_cache_entry(int byte_no, duke@435: Register method, duke@435: Register itable_index, duke@435: Register flags, duke@435: bool is_invokevirtual, twisti@3969: bool is_invokevfinal, /*unused*/ jrose@1920: bool is_invokedynamic) { duke@435: // setup registers duke@435: const Register cache = rcx; duke@435: const Register index = rdx; duke@435: assert_different_registers(method, flags); duke@435: assert_different_registers(method, cache, index); duke@435: assert_different_registers(itable_index, flags); duke@435: assert_different_registers(itable_index, cache, index); duke@435: // determine constant pool cache field offsets twisti@3969: assert(is_invokevirtual == (byte_no == f2_byte), "is_invokevirtual flag redundant"); duke@435: const int method_offset = in_bytes( coleenp@4037: ConstantPoolCache::base_offset() + twisti@3969: ((byte_no == f2_byte) duke@435: ? ConstantPoolCacheEntry::f2_offset() twisti@3969: : ConstantPoolCacheEntry::f1_offset())); coleenp@4037: const int flags_offset = in_bytes(ConstantPoolCache::base_offset() + duke@435: ConstantPoolCacheEntry::flags_offset()); duke@435: // access constant pool cache fields coleenp@4037: const int index_offset = in_bytes(ConstantPoolCache::base_offset() + duke@435: ConstantPoolCacheEntry::f2_offset()); duke@435: twisti@4133: size_t index_size = (is_invokedynamic ? sizeof(u4) : sizeof(u2)); coleenp@4037: resolve_cache_and_index(byte_no, cache, index, index_size); jrose@1920: __ movptr(method, Address(cache, index, Address::times_ptr, method_offset)); coleenp@4037: duke@435: if (itable_index != noreg) { never@739: __ movptr(itable_index, Address(cache, index, Address::times_ptr, index_offset)); duke@435: } jrose@1920: __ movl(flags, Address(cache, index, Address::times_ptr, flags_offset)); duke@435: } duke@435: duke@435: duke@435: // The registers cache and index expected to be set before call. duke@435: // Correct values of the cache and index registers are preserved. duke@435: void TemplateTable::jvmti_post_field_access(Register cache, duke@435: Register index, duke@435: bool is_static, duke@435: bool has_tos) { duke@435: if (JvmtiExport::can_post_field_access()) { duke@435: // Check to see if a field access watch has been set before we take duke@435: // the time to call into the VM. duke@435: Label L1; duke@435: assert_different_registers(cache, index, rax); duke@435: __ mov32(rax, ExternalAddress((address) JvmtiExport::get_field_access_count_addr())); duke@435: __ testl(rax,rax); duke@435: __ jcc(Assembler::zero, L1); duke@435: duke@435: // cache entry pointer coleenp@4037: __ addptr(cache, in_bytes(ConstantPoolCache::base_offset())); duke@435: __ shll(index, LogBytesPerWord); never@739: __ addptr(cache, index); duke@435: if (is_static) { never@739: __ xorptr(rax, rax); // NULL object reference duke@435: } else { duke@435: __ pop(atos); // Get the object duke@435: __ verify_oop(rax); duke@435: __ push(atos); // Restore stack state duke@435: } duke@435: // rax,: object pointer or NULL duke@435: // cache: cache entry pointer duke@435: __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_access), duke@435: rax, cache); duke@435: __ get_cache_and_index_at_bcp(cache, index, 1); duke@435: __ bind(L1); duke@435: } duke@435: } duke@435: duke@435: void TemplateTable::pop_and_check_object(Register r) { duke@435: __ pop_ptr(r); duke@435: __ null_check(r); // for field access must check obj. duke@435: __ verify_oop(r); duke@435: } duke@435: duke@435: void TemplateTable::getfield_or_static(int byte_no, bool is_static) { duke@435: transition(vtos, vtos); duke@435: duke@435: const Register cache = rcx; duke@435: const Register index = rdx; duke@435: const Register obj = rcx; duke@435: const Register off = rbx; duke@435: const Register flags = rax; duke@435: coleenp@4037: resolve_cache_and_index(byte_no, cache, index, sizeof(u2)); duke@435: jvmti_post_field_access(cache, index, is_static, false); duke@435: load_field_cp_cache_entry(obj, cache, index, off, flags, is_static); duke@435: duke@435: if (!is_static) pop_and_check_object(obj); duke@435: duke@435: const Address lo(obj, off, Address::times_1, 0*wordSize); duke@435: const Address hi(obj, off, Address::times_1, 1*wordSize); duke@435: kevinw@8368: Label Done, notByte, notBool, notInt, notShort, notChar, notLong, notFloat, notObj, notDouble; duke@435: twisti@3969: __ shrl(flags, ConstantPoolCacheEntry::tos_state_shift); duke@435: assert(btos == 0, "change code, btos != 0"); duke@435: // btos twisti@3969: __ andptr(flags, ConstantPoolCacheEntry::tos_state_mask); duke@435: __ jcc(Assembler::notZero, notByte); duke@435: duke@435: __ load_signed_byte(rax, lo ); duke@435: __ push(btos); duke@435: // Rewrite bytecode to be faster duke@435: if (!is_static) { duke@435: patch_bytecode(Bytecodes::_fast_bgetfield, rcx, rbx); duke@435: } duke@435: __ jmp(Done); duke@435: duke@435: __ bind(notByte); kevinw@8368: kevinw@8368: __ cmpl(flags, ztos); kevinw@8368: __ jcc(Assembler::notEqual, notBool); kevinw@8368: kevinw@8368: // ztos (same code as btos) kevinw@8368: __ load_signed_byte(rax, lo); kevinw@8368: __ push(ztos); kevinw@8368: // Rewrite bytecode to be faster kevinw@8368: if (!is_static) { kevinw@8368: // use btos rewriting, no truncating to t/f bit is needed for getfield. kevinw@8368: patch_bytecode(Bytecodes::_fast_bgetfield, rcx, rbx); kevinw@8368: } kevinw@8368: __ jmp(Done); kevinw@8368: kevinw@8368: __ bind(notBool); kevinw@8368: duke@435: // itos duke@435: __ cmpl(flags, itos ); duke@435: __ jcc(Assembler::notEqual, notInt); duke@435: duke@435: __ movl(rax, lo ); duke@435: __ push(itos); duke@435: // Rewrite bytecode to be faster duke@435: if (!is_static) { duke@435: patch_bytecode(Bytecodes::_fast_igetfield, rcx, rbx); duke@435: } duke@435: __ jmp(Done); duke@435: duke@435: __ bind(notInt); duke@435: // atos duke@435: __ cmpl(flags, atos ); duke@435: __ jcc(Assembler::notEqual, notObj); duke@435: duke@435: __ movl(rax, lo ); duke@435: __ push(atos); duke@435: if (!is_static) { duke@435: patch_bytecode(Bytecodes::_fast_agetfield, rcx, rbx); duke@435: } duke@435: __ jmp(Done); duke@435: duke@435: __ bind(notObj); duke@435: // ctos duke@435: __ cmpl(flags, ctos ); duke@435: __ jcc(Assembler::notEqual, notChar); duke@435: jrose@1057: __ load_unsigned_short(rax, lo ); duke@435: __ push(ctos); duke@435: if (!is_static) { duke@435: patch_bytecode(Bytecodes::_fast_cgetfield, rcx, rbx); duke@435: } duke@435: __ jmp(Done); duke@435: duke@435: __ bind(notChar); duke@435: // stos duke@435: __ cmpl(flags, stos ); duke@435: __ jcc(Assembler::notEqual, notShort); duke@435: jrose@1057: __ load_signed_short(rax, lo ); duke@435: __ push(stos); duke@435: if (!is_static) { duke@435: patch_bytecode(Bytecodes::_fast_sgetfield, rcx, rbx); duke@435: } duke@435: __ jmp(Done); duke@435: duke@435: __ bind(notShort); duke@435: // ltos duke@435: __ cmpl(flags, ltos ); duke@435: __ jcc(Assembler::notEqual, notLong); duke@435: duke@435: // Generate code as if volatile. There just aren't enough registers to duke@435: // save that information and this code is faster than the test. duke@435: __ fild_d(lo); // Must load atomically never@739: __ subptr(rsp,2*wordSize); // Make space for store duke@435: __ fistp_d(Address(rsp,0)); never@739: __ pop(rax); never@739: __ pop(rdx); duke@435: duke@435: __ push(ltos); duke@435: // Don't rewrite to _fast_lgetfield for potential volatile case. duke@435: __ jmp(Done); duke@435: duke@435: __ bind(notLong); duke@435: // ftos duke@435: __ cmpl(flags, ftos ); duke@435: __ jcc(Assembler::notEqual, notFloat); duke@435: duke@435: __ fld_s(lo); duke@435: __ push(ftos); duke@435: if (!is_static) { duke@435: patch_bytecode(Bytecodes::_fast_fgetfield, rcx, rbx); duke@435: } duke@435: __ jmp(Done); duke@435: duke@435: __ bind(notFloat); duke@435: // dtos duke@435: __ cmpl(flags, dtos ); duke@435: __ jcc(Assembler::notEqual, notDouble); duke@435: duke@435: __ fld_d(lo); duke@435: __ push(dtos); duke@435: if (!is_static) { duke@435: patch_bytecode(Bytecodes::_fast_dgetfield, rcx, rbx); duke@435: } duke@435: __ jmpb(Done); duke@435: duke@435: __ bind(notDouble); duke@435: duke@435: __ stop("Bad state"); duke@435: duke@435: __ bind(Done); duke@435: // Doug Lea believes this is not needed with current Sparcs (TSO) and Intel (PSO). duke@435: // volatile_barrier( ); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::getfield(int byte_no) { duke@435: getfield_or_static(byte_no, false); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::getstatic(int byte_no) { duke@435: getfield_or_static(byte_no, true); duke@435: } duke@435: duke@435: // The registers cache and index expected to be set before call. duke@435: // The function may destroy various registers, just not the cache and index registers. duke@435: void TemplateTable::jvmti_post_field_mod(Register cache, Register index, bool is_static) { duke@435: coleenp@4037: ByteSize cp_base_offset = ConstantPoolCache::base_offset(); duke@435: duke@435: if (JvmtiExport::can_post_field_modification()) { duke@435: // Check to see if a field modification watch has been set before we take duke@435: // the time to call into the VM. duke@435: Label L1; duke@435: assert_different_registers(cache, index, rax); duke@435: __ mov32(rax, ExternalAddress((address)JvmtiExport::get_field_modification_count_addr())); duke@435: __ testl(rax, rax); duke@435: __ jcc(Assembler::zero, L1); duke@435: duke@435: // The cache and index registers have been already set. duke@435: // This allows to eliminate this call but the cache and index duke@435: // registers have to be correspondingly used after this line. duke@435: __ get_cache_and_index_at_bcp(rax, rdx, 1); duke@435: duke@435: if (is_static) { duke@435: // Life is simple. Null out the object pointer. never@739: __ xorptr(rbx, rbx); duke@435: } else { duke@435: // Life is harder. The stack holds the value on top, followed by the object. duke@435: // We don't know the size of the value, though; it could be one or two words duke@435: // depending on its type. As a result, we must find the type to determine where duke@435: // the object is. duke@435: Label two_word, valsize_known; never@739: __ movl(rcx, Address(rax, rdx, Address::times_ptr, in_bytes(cp_base_offset + duke@435: ConstantPoolCacheEntry::flags_offset()))); never@739: __ mov(rbx, rsp); twisti@3969: __ shrl(rcx, ConstantPoolCacheEntry::tos_state_shift); twisti@3969: // Make sure we don't need to mask rcx after the above shift twisti@3969: ConstantPoolCacheEntry::verify_tos_state_shift(); duke@435: __ cmpl(rcx, ltos); duke@435: __ jccb(Assembler::equal, two_word); duke@435: __ cmpl(rcx, dtos); duke@435: __ jccb(Assembler::equal, two_word); never@739: __ addptr(rbx, Interpreter::expr_offset_in_bytes(1)); // one word jvalue (not ltos, dtos) duke@435: __ jmpb(valsize_known); duke@435: duke@435: __ bind(two_word); never@739: __ addptr(rbx, Interpreter::expr_offset_in_bytes(2)); // two words jvalue duke@435: duke@435: __ bind(valsize_known); duke@435: // setup object pointer never@739: __ movptr(rbx, Address(rbx, 0)); duke@435: } duke@435: // cache entry pointer never@739: __ addptr(rax, in_bytes(cp_base_offset)); duke@435: __ shll(rdx, LogBytesPerWord); never@739: __ addptr(rax, rdx); duke@435: // object (tos) never@739: __ mov(rcx, rsp); duke@435: // rbx,: object pointer set up above (NULL if static) duke@435: // rax,: cache entry pointer duke@435: // rcx: jvalue object on the stack duke@435: __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_modification), duke@435: rbx, rax, rcx); duke@435: __ get_cache_and_index_at_bcp(cache, index, 1); duke@435: __ bind(L1); duke@435: } duke@435: } duke@435: duke@435: duke@435: void TemplateTable::putfield_or_static(int byte_no, bool is_static) { duke@435: transition(vtos, vtos); duke@435: duke@435: const Register cache = rcx; duke@435: const Register index = rdx; duke@435: const Register obj = rcx; duke@435: const Register off = rbx; duke@435: const Register flags = rax; duke@435: coleenp@4037: resolve_cache_and_index(byte_no, cache, index, sizeof(u2)); duke@435: jvmti_post_field_mod(cache, index, is_static); duke@435: load_field_cp_cache_entry(obj, cache, index, off, flags, is_static); duke@435: duke@435: // Doug Lea believes this is not needed with current Sparcs (TSO) and Intel (PSO). duke@435: // volatile_barrier( ); duke@435: duke@435: Label notVolatile, Done; duke@435: __ movl(rdx, flags); twisti@3969: __ shrl(rdx, ConstantPoolCacheEntry::is_volatile_shift); duke@435: __ andl(rdx, 0x1); duke@435: duke@435: // field addresses duke@435: const Address lo(obj, off, Address::times_1, 0*wordSize); duke@435: const Address hi(obj, off, Address::times_1, 1*wordSize); duke@435: kevinw@8368: Label notByte, notBool, notInt, notShort, notChar, notLong, notFloat, notObj, notDouble; duke@435: twisti@3969: __ shrl(flags, ConstantPoolCacheEntry::tos_state_shift); duke@435: assert(btos == 0, "change code, btos != 0"); twisti@3969: __ andl(flags, ConstantPoolCacheEntry::tos_state_mask); duke@435: __ jcc(Assembler::notZero, notByte); duke@435: twisti@3050: // btos twisti@3050: { twisti@3050: __ pop(btos); twisti@3050: if (!is_static) pop_and_check_object(obj); twisti@3050: __ movb(lo, rax); twisti@3050: if (!is_static) { twisti@3050: patch_bytecode(Bytecodes::_fast_bputfield, rcx, rbx, true, byte_no); twisti@3050: } twisti@3050: __ jmp(Done); duke@435: } duke@435: duke@435: __ bind(notByte); kevinw@8368: __ cmpl(flags, ztos); kevinw@8368: __ jcc(Assembler::notEqual, notBool); kevinw@8368: kevinw@8368: // ztos kevinw@8368: { kevinw@8368: __ pop(ztos); kevinw@8368: if (!is_static) pop_and_check_object(obj); kevinw@8368: __ andl(rax, 0x1); kevinw@8368: __ movb(lo, rax); kevinw@8368: if (!is_static) { kevinw@8368: patch_bytecode(Bytecodes::_fast_zputfield, rcx, rbx, true, byte_no); kevinw@8368: } kevinw@8368: __ jmp(Done); kevinw@8368: } kevinw@8368: kevinw@8368: __ bind(notBool); twisti@3050: __ cmpl(flags, itos); twisti@3050: __ jcc(Assembler::notEqual, notInt); twisti@3050: duke@435: // itos twisti@3050: { twisti@3050: __ pop(itos); twisti@3050: if (!is_static) pop_and_check_object(obj); twisti@3050: __ movl(lo, rax); twisti@3050: if (!is_static) { twisti@3050: patch_bytecode(Bytecodes::_fast_iputfield, rcx, rbx, true, byte_no); twisti@3050: } twisti@3050: __ jmp(Done); duke@435: } duke@435: duke@435: __ bind(notInt); twisti@3050: __ cmpl(flags, atos); twisti@3050: __ jcc(Assembler::notEqual, notObj); twisti@3050: duke@435: // atos twisti@3050: { twisti@3050: __ pop(atos); twisti@3050: if (!is_static) pop_and_check_object(obj); twisti@3050: do_oop_store(_masm, lo, rax, _bs->kind(), false); twisti@3050: if (!is_static) { twisti@3050: patch_bytecode(Bytecodes::_fast_aputfield, rcx, rbx, true, byte_no); twisti@3050: } twisti@3050: __ jmp(Done); duke@435: } ysr@777: duke@435: __ bind(notObj); twisti@3050: __ cmpl(flags, ctos); twisti@3050: __ jcc(Assembler::notEqual, notChar); twisti@3050: duke@435: // ctos twisti@3050: { twisti@3050: __ pop(ctos); twisti@3050: if (!is_static) pop_and_check_object(obj); twisti@3050: __ movw(lo, rax); twisti@3050: if (!is_static) { twisti@3050: patch_bytecode(Bytecodes::_fast_cputfield, rcx, rbx, true, byte_no); twisti@3050: } twisti@3050: __ jmp(Done); duke@435: } duke@435: duke@435: __ bind(notChar); twisti@3050: __ cmpl(flags, stos); twisti@3050: __ jcc(Assembler::notEqual, notShort); twisti@3050: duke@435: // stos twisti@3050: { twisti@3050: __ pop(stos); twisti@3050: if (!is_static) pop_and_check_object(obj); twisti@3050: __ movw(lo, rax); twisti@3050: if (!is_static) { twisti@3050: patch_bytecode(Bytecodes::_fast_sputfield, rcx, rbx, true, byte_no); twisti@3050: } twisti@3050: __ jmp(Done); duke@435: } duke@435: duke@435: __ bind(notShort); twisti@3050: __ cmpl(flags, ltos); twisti@3050: __ jcc(Assembler::notEqual, notLong); twisti@3050: duke@435: // ltos twisti@3050: { twisti@3050: Label notVolatileLong; twisti@3050: __ testl(rdx, rdx); twisti@3050: __ jcc(Assembler::zero, notVolatileLong); twisti@3050: twisti@3050: __ pop(ltos); // overwrites rdx, do this after testing volatile. twisti@3050: if (!is_static) pop_and_check_object(obj); twisti@3050: twisti@3050: // Replace with real volatile test twisti@3050: __ push(rdx); twisti@3050: __ push(rax); // Must update atomically with FIST twisti@3050: __ fild_d(Address(rsp,0)); // So load into FPU register twisti@3050: __ fistp_d(lo); // and put into memory atomically twisti@3050: __ addptr(rsp, 2*wordSize); twisti@3050: // volatile_barrier(); twisti@3050: volatile_barrier(Assembler::Membar_mask_bits(Assembler::StoreLoad | twisti@3050: Assembler::StoreStore)); twisti@3050: // Don't rewrite volatile version twisti@3050: __ jmp(notVolatile); twisti@3050: twisti@3050: __ bind(notVolatileLong); twisti@3050: twisti@3050: __ pop(ltos); // overwrites rdx twisti@3050: if (!is_static) pop_and_check_object(obj); twisti@3050: NOT_LP64(__ movptr(hi, rdx)); twisti@3050: __ movptr(lo, rax); twisti@3050: if (!is_static) { twisti@3050: patch_bytecode(Bytecodes::_fast_lputfield, rcx, rbx, true, byte_no); twisti@3050: } twisti@3050: __ jmp(notVolatile); duke@435: } duke@435: duke@435: __ bind(notLong); twisti@3050: __ cmpl(flags, ftos); twisti@3050: __ jcc(Assembler::notEqual, notFloat); twisti@3050: duke@435: // ftos twisti@3050: { twisti@3050: __ pop(ftos); twisti@3050: if (!is_static) pop_and_check_object(obj); twisti@3050: __ fstp_s(lo); twisti@3050: if (!is_static) { twisti@3050: patch_bytecode(Bytecodes::_fast_fputfield, rcx, rbx, true, byte_no); twisti@3050: } twisti@3050: __ jmp(Done); duke@435: } duke@435: duke@435: __ bind(notFloat); twisti@3050: #ifdef ASSERT twisti@3050: __ cmpl(flags, dtos); twisti@3050: __ jcc(Assembler::notEqual, notDouble); twisti@3050: #endif twisti@3050: duke@435: // dtos twisti@3050: { twisti@3050: __ pop(dtos); twisti@3050: if (!is_static) pop_and_check_object(obj); twisti@3050: __ fstp_d(lo); twisti@3050: if (!is_static) { twisti@3050: patch_bytecode(Bytecodes::_fast_dputfield, rcx, rbx, true, byte_no); twisti@3050: } twisti@3050: __ jmp(Done); duke@435: } twisti@3050: twisti@3050: #ifdef ASSERT duke@435: __ bind(notDouble); duke@435: __ stop("Bad state"); twisti@3050: #endif duke@435: duke@435: __ bind(Done); duke@435: duke@435: // Check for volatile store duke@435: __ testl(rdx, rdx); duke@435: __ jcc(Assembler::zero, notVolatile); never@739: volatile_barrier(Assembler::Membar_mask_bits(Assembler::StoreLoad | never@739: Assembler::StoreStore)); duke@435: __ bind(notVolatile); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::putfield(int byte_no) { duke@435: putfield_or_static(byte_no, false); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::putstatic(int byte_no) { duke@435: putfield_or_static(byte_no, true); duke@435: } duke@435: duke@435: void TemplateTable::jvmti_post_fast_field_mod() { duke@435: if (JvmtiExport::can_post_field_modification()) { duke@435: // Check to see if a field modification watch has been set before we take duke@435: // the time to call into the VM. duke@435: Label L2; coleenp@3698: __ mov32(rcx, ExternalAddress((address)JvmtiExport::get_field_modification_count_addr())); coleenp@3698: __ testl(rcx,rcx); coleenp@3698: __ jcc(Assembler::zero, L2); coleenp@3698: __ pop_ptr(rbx); // copy the object pointer from tos coleenp@3698: __ verify_oop(rbx); coleenp@3698: __ push_ptr(rbx); // put the object pointer back on tos coleenp@3698: coleenp@3698: // Save tos values before call_VM() clobbers them. Since we have coleenp@3698: // to do it for every data type, we use the saved values as the coleenp@3698: // jvalue object. coleenp@3698: switch (bytecode()) { // load values into the jvalue object coleenp@3698: case Bytecodes::_fast_aputfield: __ push_ptr(rax); break; coleenp@3698: case Bytecodes::_fast_bputfield: // fall through kevinw@8368: case Bytecodes::_fast_zputfield: // fall through coleenp@3698: case Bytecodes::_fast_sputfield: // fall through coleenp@3698: case Bytecodes::_fast_cputfield: // fall through coleenp@3698: case Bytecodes::_fast_iputfield: __ push_i(rax); break; coleenp@3698: case Bytecodes::_fast_dputfield: __ push_d(); break; coleenp@3698: case Bytecodes::_fast_fputfield: __ push_f(); break; coleenp@3698: case Bytecodes::_fast_lputfield: __ push_l(rax); break; coleenp@3698: coleenp@3698: default: coleenp@3698: ShouldNotReachHere(); coleenp@3698: } coleenp@3698: __ mov(rcx, rsp); // points to jvalue on the stack coleenp@3698: // access constant pool cache entry coleenp@3698: __ get_cache_entry_pointer_at_bcp(rax, rdx, 1); coleenp@3698: __ verify_oop(rbx); coleenp@3698: // rbx,: object pointer copied above coleenp@3698: // rax,: cache entry pointer coleenp@3698: // rcx: jvalue object on the stack coleenp@3698: __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_modification), rbx, rax, rcx); coleenp@3698: coleenp@3698: switch (bytecode()) { // restore tos values coleenp@3698: case Bytecodes::_fast_aputfield: __ pop_ptr(rax); break; coleenp@3698: case Bytecodes::_fast_bputfield: // fall through kevinw@8368: case Bytecodes::_fast_zputfield: // fall through coleenp@3698: case Bytecodes::_fast_sputfield: // fall through coleenp@3698: case Bytecodes::_fast_cputfield: // fall through coleenp@3698: case Bytecodes::_fast_iputfield: __ pop_i(rax); break; coleenp@3698: case Bytecodes::_fast_dputfield: __ pop_d(); break; coleenp@3698: case Bytecodes::_fast_fputfield: __ pop_f(); break; coleenp@3698: case Bytecodes::_fast_lputfield: __ pop_l(rax); break; coleenp@3698: } coleenp@3698: __ bind(L2); duke@435: } duke@435: } duke@435: duke@435: void TemplateTable::fast_storefield(TosState state) { duke@435: transition(state, vtos); duke@435: coleenp@4037: ByteSize base = ConstantPoolCache::base_offset(); duke@435: duke@435: jvmti_post_fast_field_mod(); duke@435: duke@435: // access constant pool cache duke@435: __ get_cache_and_index_at_bcp(rcx, rbx, 1); duke@435: duke@435: // test for volatile with rdx but rdx is tos register for lputfield. never@739: if (bytecode() == Bytecodes::_fast_lputfield) __ push(rdx); never@739: __ movl(rdx, Address(rcx, rbx, Address::times_ptr, in_bytes(base + duke@435: ConstantPoolCacheEntry::flags_offset()))); duke@435: duke@435: // replace index with field offset from cache entry never@739: __ movptr(rbx, Address(rcx, rbx, Address::times_ptr, in_bytes(base + ConstantPoolCacheEntry::f2_offset()))); duke@435: duke@435: // Doug Lea believes this is not needed with current Sparcs (TSO) and Intel (PSO). duke@435: // volatile_barrier( ); duke@435: duke@435: Label notVolatile, Done; twisti@3969: __ shrl(rdx, ConstantPoolCacheEntry::is_volatile_shift); duke@435: __ andl(rdx, 0x1); duke@435: // Check for volatile store duke@435: __ testl(rdx, rdx); duke@435: __ jcc(Assembler::zero, notVolatile); duke@435: never@739: if (bytecode() == Bytecodes::_fast_lputfield) __ pop(rdx); duke@435: duke@435: // Get object from stack duke@435: pop_and_check_object(rcx); duke@435: duke@435: // field addresses duke@435: const Address lo(rcx, rbx, Address::times_1, 0*wordSize); duke@435: const Address hi(rcx, rbx, Address::times_1, 1*wordSize); duke@435: duke@435: // access field duke@435: switch (bytecode()) { kevinw@8368: case Bytecodes::_fast_zputfield: __ andl(rax, 0x1); // boolean is true if LSB is 1 kevinw@8368: // fall through to bputfield duke@435: case Bytecodes::_fast_bputfield: __ movb(lo, rax); break; duke@435: case Bytecodes::_fast_sputfield: // fall through duke@435: case Bytecodes::_fast_cputfield: __ movw(lo, rax); break; duke@435: case Bytecodes::_fast_iputfield: __ movl(lo, rax); break; never@739: case Bytecodes::_fast_lputfield: never@739: NOT_LP64(__ movptr(hi, rdx)); never@739: __ movptr(lo, rax); never@739: break; duke@435: case Bytecodes::_fast_fputfield: __ fstp_s(lo); break; duke@435: case Bytecodes::_fast_dputfield: __ fstp_d(lo); break; ysr@777: case Bytecodes::_fast_aputfield: { ysr@777: do_oop_store(_masm, lo, rax, _bs->kind(), false); ysr@777: break; ysr@777: } duke@435: default: duke@435: ShouldNotReachHere(); duke@435: } duke@435: duke@435: Label done; never@739: volatile_barrier(Assembler::Membar_mask_bits(Assembler::StoreLoad | never@739: Assembler::StoreStore)); ysr@777: // Barriers are so large that short branch doesn't reach! ysr@777: __ jmp(done); duke@435: duke@435: // Same code as above, but don't need rdx to test for volatile. duke@435: __ bind(notVolatile); duke@435: never@739: if (bytecode() == Bytecodes::_fast_lputfield) __ pop(rdx); duke@435: duke@435: // Get object from stack duke@435: pop_and_check_object(rcx); duke@435: duke@435: // access field duke@435: switch (bytecode()) { kevinw@8368: case Bytecodes::_fast_zputfield: __ andl(rax, 0x1); // boolean is true if LSB is 1 kevinw@8368: // fall through to bputfield duke@435: case Bytecodes::_fast_bputfield: __ movb(lo, rax); break; duke@435: case Bytecodes::_fast_sputfield: // fall through duke@435: case Bytecodes::_fast_cputfield: __ movw(lo, rax); break; duke@435: case Bytecodes::_fast_iputfield: __ movl(lo, rax); break; never@739: case Bytecodes::_fast_lputfield: never@739: NOT_LP64(__ movptr(hi, rdx)); never@739: __ movptr(lo, rax); never@739: break; duke@435: case Bytecodes::_fast_fputfield: __ fstp_s(lo); break; duke@435: case Bytecodes::_fast_dputfield: __ fstp_d(lo); break; ysr@777: case Bytecodes::_fast_aputfield: { ysr@777: do_oop_store(_masm, lo, rax, _bs->kind(), false); ysr@777: break; ysr@777: } duke@435: default: duke@435: ShouldNotReachHere(); duke@435: } duke@435: __ bind(done); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::fast_accessfield(TosState state) { duke@435: transition(atos, state); duke@435: duke@435: // do the JVMTI work here to avoid disturbing the register state below duke@435: if (JvmtiExport::can_post_field_access()) { duke@435: // Check to see if a field access watch has been set before we take duke@435: // the time to call into the VM. duke@435: Label L1; duke@435: __ mov32(rcx, ExternalAddress((address) JvmtiExport::get_field_access_count_addr())); duke@435: __ testl(rcx,rcx); duke@435: __ jcc(Assembler::zero, L1); duke@435: // access constant pool cache entry duke@435: __ get_cache_entry_pointer_at_bcp(rcx, rdx, 1); duke@435: __ push_ptr(rax); // save object pointer before call_VM() clobbers it duke@435: __ verify_oop(rax); duke@435: // rax,: object pointer copied above duke@435: // rcx: cache entry pointer duke@435: __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_access), rax, rcx); duke@435: __ pop_ptr(rax); // restore object pointer duke@435: __ bind(L1); duke@435: } duke@435: duke@435: // access constant pool cache duke@435: __ get_cache_and_index_at_bcp(rcx, rbx, 1); duke@435: // replace index with field offset from cache entry never@739: __ movptr(rbx, Address(rcx, never@739: rbx, never@739: Address::times_ptr, coleenp@4037: in_bytes(ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::f2_offset()))); duke@435: duke@435: duke@435: // rax,: object duke@435: __ verify_oop(rax); duke@435: __ null_check(rax); duke@435: // field addresses duke@435: const Address lo = Address(rax, rbx, Address::times_1, 0*wordSize); duke@435: const Address hi = Address(rax, rbx, Address::times_1, 1*wordSize); duke@435: duke@435: // access field duke@435: switch (bytecode()) { never@739: case Bytecodes::_fast_bgetfield: __ movsbl(rax, lo ); break; jrose@1057: case Bytecodes::_fast_sgetfield: __ load_signed_short(rax, lo ); break; jrose@1057: case Bytecodes::_fast_cgetfield: __ load_unsigned_short(rax, lo ); break; duke@435: case Bytecodes::_fast_igetfield: __ movl(rax, lo); break; duke@435: case Bytecodes::_fast_lgetfield: __ stop("should not be rewritten"); break; duke@435: case Bytecodes::_fast_fgetfield: __ fld_s(lo); break; duke@435: case Bytecodes::_fast_dgetfield: __ fld_d(lo); break; never@739: case Bytecodes::_fast_agetfield: __ movptr(rax, lo); __ verify_oop(rax); break; duke@435: default: duke@435: ShouldNotReachHere(); duke@435: } duke@435: duke@435: // Doug Lea believes this is not needed with current Sparcs(TSO) and Intel(PSO) duke@435: // volatile_barrier( ); duke@435: } duke@435: duke@435: void TemplateTable::fast_xaccess(TosState state) { duke@435: transition(vtos, state); duke@435: // get receiver never@739: __ movptr(rax, aaddress(0)); duke@435: // access constant pool cache duke@435: __ get_cache_and_index_at_bcp(rcx, rdx, 2); never@739: __ movptr(rbx, Address(rcx, never@739: rdx, never@739: Address::times_ptr, coleenp@4037: in_bytes(ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::f2_offset()))); duke@435: // make sure exception is reported in correct bcp range (getfield is next instruction) duke@435: __ increment(rsi); duke@435: __ null_check(rax); duke@435: const Address lo = Address(rax, rbx, Address::times_1, 0*wordSize); duke@435: if (state == itos) { duke@435: __ movl(rax, lo); duke@435: } else if (state == atos) { never@739: __ movptr(rax, lo); duke@435: __ verify_oop(rax); duke@435: } else if (state == ftos) { duke@435: __ fld_s(lo); duke@435: } else { duke@435: ShouldNotReachHere(); duke@435: } duke@435: __ decrement(rsi); duke@435: } duke@435: duke@435: duke@435: duke@435: //---------------------------------------------------------------------------------------------------- duke@435: // Calls duke@435: duke@435: void TemplateTable::count_calls(Register method, Register temp) { duke@435: // implemented elsewhere duke@435: ShouldNotReachHere(); duke@435: } duke@435: duke@435: twisti@3969: void TemplateTable::prepare_invoke(int byte_no, twisti@3969: Register method, // linked method (or i-klass) twisti@3969: Register index, // itable index, MethodType, etc. twisti@3969: Register recv, // if caller wants to see it twisti@3969: Register flags // if caller wants to test it twisti@3969: ) { duke@435: // determine flags twisti@3969: const Bytecodes::Code code = bytecode(); duke@435: const bool is_invokeinterface = code == Bytecodes::_invokeinterface; jrose@1161: const bool is_invokedynamic = code == Bytecodes::_invokedynamic; twisti@3969: const bool is_invokehandle = code == Bytecodes::_invokehandle; duke@435: const bool is_invokevirtual = code == Bytecodes::_invokevirtual; duke@435: const bool is_invokespecial = code == Bytecodes::_invokespecial; twisti@3969: const bool load_receiver = (recv != noreg); twisti@3969: const bool save_flags = (flags != noreg); twisti@3969: assert(load_receiver == (code != Bytecodes::_invokestatic && code != Bytecodes::_invokedynamic), ""); twisti@3969: assert(save_flags == (is_invokeinterface || is_invokevirtual), "need flags for vfinal"); twisti@3969: assert(flags == noreg || flags == rdx, ""); twisti@3969: assert(recv == noreg || recv == rcx, ""); twisti@3969: duke@435: // setup registers & access constant pool cache twisti@3969: if (recv == noreg) recv = rcx; twisti@3969: if (flags == noreg) flags = rdx; duke@435: assert_different_registers(method, index, recv, flags); duke@435: duke@435: // save 'interpreter return address' duke@435: __ save_bcp(); duke@435: jrose@1920: load_invoke_cp_cache_entry(byte_no, method, index, flags, is_invokevirtual, false, is_invokedynamic); duke@435: twisti@3969: // maybe push appendix to arguments (just before return address) twisti@3969: if (is_invokedynamic || is_invokehandle) { twisti@3969: Label L_no_push; twisti@3969: __ testl(flags, (1 << ConstantPoolCacheEntry::has_appendix_shift)); twisti@3969: __ jccb(Assembler::zero, L_no_push); twisti@3969: // Push the appendix as a trailing parameter. twisti@3969: // This must be done before we get the receiver, twisti@3969: // since the parameter_size includes it. coleenp@4037: __ push(rbx); coleenp@4037: __ mov(rbx, index); twisti@4133: assert(ConstantPoolCacheEntry::_indy_resolved_references_appendix_offset == 0, "appendix expected at index+0"); coleenp@4037: __ load_resolved_reference_at_index(index, rbx); coleenp@4037: __ pop(rbx); twisti@3969: __ push(index); // push appendix (MethodType, CallSite, etc.) twisti@3969: __ bind(L_no_push); twisti@3969: } twisti@3969: duke@435: // load receiver if needed (note: no return address pushed yet) duke@435: if (load_receiver) { duke@435: __ movl(recv, flags); twisti@3969: __ andl(recv, ConstantPoolCacheEntry::parameter_size_mask); twisti@3969: const int no_return_pc_pushed_yet = -1; // argument slot correction before we push return address twisti@3969: const int receiver_is_at_end = -1; // back off one slot to get receiver twisti@3969: Address recv_addr = __ argument_address(recv, no_return_pc_pushed_yet + receiver_is_at_end); twisti@1739: __ movptr(recv, recv_addr); twisti@1739: __ verify_oop(recv); duke@435: } duke@435: duke@435: if (save_flags) { never@739: __ mov(rsi, flags); duke@435: } duke@435: duke@435: // compute return type twisti@3969: __ shrl(flags, ConstantPoolCacheEntry::tos_state_shift); twisti@3969: // Make sure we don't need to mask flags after the above shift twisti@3969: ConstantPoolCacheEntry::verify_tos_state_shift(); duke@435: // load return address never@739: { twisti@6039: const address table_addr = (address) Interpreter::invoke_return_entry_table_for(code); jrose@1161: ExternalAddress table(table_addr); never@739: __ movptr(flags, ArrayAddress(table, Address(noreg, flags, Address::times_ptr))); duke@435: } duke@435: duke@435: // push return address never@739: __ push(flags); duke@435: twisti@3969: // Restore flags value from the constant pool cache, and restore rsi duke@435: // for later null checks. rsi is the bytecode pointer duke@435: if (save_flags) { never@739: __ mov(flags, rsi); duke@435: __ restore_bcp(); duke@435: } duke@435: } duke@435: duke@435: twisti@3969: void TemplateTable::invokevirtual_helper(Register index, twisti@3969: Register recv, twisti@3969: Register flags) { duke@435: // Uses temporary registers rax, rdx duke@435: assert_different_registers(index, recv, rax, rdx); twisti@3969: assert(index == rbx, ""); twisti@3969: assert(recv == rcx, ""); duke@435: duke@435: // Test for an invoke of a final method duke@435: Label notFinal; duke@435: __ movl(rax, flags); twisti@3969: __ andl(rax, (1 << ConstantPoolCacheEntry::is_vfinal_shift)); duke@435: __ jcc(Assembler::zero, notFinal); duke@435: twisti@3969: const Register method = index; // method must be rbx twisti@3969: assert(method == rbx, coleenp@4037: "Method* must be rbx for interpreter calling convention"); duke@435: duke@435: // do the call - the index is actually the method to call coleenp@4037: // that is, f2 is a vtable index if !is_vfinal, else f2 is a Method* duke@435: duke@435: // It's final, need a null check here! duke@435: __ null_check(recv); duke@435: duke@435: // profile this call duke@435: __ profile_final_call(rax); roland@5914: __ profile_arguments_type(rax, method, rsi, true); duke@435: duke@435: __ jump_from_interpreted(method, rax); duke@435: duke@435: __ bind(notFinal); duke@435: duke@435: // get receiver klass duke@435: __ null_check(recv, oopDesc::klass_offset_in_bytes()); twisti@2807: __ load_klass(rax, recv); duke@435: duke@435: // profile this call duke@435: __ profile_virtual_call(rax, rdi, rdx); duke@435: coleenp@4037: // get target Method* & entry point twisti@3969: __ lookup_virtual_method(rax, index, method); roland@5914: __ profile_arguments_type(rdx, method, rsi, true); duke@435: __ jump_from_interpreted(method, rdx); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::invokevirtual(int byte_no) { duke@435: transition(vtos, vtos); jrose@1920: assert(byte_no == f2_byte, "use this argument"); twisti@3969: prepare_invoke(byte_no, twisti@3969: rbx, // method or vtable index twisti@3969: noreg, // unused itable index twisti@3969: rcx, rdx); // recv, flags twisti@3969: twisti@3969: // rbx: index duke@435: // rcx: receiver duke@435: // rdx: flags duke@435: duke@435: invokevirtual_helper(rbx, rcx, rdx); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::invokespecial(int byte_no) { duke@435: transition(vtos, vtos); jrose@1920: assert(byte_no == f1_byte, "use this argument"); coleenp@4037: prepare_invoke(byte_no, rbx, noreg, // get f1 Method* twisti@3969: rcx); // get receiver also for null check twisti@3969: __ verify_oop(rcx); twisti@3969: __ null_check(rcx); duke@435: // do the call duke@435: __ profile_call(rax); roland@5914: __ profile_arguments_type(rax, rbx, rsi, false); duke@435: __ jump_from_interpreted(rbx, rax); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::invokestatic(int byte_no) { duke@435: transition(vtos, vtos); jrose@1920: assert(byte_no == f1_byte, "use this argument"); coleenp@4037: prepare_invoke(byte_no, rbx); // get f1 Method* duke@435: // do the call duke@435: __ profile_call(rax); roland@5914: __ profile_arguments_type(rax, rbx, rsi, false); duke@435: __ jump_from_interpreted(rbx, rax); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::fast_invokevfinal(int byte_no) { duke@435: transition(vtos, vtos); jrose@1920: assert(byte_no == f2_byte, "use this argument"); duke@435: __ stop("fast_invokevfinal not used on x86"); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::invokeinterface(int byte_no) { duke@435: transition(vtos, vtos); jrose@1920: assert(byte_no == f1_byte, "use this argument"); dbuck@8997: prepare_invoke(byte_no, rax, rbx, // get f1 Klass*, f2 Method* twisti@3969: rcx, rdx); // recv, flags twisti@3969: dbuck@8997: // rax: reference klass (from f1) dbuck@8997: // rbx: method (from f2) duke@435: // rcx: receiver duke@435: // rdx: flags duke@435: duke@435: // Special case of invokeinterface called for virtual method of duke@435: // java.lang.Object. See cpCacheOop.cpp for details. duke@435: // This code isn't produced by javac, but could be produced by duke@435: // another compliant java compiler. duke@435: Label notMethod; duke@435: __ movl(rdi, rdx); twisti@3969: __ andl(rdi, (1 << ConstantPoolCacheEntry::is_forced_virtual_shift)); duke@435: __ jcc(Assembler::zero, notMethod); duke@435: duke@435: invokevirtual_helper(rbx, rcx, rdx); duke@435: __ bind(notMethod); duke@435: duke@435: // Get receiver klass into rdx - also a null check duke@435: __ restore_locals(); // restore rdi twisti@3969: __ null_check(rcx, oopDesc::klass_offset_in_bytes()); twisti@2807: __ load_klass(rdx, rcx); duke@435: dbuck@8997: Label no_such_interface, no_such_method; dbuck@8997: dbuck@8997: // Receiver subtype check against REFC. dbuck@8997: // Superklass in rax. Subklass in rdx. Blows rcx, rdi. dbuck@8997: __ lookup_interface_method(// inputs: rec. class, interface, itable index dbuck@8997: rdx, rax, noreg, dbuck@8997: // outputs: scan temp. reg, scan temp. reg dbuck@8997: rsi, rdi, dbuck@8997: no_such_interface, dbuck@8997: /*return_method=*/false); dbuck@8997: dbuck@8997: duke@435: // profile this call dbuck@8997: __ restore_bcp(); // rbcp was destroyed by receiver type check duke@435: __ profile_virtual_call(rdx, rsi, rdi); duke@435: dbuck@8997: // Get declaring interface class from method, and itable index dbuck@8997: __ movptr(rax, Address(rbx, Method::const_offset())); dbuck@8997: __ movptr(rax, Address(rax, ConstMethod::constants_offset())); dbuck@8997: __ movptr(rax, Address(rax, ConstantPool::pool_holder_offset_in_bytes())); dbuck@8997: __ movl(rbx, Address(rbx, Method::itable_index_offset())); dbuck@8997: __ subl(rbx, Method::itable_index_max); dbuck@8997: __ negl(rbx); jrose@1058: jrose@1058: __ lookup_interface_method(// inputs: rec. class, interface, itable index jrose@1058: rdx, rax, rbx, jrose@1058: // outputs: method, scan temp. reg jrose@1058: rbx, rsi, jrose@1058: no_such_interface); jrose@1058: coleenp@4037: // rbx: Method* to call jrose@1058: // rcx: receiver jrose@1058: // Check for abstract method error jrose@1058: // Note: This should be done more efficiently via a throw_abstract_method_error jrose@1058: // interpreter entry point and a conditional jump to it in case of a null jrose@1058: // method. jrose@1058: __ testptr(rbx, rbx); jrose@1058: __ jcc(Assembler::zero, no_such_method); jrose@1058: roland@5914: __ profile_arguments_type(rdx, rbx, rsi, true); roland@5914: jrose@1058: // do the call jrose@1058: // rcx: receiver coleenp@4037: // rbx,: Method* jrose@1058: __ jump_from_interpreted(rbx, rdx); jrose@1058: __ should_not_reach_here(); jrose@1058: jrose@1058: // exception handling code follows... jrose@1058: // note: must restore interpreter registers to canonical jrose@1058: // state for exception handling to work correctly! jrose@1058: jrose@1058: __ bind(no_such_method); duke@435: // throw exception jrose@1058: __ pop(rbx); // pop return address (pushed by prepare_invoke) jrose@1058: __ restore_bcp(); // rsi must be correct for exception handler (was destroyed) jrose@1058: __ restore_locals(); // make sure locals pointer is correct as well (was destroyed) jrose@1058: __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_AbstractMethodError)); jrose@1058: // the call_VM checks for exception, so we should never return here. jrose@1058: __ should_not_reach_here(); jrose@1058: jrose@1058: __ bind(no_such_interface); jrose@1058: // throw exception never@739: __ pop(rbx); // pop return address (pushed by prepare_invoke) duke@435: __ restore_bcp(); // rsi must be correct for exception handler (was destroyed) duke@435: __ restore_locals(); // make sure locals pointer is correct as well (was destroyed) duke@435: __ call_VM(noreg, CAST_FROM_FN_PTR(address, duke@435: InterpreterRuntime::throw_IncompatibleClassChangeError)); duke@435: // the call_VM checks for exception, so we should never return here. duke@435: __ should_not_reach_here(); duke@435: } duke@435: twisti@3969: void TemplateTable::invokehandle(int byte_no) { twisti@3969: transition(vtos, vtos); coleenp@4037: assert(byte_no == f1_byte, "use this argument"); twisti@4133: const Register rbx_method = rbx; twisti@4133: const Register rax_mtype = rax; twisti@3969: const Register rcx_recv = rcx; twisti@3969: const Register rdx_flags = rdx; twisti@3969: twisti@3969: if (!EnableInvokeDynamic) { twisti@3969: // rewriter does not generate this bytecode twisti@3969: __ should_not_reach_here(); twisti@3969: return; twisti@3969: } twisti@3969: twisti@4133: prepare_invoke(byte_no, rbx_method, rax_mtype, rcx_recv); coleenp@4052: __ verify_method_ptr(rbx_method); twisti@3969: __ verify_oop(rcx_recv); twisti@3969: __ null_check(rcx_recv); twisti@3969: twisti@4133: // rax: MethodType object (from cpool->resolved_references[f1], if necessary) twisti@4133: // rbx: MH.invokeExact_MT method (from f2) twisti@4133: twisti@3969: // Note: rax_mtype is already pushed (if necessary) by prepare_invoke twisti@3969: twisti@3969: // FIXME: profile the LambdaForm also twisti@3969: __ profile_final_call(rax); roland@5914: __ profile_arguments_type(rdx, rbx_method, rsi, true); twisti@3969: twisti@3969: __ jump_from_interpreted(rbx_method, rdx); twisti@3969: } twisti@3969: twisti@3969: jrose@1161: void TemplateTable::invokedynamic(int byte_no) { jrose@1161: transition(vtos, vtos); coleenp@4037: assert(byte_no == f1_byte, "use this argument"); jrose@1161: jrose@1161: if (!EnableInvokeDynamic) { jrose@1161: // We should not encounter this bytecode if !EnableInvokeDynamic. jrose@1161: // The verifier will stop it. However, if we get past the verifier, jrose@1161: // this will stop the thread in a reasonable way, without crashing the JVM. jrose@1161: __ call_VM(noreg, CAST_FROM_FN_PTR(address, jrose@1161: InterpreterRuntime::throw_IncompatibleClassChangeError)); jrose@1161: // the call_VM checks for exception, so we should never return here. jrose@1161: __ should_not_reach_here(); jrose@1161: return; jrose@1161: } jrose@1161: twisti@3969: const Register rbx_method = rbx; twisti@3969: const Register rax_callsite = rax; twisti@3969: twisti@3969: prepare_invoke(byte_no, rbx_method, rax_callsite); twisti@3969: twisti@4133: // rax: CallSite object (from cpool->resolved_references[f1]) twisti@3969: // rbx: MH.linkToCallSite method (from f2) twisti@3969: twisti@3969: // Note: rax_callsite is already pushed by prepare_invoke twisti@2201: twisti@2811: // %%% should make a type profile for any invokedynamic that takes a ref argument twisti@2811: // profile this call twisti@2811: __ profile_call(rsi); roland@5914: __ profile_arguments_type(rdx, rbx, rsi, false); twisti@2811: twisti@2811: __ verify_oop(rax_callsite); twisti@3969: twisti@3969: __ jump_from_interpreted(rbx_method, rdx); jrose@1161: } jrose@1161: duke@435: //---------------------------------------------------------------------------------------------------- duke@435: // Allocation duke@435: duke@435: void TemplateTable::_new() { duke@435: transition(vtos, atos); duke@435: __ get_unsigned_2_byte_index_at_bcp(rdx, 1); duke@435: Label slow_case; bobv@2036: Label slow_case_no_pop; duke@435: Label done; duke@435: Label initialize_header; duke@435: Label initialize_object; // including clearing the fields duke@435: Label allocate_shared; duke@435: duke@435: __ get_cpool_and_tags(rcx, rax); bobv@2036: bobv@2036: // Make sure the class we're about to instantiate has been resolved. coleenp@4037: // This is done before loading InstanceKlass to be consistent with the order coleenp@4037: // how Constant Pool is updated (see ConstantPool::klass_at_put) coleenp@4037: const int tags_offset = Array::base_offset_in_bytes(); bobv@2036: __ cmpb(Address(rax, rdx, Address::times_1, tags_offset), JVM_CONSTANT_Class); bobv@2036: __ jcc(Assembler::notEqual, slow_case_no_pop); bobv@2036: coleenp@4037: // get InstanceKlass coleenp@4037: __ movptr(rcx, Address(rcx, rdx, Address::times_ptr, sizeof(ConstantPool))); never@739: __ push(rcx); // save the contexts of klass for initializing the header duke@435: duke@435: // make sure klass is initialized & doesn't have finalizer duke@435: // make sure klass is fully initialized coleenp@4037: __ cmpb(Address(rcx, InstanceKlass::init_state_offset()), InstanceKlass::fully_initialized); duke@435: __ jcc(Assembler::notEqual, slow_case); duke@435: coleenp@4037: // get instance_size in InstanceKlass (scaled to a count of bytes) stefank@3391: __ movl(rdx, Address(rcx, Klass::layout_helper_offset())); duke@435: // test to see if it has a finalizer or is malformed in some way duke@435: __ testl(rdx, Klass::_lh_instance_slow_path_bit); duke@435: __ jcc(Assembler::notZero, slow_case); duke@435: duke@435: // duke@435: // Allocate the instance duke@435: // 1) Try to allocate in the TLAB duke@435: // 2) if fail and the object is large allocate in the shared Eden duke@435: // 3) if the above fails (or is not applicable), go to a slow case duke@435: // (creates a new TLAB, etc.) duke@435: duke@435: const bool allow_shared_alloc = duke@435: Universe::heap()->supports_inline_contig_alloc() && !CMSIncrementalMode; duke@435: phh@2423: const Register thread = rcx; phh@2423: if (UseTLAB || allow_shared_alloc) { phh@2423: __ get_thread(thread); phh@2423: } phh@2423: duke@435: if (UseTLAB) { never@739: __ movptr(rax, Address(thread, in_bytes(JavaThread::tlab_top_offset()))); never@739: __ lea(rbx, Address(rax, rdx, Address::times_1)); never@739: __ cmpptr(rbx, Address(thread, in_bytes(JavaThread::tlab_end_offset()))); duke@435: __ jcc(Assembler::above, allow_shared_alloc ? allocate_shared : slow_case); never@739: __ movptr(Address(thread, in_bytes(JavaThread::tlab_top_offset())), rbx); duke@435: if (ZeroTLAB) { duke@435: // the fields have been already cleared duke@435: __ jmp(initialize_header); duke@435: } else { duke@435: // initialize both the header and fields duke@435: __ jmp(initialize_object); duke@435: } duke@435: } duke@435: duke@435: // Allocation in the shared Eden, if allowed. duke@435: // duke@435: // rdx: instance size in bytes duke@435: if (allow_shared_alloc) { duke@435: __ bind(allocate_shared); duke@435: ysr@777: ExternalAddress heap_top((address)Universe::heap()->top_addr()); ysr@777: duke@435: Label retry; duke@435: __ bind(retry); never@739: __ movptr(rax, heap_top); never@739: __ lea(rbx, Address(rax, rdx, Address::times_1)); never@739: __ cmpptr(rbx, ExternalAddress((address)Universe::heap()->end_addr())); duke@435: __ jcc(Assembler::above, slow_case); duke@435: duke@435: // Compare rax, with the top addr, and if still equal, store the new duke@435: // top addr in rbx, at the address of the top addr pointer. Sets ZF if was duke@435: // equal, and clears it otherwise. Use lock prefix for atomicity on MPs. duke@435: // duke@435: // rax,: object begin duke@435: // rbx,: object end duke@435: // rdx: instance size in bytes never@739: __ locked_cmpxchgptr(rbx, heap_top); duke@435: duke@435: // if someone beat us on the allocation, try again, otherwise continue duke@435: __ jcc(Assembler::notEqual, retry); phh@2423: phh@2423: __ incr_allocated_bytes(thread, rdx, 0); duke@435: } duke@435: duke@435: if (UseTLAB || Universe::heap()->supports_inline_contig_alloc()) { duke@435: // The object is initialized before the header. If the object size is duke@435: // zero, go directly to the header initialization. duke@435: __ bind(initialize_object); duke@435: __ decrement(rdx, sizeof(oopDesc)); duke@435: __ jcc(Assembler::zero, initialize_header); duke@435: phh@2423: // Initialize topmost object field, divide rdx by 8, check if odd and phh@2423: // test if zero. duke@435: __ xorl(rcx, rcx); // use zero reg to clear memory (shorter code) duke@435: __ shrl(rdx, LogBytesPerLong); // divide by 2*oopSize and set carry flag if odd duke@435: phh@2423: // rdx must have been multiple of 8 duke@435: #ifdef ASSERT duke@435: // make sure rdx was multiple of 8 duke@435: Label L; duke@435: // Ignore partial flag stall after shrl() since it is debug VM duke@435: __ jccb(Assembler::carryClear, L); duke@435: __ stop("object size is not multiple of 2 - adjust this code"); duke@435: __ bind(L); duke@435: // rdx must be > 0, no extra check needed here duke@435: #endif duke@435: duke@435: // initialize remaining object fields: rdx was a multiple of 8 duke@435: { Label loop; duke@435: __ bind(loop); never@739: __ movptr(Address(rax, rdx, Address::times_8, sizeof(oopDesc) - 1*oopSize), rcx); never@739: NOT_LP64(__ movptr(Address(rax, rdx, Address::times_8, sizeof(oopDesc) - 2*oopSize), rcx)); duke@435: __ decrement(rdx); duke@435: __ jcc(Assembler::notZero, loop); duke@435: } duke@435: duke@435: // initialize object header only. duke@435: __ bind(initialize_header); duke@435: if (UseBiasedLocking) { never@739: __ pop(rcx); // get saved klass back in the register. stefank@3391: __ movptr(rbx, Address(rcx, Klass::prototype_header_offset())); never@739: __ movptr(Address(rax, oopDesc::mark_offset_in_bytes ()), rbx); duke@435: } else { never@739: __ movptr(Address(rax, oopDesc::mark_offset_in_bytes ()), never@739: (int32_t)markOopDesc::prototype()); // header never@739: __ pop(rcx); // get saved klass back in the register. duke@435: } twisti@2807: __ store_klass(rax, rcx); // klass duke@435: duke@435: { duke@435: SkipIfEqual skip_if(_masm, &DTraceAllocProbes, 0); duke@435: // Trigger dtrace event for fastpath duke@435: __ push(atos); duke@435: __ call_VM_leaf( duke@435: CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_object_alloc), rax); duke@435: __ pop(atos); duke@435: } duke@435: duke@435: __ jmp(done); duke@435: } duke@435: duke@435: // slow case duke@435: __ bind(slow_case); never@739: __ pop(rcx); // restore stack pointer to what it was when we came in. bobv@2036: __ bind(slow_case_no_pop); duke@435: __ get_constant_pool(rax); duke@435: __ get_unsigned_2_byte_index_at_bcp(rdx, 1); duke@435: call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::_new), rax, rdx); duke@435: duke@435: // continue duke@435: __ bind(done); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::newarray() { duke@435: transition(itos, atos); duke@435: __ push_i(rax); // make sure everything is on the stack duke@435: __ load_unsigned_byte(rdx, at_bcp(1)); duke@435: call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::newarray), rdx, rax); duke@435: __ pop_i(rdx); // discard size duke@435: } duke@435: duke@435: duke@435: void TemplateTable::anewarray() { duke@435: transition(itos, atos); duke@435: __ get_unsigned_2_byte_index_at_bcp(rdx, 1); duke@435: __ get_constant_pool(rcx); duke@435: call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::anewarray), rcx, rdx, rax); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::arraylength() { duke@435: transition(atos, itos); duke@435: __ null_check(rax, arrayOopDesc::length_offset_in_bytes()); duke@435: __ movl(rax, Address(rax, arrayOopDesc::length_offset_in_bytes())); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::checkcast() { duke@435: transition(atos, atos); duke@435: Label done, is_null, ok_is_subtype, quicked, resolved; never@739: __ testptr(rax, rax); // Object is in EAX duke@435: __ jcc(Assembler::zero, is_null); duke@435: duke@435: // Get cpool & tags index duke@435: __ get_cpool_and_tags(rcx, rdx); // ECX=cpool, EDX=tags array duke@435: __ get_unsigned_2_byte_index_at_bcp(rbx, 1); // EBX=index duke@435: // See if bytecode has already been quicked coleenp@4037: __ cmpb(Address(rdx, rbx, Address::times_1, Array::base_offset_in_bytes()), JVM_CONSTANT_Class); duke@435: __ jcc(Assembler::equal, quicked); duke@435: duke@435: __ push(atos); coleenp@4037: call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::quicken_io_cc) ); coleenp@4037: // vm_result_2 has metadata result coleenp@4037: // borrow rdi from locals coleenp@4037: __ get_thread(rdi); coleenp@4037: __ get_vm_result_2(rax, rdi); coleenp@4037: __ restore_locals(); duke@435: __ pop_ptr(rdx); duke@435: __ jmpb(resolved); duke@435: duke@435: // Get superklass in EAX and subklass in EBX duke@435: __ bind(quicked); never@739: __ mov(rdx, rax); // Save object in EDX; EAX needed for subtype check coleenp@4037: __ movptr(rax, Address(rcx, rbx, Address::times_ptr, sizeof(ConstantPool))); duke@435: duke@435: __ bind(resolved); twisti@2807: __ load_klass(rbx, rdx); duke@435: duke@435: // Generate subtype check. Blows ECX. Resets EDI. Object in EDX. duke@435: // Superklass in EAX. Subklass in EBX. duke@435: __ gen_subtype_check( rbx, ok_is_subtype ); duke@435: duke@435: // Come here on failure never@739: __ push(rdx); duke@435: // object is at TOS duke@435: __ jump(ExternalAddress(Interpreter::_throw_ClassCastException_entry)); duke@435: duke@435: // Come here on success duke@435: __ bind(ok_is_subtype); never@739: __ mov(rax,rdx); // Restore object in EDX duke@435: duke@435: // Collect counts on whether this check-cast sees NULLs a lot or not. duke@435: if (ProfileInterpreter) { duke@435: __ jmp(done); duke@435: __ bind(is_null); duke@435: __ profile_null_seen(rcx); duke@435: } else { duke@435: __ bind(is_null); // same as 'done' duke@435: } duke@435: __ bind(done); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::instanceof() { duke@435: transition(atos, itos); duke@435: Label done, is_null, ok_is_subtype, quicked, resolved; never@739: __ testptr(rax, rax); duke@435: __ jcc(Assembler::zero, is_null); duke@435: duke@435: // Get cpool & tags index duke@435: __ get_cpool_and_tags(rcx, rdx); // ECX=cpool, EDX=tags array duke@435: __ get_unsigned_2_byte_index_at_bcp(rbx, 1); // EBX=index duke@435: // See if bytecode has already been quicked coleenp@4037: __ cmpb(Address(rdx, rbx, Address::times_1, Array::base_offset_in_bytes()), JVM_CONSTANT_Class); duke@435: __ jcc(Assembler::equal, quicked); duke@435: duke@435: __ push(atos); coleenp@4037: call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::quicken_io_cc) ); coleenp@4037: // vm_result_2 has metadata result coleenp@4037: // borrow rdi from locals coleenp@4037: __ get_thread(rdi); coleenp@4037: __ get_vm_result_2(rax, rdi); coleenp@4037: __ restore_locals(); duke@435: __ pop_ptr(rdx); twisti@2807: __ load_klass(rdx, rdx); duke@435: __ jmp(resolved); duke@435: duke@435: // Get superklass in EAX and subklass in EDX duke@435: __ bind(quicked); twisti@2807: __ load_klass(rdx, rax); coleenp@4037: __ movptr(rax, Address(rcx, rbx, Address::times_ptr, sizeof(ConstantPool))); duke@435: duke@435: __ bind(resolved); duke@435: duke@435: // Generate subtype check. Blows ECX. Resets EDI. duke@435: // Superklass in EAX. Subklass in EDX. duke@435: __ gen_subtype_check( rdx, ok_is_subtype ); duke@435: duke@435: // Come here on failure duke@435: __ xorl(rax,rax); duke@435: __ jmpb(done); duke@435: // Come here on success duke@435: __ bind(ok_is_subtype); duke@435: __ movl(rax, 1); duke@435: duke@435: // Collect counts on whether this test sees NULLs a lot or not. duke@435: if (ProfileInterpreter) { duke@435: __ jmp(done); duke@435: __ bind(is_null); duke@435: __ profile_null_seen(rcx); duke@435: } else { duke@435: __ bind(is_null); // same as 'done' duke@435: } duke@435: __ bind(done); duke@435: // rax, = 0: obj == NULL or obj is not an instanceof the specified klass duke@435: // rax, = 1: obj != NULL and obj is an instanceof the specified klass duke@435: } duke@435: duke@435: duke@435: //---------------------------------------------------------------------------------------------------- duke@435: // Breakpoints duke@435: void TemplateTable::_breakpoint() { duke@435: duke@435: // Note: We get here even if we are single stepping.. duke@435: // jbug inists on setting breakpoints at every bytecode duke@435: // even if we are in single step mode. duke@435: duke@435: transition(vtos, vtos); duke@435: duke@435: // get the unpatched byte code duke@435: __ get_method(rcx); duke@435: __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::get_original_bytecode_at), rcx, rsi); never@739: __ mov(rbx, rax); duke@435: duke@435: // post the breakpoint event duke@435: __ get_method(rcx); duke@435: __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::_breakpoint), rcx, rsi); duke@435: duke@435: // complete the execution of original bytecode duke@435: __ dispatch_only_normal(vtos); duke@435: } duke@435: duke@435: duke@435: //---------------------------------------------------------------------------------------------------- duke@435: // Exceptions duke@435: duke@435: void TemplateTable::athrow() { duke@435: transition(atos, vtos); duke@435: __ null_check(rax); duke@435: __ jump(ExternalAddress(Interpreter::throw_exception_entry())); duke@435: } duke@435: duke@435: duke@435: //---------------------------------------------------------------------------------------------------- duke@435: // Synchronization duke@435: // duke@435: // Note: monitorenter & exit are symmetric routines; which is reflected duke@435: // in the assembly code structure as well duke@435: // duke@435: // Stack layout: duke@435: // duke@435: // [expressions ] <--- rsp = expression stack top duke@435: // .. duke@435: // [expressions ] duke@435: // [monitor entry] <--- monitor block top = expression stack bot duke@435: // .. duke@435: // [monitor entry] duke@435: // [frame data ] <--- monitor block bot duke@435: // ... duke@435: // [saved rbp, ] <--- rbp, duke@435: duke@435: duke@435: void TemplateTable::monitorenter() { duke@435: transition(atos, vtos); duke@435: duke@435: // check for NULL object duke@435: __ null_check(rax); duke@435: duke@435: const Address monitor_block_top(rbp, frame::interpreter_frame_monitor_block_top_offset * wordSize); duke@435: const Address monitor_block_bot(rbp, frame::interpreter_frame_initial_sp_offset * wordSize); duke@435: const int entry_size = ( frame::interpreter_frame_monitor_size() * wordSize); duke@435: Label allocated; duke@435: duke@435: // initialize entry pointer duke@435: __ xorl(rdx, rdx); // points to free slot or NULL duke@435: duke@435: // find a free slot in the monitor block (result in rdx) duke@435: { Label entry, loop, exit; twisti@2697: __ movptr(rcx, monitor_block_top); // points to current entry, starting with top-most entry twisti@2697: twisti@2697: __ lea(rbx, monitor_block_bot); // points to word before bottom of monitor block duke@435: __ jmpb(entry); duke@435: duke@435: __ bind(loop); never@739: __ cmpptr(Address(rcx, BasicObjectLock::obj_offset_in_bytes()), (int32_t)NULL_WORD); // check if current entry is used twisti@2697: __ cmovptr(Assembler::equal, rdx, rcx); // if not used then remember entry in rdx never@739: __ cmpptr(rax, Address(rcx, BasicObjectLock::obj_offset_in_bytes())); // check if current entry is for same object never@739: __ jccb(Assembler::equal, exit); // if same object then stop searching never@739: __ addptr(rcx, entry_size); // otherwise advance to next entry duke@435: __ bind(entry); never@739: __ cmpptr(rcx, rbx); // check if bottom reached duke@435: __ jcc(Assembler::notEqual, loop); // if not at bottom then check this entry duke@435: __ bind(exit); duke@435: } duke@435: never@739: __ testptr(rdx, rdx); // check if a slot has been found never@739: __ jccb(Assembler::notZero, allocated); // if found, continue with that one duke@435: duke@435: // allocate one if there's no free slot duke@435: { Label entry, loop; duke@435: // 1. compute new pointers // rsp: old expression stack top never@739: __ movptr(rdx, monitor_block_bot); // rdx: old expression stack bottom never@739: __ subptr(rsp, entry_size); // move expression stack top never@739: __ subptr(rdx, entry_size); // move expression stack bottom never@739: __ mov(rcx, rsp); // set start value for copy loop never@739: __ movptr(monitor_block_bot, rdx); // set new monitor block top duke@435: __ jmp(entry); duke@435: // 2. move expression stack contents duke@435: __ bind(loop); never@739: __ movptr(rbx, Address(rcx, entry_size)); // load expression stack word from old location never@739: __ movptr(Address(rcx, 0), rbx); // and store it at new location never@739: __ addptr(rcx, wordSize); // advance to next word duke@435: __ bind(entry); never@739: __ cmpptr(rcx, rdx); // check if bottom reached duke@435: __ jcc(Assembler::notEqual, loop); // if not at bottom then copy next word duke@435: } duke@435: duke@435: // call run-time routine duke@435: // rdx: points to monitor entry duke@435: __ bind(allocated); duke@435: duke@435: // Increment bcp to point to the next bytecode, so exception handling for async. exceptions work correctly. duke@435: // The object has already been poped from the stack, so the expression stack looks correct. duke@435: __ increment(rsi); duke@435: never@739: __ movptr(Address(rdx, BasicObjectLock::obj_offset_in_bytes()), rax); // store object duke@435: __ lock_object(rdx); duke@435: duke@435: // check to make sure this monitor doesn't cause stack overflow after locking duke@435: __ save_bcp(); // in case of exception duke@435: __ generate_stack_overflow_check(0); duke@435: duke@435: // The bcp has already been incremented. Just need to dispatch to next instruction. duke@435: __ dispatch_next(vtos); duke@435: } duke@435: duke@435: duke@435: void TemplateTable::monitorexit() { duke@435: transition(atos, vtos); duke@435: duke@435: // check for NULL object duke@435: __ null_check(rax); duke@435: duke@435: const Address monitor_block_top(rbp, frame::interpreter_frame_monitor_block_top_offset * wordSize); duke@435: const Address monitor_block_bot(rbp, frame::interpreter_frame_initial_sp_offset * wordSize); duke@435: const int entry_size = ( frame::interpreter_frame_monitor_size() * wordSize); duke@435: Label found; duke@435: duke@435: // find matching slot duke@435: { Label entry, loop; never@739: __ movptr(rdx, monitor_block_top); // points to current entry, starting with top-most entry never@739: __ lea(rbx, monitor_block_bot); // points to word before bottom of monitor block duke@435: __ jmpb(entry); duke@435: duke@435: __ bind(loop); never@739: __ cmpptr(rax, Address(rdx, BasicObjectLock::obj_offset_in_bytes())); // check if current entry is for same object duke@435: __ jcc(Assembler::equal, found); // if same object then stop searching never@739: __ addptr(rdx, entry_size); // otherwise advance to next entry duke@435: __ bind(entry); never@739: __ cmpptr(rdx, rbx); // check if bottom reached duke@435: __ jcc(Assembler::notEqual, loop); // if not at bottom then check this entry duke@435: } duke@435: duke@435: // error handling. Unlocking was not block-structured duke@435: Label end; duke@435: __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_illegal_monitor_state_exception)); duke@435: __ should_not_reach_here(); duke@435: duke@435: // call run-time routine duke@435: // rcx: points to monitor entry duke@435: __ bind(found); duke@435: __ push_ptr(rax); // make sure object is on stack (contract with oopMaps) duke@435: __ unlock_object(rdx); duke@435: __ pop_ptr(rax); // discard object duke@435: __ bind(end); duke@435: } duke@435: duke@435: duke@435: //---------------------------------------------------------------------------------------------------- duke@435: // Wide instructions duke@435: duke@435: void TemplateTable::wide() { duke@435: transition(vtos, vtos); duke@435: __ load_unsigned_byte(rbx, at_bcp(1)); never@739: ExternalAddress wtable((address)Interpreter::_wentry_point); never@739: __ jump(ArrayAddress(wtable, Address(noreg, rbx, Address::times_ptr))); duke@435: // Note: the rsi increment step is part of the individual wide bytecode implementations duke@435: } duke@435: duke@435: duke@435: //---------------------------------------------------------------------------------------------------- duke@435: // Multi arrays duke@435: duke@435: void TemplateTable::multianewarray() { duke@435: transition(vtos, atos); duke@435: __ load_unsigned_byte(rax, at_bcp(3)); // get number of dimensions duke@435: // last dim is on top of stack; we want address of first one: duke@435: // first_addr = last_addr + (ndims - 1) * stackElementSize - 1*wordsize duke@435: // the latter wordSize to point to the beginning of the array. never@739: __ lea( rax, Address(rsp, rax, Interpreter::stackElementScale(), -wordSize)); duke@435: call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::multianewarray), rax); // pass in rax, duke@435: __ load_unsigned_byte(rbx, at_bcp(3)); never@739: __ lea(rsp, Address(rsp, rbx, Interpreter::stackElementScale())); // get rid of counts duke@435: } duke@435: duke@435: #endif /* !CC_INTERP */