-
Notifications
You must be signed in to change notification settings - Fork 751
/
Copy pathdmpmap.c
596 lines (517 loc) · 17.7 KB
/
dmpmap.c
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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
/*******************************************************************************
* Copyright IBM Corp. and others 1991
*
* 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] https://openjdk.org/legal/assembly-exception.html
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 OR GPL-2.0-only WITH OpenJDK-assembly-exception-1.0
*******************************************************************************/
#include <string.h>
#include "dmpsup.h"
#include "j9dmpnls.h"
#include "rasdump_internal.h"
#include "ut_j9dmp.h"
#define DG_SYSTEM_DUMPS "system+snap+tool"
typedef struct DgDumpCondition
{
char *name;
char *event;
char *eventString;
} DgDumpCondition;
/* Mapping for JAVA_DUMP_OPTS conditions */
static const DgDumpCondition dgConditions[] = {
/* note that the range suboption is placed at the end, it can be varied via JAVA_DUMP_OPTS...[COUNT] */
{ "ONDUMP", "user", "events=user,range=1..0" },
{ "ONERROR", "abort", "events=abort,range=1..0" },
{ "ONEXCEPTION", "gpf", "events=gpf,range=1..0" },
{ "ONINTERRUPT", "vmstop", "events=vmstop,filter=#129..192,range=1..0" },
{ "ONOUTOFMEMORY", "systhrow", "events=systhrow,filter=java/lang/OutOfMemoryError,range=1..4" }
/* note that 'ONANYSIGNAL' is handled explicitly in the mapDumpOptions) code below */
};
static const int numDumpConditions = sizeof(dgConditions) / sizeof(dgConditions[0]);
#define HEAP_KIND "heap"
#define JAVA_KIND "java"
#define SNAP_KIND "snap"
#define SYSTEM_KIND "system"
typedef struct DgDumpAction
{
char *name;
char *typeString;
} DgDumpAction;
/* Mapping for JAVA_DUMP_OPTS actions */
static const DgDumpAction dgActions[] = {
{ "JAVADUMP", JAVA_KIND },
{ "HEAPDUMP", HEAP_KIND },
{ "SYSDUMP", DG_SYSTEM_DUMPS },
{ "ALL", DG_SYSTEM_DUMPS "+heap+java+jit" },
{ "NONE", "none" },
{"SNAPDUMP", "snap"},
#ifdef J9ZOS390
{ "CEEDUMP", "ceedump" },
#endif
};
static const int numDumpActions = sizeof(dgActions) / sizeof(dgActions[0]);
/* Filter string used for some default OutOfMemory dump options */
#define SYSTHROW_OOM_1_4 "events=systhrow,range=1..4,filter=java/lang/OutOfMemoryError"
typedef struct DgDumpEnvSwitch
{
char *name;
char *typeString;
char *onOpt;
char *offOpt;
} DgDumpEnvSwitch;
/* Mapping for RAS dump environment variables. Note that these are in precedence order
* (later options take precedence over earlier ones in the table)
*/
static const DgDumpEnvSwitch dgSwitches[] = {
{
/* name */ "DISABLE_JAVADUMP",
/* kind */ JAVA_KIND,
/* on */ "none",
/* off */ NULL
},{
/* name */ "IBM_HEAPDUMP",
/* kind */ HEAP_KIND,
/* on */ "events=user+gpf",
/* off */ "none"
},{
/* name */ "IBM_HEAP_DUMP",
/* kind */ HEAP_KIND,
/* on */ "events=user+gpf",
/* off */ "none"
},{
/* name */ "IBM_JAVADUMP_OUTOFMEMORY",
/* kind */ JAVA_KIND,
/* on */ SYSTHROW_OOM_1_4,
/* off */ "none"
},{
/* name */ "IBM_HEAPDUMP_OUTOFMEMORY",
/* kind */ HEAP_KIND,
/* on */ SYSTHROW_OOM_1_4,
/* off */ "none"
},{
/* name */ "IBM_SNAPDUMP_OUTOFMEMORY",
/* kind */ SNAP_KIND,
/* on */ SYSTHROW_OOM_1_4,
/* off */ "none"
},{
/* name */ "J9NO_DUMPS",
/* kind */ DG_SYSTEM_DUMPS "+console+heap+java",
/* on */ "none",
/* off */ NULL
}
};
typedef struct OomDefaultSetting
{
const char *typeString;
const char *onOpt;
} OomDefaultSetting;
static const OomDefaultSetting oomDefaultTable[] = {
{
HEAP_KIND,
SYSTHROW_OOM_1_4
},
{
JAVA_KIND,
SYSTHROW_OOM_1_4
},
{
SNAP_KIND,
SYSTHROW_OOM_1_4
},
{
SYSTEM_KIND,
"events=systhrow,range=1..1,filter=java/lang/OutOfMemoryError,request=exclusive+compact+prepwalk"
}
};
static const UDATA numDumpEnvSwitches = sizeof(dgSwitches) / sizeof(dgSwitches[0]);
static const UDATA numOomSettings = sizeof(oomDefaultTable) / sizeof(oomDefaultTable[0]);
typedef struct DgDumpEnvSetting
{
char *name;
char *typeString;
char *prefixOpt;
} DgDumpEnvSetting;
/* Mapping for RAS dump filter environment variables */
static const DgDumpEnvSetting dgSettings[] = {
{
/* name */ "IBM_XE_COE_NAME",
/* kind */ DG_SYSTEM_DUMPS "+java",
/* prefix */ "events=throw,range=1..4,filter="
}
};
static const int numDumpEnvSettings = ( sizeof(dgSettings) / sizeof(DgDumpEnvSetting) );
typedef struct DgDumpEnvDefault
{
char *name;
char *typeString;
char *defaultOpt;
} DgDumpEnvDefault;
/* Agent defaults */
static const DgDumpEnvDefault dgDefaults[] = {
{
/* name */ "IBM_JAVA_HEAPDUMP_TEXT",
/* kind */ HEAP_KIND,
/* default */ "opts=CLASSIC"
},{
/* name */ "IBM_JAVA_HEAPDUMP_TEST",
/* kind */ HEAP_KIND,
/* default */ "opts=PHD+CLASSIC"
},
};
static const int numDumpEnvDefaults = ( sizeof(dgDefaults) / sizeof(DgDumpEnvDefault) );
/* Function to process the migration RAS environment variables IBM_JAVA_HEAPDUMP_TEXT
* and IBM_JAVA_HEAPDUMP_TEST (heapdump type options)
*/
omr_error_t
mapDumpDefaults(J9JavaVM *vm, J9RASdumpOption agentOpts[], IDATA *agentNum)
{
IDATA i, kind;
PORT_ACCESS_FROM_JAVAVM(vm);
char buf[J9_MAX_DUMP_PATH];
char *defaultString;
char *finalArg;
for (i = 0; i < numDumpEnvDefaults; i++) {
buf[0] = '\0';
j9sysinfo_get_env(dgDefaults[i].name, buf, J9_MAX_DUMP_PATH);
switch ( buf[0] ) {
case '\0' :
case '0' :
case 'F' :
case 'f' :
defaultString = NULL;
break;
default :
defaultString = dgDefaults[i].defaultOpt;
break;
}
/* Apply default? */
if ( defaultString ) {
char *typeString = dgDefaults[i].typeString;
strcpy(buf, "defaults:");
strcat(buf, defaultString);
/* Handle multiple dump types */
while ( (kind = scanDumpType(&typeString)) >= 0 ) {
finalArg = j9mem_allocate_memory(strlen(buf) + 1, OMRMEM_CATEGORY_VM);
if(!finalArg) {
return OMR_ERROR_INTERNAL;
}
strcpy(finalArg, buf);
agentOpts[*agentNum].kind = kind;
agentOpts[*agentNum].args = finalArg;
agentOpts[*agentNum].flags = J9RAS_DUMP_OPT_ARGS_ALLOC;
agentOpts[*agentNum].pass = J9RAS_DUMP_OPTS_PASS_ONE;
(*agentNum)++;
}
}
}
return OMR_ERROR_NONE;
}
/* Function to process the main migration RAS environment variables JAVA_DUMP_OPTS and
* JAVA_DUMP_TOOL. Note that the older RAS environment variables (DISABLE_JAVADUMP etc)
* are processed earlier in function mapDumpSwitches().
*/
omr_error_t
mapDumpOptions(J9JavaVM *vm, J9RASdumpOption agentOpts[], IDATA *agentNum)
{
IDATA i, j;
IDATA kind, saveAgentNum;
char *cursor;
PORT_ACCESS_FROM_JAVAVM(vm);
char buf[J9_MAX_DUMP_PATH] = "";
if (j9sysinfo_get_env("JAVA_DUMP_OPTS", buf, J9_MAX_DUMP_PATH) == -1) {
/* JAVA_DUMP_OPTS was not set, so nothing to do */
return OMR_ERROR_NONE;
}
saveAgentNum = *agentNum;
/* Rule for JAVA_DUMP_OPTS is to parse for ONANYSIGNAL first */
if ( NULL != (cursor = strstr(buf, "ONANYSIGNAL")) ) {
cursor += strlen("ONANYSIGNAL");
if ( *cursor == '(' && ( strchr(cursor, ')')) != NULL ) {
/* Loop to map all the supported conditions (for ONANYSIGNAL) */
for (i = 0; i < numDumpConditions; i++) {
/* Disable any default or earlier envvars for this condition */
for (j = 0; j < saveAgentNum; j++) {
if (strstr(agentOpts[j].args, dgConditions[i].event)) {
agentOpts[j].kind = J9RAS_DUMP_OPT_DISABLED;
}
}
/* Map any specified actions for this condition */
mapDumpActions(vm, agentOpts, agentNum, cursor, i);
}
}
}
/* Then parse for first occurrence (only) of each individual condition */
for (i = 0; i < numDumpConditions; i++) {
if ( NULL != (cursor = strstr(buf, dgConditions[i].name)) ) {
cursor += strlen(dgConditions[i].name);
if ( *cursor == '(' && ( strchr(cursor, ')')) != NULL ) {
/* Disable any default or earlier envvars for this condition */
for (j = 0; j < saveAgentNum; j++) {
if (strstr(agentOpts[j].args, dgConditions[i].event)) {
agentOpts[j].kind = J9RAS_DUMP_OPT_DISABLED;
}
}
/* Map any specified actions for this condition */
mapDumpActions(vm, agentOpts, agentNum, cursor, i);
}
}
}
/* Don't map tool dumps if environment variable is missing */
if (j9sysinfo_get_env("JAVA_DUMP_TOOL", NULL, 0) == -1) {
char *typeString = "tool";
kind = scanDumpType(&typeString);
for (i = 0; i < *agentNum; i++) {
if (agentOpts[i].kind == kind) {
agentOpts[i].kind = J9RAS_DUMP_OPT_DISABLED;
}
}
}
return OMR_ERROR_NONE;
}
/* Function to process JAVA_DUMP_OPTS actions. These are multiple comma-separate dump types, with and
* optional dump count, e.g. JAVA_DUMP_OPTS=ONERROR(JAVADUMP,SYSDUMP,HEAPDUMP[2])
*/
omr_error_t
mapDumpActions(J9JavaVM *vm, J9RASdumpOption agentOpts[], IDATA *agentNum, char *buf, IDATA condition)
{
IDATA i, j;
IDATA kind, countChars, length;
char *actionsRHS, *countRHS, *typeString;
char *eventString = NULL;
BOOLEAN allocatedEventStringAlreadyUsed = FALSE;
PORT_ACCESS_FROM_JAVAVM(vm);
actionsRHS = strchr(buf, ')');
for (i = 0; i < numDumpActions; i++) {
char *cursor = strstr(buf, dgActions[i].name);
if ( NULL == cursor || cursor > actionsRHS ) {
continue;
}
/* JAVA_DUMP_OPT action was found, translate it into -Xdump type(s) or 'none' */
typeString = dgActions[i].typeString;
if ( strcmp(typeString, "none") == 0 ) {
/* just delete all earlier settings for this event type (condition) */
for (j = 0; j < *agentNum; j++) {
if (strstr(agentOpts[j].args, dgConditions[condition].event)) {
agentOpts[j].kind = J9RAS_DUMP_OPT_DISABLED;
}
}
continue; /* (NONE,....) is honoured so continue loop */
}
/* We found a JAVA_DUMP_OPTS action, now get and process the dump count, if any */
countChars = 0;
cursor += strlen(dgActions[i].name);
if (*cursor == '[') { /* found a count parameter for this action */
countRHS = strchr(cursor, ']');
cursor++;
if ( countRHS >= cursor && countRHS < actionsRHS) { /* valid dump count found */
size_t eventStringLength = strlen(dgConditions[condition].eventString);
countChars = countRHS - cursor;
/* allocate a string for the mapped event string with the count chars appended */
length = eventStringLength + countChars;
eventString = j9mem_allocate_memory(length, OMRMEM_CATEGORY_VM);
if (NULL == eventString) {
j9tty_err_printf(PORTLIB,
"Could not allocate memory to handle JAVA_DUMP_OPTS dump count option, option ignored.\n");
countChars = 0;
} else {
/* eventString ends with "..0"; the '0' is replaced by countChars */
memcpy(eventString, dgConditions[condition].eventString, eventStringLength - 1);
memcpy(eventString + eventStringLength - 1, cursor, countChars);
eventString[length - 1] = '\0';
}
}
}
/* Now set up the dump type and event string, for multiple dump actions */
while ( (kind = scanDumpType(&typeString)) >= 0 ) {
agentOpts[*agentNum].kind = kind;
if (countChars) {
/* there was a dump count specified, so we use the locally allocated event string the first time, and dup it subsequent times*/
if(allocatedEventStringAlreadyUsed) {
/*We have to dupe the event string so the free logic later won't double-free. The original version has already been used*/
agentOpts[*agentNum].flags = J9RAS_DUMP_OPT_ARGS_ALLOC;
agentOpts[*agentNum].args = j9mem_allocate_memory(strlen(eventString) + 1, OMRMEM_CATEGORY_VM);
if(NULL == agentOpts[*agentNum].args) {
j9tty_err_printf(PORTLIB,
"Could not allocate memory to handle JAVA_DUMP_OPTS dump count option, option ignored (extra copy failed).\n");
countChars = 0;
agentOpts[*agentNum].args = dgConditions[condition].eventString;
agentOpts[*agentNum].flags = J9RAS_DUMP_OPT_ARGS_STATIC;
} else {
strcpy(agentOpts[*agentNum].args,eventString);
}
} else {
/*First time through - use the allocated event string*/
agentOpts[*agentNum].args = eventString;
agentOpts[*agentNum].flags = J9RAS_DUMP_OPT_ARGS_ALLOC;
allocatedEventStringAlreadyUsed = TRUE;
}
} else {
/* no dump count specified, use the statically defined event string */
agentOpts[*agentNum].args = dgConditions[condition].eventString;
agentOpts[*agentNum].flags = J9RAS_DUMP_OPT_ARGS_STATIC;
}
(*agentNum)++;
}
} /* end for (i = 0; i < DG_DUMP_ACTIONS; i++) */
return OMR_ERROR_NONE;
}
/* Function to process the older RAS environment variables (DISABLE_JAVADUMP etc). Note that
* the JAVA_DUMP_OPTS and JAVA_DUMP_TOOL environment variables are processed separately (later)
* in function mapDumpOptions().
*/
omr_error_t
mapDumpSwitches(J9JavaVM *vm, J9RASdumpOption agentOpts[], IDATA *agentNum)
{
UDATA i = 0;
PORT_ACCESS_FROM_JAVAVM(vm);
char *optionString, *typeString;
char buf[J9_MAX_DUMP_PATH];
BOOLEAN offSelected;
for (i = 0; i < numDumpEnvSwitches; i++) {
buf[0] = '\0';
j9sysinfo_get_env(dgSwitches[i].name, buf, J9_MAX_DUMP_PATH);
switch ( buf[0] ) {
case '\0' :
optionString = NULL;
offSelected = FALSE;
break;
case '0' :
case 'F' :
case 'f' :
offSelected = TRUE;
optionString = dgSwitches[i].offOpt;
break;
default :
offSelected = FALSE;
optionString = dgSwitches[i].onOpt;
break;
}
typeString = dgSwitches[i].typeString;
if (offSelected &&
((strcmp(dgSwitches[i].name, "IBM_HEAPDUMP_OUTOFMEMORY") == 0) ||
(strcmp(dgSwitches[i].name, "IBM_JAVADUMP_OUTOFMEMORY") == 0) ||
(strcmp(dgSwitches[i].name, "IBM_SNAPDUMP_OUTOFMEMORY") == 0) )) {
/* special case processing for specific OOM environment variables */
/* The "off" option for these variables should only disable the default dump */
/* agents that match the option values. Other agents for the same dump type */
/* should remain untouched. */
IDATA j = 0;
IDATA disableKind = scanDumpType(&typeString);
/* walk through the agentOpts and disable those that match the type and options */
for (j = 0; j < *agentNum; j++) {
if (NULL != agentOpts[j].args) {
if (agentOpts[j].kind == disableKind) {
if (strcmp(agentOpts[j].args, dgSwitches[i].onOpt) == 0) {
agentOpts[j].kind = J9RAS_DUMP_OPT_DISABLED;
}
}
}
}
} else {
IDATA kind = -1;
/* set up the dump type and event string for multiple dump actions */
while ( optionString && (kind = scanDumpType(&typeString)) >= 0 ) {
agentOpts[*agentNum].kind = kind;
agentOpts[*agentNum].args = optionString;
agentOpts[*agentNum].flags = J9RAS_DUMP_OPT_ARGS_STATIC;
(*agentNum)++;
}
}
}
return OMR_ERROR_NONE;
}
/**
* Fully disable heap, java, snap, and system dumps on out of memory
* @param @agentOpts dump agent options
* @param agentNum number of agents
*/
void
disableDumpOnOutOfMemoryError(J9RASdumpOption agentOpts[], IDATA agentNum)
{
UDATA kindCursor = 0;
for (kindCursor = 0; kindCursor < numOomSettings; ++kindCursor) {
char *typeString = (char *) oomDefaultTable[kindCursor].typeString;
IDATA disableKind = scanDumpType(&typeString);
IDATA j = 0;
for (j = 0; j < agentNum; j++) {
if ((NULL != agentOpts[j].args)
&& (agentOpts[j].kind == disableKind)
&& (strcmp(agentOpts[j].args, oomDefaultTable[kindCursor].onOpt) == 0)) {
agentOpts[j].kind = J9RAS_DUMP_OPT_DISABLED;
}
}
}
}
/**
* Fully enable heap, java, snap, and system dumps on out of memory
* @param @agentOpts dump agent options
* @param agentNum pointer to number of agents, updated by reference
*/
void
enableDumpOnOutOfMemoryError(J9RASdumpOption agentOpts[], IDATA *agentNum)
{
UDATA kindCursor = 0;
for (kindCursor = 0; kindCursor < numOomSettings; ++kindCursor) {
char *typeString = (char *) oomDefaultTable[kindCursor].typeString;
IDATA enableKind = scanDumpType(&typeString);
if (enableKind < 0) {
continue;
}
agentOpts[*agentNum].kind = enableKind;
agentOpts[*agentNum].args = (char *) oomDefaultTable[kindCursor].onOpt;
agentOpts[*agentNum].flags = J9RAS_DUMP_OPT_ARGS_STATIC;
agentOpts[*agentNum].pass = J9RAS_DUMP_OPTS_PASS_ONE;
*agentNum += 1;
}
}
/* Function to process additional RAS environment variable IBM_XE_COE_NAME
* (support for dump on filtered exception).
*/
omr_error_t
mapDumpSettings(J9JavaVM *vm, J9RASdumpOption agentOpts[], IDATA *agentNum)
{
PORT_ACCESS_FROM_JAVAVM(vm);
IDATA i = 0;
char buf[J9_MAX_DUMP_PATH];
for (i = 0; i < numDumpEnvSettings; i++) {
IDATA len = strlen(dgSettings[i].prefixOpt);
Assert_dump_true(len < J9_MAX_DUMP_PATH);
memcpy(buf, dgSettings[i].prefixOpt, len);
/* Tack on user setting */
if (j9sysinfo_get_env(dgSettings[i].name, buf + len, J9_MAX_DUMP_PATH - len) == 0) {
char *typeString = dgSettings[i].typeString;
/* Handle multiple dump types */
for (;;) {
IDATA kind = scanDumpType(&typeString);
char *finalArg = NULL;
if (kind < 0) {
break;
}
finalArg = j9mem_allocate_memory(strlen(buf) + 1, OMRMEM_CATEGORY_VM);
if (NULL == finalArg) {
return OMR_ERROR_INTERNAL;
}
strcpy(finalArg, buf);
agentOpts[*agentNum].kind = kind;
agentOpts[*agentNum].args = finalArg;
agentOpts[*agentNum].flags = J9RAS_DUMP_OPT_ARGS_ALLOC;
(*agentNum)++;
}
}
}
return OMR_ERROR_NONE;
}