< prev index next >

src/share/vm/prims/jvm.cpp

Print this page




  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/classLoader.hpp"
  27 #include "classfile/classLoaderData.inline.hpp"
  28 #include "classfile/classLoaderExt.hpp"
  29 #include "classfile/javaAssertions.hpp"
  30 #include "classfile/javaClasses.hpp"
  31 #include "classfile/symbolTable.hpp"
  32 #include "classfile/systemDictionary.hpp"
  33 #if INCLUDE_CDS
  34 #include "classfile/sharedClassUtil.hpp"
  35 #include "classfile/systemDictionaryShared.hpp"
  36 #endif
  37 #include "classfile/vmSymbols.hpp"
  38 #include "gc_interface/collectedHeap.inline.hpp"
  39 #include "interpreter/bytecode.hpp"

  40 #include "memory/oopFactory.hpp"
  41 #include "memory/referenceType.hpp"
  42 #include "memory/universe.inline.hpp"
  43 #include "oops/fieldStreams.hpp"
  44 #include "oops/instanceKlass.hpp"
  45 #include "oops/objArrayKlass.hpp"
  46 #include "oops/method.hpp"
  47 #include "prims/jvm.h"
  48 #include "prims/jvm_misc.hpp"
  49 #include "prims/jvmtiExport.hpp"
  50 #include "prims/jvmtiThreadState.hpp"
  51 #include "prims/nativeLookup.hpp"
  52 #include "prims/privilegedStack.hpp"
  53 #include "runtime/arguments.hpp"
  54 #include "runtime/dtraceJSDT.hpp"
  55 #include "runtime/handles.inline.hpp"
  56 #include "runtime/init.hpp"
  57 #include "runtime/interfaceSupport.hpp"
  58 #include "runtime/java.hpp"
  59 #include "runtime/javaCalls.hpp"
  60 #include "runtime/jfieldIDWorkaround.hpp"
  61 #include "runtime/orderAccess.inline.hpp"
  62 #include "runtime/os.hpp"
  63 #include "runtime/perfData.hpp"
  64 #include "runtime/reflection.hpp"
  65 #include "runtime/vframe.hpp"
  66 #include "runtime/vm_operations.hpp"
  67 #include "services/attachListener.hpp"
  68 #include "services/management.hpp"
  69 #include "services/threadService.hpp"
  70 #include "trace/tracing.hpp"
  71 #include "utilities/copy.hpp"
  72 #include "utilities/defaultStream.hpp"
  73 #include "utilities/dtrace.hpp"
  74 #include "utilities/events.hpp"
  75 #include "utilities/histogram.hpp"
  76 #include "utilities/top.hpp"
  77 #include "utilities/utf8.hpp"
  78 #ifdef TARGET_OS_FAMILY_linux
  79 # include "jvm_linux.h"
  80 #endif
  81 #ifdef TARGET_OS_FAMILY_solaris
  82 # include "jvm_solaris.h"
  83 #endif
  84 #ifdef TARGET_OS_FAMILY_windows
  85 # include "jvm_windows.h"
  86 #endif
  87 #ifdef TARGET_OS_FAMILY_aix
  88 # include "jvm_aix.h"
  89 #endif
  90 #ifdef TARGET_OS_FAMILY_bsd


 426   const char* temp_dir = os::get_temp_directory();
 427   Handle h = java_lang_String::create_from_platform_dependent_str(temp_dir, CHECK_NULL);
 428   return (jstring) JNIHandles::make_local(env, h());
 429 JVM_END
 430 
 431 
 432 // java.lang.Runtime /////////////////////////////////////////////////////////////////////////
 433 
 434 extern volatile jint vm_created;
 435 
 436 JVM_ENTRY_NO_ENV(void, JVM_Exit(jint code))
 437   if (vm_created != 0 && (code == 0)) {
 438     // The VM is about to exit. We call back into Java to check whether finalizers should be run
 439     Universe::run_finalizers_on_exit();
 440   }
 441   before_exit(thread);
 442   vm_exit(code);
 443 JVM_END
 444 
 445 










 446 JVM_ENTRY_NO_ENV(void, JVM_Halt(jint code))
 447   before_exit(thread);
 448   vm_exit(code);
 449 JVM_END
 450 
 451 
 452 JVM_LEAF(void, JVM_OnExit(void (*func)(void)))
 453   register_on_exit_function(func);
 454 JVM_END
 455 
 456 
 457 JVM_ENTRY_NO_ENV(void, JVM_GC(void))
 458   JVMWrapper("JVM_GC");
 459   if (!DisableExplicitGC) {
 460     Universe::heap()->collect(GCCause::_java_lang_system_gc);
 461   }
 462 JVM_END
 463 
 464 
 465 JVM_LEAF(jlong, JVM_MaxObjectInspectionAge(void))


