comparison src/os/aix/vm/os_aix.cpp @ 14703:9486a41de3b7

Merge
author amurillo
date Fri, 14 Mar 2014 10:31:11 -0700
parents 97586c131ac8
children 92aa6797d639
comparison
equal deleted inserted replaced
14656:74dd0c7b2de1 14703:9486a41de3b7
1133 return jlong(time.tb_high) * (1000 * 1000 * 1000) + jlong(time.tb_low); 1133 return jlong(time.tb_high) * (1000 * 1000 * 1000) + jlong(time.tb_low);
1134 } 1134 }
1135 } 1135 }
1136 1136
1137 void os::javaTimeNanos_info(jvmtiTimerInfo *info_ptr) { 1137 void os::javaTimeNanos_info(jvmtiTimerInfo *info_ptr) {
1138 { 1138 info_ptr->max_value = ALL_64_BITS;
1139 // gettimeofday - based on time in seconds since the Epoch thus does not wrap 1139 // mread_real_time() is monotonic (see 'os::javaTimeNanos()')
1140 info_ptr->max_value = ALL_64_BITS; 1140 info_ptr->may_skip_backward = false;
1141 1141 info_ptr->may_skip_forward = false;
1142 // gettimeofday is a real time clock so it skips
1143 info_ptr->may_skip_backward = true;
1144 info_ptr->may_skip_forward = true;
1145 }
1146
1147 info_ptr->kind = JVMTI_TIMER_ELAPSED; // elapsed not CPU time 1142 info_ptr->kind = JVMTI_TIMER_ELAPSED; // elapsed not CPU time
1148 } 1143 }
1149 1144
1150 // Return the real, user, and system times in seconds from an 1145 // Return the real, user, and system times in seconds from an
1151 // arbitrary fixed point in the past. 1146 // arbitrary fixed point in the past.
2797 2792
2798 size_t os::read(int fd, void *buf, unsigned int nBytes) { 2793 size_t os::read(int fd, void *buf, unsigned int nBytes) {
2799 return ::read(fd, buf, nBytes); 2794 return ::read(fd, buf, nBytes);
2800 } 2795 }
2801 2796
2802 #define NANOSECS_PER_MILLISEC 1000000
2803
2804 int os::sleep(Thread* thread, jlong millis, bool interruptible) {
2805 assert(thread == Thread::current(), "thread consistency check");
2806
2807 // Prevent nasty overflow in deadline calculation
2808 // by handling long sleeps similar to solaris or windows.
2809 const jlong limit = INT_MAX;
2810 int result;
2811 while (millis > limit) {
2812 if ((result = os::sleep(thread, limit, interruptible)) != OS_OK) {
2813 return result;
2814 }
2815 millis -= limit;
2816 }
2817
2818 ParkEvent * const slp = thread->_SleepEvent;
2819 slp->reset();
2820 OrderAccess::fence();
2821
2822 if (interruptible) {
2823 jlong prevtime = javaTimeNanos();
2824
2825 // Prevent precision loss and too long sleeps
2826 jlong deadline = prevtime + millis * NANOSECS_PER_MILLISEC;
2827
2828 for (;;) {
2829 if (os::is_interrupted(thread, true)) {
2830 return OS_INTRPT;
2831 }
2832
2833 jlong newtime = javaTimeNanos();
2834
2835 assert(newtime >= prevtime, "time moving backwards");
2836 // Doing prevtime and newtime in microseconds doesn't help precision,
2837 // and trying to round up to avoid lost milliseconds can result in a
2838 // too-short delay.
2839 millis -= (newtime - prevtime) / NANOSECS_PER_MILLISEC;
2840
2841 if (millis <= 0) {
2842 return OS_OK;
2843 }
2844
2845 // Stop sleeping if we passed the deadline
2846 if (newtime >= deadline) {
2847 return OS_OK;
2848 }
2849
2850 prevtime = newtime;
2851
2852 {
2853 assert(thread->is_Java_thread(), "sanity check");
2854 JavaThread *jt = (JavaThread *) thread;
2855 ThreadBlockInVM tbivm(jt);
2856 OSThreadWaitState osts(jt->osthread(), false /* not Object.wait() */);
2857
2858 jt->set_suspend_equivalent();
2859
2860 slp->park(millis);
2861
2862 // were we externally suspended while we were waiting?
2863 jt->check_and_wait_while_suspended();
2864 }
2865 }
2866 } else {
2867 OSThreadWaitState osts(thread->osthread(), false /* not Object.wait() */);
2868 jlong prevtime = javaTimeNanos();
2869
2870 // Prevent precision loss and too long sleeps
2871 jlong deadline = prevtime + millis * NANOSECS_PER_MILLISEC;
2872
2873 for (;;) {
2874 // It'd be nice to avoid the back-to-back javaTimeNanos() calls on
2875 // the 1st iteration ...
2876 jlong newtime = javaTimeNanos();
2877
2878 if (newtime - prevtime < 0) {
2879 // time moving backwards, should only happen if no monotonic clock
2880 // not a guarantee() because JVM should not abort on kernel/glibc bugs
2881 // - HS14 Commented out as not implemented.
2882 // - TODO Maybe we should implement it?
2883 //assert(!Aix::supports_monotonic_clock(), "time moving backwards");
2884 } else {
2885 millis -= (newtime - prevtime) / NANOSECS_PER_MILLISEC;
2886 }
2887
2888 if (millis <= 0) break;
2889
2890 if (newtime >= deadline) {
2891 break;
2892 }
2893
2894 prevtime = newtime;
2895 slp->park(millis);
2896 }
2897 return OS_OK;
2898 }
2899 }
2900
2901 void os::naked_short_sleep(jlong ms) { 2797 void os::naked_short_sleep(jlong ms) {
2902 struct timespec req; 2798 struct timespec req;
2903 2799
2904 assert(ms < 1000, "Un-interruptable sleep, short time use only"); 2800 assert(ms < 1000, "Un-interruptable sleep, short time use only");
2905 req.tv_sec = 0; 2801 req.tv_sec = 0;
3242 ShouldNotReachHere(); 3138 ShouldNotReachHere();
3243 } 3139 }
3244 } 3140 }
3245 3141
3246 guarantee(osthread->sr.is_running(), "Must be running!"); 3142 guarantee(osthread->sr.is_running(), "Must be running!");
3247 }
3248
3249 ////////////////////////////////////////////////////////////////////////////////
3250 // interrupt support
3251
3252 void os::interrupt(Thread* thread) {
3253 assert(Thread::current() == thread || Threads_lock->owned_by_self(),
3254 "possibility of dangling Thread pointer");
3255
3256 OSThread* osthread = thread->osthread();
3257
3258 if (!osthread->interrupted()) {
3259 osthread->set_interrupted(true);
3260 // More than one thread can get here with the same value of osthread,
3261 // resulting in multiple notifications. We do, however, want the store
3262 // to interrupted() to be visible to other threads before we execute unpark().
3263 OrderAccess::fence();
3264 ParkEvent * const slp = thread->_SleepEvent;
3265 if (slp != NULL) slp->unpark();
3266 }
3267
3268 // For JSR166. Unpark even if interrupt status already was set
3269 if (thread->is_Java_thread())
3270 ((JavaThread*)thread)->parker()->unpark();
3271
3272 ParkEvent * ev = thread->_ParkEvent;
3273 if (ev != NULL) ev->unpark();
3274
3275 }
3276
3277 bool os::is_interrupted(Thread* thread, bool clear_interrupted) {
3278 assert(Thread::current() == thread || Threads_lock->owned_by_self(),
3279 "possibility of dangling Thread pointer");
3280
3281 OSThread* osthread = thread->osthread();
3282
3283 bool interrupted = osthread->interrupted();
3284
3285 if (interrupted && clear_interrupted) {
3286 osthread->set_interrupted(false);
3287 // consider thread->_SleepEvent->reset() ... optional optimization
3288 }
3289
3290 return interrupted;
3291 } 3143 }
3292 3144
3293 /////////////////////////////////////////////////////////////////////////////////// 3145 ///////////////////////////////////////////////////////////////////////////////////
3294 // signal handling (except suspend/resume) 3146 // signal handling (except suspend/resume)
3295 3147