3331 |
3331 |
3332 |
3332 |
3333 // rmonitor - pre-checked for validity |
3333 // rmonitor - pre-checked for validity |
3334 jvmtiError |
3334 jvmtiError |
3335 JvmtiEnv::RawMonitorWait(JvmtiRawMonitor * rmonitor, jlong millis) { |
3335 JvmtiEnv::RawMonitorWait(JvmtiRawMonitor * rmonitor, jlong millis) { |
3336 int r = 0; |
|
3337 Thread* thread = Thread::current(); |
3336 Thread* thread = Thread::current(); |
3338 |
3337 int r = rmonitor->raw_wait(millis, thread); |
3339 if (thread->is_Java_thread()) { |
|
3340 JavaThread* current_thread = (JavaThread*)thread; |
|
3341 |
|
3342 /* Transition to thread_blocked without entering vm state */ |
|
3343 /* This is really evil. Normally you can't undo _thread_blocked */ |
|
3344 /* transitions like this because it would cause us to miss a */ |
|
3345 /* safepoint but since the thread was already in _thread_in_native */ |
|
3346 /* the thread is not leaving a safepoint safe state and it will */ |
|
3347 /* block when it tries to return from native. We can't safepoint */ |
|
3348 /* block in here because we could deadlock the vmthread. Blech. */ |
|
3349 |
|
3350 JavaThreadState state = current_thread->thread_state(); |
|
3351 assert(state == _thread_in_native, "Must be _thread_in_native"); |
|
3352 // frame should already be walkable since we are in native |
|
3353 assert(!current_thread->has_last_Java_frame() || |
|
3354 current_thread->frame_anchor()->walkable(), "Must be walkable"); |
|
3355 current_thread->set_thread_state(_thread_blocked); |
|
3356 |
|
3357 r = rmonitor->raw_wait(millis, true, current_thread); |
|
3358 // restore state, still at a safepoint safe state |
|
3359 current_thread->set_thread_state(state); |
|
3360 |
|
3361 } else { |
|
3362 r = rmonitor->raw_wait(millis, false, thread); |
|
3363 assert(r != JvmtiRawMonitor::M_INTERRUPTED, "non-JavaThread can't be interrupted"); |
|
3364 } |
|
3365 |
3338 |
3366 switch (r) { |
3339 switch (r) { |
3367 case JvmtiRawMonitor::M_INTERRUPTED: |
3340 case JvmtiRawMonitor::M_INTERRUPTED: |
3368 return JVMTI_ERROR_INTERRUPT; |
3341 return JVMTI_ERROR_INTERRUPT; |
3369 case JvmtiRawMonitor::M_ILLEGAL_MONITOR_STATE: |
3342 case JvmtiRawMonitor::M_ILLEGAL_MONITOR_STATE: |