duke@435: /* coleenp@4037: * Copyright (c) 1998, 2012, 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" coleenp@4037: #include "oops/method.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: void InterpreterRuntime::SignatureHandlerGenerator::pass_int() { duke@435: move(offset(), jni_offset() + 1); duke@435: } duke@435: bobv@2036: void InterpreterRuntime::SignatureHandlerGenerator::pass_float() { bobv@2036: move(offset(), jni_offset() + 1); bobv@2036: } bobv@2036: duke@435: void InterpreterRuntime::SignatureHandlerGenerator::pass_long() { duke@435: move(offset(), jni_offset() + 2); duke@435: move(offset() + 1, jni_offset() + 1); duke@435: } duke@435: duke@435: void InterpreterRuntime::SignatureHandlerGenerator::pass_object() { duke@435: box (offset(), jni_offset() + 1); duke@435: } duke@435: duke@435: void InterpreterRuntime::SignatureHandlerGenerator::move(int from_offset, int to_offset) { duke@435: __ movl(temp(), Address(from(), Interpreter::local_offset_in_bytes(from_offset))); duke@435: __ movl(Address(to(), to_offset * wordSize), temp()); duke@435: } duke@435: duke@435: duke@435: void InterpreterRuntime::SignatureHandlerGenerator::box(int from_offset, int to_offset) { never@739: __ lea(temp(), Address(from(), Interpreter::local_offset_in_bytes(from_offset))); never@739: __ cmpptr(Address(from(), Interpreter::local_offset_in_bytes(from_offset)), (int32_t)NULL_WORD); // do not use temp() to avoid AGI duke@435: Label L; duke@435: __ jcc(Assembler::notZero, L); xlu@947: __ movptr(temp(), NULL_WORD); duke@435: __ bind(L); never@739: __ movptr(Address(to(), to_offset * wordSize), temp()); duke@435: } duke@435: duke@435: duke@435: void InterpreterRuntime::SignatureHandlerGenerator::generate( uint64_t fingerprint) { duke@435: // generate code to handle arguments duke@435: iterate(fingerprint); duke@435: // return result handler duke@435: __ lea(rax, duke@435: ExternalAddress((address)Interpreter::result_handler(method()->result_type()))); duke@435: // return duke@435: __ ret(0); duke@435: __ flush(); duke@435: } duke@435: duke@435: duke@435: Register InterpreterRuntime::SignatureHandlerGenerator::from() { return rdi; } duke@435: Register InterpreterRuntime::SignatureHandlerGenerator::to() { return rsp; } duke@435: Register InterpreterRuntime::SignatureHandlerGenerator::temp() { return rcx; } duke@435: duke@435: duke@435: // Implementation of SignatureHandlerLibrary duke@435: duke@435: void SignatureHandlerLibrary::pd_set_handler(address handler) {} duke@435: duke@435: class SlowSignatureHandler: public NativeSignatureIterator { duke@435: private: duke@435: address _from; duke@435: intptr_t* _to; 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: } duke@435: bobv@2036: virtual void pass_float() { bobv@2036: *_to++ = *(jint *)(_from+Interpreter::local_offset_in_bytes(0)); bobv@2036: _from -= Interpreter::stackElementSize; bobv@2036: } bobv@2036: 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: } 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)); xlu@968: *_to++ = (*(intptr_t*)from_addr == 0) ? NULL_WORD : from_addr; twisti@1861: _from -= Interpreter::stackElementSize; duke@435: } duke@435: duke@435: public: duke@435: SlowSignatureHandler(methodHandle method, address from, intptr_t* to) : duke@435: NativeSignatureIterator(method) { duke@435: _from = from; duke@435: _to = to + (is_static() ? 2 : 1); duke@435: } duke@435: }; duke@435: coleenp@4037: IRT_ENTRY(address, InterpreterRuntime::slow_signature_handler(JavaThread* thread, Method* method, intptr_t* from, intptr_t* to)) coleenp@4037: methodHandle m(thread, (Method*)method); duke@435: assert(m->is_native(), "sanity check"); duke@435: // handle arguments duke@435: SlowSignatureHandler(m, (address)from, to + 1).iterate(UCONST64(-1)); duke@435: // return result handler duke@435: return Interpreter::result_handler(m->result_type()); duke@435: IRT_END