src/share/vm/compiler/compilerOracle.cpp

Wed, 13 Mar 2013 15:15:56 -0400

author
coleenp
date
Wed, 13 Mar 2013 15:15:56 -0400
changeset 4718
0ede345ec7c9
parent 4357
ad5dd04754ee
child 4889
cc32ccaaf47f
permissions
-rw-r--r--

8009829: CDS: JDK JPRT test fails crash in Symbol::equals()
Summary: -Xshare:dump was creating a Symbol in C_heap. There's an assert there that jdk jprt wasn't hitting because it was only done in product
Reviewed-by: dholmes, hseigel, iklam

duke@435 1 /*
kamg@3853 2 * Copyright (c) 1998, 2012, 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 static const char * command_name(OracleCommand command) {
duke@435 241 if (command < OracleFirstCommand || command >= OracleCommandCount) {
duke@435 242 return "unknown command";
duke@435 243 }
duke@435 244 return command_names[command];
duke@435 245 }
duke@435 246
duke@435 247 class MethodMatcher;
duke@435 248 static MethodMatcher* lists[OracleCommandCount] = { 0, };
duke@435 249
duke@435 250
duke@435 251 static bool check_predicate(OracleCommand command, methodHandle method) {
duke@435 252 return ((lists[command] != NULL) &&
duke@435 253 !method.is_null() &&
duke@435 254 lists[command]->match(method));
duke@435 255 }
duke@435 256
duke@435 257
duke@435 258 static MethodMatcher* add_predicate(OracleCommand command,
coleenp@2497 259 Symbol* class_name, MethodMatcher::Mode c_mode,
coleenp@2497 260 Symbol* method_name, MethodMatcher::Mode m_mode,
coleenp@2497 261 Symbol* signature) {
duke@435 262 assert(command != OptionCommand, "must use add_option_string");
duke@435 263 if (command == LogCommand && !LogCompilation && lists[LogCommand] == NULL)
duke@435 264 tty->print_cr("Warning: +LogCompilation must be enabled in order for individual methods to be logged.");
duke@435 265 lists[command] = new MethodMatcher(class_name, c_mode, method_name, m_mode, signature, lists[command]);
duke@435 266 return lists[command];
duke@435 267 }
duke@435 268
duke@435 269
duke@435 270
coleenp@2497 271 static MethodMatcher* add_option_string(Symbol* class_name, MethodMatcher::Mode c_mode,
coleenp@2497 272 Symbol* method_name, MethodMatcher::Mode m_mode,
coleenp@2497 273 Symbol* signature,
duke@435 274 const char* option) {
duke@435 275 lists[OptionCommand] = new MethodOptionMatcher(class_name, c_mode, method_name, m_mode,
duke@435 276 signature, option, lists[OptionCommand]);
duke@435 277 return lists[OptionCommand];
duke@435 278 }
duke@435 279
duke@435 280
duke@435 281 bool CompilerOracle::has_option_string(methodHandle method, const char* option) {
duke@435 282 return lists[OptionCommand] != NULL &&
duke@435 283 ((MethodOptionMatcher*)lists[OptionCommand])->match(method, option);
duke@435 284 }
duke@435 285
duke@435 286
duke@435 287 bool CompilerOracle::should_exclude(methodHandle method, bool& quietly) {
duke@435 288 quietly = true;
duke@435 289 if (lists[ExcludeCommand] != NULL) {
duke@435 290 if (lists[ExcludeCommand]->match(method)) {
duke@435 291 quietly = _quiet;
duke@435 292 return true;
duke@435 293 }
duke@435 294 }
duke@435 295
duke@435 296 if (lists[CompileOnlyCommand] != NULL) {
duke@435 297 return !lists[CompileOnlyCommand]->match(method);
duke@435 298 }
duke@435 299 return false;
duke@435 300 }
duke@435 301
duke@435 302
duke@435 303 bool CompilerOracle::should_inline(methodHandle method) {
duke@435 304 return (check_predicate(InlineCommand, method));
duke@435 305 }
duke@435 306
duke@435 307
duke@435 308 bool CompilerOracle::should_not_inline(methodHandle method) {
duke@435 309 return (check_predicate(DontInlineCommand, method));
duke@435 310 }
duke@435 311
duke@435 312
duke@435 313 bool CompilerOracle::should_print(methodHandle method) {
duke@435 314 return (check_predicate(PrintCommand, method));
duke@435 315 }
duke@435 316
duke@435 317
duke@435 318 bool CompilerOracle::should_log(methodHandle method) {
duke@435 319 if (!LogCompilation) return false;
duke@435 320 if (lists[LogCommand] == NULL) return true; // by default, log all
duke@435 321 return (check_predicate(LogCommand, method));
duke@435 322 }
duke@435 323
duke@435 324
duke@435 325 bool CompilerOracle::should_break_at(methodHandle method) {
duke@435 326 return check_predicate(BreakCommand, method);
duke@435 327 }
duke@435 328
duke@435 329
duke@435 330 static OracleCommand parse_command_name(const char * line, int* bytes_read) {
duke@435 331 assert(ARRAY_SIZE(command_names) == OracleCommandCount,
duke@435 332 "command_names size mismatch");
duke@435 333
duke@435 334 *bytes_read = 0;
never@2400 335 char command[33];
duke@435 336 int result = sscanf(line, "%32[a-z]%n", command, bytes_read);
duke@435 337 for (uint i = 0; i < ARRAY_SIZE(command_names); i++) {
duke@435 338 if (strcmp(command, command_names[i]) == 0) {
duke@435 339 return (OracleCommand)i;
duke@435 340 }
duke@435 341 }
duke@435 342 return UnknownCommand;
duke@435 343 }
duke@435 344
duke@435 345
duke@435 346 static void usage() {
duke@435 347 tty->print_cr(" CompileCommand and the CompilerOracle allows simple control over");
duke@435 348 tty->print_cr(" what's allowed to be compiled. The standard supported directives");
duke@435 349 tty->print_cr(" are exclude and compileonly. The exclude directive stops a method");
duke@435 350 tty->print_cr(" from being compiled and compileonly excludes all methods except for");
duke@435 351 tty->print_cr(" the ones mentioned by compileonly directives. The basic form of");
duke@435 352 tty->print_cr(" all commands is a command name followed by the name of the method");
duke@435 353 tty->print_cr(" in one of two forms: the standard class file format as in");
duke@435 354 tty->print_cr(" class/name.methodName or the PrintCompilation format");
duke@435 355 tty->print_cr(" class.name::methodName. The method name can optionally be followed");
duke@435 356 tty->print_cr(" by a space then the signature of the method in the class file");
duke@435 357 tty->print_cr(" format. Otherwise the directive applies to all methods with the");
duke@435 358 tty->print_cr(" same name and class regardless of signature. Leading and trailing");
duke@435 359 tty->print_cr(" *'s in the class and/or method name allows a small amount of");
duke@435 360 tty->print_cr(" wildcarding. ");
duke@435 361 tty->cr();
duke@435 362 tty->print_cr(" Examples:");
duke@435 363 tty->cr();
duke@435 364 tty->print_cr(" exclude java/lang/StringBuffer.append");
duke@435 365 tty->print_cr(" compileonly java/lang/StringBuffer.toString ()Ljava/lang/String;");
duke@435 366 tty->print_cr(" exclude java/lang/String*.*");
duke@435 367 tty->print_cr(" exclude *.toString");
duke@435 368 }
duke@435 369
duke@435 370
duke@435 371 // The characters allowed in a class or method name. All characters > 0x7f
duke@435 372 // are allowed in order to handle obfuscated class files (e.g. Volano)
duke@435 373 #define RANGEBASE "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789$_<>" \
duke@435 374 "\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f" \
duke@435 375 "\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f" \
duke@435 376 "\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf" \
duke@435 377 "\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf" \
duke@435 378 "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf" \
duke@435 379 "\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf" \
duke@435 380 "\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef" \
duke@435 381 "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff"
duke@435 382
duke@435 383 #define RANGE0 "[*" RANGEBASE "]"
duke@435 384 #define RANGEDOT "[*" RANGEBASE ".]"
duke@435 385 #define RANGESLASH "[*" RANGEBASE "/]"
duke@435 386
duke@435 387
duke@435 388 // Accept several syntaxes for these patterns
duke@435 389 // original syntax
duke@435 390 // cmd java.lang.String foo
duke@435 391 // PrintCompilation syntax
duke@435 392 // cmd java.lang.String::foo
duke@435 393 // VM syntax
duke@435 394 // cmd java/lang/String[. ]foo
duke@435 395 //
duke@435 396
duke@435 397 static const char* patterns[] = {
duke@435 398 "%*[ \t]%255" RANGEDOT " " "%255" RANGE0 "%n",
duke@435 399 "%*[ \t]%255" RANGEDOT "::" "%255" RANGE0 "%n",
duke@435 400 "%*[ \t]%255" RANGESLASH "%*[ .]" "%255" RANGE0 "%n",
duke@435 401 };
duke@435 402
duke@435 403 static MethodMatcher::Mode check_mode(char name[], const char*& error_msg) {
duke@435 404 int match = MethodMatcher::Exact;
jrose@1590 405 while (name[0] == '*') {
duke@435 406 match |= MethodMatcher::Suffix;
duke@435 407 strcpy(name, name + 1);
duke@435 408 }
duke@435 409
jrose@1590 410 if (strcmp(name, "*") == 0) return MethodMatcher::Any;
jrose@1590 411
duke@435 412 size_t len = strlen(name);
jrose@1590 413 while (len > 0 && name[len - 1] == '*') {
duke@435 414 match |= MethodMatcher::Prefix;
jrose@1590 415 name[--len] = '\0';
duke@435 416 }
duke@435 417
duke@435 418 if (strstr(name, "*") != NULL) {
duke@435 419 error_msg = " Embedded * not allowed";
duke@435 420 return MethodMatcher::Unknown;
duke@435 421 }
duke@435 422 return (MethodMatcher::Mode)match;
duke@435 423 }
duke@435 424
duke@435 425 static bool scan_line(const char * line,
duke@435 426 char class_name[], MethodMatcher::Mode* c_mode,
duke@435 427 char method_name[], MethodMatcher::Mode* m_mode,
duke@435 428 int* bytes_read, const char*& error_msg) {
duke@435 429 *bytes_read = 0;
duke@435 430 error_msg = NULL;
duke@435 431 for (uint i = 0; i < ARRAY_SIZE(patterns); i++) {
duke@435 432 if (2 == sscanf(line, patterns[i], class_name, method_name, bytes_read)) {
duke@435 433 *c_mode = check_mode(class_name, error_msg);
duke@435 434 *m_mode = check_mode(method_name, error_msg);
duke@435 435 return *c_mode != MethodMatcher::Unknown && *m_mode != MethodMatcher::Unknown;
duke@435 436 }
duke@435 437 }
duke@435 438 return false;
duke@435 439 }
duke@435 440
duke@435 441
duke@435 442
duke@435 443 void CompilerOracle::parse_from_line(char* line) {
duke@435 444 if (line[0] == '\0') return;
duke@435 445 if (line[0] == '#') return;
duke@435 446
duke@435 447 bool have_colon = (strstr(line, "::") != NULL);
duke@435 448 for (char* lp = line; *lp != '\0'; lp++) {
duke@435 449 // Allow '.' to separate the class name from the method name.
duke@435 450 // This is the preferred spelling of methods:
duke@435 451 // exclude java/lang/String.indexOf(I)I
duke@435 452 // Allow ',' for spaces (eases command line quoting).
duke@435 453 // exclude,java/lang/String.indexOf
duke@435 454 // For backward compatibility, allow space as separator also.
duke@435 455 // exclude java/lang/String indexOf
duke@435 456 // exclude,java/lang/String,indexOf
duke@435 457 // For easy cut-and-paste of method names, allow VM output format
coleenp@4037 458 // as produced by Method::print_short_name:
duke@435 459 // exclude java.lang.String::indexOf
duke@435 460 // For simple implementation convenience here, convert them all to space.
duke@435 461 if (have_colon) {
duke@435 462 if (*lp == '.') *lp = '/'; // dots build the package prefix
duke@435 463 if (*lp == ':') *lp = ' ';
duke@435 464 }
duke@435 465 if (*lp == ',' || *lp == '.') *lp = ' ';
duke@435 466 }
duke@435 467
duke@435 468 char* original_line = line;
duke@435 469 int bytes_read;
duke@435 470 OracleCommand command = parse_command_name(line, &bytes_read);
duke@435 471 line += bytes_read;
duke@435 472
never@2400 473 if (command == UnknownCommand) {
never@2400 474 tty->print_cr("CompilerOracle: unrecognized line");
never@2400 475 tty->print_cr(" \"%s\"", original_line);
never@2400 476 return;
never@2400 477 }
never@2400 478
duke@435 479 if (command == QuietCommand) {
duke@435 480 _quiet = true;
duke@435 481 return;
duke@435 482 }
duke@435 483
duke@435 484 if (command == HelpCommand) {
duke@435 485 usage();
duke@435 486 return;
duke@435 487 }
duke@435 488
duke@435 489 MethodMatcher::Mode c_match = MethodMatcher::Exact;
duke@435 490 MethodMatcher::Mode m_match = MethodMatcher::Exact;
duke@435 491 char class_name[256];
duke@435 492 char method_name[256];
duke@435 493 char sig[1024];
duke@435 494 char errorbuf[1024];
duke@435 495 const char* error_msg = NULL;
duke@435 496 MethodMatcher* match = NULL;
duke@435 497
duke@435 498 if (scan_line(line, class_name, &c_match, method_name, &m_match, &bytes_read, error_msg)) {
duke@435 499 EXCEPTION_MARK;
coleenp@2497 500 Symbol* c_name = SymbolTable::new_symbol(class_name, CHECK);
coleenp@2497 501 Symbol* m_name = SymbolTable::new_symbol(method_name, CHECK);
coleenp@2497 502 Symbol* signature = NULL;
duke@435 503
duke@435 504 line += bytes_read;
duke@435 505 // there might be a signature following the method.
duke@435 506 // signatures always begin with ( so match that by hand
never@2400 507 if (1 == sscanf(line, "%*[ \t](%254[[);/" RANGEBASE "]%n", sig + 1, &bytes_read)) {
duke@435 508 sig[0] = '(';
duke@435 509 line += bytes_read;
coleenp@2497 510 signature = SymbolTable::new_symbol(sig, CHECK);
duke@435 511 }
duke@435 512
duke@435 513 if (command == OptionCommand) {
duke@435 514 // Look for trailing options to support
duke@435 515 // ciMethod::has_option("string") to control features in the
duke@435 516 // compiler. Multiple options may follow the method name.
duke@435 517 char option[256];
duke@435 518 while (sscanf(line, "%*[ \t]%255[a-zA-Z0-9]%n", option, &bytes_read) == 1) {
duke@435 519 if (match != NULL && !_quiet) {
duke@435 520 // Print out the last match added
duke@435 521 tty->print("CompilerOracle: %s ", command_names[command]);
duke@435 522 match->print();
duke@435 523 }
duke@435 524 match = add_option_string(c_name, c_match, m_name, m_match, signature, strdup(option));
duke@435 525 line += bytes_read;
duke@435 526 }
duke@435 527 } else {
duke@435 528 bytes_read = 0;
duke@435 529 sscanf(line, "%*[ \t]%n", &bytes_read);
duke@435 530 if (line[bytes_read] != '\0') {
duke@435 531 jio_snprintf(errorbuf, sizeof(errorbuf), " Unrecognized text after command: %s", line);
duke@435 532 error_msg = errorbuf;
duke@435 533 } else {
duke@435 534 match = add_predicate(command, c_name, c_match, m_name, m_match, signature);
duke@435 535 }
duke@435 536 }
duke@435 537 }
duke@435 538
duke@435 539 if (match != NULL) {
duke@435 540 if (!_quiet) {
roland@4357 541 ResourceMark rm;
duke@435 542 tty->print("CompilerOracle: %s ", command_names[command]);
duke@435 543 match->print();
duke@435 544 }
duke@435 545 } else {
duke@435 546 tty->print_cr("CompilerOracle: unrecognized line");
duke@435 547 tty->print_cr(" \"%s\"", original_line);
duke@435 548 if (error_msg != NULL) {
duke@435 549 tty->print_cr(error_msg);
duke@435 550 }
duke@435 551 }
duke@435 552 }
duke@435 553
kamg@3899 554 static const char* default_cc_file = ".hotspot_compiler";
kamg@3899 555
duke@435 556 static const char* cc_file() {
kamg@3853 557 #ifdef ASSERT
duke@435 558 if (CompileCommandFile == NULL)
kamg@3899 559 return default_cc_file;
kamg@3853 560 #endif
duke@435 561 return CompileCommandFile;
duke@435 562 }
kamg@3853 563
kamg@3853 564 bool CompilerOracle::has_command_file() {
kamg@3853 565 return cc_file() != NULL;
kamg@3853 566 }
kamg@3853 567
duke@435 568 bool CompilerOracle::_quiet = false;
duke@435 569
duke@435 570 void CompilerOracle::parse_from_file() {
kamg@3853 571 assert(has_command_file(), "command file must be specified");
duke@435 572 FILE* stream = fopen(cc_file(), "rt");
duke@435 573 if (stream == NULL) return;
duke@435 574
duke@435 575 char token[1024];
duke@435 576 int pos = 0;
duke@435 577 int c = getc(stream);
kamg@4212 578 while(c != EOF && pos < (int)(sizeof(token)-1)) {
duke@435 579 if (c == '\n') {
duke@435 580 token[pos++] = '\0';
duke@435 581 parse_from_line(token);
duke@435 582 pos = 0;
duke@435 583 } else {
duke@435 584 token[pos++] = c;
duke@435 585 }
duke@435 586 c = getc(stream);
duke@435 587 }
duke@435 588 token[pos++] = '\0';
duke@435 589 parse_from_line(token);
duke@435 590
duke@435 591 fclose(stream);
duke@435 592 }
duke@435 593
duke@435 594 void CompilerOracle::parse_from_string(const char* str, void (*parse_line)(char*)) {
duke@435 595 char token[1024];
duke@435 596 int pos = 0;
duke@435 597 const char* sp = str;
duke@435 598 int c = *sp++;
kamg@4212 599 while (c != '\0' && pos < (int)(sizeof(token)-1)) {
duke@435 600 if (c == '\n') {
duke@435 601 token[pos++] = '\0';
duke@435 602 parse_line(token);
duke@435 603 pos = 0;
duke@435 604 } else {
duke@435 605 token[pos++] = c;
duke@435 606 }
duke@435 607 c = *sp++;
duke@435 608 }
duke@435 609 token[pos++] = '\0';
duke@435 610 parse_line(token);
duke@435 611 }
duke@435 612
duke@435 613 void CompilerOracle::append_comment_to_file(const char* message) {
kamg@3853 614 assert(has_command_file(), "command file must be specified");
duke@435 615 fileStream stream(fopen(cc_file(), "at"));
duke@435 616 stream.print("# ");
duke@435 617 for (int index = 0; message[index] != '\0'; index++) {
duke@435 618 stream.put(message[index]);
duke@435 619 if (message[index] == '\n') stream.print("# ");
duke@435 620 }
duke@435 621 stream.cr();
duke@435 622 }
duke@435 623
duke@435 624 void CompilerOracle::append_exclude_to_file(methodHandle method) {
kamg@3853 625 assert(has_command_file(), "command file must be specified");
duke@435 626 fileStream stream(fopen(cc_file(), "at"));
duke@435 627 stream.print("exclude ");
coleenp@4251 628 method->method_holder()->name()->print_symbol_on(&stream);
duke@435 629 stream.print(".");
duke@435 630 method->name()->print_symbol_on(&stream);
duke@435 631 method->signature()->print_symbol_on(&stream);
duke@435 632 stream.cr();
duke@435 633 stream.cr();
duke@435 634 }
duke@435 635
duke@435 636
duke@435 637 void compilerOracle_init() {
duke@435 638 CompilerOracle::parse_from_string(CompileCommand, CompilerOracle::parse_from_line);
duke@435 639 CompilerOracle::parse_from_string(CompileOnly, CompilerOracle::parse_compile_only);
kamg@3853 640 if (CompilerOracle::has_command_file()) {
kamg@3853 641 CompilerOracle::parse_from_file();
kamg@3899 642 } else {
kamg@3899 643 struct stat buf;
kamg@3899 644 if (os::stat(default_cc_file, &buf) == 0) {
kamg@3899 645 warning("%s file is present but has been ignored. "
kamg@3899 646 "Run with -XX:CompileCommandFile=%s to load the file.",
kamg@3899 647 default_cc_file, default_cc_file);
kamg@3899 648 }
kamg@3853 649 }
jrose@1590 650 if (lists[PrintCommand] != NULL) {
jrose@1590 651 if (PrintAssembly) {
kamg@3899 652 warning("CompileCommand and/or %s file contains 'print' commands, but PrintAssembly is also enabled", default_cc_file);
jrose@1590 653 } else if (FLAG_IS_DEFAULT(DebugNonSafepoints)) {
jrose@1590 654 warning("printing of assembly code is enabled; turning on DebugNonSafepoints to gain additional output");
jrose@1590 655 DebugNonSafepoints = true;
jrose@1590 656 }
jrose@1590 657 }
duke@435 658 }
duke@435 659
duke@435 660
duke@435 661 void CompilerOracle::parse_compile_only(char * line) {
duke@435 662 int i;
duke@435 663 char name[1024];
duke@435 664 const char* className = NULL;
duke@435 665 const char* methodName = NULL;
duke@435 666
duke@435 667 bool have_colon = (strstr(line, "::") != NULL);
duke@435 668 char method_sep = have_colon ? ':' : '.';
duke@435 669
duke@435 670 if (Verbose) {
duke@435 671 tty->print_cr(line);
duke@435 672 }
duke@435 673
duke@435 674 ResourceMark rm;
duke@435 675 while (*line != '\0') {
duke@435 676 MethodMatcher::Mode c_match = MethodMatcher::Exact;
duke@435 677 MethodMatcher::Mode m_match = MethodMatcher::Exact;
duke@435 678
duke@435 679 for (i = 0;
duke@435 680 i < 1024 && *line != '\0' && *line != method_sep && *line != ',' && !isspace(*line);
duke@435 681 line++, i++) {
duke@435 682 name[i] = *line;
duke@435 683 if (name[i] == '.') name[i] = '/'; // package prefix uses '/'
duke@435 684 }
duke@435 685
duke@435 686 if (i > 0) {
duke@435 687 char* newName = NEW_RESOURCE_ARRAY( char, i + 1);
duke@435 688 if (newName == NULL)
duke@435 689 return;
duke@435 690 strncpy(newName, name, i);
duke@435 691 newName[i] = '\0';
duke@435 692
duke@435 693 if (className == NULL) {
duke@435 694 className = newName;
duke@435 695 c_match = MethodMatcher::Prefix;
duke@435 696 } else {
duke@435 697 methodName = newName;
duke@435 698 }
duke@435 699 }
duke@435 700
duke@435 701 if (*line == method_sep) {
duke@435 702 if (className == NULL) {
duke@435 703 className = "";
duke@435 704 c_match = MethodMatcher::Any;
duke@435 705 } else {
duke@435 706 // foo/bar.blah is an exact match on foo/bar, bar.blah is a suffix match on bar
duke@435 707 if (strchr(className, '/') != NULL) {
duke@435 708 c_match = MethodMatcher::Exact;
duke@435 709 } else {
duke@435 710 c_match = MethodMatcher::Suffix;
duke@435 711 }
duke@435 712 }
duke@435 713 } else {
duke@435 714 // got foo or foo/bar
duke@435 715 if (className == NULL) {
duke@435 716 ShouldNotReachHere();
duke@435 717 } else {
duke@435 718 // got foo or foo/bar
duke@435 719 if (strchr(className, '/') != NULL) {
duke@435 720 c_match = MethodMatcher::Prefix;
duke@435 721 } else if (className[0] == '\0') {
duke@435 722 c_match = MethodMatcher::Any;
duke@435 723 } else {
duke@435 724 c_match = MethodMatcher::Substring;
duke@435 725 }
duke@435 726 }
duke@435 727 }
duke@435 728
duke@435 729 // each directive is terminated by , or NUL or . followed by NUL
duke@435 730 if (*line == ',' || *line == '\0' || (line[0] == '.' && line[1] == '\0')) {
duke@435 731 if (methodName == NULL) {
duke@435 732 methodName = "";
duke@435 733 if (*line != method_sep) {
duke@435 734 m_match = MethodMatcher::Any;
duke@435 735 }
duke@435 736 }
duke@435 737
duke@435 738 EXCEPTION_MARK;
coleenp@2497 739 Symbol* c_name = SymbolTable::new_symbol(className, CHECK);
coleenp@2497 740 Symbol* m_name = SymbolTable::new_symbol(methodName, CHECK);
coleenp@2497 741 Symbol* signature = NULL;
duke@435 742
duke@435 743 add_predicate(CompileOnlyCommand, c_name, c_match, m_name, m_match, signature);
duke@435 744 if (PrintVMOptions) {
duke@435 745 tty->print("CompileOnly: compileonly ");
duke@435 746 lists[CompileOnlyCommand]->print();
duke@435 747 }
duke@435 748
duke@435 749 className = NULL;
duke@435 750 methodName = NULL;
duke@435 751 }
duke@435 752
duke@435 753 line = *line == '\0' ? line : line + 1;
duke@435 754 }
duke@435 755 }

mercurial