src/share/vm/prims/jvm.cpp

Print this page
rev 4773 : 8005849: JEP 167: Event-Based JVM Tracing
Reviewed-by: acorn, coleenp, sla
Contributed-by: Karen Kinnear <karen.kinnear@oracle.com>, Bengt Rutisson <bengt.rutisson@oracle.com>, Calvin Cheung <calvin.cheung@oracle.com>, Erik Gahlin <erik.gahlin@oracle.com>, Erik Helin <erik.helin@oracle.com>, Jesper Wilhelmsson <jesper.wilhelmsson@oracle.com>, Keith McGuigan <keith.mcguigan@oracle.com>, Mattias Tobiasson <mattias.tobiasson@oracle.com>, Markus Gronlund <markus.gronlund@oracle.com>, Mikael Auno <mikael.auno@oracle.com>, Nils Eliasson <nils.eliasson@oracle.com>, Nils Loodin <nils.loodin@oracle.com>, Rickard Backman <rickard.backman@oracle.com>, Staffan Larsen <staffan.larsen@oracle.com>, Stefan Karlsson <stefan.karlsson@oracle.com>, Yekaterina Kantserova <yekaterina.kantserova@oracle.com>


  42 #include "prims/jvmtiExport.hpp"
  43 #include "prims/jvmtiThreadState.hpp"
  44 #include "prims/nativeLookup.hpp"
  45 #include "prims/privilegedStack.hpp"
  46 #include "runtime/arguments.hpp"
  47 #include "runtime/dtraceJSDT.hpp"
  48 #include "runtime/handles.inline.hpp"
  49 #include "runtime/init.hpp"
  50 #include "runtime/interfaceSupport.hpp"
  51 #include "runtime/java.hpp"
  52 #include "runtime/javaCalls.hpp"
  53 #include "runtime/jfieldIDWorkaround.hpp"
  54 #include "runtime/os.hpp"
  55 #include "runtime/perfData.hpp"
  56 #include "runtime/reflection.hpp"
  57 #include "runtime/vframe.hpp"
  58 #include "runtime/vm_operations.hpp"
  59 #include "services/attachListener.hpp"
  60 #include "services/management.hpp"
  61 #include "services/threadService.hpp"

  62 #include "utilities/copy.hpp"
  63 #include "utilities/defaultStream.hpp"
  64 #include "utilities/dtrace.hpp"
  65 #include "utilities/events.hpp"
  66 #include "utilities/histogram.hpp"
  67 #include "utilities/top.hpp"
  68 #include "utilities/utf8.hpp"
  69 #ifdef TARGET_OS_FAMILY_linux
  70 # include "jvm_linux.h"
  71 #endif
  72 #ifdef TARGET_OS_FAMILY_solaris
  73 # include "jvm_solaris.h"
  74 #endif
  75 #ifdef TARGET_OS_FAMILY_windows
  76 # include "jvm_windows.h"
  77 #endif
  78 #ifdef TARGET_OS_FAMILY_bsd
  79 # include "jvm_bsd.h"
  80 #endif
  81 


2982 
2983   if (millis < 0) {
2984     THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "timeout value is negative");
2985   }
2986 
2987   if (Thread::is_interrupted (THREAD, true) && !HAS_PENDING_EXCEPTION) {
2988     THROW_MSG(vmSymbols::java_lang_InterruptedException(), "sleep interrupted");
2989   }
2990 
2991   // Save current thread state and restore it at the end of this block.
2992   // And set new thread state to SLEEPING.
2993   JavaThreadSleepState jtss(thread);
2994 
2995 #ifndef USDT2
2996   HS_DTRACE_PROBE1(hotspot, thread__sleep__begin, millis);
2997 #else /* USDT2 */
2998   HOTSPOT_THREAD_SLEEP_BEGIN(
2999                              millis);
3000 #endif /* USDT2 */
3001 


