src/hotspot/share/jfr/recorder/checkpoint/types/jfrThreadGroup.cpp
changeset 58863 c16ac7a2eba4
parent 53762 65deccd64f3a
equal deleted inserted replaced
58861:2c3cc4b01880 58863:c16ac7a2eba4
    23  */
    23  */
    24 
    24 
    25 #include "precompiled.hpp"
    25 #include "precompiled.hpp"
    26 #include "jfr/recorder/checkpoint/jfrCheckpointWriter.hpp"
    26 #include "jfr/recorder/checkpoint/jfrCheckpointWriter.hpp"
    27 #include "jfr/recorder/checkpoint/types/jfrThreadGroup.hpp"
    27 #include "jfr/recorder/checkpoint/types/jfrThreadGroup.hpp"
    28 #include "jfr/utilities/jfrResourceManager.hpp"
       
    29 #include "jfr/utilities/jfrTypes.hpp"
    28 #include "jfr/utilities/jfrTypes.hpp"
    30 #include "runtime/handles.inline.hpp"
    29 #include "runtime/handles.inline.hpp"
    31 #include "runtime/jniHandles.inline.hpp"
    30 #include "runtime/jniHandles.inline.hpp"
    32 #include "runtime/safepoint.hpp"
    31 #include "runtime/safepoint.hpp"
    33 #include "runtime/semaphore.hpp"
    32 #include "runtime/semaphore.hpp"
    34 #include "utilities/growableArray.hpp"
    33 #include "utilities/growableArray.hpp"
       
    34 
       
    35 static const int initial_array_size = 30;
    35 
    36 
    36 class ThreadGroupExclusiveAccess : public StackObj {
    37 class ThreadGroupExclusiveAccess : public StackObj {
    37  private:
    38  private:
    38   static Semaphore _mutex_semaphore;
    39   static Semaphore _mutex_semaphore;
    39  public:
    40  public:
   255   } else {
   256   } else {
   256     _thread_group_oop = NULL;
   257     _thread_group_oop = NULL;
   257   }
   258   }
   258 }
   259 }
   259 
   260 
   260 JfrThreadGroup::JfrThreadGroup() : _list(NULL) {
   261 JfrThreadGroup::JfrThreadGroup() :
   261   _list = new (ResourceObj::C_HEAP, mtTracing) GrowableArray<JfrThreadGroupEntry*>(30, true);
   262   _list(new (ResourceObj::C_HEAP, mtTracing) GrowableArray<JfrThreadGroupEntry*>(initial_array_size, true, mtTracing)) {}
   262 }
       
   263 
   263 
   264 JfrThreadGroup::~JfrThreadGroup() {
   264 JfrThreadGroup::~JfrThreadGroup() {
   265   assert(SafepointSynchronize::is_at_safepoint(), "invariant");
       
   266   if (_list != NULL) {
   265   if (_list != NULL) {
   267     for (int i = 0; i < _list->length(); i++) {
   266     for (int i = 0; i < _list->length(); i++) {
   268       JfrThreadGroupEntry* e = _list->at(i);
   267       JfrThreadGroupEntry* e = _list->at(i);
   269       delete e;
   268       delete e;
   270     }
   269     }
   279 void JfrThreadGroup::set_instance(JfrThreadGroup* new_instance) {
   278 void JfrThreadGroup::set_instance(JfrThreadGroup* new_instance) {
   280   _instance = new_instance;
   279   _instance = new_instance;
   281 }
   280 }
   282 
   281 
   283 traceid JfrThreadGroup::thread_group_id(const JavaThread* jt, Thread* current) {
   282 traceid JfrThreadGroup::thread_group_id(const JavaThread* jt, Thread* current) {
   284   ResourceMark rm(current);
       
   285   HandleMark hm(current);
       
   286   JfrThreadGroupsHelper helper(jt, current);
   283   JfrThreadGroupsHelper helper(jt, current);
   287   return helper.is_valid() ? thread_group_id_internal(helper) : 0;
   284   return helper.is_valid() ? thread_group_id_internal(helper) : 0;
   288 }
   285 }
   289 
   286 
   290 traceid JfrThreadGroup::thread_group_id(JavaThread* const jt) {
   287 traceid JfrThreadGroup::thread_group_id(JavaThread* const jt) {
   291   assert(!JfrStream_lock->owned_by_self(), "holding stream lock but should not hold it here");
       
   292   return thread_group_id(jt, jt);
   288   return thread_group_id(jt, jt);
   293 }
   289 }
   294 
   290 
   295 traceid JfrThreadGroup::thread_group_id_internal(JfrThreadGroupsHelper& helper) {
   291 traceid JfrThreadGroup::thread_group_id_internal(JfrThreadGroupsHelper& helper) {
   296   ThreadGroupExclusiveAccess lock;
   292   ThreadGroupExclusiveAccess lock;
   394 // Write out JfrThreadGroup instance and then delete it
   390 // Write out JfrThreadGroup instance and then delete it
   395 void JfrThreadGroup::serialize(JfrCheckpointWriter& writer) {
   391 void JfrThreadGroup::serialize(JfrCheckpointWriter& writer) {
   396   ThreadGroupExclusiveAccess lock;
   392   ThreadGroupExclusiveAccess lock;
   397   JfrThreadGroup* tg_instance = instance();
   393   JfrThreadGroup* tg_instance = instance();
   398   assert(tg_instance != NULL, "invariant");
   394   assert(tg_instance != NULL, "invariant");
   399   ResourceManager<JfrThreadGroup> tg_handle(tg_instance);
   395   tg_instance->write_thread_group_entries(writer);
   400   set_instance(NULL);
       
   401   tg_handle->write_thread_group_entries(writer);
       
   402 }
   396 }
   403 
   397 
   404 // for writing a particular thread group
   398 // for writing a particular thread group
   405 void JfrThreadGroup::serialize(JfrCheckpointWriter* writer, traceid thread_group_id) {
   399 void JfrThreadGroup::serialize(JfrCheckpointWriter* writer, traceid thread_group_id) {
   406   assert(writer != NULL, "invariant");
   400   assert(writer != NULL, "invariant");