src/share/vm/compiler/compilerOracle.cpp

Wed, 22 Jan 2014 17:42:23 -0800

author
kvn
date
Wed, 22 Jan 2014 17:42:23 -0800
changeset 6503
a9becfeecd1b
parent 6198
55fb97c4c58d
child 6680
78bbf4d43a14
permissions
-rw-r--r--

Merge

duke@435 1 /*
mikael@6198 2 * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #include "precompiled.hpp"
stefank@2314 26 #include "compiler/compilerOracle.hpp"
stefank@2314 27 #include "memory/allocation.inline.hpp"
stefank@2314 28 #include "memory/oopFactory.hpp"
stefank@2314 29 #include "memory/resourceArea.hpp"
stefank@2314 30 #include "oops/klass.hpp"
coleenp@4037 31 #include "oops/method.hpp"
stefank@2314 32 #include "oops/oop.inline.hpp"
coleenp@2497 33 #include "oops/symbol.hpp"
stefank@2314 34 #include "runtime/handles.inline.hpp"
stefank@2314 35 #include "runtime/jniHandles.hpp"
duke@435 36
zgu@3900 37 class MethodMatcher : public CHeapObj<mtCompiler> {
duke@435 38 public:
duke@435 39 enum Mode {
duke@435 40 Exact,
duke@435 41 Prefix = 1,
duke@435 42 Suffix = 2,
duke@435 43 Substring = Prefix | Suffix,
duke@435 44 Any,
duke@435 45 Unknown = -1
duke@435 46 };
duke@435 47
duke@435 48 protected:
coleenp@2497 49 Symbol* _class_name;
coleenp@2497 50 Symbol* _method_name;
coleenp@2497 51 Symbol* _signature;
duke@435 52 Mode _class_mode;
duke@435 53 Mode _method_mode;
duke@435 54 MethodMatcher* _next;
duke@435 55
coleenp@2497 56 static bool match(Symbol* candidate, Symbol* match, Mode match_mode);
duke@435 57
coleenp@2497 58 Symbol* class_name() const { return _class_name; }
coleenp@2497 59 Symbol* method_name() const { return _method_name; }
coleenp@2497 60 Symbol* signature() const { return _signature; }
duke@435 61
duke@435 62 public:
coleenp@2497 63 MethodMatcher(Symbol* class_name, Mode class_mode,
coleenp@2497 64 Symbol* method_name, Mode method_mode,
coleenp@2497 65 Symbol* signature, MethodMatcher* next);
coleenp@2497 66 MethodMatcher(Symbol* class_name, Symbol* method_name, MethodMatcher* next);
duke@435 67
duke@435 68 // utility method
duke@435 69 MethodMatcher* find(methodHandle method) {
coleenp@4251 70 Symbol* class_name = method->method_holder()->name();
coleenp@2497 71 Symbol* method_name = method->name();
duke@435 72 for (MethodMatcher* current = this; current != NULL; current = current->_next) {
duke@435 73 if (match(class_name, current->class_name(), current->_class_mode) &&
duke@435 74 match(method_name, current->method_name(), current->_method_mode) &&
coleenp@2497 75 (current->signature() == NULL || current->signature() == method->signature())) {
duke@435 76 return current;
duke@435 77 }
duke@435 78 }
duke@435 79 return NULL;
duke@435 80 }
duke@435 81
duke@435 82 bool match(methodHandle method) {
duke@435 83 return find(method) != NULL;
duke@435 84 }
duke@435 85
duke@435 86 MethodMatcher* next() const { return _next; }
duke@435 87
coleenp@2497 88 static void print_symbol(Symbol* h, Mode mode) {
duke@435 89 ResourceMark rm;
duke@435 90
duke@435 91 if (mode == Suffix || mode == Substring || mode == Any) {
duke@435 92 tty->print("*");
duke@435 93 }
duke@435 94 if (mode != Any) {
coleenp@2497 95 h->print_symbol_on(tty);
duke@435 96 }
duke@435 97 if (mode == Prefix || mode == Substring) {
duke@435 98 tty->print("*");
duke@435 99 }
duke@435 100 }
duke@435 101
duke@435 102 void print_base() {
duke@435 103 print_symbol(class_name(), _class_mode);
duke@435 104 tty->print(".");
duke@435 105 print_symbol(method_name(), _method_mode);
coleenp@2497 106 if (signature() != NULL) {
duke@435 107 tty->print(" ");
duke@435 108 signature()->print_symbol_on(tty);
duke@435 109 }
duke@435 110 }
duke@435 111
duke@435 112 virtual void print() {
duke@435 113 print_base();
duke@435 114 tty->cr();
duke@435 115 }
duke@435 116 };
duke@435 117
coleenp@2497 118 MethodMatcher::MethodMatcher(Symbol* class_name, Symbol* method_name, MethodMatcher* next) {
coleenp@2497 119 _class_name = class_name;
coleenp@2497 120 _method_name = method_name;
duke@435 121 _next = next;
duke@435 122 _class_mode = MethodMatcher::Exact;
duke@435 123 _method_mode = MethodMatcher::Exact;
duke@435 124 _signature = NULL;
duke@435 125 }
duke@435 126
duke@435 127
coleenp@2497 128 MethodMatcher::MethodMatcher(Symbol* class_name, Mode class_mode,
coleenp@2497 129 Symbol* method_name, Mode method_mode,
coleenp@2497 130 Symbol* signature, MethodMatcher* next):
duke@435 131 _class_mode(class_mode)
duke@435 132 , _method_mode(method_mode)
duke@435 133 , _next(next)
coleenp@2497 134 , _class_name(class_name)
coleenp@2497 135 , _method_name(method_name)
coleenp@2497 136 , _signature(signature) {
duke@435 137 }
duke@435 138
coleenp@2497 139 bool MethodMatcher::match(Symbol* candidate, Symbol* match, Mode match_mode) {
duke@435 140 if (match_mode == Any) {
duke@435 141 return true;
duke@435 142 }
duke@435 143
duke@435 144 if (match_mode == Exact) {
coleenp@2497 145 return candidate == match;
duke@435 146 }
duke@435 147
duke@435 148 ResourceMark rm;
duke@435 149 const char * candidate_string = candidate->as_C_string();
duke@435 150 const char * match_string = match->as_C_string();
duke@435 151
duke@435 152 switch (match_mode) {
duke@435 153 case Prefix:
duke@435 154 return strstr(candidate_string, match_string) == candidate_string;
duke@435 155
duke@435 156 case Suffix: {
duke@435 157 size_t clen = strlen(candidate_string);
duke@435 158 size_t mlen = strlen(match_string);
duke@435 159 return clen >= mlen && strcmp(candidate_string + clen - mlen, match_string) == 0;
duke@435 160 }
duke@435 161
duke@435 162 case Substring:
duke@435 163 return strstr(candidate_string, match_string) != NULL;
duke@435 164
duke@435 165 default:
duke@435 166 return false;
duke@435 167 }
duke@435 168 }
duke@435 169
duke@435 170
duke@435 171 class MethodOptionMatcher: public MethodMatcher {
duke@435 172 const char * option;
duke@435 173 public:
coleenp@2497 174 MethodOptionMatcher(Symbol* class_name, Mode class_mode,
coleenp@2497 175 Symbol* method_name, Mode method_mode,
coleenp@2497 176 Symbol* signature, const char * opt, MethodMatcher* next):
duke@435 177 MethodMatcher(class_name, class_mode, method_name, method_mode, signature, next) {
duke@435 178 option = opt;
duke@435 179 }
duke@435 180
duke@435 181 bool match(methodHandle method, const char* opt) {
duke@435 182 MethodOptionMatcher* current = this;
duke@435 183 while (current != NULL) {
duke@435 184 current = (MethodOptionMatcher*)current->find(method);
duke@435 185 if (current == NULL) {
duke@435 186 return false;
duke@435 187 }
duke@435 188 if (strcmp(current->option, opt) == 0) {
duke@435 189 return true;
duke@435 190 }
duke@435 191 current = current->next();
duke@435 192 }
duke@435 193 return false;
duke@435 194 }
duke@435 195
duke@435 196 MethodOptionMatcher* next() {
duke@435 197 return (MethodOptionMatcher*)_next;
duke@435 198 }
duke@435 199
duke@435 200 virtual void print() {
duke@435 201 print_base();
duke@435 202 tty->print(" %s", option);
duke@435 203 tty->cr();
duke@435 204 }
duke@435 205 };
duke@435 206
duke@435 207
duke@435 208
duke@435 209 // this must parallel the command_names below
duke@435 210 enum OracleCommand {
duke@435 211 UnknownCommand = -1,
duke@435 212 OracleFirstCommand = 0,
duke@435 213 BreakCommand = OracleFirstCommand,
duke@435 214 PrintCommand,
duke@435 215 ExcludeCommand,
duke@435 216 InlineCommand,
duke@435 217 DontInlineCommand,
duke@435 218 CompileOnlyCommand,
duke@435 219 LogCommand,
duke@435 220 OptionCommand,
duke@435 221 QuietCommand,
duke@435 222 HelpCommand,
duke@435 223 OracleCommandCount
duke@435 224 };
duke@435 225
duke@435 226 // this must parallel the enum OracleCommand
duke@435 227 static const char * command_names[] = {
duke@435 228 "break",
duke@435 229 "print",
duke@435 230 "exclude",
duke@435 231 "inline",
duke@435 232 "dontinline",
duke@435 233 "compileonly",
duke@435 234 "log",
duke@435 235 "option",
duke@435 236 "quiet",
duke@435 237 "help"
duke@435 238 };
duke@435 239
duke@435 240 class MethodMatcher;
duke@435 241 static MethodMatcher* lists[OracleCommandCount] = { 0, };
duke@435 242
duke@435 243
duke@435 244 static bool check_predicate(OracleCommand command, methodHandle method) {
duke@435 245 return ((lists[command] != NULL) &&
duke@435 246 !method.is_null() &&
duke@435 247 lists[command]->match(method));
duke@435 248 }
duke@435 249
duke@435 250
duke@435 251 static MethodMatcher* add_predicate(OracleCommand command,
coleenp@2497 252 Symbol* class_name, MethodMatcher::Mode c_mode,
coleenp@2497 253 Symbol* method_name, MethodMatcher::Mode m_mode,
coleenp@2497 254 Symbol* signature) {
duke@435 255 assert(command != OptionCommand, "must use add_option_string");
duke@435 256 if (command == LogCommand && !LogCompilation && lists[LogCommand] == NULL)
duke@435 257 tty->print_cr("Warning: +LogCompilation must be enabled in order for individual methods to be logged.");
duke@435 258 lists[command] = new MethodMatcher(class_name, c_mode, method_name, m_mode, signature, lists[command]);
duke@435 259 return lists[command];
duke@435 260 }
duke@435 261
duke@435 262
duke@435 263
coleenp@2497 264 static MethodMatcher* add_option_string(Symbol* class_name, MethodMatcher::Mode c_mode,
coleenp@2497 265 Symbol* method_name, MethodMatcher::Mode m_mode,
coleenp@2497 266 Symbol* signature,
duke@435 267 const char* option) {
duke@435 268 lists[OptionCommand] = new MethodOptionMatcher(class_name, c_mode, method_name, m_mode,
duke@435 269 signature, option, lists[OptionCommand]);
duke@435 270 return lists[OptionCommand];
duke@435 271 }
duke@435 272
duke@435 273
duke@435 274 bool CompilerOracle::has_option_string(methodHandle method, const char* option) {
duke@435 275 return lists[OptionCommand] != NULL &&
duke@435 276 ((MethodOptionMatcher*)lists[OptionCommand])->match(method, option);
duke@435 277 }
duke@435 278
duke@435 279
duke@435 280 bool CompilerOracle::should_exclude(methodHandle method, bool& quietly) {
duke@435 281 quietly = true;
duke@435 282 if (lists[ExcludeCommand] != NULL) {
duke@435 283 if (lists[ExcludeCommand]->match(method)) {
duke@435 284 quietly = _quiet;
duke@435 285 return true;
duke@435 286 }
duke@435 287 }
duke@435 288
duke@435 289 if (lists[CompileOnlyCommand] != NULL) {
duke@435 290 return !lists[CompileOnlyCommand]->match(method);
duke@435 291 }
duke@435 292 return false;
duke@435 293 }
duke@435 294
duke@435 295
duke@435 296 bool CompilerOracle::should_inline(methodHandle method) {
duke@435 297 return (check_predicate(InlineCommand, method));
duke@435 298 }
duke@435 299
duke@435 300
duke@435 301 bool CompilerOracle::should_not_inline(methodHandle method) {
duke@435 302 return (check_predicate(DontInlineCommand, method));
duke@435 303 }
duke@435 304
duke@435 305
duke@435 306 bool CompilerOracle::should_print(methodHandle method) {
duke@435 307 return (check_predicate(PrintCommand, method));
duke@435 308 }
duke@435 309
duke@435 310
duke@435 311 bool CompilerOracle::should_log(methodHandle method) {
duke@435 312 if (!LogCompilation) return false;
duke@435 313 if (lists[LogCommand] == NULL) return true; // by default, log all
duke@435 314 return (check_predicate(LogCommand, method));
duke@435 315 }
duke@435 316
duke@435 317
duke@435 318 bool CompilerOracle::should_break_at(methodHandle method) {
duke@435 319 return check_predicate(BreakCommand, method);
duke@435 320 }
duke@435 321
duke@435 322
duke@435 323 static OracleCommand parse_command_name(const char * line, int* bytes_read) {
duke@435 324 assert(ARRAY_SIZE(command_names) == OracleCommandCount,
duke@435 325 "command_names size mismatch");
duke@435 326
duke@435 327 *bytes_read = 0;
never@2400 328 char command[33];
duke@435 329 int result = sscanf(line, "%32[a-z]%n", command, bytes_read);
duke@435 330 for (uint i = 0; i < ARRAY_SIZE(command_names); i++) {
duke@435 331 if (strcmp(command, command_names[i]) == 0) {
duke@435 332 return (OracleCommand)i;
duke@435 333 }
duke@435 334 }
duke@435 335 return UnknownCommand;
duke@435 336 }
duke@435 337
duke@435 338
duke@435 339 static void usage() {
duke@435 340 tty->print_cr(" CompileCommand and the CompilerOracle allows simple control over");
duke@435 341 tty->print_cr(" what's allowed to be compiled. The standard supported directives");
duke@435 342 tty->print_cr(" are exclude and compileonly. The exclude directive stops a method");
duke@435 343 tty->print_cr(" from being compiled and compileonly excludes all methods except for");
duke@435 344 tty->print_cr(" the ones mentioned by compileonly directives. The basic form of");
duke@435 345 tty->print_cr(" all commands is a command name followed by the name of the method");
duke@435 346 tty->print_cr(" in one of two forms: the standard class file format as in");
duke@435 347 tty->print_cr(" class/name.methodName or the PrintCompilation format");
duke@435 348 tty->print_cr(" class.name::methodName. The method name can optionally be followed");
duke@435 349 tty->print_cr(" by a space then the signature of the method in the class file");
duke@435 350 tty->print_cr(" format. Otherwise the directive applies to all methods with the");
duke@435 351 tty->print_cr(" same name and class regardless of signature. Leading and trailing");
duke@435 352 tty->print_cr(" *'s in the class and/or method name allows a small amount of");
duke@435 353 tty->print_cr(" wildcarding. ");
duke@435 354 tty->cr();
duke@435 355 tty->print_cr(" Examples:");
duke@435 356 tty->cr();
duke@435 357 tty->print_cr(" exclude java/lang/StringBuffer.append");
duke@435 358 tty->print_cr(" compileonly java/lang/StringBuffer.toString ()Ljava/lang/String;");
duke@435 359 tty->print_cr(" exclude java/lang/String*.*");
duke@435 360 tty->print_cr(" exclude *.toString");
duke@435 361 }
duke@435 362
duke@435 363
duke@435 364 // The characters allowed in a class or method name. All characters > 0x7f
duke@435 365 // are allowed in order to handle obfuscated class files (e.g. Volano)
duke@435 366 #define RANGEBASE "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789$_<>" \
duke@435 367 "\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f" \
duke@435 368 "\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f" \
duke@435 369 "\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf" \
duke@435 370 "\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf" \
duke@435 371 "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf" \
duke@435 372 "\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf" \
duke@435 373 "\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef" \
duke@435 374 "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff"
duke@435 375
duke@435 376 #define RANGE0 "[*" RANGEBASE "]"
duke@435 377 #define RANGEDOT "[*" RANGEBASE ".]"
duke@435 378 #define RANGESLASH "[*" RANGEBASE "/]"
duke@435 379
duke@435 380
duke@435 381 // Accept several syntaxes for these patterns
duke@435 382 // original syntax
duke@435 383 // cmd java.lang.String foo
duke@435 384 // PrintCompilation syntax
duke@435 385 // cmd java.lang.String::foo
duke@435 386 // VM syntax
duke@435 387 // cmd java/lang/String[. ]foo
duke@435 388 //
duke@435 389
duke@435 390 static const char* patterns[] = {
duke@435 391 "%*[ \t]%255" RANGEDOT " " "%255" RANGE0 "%n",
duke@435 392 "%*[ \t]%255" RANGEDOT "::" "%255" RANGE0 "%n",
duke@435 393 "%*[ \t]%255" RANGESLASH "%*[ .]" "%255" RANGE0 "%n",
duke@435 394 };
duke@435 395
duke@435 396 static MethodMatcher::Mode check_mode(char name[], const char*& error_msg) {
duke@435 397 int match = MethodMatcher::Exact;
jrose@1590 398 while (name[0] == '*') {
duke@435 399 match |= MethodMatcher::Suffix;
duke@435 400 strcpy(name, name + 1);
duke@435 401 }
duke@435 402
jrose@1590 403 if (strcmp(name, "*") == 0) return MethodMatcher::Any;
jrose@1590 404
duke@435 405 size_t len = strlen(name);
jrose@1590 406 while (len > 0 && name[len - 1] == '*') {
duke@435 407 match |= MethodMatcher::Prefix;
jrose@1590 408 name[--len] = '\0';
duke@435 409 }
duke@435 410
duke@435 411 if (strstr(name, "*") != NULL) {
duke@435 412 error_msg = " Embedded * not allowed";
duke@435 413 return MethodMatcher::Unknown;
duke@435 414 }
duke@435 415 return (MethodMatcher::Mode)match;
duke@435 416 }
duke@435 417
duke@435 418 static bool scan_line(const char * line,
duke@435 419 char class_name[], MethodMatcher::Mode* c_mode,
duke@435 420 char method_name[], MethodMatcher::Mode* m_mode,
duke@435 421 int* bytes_read, const char*& error_msg) {
duke@435 422 *bytes_read = 0;
duke@435 423 error_msg = NULL;
duke@435 424 for (uint i = 0; i < ARRAY_SIZE(patterns); i++) {
duke@435 425 if (2 == sscanf(line, patterns[i], class_name, method_name, bytes_read)) {
duke@435 426 *c_mode = check_mode(class_name, error_msg);
duke@435 427 *m_mode = check_mode(method_name, error_msg);
duke@435 428 return *c_mode != MethodMatcher::Unknown && *m_mode != MethodMatcher::Unknown;
duke@435 429 }
duke@435 430 }
duke@435 431 return false;
duke@435 432 }
duke@435 433
duke@435 434
duke@435 435
duke@435 436 void CompilerOracle::parse_from_line(char* line) {
duke@435 437 if (line[0] == '\0') return;
duke@435 438 if (line[0] == '#') return;
duke@435 439
duke@435 440 bool have_colon = (strstr(line, "::") != NULL);
duke@435 441 for (char* lp = line; *lp != '\0'; lp++) {
duke@435 442 // Allow '.' to separate the class name from the method name.
duke@435 443 // This is the preferred spelling of methods:
duke@435 444 // exclude java/lang/String.indexOf(I)I
duke@435 445 // Allow ',' for spaces (eases command line quoting).
duke@435 446 // exclude,java/lang/String.indexOf
duke@435 447 // For backward compatibility, allow space as separator also.
duke@435 448 // exclude java/lang/String indexOf
duke@435 449 // exclude,java/lang/String,indexOf
duke@435 450 // For easy cut-and-paste of method names, allow VM output format
coleenp@4037 451 // as produced by Method::print_short_name:
duke@435 452 // exclude java.lang.String::indexOf
duke@435 453 // For simple implementation convenience here, convert them all to space.
duke@435 454 if (have_colon) {
duke@435 455 if (*lp == '.') *lp = '/'; // dots build the package prefix
duke@435 456 if (*lp == ':') *lp = ' ';
duke@435 457 }
duke@435 458 if (*lp == ',' || *lp == '.') *lp = ' ';
duke@435 459 }
duke@435 460
duke@435 461 char* original_line = line;
duke@435 462 int bytes_read;
duke@435 463 OracleCommand command = parse_command_name(line, &bytes_read);
duke@435 464 line += bytes_read;
duke@435 465
never@2400 466 if (command == UnknownCommand) {
never@2400 467 tty->print_cr("CompilerOracle: unrecognized line");
never@2400 468 tty->print_cr(" \"%s\"", original_line);
never@2400 469 return;
never@2400 470 }
never@2400 471
duke@435 472 if (command == QuietCommand) {
duke@435 473 _quiet = true;
duke@435 474 return;
duke@435 475 }
duke@435 476
duke@435 477 if (command == HelpCommand) {
duke@435 478 usage();
duke@435 479 return;
duke@435 480 }
duke@435 481
duke@435 482 MethodMatcher::Mode c_match = MethodMatcher::Exact;
duke@435 483 MethodMatcher::Mode m_match = MethodMatcher::Exact;
duke@435 484 char class_name[256];
duke@435 485 char method_name[256];
duke@435 486 char sig[1024];
duke@435 487 char errorbuf[1024];
duke@435 488 const char* error_msg = NULL;
duke@435 489 MethodMatcher* match = NULL;
duke@435 490
duke@435 491 if (scan_line(line, class_name, &c_match, method_name, &m_match, &bytes_read, error_msg)) {
duke@435 492 EXCEPTION_MARK;
coleenp@2497 493 Symbol* c_name = SymbolTable::new_symbol(class_name, CHECK);
coleenp@2497 494 Symbol* m_name = SymbolTable::new_symbol(method_name, CHECK);
coleenp@2497 495 Symbol* signature = NULL;
duke@435 496
duke@435 497 line += bytes_read;
duke@435 498 // there might be a signature following the method.
duke@435 499 // signatures always begin with ( so match that by hand
never@2400 500 if (1 == sscanf(line, "%*[ \t](%254[[);/" RANGEBASE "]%n", sig + 1, &bytes_read)) {
duke@435 501 sig[0] = '(';
duke@435 502 line += bytes_read;
coleenp@2497 503 signature = SymbolTable::new_symbol(sig, CHECK);
duke@435 504 }
duke@435 505
duke@435 506 if (command == OptionCommand) {
duke@435 507 // Look for trailing options to support
duke@435 508 // ciMethod::has_option("string") to control features in the
duke@435 509 // compiler. Multiple options may follow the method name.
duke@435 510 char option[256];
duke@435 511 while (sscanf(line, "%*[ \t]%255[a-zA-Z0-9]%n", option, &bytes_read) == 1) {
duke@435 512 if (match != NULL && !_quiet) {
duke@435 513 // Print out the last match added
duke@435 514 tty->print("CompilerOracle: %s ", command_names[command]);
duke@435 515 match->print();
duke@435 516 }
duke@435 517 match = add_option_string(c_name, c_match, m_name, m_match, signature, strdup(option));
duke@435 518 line += bytes_read;
duke@435 519 }
duke@435 520 } else {
duke@435 521 bytes_read = 0;
duke@435 522 sscanf(line, "%*[ \t]%n", &bytes_read);
duke@435 523 if (line[bytes_read] != '\0') {
duke@435 524 jio_snprintf(errorbuf, sizeof(errorbuf), " Unrecognized text after command: %s", line);
duke@435 525 error_msg = errorbuf;
duke@435 526 } else {
duke@435 527 match = add_predicate(command, c_name, c_match, m_name, m_match, signature);
duke@435 528 }
duke@435 529 }
duke@435 530 }
duke@435 531
duke@435 532 if (match != NULL) {
duke@435 533 if (!_quiet) {
roland@4357 534 ResourceMark rm;
duke@435 535 tty->print("CompilerOracle: %s ", command_names[command]);
duke@435 536 match->print();
duke@435 537 }
duke@435 538 } else {
duke@435 539 tty->print_cr("CompilerOracle: unrecognized line");
duke@435 540 tty->print_cr(" \"%s\"", original_line);
duke@435 541 if (error_msg != NULL) {
duke@435 542 tty->print_cr(error_msg);
duke@435 543 }
duke@435 544 }
duke@435 545 }
duke@435 546
kamg@3899 547 static const char* default_cc_file = ".hotspot_compiler";
kamg@3899 548
duke@435 549 static const char* cc_file() {
kamg@3853 550 #ifdef ASSERT
duke@435 551 if (CompileCommandFile == NULL)
kamg@3899 552 return default_cc_file;
kamg@3853 553 #endif
duke@435 554 return CompileCommandFile;
duke@435 555 }
kamg@3853 556
kamg@3853 557 bool CompilerOracle::has_command_file() {
kamg@3853 558 return cc_file() != NULL;
kamg@3853 559 }
kamg@3853 560
duke@435 561 bool CompilerOracle::_quiet = false;
duke@435 562
duke@435 563 void CompilerOracle::parse_from_file() {
kamg@3853 564 assert(has_command_file(), "command file must be specified");
duke@435 565 FILE* stream = fopen(cc_file(), "rt");
duke@435 566 if (stream == NULL) return;
duke@435 567
duke@435 568 char token[1024];
duke@435 569 int pos = 0;
duke@435 570 int c = getc(stream);
kamg@4212 571 while(c != EOF && pos < (int)(sizeof(token)-1)) {
duke@435 572 if (c == '\n') {
duke@435 573 token[pos++] = '\0';
duke@435 574 parse_from_line(token);
duke@435 575 pos = 0;
duke@435 576 } else {
duke@435 577 token[pos++] = c;
duke@435 578 }
duke@435 579 c = getc(stream);
duke@435 580 }
duke@435 581 token[pos++] = '\0';
duke@435 582 parse_from_line(token);
duke@435 583
duke@435 584 fclose(stream);
duke@435 585 }
duke@435 586
duke@435 587 void CompilerOracle::parse_from_string(const char* str, void (*parse_line)(char*)) {
duke@435 588 char token[1024];
duke@435 589 int pos = 0;
duke@435 590 const char* sp = str;
duke@435 591 int c = *sp++;
kamg@4212 592 while (c != '\0' && pos < (int)(sizeof(token)-1)) {
duke@435 593 if (c == '\n') {
duke@435 594 token[pos++] = '\0';
duke@435 595 parse_line(token);
duke@435 596 pos = 0;
duke@435 597 } else {
duke@435 598 token[pos++] = c;
duke@435 599 }
duke@435 600 c = *sp++;
duke@435 601 }
duke@435 602 token[pos++] = '\0';
duke@435 603 parse_line(token);
duke@435 604 }
duke@435 605
duke@435 606 void CompilerOracle::append_comment_to_file(const char* message) {
kamg@3853 607 assert(has_command_file(), "command file must be specified");
duke@435 608 fileStream stream(fopen(cc_file(), "at"));
duke@435 609 stream.print("# ");
duke@435 610 for (int index = 0; message[index] != '\0'; index++) {
duke@435 611 stream.put(message[index]);
duke@435 612 if (message[index] == '\n') stream.print("# ");
duke@435 613 }
duke@435 614 stream.cr();
duke@435 615 }
duke@435 616
duke@435 617 void CompilerOracle::append_exclude_to_file(methodHandle method) {
kamg@3853 618 assert(has_command_file(), "command file must be specified");
duke@435 619 fileStream stream(fopen(cc_file(), "at"));
duke@435 620 stream.print("exclude ");
coleenp@4251 621 method->method_holder()->name()->print_symbol_on(&stream);
duke@435 622 stream.print(".");
duke@435 623 method->name()->print_symbol_on(&stream);
duke@435 624 method->signature()->print_symbol_on(&stream);
duke@435 625 stream.cr();
duke@435 626 stream.cr();
duke@435 627 }
duke@435 628
duke@435 629
duke@435 630 void compilerOracle_init() {
duke@435 631 CompilerOracle::parse_from_string(CompileCommand, CompilerOracle::parse_from_line);
duke@435 632 CompilerOracle::parse_from_string(CompileOnly, CompilerOracle::parse_compile_only);
kamg@3853 633 if (CompilerOracle::has_command_file()) {
kamg@3853 634 CompilerOracle::parse_from_file();
kamg@3899 635 } else {
kamg@3899 636 struct stat buf;
kamg@3899 637 if (os::stat(default_cc_file, &buf) == 0) {
kamg@3899 638 warning("%s file is present but has been ignored. "
kamg@3899 639 "Run with -XX:CompileCommandFile=%s to load the file.",
kamg@3899 640 default_cc_file, default_cc_file);
kamg@3899 641 }
kamg@3853 642 }
jrose@1590 643 if (lists[PrintCommand] != NULL) {
jrose@1590 644 if (PrintAssembly) {
kamg@3899 645 warning("CompileCommand and/or %s file contains 'print' commands, but PrintAssembly is also enabled", default_cc_file);
jrose@1590 646 } else if (FLAG_IS_DEFAULT(DebugNonSafepoints)) {
jrose@1590 647 warning("printing of assembly code is enabled; turning on DebugNonSafepoints to gain additional output");
jrose@1590 648 DebugNonSafepoints = true;
jrose@1590 649 }
jrose@1590 650 }
duke@435 651 }
duke@435 652
duke@435 653
duke@435 654 void CompilerOracle::parse_compile_only(char * line) {
duke@435 655 int i;
duke@435 656 char name[1024];
duke@435 657 const char* className = NULL;
duke@435 658 const char* methodName = NULL;
duke@435 659
duke@435 660 bool have_colon = (strstr(line, "::") != NULL);
duke@435 661 char method_sep = have_colon ? ':' : '.';
duke@435 662
duke@435 663 if (Verbose) {
duke@435 664 tty->print_cr(line);
duke@435 665 }
duke@435 666
duke@435 667 ResourceMark rm;
duke@435 668 while (*line != '\0') {
duke@435 669 MethodMatcher::Mode c_match = MethodMatcher::Exact;
duke@435 670 MethodMatcher::Mode m_match = MethodMatcher::Exact;
duke@435 671
duke@435 672 for (i = 0;
duke@435 673 i < 1024 && *line != '\0' && *line != method_sep && *line != ',' && !isspace(*line);
duke@435 674 line++, i++) {
duke@435 675 name[i] = *line;
duke@435 676 if (name[i] == '.') name[i] = '/'; // package prefix uses '/'
duke@435 677 }
duke@435 678
duke@435 679 if (i > 0) {
duke@435 680 char* newName = NEW_RESOURCE_ARRAY( char, i + 1);
duke@435 681 if (newName == NULL)
duke@435 682 return;
duke@435 683 strncpy(newName, name, i);
duke@435 684 newName[i] = '\0';
duke@435 685
duke@435 686 if (className == NULL) {
duke@435 687 className = newName;
duke@435 688 c_match = MethodMatcher::Prefix;
duke@435 689 } else {
duke@435 690 methodName = newName;
duke@435 691 }
duke@435 692 }
duke@435 693
duke@435 694 if (*line == method_sep) {
duke@435 695 if (className == NULL) {
duke@435 696 className = "";
duke@435 697 c_match = MethodMatcher::Any;
duke@435 698 } else {
duke@435 699 // foo/bar.blah is an exact match on foo/bar, bar.blah is a suffix match on bar
duke@435 700 if (strchr(className, '/') != NULL) {
duke@435 701 c_match = MethodMatcher::Exact;
duke@435 702 } else {
duke@435 703 c_match = MethodMatcher::Suffix;
duke@435 704 }
duke@435 705 }
duke@435 706 } else {
duke@435 707 // got foo or foo/bar
duke@435 708 if (className == NULL) {
duke@435 709 ShouldNotReachHere();
duke@435 710 } else {
duke@435 711 // got foo or foo/bar
duke@435 712 if (strchr(className, '/') != NULL) {
duke@435 713 c_match = MethodMatcher::Prefix;
duke@435 714 } else if (className[0] == '\0') {
duke@435 715 c_match = MethodMatcher::Any;
duke@435 716 } else {
duke@435 717 c_match = MethodMatcher::Substring;
duke@435 718 }
duke@435 719 }
duke@435 720 }
duke@435 721
duke@435 722 // each directive is terminated by , or NUL or . followed by NUL
duke@435 723 if (*line == ',' || *line == '\0' || (line[0] == '.' && line[1] == '\0')) {
duke@435 724 if (methodName == NULL) {
duke@435 725 methodName = "";
duke@435 726 if (*line != method_sep) {
duke@435 727 m_match = MethodMatcher::Any;
duke@435 728 }
duke@435 729 }
duke@435 730
duke@435 731 EXCEPTION_MARK;
coleenp@2497 732 Symbol* c_name = SymbolTable::new_symbol(className, CHECK);
coleenp@2497 733 Symbol* m_name = SymbolTable::new_symbol(methodName, CHECK);
coleenp@2497 734 Symbol* signature = NULL;
duke@435 735
duke@435 736 add_predicate(CompileOnlyCommand, c_name, c_match, m_name, m_match, signature);
duke@435 737 if (PrintVMOptions) {
duke@435 738 tty->print("CompileOnly: compileonly ");
duke@435 739 lists[CompileOnlyCommand]->print();
duke@435 740 }
duke@435 741
duke@435 742 className = NULL;
duke@435 743 methodName = NULL;
duke@435 744 }
duke@435 745
duke@435 746 line = *line == '\0' ? line : line + 1;
duke@435 747 }
duke@435 748 }

mercurial