Skip to content

Commit 931109e

Browse files
authored
Merge pull request #20670 from thallium/init-env-0.49
(0.49) Add JFR InitialEnvironmentVariable support
2 parents 60af720 + 97d3bd2 commit 931109e

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

runtime/vm/JFRChunkWriter.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,4 +815,52 @@ VM_JFRChunkWriter::writeInitialSystemPropertyEvents(J9JavaVM *vm)
815815
}
816816
}
817817

818+
void
819+
VM_JFRChunkWriter::writeInitialEnvironmentVariableEvents()
820+
{
821+
J9SysinfoEnvIteratorState envState;
822+
memset(&envState, 0, sizeof(envState));
823+
824+
/* Call init with zero length buffer to get the required buffer size */
825+
int32_t result = j9sysinfo_env_iterator_init(&envState, NULL, 0);
826+
827+
if (result >= 0) {
828+
int32_t bufferSize = result;
829+
void *buffer = j9mem_allocate_memory(bufferSize, OMRMEM_CATEGORY_VM);
830+
831+
if (NULL != buffer) {
832+
J9SysinfoEnvElement envElement = {NULL};
833+
834+
result = j9sysinfo_env_iterator_init(&envState, buffer, bufferSize);
835+
836+
if (result >= 0) {
837+
while (j9sysinfo_env_iterator_hasNext(&envState)) {
838+
result = j9sysinfo_env_iterator_next(&envState, &envElement);
839+
840+
if (0 == result) {
841+
/* reserve size field */
842+
U_8 *dataStart = _bufferWriter->getAndIncCursor(sizeof(U_32));
843+
const char *equalChar = strchr(envElement.nameAndValue, '=');
844+
845+
/* write event type */
846+
_bufferWriter->writeLEB128(InitialEnvironmentVariableID);
847+
848+
/* write start time */
849+
_bufferWriter->writeLEB128(j9time_nano_time());
850+
/* write key */
851+
writeUTF8String((U_8 *)envElement.nameAndValue, equalChar - envElement.nameAndValue);
852+
853+
/* write value */
854+
writeStringLiteral(equalChar + 1);
855+
856+
/* write size */
857+
_bufferWriter->writeLEB128PaddedU32(dataStart, _bufferWriter->getCursor() - dataStart);
858+
}
859+
}
860+
}
861+
862+
j9mem_free_memory(buffer);
863+
}
864+
}
865+
}
818866
#endif /* defined(J9VM_OPT_JFR) */

runtime/vm/JFRChunkWriter.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ enum MetadataTypeID {
7070
OSInformationID = 87,
7171
VirtualizationInformationID = 88,
7272
InitialSystemPropertyID = 89,
73+
InitialEnvironmentVariableID = 90,
7374
CPUInformationID = 92,
7475
CPULoadID = 94,
7576
ThreadCPULoadID = 95,
@@ -162,6 +163,7 @@ class VM_JFRChunkWriter {
162163
static constexpr int INITIAL_SYSTEM_PROPERTY_EVENT_SIZE = 6000;
163164
static constexpr int CPU_LOAD_EVENT_SIZE = (3 * sizeof(float)) + (3 * sizeof(I_64));
164165
static constexpr int THREAD_CPU_LOAD_EVENT_SIZE = (2 * sizeof(float)) + (4 * sizeof(I_64));
166+
static constexpr int INITIAL_ENVIRONMENT_VARIABLE_EVENT_SIZE = 6000;
165167

166168
static constexpr int METADATA_ID = 1;
167169

@@ -347,6 +349,8 @@ class VM_JFRChunkWriter {
347349
writeOSInformationEvent();
348350

349351
writeInitialSystemPropertyEvents(_vm);
352+
353+
writeInitialEnvironmentVariableEvents();
350354
}
351355

352356
writePhysicalMemoryEvent();
@@ -625,6 +629,8 @@ class VM_JFRChunkWriter {
625629

626630
void writeStringLiteral(const char *string);
627631

632+
void writeStringLiteral(const char *string, UDATA len);
633+
628634
U_8 *writeThreadStateCheckpointEvent();
629635

630636
U_8 *writePackageCheckpointEvent();
@@ -659,6 +665,8 @@ class VM_JFRChunkWriter {
659665

660666
void writeInitialSystemPropertyEvents(J9JavaVM *vm);
661667

668+
void writeInitialEnvironmentVariableEvents();
669+
662670
UDATA
663671
calculateRequiredBufferSize()
664672
{
@@ -713,6 +721,8 @@ class VM_JFRChunkWriter {
713721

714722
requiredBufferSize += INITIAL_SYSTEM_PROPERTY_EVENT_SIZE;
715723

724+
requiredBufferSize += INITIAL_ENVIRONMENT_VARIABLE_EVENT_SIZE;
725+
716726
requiredBufferSize += _constantPoolTypes.getCPULoadCount() * CPU_LOAD_EVENT_SIZE;
717727

718728
requiredBufferSize += _constantPoolTypes.getThreadCPULoadCount() * THREAD_CPU_LOAD_EVENT_SIZE;

0 commit comments

Comments
 (0)