Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up code for FrequentObjectsStats #20445

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 22 additions & 23 deletions runtime/gc_stats/FrequentObjectsStats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ MM_FrequentObjectsStats::newInstance(MM_EnvironmentBase *env)
{
PORT_ACCESS_FROM_ENVIRONMENT(env);
MM_FrequentObjectsStats *frequentObjectsStats;
U_32 frequentObjectAllocationSamplingDepth = MM_GCExtensions::getExtensions(env)->frequentObjectAllocationSamplingDepth;
uint32_t frequentObjectAllocationSamplingDepth = MM_GCExtensions::getExtensions(env)->frequentObjectAllocationSamplingDepth;

frequentObjectsStats = (MM_FrequentObjectsStats *)env->getForge()->allocate(sizeof(MM_FrequentObjectsStats), MM_AllocationCategory::FIXED, J9_GET_CALLSITE());
if(NULL != frequentObjectsStats) {
if (NULL != frequentObjectsStats) {
if (0 != frequentObjectAllocationSamplingDepth) {
new(frequentObjectsStats) MM_FrequentObjectsStats(PORTLIB, frequentObjectAllocationSamplingDepth);
} else {
new(frequentObjectsStats) MM_FrequentObjectsStats(PORTLIB);
}
if(!frequentObjectsStats->initialize(env)) {
if (!frequentObjectsStats->initialize(env)) {
frequentObjectsStats->kill(env);
return NULL;
}
Expand All @@ -65,7 +65,7 @@ MM_FrequentObjectsStats::initialize(MM_EnvironmentBase *env)
void
MM_FrequentObjectsStats::tearDown(MM_EnvironmentBase *env)
{
if(NULL != _spaceSaving){
if (NULL != _spaceSaving) {
spaceSavingFree(_spaceSaving);
}
}
Expand All @@ -81,23 +81,23 @@ MM_FrequentObjectsStats::kill(MM_EnvironmentBase *env)
void
MM_FrequentObjectsStats::traceStats(MM_EnvironmentBase *env)
{
UDATA i;
uintptr_t i = 0;
J9VMThread *vmThread = (J9VMThread *)env->getOmrVMThread()->_language_vmthread;
MM_GCExtensionsBase *extensions = env->getExtensions();
/* Should convert easily as frequentObjectAllocationSamplingRate is a UDATA representing a percentage*/
float sampleFreq = 100/((float) extensions->frequentObjectAllocationSamplingRate);
/* Should convert easily as frequentObjectAllocationSamplingRate is a uintptr_t representing a percentage */
float sampleFreq = 100 / ((float) extensions->frequentObjectAllocationSamplingRate);

for(i=0; i < spaceSavingGetCurSize(_spaceSaving) && i < _topKFrequent; i++){
J9Class * clazz = (J9Class *) spaceSavingGetKthMostFreq(_spaceSaving,i+1);
UDATA count = spaceSavingGetKthMostFreqCount(_spaceSaving,i+1);
for (i = 0; i < spaceSavingGetCurSize(_spaceSaving) && i < _topKFrequent; i++) {
J9Class *clazz = (J9Class *) spaceSavingGetKthMostFreq(_spaceSaving, i + 1);
uintptr_t count = spaceSavingGetKthMostFreqCount(_spaceSaving, i + 1);

if(J9ROMCLASS_IS_ARRAY(clazz->romClass)){
if (J9ROMCLASS_IS_ARRAY(clazz->romClass)) {
J9ArrayClass* arrayClass = (J9ArrayClass*) clazz;
UDATA arity = arrayClass->arity;
J9UTF8* utf;
uintptr_t arity = arrayClass->arity;
J9UTF8 *utf = NULL;

/* Max arity is 255, so define a bracket array of size 255*2 */
static const char * brackets =
static const char *brackets =
"[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]"
"[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]"
"[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]"
Expand All @@ -106,24 +106,23 @@ MM_FrequentObjectsStats::traceStats(MM_EnvironmentBase *env)

utf = J9ROMCLASS_CLASSNAME(arrayClass->leafComponentType->romClass);
Trc_MM_FrequentObjectStats_AllocationCacheIndexableObjectAllocation(
vmThread, clazz, J9UTF8_LENGTH(utf), J9UTF8_DATA(utf), arity*2, brackets, count, (UDATA) (((float)count)*sampleFreq));
}else{
vmThread, clazz, J9UTF8_LENGTH(utf), J9UTF8_DATA(utf), arity * 2, brackets, count, (uintptr_t) (((float)count) * sampleFreq));
} else {
Trc_MM_FrequentObjectStats_AllocationCacheObjectAllocation(
vmThread, clazz, J9UTF8_LENGTH(J9ROMCLASS_CLASSNAME(clazz->romClass)), J9UTF8_DATA(J9ROMCLASS_CLASSNAME(clazz->romClass)), clazz->totalInstanceSize, count, (UDATA) (((float)count)*sampleFreq));
vmThread, clazz, J9UTF8_LENGTH(J9ROMCLASS_CLASSNAME(clazz->romClass)), J9UTF8_DATA(J9ROMCLASS_CLASSNAME(clazz->romClass)), clazz->totalInstanceSize, count, (uintptr_t) (((float)count) * sampleFreq));
}
}
return;
}

void
MM_FrequentObjectsStats::merge(MM_FrequentObjectsStats* frequentObjectsStats)
MM_FrequentObjectsStats::merge(MM_FrequentObjectsStats *frequentObjectsStats)
{
UDATA i;
OMRSpaceSaving* spaceSaving = frequentObjectsStats->_spaceSaving;
uintptr_t i = 0;
OMRSpaceSaving *spaceSaving = frequentObjectsStats->_spaceSaving;

for(i = 0; i < spaceSavingGetCurSize(spaceSaving); i++ ){
spaceSavingUpdate(_spaceSaving, spaceSavingGetKthMostFreq(spaceSaving,i+1), spaceSavingGetKthMostFreqCount(spaceSaving,i+1));
for (i = 0; i < spaceSavingGetCurSize(spaceSaving); i++) {
spaceSavingUpdate(_spaceSaving, spaceSavingGetKthMostFreq(spaceSaving, i + 1), spaceSavingGetKthMostFreqCount(spaceSaving, i + 1));
}

}

12 changes: 6 additions & 6 deletions runtime/gc_stats/FrequentObjectsStats.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ class MM_FrequentObjectsStats : public MM_Base
{
/* Data Members */
public:
OMRSpaceSaving * _spaceSaving;
U_32 _topKFrequent;
OMRSpaceSaving *_spaceSaving;
uint32_t _topKFrequent;
private:
J9PortLibrary *_portLibrary;

Expand All @@ -58,9 +58,9 @@ class MM_FrequentObjectsStats : public MM_Base
* Derived from a sample run of Eclipse, which showed that the size necessary to have accurately report the top k
* elements was approximately linear.
*/
U_32 getSizeForTopKFrequent(U_32 topKFrequent)
uint32_t getSizeForTopKFrequent(uint32_t topKFrequent)
{
return topKFrequent*K_TO_SIZE_RATIO;
return topKFrequent * K_TO_SIZE_RATIO;
}

/* Function Members */
Expand Down Expand Up @@ -92,15 +92,15 @@ class MM_FrequentObjectsStats : public MM_Base
* @param portLibrary the port library
* @param k the number of frequent objects we'd like to accurately report
*/
MM_FrequentObjectsStats(J9PortLibrary *portLibrary, U_32 k=TOPK_FREQUENT_DEFAULT)
MM_FrequentObjectsStats(J9PortLibrary *portLibrary, uint32_t k = TOPK_FREQUENT_DEFAULT)
: _spaceSaving(0)
, _topKFrequent(k)
,_portLibrary(portLibrary)
{}


/* Merges a FrequentObjectStats structures together with this one*/
void merge(MM_FrequentObjectsStats* frequentObjectsStats);
void merge(MM_FrequentObjectsStats *frequentObjectsStats);

void traceStats(MM_EnvironmentBase *env);

Expand Down