Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
Signed-off-by: Gengchen Tuo <[email protected]>
  • Loading branch information
thallium committed Nov 5, 2024
1 parent 3ff809a commit 6856a4a
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 13 deletions.
31 changes: 30 additions & 1 deletion runtime/vm/JFRChunkWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -836,15 +836,44 @@ VM_JFRChunkWriter::writeThreadDumpEvent()
J9VMThread *walkThread = J9_LINKED_LIST_START_DO(_vm->mainThread);
UDATA numThreads = 0;
char *cursor = result;
J9InternalVMFunctions *vmFuncs = _vm->internalVMFunctions;
bool acquiredVMAccess = false;

if (0 == (_currentThread->publicFlags & J9_PUBLIC_FLAGS_VM_ACCESS)) {
acquiredVMAccess = true;
vmFuncs->internalAcquireVMAccess(_currentThread);
}

vmFuncs->acquireExclusiveVMAccess(_currentThread);

while (NULL != walkThread) {
UDATA javaTID = J9VMJAVALANGTHREAD_TID(_currentThread, walkThread->threadObject);
UDATA osTID = ((J9AbstractThread *)walkThread->osThread)->tid;
cursor += sprintf(cursor, "%p javaTID: %zd osTID: %zd\n", walkThread, javaTID, osTID);
char *threadName = NULL;
#if JAVA_SPEC_VERSION >= 21
if (IS_JAVA_LANG_VIRTUALTHREAD(_currentThread, walkThread->threadObject)) {
/* For VirtualThread, get name from threadObject directly. */
j9object_t nameObject = J9VMJAVALANGTHREAD_NAME(_currentThread, walkThread->threadObject);
threadName = getVMThreadNameFromString(_currentThread, nameObject);
} else
#endif /* JAVA_SPEC_VERSION >= 21 */
{
threadName = tryGetOMRVMThreadName(walkThread->omrVMThread);
}


printf("name: %s\n", threadName);
cursor += sprintf(cursor, "%s %p javaTID: %zd osTID: %zd\n", threadName, walkThread, javaTID, osTID);
numThreads++;
walkThread = J9_LINKED_LIST_NEXT_DO(_vm->mainThread, walkThread);
}
sprintf(cursor, "Number of threads: %zd", numThreads);

vmFuncs->releaseExclusiveVMAccess(_currentThread);

if (acquiredVMAccess) {
vmFuncs->internalReleaseVMAccess(_currentThread);
}
}

