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