< prev index next >

src/hotspot/share/runtime/javaCalls.cpp

Print this page




 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 
 350   CHECK_UNHANDLED_OOPS_ONLY(thread->clear_unhandled_oops();)
 351 
 352 #if INCLUDE_JVMCI
 353   // Gets the nmethod (if any) that should be called instead of normal target
 354   nmethod* alternative_target = args->alternative_target();
 355   if (alternative_target == NULL) {
 356 #endif
 357 // Verify the arguments
 358 
 359   if (CheckJNICalls)  {
 360     args->verify(method, result->get_type());
 361   }
 362   else debug_only(args->verify(method, result->get_type()));
 363 #if INCLUDE_JVMCI
 364   }
 365 #else
 366 
 367   // Ignore call if method is empty
 368   if (method->is_empty_method()) {
 369     assert(result->get_type() == T_VOID, "an empty method must return a void value");
 370     return;
 371   }


 378     // not fully initialized! (bad Java programming style)
 379     assert(holder->is_linked(), "rewriting must have taken place");
 380   }
 381 #endif
 382 
 383   CompilationPolicy::compile_if_required(method, CHECK);
 384 
 385   // Since the call stub sets up like the interpreter we call the from_interpreted_entry
 386   // so we can go compiled via a i2c. Otherwise initial entry method will always
 387   // run interpreted.
 388   address entry_point = method->from_interpreted_entry();
 389   if (JvmtiExport::can_post_interpreter_events() && thread->is_interp_only_mode()) {
 390     entry_point = method->interpreter_entry();
 391   }
 392 
 393   // Figure out if the result value is an oop or not (Note: This is a different value
 394   // than result_type. result_type will be T_INT of oops. (it is about size)
 395   BasicType result_type = runtime_type_from(result);
 396   bool oop_result_flag = (result->get_type() == T_OBJECT || result->get_type() == T_ARRAY);
 397 
 398   // NOTE: if we move the computation of the result_val_address inside
 399   // the call to call_stub, the optimizer produces wrong code.
 400   intptr_t* result_val_address = (intptr_t*)(result->get_value_addr());
 401 
 402   // Find receiver
 403   Handle receiver = (!method->is_static()) ? args->receiver() : Handle();
 404 
 405   // When we reenter Java, we need to reenable the reserved/yellow zone which
 406   // might already be disabled when we are in VM.
 407   if (!thread->stack_guards_enabled()) {
 408     thread->reguard_stack();
 409   }
 410 
 411   // Check that there are shadow pages available before changing thread state
 412   // to Java. Calculate current_stack_pointer here to make sure
 413   // stack_shadow_pages_available() and bang_stack_shadow_pages() use the same sp.
 414   address sp = os::current_stack_pointer();
 415   if (!os::stack_shadow_pages_available(THREAD, method, sp)) {
 416     // Throw stack overflow exception with preinitialized exception.
 417     Exceptions::throw_stack_overflow_exception(THREAD, __FILE__, __LINE__, method);
 418     return;
 419   } else {
 420     // Touch pages checked if the OS needs them to be touched to be mapped.
 421     os::map_stack_shadow_pages(sp);
 422   }
 423 
 424 #if INCLUDE_JVMCI
 425   if (alternative_target != NULL) {
 426     if (alternative_target->is_alive() && !alternative_target->is_unloading()) {
 427       thread->set_jvmci_alternate_call_target(alternative_target->verified_entry_point());
 428       entry_point = method->adapter()->get_i2c_entry();
 429     } else {
 430       THROW(vmSymbols::jdk_vm_ci_code_InvalidInstalledCodeException());
 431     }
 432   }
 433 #endif
 434 
 435   // do call
 436   { JavaCallWrapper link(method, receiver, result, CHECK);
 437     { HandleMark hm(thread);  // HandleMark used by HandleMarkCleaner
 438 





 439       StubRoutines::call_stub()(
 440         (address)&link,
 441         // (intptr_t*)&(result->_value), // see NOTE above (compiler problem)
 442         result_val_address,          // see NOTE above (compiler problem)
 443         result_type,
 444         method(),
 445         entry_point,
 446         args->parameters(),
 447         args->size_of_parameters(),
 448         CHECK
 449       );
 450 
 451       result = link.result();  // circumvent MS C++ 5.0 compiler bug (result is clobbered across call)
 452       // Preserve oop return value across possible gc points
 453       if (oop_result_flag) {
 454         thread->set_vm_result((oop) result->get_jobject());
 455       }
 456     }
 457   } // Exit JavaCallWrapper (can block - potential return oop must be preserved)
 458 
 459   // Check if a thread stop or suspend should be executed
 460   // The following assert was not realistic.  Thread.stop can set that bit at any moment.
 461   //assert(!thread->has_special_runtime_exit_condition(), "no async. exceptions should be installed");
 462 
 463   // Restore possible oop return
 464   if (oop_result_flag) {
 465     result->set_jobject((jobject)thread->vm_result());
 466     thread->set_vm_result(NULL);




 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   }


 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 
 390   // Figure out if the result value is an oop or not (Note: This is a different value
 391   // than result_type. result_type will be T_INT of oops. (it is about size)
 392   BasicType result_type = runtime_type_from(result);
 393   bool oop_result_flag = (result->get_type() == T_OBJECT || result->get_type() == T_ARRAY);
 394 




 395   // Find receiver
 396   Handle receiver = (!method->is_static()) ? args->receiver() : Handle();
 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 
 457   // Check if a thread stop or suspend should be executed
 458   // The following assert was not realistic.  Thread.stop can set that bit at any moment.
 459   //assert(!thread->has_special_runtime_exit_condition(), "no async. exceptions should be installed");
 460 
 461   // Restore possible oop return
 462   if (oop_result_flag) {
 463     result->set_jobject((jobject)thread->vm_result());
 464     thread->set_vm_result(NULL);


< prev index next >