1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/runtime/javaCalls.hpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,220 @@ 1.4 +/* 1.5 + * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#ifndef SHARE_VM_RUNTIME_JAVACALLS_HPP 1.29 +#define SHARE_VM_RUNTIME_JAVACALLS_HPP 1.30 + 1.31 +#include "memory/allocation.hpp" 1.32 +#include "oops/method.hpp" 1.33 +#include "runtime/handles.hpp" 1.34 +#include "runtime/javaFrameAnchor.hpp" 1.35 +#include "runtime/thread.inline.hpp" 1.36 +#include "runtime/vmThread.hpp" 1.37 +#ifdef TARGET_ARCH_x86 1.38 +# include "jniTypes_x86.hpp" 1.39 +#endif 1.40 +#ifdef TARGET_ARCH_sparc 1.41 +# include "jniTypes_sparc.hpp" 1.42 +#endif 1.43 +#ifdef TARGET_ARCH_zero 1.44 +# include "jniTypes_zero.hpp" 1.45 +#endif 1.46 +#ifdef TARGET_ARCH_arm 1.47 +# include "jniTypes_arm.hpp" 1.48 +#endif 1.49 +#ifdef TARGET_ARCH_ppc 1.50 +# include "jniTypes_ppc.hpp" 1.51 +#endif 1.52 + 1.53 +// A JavaCallWrapper is constructed before each JavaCall and destructed after the call. 1.54 +// Its purpose is to allocate/deallocate a new handle block and to save/restore the last 1.55 +// Java fp/sp. A pointer to the JavaCallWrapper is stored on the stack. 1.56 + 1.57 +class JavaCallWrapper: StackObj { 1.58 + friend class VMStructs; 1.59 + private: 1.60 + JavaThread* _thread; // the thread to which this call belongs 1.61 + JNIHandleBlock* _handles; // the saved handle block 1.62 + Method* _callee_method; // to be able to collect arguments if entry frame is top frame 1.63 + oop _receiver; // the receiver of the call (if a non-static call) 1.64 + 1.65 + JavaFrameAnchor _anchor; // last thread anchor state that we must restore 1.66 + 1.67 + JavaValue* _result; // result value 1.68 + 1.69 + public: 1.70 + // Construction/destruction 1.71 + JavaCallWrapper(methodHandle callee_method, Handle receiver, JavaValue* result, TRAPS); 1.72 + ~JavaCallWrapper(); 1.73 + 1.74 + // Accessors 1.75 + JavaThread* thread() const { return _thread; } 1.76 + JNIHandleBlock* handles() const { return _handles; } 1.77 + 1.78 + JavaFrameAnchor* anchor(void) { return &_anchor; } 1.79 + 1.80 + JavaValue* result() const { return _result; } 1.81 + // GC support 1.82 + Method* callee_method() { return _callee_method; } 1.83 + oop receiver() { return _receiver; } 1.84 + void oops_do(OopClosure* f); 1.85 + 1.86 + bool is_first_frame() const { return _anchor.last_Java_sp() == NULL; } 1.87 + 1.88 +}; 1.89 + 1.90 + 1.91 +// Encapsulates arguments to a JavaCall (faster, safer, and more convenient than using var-args) 1.92 +class JavaCallArguments : public StackObj { 1.93 + private: 1.94 + enum Constants { 1.95 + _default_size = 8 // Must be at least # of arguments in JavaCalls methods 1.96 + }; 1.97 + 1.98 + intptr_t _value_buffer [_default_size + 1]; 1.99 + bool _is_oop_buffer[_default_size + 1]; 1.100 + 1.101 + intptr_t* _value; 1.102 + bool* _is_oop; 1.103 + int _size; 1.104 + int _max_size; 1.105 + bool _start_at_zero; // Support late setting of receiver 1.106 + 1.107 + void initialize() { 1.108 + // Starts at first element to support set_receiver. 1.109 + _value = &_value_buffer[1]; 1.110 + _is_oop = &_is_oop_buffer[1]; 1.111 + 1.112 + _max_size = _default_size; 1.113 + _size = 0; 1.114 + _start_at_zero = false; 1.115 + } 1.116 + 1.117 + public: 1.118 + JavaCallArguments() { initialize(); } 1.119 + 1.120 + JavaCallArguments(Handle receiver) { 1.121 + initialize(); 1.122 + push_oop(receiver); 1.123 + } 1.124 + 1.125 + JavaCallArguments(int max_size) { 1.126 + if (max_size > _default_size) { 1.127 + _value = NEW_RESOURCE_ARRAY(intptr_t, max_size + 1); 1.128 + _is_oop = NEW_RESOURCE_ARRAY(bool, max_size + 1); 1.129 + 1.130 + // Reserve room for potential receiver in value and is_oop 1.131 + _value++; _is_oop++; 1.132 + 1.133 + _max_size = max_size; 1.134 + _size = 0; 1.135 + _start_at_zero = false; 1.136 + } else { 1.137 + initialize(); 1.138 + } 1.139 + } 1.140 + 1.141 + inline void push_oop(Handle h) { _is_oop[_size] = true; 1.142 + JNITypes::put_obj((oop)h.raw_value(), _value, _size); } 1.143 + 1.144 + inline void push_int(int i) { _is_oop[_size] = false; 1.145 + JNITypes::put_int(i, _value, _size); } 1.146 + 1.147 + inline void push_double(double d) { _is_oop[_size] = false; _is_oop[_size + 1] = false; 1.148 + JNITypes::put_double(d, _value, _size); } 1.149 + 1.150 + inline void push_long(jlong l) { _is_oop[_size] = false; _is_oop[_size + 1] = false; 1.151 + JNITypes::put_long(l, _value, _size); } 1.152 + 1.153 + inline void push_float(float f) { _is_oop[_size] = false; 1.154 + JNITypes::put_float(f, _value, _size); } 1.155 + 1.156 + // receiver 1.157 + Handle receiver() { 1.158 + assert(_size > 0, "must at least be one argument"); 1.159 + assert(_is_oop[0], "first argument must be an oop"); 1.160 + assert(_value[0] != 0, "receiver must be not-null"); 1.161 + return Handle((oop*)_value[0], false); 1.162 + } 1.163 + 1.164 + void set_receiver(Handle h) { 1.165 + assert(_start_at_zero == false, "can only be called once"); 1.166 + _start_at_zero = true; 1.167 + _is_oop--; 1.168 + _value--; 1.169 + _size++; 1.170 + _is_oop[0] = true; 1.171 + _value[0] = (intptr_t)h.raw_value(); 1.172 + } 1.173 + 1.174 + // Converts all Handles to oops, and returns a reference to parameter vector 1.175 + intptr_t* parameters() ; 1.176 + int size_of_parameters() const { return _size; } 1.177 + 1.178 + // Verify that pushed arguments fits a given method 1.179 + void verify(methodHandle method, BasicType return_type, Thread *thread); 1.180 +}; 1.181 + 1.182 +// All calls to Java have to go via JavaCalls. Sets up the stack frame 1.183 +// and makes sure that the last_Java_frame pointers are chained correctly. 1.184 +// 1.185 + 1.186 +class JavaCalls: AllStatic { 1.187 + static void call_helper(JavaValue* result, methodHandle* method, JavaCallArguments* args, TRAPS); 1.188 + public: 1.189 + // Optimized Constuctor call 1.190 + static void call_default_constructor(JavaThread* thread, methodHandle method, Handle receiver, TRAPS); 1.191 + 1.192 + // call_special 1.193 + // ------------ 1.194 + // The receiver must be first oop in argument list 1.195 + static void call_special(JavaValue* result, KlassHandle klass, Symbol* name, Symbol* signature, JavaCallArguments* args, TRAPS); 1.196 + 1.197 + static void call_special(JavaValue* result, Handle receiver, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS); // No args 1.198 + static void call_special(JavaValue* result, Handle receiver, KlassHandle klass, Symbol* name, Symbol* signature, Handle arg1, TRAPS); 1.199 + static void call_special(JavaValue* result, Handle receiver, KlassHandle klass, Symbol* name, Symbol* signature, Handle arg1, Handle arg2, TRAPS); 1.200 + 1.201 + // virtual call 1.202 + // ------------ 1.203 + 1.204 + // The receiver must be first oop in argument list 1.205 + static void call_virtual(JavaValue* result, KlassHandle spec_klass, Symbol* name, Symbol* signature, JavaCallArguments* args, TRAPS); 1.206 + 1.207 + static void call_virtual(JavaValue* result, Handle receiver, KlassHandle spec_klass, Symbol* name, Symbol* signature, TRAPS); // No args 1.208 + static void call_virtual(JavaValue* result, Handle receiver, KlassHandle spec_klass, Symbol* name, Symbol* signature, Handle arg1, TRAPS); 1.209 + static void call_virtual(JavaValue* result, Handle receiver, KlassHandle spec_klass, Symbol* name, Symbol* signature, Handle arg1, Handle arg2, TRAPS); 1.210 + 1.211 + // Static call 1.212 + // ----------- 1.213 + static void call_static(JavaValue* result, KlassHandle klass, Symbol* name, Symbol* signature, JavaCallArguments* args, TRAPS); 1.214 + 1.215 + static void call_static(JavaValue* result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS); 1.216 + static void call_static(JavaValue* result, KlassHandle klass, Symbol* name, Symbol* signature, Handle arg1, TRAPS); 1.217 + static void call_static(JavaValue* result, KlassHandle klass, Symbol* name, Symbol* signature, Handle arg1, Handle arg2, TRAPS); 1.218 + 1.219 + // Low-level interface 1.220 + static void call(JavaValue* result, methodHandle method, JavaCallArguments* args, TRAPS); 1.221 +}; 1.222 + 1.223 +#endif // SHARE_VM_RUNTIME_JAVACALLS_HPP