@@ -497,7 +497,10 @@ static OSThread* create_os_thread(Thread* thread, HANDLE thread_handle,
497
497
OSThread* osthread = new OSThread (NULL , NULL );
498
498
if (osthread == NULL ) return NULL ;
499
499
500
- // Initialize support for Java interrupts
500
+ // Initialize the JDK library's interrupt event.
501
+ // This should really be done when OSThread is constructed,
502
+ // but there is no way for a constructor to report failure to
503
+ // allocate the event.
501
504
HANDLE interrupt_event = CreateEvent (NULL , true , false , NULL );
502
505
if (interrupt_event == NULL ) {
503
506
delete osthread;
@@ -599,7 +602,10 @@ bool os::create_thread(Thread* thread, ThreadType thr_type,
599
602
return false ;
600
603
}
601
604
602
- // Initialize support for Java interrupts
605
+ // Initialize the JDK library's interrupt event.
606
+ // This should really be done when OSThread is constructed,
607
+ // but there is no way for a constructor to report failure to
608
+ // allocate the event.
603
609
HANDLE interrupt_event = CreateEvent (NULL , true , false , NULL );
604
610
if (interrupt_event == NULL ) {
605
611
delete osthread;
@@ -3480,87 +3486,7 @@ void os::pd_start_thread(Thread* thread) {
3480
3486
assert (ret != SYS_THREAD_ERROR, " StartThread failed" ); // should propagate back
3481
3487
}
3482
3488
3483
- class HighResolutionInterval : public CHeapObj <mtThread> {
3484
- // The default timer resolution seems to be 10 milliseconds.
3485
- // (Where is this written down?)
3486
- // If someone wants to sleep for only a fraction of the default,
3487
- // then we set the timer resolution down to 1 millisecond for
3488
- // the duration of their interval.
3489
- // We carefully set the resolution back, since otherwise we
3490
- // seem to incur an overhead (3%?) that we don't need.
3491
- // CONSIDER: if ms is small, say 3, then we should run with a high resolution time.
3492
- // Buf if ms is large, say 500, or 503, we should avoid the call to timeBeginPeriod().
3493
- // Alternatively, we could compute the relative error (503/500 = .6%) and only use
3494
- // timeBeginPeriod() if the relative error exceeded some threshold.
3495
- // timeBeginPeriod() has been linked to problems with clock drift on win32 systems and
3496
- // to decreased efficiency related to increased timer "tick" rates. We want to minimize
3497
- // (a) calls to timeBeginPeriod() and timeEndPeriod() and (b) time spent with high
3498
- // resolution timers running.
3499
- private:
3500
- jlong resolution;
3501
- public:
3502
- HighResolutionInterval (jlong ms) {
3503
- resolution = ms % 10L ;
3504
- if (resolution != 0 ) {
3505
- MMRESULT result = timeBeginPeriod (1L );
3506
- }
3507
- }
3508
- ~HighResolutionInterval () {
3509
- if (resolution != 0 ) {
3510
- MMRESULT result = timeEndPeriod (1L );
3511
- }
3512
- resolution = 0L ;
3513
- }
3514
- };
3515
-
3516
- int os::sleep (Thread* thread, jlong ms, bool interruptable) {
3517
- jlong limit = (jlong) MAXDWORD;
3518
-
3519
- while (ms > limit) {
3520
- int res;
3521
- if ((res = sleep (thread, limit, interruptable)) != OS_TIMEOUT) {
3522
- return res;
3523
- }
3524
- ms -= limit;
3525
- }
3526
-
3527
- assert (thread == Thread::current (), " thread consistency check" );
3528
- OSThread* osthread = thread->osthread ();
3529
- OSThreadWaitState osts (osthread, false /* not Object.wait() */ );
3530
- int result;
3531
- if (interruptable) {
3532
- assert (thread->is_Java_thread (), " must be java thread" );
3533
- JavaThread *jt = (JavaThread *) thread;
3534
- ThreadBlockInVM tbivm (jt);
3535
-
3536
- jt->set_suspend_equivalent ();
3537
- // cleared by handle_special_suspend_equivalent_condition() or
3538
- // java_suspend_self() via check_and_wait_while_suspended()
3539
-
3540
- HANDLE events[1 ];
3541
- events[0 ] = osthread->interrupt_event ();
3542
- HighResolutionInterval *phri=NULL ;
3543
- if (!ForceTimeHighResolution) {
3544
- phri = new HighResolutionInterval (ms);
3545
- }
3546
- if (WaitForMultipleObjects (1 , events, FALSE , (DWORD)ms) == WAIT_TIMEOUT) {
3547
- result = OS_TIMEOUT;
3548
- } else {
3549
- ResetEvent (osthread->interrupt_event ());
3550
- osthread->set_interrupted (false );
3551
- result = OS_INTRPT;
3552
- }
3553
- delete phri; // if it is NULL, harmless
3554
3489
3555
- // were we externally suspended while we were waiting?
3556
- jt->check_and_wait_while_suspended ();
3557
- } else {
3558
- assert (!thread->is_Java_thread (), " must not be java thread" );
3559
- Sleep ((long ) ms);
3560
- result = OS_TIMEOUT;
3561
- }
3562
- return result;
3563
- }
3564
3490
3565
3491
// Short sleep, direct OS call.
3566
3492
//
@@ -3687,6 +3613,9 @@ void os::interrupt(Thread* thread) {
3687
3613
3688
3614
ParkEvent * ev = thread->_ParkEvent ;
3689
3615
if (ev != NULL ) ev->unpark ();
3616
+
3617
+ ev = thread->_SleepEvent ;
3618
+ if (ev != NULL ) ev->unpark ();
3690
3619
}
3691
3620
3692
3621
@@ -5170,6 +5099,40 @@ bool os::ThreadCrashProtection::call(os::CrashProtectionCallback& cb) {
5170
5099
return success;
5171
5100
}
5172
5101
5102
+
5103
+ class HighResolutionInterval : public CHeapObj <mtThread> {
5104
+ // The default timer resolution seems to be 10 milliseconds.
5105
+ // (Where is this written down?)
5106
+ // If someone wants to sleep for only a fraction of the default,
5107
+ // then we set the timer resolution down to 1 millisecond for
5108
+ // the duration of their interval.
5109
+ // We carefully set the resolution back, since otherwise we
5110
+ // seem to incur an overhead (3%?) that we don't need.
5111
+ // CONSIDER: if ms is small, say 3, then we should run with a high resolution time.
5112
+ // Buf if ms is large, say 500, or 503, we should avoid the call to timeBeginPeriod().
5113
+ // Alternatively, we could compute the relative error (503/500 = .6%) and only use
5114
+ // timeBeginPeriod() if the relative error exceeded some threshold.
5115
+ // timeBeginPeriod() has been linked to problems with clock drift on win32 systems and
5116
+ // to decreased efficiency related to increased timer "tick" rates. We want to minimize
5117
+ // (a) calls to timeBeginPeriod() and timeEndPeriod() and (b) time spent with high
5118
+ // resolution timers running.
5119
+ private:
5120
+ jlong resolution;
5121
+ public:
5122
+ HighResolutionInterval (jlong ms) {
5123
+ resolution = ms % 10L ;
5124
+ if (resolution != 0 ) {
5125
+ MMRESULT result = timeBeginPeriod (1L );
5126
+ }
5127
+ }
5128
+ ~HighResolutionInterval () {
5129
+ if (resolution != 0 ) {
5130
+ MMRESULT result = timeEndPeriod (1L );
5131
+ }
5132
+ resolution = 0L ;
5133
+ }
5134
+ };
5135
+
5173
5136
// An Event wraps a win32 "CreateEvent" kernel handle.
5174
5137
//
5175
5138
// We have a number of choices regarding "CreateEvent" win32 handle leakage:
@@ -5205,7 +5168,7 @@ bool os::ThreadCrashProtection::call(os::CrashProtectionCallback& cb) {
5205
5168
// 1. Reconcile Doug's JSR166 j.u.c park-unpark with the objectmonitor implementation.
5206
5169
// 2. Consider wrapping the WaitForSingleObject(Ex) calls in SEH try/finally blocks
5207
5170
// to recover from (or at least detect) the dreaded Windows 841176 bug.
5208
- // 3. Collapse the interrupt_event, the JSR166 parker event, and the objectmonitor ParkEvent
5171
+ // 3. Collapse the JSR166 parker event, and the objectmonitor ParkEvent
5209
5172
// into a single win32 CreateEvent() handle.
5210
5173
//
5211
5174
// Assumption:
@@ -5278,11 +5241,16 @@ int os::PlatformEvent::park(jlong Millis) {
5278
5241
if (Millis > MAXTIMEOUT) {
5279
5242
prd = MAXTIMEOUT;
5280
5243
}
5244
+ HighResolutionInterval *phri = NULL ;
5245
+ if (!ForceTimeHighResolution) {
5246
+ phri = new HighResolutionInterval (prd);
5247
+ }
5281
5248
rv = ::WaitForSingleObject (_ParkHandle, prd);
5282
5249
assert (rv == WAIT_OBJECT_0 || rv == WAIT_TIMEOUT, " WaitForSingleObject failed" );
5283
5250
if (rv == WAIT_TIMEOUT) {
5284
5251
Millis -= prd;
5285
5252
}
5253
+ delete phri; // if it is NULL, harmless
5286
5254
}
5287
5255
v = _Event;
5288
5256
_Event = 0 ;
0 commit comments