< prev index next >

src/hotspot/share/runtime/javaCalls.cpp

Print this page




  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;


 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 


 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(cast_from_oop<jobject>(thread->vm_result()));
 464     thread->set_vm_result(NULL);
 465   }
 466 }
 467 
 468 
 469 //--------------------------------------------------------------------------------------
 470 // Implementation of JavaCallArguments
 471 
 472 inline bool is_value_state_indirect_oop(uint state) {
 473   assert(state != JavaCallArguments::value_state_oop,
 474          "Checking for handles after removal");
 475   assert(state < JavaCallArguments::value_state_limit,
 476          "Invalid value state %u", state);




  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;


 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 #if INCLUDE_JVMCI
 353   // Gets the alternative target (if any) that should be called
 354   Handle alternative_target = args->alternative_target();
 355   if (alternative_target.is_null()) {
 356 #endif
 357     // Verify the arguments
 358     if (DEBUG_ONLY(true ||) CheckJNICalls)  {

 359       args->verify(method, result->get_type());
 360     }

 361 #if INCLUDE_JVMCI
 362   }
 363 #else
 364 
 365   // Ignore call if method is empty
 366   if (method->is_empty_method()) {
 367     assert(result->get_type() == T_VOID, "an empty method must return a void value");
 368     return;
 369   }
 370 #endif
 371 
 372 #ifdef ASSERT
 373   { InstanceKlass* holder = method->method_holder();
 374     // A klass might not be initialized since JavaCall's might be used during the executing of
 375     // the <clinit>. For example, a Thread.start might start executing on an object that is
 376     // not fully initialized! (bad Java programming style)
 377     assert(holder->is_linked(), "rewriting must have taken place");
 378   }
 379 #endif
 380 


 398 
 399   // When we reenter Java, we need to reenable the reserved/yellow zone which
 400   // might already be disabled when we are in VM.
 401   if (!thread->stack_guards_enabled()) {
 402     thread->reguard_stack();
 403   }
 404 
 405   // Check that there are shadow pages available before changing thread state
 406   // to Java. Calculate current_stack_pointer here to make sure
 407   // stack_shadow_pages_available() and bang_stack_shadow_pages() use the same sp.
 408   address sp = os::current_stack_pointer();
 409   if (!os::stack_shadow_pages_available(THREAD, method, sp)) {
 410     // Throw stack overflow exception with preinitialized exception.
 411     Exceptions::throw_stack_overflow_exception(THREAD, __FILE__, __LINE__, method);
 412     return;
 413   } else {
 414     // Touch pages checked if the OS needs them to be touched to be mapped.
 415     os::map_stack_shadow_pages(sp);
 416   }
 417 











 418   // do call
 419   { JavaCallWrapper link(method, receiver, result, CHECK);
 420     { HandleMark hm(thread);  // HandleMark used by HandleMarkCleaner
 421 
 422       // NOTE: if we move the computation of the result_val_address inside
 423       // the call to call_stub, the optimizer produces wrong code.
 424       intptr_t* result_val_address = (intptr_t*)(result->get_value_addr());
 425       intptr_t* parameter_address = args->parameters();
 426 #if INCLUDE_JVMCI
 427       if (!alternative_target.is_null()) {
 428         // Must extract verified entry point from HotSpotNmethod after VM to Java
 429         // transition in JavaCallWrapper constructor so that it is safe with
 430         // respect to nmethod sweeping.
 431         address verified_entry_point = (address) HotSpotJVMCI::InstalledCode::entryPoint(NULL, alternative_target());
 432         if (verified_entry_point != 0) {
 433           thread->set_jvmci_alternate_call_target(verified_entry_point);
 434           entry_point = method->adapter()->get_i2c_entry();
 435         } else {
 436           // Sweeper made nmethod non-entrant or zombie at VM to Java transition
 437           entry_point = NULL;
 438         }
 439       }
 440       if (entry_point != NULL) {
 441 #endif
 442         StubRoutines::call_stub()(
 443           (address)&link,
 444           // (intptr_t*)&(result->_value), // see NOTE above (compiler problem)
 445           result_val_address,          // see NOTE above (compiler problem)
 446           result_type,
 447           method(),
 448           entry_point,
 449           parameter_address,
 450           args->size_of_parameters(),
 451           CHECK
 452         );
 453 
 454         result = link.result();  // circumvent MS C++ 5.0 compiler bug (result is clobbered across call)
 455         // Preserve oop return value across possible gc points
 456         if (oop_result_flag) {
 457           thread->set_vm_result((oop) result->get_jobject());
 458         }
 459       }
 460 #if INCLUDE_JVMCI
 461     }
 462 #endif
 463   } // Exit JavaCallWrapper (can block - potential return oop must be preserved)
 464 
 465   #if INCLUDE_JVMCI
 466     if (entry_point == NULL) {
 467       // Cannot creation exception until back in VM from Java
 468       THROW(vmSymbols::jdk_vm_ci_code_InvalidInstalledCodeException());
 469     }
 470   #endif
 471 
 472   // Check if a thread stop or suspend should be executed
 473   // The following assert was not realistic.  Thread.stop can set that bit at any moment.
 474   //assert(!thread->has_special_runtime_exit_condition(), "no async. exceptions should be installed");
 475 
 476   // Restore possible oop return
 477   if (oop_result_flag) {
 478     result->set_jobject(cast_from_oop<jobject>(thread->vm_result()));
 479     thread->set_vm_result(NULL);
 480   }
 481 }
 482 
 483 
 484 //--------------------------------------------------------------------------------------
 485 // Implementation of JavaCallArguments
 486 
 487 inline bool is_value_state_indirect_oop(uint state) {
 488   assert(state != JavaCallArguments::value_state_oop,
 489          "Checking for handles after removal");
 490   assert(state < JavaCallArguments::value_state_limit,
 491          "Invalid value state %u", state);


< prev index next >