-
Notifications
You must be signed in to change notification settings - Fork 139
/
Copy pathomrtracelog.cpp
1309 lines (1179 loc) · 38.7 KB
/
omrtracelog.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
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 1998
*
* 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 <stdlib.h>
#include "omrstdarg.h"
#include "omrtrace_internal.h"
#include "pool_api.h"
#include "omrutil.h"
#include "AtomicSupport.hpp"
#define MAX_QUALIFIED_NAME_LENGTH 16
static OMR_TraceBuffer *allocateTraceBuffer(OMR_TraceThread *currentThread);
static UtProcessorInfo *getProcessorInfo(void);
static void raiseAssertion(void);
char pointerSpec[2] = {(char)sizeof(char *), '\0'};
#define UNKNOWN_SERVICE_LEVEL "Unknown version"
/*******************************************************************************
* name - initTraceHeader
* description - Inititializes the trace header.
* parameters - void
* returns - OMR error code
******************************************************************************/
omr_error_t
initTraceHeader(void)
{
int size;
UtTraceFileHdr *trcHdr;
char *ptr;
UtTraceCfg *cfg;
int actSize, srvSize, startSize;
UtProcessorInfo *procinfo;
OMRPORT_ACCESS_FROM_OMRPORT(OMR_TRACEGLOBAL(portLibrary));
/*
* Return if it already exists
*/
if (OMR_TRACEGLOBAL(traceHeader) != NULL) {
return OMR_ERROR_NONE;
}
size = offsetof(UtTraceFileHdr, traceSection);
size += sizeof(UtTraceSection);
/*
* Calculate length of service section
*/
srvSize = offsetof(UtServiceSection, level);
if (OMR_TRACEGLOBAL(serviceInfo) == NULL) {
/* Make sure we allocate this so we can free it on shutdown. */
OMR_TRACEGLOBAL(serviceInfo) = (char *)omrmem_allocate_memory(sizeof(UNKNOWN_SERVICE_LEVEL) + 1, OMRMEM_CATEGORY_TRACE);
if (NULL == OMR_TRACEGLOBAL(serviceInfo)) {
return OMR_ERROR_OUT_OF_NATIVE_MEMORY;
}
strcpy(OMR_TRACEGLOBAL(serviceInfo), UNKNOWN_SERVICE_LEVEL);
}
srvSize += (int)strlen(OMR_TRACEGLOBAL(serviceInfo)) + 1;
srvSize = ((srvSize +
UT_STRUCT_ALIGN - 1) / UT_STRUCT_ALIGN) * UT_STRUCT_ALIGN;
size += srvSize;
/*
* Calculate length of startup options
*/
startSize = offsetof(UtStartupSection, options);
if (OMR_TRACEGLOBAL(properties) != NULL) {
startSize += (int)strlen(OMR_TRACEGLOBAL(properties)) + 1;
}
startSize = ((startSize +
UT_STRUCT_ALIGN - 1) / UT_STRUCT_ALIGN) * UT_STRUCT_ALIGN;
startSize = ((startSize + 3) / 4) * 4;
size += startSize;
/*
* Calculate length of trace activation commands
*/
actSize = offsetof(UtActiveSection, active);
for (cfg = OMR_TRACEGLOBAL(config);
cfg != NULL;
cfg = cfg->next) {
actSize += (int)strlen(cfg->command) + 1;
}
actSize = ((actSize +
UT_STRUCT_ALIGN - 1) / UT_STRUCT_ALIGN) * UT_STRUCT_ALIGN;
actSize = ((actSize + 3) / 4) * 4;
size += actSize;
/*
* Add length of UtProcSection
*/
size += sizeof(UtProcSection);
trcHdr = (UtTraceFileHdr *)omrmem_allocate_memory(size, OMRMEM_CATEGORY_TRACE);
if (NULL == trcHdr) {
UT_DBGOUT(1, ("<UT> Out of memory in initTraceHeader\n"));
return OMR_ERROR_OUT_OF_NATIVE_MEMORY;
}
memset(trcHdr, '\0', size);
initHeader(&trcHdr->header, UT_TRACE_HEADER_NAME, size);
trcHdr->bufferSize = OMR_TRACEGLOBAL(bufferSize);
trcHdr->endianSignature = UT_ENDIAN_SIGNATURE;
trcHdr->traceStart = offsetof(UtTraceFileHdr, traceSection);
trcHdr->serviceStart = trcHdr->traceStart + sizeof(UtTraceSection);
trcHdr->startupStart = trcHdr->serviceStart + srvSize;
trcHdr->activeStart = trcHdr->startupStart + startSize;
trcHdr->processorStart = trcHdr->activeStart + actSize;
/*
* Initialize trace section
*/
ptr = (char *)trcHdr + trcHdr->traceStart;
initHeader((UtDataHeader *)ptr, UT_TRACE_SECTION_NAME,
sizeof(UtTraceSection));
((UtTraceSection *)ptr)->startPlatform = OMR_TRACEGLOBAL(startPlatform);
((UtTraceSection *)ptr)->startSystem = OMR_TRACEGLOBAL(startSystem);
((UtTraceSection *)ptr)->type = OMR_TRACEGLOBAL(traceInCore) ? UT_TRACE_INTERNAL : UT_TRACE_EXTERNAL;
((UtTraceSection *)ptr)->generations = 0;
((UtTraceSection *)ptr)->pointerSize = sizeof(void *);
/*
* Initialize service level section
*/
ptr = (char *)trcHdr + trcHdr->serviceStart;
initHeader((UtDataHeader *)ptr, UT_SERVICE_SECTION_NAME, srvSize);
ptr += offsetof(UtServiceSection, level);
strcpy(ptr, OMR_TRACEGLOBAL(serviceInfo));
/*
* Initialize startup option section
*/
ptr = (char *)trcHdr + trcHdr->startupStart;
initHeader((UtDataHeader *)ptr, UT_STARTUP_SECTION_NAME, startSize);
ptr += offsetof(UtStartupSection, options);
if (OMR_TRACEGLOBAL(properties) != NULL) {
strcpy(ptr, OMR_TRACEGLOBAL(properties));
/*ptr += strlen(OMR_TRACEGLOBAL(properties)) + 1;*/
}
/*
* Fill in UtActiveSection with trace activation commands
*/
ptr = (char *)trcHdr + trcHdr->activeStart;
initHeader((UtDataHeader *)ptr, UT_ACTIVE_SECTION_NAME, actSize);
ptr += offsetof(UtActiveSection, active);
for (cfg = OMR_TRACEGLOBAL(config);
cfg != NULL;
cfg = cfg->next) {
strcpy(ptr, cfg->command);
ptr += strlen(cfg->command) + 1;
}
/*
* Initialize UtProcSection
*/
ptr = (char *)trcHdr + trcHdr->processorStart;
initHeader((UtDataHeader *)ptr, UT_PROC_SECTION_NAME,
sizeof(UtProcSection));
ptr += offsetof(UtProcSection, processorInfo);
procinfo = getProcessorInfo();
if (procinfo == NULL) {
return OMR_ERROR_OUT_OF_NATIVE_MEMORY;
} else {
memcpy(ptr, procinfo, sizeof(UtProcessorInfo));
omrmem_free_memory(procinfo);
}
OMR_TRACEGLOBAL(traceHeader) = trcHdr;
return OMR_ERROR_NONE;
}
/*******************************************************************************
* name - getTrcBuf
* description - Get and initialize a TraceBuffer
* parameters - thr, current buffer pointer or null, buffer type
* returns - TraceBuffer pointer or NULL
******************************************************************************/
static OMR_TraceBuffer *
getTrcBuf(OMR_TraceThread *thr, OMR_TraceBuffer *oldBuf, int bufferType)
{
OMR_TraceBuffer *trcBuf;
const uint32_t typeFlags = UT_TRC_BUFFER_ACTIVE | UT_TRC_BUFFER_NEW;
uint64_t writePlatform;
uint64_t writeSystem;
OMRPORT_ACCESS_FROM_OMRPORT(OMR_TRACEGLOBAL(portLibrary));
writePlatform = omrtime_hires_clock();
writeSystem = ((uint64_t) omrtime_current_time_millis());
writePlatform = (writePlatform >> 1) + (omrtime_hires_clock() >> 1);
if (oldBuf != NULL) {
/*
* Update write timestamp in case of a dump being taken before
* the buffer is ever written to disk for any reason
*/
oldBuf->record.writeSystem = writeSystem;
oldBuf->record.writePlatform = writePlatform;
/* Null the thread reference as there's no guarantee it's valid after this point */
oldBuf->thr = NULL;
if (OMR_TRACEGLOBAL(traceInCore)) {
/*
* Incore trace mode so reuse existing buffer, wrapping to the top
*/
trcBuf = oldBuf;
goto out;
} else {
publishTraceBuffer(thr, oldBuf);
}
}
/*
* Reuse buffer if there is one
*/
trcBuf = recycleTraceBuffer(thr);
/*
* If no buffers, try to obtain one
*/
if (trcBuf == NULL) {
/*
* CMVC 164637: Don't use memory allocation routines when handling signals.
* Returning NULL will make us spill some trace points.
*/
if (omrsig_get_current_signal()) {
return NULL;
}
trcBuf = allocateTraceBuffer(thr);
if (trcBuf == NULL) {
if (OMR_TRACEGLOBAL(dynamicBuffers) == TRUE) {
OMR_TRACEGLOBAL(dynamicBuffers) = FALSE;
/* Native memory allocation failure, falling back to nodynamic trace settings. */
trcBuf = getTrcBuf(thr, oldBuf, bufferType);
}
return trcBuf;
}
VM_AtomicSupport::addU32((volatile uint32_t *)&OMR_TRACEGLOBAL(allocatedTraceBuffers), 1);
UT_DBGOUT(1, ("<UT> Allocated buffer %i " UT_POINTER_SPEC "\n", OMR_TRACEGLOBAL(allocatedTraceBuffers), trcBuf));
}
/*
* Initialize buffer for this thread
*/
UT_DBGOUT(5, ("<UT> Buffer " UT_POINTER_SPEC " obtained for thread " UT_POINTER_SPEC "\n", trcBuf, thr));
trcBuf->next = NULL;
trcBuf->bufferType = bufferType;
trcBuf->thr = NULL;
if (bufferType == UT_NORMAL_BUFFER) {
trcBuf->record.threadId = (uint64_t)(uintptr_t)thr->id;
trcBuf->record.threadSyn1 = (uint64_t)(uintptr_t)thr->synonym1;
trcBuf->record.threadSyn2 = (uint64_t)(uintptr_t)thr->synonym2;
strncpy(trcBuf->record.threadName, thr->name, UT_MAX_THREAD_NAME_LENGTH);
trcBuf->record.threadName[UT_MAX_THREAD_NAME_LENGTH] = '\0';
thr->trcBuf = trcBuf;
}
trcBuf->record.firstEntry = offsetof(UtTraceRecord, threadName) +
(int32_t)strlen(trcBuf->record.threadName) + 1;
out:
trcBuf->flags = typeFlags;
/* we reset the contents of the buffer first so that even if we're in the middle of
* flushing/writing this buffer, the record maintains its consistency.
*/
trcBuf->record.nextEntry = trcBuf->record.firstEntry;
VM_AtomicSupport::readBarrier();
*((char *)&trcBuf->record + trcBuf->record.firstEntry) = '\0';
trcBuf->record.sequence = writePlatform;
trcBuf->record.wrapSequence = trcBuf->record.sequence;
/* in case this buffer is dumped rather than queued we want non zero values for the write times */
trcBuf->record.writeSystem = writeSystem;
trcBuf->record.writePlatform = writePlatform;
return trcBuf;
}
/*******************************************************************************
* name - copyToBuffer
* description - Routine to copy data to trace buffer if it may wrap
* parameters - OMR_TraceThread, buffer type, trace data, current tracebuffer
* pointer, length of the data to copy, traceentry length and
* start of the buffer
* returns - void
******************************************************************************/
static void
copyToBuffer(OMR_TraceThread *thr,
int bufferType,
const char *var,
char **p,
int length,
int *entryLength,
OMR_TraceBuffer **trcBuf)
{
int bufLeft = (int)((char *)&(*trcBuf)->record + OMR_TRACEGLOBAL(bufferSize) - *p);
int remainder;
const char *str;
/*
* Will this exceed maximum trace record length ?
*/
if ((*entryLength + length) > UT_MAX_EXTENDED_LENGTH) {
length = UT_MAX_EXTENDED_LENGTH - *entryLength;
if (length <= 0) {
return;
}
}
/*
* Will the record fit in the buffer ?
*/
if (length < bufLeft) {
memcpy(*p, var, length);
*entryLength += length;
*p += length;
} else {
/*
* Otherwise, copy what will fit...
*/
str = var;
remainder = length;
if (bufLeft > 0) {
memcpy(*p, str, bufLeft);
remainder -= bufLeft;
*entryLength += bufLeft;
*p += bufLeft;
str += bufLeft;
}
/*
* ... and get another buffer
*/
while (remainder > 0) {
*trcBuf = getTrcBuf(thr, *trcBuf, bufferType);
if (*trcBuf != NULL) {
/* we're about to copy stuff into it so mark the buffer as not new so it can be queued */
VM_AtomicSupport::bitAndU32((volatile uint32_t *)(&(*trcBuf)->flags), ~UT_TRC_BUFFER_NEW);
(*trcBuf)->thr = thr;
/* we need to update p and bufLeft irrespective of what happens next */
*p = (char *)&(*trcBuf)->record + (*trcBuf)->record.nextEntry;
bufLeft = OMR_TRACEGLOBAL(bufferSize) - (*trcBuf)->record.nextEntry;
/* if there's already a tracepoint in the buffer we need to use nextEntry +1 */
if ((*trcBuf)->record.nextEntry != (*trcBuf)->record.firstEntry) {
(*p)++;
bufLeft--;
} else {
/* there is a possibility that we will span this entire buffer with the current trace point
* but not with the data we are currently copying so we need to set this here as a precaution.
* nextEntry is always reconstructed at the end of the trace point from the cursor so this is
* overwritten if it's not needed.
*/
(*trcBuf)->record.nextEntry = -1;
}
if (remainder < bufLeft) {
memcpy(*p, str, remainder);
*p += remainder;
*entryLength += remainder;
remainder = 0;
} else {
memcpy(*p, str, bufLeft);
*entryLength += bufLeft;
*p += bufLeft;
remainder -= bufLeft;
str += bufLeft;
}
} else {
remainder = 0;
}
}
}
}
/*******************************************************************************
* name - tracePrint
* description - Print a tracepoint directly
* parameters - OMR_TraceThread, tracepoint identifier and trace data.
* returns - void
*
******************************************************************************/
static void
tracePrint(OMR_TraceThread *thr, UtModuleInfo *modInfo, uint32_t traceId, va_list var)
{
int id;
char *format;
uint32_t hh, mm, ss, millis;
char threadSwitch = ' ';
char entryexit = ' ';
char excpt = ' ';
static char blanks[] = " "
" "
" "
" "
" ";
char qualifiedModuleName[MAX_QUALIFIED_NAME_LENGTH + 1];
const char *moduleName = NULL;
OMRPORT_ACCESS_FROM_OMRPORT(OMR_TRACEGLOBAL(portLibrary));
memset(qualifiedModuleName, '\0', sizeof(qualifiedModuleName));
if (modInfo == NULL) {
strcpy(qualifiedModuleName, "dg");
moduleName = "dg";
} else if (modInfo->traceVersionInfo->traceVersion >= 7 && modInfo->containerModule != NULL) {
omrstr_printf(qualifiedModuleName, MAX_QUALIFIED_NAME_LENGTH, "%s(%s)", modInfo->name, modInfo->containerModule->name);
moduleName = modInfo->name;
} else {
strncpy(qualifiedModuleName, modInfo->name, MAX_QUALIFIED_NAME_LENGTH);
moduleName = modInfo->name;
}
/*
* Split tracepoint id into component and tracepoint within component
*/
id = (traceId >> 8) & UT_TRC_ID_MASK;
/*
* Find the appropriate format for this tracepoint
*/
format = getFormatString(moduleName, id);
if (format == NULL) {
return;
}
/*
* Get the time in GMT
*/
getTimestamp(omrtime_current_time_millis(), &hh, &mm, &ss, &millis);
/*
* Hold the traceLock to avoid a trace data corruption
*/
getTraceLock(thr);
/*
* Check for thread switch since last tracepoint
*/
if (OMR_TRACEGLOBAL(lastPrint) != thr) {
OMR_TRACEGLOBAL(lastPrint) = thr;
threadSwitch = '*';
}
if (OMR_TRACEGLOBAL(indentPrint)) {
/*
* If indented print was requested
*/
char *indent;
excpt = format[0]; /* Pick up exception flag, if any */
entryexit = format[1];
/*
* If this is an exit type tracepoint, decrease the indentation,
* but make sure it doesn't go negative
*/
if (format[1] == '<' &&
thr->indent > 0) {
thr->indent--;
}
/*
* Set indent, limited by the size of the array of blanks above
*/
indent = blanks + sizeof(blanks) - 1 - thr->indent;
indent = (indent < blanks) ? blanks : indent;
/*
* If this is an entry type tracepoint, increase the indentation
*/
if (format[1] == '>') {
thr->indent++;
}
if (format[1] == ' ') {
entryexit = '-';
}
/*
* Indented print
*/
omrtty_err_printf("%02d:%02d:%02d.%03d%c" UT_POINTER_SPEC
"%16s.%-6d %c %s %c ", hh, mm, ss, millis, threadSwitch, thr->id, qualifiedModuleName,
id, excpt, indent, entryexit);
omrtty_err_vprintf(format + 2, var);
} else {
/*
* Non-indented print
*/
excpt = format[0];
format[1] == ' ' ? (entryexit = '-') : (entryexit = format[1]);
omrtty_err_printf("%02d:%02d:%02d.%03d%c" UT_POINTER_SPEC
"%16s.%-6d %c %c ", hh, mm, ss, millis, threadSwitch, thr->id, qualifiedModuleName,
id, excpt, entryexit);
omrtty_err_vprintf(format + 2, var);
}
omrtty_err_printf("\n");
freeTraceLock(thr);
}
/*******************************************************************************
* name - traceAssertion
* description - Print a tracepoint directly
* parameters - OMR_TraceThread, tracepoint identifier and trace data.
* returns - void
*
******************************************************************************/
static void
traceAssertion(OMR_TraceThread *thr, UtModuleInfo *modInfo, uint32_t traceId, va_list var)
{
int id;
const char *format;
uint32_t hh, mm, ss, millis;
char qualifiedModuleName[MAX_QUALIFIED_NAME_LENGTH + 1];
OMRPORT_ACCESS_FROM_OMRPORT(OMR_TRACEGLOBAL(portLibrary));
memset(qualifiedModuleName, '\0', sizeof(qualifiedModuleName));
if (modInfo == NULL) {
strcpy(qualifiedModuleName, "dg");
} else if (modInfo->traceVersionInfo->traceVersion >= 7 && modInfo->containerModule != NULL) {
omrstr_printf(qualifiedModuleName, MAX_QUALIFIED_NAME_LENGTH, "%s(%s)", modInfo->name, modInfo->containerModule->name);
} else {
strncpy(qualifiedModuleName, modInfo->name, MAX_QUALIFIED_NAME_LENGTH);
}
getTimestamp(omrtime_current_time_millis(), &hh, &mm, &ss, &millis);
/*
* Split tracepoint id into component and tracepoint within component
*/
id = (traceId >> 8) & UT_TRC_ID_MASK;
format = "* ** ASSERTION FAILED ** at %s:%d: %s";
/*
* Hold the traceLock to avoid a trace data corruption
*/
getTraceLock(thr);
/*
* Non-indented print
*/
omrtty_err_printf("%02d:%02d:%02d.%03d " UT_POINTER_SPEC
"%8s.%-6d * ", hh, mm, ss, millis, thr->id, qualifiedModuleName,
id);
omrtty_err_vprintf(format + 2, var);
omrtty_err_printf("\n");
freeTraceLock(thr);
}
/*******************************************************************************
* name - traceCount
* description - Increment the count for a tracepoint
* parameters - moduleInfo, tracepoint identifier
* returns - void
******************************************************************************/
static void
traceCount(UtModuleInfo *moduleInfo, uint32_t traceId)
{
int traceNum = (traceId >> 8) & UT_TRC_ID_MASK;
incrementTraceCounter(moduleInfo, OMR_TRACEGLOBAL(componentList), traceNum);
}
/*******************************************************************************
* name - utTraceV
* description - Make a tracepoint
* parameters - OMR_TraceThread, tracepoint identifier and trace data.
* returns - void
*
******************************************************************************/
static void
traceV(OMR_TraceThread *thr, UtModuleInfo *modInfo, uint32_t traceId, const char *spec,
va_list var, int bufferType)
{
OMR_TraceBuffer *trcBuf;
int lastSequence;
int entryLength;
int length;
char *p;
const signed char *str;
char *format = NULL;
int32_t intVar;
char charVar;
unsigned short shortVar;
int64_t i64Var;
double doubleVar;
char *ptrVar;
const char *stringVar;
size_t stringVarLen;
char *containerModuleVar = NULL;
size_t containerModuleVarLen = 0;
char temp[3];
static char lengthConversion[] = {0,
sizeof(char),
sizeof(short),
0,
sizeof(int32_t),
sizeof(float),
sizeof(char *),
sizeof(double),
sizeof(int64_t),
sizeof(long double),
0
};
OMRPORT_ACCESS_FROM_OMRPORT(OMR_TRACEGLOBAL(portLibrary));
if (modInfo != NULL) {
traceId += (257 << 8); /* this will be translated back by the formatter */
stringVar = modInfo->name;
stringVarLen = length = modInfo->namelength;
if (modInfo->traceVersionInfo->traceVersion >= 7 && modInfo->containerModule != NULL) {
containerModuleVar = modInfo->containerModule->name;
containerModuleVarLen = modInfo->containerModule->namelength;
length += (int)containerModuleVarLen + sizeof("()") - 1;
}
} else {
/* modInfo == NULL means this is a tracepoint for the trace formatter */
stringVar = "INTERNALTRACECOMPONENT";
stringVarLen = length = sizeof("INTERNALTRACECOMPONENT") - 1;
}
/*
* Trace buffer available ?
*/
if (bufferType == UT_NORMAL_BUFFER) {
if (((trcBuf = thr->trcBuf) == NULL)
&& ((trcBuf = getTrcBuf(thr, NULL, bufferType)) == NULL)
) {
return;
}
} else {
return;
}
if (trcBuf->flags & UT_TRC_BUFFER_NEW) {
VM_AtomicSupport::bitAndU32((volatile uint32_t *)(&trcBuf->flags), ~UT_TRC_BUFFER_NEW);
trcBuf->thr = thr;
}
lastSequence = (int32_t)(trcBuf->record.sequence >> 32);
trcBuf->record.sequence = omrtime_hires_clock();
p = (char *)&trcBuf->record + trcBuf->record.nextEntry + 1;
/* additional sanity check */
if ((p < (char *)&trcBuf->record) || (p > ((char *)&trcBuf->record + OMR_TRACEGLOBAL(bufferSize)))) {
/* the buffer's been mangled so free it for reuse and acquire another */
UT_DBGOUT(1, ("<UT> invalid nextEntry value in record. Freed trace buffer for thread " UT_POINTER_SPEC " and reinitialized\n", thr));
releaseTraceBuffer(thr, trcBuf);
thr->trcBuf = NULL;
trcBuf = getTrcBuf(thr, NULL, bufferType);
if (trcBuf == NULL) {
return;
}
p = (char *)&trcBuf->record + trcBuf->record.nextEntry + 1;
}
if ((OMR_TRACEGLOBAL(bufferSize) - trcBuf->record.nextEntry) > (UT_FASTPATH + length + 4)) {
/* there is space in the buffer for a minimal entry, so avoid the overhead of copyToBuffer func */
if (lastSequence != (int32_t)(trcBuf->record.sequence >> 32)) {
*p = UT_TRC_SEQ_WRAP_ID[0];
*(p + 1) = UT_TRC_SEQ_WRAP_ID[1];
*(p + 2) = UT_TRC_SEQ_WRAP_ID[2];
memcpy(p + 3, &lastSequence, sizeof(int32_t));
*(p + 7) = UT_TRC_SEQ_WRAP_LENGTH;
trcBuf->record.nextEntry += UT_TRC_SEQ_WRAP_LENGTH;
p += UT_TRC_SEQ_WRAP_LENGTH;
}
*p = (char)(traceId >> 24);
*(p + 1) = (char)(traceId >> 16);
*(p + 2) = (char)(traceId >> 8);
{
int32_t temp = (int32_t)(trcBuf->record.sequence & 0xFFFFFFFF);
memcpy(p + 3, &temp, sizeof(int32_t));
}
p += 7;
/* write name length into buffer */
memcpy(p, &length, 4);
/* write name into buffer */
memcpy(p + 4, stringVar, stringVarLen);
p += (stringVarLen + 4);
/* if tracepoint is part of other component - write container's name into buffer */
if (containerModuleVar != NULL) {
*p++ = '(';
memcpy(p, containerModuleVar, containerModuleVarLen);
p += containerModuleVarLen;
*p++ = ')';
}
entryLength = length + 12;
*p = 12 + length;
} else {
/* approaching end of buffer, use copyToBuffer to handle the wrap */
/*
* Handle sequence counter wrap
*
* It's not a problem if the sequence counter write is aborted/discarded
* by nodynamic because it applies to the *preceeding* tracepoints and
* they'll have been discarded as well.
*/
if (lastSequence != (int32_t)(trcBuf->record.sequence >> 32)) {
char len = UT_TRC_SEQ_WRAP_LENGTH;
entryLength = 0;
copyToBuffer(thr, bufferType, UT_TRC_SEQ_WRAP_ID, &p, 3,
&entryLength, &trcBuf);
copyToBuffer(thr, bufferType, (char *)&lastSequence, &p, 4,
&entryLength, &trcBuf);
copyToBuffer(thr, bufferType, &len, &p, 1,
&entryLength, &trcBuf);
/* copyToBuffer increments p past the last byte written, but nextEntry
* needs to point to the length byte so we need -1 here.
*/
trcBuf->record.nextEntry = (int32_t)(p - (char *)&trcBuf->record - 1);
}
entryLength = 1;
temp[0] = (char)(traceId >> 24);
temp[1] = (char)(traceId >> 16);
temp[2] = (char)(traceId >> 8);
copyToBuffer(thr, bufferType, temp, &p, 3, &entryLength, &trcBuf);
intVar = (int32_t)trcBuf->record.sequence;
copyToBuffer(thr, bufferType, (char *)&intVar,
&p, 4, &entryLength, &trcBuf);
/* write name length to buffer */
copyToBuffer(thr, bufferType, (char *)&length,
&p, 4, &entryLength, &trcBuf);
/* write name to buffer */
copyToBuffer(thr, bufferType, stringVar, &p,
(int)stringVarLen, &entryLength, &trcBuf);
if (containerModuleVar != NULL) {
copyToBuffer(thr, bufferType, "(", &p, 1, &entryLength, &trcBuf);
copyToBuffer(thr, bufferType, containerModuleVar, &p, (int)containerModuleVarLen, &entryLength, &trcBuf);
copyToBuffer(thr, bufferType, ")", &p, 1, &entryLength, &trcBuf);
}
charVar = (char)entryLength;
copyToBuffer(thr, bufferType, &charVar, &p, 1, &entryLength,
&trcBuf);
p--;
entryLength--;
}
/*
* Process maximal trace
*/
str = (const signed char *)spec;
if (OMR_ARE_ANY_BITS_SET(thr->currentOutputMask, UT_MAXIMAL | UT_EXCEPTION) && (str != NULL)) {
int i;
/*
* Calculate the length
*/
length = 0;
for (i = 0; str[i] > UT_TRACE_DATA_TYPE_END; i++) {
length += lengthConversion[str[i]];
}
if (str[i] != UT_TRACE_DATA_TYPE_END) {
length = -1;
}
/*
* If we know the length and it will fit without a wrap
*/
if ((length > 0) &&
((p + length + 1) < (char *)&trcBuf->record + OMR_TRACEGLOBAL(bufferSize))) {
while (*str != '\0') {
switch (*str) {
/*
* Words
*/
case UT_TRACE_DATA_TYPE_INT32: {
intVar = va_arg(var, int32_t);
memcpy(p, &intVar, sizeof(int32_t));
p += sizeof(int32_t);
entryLength += sizeof(int32_t);
break;
}
/*
* Pointers
*/
case UT_TRACE_DATA_TYPE_POINTER: {
ptrVar = va_arg(var, char *);
memcpy(p, &ptrVar, sizeof(char *));
p += sizeof(char *);
entryLength += sizeof(char *);
break;
}
/*
* 64 bit integers
*/
case UT_TRACE_DATA_TYPE_INT64: {
i64Var = va_arg(var, int64_t);
memcpy(p, &i64Var, sizeof(int64_t));
p += sizeof(int64_t);
entryLength += sizeof(int64_t);
break;
}
/*
* Doubles
*/
/* CMVC 164940 All %f tracepoints are internally promoted to double.
* Affects:
* TraceFormat com/ibm/jvm/format/Message.java
* TraceFormat com/ibm/jvm/trace/format/api/Message.java
* VM_Common ute/ut_trace.c
* TraceGen OldTrace.java
* Intentional fall through to next case.
*/
case UT_TRACE_DATA_TYPE_DOUBLE: {
doubleVar = va_arg(var, double);
memcpy(p, &doubleVar, sizeof(double));
p += sizeof(double);
entryLength += sizeof(double);
break;
}
/*
* Bytes
*/
case UT_TRACE_DATA_TYPE_CHAR: {
charVar = (char)va_arg(var, int32_t);
*p = charVar;
p += sizeof(char);
entryLength += sizeof(char);
break;
}
/*
* Shorts
*/
case UT_TRACE_DATA_TYPE_SHORT: {
shortVar = (short)va_arg(var, int32_t);
memcpy(p, &shortVar, sizeof(short));
p += sizeof(short);
entryLength += sizeof(short);
break;
}
}
str++;
}
*p = (unsigned char)entryLength;
/*
* There's a chance of a wrap, so take it slow..
*/
} else {
int32_t left;
while (*str != '\0') {
left = (int32_t)((char *)&trcBuf->record + OMR_TRACEGLOBAL(bufferSize) - p);
switch (*str) {
/*
* Words
*/
case UT_TRACE_DATA_TYPE_INT32: {
intVar = va_arg(var, int32_t);
if (left > (int32_t)sizeof(int32_t)) {
memcpy(p, &intVar, sizeof(int32_t));
p += sizeof(int32_t);
entryLength += sizeof(int32_t);
} else {
copyToBuffer(thr, bufferType, (char *)&intVar,
&p, sizeof(int32_t), &entryLength,
&trcBuf);
}
break;
}
/*
* Pointers
*/
case UT_TRACE_DATA_TYPE_POINTER: {
ptrVar = va_arg(var, char *);
if (left > (int32_t)sizeof(char *)) {
memcpy(p, &ptrVar, sizeof(char *));
p += sizeof(char *);
entryLength += sizeof(char *);
} else {
copyToBuffer(thr, bufferType, (char *)&ptrVar,
&p, sizeof(char *), &entryLength,
&trcBuf);
}
break;
}
/*
* Strings
*/
case UT_TRACE_DATA_TYPE_STRING: {
if ((modInfo != NULL) && (UT_APPLICATION_TRACE_MODULE == modInfo->moduleId)) {
stringVar = format;
} else {
stringVar = va_arg(var, char *);
}
if (stringVar == NULL) {
stringVar = UT_NULL_POINTER;
}
length = (int32_t)strlen(stringVar) + 1;
if (left > length) {
memcpy(p, stringVar, length);
p += length;
entryLength += length;
} else {
copyToBuffer(thr, bufferType, stringVar, &p,
length, &entryLength, &trcBuf);
}
break;
}
/*
* UTF8 strings
*/
case UT_TRACE_DATA_TYPE_PRECISION: {
length = va_arg(var, int32_t);
str++;
if (*str == UT_TRACE_DATA_TYPE_STRING) {
stringVar = va_arg(var, char *);
if (stringVar == NULL) {
length = 0;
}
shortVar = (unsigned short)length;
if (left > (int32_t)sizeof(short)) {
memcpy(p, &shortVar, sizeof(short));
p += sizeof(short);
entryLength += sizeof(short);
left -= (int32_t)sizeof(short);
} else {
copyToBuffer(thr, bufferType, (char *)&shortVar,
&p, sizeof(short), &entryLength,
&trcBuf);
left = (int32_t)((char *)&trcBuf->record +
OMR_TRACEGLOBAL(bufferSize) - p);
}
if (length > 0) {
if (left > length) {
memcpy(p, stringVar, length);
p += length;
entryLength += length;
} else {
copyToBuffer(thr, bufferType, stringVar, &p,
length, &entryLength, &trcBuf);
}
}
}
break;
}
/*
* 64 bit integers
*/
case UT_TRACE_DATA_TYPE_INT64: {
i64Var = va_arg(var, int64_t);
if (left > (int32_t)sizeof(int64_t)) {
memcpy(p, &i64Var, sizeof(int64_t));