Skip to content

Commit

Permalink
Convert jvmtiThread.c to jvmtiThread.cpp
Browse files Browse the repository at this point in the history
This will simplify future changes for virtual thread support.

Signed-off-by: Babneet Singh <[email protected]>
  • Loading branch information
babsingh committed Nov 20, 2023
1 parent be78d79 commit 69fbaa8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion runtime/jvmti/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ j9vm_add_library(j9jvmti SHARED
jvmtiStackFrame.c
jvmtiStartup.c
jvmtiSystemProperties.c
jvmtiThread.c
jvmtiThread.cpp
jvmtiThreadGroup.c
jvmtiTimers.c
jvmtiWatchedField.c
Expand Down
24 changes: 14 additions & 10 deletions runtime/jvmti/jvmtiThread.c → runtime/jvmti/jvmtiThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include "jvmtiHelpers.h"
#include "jvmti_internal.h"

extern "C" {

typedef struct J9JVMTIRunAgentThreadArgs {
jvmtiEnv *jvmti_env;
jvmtiStartFunction proc;
Expand Down Expand Up @@ -180,7 +182,7 @@ jvmtiGetAllThreads(jvmtiEnv *env,

vm->internalVMFunctions->acquireExclusiveVMAccess(currentThread);

threads = j9mem_allocate_memory(sizeof(jthread) * vm->totalThreadCount, J9MEM_CATEGORY_JVMTI_ALLOCATE);
threads = (jthread *)j9mem_allocate_memory(sizeof(jthread) * vm->totalThreadCount, J9MEM_CATEGORY_JVMTI_ALLOCATE);
if (NULL == threads) {
rc = JVMTI_ERROR_OUT_OF_MEMORY;
} else {
Expand Down Expand Up @@ -525,7 +527,7 @@ jvmtiGetThreadInfo(jvmtiEnv *env,
j9object_t threadName = J9VMJAVALANGTHREAD_NAME(currentThread, threadObject);

if (NULL == threadName) {
name = j9mem_allocate_memory(1, J9MEM_CATEGORY_JVMTI_ALLOCATE);
name = (char *)j9mem_allocate_memory(1, J9MEM_CATEGORY_JVMTI_ALLOCATE);
if (NULL == name) {
rc = JVMTI_ERROR_OUT_OF_MEMORY;
goto release;
Expand All @@ -543,7 +545,7 @@ jvmtiGetThreadInfo(jvmtiEnv *env,
size_t threadNameLen = (NULL == threadName) ? 1 : (strlen(threadName) + 1);

/* Be sure to allocate at least one byte for the nul termination. */
name = j9mem_allocate_memory(threadNameLen, J9MEM_CATEGORY_JVMTI_ALLOCATE);
name = (char *)j9mem_allocate_memory(threadNameLen, J9MEM_CATEGORY_JVMTI_ALLOCATE);
if (NULL == name) {
/* Failed to allocate memory, so release VMTthread and exit. */
releaseOMRVMThreadName(targetThread->omrVMThread);
Expand Down Expand Up @@ -698,7 +700,7 @@ jvmtiGetOwnedMonitorInfo(jvmtiEnv *env,

count = walkLocalMonitorRefs(currentThread, NULL, targetThread, threadToWalk, UDATA_MAX);

locks = j9mem_allocate_memory(sizeof(jobject) * count, J9MEM_CATEGORY_JVMTI_ALLOCATE);
locks = (jobject *)j9mem_allocate_memory(sizeof(jobject) * count, J9MEM_CATEGORY_JVMTI_ALLOCATE);
if (NULL == locks) {
rc = JVMTI_ERROR_OUT_OF_MEMORY;
} else if (0 != count) {
Expand Down Expand Up @@ -817,7 +819,7 @@ jvmtiGetOwnedMonitorStackDepthInfo(jvmtiEnv *env,

/* Do we have any records at all? */
if (maxRecords > 0) {
resultArray = j9mem_allocate_memory((jlong)maxRecords * sizeof(jvmtiMonitorStackDepthInfo), J9MEM_CATEGORY_JVMTI_ALLOCATE);
resultArray = (jvmtiMonitorStackDepthInfo *)j9mem_allocate_memory((jlong)maxRecords * sizeof(jvmtiMonitorStackDepthInfo), J9MEM_CATEGORY_JVMTI_ALLOCATE);
if (NULL == resultArray) {
maxRecords = 0;
resultArray = NULL;
Expand Down Expand Up @@ -970,7 +972,7 @@ jvmtiRunAgentThread(jvmtiEnv *env,
}

/* Create entry args for the thread proc. */
args = j9mem_allocate_memory(sizeof(J9JVMTIRunAgentThreadArgs), J9MEM_CATEGORY_JVMTI);
args = (J9JVMTIRunAgentThreadArgs *)j9mem_allocate_memory(sizeof(J9JVMTIRunAgentThreadArgs), J9MEM_CATEGORY_JVMTI);
if (NULL == args) {
rc = JVMTI_ERROR_OUT_OF_MEMORY;
} else {
Expand Down Expand Up @@ -1169,7 +1171,7 @@ static int J9THREAD_PROC
agentThreadStart(void *entryArg)
{
UDATA result = 0;
J9JVMTIRunAgentThreadArgs *args = entryArg;
J9JVMTIRunAgentThreadArgs *args = (J9JVMTIRunAgentThreadArgs *)entryArg;
J9JavaVM *vm = JAVAVM_FROM_ENV((J9JVMTIEnv *)args->jvmti_env);
J9VMThread *vmThread = vm->internalVMFunctions->currentVMThread(vm);
PORT_ACCESS_FROM_JAVAVM(vm);
Expand All @@ -1189,7 +1191,7 @@ agentThreadStart(void *entryArg)
static UDATA
wrappedAgentThreadStart(J9PortLibrary *portLib, void *entryArg)
{
J9JVMTIRunAgentThreadArgs *args = entryArg;
J9JVMTIRunAgentThreadArgs *args = (J9JVMTIRunAgentThreadArgs *)entryArg;
J9JavaVM *vm = JAVAVM_FROM_ENV((J9JVMTIEnv *)args->jvmti_env);
J9VMThread *vmThread = vm->internalVMFunctions->currentVMThread(vm);
jvmtiEnv *jvmti_env = args->jvmti_env;
Expand Down Expand Up @@ -1279,10 +1281,10 @@ walkLocalMonitorRefs(J9VMThread *currentThread, jobject *locks, J9VMThread *targ

/* Check the local JNI refs. */
while (NULL != frame) {
ref = pool_startDo(frame->references, &poolState);
ref = (j9object_t *)pool_startDo((J9Pool *)frame->references, &poolState);
while (NULL != ref) {
ownedMonitorIterator(currentThread, &walkState, ref, ref);
ref = pool_nextDo(&poolState);
ref = (j9object_t *)pool_nextDo(&poolState);
}
frame = frame->previous;
}
Expand Down Expand Up @@ -1475,3 +1477,5 @@ jvmtiResumeAllVirtualThreads(jvmtiEnv *env,
TRACE_JVMTI_RETURN(jvmtiResumeAllVirtualThreads);
}
#endif /* JAVA_SPEC_VERSION >= 19 */

} /* extern "C" */
2 changes: 1 addition & 1 deletion runtime/jvmti/jvmti_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -2238,7 +2238,7 @@ jvmtiSetSystemProperty(jvmtiEnv* env,
const char* value);


/* ---------------- jvmtiThread.c ---------------- */
/* ---------------- jvmtiThread.cpp ---------------- */

/**
* @brief
Expand Down

0 comments on commit 69fbaa8

Please sign in to comment.