66#ifndef _CODECACHE_H
77#define _CODECACHE_H
88
9+ #include " common.h"
10+ #include " counters.h"
911#include " utils.h"
1012
1113#include < jvmti.h>
@@ -258,9 +260,10 @@ class CodeCacheArray {
258260 volatile int _reserved; // next slot to reserve (CAS by writers)
259261 volatile int _count; // published count (all indices < _count have non-NULL pointers)
260262 volatile size_t _used_memory;
263+ bool _overflow_reported;
261264
262265public:
263- CodeCacheArray () : _reserved(0 ), _count(0 ), _used_memory(0 ) {
266+ CodeCacheArray () : _reserved(0 ), _count(0 ), _used_memory(0 ), _overflow_reported( false ) {
264267 memset (_libs, 0 , MAX_NATIVE_LIBS * sizeof (CodeCache *));
265268 }
266269
@@ -272,10 +275,17 @@ class CodeCacheArray {
272275 // Pointer-first add: reserve a slot via CAS on _reserved, store the
273276 // pointer with RELEASE, then advance _count. Readers see count() grow
274277 // only after the pointer is visible, so indices < count() never yield NULL.
275- void add (CodeCache *lib) {
278+ bool add (CodeCache *lib) {
276279 int slot = __atomic_load_n (&_reserved, __ATOMIC_RELAXED);
277280 do {
278- if (slot >= MAX_NATIVE_LIBS ) return ;
281+ if (slot >= MAX_NATIVE_LIBS ) {
282+ Counters::increment (NATIVE_LIBS_DROPPED );
283+ if (!_overflow_reported) {
284+ _overflow_reported = true ;
285+ LOG_WARN (" Native library limit reached (%d). Additional libraries will not be tracked." , MAX_NATIVE_LIBS );
286+ }
287+ return false ;
288+ }
279289 } while (!__atomic_compare_exchange_n (&_reserved, &slot, slot + 1 ,
280290 true , __ATOMIC_RELAXED, __ATOMIC_RELAXED));
281291 assert (__atomic_load_n (&_libs[slot], __ATOMIC_RELAXED) == nullptr );
@@ -289,6 +299,7 @@ class CodeCacheArray {
289299 // wait for preceding slots to publish
290300 }
291301 __atomic_store_n (&_count, slot + 1 , __ATOMIC_RELEASE);
302+ return true ;
292303 }
293304
294305 CodeCache* at (int index) const {
0 commit comments