Skip to content

Commit

Permalink
Merge pull request #18355 from tajila/issue4
Browse files Browse the repository at this point in the history
Fix interpreter transition in getThreadAllocBytes
  • Loading branch information
pshipton committed Oct 26, 2023
2 parents 8f72ea7 + 3618106 commit ae0b30a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
1 change: 0 additions & 1 deletion runtime/jcl/common/mgmtthread.c
Expand Up @@ -465,7 +465,6 @@ Java_com_ibm_lang_management_internal_ExtendedThreadMXBeanImpl_getThreadAllocate

/* Shortcut for the current thread. */
if (getThreadID(currentThread, (j9object_t)currentThread->threadObject) == threadID) {
vmfns->internalExitVMToJNI(currentThread);
if (mmfns->j9gc_get_cumulative_bytes_allocated_by_thread(currentThread, &allocatedBytes)) {
result = (jlong) allocatedBytes;
}
Expand Down
Expand Up @@ -1068,31 +1068,32 @@ public final void testThreadAllocationMetricsOnCurrentThread() {
com.sun.management.ThreadMXBean sunTB = (com.sun.management.ThreadMXBean)tb;
AssertJUnit.assertTrue(sunTB.isThreadAllocatedMemoryEnabled());
AssertJUnit.assertTrue(sunTB.isThreadAllocatedMemorySupported());
long tid = Thread.currentThread().getId();

long bytes1 = sunTB.getCurrentThreadAllocatedBytes();
long bytes1 = sunTB.getThreadAllocatedBytes(tid);
AssertJUnit.assertTrue(bytes1 > 0);
ArrayList list = new ArrayList<>();

for (int i = 0; i < 1000; i++) {
list.add(new Object[100]);
}

long bytes2 = sunTB.getCurrentThreadAllocatedBytes();
long bytes2 = sunTB.getThreadAllocatedBytes(tid);
AssertJUnit.assertTrue(bytes2 > bytes1);

sunTB.setThreadAllocatedMemoryEnabled(false);
long bytes3 = sunTB.getCurrentThreadAllocatedBytes();
long bytes3 = sunTB.getThreadAllocatedBytes(tid);
AssertJUnit.assertTrue(bytes3 == -1);

sunTB.setThreadAllocatedMemoryEnabled(false);
long bytes4 = sunTB.getCurrentThreadAllocatedBytes();
long bytes4 = sunTB.getThreadAllocatedBytes(tid);
AssertJUnit.assertTrue(bytes4 >= bytes3);

for (int i = 0; i < 1000; i++) {
list.add(new Object[100]);
}

long bytes5 = sunTB.getCurrentThreadAllocatedBytes();
long bytes5 = sunTB.getThreadAllocatedBytes(tid);
AssertJUnit.assertTrue(bytes5 >= bytes4);
}

Expand Down

0 comments on commit ae0b30a

Please sign in to comment.