42 #include "jfr/writers/jfrJavaEventWriter.hpp" 43 #include "memory/metaspaceGCThresholdUpdater.hpp" 44 #include "memory/referenceType.hpp" 45 #include "memory/universe.hpp" 46 #include "runtime/flags/jvmFlag.hpp" 47 #include "runtime/mutexLocker.hpp" 48 #include "runtime/osThread.hpp" 49 #include "runtime/safepoint.hpp" 50 #include "runtime/synchronizer.hpp" 51 #include "runtime/thread.inline.hpp" 52 #include "runtime/vm_operations.hpp" 53 54 #ifdef COMPILER2 55 #include "opto/compile.hpp" 56 #include "opto/node.hpp" 57 #endif 58 #if INCLUDE_G1GC 59 #include "gc/g1/g1HeapRegionTraceType.hpp" 60 #include "gc/g1/g1YCTypes.hpp" 61 #endif 62 63 // implementation for the static registration function exposed in the api 64 bool JfrSerializer::register_serializer(JfrTypeId id, bool require_safepoint, bool permit_cache, JfrSerializer* cs) { 65 assert(cs != NULL, "invariant"); 66 return JfrCheckpointManager::register_serializer(id, require_safepoint, permit_cache, cs); 67 } 68 69 class JfrCheckpointThreadCountClosure : public ThreadClosure { 70 private: 71 u4 _total_threads; 72 public: 73 JfrCheckpointThreadCountClosure() : _total_threads(0) {} 74 u4 total_threads() { return _total_threads; } 75 void do_thread(Thread *t) { _total_threads++; } 76 }; 77 78 // Requires a ResourceMark for get_thread_name/as_utf8 79 class JfrCheckpointThreadClosure : public ThreadClosure { 80 private: 81 JfrCheckpointWriter& _writer; 328 329 void JfrThreadConstant::serialize(JfrCheckpointWriter& writer) { 330 assert(_thread != NULL, "invariant"); 331 assert(_thread == Thread::current(), "invariant"); 332 assert(_thread->is_Java_thread(), "invariant"); 333 assert(!_thread->jfr_thread_local()->has_thread_checkpoint(), "invariant"); 334 ResourceMark rm(_thread); 335 const oop threadObj = _thread->threadObj(); 336 assert(threadObj != NULL, "invariant"); 337 const u8 java_lang_thread_id = java_lang_Thread::thread_id(threadObj); 338 const char* const thread_name = _thread->name(); 339 const traceid thread_group_id = JfrThreadGroup::thread_group_id(_thread); 340 writer.write_count(1); 341 writer.write_key(_thread->jfr_thread_local()->thread_id()); 342 writer.write(thread_name); 343 writer.write((u8)_thread->osthread()->thread_id()); 344 writer.write(thread_name); 345 writer.write(java_lang_thread_id); 346 writer.write(thread_group_id); 347 JfrThreadGroup::serialize(&writer, thread_group_id); 348 } | 42 #include "jfr/writers/jfrJavaEventWriter.hpp" 43 #include "memory/metaspaceGCThresholdUpdater.hpp" 44 #include "memory/referenceType.hpp" 45 #include "memory/universe.hpp" 46 #include "runtime/flags/jvmFlag.hpp" 47 #include "runtime/mutexLocker.hpp" 48 #include "runtime/osThread.hpp" 49 #include "runtime/safepoint.hpp" 50 #include "runtime/synchronizer.hpp" 51 #include "runtime/thread.inline.hpp" 52 #include "runtime/vm_operations.hpp" 53 54 #ifdef COMPILER2 55 #include "opto/compile.hpp" 56 #include "opto/node.hpp" 57 #endif 58 #if INCLUDE_G1GC 59 #include "gc/g1/g1HeapRegionTraceType.hpp" 60 #include "gc/g1/g1YCTypes.hpp" 61 #endif 62 #if INCLUDE_ZGC 63 #include "gc/z/zStat.hpp" 64 #endif 65 66 // implementation for the static registration function exposed in the api 67 bool JfrSerializer::register_serializer(JfrTypeId id, bool require_safepoint, bool permit_cache, JfrSerializer* cs) { 68 assert(cs != NULL, "invariant"); 69 return JfrCheckpointManager::register_serializer(id, require_safepoint, permit_cache, cs); 70 } 71 72 class JfrCheckpointThreadCountClosure : public ThreadClosure { 73 private: 74 u4 _total_threads; 75 public: 76 JfrCheckpointThreadCountClosure() : _total_threads(0) {} 77 u4 total_threads() { return _total_threads; } 78 void do_thread(Thread *t) { _total_threads++; } 79 }; 80 81 // Requires a ResourceMark for get_thread_name/as_utf8 82 class JfrCheckpointThreadClosure : public ThreadClosure { 83 private: 84 JfrCheckpointWriter& _writer; 331 332 void JfrThreadConstant::serialize(JfrCheckpointWriter& writer) { 333 assert(_thread != NULL, "invariant"); 334 assert(_thread == Thread::current(), "invariant"); 335 assert(_thread->is_Java_thread(), "invariant"); 336 assert(!_thread->jfr_thread_local()->has_thread_checkpoint(), "invariant"); 337 ResourceMark rm(_thread); 338 const oop threadObj = _thread->threadObj(); 339 assert(threadObj != NULL, "invariant"); 340 const u8 java_lang_thread_id = java_lang_Thread::thread_id(threadObj); 341 const char* const thread_name = _thread->name(); 342 const traceid thread_group_id = JfrThreadGroup::thread_group_id(_thread); 343 writer.write_count(1); 344 writer.write_key(_thread->jfr_thread_local()->thread_id()); 345 writer.write(thread_name); 346 writer.write((u8)_thread->osthread()->thread_id()); 347 writer.write(thread_name); 348 writer.write(java_lang_thread_id); 349 writer.write(thread_group_id); 350 JfrThreadGroup::serialize(&writer, thread_group_id); 351 } 352 353 void ZStatisticsCounterTypeConstant::serialize(JfrCheckpointWriter& writer) { 354 #if INCLUDE_ZGC 355 writer.write_count(ZStatCounter::count()); 356 for (ZStatCounter* counter = ZStatCounter::first(); counter != NULL; counter = counter->next()) { 357 writer.write_key(counter->id()); 358 writer.write(counter->name()); 359 } 360 #else 361 writer.write_count(0); 362 #endif 363 } 364 365 void ZStatisticsSamplerTypeConstant::serialize(JfrCheckpointWriter& writer) { 366 #if INCLUDE_ZGC 367 writer.write_count(ZStatSampler::count()); 368 for (ZStatSampler* sampler = ZStatSampler::first(); sampler != NULL; sampler = sampler->next()) { 369 writer.write_key(sampler->id()); 370 writer.write(sampler->name()); 371 } 372 #else 373 writer.write_count(0); 374 #endif 375 } |