hotspot/src/share/vm/prims/jvm.cpp
changeset 10739 91935236600e
parent 10565 dc90c239f4ec
child 11256 025cd1741566
equal deleted inserted replaced
10738:cc19612c6b9f 10739:91935236600e
    77 # include "jvm_bsd.h"
    77 # include "jvm_bsd.h"
    78 #endif
    78 #endif
    79 
    79 
    80 #include <errno.h>
    80 #include <errno.h>
    81 
    81 
       
    82 #ifndef USDT2
    82 HS_DTRACE_PROBE_DECL1(hotspot, thread__sleep__begin, long long);
    83 HS_DTRACE_PROBE_DECL1(hotspot, thread__sleep__begin, long long);
    83 HS_DTRACE_PROBE_DECL1(hotspot, thread__sleep__end, int);
    84 HS_DTRACE_PROBE_DECL1(hotspot, thread__sleep__end, int);
    84 HS_DTRACE_PROBE_DECL0(hotspot, thread__yield);
    85 HS_DTRACE_PROBE_DECL0(hotspot, thread__yield);
       
    86 #endif /* !USDT2 */
    85 
    87 
    86 /*
    88 /*
    87   NOTE about use of any ctor or function call that can trigger a safepoint/GC:
    89   NOTE about use of any ctor or function call that can trigger a safepoint/GC:
    88   such ctors and calls MUST NOT come between an oop declaration/init and its
    90   such ctors and calls MUST NOT come between an oop declaration/init and its
    89   usage because if objects are move this may cause various memory stomps, bus
    91   usage because if objects are move this may cause various memory stomps, bus
  2814 
  2816 
  2815 
  2817 
  2816 JVM_ENTRY(void, JVM_Yield(JNIEnv *env, jclass threadClass))
  2818 JVM_ENTRY(void, JVM_Yield(JNIEnv *env, jclass threadClass))
  2817   JVMWrapper("JVM_Yield");
  2819   JVMWrapper("JVM_Yield");
  2818   if (os::dont_yield()) return;
  2820   if (os::dont_yield()) return;
       
  2821 #ifndef USDT2
  2819   HS_DTRACE_PROBE0(hotspot, thread__yield);
  2822   HS_DTRACE_PROBE0(hotspot, thread__yield);
       
  2823 #else /* USDT2 */
       
  2824   HOTSPOT_THREAD_YIELD();
       
  2825 #endif /* USDT2 */
  2820   // When ConvertYieldToSleep is off (default), this matches the classic VM use of yield.
  2826   // When ConvertYieldToSleep is off (default), this matches the classic VM use of yield.
  2821   // Critical for similar threading behaviour
  2827   // Critical for similar threading behaviour
  2822   if (ConvertYieldToSleep) {
  2828   if (ConvertYieldToSleep) {
  2823     os::sleep(thread, MinSleepInterval, false);
  2829     os::sleep(thread, MinSleepInterval, false);
  2824   } else {
  2830   } else {
  2840 
  2846 
  2841   // Save current thread state and restore it at the end of this block.
  2847   // Save current thread state and restore it at the end of this block.
  2842   // And set new thread state to SLEEPING.
  2848   // And set new thread state to SLEEPING.
  2843   JavaThreadSleepState jtss(thread);
  2849   JavaThreadSleepState jtss(thread);
  2844 
  2850 
       
  2851 #ifndef USDT2
  2845   HS_DTRACE_PROBE1(hotspot, thread__sleep__begin, millis);
  2852   HS_DTRACE_PROBE1(hotspot, thread__sleep__begin, millis);
       
  2853 #else /* USDT2 */
       
  2854   HOTSPOT_THREAD_SLEEP_BEGIN(
       
  2855                              millis);
       
  2856 #endif /* USDT2 */
  2846 
  2857 
  2847   if (millis == 0) {
  2858   if (millis == 0) {
  2848     // When ConvertSleepToYield is on, this matches the classic VM implementation of
  2859     // When ConvertSleepToYield is on, this matches the classic VM implementation of
  2849     // JVM_Sleep. Critical for similar threading behaviour (Win32)
  2860     // JVM_Sleep. Critical for similar threading behaviour (Win32)
  2850     // It appears that in certain GUI contexts, it may be beneficial to do a short sleep
  2861     // It appears that in certain GUI contexts, it may be beneficial to do a short sleep
  2862     thread->osthread()->set_state(SLEEPING);
  2873     thread->osthread()->set_state(SLEEPING);
  2863     if (os::sleep(thread, millis, true) == OS_INTRPT) {
  2874     if (os::sleep(thread, millis, true) == OS_INTRPT) {
  2864       // An asynchronous exception (e.g., ThreadDeathException) could have been thrown on
  2875       // An asynchronous exception (e.g., ThreadDeathException) could have been thrown on
  2865       // us while we were sleeping. We do not overwrite those.
  2876       // us while we were sleeping. We do not overwrite those.
  2866       if (!HAS_PENDING_EXCEPTION) {
  2877       if (!HAS_PENDING_EXCEPTION) {
       
  2878 #ifndef USDT2
  2867         HS_DTRACE_PROBE1(hotspot, thread__sleep__end,1);
  2879         HS_DTRACE_PROBE1(hotspot, thread__sleep__end,1);
       
  2880 #else /* USDT2 */
       
  2881         HOTSPOT_THREAD_SLEEP_END(
       
  2882                                  1);
       
  2883 #endif /* USDT2 */
  2868         // TODO-FIXME: THROW_MSG returns which means we will not call set_state()
  2884         // TODO-FIXME: THROW_MSG returns which means we will not call set_state()
  2869         // to properly restore the thread state.  That's likely wrong.
  2885         // to properly restore the thread state.  That's likely wrong.
  2870         THROW_MSG(vmSymbols::java_lang_InterruptedException(), "sleep interrupted");
  2886         THROW_MSG(vmSymbols::java_lang_InterruptedException(), "sleep interrupted");
  2871       }
  2887       }
  2872     }
  2888     }
  2873     thread->osthread()->set_state(old_state);
  2889     thread->osthread()->set_state(old_state);
  2874   }
  2890   }
       
  2891 #ifndef USDT2
  2875   HS_DTRACE_PROBE1(hotspot, thread__sleep__end,0);
  2892   HS_DTRACE_PROBE1(hotspot, thread__sleep__end,0);
       
  2893 #else /* USDT2 */
       
  2894   HOTSPOT_THREAD_SLEEP_END(
       
  2895                            0);
       
  2896 #endif /* USDT2 */
  2876 JVM_END
  2897 JVM_END
  2877 
  2898 
  2878 JVM_ENTRY(jobject, JVM_CurrentThread(JNIEnv* env, jclass threadClass))
  2899 JVM_ENTRY(jobject, JVM_CurrentThread(JNIEnv* env, jclass threadClass))
  2879   JVMWrapper("JVM_CurrentThread");
  2900   JVMWrapper("JVM_CurrentThread");
  2880   oop jthread = thread->threadObj();
  2901   oop jthread = thread->threadObj();
  2988   if (JvmtiExport::should_post_data_dump()) {
  3009   if (JvmtiExport::should_post_data_dump()) {
  2989     JvmtiExport::post_data_dump();
  3010     JvmtiExport::post_data_dump();
  2990   }
  3011   }
  2991 JVM_END
  3012 JVM_END
  2992 
  3013 
       
  3014 JVM_ENTRY(void, JVM_SetNativeThreadName(JNIEnv* env, jobject jthread, jstring name))
       
  3015   JVMWrapper("JVM_SetNativeThreadName");
       
  3016   ResourceMark rm(THREAD);
       
  3017   oop java_thread = JNIHandles::resolve_non_null(jthread);
       
  3018   JavaThread* thr = java_lang_Thread::thread(java_thread);
       
  3019   // Thread naming only supported for the current thread, doesn't work for
       
  3020   // target threads.
       
  3021   if (Thread::current() == thr && !thr->has_attached_via_jni()) {
       
  3022     // we don't set the name of an attached thread to avoid stepping
       
  3023     // on other programs
       
  3024     const char *thread_name = java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(name));
       
  3025     os::set_native_thread_name(thread_name);
       
  3026   }
       
  3027 JVM_END
  2993 
  3028 
  2994 // java.lang.SecurityManager ///////////////////////////////////////////////////////////////////////
  3029 // java.lang.SecurityManager ///////////////////////////////////////////////////////////////////////
  2995 
  3030 
  2996 static bool is_trusted_frame(JavaThread* jthread, vframeStream* vfst) {
  3031 static bool is_trusted_frame(JavaThread* jthread, vframeStream* vfst) {
  2997   assert(jthread->is_Java_thread(), "must be a Java thread");
  3032   assert(jthread->is_Java_thread(), "must be a Java thread");