Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions runtime/codert_vm/jswalk.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ UDATA jitWalkStackFrames(J9StackWalkState *walkState)
walkState->dropToCurrentFrame = jitDropToCurrentFrame;

while ((walkState->jitInfo = jitGetExceptionTable(walkState)) != NULL) {
#if defined(J9MAPCACHE_DEBUG)
memset(&walkState->romMethodInfo, 0, sizeof(walkState->romMethodInfo));
#endif /* J9MAPCACHE_DEBUG */
walkState->stackMap = NULL;
walkState->inlineMap = NULL;
walkState->bp = walkState->unwindSP + getJitTotalFrameSize(walkState->jitInfo);
Expand Down Expand Up @@ -212,6 +215,8 @@ UDATA jitWalkStackFrames(J9StackWalkState *walkState)
lswRecord(walkState, LSW_TYPE_METHOD, walkState->method);
lswRecord(walkState, LSW_TYPE_JIT_FRAME_INFO, walkState);
#endif
initializeBasicROMMethodInfo(walkState, J9_ROM_METHOD_FROM_RAM_METHOD(walkState->method));

if ((rc = walkFrame(walkState)) != J9_STACKWALK_KEEP_ITERATING) {
return rc;
}
Expand Down Expand Up @@ -250,6 +255,7 @@ UDATA jitWalkStackFrames(J9StackWalkState *walkState)
#ifdef J9VM_INTERP_LINEAR_STACKWALK_TRACING
lswRecord(walkState, LSW_TYPE_JIT_FRAME_INFO, walkState);
#endif
initializeBasicROMMethodInfo(walkState, J9_ROM_METHOD_FROM_RAM_METHOD(walkState->method));
if ((rc = walkFrame(walkState)) != J9_STACKWALK_KEEP_ITERATING) {
return rc;
}
Expand Down Expand Up @@ -1977,6 +1983,9 @@ jitWalkOSRFrame(J9StackWalkState *walkState, J9OSRFrame *osrFrame)
UDATA *localSlots = ((UDATA*)(osrFrame + 1)) + maxStack;
UDATA *nextFrame = localSlots + numberOfLocals;
J9MonitorEnterRecord *enterRecord = osrFrame->monitorEnterRecords;
J9ROMMethod *romMethod = J9_ROM_METHOD_FROM_RAM_METHOD(method);

initializeBasicROMMethodInfo(walkState, romMethod);

#ifdef J9VM_INTERP_STACKWALK_TRACING
{
Expand All @@ -1987,6 +1996,7 @@ jitWalkOSRFrame(J9StackWalkState *walkState, J9OSRFrame *osrFrame)
walkState->method = stateMethod;
}
#endif

walkBytecodeFrameSlots(walkState, method, offsetPC,
localSlots - 1, pendingStackHeight,
nextFrame - 1, numberOfLocals, TRUE);
Expand Down
5 changes: 3 additions & 2 deletions runtime/oti/j9modifiers_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,9 @@
/* Composite Flag checks */

#define J9ROMCLASS_IS_PRIMITIVE_OR_ARRAY(romClass) _J9ROMCLASS_SUNMODIFIER_IS_ANY_SET((romClass), J9AccClassArray | J9AccClassInternalPrimitiveType)
#define J9ROMMETHOD_IS_NON_EMPTY_OBJECT_CONSTRUCTOR(romMethod) \
((((romMethod)->modifiers) & (J9AccMethodObjectConstructor | J9AccEmptyMethod)) == J9AccMethodObjectConstructor)
#define J9ROMMETHOD_MODIFIERS_IS_NON_EMPTY_OBJECT_CONSTRUCTOR(modifiers) \
(((modifiers) & (J9AccMethodObjectConstructor | J9AccEmptyMethod)) == J9AccMethodObjectConstructor)
#define J9ROMMETHOD_IS_NON_EMPTY_OBJECT_CONSTRUCTOR(romMethod) J9ROMMETHOD_MODIFIERS_IS_NON_EMPTY_OBJECT_CONSTRUCTOR((romMethod)->modifiers)

/* Class instances are allocated via the new bytecode */
#define J9ROMCLASS_ALLOCATES_VIA_NEW(romClass) \
Expand Down
35 changes: 27 additions & 8 deletions runtime/oti/j9nonbuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -1147,12 +1147,32 @@ typedef struct J9CudaGlobals {
jmethodID runnable_run;
} J9CudaGlobals;

#define J9_MAP_CACHE_SLOTS 2

typedef struct J9MapCacheEntry {
/* Cache slot sizes must all be multiples of 2 */
#define J9_STACKMAP_CACHE_SLOTS 2
#define J9_LOCALMAP_CACHE_SLOTS 2
#define J9_ARGBITS_CACHE_SLOTS 2

/* Flag values for J9ROMMethodInfo */
#define J9MAPCACHE_STACKMAP_CACHED 1
#define J9MAPCACHE_LOCALMAP_CACHED 2
#define J9MAPCACHE_ARGBITS_CACHED 4
#define J9MAPCACHE_METHOD_IS_CONSTRUCTOR 8
#define J9MAPCACHE_VALID 128

/* J9ROMMethodInfo must be a multiple of 8 bytes in size */
typedef struct J9ROMMethodInfo {
void *key;
U_32 bits[J9_MAP_CACHE_SLOTS];
} J9MapCacheEntry;
U_32 stackmap[J9_STACKMAP_CACHE_SLOTS];
U_32 localmap[J9_ARGBITS_CACHE_SLOTS];
U_32 argbits[J9_ARGBITS_CACHE_SLOTS];
U_32 modifiers;
U_16 tempCount;
U_8 argCount;
U_8 flags;
#if !defined(J9VM_ENV_DATA64)
U_32 padTo64;
#endif /* !defined(J9VM_ENV_DATA64) */
} J9ROMMethodInfo;

#if defined(J9VM_OPT_SHARED_CLASSES)

Expand Down Expand Up @@ -2808,6 +2828,7 @@ typedef struct J9StackWalkState {
void* stackMap;
void* inlineMap;
UDATA loopBreaker;
J9ROMMethodInfo romMethodInfo; /* 64-bit aligned */
/* The size of J9StackWalkState must be a multiple of 8 because it is inlined into
* J9VMThread where alignment assumotions are being made.
*/
Expand Down Expand Up @@ -3740,9 +3761,7 @@ typedef struct J9ClassLoader {
UDATA initClassPathEntryCount;
UDATA asyncGetCallTraceUsed;
omrthread_monitor_t mapCacheMutex;
struct J9HashTable* localmapCache;
struct J9HashTable* argsbitsCache;
struct J9HashTable* stackmapCache;
struct J9HashTable* romMethodInfoCache;
#if defined(J9VM_OPT_JFR)
J9HashTable *typeIDs;
#endif /* defined(J9VM_OPT_JFR) */
Expand Down
29 changes: 7 additions & 22 deletions runtime/oti/stackmap_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,30 +196,15 @@ j9stackmap_StackBitsForPC(J9PortLibrary * portLib, UDATA pc, J9ROMClass * romCla
UDATA * (* getBuffer) (void * userData),
void (* releaseBuffer) (void * userData));

/* ---------------- mapcache.cpp ---------------- */

/* ------------------- mapcache.cpp ----------------- */

/* These are cache wrapper functions with the same parameters as the j9localmap_ versions,
* with VM and J9ClassLoader added on the end.
*/

IDATA
j9cached_StackBitsForPC(UDATA pc, J9ROMClass * romClass, J9ROMMethod * romMethod,
U_32 * resultArrayBase, UDATA resultArraySize,
void * userData,
UDATA * (* getBuffer) (void * userData),
void (* releaseBuffer) (void * userData),
J9JavaVM *vm, J9ClassLoader *classLoader);

/**
* @brief
* @param walkState
* @param romMethod
*/
void
j9cached_ArgBitsForPC0(J9ROMClass *romClass, J9ROMMethod *romMethod, U_32 *resultArrayBase, J9JavaVM *vm, J9ClassLoader *classLoader);

IDATA
j9cached_LocalBitsForPC(J9ROMClass * romClass, J9ROMMethod * romMethod, UDATA pc, U_32 * resultArrayBase,
void * userData,
UDATA * (* getBuffer) (void * userData),
void (* releaseBuffer) (void * userData),
J9JavaVM *vm, J9ClassLoader * classLoader);
initializeBasicROMMethodInfo(J9StackWalkState *walkState, J9ROMMethod *romMethod);

#ifdef __cplusplus
}
Expand Down
61 changes: 59 additions & 2 deletions runtime/stackmap/mapcache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,60 @@

extern "C" {

void
initializeBasicROMMethodInfo(J9StackWalkState *walkState, J9ROMMethod *romMethod)
{
J9ROMMethodInfo *romMethodInfo = &walkState->romMethodInfo;
memset(romMethodInfo, 0, sizeof(*romMethodInfo));
romMethodInfo->argCount = romMethod->argCount;
romMethodInfo->tempCount = romMethod->tempCount;
romMethodInfo->modifiers = romMethod->modifiers;
#if defined(J9MAPCACHE_DEBUG)
romMethodInfo->flags = J9MAPCACHE_VALID;
#endif /* J9MAPCACHE_DEBUG */
if (!(romMethod->modifiers & J9AccStatic)) {
if (J9UTF8_DATA(J9ROMMETHOD_NAME(romMethod))[0] == '<') {
romMethodInfo->flags |= J9MAPCACHE_METHOD_IS_CONSTRUCTOR;
}
}
}

void
populateROMMethodInfo(J9StackWalkState *walkState, J9ROMMethod *romMethod, void *key)
{
initializeBasicROMMethodInfo(walkState, romMethod);
#if 0
bool found = false;
J9Method *method = walkState->method;
J9ClassLoader *classLoader = J9_CLASS_FROM_METHOD(method)->classLoader;
omrthread_monitor_t mapCacheMutex = classLoader->mapCacheMutex;

/* If the mapCacheMutex exists, the caching feature is enabled */
if (NULL != mapCacheMutex) {
omrthread_monitor_enter(mapCacheMutex);
J9HashTable *mapCache = classLoader->romMethodInfoCache;

/* If the cache exists, check it for this key */
if (NULL != mapCache) {
J9ROMMethodInfo exemplar = { 0 };
exemplar.key = key;
J9ROMMethodInfo *entry = (J9ROMMethodInfo*)hashTableFind(mapCache, &exemplar);

if (NULL != entry) {
/* Cache hit - copy the info */
*romMethodInfo = *entry;
} else {
/* Cache miss - populate the info and cache it */
}
}

omrthread_monitor_exit(mapCacheMutex);
}
#endif
}

#if 0

/**
* @brief Map cache hash function
* @param key J9MapCacheEntry pointer
Expand Down Expand Up @@ -83,7 +137,7 @@ checkCache(J9JavaVM *vm, J9ClassLoader *classLoader, void *key, J9HashTable *map
J9MapCacheEntry *entry = (J9MapCacheEntry*)hashTableFind(mapCache, &exemplar);

if (NULL != entry) {
memcpy(resultArrayBase, entry->bits, sizeof(U_32) * mapWords);
memcpy(resultArrayBase, &entry->data.bits, sizeof(U_32) * mapWords);
found = true;
}
}
Expand Down Expand Up @@ -135,7 +189,7 @@ updateCache(J9JavaVM *vm, J9ClassLoader *classLoader, void *key, J9HashTable **c
if (NULL != mapCache) {
J9MapCacheEntry entry = { 0 };
entry.key = key;
memcpy(entry.bits, resultArrayBase, sizeof(U_32) * mapWords);
memcpy(&entry.data.bits, resultArrayBase, sizeof(U_32) * mapWords);
hashTableAdd(mapCache, &entry);
}

Expand Down Expand Up @@ -201,4 +255,7 @@ j9cached_LocalBitsForPC(J9ROMClass * romClass, J9ROMMethod * romMethod, UDATA pc
return rc;
}

#endif


} /* extern "C" */
14 changes: 3 additions & 11 deletions runtime/vm/classallocation.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,9 @@ U_32 classPropagationTable[CLASS_PROPAGATION_TABLE_SIZE] = {
void
freeMapCaches(J9ClassLoader *classLoader)
{
if (NULL != classLoader->localmapCache) {
hashTableFree(classLoader->localmapCache);
classLoader->localmapCache = NULL;
}
if (NULL != classLoader->argsbitsCache) {
hashTableFree(classLoader->argsbitsCache);
classLoader->argsbitsCache = NULL;
}
if (NULL != classLoader->stackmapCache) {
hashTableFree(classLoader->stackmapCache);
classLoader->stackmapCache = NULL;
if (NULL != classLoader->romMethodInfoCache) {
hashTableFree(classLoader->romMethodInfoCache);
classLoader->romMethodInfoCache = NULL;
}
}

Expand Down
Loading