duke@435: /* trims@1907: * Copyright (c) 1998, 2010, 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" stefank@2314: #include "interpreter/interpreter.hpp" stefank@2314: #include "interpreter/interpreterRuntime.hpp" stefank@2314: #include "memory/allocation.inline.hpp" stefank@2314: #include "memory/universe.inline.hpp" stefank@2314: #include "oops/methodOop.hpp" stefank@2314: #include "oops/oop.inline.hpp" stefank@2314: #include "runtime/handles.inline.hpp" stefank@2314: #include "runtime/icache.hpp" stefank@2314: #include "runtime/interfaceSupport.hpp" stefank@2314: #include "runtime/signature.hpp" duke@435: duke@435: duke@435: #define __ _masm-> duke@435: duke@435: duke@435: // Implementation of SignatureHandlerGenerator duke@435: duke@435: void InterpreterRuntime::SignatureHandlerGenerator::pass_word(int size_of_arg, int offset_in_arg) { duke@435: Argument jni_arg(jni_offset() + offset_in_arg, false); duke@435: Register Rtmp = O0; duke@435: __ ld(Llocals, Interpreter::local_offset_in_bytes(offset()), Rtmp); duke@435: duke@435: __ store_argument(Rtmp, jni_arg); duke@435: } duke@435: duke@435: void InterpreterRuntime::SignatureHandlerGenerator::pass_long() { duke@435: Argument jni_arg(jni_offset(), false); duke@435: Register Rtmp = O0; duke@435: duke@435: #ifdef _LP64 duke@435: __ ldx(Llocals, Interpreter::local_offset_in_bytes(offset() + 1), Rtmp); duke@435: __ store_long_argument(Rtmp, jni_arg); duke@435: #else duke@435: __ ld(Llocals, Interpreter::local_offset_in_bytes(offset() + 1), Rtmp); duke@435: __ store_argument(Rtmp, jni_arg); duke@435: __ ld(Llocals, Interpreter::local_offset_in_bytes(offset() + 0), Rtmp); duke@435: Argument successor(jni_arg.successor()); duke@435: __ store_argument(Rtmp, successor); duke@435: #endif duke@435: } duke@435: duke@435: duke@435: void InterpreterRuntime::SignatureHandlerGenerator::pass_float() { duke@435: Argument jni_arg(jni_offset(), false); bobv@2036: #ifdef _LP64 duke@435: FloatRegister Rtmp = F0; duke@435: __ ldf(FloatRegisterImpl::S, Llocals, Interpreter::local_offset_in_bytes(offset()), Rtmp); duke@435: __ store_float_argument(Rtmp, jni_arg); bobv@2036: #else bobv@2036: Register Rtmp = O0; bobv@2036: __ ld(Llocals, Interpreter::local_offset_in_bytes(offset()), Rtmp); bobv@2036: __ store_argument(Rtmp, jni_arg); bobv@2036: #endif duke@435: } duke@435: duke@435: duke@435: void InterpreterRuntime::SignatureHandlerGenerator::pass_double() { duke@435: Argument jni_arg(jni_offset(), false); duke@435: #ifdef _LP64 duke@435: FloatRegister Rtmp = F0; duke@435: __ ldf(FloatRegisterImpl::D, Llocals, Interpreter::local_offset_in_bytes(offset() + 1), Rtmp); duke@435: __ store_double_argument(Rtmp, jni_arg); duke@435: #else duke@435: Register Rtmp = O0; duke@435: __ ld(Llocals, Interpreter::local_offset_in_bytes(offset() + 1), Rtmp); duke@435: __ store_argument(Rtmp, jni_arg); duke@435: __ ld(Llocals, Interpreter::local_offset_in_bytes(offset()), Rtmp); duke@435: Argument successor(jni_arg.successor()); duke@435: __ store_argument(Rtmp, successor); duke@435: #endif duke@435: } duke@435: duke@435: void InterpreterRuntime::SignatureHandlerGenerator::pass_object() { duke@435: Argument jni_arg(jni_offset(), false); duke@435: Argument java_arg( offset(), true); duke@435: Register Rtmp1 = O0; duke@435: Register Rtmp2 = jni_arg.is_register() ? jni_arg.as_register() : O0; duke@435: Register Rtmp3 = G3_scratch; duke@435: duke@435: // the handle for a receiver will never be null duke@435: bool do_NULL_check = offset() != 0 || is_static(); duke@435: twisti@1162: Address h_arg = Address(Llocals, Interpreter::local_offset_in_bytes(offset())); duke@435: __ ld_ptr(h_arg, Rtmp1); duke@435: if (!do_NULL_check) { twisti@1162: __ add(h_arg.base(), h_arg.disp(), Rtmp2); duke@435: } else { duke@435: if (Rtmp1 == Rtmp2) duke@435: __ tst(Rtmp1); duke@435: else __ addcc(G0, Rtmp1, Rtmp2); // optimize mov/test pair duke@435: Label L; duke@435: __ brx(Assembler::notZero, true, Assembler::pt, L); twisti@1162: __ delayed()->add(h_arg.base(), h_arg.disp(), Rtmp2); duke@435: __ bind(L); duke@435: } duke@435: __ store_ptr_argument(Rtmp2, jni_arg); // this is often a no-op duke@435: } duke@435: duke@435: duke@435: void InterpreterRuntime::SignatureHandlerGenerator::generate(uint64_t fingerprint) { duke@435: duke@435: // generate code to handle arguments duke@435: iterate(fingerprint); duke@435: duke@435: // return result handler twisti@1162: AddressLiteral result_handler(Interpreter::result_handler(method()->result_type())); twisti@1162: __ sethi(result_handler, Lscratch); duke@435: __ retl(); twisti@1162: __ delayed()->add(Lscratch, result_handler.low10(), Lscratch); duke@435: duke@435: __ flush(); duke@435: } duke@435: duke@435: duke@435: // Implementation of SignatureHandlerLibrary duke@435: duke@435: void SignatureHandlerLibrary::pd_set_handler(address handler) {} duke@435: duke@435: duke@435: class SlowSignatureHandler: public NativeSignatureIterator { duke@435: private: duke@435: address _from; duke@435: intptr_t* _to; duke@435: intptr_t* _RegArgSignature; // Signature of first Arguments to be passed in Registers duke@435: uint _argcount; duke@435: duke@435: enum { // We need to differenciate float from non floats in reg args duke@435: non_float = 0, duke@435: float_sig = 1, duke@435: double_sig = 2, duke@435: long_sig = 3 duke@435: }; duke@435: duke@435: virtual void pass_int() { duke@435: *_to++ = *(jint *)(_from+Interpreter::local_offset_in_bytes(0)); twisti@1861: _from -= Interpreter::stackElementSize; duke@435: add_signature( non_float ); duke@435: } duke@435: duke@435: virtual void pass_object() { duke@435: // pass address of from duke@435: intptr_t *from_addr = (intptr_t*)(_from + Interpreter::local_offset_in_bytes(0)); duke@435: *_to++ = (*from_addr == 0) ? NULL : (intptr_t) from_addr; twisti@1861: _from -= Interpreter::stackElementSize; duke@435: add_signature( non_float ); duke@435: } duke@435: duke@435: #ifdef _LP64 duke@435: virtual void pass_float() { duke@435: *_to++ = *(jint *)(_from+Interpreter::local_offset_in_bytes(0)); twisti@1861: _from -= Interpreter::stackElementSize; duke@435: add_signature( float_sig ); duke@435: } duke@435: duke@435: virtual void pass_double() { duke@435: *_to++ = *(intptr_t*)(_from+Interpreter::local_offset_in_bytes(1)); twisti@1861: _from -= 2*Interpreter::stackElementSize; duke@435: add_signature( double_sig ); duke@435: } duke@435: duke@435: virtual void pass_long() { duke@435: _to[0] = *(intptr_t*)(_from+Interpreter::local_offset_in_bytes(1)); duke@435: _to += 1; twisti@1861: _from -= 2*Interpreter::stackElementSize; duke@435: add_signature( long_sig ); duke@435: } duke@435: #else duke@435: // pass_double() is pass_long() and pass_float() only _LP64 duke@435: virtual void pass_long() { duke@435: _to[0] = *(intptr_t*)(_from+Interpreter::local_offset_in_bytes(1)); duke@435: _to[1] = *(intptr_t*)(_from+Interpreter::local_offset_in_bytes(0)); duke@435: _to += 2; twisti@1861: _from -= 2*Interpreter::stackElementSize; duke@435: add_signature( non_float ); duke@435: } bobv@2036: bobv@2036: virtual void pass_float() { bobv@2036: *_to++ = *(jint *)(_from+Interpreter::local_offset_in_bytes(0)); bobv@2036: _from -= Interpreter::stackElementSize; bobv@2036: add_signature( non_float ); bobv@2036: } bobv@2036: duke@435: #endif // _LP64 duke@435: duke@435: virtual void add_signature( intptr_t sig_type ) { duke@435: if ( _argcount < (sizeof (intptr_t))*4 ) { duke@435: *_RegArgSignature |= (sig_type << (_argcount*2) ); duke@435: _argcount++; duke@435: } duke@435: } duke@435: duke@435: duke@435: public: duke@435: SlowSignatureHandler(methodHandle method, address from, intptr_t* to, intptr_t *RegArgSig) : NativeSignatureIterator(method) { duke@435: _from = from; duke@435: _to = to; duke@435: _RegArgSignature = RegArgSig; duke@435: *_RegArgSignature = 0; duke@435: _argcount = method->is_static() ? 2 : 1; duke@435: } duke@435: }; duke@435: duke@435: duke@435: IRT_ENTRY(address, InterpreterRuntime::slow_signature_handler( duke@435: JavaThread* thread, duke@435: methodOopDesc* method, duke@435: intptr_t* from, duke@435: intptr_t* to )) duke@435: methodHandle m(thread, method); duke@435: assert(m->is_native(), "sanity check"); duke@435: // handle arguments duke@435: // Warning: We use reg arg slot 00 temporarily to return the RegArgSignature duke@435: // back to the code that pops the arguments into the CPU registers duke@435: SlowSignatureHandler(m, (address)from, m->is_static() ? to+2 : to+1, to).iterate(UCONST64(-1)); duke@435: // return result handler duke@435: return Interpreter::result_handler(m->result_type()); duke@435: IRT_END