src/hotspot/share/jfr/recorder/storage/jfrStorage.cpp
branchJEP-349-branch
changeset 57870 00860d9caf4d
parent 57360 5d043a159d5c
child 58154 060d9d139109
equal deleted inserted replaced
57862:84ef29ccac56 57870:00860d9caf4d
   323   return mspace_get_free_with_detach(0, age_mspace, thread);
   323   return mspace_get_free_with_detach(0, age_mspace, thread);
   324 }
   324 }
   325 
   325 
   326 static bool insert_full_age_node(JfrAgeNode* age_node, JfrStorageAgeMspace* age_mspace, Thread* thread) {
   326 static bool insert_full_age_node(JfrAgeNode* age_node, JfrStorageAgeMspace* age_mspace, Thread* thread) {
   327   assert(JfrBuffer_lock->owned_by_self(), "invariant");
   327   assert(JfrBuffer_lock->owned_by_self(), "invariant");
       
   328   assert(age_node != NULL, "invariant");
       
   329   assert(age_node->acquired_by_self(), "invariant");
   328   assert(age_node->retired_buffer()->retired(), "invariant");
   330   assert(age_node->retired_buffer()->retired(), "invariant");
       
   331   age_node->release(); // drop identity claim on age node when inserting to full list
       
   332   assert(age_node->identity() == NULL, "invariant");
   329   age_mspace->insert_full_head(age_node);
   333   age_mspace->insert_full_head(age_node);
   330   return true;
   334   return true;
   331 }
   335 }
   332 
   336 
   333 static bool full_buffer_registration(BufferPtr buffer, JfrStorageAgeMspace* age_mspace, JfrStorageControl& control, Thread* thread) {
   337 static bool full_buffer_registration(BufferPtr buffer, JfrStorageAgeMspace* age_mspace, JfrStorageControl& control, Thread* thread) {
   340     age_node = new_age_node(buffer, age_mspace, thread);
   344     age_node = new_age_node(buffer, age_mspace, thread);
   341     if (age_node == NULL) {
   345     if (age_node == NULL) {
   342       return false;
   346       return false;
   343     }
   347     }
   344   }
   348   }
       
   349   assert(age_node != NULL, "invariant");
   345   assert(age_node->acquired_by_self(), "invariant");
   350   assert(age_node->acquired_by_self(), "invariant");
   346   assert(age_node != NULL, "invariant");
       
   347   age_node->set_retired_buffer(buffer);
   351   age_node->set_retired_buffer(buffer);
   348   control.increment_full();
   352   control.increment_full();
   349   return insert_full_age_node(age_node, age_mspace, thread);
   353   return insert_full_age_node(age_node, age_mspace, thread);
   350 }
   354 }
   351 
   355 
   423     while (true) {
   427     while (true) {
   424       JfrAgeNode* const oldest_age_node = _age_mspace->full_tail();
   428       JfrAgeNode* const oldest_age_node = _age_mspace->full_tail();
   425       if (oldest_age_node == NULL) {
   429       if (oldest_age_node == NULL) {
   426         break;
   430         break;
   427       }
   431       }
       
   432       assert(oldest_age_node->identity() == NULL, "invariant");
   428       BufferPtr const buffer = oldest_age_node->retired_buffer();
   433       BufferPtr const buffer = oldest_age_node->retired_buffer();
   429       assert(buffer->retired(), "invariant");
   434       assert(buffer->retired(), "invariant");
   430       discarded_size += buffer->unflushed_size();
   435       discarded_size += buffer->unflushed_size();
   431       num_full_post_discard = control().decrement_full();
   436       num_full_post_discard = control().decrement_full();
   432       if (buffer->transient()) {
   437       if (buffer->transient()) {
   434         mspace_release_full(oldest_age_node, _age_mspace);
   439         mspace_release_full(oldest_age_node, _age_mspace);
   435         continue;
   440         continue;
   436       } else {
   441       } else {
   437         mspace_release_full(oldest_age_node, _age_mspace);
   442         mspace_release_full(oldest_age_node, _age_mspace);
   438         buffer->reinitialize();
   443         buffer->reinitialize();
   439         buffer->release(); // pusb
   444         buffer->release(); // publish
   440         break;
   445         break;
   441       }
   446       }
   442     }
   447     }
   443     JfrBuffer_lock->unlock();
   448     JfrBuffer_lock->unlock();
   444     const size_t number_of_discards = num_full_pre_discard - num_full_post_discard;
   449     const size_t number_of_discards = num_full_pre_discard - num_full_post_discard;
   652   assert(count > 0, "invariant");
   657   assert(count > 0, "invariant");
   653   JfrAgeNode* node = head;
   658   JfrAgeNode* node = head;
   654   JfrAgeNode* last = NULL;
   659   JfrAgeNode* last = NULL;
   655   while (node != NULL) {
   660   while (node != NULL) {
   656     last = node;
   661     last = node;
       
   662     assert(node->identity() == NULL, "invariant");
   657     BufferPtr const buffer = node->retired_buffer();
   663     BufferPtr const buffer = node->retired_buffer();
   658     assert(buffer != NULL, "invariant");
   664     assert(buffer != NULL, "invariant");
   659     assert(buffer->retired(), "invariant");
   665     assert(buffer->retired(), "invariant");
   660     processor.process(buffer);
   666     processor.process(buffer);
   661     // at this point, buffer is already live or destroyed
   667     // at this point, buffer is already live or destroyed
   662     node->clear_identity();
       
   663     JfrAgeNode* const next = (JfrAgeNode*)node->next();
   668     JfrAgeNode* const next = (JfrAgeNode*)node->next();
   664     if (node->transient()) {
   669     if (node->transient()) {
   665       // detach
   670       // detach
   666       last = (JfrAgeNode*)last->prev();
   671       last = (JfrAgeNode*)last->prev();
   667       if (last != NULL) {
   672       if (last != NULL) {
   702   return count;
   707   return count;
   703 }
   708 }
   704 
   709 
   705 static void log(size_t count, size_t amount, bool clear = false) {
   710 static void log(size_t count, size_t amount, bool clear = false) {
   706   if (log_is_enabled(Debug, jfr, system)) {
   711   if (log_is_enabled(Debug, jfr, system)) {
   707     assert(count > 0, "invariant");
   712     if (count > 0) {
   708       log_debug(jfr, system)("%s " SIZE_FORMAT " full buffer(s) of " SIZE_FORMAT" B of data%s",
   713       log_debug(jfr, system)("%s " SIZE_FORMAT " full buffer(s) of " SIZE_FORMAT" B of data%s",
   709         clear ? "Discarded" : "Wrote", count, amount, clear ? "." : " to chunk.");
   714         clear ? "Discarded" : "Wrote", count, amount, clear ? "." : " to chunk.");
       
   715     }
   710   }
   716   }
   711 }
   717 }
   712 
   718 
   713 // full writer
   719 // full writer
   714 // Assumption is retired only; exclusive access
   720 // Assumption is retired only; exclusive access