src/share/vm/runtime/synchronizer.cpp

Print this page




1626 
1627   // TODO: Add objectMonitor leak detection.
1628   // Audit/inventory the objectMonitors -- make sure they're all accounted for.
1629   GVars.stwRandom = os::random();
1630   GVars.stwCycle++;
1631 }
1632 
1633 // Monitor cleanup on JavaThread::exit
1634 
1635 // Iterate through monitor cache and attempt to release thread's monitors
1636 // Gives up on a particular monitor if an exception occurs, but continues
1637 // the overall iteration, swallowing the exception.
1638 class ReleaseJavaMonitorsClosure: public MonitorClosure {
1639  private:
1640   TRAPS;
1641 
1642  public:
1643   ReleaseJavaMonitorsClosure(Thread* thread) : THREAD(thread) {}
1644   void do_monitor(ObjectMonitor* mid) {
1645     if (mid->owner() == THREAD) {




1646       (void)mid->complete_exit(CHECK);
1647     }
1648   }
1649 };
1650 
1651 // Release all inflated monitors owned by THREAD.  Lightweight monitors are
1652 // ignored.  This is meant to be called during JNI thread detach which assumes
1653 // all remaining monitors are heavyweight.  All exceptions are swallowed.
1654 // Scanning the extant monitor list can be time consuming.
1655 // A simple optimization is to add a per-thread flag that indicates a thread
1656 // called jni_monitorenter() during its lifetime.
1657 //
1658 // Instead of No_Savepoint_Verifier it might be cheaper to
1659 // use an idiom of the form:
1660 //   auto int tmp = SafepointSynchronize::_safepoint_counter ;
1661 //   <code that must not run at safepoint>
1662 //   guarantee (((tmp ^ _safepoint_counter) | (tmp & 1)) == 0) ;
1663 // Since the tests are extremely cheap we could leave them enabled
1664 // for normal product builds.
1665 




1626 
1627   // TODO: Add objectMonitor leak detection.
1628   // Audit/inventory the objectMonitors -- make sure they're all accounted for.
1629   GVars.stwRandom = os::random();
1630   GVars.stwCycle++;
1631 }
1632 
1633 // Monitor cleanup on JavaThread::exit
1634 
1635 // Iterate through monitor cache and attempt to release thread's monitors
1636 // Gives up on a particular monitor if an exception occurs, but continues
1637 // the overall iteration, swallowing the exception.
1638 class ReleaseJavaMonitorsClosure: public MonitorClosure {
1639  private:
1640   TRAPS;
1641 
1642  public:
1643   ReleaseJavaMonitorsClosure(Thread* thread) : THREAD(thread) {}
1644   void do_monitor(ObjectMonitor* mid) {
1645     if (mid->owner() == THREAD) {
1646       guarantee(!GuaranteeOnMonitorMismatch,
1647                 err_msg("exiting JavaThread=" INTPTR_FORMAT
1648                         " unexpectedly owns ObjectMonitor=" INTPTR_FORMAT,
1649                         THREAD, mid));
1650       (void)mid->complete_exit(CHECK);
1651     }
1652   }
1653 };
1654 
1655 // Release all inflated monitors owned by THREAD.  Lightweight monitors are
1656 // ignored.  This is meant to be called during JNI thread detach which assumes
1657 // all remaining monitors are heavyweight.  All exceptions are swallowed.
1658 // Scanning the extant monitor list can be time consuming.
1659 // A simple optimization is to add a per-thread flag that indicates a thread
1660 // called jni_monitorenter() during its lifetime.
1661 //
1662 // Instead of No_Savepoint_Verifier it might be cheaper to
1663 // use an idiom of the form:
1664 //   auto int tmp = SafepointSynchronize::_safepoint_counter ;
1665 //   <code that must not run at safepoint>
1666 //   guarantee (((tmp ^ _safepoint_counter) | (tmp & 1)) == 0) ;
1667 // Since the tests are extremely cheap we could leave them enabled
1668 // for normal product builds.
1669