-
Notifications
You must be signed in to change notification settings - Fork 729
/
trigger.c
1584 lines (1338 loc) · 52.2 KB
/
trigger.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 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
*******************************************************************************/
/*
* Note: remove this when portlib can supply the current user name
*/
#ifdef WIN32
#include <windows.h>
#include <lmcons.h>
#else
#ifdef J9ZOS390
#include "atoe.h"
#endif
#endif
/* _GNU_SOURCE forces GLIBC_2.0 sscanf/vsscanf/fscanf for RHEL5 compatibility */
#if defined(LINUX) && !defined(J9ZTPF)
#define _GNU_SOURCE
#endif /* defined(__GNUC__) */
#include "dmpsup.h"
#include "j9dmpnls.h"
#include "j9consts.h"
#include "vmaccess.h"
#include "vmhook.h"
#include "mmhook.h"
#include "mmomrhook.h"
#include "rasdump_internal.h"
#include <stdlib.h>
#include <string.h>
#include "j9dump.h"
#include "j9cp.h"
#include "rommeth.h"
#include "objhelp.h"
#include "jvminit.h"
#include "ute.h"
typedef enum J9RASdumpMatchResult
{
J9RAS_DUMP_NO_MATCH = 0,
J9RAS_DUMP_MATCH = 1,
J9RAS_DUMP_FILTER_MISMATCH = 2
} J9RASdumpMatchResult;
#define J9_MAX_JOBNAME 16
#define J9_MAX_DUMP_DETAIL_LENGTH 512
/* Lock words, used to suspend other dumps */
static UDATA rasDumpSuspendKey = 0;
static UDATA rasDumpFirstThread = 0;
/* Postpone GC and thread event hooks until later phases of VM initialization. */
UDATA rasDumpPostponeHooks = \
J9RAS_DUMP_ON_CLASS_UNLOAD | \
J9RAS_DUMP_ON_GLOBAL_GC | \
J9RAS_DUMP_ON_SLOW_EXCLUSIVE_ENTER | \
J9RAS_DUMP_ON_OBJECT_ALLOCATION | \
J9RAS_DUMP_ON_EXCESSIVE_GC | \
J9RAS_DUMP_ON_THREAD_START | \
J9RAS_DUMP_ON_THREAD_BLOCKED | \
J9RAS_DUMP_ON_THREAD_END;
/* Outstanding hook requests - flushed after VM init */
UDATA rasDumpPendingHooks = 0;
/* Cached VM event handlers for use by J9VMRASdumpHooks */
UDATA rasDumpUnhookedEvents = J9RAS_DUMP_ON_ANY;
static void rasDumpHookVmInit (J9HookInterface** hookInterface, UDATA eventNum, void* eventData, void* userData);
static void rasDumpHookGCInitialized(J9HookInterface** hookInterface, UDATA eventNum, void* eventData, void* userData);
static void rasDumpHookAllocationThreshold(J9HookInterface** hookInterface, UDATA eventNum, void* eventData, void* userData);
static void rasDumpHookSlowExclusive (J9HookInterface** hookInterface, UDATA eventNum, void* eventData, void* userData);
static void rasDumpHookThreadStart (J9HookInterface** hookInterface, UDATA eventNum, void* eventData, void* userData);
static void rasDumpHookExceptionDescribe (J9HookInterface** hookInterface, UDATA eventNum, void* eventData, void* userData);
#if (defined(J9VM_GC_DYNAMIC_CLASS_UNLOADING))
static void rasDumpHookClassesUnload (J9HookInterface** hookInterface, UDATA eventNum, void* eventData, void* userData);
#endif /* J9VM_GC_DYNAMIC_CLASS_UNLOADING */
static void rasDumpHookVmShutdown (J9HookInterface** hookInterface, UDATA eventNum, void* eventData, void* userData);
static void rasDumpHookExceptionThrow (J9HookInterface** hookInterface, UDATA eventNum, void* eventData, void* userData);
static void rasDumpHookGlobalGcStart (J9HookInterface** hookInterface, UDATA eventNum, void* eventData, void* userData);
static void rasDumpHookThreadEnd (J9HookInterface** hookInterface, UDATA eventNum, void* eventData, void* userData);
static J9RASdumpMatchResult matchesFilter (J9VMThread *vmThread, J9RASdumpEventData *eventData, UDATA eventFlags, char *filter, char *subFilter);
static void rasDumpHookExceptionSysthrow PROTOTYPE((J9HookInterface** hookInterface, UDATA eventNum, void* eventData, void* userData));
static void rasDumpHookClassLoad (J9HookInterface** hookInterface, UDATA eventNum, void* eventData, void* userData);
static void rasDumpHookExceptionCatch (J9HookInterface** hookInterface, UDATA eventNum, void* eventData, void* userData);
static void rasDumpHookMonitorContendedEnter (J9HookInterface** hookInterface, UDATA eventNum, void* eventData, void* userData);
static void rasDumpHookCorruptCache(J9HookInterface** hookInterface, UDATA eventNum, void* eventData, void* userData);
static void rasDumpHookExcessiveGC(J9HookInterface** hookInterface, UDATA eventNum, void* eventData, void* userData);
extern omr_error_t doHeapDump(J9RASdumpAgent *agent, char *label, J9RASdumpContext *context);
extern omr_error_t doSilentDump(J9RASdumpAgent *agent, char *label, J9RASdumpContext *context);
extern omr_error_t doToolDump(J9RASdumpAgent *agent, char *label, J9RASdumpContext *context);
extern void setAllocationThreshold(J9VMThread *vmThread, UDATA min, UDATA max);
struct ExceptionStackFrame
{
J9ROMClass *romClass;
J9ROMMethod *romMethod;
int callStackOffset;
int desiredOffset;
};
static UDATA
countExceptionStackFrame(J9VMThread *vmThread, void *userData, UDATA bytecodeOffset, J9ROMClass *romClass, J9ROMMethod *romMethod, J9UTF8 *fileName, UDATA lineNumber, J9ClassLoader* classLoader, J9Class* ramClass)
{
struct ExceptionStackFrame *frame = (struct ExceptionStackFrame *) userData;
/* Stop and fill in the struct when we have reached the required frame. */
if (frame->callStackOffset++ == frame->desiredOffset) {
frame->romClass = romClass;
frame->romMethod = romMethod;
return FALSE;
}
return TRUE;
}
/**
* Multiply the given 'val' by a suffix character. Supports 'k' and 'm'.
*
* @param[in/out] val - value to update
* @param[in] suffix - suffix character to process
*
* @return one on success, zero on failure
*/
static UDATA multiplyBySuffix(UDATA *val, char suffix)
{
switch (suffix) {
case 'k':
case 'K':
*val *= 1024;
return 1;
case 'm':
case 'M':
*val *= 1024 * 1024;
return 1;
}
return 0;
}
/**
* Parse an allocation range of the form "#5m" or "#5m..6m".
*
* @param[in] range - string containing the range
* @param[out] min - lower bound of the range
* @param[out] max - upper bound of the range (optional).
*
* @return zero on failure, one on success.
*/
UDATA
parseAllocationRange(char *range, UDATA *min, UDATA *max)
{
if (*range != '#') {
return 0;
}
range++;
if (scan_udata(&range, min) != 0) {
/* No matching numeric value */
return 0;
}
if (multiplyBySuffix(min, *range)) {
range++;
}
if (try_scan(&range, "..")) {
if (scan_udata(&range, max) != 0) {
/* No matching numeric value */
return 0;
}
multiplyBySuffix(max, *range);
} else {
*max = UDATA_MAX;
}
if (*min > *max) {
return 0;
}
return 1;
}
static J9RASdumpMatchResult
matchesObjectAllocationFilter(J9RASdumpEventData *eventData, char *filter)
{
char *message = eventData->detailData;
char *msgPtr = NULL;
UDATA msgValue = 0;
char msgText[20];
char *fltPtr = NULL;
UDATA fltValueMin = 0;
UDATA fltValueMax = 0;
char fltText[20];
if (!filter) {
/* Must have a filter for matching object allocation */
return J9RAS_DUMP_NO_MATCH;
}
strncpy(msgText, message, sizeof(msgText) - 1);
msgText[sizeof(msgText) - 1] = '\0';
strncpy(fltText, filter, sizeof(fltText) - 1);
fltText[sizeof(fltText) - 1] = '\0';
/* Convert the message to a number */
msgPtr = msgText;
if (scan_udata(&msgPtr, &msgValue) != 0) {
/* No matching numeric value */
return J9RAS_DUMP_NO_MATCH;
}
/* Convert the filter range to two numbers */
fltPtr = fltText;
if (!parseAllocationRange(fltPtr, &fltValueMin, &fltValueMax)) {
return J9RAS_DUMP_NO_MATCH;
}
/* Do the range check */
if (msgValue >= fltValueMin && msgValue <= fltValueMax) {
return J9RAS_DUMP_MATCH;
}
return J9RAS_DUMP_NO_MATCH;
}
static J9RASdumpMatchResult
matchesSlowExclusiveEnterFilter(J9RASdumpEventData *eventData, char *filter)
{
char *message = eventData->detailData;
char *msgPtr = NULL;
IDATA msgValue = 0;
char msgText[20];
char *fltPtr = NULL;
IDATA fltValue = 0;
char fltText[20];
strncpy(msgText, message, sizeof(msgText) - 1);
msgText[sizeof(msgText) - 1] = '\0';
strncpy(fltText, filter, sizeof(fltText) - 1);
fltText[sizeof(fltText) - 1] = '\0';
/* convert the message value to a number */
msgPtr = msgText;
if (scan_idata(&msgPtr, &msgValue) != 0) {
/* No matching numeric value */
return J9RAS_DUMP_NO_MATCH;
}
/* convert the filter value to a number */
fltPtr = fltText;
if (*fltPtr == '#') {
/* Skip over the leading #, if any. See defect 196215, as well as allowing a leading # (as documented) we are
* deliberately preserving the previous behaviour, which allowed the user to specify filter=<nn>ms, without the #
*/
fltPtr++;
}
if (scan_idata(&fltPtr, &fltValue) != 0) {
/* No matching numeric value */
return J9RAS_DUMP_NO_MATCH;
}
if (strcmp(fltPtr, "ms") != 0) {
/* No matching range */
return J9RAS_DUMP_NO_MATCH;
}
/* compare the filter with the message */
if (msgValue >= fltValue) {
return J9RAS_DUMP_MATCH;
} else {
return J9RAS_DUMP_NO_MATCH;
}
}
static J9RASdumpMatchResult
matchesVMShutdownFilter(J9RASdumpEventData *eventData, char *filter)
{
char *message = eventData->detailData;
IDATA value;
/* Numeric range comparison? */
if (*message != '#') {
return J9RAS_DUMP_NO_MATCH;
}
if (filter && *filter != '#') {
/* Special case: text filter has been applied to a numeric message (ie. vmstop event) */
return J9RAS_DUMP_FILTER_MISMATCH;
}
message++;
/* Number detail encoded as null-terminated hex */
scan_hex(&message, (UDATA *)&value);
/* Match to number ranges encoded in filter string */
while (try_scan(&filter, "#")) {
IDATA lhs, rhs;
scan_idata(&filter, &lhs);
if (try_scan(&filter, "..")) {
scan_idata(&filter, &rhs);
} else {
rhs = lhs;
}
if (lhs <= value && value <= rhs) {
return J9RAS_DUMP_MATCH;
}
}
/* No matching range */
return J9RAS_DUMP_NO_MATCH;
}
static J9RASdumpMatchResult
matchesExceptionFilter(J9VMThread *vmThread, J9RASdumpEventData *eventData, UDATA eventFlags, char *filter, char *subFilter)
{
PORT_ACCESS_FROM_VMC(vmThread);
char *message = eventData->detailData;
UDATA nbytes = eventData->detailLength;
UDATA buflen = 0;
char *buf = NULL;
const char *needleString = NULL;
UDATA needleLength;
U_32 matchFlag;
UDATA retCode = J9RAS_DUMP_NO_MATCH;
if (eventData->exceptionRef && filter != NULL) {
j9object_t exception = *((j9object_t *) eventData->exceptionRef);
char *hashSignInFilter = NULL;
char *stackOffsetFilter = NULL;
struct ExceptionStackFrame throwSite;
throwSite.romClass = NULL;
throwSite.romMethod = NULL;
throwSite.callStackOffset = 0;
throwSite.desiredOffset = 0;
/* Filter an exception event on throw/catch site if the new filter syntax is used */
hashSignInFilter = strrchr((const char *) filter, '#');
if (NULL != hashSignInFilter) {
hashSignInFilter++;
if (*hashSignInFilter >= '0' && *hashSignInFilter <= '9') {
stackOffsetFilter = hashSignInFilter;
sscanf(hashSignInFilter, "%d", &throwSite.desiredOffset);
}
if (eventFlags & J9RAS_DUMP_ON_EXCEPTION_CATCH) {
J9StackWalkState * walkState = vmThread->stackWalkState;
if (NULL != walkState) {
walkState->walkThread = vmThread;
walkState->flags = J9_STACKWALK_INCLUDE_NATIVES | J9_STACKWALK_VISIBLE_ONLY | J9_STACKWALK_COUNT_SPECIFIED;
walkState->skipCount = 0;
walkState->maxFrames = 1;
vmThread->javaVM->walkStackFrames(vmThread, walkState);
if (NULL != walkState->method) {
throwSite.romClass = J9_CLASS_FROM_METHOD(walkState->method)->romClass;
throwSite.romMethod = J9_ROM_METHOD_FROM_RAM_METHOD(walkState->method);
}
}
} else {
/* For other events, walk the stack to find the desired frame */
vmThread->javaVM->internalVMFunctions->iterateStackTrace(vmThread, (j9object_t*) eventData->exceptionRef, countExceptionStackFrame, &throwSite, TRUE, FALSE);
}
}
if (throwSite.romClass && throwSite.romMethod) {
J9UTF8 *exceptionClassName = J9ROMCLASS_CLASSNAME(J9OBJECT_CLAZZ(vmThread, exception)->romClass);
J9UTF8 *throwClassName = J9ROMCLASS_CLASSNAME(throwSite.romClass);
J9UTF8 *throwMethodName = J9ROMMETHOD_NAME(throwSite.romMethod);
if (throwClassName && throwMethodName) {
if (stackOffsetFilter) {
buflen = J9UTF8_LENGTH(exceptionClassName) + J9UTF8_LENGTH(throwClassName) + J9UTF8_LENGTH(throwMethodName) + strlen(stackOffsetFilter) + 3;
} else {
buflen = J9UTF8_LENGTH(exceptionClassName) + J9UTF8_LENGTH(throwClassName) + J9UTF8_LENGTH(throwMethodName) + 2;
}
buf = j9mem_allocate_memory(buflen + 1, OMRMEM_CATEGORY_VM);
if (buf != NULL) {
int end = J9UTF8_LENGTH(exceptionClassName);
memcpy(buf, J9UTF8_DATA(exceptionClassName), J9UTF8_LENGTH(exceptionClassName));
buf[end] = '#';
memcpy(buf + end + 1, J9UTF8_DATA(throwClassName), J9UTF8_LENGTH(throwClassName));
end += J9UTF8_LENGTH(throwClassName) + 1;
buf[end] = '.';
memcpy(buf + end + 1, J9UTF8_DATA(throwMethodName), J9UTF8_LENGTH(throwMethodName));
if (stackOffsetFilter) {
end += J9UTF8_LENGTH(throwMethodName) + 1;
buf[end] = '#';
j9str_printf(PORTLIB, buf + end + 1, buflen - end, "%d", throwSite.desiredOffset);
}
buf[buflen] = '\0';
}
}
}
}
if (buf && buflen) {
message = buf;
nbytes = buflen;
}
/* Apply standard text filter */
if (filter && parseWildcard(filter, strlen(filter), &needleString, &needleLength, &matchFlag) == 0) {
if (wildcardMatch(matchFlag, needleString, needleLength, message, nbytes)) {
retCode = J9RAS_DUMP_MATCH;
} else {
if (buf != NULL) {
j9mem_free_memory(buf);
}
return retCode;
}
}
if (buf != NULL) {
j9mem_free_memory(buf);
buf = NULL;
buflen = 0;
}
if (subFilter && parseWildcard(subFilter, strlen(subFilter), &needleString, &needleLength, &matchFlag) == 0) {
if (eventData->exceptionRef && *eventData->exceptionRef) {
char stackBuffer[256];
j9object_t emessage = J9VMJAVALANGTHROWABLE_DETAILMESSAGE(vmThread, *eventData->exceptionRef);
if (NULL != emessage) {
buf = vmThread->javaVM->internalVMFunctions->copyStringToUTF8WithMemAlloc(vmThread, emessage, J9_STR_NULL_TERMINATE_RESULT, "", 0, stackBuffer, 256, &buflen);
if (NULL != buf) {
if (wildcardMatch(matchFlag, needleString, needleLength, buf, buflen)) {
retCode = J9RAS_DUMP_MATCH;
} else {
retCode = J9RAS_DUMP_NO_MATCH;
}
}
}
if (buf != stackBuffer) {
j9mem_free_memory(buf);
}
}
}
return retCode;
}
static J9RASdumpMatchResult
matchesFilter(J9VMThread *vmThread, J9RASdumpEventData *eventData, UDATA eventFlags, char *filter, char *subFilter)
{
if (eventFlags & J9RAS_DUMP_ON_OBJECT_ALLOCATION) {
/* This comes before the default filter because object allocation MUST have a filter */
return matchesObjectAllocationFilter(eventData, filter);
}
/* For exception specific events the filter and subfilter default(null) matches to all
* For non exception specific events the filter default(null) matches to all
*/
if (((0 != (eventFlags & J9RAS_DUMP_EXCEPTION_EVENT_GROUP)) && NULL == filter && NULL == subFilter) ||
((0 == (eventFlags & J9RAS_DUMP_EXCEPTION_EVENT_GROUP)) && NULL == filter))
{
return J9RAS_DUMP_MATCH;
}
if (eventFlags & J9RAS_DUMP_ON_SLOW_EXCLUSIVE_ENTER) {
return matchesSlowExclusiveEnterFilter(eventData, filter);
} else if (eventFlags & J9RAS_DUMP_ON_VM_SHUTDOWN) {
return matchesVMShutdownFilter(eventData, filter);
} else if (0 != (eventFlags & (J9RAS_DUMP_EXCEPTION_EVENT_GROUP | J9RAS_DUMP_ON_CLASS_LOAD))) {
return matchesExceptionFilter(vmThread, eventData, eventFlags, filter, subFilter);
}
return J9RAS_DUMP_NO_MATCH;
}
omr_error_t
printLabelSpec(struct J9JavaVM *vm)
{
PORT_ACCESS_FROM_JAVAVM(vm);
/* Since j9tty_err_printf() is a function macro, #ifdefs can't be used in
* its argument list.
*/
const char *labelSpec =
" %%Y year 1900..????\n"
" %%y century 00..99\n"
" %%m month 01..12\n"
" %%d day 01..31\n"
" %%H hour 00..23\n"
" %%M minute 00..59\n"
" %%S second 00..59\n"
"\n"
" %%pid process id\n"
" %%uid user name\n"
#ifdef J9ZOS390
" %%job job name\n"
" %%jobid job ID\n"
" %%asid ASID\n"
#endif
" %%seq dump counter\n"
" %%tick msec counter\n"
" %%home java home\n"
" %%last last dump\n"
" %%event dump event\n"
"\n";
j9tty_err_printf(PORTLIB, labelSpec);
return OMR_ERROR_NONE;
}
UDATA
prepareForDump(struct J9JavaVM *vm, struct J9RASdumpAgent *agent, struct J9RASdumpContext *context, UDATA state)
{
UDATA dumpKey = 1 + (UDATA)omrthread_self();
J9VMThread *vmThread = context->onThread;
UDATA newState = state;
RasGlobalStorage * j9ras = (RasGlobalStorage *)vm->j9rasGlobalStorage;
UtInterface * uteInterface = (UtInterface *)(j9ras ? j9ras->utIntf : NULL);
BOOLEAN exclusiveHeld = J9_XACCESS_NONE != vm->exclusiveAccessState;
BOOLEAN acquireVMAccessAfterWait = FALSE;
/* Is trace running? */
if( uteInterface && uteInterface->server ) {
/* Disable trace while taking a dump. */
uteInterface->server->DisableTrace(UT_DISABLE_GLOBAL);
newState |= J9RAS_DUMP_TRACE_DISABLED;
}
/* Release vm access until this thread has the dumpKey and is ready to run. This will allow other threads to obtain exclusiveVMAccess in the meantime. */
if ((NULL != vmThread) && !vmThread->inNative) {
if (J9_ARE_ANY_BITS_SET(vmThread->publicFlags, J9_PUBLIC_FLAGS_VM_ACCESS)) {
vm->internalVMFunctions->internalReleaseVMAccess(vmThread);
acquireVMAccessAfterWait = TRUE;
}
}
/*
* The following actions are considered safe to call during a crash situation...
*/
/* For fatal events, the first failing thread sets the global rasDumpFirstThread. It then gets higher priority on the
* serial dump lock, see below. This allows the first failing thread to complete its dumps and exit the VM, reducing
* the number of dumps written and out-time if multiple threads crash.
*/
if (J9_ARE_ANY_BITS_SET(context->eventFlags, J9RAS_DUMP_ON_GP_FAULT | J9RAS_DUMP_ON_ABORT_SIGNAL | J9RAS_DUMP_ON_TRACE_ASSERT)) {
compareAndSwapUDATA(&rasDumpFirstThread, 0, dumpKey);
}
if (rasDumpSuspendKey == dumpKey) {
/* We already have the lock */
} else {
UDATA newKey = 0;
/* Grab the dump lock? */
if (J9_ARE_ANY_BITS_SET(agent->requestMask, J9RAS_DUMP_DO_SUSPEND_OTHER_DUMPS)) {
newState |= J9RAS_DUMP_GOT_LOCK;
newKey = dumpKey;
}
/* Always wait for the lock, but only grab it when requested */
while (0 != compareAndSwapUDATA(&rasDumpSuspendKey, 0, newKey)) {
if (rasDumpFirstThread == dumpKey) {
/* First failing thread gets a simple priority boost over other threads waiting for lock */
omrthread_sleep(20);
} else {
omrthread_sleep(200);
}
}
}
if (acquireVMAccessAfterWait) {
vm->internalVMFunctions->internalAcquireVMAccess(vmThread);
}
if (J9_ARE_NO_BITS_SET(context->eventFlags, J9RAS_DUMP_ON_GP_FAULT | J9RAS_DUMP_ON_ABORT_SIGNAL | J9RAS_DUMP_ON_TRACE_ASSERT)) {
/*
* The following actions may deadlock, so don't use them
* if this is a crash situation or a trace assertion.
*/
/* Share exclusive access when it's a "slow entry" or "user" event, as there may be a deadlock */
UDATA shareVMAccess = exclusiveHeld
&& OMR_ARE_ANY_BITS_SET(context->eventFlags, J9RAS_DUMP_ON_USER_SIGNAL | J9RAS_DUMP_ON_SLOW_EXCLUSIVE_ENTER);
if ( shareVMAccess == 0 ) {
/* Deferred attach of SigQuit thread, needed if we're preparing to walk the heap (GC pre-req) */
if (OMR_ARE_ANY_BITS_SET(agent->requestMask, J9RAS_DUMP_DO_PREPARE_HEAP_FOR_WALK | J9RAS_DUMP_DO_COMPACT_HEAP | J9RAS_DUMP_DO_ATTACH_THREAD)
&& OMR_ARE_ANY_BITS_SET(context->eventFlags, J9RAS_DUMP_ON_USER_SIGNAL | J9RAS_DUMP_ON_USER2_SIGNAL)
) {
JavaVMAttachArgs attachArgs;
attachArgs.version = JNI_VERSION_1_2;
attachArgs.name = "SIGQUIT Thread";
attachArgs.group = NULL;
if (!vmThread) {
vm->internalVMFunctions->AttachCurrentThreadAsDaemon((JavaVM *)vm, (void **)&vmThread, &attachArgs);
context->onThread = vmThread;
newState |= J9RAS_DUMP_ATTACHED_THREAD;
} else {
/* already attached, don't set flag to detach us on way out of heapdump! */
}
}
if ( (agent->requestMask & J9RAS_DUMP_DO_EXCLUSIVE_VM_ACCESS) &&
(state & J9RAS_DUMP_GOT_EXCLUSIVE_VM_ACCESS) == 0 ) {
if (vmThread) {
#if defined(J9VM_INTERP_ATOMIC_FREE_JNI)
if (vmThread->inNative) {
vm->internalVMFunctions->internalEnterVMFromJNI(vmThread);
newState |= J9RAS_DUMP_GOT_JNI_VM_ACCESS;
} else
#endif /* J9VM_INTERP_ATOMIC_FREE_JNI */
if ((vmThread->publicFlags & J9_PUBLIC_FLAGS_VM_ACCESS) == 0) {
vm->internalVMFunctions->internalAcquireVMAccess(vmThread);
newState |= J9RAS_DUMP_GOT_VM_ACCESS;
}
vm->internalVMFunctions->acquireExclusiveVMAccess(vmThread);
} else {
vm->internalVMFunctions->acquireExclusiveVMAccessFromExternalThread(vm);
}
newState |= J9RAS_DUMP_GOT_EXCLUSIVE_VM_ACCESS;
}
}
}
if ( (agent->requestMask & J9RAS_DUMP_DO_COMPACT_HEAP) &&
((state & J9RAS_DUMP_HEAP_COMPACTED) == 0 ) ) {
/* If exclusive access has been obtained, do the requested compaction */
if ((newState & J9RAS_DUMP_GOT_EXCLUSIVE_VM_ACCESS) && (vmThread != 0)) {
J9RASdumpEventData *eventData = context->eventData;
/* Don't try and compact the heap if it may cause recursion in GC */
UDATA gcEvent =
(context->eventFlags & J9RAS_DUMP_ON_GLOBAL_GC) ||
(context->eventFlags & J9RAS_DUMP_ON_CLASS_UNLOAD) ||
(context->eventFlags & J9RAS_DUMP_ON_EXCESSIVE_GC) ||
(eventData && matchesFilter(vmThread, eventData, context->eventFlags, "*OutOfMemoryError", NULL) == J9RAS_DUMP_MATCH) ||
/* Tracepoint trigger when exclusive is held also indicates we may be in GC */
(eventData && eventData->detailData && strcmp(eventData->detailData,"-Xtrace:trigger") == 0 && exclusiveHeld);
/*
* The extra check of this runtime flag is to defer invoking GC till class objects are assigned during startup;
* otherwise NULL class objects would be captured by GC assertion.
*/
if ( J9_ARE_ALL_BITS_SET(vm->extendedRuntimeFlags, J9_EXTENDED_RUNTIME_CLASS_OBJECT_ASSIGNED) && !gcEvent ) {
vm->memoryManagerFunctions->j9gc_modron_global_collect_with_overrides(vmThread, J9MMCONSTANT_EXPLICIT_GC_RASDUMP_COMPACT);
newState |= J9RAS_DUMP_HEAP_COMPACTED;
}
}
}
if ( (agent->requestMask & J9RAS_DUMP_DO_PREPARE_HEAP_FOR_WALK) &&
((state & J9RAS_DUMP_HEAP_PREPARED) == 0 ) ) {
/* If exclusive access has been obtained, do the requested preparation */
if (newState & J9RAS_DUMP_GOT_EXCLUSIVE_VM_ACCESS) {
vm->memoryManagerFunctions->j9gc_flush_caches_for_walk(vm);
newState |= J9RAS_DUMP_HEAP_PREPARED;
}
}
return newState;
}
UDATA
unwindAfterDump(struct J9JavaVM *vm, struct J9RASdumpContext *context, UDATA state)
{
UDATA dumpKey = 1 + (UDATA)omrthread_self();
J9VMThread *vmThread = context->onThread;
UDATA newState = state;
/*
* Must be in reverse order to the requested actions
*/
if (state & J9RAS_DUMP_GOT_EXCLUSIVE_VM_ACCESS) {
if (vmThread) {
vm->internalVMFunctions->releaseExclusiveVMAccess(vmThread);
#if defined(J9VM_INTERP_ATOMIC_FREE_JNI)
if (state & J9RAS_DUMP_GOT_JNI_VM_ACCESS) {
vm->internalVMFunctions->internalExitVMToJNI(vmThread);
newState &= ~J9RAS_DUMP_GOT_JNI_VM_ACCESS;
} else
#endif /* J9VM_INTERP_ATOMIC_FREE_JNI */
if (state & J9RAS_DUMP_GOT_VM_ACCESS) {
vm->internalVMFunctions->internalReleaseVMAccess(vmThread);
newState &= ~J9RAS_DUMP_GOT_VM_ACCESS;
}
} else {
vm->internalVMFunctions->releaseExclusiveVMAccessFromExternalThread(vm);
}
/* Releasing exclusive access potentially invalidates the state of the heap... */
newState &= ~( J9RAS_DUMP_GOT_EXCLUSIVE_VM_ACCESS | J9RAS_DUMP_HEAP_COMPACTED | J9RAS_DUMP_HEAP_PREPARED );
}
if (state & J9RAS_DUMP_ATTACHED_THREAD) {
(*((JavaVM *)vm))->DetachCurrentThread((JavaVM *)vm);
context->onThread = NULL;
newState &= ~J9RAS_DUMP_ATTACHED_THREAD;
}
if (state & J9RAS_DUMP_GOT_LOCK) {
/* Should work unless omrthread_self returns a different value than before, which is unlikely */
compareAndSwapUDATA(&rasDumpSuspendKey, dumpKey, 0);
newState &= ~J9RAS_DUMP_GOT_LOCK;
}
if( state & J9RAS_DUMP_TRACE_DISABLED) {
RasGlobalStorage * j9ras = (RasGlobalStorage *)vm->j9rasGlobalStorage;
UtInterface * uteInterface = (UtInterface *)(j9ras ? j9ras->utIntf : NULL);
/* Is trace running? */
if( uteInterface && uteInterface->server ) {
/* Re-enable trace now we are out of the dump code.*/
uteInterface->server->EnableTrace(UT_ENABLE_GLOBAL);
newState &= ~J9RAS_DUMP_TRACE_DISABLED;
}
}
return newState;
}
/*
* Function : dumpLabel()
* Convert a dump label template into an actual dump label by expanding all the tokens.
*
* Parameters:
* vm [in] - VM structure pointer
* agent - dump agent pointer
* context - dump context pointer
* buf [in/out] - memory buffer for expanded label
* len [in] - length of supplied buffer
* reqLen [out] - length of buffer required, if expansion would have overflowed buf
* now [in] - current time
*
* Returns: OMR_ERROR_NONE, OMR_ERROR_INTERNAL, OMR_ERROR_OUT_OF_NATIVE_MEMORY
*/
omr_error_t
dumpLabel(struct J9JavaVM *vm, J9RASdumpAgent *agent, J9RASdumpContext *context, char *buf, size_t len, UDATA *reqLen, I_64 now)
{
/* Monotonic counter */
static UDATA seqNum = 0;
struct J9StringTokens *stringTokens;
RasDumpGlobalStorage *dump_storage = (RasDumpGlobalStorage *)vm->j9rasdumpGlobalStorage;
PORT_ACCESS_FROM_JAVAVM(vm);
/* access the rasdump global storage */
if (NULL == dump_storage) {
return OMR_ERROR_INTERNAL;
}
/* lock access to the tokens */
omrthread_monitor_enter(dump_storage->dumpLabelTokensMutex);
stringTokens = dump_storage->dumpLabelTokens;
j9str_set_time_tokens(stringTokens, now);
seqNum += 1; /* Atomicity guaranteed as we are inside the dumpLabelTokensMutex */
if (j9str_set_token(PORTLIB, stringTokens, "seq", "%04u", seqNum)) {
omrthread_monitor_exit(dump_storage->dumpLabelTokensMutex);
return OMR_ERROR_INTERNAL;
}
if (j9str_set_token(PORTLIB, stringTokens, "home", "%s", (vm->javaHome == NULL) ? "" : (char *)vm->javaHome)) {
omrthread_monitor_exit(dump_storage->dumpLabelTokensMutex);
return OMR_ERROR_INTERNAL;
}
if (j9str_set_token(PORTLIB, stringTokens, "event", "%s", mapDumpEvent(context->eventFlags))) {
omrthread_monitor_exit(dump_storage->dumpLabelTokensMutex);
return OMR_ERROR_INTERNAL;
}
if (j9str_set_token(PORTLIB, stringTokens, "list", "%s", (context->dumpList == NULL) ? "" : context->dumpList)) {
omrthread_monitor_exit(dump_storage->dumpLabelTokensMutex);
return OMR_ERROR_INTERNAL;
}
/* %vmbin is not listed in printLabelSpec as it is only useful for loading internal tools that live in the vm directory. */
if (j9str_set_token(PORTLIB, stringTokens, "vmbin", "%s", (vm->j2seRootDirectory == NULL) ? "" : (char *)vm->j2seRootDirectory)) {
omrthread_monitor_exit(dump_storage->dumpLabelTokensMutex);
return OMR_ERROR_INTERNAL;
}
/* Default label is "-", ie. stderr */
if (agent->labelTemplate == NULL) {
agent->labelTemplate = "-";
}
/* Check the return value here to see if token expansion fitted in the buffer */
*reqLen = j9str_subst_tokens(buf, len, agent->labelTemplate, stringTokens);
if (*reqLen > len) {
omrthread_monitor_exit(dump_storage->dumpLabelTokensMutex);
return OMR_ERROR_OUT_OF_NATIVE_MEMORY;
}
if (agent->dumpFn != doToolDump ) {
/* Cache last dump label (but not for tool dumps!) */
if (j9str_set_token(PORTLIB, stringTokens, "last", "%s", buf)) {
omrthread_monitor_exit(dump_storage->dumpLabelTokensMutex);
return OMR_ERROR_INTERNAL;
}
}
/* release access to the tokens */
omrthread_monitor_exit(dump_storage->dumpLabelTokensMutex);
return OMR_ERROR_NONE;
}
omr_error_t
triggerOneOffDump(struct J9JavaVM *vm, char *optionString, char *caller, char *fileName, size_t fileNameLength)
{
IDATA kind;
omr_error_t retVal = OMR_ERROR_INTERNAL;
size_t len;
if( optionString == NULL ) {
return OMR_ERROR_INTERNAL;
}
kind = scanDumpType(&optionString);
if ( kind >= 0 ) {
J9RASdumpContext context;
J9RASdumpEventData eventData;
/* we lock the dump configuration here so that the agent and setting queues can't be
* changed underneath us while we're producing the dumps
*/
lockConfigForUse();
/* Construct a pseudo-context */
context.javaVM = vm;
context.onThread = vm->internalVMFunctions->currentVMThread(vm);
context.eventFlags = J9RAS_DUMP_ON_USER_REQUEST;
context.eventData = &eventData;
context.dumpList = fileName;
context.dumpListSize = fileNameLength;
context.dumpListIndex = 0;
eventData.detailData = caller;
if (caller != NULL) {
eventData.detailLength = strlen(caller);
} else {
eventData.detailLength = 0;
}
eventData.exceptionRef = NULL;
retVal = createAndRunOneOffDumpAgent(vm,&context,kind,optionString);
/* Remove the trailing tab added to the filename as a separator, it's only
* used for multiple dumps and will confuse the caller.
*/
if( fileName ) {
len = strlen(fileName);
} else {
len = 0;
}
if( len > 0 && len <= fileNameLength) {
if( fileName[len-1] == '\t') {
fileName[len-1] = '\0';
}
}
/* Allow configuration updates again */
unlockConfig();
}
return retVal;
}
omr_error_t
triggerDumpAgents(struct J9JavaVM *vm, struct J9VMThread *self, UDATA eventFlags, struct J9RASdumpEventData *eventData)
{
J9RASdumpQueue *queue;
/* we lock the dump configuration here so that the agent and setting queues can't be
* changed underneath us while we're producing the dumps
*/
lockConfigForUse();
/*
* Sanity check
*/
if ( FIND_DUMP_QUEUE(vm, queue) ) {
J9RASdumpAgent *node;
PORT_ACCESS_FROM_JAVAVM(vm);
U_32 dumpTaken = 0;
U_32 printed = 0;
BOOLEAN toolDumpFound = FALSE;
IDATA dumpAgentCount = 0;
UDATA state = 0;
U_64 now = j9time_current_time_millis();
UDATA detailLength = eventData ? eventData->detailLength : 0;
char *detailData = detailLength ? eventData->detailData : "";
char detailBuf[J9_MAX_DUMP_DETAIL_LENGTH + 1];
J9RASdumpContext context;
context.javaVM = vm;
context.onThread = self;
context.eventFlags = eventFlags;
context.eventData = eventData;
context.dumpList = NULL;
context.dumpListSize = 0;
context.dumpListIndex = 0;
if (detailLength > J9_MAX_DUMP_DETAIL_LENGTH) {
detailLength = J9_MAX_DUMP_DETAIL_LENGTH;
}
strncpy(detailBuf, detailData, detailLength);
detailBuf[detailLength] = '\0';
/* Scan the dump agents first to see if we need to provide a dump list for tool agents */
for ( node = queue->agents; node != NULL; node = node->nextPtr ) {
if ( eventFlags & node->eventMask ) {
if ( node->dumpFn == doToolDump ) {
toolDumpFound = TRUE;
} else {
/* count number of agents for this event, not including tool dumps themselves */
dumpAgentCount++;
if (node->dumpFn == doHeapDump && strstr(node->dumpOptions, "CLASSIC") && strstr(node->dumpOptions, "PHD")) {
/* fake up a slot for the dual dump */
dumpAgentCount++;
}
}
}
}
if (toolDumpFound && (dumpAgentCount > 0)) {
/* there is a tool dump, so allocate a buffer for the list of dump labels. Need to account for the \t separators and \0 */
context.dumpListSize = ((J9_MAX_DUMP_PATH +1) * dumpAgentCount) + 1;
context.dumpList = j9mem_allocate_memory(context.dumpListSize, OMRMEM_CATEGORY_VM);
if (context.dumpList) {
memset(context.dumpList, 0, context.dumpListSize);
}
}
/* Trigger agents for this event, in priority order */
for ( node = queue->agents; node != NULL; node = node->nextPtr ) {
if ( eventFlags & node->eventMask ) {
/* NOTE: we allow trigger on filter mismatch (ie. exception text filter applied to vmstop exit code) */
if (NULL == eventData || matchesFilter(self, eventData, eventFlags, node->detailFilter, node->subFilter) != J9RAS_DUMP_NO_MATCH) {
/* increment count, but don't go past stopOnCount for a finite range */
UDATA oldCount = node->count;
UDATA newCount = oldCount + 1;
while ((newCount <= node->stopOnCount) || (node->stopOnCount < node->startOnCount)) {
UDATA current = compareAndSwapUDATA(&node->count, oldCount, newCount);
if (current == oldCount) {
/* increment was successful */
break;
}
oldCount = current;
newCount = current + 1;
}
/* Now check if the updated count is within the trigger range. */
if ((newCount >= node->startOnCount) &&
((node->stopOnCount < node->startOnCount) || (newCount <= node->stopOnCount))) {
if (printed == 0) {