Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/gc_verbose_java/VerboseJava.cpp
5985 views
1
/*******************************************************************************
2
* Copyright (c) 2001, 2019 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
#include "j9.h"
23
#include "j9cfg.h"
24
#include "mmhook.h"
25
26
#include "AtomicOperations.hpp"
27
#include "Base.hpp"
28
#include "GCExtensions.hpp"
29
#include "VerboseEventStream.hpp"
30
#include "VerboseOutputAgent.hpp"
31
#include "VerboseWriter.hpp"
32
#include "VerboseManagerJava.hpp"
33
#include "VerboseManagerOld.hpp"
34
35
#include "gcutils.h"
36
#include "modronnls.h"
37
38
#include <string.h>
39
40
#include "EnvironmentBase.hpp"
41
42
extern "C" {
43
44
static UDATA gcDebugVerboseStartupLogging(J9JavaVM *javaVM, char* filename, UDATA numFiles, UDATA numCycles);
45
static void gcDebugVerboseShutdownLogging(J9JavaVM *javaVM, UDATA releaseVerboseStructures);
46
static void gcDumpMemorySizes(J9JavaVM *javaVM);
47
static UDATA configureVerbosegc(J9JavaVM *javaVM, int enable, char* filename, UDATA numFiles, UDATA numCycles);
48
static UDATA queryVerbosegc(J9JavaVM *javaVM);
49
50
/**
51
* Verbose Function table.
52
*/
53
J9MemoryManagerVerboseInterface functionTable = {
54
gcDebugVerboseStartupLogging,
55
gcDebugVerboseShutdownLogging,
56
gcDumpMemorySizes,
57
configureVerbosegc,
58
queryVerbosegc
59
};
60
61
/**
62
* Initializes the verbose function table.
63
*/
64
void
65
initializeVerboseFunctionTable(J9JavaVM *javaVM)
66
{
67
J9MemoryManagerVerboseInterface *mmFuncTable;
68
J9MemoryManagerVerboseInterface *verboseTable = &functionTable;
69
70
mmFuncTable = (J9MemoryManagerVerboseInterface *)javaVM->memoryManagerFunctions->getVerboseGCFunctionTable(javaVM);
71
72
mmFuncTable->gcDebugVerboseStartupLogging = verboseTable->gcDebugVerboseStartupLogging;
73
mmFuncTable->gcDebugVerboseShutdownLogging = verboseTable->gcDebugVerboseShutdownLogging;
74
mmFuncTable->gcDumpMemorySizes = verboseTable->gcDumpMemorySizes;
75
mmFuncTable->configureVerbosegc = verboseTable->configureVerbosegc;
76
mmFuncTable->queryVerbosegc = verboseTable->queryVerbosegc;
77
}
78
79
static UDATA
80
configureVerbosegc(J9JavaVM *javaVM, int enable, char* filename, UDATA numFiles, UDATA numCycles)
81
{
82
MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(javaVM);
83
MM_VerboseManagerBase *manager = extensions->verboseGCManager;
84
85
if (!manager && !enable) {
86
/* they're turning verbosegc off, but it's never been started?! */
87
return 1;
88
}
89
90
if (!manager) {
91
/* startup the verbosegc manager */
92
MM_EnvironmentBase env(javaVM->omrVM);
93
if (extensions->verboseNewFormat) {
94
manager = MM_VerboseManagerJava::newInstance(&env, javaVM->omrVM);
95
} else {
96
/* Used with -Xgc:verboseFormat:deprecated */
97
manager = MM_VerboseManagerOld::newInstance(&env, javaVM->omrVM);
98
}
99
if (manager) {
100
(MM_GCExtensions::getExtensions(javaVM))->verboseGCManager = manager;
101
} else {
102
return 0;
103
}
104
manager = (MM_GCExtensions::getExtensions(javaVM))->verboseGCManager;
105
}
106
107
if (!manager->configureVerboseGC(javaVM->omrVM, filename, numFiles, numCycles)) {
108
return 0;
109
}
110
111
if (enable) {
112
manager->enableVerboseGC();
113
} else {
114
manager->disableVerboseGC();
115
}
116
117
return 1;
118
}
119
120
/**
121
* Query whether verbosegc is currently enabled.
122
* Return the number of output agents that are currently enabled.
123
*/
124
static UDATA
125
queryVerbosegc(J9JavaVM *javaVM)
126
{
127
MM_VerboseManagerBase *manager = (MM_GCExtensions::getExtensions(javaVM))->verboseGCManager;
128
129
if (NULL != manager) {
130
return manager->countActiveOutputHandlers();
131
}
132
133
return 0;
134
}
135
136
/**
137
* Allocates and initializes the verbose gc infrastructure.
138
* @param filename The name of the file or output stream to log to.
139
* @param numFiles The number of files to log to.
140
* @param numCycles The number of gc cycles to log to each file.
141
* @return 1 if successful, 0 otherwise.
142
*/
143
static UDATA
144
gcDebugVerboseStartupLogging(J9JavaVM *javaVM, char* filename, UDATA numFiles, UDATA numCycles)
145
{
146
return configureVerbosegc(javaVM, 1, filename, numFiles, numCycles);
147
}
148
149
/**
150
* Bring down the verbose gc infrastructure.
151
* Closes the verbose gc output streams and if safe releases the infrastructure.
152
* @param releaseVerboseStructures Indicator of whether it is safe to free the infrastructure.
153
* @return Pointer to the allocated memory.
154
*/
155
static void
156
gcDebugVerboseShutdownLogging(J9JavaVM *javaVM, UDATA releaseVerboseStructures)
157
{
158
MM_EnvironmentBase env(javaVM->omrVM);
159
MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(javaVM);
160
161
if (NULL == extensions) {
162
return;
163
}
164
165
MM_VerboseManagerBase *manager = extensions->verboseGCManager;
166
167
if (NULL == manager) {
168
return;
169
}
170
171
manager->closeStreams(&env);
172
173
if (releaseVerboseStructures) {
174
manager->kill(&env);
175
extensions->verboseGCManager = NULL;
176
}
177
}
178
179
/**
180
* Dump sizes with the correct qualifier.
181
* @param byteSize The size in bytes.
182
* @param optionName The name of the option.
183
* @param module_name The NLS module to look in
184
* @param message_num The message number to get from the module
185
*/
186
void
187
gcDumpQualifiedSize(J9PortLibrary* portLib, UDATA byteSize, const char* optionName, U_32 module_name, U_32 message_num)
188
{
189
char buffer[16] = {'\0'};
190
UDATA size = 0;
191
UDATA paramSize = 0;
192
const char* qualifier = NULL;
193
const char* optionDescription = NULL;
194
PORT_ACCESS_FROM_PORT(portLib);
195
196
/* Obtain the qualified size (e.g. 2k) */
197
size = byteSize;
198
qualifiedSize(&size, &qualifier);
199
200
/* look up the appropriate translation */
201
optionDescription = OMRPORT_FROM_J9PORT(PORTLIB)->nls_lookup_message(
202
OMRPORT_FROM_J9PORT(PORTLIB),
203
J9NLS_DO_NOT_APPEND_NEWLINE | J9NLS_DO_NOT_PRINT_MESSAGE_TAG,
204
module_name,
205
message_num,
206
NULL);
207
208
/* Format output String */
209
paramSize = j9str_printf(PORTLIB, buffer, 16, "%zu%s", size, qualifier);
210
paramSize = 15 - paramSize;
211
paramSize += strlen(optionDescription);
212
paramSize -= strlen(optionName);
213
j9tty_printf(PORTLIB, " %s%s %*s\n", optionName, buffer, paramSize, optionDescription);
214
215
return;
216
}
217
218
/**
219
* Dump gc memory sizes.
220
* Output is intentionally ordered the same as "j9 -X"
221
*/
222
static void
223
gcDumpMemorySizes(J9JavaVM *javaVM)
224
{
225
MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(javaVM);
226
UDATA *pageSizes = NULL;
227
PORT_ACCESS_FROM_JAVAVM(javaVM);
228
229
gcDumpQualifiedSize(PORTLIB, javaVM->ramClassAllocationIncrement, "-Xmca", J9NLS_GC_VERB_SIZES_XMCA);
230
gcDumpQualifiedSize(PORTLIB, javaVM->romClassAllocationIncrement, "-Xmco", J9NLS_GC_VERB_SIZES_XMCO);
231
232
#if defined(OMR_GC_COMPRESSED_POINTERS)
233
if (J9JAVAVM_COMPRESS_OBJECT_REFERENCES(javaVM)) {
234
gcDumpQualifiedSize(PORTLIB, extensions->suballocatorInitialSize, "-Xmcrs", J9NLS_GC_VERB_SIZES_XMCRS);
235
} else
236
#endif /* defined(OMR_GC_COMPRESSED_POINTERS) */
237
{
238
gcDumpQualifiedSize(PORTLIB, 0, "-Xmcrs", J9NLS_GC_VERB_SIZES_XMCRS);
239
}
240
241
if (extensions->isVLHGC()) {
242
#if defined (J9VM_GC_VLHGC)
243
gcDumpQualifiedSize(PORTLIB, extensions->tarokIdealEdenMinimumBytes, "-Xmns", J9NLS_GC_VERB_SIZES_XMNS);
244
gcDumpQualifiedSize(PORTLIB, extensions->tarokIdealEdenMaximumBytes, "-Xmnx", J9NLS_GC_VERB_SIZES_XMNX);
245
#endif /* J9VM_GC_VLHGC */
246
} else if (!extensions->isMetronomeGC()) {
247
gcDumpQualifiedSize(PORTLIB, extensions->newSpaceSize, "-Xmns", J9NLS_GC_VERB_SIZES_XMNS);
248
gcDumpQualifiedSize(PORTLIB, extensions->maxNewSpaceSize, "-Xmnx", J9NLS_GC_VERB_SIZES_XMNX);
249
}
250
gcDumpQualifiedSize(PORTLIB, extensions->initialMemorySize, "-Xms", J9NLS_GC_VERB_SIZES_XMS);
251
if (!(extensions->isMetronomeGC())) {
252
gcDumpQualifiedSize(PORTLIB, extensions->oldSpaceSize, "-Xmos", J9NLS_GC_VERB_SIZES_XMOS);
253
gcDumpQualifiedSize(PORTLIB, extensions->maxOldSpaceSize, "-Xmox", J9NLS_GC_VERB_SIZES_XMOX);
254
}
255
256
if (extensions->allocationIncrementSetByUser) {
257
gcDumpQualifiedSize(PORTLIB, extensions->allocationIncrement, "-Xmoi", J9NLS_GC_VERB_SIZES_XMOI);
258
}
259
gcDumpQualifiedSize(PORTLIB, extensions->memoryMax, "-Xmx", J9NLS_GC_VERB_SIZES_XMX);
260
261
if (extensions->isStandardGC()) {
262
#if defined(J9VM_GC_MODRON_SCAVENGER)
263
gcDumpQualifiedSize(PORTLIB, extensions->rememberedSet.getGrowSize(), "-Xmr", J9NLS_GC_VERB_SIZES_XMR);
264
#endif /* J9VM_GC_GENERATIONAL */
265
}
266
267
if (0 != extensions->softMx) {
268
gcDumpQualifiedSize(PORTLIB, extensions->softMx, "-Xsoftmx", J9NLS_GC_VERB_SIZES_XSOFTMX);
269
}
270
271
272
pageSizes = j9vmem_supported_page_sizes();
273
/* If entry at index 1 of supported page size array is non zero, then large pages are available */
274
{
275
const char* optionDescription = NULL;
276
UDATA *pageFlags = NULL;
277
UDATA pageIndex = 0;
278
UDATA size = 0;
279
const char *qualifier = NULL;
280
const char* optionName = "-Xlp:objectheap:pagesize=";
281
char postOption[16] = {'\0'};
282
283
/* Obtain the qualified size (e.g. 4K) */
284
size = extensions->requestedPageSize;
285
qualifiedSize(&size, &qualifier);
286
287
/* look up the appropriate translation */
288
optionDescription = j9nls_lookup_message(
289
J9NLS_DO_NOT_APPEND_NEWLINE | J9NLS_DO_NOT_PRINT_MESSAGE_TAG,
290
J9NLS_GC_VERB_SIZES_XLP,
291
NULL);
292
293
if (J9PORT_VMEM_PAGE_FLAG_NOT_USED != extensions->requestedPageFlags) {
294
j9str_printf(PORTLIB, postOption, 16, ",%s", getPageTypeString(extensions->requestedPageFlags));
295
}
296
297
j9tty_printf(PORTLIB, " %s%zu%s%s\t %s\n", optionName, size, qualifier, postOption, optionDescription);
298
299
pageFlags = j9vmem_supported_page_flags();
300
301
optionDescription = j9nls_lookup_message(J9NLS_DO_NOT_APPEND_NEWLINE | J9NLS_DO_NOT_PRINT_MESSAGE_TAG,
302
J9NLS_GC_VERB_SIZES_AVAILABLE_XLP,
303
NULL);
304
305
j9tty_printf(PORTLIB, " %*s %s", 15, " ", optionDescription);
306
307
for(pageIndex = 0; 0 != pageSizes[pageIndex]; pageIndex++) {
308
const char *pageTypeString = NULL;
309
size = pageSizes[pageIndex];
310
qualifiedSize(&size, &qualifier);
311
j9tty_printf(PORTLIB, "\n %*s %zu%s", 15, " ", size, qualifier);
312
if (J9PORT_VMEM_PAGE_FLAG_NOT_USED != pageFlags[pageIndex]) {
313
pageTypeString = getPageTypeString(pageFlags[pageIndex]);
314
}
315
if (NULL != pageTypeString) {
316
j9tty_printf(PORTLIB, " %s", pageTypeString);
317
}
318
}
319
j9tty_printf(PORTLIB, "\n");
320
}
321
322
return;
323
}
324
325
} /* extern "C" */
326
327