src/share/vm/compiler/compilerOracle.cpp

Thu, 27 May 2010 19:08:38 -0700

author
trims
date
Thu, 27 May 2010 19:08:38 -0700
changeset 1907
c18cbe5936b8
parent 1590
4e6abf09f540
child 2314
f95d63e2154a
permissions
-rw-r--r--

6941466: Oracle rebranding changes for Hotspot repositories
Summary: Change all the Sun copyrights to Oracle copyright
Reviewed-by: ohair

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

mercurial