Skip to content

Commit

Permalink
Merge pull request #20616 from thallium/init-env
Browse files Browse the repository at this point in the history
Add JFR InitialEnvironmentVariable support
  • Loading branch information
tajila authored Nov 21, 2024
2 parents 28a6b3e + 7a84785 commit 708db6e
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
48 changes: 48 additions & 0 deletions runtime/vm/JFRChunkWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -815,4 +815,52 @@ VM_JFRChunkWriter::writeInitialSystemPropertyEvents(J9JavaVM *vm)
}
}

void
VM_JFRChunkWriter::writeInitialEnvironmentVariableEvents()
{
J9SysinfoEnvIteratorState envState;
memset(&envState, 0, sizeof(envState));

/* Call init with zero length buffer to get the required buffer size */
int32_t result = j9sysinfo_env_iterator_init(&envState, NULL, 0);

if (result >= 0) {
int32_t bufferSize = result;
void *buffer = j9mem_allocate_memory(bufferSize, OMRMEM_CATEGORY_VM);

if (NULL != buffer) {
J9SysinfoEnvElement envElement = {NULL};

result = j9sysinfo_env_iterator_init(&envState, buffer, bufferSize);

if (result >= 0) {
while (j9sysinfo_env_iterator_hasNext(&envState)) {
result = j9sysinfo_env_iterator_next(&envState, &envElement);

if (0 == result) {
/* reserve size field */
U_8 *dataStart = _bufferWriter->getAndIncCursor(sizeof(U_32));
const char *equalChar = strchr(envElement.nameAndValue, '=');

/* write event type */
_bufferWriter->writeLEB128(InitialEnvironmentVariableID);

/* write start time */
_bufferWriter->writeLEB128(j9time_nano_time());
/* write key */
writeUTF8String((U_8 *)envElement.nameAndValue, equalChar - envElement.nameAndValue);

/* write value */
writeStringLiteral(equalChar + 1);

/* write size */
_bufferWriter->writeLEB128PaddedU32(dataStart, _bufferWriter->getCursor() - dataStart);
}
}
}

j9mem_free_memory(buffer);
}
}
}
#endif /* defined(J9VM_OPT_JFR) */
10 changes: 10 additions & 0 deletions runtime/vm/JFRChunkWriter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ enum MetadataTypeID {
OSInformationID = 87,
VirtualizationInformationID = 88,
InitialSystemPropertyID = 89,
InitialEnvironmentVariableID = 90,
CPUInformationID = 92,
CPULoadID = 94,
ThreadCPULoadID = 95,
Expand Down Expand Up @@ -162,6 +163,7 @@ class VM_JFRChunkWriter {
static constexpr int INITIAL_SYSTEM_PROPERTY_EVENT_SIZE = 6000;
static constexpr int CPU_LOAD_EVENT_SIZE = (3 * sizeof(float)) + (3 * sizeof(I_64));
static constexpr int THREAD_CPU_LOAD_EVENT_SIZE = (2 * sizeof(float)) + (4 * sizeof(I_64));
static constexpr int INITIAL_ENVIRONMENT_VARIABLE_EVENT_SIZE = 6000;

static constexpr int METADATA_ID = 1;

Expand Down Expand Up @@ -348,6 +350,8 @@ class VM_JFRChunkWriter {
writeOSInformationEvent();

writeInitialSystemPropertyEvents(_vm);

writeInitialEnvironmentVariableEvents();
}

writePhysicalMemoryEvent();
Expand Down Expand Up @@ -626,6 +630,8 @@ class VM_JFRChunkWriter {

void writeStringLiteral(const char *string);

void writeStringLiteral(const char *string, UDATA len);

U_8 *writeThreadStateCheckpointEvent();

U_8 *writePackageCheckpointEvent();
Expand Down Expand Up @@ -660,6 +666,8 @@ class VM_JFRChunkWriter {

void writeInitialSystemPropertyEvents(J9JavaVM *vm);

void writeInitialEnvironmentVariableEvents();

UDATA
calculateRequiredBufferSize()
{
Expand Down Expand Up @@ -714,6 +722,8 @@ class VM_JFRChunkWriter {

requiredBufferSize += INITIAL_SYSTEM_PROPERTY_EVENT_SIZE;

requiredBufferSize += INITIAL_ENVIRONMENT_VARIABLE_EVENT_SIZE;

requiredBufferSize += _constantPoolTypes.getCPULoadCount() * CPU_LOAD_EVENT_SIZE;

requiredBufferSize += _constantPoolTypes.getThreadCPULoadCount() * THREAD_CPU_LOAD_EVENT_SIZE;
Expand Down

0 comments on commit 708db6e

Please sign in to comment.