< prev index next >

src/hotspot/share/gc/z/zForwarding.inline.hpp

Print this page




  59 
  60 inline bool ZForwarding::inc_refcount() {
  61   uint32_t refcount = Atomic::load(&_refcount);
  62 
  63   while (refcount > 0) {
  64     const uint32_t old_refcount = refcount;
  65     const uint32_t new_refcount = old_refcount + 1;
  66     const uint32_t prev_refcount = Atomic::cmpxchg(new_refcount, &_refcount, old_refcount);
  67     if (prev_refcount == old_refcount) {
  68       return true;
  69     }
  70 
  71     refcount = prev_refcount;
  72   }
  73 
  74   return false;
  75 }
  76 
  77 inline bool ZForwarding::dec_refcount() {
  78   assert(_refcount > 0, "Invalid state");
  79   return Atomic::sub(1u, &_refcount) == 0u;
  80 }
  81 
  82 inline bool ZForwarding::retain_page() {
  83   return inc_refcount();
  84 }
  85 
  86 inline void ZForwarding::release_page() {
  87   if (dec_refcount()) {
  88     ZHeap::heap()->free_page(_page, true /* reclaimed */);
  89     _page = NULL;
  90   }
  91 }
  92 
  93 inline ZForwardingEntry* ZForwarding::entries() const {
  94   return _entries(this);
  95 }
  96 
  97 inline ZForwardingEntry ZForwarding::at(ZForwardingCursor* cursor) const {
  98   return Atomic::load(entries() + *cursor);
  99 }




  59 
  60 inline bool ZForwarding::inc_refcount() {
  61   uint32_t refcount = Atomic::load(&_refcount);
  62 
  63   while (refcount > 0) {
  64     const uint32_t old_refcount = refcount;
  65     const uint32_t new_refcount = old_refcount + 1;
  66     const uint32_t prev_refcount = Atomic::cmpxchg(new_refcount, &_refcount, old_refcount);
  67     if (prev_refcount == old_refcount) {
  68       return true;
  69     }
  70 
  71     refcount = prev_refcount;
  72   }
  73 
  74   return false;
  75 }
  76 
  77 inline bool ZForwarding::dec_refcount() {
  78   assert(_refcount > 0, "Invalid state");
  79   return Atomic::sub(&_refcount, 1u) == 0u;
  80 }
  81 
  82 inline bool ZForwarding::retain_page() {
  83   return inc_refcount();
  84 }
  85 
  86 inline void ZForwarding::release_page() {
  87   if (dec_refcount()) {
  88     ZHeap::heap()->free_page(_page, true /* reclaimed */);
  89     _page = NULL;
  90   }
  91 }
  92 
  93 inline ZForwardingEntry* ZForwarding::entries() const {
  94   return _entries(this);
  95 }
  96 
  97 inline ZForwardingEntry ZForwarding::at(ZForwardingCursor* cursor) const {
  98   return Atomic::load(entries() + *cursor);
  99 }


< prev index next >