/* write result */
Expand Down
8 changes: 5 additions & 3 deletions runtime/vm/JFRChunkWriter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ class VM_JFRChunkWriter {
static constexpr int CPU_INFORMATION_EVENT_SIZE = 600;
static constexpr int OS_INFORMATION_EVENT_SIZE = 100;
static constexpr int INITIAL_SYSTEM_PROPERTY_EVENT_SIZE = 6000;
static constexpr int THREAD_DUMP_EVENT_SIZE = 3000;
static constexpr int THREAD_DUMP_EVENT_SIZE = 10000;
static constexpr int NATIVE_LIBRARY_EVENT_SIZE = 3000;

static constexpr int METADATA_ID = 1;
Expand Down Expand Up @@ -250,7 +250,7 @@ class VM_JFRChunkWriter {

}

void writeJFRChunk()
void writeJFRChunk(bool isExclusivePermited)
{
U_8 *buffer = NULL;
UDATA requiredBufferSize = 0;
Expand Down Expand Up @@ -345,7 +345,9 @@ class VM_JFRChunkWriter {

writePhysicalMemoryEvent();

writeThreadDumpEvent();
if (isExclusivePermited) {
writeThreadDumpEvent();
}

writeNativeLibraryEvents();

Expand Down
4 changes: 2 additions & 2 deletions runtime/vm/JFRWriter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class VM_JFRWriter {
}

static bool
flushJFRDataToFile(J9VMThread *currentThread, bool finalWrite)
flushJFRDataToFile(J9VMThread *currentThread, bool finalWrite, bool isExclusivePermited)
{
bool result = true;
VM_JFRChunkWriter chunkWriter(currentThread, finalWrite);
Expand All @@ -190,7 +190,7 @@ class VM_JFRWriter {
goto fail;
}

chunkWriter.writeJFRChunk();
chunkWriter.writeJFRChunk(isExclusivePermited);
if (!chunkWriter.isOkay()) {
result = false;
goto fail;
Expand Down
14 changes: 7 additions & 7 deletions runtime/vm/jfr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ jfrBufferNextDo(J9JFRBufferWalkState *walkState)
* @returns true on success, false on failure
*/
static bool
writeOutGlobalBuffer(J9VMThread *currentThread, bool finalWrite)
writeOutGlobalBuffer(J9VMThread *currentThread, bool finalWrite, bool isExclusivePermited)
{
J9JavaVM *vm = currentThread->javaVM;

Expand All @@ -138,7 +138,7 @@ writeOutGlobalBuffer(J9VMThread *currentThread, bool finalWrite)
j9tty_printf(PORTLIB, "\n!!! writing global buffer %p of size %p\n", currentThread, vm->jfrBuffer.bufferSize - vm->jfrBuffer.bufferRemaining);
#endif /* defined(DEBUG) */

VM_JFRWriter::flushJFRDataToFile(currentThread, finalWrite);
VM_JFRWriter::flushJFRDataToFile(currentThread, finalWrite, isExclusivePermited);

/* Reset the buffer */
vm->jfrBuffer.bufferRemaining = vm->jfrBuffer.bufferSize;
Expand Down Expand Up @@ -172,7 +172,7 @@ flushBufferToGlobal(J9VMThread *currentThread, J9VMThread *flushThread)

omrthread_monitor_enter(vm->jfrBufferMutex);
if (vm->jfrBuffer.bufferRemaining < bufferSize) {
if (!writeOutGlobalBuffer(currentThread, false)) {
if (!writeOutGlobalBuffer(currentThread, false, true)) {
omrthread_monitor_exit(vm->jfrBufferMutex);
success = false;
goto done;
Expand Down Expand Up @@ -356,7 +356,7 @@ jfrThreadDestroy(J9HookInterface **hook, UDATA eventNum, void *eventData, void *
* invalid, so write out all of the available data now.
*/
flushAllThreadBuffers(currentThread, false, true);
writeOutGlobalBuffer(currentThread, false);
writeOutGlobalBuffer(currentThread, false, false);

/* Free the thread local buffer */
j9mem_free_memory((void*)currentThread->jfrBuffer.bufferStart);
Expand Down Expand Up @@ -388,7 +388,7 @@ jfrClassesUnload(J9HookInterface **hook, UDATA eventNum, void *eventData, void *
* invalid, so write out all of the available data now.
*/
flushAllThreadBuffers(currentThread, false, false);
writeOutGlobalBuffer(currentThread, false);
writeOutGlobalBuffer(currentThread, false, true);
}

/**
Expand Down Expand Up @@ -419,7 +419,7 @@ jfrVMShutdown(J9HookInterface **hook, UDATA eventNum, void *eventData, void *use

/* Flush and free all the thread buffers and write out the global buffer */
flushAllThreadBuffers(currentThread, true, false);
writeOutGlobalBuffer(currentThread, true);
writeOutGlobalBuffer(currentThread, true, true);

if (acquiredExclusive) {
releaseExclusiveVMAccess(currentThread);
Expand Down Expand Up @@ -850,7 +850,7 @@ jfrDump(J9VMThread *currentThread, BOOLEAN finalWrite)

/* Flush all the thread buffers and write out the global buffer. */
flushAllThreadBuffers(currentThread, finalWrite, false);
writeOutGlobalBuffer(currentThread, finalWrite);
writeOutGlobalBuffer(currentThread, finalWrite, true);
}
} /* extern "C" */

Expand Down

0 comments on commit 6856a4a

Please sign in to comment.