--- old/src/hotspot/share/prims/jvmtiEnv.cpp 2019-10-03 23:47:52.435207218 -0400 +++ new/src/hotspot/share/prims/jvmtiEnv.cpp 2019-10-03 23:47:51.328195868 -0400 @@ -3229,23 +3229,23 @@ jvmtiError JvmtiEnv::DestroyRawMonitor(JvmtiRawMonitor * rmonitor) { if (Threads::number_of_threads() == 0) { - // Remove this monitor from pending raw monitors list + // Remove this monitor from pending raw monitors list // if it has entered in onload or start phase. JvmtiPendingMonitors::destroy(rmonitor); } else { Thread* thread = Thread::current(); - if (rmonitor->is_entered(thread)) { + if (rmonitor->owner() == thread) { // The caller owns this monitor which we are about to destroy. // We exit the underlying synchronization object so that the // "delete monitor" call below can work without an assertion // failure on systems that don't like destroying synchronization // objects that are locked. int r; - intptr_t recursion = rmonitor->recursions(); - for (intptr_t i = 0; i <= recursion; i++) { + int recursion = rmonitor->recursions(); + for (int i = 0; i <= recursion; i++) { r = rmonitor->raw_exit(thread); - assert(r == ObjectMonitor::OM_OK, "raw_exit should have worked"); - if (r != ObjectMonitor::OM_OK) { // robustness + assert(r == JvmtiRawMonitor::M_OK, "raw_exit should have worked"); + if (r != JvmtiRawMonitor::M_OK) { // robustness return JVMTI_ERROR_INTERNAL; } } @@ -3271,7 +3271,7 @@ jvmtiError JvmtiEnv::RawMonitorEnter(JvmtiRawMonitor * rmonitor) { if (Threads::number_of_threads() == 0) { - // No JavaThreads exist so ObjectMonitor enter cannot be + // No JavaThreads exist so JvmtiRawMonitor enter cannot be // used, add this raw monitor to the pending list. // The pending monitors will be actually entered when // the VM is setup. @@ -3279,20 +3279,10 @@ // in thread.cpp. JvmtiPendingMonitors::enter(rmonitor); } else { - int r = 0; Thread* thread = Thread::current(); - if (thread->is_Java_thread()) { JavaThread* current_thread = (JavaThread*)thread; -#ifdef PROPER_TRANSITIONS - // Not really unknown but ThreadInVMfromNative does more than we want - ThreadInVMfromUnknown __tiv; - { - ThreadBlockInVM __tbivm(current_thread); - r = rmonitor->raw_enter(current_thread); - } -#else /* Transition to thread_blocked without entering vm state */ /* This is really evil. Normally you can't undo _thread_blocked */ /* transitions like this because it would cause us to miss a */ @@ -3308,22 +3298,11 @@ current_thread->frame_anchor()->walkable(), "Must be walkable"); current_thread->set_thread_state(_thread_blocked); - r = rmonitor->raw_enter(current_thread); + rmonitor->raw_enter(current_thread); // restore state, still at a safepoint safe state current_thread->set_thread_state(state); - -#endif /* PROPER_TRANSITIONS */ - assert(r == ObjectMonitor::OM_OK, "raw_enter should have worked"); } else { - if (thread->is_Named_thread()) { - r = rmonitor->raw_enter(thread); - } else { - ShouldNotReachHere(); - } - } - - if (r != ObjectMonitor::OM_OK) { // robustness - return JVMTI_ERROR_INTERNAL; + rmonitor->raw_enter(thread); } } return JVMTI_ERROR_NONE; @@ -3342,31 +3321,10 @@ err = JVMTI_ERROR_NOT_MONITOR_OWNER; } } else { - int r = 0; Thread* thread = Thread::current(); - - if (thread->is_Java_thread()) { - JavaThread* current_thread = (JavaThread*)thread; -#ifdef PROPER_TRANSITIONS - // Not really unknown but ThreadInVMfromNative does more than we want - ThreadInVMfromUnknown __tiv; -#endif /* PROPER_TRANSITIONS */ - r = rmonitor->raw_exit(current_thread); - } else { - if (thread->is_Named_thread()) { - r = rmonitor->raw_exit(thread); - } else { - ShouldNotReachHere(); - } - } - - if (r == ObjectMonitor::OM_ILLEGAL_MONITOR_STATE) { + int r = rmonitor->raw_exit(thread); + if (r == JvmtiRawMonitor::M_ILLEGAL_MONITOR_STATE) { err = JVMTI_ERROR_NOT_MONITOR_OWNER; - } else { - assert(r == ObjectMonitor::OM_OK, "raw_exit should have worked"); - if (r != ObjectMonitor::OM_OK) { // robustness - err = JVMTI_ERROR_INTERNAL; - } } } return err; @@ -3381,14 +3339,7 @@ if (thread->is_Java_thread()) { JavaThread* current_thread = (JavaThread*)thread; -#ifdef PROPER_TRANSITIONS - // Not really unknown but ThreadInVMfromNative does more than we want - ThreadInVMfromUnknown __tiv; - { - ThreadBlockInVM __tbivm(current_thread); - r = rmonitor->raw_wait(millis, true, current_thread); - } -#else + /* Transition to thread_blocked without entering vm state */ /* This is really evil. Normally you can't undo _thread_blocked */ /* transitions like this because it would cause us to miss a */ @@ -3408,57 +3359,31 @@ // restore state, still at a safepoint safe state current_thread->set_thread_state(state); -#endif /* PROPER_TRANSITIONS */ } else { - if (thread->is_Named_thread()) { r = rmonitor->raw_wait(millis, false, thread); - } else { - ShouldNotReachHere(); - } + assert(r != JvmtiRawMonitor::M_INTERRUPTED, "non-JavaThread can't be interrupted"); } switch (r) { - case ObjectMonitor::OM_INTERRUPTED: + case JvmtiRawMonitor::M_INTERRUPTED: return JVMTI_ERROR_INTERRUPT; - case ObjectMonitor::OM_ILLEGAL_MONITOR_STATE: + case JvmtiRawMonitor::M_ILLEGAL_MONITOR_STATE: return JVMTI_ERROR_NOT_MONITOR_OWNER; + default: + return JVMTI_ERROR_NONE; } - assert(r == ObjectMonitor::OM_OK, "raw_wait should have worked"); - if (r != ObjectMonitor::OM_OK) { // robustness - return JVMTI_ERROR_INTERNAL; - } - - return JVMTI_ERROR_NONE; } /* end RawMonitorWait */ // rmonitor - pre-checked for validity jvmtiError JvmtiEnv::RawMonitorNotify(JvmtiRawMonitor * rmonitor) { - int r = 0; Thread* thread = Thread::current(); + int r = rmonitor->raw_notify(thread); - if (thread->is_Java_thread()) { - JavaThread* current_thread = (JavaThread*)thread; - // Not really unknown but ThreadInVMfromNative does more than we want - ThreadInVMfromUnknown __tiv; - r = rmonitor->raw_notify(current_thread); - } else { - if (thread->is_Named_thread()) { - r = rmonitor->raw_notify(thread); - } else { - ShouldNotReachHere(); - } - } - - if (r == ObjectMonitor::OM_ILLEGAL_MONITOR_STATE) { + if (r == JvmtiRawMonitor::M_ILLEGAL_MONITOR_STATE) { return JVMTI_ERROR_NOT_MONITOR_OWNER; } - assert(r == ObjectMonitor::OM_OK, "raw_notify should have worked"); - if (r != ObjectMonitor::OM_OK) { // robustness - return JVMTI_ERROR_INTERNAL; - } - return JVMTI_ERROR_NONE; } /* end RawMonitorNotify */ @@ -3466,29 +3391,12 @@ // rmonitor - pre-checked for validity jvmtiError JvmtiEnv::RawMonitorNotifyAll(JvmtiRawMonitor * rmonitor) { - int r = 0; Thread* thread = Thread::current(); + int r = rmonitor->raw_notifyAll(thread); - if (thread->is_Java_thread()) { - JavaThread* current_thread = (JavaThread*)thread; - ThreadInVMfromUnknown __tiv; - r = rmonitor->raw_notifyAll(current_thread); - } else { - if (thread->is_Named_thread()) { - r = rmonitor->raw_notifyAll(thread); - } else { - ShouldNotReachHere(); - } - } - - if (r == ObjectMonitor::OM_ILLEGAL_MONITOR_STATE) { + if (r == JvmtiRawMonitor::M_ILLEGAL_MONITOR_STATE) { return JVMTI_ERROR_NOT_MONITOR_OWNER; } - assert(r == ObjectMonitor::OM_OK, "raw_notifyAll should have worked"); - if (r != ObjectMonitor::OM_OK) { // robustness - return JVMTI_ERROR_INTERNAL; - } - return JVMTI_ERROR_NONE; } /* end RawMonitorNotifyAll */