3259 JVM_END
3260 
3261 
3262 JVM_ENTRY(void, JVM_Yield(JNIEnv *env, jclass threadClass))
3263   JVMWrapper("JVM_Yield");
3264   if (os::dont_yield()) return;
3265 #ifndef USDT2
3266   HS_DTRACE_PROBE0(hotspot, thread__yield);
3267 #else /* USDT2 */
3268   HOTSPOT_THREAD_YIELD();
3269 #endif /* USDT2 */
3270   // When ConvertYieldToSleep is off (default), this matches the classic VM use of yield.
3271   // Critical for similar threading behaviour
3272   if (ConvertYieldToSleep) {
3273     os::sleep(thread, MinSleepInterval, false);
3274   } else {
3275     os::yield();
3276   }
3277 JVM_END
3278 






3279 
3280 JVM_ENTRY(void, JVM_Sleep(JNIEnv* env, jclass threadClass, jlong millis))
3281   JVMWrapper("JVM_Sleep");
3282 
3283   if (millis < 0) {
3284     THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "timeout value is negative");
3285   }
3286 
3287   if (Thread::is_interrupted (THREAD, true) && !HAS_PENDING_EXCEPTION) {
3288     THROW_MSG(vmSymbols::java_lang_InterruptedException(), "sleep interrupted");
3289   }
3290 
3291   // Save current thread state and restore it at the end of this block.
3292   // And set new thread state to SLEEPING.
3293   JavaThreadSleepState jtss(thread);
3294 
3295 #ifndef USDT2
3296   HS_DTRACE_PROBE1(hotspot, thread__sleep__begin, millis);
3297 #else /* USDT2 */
3298   HOTSPOT_THREAD_SLEEP_BEGIN(


3305     // When ConvertSleepToYield is on, this matches the classic VM implementation of
3306     // JVM_Sleep. Critical for similar threading behaviour (Win32)
3307     // It appears that in certain GUI contexts, it may be beneficial to do a short sleep
3308     // for SOLARIS
3309     if (ConvertSleepToYield) {
3310       os::yield();
3311     } else {
3312       ThreadState old_state = thread->osthread()->get_state();
3313       thread->osthread()->set_state(SLEEPING);
3314       os::sleep(thread, MinSleepInterval, false);
3315       thread->osthread()->set_state(old_state);
3316     }
3317   } else {
3318     ThreadState old_state = thread->osthread()->get_state();
3319     thread->osthread()->set_state(SLEEPING);
3320     if (os::sleep(thread, millis, true) == OS_INTRPT) {
3321       // An asynchronous exception (e.g., ThreadDeathException) could have been thrown on
3322       // us while we were sleeping. We do not overwrite those.
3323       if (!HAS_PENDING_EXCEPTION) {
3324         if (event.should_commit()) {
3325           event.set_time(millis);
3326           event.commit();
3327         }
3328 #ifndef USDT2
3329         HS_DTRACE_PROBE1(hotspot, thread__sleep__end,1);
3330 #else /* USDT2 */
3331         HOTSPOT_THREAD_SLEEP_END(
3332                                  1);
3333 #endif /* USDT2 */
3334         // TODO-FIXME: THROW_MSG returns which means we will not call set_state()
3335         // to properly restore the thread state.  That's likely wrong.
3336         THROW_MSG(vmSymbols::java_lang_InterruptedException(), "sleep interrupted");
3337       }
3338     }
3339     thread->osthread()->set_state(old_state);
3340   }
3341   if (event.should_commit()) {
3342     event.set_time(millis);
3343     event.commit();
3344   }
3345 #ifndef USDT2
3346   HS_DTRACE_PROBE1(hotspot, thread__sleep__end,0);
3347 #else /* USDT2 */
3348   HOTSPOT_THREAD_SLEEP_END(
3349                            0);
3350 #endif /* USDT2 */
3351 JVM_END
3352 
3353 JVM_ENTRY(jobject, JVM_CurrentThread(JNIEnv* env, jclass threadClass))
3354   JVMWrapper("JVM_CurrentThread");
3355   oop jthread = thread->threadObj();
3356   assert (thread != NULL, "no current thread!");
3357   return JNIHandles::make_local(env, jthread);
3358 JVM_END
3359 
3360 
3361 JVM_ENTRY(jint, JVM_CountStackFrames(JNIEnv* env, jobject jthread))
3362   JVMWrapper("JVM_CountStackFrames");
3363 




  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/classLoader.hpp"
  27 #include "classfile/classLoaderData.inline.hpp"
  28 #include "classfile/classLoaderExt.hpp"
  29 #include "classfile/javaAssertions.hpp"
  30 #include "classfile/javaClasses.hpp"
  31 #include "classfile/symbolTable.hpp"
  32 #include "classfile/systemDictionary.hpp"
  33 #if INCLUDE_CDS
  34 #include "classfile/sharedClassUtil.hpp"
  35 #include "classfile/systemDictionaryShared.hpp"
  36 #endif
  37 #include "classfile/vmSymbols.hpp"
  38 #include "gc_interface/collectedHeap.inline.hpp"
  39 #include "interpreter/bytecode.hpp"
  40 #include "jfr/jfrEvents.hpp"
  41 #include "memory/oopFactory.hpp"
  42 #include "memory/referenceType.hpp"
  43 #include "memory/universe.inline.hpp"
  44 #include "oops/fieldStreams.hpp"
  45 #include "oops/instanceKlass.hpp"
  46 #include "oops/objArrayKlass.hpp"
  47 #include "oops/method.hpp"
  48 #include "prims/jvm.h"
  49 #include "prims/jvm_misc.hpp"
  50 #include "prims/jvmtiExport.hpp"
  51 #include "prims/jvmtiThreadState.hpp"
  52 #include "prims/nativeLookup.hpp"
  53 #include "prims/privilegedStack.hpp"
  54 #include "runtime/arguments.hpp"
  55 #include "runtime/dtraceJSDT.hpp"
  56 #include "runtime/handles.inline.hpp"
  57 #include "runtime/init.hpp"
  58 #include "runtime/interfaceSupport.hpp"
  59 #include "runtime/java.hpp"
  60 #include "runtime/javaCalls.hpp"
  61 #include "runtime/jfieldIDWorkaround.hpp"
  62 #include "runtime/orderAccess.inline.hpp"
  63 #include "runtime/os.hpp"
  64 #include "runtime/perfData.hpp"
  65 #include "runtime/reflection.hpp"
  66 #include "runtime/vframe.hpp"
  67 #include "runtime/vm_operations.hpp"
  68 #include "services/attachListener.hpp"
  69 #include "services/management.hpp"
  70 #include "services/threadService.hpp"

  71 #include "utilities/copy.hpp"
  72 #include "utilities/defaultStream.hpp"
  73 #include "utilities/dtrace.hpp"
  74 #include "utilities/events.hpp"
  75 #include "utilities/histogram.hpp"
  76 #include "utilities/top.hpp"
  77 #include "utilities/utf8.hpp"
  78 #ifdef TARGET_OS_FAMILY_linux
  79 # include "jvm_linux.h"
  80 #endif
  81 #ifdef TARGET_OS_FAMILY_solaris
  82 # include "jvm_solaris.h"
  83 #endif
  84 #ifdef TARGET_OS_FAMILY_windows
  85 # include "jvm_windows.h"
  86 #endif
  87 #ifdef TARGET_OS_FAMILY_aix
  88 # include "jvm_aix.h"
  89 #endif
  90 #ifdef TARGET_OS_FAMILY_bsd


 426   const char* temp_dir = os::get_temp_directory();
 427   Handle h = java_lang_String::create_from_platform_dependent_str(temp_dir, CHECK_NULL);
 428   return (jstring) JNIHandles::make_local(env, h());
 429 JVM_END
 430 
 431 
 432 // java.lang.Runtime /////////////////////////////////////////////////////////////////////////
 433 
 434 extern volatile jint vm_created;
 435 
 436 JVM_ENTRY_NO_ENV(void, JVM_Exit(jint code))
 437   if (vm_created != 0 && (code == 0)) {
 438     // The VM is about to exit. We call back into Java to check whether finalizers should be run
 439     Universe::run_finalizers_on_exit();
 440   }
 441   before_exit(thread);
 442   vm_exit(code);
 443 JVM_END
 444 
 445 
 446 JVM_ENTRY_NO_ENV(void, JVM_BeforeHalt())
 447   JVMWrapper("JVM_BeforeHalt");
 448   EventShutdown event;
 449   if (event.should_commit()) {
 450     event.set_reason("Shutdown requested from Java");
 451     event.commit();
 452   }
 453 JVM_END
 454 
 455 
 456 JVM_ENTRY_NO_ENV(void, JVM_Halt(jint code))
 457   before_exit(thread);
 458   vm_exit(code);
 459 JVM_END
 460 
 461 
 462 JVM_LEAF(void, JVM_OnExit(void (*func)(void)))
 463   register_on_exit_function(func);
 464 JVM_END
 465 
 466 
 467 JVM_ENTRY_NO_ENV(void, JVM_GC(void))
 468   JVMWrapper("JVM_GC");
 469   if (!DisableExplicitGC) {
 470     Universe::heap()->collect(GCCause::_java_lang_system_gc);
 471   }
 472 JVM_END
 473 
 474 
 475 JVM_LEAF(jlong, JVM_MaxObjectInspectionAge(void))


