From 893614917bf2db2e3e16c620154fe391c28e29ea Mon Sep 17 00:00:00 2001 From: Theresa Mammarella Date: Thu, 19 Sep 2024 12:28:03 -0400 Subject: [PATCH] Atomically free romToRam hash table and mutex Signed-off-by: Theresa Mammarella --- runtime/shared_common/shrinit.cpp | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/runtime/shared_common/shrinit.cpp b/runtime/shared_common/shrinit.cpp index fcc5a40ef5b..80052782513 100644 --- a/runtime/shared_common/shrinit.cpp +++ b/runtime/shared_common/shrinit.cpp @@ -4303,6 +4303,14 @@ j9shr_shutdown(J9JavaVM *vm) if (config->jclCacheMutex) { omrthread_monitor_destroy(config->jclCacheMutex); } + + if (compareAndSwapUDATA((uintptr_t *)&config->romToRamHashTable, (uintptr_t)romToRamHashTable, (uintptr_t)NULL)) { + config->romToRamHashTableMutex = NULL; + omrthread_rwmutex_enter_write(romToRamHashTableMutex); + hashTableFree(romToRamHashTable); + omrthread_rwmutex_exit_write(romToRamHashTableMutex); + omrthread_rwmutex_destroy(romToRamHashTableMutex); + } j9mem_free_memory(config->sharedAPIObject); j9mem_free_memory(config); @@ -4329,16 +4337,6 @@ j9shr_shutdown(J9JavaVM *vm) if (utfHashTable) { hashTableFree(utfHashTable); } - if (NULL != romToRamHashTable) { - omrthread_rwmutex_enter_write(romToRamHashTableMutex); - config->romToRamHashTable = NULL; - config->romToRamHashTableMutex = NULL; - if (romToRamHashTable) { - hashTableFree(romToRamHashTable); - } - omrthread_rwmutex_exit_write(romToRamHashTableMutex); - omrthread_rwmutex_destroy(romToRamHashTableMutex); - } /* Kill the string farm */