diff --git a/runtime/vm/JFRChunkWriter.cpp b/runtime/vm/JFRChunkWriter.cpp index afc55972887..2be5b51dc7c 100644 --- a/runtime/vm/JFRChunkWriter.cpp +++ b/runtime/vm/JFRChunkWriter.cpp @@ -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 */ diff --git a/runtime/vm/JFRChunkWriter.hpp b/runtime/vm/JFRChunkWriter.hpp index bb33e63f47e..430cb98f2a0 100644 --- a/runtime/vm/JFRChunkWriter.hpp +++ b/runtime/vm/JFRChunkWriter.hpp @@ -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; @@ -250,7 +250,7 @@ class VM_JFRChunkWriter { } - void writeJFRChunk() + void writeJFRChunk(bool isExclusivePermited) { U_8 *buffer = NULL; UDATA requiredBufferSize = 0; @@ -345,7 +345,9 @@ class VM_JFRChunkWriter { writePhysicalMemoryEvent(); - writeThreadDumpEvent(); + if (isExclusivePermited) { + writeThreadDumpEvent(); + } writeNativeLibraryEvents(); diff --git a/runtime/vm/JFRWriter.hpp b/runtime/vm/JFRWriter.hpp index 2da046d36a2..0f5768abee9 100644 --- a/runtime/vm/JFRWriter.hpp +++ b/runtime/vm/JFRWriter.hpp @@ -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); @@ -190,7 +190,7 @@ class VM_JFRWriter { goto fail; } - chunkWriter.writeJFRChunk(); + chunkWriter.writeJFRChunk(isExclusivePermited); if (!chunkWriter.isOkay()) { result = false; goto fail; diff --git a/runtime/vm/jfr.cpp b/runtime/vm/jfr.cpp index 53603a926ee..cb2c0a29eea 100644 --- a/runtime/vm/jfr.cpp +++ b/runtime/vm/jfr.cpp @@ -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; @@ -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; @@ -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; @@ -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); @@ -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); } /** @@ -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); @@ -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" */