< prev index next >

src/hotspot/share/prims/jvm.cpp

Print this page




2961   if (millis < 0) {
2962     THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "timeout value is negative");
2963   }
2964 
2965   if (Thread::is_interrupted (THREAD, true) && !HAS_PENDING_EXCEPTION) {
2966     THROW_MSG(vmSymbols::java_lang_InterruptedException(), "sleep interrupted");
2967   }
2968 
2969   // Save current thread state and restore it at the end of this block.
2970   // And set new thread state to SLEEPING.
2971   JavaThreadSleepState jtss(thread);
2972 
2973   HOTSPOT_THREAD_SLEEP_BEGIN(millis);
2974   EventThreadSleep event;
2975 
2976   if (millis == 0) {
2977     os::naked_yield();
2978   } else {
2979     ThreadState old_state = thread->osthread()->get_state();
2980     thread->osthread()->set_state(SLEEPING);
2981     if (os::sleep(thread, millis) == OS_INTRPT) {
2982       // An asynchronous exception (e.g., ThreadDeathException) could have been thrown on
2983       // us while we were sleeping. We do not overwrite those.
2984       if (!HAS_PENDING_EXCEPTION) {
2985         if (event.should_commit()) {
2986           post_thread_sleep_event(&event, millis);
2987         }
2988         HOTSPOT_THREAD_SLEEP_END(1);
2989 
2990         // TODO-FIXME: THROW_MSG returns which means we will not call set_state()
2991         // to properly restore the thread state.  That's likely wrong.
2992         THROW_MSG(vmSymbols::java_lang_InterruptedException(), "sleep interrupted");
2993       }
2994     }
2995     thread->osthread()->set_state(old_state);
2996   }
2997   if (event.should_commit()) {
2998     post_thread_sleep_event(&event, millis);
2999   }
3000   HOTSPOT_THREAD_SLEEP_END(0);
3001 JVM_END




2961   if (millis < 0) {
2962     THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "timeout value is negative");
2963   }
2964 
2965   if (Thread::is_interrupted (THREAD, true) && !HAS_PENDING_EXCEPTION) {
2966     THROW_MSG(vmSymbols::java_lang_InterruptedException(), "sleep interrupted");
2967   }
2968 
2969   // Save current thread state and restore it at the end of this block.
2970   // And set new thread state to SLEEPING.
2971   JavaThreadSleepState jtss(thread);
2972 
2973   HOTSPOT_THREAD_SLEEP_BEGIN(millis);
2974   EventThreadSleep event;
2975 
2976   if (millis == 0) {
2977     os::naked_yield();
2978   } else {
2979     ThreadState old_state = thread->osthread()->get_state();
2980     thread->osthread()->set_state(SLEEPING);
2981     if (!thread->sleep(millis)) { // interrupted
2982       // An asynchronous exception (e.g., ThreadDeathException) could have been thrown on
2983       // us while we were sleeping. We do not overwrite those.
2984       if (!HAS_PENDING_EXCEPTION) {
2985         if (event.should_commit()) {
2986           post_thread_sleep_event(&event, millis);
2987         }
2988         HOTSPOT_THREAD_SLEEP_END(1);
2989 
2990         // TODO-FIXME: THROW_MSG returns which means we will not call set_state()
2991         // to properly restore the thread state.  That's likely wrong.
2992         THROW_MSG(vmSymbols::java_lang_InterruptedException(), "sleep interrupted");
2993       }
2994     }
2995     thread->osthread()->set_state(old_state);
2996   }
2997   if (event.should_commit()) {
2998     post_thread_sleep_event(&event, millis);
2999   }
3000   HOTSPOT_THREAD_SLEEP_END(0);
3001 JVM_END


< prev index next >