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