Path: blob/master/runtime/gc_stats/FrequentObjectsStats.cpp
5985 views
1/*******************************************************************************2* Copyright (c) 1991, 2014 IBM Corp. and others3*4* This program and the accompanying materials are made available under5* the terms of the Eclipse Public License 2.0 which accompanies this6* distribution and is available at https://www.eclipse.org/legal/epl-2.0/7* or the Apache License, Version 2.0 which accompanies this distribution and8* is available at https://www.apache.org/licenses/LICENSE-2.0.9*10* This Source Code may also be made available under the following11* Secondary Licenses when the conditions for such availability set12* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU13* General Public License, version 2 with the GNU Classpath14* Exception [1] and GNU General Public License, version 2 with the15* OpenJDK Assembly Exception [2].16*17* [1] https://www.gnu.org/software/classpath/license.html18* [2] http://openjdk.java.net/legal/assembly-exception.html19*20* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception21*******************************************************************************/22#include "FrequentObjectsStats.hpp"2324#include "EnvironmentBase.hpp"25#include "GCExtensions.hpp"26#include "ModronAssertions.h"2728/**29* Create and return a new instance of MM_FrequentObjectsStats.30*31* @return the new instance, or NULL on failure.32*/33MM_FrequentObjectsStats *34MM_FrequentObjectsStats::newInstance(MM_EnvironmentBase *env)35{36PORT_ACCESS_FROM_ENVIRONMENT(env);37MM_FrequentObjectsStats *frequentObjectsStats;38U_32 frequentObjectAllocationSamplingDepth = MM_GCExtensions::getExtensions(env)->frequentObjectAllocationSamplingDepth;3940frequentObjectsStats = (MM_FrequentObjectsStats *)env->getForge()->allocate(sizeof(MM_FrequentObjectsStats), MM_AllocationCategory::FIXED, J9_GET_CALLSITE());41if(NULL != frequentObjectsStats) {42if (0 != frequentObjectAllocationSamplingDepth) {43new(frequentObjectsStats) MM_FrequentObjectsStats(PORTLIB, frequentObjectAllocationSamplingDepth);44} else {45new(frequentObjectsStats) MM_FrequentObjectsStats(PORTLIB);46}47if(!frequentObjectsStats->initialize(env)) {48frequentObjectsStats->kill(env);49return NULL;50}51}52return frequentObjectsStats;53}545556bool57MM_FrequentObjectsStats::initialize(MM_EnvironmentBase *env)58{59_spaceSaving = spaceSavingNew(OMRPORT_FROM_J9PORT(_portLibrary), getSizeForTopKFrequent(_topKFrequent));6061return (NULL != _spaceSaving);62}6364void65MM_FrequentObjectsStats::tearDown(MM_EnvironmentBase *env)66{67if(NULL != _spaceSaving){68spaceSavingFree(_spaceSaving);69}70}717273void74MM_FrequentObjectsStats::kill(MM_EnvironmentBase *env)75{76tearDown(env);77env->getForge()->free(this);78}7980void81MM_FrequentObjectsStats::traceStats(MM_EnvironmentBase *env)82{83UDATA i;84J9VMThread *vmThread = (J9VMThread *)env->getOmrVMThread()->_language_vmthread;85MM_GCExtensionsBase *extensions = env->getExtensions();86/* Should convert easily as frequentObjectAllocationSamplingRate is a UDATA representing a percentage*/87float sampleFreq = 100/((float) extensions->frequentObjectAllocationSamplingRate);8889for(i=0; i < spaceSavingGetCurSize(_spaceSaving) && i < _topKFrequent; i++){90J9Class * clazz = (J9Class *) spaceSavingGetKthMostFreq(_spaceSaving,i+1);91UDATA count = spaceSavingGetKthMostFreqCount(_spaceSaving,i+1);9293if(J9ROMCLASS_IS_ARRAY(clazz->romClass)){94J9ArrayClass* arrayClass = (J9ArrayClass*) clazz;95UDATA arity = arrayClass->arity;96J9UTF8* utf;9798/* Max arity is 255, so define a bracket array of size 255*2 */99static const char * brackets =100"[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]"101"[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]"102"[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]"103"[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]";104105106utf = J9ROMCLASS_CLASSNAME(arrayClass->leafComponentType->romClass);107Trc_MM_FrequentObjectStats_AllocationCacheIndexableObjectAllocation(108vmThread, clazz, J9UTF8_LENGTH(utf), J9UTF8_DATA(utf), arity*2, brackets, count, (UDATA) (((float)count)*sampleFreq));109}else{110Trc_MM_FrequentObjectStats_AllocationCacheObjectAllocation(111vmThread, clazz, J9UTF8_LENGTH(J9ROMCLASS_CLASSNAME(clazz->romClass)), J9UTF8_DATA(J9ROMCLASS_CLASSNAME(clazz->romClass)), clazz->totalInstanceSize, count, (UDATA) (((float)count)*sampleFreq));112}113}114return;115}116117void118MM_FrequentObjectsStats::merge(MM_FrequentObjectsStats* frequentObjectsStats)119{120UDATA i;121OMRSpaceSaving* spaceSaving = frequentObjectsStats->_spaceSaving;122123for(i = 0; i < spaceSavingGetCurSize(spaceSaving); i++ ){124spaceSavingUpdate(_spaceSaving, spaceSavingGetKthMostFreq(spaceSaving,i+1), spaceSavingGetKthMostFreqCount(spaceSaving,i+1));125}126127}128129130131