3002   if (millis == 0) {
3003     // When ConvertSleepToYield is on, this matches the classic VM implementation of
3004     // JVM_Sleep. Critical for similar threading behaviour (Win32)
3005     // It appears that in certain GUI contexts, it may be beneficial to do a short sleep
3006     // for SOLARIS
3007     if (ConvertSleepToYield) {
3008       os::yield();
3009     } else {
3010       ThreadState old_state = thread->osthread()->get_state();
3011       thread->osthread()->set_state(SLEEPING);
3012       os::sleep(thread, MinSleepInterval, false);
3013       thread->osthread()->set_state(old_state);
3014     }
3015   } else {
3016     ThreadState old_state = thread->osthread()->get_state();
3017     thread->osthread()->set_state(SLEEPING);
3018     if (os::sleep(thread, millis, true) == OS_INTRPT) {
3019       // An asynchronous exception (e.g., ThreadDeathException) could have been thrown on
3020       // us while we were sleeping. We do not overwrite those.
3021       if (!HAS_PENDING_EXCEPTION) {




3022 #ifndef USDT2
3023         HS_DTRACE_PROBE1(hotspot, thread__sleep__end,1);
3024 #else /* USDT2 */
3025         HOTSPOT_THREAD_SLEEP_END(
3026                                  1);
3027 #endif /* USDT2 */
3028         // TODO-FIXME: THROW_MSG returns which means we will not call set_state()
3029         // to properly restore the thread state.  That's likely wrong.
3030         THROW_MSG(vmSymbols::java_lang_InterruptedException(), "sleep interrupted");
3031       }
3032     }
3033     thread->osthread()->set_state(old_state);
3034   }




3035 #ifndef USDT2
3036   HS_DTRACE_PROBE1(hotspot, thread__sleep__end,0);
3037 #else /* USDT2 */
3038   HOTSPOT_THREAD_SLEEP_END(
3039                            0);
3040 #endif /* USDT2 */
3041 JVM_END
3042 
3043 JVM_ENTRY(jobject, JVM_CurrentThread(JNIEnv* env, jclass threadClass))
3044   JVMWrapper("JVM_CurrentThread");
3045   oop jthread = thread->threadObj();
3046   assert (thread != NULL, "no current thread!");
3047   return JNIHandles::make_local(env, jthread);
3048 JVM_END
3049 
3050 
3051 JVM_ENTRY(jint, JVM_CountStackFrames(JNIEnv* env, jobject jthread))
3052   JVMWrapper("JVM_CountStackFrames");
3053 
3054   // Ensure that the C++ Thread and OSThread structures aren't freed before we operate




  42 #include "prims/jvmtiExport.hpp"
  43 #include "prims/jvmtiThreadState.hpp"
  44 #include "prims/nativeLookup.hpp"
  45 #include "prims/privilegedStack.hpp"
  46 #include "runtime/arguments.hpp"
  47 #include "runtime/dtraceJSDT.hpp"
  48 #include "runtime/handles.inline.hpp"
  49 #include "runtime/init.hpp"
  50 #include "runtime/interfaceSupport.hpp"
  51 #include "runtime/java.hpp"
  52 #include "runtime/javaCalls.hpp"
  53 #include "runtime/jfieldIDWorkaround.hpp"
  54 #include "runtime/os.hpp"
  55 #include "runtime/perfData.hpp"
  56 #include "runtime/reflection.hpp"
  57 #include "runtime/vframe.hpp"
  58 #include "runtime/vm_operations.hpp"
  59 #include "services/attachListener.hpp"
  60 #include "services/management.hpp"
  61 #include "services/threadService.hpp"
  62 #include "trace/tracing.hpp"
  63 #include "utilities/copy.hpp"
  64 #include "utilities/defaultStream.hpp"
  65 #include "utilities/dtrace.hpp"
  66 #include "utilities/events.hpp"
  67 #include "utilities/histogram.hpp"
  68 #include "utilities/top.hpp"
  69 #include "utilities/utf8.hpp"
  70 #ifdef TARGET_OS_FAMILY_linux
  71 # include "jvm_linux.h"
  72 #endif
  73 #ifdef TARGET_OS_FAMILY_solaris
  74 # include "jvm_solaris.h"
  75 #endif
  76 #ifdef TARGET_OS_FAMILY_windows
  77 # include "jvm_windows.h"
  78 #endif
  79 #ifdef TARGET_OS_FAMILY_bsd
  80 # include "jvm_bsd.h"
  81 #endif
  82 


