Skip to content

Commit 495e826

Browse files
Harshitha PopuriHarshitha Popuri
authored andcommitted
fixup
1 parent 654c865 commit 495e826

File tree

2 files changed

+13
-221
lines changed

2 files changed

+13
-221
lines changed

runtime/stackmap/mapcache.cpp

Lines changed: 7 additions & 219 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ populateROMMethodInfo(J9StackWalkState *walkState, J9ROMMethod *romMethod, void
132132
/* Always compute argument bits */
133133
j9localmap_ArgBitsForPC0(romClass, romMethod, newInfo.argbits);
134134

135-
if (computeStackAndLocals && pc < (UDATA)J9_BYTECODE_SIZE_FROM_ROM_METHOD(romMethod)) {
135+
if (computeStackAndLocals) {
136136
/* Compute stack map for this PC */
137137
j9stackmap_StackBitsForPC(
138138
vm->portLibrary,
@@ -172,7 +172,6 @@ populateROMMethodInfo(J9StackWalkState *walkState, J9ROMMethod *romMethod, void
172172
void
173173
getROMMethodInfoForROMMethod(J9StackWalkState *walkState, J9ROMMethod *romMethod)
174174
{
175-
initializeBasicROMMethodInfo(walkState, romMethod);
176175
J9Method *method = walkState->method;
177176
J9ClassLoader *classLoader = J9_CLASS_FROM_METHOD(method)->classLoader;
178177

@@ -181,9 +180,11 @@ getROMMethodInfoForROMMethod(J9StackWalkState *walkState, J9ROMMethod *romMethod
181180

182181
/* Check cache first */
183182
if (!checkROMMethodInfoCache(classLoader, key, &tmp)) {
184-
/* Cache miss or not populated: populate argbits only */
183+
/* Cache miss or not populated */
184+
initializeBasicROMMethodInfo(walkState, romMethod);
185185
populateROMMethodInfo(walkState, romMethod, key, 0, false);
186186
} else {
187+
/* Cache hit */
187188
walkState->romMethodInfo = tmp;
188189
}
189190
}
@@ -192,7 +193,6 @@ getROMMethodInfoForROMMethod(J9StackWalkState *walkState, J9ROMMethod *romMethod
192193
void
193194
getROMMethodInfoForBytecodePC(J9StackWalkState *walkState, J9ROMMethod *romMethod, UDATA pc)
194195
{
195-
initializeBasicROMMethodInfo(walkState, romMethod);
196196
if (pc <= J9SF_MAX_SPECIAL_FRAME_TYPE || pc >= (UDATA)J9_BYTECODE_SIZE_FROM_ROM_METHOD(romMethod)) {
197197
return;
198198
}
@@ -205,226 +205,14 @@ getROMMethodInfoForBytecodePC(J9StackWalkState *walkState, J9ROMMethod *romMetho
205205

206206
/* Check cache first */
207207
if (!checkROMMethodInfoCache(classLoader, key, &tmp)) {
208-
/* Cache miss or not populated: compute stack/local maps */
208+
/* Cache miss or not populated */
209+
initializeBasicROMMethodInfo(walkState, romMethod);
209210
populateROMMethodInfo(walkState, romMethod, key, pc, true);
210211
} else {
212+
/* Cache hit */
211213
walkState->romMethodInfo = tmp;
212214
}
213215
}
214216

215-
#if 0
216-
217-
void
218-
populateROMMethodInfo(J9StackWalkState *walkState, J9ROMMethod *romMethod, void *key)
219-
{
220-
initializeBasicROMMethodInfo(walkState, romMethod);
221-
222-
bool found = false;
223-
J9Method *method = walkState->method;
224-
J9ClassLoader *classLoader = J9_CLASS_FROM_METHOD(method)->classLoader;
225-
omrthread_monitor_t mapCacheMutex = classLoader->mapCacheMutex;
226-
227-
/* If the mapCacheMutex exists, the caching feature is enabled */
228-
if (NULL != mapCacheMutex) {
229-
omrthread_monitor_enter(mapCacheMutex);
230-
J9HashTable *mapCache = classLoader->romMethodInfoCache;
231-
232-
/* If the cache exists, check it for this key */
233-
if (NULL != mapCache) {
234-
J9ROMMethodInfo exemplar = { 0 };
235-
exemplar.key = key;
236-
J9ROMMethodInfo *entry = (J9ROMMethodInfo*)hashTableFind(mapCache, &exemplar);
237-
238-
if (NULL != entry) {
239-
/* Cache hit - copy the info */
240-
*romMethodInfo = *entry;
241-
} else {
242-
/* Cache miss - populate the info and cache it */
243-
}
244-
}
245-
246-
omrthread_monitor_exit(mapCacheMutex);
247-
}
248-
}
249-
250-
251-
/**
252-
* @brief Map cache hash function
253-
* @param key J9MapCacheEntry pointer
254-
* @param userData not used
255-
* @return hash value
256-
*/
257-
static UDATA
258-
localMapHashFn(void *key, void *userData)
259-
{
260-
J9MapCacheEntry *entry = (J9MapCacheEntry*)key;
261-
262-
return (UDATA)entry->key;
263-
}
264-
265-
/**
266-
* @brief Map cache comparator function
267-
* @param leftKey J9MapCacheEntry pointer
268-
* @param rightKey J9MapCacheEntry pointer
269-
* @param userData not used
270-
* @return 0 if comparision fails, non-zero if succeess
271-
*/
272-
static UDATA
273-
localMapHashEqualFn(void *leftKey, void *rightKey, void *userData)
274-
{
275-
J9MapCacheEntry *leftEntry = (J9MapCacheEntry*)leftKey;
276-
J9MapCacheEntry *rightEntry = (J9MapCacheEntry*)rightKey;
277-
278-
return (leftEntry->key == rightEntry->key);
279-
}
280-
281-
/**
282-
* @brief Check the given cache for the key. If found, populate the resultArray.
283-
* @param vm the J9JavaVM
284-
* @param classLoader the J9ClassLoader
285-
* @param key the cache key
286-
* @param mapCache the cache to search
287-
* @param resultArrayBase the result array
288-
* @param mapWords the numhber of U_32 in the result array
289-
* @return true on cache hit, false on miss
290-
*/
291-
static bool
292-
checkCache(J9JavaVM *vm, J9ClassLoader *classLoader, void *key, J9HashTable *mapCache, U_32 *resultArrayBase, UDATA mapWords)
293-
{
294-
bool found = false;
295-
omrthread_monitor_t mapCacheMutex = classLoader->mapCacheMutex;
296-
297-
/* If the mapCacheMutex exists, the caching feature is enabled */
298-
if (NULL != mapCacheMutex) {
299-
if (mapWords <= J9_MAP_CACHE_SLOTS) {
300-
omrthread_monitor_enter(mapCacheMutex);
301-
302-
/* If the cache exists, check it for this key */
303-
if (NULL != mapCache) {
304-
J9MapCacheEntry exemplar = { 0 };
305-
exemplar.key = key;
306-
J9MapCacheEntry *entry = (J9MapCacheEntry*)hashTableFind(mapCache, &exemplar);
307-
308-
if (NULL != entry) {
309-
memcpy(resultArrayBase, &entry->data.bits, sizeof(U_32) * mapWords);
310-
found = true;
311-
}
312-
}
313-
314-
omrthread_monitor_exit(mapCacheMutex);
315-
}
316-
}
317-
318-
return found;
319-
}
320-
321-
/**
322-
* @brief Cache a result in the given cache for the key.
323-
* @param vm the J9JavaVM
324-
* @param classLoader the J9ClassLoader
325-
* @param key the cache key
326-
* @param cacheSlot pointer to the slot holding the cache pointer
327-
* @param resultArrayBase the result array
328-
* @param mapWords the numhber of U_32 in the result array
329-
*/
330-
static void
331-
updateCache(J9JavaVM *vm, J9ClassLoader *classLoader, void *key, J9HashTable **cacheSlot, U_32 *resultArrayBase, UDATA mapWords)
332-
{
333-
omrthread_monitor_t mapCacheMutex = classLoader->mapCacheMutex;
334-
335-
/* If the mapCacheMutex exists, the caching feature is enabled */
336-
if (NULL != mapCacheMutex) {
337-
if (mapWords <= J9_MAP_CACHE_SLOTS) {
338-
omrthread_monitor_enter(mapCacheMutex);
339-
340-
/* Create the cache if necessary - failure is non-fatal */
341-
J9HashTable *mapCache = *cacheSlot;
342-
if (NULL == mapCache) {
343-
mapCache = hashTableNew(OMRPORT_FROM_J9PORT(vm->portLibrary),
344-
J9_GET_CALLSITE(),
345-
0,
346-
sizeof(J9MapCacheEntry),
347-
sizeof(J9MapCacheEntry *),
348-
0,
349-
J9MEM_CATEGORY_VM,
350-
localMapHashFn,
351-
localMapHashEqualFn,
352-
NULL,
353-
NULL);
354-
*cacheSlot = mapCache;
355-
}
356-
357-
/* If the cache exists, attempt to add and entry for this map - failure is non-fatal */
358-
if (NULL != mapCache) {
359-
J9MapCacheEntry entry = { 0 };
360-
entry.key = key;
361-
memcpy(&entry.data.bits, resultArrayBase, sizeof(U_32) * mapWords);
362-
hashTableAdd(mapCache, &entry);
363-
}
364-
365-
omrthread_monitor_exit(mapCacheMutex);
366-
}
367-
}
368-
}
369-
370-
IDATA
371-
j9cached_StackBitsForPC(UDATA pc, J9ROMClass * romClass, J9ROMMethod * romMethod,
372-
U_32 * resultArrayBase, UDATA resultArraySize,
373-
void * userData,
374-
UDATA * (* getBuffer) (void * userData),
375-
void (* releaseBuffer) (void * userData),
376-
J9JavaVM *vm, J9ClassLoader *classLoader)
377-
{
378-
UDATA mapWords = (resultArraySize + 31) >> 5;
379-
void *bytecodePC = (void*)(J9_BYTECODE_START_FROM_ROM_METHOD(romMethod) + pc);
380-
IDATA rc = 0;
381-
382-
if (!checkCache(vm, classLoader, bytecodePC, classLoader->stackmapCache, resultArrayBase, mapWords)) {
383-
/* Cache miss - perform the map and attempt to cache the result if successful */
384-
rc = j9stackmap_StackBitsForPC(vm->portLibrary, pc, romClass, romMethod,
385-
resultArrayBase, resultArraySize, userData, getBuffer, releaseBuffer);
386-
if (0 == rc) {
387-
updateCache(vm, classLoader, bytecodePC, &classLoader->stackmapCache, resultArrayBase, mapWords);
388-
}
389-
}
390-
return rc;
391-
}
392-
393-
void
394-
j9cached_ArgBitsForPC0(J9ROMClass *romClass, J9ROMMethod *romMethod, U_32 *resultArrayBase, J9JavaVM *vm, J9ClassLoader *classLoader)
395-
{
396-
UDATA mapWords = (J9_ARG_COUNT_FROM_ROM_METHOD(romMethod) + 31) >> 5;
397-
398-
if (!checkCache(vm, classLoader, (void*)romMethod, classLoader->argsbitsCache, resultArrayBase, mapWords)) {
399-
/* Cache miss - perform the map and attempt to cache the result */
400-
j9localmap_ArgBitsForPC0(romClass, romMethod, resultArrayBase);
401-
updateCache(vm, classLoader, (void*)romMethod, &classLoader->argsbitsCache, resultArrayBase, mapWords);
402-
}
403-
}
404-
405-
IDATA
406-
j9cached_LocalBitsForPC(J9ROMClass * romClass, J9ROMMethod * romMethod, UDATA pc, U_32 * resultArrayBase,
407-
void * userData,
408-
UDATA * (* getBuffer) (void * userData),
409-
void (* releaseBuffer) (void * userData),
410-
J9JavaVM *vm, J9ClassLoader * classLoader)
411-
{
412-
IDATA rc = 0;
413-
void *bytecodePC = (void*)(J9_BYTECODE_START_FROM_ROM_METHOD(romMethod) + pc);
414-
UDATA mapWords = (UDATA) ((J9_TEMP_COUNT_FROM_ROM_METHOD(romMethod) + J9_ARG_COUNT_FROM_ROM_METHOD(romMethod) + 31) >> 5);
415-
416-
if (!checkCache(vm, classLoader, bytecodePC, classLoader->localmapCache, resultArrayBase, mapWords)) {
417-
/* Cache miss - perform the map and attempt to cache the result if successful */
418-
rc = vm->localMapFunction(vm->portLibrary, romClass, romMethod, pc, resultArrayBase, userData, getBuffer, releaseBuffer);
419-
if (0 == rc) {
420-
updateCache(vm, classLoader, bytecodePC, &classLoader->localmapCache, resultArrayBase, mapWords);
421-
}
422-
}
423-
424-
return rc;
425-
}
426-
427-
#endif
428-
429217

430218
} /* extern "C" */

runtime/vm/swalk.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,9 @@ walkMethodFrame(J9StackWalkState * walkState)
720720
MARK_SLOT_AS_OBJECT(walkState, (j9object_t*) &(methodFrame->specialFrameFlags));
721721
walkState->method = methodFrame->method;
722722
if (NULL != walkState->method) {
723-
initializeBasicROMMethodInfo(walkState, J9_ROM_METHOD_FROM_RAM_METHOD(walkState->method));
723+
J9ROMMethod *romMethod = J9_ROM_METHOD_FROM_RAM_METHOD(walkState->method);
724+
getROMMethodInfoForROMMethod(walkState, romMethod);
725+
//initializeBasicROMMethodInfo(walkState, J9_ROM_METHOD_FROM_RAM_METHOD(walkState->method));
724726
}
725727
walkState->unwindSP = (UDATA *) methodFrame;
726728

@@ -1234,7 +1236,9 @@ static void walkJITJNICalloutFrame(J9StackWalkState * walkState)
12341236
MARK_SLOT_AS_OBJECT(walkState, (j9object_t*) &(methodFrame->specialFrameFlags));
12351237
walkState->method = methodFrame->method;
12361238
if (NULL != walkState->method) {
1237-
initializeBasicROMMethodInfo(walkState, J9_ROM_METHOD_FROM_RAM_METHOD(walkState->method));
1239+
J9ROMMethod *romMethod = J9_ROM_METHOD_FROM_RAM_METHOD(walkState->method);
1240+
getROMMethodInfoForROMMethod(walkState, romMethod);
1241+
//initializeBasicROMMethodInfo(walkState, J9_ROM_METHOD_FROM_RAM_METHOD(walkState->method));
12381242
}
12391243
walkState->constantPool = UNTAGGED_METHOD_CP(walkState->method);
12401244
#ifdef J9VM_INTERP_STACKWALK_TRACING

0 commit comments

Comments
 (0)