3269 JVM_END
3270 
3271 
3272 JVM_ENTRY(void, JVM_Yield(JNIEnv *env, jclass threadClass))
3273   JVMWrapper("JVM_Yield");
3274   if (os::dont_yield()) return;
3275 #ifndef USDT2
3276   HS_DTRACE_PROBE0(hotspot, thread__yield);
3277 #else /* USDT2 */
3278   HOTSPOT_THREAD_YIELD();
3279 #endif /* USDT2 */
3280   // When ConvertYieldToSleep is off (default), this matches the classic VM use of yield.
3281   // Critical for similar threading behaviour
3282   if (ConvertYieldToSleep) {
3283     os::sleep(thread, MinSleepInterval, false);
3284   } else {
3285     os::yield();
3286   }
3287 JVM_END
3288 
3289 static void post_thread_sleep_event(EventThreadSleep* event, jlong millis) {
3290   assert(event != NULL, "invariant");
3291   assert(event->should_commit(), "invariant");
3292   event->set_time(millis);
3293   event->commit();
3294 }
3295 
3296 JVM_ENTRY(void, JVM_Sleep(JNIEnv* env, jclass threadClass, jlong millis))
3297   JVMWrapper("JVM_Sleep");
3298 
3299   if (millis < 0) {
3300     THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "timeout value is negative");
3301   }
3302 
3303   if (Thread::is_interrupted (THREAD, true) && !HAS_PENDING_EXCEPTION) {
3304     THROW_MSG(vmSymbols::java_lang_InterruptedException(), "sleep interrupted");
3305   }
3306 
3307   // Save current thread state and restore it at the end of this block.
3308   // And set new thread state to SLEEPING.
3309   JavaThreadSleepState jtss(thread);
3310 
3311 #ifndef USDT2
3312   HS_DTRACE_PROBE1(hotspot, thread__sleep__begin, millis);
3313 #else /* USDT2 */
3314   HOTSPOT_THREAD_SLEEP_BEGIN(


3321     // When ConvertSleepToYield is on, this matches the classic VM implementation of
3322     // JVM_Sleep. Critical for similar threading behaviour (Win32)
3323     // It appears that in certain GUI contexts, it may be beneficial to do a short sleep
3324     // for SOLARIS
3325     if (ConvertSleepToYield) {
3326       os::yield();
3327     } else {
3328       ThreadState old_state = thread->osthread()->get_state();
3329       thread->osthread()->set_state(SLEEPING);
3330       os::sleep(thread, MinSleepInterval, false);
3331       thread->osthread()->set_state(old_state);
3332     }
3333   } else {
3334     ThreadState old_state = thread->osthread()->get_state();
3335     thread->osthread()->set_state(SLEEPING);
3336     if (os::sleep(thread, millis, true) == OS_INTRPT) {
3337       // An asynchronous exception (e.g., ThreadDeathException) could have been thrown on
3338       // us while we were sleeping. We do not overwrite those.
3339       if (!HAS_PENDING_EXCEPTION) {
3340         if (event.should_commit()) {
3341           post_thread_sleep_event(&event, millis);

3342         }
3343 #ifndef USDT2
3344         HS_DTRACE_PROBE1(hotspot, thread__sleep__end,1);
3345 #else /* USDT2 */
3346         HOTSPOT_THREAD_SLEEP_END(
3347                                  1);
3348 #endif /* USDT2 */
3349         // TODO-FIXME: THROW_MSG returns which means we will not call set_state()
3350         // to properly restore the thread state.  That's likely wrong.
3351         THROW_MSG(vmSymbols::java_lang_InterruptedException(), "sleep interrupted");
3352       }
3353     }
3354     thread->osthread()->set_state(old_state);
3355   }
3356   if (event.should_commit()) {
3357     post_thread_sleep_event(&event, millis);

3358   }
3359 #ifndef USDT2
3360   HS_DTRACE_PROBE1(hotspot, thread__sleep__end,0);
3361 #else /* USDT2 */
3362   HOTSPOT_THREAD_SLEEP_END(
3363                            0);
3364 #endif /* USDT2 */
3365 JVM_END
3366 
3367 JVM_ENTRY(jobject, JVM_CurrentThread(JNIEnv* env, jclass threadClass))
3368   JVMWrapper("JVM_CurrentThread");
3369   oop jthread = thread->threadObj();
3370   assert (thread != NULL, "no current thread!");
3371   return JNIHandles::make_local(env, jthread);
3372 JVM_END
3373 
3374 
3375 JVM_ENTRY(jint, JVM_CountStackFrames(JNIEnv* env, jobject jthread))
3376   JVMWrapper("JVM_CountStackFrames");
3377 


< prev index next >