Skip to content

Commit

Permalink
Expose alloc cache size API
Browse files Browse the repository at this point in the history
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 <Aleksandar_Micic@ca.ibm.com>
  • Loading branch information
Aleksandar Micic authored and Aleksandar Micic committed Feb 9, 2024
1 parent ac0dab2 commit 1a93a9d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
14 changes: 13 additions & 1 deletion gc/base/ObjectAllocationInterface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
26 changes: 26 additions & 0 deletions gc/base/TLHAllocationInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
2 changes: 2 additions & 0 deletions gc/base/TLHAllocationInterface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down

0 comments on commit 1a93a9d

Please sign in to comment.