Skip to content

Commit fba2247

Browse files
authored
Merge pull request #21382 from adpopescu/jfr-gc-heap-event
Add JFR GCHeapConfiguration Event
2 parents ed10257 + 4cc96eb commit fba2247

File tree

4 files changed

+124
-0
lines changed

4 files changed

+124
-0
lines changed

runtime/vm/JFRChunkWriter.cpp

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,70 @@ VM_JFRChunkWriter::writeOSInformationEvent()
809809
return dataStart;
810810
}
811811

812+
void
813+
VM_JFRChunkWriter::writeNarrowOOPModeTypesEvent()
814+
{
815+
U_8 *dataStart = writeCheckpointEventHeader(Generic, 1);
816+
817+
/* class ID */
818+
_bufferWriter->writeLEB128(NarrowOopModesID);
819+
820+
/* number of states */
821+
_bufferWriter->writeLEB128(OOPModeTypeCount);
822+
823+
for (int i = 0; i < OOPModeTypeCount; i++) {
824+
/* constant index */
825+
_bufferWriter->writeLEB128(i);
826+
827+
/* write string */
828+
writeStringLiteral(oopModeTypeNames[i]);
829+
}
830+
831+
/* write size */
832+
writeEventSize(dataStart);
833+
834+
}
835+
836+
void
837+
VM_JFRChunkWriter::writeGCHeapConfigurationEvent()
838+
{
839+
GCHeapConfigurationEntry *gcConfig = &(VM_JFRConstantPoolTypes::getJFRConstantEvents(_vm)->GCHeapConfigEntry);
840+
841+
/* reserve size field */
842+
U_8 *dataStart = reserveEventSize();
843+
844+
/* write event type */
845+
_bufferWriter->writeLEB128(GCHeapConfigID);
846+
847+
/* write event start time */
848+
_bufferWriter->writeLEB128(j9time_nano_time());
849+
850+
/* write heap min size */
851+
_bufferWriter->writeLEB128(gcConfig->minSize);
852+
853+
/* write heap max size */
854+
_bufferWriter->writeLEB128(gcConfig->maxSize);
855+
856+
/* write heap initial size */
857+
_bufferWriter->writeLEB128(gcConfig->initialSize);
858+
859+
/* write whether oops are used or not */
860+
_bufferWriter->writeBoolean(gcConfig->usesCompressedOops);
861+
862+
/* write oops type being used */
863+
_bufferWriter->writeLEB128(gcConfig->compressedOopsMode);
864+
865+
/* write how object alignment is on the heap */
866+
_bufferWriter->writeLEB128(gcConfig->objectAlignment);
867+
868+
/* write how many bits head addresses are */
869+
_bufferWriter->writeLEB128(gcConfig->heapAddressBits);
870+
871+
/* write event size */
872+
writeEventSize(dataStart);
873+
874+
}
875+
812876
void
813877
VM_JFRChunkWriter::writeInitialSystemPropertyEvents(J9JavaVM *vm)
814878
{

runtime/vm/JFRChunkWriter.hpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ static constexpr const char * const threadStateNames[] = {
5252
"STATE_BLOCKED_ON_MONITOR_ENTER"
5353
};
5454

55+
static constexpr const char * const oopModeTypeNames[] = {
56+
"Zero based"
57+
};
58+
5559
enum StringEnconding {
5660
NullString = 0,
5761
EmptyString,
@@ -82,13 +86,15 @@ enum MetadataTypeID {
8286
PhysicalMemoryID = 108,
8387
ExecutionSampleID = 109,
8488
ThreadDumpID = 111,
89+
GCHeapConfigID = 133,
8590
ThreadID = 164,
8691
ThreadGroupID = 165,
8792
ClassID = 166,
8893
ClassLoaderID = 167,
8994
MethodID = 168,
9095
SymbolID = 169,
9196
ThreadStateID = 170,
97+
NarrowOopModesID = 180,
9298
ModuleID = 186,
9399
PackageID = 187,
94100
StackTraceID = 188,
@@ -148,6 +154,7 @@ class VM_JFRChunkWriter {
148154
static constexpr int CHECKPOINT_EVENT_HEADER_AND_FOOTER = 68;
149155
static constexpr int STRING_CONSTANT_SIZE = 128;
150156
static constexpr int THREADSTATE_ENTRY_LENGTH = CHECKPOINT_EVENT_HEADER_AND_FOOTER + sizeof(threadStateNames) + (THREADSTATE_COUNT * STRING_HEADER_LENGTH);
157+
static constexpr int OOP_MODES_ENTRY_SIZE = CHECKPOINT_EVENT_HEADER_AND_FOOTER + sizeof(oopModeTypeNames) + (OOPModeTypeCount * STRING_HEADER_LENGTH);
151158
static constexpr int CLASS_ENTRY_ENTRY_SIZE = (5 * sizeof(U_64)) + sizeof(U_8);
152159
static constexpr int CLASSLOADER_ENTRY_SIZE = 3 * sizeof(U_64);
153160
static constexpr int PACKAGE_ENTRY_SIZE = (3 * sizeof(U_64)) + sizeof(U_8);
@@ -344,6 +351,10 @@ class VM_JFRChunkWriter {
344351

345352
writeFrameTypeCheckpointEvent();
346353

354+
if (0 == _vm->jfrState.jfrChunkCount) {
355+
writeNarrowOOPModeTypesEvent();
356+
}
357+
347358
writeThreadCheckpointEvent();
348359

349360
writeThreadGroupCheckpointEvent();
@@ -399,6 +410,8 @@ class VM_JFRChunkWriter {
399410
writeInitialSystemPropertyEvents(_vm);
400411

401412
writeInitialEnvironmentVariableEvents();
413+
414+
writeGCHeapConfigurationEvent();
402415
}
403416

404417
writePhysicalMemoryEvent();
@@ -800,6 +813,10 @@ class VM_JFRChunkWriter {
800813

801814
U_8 *writeThreadDumpEvent();
802815

816+
void writeNarrowOOPModeTypesEvent();
817+
818+
void writeGCHeapConfigurationEvent();
819+
803820
void writeInitialSystemPropertyEvents(J9JavaVM *vm);
804821

805822
void writeInitialEnvironmentVariableEvents();

runtime/vm/JFRConstantPoolTypes.hpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ enum FrameType {
6363
FrameTypeCount,
6464
};
6565

66+
enum OOPModeType {
67+
ZeroBased = 0,
68+
OOPModeTypeCount,
69+
};
70+
6671
enum ThreadState {
6772
NEW = 0,
6873
TERMINATED,
@@ -288,6 +293,16 @@ struct CPUInformationEntry {
288293
U_32 hwThreads;
289294
};
290295

296+
struct GCHeapConfigurationEntry {
297+
U_64 minSize;
298+
U_64 maxSize;
299+
U_64 initialSize;
300+
BOOLEAN usesCompressedOops;
301+
OOPModeType compressedOopsMode;
302+
U_64 objectAlignment;
303+
UDATA heapAddressBits;
304+
};
305+
291306
struct VirtualizationInformationEntry {
292307
const char *name;
293308
};
@@ -301,6 +316,7 @@ struct JFRConstantEvents {
301316
CPUInformationEntry CPUInfoEntry;
302317
VirtualizationInformationEntry VirtualizationInfoEntry;
303318
OSInformationEntry OSInfoEntry;
319+
GCHeapConfigurationEntry GCHeapConfigEntry;
304320
};
305321

306322
class VM_JFRConstantPoolTypes {
@@ -989,6 +1005,7 @@ class VM_JFRConstantPoolTypes {
9891005
initializeCPUInformationEvent(vm, currentThread, result);
9901006
initializeVirtualizationInformation(vm);
9911007
initializeOSInformation(vm, result);
1008+
initializeGCHeapConfigurationEvent(vm, result);
9921009
}
9931010

9941011
/**
@@ -1209,6 +1226,26 @@ class VM_JFRConstantPoolTypes {
12091226
}
12101227
}
12111228

1229+
/**
1230+
* Initialize GCHeapConfigurationEntry
1231+
*
1232+
* @param vm[in] the J9JavaVM
1233+
*/
1234+
static void initializeGCHeapConfigurationEvent(J9JavaVM *vm, BuildResult *result)
1235+
{
1236+
J9MemoryManagerFunctions *mmFuncs = vm->memoryManagerFunctions;
1237+
GCHeapConfigurationEntry *gcConfiguration = &(getJFRConstantEvents(vm)->GCHeapConfigEntry);
1238+
1239+
gcConfiguration->minSize = mmFuncs->j9gc_get_initial_heap_size(vm);
1240+
gcConfiguration->maxSize = mmFuncs->j9gc_get_maximum_heap_size(vm);
1241+
gcConfiguration->initialSize = gcConfiguration->minSize;
1242+
uintptr_t value;
1243+
gcConfiguration->usesCompressedOops = mmFuncs->j9gc_modron_getConfigurationValueForKey(vm, j9gc_modron_configuration_compressObjectReferences, &value) ? value : 0;
1244+
gcConfiguration->compressedOopsMode = ZeroBased;
1245+
gcConfiguration->objectAlignment = vm->objectAlignmentInBytes;
1246+
gcConfiguration->heapAddressBits = J9JAVAVM_REFERENCE_SIZE(vm) * 8;
1247+
}
1248+
12121249
VM_JFRConstantPoolTypes(J9VMThread *currentThread)
12131250
: _currentThread(currentThread)
12141251
, _vm(currentThread->javaVM)

test/functional/cmdLineTests/jfr/jfrevents.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,10 @@ SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0-only WITH Classpath-ex
7575
<output type="success" caseSensitive="yes" regex="no">stackTrace</output>
7676
<output type="failure" caseSensitive="yes" regex="no">jfr print: could not read recording</output>
7777
</test>
78+
<test id="test jfr gc heap configuration - approx 30seconds">
79+
<command>$JFR_EXE$ print --xml --events "GCHeapConfiguration" defaultJ9recording.jfr</command>
80+
<output type="required" caseSensitive="yes" regex="no">http://www.w3.org/2001/XMLSchema-instance</output>
81+
<output type="success" caseSensitive="yes" regex="no">jdk.GCHeapConfiguration</output>
82+
<output type="failure" caseSensitive="yes" regex="no">jfr print: could not read recording</output>
83+
</test>
7884
</suite>

0 commit comments

Comments
 (0)