src/os/linux/vm/os_linux.cpp

Print this page




3851       // the 1st iteration ...
3852       jlong newtime = javaTimeNanos();
3853 
3854       if (newtime - prevtime < 0) {
3855         // time moving backwards, should only happen if no monotonic clock
3856         // not a guarantee() because JVM should not abort on kernel/glibc bugs
3857         assert(!Linux::supports_monotonic_clock(), "time moving backwards");
3858       } else {
3859         millis -= (newtime - prevtime) / NANOSECS_PER_MILLISEC;
3860       }
3861 
3862       if(millis <= 0) break ;
3863 
3864       prevtime = newtime;
3865       slp->park(millis);
3866     }
3867     return OS_OK ;
3868   }
3869 }
3870 
3871 int os::naked_sleep() {
3872   // %% make the sleep time an integer flag. for now use 1 millisec.
3873   return os::sleep(Thread::current(), 1, false);
























3874 }
3875 
3876 // Sleep forever; naked call to OS-specific sleep; use with CAUTION
3877 void os::infinite_sleep() {
3878   while (true) {    // sleep forever ...
3879     ::sleep(100);   // ... 100 seconds at a time
3880   }
3881 }
3882 
3883 // Used to convert frequent JVM_Yield() to nops
3884 bool os::dont_yield() {
3885   return DontYieldALot;
3886 }
3887 
3888 void os::yield() {
3889   sched_yield();
3890 }
3891 
3892 os::YieldResult os::NakedYield() { sched_yield(); return os::YIELD_UNKNOWN ;}
3893 




3851       // the 1st iteration ...
3852       jlong newtime = javaTimeNanos();
3853 
3854       if (newtime - prevtime < 0) {
3855         // time moving backwards, should only happen if no monotonic clock
3856         // not a guarantee() because JVM should not abort on kernel/glibc bugs
3857         assert(!Linux::supports_monotonic_clock(), "time moving backwards");
3858       } else {
3859         millis -= (newtime - prevtime) / NANOSECS_PER_MILLISEC;
3860       }
3861 
3862       if(millis <= 0) break ;
3863 
3864       prevtime = newtime;
3865       slp->park(millis);
3866     }
3867     return OS_OK ;
3868   }
3869 }
3870 
3871 //
3872 // Short sleep, direct OS call.
3873 //
3874 // Note: certain versions of Linux CFS scheduler (since 2.6.23) do not guarantee
3875 // sched_yield(2) will actually give up the CPU:
3876 //
3877 //   * Alone on this pariticular CPU, keeps running.
3878 //   * Before the introduction of "skip_buddy" with "compat_yield" disabled 
3879 //     (pre 2.6.39).
3880 //
3881 // So calling this with 0 is an alternative.
3882 //
3883 void os::naked_short_sleep(jlong ms) {
3884   struct timespec req;
3885 
3886   assert(ms < 1000, "Un-interruptable sleep, short time use only");
3887   req.tv_sec = 0;
3888   if (ms > 0) {
3889     req.tv_nsec = (ms % 1000) * 1000000;
3890   }
3891   else {
3892     req.tv_nsec = 1;
3893   }
3894 
3895   nanosleep(&req, NULL);
3896 
3897   return;
3898 }
3899 
3900 // Sleep forever; naked call to OS-specific sleep; use with CAUTION
3901 void os::infinite_sleep() {
3902   while (true) {    // sleep forever ...
3903     ::sleep(100);   // ... 100 seconds at a time
3904   }
3905 }
3906 
3907 // Used to convert frequent JVM_Yield() to nops
3908 bool os::dont_yield() {
3909   return DontYieldALot;
3910 }
3911 
3912 void os::yield() {
3913   sched_yield();
3914 }
3915 
3916 os::YieldResult os::NakedYield() { sched_yield(); return os::YIELD_UNKNOWN ;}
3917