src/share/vm/runtime/javaCalls.hpp

Wed, 14 Oct 2020 17:44:48 +0800

author
aoqi
date
Wed, 14 Oct 2020 17:44:48 +0800
changeset 9931
fd44df5e3bc3
parent 9703
2fdf635bcf28
permissions
-rw-r--r--

Merge

duke@435 1 /*
phh@9669 2 * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
aoqi@1 25 /*
aoqi@1 26 * This file has been modified by Loongson Technology in 2015. These
aoqi@1 27 * modifications are Copyright (c) 2015 Loongson Technology, and are made
aoqi@1 28 * available on the same license terms set forth above.
aoqi@1 29 */
aoqi@1 30
stefank@2314 31 #ifndef SHARE_VM_RUNTIME_JAVACALLS_HPP
stefank@2314 32 #define SHARE_VM_RUNTIME_JAVACALLS_HPP
stefank@2314 33
stefank@2314 34 #include "memory/allocation.hpp"
coleenp@4037 35 #include "oops/method.hpp"
stefank@2314 36 #include "runtime/handles.hpp"
stefank@2314 37 #include "runtime/javaFrameAnchor.hpp"
stefank@4299 38 #include "runtime/thread.inline.hpp"
stefank@2314 39 #include "runtime/vmThread.hpp"
stefank@2314 40 #ifdef TARGET_ARCH_x86
stefank@2314 41 # include "jniTypes_x86.hpp"
stefank@2314 42 #endif
stefank@2314 43 #ifdef TARGET_ARCH_sparc
stefank@2314 44 # include "jniTypes_sparc.hpp"
stefank@2314 45 #endif
stefank@2314 46 #ifdef TARGET_ARCH_zero
stefank@2314 47 # include "jniTypes_zero.hpp"
stefank@2314 48 #endif
bobv@2508 49 #ifdef TARGET_ARCH_arm
bobv@2508 50 # include "jniTypes_arm.hpp"
bobv@2508 51 #endif
bobv@2508 52 #ifdef TARGET_ARCH_ppc
bobv@2508 53 # include "jniTypes_ppc.hpp"
bobv@2508 54 #endif
aoqi@1 55 #ifdef TARGET_ARCH_mips
aoqi@1 56 # include "jniTypes_mips.hpp"
aoqi@1 57 #endif
stefank@2314 58
duke@435 59 // A JavaCallWrapper is constructed before each JavaCall and destructed after the call.
duke@435 60 // Its purpose is to allocate/deallocate a new handle block and to save/restore the last
duke@435 61 // Java fp/sp. A pointer to the JavaCallWrapper is stored on the stack.
duke@435 62
duke@435 63 class JavaCallWrapper: StackObj {
duke@435 64 friend class VMStructs;
duke@435 65 private:
duke@435 66 JavaThread* _thread; // the thread to which this call belongs
duke@435 67 JNIHandleBlock* _handles; // the saved handle block
coleenp@4037 68 Method* _callee_method; // to be able to collect arguments if entry frame is top frame
duke@435 69 oop _receiver; // the receiver of the call (if a non-static call)
duke@435 70
duke@435 71 JavaFrameAnchor _anchor; // last thread anchor state that we must restore
duke@435 72
duke@435 73 JavaValue* _result; // result value
duke@435 74
duke@435 75 public:
duke@435 76 // Construction/destruction
duke@435 77 JavaCallWrapper(methodHandle callee_method, Handle receiver, JavaValue* result, TRAPS);
duke@435 78 ~JavaCallWrapper();
duke@435 79
duke@435 80 // Accessors
duke@435 81 JavaThread* thread() const { return _thread; }
duke@435 82 JNIHandleBlock* handles() const { return _handles; }
duke@435 83
duke@435 84 JavaFrameAnchor* anchor(void) { return &_anchor; }
duke@435 85
duke@435 86 JavaValue* result() const { return _result; }
duke@435 87 // GC support
coleenp@4037 88 Method* callee_method() { return _callee_method; }
duke@435 89 oop receiver() { return _receiver; }
duke@435 90 void oops_do(OopClosure* f);
duke@435 91
rbackman@5419 92 bool is_first_frame() const { return _anchor.last_Java_sp() == NULL; }
rbackman@5419 93
duke@435 94 };
duke@435 95
duke@435 96
duke@435 97 // Encapsulates arguments to a JavaCall (faster, safer, and more convenient than using var-args)
duke@435 98 class JavaCallArguments : public StackObj {
duke@435 99 private:
duke@435 100 enum Constants {
duke@435 101 _default_size = 8 // Must be at least # of arguments in JavaCalls methods
duke@435 102 };
duke@435 103
phh@9669 104 intptr_t _value_buffer [_default_size + 1];
phh@9669 105 u_char _value_state_buffer[_default_size + 1];
duke@435 106
duke@435 107 intptr_t* _value;
phh@9669 108 u_char* _value_state;
duke@435 109 int _size;
duke@435 110 int _max_size;
duke@435 111 bool _start_at_zero; // Support late setting of receiver
duke@435 112
duke@435 113 void initialize() {
duke@435 114 // Starts at first element to support set_receiver.
phh@9669 115 _value = &_value_buffer[1];
phh@9669 116 _value_state = &_value_state_buffer[1];
duke@435 117
duke@435 118 _max_size = _default_size;
duke@435 119 _size = 0;
duke@435 120 _start_at_zero = false;
duke@435 121 }
duke@435 122
phh@9669 123 // Helper for push_oop and the like. The value argument is a
phh@9669 124 // "handle" that refers to an oop. We record the address of the
phh@9669 125 // handle rather than the designated oop. The handle is later
phh@9669 126 // resolved to the oop by parameters(). This delays the exposure of
phh@9669 127 // naked oops until it is GC-safe.
phh@9669 128 template<typename T>
phh@9669 129 inline int push_oop_impl(T handle, int size) {
phh@9669 130 // JNITypes::put_obj expects an oop value, so we play fast and
phh@9669 131 // loose with the type system. The cast from handle type to oop
phh@9669 132 // *must* use a C-style cast. In a product build it performs a
phh@9669 133 // reinterpret_cast. In a debug build (more accurately, in a
phh@9669 134 // CHECK_UNHANDLED_OOPS build) it performs a static_cast, invoking
phh@9669 135 // the debug-only oop class's conversion from void* constructor.
phh@9669 136 JNITypes::put_obj((oop)handle, _value, size); // Updates size.
phh@9669 137 return size; // Return the updated size.
phh@9669 138 }
phh@9669 139
duke@435 140 public:
duke@435 141 JavaCallArguments() { initialize(); }
duke@435 142
duke@435 143 JavaCallArguments(Handle receiver) {
duke@435 144 initialize();
duke@435 145 push_oop(receiver);
duke@435 146 }
duke@435 147
duke@435 148 JavaCallArguments(int max_size) {
duke@435 149 if (max_size > _default_size) {
phh@9669 150 _value = NEW_RESOURCE_ARRAY(intptr_t, max_size + 1);
phh@9669 151 _value_state = NEW_RESOURCE_ARRAY(u_char, max_size + 1);
twisti@1861 152
phh@9669 153 // Reserve room for potential receiver in value and state
phh@9669 154 _value++;
phh@9669 155 _value_state++;
twisti@1861 156
duke@435 157 _max_size = max_size;
duke@435 158 _size = 0;
duke@435 159 _start_at_zero = false;
duke@435 160 } else {
duke@435 161 initialize();
duke@435 162 }
duke@435 163 }
duke@435 164
phh@9669 165 // The possible values for _value_state elements.
phh@9669 166 enum {
phh@9669 167 value_state_primitive,
phh@9669 168 value_state_oop,
phh@9669 169 value_state_handle,
phh@9669 170 value_state_jobject,
phh@9669 171 value_state_limit
phh@9669 172 };
duke@435 173
phh@9669 174 inline void push_oop(Handle h) {
phh@9669 175 _value_state[_size] = value_state_handle;
phh@9669 176 _size = push_oop_impl(h.raw_value(), _size);
phh@9669 177 }
duke@435 178
phh@9669 179 inline void push_jobject(jobject h) {
phh@9669 180 _value_state[_size] = value_state_jobject;
phh@9669 181 _size = push_oop_impl(h, _size);
phh@9669 182 }
duke@435 183
phh@9669 184 inline void push_int(int i) {
phh@9669 185 _value_state[_size] = value_state_primitive;
phh@9669 186 JNITypes::put_int(i, _value, _size);
phh@9669 187 }
duke@435 188
phh@9669 189 inline void push_double(double d) {
phh@9669 190 _value_state[_size] = value_state_primitive;
phh@9669 191 _value_state[_size + 1] = value_state_primitive;
phh@9669 192 JNITypes::put_double(d, _value, _size);
phh@9669 193 }
phh@9669 194
phh@9669 195 inline void push_long(jlong l) {
phh@9669 196 _value_state[_size] = value_state_primitive;
phh@9669 197 _value_state[_size + 1] = value_state_primitive;
phh@9669 198 JNITypes::put_long(l, _value, _size);
phh@9669 199 }
phh@9669 200
phh@9669 201 inline void push_float(float f) {
phh@9669 202 _value_state[_size] = value_state_primitive;
phh@9669 203 JNITypes::put_float(f, _value, _size);
phh@9669 204 }
duke@435 205
duke@435 206 // receiver
duke@435 207 Handle receiver() {
duke@435 208 assert(_size > 0, "must at least be one argument");
phh@9669 209 assert(_value_state[0] == value_state_handle,
phh@9669 210 "first argument must be an oop");
duke@435 211 assert(_value[0] != 0, "receiver must be not-null");
duke@435 212 return Handle((oop*)_value[0], false);
duke@435 213 }
duke@435 214
duke@435 215 void set_receiver(Handle h) {
duke@435 216 assert(_start_at_zero == false, "can only be called once");
duke@435 217 _start_at_zero = true;
phh@9669 218 _value_state--;
duke@435 219 _value--;
duke@435 220 _size++;
phh@9669 221 _value_state[0] = value_state_handle;
phh@9669 222 push_oop_impl(h.raw_value(), 0);
duke@435 223 }
duke@435 224
duke@435 225 // Converts all Handles to oops, and returns a reference to parameter vector
duke@435 226 intptr_t* parameters() ;
duke@435 227 int size_of_parameters() const { return _size; }
duke@435 228
duke@435 229 // Verify that pushed arguments fits a given method
phh@9669 230 void verify(methodHandle method, BasicType return_type);
duke@435 231 };
duke@435 232
duke@435 233 // All calls to Java have to go via JavaCalls. Sets up the stack frame
duke@435 234 // and makes sure that the last_Java_frame pointers are chained correctly.
duke@435 235 //
duke@435 236
duke@435 237 class JavaCalls: AllStatic {
duke@435 238 static void call_helper(JavaValue* result, methodHandle* method, JavaCallArguments* args, TRAPS);
duke@435 239 public:
duke@435 240 // Optimized Constuctor call
duke@435 241 static void call_default_constructor(JavaThread* thread, methodHandle method, Handle receiver, TRAPS);
duke@435 242
duke@435 243 // call_special
duke@435 244 // ------------
duke@435 245 // The receiver must be first oop in argument list
coleenp@2497 246 static void call_special(JavaValue* result, KlassHandle klass, Symbol* name, Symbol* signature, JavaCallArguments* args, TRAPS);
duke@435 247
coleenp@2497 248 static void call_special(JavaValue* result, Handle receiver, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS); // No args
coleenp@2497 249 static void call_special(JavaValue* result, Handle receiver, KlassHandle klass, Symbol* name, Symbol* signature, Handle arg1, TRAPS);
coleenp@2497 250 static void call_special(JavaValue* result, Handle receiver, KlassHandle klass, Symbol* name, Symbol* signature, Handle arg1, Handle arg2, TRAPS);
duke@435 251
duke@435 252 // virtual call
duke@435 253 // ------------
duke@435 254
duke@435 255 // The receiver must be first oop in argument list
coleenp@2497 256 static void call_virtual(JavaValue* result, KlassHandle spec_klass, Symbol* name, Symbol* signature, JavaCallArguments* args, TRAPS);
duke@435 257
coleenp@2497 258 static void call_virtual(JavaValue* result, Handle receiver, KlassHandle spec_klass, Symbol* name, Symbol* signature, TRAPS); // No args
coleenp@2497 259 static void call_virtual(JavaValue* result, Handle receiver, KlassHandle spec_klass, Symbol* name, Symbol* signature, Handle arg1, TRAPS);
coleenp@2497 260 static void call_virtual(JavaValue* result, Handle receiver, KlassHandle spec_klass, Symbol* name, Symbol* signature, Handle arg1, Handle arg2, TRAPS);
duke@435 261
duke@435 262 // Static call
duke@435 263 // -----------
coleenp@2497 264 static void call_static(JavaValue* result, KlassHandle klass, Symbol* name, Symbol* signature, JavaCallArguments* args, TRAPS);
duke@435 265
coleenp@2497 266 static void call_static(JavaValue* result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS);
coleenp@2497 267 static void call_static(JavaValue* result, KlassHandle klass, Symbol* name, Symbol* signature, Handle arg1, TRAPS);
coleenp@2497 268 static void call_static(JavaValue* result, KlassHandle klass, Symbol* name, Symbol* signature, Handle arg1, Handle arg2, TRAPS);
duke@435 269
duke@435 270 // Low-level interface
duke@435 271 static void call(JavaValue* result, methodHandle method, JavaCallArguments* args, TRAPS);
duke@435 272 };
stefank@2314 273
stefank@2314 274 #endif // SHARE_VM_RUNTIME_JAVACALLS_HPP

mercurial