src/share/vm/runtime/javaCalls.hpp

Tue, 07 May 2019 20:38:26 +0000

author
phh
date
Tue, 07 May 2019 20:38:26 +0000
changeset 9669
32bc598624bd
parent 6198
55fb97c4c58d
child 9703
2fdf635bcf28
permissions
-rw-r--r--

8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
Summary: Add tag bit to all JNI weak handles
Reviewed-by: kbarrett, coleenp, tschatzl

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
stefank@2314 25 #ifndef SHARE_VM_RUNTIME_JAVACALLS_HPP
stefank@2314 26 #define SHARE_VM_RUNTIME_JAVACALLS_HPP
stefank@2314 27
stefank@2314 28 #include "memory/allocation.hpp"
coleenp@4037 29 #include "oops/method.hpp"
stefank@2314 30 #include "runtime/handles.hpp"
stefank@2314 31 #include "runtime/javaFrameAnchor.hpp"
stefank@4299 32 #include "runtime/thread.inline.hpp"
stefank@2314 33 #include "runtime/vmThread.hpp"
stefank@2314 34 #ifdef TARGET_ARCH_x86
stefank@2314 35 # include "jniTypes_x86.hpp"
stefank@2314 36 #endif
stefank@2314 37 #ifdef TARGET_ARCH_sparc
stefank@2314 38 # include "jniTypes_sparc.hpp"
stefank@2314 39 #endif
stefank@2314 40 #ifdef TARGET_ARCH_zero
stefank@2314 41 # include "jniTypes_zero.hpp"
stefank@2314 42 #endif
bobv@2508 43 #ifdef TARGET_ARCH_arm
bobv@2508 44 # include "jniTypes_arm.hpp"
bobv@2508 45 #endif
bobv@2508 46 #ifdef TARGET_ARCH_ppc
bobv@2508 47 # include "jniTypes_ppc.hpp"
bobv@2508 48 #endif
stefank@2314 49
duke@435 50 // A JavaCallWrapper is constructed before each JavaCall and destructed after the call.
duke@435 51 // Its purpose is to allocate/deallocate a new handle block and to save/restore the last
duke@435 52 // Java fp/sp. A pointer to the JavaCallWrapper is stored on the stack.
duke@435 53
duke@435 54 class JavaCallWrapper: StackObj {
duke@435 55 friend class VMStructs;
duke@435 56 private:
duke@435 57 JavaThread* _thread; // the thread to which this call belongs
duke@435 58 JNIHandleBlock* _handles; // the saved handle block
coleenp@4037 59 Method* _callee_method; // to be able to collect arguments if entry frame is top frame
duke@435 60 oop _receiver; // the receiver of the call (if a non-static call)
duke@435 61
duke@435 62 JavaFrameAnchor _anchor; // last thread anchor state that we must restore
duke@435 63
duke@435 64 JavaValue* _result; // result value
duke@435 65
duke@435 66 public:
duke@435 67 // Construction/destruction
duke@435 68 JavaCallWrapper(methodHandle callee_method, Handle receiver, JavaValue* result, TRAPS);
duke@435 69 ~JavaCallWrapper();
duke@435 70
duke@435 71 // Accessors
duke@435 72 JavaThread* thread() const { return _thread; }
duke@435 73 JNIHandleBlock* handles() const { return _handles; }
duke@435 74
duke@435 75 JavaFrameAnchor* anchor(void) { return &_anchor; }
duke@435 76
duke@435 77 JavaValue* result() const { return _result; }
duke@435 78 // GC support
coleenp@4037 79 Method* callee_method() { return _callee_method; }
duke@435 80 oop receiver() { return _receiver; }
duke@435 81 void oops_do(OopClosure* f);
duke@435 82
rbackman@5419 83 bool is_first_frame() const { return _anchor.last_Java_sp() == NULL; }
rbackman@5419 84
duke@435 85 };
duke@435 86
duke@435 87
duke@435 88 // Encapsulates arguments to a JavaCall (faster, safer, and more convenient than using var-args)
duke@435 89 class JavaCallArguments : public StackObj {
duke@435 90 private:
duke@435 91 enum Constants {
duke@435 92 _default_size = 8 // Must be at least # of arguments in JavaCalls methods
duke@435 93 };
duke@435 94
phh@9669 95 intptr_t _value_buffer [_default_size + 1];
phh@9669 96 u_char _value_state_buffer[_default_size + 1];
duke@435 97
duke@435 98 intptr_t* _value;
phh@9669 99 u_char* _value_state;
duke@435 100 int _size;
duke@435 101 int _max_size;
duke@435 102 bool _start_at_zero; // Support late setting of receiver
duke@435 103
duke@435 104 void initialize() {
duke@435 105 // Starts at first element to support set_receiver.
phh@9669 106 _value = &_value_buffer[1];
phh@9669 107 _value_state = &_value_state_buffer[1];
duke@435 108
duke@435 109 _max_size = _default_size;
duke@435 110 _size = 0;
duke@435 111 _start_at_zero = false;
duke@435 112 }
duke@435 113
phh@9669 114 // Helper for push_oop and the like. The value argument is a
phh@9669 115 // "handle" that refers to an oop. We record the address of the
phh@9669 116 // handle rather than the designated oop. The handle is later
phh@9669 117 // resolved to the oop by parameters(). This delays the exposure of
phh@9669 118 // naked oops until it is GC-safe.
phh@9669 119 template<typename T>
phh@9669 120 inline int push_oop_impl(T handle, int size) {
phh@9669 121 // JNITypes::put_obj expects an oop value, so we play fast and
phh@9669 122 // loose with the type system. The cast from handle type to oop
phh@9669 123 // *must* use a C-style cast. In a product build it performs a
phh@9669 124 // reinterpret_cast. In a debug build (more accurately, in a
phh@9669 125 // CHECK_UNHANDLED_OOPS build) it performs a static_cast, invoking
phh@9669 126 // the debug-only oop class's conversion from void* constructor.
phh@9669 127 JNITypes::put_obj((oop)handle, _value, size); // Updates size.
phh@9669 128 return size; // Return the updated size.
phh@9669 129 }
phh@9669 130
duke@435 131 public:
duke@435 132 JavaCallArguments() { initialize(); }
duke@435 133
duke@435 134 JavaCallArguments(Handle receiver) {
duke@435 135 initialize();
duke@435 136 push_oop(receiver);
duke@435 137 }
duke@435 138
duke@435 139 JavaCallArguments(int max_size) {
duke@435 140 if (max_size > _default_size) {
phh@9669 141 _value = NEW_RESOURCE_ARRAY(intptr_t, max_size + 1);
phh@9669 142 _value_state = NEW_RESOURCE_ARRAY(u_char, max_size + 1);
twisti@1861 143
phh@9669 144 // Reserve room for potential receiver in value and state
phh@9669 145 _value++;
phh@9669 146 _value_state++;
twisti@1861 147
duke@435 148 _max_size = max_size;
duke@435 149 _size = 0;
duke@435 150 _start_at_zero = false;
duke@435 151 } else {
duke@435 152 initialize();
duke@435 153 }
duke@435 154 }
duke@435 155
phh@9669 156 // The possible values for _value_state elements.
phh@9669 157 enum {
phh@9669 158 value_state_primitive,
phh@9669 159 value_state_oop,
phh@9669 160 value_state_handle,
phh@9669 161 value_state_jobject,
phh@9669 162 value_state_limit
phh@9669 163 };
duke@435 164
phh@9669 165 inline void push_oop(Handle h) {
phh@9669 166 _value_state[_size] = value_state_handle;
phh@9669 167 _size = push_oop_impl(h.raw_value(), _size);
phh@9669 168 }
duke@435 169
phh@9669 170 inline void push_jobject(jobject h) {
phh@9669 171 _value_state[_size] = value_state_jobject;
phh@9669 172 _size = push_oop_impl(h, _size);
phh@9669 173 }
duke@435 174
phh@9669 175 inline void push_int(int i) {
phh@9669 176 _value_state[_size] = value_state_primitive;
phh@9669 177 JNITypes::put_int(i, _value, _size);
phh@9669 178 }
duke@435 179
phh@9669 180 inline void push_double(double d) {
phh@9669 181 _value_state[_size] = value_state_primitive;
phh@9669 182 _value_state[_size + 1] = value_state_primitive;
phh@9669 183 JNITypes::put_double(d, _value, _size);
phh@9669 184 }
phh@9669 185
phh@9669 186 inline void push_long(jlong l) {
phh@9669 187 _value_state[_size] = value_state_primitive;
phh@9669 188 _value_state[_size + 1] = value_state_primitive;
phh@9669 189 JNITypes::put_long(l, _value, _size);
phh@9669 190 }
phh@9669 191
phh@9669 192 inline void push_float(float f) {
phh@9669 193 _value_state[_size] = value_state_primitive;
phh@9669 194 JNITypes::put_float(f, _value, _size);
phh@9669 195 }
duke@435 196
duke@435 197 // receiver
duke@435 198 Handle receiver() {
duke@435 199 assert(_size > 0, "must at least be one argument");
phh@9669 200 assert(_value_state[0] == value_state_handle,
phh@9669 201 "first argument must be an oop");
duke@435 202 assert(_value[0] != 0, "receiver must be not-null");
duke@435 203 return Handle((oop*)_value[0], false);
duke@435 204 }
duke@435 205
duke@435 206 void set_receiver(Handle h) {
duke@435 207 assert(_start_at_zero == false, "can only be called once");
duke@435 208 _start_at_zero = true;
phh@9669 209 _value_state--;
duke@435 210 _value--;
duke@435 211 _size++;
phh@9669 212 _value_state[0] = value_state_handle;
phh@9669 213 push_oop_impl(h.raw_value(), 0);
duke@435 214 }
duke@435 215
duke@435 216 // Converts all Handles to oops, and returns a reference to parameter vector
duke@435 217 intptr_t* parameters() ;
duke@435 218 int size_of_parameters() const { return _size; }
duke@435 219
duke@435 220 // Verify that pushed arguments fits a given method
phh@9669 221 void verify(methodHandle method, BasicType return_type);
duke@435 222 };
duke@435 223
duke@435 224 // All calls to Java have to go via JavaCalls. Sets up the stack frame
duke@435 225 // and makes sure that the last_Java_frame pointers are chained correctly.
duke@435 226 //
duke@435 227
duke@435 228 class JavaCalls: AllStatic {
duke@435 229 static void call_helper(JavaValue* result, methodHandle* method, JavaCallArguments* args, TRAPS);
duke@435 230 public:
duke@435 231 // Optimized Constuctor call
duke@435 232 static void call_default_constructor(JavaThread* thread, methodHandle method, Handle receiver, TRAPS);
duke@435 233
duke@435 234 // call_special
duke@435 235 // ------------
duke@435 236 // The receiver must be first oop in argument list
coleenp@2497 237 static void call_special(JavaValue* result, KlassHandle klass, Symbol* name, Symbol* signature, JavaCallArguments* args, TRAPS);
duke@435 238
coleenp@2497 239 static void call_special(JavaValue* result, Handle receiver, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS); // No args
coleenp@2497 240 static void call_special(JavaValue* result, Handle receiver, KlassHandle klass, Symbol* name, Symbol* signature, Handle arg1, TRAPS);
coleenp@2497 241 static void call_special(JavaValue* result, Handle receiver, KlassHandle klass, Symbol* name, Symbol* signature, Handle arg1, Handle arg2, TRAPS);
duke@435 242
duke@435 243 // virtual call
duke@435 244 // ------------
duke@435 245
duke@435 246 // The receiver must be first oop in argument list
coleenp@2497 247 static void call_virtual(JavaValue* result, KlassHandle spec_klass, Symbol* name, Symbol* signature, JavaCallArguments* args, TRAPS);
duke@435 248
coleenp@2497 249 static void call_virtual(JavaValue* result, Handle receiver, KlassHandle spec_klass, Symbol* name, Symbol* signature, TRAPS); // No args
coleenp@2497 250 static void call_virtual(JavaValue* result, Handle receiver, KlassHandle spec_klass, Symbol* name, Symbol* signature, Handle arg1, TRAPS);
coleenp@2497 251 static void call_virtual(JavaValue* result, Handle receiver, KlassHandle spec_klass, Symbol* name, Symbol* signature, Handle arg1, Handle arg2, TRAPS);
duke@435 252
duke@435 253 // Static call
duke@435 254 // -----------
coleenp@2497 255 static void call_static(JavaValue* result, KlassHandle klass, Symbol* name, Symbol* signature, JavaCallArguments* args, TRAPS);
duke@435 256
coleenp@2497 257 static void call_static(JavaValue* result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS);
coleenp@2497 258 static void call_static(JavaValue* result, KlassHandle klass, Symbol* name, Symbol* signature, Handle arg1, TRAPS);
coleenp@2497 259 static void call_static(JavaValue* result, KlassHandle klass, Symbol* name, Symbol* signature, Handle arg1, Handle arg2, TRAPS);
duke@435 260
duke@435 261 // Low-level interface
duke@435 262 static void call(JavaValue* result, methodHandle method, JavaCallArguments* args, TRAPS);
duke@435 263 };
stefank@2314 264
stefank@2314 265 #endif // SHARE_VM_RUNTIME_JAVACALLS_HPP

mercurial