Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/gc_stats/FrequentObjectsStats.hpp
5986 views
1
/*******************************************************************************
2
* Copyright (c) 1991, 2021 IBM Corp. and others
3
*
4
* This program and the accompanying materials are made available under
5
* the terms of the Eclipse Public License 2.0 which accompanies this
6
* 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 and
8
* is available at https://www.apache.org/licenses/LICENSE-2.0.
9
*
10
* This Source Code may also be made available under the following
11
* Secondary Licenses when the conditions for such availability set
12
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
13
* General Public License, version 2 with the GNU Classpath
14
* Exception [1] and GNU General Public License, version 2 with the
15
* OpenJDK Assembly Exception [2].
16
*
17
* [1] https://www.gnu.org/software/classpath/license.html
18
* [2] http://openjdk.java.net/legal/assembly-exception.html
19
*
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-exception
21
*******************************************************************************/
22
23
/**
24
* @file
25
* @ingroup GC_Stats
26
*/
27
28
#if !defined(FREQUENTOBJECTSSTATS_HPP_)
29
#define FREQUENTOBJECTSSTATS_HPP_
30
31
#include "j9.h"
32
#include "objectdescription.h"
33
#include "spacesaving.h"
34
35
#include "Base.hpp"
36
#include "EnvironmentBase.hpp"
37
38
#define TOPK_FREQUENT_DEFAULT 10
39
#define K_TO_SIZE_RATIO 8
40
41
/*
42
* Keeps track of the most frequent class instantiations
43
*/
44
45
class MM_FrequentObjectsStats : public MM_Base
46
{
47
/* Data Members */
48
public:
49
OMRSpaceSaving * _spaceSaving;
50
U_32 _topKFrequent;
51
private:
52
J9PortLibrary *_portLibrary;
53
54
private:
55
56
/*
57
* Estimates the space necessary to report the top k elements accurately 90% of the time.
58
* Derived from a sample run of Eclipse, which showed that the size necessary to have accurately report the top k
59
* elements was approximately linear.
60
*/
61
U_32 getSizeForTopKFrequent(U_32 topKFrequent)
62
{
63
return topKFrequent*K_TO_SIZE_RATIO;
64
}
65
66
/* Function Members */
67
public:
68
static MM_FrequentObjectsStats *newInstance(MM_EnvironmentBase *env);
69
virtual void kill(MM_EnvironmentBase *env);
70
71
/* reset the stats*/
72
void clear()
73
{
74
spaceSavingClear(_spaceSaving);
75
}
76
77
/*
78
* Update stats with another class
79
* @param clazz another clazz to record
80
*/
81
void update(MM_EnvironmentBase *env, omrobjectptr_t object)
82
{
83
/* Todo: implement ability to do ranking based on total size of object instances, instead
84
* of just number of object instances
85
*/
86
87
spaceSavingUpdate(_spaceSaving, J9OBJECT_CLAZZ((J9VMThread *)env->getLanguageVMThread(), object), 1);
88
}
89
90
/* Creates a data structure which keeps track of the k most frequent class allocations (estimated probability of 90% of
91
* reporting this accurately (and in the correct order). The larger k is, the more memory is required
92
* @param portLibrary the port library
93
* @param k the number of frequent objects we'd like to accurately report
94
*/
95
MM_FrequentObjectsStats(J9PortLibrary *portLibrary, U_32 k=TOPK_FREQUENT_DEFAULT)
96
: _spaceSaving(0)
97
, _topKFrequent(k)
98
,_portLibrary(portLibrary)
99
{}
100
101
102
/* Merges a FrequentObjectStats structures together with this one*/
103
void merge(MM_FrequentObjectsStats* frequentObjectsStats);
104
105
void traceStats(MM_EnvironmentBase *env);
106
107
protected:
108
virtual bool initialize(MM_EnvironmentBase *env);
109
virtual void tearDown(MM_EnvironmentBase *env);
110
};
111
112
#endif /* !FREQUENTOBJECTSSTATS_HPP_ */
113
114