1010N/A/*
1879N/A * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
1379N/A * Copyright 2007, 2008, 2010 Red Hat, Inc.
1010N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1010N/A *
1010N/A * This code is free software; you can redistribute it and/or modify it
1010N/A * under the terms of the GNU General Public License version 2 only, as
1010N/A * published by the Free Software Foundation.
1010N/A *
1010N/A * This code is distributed in the hope that it will be useful, but WITHOUT
1010N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1010N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1010N/A * version 2 for more details (a copy is included in the LICENSE file that
1010N/A * accompanied this code).
1010N/A *
1010N/A * You should have received a copy of the GNU General Public License version
1010N/A * 2 along with this work; if not, write to the Free Software Foundation,
1010N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1010N/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.
1010N/A *
1010N/A */
1010N/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"
1879N/A#include "stack_zero.inline.hpp"
1010N/A
1010N/Avoid InterpreterRuntime::SignatureHandlerGeneratorBase::pass_int() {
1010N/A push(T_INT);
1010N/A _cif->nargs++;
1010N/A}
1010N/A
1010N/Avoid InterpreterRuntime::SignatureHandlerGeneratorBase::pass_long() {
1010N/A push(T_LONG);
1010N/A _cif->nargs++;
1010N/A}
1010N/A
1010N/Avoid InterpreterRuntime::SignatureHandlerGeneratorBase::pass_float() {
1010N/A push(T_FLOAT);
1010N/A _cif->nargs++;
1010N/A}
1010N/A
1010N/Avoid InterpreterRuntime::SignatureHandlerGeneratorBase::pass_double() {
1010N/A push(T_DOUBLE);
1010N/A _cif->nargs++;
1010N/A}
1010N/A
1010N/Avoid InterpreterRuntime::SignatureHandlerGeneratorBase::pass_object() {
1010N/A push(T_OBJECT);
1010N/A _cif->nargs++;
1010N/A}
1010N/A
1010N/Avoid InterpreterRuntime::SignatureHandlerGeneratorBase::push(BasicType type) {
1010N/A ffi_type *ftype;
1010N/A switch (type) {
1010N/A case T_VOID:
1010N/A ftype = &ffi_type_void;
1010N/A break;
1010N/A
1010N/A case T_BOOLEAN:
1010N/A ftype = &ffi_type_uint8;
1010N/A break;
1010N/A
1010N/A case T_CHAR:
1010N/A ftype = &ffi_type_uint16;
1010N/A break;
1010N/A
1010N/A case T_BYTE:
1010N/A ftype = &ffi_type_sint8;
1010N/A break;
1010N/A
1010N/A case T_SHORT:
1010N/A ftype = &ffi_type_sint16;
1010N/A break;
1010N/A
1010N/A case T_INT:
1010N/A ftype = &ffi_type_sint32;
1010N/A break;
1010N/A
1010N/A case T_LONG:
1010N/A ftype = &ffi_type_sint64;
1010N/A break;
1010N/A
1010N/A case T_FLOAT:
1010N/A ftype = &ffi_type_float;
1010N/A break;
1010N/A
1010N/A case T_DOUBLE:
1010N/A ftype = &ffi_type_double;
1010N/A break;
1010N/A
1010N/A case T_OBJECT:
1010N/A case T_ARRAY:
1010N/A ftype = &ffi_type_pointer;
1010N/A break;
1010N/A
1010N/A default:
1010N/A ShouldNotReachHere();
1010N/A }
1010N/A push((intptr_t) ftype);
1010N/A}
1010N/A
1010N/A// For fast signature handlers the "signature handler" is generated
1010N/A// into a temporary buffer. It is then copied to its final location,
1010N/A// and pd_set_handler is called on it. We have this two stage thing
1010N/A// to accomodate this.
1010N/A
1010N/Avoid InterpreterRuntime::SignatureHandlerGeneratorBase::generate(
1010N/A uint64_t fingerprint) {
1010N/A
1010N/A // Build the argument types list
1010N/A pass_object();
1010N/A if (method()->is_static())
1010N/A pass_object();
1010N/A iterate(fingerprint);
1010N/A
1010N/A // Tack on the result type
1010N/A push(method()->result_type());
1010N/A}
1010N/A
1010N/Avoid InterpreterRuntime::SignatureHandler::finalize() {
1010N/A ffi_status status =
1010N/A ffi_prep_cif(cif(),
1010N/A FFI_DEFAULT_ABI,
1010N/A argument_count(),
1010N/A result_type(),
1010N/A argument_types());
1010N/A
1010N/A assert(status == FFI_OK, "should be");
1010N/A}
1010N/A
1010N/AIRT_ENTRY(address,
1010N/A InterpreterRuntime::slow_signature_handler(JavaThread* thread,
1010N/A methodOop method,
1010N/A intptr_t* unused1,
1010N/A intptr_t* unused2))
1010N/A ZeroStack *stack = thread->zero_stack();
1010N/A
1010N/A int required_words =
1010N/A (align_size_up(sizeof(ffi_cif), wordSize) >> LogBytesPerWord) +
1010N/A (method->is_static() ? 2 : 1) + method->size_of_parameters() + 1;
1379N/A
1379N/A stack->overflow_check(required_words, CHECK_NULL);
1010N/A
1010N/A intptr_t *buf = (intptr_t *) stack->alloc(required_words * wordSize);
1010N/A SlowSignatureHandlerGenerator sshg(methodHandle(thread, method), buf);
1010N/A sshg.generate(UCONST64(-1));
1010N/A
1010N/A SignatureHandler *handler = sshg.handler();
1010N/A handler->finalize();
1010N/A
1010N/A return (address) handler;
1010N/AIRT_END
1010N/A
1010N/Avoid SignatureHandlerLibrary::pd_set_handler(address handlerAddr) {
1010N/A InterpreterRuntime::SignatureHandler *handler =
1010N/A InterpreterRuntime::SignatureHandler::from_handlerAddr(handlerAddr);
1010N/A
1010N/A handler->finalize();
1010N/A}