Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/runtime/javaCalls.hpp
32285 views
/*1* Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_VM_RUNTIME_JAVACALLS_HPP25#define SHARE_VM_RUNTIME_JAVACALLS_HPP2627#include "memory/allocation.hpp"28#include "oops/method.hpp"29#include "runtime/handles.hpp"30#include "runtime/javaFrameAnchor.hpp"31#include "runtime/thread.inline.hpp"32#include "runtime/vmThread.hpp"33#ifdef TARGET_ARCH_x8634# include "jniTypes_x86.hpp"35#endif36#ifdef TARGET_ARCH_aarch3237# include "jniTypes_aarch32.hpp"38#endif39#ifdef TARGET_ARCH_aarch6440# include "jniTypes_aarch64.hpp"41#endif42#ifdef TARGET_ARCH_sparc43# include "jniTypes_sparc.hpp"44#endif45#ifdef TARGET_ARCH_zero46# include "jniTypes_zero.hpp"47#endif48#ifdef TARGET_ARCH_arm49# include "jniTypes_arm.hpp"50#endif51#ifdef TARGET_ARCH_ppc52# include "jniTypes_ppc.hpp"53#endif5455// A JavaCallWrapper is constructed before each JavaCall and destructed after the call.56// Its purpose is to allocate/deallocate a new handle block and to save/restore the last57// Java fp/sp. A pointer to the JavaCallWrapper is stored on the stack.5859class JavaCallWrapper: StackObj {60friend class VMStructs;61private:62JavaThread* _thread; // the thread to which this call belongs63JNIHandleBlock* _handles; // the saved handle block64Method* _callee_method; // to be able to collect arguments if entry frame is top frame65oop _receiver; // the receiver of the call (if a non-static call)6667JavaFrameAnchor _anchor; // last thread anchor state that we must restore6869JavaValue* _result; // result value7071public:72// Construction/destruction73JavaCallWrapper(methodHandle callee_method, Handle receiver, JavaValue* result, TRAPS);74~JavaCallWrapper();7576// Accessors77JavaThread* thread() const { return _thread; }78JNIHandleBlock* handles() const { return _handles; }7980JavaFrameAnchor* anchor(void) { return &_anchor; }8182JavaValue* result() const { return _result; }83// GC support84Method* callee_method() { return _callee_method; }85oop receiver() { return _receiver; }86void oops_do(OopClosure* f);8788bool is_first_frame() const { return _anchor.last_Java_sp() == NULL; }8990};919293// Encapsulates arguments to a JavaCall (faster, safer, and more convenient than using var-args)94class JavaCallArguments : public StackObj {95private:96enum Constants {97_default_size = 8 // Must be at least # of arguments in JavaCalls methods98};99100intptr_t _value_buffer [_default_size + 1];101u_char _value_state_buffer[_default_size + 1];102103intptr_t* _value;104u_char* _value_state;105int _size;106int _max_size;107bool _start_at_zero; // Support late setting of receiver108109void initialize() {110// Starts at first element to support set_receiver.111_value = &_value_buffer[1];112_value_state = &_value_state_buffer[1];113114_max_size = _default_size;115_size = 0;116_start_at_zero = false;117}118119// Helper for push_oop and the like. The value argument is a120// "handle" that refers to an oop. We record the address of the121// handle rather than the designated oop. The handle is later122// resolved to the oop by parameters(). This delays the exposure of123// naked oops until it is GC-safe.124template<typename T>125inline int push_oop_impl(T handle, int size) {126// JNITypes::put_obj expects an oop value, so we play fast and127// loose with the type system. The cast from handle type to oop128// *must* use a C-style cast. In a product build it performs a129// reinterpret_cast. In a debug build (more accurately, in a130// CHECK_UNHANDLED_OOPS build) it performs a static_cast, invoking131// the debug-only oop class's conversion from void* constructor.132JNITypes::put_obj((oop)handle, _value, size); // Updates size.133return size; // Return the updated size.134}135136public:137JavaCallArguments() { initialize(); }138139JavaCallArguments(Handle receiver) {140initialize();141push_oop(receiver);142}143144JavaCallArguments(int max_size) {145if (max_size > _default_size) {146_value = NEW_RESOURCE_ARRAY(intptr_t, max_size + 1);147_value_state = NEW_RESOURCE_ARRAY(u_char, max_size + 1);148149// Reserve room for potential receiver in value and state150_value++;151_value_state++;152153_max_size = max_size;154_size = 0;155_start_at_zero = false;156} else {157initialize();158}159}160161// The possible values for _value_state elements.162enum {163value_state_primitive,164value_state_oop,165value_state_handle,166value_state_jobject,167value_state_limit168};169170inline void push_oop(Handle h) {171_value_state[_size] = value_state_handle;172_size = push_oop_impl(h.raw_value(), _size);173}174175inline void push_jobject(jobject h) {176_value_state[_size] = value_state_jobject;177_size = push_oop_impl(h, _size);178}179180inline void push_int(int i) {181_value_state[_size] = value_state_primitive;182JNITypes::put_int(i, _value, _size);183}184185inline void push_double(double d) {186_value_state[_size] = value_state_primitive;187_value_state[_size + 1] = value_state_primitive;188JNITypes::put_double(d, _value, _size);189}190191inline void push_long(jlong l) {192_value_state[_size] = value_state_primitive;193_value_state[_size + 1] = value_state_primitive;194JNITypes::put_long(l, _value, _size);195}196197inline void push_float(float f) {198_value_state[_size] = value_state_primitive;199JNITypes::put_float(f, _value, _size);200}201202// receiver203Handle receiver() {204assert(_size > 0, "must at least be one argument");205assert(_value_state[0] == value_state_handle,206"first argument must be an oop");207assert(_value[0] != 0, "receiver must be not-null");208return Handle((oop*)_value[0], false);209}210211void set_receiver(Handle h) {212assert(_start_at_zero == false, "can only be called once");213_start_at_zero = true;214_value_state--;215_value--;216_size++;217_value_state[0] = value_state_handle;218push_oop_impl(h.raw_value(), 0);219}220221// Converts all Handles to oops, and returns a reference to parameter vector222intptr_t* parameters() ;223int size_of_parameters() const { return _size; }224225// Verify that pushed arguments fits a given method226void verify(methodHandle method, BasicType return_type);227};228229// All calls to Java have to go via JavaCalls. Sets up the stack frame230// and makes sure that the last_Java_frame pointers are chained correctly.231//232233class JavaCalls: AllStatic {234static void call_helper(JavaValue* result, methodHandle* method, JavaCallArguments* args, TRAPS);235public:236// Optimized Constuctor call237static void call_default_constructor(JavaThread* thread, methodHandle method, Handle receiver, TRAPS);238239// call_special240// ------------241// The receiver must be first oop in argument list242static void call_special(JavaValue* result, KlassHandle klass, Symbol* name, Symbol* signature, JavaCallArguments* args, TRAPS);243244static void call_special(JavaValue* result, Handle receiver, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS); // No args245static void call_special(JavaValue* result, Handle receiver, KlassHandle klass, Symbol* name, Symbol* signature, Handle arg1, TRAPS);246static void call_special(JavaValue* result, Handle receiver, KlassHandle klass, Symbol* name, Symbol* signature, Handle arg1, Handle arg2, TRAPS);247248// virtual call249// ------------250251// The receiver must be first oop in argument list252static void call_virtual(JavaValue* result, KlassHandle spec_klass, Symbol* name, Symbol* signature, JavaCallArguments* args, TRAPS);253254static void call_virtual(JavaValue* result, Handle receiver, KlassHandle spec_klass, Symbol* name, Symbol* signature, TRAPS); // No args255static void call_virtual(JavaValue* result, Handle receiver, KlassHandle spec_klass, Symbol* name, Symbol* signature, Handle arg1, TRAPS);256static void call_virtual(JavaValue* result, Handle receiver, KlassHandle spec_klass, Symbol* name, Symbol* signature, Handle arg1, Handle arg2, TRAPS);257258// Static call259// -----------260static void call_static(JavaValue* result, KlassHandle klass, Symbol* name, Symbol* signature, JavaCallArguments* args, TRAPS);261262static void call_static(JavaValue* result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS);263static void call_static(JavaValue* result, KlassHandle klass, Symbol* name, Symbol* signature, Handle arg1, TRAPS);264static void call_static(JavaValue* result, KlassHandle klass, Symbol* name, Symbol* signature, Handle arg1, Handle arg2, TRAPS);265266// Low-level interface267static void call(JavaValue* result, methodHandle method, JavaCallArguments* args, TRAPS);268};269270#endif // SHARE_VM_RUNTIME_JAVACALLS_HPP271272273