Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/compiler/compilerOracle.cpp
32285 views
1
/*
2
* Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*
23
*/
24
25
#include "precompiled.hpp"
26
#include "compiler/compilerOracle.hpp"
27
#include "memory/allocation.inline.hpp"
28
#include "memory/oopFactory.hpp"
29
#include "memory/resourceArea.hpp"
30
#include "oops/klass.hpp"
31
#include "oops/method.hpp"
32
#include "oops/oop.inline.hpp"
33
#include "oops/symbol.hpp"
34
#include "runtime/handles.inline.hpp"
35
#include "runtime/jniHandles.hpp"
36
37
class MethodMatcher : public CHeapObj<mtCompiler> {
38
public:
39
enum Mode {
40
Exact,
41
Prefix = 1,
42
Suffix = 2,
43
Substring = Prefix | Suffix,
44
Any,
45
Unknown = -1
46
};
47
48
protected:
49
Symbol* _class_name;
50
Symbol* _method_name;
51
Symbol* _signature;
52
Mode _class_mode;
53
Mode _method_mode;
54
MethodMatcher* _next;
55
56
static bool match(Symbol* candidate, Symbol* match, Mode match_mode);
57
58
Symbol* class_name() const { return _class_name; }
59
Symbol* method_name() const { return _method_name; }
60
Symbol* signature() const { return _signature; }
61
62
public:
63
MethodMatcher(Symbol* class_name, Mode class_mode,
64
Symbol* method_name, Mode method_mode,
65
Symbol* signature, MethodMatcher* next);
66
MethodMatcher(Symbol* class_name, Symbol* method_name, MethodMatcher* next);
67
68
// utility method
69
MethodMatcher* find(methodHandle method) {
70
Symbol* class_name = method->method_holder()->name();
71
Symbol* method_name = method->name();
72
for (MethodMatcher* current = this; current != NULL; current = current->_next) {
73
if (match(class_name, current->class_name(), current->_class_mode) &&
74
match(method_name, current->method_name(), current->_method_mode) &&
75
(current->signature() == NULL || current->signature() == method->signature())) {
76
return current;
77
}
78
}
79
return NULL;
80
}
81
82
bool match(methodHandle method) {
83
return find(method) != NULL;
84
}
85
86
MethodMatcher* next() const { return _next; }
87
88
static void print_symbol(Symbol* h, Mode mode) {
89
ResourceMark rm;
90
91
if (mode == Suffix || mode == Substring || mode == Any) {
92
tty->print("*");
93
}
94
if (mode != Any) {
95
h->print_symbol_on(tty);
96
}
97
if (mode == Prefix || mode == Substring) {
98
tty->print("*");
99
}
100
}
101
102
void print_base() {
103
print_symbol(class_name(), _class_mode);
104
tty->print(".");
105
print_symbol(method_name(), _method_mode);
106
if (signature() != NULL) {
107
tty->print(" ");
108
signature()->print_symbol_on(tty);
109
}
110
}
111
112
virtual void print() {
113
print_base();
114
tty->cr();
115
}
116
};
117
118
MethodMatcher::MethodMatcher(Symbol* class_name, Symbol* method_name, MethodMatcher* next) {
119
_class_name = class_name;
120
_method_name = method_name;
121
_next = next;
122
_class_mode = MethodMatcher::Exact;
123
_method_mode = MethodMatcher::Exact;
124
_signature = NULL;
125
}
126
127
128
MethodMatcher::MethodMatcher(Symbol* class_name, Mode class_mode,
129
Symbol* method_name, Mode method_mode,
130
Symbol* signature, MethodMatcher* next):
131
_class_mode(class_mode)
132
, _method_mode(method_mode)
133
, _next(next)
134
, _class_name(class_name)
135
, _method_name(method_name)
136
, _signature(signature) {
137
}
138
139
bool MethodMatcher::match(Symbol* candidate, Symbol* match, Mode match_mode) {
140
if (match_mode == Any) {
141
return true;
142
}
143
144
if (match_mode == Exact) {
145
return candidate == match;
146
}
147
148
ResourceMark rm;
149
const char * candidate_string = candidate->as_C_string();
150
const char * match_string = match->as_C_string();
151
152
switch (match_mode) {
153
case Prefix:
154
return strstr(candidate_string, match_string) == candidate_string;
155
156
case Suffix: {
157
size_t clen = strlen(candidate_string);
158
size_t mlen = strlen(match_string);
159
return clen >= mlen && strcmp(candidate_string + clen - mlen, match_string) == 0;
160
}
161
162
case Substring:
163
return strstr(candidate_string, match_string) != NULL;
164
165
default:
166
return false;
167
}
168
}
169
170
enum OptionType {
171
IntxType,
172
UintxType,
173
BoolType,
174
CcstrType,
175
UnknownType
176
};
177
178
/* Methods to map real type names to OptionType */
179
template<typename T>
180
static OptionType get_type_for() {
181
return UnknownType;
182
};
183
184
template<> OptionType get_type_for<intx>() {
185
return IntxType;
186
}
187
188
template<> OptionType get_type_for<uintx>() {
189
return UintxType;
190
}
191
192
template<> OptionType get_type_for<bool>() {
193
return BoolType;
194
}
195
196
template<> OptionType get_type_for<ccstr>() {
197
return CcstrType;
198
}
199
200
template<typename T>
201
static const T copy_value(const T value) {
202
return value;
203
}
204
205
template<> const ccstr copy_value<ccstr>(const ccstr value) {
206
return (const ccstr)strdup(value);
207
}
208
209
template <typename T>
210
class TypedMethodOptionMatcher : public MethodMatcher {
211
const char* _option;
212
OptionType _type;
213
const T _value;
214
215
public:
216
TypedMethodOptionMatcher(Symbol* class_name, Mode class_mode,
217
Symbol* method_name, Mode method_mode,
218
Symbol* signature, const char* opt,
219
const T value, MethodMatcher* next) :
220
MethodMatcher(class_name, class_mode, method_name, method_mode, signature, next),
221
_type(get_type_for<T>()), _value(copy_value<T>(value)) {
222
_option = strdup(opt);
223
}
224
225
~TypedMethodOptionMatcher() {
226
free((void*)_option);
227
}
228
229
TypedMethodOptionMatcher* match(methodHandle method, const char* opt) {
230
TypedMethodOptionMatcher* current = this;
231
while (current != NULL) {
232
current = (TypedMethodOptionMatcher*)current->find(method);
233
if (current == NULL) {
234
return NULL;
235
}
236
if (strcmp(current->_option, opt) == 0) {
237
return current;
238
}
239
current = current->next();
240
}
241
return NULL;
242
}
243
244
TypedMethodOptionMatcher* next() {
245
return (TypedMethodOptionMatcher*)_next;
246
}
247
248
OptionType get_type(void) {
249
return _type;
250
};
251
252
T value() { return _value; }
253
254
void print() {
255
ttyLocker ttyl;
256
print_base();
257
tty->print(" %s", _option);
258
tty->print(" <unknown option type>");
259
tty->cr();
260
}
261
};
262
263
template<>
264
void TypedMethodOptionMatcher<intx>::print() {
265
ttyLocker ttyl;
266
print_base();
267
tty->print(" intx %s", _option);
268
tty->print(" = " INTX_FORMAT, _value);
269
tty->cr();
270
};
271
272
template<>
273
void TypedMethodOptionMatcher<uintx>::print() {
274
ttyLocker ttyl;
275
print_base();
276
tty->print(" uintx %s", _option);
277
tty->print(" = " UINTX_FORMAT, _value);
278
tty->cr();
279
};
280
281
template<>
282
void TypedMethodOptionMatcher<bool>::print() {
283
ttyLocker ttyl;
284
print_base();
285
tty->print(" bool %s", _option);
286
tty->print(" = %s", _value ? "true" : "false");
287
tty->cr();
288
};
289
290
template<>
291
void TypedMethodOptionMatcher<ccstr>::print() {
292
ttyLocker ttyl;
293
print_base();
294
tty->print(" const char* %s", _option);
295
tty->print(" = '%s'", _value);
296
tty->cr();
297
};
298
299
// this must parallel the command_names below
300
enum OracleCommand {
301
UnknownCommand = -1,
302
OracleFirstCommand = 0,
303
BreakCommand = OracleFirstCommand,
304
PrintCommand,
305
ExcludeCommand,
306
InlineCommand,
307
DontInlineCommand,
308
CompileOnlyCommand,
309
LogCommand,
310
OptionCommand,
311
QuietCommand,
312
HelpCommand,
313
OracleCommandCount
314
};
315
316
// this must parallel the enum OracleCommand
317
static const char * command_names[] = {
318
"break",
319
"print",
320
"exclude",
321
"inline",
322
"dontinline",
323
"compileonly",
324
"log",
325
"option",
326
"quiet",
327
"help"
328
};
329
330
class MethodMatcher;
331
static MethodMatcher* lists[OracleCommandCount] = { 0, };
332
333
334
static bool check_predicate(OracleCommand command, methodHandle method) {
335
return ((lists[command] != NULL) &&
336
!method.is_null() &&
337
lists[command]->match(method));
338
}
339
340
341
static MethodMatcher* add_predicate(OracleCommand command,
342
Symbol* class_name, MethodMatcher::Mode c_mode,
343
Symbol* method_name, MethodMatcher::Mode m_mode,
344
Symbol* signature) {
345
assert(command != OptionCommand, "must use add_option_string");
346
if (command == LogCommand && !LogCompilation && lists[LogCommand] == NULL)
347
tty->print_cr("Warning: +LogCompilation must be enabled in order for individual methods to be logged.");
348
lists[command] = new MethodMatcher(class_name, c_mode, method_name, m_mode, signature, lists[command]);
349
return lists[command];
350
}
351
352
template<typename T>
353
static MethodMatcher* add_option_string(Symbol* class_name, MethodMatcher::Mode c_mode,
354
Symbol* method_name, MethodMatcher::Mode m_mode,
355
Symbol* signature,
356
const char* option,
357
T value) {
358
lists[OptionCommand] = new TypedMethodOptionMatcher<T>(class_name, c_mode, method_name, m_mode,
359
signature, option, value, lists[OptionCommand]);
360
return lists[OptionCommand];
361
}
362
363
template<typename T>
364
static bool get_option_value(methodHandle method, const char* option, T& value) {
365
TypedMethodOptionMatcher<T>* m;
366
if (lists[OptionCommand] != NULL
367
&& (m = ((TypedMethodOptionMatcher<T>*)lists[OptionCommand])->match(method, option)) != NULL
368
&& m->get_type() == get_type_for<T>()) {
369
value = m->value();
370
return true;
371
} else {
372
return false;
373
}
374
}
375
376
bool CompilerOracle::has_option_string(methodHandle method, const char* option) {
377
bool value = false;
378
get_option_value(method, option, value);
379
return value;
380
}
381
382
template<typename T>
383
bool CompilerOracle::has_option_value(methodHandle method, const char* option, T& value) {
384
return ::get_option_value(method, option, value);
385
}
386
387
// Explicit instantiation for all OptionTypes supported.
388
template bool CompilerOracle::has_option_value<intx>(methodHandle method, const char* option, intx& value);
389
template bool CompilerOracle::has_option_value<uintx>(methodHandle method, const char* option, uintx& value);
390
template bool CompilerOracle::has_option_value<bool>(methodHandle method, const char* option, bool& value);
391
template bool CompilerOracle::has_option_value<ccstr>(methodHandle method, const char* option, ccstr& value);
392
393
bool CompilerOracle::should_exclude(methodHandle method, bool& quietly) {
394
quietly = true;
395
if (lists[ExcludeCommand] != NULL) {
396
if (lists[ExcludeCommand]->match(method)) {
397
quietly = _quiet;
398
return true;
399
}
400
}
401
402
if (lists[CompileOnlyCommand] != NULL) {
403
return !lists[CompileOnlyCommand]->match(method);
404
}
405
return false;
406
}
407
408
409
bool CompilerOracle::should_inline(methodHandle method) {
410
return (check_predicate(InlineCommand, method));
411
}
412
413
414
bool CompilerOracle::should_not_inline(methodHandle method) {
415
return (check_predicate(DontInlineCommand, method));
416
}
417
418
419
bool CompilerOracle::should_print(methodHandle method) {
420
return (check_predicate(PrintCommand, method));
421
}
422
423
424
bool CompilerOracle::should_log(methodHandle method) {
425
if (!LogCompilation) return false;
426
if (lists[LogCommand] == NULL) return true; // by default, log all
427
return (check_predicate(LogCommand, method));
428
}
429
430
431
bool CompilerOracle::should_break_at(methodHandle method) {
432
return check_predicate(BreakCommand, method);
433
}
434
435
436
static OracleCommand parse_command_name(const char * line, int* bytes_read) {
437
assert(ARRAY_SIZE(command_names) == OracleCommandCount,
438
"command_names size mismatch");
439
440
*bytes_read = 0;
441
char command[33];
442
int result = sscanf(line, "%32[a-z]%n", command, bytes_read);
443
for (uint i = 0; i < ARRAY_SIZE(command_names); i++) {
444
if (strcmp(command, command_names[i]) == 0) {
445
return (OracleCommand)i;
446
}
447
}
448
return UnknownCommand;
449
}
450
451
452
static void usage() {
453
tty->print_cr(" CompileCommand and the CompilerOracle allows simple control over");
454
tty->print_cr(" what's allowed to be compiled. The standard supported directives");
455
tty->print_cr(" are exclude and compileonly. The exclude directive stops a method");
456
tty->print_cr(" from being compiled and compileonly excludes all methods except for");
457
tty->print_cr(" the ones mentioned by compileonly directives. The basic form of");
458
tty->print_cr(" all commands is a command name followed by the name of the method");
459
tty->print_cr(" in one of two forms: the standard class file format as in");
460
tty->print_cr(" class/name.methodName or the PrintCompilation format");
461
tty->print_cr(" class.name::methodName. The method name can optionally be followed");
462
tty->print_cr(" by a space then the signature of the method in the class file");
463
tty->print_cr(" format. Otherwise the directive applies to all methods with the");
464
tty->print_cr(" same name and class regardless of signature. Leading and trailing");
465
tty->print_cr(" *'s in the class and/or method name allows a small amount of");
466
tty->print_cr(" wildcarding. ");
467
tty->cr();
468
tty->print_cr(" Examples:");
469
tty->cr();
470
tty->print_cr(" exclude java/lang/StringBuffer.append");
471
tty->print_cr(" compileonly java/lang/StringBuffer.toString ()Ljava/lang/String;");
472
tty->print_cr(" exclude java/lang/String*.*");
473
tty->print_cr(" exclude *.toString");
474
}
475
476
477
// The characters allowed in a class or method name. All characters > 0x7f
478
// are allowed in order to handle obfuscated class files (e.g. Volano)
479
#define RANGEBASE "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789$_<>" \
480
"\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f" \
481
"\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f" \
482
"\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf" \
483
"\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf" \
484
"\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf" \
485
"\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf" \
486
"\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef" \
487
"\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff"
488
489
#define RANGE0 "[*" RANGEBASE "]"
490
#define RANGESLASH "[*" RANGEBASE "/]"
491
492
static MethodMatcher::Mode check_mode(char name[], const char*& error_msg) {
493
int match = MethodMatcher::Exact;
494
while (name[0] == '*') {
495
match |= MethodMatcher::Suffix;
496
strcpy(name, name + 1);
497
}
498
499
if (strcmp(name, "*") == 0) return MethodMatcher::Any;
500
501
size_t len = strlen(name);
502
while (len > 0 && name[len - 1] == '*') {
503
match |= MethodMatcher::Prefix;
504
name[--len] = '\0';
505
}
506
507
if (strstr(name, "*") != NULL) {
508
error_msg = " Embedded * not allowed";
509
return MethodMatcher::Unknown;
510
}
511
return (MethodMatcher::Mode)match;
512
}
513
514
static bool scan_line(const char * line,
515
char class_name[], MethodMatcher::Mode* c_mode,
516
char method_name[], MethodMatcher::Mode* m_mode,
517
int* bytes_read, const char*& error_msg) {
518
*bytes_read = 0;
519
error_msg = NULL;
520
if (2 == sscanf(line, "%*[ \t]%255" RANGESLASH "%*[ ]" "%255" RANGE0 "%n", class_name, method_name, bytes_read)) {
521
*c_mode = check_mode(class_name, error_msg);
522
*m_mode = check_mode(method_name, error_msg);
523
return *c_mode != MethodMatcher::Unknown && *m_mode != MethodMatcher::Unknown;
524
}
525
return false;
526
}
527
528
529
530
// Scan next flag and value in line, return MethodMatcher object on success, NULL on failure.
531
// On failure, error_msg contains description for the first error.
532
// For future extensions: set error_msg on first error.
533
static MethodMatcher* scan_flag_and_value(const char* type, const char* line, int& total_bytes_read,
534
Symbol* c_name, MethodMatcher::Mode c_match,
535
Symbol* m_name, MethodMatcher::Mode m_match,
536
Symbol* signature,
537
char* errorbuf, const int buf_size) {
538
total_bytes_read = 0;
539
int bytes_read = 0;
540
char flag[256];
541
542
// Read flag name.
543
if (sscanf(line, "%*[ \t]%255[a-zA-Z0-9]%n", flag, &bytes_read) == 1) {
544
line += bytes_read;
545
total_bytes_read += bytes_read;
546
547
// Read value.
548
if (strcmp(type, "intx") == 0) {
549
intx value;
550
if (sscanf(line, "%*[ \t]" INTX_FORMAT "%n", &value, &bytes_read) == 1) {
551
total_bytes_read += bytes_read;
552
return add_option_string(c_name, c_match, m_name, m_match, signature, flag, value);
553
} else {
554
jio_snprintf(errorbuf, buf_size, " Value cannot be read for flag %s of type %s ", flag, type);
555
}
556
} else if (strcmp(type, "uintx") == 0) {
557
uintx value;
558
if (sscanf(line, "%*[ \t]" UINTX_FORMAT "%n", &value, &bytes_read) == 1) {
559
total_bytes_read += bytes_read;
560
return add_option_string(c_name, c_match, m_name, m_match, signature, flag, value);
561
} else {
562
jio_snprintf(errorbuf, buf_size, " Value cannot be read for flag %s of type %s", flag, type);
563
}
564
} else if (strcmp(type, "ccstr") == 0) {
565
ResourceMark rm;
566
char* value = NEW_RESOURCE_ARRAY(char, strlen(line) + 1);
567
if (sscanf(line, "%*[ \t]%255[_a-zA-Z0-9]%n", value, &bytes_read) == 1) {
568
total_bytes_read += bytes_read;
569
return add_option_string(c_name, c_match, m_name, m_match, signature, flag, (ccstr)value);
570
} else {
571
jio_snprintf(errorbuf, buf_size, " Value cannot be read for flag %s of type %s", flag, type);
572
}
573
} else if (strcmp(type, "ccstrlist") == 0) {
574
// Accumulates several strings into one. The internal type is ccstr.
575
ResourceMark rm;
576
char* value = NEW_RESOURCE_ARRAY(char, strlen(line) + 1);
577
char* next_value = value;
578
if (sscanf(line, "%*[ \t]%255[_a-zA-Z0-9]%n", next_value, &bytes_read) == 1) {
579
total_bytes_read += bytes_read;
580
line += bytes_read;
581
next_value += bytes_read;
582
char* end_value = next_value-1;
583
while (sscanf(line, "%*[ \t]%255[_a-zA-Z0-9]%n", next_value, &bytes_read) == 1) {
584
total_bytes_read += bytes_read;
585
line += bytes_read;
586
*end_value = ' '; // override '\0'
587
next_value += bytes_read;
588
end_value = next_value-1;
589
}
590
return add_option_string(c_name, c_match, m_name, m_match, signature, flag, (ccstr)value);
591
} else {
592
jio_snprintf(errorbuf, buf_size, " Value cannot be read for flag %s of type %s", flag, type);
593
}
594
} else if (strcmp(type, "bool") == 0) {
595
char value[256];
596
if (sscanf(line, "%*[ \t]%255[a-zA-Z]%n", value, &bytes_read) == 1) {
597
if (strcmp(value, "true") == 0) {
598
total_bytes_read += bytes_read;
599
return add_option_string(c_name, c_match, m_name, m_match, signature, flag, true);
600
} else if (strcmp(value, "false") == 0) {
601
total_bytes_read += bytes_read;
602
return add_option_string(c_name, c_match, m_name, m_match, signature, flag, false);
603
} else {
604
jio_snprintf(errorbuf, buf_size, " Value cannot be read for flag %s of type %s", flag, type);
605
}
606
} else {
607
jio_snprintf(errorbuf, sizeof(errorbuf), " Value cannot be read for flag %s of type %s", flag, type);
608
}
609
} else {
610
jio_snprintf(errorbuf, sizeof(errorbuf), " Type %s not supported ", type);
611
}
612
} else {
613
jio_snprintf(errorbuf, sizeof(errorbuf), " Flag name for type %s should be alphanumeric ", type);
614
}
615
return NULL;
616
}
617
618
void CompilerOracle::parse_from_line(char* line) {
619
if (line[0] == '\0') return;
620
if (line[0] == '#') return;
621
622
bool have_colon = (strstr(line, "::") != NULL);
623
for (char* lp = line; *lp != '\0'; lp++) {
624
// Allow '.' to separate the class name from the method name.
625
// This is the preferred spelling of methods:
626
// exclude java/lang/String.indexOf(I)I
627
// Allow ',' for spaces (eases command line quoting).
628
// exclude,java/lang/String.indexOf
629
// For backward compatibility, allow space as separator also.
630
// exclude java/lang/String indexOf
631
// exclude,java/lang/String,indexOf
632
// For easy cut-and-paste of method names, allow VM output format
633
// as produced by Method::print_short_name:
634
// exclude java.lang.String::indexOf
635
// For simple implementation convenience here, convert them all to space.
636
if (have_colon) {
637
if (*lp == '.') *lp = '/'; // dots build the package prefix
638
if (*lp == ':') *lp = ' ';
639
}
640
if (*lp == ',' || *lp == '.') *lp = ' ';
641
}
642
643
char* original_line = line;
644
int bytes_read;
645
OracleCommand command = parse_command_name(line, &bytes_read);
646
line += bytes_read;
647
ResourceMark rm;
648
649
if (command == UnknownCommand) {
650
ttyLocker ttyl;
651
tty->print_cr("CompilerOracle: unrecognized line");
652
tty->print_cr(" \"%s\"", original_line);
653
return;
654
}
655
656
if (command == QuietCommand) {
657
_quiet = true;
658
return;
659
}
660
661
if (command == HelpCommand) {
662
usage();
663
return;
664
}
665
666
MethodMatcher::Mode c_match = MethodMatcher::Exact;
667
MethodMatcher::Mode m_match = MethodMatcher::Exact;
668
char class_name[256];
669
char method_name[256];
670
char sig[1024];
671
char errorbuf[1024];
672
const char* error_msg = NULL; // description of first error that appears
673
MethodMatcher* match = NULL;
674
675
if (scan_line(line, class_name, &c_match, method_name, &m_match, &bytes_read, error_msg)) {
676
EXCEPTION_MARK;
677
Symbol* c_name = SymbolTable::new_symbol(class_name, CHECK);
678
Symbol* m_name = SymbolTable::new_symbol(method_name, CHECK);
679
Symbol* signature = NULL;
680
681
line += bytes_read;
682
// there might be a signature following the method.
683
// signatures always begin with ( so match that by hand
684
if (1 == sscanf(line, "%*[ \t](%254[[);/" RANGEBASE "]%n", sig + 1, &bytes_read)) {
685
sig[0] = '(';
686
line += bytes_read;
687
signature = SymbolTable::new_symbol(sig, CHECK);
688
}
689
690
if (command == OptionCommand) {
691
// Look for trailing options.
692
//
693
// Two types of trailing options are
694
// supported:
695
//
696
// (1) CompileCommand=option,Klass::method,flag
697
// (2) CompileCommand=option,Klass::method,type,flag,value
698
//
699
// Type (1) is used to support ciMethod::has_option("someflag")
700
// (i.e., to check if a flag "someflag" is enabled for a method).
701
//
702
// Type (2) is used to support options with a value. Values can have the
703
// the following types: intx, uintx, bool, ccstr, and ccstrlist.
704
//
705
// For future extensions: extend scan_flag_and_value()
706
char option[256]; // stores flag for Type (1) and type of Type (2)
707
while (sscanf(line, "%*[ \t]%255[a-zA-Z0-9]%n", option, &bytes_read) == 1) {
708
if (match != NULL && !_quiet) {
709
// Print out the last match added
710
ttyLocker ttyl;
711
tty->print("CompilerOracle: %s ", command_names[command]);
712
match->print();
713
}
714
line += bytes_read;
715
716
if (strcmp(option, "intx") == 0
717
|| strcmp(option, "uintx") == 0
718
|| strcmp(option, "bool") == 0
719
|| strcmp(option, "ccstr") == 0
720
|| strcmp(option, "ccstrlist") == 0
721
) {
722
723
// Type (2) option: parse flag name and value.
724
match = scan_flag_and_value(option, line, bytes_read,
725
c_name, c_match, m_name, m_match, signature,
726
errorbuf, sizeof(errorbuf));
727
if (match == NULL) {
728
error_msg = errorbuf;
729
break;
730
}
731
line += bytes_read;
732
} else {
733
// Type (1) option
734
match = add_option_string(c_name, c_match, m_name, m_match, signature, option, true);
735
}
736
} // while(
737
} else {
738
match = add_predicate(command, c_name, c_match, m_name, m_match, signature);
739
}
740
}
741
742
ttyLocker ttyl;
743
if (error_msg != NULL) {
744
// an error has happened
745
tty->print_cr("CompilerOracle: unrecognized line");
746
tty->print_cr(" \"%s\"", original_line);
747
if (error_msg != NULL) {
748
tty->print_cr("%s", error_msg);
749
}
750
} else {
751
// check for remaining characters
752
bytes_read = 0;
753
sscanf(line, "%*[ \t]%n", &bytes_read);
754
if (line[bytes_read] != '\0') {
755
tty->print_cr("CompilerOracle: unrecognized line");
756
tty->print_cr(" \"%s\"", original_line);
757
tty->print_cr(" Unrecognized text %s after command ", line);
758
} else if (match != NULL && !_quiet) {
759
tty->print("CompilerOracle: %s ", command_names[command]);
760
match->print();
761
}
762
}
763
}
764
765
static const char* default_cc_file = ".hotspot_compiler";
766
767
static const char* cc_file() {
768
#ifdef ASSERT
769
if (CompileCommandFile == NULL)
770
return default_cc_file;
771
#endif
772
return CompileCommandFile;
773
}
774
775
bool CompilerOracle::has_command_file() {
776
return cc_file() != NULL;
777
}
778
779
bool CompilerOracle::_quiet = false;
780
781
void CompilerOracle::parse_from_file() {
782
assert(has_command_file(), "command file must be specified");
783
FILE* stream = fopen(cc_file(), "rt");
784
if (stream == NULL) return;
785
786
char token[1024];
787
int pos = 0;
788
int c = getc(stream);
789
while(c != EOF && pos < (int)(sizeof(token)-1)) {
790
if (c == '\n') {
791
token[pos++] = '\0';
792
parse_from_line(token);
793
pos = 0;
794
} else {
795
token[pos++] = c;
796
}
797
c = getc(stream);
798
}
799
token[pos++] = '\0';
800
parse_from_line(token);
801
802
fclose(stream);
803
}
804
805
void CompilerOracle::parse_from_string(const char* str, void (*parse_line)(char*)) {
806
char token[1024];
807
int pos = 0;
808
const char* sp = str;
809
int c = *sp++;
810
while (c != '\0' && pos < (int)(sizeof(token)-1)) {
811
if (c == '\n') {
812
token[pos++] = '\0';
813
parse_line(token);
814
pos = 0;
815
} else {
816
token[pos++] = c;
817
}
818
c = *sp++;
819
}
820
token[pos++] = '\0';
821
parse_line(token);
822
}
823
824
void CompilerOracle::append_comment_to_file(const char* message) {
825
assert(has_command_file(), "command file must be specified");
826
fileStream stream(fopen(cc_file(), "at"));
827
stream.print("# ");
828
for (int index = 0; message[index] != '\0'; index++) {
829
stream.put(message[index]);
830
if (message[index] == '\n') stream.print("# ");
831
}
832
stream.cr();
833
}
834
835
void CompilerOracle::append_exclude_to_file(methodHandle method) {
836
assert(has_command_file(), "command file must be specified");
837
fileStream stream(fopen(cc_file(), "at"));
838
stream.print("exclude ");
839
method->method_holder()->name()->print_symbol_on(&stream);
840
stream.print(".");
841
method->name()->print_symbol_on(&stream);
842
method->signature()->print_symbol_on(&stream);
843
stream.cr();
844
stream.cr();
845
}
846
847
848
void compilerOracle_init() {
849
CompilerOracle::parse_from_string(CompileCommand, CompilerOracle::parse_from_line);
850
CompilerOracle::parse_from_string(CompileOnly, CompilerOracle::parse_compile_only);
851
if (CompilerOracle::has_command_file()) {
852
CompilerOracle::parse_from_file();
853
} else {
854
struct stat buf;
855
if (os::stat(default_cc_file, &buf) == 0) {
856
warning("%s file is present but has been ignored. "
857
"Run with -XX:CompileCommandFile=%s to load the file.",
858
default_cc_file, default_cc_file);
859
}
860
}
861
if (lists[PrintCommand] != NULL) {
862
if (PrintAssembly) {
863
warning("CompileCommand and/or %s file contains 'print' commands, but PrintAssembly is also enabled", default_cc_file);
864
} else if (FLAG_IS_DEFAULT(DebugNonSafepoints)) {
865
warning("printing of assembly code is enabled; turning on DebugNonSafepoints to gain additional output");
866
DebugNonSafepoints = true;
867
}
868
}
869
}
870
871
872
void CompilerOracle::parse_compile_only(char * line) {
873
int i;
874
char name[1024];
875
const char* className = NULL;
876
const char* methodName = NULL;
877
878
bool have_colon = (strstr(line, "::") != NULL);
879
char method_sep = have_colon ? ':' : '.';
880
881
if (Verbose) {
882
tty->print_cr("%s", line);
883
}
884
885
ResourceMark rm;
886
while (*line != '\0') {
887
MethodMatcher::Mode c_match = MethodMatcher::Exact;
888
MethodMatcher::Mode m_match = MethodMatcher::Exact;
889
890
for (i = 0;
891
i < 1024 && *line != '\0' && *line != method_sep && *line != ',' && !isspace(*line);
892
line++, i++) {
893
name[i] = *line;
894
if (name[i] == '.') name[i] = '/'; // package prefix uses '/'
895
}
896
897
if (i > 0) {
898
char* newName = NEW_RESOURCE_ARRAY( char, i + 1);
899
if (newName == NULL)
900
return;
901
strncpy(newName, name, i);
902
newName[i] = '\0';
903
904
if (className == NULL) {
905
className = newName;
906
c_match = MethodMatcher::Prefix;
907
} else {
908
methodName = newName;
909
}
910
}
911
912
if (*line == method_sep) {
913
if (className == NULL) {
914
className = "";
915
c_match = MethodMatcher::Any;
916
} else {
917
// foo/bar.blah is an exact match on foo/bar, bar.blah is a suffix match on bar
918
if (strchr(className, '/') != NULL) {
919
c_match = MethodMatcher::Exact;
920
} else {
921
c_match = MethodMatcher::Suffix;
922
}
923
}
924
} else {
925
// got foo or foo/bar
926
if (className == NULL) {
927
ShouldNotReachHere();
928
} else {
929
// got foo or foo/bar
930
if (strchr(className, '/') != NULL) {
931
c_match = MethodMatcher::Prefix;
932
} else if (className[0] == '\0') {
933
c_match = MethodMatcher::Any;
934
} else {
935
c_match = MethodMatcher::Substring;
936
}
937
}
938
}
939
940
// each directive is terminated by , or NUL or . followed by NUL
941
if (*line == ',' || *line == '\0' || (line[0] == '.' && line[1] == '\0')) {
942
if (methodName == NULL) {
943
methodName = "";
944
if (*line != method_sep) {
945
m_match = MethodMatcher::Any;
946
}
947
}
948
949
EXCEPTION_MARK;
950
Symbol* c_name = SymbolTable::new_symbol(className, CHECK);
951
Symbol* m_name = SymbolTable::new_symbol(methodName, CHECK);
952
Symbol* signature = NULL;
953
954
add_predicate(CompileOnlyCommand, c_name, c_match, m_name, m_match, signature);
955
if (PrintVMOptions) {
956
tty->print("CompileOnly: compileonly ");
957
lists[CompileOnlyCommand]->print();
958
}
959
960
className = NULL;
961
methodName = NULL;
962
}
963
964
line = *line == '\0' ? line : line + 1;
965
}
966
}
967
968