src/hotspot/share/runtime/synchronizer.cpp
changeset 59325 3636bab5e81e
parent 59252 623722a6aeb9
equal deleted inserted replaced
59324:5e8f9713e343 59325:3636bab5e81e
   527   volatile int hc_sequence;
   527   volatile int hc_sequence;
   528   DEFINE_PAD_MINUS_SIZE(2, DEFAULT_CACHE_LINE_SIZE, sizeof(volatile int));
   528   DEFINE_PAD_MINUS_SIZE(2, DEFAULT_CACHE_LINE_SIZE, sizeof(volatile int));
   529 };
   529 };
   530 
   530 
   531 static SharedGlobals GVars;
   531 static SharedGlobals GVars;
   532 static int MonitorScavengeThreshold = 1000000;
   532 static int _forceMonitorScavenge = 0; // Scavenge required and pending
   533 static volatile int ForceMonitorScavenge = 0; // Scavenge required and pending
       
   534 
   533 
   535 static markWord read_stable_mark(oop obj) {
   534 static markWord read_stable_mark(oop obj) {
   536   markWord mark = obj->mark();
   535   markWord mark = obj->mark();
   537   if (!mark.is_being_inflated()) {
   536   if (!mark.is_being_inflated()) {
   538     return mark;       // normal fast-path return
   537     return mark;       // normal fast-path return
   913   return monitor_usage > MonitorUsedDeflationThreshold;
   912   return monitor_usage > MonitorUsedDeflationThreshold;
   914 }
   913 }
   915 
   914 
   916 bool ObjectSynchronizer::is_cleanup_needed() {
   915 bool ObjectSynchronizer::is_cleanup_needed() {
   917   if (MonitorUsedDeflationThreshold > 0) {
   916   if (MonitorUsedDeflationThreshold > 0) {
   918     return monitors_used_above_threshold();
   917     if (monitors_used_above_threshold()) {
       
   918       return true;
       
   919     }
       
   920   }
       
   921   return needs_monitor_scavenge();
       
   922 }
       
   923 
       
   924 bool ObjectSynchronizer::needs_monitor_scavenge() {
       
   925   if (Atomic::load(&_forceMonitorScavenge) == 1) {
       
   926     log_info(monitorinflation)("Monitor scavenge needed, triggering safepoint cleanup.");
       
   927     return true;
   919   }
   928   }
   920   return false;
   929   return false;
   921 }
   930 }
   922 
   931 
   923 void ObjectSynchronizer::oops_do(OopClosure* f) {
   932 void ObjectSynchronizer::oops_do(OopClosure* f) {
   981 // type of limit.  Beware that if MonitorBound is set to too low a value
   990 // type of limit.  Beware that if MonitorBound is set to too low a value
   982 // we could just loop. In addition, if MonitorBound is set to a low value
   991 // we could just loop. In addition, if MonitorBound is set to a low value
   983 // we'll incur more safepoints, which are harmful to performance.
   992 // we'll incur more safepoints, which are harmful to performance.
   984 // See also: GuaranteedSafepointInterval
   993 // See also: GuaranteedSafepointInterval
   985 //
   994 //
   986 // The current implementation uses asynchronous VM operations.
       
   987 //
       
   988 // If MonitorBound is set, the boundry applies to
   995 // If MonitorBound is set, the boundry applies to
   989 //     (g_om_population - g_om_free_count)
   996 //     (g_om_population - g_om_free_count)
   990 // i.e., if there are not enough ObjectMonitors on the global free list,
   997 // i.e., if there are not enough ObjectMonitors on the global free list,
   991 // then a safepoint deflation is induced. Picking a good MonitorBound value
   998 // then a safepoint deflation is induced. Picking a good MonitorBound value
   992 // is non-trivial.
   999 // is non-trivial.
   993 
  1000 
   994 static void InduceScavenge(Thread* self, const char * Whence) {
  1001 static void InduceScavenge(Thread* self, const char * Whence) {
   995   // Induce STW safepoint to trim monitors
  1002   // Induce STW safepoint to trim monitors
   996   // Ultimately, this results in a call to deflate_idle_monitors() in the near future.
  1003   // Ultimately, this results in a call to deflate_idle_monitors() in the near future.
   997   // More precisely, trigger an asynchronous STW safepoint as the number
  1004   // More precisely, trigger a cleanup safepoint as the number
   998   // of active monitors passes the specified threshold.
  1005   // of active monitors passes the specified threshold.
   999   // TODO: assert thread state is reasonable
  1006   // TODO: assert thread state is reasonable
  1000 
  1007 
  1001   if (ForceMonitorScavenge == 0 && Atomic::xchg(&ForceMonitorScavenge, 1) == 0) {
  1008   if (Atomic::xchg (&_forceMonitorScavenge, 1) == 0) {
  1002     // Induce a 'null' safepoint to scavenge monitors
  1009     VMThread::check_for_forced_cleanup();
  1003     // Must VM_Operation instance be heap allocated as the op will be enqueue and posted
       
  1004     // to the VMthread and have a lifespan longer than that of this activation record.
       
  1005     // The VMThread will delete the op when completed.
       
  1006     VMThread::execute(new VM_ScavengeMonitors());
       
  1007   }
  1010   }
  1008 }
  1011 }
  1009 
  1012 
  1010 ObjectMonitor* ObjectSynchronizer::om_alloc(Thread* self) {
  1013 ObjectMonitor* ObjectSynchronizer::om_alloc(Thread* self) {
  1011   // A large MAXPRIVATE value reduces both list lock contention
  1014   // A large MAXPRIVATE value reduces both list lock contention
  1679                                "g_om_free_count=%d", g_om_population,
  1682                                "g_om_free_count=%d", g_om_population,
  1680                                g_om_in_use_count, g_om_free_count);
  1683                                g_om_in_use_count, g_om_free_count);
  1681     Thread::muxRelease(&gListLock);
  1684     Thread::muxRelease(&gListLock);
  1682   }
  1685   }
  1683 
  1686 
  1684   ForceMonitorScavenge = 0;    // Reset
  1687   Atomic::store(&_forceMonitorScavenge, 0);    // Reset
  1685 
  1688 
  1686   OM_PERFDATA_OP(Deflations, inc(counters->n_scavenged));
  1689   OM_PERFDATA_OP(Deflations, inc(counters->n_scavenged));
  1687   OM_PERFDATA_OP(MonExtant, set_value(counters->n_in_circulation));
  1690   OM_PERFDATA_OP(MonExtant, set_value(counters->n_in_circulation));
  1688 
  1691 
  1689   GVars.stw_random = os::random();
  1692   GVars.stw_random = os::random();