Skip to content

Commit d98e1e5

Browse files
authored
Merge pull request #19805 from fengxue-IS/enhance-profiling
Refactor Continuation cache profiling
2 parents 97d0bb7 + 0076e93 commit d98e1e5

File tree

4 files changed

+54
-19
lines changed

4 files changed

+54
-19
lines changed

runtime/oti/j9consts.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ extern "C" {
365365
#define J9_EXTENDED_RUNTIME2_NEVER_KEEP_JNI_IDS 0x4000000
366366
#define J9_EXTENDED_RUNTIME2_FFI_PROTO 0x8000000
367367
#define J9_EXTENDED_RUNTIME2_DISABLE_EXTENDED_HCR 0x10000000
368+
#define J9_EXTENDED_RUNTIME2_ENABLE_CONTINUATION_CACHE_SUMMARY 0x20000000
368369

369370
#define J9_OBJECT_HEADER_AGE_DEFAULT 0xA /* OBJECT_HEADER_AGE_DEFAULT */
370371
#define J9_OBJECT_HEADER_SHAPE_MASK 0xE /* OBJECT_HEADER_SHAPE_MASK */

runtime/oti/j9nonbuilder.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6123,14 +6123,19 @@ typedef struct J9JavaVM {
61236123
J9VMContinuation **continuationT2Cache;
61246124
U_32 continuationT1Size;
61256125
U_32 continuationT2Size;
6126-
#if defined(J9VM_PROF_CONTINUATION_ALLOCATION)
61276126
volatile U_32 t1CacheHit;
61286127
volatile U_32 t2CacheHit;
6128+
volatile U_32 cacheMiss;
6129+
volatile U_32 t2store;
6130+
volatile U_32 cacheFree;
6131+
volatile U_64 totalContinuationStackSize;
6132+
#if defined(J9VM_PROF_CONTINUATION_ALLOCATION)
61296133
volatile I_64 avgCacheLookupTime;
61306134
volatile U_32 fastAlloc;
61316135
volatile U_32 slowAlloc;
61326136
volatile I_64 fastAllocAvgTime;
61336137
volatile I_64 slowAllocAvgTime;
6138+
volatile I_64 avgCacheFreeTime;
61346139
#endif /* defined(J9VM_PROF_CONTINUATION_ALLOCATION) */
61356140
#endif /* JAVA_SPEC_VERSION >= 19 */
61366141
#if defined(J9VM_OPT_CRIU_SUPPORT)

runtime/vm/ContinuationHelpers.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,7 @@ createContinuation(J9VMThread *currentThread, j9object_t continuationObject)
5252
if (NULL != currentThread->continuationT1Cache[i]) {
5353
continuation = currentThread->continuationT1Cache[i];
5454
currentThread->continuationT1Cache[i] = NULL;
55-
#if defined(J9VM_PROF_CONTINUATION_ALLOCATION)
5655
vm->t1CacheHit += 1;
57-
#endif /* defined(J9VM_PROF_CONTINUATION_ALLOCATION) */
5856
break;
5957
}
6058
}
@@ -69,9 +67,7 @@ createContinuation(J9VMThread *currentThread, j9object_t continuationObject)
6967
(uintptr_t)continuation,
7068
(uintptr_t)NULL))
7169
) {
72-
#if defined(J9VM_PROF_CONTINUATION_ALLOCATION)
7370
vm->t2CacheHit += 1;
74-
#endif /* defined(J9VM_PROF_CONTINUATION_ALLOCATION) */
7571
break;
7672
}
7773
continuation = NULL;
@@ -120,6 +116,7 @@ createContinuation(J9VMThread *currentThread, j9object_t continuationObject)
120116
vm->fastAllocAvgTime += totalTime;
121117
}
122118
#endif /* defined(J9VM_PROF_CONTINUATION_ALLOCATION) */
119+
vm->cacheMiss += 1;
123120
} else {
124121
/* Reset and reuse the stack in the recycled continuation. */
125122
stack = continuation->stackObject;
@@ -363,6 +360,7 @@ recycleContinuation(J9JavaVM *vm, J9VMThread *vmThread, J9VMContinuation* contin
363360
{
364361
PORT_ACCESS_FROM_JAVAVM(vm);
365362
bool cached = false;
363+
vm->totalContinuationStackSize += continuation->stackObject->size;
366364

367365
if (!skipLocalCache && (0 < vm->continuationT1Size)) {
368366
/* If called by carrier thread (not global), try to store in local cache first.
@@ -396,11 +394,13 @@ recycleContinuation(J9JavaVM *vm, J9VMThread *vmThread, J9VMContinuation* contin
396394
(uintptr_t)continuation))
397395
) {
398396
cached = true;
397+
vm->t2store += 1;
399398
break;
400399
}
401400
}
402401

403402
if (!cached) {
403+
vm->cacheFree += 1;
404404
/* Caching failed, free the J9VMContinuation struct. */
405405
freeJavaStack(vm, continuation->stackObject);
406406
j9mem_free_memory(continuation);

runtime/vm/jvminit.c

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1822,18 +1822,37 @@ processContinuationCacheOptions(J9JavaVM *vm)
18221822
IDATA argIndex = FIND_AND_CONSUME_VMARG(STARTSWITH_MATCH, VMOPT_XXCONTINUATIONCACHE, NULL);
18231823
if (-1 != argIndex) {
18241824
char *cursor = NULL;
1825+
char* scanEnd = NULL;
18251826
U_32 cacheSize = 0;
1827+
18261828
GET_OPTION_OPTION(argIndex, ':', ':', &cursor);
1829+
scanEnd = cursor + strlen(cursor);
18271830

1828-
if (try_scan(&cursor, "t1=") && (0 == omr_scan_u32(&cursor, &cacheSize))) {
1829-
vm->continuationT1Size = cacheSize;
1831+
while (cursor < scanEnd) {
1832+
if (try_scan(&cursor, "t1=") && (0 == omr_scan_u32(&cursor, &cacheSize))) {
1833+
vm->continuationT1Size = cacheSize;
18301834

1831-
if (try_scan(&cursor, ",t2=") && (0 == omr_scan_u32(&cursor, &cacheSize))){
1832-
vm->continuationT2Size = cacheSize;
1835+
if (try_scan(&cursor, ",t2=") && (0 == omr_scan_u32(&cursor, &cacheSize))){
1836+
vm->continuationT2Size = cacheSize;
1837+
rc = 0;
1838+
}
1839+
} else if (try_scan(&cursor, "printSummary")) {
1840+
/* Set VM flag. */
1841+
vm->extendedRuntimeFlags2 |= J9_EXTENDED_RUNTIME2_ENABLE_CONTINUATION_CACHE_SUMMARY;
18331842
rc = 0;
1843+
} else {
1844+
rc = -1;
1845+
break;
1846+
}
1847+
1848+
/* Skip ',' delimiter. */
1849+
if (',' == *cursor) {
1850+
cursor++;
18341851
}
18351852
}
1836-
} else {
1853+
}
1854+
/* Set default cache size. */
1855+
if (0 == vm->continuationT1Size) {
18371856
PORT_ACCESS_FROM_JAVAVM(vm);
18381857
vm->continuationT1Size = 1;
18391858
vm->continuationT2Size = (U_32)(j9sysinfo_get_number_CPUs_by_type(J9PORT_CPU_TARGET) * 2);
@@ -6530,22 +6549,32 @@ runExitStages(J9JavaVM* vm, J9VMThread* vmThread)
65306549
}
65316550
}
65326551
#endif
6533-
6534-
#if defined(J9VM_PROF_CONTINUATION_ALLOCATION)
6535-
if (0 < (vm->t1CacheHit + vm->t2CacheHit + vm->fastAlloc + vm->slowAlloc)) {
6552+
#if JAVA_SPEC_VERSION >= 19
6553+
if (J9_ARE_ANY_BITS_SET(vm->extendedRuntimeFlags2, J9_EXTENDED_RUNTIME2_ENABLE_CONTINUATION_CACHE_SUMMARY)
6554+
&& (0 < (vm->t1CacheHit + vm->t2CacheHit + vm->cacheMiss))
6555+
) {
65366556
PORT_ACCESS_FROM_JAVAVM(vm);
6537-
j9tty_printf(PORTLIB, "\nTotal Continuation entries: %u\n", vm->t1CacheHit + vm->t2CacheHit + vm->fastAlloc + vm->slowAlloc);
6557+
j9tty_printf(PORTLIB, "\nContinuation Cache Summary:");
6558+
j9tty_printf(PORTLIB, "\n T1 size: %u T2 size: %u\n", vm->continuationT1Size, vm->continuationT2Size);
6559+
j9tty_printf(PORTLIB, "\nTotal Continuation entries: %u\n", vm->t1CacheHit + vm->t2CacheHit + vm->cacheMiss);
65386560
j9tty_printf(PORTLIB, "\nCache Hits: %u", vm->t1CacheHit + vm->t2CacheHit);
65396561
j9tty_printf(PORTLIB, "\n T1 Cache Hits: %u", vm->t1CacheHit);
65406562
j9tty_printf(PORTLIB, "\n T2 Cache Hits: %u", vm->t2CacheHit);
6541-
j9tty_printf(PORTLIB, "\nCache Miss: %u", vm->fastAlloc + vm->slowAlloc);
6563+
j9tty_printf(PORTLIB, "\nCache Miss: %u", vm->cacheMiss);
6564+
#if defined(J9VM_PROF_CONTINUATION_ALLOCATION)
65426565
j9tty_printf(PORTLIB, "\n Fast Alloc (<10000ns): %u", vm->fastAlloc);
6543-
j9tty_printf(PORTLIB, "\n Avg Fast Alloc Time: %lldns", (vm->fastAlloc > 0 ? (vm->fastAllocAvgTime / (I_64)vm->fastAlloc) : 0));
6566+
j9tty_printf(PORTLIB, "\n Avg Fast Alloc Time: %lld ns", (vm->fastAlloc > 0 ? (vm->fastAllocAvgTime / (I_64)vm->fastAlloc) : 0));
65446567
j9tty_printf(PORTLIB, "\n Slow Alloc (>10000ns): %u", vm->slowAlloc);
6545-
j9tty_printf(PORTLIB, "\n Avg Slow Alloc Time: %lldns", (vm->slowAlloc > 0 ? (vm->slowAllocAvgTime / (I_64)vm->slowAlloc) : 0));
6546-
j9tty_printf(PORTLIB, "\nAvg Cache Lookup Time: %lldns\n", (vm->avgCacheLookupTime / (I_64)(vm->t1CacheHit + vm->t2CacheHit + vm->fastAlloc + vm->slowAlloc)));
6547-
}
6568+
j9tty_printf(PORTLIB, "\n Avg Slow Alloc Time: %lld ns", (vm->slowAlloc > 0 ? (vm->slowAllocAvgTime / (I_64)vm->slowAlloc) : 0));
6569+
j9tty_printf(PORTLIB, "\nAvg Cache Lookup Time: %lld ns", (vm->avgCacheLookupTime / (I_64)(vm->t1CacheHit + vm->t2CacheHit + vm->fastAlloc + vm->slowAlloc)));
65486570
#endif /* defined(J9VM_PROF_CONTINUATION_ALLOCATION) */
6571+
j9tty_printf(PORTLIB, "\n\nCache store: %u", vm->t1CacheHit + vm->t2CacheHit + vm->cacheMiss - vm->cacheFree);
6572+
j9tty_printf(PORTLIB, "\n T1 Cache store: %u", vm->t1CacheHit + vm->t2CacheHit + vm->cacheMiss - vm->cacheFree - vm->t2store);
6573+
j9tty_printf(PORTLIB, "\n T2 Cache store: %u", vm->t2store);
6574+
j9tty_printf(PORTLIB, "\nCache Freed: %u\n", vm->cacheFree);
6575+
j9tty_printf(PORTLIB, "\nAvg Cache Stack Size: %.2f KB\n", (double)vm->totalContinuationStackSize / (vm->t1CacheHit + vm->t2CacheHit + vm->cacheMiss) / 1024);
6576+
}
6577+
#endif /* JAVA_SPEC_VERSION >= 19 */
65496578

65506579
/* Unload before trace engine exits */
65516580
UT_MODULE_UNLOADED(J9_UTINTERFACE_FROM_VM(vm));

0 commit comments

Comments
 (0)