From 77ead449e494f4dae147144dbcc978bb107e2817 Mon Sep 17 00:00:00 2001 From: Robbin Ehn Date: Thu, 9 Feb 2023 18:39:45 +0000 Subject: [PATCH] 8302066: Counter _number_of_nmethods_with_dependencies should be atomic. Reviewed-by: thartmann, kvn --- src/hotspot/share/code/codeCache.cpp | 14 ++++++++------ src/hotspot/share/code/codeCache.hpp | 10 +++++----- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/hotspot/share/code/codeCache.cpp b/src/hotspot/share/code/codeCache.cpp index df1b27b3165..ce6e67e9b82 100644 --- a/src/hotspot/share/code/codeCache.cpp +++ b/src/hotspot/share/code/codeCache.cpp @@ -168,7 +168,7 @@ class CodeBlob_sizes { address CodeCache::_low_bound = 0; address CodeCache::_high_bound = 0; -int CodeCache::_number_of_nmethods_with_dependencies = 0; +volatile int CodeCache::_number_of_nmethods_with_dependencies = 0; ExceptionCache* volatile CodeCache::_exception_cache_purge_list = nullptr; // Initialize arrays of CodeHeap subsets @@ -587,7 +587,7 @@ void CodeCache::free(CodeBlob* cb) { if (cb->is_nmethod()) { heap->set_nmethod_count(heap->nmethod_count() - 1); if (((nmethod *)cb)->has_dependencies()) { - _number_of_nmethods_with_dependencies--; + Atomic::dec(&_number_of_nmethods_with_dependencies); } } if (cb->is_adapter_blob()) { @@ -622,7 +622,7 @@ void CodeCache::commit(CodeBlob* cb) { if (cb->is_nmethod()) { heap->set_nmethod_count(heap->nmethod_count() + 1); if (((nmethod *)cb)->has_dependencies()) { - _number_of_nmethods_with_dependencies++; + Atomic::inc(&_number_of_nmethods_with_dependencies); } } if (cb->is_adapter_blob()) { @@ -1219,8 +1219,8 @@ void codeCache_init() { //------------------------------------------------------------------------------------------------ -int CodeCache::number_of_nmethods_with_dependencies() { - return _number_of_nmethods_with_dependencies; +bool CodeCache::has_nmethods_with_dependencies() { + return Atomic::load_acquire(&_number_of_nmethods_with_dependencies) != 0; } void CodeCache::clear_inline_caches() { @@ -1431,7 +1431,9 @@ void CodeCache::make_nmethod_deoptimized(CompiledMethod* nm) { void CodeCache::flush_dependents_on(InstanceKlass* dependee) { assert_lock_strong(Compile_lock); - if (number_of_nmethods_with_dependencies() == 0) return; + if (!has_nmethods_with_dependencies()) { + return; + } int marked = 0; if (dependee->is_linked()) { diff --git a/src/hotspot/share/code/codeCache.hpp b/src/hotspot/share/code/codeCache.hpp index 289c84d8184..58c69b73b09 100644 --- a/src/hotspot/share/code/codeCache.hpp +++ b/src/hotspot/share/code/codeCache.hpp @@ -93,9 +93,9 @@ class CodeCache : AllStatic { static GrowableArray* _nmethod_heaps; static GrowableArray* _allocable_heaps; - static address _low_bound; // Lower bound of CodeHeap addresses - static address _high_bound; // Upper bound of CodeHeap addresses - static int _number_of_nmethods_with_dependencies; // Total number of nmethods with dependencies + static address _low_bound; // Lower bound of CodeHeap addresses + static address _high_bound; // Upper bound of CodeHeap addresses + static volatile int _number_of_nmethods_with_dependencies; // Total number of nmethods with dependencies static uint8_t _unloading_cycle; // Global state for recognizing old nmethods that need to be unloaded static uint64_t _gc_epoch; // Global state for tracking when nmethods were found to be on-stack @@ -323,8 +323,8 @@ class CodeCache : AllStatic { // Support for fullspeed debugging static void flush_dependents_on_method(const methodHandle& dependee); - // tells how many nmethods have dependencies - static int number_of_nmethods_with_dependencies(); + // tells if there are nmethods with dependencies + static bool has_nmethods_with_dependencies(); static int get_codemem_full_count(CodeBlobType code_blob_type) { CodeHeap* heap = get_code_heap(code_blob_type);