2983 
2984   if (millis < 0) {
2985     THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "timeout value is negative");
2986   }
2987 
2988   if (Thread::is_interrupted (THREAD, true) && !HAS_PENDING_EXCEPTION) {
2989     THROW_MSG(vmSymbols::java_lang_InterruptedException(), "sleep interrupted");
2990   }
2991 
2992   // Save current thread state and restore it at the end of this block.
2993   // And set new thread state to SLEEPING.
2994   JavaThreadSleepState jtss(thread);
2995 
2996 #ifndef USDT2
2997   HS_DTRACE_PROBE1(hotspot, thread__sleep__begin, millis);
2998 #else /* USDT2 */
2999   HOTSPOT_THREAD_SLEEP_BEGIN(
3000                              millis);
3001 #endif /* USDT2 */
3002 
3003   EventThreadSleep event;
3004 
3005   if (millis == 0) {
3006     // When ConvertSleepToYield is on, this matches the classic VM implementation of
3007     // JVM_Sleep. Critical for similar threading behaviour (Win32)
3008     // It appears that in certain GUI contexts, it may be beneficial to do a short sleep
3009     // for SOLARIS
3010     if (ConvertSleepToYield) {
3011       os::yield();
3012     } else {
3013       ThreadState old_state = thread->osthread()->get_state();
3014       thread->osthread()->set_state(SLEEPING);
3015       os::sleep(thread, MinSleepInterval, false);
3016       thread->osthread()->set_state(old_state);
3017     }
3018   } else {
3019     ThreadState old_state = thread->osthread()->get_state();
3020     thread->osthread()->set_state(SLEEPING);
3021     if (os::sleep(thread, millis, true) == OS_INTRPT) {
3022       // An asynchronous exception (e.g., ThreadDeathException) could have been thrown on
3023       // us while we were sleeping. We do not overwrite those.
3024       if (!HAS_PENDING_EXCEPTION) {
3025         if (event.should_commit()) {
3026           event.set_time(millis);
3027           event.commit();
3028         }
3029 #ifndef USDT2
3030         HS_DTRACE_PROBE1(hotspot, thread__sleep__end,1);
3031 #else /* USDT2 */
3032         HOTSPOT_THREAD_SLEEP_END(
3033                                  1);
3034 #endif /* USDT2 */
3035         // TODO-FIXME: THROW_MSG returns which means we will not call set_state()
3036         // to properly restore the thread state.  That's likely wrong.
3037         THROW_MSG(vmSymbols::java_lang_InterruptedException(), "sleep interrupted");
3038       }
3039     }
3040     thread->osthread()->set_state(old_state);
3041   }
3042   if (event.should_commit()) {
3043     event.set_time(millis);
3044     event.commit();
3045   }
3046 #ifndef USDT2
3047   HS_DTRACE_PROBE1(hotspot, thread__sleep__end,0);
3048 #else /* USDT2 */
3049   HOTSPOT_THREAD_SLEEP_END(
3050                            0);
3051 #endif /* USDT2 */
3052 JVM_END
3053 
3054 JVM_ENTRY(jobject, JVM_CurrentThread(JNIEnv* env, jclass threadClass))
3055   JVMWrapper("JVM_CurrentThread");
3056   oop jthread = thread->threadObj();
3057   assert (thread != NULL, "no current thread!");
3058   return JNIHandles::make_local(env, jthread);
3059 JVM_END
3060 
3061 
3062 JVM_ENTRY(jint, JVM_CountStackFrames(JNIEnv* env, jobject jthread))
3063   JVMWrapper("JVM_CountStackFrames");
3064 
3065   // Ensure that the C++ Thread and OSThread structures aren't freed before we operate