@@ -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
172172void
173173getROMMethodInfoForROMMethod (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
192193void
193194getROMMethodInfoForBytecodePC (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" */
0 commit comments