13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "classfile/systemDictionary.hpp"
27 #include "classfile/vmSymbols.hpp"
28 #include "code/nmethod.hpp"
29 #include "compiler/compilationPolicy.hpp"
30 #include "compiler/compileBroker.hpp"
31 #include "interpreter/interpreter.hpp"
32 #include "interpreter/linkResolver.hpp"
33 #include "memory/universe.hpp"
34 #include "oops/method.inline.hpp"
35 #include "oops/oop.inline.hpp"
36 #include "prims/jniCheck.hpp"
37 #include "runtime/handles.inline.hpp"
38 #include "runtime/interfaceSupport.inline.hpp"
39 #include "runtime/javaCalls.hpp"
40 #include "runtime/jniHandles.inline.hpp"
41 #include "runtime/mutexLocker.hpp"
42 #include "runtime/os.inline.hpp"
43 #include "runtime/sharedRuntime.hpp"
44 #include "runtime/signature.hpp"
45 #include "runtime/stubRoutines.hpp"
46 #include "runtime/thread.inline.hpp"
47
48 // -----------------------------------------------------
49 // Implementation of JavaCallWrapper
50
51 JavaCallWrapper::JavaCallWrapper(const methodHandle& callee_method, Handle receiver, JavaValue* result, TRAPS) {
52 JavaThread* thread = (JavaThread *)THREAD;
329 // Implementation of JavaCalls (low level)
330
331
332 void JavaCalls::call(JavaValue* result, const methodHandle& method, JavaCallArguments* args, TRAPS) {
333 // Check if we need to wrap a potential OS exception handler around thread
334 // This is used for e.g. Win32 structured exception handlers
335 assert(THREAD->is_Java_thread(), "only JavaThreads can make JavaCalls");
336 // Need to wrap each and every time, since there might be native code down the
337 // stack that has installed its own exception handlers
338 os::os_exception_wrapper(call_helper, result, method, args, THREAD);
339 }
340
341 void JavaCalls::call_helper(JavaValue* result, const methodHandle& method, JavaCallArguments* args, TRAPS) {
342
343 JavaThread* thread = (JavaThread*)THREAD;
344 assert(thread->is_Java_thread(), "must be called by a java thread");
345 assert(method.not_null(), "must have a method to call");
346 assert(!SafepointSynchronize::is_at_safepoint(), "call to Java code during VM operation");
347 assert(!thread->handle_area()->no_handle_mark_active(), "cannot call out to Java here");
348
349 #if INCLUDE_JVMCI
350 // Gets the nmethod (if any) that should be called instead of normal target
351 nmethod* alternative_target = args->alternative_target();
352 if (alternative_target == NULL) {
353 #endif
354 // Verify the arguments
355
356 if (CheckJNICalls) {
357 args->verify(method, result->get_type());
358 }
359 else debug_only(args->verify(method, result->get_type()));
360 #if INCLUDE_JVMCI
361 }
362 #else
363
364 // Ignore call if method is empty
365 if (method->is_empty_method()) {
366 assert(result->get_type() == T_VOID, "an empty method must return a void value");
367 return;
368 }
369 #endif
370
371 #ifdef ASSERT
372 { InstanceKlass* holder = method->method_holder();
373 // A klass might not be initialized since JavaCall's might be used during the executing of
374 // the <clinit>. For example, a Thread.start might start executing on an object that is
375 // not fully initialized! (bad Java programming style)
376 assert(holder->is_linked(), "rewriting must have taken place");
377 }
378 #endif
379
380 CompilationPolicy::compile_if_required(method, CHECK);
381
382 // Since the call stub sets up like the interpreter we call the from_interpreted_entry
383 // so we can go compiled via a i2c. Otherwise initial entry method will always
384 // run interpreted.
385 address entry_point = method->from_interpreted_entry();
386 if (JvmtiExport::can_post_interpreter_events() && thread->is_interp_only_mode()) {
387 entry_point = method->interpreter_entry();
388 }
389
397
398 // When we reenter Java, we need to reenable the reserved/yellow zone which
399 // might already be disabled when we are in VM.
400 if (!thread->stack_guards_enabled()) {
401 thread->reguard_stack();
402 }
403
404 // Check that there are shadow pages available before changing thread state
405 // to Java. Calculate current_stack_pointer here to make sure
406 // stack_shadow_pages_available() and bang_stack_shadow_pages() use the same sp.
407 address sp = os::current_stack_pointer();
408 if (!os::stack_shadow_pages_available(THREAD, method, sp)) {
409 // Throw stack overflow exception with preinitialized exception.
410 Exceptions::throw_stack_overflow_exception(THREAD, __FILE__, __LINE__, method);
411 return;
412 } else {
413 // Touch pages checked if the OS needs them to be touched to be mapped.
414 os::map_stack_shadow_pages(sp);
415 }
416
417 #if INCLUDE_JVMCI
418 if (alternative_target != NULL) {
419 if (alternative_target->is_alive() && !alternative_target->is_unloading()) {
420 thread->set_jvmci_alternate_call_target(alternative_target->verified_entry_point());
421 entry_point = method->adapter()->get_i2c_entry();
422 } else {
423 THROW(vmSymbols::jdk_vm_ci_code_InvalidInstalledCodeException());
424 }
425 }
426 #endif
427
428 // do call
429 { JavaCallWrapper link(method, receiver, result, CHECK);
430 { HandleMark hm(thread); // HandleMark used by HandleMarkCleaner
431
432 // NOTE: if we move the computation of the result_val_address inside
433 // the call to call_stub, the optimizer produces wrong code.
434 intptr_t* result_val_address = (intptr_t*)(result->get_value_addr());
435 intptr_t* parameter_address = args->parameters();
436
437 StubRoutines::call_stub()(
438 (address)&link,
439 // (intptr_t*)&(result->_value), // see NOTE above (compiler problem)
440 result_val_address, // see NOTE above (compiler problem)
441 result_type,
442 method(),
443 entry_point,
444 parameter_address,
445 args->size_of_parameters(),
446 CHECK
447 );
448
449 result = link.result(); // circumvent MS C++ 5.0 compiler bug (result is clobbered across call)
450 // Preserve oop return value across possible gc points
451 if (oop_result_flag) {
452 thread->set_vm_result((oop) result->get_jobject());
453 }
454 }
455 } // Exit JavaCallWrapper (can block - potential return oop must be preserved)
456
|
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "classfile/systemDictionary.hpp"
27 #include "classfile/vmSymbols.hpp"
28 #include "code/nmethod.hpp"
29 #include "compiler/compilationPolicy.hpp"
30 #include "compiler/compileBroker.hpp"
31 #include "interpreter/interpreter.hpp"
32 #include "interpreter/linkResolver.hpp"
33 #if INCLUDE_JVMCI
34 #include "jvmci/jvmciJavaClasses.hpp"
35 #endif
36 #include "memory/universe.hpp"
37 #include "oops/method.inline.hpp"
38 #include "oops/oop.inline.hpp"
39 #include "prims/jniCheck.hpp"
40 #include "runtime/handles.inline.hpp"
41 #include "runtime/interfaceSupport.inline.hpp"
42 #include "runtime/javaCalls.hpp"
43 #include "runtime/jniHandles.inline.hpp"
44 #include "runtime/mutexLocker.hpp"
45 #include "runtime/os.inline.hpp"
46 #include "runtime/sharedRuntime.hpp"
47 #include "runtime/signature.hpp"
48 #include "runtime/stubRoutines.hpp"
49 #include "runtime/thread.inline.hpp"
50
51 // -----------------------------------------------------
52 // Implementation of JavaCallWrapper
53
54 JavaCallWrapper::JavaCallWrapper(const methodHandle& callee_method, Handle receiver, JavaValue* result, TRAPS) {
55 JavaThread* thread = (JavaThread *)THREAD;
332 // Implementation of JavaCalls (low level)
333
334
335 void JavaCalls::call(JavaValue* result, const methodHandle& method, JavaCallArguments* args, TRAPS) {
336 // Check if we need to wrap a potential OS exception handler around thread
337 // This is used for e.g. Win32 structured exception handlers
338 assert(THREAD->is_Java_thread(), "only JavaThreads can make JavaCalls");
339 // Need to wrap each and every time, since there might be native code down the
340 // stack that has installed its own exception handlers
341 os::os_exception_wrapper(call_helper, result, method, args, THREAD);
342 }
343
344 void JavaCalls::call_helper(JavaValue* result, const methodHandle& method, JavaCallArguments* args, TRAPS) {
345
346 JavaThread* thread = (JavaThread*)THREAD;
347 assert(thread->is_Java_thread(), "must be called by a java thread");
348 assert(method.not_null(), "must have a method to call");
349 assert(!SafepointSynchronize::is_at_safepoint(), "call to Java code during VM operation");
350 assert(!thread->handle_area()->no_handle_mark_active(), "cannot call out to Java here");
351
352 // Verify the arguments
353 if (JVMCI_ONLY(args->alternative_target().is_null() &&) (DEBUG_ONLY(true ||) CheckJNICalls)) {
354 args->verify(method, result->get_type());
355 }
356 // Ignore call if method is empty
357 if (JVMCI_ONLY(args->alternative_target().is_null() &&) method->is_empty_method()) {
358 assert(result->get_type() == T_VOID, "an empty method must return a void value");
359 return;
360 }
361
362 #ifdef ASSERT
363 { InstanceKlass* holder = method->method_holder();
364 // A klass might not be initialized since JavaCall's might be used during the executing of
365 // the <clinit>. For example, a Thread.start might start executing on an object that is
366 // not fully initialized! (bad Java programming style)
367 assert(holder->is_linked(), "rewriting must have taken place");
368 }
369 #endif
370
371 CompilationPolicy::compile_if_required(method, CHECK);
372
373 // Since the call stub sets up like the interpreter we call the from_interpreted_entry
374 // so we can go compiled via a i2c. Otherwise initial entry method will always
375 // run interpreted.
376 address entry_point = method->from_interpreted_entry();
377 if (JvmtiExport::can_post_interpreter_events() && thread->is_interp_only_mode()) {
378 entry_point = method->interpreter_entry();
379 }
380
388
389 // When we reenter Java, we need to reenable the reserved/yellow zone which
390 // might already be disabled when we are in VM.
391 if (!thread->stack_guards_enabled()) {
392 thread->reguard_stack();
393 }
394
395 // Check that there are shadow pages available before changing thread state
396 // to Java. Calculate current_stack_pointer here to make sure
397 // stack_shadow_pages_available() and bang_stack_shadow_pages() use the same sp.
398 address sp = os::current_stack_pointer();
399 if (!os::stack_shadow_pages_available(THREAD, method, sp)) {
400 // Throw stack overflow exception with preinitialized exception.
401 Exceptions::throw_stack_overflow_exception(THREAD, __FILE__, __LINE__, method);
402 return;
403 } else {
404 // Touch pages checked if the OS needs them to be touched to be mapped.
405 os::map_stack_shadow_pages(sp);
406 }
407
408 // do call
409 { JavaCallWrapper link(method, receiver, result, CHECK);
410 { HandleMark hm(thread); // HandleMark used by HandleMarkCleaner
411
412 // NOTE: if we move the computation of the result_val_address inside
413 // the call to call_stub, the optimizer produces wrong code.
414 intptr_t* result_val_address = (intptr_t*)(result->get_value_addr());
415 intptr_t* parameter_address = args->parameters();
416 #if INCLUDE_JVMCI
417 // Gets the alternative target (if any) that should be called
418 Handle alternative_target = args->alternative_target();
419 if (!alternative_target.is_null()) {
420 // Must extract verified entry point from HotSpotNmethod after VM to Java
421 // transition in JavaCallWrapper constructor so that it is safe with
422 // respect to nmethod sweeping.
423 address verified_entry_point = (address) HotSpotJVMCI::InstalledCode::entryPoint(NULL, alternative_target());
424 if (verified_entry_point != NULL) {
425 thread->set_jvmci_alternate_call_target(verified_entry_point);
426 entry_point = method->adapter()->get_i2c_entry();
427 }
428 }
429 #endif
430 StubRoutines::call_stub()(
431 (address)&link,
432 // (intptr_t*)&(result->_value), // see NOTE above (compiler problem)
433 result_val_address, // see NOTE above (compiler problem)
434 result_type,
435 method(),
436 entry_point,
437 parameter_address,
438 args->size_of_parameters(),
439 CHECK
440 );
441
442 result = link.result(); // circumvent MS C++ 5.0 compiler bug (result is clobbered across call)
443 // Preserve oop return value across possible gc points
444 if (oop_result_flag) {
445 thread->set_vm_result((oop) result->get_jobject());
446 }
447 }
448 } // Exit JavaCallWrapper (can block - potential return oop must be preserved)
449
|