src/hotspot/share/runtime/synchronizer.cpp
changeset 54291 e6c86f6012bf
parent 53588 a5f46c4690f8
child 54609 04857e2cd509
equal deleted inserted replaced
54290:8af48416e31f 54291:e6c86f6012bf
  1268     gOmInUseList = inUseList;
  1268     gOmInUseList = inUseList;
  1269     gOmInUseCount += inUseTally;
  1269     gOmInUseCount += inUseTally;
  1270   }
  1270   }
  1271 
  1271 
  1272   Thread::muxRelease(&gListLock);
  1272   Thread::muxRelease(&gListLock);
       
  1273 
       
  1274   LogStreamHandle(Debug, monitorinflation) lsh_debug;
       
  1275   LogStreamHandle(Info, monitorinflation) lsh_info;
       
  1276   LogStream * ls = NULL;
       
  1277   if (log_is_enabled(Debug, monitorinflation)) {
       
  1278     ls = &lsh_debug;
       
  1279   } else if ((tally != 0 || inUseTally != 0) &&
       
  1280              log_is_enabled(Info, monitorinflation)) {
       
  1281     ls = &lsh_info;
       
  1282   }
       
  1283   if (ls != NULL) {
       
  1284     ls->print_cr("omFlush: jt=" INTPTR_FORMAT ", free_monitor_tally=%d"
       
  1285                  ", in_use_monitor_tally=%d" ", omFreeProvision=%d",
       
  1286                  p2i(Self), tally, inUseTally, Self->omFreeProvision);
       
  1287   }
  1273 }
  1288 }
  1274 
  1289 
  1275 static void post_monitor_inflate_event(EventJavaMonitorInflate* event,
  1290 static void post_monitor_inflate_event(EventJavaMonitorInflate* event,
  1276                                        const oop obj,
  1291                                        const oop obj,
  1277                                        ObjectSynchronizer::InflateCause cause) {
  1292                                        ObjectSynchronizer::InflateCause cause) {
  1663   // monitors. Note: if the work is split among more than one
  1678   // monitors. Note: if the work is split among more than one
  1664   // worker thread, then the reported time will likely be more
  1679   // worker thread, then the reported time will likely be more
  1665   // than a beginning to end measurement of the phase.
  1680   // than a beginning to end measurement of the phase.
  1666   log_info(safepoint, cleanup)("deflating per-thread idle monitors, %3.7f secs, monitors=%d", counters->perThreadTimes, counters->perThreadScavenged);
  1681   log_info(safepoint, cleanup)("deflating per-thread idle monitors, %3.7f secs, monitors=%d", counters->perThreadTimes, counters->perThreadScavenged);
  1667 
  1682 
  1668   LogStreamHandle(Debug, monitorinflation) lsh_debug;
       
  1669   LogStreamHandle(Info, monitorinflation) lsh_info;
       
  1670   LogStream * ls = NULL;
       
  1671   if (log_is_enabled(Debug, monitorinflation)) {
       
  1672     ls = &lsh_debug;
       
  1673   } else if (counters->perThreadScavenged != 0 && log_is_enabled(Info, monitorinflation)) {
       
  1674     ls = &lsh_info;
       
  1675   }
       
  1676   if (ls != NULL) {
       
  1677     ls->print_cr("deflating per-thread idle monitors, %3.7f secs, %d monitors", counters->perThreadTimes, counters->perThreadScavenged);
       
  1678   }
       
  1679 
       
  1680   gMonitorFreeCount += counters->nScavenged;
  1683   gMonitorFreeCount += counters->nScavenged;
  1681 
  1684 
  1682   if (log_is_enabled(Debug, monitorinflation)) {
  1685   if (log_is_enabled(Debug, monitorinflation)) {
  1683     // exit_globals()'s call to audit_and_print_stats() is done
  1686     // exit_globals()'s call to audit_and_print_stats() is done
  1684     // at the Info level.
  1687     // at the Info level.
  1685     ObjectSynchronizer::audit_and_print_stats(false /* on_exit */);
  1688     ObjectSynchronizer::audit_and_print_stats(false /* on_exit */);
       
  1689   } else if (log_is_enabled(Info, monitorinflation)) {
       
  1690     Thread::muxAcquire(&gListLock, "finish_deflate_idle_monitors");
       
  1691     log_info(monitorinflation)("gMonitorPopulation=%d, gOmInUseCount=%d, "
       
  1692                                "gMonitorFreeCount=%d", gMonitorPopulation,
       
  1693                                gOmInUseCount, gMonitorFreeCount);
       
  1694     Thread::muxRelease(&gListLock);
  1686   }
  1695   }
  1687 
  1696 
  1688   ForceMonitorScavenge = 0;    // Reset
  1697   ForceMonitorScavenge = 0;    // Reset
  1689 
  1698 
  1690   OM_PERFDATA_OP(Deflations, inc(counters->nScavenged));
  1699   OM_PERFDATA_OP(Deflations, inc(counters->nScavenged));
  1705       log_is_enabled(Info, monitorinflation)) {
  1714       log_is_enabled(Info, monitorinflation)) {
  1706     timer.start();
  1715     timer.start();
  1707   }
  1716   }
  1708 
  1717 
  1709   int deflated_count = deflate_monitor_list(thread->omInUseList_addr(), &freeHeadp, &freeTailp);
  1718   int deflated_count = deflate_monitor_list(thread->omInUseList_addr(), &freeHeadp, &freeTailp);
  1710 
       
  1711   timer.stop();
       
  1712 
  1719 
  1713   Thread::muxAcquire(&gListLock, "deflate_thread_local_monitors");
  1720   Thread::muxAcquire(&gListLock, "deflate_thread_local_monitors");
  1714 
  1721 
  1715   // Adjust counters
  1722   // Adjust counters
  1716   counters->nInCirculation += thread->omInUseCount;
  1723   counters->nInCirculation += thread->omInUseCount;
  1717   thread->omInUseCount -= deflated_count;
  1724   thread->omInUseCount -= deflated_count;
  1718   counters->nScavenged += deflated_count;
  1725   counters->nScavenged += deflated_count;
  1719   counters->nInuse += thread->omInUseCount;
  1726   counters->nInuse += thread->omInUseCount;
  1720   counters->perThreadScavenged += deflated_count;
  1727   counters->perThreadScavenged += deflated_count;
  1721   // For now, we only care about cumulative per-thread deflation time.
       
  1722   counters->perThreadTimes += timer.seconds();
       
  1723 
  1728 
  1724   // Move the scavenged monitors back to the global free list.
  1729   // Move the scavenged monitors back to the global free list.
  1725   if (freeHeadp != NULL) {
  1730   if (freeHeadp != NULL) {
  1726     guarantee(freeTailp != NULL && deflated_count > 0, "invariant");
  1731     guarantee(freeTailp != NULL && deflated_count > 0, "invariant");
  1727     assert(freeTailp->FreeNext == NULL, "invariant");
  1732     assert(freeTailp->FreeNext == NULL, "invariant");
  1728 
  1733 
  1729     // constant-time list splice - prepend scavenged segment to gFreeList
  1734     // constant-time list splice - prepend scavenged segment to gFreeList
  1730     freeTailp->FreeNext = gFreeList;
  1735     freeTailp->FreeNext = gFreeList;
  1731     gFreeList = freeHeadp;
  1736     gFreeList = freeHeadp;
  1732   }
  1737   }
       
  1738 
       
  1739   timer.stop();
       
  1740   // Safepoint logging cares about cumulative perThreadTimes and
       
  1741   // we'll capture most of the cost, but not the muxRelease() which
       
  1742   // should be cheap.
       
  1743   counters->perThreadTimes += timer.seconds();
       
  1744 
  1733   Thread::muxRelease(&gListLock);
  1745   Thread::muxRelease(&gListLock);
       
  1746 
       
  1747   LogStreamHandle(Debug, monitorinflation) lsh_debug;
       
  1748   LogStreamHandle(Info, monitorinflation) lsh_info;
       
  1749   LogStream * ls = NULL;
       
  1750   if (log_is_enabled(Debug, monitorinflation)) {
       
  1751     ls = &lsh_debug;
       
  1752   } else if (deflated_count != 0 && log_is_enabled(Info, monitorinflation)) {
       
  1753     ls = &lsh_info;
       
  1754   }
       
  1755   if (ls != NULL) {
       
  1756     ls->print_cr("jt=" INTPTR_FORMAT ": deflating per-thread idle monitors, %3.7f secs, %d monitors", p2i(thread), timer.seconds(), deflated_count);
       
  1757   }
  1734 }
  1758 }
  1735 
  1759 
  1736 // Monitor cleanup on JavaThread::exit
  1760 // Monitor cleanup on JavaThread::exit
  1737 
  1761 
  1738 // Iterate through monitor cache and attempt to release thread's monitors
  1762 // Iterate through monitor cache and attempt to release thread's monitors
  1837 
  1861 
  1838   ls->print_cr("Checking global lists:");
  1862   ls->print_cr("Checking global lists:");
  1839 
  1863 
  1840   // Check gMonitorPopulation:
  1864   // Check gMonitorPopulation:
  1841   if (gMonitorPopulation == chkMonitorPopulation) {
  1865   if (gMonitorPopulation == chkMonitorPopulation) {
  1842      ls->print_cr("gMonitorPopulation=%d equals chkMonitorPopulation=%d",
  1866     ls->print_cr("gMonitorPopulation=%d equals chkMonitorPopulation=%d",
  1843                   gMonitorPopulation, chkMonitorPopulation);
  1867                  gMonitorPopulation, chkMonitorPopulation);
  1844   } else {
  1868   } else {
  1845      ls->print_cr("ERROR: gMonitorPopulation=%d is not equal to "
  1869     ls->print_cr("ERROR: gMonitorPopulation=%d is not equal to "
  1846                   "chkMonitorPopulation=%d", gMonitorPopulation,
  1870                  "chkMonitorPopulation=%d", gMonitorPopulation,
  1847                   chkMonitorPopulation);
  1871                  chkMonitorPopulation);
  1848      error_cnt++;
  1872     error_cnt++;
  1849   }
  1873   }
  1850 
  1874 
  1851   // Check gOmInUseList and gOmInUseCount:
  1875   // Check gOmInUseList and gOmInUseCount:
  1852   chk_global_in_use_list_and_count(ls, &error_cnt);
  1876   chk_global_in_use_list_and_count(ls, &error_cnt);
  1853 
  1877