Path: blob/master/src/hotspot/share/runtime/javaCalls.hpp
40951 views
/*1* Copyright (c) 1997, 2019, 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_RUNTIME_JAVACALLS_HPP25#define SHARE_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.hpp"32#include "runtime/vmThread.hpp"33#include "utilities/macros.hpp"3435#include CPU_HEADER(jniTypes)3637// A JavaCallWrapper is constructed before each JavaCall and destructed after the call.38// Its purpose is to allocate/deallocate a new handle block and to save/restore the last39// Java fp/sp. A pointer to the JavaCallWrapper is stored on the stack.4041class JavaCallWrapper: StackObj {42friend class VMStructs;43private:44JavaThread* _thread; // the thread to which this call belongs45JNIHandleBlock* _handles; // the saved handle block46Method* _callee_method; // to be able to collect arguments if entry frame is top frame47oop _receiver; // the receiver of the call (if a non-static call)4849JavaFrameAnchor _anchor; // last thread anchor state that we must restore5051JavaValue* _result; // result value5253public:54// Construction/destruction55JavaCallWrapper(const methodHandle& callee_method, Handle receiver, JavaValue* result, TRAPS);56~JavaCallWrapper();5758// Accessors59JavaThread* thread() const { return _thread; }60JNIHandleBlock* handles() const { return _handles; }6162JavaFrameAnchor* anchor(void) { return &_anchor; }6364JavaValue* result() const { return _result; }65// GC support66Method* callee_method() { return _callee_method; }67oop receiver() { return _receiver; }68void oops_do(OopClosure* f);6970bool is_first_frame() const { return _anchor.last_Java_sp() == NULL; }7172};737475// Encapsulates arguments to a JavaCall (faster, safer, and more convenient than using var-args)76class JavaCallArguments : public StackObj {77private:78enum Constants {79_default_size = 8 // Must be at least # of arguments in JavaCalls methods80};8182intptr_t _value_buffer [_default_size + 1];83u_char _value_state_buffer[_default_size + 1];8485intptr_t* _value;86u_char* _value_state;87int _size;88int _max_size;89bool _start_at_zero; // Support late setting of receiver90#if INCLUDE_JVMCI91Handle _alternative_target; // HotSpotNmethod wrapping an nmethod whose verified entry point92// should be called instead of the normal target93#endif9495void initialize() {96// Starts at first element to support set_receiver.97_value = &_value_buffer[1];98_value_state = &_value_state_buffer[1];99100_max_size = _default_size;101_size = 0;102_start_at_zero = false;103}104105public:106JavaCallArguments() { initialize(); }107108JavaCallArguments(Handle receiver) {109initialize();110push_oop(receiver);111}112113JavaCallArguments(int max_size) {114if (max_size > _default_size) {115_value = NEW_RESOURCE_ARRAY(intptr_t, max_size + 1);116_value_state = NEW_RESOURCE_ARRAY(u_char, max_size + 1);117118// Reserve room for potential receiver in value and state119_value++;120_value_state++;121122_max_size = max_size;123_size = 0;124_start_at_zero = false;125} else {126initialize();127}128}129130#if INCLUDE_JVMCI131void set_alternative_target(Handle target) {132_alternative_target = target;133}134135Handle alternative_target() {136return _alternative_target;137}138#endif139140// The possible values for _value_state elements.141enum {142value_state_primitive,143value_state_oop,144value_state_handle,145value_state_jobject,146value_state_limit147};148149inline void push_oop(Handle h) {150_value_state[_size] = value_state_handle;151JNITypes::put_obj(h, _value, _size);152}153154inline void push_jobject(jobject h) {155_value_state[_size] = value_state_jobject;156JNITypes::put_obj(h, _value, _size);157}158159inline void push_int(int i) {160_value_state[_size] = value_state_primitive;161JNITypes::put_int(i, _value, _size);162}163164inline void push_double(double d) {165_value_state[_size] = value_state_primitive;166_value_state[_size + 1] = value_state_primitive;167JNITypes::put_double(d, _value, _size);168}169170inline void push_long(jlong l) {171_value_state[_size] = value_state_primitive;172_value_state[_size + 1] = value_state_primitive;173JNITypes::put_long(l, _value, _size);174}175176inline void push_float(float f) {177_value_state[_size] = value_state_primitive;178JNITypes::put_float(f, _value, _size);179}180181// receiver182Handle receiver() {183assert(_size > 0, "must at least be one argument");184assert(_value_state[0] == value_state_handle,185"first argument must be an oop");186assert(_value[0] != 0, "receiver must be not-null");187return Handle((oop*)_value[0], false);188}189190void set_receiver(Handle h) {191assert(_start_at_zero == false, "can only be called once");192_start_at_zero = true;193_value_state--;194_value--;195_size++;196_value_state[0] = value_state_handle;197198int size = 0;199JNITypes::put_obj(h, _value, size);200}201202// Converts all Handles to oops, and returns a reference to parameter vector203intptr_t* parameters() ;204int size_of_parameters() const { return _size; }205206// Verify that pushed arguments fits a given method207void verify(const methodHandle& method, BasicType return_type);208};209210// All calls to Java have to go via JavaCalls. Sets up the stack frame211// and makes sure that the last_Java_frame pointers are chained correctly.212//213214class JavaCalls: AllStatic {215static void call_helper(JavaValue* result, const methodHandle& method, JavaCallArguments* args, TRAPS);216public:217// call_special218// ------------219// The receiver must be first oop in argument list220static void call_special(JavaValue* result, Klass* klass, Symbol* name, Symbol* signature, JavaCallArguments* args, TRAPS);221222static void call_special(JavaValue* result, Handle receiver, Klass* klass, Symbol* name, Symbol* signature, TRAPS); // No args223static void call_special(JavaValue* result, Handle receiver, Klass* klass, Symbol* name, Symbol* signature, Handle arg1, TRAPS);224static void call_special(JavaValue* result, Handle receiver, Klass* klass, Symbol* name, Symbol* signature, Handle arg1, Handle arg2, TRAPS);225226// virtual call227// ------------228229// The receiver must be first oop in argument list230static void call_virtual(JavaValue* result, Klass* spec_klass, Symbol* name, Symbol* signature, JavaCallArguments* args, TRAPS);231232static void call_virtual(JavaValue* result, Handle receiver, Klass* spec_klass, Symbol* name, Symbol* signature, TRAPS); // No args233static void call_virtual(JavaValue* result, Handle receiver, Klass* spec_klass, Symbol* name, Symbol* signature, Handle arg1, TRAPS);234static void call_virtual(JavaValue* result, Handle receiver, Klass* spec_klass, Symbol* name, Symbol* signature, Handle arg1, Handle arg2, TRAPS);235236// Static call237// -----------238static void call_static(JavaValue* result, Klass* klass, Symbol* name, Symbol* signature, JavaCallArguments* args, TRAPS);239240static void call_static(JavaValue* result, Klass* klass, Symbol* name, Symbol* signature, TRAPS);241static void call_static(JavaValue* result, Klass* klass, Symbol* name, Symbol* signature, Handle arg1, TRAPS);242static void call_static(JavaValue* result, Klass* klass, Symbol* name, Symbol* signature, Handle arg1, Handle arg2, TRAPS);243static void call_static(JavaValue* result, Klass* klass, Symbol* name, Symbol* signature, Handle arg1, Handle arg2, Handle arg3, TRAPS);244245// Allocate instance + invoke constructor. This is equivalent to "new Klass(args ...)" expression in Java code.246static Handle construct_new_instance(InstanceKlass* klass, Symbol* constructor_signature, JavaCallArguments* args, TRAPS);247248static Handle construct_new_instance(InstanceKlass* klass, Symbol* constructor_signature, TRAPS);249static Handle construct_new_instance(InstanceKlass* klass, Symbol* constructor_signature, Handle arg1, TRAPS);250static Handle construct_new_instance(InstanceKlass* klass, Symbol* constructor_signature, Handle arg1, Handle arg2, TRAPS);251252// Low-level interface253static void call(JavaValue* result, const methodHandle& method, JavaCallArguments* args, TRAPS);254};255256#endif // SHARE_RUNTIME_JAVACALLS_HPP257258259