Path: blob/master/src/hotspot/cpu/zero/interpreterRT_zero.cpp
40931 views
/*1* Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.2* Copyright 2007, 2008, 2010 Red Hat, Inc.3* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.4*5* This code is free software; you can redistribute it and/or modify it6* under the terms of the GNU General Public License version 2 only, as7* published by the Free Software Foundation.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 2 along with this work; if not, write to the Free Software Foundation,17* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.18*19* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*23*/2425#include "precompiled.hpp"26#include "interpreter/interpreter.hpp"27#include "interpreter/interpreterRuntime.hpp"28#include "memory/allocation.inline.hpp"29#include "oops/method.hpp"30#include "oops/oop.inline.hpp"31#include "runtime/handles.inline.hpp"32#include "runtime/icache.hpp"33#include "runtime/interfaceSupport.inline.hpp"34#include "runtime/signature.hpp"35#include "stack_zero.inline.hpp"36#include "utilities/align.hpp"3738void InterpreterRuntime::SignatureHandlerGeneratorBase::pass_int() {39push(T_INT);40_cif->nargs++;41}4243void InterpreterRuntime::SignatureHandlerGeneratorBase::pass_long() {44push(T_LONG);45_cif->nargs++;46}4748void InterpreterRuntime::SignatureHandlerGeneratorBase::pass_float() {49push(T_FLOAT);50_cif->nargs++;51}5253void InterpreterRuntime::SignatureHandlerGeneratorBase::pass_double() {54push(T_DOUBLE);55_cif->nargs++;56}5758void InterpreterRuntime::SignatureHandlerGeneratorBase::pass_object() {59push(T_OBJECT);60_cif->nargs++;61}6263void InterpreterRuntime::SignatureHandlerGeneratorBase::push(BasicType type) {64ffi_type *ftype = NULL;65switch (type) {66case T_VOID:67ftype = &ffi_type_void;68break;6970case T_BOOLEAN:71ftype = &ffi_type_uint8;72break;7374case T_CHAR:75ftype = &ffi_type_uint16;76break;7778case T_BYTE:79ftype = &ffi_type_sint8;80break;8182case T_SHORT:83ftype = &ffi_type_sint16;84break;8586case T_INT:87ftype = &ffi_type_sint32;88break;8990case T_LONG:91ftype = &ffi_type_sint64;92break;9394case T_FLOAT:95ftype = &ffi_type_float;96break;9798case T_DOUBLE:99ftype = &ffi_type_double;100break;101102case T_OBJECT:103case T_ARRAY:104ftype = &ffi_type_pointer;105break;106107default:108ShouldNotReachHere();109}110push((intptr_t) ftype);111}112113// For fast signature handlers the "signature handler" is generated114// into a temporary buffer. It is then copied to its final location,115// and pd_set_handler is called on it. We have this two stage thing116// to accomodate this.117118void InterpreterRuntime::SignatureHandlerGeneratorBase::generate(119uint64_t fingerprint) {120121// Build the argument types list122pass_object();123if (method()->is_static())124pass_object();125iterate(fingerprint);126127// Tack on the result type128push(method()->result_type());129}130131InterpreterRuntime::SignatureHandlerGenerator::SignatureHandlerGenerator(const methodHandle& method, CodeBuffer* buffer)132: SignatureHandlerGeneratorBase(method, (ffi_cif *) buffer->insts_end()),133_cb(buffer) {134_cb->set_insts_end((address) (cif() + 1));135}136137void InterpreterRuntime::SignatureHandlerGenerator::push(intptr_t value) {138intptr_t *dst = (intptr_t *) _cb->insts_end();139_cb->set_insts_end((address) (dst + 1));140*dst = value;141}142143void InterpreterRuntime::SignatureHandler::finalize() {144ffi_status status =145ffi_prep_cif(cif(),146FFI_DEFAULT_ABI,147argument_count(),148result_type(),149argument_types());150151assert(status == FFI_OK, "should be");152}153154JRT_ENTRY(address,155InterpreterRuntime::slow_signature_handler(JavaThread* current,156Method* method,157intptr_t* unused1,158intptr_t* unused2))159ZeroStack *stack = current->zero_stack();160161int required_words =162(align_up(sizeof(ffi_cif), wordSize) >> LogBytesPerWord) +163(method->is_static() ? 2 : 1) + method->size_of_parameters() + 1;164165stack->overflow_check(required_words, CHECK_NULL);166167intptr_t *buf = (intptr_t *) stack->alloc(required_words * wordSize);168SlowSignatureHandlerGenerator sshg(methodHandle(current, method), buf);169sshg.generate((uint64_t)CONST64(-1));170171SignatureHandler *handler = sshg.handler();172handler->finalize();173174return (address) handler;175JRT_END176177void SignatureHandlerLibrary::pd_set_handler(address handlerAddr) {178InterpreterRuntime::SignatureHandler *handler =179InterpreterRuntime::SignatureHandler::from_handlerAddr(handlerAddr);180181handler->finalize();182}183184185