aoqi@0: /* aoqi@0: * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: * aoqi@0: */ aoqi@0: aoqi@0: #include "precompiled.hpp" aoqi@0: #include "asm/macroAssembler.hpp" aoqi@0: #include "memory/resourceArea.hpp" aoqi@0: #include "prims/jniFastGetField.hpp" aoqi@0: #include "prims/jvm_misc.hpp" aoqi@0: #include "runtime/safepoint.hpp" aoqi@0: aoqi@0: #define __ masm-> aoqi@0: aoqi@0: #define BUFFER_SIZE 30 aoqi@0: aoqi@0: #ifdef _WINDOWS aoqi@0: GetBooleanField_t JNI_FastGetField::jni_fast_GetBooleanField_fp; aoqi@0: GetByteField_t JNI_FastGetField::jni_fast_GetByteField_fp; aoqi@0: GetCharField_t JNI_FastGetField::jni_fast_GetCharField_fp; aoqi@0: GetShortField_t JNI_FastGetField::jni_fast_GetShortField_fp; aoqi@0: GetIntField_t JNI_FastGetField::jni_fast_GetIntField_fp; aoqi@0: GetLongField_t JNI_FastGetField::jni_fast_GetLongField_fp; aoqi@0: GetFloatField_t JNI_FastGetField::jni_fast_GetFloatField_fp; aoqi@0: GetDoubleField_t JNI_FastGetField::jni_fast_GetDoubleField_fp; aoqi@0: #endif aoqi@0: aoqi@0: // Instead of issuing lfence for LoadLoad barrier, we create data dependency aoqi@0: // between loads, which is much more efficient than lfence. aoqi@0: aoqi@0: address JNI_FastGetField::generate_fast_get_int_field0(BasicType type) { aoqi@0: const char *name; aoqi@0: switch (type) { aoqi@0: case T_BOOLEAN: name = "jni_fast_GetBooleanField"; break; aoqi@0: case T_BYTE: name = "jni_fast_GetByteField"; break; aoqi@0: case T_CHAR: name = "jni_fast_GetCharField"; break; aoqi@0: case T_SHORT: name = "jni_fast_GetShortField"; break; aoqi@0: case T_INT: name = "jni_fast_GetIntField"; break; aoqi@0: default: ShouldNotReachHere(); aoqi@0: } aoqi@0: ResourceMark rm; aoqi@0: BufferBlob* blob = BufferBlob::create(name, BUFFER_SIZE*wordSize); aoqi@0: CodeBuffer cbuf(blob); aoqi@0: MacroAssembler* masm = new MacroAssembler(&cbuf); aoqi@0: address fast_entry = __ pc(); aoqi@0: aoqi@0: Label slow; aoqi@0: aoqi@0: // stack layout: offset from rsp (in words): aoqi@0: // return pc 0 aoqi@0: // jni env 1 aoqi@0: // obj 2 aoqi@0: // jfieldID 3 aoqi@0: aoqi@0: ExternalAddress counter(SafepointSynchronize::safepoint_counter_addr()); aoqi@0: __ mov32 (rcx, counter); aoqi@0: __ testb (rcx, 1); aoqi@0: __ jcc (Assembler::notZero, slow); aoqi@0: if (os::is_MP()) { aoqi@0: __ mov(rax, rcx); aoqi@0: __ andptr(rax, 1); // rax, must end up 0 aoqi@0: __ movptr(rdx, Address(rsp, rax, Address::times_1, 2*wordSize)); aoqi@0: // obj, notice rax, is 0. aoqi@0: // rdx is data dependent on rcx. aoqi@0: } else { aoqi@0: __ movptr (rdx, Address(rsp, 2*wordSize)); // obj aoqi@0: } aoqi@0: __ movptr(rax, Address(rsp, 3*wordSize)); // jfieldID aoqi@0: __ movptr(rdx, Address(rdx, 0)); // *obj aoqi@0: __ shrptr (rax, 2); // offset aoqi@0: aoqi@0: assert(count < LIST_CAPACITY, "LIST_CAPACITY too small"); aoqi@0: speculative_load_pclist[count] = __ pc(); aoqi@0: switch (type) { aoqi@0: case T_BOOLEAN: __ movzbl (rax, Address(rdx, rax, Address::times_1)); break; aoqi@0: case T_BYTE: __ movsbl (rax, Address(rdx, rax, Address::times_1)); break; aoqi@0: case T_CHAR: __ movzwl (rax, Address(rdx, rax, Address::times_1)); break; aoqi@0: case T_SHORT: __ movswl (rax, Address(rdx, rax, Address::times_1)); break; aoqi@0: case T_INT: __ movl (rax, Address(rdx, rax, Address::times_1)); break; aoqi@0: default: ShouldNotReachHere(); aoqi@0: } aoqi@0: aoqi@0: Address ca1; aoqi@0: if (os::is_MP()) { aoqi@0: __ lea(rdx, counter); aoqi@0: __ xorptr(rdx, rax); aoqi@0: __ xorptr(rdx, rax); aoqi@0: __ cmp32(rcx, Address(rdx, 0)); aoqi@0: // ca1 is the same as ca because aoqi@0: // rax, ^ counter_addr ^ rax, = address aoqi@0: // ca1 is data dependent on rax,. aoqi@0: } else { aoqi@0: __ cmp32(rcx, counter); aoqi@0: } aoqi@0: __ jcc (Assembler::notEqual, slow); aoqi@0: aoqi@0: #ifndef _WINDOWS aoqi@0: __ ret (0); aoqi@0: #else aoqi@0: // __stdcall calling convention aoqi@0: __ ret (3*wordSize); aoqi@0: #endif aoqi@0: aoqi@0: slowcase_entry_pclist[count++] = __ pc(); aoqi@0: __ bind (slow); aoqi@0: address slow_case_addr; aoqi@0: switch (type) { aoqi@0: case T_BOOLEAN: slow_case_addr = jni_GetBooleanField_addr(); break; aoqi@0: case T_BYTE: slow_case_addr = jni_GetByteField_addr(); break; aoqi@0: case T_CHAR: slow_case_addr = jni_GetCharField_addr(); break; aoqi@0: case T_SHORT: slow_case_addr = jni_GetShortField_addr(); break; aoqi@0: case T_INT: slow_case_addr = jni_GetIntField_addr(); aoqi@0: } aoqi@0: // tail call aoqi@0: __ jump (ExternalAddress(slow_case_addr)); aoqi@0: aoqi@0: __ flush (); aoqi@0: aoqi@0: #ifndef _WINDOWS aoqi@0: return fast_entry; aoqi@0: #else aoqi@0: switch (type) { aoqi@0: case T_BOOLEAN: jni_fast_GetBooleanField_fp = (GetBooleanField_t) fast_entry; break; aoqi@0: case T_BYTE: jni_fast_GetByteField_fp = (GetByteField_t) fast_entry; break; aoqi@0: case T_CHAR: jni_fast_GetCharField_fp = (GetCharField_t) fast_entry; break; aoqi@0: case T_SHORT: jni_fast_GetShortField_fp = (GetShortField_t) fast_entry; break; aoqi@0: case T_INT: jni_fast_GetIntField_fp = (GetIntField_t) fast_entry; break; aoqi@0: } aoqi@0: return os::win32::fast_jni_accessor_wrapper(type); aoqi@0: #endif aoqi@0: } aoqi@0: aoqi@0: address JNI_FastGetField::generate_fast_get_boolean_field() { aoqi@0: return generate_fast_get_int_field0(T_BOOLEAN); aoqi@0: } aoqi@0: aoqi@0: address JNI_FastGetField::generate_fast_get_byte_field() { aoqi@0: return generate_fast_get_int_field0(T_BYTE); aoqi@0: } aoqi@0: aoqi@0: address JNI_FastGetField::generate_fast_get_char_field() { aoqi@0: return generate_fast_get_int_field0(T_CHAR); aoqi@0: } aoqi@0: aoqi@0: address JNI_FastGetField::generate_fast_get_short_field() { aoqi@0: return generate_fast_get_int_field0(T_SHORT); aoqi@0: } aoqi@0: aoqi@0: address JNI_FastGetField::generate_fast_get_int_field() { aoqi@0: return generate_fast_get_int_field0(T_INT); aoqi@0: } aoqi@0: aoqi@0: address JNI_FastGetField::generate_fast_get_long_field() { aoqi@0: const char *name = "jni_fast_GetLongField"; aoqi@0: ResourceMark rm; aoqi@0: BufferBlob* blob = BufferBlob::create(name, BUFFER_SIZE*wordSize); aoqi@0: CodeBuffer cbuf(blob); aoqi@0: MacroAssembler* masm = new MacroAssembler(&cbuf); aoqi@0: address fast_entry = __ pc(); aoqi@0: aoqi@0: Label slow; aoqi@0: aoqi@0: // stack layout: offset from rsp (in words): aoqi@0: // old rsi 0 aoqi@0: // return pc 1 aoqi@0: // jni env 2 aoqi@0: // obj 3 aoqi@0: // jfieldID 4 aoqi@0: aoqi@0: ExternalAddress counter(SafepointSynchronize::safepoint_counter_addr()); aoqi@0: aoqi@0: __ push (rsi); aoqi@0: __ mov32 (rcx, counter); aoqi@0: __ testb (rcx, 1); aoqi@0: __ jcc (Assembler::notZero, slow); aoqi@0: if (os::is_MP()) { aoqi@0: __ mov(rax, rcx); aoqi@0: __ andptr(rax, 1); // rax, must end up 0 aoqi@0: __ movptr(rdx, Address(rsp, rax, Address::times_1, 3*wordSize)); aoqi@0: // obj, notice rax, is 0. aoqi@0: // rdx is data dependent on rcx. aoqi@0: } else { aoqi@0: __ movptr(rdx, Address(rsp, 3*wordSize)); // obj aoqi@0: } aoqi@0: __ movptr(rsi, Address(rsp, 4*wordSize)); // jfieldID aoqi@0: __ movptr(rdx, Address(rdx, 0)); // *obj aoqi@0: __ shrptr(rsi, 2); // offset aoqi@0: aoqi@0: assert(count < LIST_CAPACITY-1, "LIST_CAPACITY too small"); aoqi@0: speculative_load_pclist[count++] = __ pc(); aoqi@0: __ movptr(rax, Address(rdx, rsi, Address::times_1)); aoqi@0: #ifndef _LP64 aoqi@0: speculative_load_pclist[count] = __ pc(); aoqi@0: __ movl(rdx, Address(rdx, rsi, Address::times_1, 4)); aoqi@0: #endif // _LP64 aoqi@0: aoqi@0: if (os::is_MP()) { aoqi@0: __ lea(rsi, counter); aoqi@0: __ xorptr(rsi, rdx); aoqi@0: __ xorptr(rsi, rax); aoqi@0: __ xorptr(rsi, rdx); aoqi@0: __ xorptr(rsi, rax); aoqi@0: __ cmp32(rcx, Address(rsi, 0)); aoqi@0: // ca1 is the same as ca because aoqi@0: // rax, ^ rdx ^ counter_addr ^ rax, ^ rdx = address aoqi@0: // ca1 is data dependent on both rax, and rdx. aoqi@0: } else { aoqi@0: __ cmp32(rcx, counter); aoqi@0: } aoqi@0: __ jcc (Assembler::notEqual, slow); aoqi@0: aoqi@0: __ pop (rsi); aoqi@0: aoqi@0: #ifndef _WINDOWS aoqi@0: __ ret (0); aoqi@0: #else aoqi@0: // __stdcall calling convention aoqi@0: __ ret (3*wordSize); aoqi@0: #endif aoqi@0: aoqi@0: slowcase_entry_pclist[count-1] = __ pc(); aoqi@0: slowcase_entry_pclist[count++] = __ pc(); aoqi@0: __ bind (slow); aoqi@0: __ pop (rsi); aoqi@0: address slow_case_addr = jni_GetLongField_addr();; aoqi@0: // tail call aoqi@0: __ jump (ExternalAddress(slow_case_addr)); aoqi@0: aoqi@0: __ flush (); aoqi@0: aoqi@0: #ifndef _WINDOWS aoqi@0: return fast_entry; aoqi@0: #else aoqi@0: jni_fast_GetLongField_fp = (GetLongField_t) fast_entry; aoqi@0: return os::win32::fast_jni_accessor_wrapper(T_LONG); aoqi@0: #endif aoqi@0: } aoqi@0: aoqi@0: address JNI_FastGetField::generate_fast_get_float_field0(BasicType type) { aoqi@0: const char *name; aoqi@0: switch (type) { aoqi@0: case T_FLOAT: name = "jni_fast_GetFloatField"; break; aoqi@0: case T_DOUBLE: name = "jni_fast_GetDoubleField"; break; aoqi@0: default: ShouldNotReachHere(); aoqi@0: } aoqi@0: ResourceMark rm; aoqi@0: BufferBlob* blob = BufferBlob::create(name, BUFFER_SIZE*wordSize); aoqi@0: CodeBuffer cbuf(blob); aoqi@0: MacroAssembler* masm = new MacroAssembler(&cbuf); aoqi@0: address fast_entry = __ pc(); aoqi@0: aoqi@0: Label slow_with_pop, slow; aoqi@0: aoqi@0: // stack layout: offset from rsp (in words): aoqi@0: // return pc 0 aoqi@0: // jni env 1 aoqi@0: // obj 2 aoqi@0: // jfieldID 3 aoqi@0: aoqi@0: ExternalAddress counter(SafepointSynchronize::safepoint_counter_addr()); aoqi@0: aoqi@0: __ mov32 (rcx, counter); aoqi@0: __ testb (rcx, 1); aoqi@0: __ jcc (Assembler::notZero, slow); aoqi@0: if (os::is_MP()) { aoqi@0: __ mov(rax, rcx); aoqi@0: __ andptr(rax, 1); // rax, must end up 0 aoqi@0: __ movptr(rdx, Address(rsp, rax, Address::times_1, 2*wordSize)); aoqi@0: // obj, notice rax, is 0. aoqi@0: // rdx is data dependent on rcx. aoqi@0: } else { aoqi@0: __ movptr(rdx, Address(rsp, 2*wordSize)); // obj aoqi@0: } aoqi@0: __ movptr(rax, Address(rsp, 3*wordSize)); // jfieldID aoqi@0: __ movptr(rdx, Address(rdx, 0)); // *obj aoqi@0: __ shrptr(rax, 2); // offset aoqi@0: aoqi@0: assert(count < LIST_CAPACITY, "LIST_CAPACITY too small"); aoqi@0: speculative_load_pclist[count] = __ pc(); aoqi@0: switch (type) { aoqi@0: #ifndef _LP64 aoqi@0: case T_FLOAT: __ fld_s (Address(rdx, rax, Address::times_1)); break; aoqi@0: case T_DOUBLE: __ fld_d (Address(rdx, rax, Address::times_1)); break; aoqi@0: #else aoqi@0: case T_FLOAT: __ movflt (xmm0, Address(robj, roffset, Address::times_1)); break; aoqi@0: case T_DOUBLE: __ movdbl (xmm0, Address(robj, roffset, Address::times_1)); break; aoqi@0: #endif // _LP64 aoqi@0: default: ShouldNotReachHere(); aoqi@0: } aoqi@0: aoqi@0: Address ca1; aoqi@0: if (os::is_MP()) { aoqi@0: __ fst_s (Address(rsp, -4)); aoqi@0: __ lea(rdx, counter); aoqi@0: __ movl (rax, Address(rsp, -4)); aoqi@0: // garbage hi-order bits on 64bit are harmless. aoqi@0: __ xorptr(rdx, rax); aoqi@0: __ xorptr(rdx, rax); aoqi@0: __ cmp32(rcx, Address(rdx, 0)); aoqi@0: // rax, ^ counter_addr ^ rax, = address aoqi@0: // ca1 is data dependent on the field aoqi@0: // access. aoqi@0: } else { aoqi@0: __ cmp32(rcx, counter); aoqi@0: } aoqi@0: __ jcc (Assembler::notEqual, slow_with_pop); aoqi@0: aoqi@0: #ifndef _WINDOWS aoqi@0: __ ret (0); aoqi@0: #else aoqi@0: // __stdcall calling convention aoqi@0: __ ret (3*wordSize); aoqi@0: #endif aoqi@0: aoqi@0: __ bind (slow_with_pop); aoqi@0: // invalid load. pop FPU stack. aoqi@0: __ fstp_d (0); aoqi@0: aoqi@0: slowcase_entry_pclist[count++] = __ pc(); aoqi@0: __ bind (slow); aoqi@0: address slow_case_addr; aoqi@0: switch (type) { aoqi@0: case T_FLOAT: slow_case_addr = jni_GetFloatField_addr(); break; aoqi@0: case T_DOUBLE: slow_case_addr = jni_GetDoubleField_addr(); break; aoqi@0: default: ShouldNotReachHere(); aoqi@0: } aoqi@0: // tail call aoqi@0: __ jump (ExternalAddress(slow_case_addr)); aoqi@0: aoqi@0: __ flush (); aoqi@0: aoqi@0: #ifndef _WINDOWS aoqi@0: return fast_entry; aoqi@0: #else aoqi@0: switch (type) { aoqi@0: case T_FLOAT: jni_fast_GetFloatField_fp = (GetFloatField_t) fast_entry; break; aoqi@0: case T_DOUBLE: jni_fast_GetDoubleField_fp = (GetDoubleField_t) fast_entry; break; aoqi@0: } aoqi@0: return os::win32::fast_jni_accessor_wrapper(type); aoqi@0: #endif aoqi@0: } aoqi@0: aoqi@0: address JNI_FastGetField::generate_fast_get_float_field() { aoqi@0: return generate_fast_get_float_field0(T_FLOAT); aoqi@0: } aoqi@0: aoqi@0: address JNI_FastGetField::generate_fast_get_double_field() { aoqi@0: return generate_fast_get_float_field0(T_DOUBLE); aoqi@0: }