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
3192 JVM_END
3193
3194
3195 JVM_ENTRY(void, JVM_Yield(JNIEnv *env, jclass threadClass))
3196 JVMWrapper("JVM_Yield");
3197 if (os::dont_yield()) return;
3198 #ifndef USDT2
3199 HS_DTRACE_PROBE0(hotspot, thread__yield);
3200 #else /* USDT2 */
3201 HOTSPOT_THREAD_YIELD();
3202 #endif /* USDT2 */
3203 // When ConvertYieldToSleep is off (default), this matches the classic VM use of yield.
3204 // Critical for similar threading behaviour
3205 if (ConvertYieldToSleep) {
3206 os::sleep(thread, MinSleepInterval, false);
3207 } else {
3208 os::yield();
3209 }
3210 JVM_END
3211
3212
3213 JVM_ENTRY(void, JVM_Sleep(JNIEnv* env, jclass threadClass, jlong millis))
3214 JVMWrapper("JVM_Sleep");
3215
3216 if (millis < 0) {
3217 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "timeout value is negative");
3218 }
3219
3220 if (Thread::is_interrupted (THREAD, true) && !HAS_PENDING_EXCEPTION) {
3221 THROW_MSG(vmSymbols::java_lang_InterruptedException(), "sleep interrupted");
3222 }
3223
3224 // Save current thread state and restore it at the end of this block.
3225 // And set new thread state to SLEEPING.
3226 JavaThreadSleepState jtss(thread);
3227
3228 #ifndef USDT2
3229 HS_DTRACE_PROBE1(hotspot, thread__sleep__begin, millis);
3230 #else /* USDT2 */
3231 HOTSPOT_THREAD_SLEEP_BEGIN(
3238 // When ConvertSleepToYield is on, this matches the classic VM implementation of
3239 // JVM_Sleep. Critical for similar threading behaviour (Win32)
3240 // It appears that in certain GUI contexts, it may be beneficial to do a short sleep
3241 // for SOLARIS
3242 if (ConvertSleepToYield) {
3243 os::yield();
3244 } else {
3245 ThreadState old_state = thread->osthread()->get_state();
3246 thread->osthread()->set_state(SLEEPING);
3247 os::sleep(thread, MinSleepInterval, false);
3248 thread->osthread()->set_state(old_state);
3249 }
3250 } else {
3251 ThreadState old_state = thread->osthread()->get_state();
3252 thread->osthread()->set_state(SLEEPING);
3253 if (os::sleep(thread, millis, true) == OS_INTRPT) {
3254 // An asynchronous exception (e.g., ThreadDeathException) could have been thrown on
3255 // us while we were sleeping. We do not overwrite those.
3256 if (!HAS_PENDING_EXCEPTION) {
3257 if (event.should_commit()) {
3258 event.set_time(millis);
3259 event.commit();
3260 }
3261 #ifndef USDT2
3262 HS_DTRACE_PROBE1(hotspot, thread__sleep__end,1);
3263 #else /* USDT2 */
3264 HOTSPOT_THREAD_SLEEP_END(
3265 1);
3266 #endif /* USDT2 */
3267 // TODO-FIXME: THROW_MSG returns which means we will not call set_state()
3268 // to properly restore the thread state. That's likely wrong.
3269 THROW_MSG(vmSymbols::java_lang_InterruptedException(), "sleep interrupted");
3270 }
3271 }
3272 thread->osthread()->set_state(old_state);
3273 }
3274 if (event.should_commit()) {
3275 event.set_time(millis);
3276 event.commit();
3277 }
3278 #ifndef USDT2
3279 HS_DTRACE_PROBE1(hotspot, thread__sleep__end,0);
3280 #else /* USDT2 */
3281 HOTSPOT_THREAD_SLEEP_END(
3282 0);
3283 #endif /* USDT2 */
3284 JVM_END
3285
3286 JVM_ENTRY(jobject, JVM_CurrentThread(JNIEnv* env, jclass threadClass))
3287 JVMWrapper("JVM_CurrentThread");
3288 oop jthread = thread->threadObj();
3289 assert (thread != NULL, "no current thread!");
3290 return JNIHandles::make_local(env, jthread);
3291 JVM_END
3292
3293
3294 JVM_ENTRY(jint, JVM_CountStackFrames(JNIEnv* env, jobject jthread))
3295 JVMWrapper("JVM_CountStackFrames");
3296
|
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
3192 JVM_END
3193
3194
3195 JVM_ENTRY(void, JVM_Yield(JNIEnv *env, jclass threadClass))
3196 JVMWrapper("JVM_Yield");
3197 if (os::dont_yield()) return;
3198 #ifndef USDT2
3199 HS_DTRACE_PROBE0(hotspot, thread__yield);
3200 #else /* USDT2 */
3201 HOTSPOT_THREAD_YIELD();
3202 #endif /* USDT2 */
3203 // When ConvertYieldToSleep is off (default), this matches the classic VM use of yield.
3204 // Critical for similar threading behaviour
3205 if (ConvertYieldToSleep) {
3206 os::sleep(thread, MinSleepInterval, false);
3207 } else {
3208 os::yield();
3209 }
3210 JVM_END
3211
3212 static void post_thread_sleep_event(EventThreadSleep* event, jlong millis) {
3213 assert(event != NULL, "invariant");
3214 assert(event->should_commit(), "invariant");
3215 event->set_time(millis);
3216 event->commit();
3217 }
3218
3219 JVM_ENTRY(void, JVM_Sleep(JNIEnv* env, jclass threadClass, jlong millis))
3220 JVMWrapper("JVM_Sleep");
3221
3222 if (millis < 0) {
3223 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "timeout value is negative");
3224 }
3225
3226 if (Thread::is_interrupted (THREAD, true) && !HAS_PENDING_EXCEPTION) {
3227 THROW_MSG(vmSymbols::java_lang_InterruptedException(), "sleep interrupted");
3228 }
3229
3230 // Save current thread state and restore it at the end of this block.
3231 // And set new thread state to SLEEPING.
3232 JavaThreadSleepState jtss(thread);
3233
3234 #ifndef USDT2
3235 HS_DTRACE_PROBE1(hotspot, thread__sleep__begin, millis);
3236 #else /* USDT2 */
3237 HOTSPOT_THREAD_SLEEP_BEGIN(
3244 // When ConvertSleepToYield is on, this matches the classic VM implementation of
3245 // JVM_Sleep. Critical for similar threading behaviour (Win32)
3246 // It appears that in certain GUI contexts, it may be beneficial to do a short sleep
3247 // for SOLARIS
3248 if (ConvertSleepToYield) {
3249 os::yield();
3250 } else {
3251 ThreadState old_state = thread->osthread()->get_state();
3252 thread->osthread()->set_state(SLEEPING);
3253 os::sleep(thread, MinSleepInterval, false);
3254 thread->osthread()->set_state(old_state);
3255 }
3256 } else {
3257 ThreadState old_state = thread->osthread()->get_state();
3258 thread->osthread()->set_state(SLEEPING);
3259 if (os::sleep(thread, millis, true) == OS_INTRPT) {
3260 // An asynchronous exception (e.g., ThreadDeathException) could have been thrown on
3261 // us while we were sleeping. We do not overwrite those.
3262 if (!HAS_PENDING_EXCEPTION) {
3263 if (event.should_commit()) {
3264 post_thread_sleep_event(&event, millis);
3265 }
3266 #ifndef USDT2
3267 HS_DTRACE_PROBE1(hotspot, thread__sleep__end,1);
3268 #else /* USDT2 */
3269 HOTSPOT_THREAD_SLEEP_END(
3270 1);
3271 #endif /* USDT2 */
3272 // TODO-FIXME: THROW_MSG returns which means we will not call set_state()
3273 // to properly restore the thread state. That's likely wrong.
3274 THROW_MSG(vmSymbols::java_lang_InterruptedException(), "sleep interrupted");
3275 }
3276 }
3277 thread->osthread()->set_state(old_state);
3278 }
3279 if (event.should_commit()) {
3280 post_thread_sleep_event(&event, millis);
3281 }
3282 #ifndef USDT2
3283 HS_DTRACE_PROBE1(hotspot, thread__sleep__end,0);
3284 #else /* USDT2 */
3285 HOTSPOT_THREAD_SLEEP_END(
3286 0);
3287 #endif /* USDT2 */
3288 JVM_END
3289
3290 JVM_ENTRY(jobject, JVM_CurrentThread(JNIEnv* env, jclass threadClass))
3291 JVMWrapper("JVM_CurrentThread");
3292 oop jthread = thread->threadObj();
3293 assert (thread != NULL, "no current thread!");
3294 return JNIHandles::make_local(env, jthread);
3295 JVM_END
3296
3297
3298 JVM_ENTRY(jint, JVM_CountStackFrames(JNIEnv* env, jobject jthread))
3299 JVMWrapper("JVM_CountStackFrames");
3300
|