Path: blob/master/runtime/gc_stats/FrequentObjectsStats.hpp
5986 views
/*******************************************************************************1* Copyright (c) 1991, 2021 IBM Corp. and others2*3* This program and the accompanying materials are made available under4* the terms of the Eclipse Public License 2.0 which accompanies this5* distribution and is available at https://www.eclipse.org/legal/epl-2.0/6* or the Apache License, Version 2.0 which accompanies this distribution and7* is available at https://www.apache.org/licenses/LICENSE-2.0.8*9* This Source Code may also be made available under the following10* Secondary Licenses when the conditions for such availability set11* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU12* General Public License, version 2 with the GNU Classpath13* Exception [1] and GNU General Public License, version 2 with the14* OpenJDK Assembly Exception [2].15*16* [1] https://www.gnu.org/software/classpath/license.html17* [2] http://openjdk.java.net/legal/assembly-exception.html18*19* 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-exception20*******************************************************************************/2122/**23* @file24* @ingroup GC_Stats25*/2627#if !defined(FREQUENTOBJECTSSTATS_HPP_)28#define FREQUENTOBJECTSSTATS_HPP_2930#include "j9.h"31#include "objectdescription.h"32#include "spacesaving.h"3334#include "Base.hpp"35#include "EnvironmentBase.hpp"3637#define TOPK_FREQUENT_DEFAULT 1038#define K_TO_SIZE_RATIO 83940/*41* Keeps track of the most frequent class instantiations42*/4344class MM_FrequentObjectsStats : public MM_Base45{46/* Data Members */47public:48OMRSpaceSaving * _spaceSaving;49U_32 _topKFrequent;50private:51J9PortLibrary *_portLibrary;5253private:5455/*56* Estimates the space necessary to report the top k elements accurately 90% of the time.57* Derived from a sample run of Eclipse, which showed that the size necessary to have accurately report the top k58* elements was approximately linear.59*/60U_32 getSizeForTopKFrequent(U_32 topKFrequent)61{62return topKFrequent*K_TO_SIZE_RATIO;63}6465/* Function Members */66public:67static MM_FrequentObjectsStats *newInstance(MM_EnvironmentBase *env);68virtual void kill(MM_EnvironmentBase *env);6970/* reset the stats*/71void clear()72{73spaceSavingClear(_spaceSaving);74}7576/*77* Update stats with another class78* @param clazz another clazz to record79*/80void update(MM_EnvironmentBase *env, omrobjectptr_t object)81{82/* Todo: implement ability to do ranking based on total size of object instances, instead83* of just number of object instances84*/8586spaceSavingUpdate(_spaceSaving, J9OBJECT_CLAZZ((J9VMThread *)env->getLanguageVMThread(), object), 1);87}8889/* Creates a data structure which keeps track of the k most frequent class allocations (estimated probability of 90% of90* reporting this accurately (and in the correct order). The larger k is, the more memory is required91* @param portLibrary the port library92* @param k the number of frequent objects we'd like to accurately report93*/94MM_FrequentObjectsStats(J9PortLibrary *portLibrary, U_32 k=TOPK_FREQUENT_DEFAULT)95: _spaceSaving(0)96, _topKFrequent(k)97,_portLibrary(portLibrary)98{}99100101/* Merges a FrequentObjectStats structures together with this one*/102void merge(MM_FrequentObjectsStats* frequentObjectsStats);103104void traceStats(MM_EnvironmentBase *env);105106protected:107virtual bool initialize(MM_EnvironmentBase *env);108virtual void tearDown(MM_EnvironmentBase *env);109};110111#endif /* !FREQUENTOBJECTSSTATS_HPP_ */112113114