-
Notifications
You must be signed in to change notification settings - Fork 397
/
Copy pathLimitFile.cpp
1424 lines (1279 loc) · 42.6 KB
/
LimitFile.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 (c) 2000, 2020 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
* distribution and is available at http://eclipse.org/legal/epl-2.0
* or the Apache License, Version 2.0 which accompanies this distribution
* and is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License, v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception [1] and GNU General Public
* License, version 2 with the OpenJDK Assembly Exception [2].
*
* [1] https://www.gnu.org/software/classpath/license.html
* [2] http://openjdk.java.net/legal/assembly-exception.html
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
*******************************************************************************/
#include <ctype.h>
#include <limits.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "env/FrontEnd.hpp"
#include "compile/Compilation.hpp"
#include "compile/Method.hpp"
#include "compile/ResolvedMethod.hpp"
#include "control/Options.hpp"
#include "control/OptionsUtil.hpp"
#include "control/Options_inlines.hpp"
#include "env/CompilerEnv.hpp"
#include "env/PersistentInfo.hpp"
#include "env/TRMemory.hpp"
#include "env/VerboseLog.hpp"
#include "env/jittypes.h"
#include "infra/Assert.hpp"
#include "optimizer/OptimizationManager.hpp"
#include "optimizer/Optimizations.hpp"
#include "optimizer/Optimizer.hpp"
#include "ras/Debug.hpp"
#include "infra/SimpleRegex.hpp"
#define PSEUDO_RANDOM_NUMBER_PREFIX "#num"
#define PSEUDO_RANDOM_NUMBER_PREFIX_LEN 4
#define PSEUDO_RANDOM_SUFFIX '#'
#define FILTER_POOL_CHUNK_SIZE 32768
#define FILTER_SIZE (sizeof(TR::CompilationFilters) + sizeof(TR_FilterBST*) * FILTER_HASH_SIZE)
void
TR_Debug::clearFilters(TR::CompilationFilters * filters)
{
char *buf = (char*) findOrCreateFilters(filters);
int32_t size = FILTER_SIZE;
memset(buf, 0, size);
filters->filterHash = (TR_FilterBST **)(buf + sizeof(TR::CompilationFilters));
filters->setDefaultExclude(false);
filters->excludedMethodFilter = NULL;
}
void
TR_Debug::clearFilters(bool loadLimit)
{
if (loadLimit)
clearFilters(_relocationFilters);
else
clearFilters(_compilationFilters);
}
TR::CompilationFilters *
TR_Debug::findOrCreateFilters(TR::CompilationFilters * filters)
{
if (filters)
return filters;
else
{
int32_t size = sizeof(TR::CompilationFilters) + sizeof(TR_FilterBST*) * FILTER_HASH_SIZE;
char * buf = (char *)(TR::Compiler->regionAllocator.allocate(size));
filters = (TR::CompilationFilters *)buf;
clearFilters(filters);
return filters;
}
}
TR::CompilationFilters *
TR_Debug::findOrCreateFilters(bool loadLimit)
{
if (loadLimit)
// initializing filters using the new interface
return _relocationFilters=findOrCreateFilters(_relocationFilters);
else
// initializing filters using the new interface
return _compilationFilters=findOrCreateFilters(_compilationFilters);
}
TR_FilterBST *
TR_Debug::addFilter(char * & filterString, int32_t scanningExclude, int32_t optionSetIndex, int32_t lineNum, TR::CompilationFilters * anyFilters)
{
uint32_t filterType = scanningExclude ? TR_FILTER_EXCLUDE_NAME_ONLY : TR_FILTER_NAME_ONLY;
// Allocate the filter hash table, if it hasn't been already.
//
TR::CompilationFilters * filters = findOrCreateFilters(anyFilters);
TR_FilterBST * filterBST = new (TR::Compiler->regionAllocator) TR_FilterBST(filterType, optionSetIndex, lineNum);
int32_t nameLength;
if (*filterString == '{')
{
char *filterCursor = filterString;
filterType = scanningExclude ? TR_FILTER_EXCLUDE_REGEX : TR_FILTER_REGEX;
filterBST->setFilterType(filterType);
// Create the regular expression from the regex string
//
TR::SimpleRegex *regex = TR::SimpleRegex::create(filterCursor);
if (!regex)
{
TR_VerboseLog::writeLineLocked(TR_Vlog_FAILURE, "Bad regular expression at --> '%s'", filterCursor);
return 0;
}
nameLength = filterCursor - filterString;
filterBST->setRegex(regex);
filterBST->setNext(filters->hasRegexFilter()? filters->filterRegexList : NULL);
filters->filterRegexList = filterBST;
filters->setHasRegexFilter();
}
else
{
// Note - the following call changes the filterType field in the filterBST
//
nameLength = scanFilterName(filterString, filterBST);
if (!nameLength)
return 0;
// Add the filter to the appropriate data structure
//
filterType = filterBST->getFilterType();
if (filterType == TR_FILTER_EXCLUDE_NAME_ONLY ||
filterType == TR_FILTER_NAME_ONLY)
{
if (filters->filterNameList)
filterBST->insert(filters->filterNameList);
else
filters->filterNameList = filterBST;
filters->setHasNameFilter();
}
else
{
TR_FilterBST **bucket = &(filters->filterHash[nameLength % FILTER_HASH_SIZE]);
if (*bucket)
filterBST->insert(*bucket);
else
*bucket = filterBST;
if (filterType == TR_FILTER_NAME_AND_SIG ||
filterType == TR_FILTER_EXCLUDE_NAME_AND_SIG)
filters->setHasNameSigFilter();
else
filters->setHasClassNameSigFilter();
}
}
// We start by assuming we are including everything by default.
// If we find a +ve filter (i.e. include only this) which is not part of an
// option subset, change the default to be exclude everything.
//
if (!scanningExclude && optionSetIndex == 0)
{
filters->setDefaultExclude(true);
}
filterString += nameLength;
return filterBST;
}
TR_FilterBST *
TR_Debug::addFilter(char * & filterString, int32_t scanningExclude, int32_t optionSetIndex, int32_t lineNum, bool loadLimit)
{
if (loadLimit)
{
// initializing filters using the new interface
_relocationFilters=findOrCreateFilters(_relocationFilters);
return addFilter(filterString, scanningExclude, optionSetIndex, lineNum, _relocationFilters);
}
else
{
// initializing filters using the new interface
_compilationFilters=findOrCreateFilters(_compilationFilters);
return addFilter(filterString, scanningExclude, optionSetIndex, lineNum, _compilationFilters);
}
}
TR_FilterBST *
TR_Debug::addExcludedMethodFilter(bool loadLimit)
{
TR_FilterBST * filterBST = new (TR::Compiler->regionAllocator) TR_FilterBST(TR_FILTER_EXCLUDE_SPECIFIC_METHOD, TR_EXCLUDED_OPTIONSET_INDEX);
if (loadLimit)
{
_relocationFilters=findOrCreateFilters(_relocationFilters);
_relocationFilters->excludedMethodFilter = filterBST;
}
else
{
_compilationFilters = findOrCreateFilters(_compilationFilters);
_compilationFilters->excludedMethodFilter = filterBST;
}
return filterBST;
}
bool
TR_Debug::addSamplingPoint(char * filterString, TR_FilterBST * & lastSamplingPoint, bool loadLimit)
{
char *p;
int32_t tickCount;
if (1 != sscanf(filterString, "(%d) ", &tickCount))
return false;
uint32_t type;
for (p = filterString; *p && *p != '\t'; p++)
{}
p++;
if (*p == 'C')
{
type = TR_FILTER_SAMPLE_COMPILED;
p += 9;
}
else if (*p == 'I')
{
type = TR_FILTER_SAMPLE_INTERPRETED;
p += 12;
}
else
return false;
// Skip the method name and scan the rest of the string to see if the
// sampling point did anything
//
char *methodName = p;
//for (p++; *p && *p != '>'; p++) // WILL CATCH <init>
// {}
//if (!*p)
// return false;
p = strstr(p, "-->");
if (!p)
return false;
p += 2;
TR::CompilationFilters *filters = findOrCreateFilters(loadLimit);
TR_FilterBST * filterBST = new (TR::Compiler->regionAllocator) TR_FilterBST(type, tickCount);
if (!scanFilterName(methodName, filterBST))
return false;
// Make sure a full method signature was specified on the sampling log line
// and then reset the filter type to the proper value
//
if (filterBST->getFilterType() != TR_FILTER_SPECIFIC_METHOD)
return false;
filterBST->setFilterType(type);
// Set up the rest of the information in the filter and add it to the
// sampling point list.
int32_t count;
if (type == TR_FILTER_SAMPLE_INTERPRETED)
{
// Pick up new invocation count
//
if (1 != sscanf(p, "> %d", &count))
return false;
filterBST->setSampleCount(count);
}
else
{
// Pick up new compilation level, Use the top bit as a "profiled" tag bit.
//
if (1 != sscanf(p, "> recompile at level %d", &count))
return false;
filterBST->setSampleLevel(count);
if (strstr(p+21,", profiled"))
filterBST->setSampleProfiled(1);
else
filterBST->setSampleProfiled(0);
}
// Add the filter to the sampling point list
//
if (lastSamplingPoint)
lastSamplingPoint->setNext(filterBST);
else
filters->samplingPoints = filterBST;
lastSamplingPoint = filterBST;
return true;
}
bool
TR_Debug::scanInlineFilters(FILE * inlineFile, int32_t & lineNumber, TR::CompilationFilters * filters)
{
char limitReadBuffer[1024];
bool inlineFileError = false;
TR_FilterBST* filter = NULL;
while(fgets(limitReadBuffer, sizeof(limitReadBuffer), inlineFile))
{
++lineNumber;
//ignore range for now
//if (lineNumber < firstLine || lineNumber > lastLine)
// continue;
char includeFlag = limitReadBuffer[0];
if (includeFlag == '[')
{
//TR_VerboseLog::writeLine(TR_Vlog_INFO, "Sub inline file entry start --> '%s'", limitReadBuffer);
if (filter)
{
filter->subGroup = findOrCreateFilters(filter->subGroup);
filter->subGroup->setDefaultExclude(true);
inlineFileError = !scanInlineFilters(inlineFile, lineNumber, filter->subGroup);
}
}
else if (includeFlag == ']')
{
//TR_VerboseLog::writeLine(TR_Vlog_INFO, "Sub inline file entry end --> '%s'", limitReadBuffer);
// always return true (success)
// this will ignore the rest of the filters if no matching open bracket.
return true;
}
else if (includeFlag == '+' || includeFlag == '-')
{
char *p = limitReadBuffer+1;
int32_t optionSet;
if (*p >= '0' && *p <= '9')
optionSet = *(p++) - '0';
else
optionSet = 0;
if (*(p++) != ' ')
{
inlineFileError = true;
break;
}
// Skip hotness level if it is present
//
if (*p == '(')
{
for (p++; *p && *p != ')'; p++)
{}
if (*(p++) != ')')
{
inlineFileError = true;
break;
}
if (*(p++) != ' ')
{
inlineFileError = true;
break;
}
}
filter = addFilter(p, (('+' == includeFlag) ? 0 : 1), optionSet, lineNumber, filters);
if (!filter)
{
inlineFileError = true;
TR_VerboseLog::writeLineLocked(TR_Vlog_FAILURE, "Bad inline file entry --> '%s'", limitReadBuffer);
break;
}
}
}
return !inlineFileError;
}
/** \brief
* This function opens the inlinefile and adds its entries to a TR::CompilationFilters.
*
* An inlinefile is a file containing a list of methods, one per line, which the inliner will limit itself to
* when trying to perform inlining. In other words, only methods from the file can be inlined, but there is no
* guarantee that any of them will be inlined. The format for entry is:
*
* + signature
*
* \param option
* Points to the first char after inlinefile=
*
* \param base
* Unused variable needed for downstream projects.
*
* \param entry
* The option table entry for this option.
*
* \param cmdLineOptions
* Unused variable needed for downstream projects.
*
* \return
* The unmodified parameter option if there is a problem with the file, aborting JIT initialization.
* Otherwise a pointer to the next comma or NULL.
*/
char *
TR_Debug::inlinefileOption(char *option, void *base, TR::OptionTable *entry, TR::Options * cmdLineOptions)
{
char *endOpt = option;
char *name = option;
char *fail = option;
// move to the end of this option
for (; *endOpt && *endOpt != ','; endOpt++)
{}
int32_t len = endOpt - name;
if (!len)
return option;
char *inlineFileName = (char *)(TR::Compiler->regionAllocator.allocate(len+1));
memcpy(inlineFileName, name, len);
inlineFileName[len] = 0; // NULL terminate the copied string
entry->msgInfo = (intptr_t)inlineFileName;
FILE *inlineFile = fopen(inlineFileName, "r");
bool success = false;
if (inlineFile)
{
// initializing _inlineFilters using the new interface
_inlineFilters = findOrCreateFilters(_inlineFilters);
TR::CompilationFilters * filters = _inlineFilters;
filters->setDefaultExclude(true);
int32_t lineNumber = 0;
success = scanInlineFilters(inlineFile, lineNumber, filters);
fclose(inlineFile);
}
if (!success)
{
TR_VerboseLog::writeLineLocked(TR_Vlog_FAILURE, "Unable to read inline file --> '%s'", inlineFileName);
return fail; // We want to fail if we can't read the file because it is too easy to miss that the file wasn't picked up
}
return endOpt;
}
/** \brief
* Processes a limitfile= option, parses and applies the limitfile to compilation control.
*
* A limitfile is a compiler verbose log, produced by the option -Xjit:verbose,vlog=filename
* When a verbose log is used as a limitfile, only the methods contained within the file
* will be compiled if they are queued for compilation. The format of the method entries in
* the file must match that of a verbose log.
*
* The option can be used in 2 ways:
* limitfile=filename
* limitfile=(filename,xx,yy)
*
* The when the latter is used, xx-yy denotes a line number range (starting at zero and ignoring # comments)
* to restrict the limiting to. This is commonly used in debugging to narrow down a problem to a specific
* method by doing a binary search on the limitfile.
*
* \param option
* Points to the first char after inlinefile=
*
* \param base
* Unused variable needed for downstream projects.
*
* \param entry
* The option table entry for this option.
*
* \param cmdLineOptions
* The command line options.
*
* \param loadLimit
* The load limit.
*
* \param pseudoRandomListHeadPtr
* A list of pseudo random numbers.
*
* \return
* The unmodified parameter option if there is a problem with the file, aborting JIT initialization.
* Otherwise a pointer to the next comma or NULL.
*/
char *
TR_Debug::limitfileOption(char *option, void *base, TR::OptionTable *entry, TR::Options * cmdLineOptions, bool loadLimit, TR_PseudoRandomNumbersListElement **pseudoRandomListHeadPtr)
{
char *endOpt = option;
char *name = option;
char *fail = option;
bool range = false;
if (*endOpt == '(')
{
++endOpt;
++name;
range = true;
}
for (; *endOpt && *endOpt != ','; endOpt++)
{}
int32_t len = endOpt - name;
if (!len)
return option;
char *limitFileName = (char *)(TR::Compiler->regionAllocator.allocate(len+1));
memcpy(limitFileName, name, len);
limitFileName[len] = 0;
entry->msgInfo = (intptr_t)limitFileName;
intptr_t firstLine = 1, lastLine = INT_MAX;
if (range)
{
if (!*endOpt)
return option;
firstLine = TR::Options::getNumericValue(++endOpt);
if (*endOpt == ',')
lastLine = TR::Options::getNumericValue(++endOpt);
if (*endOpt != ')')
return option;
++endOpt;
}
FILE *limitFile = fopen(limitFileName, "r");
if (limitFile)
{
TR::CompilationFilters * filters = findOrCreateFilters(loadLimit);
filters->setDefaultExclude(true);
char limitReadBuffer[1024];
bool limitFileError = false;
int32_t lineNumber = 0;
TR_PseudoRandomNumbersListElement *pseudoRandomListHead = NULL;
if (pseudoRandomListHeadPtr)
pseudoRandomListHead = *pseudoRandomListHeadPtr;
TR_PseudoRandomNumbersListElement *curPseudoRandomListElem = pseudoRandomListHead;
int32_t curIndex = 0;
while(fgets(limitReadBuffer, sizeof(limitReadBuffer), limitFile))
{
++lineNumber;
if (lineNumber < firstLine || lineNumber > lastLine)
continue;
char includeFlag = limitReadBuffer[0];
if (strncmp(limitReadBuffer,"-precompileMethod",17) == 0)
{
char *p = limitReadBuffer+18;
if (!addFilter(p, 0, 0, lineNumber, loadLimit))
{
limitFileError = true;
break;
}
}
else if (strncmp(limitReadBuffer,"-noprecompileMethod",19) == 0)
{
char *p = limitReadBuffer+20;
if (!addFilter(p, 1, 0, lineNumber, loadLimit))
{
limitFileError = true;
break;
}
}
else if (includeFlag == '+' || includeFlag == '-')
{
char *p = limitReadBuffer+1;
int32_t optionSet;
if (*p >= '0' && *p <= '9')
optionSet = *(p++) - '0';
else
optionSet = 0;
if (*(p++) != ' ')
{
limitFileError = true;
break;
}
// Skip hotness level if it is present
//
if (*p == '(')
{
for (p++; *p && *p != ')'; p++)
{}
if (*(p++) != ')')
{
limitFileError = true;
break;
}
if (*(p++) != ' ')
{
limitFileError = true;
break;
}
}
//if (optionSet > 0)
// filters->setDefaultExclude(false);
if (!addFilter(p, (('+' == includeFlag) ? 0 : 1), optionSet, lineNumber, loadLimit))
{
limitFileError = true;
break;
}
}
else if (strncmp(limitReadBuffer,PSEUDO_RANDOM_NUMBER_PREFIX, PSEUDO_RANDOM_NUMBER_PREFIX_LEN) == 0)
{
char *p = limitReadBuffer + PSEUDO_RANDOM_NUMBER_PREFIX_LEN;
if (*(p++) != ' ')
{
limitFileError = true;
break;
}
bool isNegative = false;
if (*(p) == '-')
{
p++;
isNegative = true;
}
int32_t randNum;
while (isdigit(p[0]))
{
randNum = atoi(p);
while(isdigit(p[0]))
++p;
if (isNegative)
randNum = -1*randNum;
if ((curPseudoRandomListElem == NULL) ||
(curIndex == PSEUDO_RANDOM_NUMBERS_SIZE))
{
int32_t sz = sizeof(TR_PseudoRandomNumbersListElement);
TR_PseudoRandomNumbersListElement *newPseudoRandomListElem = (TR_PseudoRandomNumbersListElement *)(TR::Compiler->regionAllocator.allocate(sz));
newPseudoRandomListElem->_next = NULL;
curIndex = 0;
if (curPseudoRandomListElem == NULL)
*pseudoRandomListHeadPtr = newPseudoRandomListElem;
else
curPseudoRandomListElem->_next = newPseudoRandomListElem;
curPseudoRandomListElem = newPseudoRandomListElem;
}
if (curPseudoRandomListElem == NULL)
{
limitFileError = true;
break;
}
curPseudoRandomListElem->_pseudoRandomNumbers[curIndex++] = randNum;
curPseudoRandomListElem->_curIndex = curIndex;
if (*p == PSEUDO_RANDOM_SUFFIX)
break;
if (*(p++) != ' ')
{
limitFileError = true;
break;
}
isNegative = false;
if (*(p) == '-')
{
p++;
isNegative = true;
}
}
}
}
if (limitFileError)
{
TR_VerboseLog::writeLineLocked(TR_Vlog_FAILURE, "Bad limit file entry --> '%s'", limitReadBuffer);
return fail;
}
fclose(limitFile);
}
else
{
TR_VerboseLog::writeLineLocked(TR_Vlog_FAILURE, "Unable to read limit file --> '%s'", limitFileName);
return fail; //We want to fail if we can't read the file because it is too easy to miss that the file wasn't picked up
}
return endOpt;
}
char *
TR_Debug::limitOption(char *option, void *base, TR::OptionTable *entry, TR::Options * cmdLineOptions, bool loadLimit)
{
char *p = option;
// this use the old interface
TR_FilterBST *filter = addFilter(p, entry->parm1, 0, 0, loadLimit);
if (!filter)
return option;
int32_t len = p - option;
char *limitName = (char *)(TR::Compiler->regionAllocator.allocate(len+1));
memcpy(limitName, option, len);
limitName[len] = 0;
entry->msgInfo = (intptr_t)limitName;
// Look for option subset if this is "limit" rather than "exclude"
//
TR::SimpleRegex *methodRegex = filter->getRegex();
if (methodRegex && !entry->parm1 && (*p == '(' || *p == '{'))
{
TR::SimpleRegex *optLevelRegex = NULL;
// Scan off the opt level regex if it is present
//
if (*p == '{')
{
optLevelRegex = TR::SimpleRegex::create(p);
if (!optLevelRegex || *p != '(')
{
if (!optLevelRegex) {
TR_VerboseLog::writeLineLocked(TR_Vlog_FAILURE, "Bad regular expression at --> '%s'", p);
}
return option;
}
}
// If an option subset was found, save the information for later
// processing
//
char *startOptString = ++p;
int32_t parenNest = 1;
for (; *p; p++)
{
if (*p == '(')
parenNest++;
else if (*p == ')')
{
if (--parenNest == 0)
{
p++;
break;
}
}
}
if (parenNest)
return startOptString;
// Save the option set - its option string will be processed after
// the main options have been finished.
//
TR::OptionSet *newSet = (TR::OptionSet *)(TR::Compiler->regionAllocator.allocate(sizeof(TR::OptionSet)));
newSet->init(startOptString);
newSet->setMethodRegex(methodRegex);
newSet->setOptLevelRegex(optLevelRegex);
cmdLineOptions->addOptionSet(newSet);
}
return p;
}
void * TR_FilterBST::operator new(size_t size, TR::PersistentAllocator &allocator)
{
return allocator.allocate(size);
}
TR_FilterBST *TR_FilterBST::find(const char *methodName, int32_t methodNameLen)
{
// Find the filter for the given method name in the tree rooted at node.
//
int32_t rc;
TR_FilterBST *node;
for (node = this; node; node = node->getChild(rc))
{
rc = strncmp(methodName, node->getName(), methodNameLen);
if (rc == 0)
{
rc = methodNameLen - node->getNameLen();
if (rc == 0)
break;
}
rc = (rc < 0) ? 0 : 1;
}
return node;
}
TR_FilterBST *TR_FilterBST::find(const char *methodName, int32_t methodNameLen, const char *methodClass, int32_t methodClassLen, const char *methodSignature, int32_t methodSignatureLen)
{
// Find the filter for the given method name, class and signature in the
// tree rooted at node.
//
int32_t rc;
TR_FilterBST *node;
for (node = this; node; node = node->getChild(rc))
{
rc = strncmp(methodName, node->getName(), methodNameLen);
if (rc == 0)
rc = methodNameLen - node->getNameLen();
if (rc == 0)
{
rc = strncmp(methodClass, node->getClass(), methodClassLen);
if (rc == 0)
rc = methodClassLen - strlen(node->getClass());
if (rc == 0)
{
rc = strncmp(methodSignature, node->getSignature(), methodSignatureLen);
if (rc == 0)
rc = methodSignatureLen - strlen(node->getSignature());
if (rc == 0)
break;
}
}
rc = (rc < 0) ? 0 : 1;
}
return node;
}
TR_FilterBST *TR_FilterBST::findRegex(const char *methodSpec)
{
TR_FilterBST *f;
for (f=this; f && !f->_regex->match(methodSpec); f = f->getNext());
return f;
}
void TR_FilterBST::insert(TR_FilterBST *node)
{
// Insert this filter into the tree rooted at node. If the filter already
// exists, don't insert the new one.
//
int32_t rc;
while (node)
{
rc = strcmp(getName(), node->getName());
if (rc == 0)
{
rc = strcmp(getClass(), node->getClass());
if (rc == 0)
{
rc = strcmp(getSignature(), node->getSignature());
if (rc == 0)
break;
}
}
TR_FilterBST *child;
rc = (rc < 0) ? 0 : 1;
child = node->getChild(rc);
if (child)
node = child;
else
{
node->setChild(rc, this);
break;
}
}
}
void
TR_Debug::print(TR_FilterBST * filter)
{
/*
if (filter->_optionSet)
TR_VerboseLog::write(" {%d}", filter->_optionSet);
if (filter->_lineNumber)
TR_VerboseLog::write(" [%d]", filter->_lineNumber);
*/
TR_VerboseLog::vlogAcquire();
switch (filter->_filterType)
{
case TR_FILTER_EXCLUDE_NAME_ONLY:
TR_VerboseLog::write(" -%s", "NAME_ONLY");
break;
case TR_FILTER_EXCLUDE_NAME_AND_SIG:
TR_VerboseLog::write(" -%s", "NAME_AND_SIG");
break;
case TR_FILTER_EXCLUDE_SPECIFIC_METHOD:
TR_VerboseLog::write(" -%s", "SPECIFIC_METHOD");
break;
case TR_FILTER_EXCLUDE_REGEX:
TR_VerboseLog::write(" -%s", "REGEX");
break;
case TR_FILTER_NAME_ONLY:
TR_VerboseLog::write(" +%s", "NAME_ONLY");
break;
case TR_FILTER_NAME_AND_SIG:
TR_VerboseLog::write(" +%s", "NAME_AND_SIG");
break;
case TR_FILTER_SPECIFIC_METHOD:
TR_VerboseLog::write(" +%s", "SPECIFIC_METHOD");
break;
case TR_FILTER_REGEX:
TR_VerboseLog::write(" +%s", "REGEX");
break;
}
switch (filter->_filterType)
{
case TR_FILTER_EXCLUDE_NAME_ONLY:
TR_VerboseLog::write(" {^*.%s(*}\n", filter->getName());
break;
case TR_FILTER_EXCLUDE_NAME_AND_SIG:
TR_VerboseLog::write(" {^*.%s%s}\n", filter->getName(), filter->getSignature());
break;
case TR_FILTER_EXCLUDE_SPECIFIC_METHOD:
TR_VerboseLog::write(" {^%s.%s%s}\n", filter->getClass(), filter->getName(), filter->getSignature());
break;
case TR_FILTER_EXCLUDE_REGEX:
TR_VerboseLog::write(" ");
filter->getRegex()->print(true);
TR_VerboseLog::write("\n");
break;
case TR_FILTER_NAME_ONLY:
TR_VerboseLog::write(" {*.%s(*}\n", filter->getName());
break;
case TR_FILTER_NAME_AND_SIG:
TR_VerboseLog::write(" {*.%s%s}\n", filter->getName(), filter->getSignature());
break;
case TR_FILTER_SPECIFIC_METHOD:
TR_VerboseLog::write(" {%s.%s%s}\n", filter->getClass(), filter->getName(), filter->getSignature());
break;
case TR_FILTER_REGEX:
TR_VerboseLog::write(" ");
filter->getRegex()->print(false);
TR_VerboseLog::write("\n");
break;
}
if (filter->subGroup)
{
TR_VerboseLog::write(" [\n");
printFilters(filter->subGroup);
TR_VerboseLog::write(" ]\n");
}
TR_VerboseLog::vlogRelease();
}
void
TR_Debug::printFilters(TR::CompilationFilters * filters)
{
int32_t i;
if (filters)
{
if (filters->filterHash)
{
for (i = 0; i < FILTER_HASH_SIZE; i++)
if (filters->filterHash[i])
printFilterTree(filters->filterHash[i]);
}
if (filters->filterNameList)
{
printFilterTree(filters->filterNameList);
}
if (filters->filterRegexList)
{
for (TR_FilterBST * filter = filters->filterRegexList; filter; filter = filter->getNext())
print(filter);
}
}
}
void
TR_Debug::printFilters()
{
TR_VerboseLog::vlogAcquire();
TR_VerboseLog::writeLine("<compilationFilters>");
printFilters(_compilationFilters);
TR_VerboseLog::writeLine("</compilationFilters>");
TR_VerboseLog::writeLine("<relocationFilters>");
printFilters(_relocationFilters);
TR_VerboseLog::writeLine("</relocationFilters>");
TR_VerboseLog::writeLine("<inlineFilters>");
printFilters(_inlineFilters);
TR_VerboseLog::writeLine("</inlineFilters>");
TR_VerboseLog::vlogRelease();
}
void
TR_Debug::printFilterTree(TR_FilterBST *root)
{
if (root->getChild(0))