@@ -315,6 +315,12 @@ struct ClassLoaderStatisticsEntry {
315315 U_64 hiddenBlockSize;
316316};
317317
318+ struct ThreadAllocationStatisticsEntry {
319+ I_64 ticks;
320+ U_64 threadIndex;
321+ U_64 allocated;
322+ };
323+
318324struct ThreadContextSwitchRateEntry {
319325 I_64 ticks;
320326 float switchRate;
@@ -555,6 +561,8 @@ class VM_JFRConstantPoolTypes {
555561 UDATA _dataLossCount;
556562 J9Pool *_threadDumpTable;
557563 UDATA _threadDumpCount;
564+ J9Pool *_threadAllocationStatisticsTable;
565+ UDATA _threadAllocationStatisticsCount;
558566
559567 /* Periodic events. */
560568 bool _shouldWriteJVMInformation;
@@ -727,8 +735,6 @@ class VM_JFRConstantPoolTypes {
727735
728736 U_32 addStringUTF8Entry (J9UTF8 *string, bool free);
729737
730- U_32 addThreadEntry (J9VMThread *vmThread);
731-
732738 U_32 addNetworkInterfaceNameEntry (const char *networkInterfaceName);
733739
734740 U_32 addThreadGroupEntry (j9object_t threadGroup);
@@ -879,6 +885,8 @@ class VM_JFRConstantPoolTypes {
879885
880886 void addThreadDumpEntry (J9JFRThreadDump *threadDumpData);
881887
888+ void addThreadAllocationStatistics (J9JFRThreadAllocationStatistics *threadAlocationData);
889+
882890 void addThreadObjectEntry (J9JFRThreadObject *tableEntry);
883891
884892 J9Pool *getExecutionSampleTable ()
@@ -936,6 +944,11 @@ class VM_JFRConstantPoolTypes {
936944 return _classLoaderStatisticsTable;
937945 }
938946
947+ J9Pool *getThreadAllocationStatisticsTable ()
948+ {
949+ return _threadAllocationStatisticsTable;
950+ }
951+
939952 J9Pool *getThreadContextSwitchRateTable ()
940953 {
941954 return _threadContextSwitchRateTable;
@@ -1101,6 +1114,11 @@ class VM_JFRConstantPoolTypes {
11011114 return _classLoaderStatisticsCount;
11021115 }
11031116
1117+ UDATA getThreadAllocationStatisticsCount ()
1118+ {
1119+ return _threadAllocationStatisticsCount;
1120+ }
1121+
11041122 UDATA getThreadContextSwitchRateCount ()
11051123 {
11061124 return _threadContextSwitchRateCount;
@@ -1453,6 +1471,9 @@ class VM_JFRConstantPoolTypes {
14531471 case J9JFR_EVENT_TYPE_DATA_LOSS :
14541472 addDataLossEntry ((J9JFRDataLoss *)event);
14551473 break ;
1474+ case J9JFR_EVENT_TYPE_THREAD_ALLOCATION_STATISTICS :
1475+ addThreadAllocationStatistics ((J9JFRThreadAllocationStatistics *)event);
1476+ break ;
14561477 default :
14571478 Assert_VM_unreachable ();
14581479 break ;
@@ -1464,15 +1485,14 @@ class VM_JFRConstantPoolTypes {
14641485 goto done;
14651486 }
14661487
1467- addAllThreads ();
1468-
14691488 if (J9_ARE_NO_BITS_SET (_vm->extendedRuntimeFlags3 , J9_EXTENDED_RUNTIME3_JFR_V2_SUPPORT )) {
14701489 if (dumpCalled) {
14711490 loadSystemProcesses (_currentThread);
14721491 loadNativeLibraries (_currentThread);
14731492 loadModuleRequireAndModuleExportEvents ();
14741493 loadClassLoaderStatisticsEvents (_currentThread);
14751494 loadThreadDumpEvents (_currentThread);
1495+ loadThreadAllocationStatisticsEvents ();
14761496 }
14771497 } else {
14781498 if (_shouldWriteSystemProcess) {
@@ -1489,6 +1509,8 @@ class VM_JFRConstantPoolTypes {
14891509 }
14901510 }
14911511
1512+ addAllThreads ();
1513+
14921514 shallowEntries = pool_new (sizeof (ClassEntry **), 0 , sizeof (U_64 ), 0 , J9_GET_CALLSITE (), OMRMEM_CATEGORY_VM , POOL_FOR_PORT (privatePortLibrary));
14931515 if (NULL == shallowEntries) {
14941516 _buildResult = OutOfMemory;
@@ -2092,6 +2114,44 @@ class VM_JFRConstantPoolTypes {
20922114 return ;
20932115 }
20942116
2117+ /* *
2118+ * @brief Generate and add ThreadAllocationStatistics events to _threadAllocationStatisticsTable.
2119+ */
2120+ void loadThreadAllocationStatisticsEvents ()
2121+ {
2122+ int64_t time = j9time_nano_time ();
2123+ J9InternalVMFunctions *vmFuncs = _vm->internalVMFunctions ;
2124+ J9MemoryManagerFunctions *mmfns = _vm->memoryManagerFunctions ;
2125+
2126+ Assert_VM_mustHaveVMAccess (_currentThread);
2127+ vmFuncs->acquireExclusiveVMAccess (_currentThread);
2128+
2129+ J9VMThread *walkThread = J9_LINKED_LIST_START_DO (_vm->mainThread );
2130+
2131+ while (NULL != walkThread) {
2132+ ThreadAllocationStatisticsEntry *entry = (ThreadAllocationStatisticsEntry *)pool_newElement (_threadAllocationStatisticsTable);
2133+ if (NULL == entry) {
2134+ _buildResult = OutOfMemory;
2135+ break ;
2136+ }
2137+ memset (entry, 0 , sizeof (*entry));
2138+
2139+ entry->ticks = time;
2140+ entry->threadIndex = getThreadTID (_currentThread, walkThread);
2141+ if (isResultNotOKay ()) {
2142+ goto done;
2143+ }
2144+ UDATA allocated = 0 ;
2145+ mmfns->j9gc_get_cumulative_bytes_allocated_by_thread (walkThread, &allocated);
2146+ entry->allocated = (U_64 )allocated;
2147+
2148+ _threadAllocationStatisticsCount += 1 ;
2149+ walkThread = J9_LINKED_LIST_NEXT_DO (_vm->mainThread , walkThread);
2150+ }
2151+ done:
2152+ vmFuncs->releaseExclusiveVMAccess (_currentThread);
2153+ }
2154+
20952155 VM_JFRConstantPoolTypes (J9VMThread *currentThread)
20962156 : _currentThread(currentThread)
20972157 , _vm(currentThread->javaVM)
@@ -2170,6 +2230,8 @@ class VM_JFRConstantPoolTypes {
21702230 , _dataLossCount(0 )
21712231 , _threadDumpTable(NULL )
21722232 , _threadDumpCount(0 )
2233+ , _threadAllocationStatisticsTable(NULL )
2234+ , _threadAllocationStatisticsCount(0 )
21732235 , _shouldWriteJVMInformation(false )
21742236 , _shouldWriteCPUInformationEvent(false )
21752237 , _shouldWriteVirtualizationInformationEvent(false )
@@ -2326,6 +2388,12 @@ class VM_JFRConstantPoolTypes {
23262388 goto done;
23272389 }
23282390
2391+ _threadAllocationStatisticsTable = pool_new (sizeof (ThreadAllocationStatisticsEntry), 0 , sizeof (U_64 ), 0 , J9_GET_CALLSITE (), OMRMEM_CATEGORY_VM , POOL_FOR_PORT (privatePortLibrary));
2392+ if (NULL == _threadAllocationStatisticsTable) {
2393+ _buildResult = OutOfMemory;
2394+ goto done;
2395+ }
2396+
23292397 _threadContextSwitchRateTable = pool_new (sizeof (ThreadContextSwitchRateEntry), 0 , sizeof (U_64 ), 0 , J9_GET_CALLSITE (), OMRMEM_CATEGORY_VM , POOL_FOR_PORT (privatePortLibrary));
23302398 if (NULL == _threadContextSwitchRateTable) {
23312399 _buildResult = OutOfMemory;
@@ -2516,6 +2584,7 @@ class VM_JFRConstantPoolTypes {
25162584 pool_kill (_networkUtilizationTable);
25172585 pool_kill (_dataLossTable);
25182586 pool_kill (_threadDumpTable);
2587+ pool_kill (_threadAllocationStatisticsTable);
25192588 freeNetworkInterfaceNames ();
25202589 j9mem_free_memory (_globalStringTable);
25212590 }
0 commit comments