< prev index next >

src/hotspot/share/jfr/recorder/storage/jfrBuffer.cpp

Print this page




  87 
  88 const u1* JfrBuffer::stable_top() const {
  89   const u1* current_top;
  90   do {
  91     current_top = Atomic::load(&_top);
  92   } while (MUTEX_CLAIM == current_top);
  93   return current_top;
  94 }
  95 
  96 const u1* JfrBuffer::top() const {
  97   return _top;
  98 }
  99 
 100 void JfrBuffer::set_top(const u1* new_top) {
 101   _top = new_top;
 102 }
 103 
 104 const u1* JfrBuffer::concurrent_top() const {
 105   do {
 106     const u1* current_top = stable_top();
 107     if (Atomic::cmpxchg(MUTEX_CLAIM, &_top, current_top) == current_top) {
 108       return current_top;
 109     }
 110   } while (true);
 111 }
 112 
 113 void JfrBuffer::set_concurrent_top(const u1* new_top) {
 114   assert(new_top != MUTEX_CLAIM, "invariant");
 115   assert(new_top <= end(), "invariant");
 116   assert(new_top >= start(), "invariant");
 117   assert(top() == MUTEX_CLAIM, "invariant");
 118   OrderAccess::storestore();
 119   _top = new_top;
 120 }
 121 
 122 size_t JfrBuffer::unflushed_size() const {
 123   return pos() - stable_top();
 124 }
 125 
 126 void JfrBuffer::acquire(const void* id) {
 127   assert(id != NULL, "invariant");
 128   const void* current_id;
 129   do {
 130     current_id = Atomic::load(&_identity);
 131   } while (current_id != NULL || Atomic::cmpxchg(id, &_identity, current_id) != current_id);
 132 }
 133 
 134 bool JfrBuffer::try_acquire(const void* id) {
 135   assert(id != NULL, "invariant");
 136   const void* const current_id = Atomic::load(&_identity);
 137   return current_id == NULL && Atomic::cmpxchg(id, &_identity, current_id) == current_id;
 138 }
 139 
 140 void JfrBuffer::release() {
 141   OrderAccess::storestore();
 142   _identity = NULL;
 143 }
 144 
 145 bool JfrBuffer::acquired_by(const void* id) const {
 146   return identity() == id;
 147 }
 148 
 149 bool JfrBuffer::acquired_by_self() const {
 150   return acquired_by(Thread::current());
 151 }
 152 
 153 #ifdef ASSERT
 154 static bool validate_to(const JfrBuffer* const to, size_t size) {
 155   assert(to != NULL, "invariant");
 156   assert(to->acquired_by_self(), "invariant");
 157   assert(to->free_size() >= size, "invariant");




  87 
  88 const u1* JfrBuffer::stable_top() const {
  89   const u1* current_top;
  90   do {
  91     current_top = Atomic::load(&_top);
  92   } while (MUTEX_CLAIM == current_top);
  93   return current_top;
  94 }
  95 
  96 const u1* JfrBuffer::top() const {
  97   return _top;
  98 }
  99 
 100 void JfrBuffer::set_top(const u1* new_top) {
 101   _top = new_top;
 102 }
 103 
 104 const u1* JfrBuffer::concurrent_top() const {
 105   do {
 106     const u1* current_top = stable_top();
 107     if (Atomic::cmpxchg(&_top, current_top, MUTEX_CLAIM) == current_top) {
 108       return current_top;
 109     }
 110   } while (true);
 111 }
 112 
 113 void JfrBuffer::set_concurrent_top(const u1* new_top) {
 114   assert(new_top != MUTEX_CLAIM, "invariant");
 115   assert(new_top <= end(), "invariant");
 116   assert(new_top >= start(), "invariant");
 117   assert(top() == MUTEX_CLAIM, "invariant");
 118   OrderAccess::storestore();
 119   _top = new_top;
 120 }
 121 
 122 size_t JfrBuffer::unflushed_size() const {
 123   return pos() - stable_top();
 124 }
 125 
 126 void JfrBuffer::acquire(const void* id) {
 127   assert(id != NULL, "invariant");
 128   const void* current_id;
 129   do {
 130     current_id = Atomic::load(&_identity);
 131   } while (current_id != NULL || Atomic::cmpxchg(&_identity, current_id, id) != current_id);
 132 }
 133 
 134 bool JfrBuffer::try_acquire(const void* id) {
 135   assert(id != NULL, "invariant");
 136   const void* const current_id = Atomic::load(&_identity);
 137   return current_id == NULL && Atomic::cmpxchg(&_identity, current_id, id) == current_id;
 138 }
 139 
 140 void JfrBuffer::release() {
 141   OrderAccess::storestore();
 142   _identity = NULL;
 143 }
 144 
 145 bool JfrBuffer::acquired_by(const void* id) const {
 146   return identity() == id;
 147 }
 148 
 149 bool JfrBuffer::acquired_by_self() const {
 150   return acquired_by(Thread::current());
 151 }
 152 
 153 #ifdef ASSERT
 154 static bool validate_to(const JfrBuffer* const to, size_t size) {
 155   assert(to != NULL, "invariant");
 156   assert(to->acquired_by_self(), "invariant");
 157   assert(to->free_size() >= size, "invariant");


< prev index next >