diff --git a/src/hotspot/share/code/codeCache.cpp b/src/hotspot/share/code/codeCache.cpp index 99539ed80cc..3af55c00567 100644 --- a/src/hotspot/share/code/codeCache.cpp +++ b/src/hotspot/share/code/codeCache.cpp @@ -573,6 +573,8 @@ CodeBlob* CodeCache::allocate(int size, CodeBlobType code_blob_type, bool handle CompileBroker::handle_full_code_cache(orig_code_blob_type); } return nullptr; + } else { + OrderAccess::release(); // ensure heap expansion is visible to an asynchronous observer (e.g. CodeHeapPool::get_memory_usage()) } if (PrintCodeCacheExtension) { ResourceMark rm; diff --git a/src/hotspot/share/services/memoryPool.cpp b/src/hotspot/share/services/memoryPool.cpp index 15210835478..d5b8f93d929 100644 --- a/src/hotspot/share/services/memoryPool.cpp +++ b/src/hotspot/share/services/memoryPool.cpp @@ -179,6 +179,7 @@ CodeHeapPool::CodeHeapPool(CodeHeap* codeHeap, const char* name, bool support_us MemoryUsage CodeHeapPool::get_memory_usage() { size_t used = used_in_bytes(); + OrderAccess::acquire(); // ensure possible cache expansion in CodeCache::allocate is seen size_t committed = _codeHeap->capacity(); size_t maxSize = (available_for_allocation() ? max_size() : 0);