From 1a93a9d290a673e24b741ef1929125dc3315d431 Mon Sep 17 00:00:00 2001 From: Aleksandar Micic Date: Fri, 9 Feb 2024 13:07:59 -0500 Subject: [PATCH] Expose alloc cache size API Expose remaining and refresh size APIs for ObjectAllocationInterface, and implement it for TLHAllocationInterface. While this values are functionally needed only internally within the class, they will be used for stats reporting purposes outisde the class, hence need to be public. Signed-off-by: Aleksandar Micic --- gc/base/ObjectAllocationInterface.hpp | 14 +++++++++++++- gc/base/TLHAllocationInterface.cpp | 26 ++++++++++++++++++++++++++ gc/base/TLHAllocationInterface.hpp | 2 ++ 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/gc/base/ObjectAllocationInterface.hpp b/gc/base/ObjectAllocationInterface.hpp index 8431896445b..b060f118689 100644 --- a/gc/base/ObjectAllocationInterface.hpp +++ b/gc/base/ObjectAllocationInterface.hpp @@ -127,7 +127,19 @@ class MM_ObjectAllocationInterface : public MM_BaseVirtual virtual void flushCache(MM_EnvironmentBase *env); virtual void restartCache(MM_EnvironmentBase *env); - + /** + * Return the size of currently remaining/unused part of the cache. + * With dual cache setup (pre-zeroed or non-pre-zeroed), both sizes can be obtained. + * @param nonZero if true, return pre-zeroed remaining cache size, otherwise non-pre-zeroed one + */ + virtual uintptr_t getRemainingCacheSize(bool nonZero) { return 0; } + /** + * With dynamically sized caches, return the size of the cache on next refresh + * With dual cache setup (pre-zeroed or non-pre-zeroed), both sizes can be obtained. + * @param nonZero if true, return pre-zeroed refresh cache size, otherwise non-pre-zeroed one + */ + virtual uintptr_t getRefreshCacheSize(bool nonZero) { return 0; } + virtual void enableCachedAllocations(MM_EnvironmentBase* env) {}; virtual void disableCachedAllocations(MM_EnvironmentBase* env) {}; virtual bool cachedAllocationsEnabled(MM_EnvironmentBase* env) { return true; } diff --git a/gc/base/TLHAllocationInterface.cpp b/gc/base/TLHAllocationInterface.cpp index ba02f2d5b9d..d897bd77f47 100644 --- a/gc/base/TLHAllocationInterface.cpp +++ b/gc/base/TLHAllocationInterface.cpp @@ -309,4 +309,30 @@ MM_TLHAllocationInterface::restartCache(MM_EnvironmentBase *env) #endif /* defined(OMR_GC_NON_ZERO_TLH) */ } +uintptr_t +MM_TLHAllocationInterface::getRemainingCacheSize(bool nonZero) +{ +#if defined(OMR_GC_NON_ZERO_TLH) + if (nonZero) { + return _tlhAllocationSupportNonZero.getRemainingSize(); + } else +#endif /* defined(OMR_GC_NON_ZERO_TLH) */ + { + return _tlhAllocationSupport.getRemainingSize(); + } +} + +uintptr_t +MM_TLHAllocationInterface::getRefreshCacheSize(bool nonZero) +{ +#if defined(OMR_GC_NON_ZERO_TLH) + if (nonZero) { + return _tlhAllocationSupportNonZero.getRefreshSize(); + } else +#endif /* defined(OMR_GC_NON_ZERO_TLH) */ + { + return _tlhAllocationSupport.getRefreshSize(); + } +} + #endif /* OMR_GC_THREAD_LOCAL_HEAP */ diff --git a/gc/base/TLHAllocationInterface.hpp b/gc/base/TLHAllocationInterface.hpp index 54eda9e2957..31207629321 100644 --- a/gc/base/TLHAllocationInterface.hpp +++ b/gc/base/TLHAllocationInterface.hpp @@ -77,6 +77,8 @@ class MM_TLHAllocationInterface : public MM_ObjectAllocationInterface virtual void flushCache(MM_EnvironmentBase *env); virtual void restartCache(MM_EnvironmentBase *env); + virtual uintptr_t getRemainingCacheSize(bool nonZero); + virtual uintptr_t getRefreshCacheSize(bool nonZero); /* BEN TODO: Collapse the env->enable/disableInlineTLHAllocate with these enable/disableCachedAllocations */ virtual void enableCachedAllocations(MM_EnvironmentBase* env) { _cachedAllocationsEnabled = true; }