0N/A/*
1472N/A * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
1879N/A#include "precompiled.hpp"
1879N/A#include "interpreter/interpreter.hpp"
1879N/A#include "interpreter/interpreterRuntime.hpp"
1879N/A#include "memory/allocation.inline.hpp"
1879N/A#include "memory/universe.inline.hpp"
1879N/A#include "oops/methodOop.hpp"
1879N/A#include "oops/oop.inline.hpp"
1879N/A#include "runtime/handles.inline.hpp"
1879N/A#include "runtime/icache.hpp"
1879N/A#include "runtime/interfaceSupport.hpp"
1879N/A#include "runtime/signature.hpp"
0N/A
0N/A
0N/A#define __ _masm->
0N/A
0N/A
0N/A// Implementation of SignatureHandlerGenerator
0N/A
0N/Avoid InterpreterRuntime::SignatureHandlerGenerator::pass_word(int size_of_arg, int offset_in_arg) {
0N/A Argument jni_arg(jni_offset() + offset_in_arg, false);
0N/A Register Rtmp = O0;
0N/A __ ld(Llocals, Interpreter::local_offset_in_bytes(offset()), Rtmp);
0N/A
0N/A __ store_argument(Rtmp, jni_arg);
0N/A}
0N/A
0N/Avoid InterpreterRuntime::SignatureHandlerGenerator::pass_long() {
0N/A Argument jni_arg(jni_offset(), false);
0N/A Register Rtmp = O0;
0N/A
0N/A#ifdef _LP64
0N/A __ ldx(Llocals, Interpreter::local_offset_in_bytes(offset() + 1), Rtmp);
0N/A __ store_long_argument(Rtmp, jni_arg);
0N/A#else
0N/A __ ld(Llocals, Interpreter::local_offset_in_bytes(offset() + 1), Rtmp);
0N/A __ store_argument(Rtmp, jni_arg);
0N/A __ ld(Llocals, Interpreter::local_offset_in_bytes(offset() + 0), Rtmp);
0N/A Argument successor(jni_arg.successor());
0N/A __ store_argument(Rtmp, successor);
0N/A#endif
0N/A}
0N/A
0N/A
0N/Avoid InterpreterRuntime::SignatureHandlerGenerator::pass_float() {
0N/A Argument jni_arg(jni_offset(), false);
1601N/A#ifdef _LP64
0N/A FloatRegister Rtmp = F0;
0N/A __ ldf(FloatRegisterImpl::S, Llocals, Interpreter::local_offset_in_bytes(offset()), Rtmp);
0N/A __ store_float_argument(Rtmp, jni_arg);
1601N/A#else
1601N/A Register Rtmp = O0;
1601N/A __ ld(Llocals, Interpreter::local_offset_in_bytes(offset()), Rtmp);
1601N/A __ store_argument(Rtmp, jni_arg);
1601N/A#endif
0N/A}
0N/A
0N/A
0N/Avoid InterpreterRuntime::SignatureHandlerGenerator::pass_double() {
0N/A Argument jni_arg(jni_offset(), false);
0N/A#ifdef _LP64
0N/A FloatRegister Rtmp = F0;
0N/A __ ldf(FloatRegisterImpl::D, Llocals, Interpreter::local_offset_in_bytes(offset() + 1), Rtmp);
0N/A __ store_double_argument(Rtmp, jni_arg);
0N/A#else
0N/A Register Rtmp = O0;
0N/A __ ld(Llocals, Interpreter::local_offset_in_bytes(offset() + 1), Rtmp);
0N/A __ store_argument(Rtmp, jni_arg);
0N/A __ ld(Llocals, Interpreter::local_offset_in_bytes(offset()), Rtmp);
0N/A Argument successor(jni_arg.successor());
0N/A __ store_argument(Rtmp, successor);
0N/A#endif
0N/A}
0N/A
0N/Avoid InterpreterRuntime::SignatureHandlerGenerator::pass_object() {
0N/A Argument jni_arg(jni_offset(), false);
0N/A Argument java_arg( offset(), true);
0N/A Register Rtmp1 = O0;
0N/A Register Rtmp2 = jni_arg.is_register() ? jni_arg.as_register() : O0;
0N/A Register Rtmp3 = G3_scratch;
0N/A
0N/A // the handle for a receiver will never be null
0N/A bool do_NULL_check = offset() != 0 || is_static();
0N/A
727N/A Address h_arg = Address(Llocals, Interpreter::local_offset_in_bytes(offset()));
0N/A __ ld_ptr(h_arg, Rtmp1);
0N/A if (!do_NULL_check) {
727N/A __ add(h_arg.base(), h_arg.disp(), Rtmp2);
0N/A } else {
0N/A if (Rtmp1 == Rtmp2)
0N/A __ tst(Rtmp1);
0N/A else __ addcc(G0, Rtmp1, Rtmp2); // optimize mov/test pair
0N/A Label L;
0N/A __ brx(Assembler::notZero, true, Assembler::pt, L);
727N/A __ delayed()->add(h_arg.base(), h_arg.disp(), Rtmp2);
0N/A __ bind(L);
0N/A }
0N/A __ store_ptr_argument(Rtmp2, jni_arg); // this is often a no-op
0N/A}
0N/A
0N/A
0N/Avoid InterpreterRuntime::SignatureHandlerGenerator::generate(uint64_t fingerprint) {
0N/A
0N/A // generate code to handle arguments
0N/A iterate(fingerprint);
0N/A
0N/A // return result handler
727N/A AddressLiteral result_handler(Interpreter::result_handler(method()->result_type()));
727N/A __ sethi(result_handler, Lscratch);
0N/A __ retl();
727N/A __ delayed()->add(Lscratch, result_handler.low10(), Lscratch);
0N/A
0N/A __ flush();
0N/A}
0N/A
0N/A
0N/A// Implementation of SignatureHandlerLibrary
0N/A
0N/Avoid SignatureHandlerLibrary::pd_set_handler(address handler) {}
0N/A
0N/A
0N/Aclass SlowSignatureHandler: public NativeSignatureIterator {
0N/A private:
0N/A address _from;
0N/A intptr_t* _to;
0N/A intptr_t* _RegArgSignature; // Signature of first Arguments to be passed in Registers
0N/A uint _argcount;
0N/A
0N/A enum { // We need to differenciate float from non floats in reg args
0N/A non_float = 0,
0N/A float_sig = 1,
0N/A double_sig = 2,
0N/A long_sig = 3
0N/A };
0N/A
0N/A virtual void pass_int() {
0N/A *_to++ = *(jint *)(_from+Interpreter::local_offset_in_bytes(0));
1426N/A _from -= Interpreter::stackElementSize;
0N/A add_signature( non_float );
0N/A }
0N/A
0N/A virtual void pass_object() {
0N/A // pass address of from
0N/A intptr_t *from_addr = (intptr_t*)(_from + Interpreter::local_offset_in_bytes(0));
0N/A *_to++ = (*from_addr == 0) ? NULL : (intptr_t) from_addr;
1426N/A _from -= Interpreter::stackElementSize;
0N/A add_signature( non_float );
0N/A }
0N/A
0N/A#ifdef _LP64
0N/A virtual void pass_float() {
0N/A *_to++ = *(jint *)(_from+Interpreter::local_offset_in_bytes(0));
1426N/A _from -= Interpreter::stackElementSize;
0N/A add_signature( float_sig );
0N/A }
0N/A
0N/A virtual void pass_double() {
0N/A *_to++ = *(intptr_t*)(_from+Interpreter::local_offset_in_bytes(1));
1426N/A _from -= 2*Interpreter::stackElementSize;
0N/A add_signature( double_sig );
0N/A }
0N/A
0N/A virtual void pass_long() {
0N/A _to[0] = *(intptr_t*)(_from+Interpreter::local_offset_in_bytes(1));
0N/A _to += 1;
1426N/A _from -= 2*Interpreter::stackElementSize;
0N/A add_signature( long_sig );
0N/A }
0N/A#else
0N/A // pass_double() is pass_long() and pass_float() only _LP64
0N/A virtual void pass_long() {
0N/A _to[0] = *(intptr_t*)(_from+Interpreter::local_offset_in_bytes(1));
0N/A _to[1] = *(intptr_t*)(_from+Interpreter::local_offset_in_bytes(0));
0N/A _to += 2;
1426N/A _from -= 2*Interpreter::stackElementSize;
0N/A add_signature( non_float );
0N/A }
1601N/A
1601N/A virtual void pass_float() {
1601N/A *_to++ = *(jint *)(_from+Interpreter::local_offset_in_bytes(0));
1601N/A _from -= Interpreter::stackElementSize;
1601N/A add_signature( non_float );
1601N/A }
1601N/A
0N/A#endif // _LP64
0N/A
0N/A virtual void add_signature( intptr_t sig_type ) {
0N/A if ( _argcount < (sizeof (intptr_t))*4 ) {
0N/A *_RegArgSignature |= (sig_type << (_argcount*2) );
0N/A _argcount++;
0N/A }
0N/A }
0N/A
0N/A
0N/A public:
0N/A SlowSignatureHandler(methodHandle method, address from, intptr_t* to, intptr_t *RegArgSig) : NativeSignatureIterator(method) {
0N/A _from = from;
0N/A _to = to;
0N/A _RegArgSignature = RegArgSig;
0N/A *_RegArgSignature = 0;
0N/A _argcount = method->is_static() ? 2 : 1;
0N/A }
0N/A};
0N/A
0N/A
0N/AIRT_ENTRY(address, InterpreterRuntime::slow_signature_handler(
0N/A JavaThread* thread,
0N/A methodOopDesc* method,
0N/A intptr_t* from,
0N/A intptr_t* to ))
0N/A methodHandle m(thread, method);
0N/A assert(m->is_native(), "sanity check");
0N/A // handle arguments
0N/A // Warning: We use reg arg slot 00 temporarily to return the RegArgSignature
0N/A // back to the code that pops the arguments into the CPU registers
0N/A SlowSignatureHandler(m, (address)from, m->is_static() ? to+2 : to+1, to).iterate(UCONST64(-1));
0N/A // return result handler
0N/A return Interpreter::result_handler(m->result_type());
0N/AIRT_END