-
Notifications
You must be signed in to change notification settings - Fork 751
/
Copy pathdmpsup.c
1732 lines (1487 loc) · 54.2 KB
/
dmpsup.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
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*******************************************************************************
* 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 "dmpsup.h"
#include "rasdump_internal.h"
#include "jvminit.h"
#include "j9consts.h"
#include "j9dump.h"
#include "j9dmpnls.h"
#include <string.h>
#include "omrmutex.h"
#include "j9port.h"
#include "jvmri.h"
#include "omrthread.h"
#include "omrlinkedlist.h"
#if defined(J9VM_PORT_OMRSIG_SUPPORT)
#include "omrsig.h"
#else /* defined(J9VM_PORT_OMRSIG_SUPPORT) */
#include <signal.h>
#endif /* defined(J9VM_PORT_OMRSIG_SUPPORT) */
#define _UTE_STATIC_
#include "ut_j9dmp.h"
#undef _UTE_STATIC_
/* Abort data */
static J9JavaVM *cachedVM = NULL;
/* config starts locked and we unlock it once the initial configuration is in place */
static UDATA rasDumpLockConfig = -1;
/* GLOBAL: dump agent bitvectors */
UDATA rasDumpAgentEnabled = (UDATA)-1;
char* dumpDirectoryPrefix = NULL;
#define MAX_DUMP_OPTS 128
#define MAX_INTERESTING_LENGTH 255
#if defined(J9ZOS390)
#if defined(J9VM_ENV_DATA64)
#include <__le_api.h>
#else
#include <leawi.h>
#include <ceeedcct.h>
#endif
#endif
/* Default -Xdump agent definitions. To allow env var modifications we don't merge these here, they
* will get merged later when the agents are loaded
*/
static const J9RASdefaultOption defaultAgents[] = {
{ "heap", "events=systhrow,range=1..4,filter=java/lang/OutOfMemoryError" },
{ "java", "events=gpf,range=1..0" },
{ "java", "events=user,range=1..0" },
{ "java", "events=abort,range=1..0" },
{ "java", "events=traceassert,range=1..0" },
{ "java", "events=systhrow,range=1..4,filter=java/lang/OutOfMemoryError" },
{ "java", "events=corruptcache,range=1..0" },
{ "snap", "events=gpf,range=1..0" },
{ "snap", "events=abort,range=1..0" },
{ "snap", "events=traceassert,range=1..0" },
{ "snap", "events=systhrow,range=1..4,filter=java/lang/OutOfMemoryError" },
{ "snap", "events=corruptcache,range=1..0"},
{ "system", "events=gpf,range=1..0" },
#ifdef J9ZOS390
{ "system", "events=user,range=1..0" },
#endif
{ "system", "events=abort,range=1..0" },
{ "system", "events=traceassert,range=1..0" },
{ "system", "events=corruptcache,range=1..0" },
/* System dumps added for OOM, all platforms. JTC-JAT LIR #17406 */
{ "system", "events=systhrow,range=1..1,filter=java/lang/OutOfMemoryError,request=exclusive+compact+prepwalk" },
#ifdef J9VM_INTERP_NATIVE_SUPPORT
{ "jit", "events=gpf,range=1..0" },
{ "jit", "events=abort,range=1..0" }
#endif /* J9VM_INTERP_NATIVE_SUPPORT */
};
static const int numDefaultAgents = ( sizeof(defaultAgents) / sizeof(J9RASdefaultOption) );
static omr_error_t shutdownDumpAgents (J9JavaVM *vm);
static omr_error_t popDumpFacade (J9JavaVM *vm);
static omr_error_t installAbortHandler (J9JavaVM *vm);
static omr_error_t showDumpAgents (J9JavaVM *vm);
static IDATA configureDumpAgents(J9JavaVM *vm, J9VMInitArgs *j9vm_args, BOOLEAN isBootup);
#if defined(J9VM_OPT_CRIU_SUPPORT)
static IDATA criuReloadXDumpAgents(J9JavaVM *vm, J9VMInitArgs *j9vm_args);
#endif /* defined(J9VM_OPT_CRIU_SUPPORT) */
static omr_error_t printDumpUsage (J9JavaVM *vm);
static omr_error_t pushDumpFacade (J9JavaVM *vm);
static void abortHandler (int sig);
static void initRasDumpGlobalStorage(J9JavaVM *vm);
static void freeRasDumpGlobalStorage(J9JavaVM *vm);
static void hookVmInitialized PROTOTYPE((J9HookInterface** hook, UDATA eventNum, void* eventData, void* userData));
#if defined(LINUX)
static J9RASSystemInfo *appendSystemInfoFromFile(J9JavaVM *vm, U_32 key, const char *fileName);
#endif /* defined(LINUX) */
#ifdef J9ZOS390
static IDATA processZOSDumpOptions(J9JavaVM *vm, J9RASdumpOption* agentOpts, int optIndex);
static void triggerAbend(void);
#endif
#if defined(J9VM_PORT_OMRSIG_SUPPORT) && defined(WIN32)
/*
* this code causes omrsig to be looked up dynamically and for the local functions to pass through to it.
*/
typedef sig_handler_t (*omrsig_primary_signal_Type)(int sig, sig_handler_t disp);
typedef int (*omrsig_handler_Type)(int sig, void *siginfo, void *uc);
static omrsig_primary_signal_Type omrsig_primary_signal_Static;
static omrsig_handler_Type omrsig_handler_Static;
static UDATA omrsigHandle;
BOOLEAN
loadOMRSIG(J9JavaVM *vm)
{
J9VMDllLoadInfo omrsigLoadInfo;
PORT_ACCESS_FROM_JAVAVM( vm );
memset(&omrsigLoadInfo, 0, sizeof(J9VMDllLoadInfo));
omrsigLoadInfo.loadFlags |= XRUN_LIBRARY;
strcpy((char *) &omrsigLoadInfo.dllName, "omrsig");
if (vm->internalVMFunctions->loadJ9DLL(vm, &omrsigLoadInfo) != TRUE) {
j9tty_err_printf(PORTLIB, "Can't open OMRSIG library\n");
return FALSE;
}
omrsigHandle = omrsigLoadInfo.descriptor;
j9sl_lookup_name(omrsigHandle, "omrsig_primary_signal", (UDATA *) &omrsig_primary_signal_Static, "IP");
j9sl_lookup_name(omrsigHandle, "omrsig_handler", (UDATA *) &omrsig_handler_Static, "IPP");
return TRUE;
}
void
unloadOMRSIG(J9PortLibrary *portLib)
{
PORT_ACCESS_FROM_PORT(portLib);
j9sl_close_shared_library(omrsigHandle);
omrsigHandle = 0;
}
sig_handler_t
omrsig_primary_signal(int sig, sig_handler_t disp)
{
if (NULL == omrsig_primary_signal_Static)
return NULL;
return omrsig_primary_signal_Static(sig, disp);
}
int
omrsig_handler(int sig, void *siginfo, void *uc)
{
if (NULL == omrsig_handler_Static)
return 0;
return omrsig_handler_Static(sig, siginfo, uc);
}
#endif
static void
abortHandler(int sig)
{
J9VMThread *vmThread = cachedVM ? cachedVM->internalVMFunctions->currentVMThread(cachedVM) : NULL;
#if defined(J9ZOS390)
BOOLEAN doTriggerAbend = FALSE;
#endif
#if defined(J9VM_PORT_OMRSIG_SUPPORT)
/* Chain to application handler */
if ( !vmThread || (vmThread && (cachedVM->sigFlags & J9_SIG_NO_SIG_CHAIN) == 0) ) {
omrsig_handler(sig, 0, 0);
}
#endif /* defined(J9VM_PORT_OMRSIG_SUPPORT) */
/* Re-install application abort handler */
OMRSIG_SIGNAL(SIGABRT, SIG_DFL);
/* To get the dumps we must ensure that this thread is attached to the vm. */
/* Also, we must have a valid cachedVM in order to get the attach to work. */
if (cachedVM && !vmThread) {
J9JavaVM* vm = cachedVM; /* local variable required by FIND_DLL_TABLE_ENTRY macro below */
J9VMDllLoadInfo *loadInfo = FIND_DLL_TABLE_ENTRY(J9_RAS_DUMP_DLL_NAME);
/* Only attempt to attach thread while JVM is up and running. JTC-JAT PR 86446 + PR 98920 */
if (loadInfo
&& (IS_STAGE_COMPLETED(loadInfo->completedBits, VM_INITIALIZATION_COMPLETE))
&& (!IS_STAGE_COMPLETED(loadInfo->completedBits, INTERPRETER_SHUTDOWN))
) {
JavaVMAttachArgs attachArgs;
attachArgs.version = JNI_VERSION_1_2;
attachArgs.name = "SIGABRT Thread";
attachArgs.group = NULL;
cachedVM->internalVMFunctions->AttachCurrentThreadAsDaemon((JavaVM *)cachedVM, (void **)&vmThread, &attachArgs);
}
}
#if defined(J9ZOS390)
if (NULL != cachedVM) {
if (J9_SIG_POSIX_COOPERATIVE_SHUTDOWN == (J9_SIG_POSIX_COOPERATIVE_SHUTDOWN & cachedVM->sigFlags)) {
doTriggerAbend = TRUE;
}
}
#endif /* defined(J9ZOS390) */
if ( vmThread ) {
PORT_ACCESS_FROM_JAVAVM(cachedVM);
/* Check if we are running on the Java stack, by comparing the address of a local variable against the lower
* and upper bounds of the Java stack. If we are on the Java stack it is not safe to run the RAS dump agents,
* so just issue a message here and drop out to let the OS handle the abort. JTC-JAT Problem Report 77991.
*/
J9JavaStack* javaStack = vmThread->stackObject;
UDATA* lowestSlot = J9_LOWEST_STACK_SLOT(vmThread);
UDATA* highestSlot = javaStack ? javaStack->end : NULL;
UDATA* localAddress = (UDATA*)&highestSlot;
if ((localAddress >= lowestSlot) && (localAddress < highestSlot)) {
/* Running on Java stack, do not attempt to produce RAS dumps */
j9nls_printf(PORTLIB, J9NLS_WARNING | J9NLS_STDERR, J9NLS_DMP_ABORT_ON_JAVA_STACK);
} else {
if (OMR_ERROR_NONE == J9DMP_TRIGGER(cachedVM, vmThread, J9RAS_DUMP_ON_ABORT_SIGNAL)) {
#if defined(J9ZOS390)
if (doTriggerAbend) {
triggerAbend();
/* unreachable */
}
#endif
/* RAS dump agents triggered OK, call exit not abort to avoid extra OS dumps, defect 148334 */
j9exit_shutdown_and_exit(1);
}
}
}
#if defined(J9ZOS390)
if (doTriggerAbend) {
triggerAbend();
/* unreachable */
}
#endif
/* Re-send abort signal (needed if it was an asynchronous request) */
abort();
}
#if defined(J9ZOS390)
static void
triggerAbend(void)
{
sigrelse(SIGABND); /* CMVC 191934: need to unblock sigabnd before issuing the abend call */
#if defined(J9VM_ENV_DATA64)
__cabend(PORT_ABEND_CODE, PORT_ABEND_REASON_CODE, PORT_ABEND_CLEANUP_CODE);
/* unreachable */
#else
/* 31-bit z/OS */
{
_INT4 code = PORT_ABEND_CODE;
_INT4 reason = PORT_ABEND_REASON_CODE;
_INT4 cleanup = PORT_ABEND_CLEANUP_CODE; /* normal termination processing */
CEE3AB2(&code, &reason, &cleanup);
/* unreachable */
}
#endif
}
#endif /* J9ZOS390 */
static omr_error_t
installAbortHandler(J9JavaVM *vm)
{
/* Handler can only map to one VM */
if ( cachedVM ) {
return OMR_ERROR_INTERNAL;
}
cachedVM = vm;
/* Install one-shot dump trigger */
OMRSIG_SIGNAL(SIGABRT, abortHandler);
return OMR_ERROR_NONE;
}
UDATA
lockConfigForUse(void)
{
while (1) {
IDATA currentValue = rasDumpLockConfig;
if (currentValue >= 0) {
if (compareAndSwapUDATA(&rasDumpLockConfig, currentValue, currentValue + 1) == currentValue) {
break;
}
}
omrthread_yield();
}
/* we block until we succeed so we only ever return true */
return 1;
}
UDATA
lockConfigForUpdate(void)
{
/* if the config is not currently in use then we can update it, otherwise let the caller know that
* the config is in use and they should try again later
*/
return compareAndSwapUDATA(&rasDumpLockConfig, 0, -1) == 0;
}
UDATA
unlockConfig(void)
{
while (1) {
IDATA currentValue = rasDumpLockConfig;
IDATA newValue = 0;
if (currentValue < 0) {
/* We're undoing an update lock or correcting a mangled state.
* We gamble on releasing with mangled state so that dumps don't become completely non functional
*/
newValue = 0;
} else if (currentValue > 0) {
newValue = currentValue - 1;
}
if (compareAndSwapUDATA(&rasDumpLockConfig, currentValue, newValue) == currentValue) {
break;
}
omrthread_yield();
}
/* we block until we succeed so we only ever return true */
return 1;
}
static omr_error_t
showDumpAgents(J9JavaVM *vm)
{
PORT_ACCESS_FROM_JAVAVM(vm);
J9RASdumpAgent *agent = NULL;
j9tty_err_printf(PORTLIB, "\nRegistered dump agents\n----------------------\n");
while (seekDumpAgent(vm, &agent, NULL) == OMR_ERROR_NONE)
{
printDumpAgent(vm, agent);
j9tty_err_printf(PORTLIB, "----------------------\n");
}
j9tty_err_printf(PORTLIB, "\n");
return OMR_ERROR_NONE;
}
static omr_error_t
storeDefaultData(J9JavaVM *vm)
{
J9RASdumpQueue *queue = (J9RASdumpQueue *)vm->j9rasDumpFunctions;
queue->defaultAgents = copyDumpAgentsQueue(vm, queue->agents);
if (queue->defaultAgents == NULL){
return OMR_ERROR_INTERNAL;
}
queue->defaultSettings = copyDumpSettingsQueue(vm, queue->settings);
if (queue->defaultSettings == NULL){
return OMR_ERROR_INTERNAL;
}
return OMR_ERROR_NONE;
}
#if defined(J9VM_OPT_CRIU_SUPPORT)
/**
* CRIU restore loads dump agents using an option file.
*
* @param[in] vm pointer to the J9JavaVM
* @param[in] vmArgs a J9VMInitArgs
*
* @return return J9VMDLLMAIN_OK if success, otherwise failures
*/
static IDATA
criuReloadXDumpAgents(J9JavaVM *vm, J9VMInitArgs *vmArgs)
{
/* similar with startup except at CRIU restore */
IDATA result = 0;
J9VMThread *vmThread = vm->mainThread;
Trc_trcengine_criu_criuReloadXDumpAgents_Entry(vmThread);
result = configureDumpAgents(vm, vmArgs, FALSE);
unlockConfig();
Trc_trcengine_criu_criuReloadXDumpAgents_Exit(vmThread, result);
return result;
}
#endif /* defined(J9VM_OPT_CRIU_SUPPORT) */
/**
* A helper method for configuring the RAS dump agents.
* Since Java 6 SR2 (VMDESIGN 1477), in increasing order of precedence:
* Default agents
* DISABLE_JAVADUMP, IBM_HEAPDUMP, IBM_HEAP_DUMP
* IBM_JAVADUMP_OUTOFMEMORY, IBM_HEAPDUMP_OUTOFMEMORY
* JAVA_DUMP_OPTS environment variable (including dump count parameter)
* -Xdump command-line options
* @param[in] vm pointer to the J9JavaVM
* @param[in] vmArgs a J9VMInitArgs
* @param[in] isBootup if this is bootup or CRIUR restore
*
* @return return J9VMDLLMAIN_OK if success, otherwise failures
*/
static IDATA
configureDumpAgents(J9JavaVM *vm, J9VMInitArgs *j9vm_args, BOOLEAN isBootup)
{
PORT_ACCESS_FROM_JAVAVM(vm);
IDATA i;
IDATA xdumpIndex = 0;
IDATA showAgents = 0;
RasDumpGlobalStorage *dumpGlobal = (RasDumpGlobalStorage *)vm->j9rasdumpGlobalStorage;
/* Record recognized agent options (R...L) */
J9RASdumpOption* agentOpts = NULL;
IDATA agentNum = 0;
IDATA kind = 0;
char *optionString = NULL;
/*
* -XX:[+-]HeapDumpOnOutOfMemoryError.
*/
IDATA heapDumpIndex = -1; /* index of the rightmost HeapDumpOnOutOfMemoryError option */
BOOLEAN processXXHeapDump = FALSE; /* either -XX:[+-]HeapDumpOnOutOfMemoryError is specified */
BOOLEAN enableXXHeapDump = FALSE; /* -XX:+HeapDumpOnOutOfMemoryError is selected */
/* -Xdump:help */
if ( FIND_AND_CONSUME_ARG(j9vm_args, EXACT_MATCH, VMOPT_XDUMP ":help", NULL) >= 0 )
{
printDumpUsage(vm);
return J9VMDLLMAIN_SILENT_EXIT_VM;
}
/* -Xdump:events */
if ( FIND_AND_CONSUME_ARG(j9vm_args, EXACT_MATCH, VMOPT_XDUMP ":events", NULL) >= 0 )
{
j9tty_err_printf(PORTLIB, "\nTrigger events:\n\n");
printDumpEvents( vm, J9RAS_DUMP_ON_ANY, 1 );
return J9VMDLLMAIN_SILENT_EXIT_VM;
}
/* -Xdump:request */
if ( FIND_AND_CONSUME_ARG(j9vm_args, EXACT_MATCH, VMOPT_XDUMP ":request", NULL) >= 0 )
{
j9tty_err_printf(PORTLIB, "\nAdditional VM requests:\n\n");
printDumpRequests( vm, (UDATA)-1, 1 );
return J9VMDLLMAIN_SILENT_EXIT_VM;
}
/* -Xdump:tokens */
if ( FIND_AND_CONSUME_ARG(j9vm_args, EXACT_MATCH, VMOPT_XDUMP ":tokens", NULL) >= 0 )
{
j9tty_err_printf(PORTLIB, "\nLabel tokens:\n\n");
printLabelSpec( vm );
return J9VMDLLMAIN_SILENT_EXIT_VM;
}
/* -Xdump:what */
if ( FIND_AND_CONSUME_ARG(j9vm_args, EXACT_MATCH, VMOPT_XDUMP ":what", NULL) >= 0 )
{
showAgents = 1;
}
/* -Xdump:noprotect */
if ( FIND_AND_CONSUME_ARG(j9vm_args, EXACT_MATCH, VMOPT_XDUMP ":noprotect", NULL) >= 0 )
{
dumpGlobal->noProtect = 1;
}
/* -Xdump:nofailover */
if ( FIND_AND_CONSUME_ARG(j9vm_args, EXACT_MATCH, VMOPT_XDUMP ":nofailover", NULL) >= 0 )
{
dumpGlobal->noFailover = 1;
}
/* -Xdump:dynamic ... grab hooks before the JIT turns them off */
if ( FIND_AND_CONSUME_ARG(j9vm_args, EXACT_MATCH, VMOPT_XDUMP ":dynamic", NULL) >= 0 )
{
rasDumpEnableHooks(vm, J9RAS_DUMP_ON_EXCEPTION_THROW | J9RAS_DUMP_ON_EXCEPTION_CATCH);
}
#if defined(OMR_CONFIGURABLE_SUSPEND_SIGNAL)
/* -Xdump:suspendwith */
xdumpIndex = FIND_AND_CONSUME_ARG(j9vm_args, STARTSWITH_MATCH, VMOPT_XDUMP ":suspendwith", NULL);
if (xdumpIndex >= 0) {
/* Get value of -Xdump:suspendwith */
const char *optName = VMOPT_XDUMP ":suspendwith=";
UDATA suspendwith = 0;
UDATA parseError = GET_INTEGER_VALUE_ARGS(j9vm_args, xdumpIndex, optName, suspendwith);
if (OPTION_OK != parseError) {
j9nls_printf(PORTLIB, J9NLS_ERROR | J9NLS_STDERR, J9NLS_DMP_INVALID_OR_RESERVED, optName);
printDumpUsage(vm);
return J9VMDLLMAIN_SILENT_EXIT_VM;
} else {
OMRPORT_ACCESS_FROM_OMRPORT(OMRPORT_FROM_J9PORT(privatePortLibrary));
int32_t result = omrintrospect_set_suspend_signal_offset((int32_t)suspendwith);
if (0 != result) {
if (J9PORT_ERROR_NOT_SUPPORTED_ON_THIS_PLATFORM == result) {
j9nls_printf(PORTLIB, J9NLS_ERROR | J9NLS_STDERR, J9NLS_DMP_UNSUPPORTED_ON_PLATFORM, "suspendwith");
} else {
j9nls_printf(PORTLIB, J9NLS_ERROR | J9NLS_STDERR, J9NLS_DMP_INVALID_OR_RESERVED, "suspendwith");
}
printDumpUsage(vm);
return J9VMDLLMAIN_SILENT_EXIT_VM;
}
}
}
#endif
/* process options controlling javadump symbol resolution */
{
IDATA noSymbols = FIND_AND_CONSUME_ARG(j9vm_args, EXACT_MATCH, VMOPT_XXNOSHOWNATIVESTACKSYMBOLS, NULL);
IDATA allSymbols = FIND_AND_CONSUME_ARG(j9vm_args, EXACT_MATCH, VMOPT_XXSHOWNATIVESTACKSYMBOLS_ALL, NULL);
IDATA basicSymbols = FIND_AND_CONSUME_ARG(j9vm_args, EXACT_MATCH, VMOPT_XXSHOWNATIVESTACKSYMBOLS_BASIC, NULL);
/* set default */
dumpGlobal->showNativeSymbols = J9RAS_JAVADUMP_SHOW_NATIVE_STACK_SYMBOLS_BASIC;
if ((noSymbols > allSymbols) && (noSymbols > basicSymbols)) {
/* no symbols requested */
dumpGlobal->showNativeSymbols = J9RAS_JAVADUMP_SHOW_NATIVE_STACK_SYMBOLS_NONE;
} else if ((allSymbols > basicSymbols) && (allSymbols > noSymbols)) {
/* all symbols requested */
dumpGlobal->showNativeSymbols = J9RAS_JAVADUMP_SHOW_NATIVE_STACK_SYMBOLS_ALL;
}
}
agentOpts = j9mem_allocate_memory(sizeof(J9RASdumpOption)*MAX_DUMP_OPTS, OMRMEM_CATEGORY_VM);
if( NULL == agentOpts ) {
j9tty_err_printf(PORTLIB, "Storage for dump options not available, unable to process dump options\n");
return J9VMDLLMAIN_FAILED;
}
memset(agentOpts,0,sizeof(J9RASdumpOption)*MAX_DUMP_OPTS);
/* Load up the default agents */
for (i = 0; i < numDefaultAgents; i++) {
char *typeString = defaultAgents[i].type;
agentOpts[agentNum].kind = scanDumpType(&typeString);
agentOpts[agentNum].flags = J9RAS_DUMP_OPT_ARGS_STATIC;
agentOpts[agentNum].args = defaultAgents[i].args;
agentNum++;
}
/* Process DISABLE_JAVADUMP IBM_HEAPDUMP IBM_JAVADUMP_OUTOFMEMORY and IBM_HEAPDUMP_OUTOFMEMORY */
mapDumpSwitches(vm, agentOpts, &agentNum);
/* Process JAVA_DUMP_OPTS */
mapDumpOptions(vm, agentOpts, &agentNum);
/* Process IBM_JAVA_HEAPDUMP_TEXT and IBM_JAVA_HEAPDUMP_TEST */
mapDumpDefaults(vm, agentOpts, &agentNum);
/* Process IBM_XE_COE_NAME */
mapDumpSettings(vm, agentOpts, &agentNum);
/*
* Process -XX:[+-]HeapDumpOnOutOfMemoryError.
* Set heapDumpIndex to the index of the rightmost option
* and indicate whether enable or disable wins.
*/
heapDumpIndex = FIND_AND_CONSUME_ARG(j9vm_args, EXACT_MATCH, VMOPT_XXNOHEAPDUMPONOOM, NULL);
xdumpIndex = FIND_AND_CONSUME_ARG(j9vm_args, EXACT_MATCH, VMOPT_XXHEAPDUMPONOOM, NULL);
processXXHeapDump = ((xdumpIndex >= 0) || (heapDumpIndex >= 0));
if (xdumpIndex > heapDumpIndex) {
enableXXHeapDump = TRUE;
heapDumpIndex = xdumpIndex;
}
/*
* Process -Xdump command-line options (L..R).
* Treat -XX:[+-]HeapDumpOnOutOfMemoryError as an alias of -Xdump.
*/
xdumpIndex = FIND_ARG_IN_ARGS_FORWARD(j9vm_args, OPTIONAL_LIST_MATCH, VMOPT_XDUMP, NULL);
while (xdumpIndex >= 0)
{
if (agentNum >= MAX_DUMP_OPTS) {
j9nls_printf(PORTLIB, J9NLS_ERROR | J9NLS_STDERR, J9NLS_DMP_TOO_MANY_DUMP_OPTIONS, MAX_DUMP_OPTS);
return J9VMDLLMAIN_FAILED;
}
/* HeapDumpOnOutOfMemoryError before current -Xdump. */
if (processXXHeapDump && (heapDumpIndex < xdumpIndex)) {
/* process the -XX:[+-]HeapDumpOnOutOfMemoryError option first */
if (enableXXHeapDump) {
enableDumpOnOutOfMemoryError(agentOpts, &agentNum);
} else {
disableDumpOnOutOfMemoryError(agentOpts, agentNum);
}
processXXHeapDump = FALSE;
}
if ( IS_CONSUMABLE(j9vm_args, xdumpIndex) && !IS_CONSUMED(j9vm_args, xdumpIndex) )
{
BOOLEAN isMappedToolDump = FALSE;
/* Handle mapped tool dump options */
if (HAS_MAPPING(j9vm_args, xdumpIndex)) {
char *mappingJ9Name = MAPPING_J9NAME(j9vm_args, xdumpIndex);
char *toolString = ":tool:";
char *toolCursor = strstr(mappingJ9Name, toolString);
if (NULL != toolCursor) {
char *optionValue = NULL;
/* The mapped option specifies the tool command to run after the equals */
GET_OPTION_VALUE_ARGS(j9vm_args, xdumpIndex, '=', &optionValue);
/* Move toolCursor past ":tool:" */
toolCursor += strlen(toolString);
if (NULL != optionValue) {
size_t toolCursorLength = strlen(toolCursor);
size_t optionValueLength = strlen(optionValue);
size_t optionStringMemAlloc = toolCursorLength + optionValueLength + 1;
/* Construct optionString by combining the J9 tool dump command with the mapped option */
optionString = (char *) j9mem_allocate_memory(optionStringMemAlloc, OMRMEM_CATEGORY_VM);
if (NULL != optionString) {
strcpy(optionString, toolCursor);
strcat(optionString + toolCursorLength, optionValue);
isMappedToolDump = TRUE;
} else {
char *mappingMapName = MAPPING_MAPNAME(j9vm_args, xdumpIndex);
j9tty_err_printf(PORTLIB, "Unable to map %s to J9 %s - Could not allocate the requested size of memory %zu for optionString\n", mappingMapName, mappingJ9Name, optionStringMemAlloc);
return J9VMDLLMAIN_FAILED;
}
}
} else {
GET_OPTION_VALUE_ARGS(j9vm_args, xdumpIndex, ':', &optionString);
}
} else {
GET_OPTION_VALUE_ARGS(j9vm_args, xdumpIndex, ':', &optionString);
}
if (!optionString) {
/* ... silent option ... */
} else if( strncmp(optionString, "none", strlen("none") ) == 0 ){
/* "none" found without any agent type, pretend we found all agents. */
for (kind = 0; kind < ( (IDATA)j9RasDumpKnownSpecs ); kind++) {
agentOpts[agentNum].kind = kind;
agentOpts[agentNum].flags = J9RAS_DUMP_OPT_ARGS_STATIC;
agentOpts[agentNum].args = optionString;
agentOpts[agentNum].pass = J9RAS_DUMP_OPTS_PASS_ONE;
agentNum++;
}
} else if (isMappedToolDump) {
char * toolString = "tool";
agentOpts[agentNum].kind = scanDumpType(&toolString);
agentOpts[agentNum].flags = J9RAS_DUMP_OPT_ARGS_ALLOC;
agentOpts[agentNum].args = optionString;
agentOpts[agentNum].pass = J9RAS_DUMP_OPTS_PASS_ONE;
agentNum++;
} else {
char *typeString = optionString;
/* Find group dump settings */
optionString += strcspn(typeString, ":");
if (*optionString == ':') {optionString++;}
/* Handle multiple dump types */
while ( typeString < optionString && (kind = scanDumpType(&typeString)) >= 0 ) {
if ( strcmp(optionString, "help") == 0 ) {
printDumpSpec(vm, kind, 2);
return J9VMDLLMAIN_SILENT_EXIT_VM;
}
agentOpts[agentNum].kind = kind;
agentOpts[agentNum].flags = J9RAS_DUMP_OPT_ARGS_STATIC;
agentOpts[agentNum].args = optionString;
agentOpts[agentNum].pass = J9RAS_DUMP_OPTS_PASS_ONE;
agentNum++;
}
/* Unprocessed dump type(s) remaining */
if ( typeString < optionString ) {
j9nls_printf(PORTLIB, J9NLS_ERROR | J9NLS_STDERR, J9NLS_DMP_UNRECOGNISED_OPTION_STR, typeString);
printDumpUsage(vm);
return J9VMDLLMAIN_SILENT_EXIT_VM;
}
}
CONSUME_ARG(j9vm_args, xdumpIndex);
}
xdumpIndex = FIND_NEXT_ARG_IN_ARGS_FORWARD(j9vm_args, OPTIONAL_LIST_MATCH, VMOPT_XDUMP, NULL, xdumpIndex);
}
/* handle the case of no -Xdump options */
if (processXXHeapDump) {
if (enableXXHeapDump) {
enableDumpOnOutOfMemoryError(agentOpts, &agentNum);
} else {
disableDumpOnOutOfMemoryError(agentOpts, agentNum);
}
}
/* Process active agent options (L..R) */
for (i = 0; i < agentNum; i++) {
if (agentOpts[i].kind == J9RAS_DUMP_OPT_DISABLED) continue;
if (agentOpts[i].pass != J9RAS_DUMP_OPTS_PASS_ONE) continue;
/*j9tty_err_printf(PORTLIB, "configureDumpAgents() loading agent for %d %s\n",agentOpts[i].kind, agentOpts[i].args); */
if ( (strncmp(agentOpts[i].args, "none", strlen("none")) == 0)) {
if (deleteMatchingAgents(vm, agentOpts[i].kind, agentOpts[i].args) == OMR_ERROR_INTERNAL) {
printDumpSpec(vm, agentOpts[i].kind, 2);
return J9VMDLLMAIN_SILENT_EXIT_VM;
}
} else if ( strcmp(agentOpts[i].args, "defaults") == 0 ) {
/* Matches "defaults" not "defaults:" */
printDumpSpec(vm, agentOpts[i].kind, 1);
} else {
#ifdef J9ZOS390
processZOSDumpOptions(vm, agentOpts, i);
#else
if (loadDumpAgent(vm, agentOpts[i].kind, agentOpts[i].args) == OMR_ERROR_INTERNAL) {
printDumpSpec(vm, agentOpts[i].kind, 2);
return J9VMDLLMAIN_SILENT_EXIT_VM;
}
#endif
}
}
/* Process active DEFAULT agent options (L..R) */
for (i = 0; i < agentNum; i++) {
if (agentOpts[i].kind == J9RAS_DUMP_OPT_DISABLED) continue;
if (agentOpts[i].pass == J9RAS_DUMP_OPTS_PASS_ONE) continue;
/*j9tty_err_printf(PORTLIB, "configureDumpAgents() loading agent for %d %s\n",agentOpts[i].kind, agentOpts[i].args); */
if ( (strncmp(agentOpts[i].args, "none", strlen("none")) == 0)) {
if (deleteMatchingAgents(vm, agentOpts[i].kind, agentOpts[i].args) == OMR_ERROR_INTERNAL) {
printDumpSpec(vm, agentOpts[i].kind, 2);
return J9VMDLLMAIN_SILENT_EXIT_VM;
}
} else {
if (loadDumpAgent(vm, agentOpts[i].kind, agentOpts[i].args) == OMR_ERROR_INTERNAL) {
printDumpSpec(vm, agentOpts[i].kind, 2);
return J9VMDLLMAIN_SILENT_EXIT_VM;
}
}
}
/* Re-process active agent options (L..R) to do deletes and replace any options killed by a delete that
* preceded them. */
for (i = 0; i < agentNum; i++) {
if (agentOpts[i].kind == J9RAS_DUMP_OPT_DISABLED) continue;
if (agentOpts[i].pass != J9RAS_DUMP_OPTS_PASS_ONE) continue;
/*j9tty_err_printf(PORTLIB, "configureDumpAgents() loading agent for %d %s\n",agentOpts[i].kind, agentOpts[i].args); */
if ( (strncmp(agentOpts[i].args, "none", strlen("none")) == 0)) {
if (deleteMatchingAgents(vm, agentOpts[i].kind, agentOpts[i].args) == OMR_ERROR_INTERNAL) {
printDumpSpec(vm, agentOpts[i].kind, 2);
return J9VMDLLMAIN_SILENT_EXIT_VM;
}
} else {
#ifdef J9ZOS390
processZOSDumpOptions(vm, agentOpts, i);
#else
if (loadDumpAgent(vm, agentOpts[i].kind, agentOpts[i].args) == OMR_ERROR_INTERNAL) {
printDumpSpec(vm, agentOpts[i].kind, 2);
return J9VMDLLMAIN_SILENT_EXIT_VM;
}
#endif
}
}
if (showAgents) {
showDumpAgents(vm);
}
storeDefaultData(vm);
/* Free any allocated argument strings (used when we have a variable dump count) */
for (i = 0; i < agentNum; i++) {
if (agentOpts[i].flags == J9RAS_DUMP_OPT_ARGS_ALLOC) {
j9mem_free_memory(agentOpts[i].args);
}
}
j9mem_free_memory(agentOpts);
return J9VMDLLMAIN_OK;
}
static omr_error_t
shutdownDumpAgents(J9JavaVM *vm)
{
J9RASdumpQueue *queue;
if ( FIND_DUMP_QUEUE(vm, queue) ) {
J9RASdumpAgent * current = queue->agents;
while (current) {
J9RASdumpAgent * next = current->nextPtr;
if (current->shutdownFn) {
current->shutdownFn(vm, ¤t); /* agent will remove itself */
} else {
removeDumpAgent(vm, current);
}
current = next;
}
}
return OMR_ERROR_NONE;
}
static omr_error_t
printDumpUsage(J9JavaVM *vm)
{
IDATA kind = 0;
PORT_ACCESS_FROM_JAVAVM(vm);
j9tty_err_printf(PORTLIB, "\nUsage:\n\n");
j9tty_err_printf(PORTLIB, " -Xdump:help Print general dump help\n");
j9tty_err_printf(PORTLIB, " -Xdump:none Ignore all previous/default dump options\n");
j9tty_err_printf(PORTLIB, " -Xdump:events List available trigger events\n");
j9tty_err_printf(PORTLIB, " -Xdump:request List additional VM requests\n");
j9tty_err_printf(PORTLIB, " -Xdump:tokens List recognized label tokens\n");
j9tty_err_printf(PORTLIB, " -Xdump:dynamic Enable support for pluggable agents\n");
j9tty_err_printf(PORTLIB, " -Xdump:what Show registered agents on startup\n");
j9tty_err_printf(PORTLIB, " -Xdump:nofailover Disable dump failover to temporary directory\n");
j9tty_err_printf(PORTLIB, " -Xdump:directory=<path> Set the default directory path for dump files to be written to\n");
#if defined(OMR_CONFIGURABLE_SUSPEND_SIGNAL)
j9tty_err_printf(PORTLIB, " -Xdump:suspendwith=<num> Use SIGRTMIN+<num> to suspend threads\n");
#endif
j9tty_err_printf(PORTLIB, "\n");
j9tty_err_printf(PORTLIB, " -Xdump:<type>:help Print detailed dump help\n");
j9tty_err_printf(PORTLIB, " -Xdump:<type>:none Ignore previous dump options of this type\n");
j9tty_err_printf(PORTLIB, " -Xdump:<type>:defaults Print/update default settings for this type\n");
j9tty_err_printf(PORTLIB, " -Xdump:<type> Request this type of dump (using defaults)\n");
j9tty_err_printf(PORTLIB, "\nDump types:\n\n");
/* Print dump specifications until all done */
while (printDumpSpec(vm, kind++, 0) == OMR_ERROR_NONE) {}
j9tty_err_printf(PORTLIB, "\nExample:\n\n");
j9tty_err_printf(PORTLIB, " java -Xdump:heap:none -Xdump:heap:events=fullgc class [args...]\n\n");
j9tty_err_printf(PORTLIB, "Turns off default heapdumps, then requests a heapdump on every full GC.\n\n");
return OMR_ERROR_NONE;
}
omr_error_t
queryVmDump(struct J9JavaVM *vm, int buffer_size, void* options_buffer, int* data_size)
{
J9RASdumpAgent* agent = NULL;
char* tempBuf = NULL;
IDATA numBytes = 1024;
IDATA numBytesWritten = 0;
IDATA writtenToBuffer = FALSE;
IDATA foundDumpAgent = FALSE;
omr_error_t rc = OMR_ERROR_NONE;
PORT_ACCESS_FROM_JAVAVM(vm);
if (NULL == data_size) {
/* cannot write the data_size so abandon at this point. */
return OMR_ERROR_ILLEGAL_ARGUMENT;
}
/* block until the config is available for use */
lockConfigForUse();
do {
/* allocate an internal buffer that can hold the output */
tempBuf = (char *)j9mem_allocate_memory(numBytes, OMRMEM_CATEGORY_VM);
if (NULL == tempBuf) {
/* memory allocation error has occurred */
return OMR_ERROR_OUT_OF_NATIVE_MEMORY;
} else {
while (seekDumpAgent(vm, &agent, NULL) == OMR_ERROR_NONE)
{
foundDumpAgent = TRUE;
writtenToBuffer = queryAgent(vm, agent, numBytes, tempBuf, &numBytesWritten);
if (!writtenToBuffer) {
break;
}
}
}
if (!foundDumpAgent) {
/* failed to find a dump agent in the queue, so clean up and return */
/* free our internal buffer */
j9mem_free_memory(tempBuf);
*data_size = 0;
unlockConfig();
return OMR_ERROR_NONE;
}
if (!writtenToBuffer) {
/* double the allocation amount and try again */
numBytes *= 2;
numBytesWritten = 0;
agent = NULL;
} else {
/* copy the memory into the user's buffer and then free our internal buffer */
numBytesWritten++;
if (buffer_size >= numBytesWritten && options_buffer != NULL) {
/* do the copy */
memcpy(options_buffer, tempBuf, numBytesWritten);
} else {
/* options_buffer is null or buffer_size too low */
if (NULL == options_buffer) {
rc = OMR_ERROR_ILLEGAL_ARGUMENT;
} else {
/* buffer_size too low */
rc = OMR_ERROR_INTERNAL;
}
}
}
/* free our internal buffer */
j9mem_free_memory(tempBuf);
} while (!writtenToBuffer);
*data_size = (int)numBytesWritten;
unlockConfig();
return rc;
}
omr_error_t
setDumpOption(struct J9JavaVM *vm, char *optionString)
{
PORT_ACCESS_FROM_JAVAVM(vm);
/* -Xdump:what */
if ( strcmp(optionString, "what") == 0 )
{
/* prevent the configuration from changing under us while we inspect it */
lockConfigForUse();
showDumpAgents(vm);
}
/* -Xdump:none */
else if ( strcmp(optionString, "none") == 0 )
{
if (lockConfigForUpdate()) {
shutdownDumpAgents(vm);
} else {
return OMR_ERROR_NOT_AVAILABLE;
}
}
else if (lockConfigForUpdate())
{
char *typeString = optionString;
char *checkTypeString = typeString;
IDATA kind;
/* Find group dump settings */
optionString += strcspn(typeString, ":");
if (*optionString == ':') {optionString++;}
/* Check all dump types are valid before processing each one. */
while ( checkTypeString < optionString )
{
kind = scanDumpType(&checkTypeString);
/* Block bad dump types. (We can't do this later as we may get
* half way through setting up the dump agents before we find an
* invalid one and have partially set the configuration we were
* passed.
*/
if (J9RAS_DUMP_INVALID_TYPE == kind) {
unlockConfig();
return OMR_ERROR_INTERNAL; /* Return unrecognized dump type error code. */
}