-
Notifications
You must be signed in to change notification settings - Fork 401
/
Copy pathOptionsDebug.cpp
519 lines (481 loc) · 17.3 KB
/
OptionsDebug.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
/*******************************************************************************
* Copyright IBM Corp. and others 2000
*
* 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 <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "env/FrontEnd.hpp"
#include "compile/Compilation.hpp"
#include "control/Options.hpp"
#include "control/OptionsUtil.hpp"
#include "control/Options_inlines.hpp"
#include "env/FilePointer.hpp"
#include "env/ObjectModel.hpp"
#include "env/jittypes.h"
#include "env/CompilerEnv.hpp"
#include "env/VerboseLog.hpp"
#include "infra/Assert.hpp"
#include "infra/SimpleRegex.hpp"
#include "optimizer/Optimizations.hpp"
#include "ras/Debug.hpp"
#include "ras/IgnoreLocale.hpp"
#ifdef J9_PROJECT_SPECIFIC
#include "env/VMJ9.h"
#endif
// Help text constant information
//
#define OPTION_NAME_INDENT 3
#define DESCRIPTION_START_COLUMN 40
#define DESCRIPTION_TEXT_INDENT 3
#define DEFAULT_OPTION_LINE_WIDTH 80
static char optionCategories[] = {' ','C','O','L','D','R','I','M',0}; // Must match categories[] in codegen.dev/Options.cpp
static const char *optionCategoryNames[] = {"\nGeneral options:\n",
"\nCode generation options:\n",
"\nOptimization options:\n",
"\nLogging and display options:\n",
"\nDebugging options:\n",
"\nRecompilation and profiling options:\n",
"\nInternal options:\n",
"\nOther options:\n",
0 // Fail quickly if we run past the end of this array
};
TR::FILE *TR_Debug::findLogFile(TR::Options *cmdLineOptions, TR::OptionSet *optSet, char *logFileName)
{
char *fileName = cmdLineOptions->getLogFileName();
TR::FILE *logFile = NULL;
if (fileName && !STRICMP(logFileName, fileName))
logFile = cmdLineOptions->getLogFile();
else
{
for (TR::OptionSet *prev = cmdLineOptions->getFirstOptionSet(); prev && prev != optSet; prev = prev->getNext())
{
fileName = prev->getOptions() ? prev->getOptions()->getLogFileName() : NULL;
if (fileName && !STRICMP(logFileName, fileName))
{
logFile = prev->getOptions()->getLogFile();
break;
}
}
}
return logFile;
}
TR::FILE *TR_Debug::findLogFile(TR::Options *aotCmdLineOptions, TR::Options *jitCmdLineOptions, TR::OptionSet *optSet, char *logFileName)
{
if (aotCmdLineOptions)
{
TR::FILE *logFile = findLogFile(aotCmdLineOptions, optSet, logFileName);
if (logFile != NULL)
return logFile;
}
if (jitCmdLineOptions)
{
TR::FILE *logFile = findLogFile(jitCmdLineOptions, optSet, logFileName);
if (logFile != NULL)
return logFile;
}
return NULL;
}
// Search all options sets, jitCmdLineOptions and aotCmdLineOptions to see if they
// have speciafied a log file with the given name. All options that match are
// returned in optionsArray. if the size of the array is insufficient to hold them
// all, the required size is returned so that the caller can provide a bigger array
int32_t TR_Debug::findLogFile(const char *logFileName, TR::Options *aotCmdLineOptions, TR::Options *jitCmdLineOptions, TR::Options **optionsArray, int32_t arraySize)
{
int32_t index = 0;
findLogFile(logFileName, aotCmdLineOptions, optionsArray, arraySize, index);
findLogFile(logFileName, jitCmdLineOptions, optionsArray, arraySize, index);
return index;
}
void TR_Debug::findLogFile(const char *logFileName, TR::Options *cmdOptions, TR::Options **optionsArray,
int32_t arraySize, int32_t &index)
{
if (!cmdOptions)
return;
if (cmdOptions->getLogFileName() && !STRICMP(logFileName, cmdOptions->getLogFileName()))
{
if (index < arraySize)
optionsArray[index] = cmdOptions;
index++;
}
for (TR::OptionSet *optSet = cmdOptions->getFirstOptionSet(); optSet; optSet = optSet->getNext())
{
if (optSet->getOptions() && optSet->getOptions()->getLogFileName() && !STRICMP(logFileName, optSet->getOptions()->getLogFileName()))
{
if (index < arraySize)
optionsArray[index] = optSet->getOptions();
index++;
}
}
}
static bool regexExcludes(TR::SimpleRegex *regex, const char *string)
{
if (regex)
return !regex->match(string, false); // case-insensitive
else
return false;
}
void TR_Debug::dumpOptionHelp(TR::OptionTable * firstOjit, TR::OptionTable * firstOfe, TR::SimpleRegex *nameFilter)
{
static int optionLineWidth=0;
if (!optionLineWidth)
{
static char *columns = ::feGetEnv("COLUMNS");
if (columns)
optionLineWidth = atoi(columns);
else
optionLineWidth = DEFAULT_OPTION_LINE_WIDTH;
}
TR::OptionTable * entry;
TR_VerboseLog::CriticalSection vlogLock;
TR_VerboseLog::writeLine(TR_Vlog_INFO,"Usage: -Xjit:option([,option]*)");
for (int32_t cat = 0; optionCategories[cat]; cat++)
{
// Don't print internal options
// TODO: Perhaps add something like -Xjit:helpInternal to print these
//
if (optionCategories[cat] == 'I')
continue;
TR::OptionTable * ojit = firstOjit;
TR::OptionTable * ofe = firstOfe;
bool entryFound = false;
while (ojit->name || ofe->name)
{
if (ojit->name
&& ( ojit->helpText == NULL
|| ojit->helpText[0] != optionCategories[cat]
|| (regexExcludes(nameFilter, ojit->name) && regexExcludes(nameFilter, ojit->helpText))))
{
ojit++;
continue;
}
if (ofe->name
&& ( ofe->helpText == NULL
|| ofe->helpText[0] != optionCategories[cat]
|| (regexExcludes(nameFilter, ofe->name) && regexExcludes(nameFilter, ofe->helpText))))
{
ofe++;
continue;
}
if (!ojit->name)
entry = ofe++;
else if (!ofe->name)
entry = ojit++;
else
{
int32_t diff = STRICMP(ojit->name, ofe->name);
TR_ASSERT(diff != 0, "Two options with name '%s'", ojit->name);
if (diff < 0)
entry = ojit++;
else
entry = ofe++;
}
// Print category header if this is the first entry in category
//
if (!entryFound)
{
entryFound = true;
TR_VerboseLog::writeLine(TR_Vlog_INFO,optionCategoryNames[cat]);
}
// Set up the option name
//
if (!entry->length)
entry->length = static_cast<int32_t>(strlen(entry->name));
TR_VerboseLog::write("%*s%s", OPTION_NAME_INDENT, " ", entry->name);
int32_t currentColumn = static_cast<int32_t>(entry->length+OPTION_NAME_INDENT);
// Set up the argument text
//
int32_t i;
for (i = 1; entry->helpText[i] && entry->helpText[i] != '\t'; i++)
{}
if (i > 1)
TR_VerboseLog::write("%.*s", i-1, entry->helpText+1);
currentColumn += i-1;
// Align option description
//
if (currentColumn < DESCRIPTION_START_COLUMN)
TR_VerboseLog::write("%*s", DESCRIPTION_START_COLUMN-currentColumn, " ");
else
{
TR_VerboseLog::writeLine("");
TR_VerboseLog::write(TR_Vlog_INFO, "%*s", DESCRIPTION_START_COLUMN, " ");
}
currentColumn = DESCRIPTION_START_COLUMN;
// Write option description
//
if (entry->helpText[i] == '\t')
i++;
int32_t start = i, lastWordBreak = i;
while (entry->helpText[i])
{
if (entry->helpText[i] == '\n')
// Force a line break
{
lastWordBreak = i;
i = 9999;
}
if ((i - start) >= (optionLineWidth - DESCRIPTION_START_COLUMN))
{
if (lastWordBreak == start)
lastWordBreak = i;
TR_VerboseLog::write("%.*s", lastWordBreak-start, entry->helpText+start);
currentColumn = DESCRIPTION_START_COLUMN + DESCRIPTION_TEXT_INDENT;
TR_VerboseLog::writeLine("");
TR_VerboseLog::write(TR_Vlog_INFO, "%*s", currentColumn, " ");
start = i = ++lastWordBreak;
continue;
}
if (entry->helpText[i] == ' ')
lastWordBreak = i;
i++;
}
TR_VerboseLog::write("%s", entry->helpText+start);
}
}
TR_VerboseLog::writeLine("");
TR_VerboseLog::writeLine(TR_Vlog_INFO, "");
}
void
TR_Debug::dumpOptions(
const char *optionsType,
const char *options,
const char *envOptions,
TR::Options *cmdLineOptions,
TR::OptionTable *ojit,
TR::OptionTable *ofe,
void * feBase,
TR_FrontEnd *fe)
{
TR::OptionTable *entry;
char *base;
TR::Compilation* comp = TR::comp();
static int printCounter = 0;
static int vmCounter = 0;
#ifdef J9_PROJECT_SPECIFIC
TR_J9VMBase *fej9 = (TR_J9VMBase *)fe;
#endif
TR_VerboseLog::CriticalSection vlogLock;
if(!vmCounter)
TR_VerboseLog::writeLine(TR_Vlog_INFO,"_______________________________________");
if(!printCounter)
{
fe->printVerboseLogHeader(cmdLineOptions);
printCounter++;
}
bool extendCheck = false;
if (cmdLineOptions->getVerboseOption(TR_VerboseExtended))
{
extendCheck = true;
TR_VerboseLog::writeLine(TR_Vlog_INFO,"%s type: Testarossa (Full) ", optionsType);
TR_VerboseLog::writeLine(TR_Vlog_INFO,"%s ", optionsType);
}
TR_VerboseLog::writeLine(TR_Vlog_INFO,"_______________________________________");
if(vmCounter)
TR_VerboseLog::writeLine(TR_Vlog_INFO,"JIT ");
else
TR_VerboseLog::writeLine(TR_Vlog_INFO,"AOT ");
vmCounter++;
TR_VerboseLog::writeLine(TR_Vlog_INFO,"options specified:");
TR_VerboseLog::writeLine(TR_Vlog_INFO," %s", options);
if (envOptions)
{
if(*options)
TR_VerboseLog::write(",");
TR_VerboseLog::write(envOptions);
}
TR_VerboseLog::writeLine(TR_Vlog_INFO,"");
TR_VerboseLog::writeLine(TR_Vlog_INFO,"options in effect:");
while (ojit->name || ofe->name)
{
if (ojit->name &&
(!ojit->msg || (ojit->msg[0] == 'F' && !(ojit->msgInfo & OPTION_FOUND))) && !ojit->enabled)
{
ojit++;
continue;
}
if (ofe->name &&
(!ofe->msg || (ofe->msg[0] == 'F' && !(ofe->msgInfo & OPTION_FOUND))) && !ofe->enabled)
{
ofe++;
continue;
}
if (!ojit->name)
{
entry = ofe++;
base = (char*)feBase;
}
else if (!ofe->name)
{
entry = ojit++;
base = (char*)cmdLineOptions;
}
else
{
int32_t diff = STRICMP(ojit->name, ofe->name);
TR_ASSERT(diff != 0, "Two options with help text");
if (diff < 0)
{
entry = ojit++;
base = (char*)cmdLineOptions;
}
else
{
entry = ofe++;
base = (char*)feBase;
}
}
// See if this entry needs to be printed
//
bool printIt = true;
intptr_t value = 0;
TR::SimpleRegex * regex = 0;
if (entry->fcn == TR::Options::setBit)
{
if (entry->msg[0] == 'P')
{
uint32_t word=*((uint32_t*)(base+entry->parm1));
printIt = (word & (entry->parm2)) != 0;
}
}
else if (entry->fcn == TR::Options::setVerboseBits)
{
if (entry->msg[0] == 'P')
printIt = cmdLineOptions->isAnyVerboseOptionSet();
}
else if (entry->fcn == TR::Options::resetBit)
{
if (entry->msg[0] == 'P')
printIt = ((*((int32_t*)(base+entry->parm1))) & entry->parm2) == 0;
}
else if (entry->fcn == TR::Options::setValue)
{
value = *(base+entry->parm1);
if (entry->msg[0] == 'P')
printIt = (value == entry->parm2);
}
else if (entry->fcn == TR::Options::set32BitValue)
{
value = (intptr_t)(*((int32_t*)(base+entry->parm1)));
if (entry->msg[0] == 'P')
printIt = (value == entry->parm2);
}
else if (entry->fcn == TR::Options::setNumeric)
{
value = (intptr_t)(*((intptr_t*)(base+entry->parm1)));
if (entry->msg[0] == 'P')
printIt = (value != 0);
}
else if (entry->fcn == TR::Options::set32BitNumeric || entry->fcn == TR::Options::set32BitSignedNumeric || entry->fcn == TR::Options::setCount)
{
value = (intptr_t)(*((int32_t*)(base+entry->parm1)));
if (entry->msg[0] == 'P')
printIt = (value != 0);
}
else if (entry->fcn == TR::Options::setStaticNumericKBAdjusted)
{
value = *(int32_t *)entry->parm1;
if (entry->msg[0] == 'P')
printIt = (value != 0);
}
else if (entry->fcn == TR::Options::setStaticNumeric)
{
value = *(int32_t *)entry->parm1;
if (entry->msg[0] == 'P')
printIt = (value != 0);
}
else if (entry->fcn == TR::Options::setString)
{
value = (intptr_t)(*((char**)(base+entry->parm1)));
if (entry->msg[0] == 'P')
printIt = (value != 0);
}
else if (entry->fcn == TR::Options::setStaticString)
{
value = (intptr_t)(*((char**)(entry->parm1)));
if (entry->msg[0] == 'P')
printIt = (value != 0);
}
#ifdef J9_PROJECT_SPECIFIC
else if (entry->fcn == TR::Options::setStringForPrivateBase)
{
char *localBase = (char*)fej9->getPrivateConfig();
value = (intptr_t)(*((char**)(localBase+entry->parm1)));
if (entry->msg[0] == 'P')
printIt = (value != 0);
}
else if (entry->fcn == TR::Options::setJitConfigNumericValue)
{
value = (intptr_t)(*((char**)(base+entry->parm1)));
printIt = true;
}
#endif /* J9_PROJECT_SPECIFIC */
else if (entry->fcn == TR::Options::disableOptimization)
{
value = ((TR::Options *)base)->isDisabled((OMR::Optimizations)entry->parm1);
printIt = (value != 0);
}
else if (entry->fcn == TR::Options::setRegex)
{
regex = *(TR::SimpleRegex **)(base+entry->parm1);
printIt = (regex != 0);
}
else if (entry->fcn == TR::Options::breakOnLoad)
{
printIt = false;
}
else
{
value = entry->msgInfo;
if (entry->msg[0] == 'P')
printIt = (value != 0);
}
if (printIt && (entry->msg[0]=='F'|| extendCheck))
{
TR_VerboseLog::write(TR_Vlog_INFO," %s", entry->name);
if (regex)
regex->print(false);
else if (entry->msg[1])
TR_VerboseLog::write(entry->msg+1, value);
else if (entry->fcn == TR::Options::setVerboseBits || entry->fcn == TR::Options::setVerboseBitsInJitPrivateConfig)
{
//since java uses different function, we need to check for that to get our verbose options printed
TR_VerboseLog::write("{");
base = (char*)cmdLineOptions;
const char *sep = "";
for (int i=0; i < TR_NumVerboseOptions; i++)
{
TR_VerboseFlags flag = (TR_VerboseFlags)i;
if (cmdLineOptions->getVerboseOption(flag))
{
TR_VerboseLog::write("%s%s", sep, cmdLineOptions->getVerboseOptionName(flag));
sep = "|";
}
}
TR_VerboseLog::write("}");
}
TR_VerboseLog::writeLine("");
}
}
#ifdef J9_PROJECT_SPECIFIC
if (fej9->generateCompressedPointers())
{
TR_VerboseLog::writeLine(TR_Vlog_INFO, " compressedRefs shiftAmount=%d", TR::Compiler->om.compressedReferenceShift());
}
#endif
}