41 #include "runtime/jniHandles.inline.hpp"
42 #include "runtime/mutexLocker.hpp"
43 #include "runtime/os.inline.hpp"
44 #include "runtime/sharedRuntime.hpp"
45 #include "runtime/signature.hpp"
46 #include "runtime/stubRoutines.hpp"
47 #include "runtime/thread.inline.hpp"
48 #if INCLUDE_JVMCI
49 #include "jvmci/jvmciJavaClasses.hpp"
50 #endif
51
52 // -----------------------------------------------------
53 // Implementation of JavaCallWrapper
54
55 JavaCallWrapper::JavaCallWrapper(const methodHandle& callee_method, Handle receiver, JavaValue* result, TRAPS) {
56 JavaThread* thread = THREAD;
57
58 guarantee(thread->is_Java_thread(), "crucial check - the VM thread cannot and must not escape to Java code");
59 assert(!thread->owns_locks(), "must release all locks when leaving VM");
60 guarantee(thread->can_call_java(), "cannot make java calls from the native compiler");
61 _result = result;
62
63 // Allocate handle block for Java code. This must be done before we change thread_state to _thread_in_Java_or_stub,
64 // since it can potentially block.
65 JNIHandleBlock* new_handles = JNIHandleBlock::allocate_block(thread);
66
67 // clear any pending exception in thread (native calls start with no exception pending)
68 thread->clear_pending_exception();
69
70 // After this, we are official in JavaCode. This needs to be done before we change any of the thread local
71 // info, since we cannot find oops before the new information is set up completely.
72 ThreadStateTransition::transition_from_vm(thread, _thread_in_Java, true /* check_asyncs */);
73
74 // Make sure to set the oop's after the thread transition - since we can block there. No one is GC'ing
75 // the JavaCallWrapper before the entry frame is on the stack.
76 _callee_method = callee_method();
77 _receiver = receiver();
78
79 #ifdef CHECK_UNHANDLED_OOPS
80 THREAD->allow_unhandled_oop(&_receiver);
225 void JavaCalls::call_special(JavaValue* result, Handle receiver, Klass* klass, Symbol* name, Symbol* signature, Handle arg1, TRAPS) {
226 JavaCallArguments args(receiver);
227 args.push_oop(arg1);
228 call_special(result, klass, name, signature, &args, CHECK);
229 }
230
231
232 void JavaCalls::call_special(JavaValue* result, Handle receiver, Klass* klass, Symbol* name, Symbol* signature, Handle arg1, Handle arg2, TRAPS) {
233 JavaCallArguments args(receiver);
234 args.push_oop(arg1);
235 args.push_oop(arg2);
236 call_special(result, klass, name, signature, &args, CHECK);
237 }
238
239
240 // ============ Static calls ============
241
242 void JavaCalls::call_static(JavaValue* result, Klass* klass, Symbol* name, Symbol* signature, JavaCallArguments* args, TRAPS) {
243 CallInfo callinfo;
244 LinkInfo link_info(klass, name, signature);
245 LinkResolver::resolve_static_call(callinfo, link_info, true, CHECK);
246 methodHandle method(THREAD, callinfo.selected_method());
247 assert(method.not_null(), "should have thrown exception");
248
249 // Invoke the method
250 JavaCalls::call(result, method, args, CHECK);
251 }
252
253
254 void JavaCalls::call_static(JavaValue* result, Klass* klass, Symbol* name, Symbol* signature, TRAPS) {
255 JavaCallArguments args;
256 call_static(result, klass, name, signature, &args, CHECK);
257 }
258
259
260 void JavaCalls::call_static(JavaValue* result, Klass* klass, Symbol* name, Symbol* signature, Handle arg1, TRAPS) {
261 JavaCallArguments args(arg1);
262 call_static(result, klass, name, signature, &args, CHECK);
263 }
264
265
|
41 #include "runtime/jniHandles.inline.hpp"
42 #include "runtime/mutexLocker.hpp"
43 #include "runtime/os.inline.hpp"
44 #include "runtime/sharedRuntime.hpp"
45 #include "runtime/signature.hpp"
46 #include "runtime/stubRoutines.hpp"
47 #include "runtime/thread.inline.hpp"
48 #if INCLUDE_JVMCI
49 #include "jvmci/jvmciJavaClasses.hpp"
50 #endif
51
52 // -----------------------------------------------------
53 // Implementation of JavaCallWrapper
54
55 JavaCallWrapper::JavaCallWrapper(const methodHandle& callee_method, Handle receiver, JavaValue* result, TRAPS) {
56 JavaThread* thread = THREAD;
57
58 guarantee(thread->is_Java_thread(), "crucial check - the VM thread cannot and must not escape to Java code");
59 assert(!thread->owns_locks(), "must release all locks when leaving VM");
60 guarantee(thread->can_call_java(), "cannot make java calls from the native compiler");
61 assert(!thread->preempting(), "");
62 _result = result;
63
64 // Allocate handle block for Java code. This must be done before we change thread_state to _thread_in_Java_or_stub,
65 // since it can potentially block.
66 JNIHandleBlock* new_handles = JNIHandleBlock::allocate_block(thread);
67
68 // clear any pending exception in thread (native calls start with no exception pending)
69 thread->clear_pending_exception();
70
71 // After this, we are official in JavaCode. This needs to be done before we change any of the thread local
72 // info, since we cannot find oops before the new information is set up completely.
73 ThreadStateTransition::transition_from_vm(thread, _thread_in_Java, true /* check_asyncs */);
74
75 // Make sure to set the oop's after the thread transition - since we can block there. No one is GC'ing
76 // the JavaCallWrapper before the entry frame is on the stack.
77 _callee_method = callee_method();
78 _receiver = receiver();
79
80 #ifdef CHECK_UNHANDLED_OOPS
81 THREAD->allow_unhandled_oop(&_receiver);
226 void JavaCalls::call_special(JavaValue* result, Handle receiver, Klass* klass, Symbol* name, Symbol* signature, Handle arg1, TRAPS) {
227 JavaCallArguments args(receiver);
228 args.push_oop(arg1);
229 call_special(result, klass, name, signature, &args, CHECK);
230 }
231
232
233 void JavaCalls::call_special(JavaValue* result, Handle receiver, Klass* klass, Symbol* name, Symbol* signature, Handle arg1, Handle arg2, TRAPS) {
234 JavaCallArguments args(receiver);
235 args.push_oop(arg1);
236 args.push_oop(arg2);
237 call_special(result, klass, name, signature, &args, CHECK);
238 }
239
240
241 // ============ Static calls ============
242
243 void JavaCalls::call_static(JavaValue* result, Klass* klass, Symbol* name, Symbol* signature, JavaCallArguments* args, TRAPS) {
244 CallInfo callinfo;
245 LinkInfo link_info(klass, name, signature);
246 LinkResolver::resolve_static_call(callinfo, link_info, StaticMode::initialize_klass, CHECK);
247 methodHandle method(THREAD, callinfo.selected_method());
248 assert(method.not_null(), "should have thrown exception");
249
250 // Invoke the method
251 JavaCalls::call(result, method, args, CHECK);
252 }
253
254
255 void JavaCalls::call_static(JavaValue* result, Klass* klass, Symbol* name, Symbol* signature, TRAPS) {
256 JavaCallArguments args;
257 call_static(result, klass, name, signature, &args, CHECK);
258 }
259
260
261 void JavaCalls::call_static(JavaValue* result, Klass* klass, Symbol* name, Symbol* signature, Handle arg1, TRAPS) {
262 JavaCallArguments args(arg1);
263 call_static(result, klass, name, signature, &args, CHECK);
264 }
265
266
|