Skip to content

Commit

Permalink
Fix interpreter transition in getThreadAllocBytes
Browse files Browse the repository at this point in the history
Fix interpreter transition in getThreadAllocatedBytes. Also use
parameterized variant of the API to support JDK8.

Signed-off-by: Tobi Ajila <[email protected]>
  • Loading branch information
tajila committed Nov 9, 2023
1 parent 8716a18 commit dad3c02
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 dad3c02

Please sign in to comment.