Skip to content

Commit 7dd0009

Browse files
committed
JFR PhysicalMemory event fix-up
In V2, respond to emit event request immediately instead of deferring to chunk generation. This allows multiple such events to be generated in one chunk. Related: #24194 Signed-off-by: Gengchen Tuo <gengchen.tuo@ibm.com>
1 parent cb98417 commit 7dd0009

5 files changed

Lines changed: 111 additions & 18 deletions

File tree

runtime/oti/j9nonbuilder.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,12 @@ typedef struct J9JFRThreadDump {
585585
UDATA bufferSize;
586586
} J9JFRThreadDump;
587587

588+
typedef struct J9JFRPhysicalMemory {
589+
J9JFR_EVENT_COMMON_FIELDS
590+
U_64 totalSize;
591+
U_64 usedSize;
592+
} J9JFRPhysicalMemory;
593+
588594
#endif /* defined(J9VM_OPT_JFR) */
589595

590596
/* @ddr_namespace: map_to_type=J9CfrError */

runtime/vm/JFRChunkWriter.hpp

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ class VM_JFRChunkWriter {
217217
static constexpr int MONITOR_ENTER_EVENT_SIZE = sizeof(U_32) + (3 * LEB128_64_SIZE) + (5 * LEB128_32_SIZE);
218218
static constexpr int THREAD_PARK_EVENT_SIZE = (9 * sizeof(U_64)) + sizeof(U_32);
219219
static constexpr int JVM_INFORMATION_EVENT_SIZE = 3000;
220-
static constexpr int PHYSICAL_MEMORY_EVENT_SIZE = (4 * sizeof(U_64)) + sizeof(U_32);
220+
static constexpr int PHYSICAL_MEMORY_EVENT_SIZE = LEB128_32_SIZE + (4 * LEB128_64_SIZE);
221221
static constexpr int VIRTUALIZATION_INFORMATION_EVENT_SIZE = 50;
222222
static constexpr int CPU_INFORMATION_EVENT_SIZE = 600;
223223
static constexpr int OS_INFORMATION_EVENT_SIZE = 100;
@@ -475,6 +475,8 @@ class VM_JFRChunkWriter {
475475

476476
pool_do(_constantPoolTypes.getGarbageCollectionTable(), &writeGarbageCollectionEvent, _bufferWriter);
477477

478+
pool_do(_constantPoolTypes.getPhysicalMemoryTable(), &writePhysicalMemoryEvent, _bufferWriter);
479+
478480
pool_do(_constantPoolTypes.getGCHeapSummaryTable(), &writeGCHeapSummaryEvent, _bufferWriter);
479481

480482
pool_do(_constantPoolTypes.getNetworkUtilizationTable(), &writeNetworkUtilizationEvent, this);
@@ -541,9 +543,7 @@ class VM_JFRChunkWriter {
541543
writeYoungGenerationConfigurationEvent();
542544
}
543545

544-
if (_constantPoolTypes.shouldWritePhysicalMemory()) {
545-
writePhysicalMemoryEvent();
546-
}
546+
547547
}
548548

549549
writeJFRHeader();
@@ -871,6 +871,32 @@ class VM_JFRChunkWriter {
871871
writeEventSize(_bufferWriter, dataStart);
872872
}
873873

874+
static void
875+
writePhysicalMemoryEvent(void *anElement, void *userData)
876+
{
877+
PhysicalMemoryEntry *entry = (PhysicalMemoryEntry *)anElement;
878+
VM_BufferWriter *_bufferWriter = (VM_BufferWriter *)userData;
879+
880+
/* reserve size field */
881+
U_8 *dataStart = reserveEventSize(_bufferWriter);
882+
883+
/* write event type */
884+
_bufferWriter->writeLEB128(PhysicalMemoryID);
885+
886+
/* write start time */
887+
_bufferWriter->writeLEB128(entry->ticks);
888+
889+
/* write total size */
890+
_bufferWriter->writeLEB128(entry->totalSize);
891+
892+
/* write used size */
893+
_bufferWriter->writeLEB128(entry->usedSize);
894+
895+
/* write size */
896+
writeEventSize(_bufferWriter, dataStart);
897+
}
898+
899+
874900
void
875901
writeJFRChunkToFile()
876902
{
@@ -1041,7 +1067,7 @@ class VM_JFRChunkWriter {
10411067

10421068
requiredBufferSize += OS_INFORMATION_EVENT_SIZE;
10431069

1044-
requiredBufferSize += PHYSICAL_MEMORY_EVENT_SIZE;
1070+
requiredBufferSize += (_constantPoolTypes.getPhysicalMemoryCount() * PHYSICAL_MEMORY_EVENT_SIZE);
10451071

10461072
requiredBufferSize += VIRTUALIZATION_INFORMATION_EVENT_SIZE;
10471073

runtime/vm/JFRConstantPoolTypes.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1547,6 +1547,26 @@ VM_JFRConstantPoolTypes::addThreadDumpEntry(J9JFRThreadDump *threadDumpData)
15471547
return;
15481548
}
15491549

1550+
void
1551+
VM_JFRConstantPoolTypes::addPhysicalMemoryEntry(J9JFRPhysicalMemory *physicalMemoryData)
1552+
{
1553+
PhysicalMemoryEntry *entry = (PhysicalMemoryEntry *)pool_newElement(_physicalMemoryTable);
1554+
1555+
if (NULL == entry) {
1556+
_buildResult = OutOfMemory;
1557+
goto done;
1558+
}
1559+
1560+
entry->ticks = physicalMemoryData->startTicks;
1561+
entry->totalSize = physicalMemoryData->totalSize;
1562+
entry->usedSize = physicalMemoryData->usedSize;
1563+
1564+
_physicalMemoryCount += 1;
1565+
1566+
done:
1567+
return;
1568+
}
1569+
15501570
void
15511571
VM_JFRConstantPoolTypes::printTables()
15521572
{

runtime/vm/JFRConstantPoolTypes.hpp

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,12 @@ struct ThreadDumpEntry {
461461
UDATA resultLength;
462462
};
463463

464+
struct PhysicalMemoryEntry {
465+
I_64 ticks;
466+
U_64 totalSize;
467+
U_64 usedSize;
468+
};
469+
464470
struct JFRConstantEvents {
465471
JVMInformationEntry JVMInfoEntry;
466472
CPUInformationEntry CPUInfoEntry;
@@ -555,6 +561,8 @@ class VM_JFRConstantPoolTypes {
555561
UDATA _dataLossCount;
556562
J9Pool *_threadDumpTable;
557563
UDATA _threadDumpCount;
564+
J9Pool *_physicalMemoryTable;
565+
UDATA _physicalMemoryCount;
558566

559567
/* Periodic events. */
560568
bool _shouldWriteJVMInformation;
@@ -565,7 +573,6 @@ class VM_JFRConstantPoolTypes {
565573
bool _shouldWriteInitialEnvironmentVariableEvents;
566574
bool _shouldWritewriteGCHeapConfigurationEvent;
567575
bool _shouldWriteYoungGenerationConfigurationEvent;
568-
bool _shouldWritePhysicalMemory;
569576
bool _shouldWriteSystemProcess;
570577
bool _shouldWriteNativeLibrary;
571578
bool _shouldWriteModuleRequire;
@@ -875,6 +882,9 @@ class VM_JFRConstantPoolTypes {
875882
void addGCHeapSummaryEntry(J9JFRGCHeapSummary *gcHeapSummaryData);
876883

877884
void addNetworkUtilizationEntry(J9JFRNetworkUtilization *networkUtilizationData);
885+
886+
void addPhysicalMemoryEntry(J9JFRPhysicalMemory *physicalMemoryData);
887+
878888
void addDataLossEntry(J9JFRDataLoss *dataLossData);
879889

880890
void addThreadDumpEntry(J9JFRThreadDump *threadDumpData);
@@ -1256,6 +1266,16 @@ class VM_JFRConstantPoolTypes {
12561266
return _stackFrameCount;
12571267
}
12581268

1269+
UDATA getPhysicalMemoryCount()
1270+
{
1271+
return _physicalMemoryCount;
1272+
}
1273+
1274+
J9Pool *getPhysicalMemoryTable()
1275+
{
1276+
return _physicalMemoryTable;
1277+
}
1278+
12591279
bool shouldWriteJVMInformation()
12601280
{
12611281
return _shouldWriteJVMInformation;
@@ -1296,11 +1316,6 @@ class VM_JFRConstantPoolTypes {
12961316
return _shouldWriteYoungGenerationConfigurationEvent;
12971317
}
12981318

1299-
bool shouldWritePhysicalMemory()
1300-
{
1301-
return _shouldWritePhysicalMemory;
1302-
}
1303-
13041319
bool shouldWriteSystemProcess()
13051320
{
13061321
return _shouldWriteSystemProcess;
@@ -1430,7 +1445,7 @@ class VM_JFRConstantPoolTypes {
14301445
_shouldWriteYoungGenerationConfigurationEvent = true;
14311446
break;
14321447
case J9JFR_EVENT_TYPE_PHYSICAL_MEMORY:
1433-
_shouldWritePhysicalMemory = true;
1448+
addPhysicalMemoryEntry((J9JFRPhysicalMemory *)event);
14341449
break;
14351450
case J9JFR_EVENT_TYPE_SYSTEM_PROCESS:
14361451
_shouldWriteSystemProcess = true;
@@ -2170,6 +2185,8 @@ class VM_JFRConstantPoolTypes {
21702185
, _dataLossCount(0)
21712186
, _threadDumpTable(NULL)
21722187
, _threadDumpCount(0)
2188+
, _physicalMemoryTable(NULL)
2189+
, _physicalMemoryCount(0)
21732190
, _shouldWriteJVMInformation(false)
21742191
, _shouldWriteCPUInformationEvent(false)
21752192
, _shouldWriteVirtualizationInformationEvent(false)
@@ -2178,7 +2195,6 @@ class VM_JFRConstantPoolTypes {
21782195
, _shouldWriteInitialEnvironmentVariableEvents(false)
21792196
, _shouldWritewriteGCHeapConfigurationEvent(false)
21802197
, _shouldWriteYoungGenerationConfigurationEvent(false)
2181-
, _shouldWritePhysicalMemory(false)
21822198
, _shouldWriteSystemProcess(false)
21832199
, _shouldWriteNativeLibrary(false)
21842200
, _shouldWriteModuleRequire(false)
@@ -2338,6 +2354,13 @@ class VM_JFRConstantPoolTypes {
23382354
goto done;
23392355
}
23402356

2357+
_physicalMemoryTable = pool_new(sizeof(PhysicalMemoryEntry), 0, sizeof(U_64), 0, J9_GET_CALLSITE(), OMRMEM_CATEGORY_VM, POOL_FOR_PORT(privatePortLibrary));
2358+
if (NULL == _physicalMemoryTable) {
2359+
_buildResult = OutOfMemory;
2360+
goto done;
2361+
}
2362+
2363+
23412364
_systemProcessTable = pool_new(sizeof(SystemProcessEntry), 0, sizeof(U_64), 0, J9_GET_CALLSITE(), OMRMEM_CATEGORY_VM, POOL_FOR_PORT(privatePortLibrary));
23422365
if (NULL == _systemProcessTable) {
23432366
_buildResult = OutOfMemory;
@@ -2516,6 +2539,7 @@ class VM_JFRConstantPoolTypes {
25162539
pool_kill(_networkUtilizationTable);
25172540
pool_kill(_dataLossTable);
25182541
pool_kill(_threadDumpTable);
2542+
pool_kill(_physicalMemoryTable);
25192543
freeNetworkInterfaceNames();
25202544
j9mem_free_memory(_globalStringTable);
25212545
}

runtime/vm/jfr.cpp

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,14 +193,16 @@ jfrEventSize(J9JFREvent *jfrEvent)
193193
case J9JFR_EVENT_TYPE_INITIAL_ENVIRONMENT_VARIABLE:
194194
case J9JFR_EVENT_TYPE_GC_HEAP_CONFIGURATION:
195195
case J9JFR_EVENT_TYPE_YOUNG_GENERATION_CONFIGURATION:
196-
case J9JFR_EVENT_TYPE_PHYSICAL_MEMORY:
197196
case J9JFR_EVENT_TYPE_SYSTEM_PROCESS:
198197
case J9JFR_EVENT_TYPE_MODULE_REQUIRE:
199198
case J9JFR_EVENT_TYPE_MODULE_EXPORT:
200199
case J9JFR_EVENT_TYPE_CLASS_LOADER_STATISTICS:
201200
case J9JFR_EVENT_TYPE_NATIVE_LIBRARY:
202201
size = sizeof(J9JFREvent);
203202
break;
203+
case J9JFR_EVENT_TYPE_PHYSICAL_MEMORY:
204+
size = sizeof(J9JFRPhysicalMemory);
205+
break;
204206
default:
205207
Assert_VM_unreachable();
206208
break;
@@ -1583,6 +1585,24 @@ jfrThreadStatistics(J9VMThread *currentThread)
15831585

15841586
}
15851587

1588+
static void
1589+
jfrPhysicalMemory(J9VMThread *currentThread)
1590+
{
1591+
PORT_ACCESS_FROM_VMC(currentThread);
1592+
1593+
J9MemoryInfo memInfo = {0};
1594+
I_32 rc = j9sysinfo_get_memory_info(&memInfo);
1595+
1596+
if (0 == rc) {
1597+
J9JFRPhysicalMemory *jfrEvent = (J9JFRPhysicalMemory *)reserveBuffer(currentThread, currentThread, sizeof(J9JFRPhysicalMemory));
1598+
if (NULL != jfrEvent) {
1599+
initializeEventFields(currentThread, currentThread, (J9JFREvent *)jfrEvent, J9JFR_EVENT_TYPE_PHYSICAL_MEMORY);
1600+
jfrEvent->totalSize = memInfo.totalPhysical;
1601+
jfrEvent->usedSize = memInfo.totalPhysical - memInfo.availPhysical;
1602+
}
1603+
}
1604+
}
1605+
15861606
static int J9THREAD_PROC
15871607
jfrSamplingThreadProc(void *entryArg)
15881608
{
@@ -2307,10 +2327,7 @@ JfrPeriodicEventSet::requestClassLoaderStatistics(J9VMThread *currentThread)
23072327
void
23082328
JfrPeriodicEventSet::requestPhysicalMemory(J9VMThread *currentThread)
23092329
{
2310-
J9JFREvent *jfrEvent = (J9JFREvent *)reserveBuffer(currentThread, currentThread, sizeof(J9JFREvent));
2311-
if (NULL != jfrEvent) {
2312-
initializeEventFields(currentThread, currentThread, jfrEvent, J9JFR_EVENT_TYPE_PHYSICAL_MEMORY);
2313-
}
2330+
jfrPhysicalMemory(currentThread);
23142331
}
23152332

23162333
void

0 commit comments

Comments
 (0)