Skip to content

Commit 19d1ee8

Browse files
committed
Part 1 of stack walker ROM method cache
Signed-off-by: Graham Chapman <[email protected]>
1 parent 42fa4e3 commit 19d1ee8

File tree

7 files changed

+231
-108
lines changed

7 files changed

+231
-108
lines changed

runtime/codert_vm/jswalk.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ UDATA jitWalkStackFrames(J9StackWalkState *walkState)
172172
walkState->dropToCurrentFrame = jitDropToCurrentFrame;
173173

174174
while ((walkState->jitInfo = jitGetExceptionTable(walkState)) != NULL) {
175+
#if defined(J9MAPCACHE_DEBUG)
176+
memset(&walkState->romMethodInfo, 0, sizeof(walkState->romMethodInfo));
177+
#endif /* J9MAPCACHE_DEBUG */
175178
walkState->stackMap = NULL;
176179
walkState->inlineMap = NULL;
177180
walkState->bp = walkState->unwindSP + getJitTotalFrameSize(walkState->jitInfo);
@@ -212,6 +215,8 @@ UDATA jitWalkStackFrames(J9StackWalkState *walkState)
212215
lswRecord(walkState, LSW_TYPE_METHOD, walkState->method);
213216
lswRecord(walkState, LSW_TYPE_JIT_FRAME_INFO, walkState);
214217
#endif
218+
initializeBasicROMMethodInfo(walkState, J9_ROM_METHOD_FROM_RAM_METHOD(walkState->method));
219+
215220
if ((rc = walkFrame(walkState)) != J9_STACKWALK_KEEP_ITERATING) {
216221
return rc;
217222
}
@@ -250,6 +255,7 @@ UDATA jitWalkStackFrames(J9StackWalkState *walkState)
250255
#ifdef J9VM_INTERP_LINEAR_STACKWALK_TRACING
251256
lswRecord(walkState, LSW_TYPE_JIT_FRAME_INFO, walkState);
252257
#endif
258+
initializeBasicROMMethodInfo(walkState, J9_ROM_METHOD_FROM_RAM_METHOD(walkState->method));
253259
if ((rc = walkFrame(walkState)) != J9_STACKWALK_KEEP_ITERATING) {
254260
return rc;
255261
}
@@ -1977,6 +1983,9 @@ jitWalkOSRFrame(J9StackWalkState *walkState, J9OSRFrame *osrFrame)
19771983
UDATA *localSlots = ((UDATA*)(osrFrame + 1)) + maxStack;
19781984
UDATA *nextFrame = localSlots + numberOfLocals;
19791985
J9MonitorEnterRecord *enterRecord = osrFrame->monitorEnterRecords;
1986+
J9ROMMethod *romMethod = J9_ROM_METHOD_FROM_RAM_METHOD(method);
1987+
1988+
initializeBasicROMMethodInfo(walkState, romMethod);
19801989

19811990
#ifdef J9VM_INTERP_STACKWALK_TRACING
19821991
{
@@ -1987,6 +1996,7 @@ jitWalkOSRFrame(J9StackWalkState *walkState, J9OSRFrame *osrFrame)
19871996
walkState->method = stateMethod;
19881997
}
19891998
#endif
1999+
19902000
walkBytecodeFrameSlots(walkState, method, offsetPC,
19912001
localSlots - 1, pendingStackHeight,
19922002
nextFrame - 1, numberOfLocals, TRUE);

runtime/oti/j9modifiers_api.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,9 @@
116116
/* Composite Flag checks */
117117

118118
#define J9ROMCLASS_IS_PRIMITIVE_OR_ARRAY(romClass) _J9ROMCLASS_SUNMODIFIER_IS_ANY_SET((romClass), J9AccClassArray | J9AccClassInternalPrimitiveType)
119-
#define J9ROMMETHOD_IS_NON_EMPTY_OBJECT_CONSTRUCTOR(romMethod) \
120-
((((romMethod)->modifiers) & (J9AccMethodObjectConstructor | J9AccEmptyMethod)) == J9AccMethodObjectConstructor)
119+
#define J9ROMMETHOD_MODIFIERS_IS_NON_EMPTY_OBJECT_CONSTRUCTOR(modifiers) \
120+
(((modifiers) & (J9AccMethodObjectConstructor | J9AccEmptyMethod)) == J9AccMethodObjectConstructor)
121+
#define J9ROMMETHOD_IS_NON_EMPTY_OBJECT_CONSTRUCTOR(romMethod) J9ROMMETHOD_MODIFIERS_IS_NON_EMPTY_OBJECT_CONSTRUCTOR((romMethod)->modifiers)
121122

122123
/* Class instances are allocated via the new bytecode */
123124
#define J9ROMCLASS_ALLOCATES_VIA_NEW(romClass) \

runtime/oti/j9nonbuilder.h

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,12 +1147,32 @@ typedef struct J9CudaGlobals {
11471147
jmethodID runnable_run;
11481148
} J9CudaGlobals;
11491149

1150-
#define J9_MAP_CACHE_SLOTS 2
1151-
1152-
typedef struct J9MapCacheEntry {
1150+
/* Cache slot sizes must all be multiples of 2 */
1151+
#define J9_STACKMAP_CACHE_SLOTS 2
1152+
#define J9_LOCALMAP_CACHE_SLOTS 2
1153+
#define J9_ARGBITS_CACHE_SLOTS 2
1154+
1155+
/* Flag values for J9ROMMethodInfo */
1156+
#define J9MAPCACHE_STACKMAP_CACHED 1
1157+
#define J9MAPCACHE_LOCALMAP_CACHED 2
1158+
#define J9MAPCACHE_ARGBITS_CACHED 4
1159+
#define J9MAPCACHE_METHOD_IS_CONSTRUCTOR 8
1160+
#define J9MAPCACHE_VALID 128
1161+
1162+
/* J9ROMMethodInfo must be a multiple of 8 bytes in size */
1163+
typedef struct J9ROMMethodInfo {
11531164
void *key;
1154-
U_32 bits[J9_MAP_CACHE_SLOTS];
1155-
} J9MapCacheEntry;
1165+
U_32 stackmap[J9_STACKMAP_CACHE_SLOTS];
1166+
U_32 localmap[J9_ARGBITS_CACHE_SLOTS];
1167+
U_32 argbits[J9_ARGBITS_CACHE_SLOTS];
1168+
U_32 modifiers;
1169+
U_16 tempCount;
1170+
U_8 argCount;
1171+
U_8 flags;
1172+
#if !defined(J9VM_ENV_DATA64)
1173+
U_32 padTo64;
1174+
#endif /* !defined(J9VM_ENV_DATA64) */
1175+
} J9ROMMethodInfo;
11561176

11571177
#if defined(J9VM_OPT_SHARED_CLASSES)
11581178

@@ -2808,6 +2828,7 @@ typedef struct J9StackWalkState {
28082828
void* stackMap;
28092829
void* inlineMap;
28102830
UDATA loopBreaker;
2831+
J9ROMMethodInfo romMethodInfo; /* 64-bit aligned */
28112832
/* The size of J9StackWalkState must be a multiple of 8 because it is inlined into
28122833
* J9VMThread where alignment assumotions are being made.
28132834
*/
@@ -3740,9 +3761,7 @@ typedef struct J9ClassLoader {
37403761
UDATA initClassPathEntryCount;
37413762
UDATA asyncGetCallTraceUsed;
37423763
omrthread_monitor_t mapCacheMutex;
3743-
struct J9HashTable* localmapCache;
3744-
struct J9HashTable* argsbitsCache;
3745-
struct J9HashTable* stackmapCache;
3764+
struct J9HashTable* romMethodInfoCache;
37463765
#if defined(J9VM_OPT_JFR)
37473766
J9HashTable *typeIDs;
37483767
#endif /* defined(J9VM_OPT_JFR) */

runtime/oti/stackmap_api.h

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -196,30 +196,15 @@ j9stackmap_StackBitsForPC(J9PortLibrary * portLib, UDATA pc, J9ROMClass * romCla
196196
UDATA * (* getBuffer) (void * userData),
197197
void (* releaseBuffer) (void * userData));
198198

199+
/* ---------------- mapcache.cpp ---------------- */
199200

200-
/* ------------------- mapcache.cpp ----------------- */
201-
202-
/* These are cache wrapper functions with the same parameters as the j9localmap_ versions,
203-
* with VM and J9ClassLoader added on the end.
204-
*/
205-
206-
IDATA
207-
j9cached_StackBitsForPC(UDATA pc, J9ROMClass * romClass, J9ROMMethod * romMethod,
208-
U_32 * resultArrayBase, UDATA resultArraySize,
209-
void * userData,
210-
UDATA * (* getBuffer) (void * userData),
211-
void (* releaseBuffer) (void * userData),
212-
J9JavaVM *vm, J9ClassLoader *classLoader);
213-
201+
/**
202+
* @brief
203+
* @param walkState
204+
* @param romMethod
205+
*/
214206
void
215-
j9cached_ArgBitsForPC0(J9ROMClass *romClass, J9ROMMethod *romMethod, U_32 *resultArrayBase, J9JavaVM *vm, J9ClassLoader *classLoader);
216-
217-
IDATA
218-
j9cached_LocalBitsForPC(J9ROMClass * romClass, J9ROMMethod * romMethod, UDATA pc, U_32 * resultArrayBase,
219-
void * userData,
220-
UDATA * (* getBuffer) (void * userData),
221-
void (* releaseBuffer) (void * userData),
222-
J9JavaVM *vm, J9ClassLoader * classLoader);
207+
initializeBasicROMMethodInfo(J9StackWalkState *walkState, J9ROMMethod *romMethod);
223208

224209
#ifdef __cplusplus
225210
}

runtime/stackmap/mapcache.cpp

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,60 @@
2525

2626
extern "C" {
2727

28+
void
29+
initializeBasicROMMethodInfo(J9StackWalkState *walkState, J9ROMMethod *romMethod)
30+
{
31+
J9ROMMethodInfo *romMethodInfo = &walkState->romMethodInfo;
32+
memset(romMethodInfo, 0, sizeof(*romMethodInfo));
33+
romMethodInfo->argCount = romMethod->argCount;
34+
romMethodInfo->tempCount = romMethod->tempCount;
35+
romMethodInfo->modifiers = romMethod->modifiers;
36+
#if defined(J9MAPCACHE_DEBUG)
37+
romMethodInfo->flags = J9MAPCACHE_VALID;
38+
#endif /* J9MAPCACHE_DEBUG */
39+
if (!(romMethod->modifiers & J9AccStatic)) {
40+
if (J9UTF8_DATA(J9ROMMETHOD_NAME(romMethod))[0] == '<') {
41+
romMethodInfo->flags |= J9MAPCACHE_METHOD_IS_CONSTRUCTOR;
42+
}
43+
}
44+
}
45+
46+
void
47+
populateROMMethodInfo(J9StackWalkState *walkState, J9ROMMethod *romMethod, void *key)
48+
{
49+
initializeBasicROMMethodInfo(walkState, romMethod);
50+
#if 0
51+
bool found = false;
52+
J9Method *method = walkState->method;
53+
J9ClassLoader *classLoader = J9_CLASS_FROM_METHOD(method)->classLoader;
54+
omrthread_monitor_t mapCacheMutex = classLoader->mapCacheMutex;
55+
56+
/* If the mapCacheMutex exists, the caching feature is enabled */
57+
if (NULL != mapCacheMutex) {
58+
omrthread_monitor_enter(mapCacheMutex);
59+
J9HashTable *mapCache = classLoader->romMethodInfoCache;
60+
61+
/* If the cache exists, check it for this key */
62+
if (NULL != mapCache) {
63+
J9ROMMethodInfo exemplar = { 0 };
64+
exemplar.key = key;
65+
J9ROMMethodInfo *entry = (J9ROMMethodInfo*)hashTableFind(mapCache, &exemplar);
66+
67+
if (NULL != entry) {
68+
/* Cache hit - copy the info */
69+
*romMethodInfo = *entry;
70+
} else {
71+
/* Cache miss - populate the info and cache it */
72+
}
73+
}
74+
75+
omrthread_monitor_exit(mapCacheMutex);
76+
}
77+
#endif
78+
}
79+
80+
#if 0
81+
2882
/**
2983
* @brief Map cache hash function
3084
* @param key J9MapCacheEntry pointer
@@ -83,7 +137,7 @@ checkCache(J9JavaVM *vm, J9ClassLoader *classLoader, void *key, J9HashTable *map
83137
J9MapCacheEntry *entry = (J9MapCacheEntry*)hashTableFind(mapCache, &exemplar);
84138

85139
if (NULL != entry) {
86-
memcpy(resultArrayBase, entry->bits, sizeof(U_32) * mapWords);
140+
memcpy(resultArrayBase, &entry->data.bits, sizeof(U_32) * mapWords);
87141
found = true;
88142
}
89143
}
@@ -135,7 +189,7 @@ updateCache(J9JavaVM *vm, J9ClassLoader *classLoader, void *key, J9HashTable **c
135189
if (NULL != mapCache) {
136190
J9MapCacheEntry entry = { 0 };
137191
entry.key = key;
138-
memcpy(entry.bits, resultArrayBase, sizeof(U_32) * mapWords);
192+
memcpy(&entry.data.bits, resultArrayBase, sizeof(U_32) * mapWords);
139193
hashTableAdd(mapCache, &entry);
140194
}
141195

@@ -201,4 +255,7 @@ j9cached_LocalBitsForPC(J9ROMClass * romClass, J9ROMMethod * romMethod, UDATA pc
201255
return rc;
202256
}
203257

258+
#endif
259+
260+
204261
} /* extern "C" */

runtime/vm/classallocation.c

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,9 @@ U_32 classPropagationTable[CLASS_PROPAGATION_TABLE_SIZE] = {
6767
void
6868
freeMapCaches(J9ClassLoader *classLoader)
6969
{
70-
if (NULL != classLoader->localmapCache) {
71-
hashTableFree(classLoader->localmapCache);
72-
classLoader->localmapCache = NULL;
73-
}
74-
if (NULL != classLoader->argsbitsCache) {
75-
hashTableFree(classLoader->argsbitsCache);
76-
classLoader->argsbitsCache = NULL;
77-
}
78-
if (NULL != classLoader->stackmapCache) {
79-
hashTableFree(classLoader->stackmapCache);
80-
classLoader->stackmapCache = NULL;
70+
if (NULL != classLoader->romMethodInfoCache) {
71+
hashTableFree(classLoader->romMethodInfoCache);
72+
classLoader->romMethodInfoCache = NULL;
8173
}
8274
}
8375

0 commit comments

Comments
 (0)