Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/gc_stats/FrequentObjectsStats.cpp
5985 views
1
2
/*******************************************************************************
3
* Copyright (c) 1991, 2014 IBM Corp. and others
4
*
5
* This program and the accompanying materials are made available under
6
* the terms of the Eclipse Public License 2.0 which accompanies this
7
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
8
* or the Apache License, Version 2.0 which accompanies this distribution and
9
* is available at https://www.apache.org/licenses/LICENSE-2.0.
10
*
11
* This Source Code may also be made available under the following
12
* Secondary Licenses when the conditions for such availability set
13
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
14
* General Public License, version 2 with the GNU Classpath
15
* Exception [1] and GNU General Public License, version 2 with the
16
* OpenJDK Assembly Exception [2].
17
*
18
* [1] https://www.gnu.org/software/classpath/license.html
19
* [2] http://openjdk.java.net/legal/assembly-exception.html
20
*
21
* 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
22
*******************************************************************************/
23
#include "FrequentObjectsStats.hpp"
24
25
#include "EnvironmentBase.hpp"
26
#include "GCExtensions.hpp"
27
#include "ModronAssertions.h"
28
29
/**
30
* Create and return a new instance of MM_FrequentObjectsStats.
31
*
32
* @return the new instance, or NULL on failure.
33
*/
34
MM_FrequentObjectsStats *
35
MM_FrequentObjectsStats::newInstance(MM_EnvironmentBase *env)
36
{
37
PORT_ACCESS_FROM_ENVIRONMENT(env);
38
MM_FrequentObjectsStats *frequentObjectsStats;
39
U_32 frequentObjectAllocationSamplingDepth = MM_GCExtensions::getExtensions(env)->frequentObjectAllocationSamplingDepth;
40
41
frequentObjectsStats = (MM_FrequentObjectsStats *)env->getForge()->allocate(sizeof(MM_FrequentObjectsStats), MM_AllocationCategory::FIXED, J9_GET_CALLSITE());
42
if(NULL != frequentObjectsStats) {
43
if (0 != frequentObjectAllocationSamplingDepth) {
44
new(frequentObjectsStats) MM_FrequentObjectsStats(PORTLIB, frequentObjectAllocationSamplingDepth);
45
} else {
46
new(frequentObjectsStats) MM_FrequentObjectsStats(PORTLIB);
47
}
48
if(!frequentObjectsStats->initialize(env)) {
49
frequentObjectsStats->kill(env);
50
return NULL;
51
}
52
}
53
return frequentObjectsStats;
54
}
55
56
57
bool
58
MM_FrequentObjectsStats::initialize(MM_EnvironmentBase *env)
59
{
60
_spaceSaving = spaceSavingNew(OMRPORT_FROM_J9PORT(_portLibrary), getSizeForTopKFrequent(_topKFrequent));
61
62
return (NULL != _spaceSaving);
63
}
64
65
void
66
MM_FrequentObjectsStats::tearDown(MM_EnvironmentBase *env)
67
{
68
if(NULL != _spaceSaving){
69
spaceSavingFree(_spaceSaving);
70
}
71
}
72
73
74
void
75
MM_FrequentObjectsStats::kill(MM_EnvironmentBase *env)
76
{
77
tearDown(env);
78
env->getForge()->free(this);
79
}
80
81
void
82
MM_FrequentObjectsStats::traceStats(MM_EnvironmentBase *env)
83
{
84
UDATA i;
85
J9VMThread *vmThread = (J9VMThread *)env->getOmrVMThread()->_language_vmthread;
86
MM_GCExtensionsBase *extensions = env->getExtensions();
87
/* Should convert easily as frequentObjectAllocationSamplingRate is a UDATA representing a percentage*/
88
float sampleFreq = 100/((float) extensions->frequentObjectAllocationSamplingRate);
89
90
for(i=0; i < spaceSavingGetCurSize(_spaceSaving) && i < _topKFrequent; i++){
91
J9Class * clazz = (J9Class *) spaceSavingGetKthMostFreq(_spaceSaving,i+1);
92
UDATA count = spaceSavingGetKthMostFreqCount(_spaceSaving,i+1);
93
94
if(J9ROMCLASS_IS_ARRAY(clazz->romClass)){
95
J9ArrayClass* arrayClass = (J9ArrayClass*) clazz;
96
UDATA arity = arrayClass->arity;
97
J9UTF8* utf;
98
99
/* Max arity is 255, so define a bracket array of size 255*2 */
100
static const char * brackets =
101
"[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]"
102
"[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]"
103
"[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]"
104
"[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]";
105
106
107
utf = J9ROMCLASS_CLASSNAME(arrayClass->leafComponentType->romClass);
108
Trc_MM_FrequentObjectStats_AllocationCacheIndexableObjectAllocation(
109
vmThread, clazz, J9UTF8_LENGTH(utf), J9UTF8_DATA(utf), arity*2, brackets, count, (UDATA) (((float)count)*sampleFreq));
110
}else{
111
Trc_MM_FrequentObjectStats_AllocationCacheObjectAllocation(
112
vmThread, clazz, J9UTF8_LENGTH(J9ROMCLASS_CLASSNAME(clazz->romClass)), J9UTF8_DATA(J9ROMCLASS_CLASSNAME(clazz->romClass)), clazz->totalInstanceSize, count, (UDATA) (((float)count)*sampleFreq));
113
}
114
}
115
return;
116
}
117
118
void
119
MM_FrequentObjectsStats::merge(MM_FrequentObjectsStats* frequentObjectsStats)
120
{
121
UDATA i;
122
OMRSpaceSaving* spaceSaving = frequentObjectsStats->_spaceSaving;
123
124
for(i = 0; i < spaceSavingGetCurSize(spaceSaving); i++ ){
125
spaceSavingUpdate(_spaceSaving, spaceSavingGetKthMostFreq(spaceSaving,i+1), spaceSavingGetKthMostFreqCount(spaceSaving,i+1));
126
}
127
128
}
129
130
131