Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/gc_trace_standard/TgcFreeListSummary.cpp
5985 views
1
2
/*******************************************************************************
3
* Copyright (c) 1991, 2019 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
24
#include "j9.h"
25
#include "j9cfg.h"
26
#include "mmhook.h"
27
#include "j9port.h"
28
#include "modronopt.h"
29
#include "ModronAssertions.h"
30
31
#include "TgcFreeListSummary.hpp"
32
33
#include "GCExtensions.hpp"
34
#include "HeapStats.hpp"
35
#include "TgcExtensions.hpp"
36
37
#include "EnvironmentBase.hpp"
38
#include "Heap.hpp"
39
#include "HeapLinkedFreeHeader.hpp"
40
#include "HeapMemoryPoolIterator.hpp"
41
#include "MemoryPool.hpp"
42
43
#define STAT_ELEMENTS 22
44
#define FIRST_ELEMENT_THRESHOLD 1024
45
46
/*
47
* Free List Summary is organized as a array of counters. Each counter represents number of holes in pool with size in particular range.
48
* First element represents number of holes smaller then FIRST_ELEMENT_THRESHOLD bytes (but larger then dark matter threshold - 512 bytes default)
49
* Second element represents number of holes smaller then 2 * FIRST_ELEMENT_THRESHOLD but larger then FIRST_ELEMENT_THRESHOLD.
50
* Each next element has a doubled threshold, except last one which represents number of holes larger then previous threshold.
51
* The table of thresholds for FIRST_ELEMENT_THRESHOLD = 1024 and number of elements = 22 is below:
52
*
53
* 1 <1024
54
* 2 <2048
55
* 3 <4096
56
* 4 <8192
57
* 5 <16384
58
* 6 <32768
59
* 7 <65536
60
* 8 <131072
61
* 9 <262144
62
* 10 <524288
63
* 11 <1048576
64
* 12 <2097152
65
* 13 <4194304
66
* 14 <8388608
67
* 15 <16777216
68
* 16 <33554432
69
* 17 <67108864
70
* 18 <134217728
71
* 19 <268435456
72
* 20 <536870912
73
* 21 <1073741824
74
* 22 >=1073741824
75
*
76
*/
77
78
/*
79
* Increment the counter responsible for size in range
80
* @param size Size of hole we want to add to count
81
* @param array Pointer to Free List Summary array
82
* @param elements Number of elements in Free List Summary array
83
*/
84
static void
85
addSizeToSummary(UDATA size, UDATA *array, UDATA elements)
86
{
87
UDATA i;
88
UDATA n = FIRST_ELEMENT_THRESHOLD;
89
for (i = 0; i < elements - 1; i++) {
90
if (size < n) {
91
array[i] += 1;
92
return;
93
}
94
n = n * 2;
95
}
96
array[elements - 1] += 1;
97
}
98
99
/*
100
* Calculate Free List Summary for Memory Pool. Return size of Largest hole discovered in pool
101
* @param env thread information
102
* @param pool Memory pool to calculate summary
103
* @param statsArray Pointer to Free List Summary array
104
* @param elements Number of elements in Free List Summary array
105
* @return Size of largest hole discovered in pool
106
*/
107
static UDATA
108
calcSummaryForMemoryPool(MM_EnvironmentBase *env, MM_MemoryPool *pool, UDATA *statsArray, UDATA elements)
109
{
110
UDATA i;
111
UDATA largest = 0;
112
113
for (i = 0; i < elements; i++) {
114
statsArray[i] = 0;
115
}
116
117
MM_HeapLinkedFreeHeader *currentFreeEntry = (MM_HeapLinkedFreeHeader *)pool->getFirstFreeStartingAddr(env);
118
while(currentFreeEntry) {
119
UDATA size = currentFreeEntry->getSize();
120
if (size > largest) {
121
largest = size;
122
}
123
addSizeToSummary(size, statsArray, elements);
124
currentFreeEntry = (MM_HeapLinkedFreeHeader *)pool->getNextFreeStartingAddr(env, currentFreeEntry);
125
}
126
127
return largest;
128
}
129
130
/*
131
* Walk all MPAOLs in heap, calculate Free List Summary and print it.
132
* @param env thread information
133
* @param verboseEvent Event description iv verbose form
134
*/
135
static void
136
calcAndPrintFreeListSummary(MM_EnvironmentBase *env, const char *verboseEvent)
137
{
138
MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(env);
139
MM_TgcExtensions *tgcExtensions = MM_TgcExtensions::getExtensions(extensions);
140
MM_MemoryPool *memoryPool = NULL;
141
MM_HeapMemoryPoolIterator poolIterator(env, extensions->heap);
142
143
UDATA statsArray[STAT_ELEMENTS];
144
UDATA statLargest = 0;
145
UDATA i;
146
147
tgcExtensions->printf("\n<free_list_summary reason=\"%s\">\n", verboseEvent);
148
while(NULL != (memoryPool = (MM_MemoryPool *)poolIterator.nextPool())) {
149
statLargest = calcSummaryForMemoryPool(env, memoryPool, statsArray, STAT_ELEMENTS);
150
tgcExtensions->printf("<memory_pool address=\"%p\" name=\"%s\" largest=\"%d\">", memoryPool, memoryPool->getPoolName(), statLargest);
151
for (i = 0; i < STAT_ELEMENTS; i++) {
152
tgcExtensions->printf(" %d", statsArray[i]);
153
}
154
tgcExtensions->printf(" </memory_pool>\n");
155
}
156
tgcExtensions->printf("</free_list_summary>\n");
157
}
158
159
/*
160
* Handle for J9HOOK_MM_GLOBAL_GC_START event
161
*/
162
static void
163
tgcHookFreeListSummaryStart(J9HookInterface** hook, UDATA eventNum, void* eventData, void* userData)
164
{
165
MM_GlobalGCEndEvent* event = (MM_GlobalGCEndEvent*)eventData;
166
MM_EnvironmentBase *env = MM_EnvironmentBase::getEnvironment(event->currentThread);
167
calcAndPrintFreeListSummary(env, "Global GC Start");
168
}
169
170
/*
171
* Handle for J9HOOK_MM_GLOBAL_GC_END event
172
*/
173
static void
174
tgcHookFreeListSummaryEnd(J9HookInterface** hook, UDATA eventNum, void* eventData, void* userData)
175
{
176
MM_GlobalGCEndEvent* event = (MM_GlobalGCEndEvent*)eventData;
177
MM_EnvironmentBase *env = MM_EnvironmentBase::getEnvironment(event->currentThread);
178
calcAndPrintFreeListSummary(env, "Global GC End");
179
}
180
181
/*
182
* Initialization for Free List Summary request
183
*/
184
bool
185
tgcFreeListSummaryInitialize(J9JavaVM *javaVM)
186
{
187
MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(javaVM);
188
bool result = true;
189
190
J9HookInterface** hooks = J9_HOOK_INTERFACE(extensions->omrHookInterface);
191
(*hooks)->J9HookRegisterWithCallSite(hooks, J9HOOK_MM_OMR_GLOBAL_GC_START, tgcHookFreeListSummaryStart, OMR_GET_CALLSITE(), javaVM);
192
(*hooks)->J9HookRegisterWithCallSite(hooks, J9HOOK_MM_OMR_GLOBAL_GC_END, tgcHookFreeListSummaryEnd, OMR_GET_CALLSITE(), javaVM);
193
194
return result;
195
}
196
197