src/hotspot/share/jfr/recorder/storage/jfrBuffer.cpp
changeset 58863 c16ac7a2eba4
parent 55053 d58e1a447d2b
child 59252 623722a6aeb9
equal deleted inserted replaced
58861:2c3cc4b01880 58863:c16ac7a2eba4
    52   assert(!lease(), "invariant");
    52   assert(!lease(), "invariant");
    53   assert(!retired(), "invariant");
    53   assert(!retired(), "invariant");
    54   return true;
    54   return true;
    55 }
    55 }
    56 
    56 
    57 void JfrBuffer::reinitialize() {
    57 void JfrBuffer::reinitialize(bool exclusion /* false */) {
    58   assert(!lease(), "invariant");
    58   assert(!lease(), "invariant");
    59   assert(!transient(), "invariant");
    59   assert(!transient(), "invariant");
    60   set_pos(start());
    60   set_pos(start());
       
    61   if (exclusion != excluded()) {
       
    62     // update
       
    63     if (exclusion) {
       
    64       set_excluded();
       
    65     } else {
       
    66       clear_excluded();
       
    67     }
       
    68   }
    61   clear_retired();
    69   clear_retired();
    62   set_top(start());
    70   set_top(start());
    63 }
    71 }
    64 
    72 
    65 void JfrBuffer::concurrent_reinitialization() {
    73 void JfrBuffer::concurrent_reinitialization() {
    78 }
    86 }
    79 
    87 
    80 const u1* JfrBuffer::stable_top() const {
    88 const u1* JfrBuffer::stable_top() const {
    81   const u1* current_top;
    89   const u1* current_top;
    82   do {
    90   do {
    83     current_top = OrderAccess::load_acquire(&_top);
    91     current_top = Atomic::load(&_top);
    84   } while (MUTEX_CLAIM == current_top);
    92   } while (MUTEX_CLAIM == current_top);
    85   return current_top;
    93   return current_top;
    86 }
    94 }
    87 
    95 
    88 const u1* JfrBuffer::top() const {
    96 const u1* JfrBuffer::top() const {
   105 void JfrBuffer::set_concurrent_top(const u1* new_top) {
   113 void JfrBuffer::set_concurrent_top(const u1* new_top) {
   106   assert(new_top != MUTEX_CLAIM, "invariant");
   114   assert(new_top != MUTEX_CLAIM, "invariant");
   107   assert(new_top <= end(), "invariant");
   115   assert(new_top <= end(), "invariant");
   108   assert(new_top >= start(), "invariant");
   116   assert(new_top >= start(), "invariant");
   109   assert(top() == MUTEX_CLAIM, "invariant");
   117   assert(top() == MUTEX_CLAIM, "invariant");
   110   OrderAccess::release_store(&_top, new_top);
   118   OrderAccess::storestore();
       
   119   _top = new_top;
   111 }
   120 }
   112 
   121 
   113 size_t JfrBuffer::unflushed_size() const {
   122 size_t JfrBuffer::unflushed_size() const {
   114   return pos() - stable_top();
   123   return pos() - stable_top();
   115 }
   124 }
   116 
   125 
   117 void JfrBuffer::acquire(const void* id) {
   126 void JfrBuffer::acquire(const void* id) {
   118   assert(id != NULL, "invariant");
   127   assert(id != NULL, "invariant");
   119   const void* current_id;
   128   const void* current_id;
   120   do {
   129   do {
   121     current_id = OrderAccess::load_acquire(&_identity);
   130     current_id = Atomic::load(&_identity);
   122   } while (current_id != NULL || Atomic::cmpxchg(id, &_identity, current_id) != current_id);
   131   } while (current_id != NULL || Atomic::cmpxchg(id, &_identity, current_id) != current_id);
   123 }
   132 }
   124 
   133 
   125 bool JfrBuffer::try_acquire(const void* id) {
   134 bool JfrBuffer::try_acquire(const void* id) {
   126   assert(id != NULL, "invariant");
   135   assert(id != NULL, "invariant");
   127   const void* const current_id = OrderAccess::load_acquire(&_identity);
   136   const void* const current_id = Atomic::load(&_identity);
   128   return current_id == NULL && Atomic::cmpxchg(id, &_identity, current_id) == current_id;
   137   return current_id == NULL && Atomic::cmpxchg(id, &_identity, current_id) == current_id;
   129 }
   138 }
   130 
   139 
   131 void JfrBuffer::release() {
   140 void JfrBuffer::release() {
   132   OrderAccess::release_store(&_identity, (const void*)NULL);
   141   OrderAccess::storestore();
       
   142   _identity = NULL;
   133 }
   143 }
   134 
   144 
   135 bool JfrBuffer::acquired_by(const void* id) const {
   145 bool JfrBuffer::acquired_by(const void* id) const {
   136   return identity() == id;
   146   return identity() == id;
   137 }
   147 }
   184 }
   194 }
   185 
   195 
   186 enum FLAG {
   196 enum FLAG {
   187   RETIRED = 1,
   197   RETIRED = 1,
   188   TRANSIENT = 2,
   198   TRANSIENT = 2,
   189   LEASE = 4
   199   LEASE = 4,
       
   200   EXCLUDED = 8
   190 };
   201 };
   191 
   202 
   192 bool JfrBuffer::transient() const {
   203 bool JfrBuffer::transient() const {
   193   return (u1)TRANSIENT == (_flags & (u1)TRANSIENT);
   204   return (u1)TRANSIENT == (_flags & (u1)TRANSIENT);
   194 }
   205 }
   219     _flags ^= (u1)LEASE;
   230     _flags ^= (u1)LEASE;
   220   }
   231   }
   221   assert(!lease(), "invariant");
   232   assert(!lease(), "invariant");
   222 }
   233 }
   223 
   234 
   224 static u2 load_acquire_flags(const u2* const flags) {
   235 bool JfrBuffer::excluded() const {
   225   return OrderAccess::load_acquire(flags);
   236   return (u1)EXCLUDED == (_flags & (u1)EXCLUDED);
   226 }
   237 }
   227 
   238 
   228 static void release_store_flags(u2* const flags, u2 new_flags) {
   239 void JfrBuffer::set_excluded() {
   229   OrderAccess::release_store(flags, new_flags);
   240   _flags |= (u1)EXCLUDED;
       
   241   assert(excluded(), "invariant");
       
   242 }
       
   243 
       
   244 void JfrBuffer::clear_excluded() {
       
   245   if (excluded()) {
       
   246     OrderAccess::storestore();
       
   247     _flags ^= (u1)EXCLUDED;
       
   248   }
       
   249   assert(!excluded(), "invariant");
   230 }
   250 }
   231 
   251 
   232 bool JfrBuffer::retired() const {
   252 bool JfrBuffer::retired() const {
   233   return (u1)RETIRED == (load_acquire_flags(&_flags) & (u1)RETIRED);
   253   return (_flags & (u1)RETIRED) == (u1)RETIRED;
   234 }
   254 }
   235 
   255 
   236 void JfrBuffer::set_retired() {
   256 void JfrBuffer::set_retired() {
   237   const u2 new_flags = load_acquire_flags(&_flags) | (u1)RETIRED;
   257   OrderAccess::storestore();
   238   release_store_flags(&_flags, new_flags);
   258   _flags |= (u1)RETIRED;
   239 }
   259 }
   240 
   260 
   241 void JfrBuffer::clear_retired() {
   261 void JfrBuffer::clear_retired() {
   242   u2 new_flags = load_acquire_flags(&_flags);
   262   if (retired()) {
   243   if ((u1)RETIRED == (new_flags & (u1)RETIRED)) {
   263     OrderAccess::storestore();
   244     new_flags ^= (u1)RETIRED;
   264     _flags ^= (u1)RETIRED;
   245     release_store_flags(&_flags, new_flags);
   265   }
   246   }
   266 }
   247 }