hotspot/src/share/vm/runtime/synchronizer.cpp
changeset 20282 7f9cbdf89af2
parent 18025 b7bcf7497f93
child 22838 82c7497fbad4
child 22190 d306a75a70d3
equal deleted inserted replaced
20281:e4d33bd980c4 20282:7f9cbdf89af2
   152 ObjectMonitor * volatile ObjectSynchronizer::gOmInUseList  = NULL ;
   152 ObjectMonitor * volatile ObjectSynchronizer::gOmInUseList  = NULL ;
   153 int ObjectSynchronizer::gOmInUseCount = 0;
   153 int ObjectSynchronizer::gOmInUseCount = 0;
   154 static volatile intptr_t ListLock = 0 ;      // protects global monitor free-list cache
   154 static volatile intptr_t ListLock = 0 ;      // protects global monitor free-list cache
   155 static volatile int MonitorFreeCount  = 0 ;      // # on gFreeList
   155 static volatile int MonitorFreeCount  = 0 ;      // # on gFreeList
   156 static volatile int MonitorPopulation = 0 ;      // # Extant -- in circulation
   156 static volatile int MonitorPopulation = 0 ;      // # Extant -- in circulation
   157 #define CHAINMARKER ((oop)-1)
   157 #define CHAINMARKER (cast_to_oop<intptr_t>(-1))
   158 
   158 
   159 // -----------------------------------------------------------------------------
   159 // -----------------------------------------------------------------------------
   160 //  Fast Monitor Enter/Exit
   160 //  Fast Monitor Enter/Exit
   161 // This the fast monitor enter. The interpreter and compiler use
   161 // This the fast monitor enter. The interpreter and compiler use
   162 // some assembly copies of this code. Make sure update those code
   162 // some assembly copies of this code. Make sure update those code
   508          // and calling park().  When inflation was complete the thread that accomplished inflation
   508          // and calling park().  When inflation was complete the thread that accomplished inflation
   509          // would detach the list and set the markword to inflated with a single CAS and
   509          // would detach the list and set the markword to inflated with a single CAS and
   510          // then for each thread on the list, set the flag and unpark() the thread.
   510          // then for each thread on the list, set the flag and unpark() the thread.
   511          // This is conceptually similar to muxAcquire-muxRelease, except that muxRelease
   511          // This is conceptually similar to muxAcquire-muxRelease, except that muxRelease
   512          // wakes at most one thread whereas we need to wake the entire list.
   512          // wakes at most one thread whereas we need to wake the entire list.
   513          int ix = (intptr_t(obj) >> 5) & (NINFLATIONLOCKS-1) ;
   513          int ix = (cast_from_oop<intptr_t>(obj) >> 5) & (NINFLATIONLOCKS-1) ;
   514          int YieldThenBlock = 0 ;
   514          int YieldThenBlock = 0 ;
   515          assert (ix >= 0 && ix < NINFLATIONLOCKS, "invariant") ;
   515          assert (ix >= 0 && ix < NINFLATIONLOCKS, "invariant") ;
   516          assert ((NINFLATIONLOCKS & (NINFLATIONLOCKS-1)) == 0, "invariant") ;
   516          assert ((NINFLATIONLOCKS & (NINFLATIONLOCKS-1)) == 0, "invariant") ;
   517          Thread::muxAcquire (InflationLocks + ix, "InflationLock") ;
   517          Thread::muxAcquire (InflationLocks + ix, "InflationLock") ;
   518          while (obj->mark() == markOopDesc::INFLATING()) {
   518          while (obj->mark() == markOopDesc::INFLATING()) {
   563   } else
   563   } else
   564   if (hashCode == 1) {
   564   if (hashCode == 1) {
   565      // This variation has the property of being stable (idempotent)
   565      // This variation has the property of being stable (idempotent)
   566      // between STW operations.  This can be useful in some of the 1-0
   566      // between STW operations.  This can be useful in some of the 1-0
   567      // synchronization schemes.
   567      // synchronization schemes.
   568      intptr_t addrBits = intptr_t(obj) >> 3 ;
   568      intptr_t addrBits = cast_from_oop<intptr_t>(obj) >> 3 ;
   569      value = addrBits ^ (addrBits >> 5) ^ GVars.stwRandom ;
   569      value = addrBits ^ (addrBits >> 5) ^ GVars.stwRandom ;
   570   } else
   570   } else
   571   if (hashCode == 2) {
   571   if (hashCode == 2) {
   572      value = 1 ;            // for sensitivity testing
   572      value = 1 ;            // for sensitivity testing
   573   } else
   573   } else
   574   if (hashCode == 3) {
   574   if (hashCode == 3) {
   575      value = ++GVars.hcSequence ;
   575      value = ++GVars.hcSequence ;
   576   } else
   576   } else
   577   if (hashCode == 4) {
   577   if (hashCode == 4) {
   578      value = intptr_t(obj) ;
   578      value = cast_from_oop<intptr_t>(obj) ;
   579   } else {
   579   } else {
   580      // Marsaglia's xor-shift scheme with thread-specific state
   580      // Marsaglia's xor-shift scheme with thread-specific state
   581      // This is probably the best overall implementation -- we'll
   581      // This is probably the best overall implementation -- we'll
   582      // likely make this the default in future releases.
   582      // likely make this the default in future releases.
   583      unsigned t = Self->_hashStateX ;
   583      unsigned t = Self->_hashStateX ;
  1319           TEVENT(Inflate: overwrite stacklock) ;
  1319           TEVENT(Inflate: overwrite stacklock) ;
  1320           if (TraceMonitorInflation) {
  1320           if (TraceMonitorInflation) {
  1321             if (object->is_instance()) {
  1321             if (object->is_instance()) {
  1322               ResourceMark rm;
  1322               ResourceMark rm;
  1323               tty->print_cr("Inflating object " INTPTR_FORMAT " , mark " INTPTR_FORMAT " , type %s",
  1323               tty->print_cr("Inflating object " INTPTR_FORMAT " , mark " INTPTR_FORMAT " , type %s",
  1324                 (intptr_t) object, (intptr_t) object->mark(),
  1324                 (void *) object, (intptr_t) object->mark(),
  1325                 object->klass()->external_name());
  1325                 object->klass()->external_name());
  1326             }
  1326             }
  1327           }
  1327           }
  1328           return m ;
  1328           return m ;
  1329       }
  1329       }
  1369       TEVENT(Inflate: overwrite neutral) ;
  1369       TEVENT(Inflate: overwrite neutral) ;
  1370       if (TraceMonitorInflation) {
  1370       if (TraceMonitorInflation) {
  1371         if (object->is_instance()) {
  1371         if (object->is_instance()) {
  1372           ResourceMark rm;
  1372           ResourceMark rm;
  1373           tty->print_cr("Inflating object " INTPTR_FORMAT " , mark " INTPTR_FORMAT " , type %s",
  1373           tty->print_cr("Inflating object " INTPTR_FORMAT " , mark " INTPTR_FORMAT " , type %s",
  1374             (intptr_t) object, (intptr_t) object->mark(),
  1374             (void *) object, (intptr_t) object->mark(),
  1375             object->klass()->external_name());
  1375             object->klass()->external_name());
  1376         }
  1376         }
  1377       }
  1377       }
  1378       return m ;
  1378       return m ;
  1379   }
  1379   }
  1437      TEVENT (deflate_idle_monitors - scavenge1) ;
  1437      TEVENT (deflate_idle_monitors - scavenge1) ;
  1438      if (TraceMonitorInflation) {
  1438      if (TraceMonitorInflation) {
  1439        if (obj->is_instance()) {
  1439        if (obj->is_instance()) {
  1440          ResourceMark rm;
  1440          ResourceMark rm;
  1441            tty->print_cr("Deflating object " INTPTR_FORMAT " , mark " INTPTR_FORMAT " , type %s",
  1441            tty->print_cr("Deflating object " INTPTR_FORMAT " , mark " INTPTR_FORMAT " , type %s",
  1442                 (intptr_t) obj, (intptr_t) obj->mark(), obj->klass()->external_name());
  1442                 (void *) obj, (intptr_t) obj->mark(), obj->klass()->external_name());
  1443        }
  1443        }
  1444      }
  1444      }
  1445 
  1445 
  1446      // Restore the header back to obj
  1446      // Restore the header back to obj
  1447      obj->release_set_mark(mid->header());
  1447      obj->release_set_mark(mid->header());