aoqi@0: /* aoqi@0: * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: * aoqi@0: */ aoqi@0: aoqi@0: #include "precompiled.hpp" aoqi@0: #include "compiler/compilerOracle.hpp" aoqi@0: #include "memory/allocation.inline.hpp" aoqi@0: #include "memory/oopFactory.hpp" aoqi@0: #include "memory/resourceArea.hpp" aoqi@0: #include "oops/klass.hpp" aoqi@0: #include "oops/method.hpp" aoqi@0: #include "oops/oop.inline.hpp" aoqi@0: #include "oops/symbol.hpp" aoqi@0: #include "runtime/handles.inline.hpp" aoqi@0: #include "runtime/jniHandles.hpp" aoqi@0: aoqi@0: class MethodMatcher : public CHeapObj { aoqi@0: public: aoqi@0: enum Mode { aoqi@0: Exact, aoqi@0: Prefix = 1, aoqi@0: Suffix = 2, aoqi@0: Substring = Prefix | Suffix, aoqi@0: Any, aoqi@0: Unknown = -1 aoqi@0: }; aoqi@0: aoqi@0: protected: aoqi@0: Symbol* _class_name; aoqi@0: Symbol* _method_name; aoqi@0: Symbol* _signature; aoqi@0: Mode _class_mode; aoqi@0: Mode _method_mode; aoqi@0: MethodMatcher* _next; aoqi@0: aoqi@0: static bool match(Symbol* candidate, Symbol* match, Mode match_mode); aoqi@0: aoqi@0: Symbol* class_name() const { return _class_name; } aoqi@0: Symbol* method_name() const { return _method_name; } aoqi@0: Symbol* signature() const { return _signature; } aoqi@0: aoqi@0: public: aoqi@0: MethodMatcher(Symbol* class_name, Mode class_mode, aoqi@0: Symbol* method_name, Mode method_mode, aoqi@0: Symbol* signature, MethodMatcher* next); aoqi@0: MethodMatcher(Symbol* class_name, Symbol* method_name, MethodMatcher* next); aoqi@0: aoqi@0: // utility method aoqi@0: MethodMatcher* find(methodHandle method) { aoqi@0: Symbol* class_name = method->method_holder()->name(); aoqi@0: Symbol* method_name = method->name(); aoqi@0: for (MethodMatcher* current = this; current != NULL; current = current->_next) { aoqi@0: if (match(class_name, current->class_name(), current->_class_mode) && aoqi@0: match(method_name, current->method_name(), current->_method_mode) && aoqi@0: (current->signature() == NULL || current->signature() == method->signature())) { aoqi@0: return current; aoqi@0: } aoqi@0: } aoqi@0: return NULL; aoqi@0: } aoqi@0: aoqi@0: bool match(methodHandle method) { aoqi@0: return find(method) != NULL; aoqi@0: } aoqi@0: aoqi@0: MethodMatcher* next() const { return _next; } aoqi@0: aoqi@0: static void print_symbol(Symbol* h, Mode mode) { aoqi@0: ResourceMark rm; aoqi@0: aoqi@0: if (mode == Suffix || mode == Substring || mode == Any) { aoqi@0: tty->print("*"); aoqi@0: } aoqi@0: if (mode != Any) { aoqi@0: h->print_symbol_on(tty); aoqi@0: } aoqi@0: if (mode == Prefix || mode == Substring) { aoqi@0: tty->print("*"); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: void print_base() { aoqi@0: print_symbol(class_name(), _class_mode); aoqi@0: tty->print("."); aoqi@0: print_symbol(method_name(), _method_mode); aoqi@0: if (signature() != NULL) { aoqi@0: tty->print(" "); aoqi@0: signature()->print_symbol_on(tty); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: virtual void print() { aoqi@0: print_base(); aoqi@0: tty->cr(); aoqi@0: } aoqi@0: }; aoqi@0: aoqi@0: MethodMatcher::MethodMatcher(Symbol* class_name, Symbol* method_name, MethodMatcher* next) { aoqi@0: _class_name = class_name; aoqi@0: _method_name = method_name; aoqi@0: _next = next; aoqi@0: _class_mode = MethodMatcher::Exact; aoqi@0: _method_mode = MethodMatcher::Exact; aoqi@0: _signature = NULL; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: MethodMatcher::MethodMatcher(Symbol* class_name, Mode class_mode, aoqi@0: Symbol* method_name, Mode method_mode, aoqi@0: Symbol* signature, MethodMatcher* next): aoqi@0: _class_mode(class_mode) aoqi@0: , _method_mode(method_mode) aoqi@0: , _next(next) aoqi@0: , _class_name(class_name) aoqi@0: , _method_name(method_name) aoqi@0: , _signature(signature) { aoqi@0: } aoqi@0: aoqi@0: bool MethodMatcher::match(Symbol* candidate, Symbol* match, Mode match_mode) { aoqi@0: if (match_mode == Any) { aoqi@0: return true; aoqi@0: } aoqi@0: aoqi@0: if (match_mode == Exact) { aoqi@0: return candidate == match; aoqi@0: } aoqi@0: aoqi@0: ResourceMark rm; aoqi@0: const char * candidate_string = candidate->as_C_string(); aoqi@0: const char * match_string = match->as_C_string(); aoqi@0: aoqi@0: switch (match_mode) { aoqi@0: case Prefix: aoqi@0: return strstr(candidate_string, match_string) == candidate_string; aoqi@0: aoqi@0: case Suffix: { aoqi@0: size_t clen = strlen(candidate_string); aoqi@0: size_t mlen = strlen(match_string); aoqi@0: return clen >= mlen && strcmp(candidate_string + clen - mlen, match_string) == 0; aoqi@0: } aoqi@0: aoqi@0: case Substring: aoqi@0: return strstr(candidate_string, match_string) != NULL; aoqi@0: aoqi@0: default: aoqi@0: return false; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: aoqi@0: class MethodOptionMatcher: public MethodMatcher { aoqi@0: const char * option; aoqi@0: public: aoqi@0: MethodOptionMatcher(Symbol* class_name, Mode class_mode, aoqi@0: Symbol* method_name, Mode method_mode, aoqi@0: Symbol* signature, const char * opt, MethodMatcher* next): aoqi@0: MethodMatcher(class_name, class_mode, method_name, method_mode, signature, next) { aoqi@0: option = opt; aoqi@0: } aoqi@0: aoqi@0: bool match(methodHandle method, const char* opt) { aoqi@0: MethodOptionMatcher* current = this; aoqi@0: while (current != NULL) { aoqi@0: current = (MethodOptionMatcher*)current->find(method); aoqi@0: if (current == NULL) { aoqi@0: return false; aoqi@0: } aoqi@0: if (strcmp(current->option, opt) == 0) { aoqi@0: return true; aoqi@0: } aoqi@0: current = current->next(); aoqi@0: } aoqi@0: return false; aoqi@0: } aoqi@0: aoqi@0: MethodOptionMatcher* next() { aoqi@0: return (MethodOptionMatcher*)_next; aoqi@0: } aoqi@0: aoqi@0: virtual void print() { aoqi@0: print_base(); aoqi@0: tty->print(" %s", option); aoqi@0: tty->cr(); aoqi@0: } aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: aoqi@0: // this must parallel the command_names below aoqi@0: enum OracleCommand { aoqi@0: UnknownCommand = -1, aoqi@0: OracleFirstCommand = 0, aoqi@0: BreakCommand = OracleFirstCommand, aoqi@0: PrintCommand, aoqi@0: ExcludeCommand, aoqi@0: InlineCommand, aoqi@0: DontInlineCommand, aoqi@0: CompileOnlyCommand, aoqi@0: LogCommand, aoqi@0: OptionCommand, aoqi@0: QuietCommand, aoqi@0: HelpCommand, aoqi@0: OracleCommandCount aoqi@0: }; aoqi@0: aoqi@0: // this must parallel the enum OracleCommand aoqi@0: static const char * command_names[] = { aoqi@0: "break", aoqi@0: "print", aoqi@0: "exclude", aoqi@0: "inline", aoqi@0: "dontinline", aoqi@0: "compileonly", aoqi@0: "log", aoqi@0: "option", aoqi@0: "quiet", aoqi@0: "help" aoqi@0: }; aoqi@0: aoqi@0: class MethodMatcher; aoqi@0: static MethodMatcher* lists[OracleCommandCount] = { 0, }; aoqi@0: aoqi@0: aoqi@0: static bool check_predicate(OracleCommand command, methodHandle method) { aoqi@0: return ((lists[command] != NULL) && aoqi@0: !method.is_null() && aoqi@0: lists[command]->match(method)); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: static MethodMatcher* add_predicate(OracleCommand command, aoqi@0: Symbol* class_name, MethodMatcher::Mode c_mode, aoqi@0: Symbol* method_name, MethodMatcher::Mode m_mode, aoqi@0: Symbol* signature) { aoqi@0: assert(command != OptionCommand, "must use add_option_string"); aoqi@0: if (command == LogCommand && !LogCompilation && lists[LogCommand] == NULL) aoqi@0: tty->print_cr("Warning: +LogCompilation must be enabled in order for individual methods to be logged."); aoqi@0: lists[command] = new MethodMatcher(class_name, c_mode, method_name, m_mode, signature, lists[command]); aoqi@0: return lists[command]; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: aoqi@0: static MethodMatcher* add_option_string(Symbol* class_name, MethodMatcher::Mode c_mode, aoqi@0: Symbol* method_name, MethodMatcher::Mode m_mode, aoqi@0: Symbol* signature, aoqi@0: const char* option) { aoqi@0: lists[OptionCommand] = new MethodOptionMatcher(class_name, c_mode, method_name, m_mode, aoqi@0: signature, option, lists[OptionCommand]); aoqi@0: return lists[OptionCommand]; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: bool CompilerOracle::has_option_string(methodHandle method, const char* option) { aoqi@0: return lists[OptionCommand] != NULL && aoqi@0: ((MethodOptionMatcher*)lists[OptionCommand])->match(method, option); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: bool CompilerOracle::should_exclude(methodHandle method, bool& quietly) { aoqi@0: quietly = true; aoqi@0: if (lists[ExcludeCommand] != NULL) { aoqi@0: if (lists[ExcludeCommand]->match(method)) { aoqi@0: quietly = _quiet; aoqi@0: return true; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: if (lists[CompileOnlyCommand] != NULL) { aoqi@0: return !lists[CompileOnlyCommand]->match(method); aoqi@0: } aoqi@0: return false; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: bool CompilerOracle::should_inline(methodHandle method) { aoqi@0: return (check_predicate(InlineCommand, method)); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: bool CompilerOracle::should_not_inline(methodHandle method) { aoqi@0: return (check_predicate(DontInlineCommand, method)); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: bool CompilerOracle::should_print(methodHandle method) { aoqi@0: return (check_predicate(PrintCommand, method)); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: bool CompilerOracle::should_log(methodHandle method) { aoqi@0: if (!LogCompilation) return false; aoqi@0: if (lists[LogCommand] == NULL) return true; // by default, log all aoqi@0: return (check_predicate(LogCommand, method)); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: bool CompilerOracle::should_break_at(methodHandle method) { aoqi@0: return check_predicate(BreakCommand, method); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: static OracleCommand parse_command_name(const char * line, int* bytes_read) { aoqi@0: assert(ARRAY_SIZE(command_names) == OracleCommandCount, aoqi@0: "command_names size mismatch"); aoqi@0: aoqi@0: *bytes_read = 0; aoqi@0: char command[33]; aoqi@0: int result = sscanf(line, "%32[a-z]%n", command, bytes_read); aoqi@0: for (uint i = 0; i < ARRAY_SIZE(command_names); i++) { aoqi@0: if (strcmp(command, command_names[i]) == 0) { aoqi@0: return (OracleCommand)i; aoqi@0: } aoqi@0: } aoqi@0: return UnknownCommand; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: static void usage() { aoqi@0: tty->print_cr(" CompileCommand and the CompilerOracle allows simple control over"); aoqi@0: tty->print_cr(" what's allowed to be compiled. The standard supported directives"); aoqi@0: tty->print_cr(" are exclude and compileonly. The exclude directive stops a method"); aoqi@0: tty->print_cr(" from being compiled and compileonly excludes all methods except for"); aoqi@0: tty->print_cr(" the ones mentioned by compileonly directives. The basic form of"); aoqi@0: tty->print_cr(" all commands is a command name followed by the name of the method"); aoqi@0: tty->print_cr(" in one of two forms: the standard class file format as in"); aoqi@0: tty->print_cr(" class/name.methodName or the PrintCompilation format"); aoqi@0: tty->print_cr(" class.name::methodName. The method name can optionally be followed"); aoqi@0: tty->print_cr(" by a space then the signature of the method in the class file"); aoqi@0: tty->print_cr(" format. Otherwise the directive applies to all methods with the"); aoqi@0: tty->print_cr(" same name and class regardless of signature. Leading and trailing"); aoqi@0: tty->print_cr(" *'s in the class and/or method name allows a small amount of"); aoqi@0: tty->print_cr(" wildcarding. "); aoqi@0: tty->cr(); aoqi@0: tty->print_cr(" Examples:"); aoqi@0: tty->cr(); aoqi@0: tty->print_cr(" exclude java/lang/StringBuffer.append"); aoqi@0: tty->print_cr(" compileonly java/lang/StringBuffer.toString ()Ljava/lang/String;"); aoqi@0: tty->print_cr(" exclude java/lang/String*.*"); aoqi@0: tty->print_cr(" exclude *.toString"); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: // The characters allowed in a class or method name. All characters > 0x7f aoqi@0: // are allowed in order to handle obfuscated class files (e.g. Volano) aoqi@0: #define RANGEBASE "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789$_<>" \ aoqi@0: "\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f" \ aoqi@0: "\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f" \ aoqi@0: "\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf" \ aoqi@0: "\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf" \ aoqi@0: "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf" \ aoqi@0: "\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf" \ aoqi@0: "\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef" \ aoqi@0: "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff" aoqi@0: aoqi@0: #define RANGE0 "[*" RANGEBASE "]" aoqi@0: #define RANGEDOT "[*" RANGEBASE ".]" aoqi@0: #define RANGESLASH "[*" RANGEBASE "/]" aoqi@0: aoqi@0: aoqi@0: // Accept several syntaxes for these patterns aoqi@0: // original syntax aoqi@0: // cmd java.lang.String foo aoqi@0: // PrintCompilation syntax aoqi@0: // cmd java.lang.String::foo aoqi@0: // VM syntax aoqi@0: // cmd java/lang/String[. ]foo aoqi@0: // aoqi@0: aoqi@0: static const char* patterns[] = { aoqi@0: "%*[ \t]%255" RANGEDOT " " "%255" RANGE0 "%n", aoqi@0: "%*[ \t]%255" RANGEDOT "::" "%255" RANGE0 "%n", aoqi@0: "%*[ \t]%255" RANGESLASH "%*[ .]" "%255" RANGE0 "%n", aoqi@0: }; aoqi@0: aoqi@0: static MethodMatcher::Mode check_mode(char name[], const char*& error_msg) { aoqi@0: int match = MethodMatcher::Exact; aoqi@0: while (name[0] == '*') { aoqi@0: match |= MethodMatcher::Suffix; aoqi@0: strcpy(name, name + 1); aoqi@0: } aoqi@0: aoqi@0: if (strcmp(name, "*") == 0) return MethodMatcher::Any; aoqi@0: aoqi@0: size_t len = strlen(name); aoqi@0: while (len > 0 && name[len - 1] == '*') { aoqi@0: match |= MethodMatcher::Prefix; aoqi@0: name[--len] = '\0'; aoqi@0: } aoqi@0: aoqi@0: if (strstr(name, "*") != NULL) { aoqi@0: error_msg = " Embedded * not allowed"; aoqi@0: return MethodMatcher::Unknown; aoqi@0: } aoqi@0: return (MethodMatcher::Mode)match; aoqi@0: } aoqi@0: aoqi@0: static bool scan_line(const char * line, aoqi@0: char class_name[], MethodMatcher::Mode* c_mode, aoqi@0: char method_name[], MethodMatcher::Mode* m_mode, aoqi@0: int* bytes_read, const char*& error_msg) { aoqi@0: *bytes_read = 0; aoqi@0: error_msg = NULL; aoqi@0: for (uint i = 0; i < ARRAY_SIZE(patterns); i++) { aoqi@0: if (2 == sscanf(line, patterns[i], class_name, method_name, bytes_read)) { aoqi@0: *c_mode = check_mode(class_name, error_msg); aoqi@0: *m_mode = check_mode(method_name, error_msg); aoqi@0: return *c_mode != MethodMatcher::Unknown && *m_mode != MethodMatcher::Unknown; aoqi@0: } aoqi@0: } aoqi@0: return false; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: aoqi@0: void CompilerOracle::parse_from_line(char* line) { aoqi@0: if (line[0] == '\0') return; aoqi@0: if (line[0] == '#') return; aoqi@0: aoqi@0: bool have_colon = (strstr(line, "::") != NULL); aoqi@0: for (char* lp = line; *lp != '\0'; lp++) { aoqi@0: // Allow '.' to separate the class name from the method name. aoqi@0: // This is the preferred spelling of methods: aoqi@0: // exclude java/lang/String.indexOf(I)I aoqi@0: // Allow ',' for spaces (eases command line quoting). aoqi@0: // exclude,java/lang/String.indexOf aoqi@0: // For backward compatibility, allow space as separator also. aoqi@0: // exclude java/lang/String indexOf aoqi@0: // exclude,java/lang/String,indexOf aoqi@0: // For easy cut-and-paste of method names, allow VM output format aoqi@0: // as produced by Method::print_short_name: aoqi@0: // exclude java.lang.String::indexOf aoqi@0: // For simple implementation convenience here, convert them all to space. aoqi@0: if (have_colon) { aoqi@0: if (*lp == '.') *lp = '/'; // dots build the package prefix aoqi@0: if (*lp == ':') *lp = ' '; aoqi@0: } aoqi@0: if (*lp == ',' || *lp == '.') *lp = ' '; aoqi@0: } aoqi@0: aoqi@0: char* original_line = line; aoqi@0: int bytes_read; aoqi@0: OracleCommand command = parse_command_name(line, &bytes_read); aoqi@0: line += bytes_read; aoqi@0: aoqi@0: if (command == UnknownCommand) { aoqi@0: tty->print_cr("CompilerOracle: unrecognized line"); aoqi@0: tty->print_cr(" \"%s\"", original_line); aoqi@0: return; aoqi@0: } aoqi@0: aoqi@0: if (command == QuietCommand) { aoqi@0: _quiet = true; aoqi@0: return; aoqi@0: } aoqi@0: aoqi@0: if (command == HelpCommand) { aoqi@0: usage(); aoqi@0: return; aoqi@0: } aoqi@0: aoqi@0: MethodMatcher::Mode c_match = MethodMatcher::Exact; aoqi@0: MethodMatcher::Mode m_match = MethodMatcher::Exact; aoqi@0: char class_name[256]; aoqi@0: char method_name[256]; aoqi@0: char sig[1024]; aoqi@0: char errorbuf[1024]; aoqi@0: const char* error_msg = NULL; aoqi@0: MethodMatcher* match = NULL; aoqi@0: aoqi@0: if (scan_line(line, class_name, &c_match, method_name, &m_match, &bytes_read, error_msg)) { aoqi@0: EXCEPTION_MARK; aoqi@0: Symbol* c_name = SymbolTable::new_symbol(class_name, CHECK); aoqi@0: Symbol* m_name = SymbolTable::new_symbol(method_name, CHECK); aoqi@0: Symbol* signature = NULL; aoqi@0: aoqi@0: line += bytes_read; aoqi@0: // there might be a signature following the method. aoqi@0: // signatures always begin with ( so match that by hand aoqi@0: if (1 == sscanf(line, "%*[ \t](%254[[);/" RANGEBASE "]%n", sig + 1, &bytes_read)) { aoqi@0: sig[0] = '('; aoqi@0: line += bytes_read; aoqi@0: signature = SymbolTable::new_symbol(sig, CHECK); aoqi@0: } aoqi@0: aoqi@0: if (command == OptionCommand) { aoqi@0: // Look for trailing options to support aoqi@0: // ciMethod::has_option("string") to control features in the aoqi@0: // compiler. Multiple options may follow the method name. aoqi@0: char option[256]; aoqi@0: while (sscanf(line, "%*[ \t]%255[a-zA-Z0-9]%n", option, &bytes_read) == 1) { aoqi@0: if (match != NULL && !_quiet) { aoqi@0: // Print out the last match added aoqi@0: tty->print("CompilerOracle: %s ", command_names[command]); aoqi@0: match->print(); aoqi@0: } aoqi@0: match = add_option_string(c_name, c_match, m_name, m_match, signature, strdup(option)); aoqi@0: line += bytes_read; aoqi@0: } aoqi@0: } else { aoqi@0: bytes_read = 0; aoqi@0: sscanf(line, "%*[ \t]%n", &bytes_read); aoqi@0: if (line[bytes_read] != '\0') { aoqi@0: jio_snprintf(errorbuf, sizeof(errorbuf), " Unrecognized text after command: %s", line); aoqi@0: error_msg = errorbuf; aoqi@0: } else { aoqi@0: match = add_predicate(command, c_name, c_match, m_name, m_match, signature); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: if (match != NULL) { aoqi@0: if (!_quiet) { aoqi@0: ResourceMark rm; aoqi@0: tty->print("CompilerOracle: %s ", command_names[command]); aoqi@0: match->print(); aoqi@0: } aoqi@0: } else { aoqi@0: tty->print_cr("CompilerOracle: unrecognized line"); aoqi@0: tty->print_cr(" \"%s\"", original_line); aoqi@0: if (error_msg != NULL) { aoqi@0: tty->print_cr("%s", error_msg); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: static const char* default_cc_file = ".hotspot_compiler"; aoqi@0: aoqi@0: static const char* cc_file() { aoqi@0: #ifdef ASSERT aoqi@0: if (CompileCommandFile == NULL) aoqi@0: return default_cc_file; aoqi@0: #endif aoqi@0: return CompileCommandFile; aoqi@0: } aoqi@0: aoqi@0: bool CompilerOracle::has_command_file() { aoqi@0: return cc_file() != NULL; aoqi@0: } aoqi@0: aoqi@0: bool CompilerOracle::_quiet = false; aoqi@0: aoqi@0: void CompilerOracle::parse_from_file() { aoqi@0: assert(has_command_file(), "command file must be specified"); aoqi@0: FILE* stream = fopen(cc_file(), "rt"); aoqi@0: if (stream == NULL) return; aoqi@0: aoqi@0: char token[1024]; aoqi@0: int pos = 0; aoqi@0: int c = getc(stream); aoqi@0: while(c != EOF && pos < (int)(sizeof(token)-1)) { aoqi@0: if (c == '\n') { aoqi@0: token[pos++] = '\0'; aoqi@0: parse_from_line(token); aoqi@0: pos = 0; aoqi@0: } else { aoqi@0: token[pos++] = c; aoqi@0: } aoqi@0: c = getc(stream); aoqi@0: } aoqi@0: token[pos++] = '\0'; aoqi@0: parse_from_line(token); aoqi@0: aoqi@0: fclose(stream); aoqi@0: } aoqi@0: aoqi@0: void CompilerOracle::parse_from_string(const char* str, void (*parse_line)(char*)) { aoqi@0: char token[1024]; aoqi@0: int pos = 0; aoqi@0: const char* sp = str; aoqi@0: int c = *sp++; aoqi@0: while (c != '\0' && pos < (int)(sizeof(token)-1)) { aoqi@0: if (c == '\n') { aoqi@0: token[pos++] = '\0'; aoqi@0: parse_line(token); aoqi@0: pos = 0; aoqi@0: } else { aoqi@0: token[pos++] = c; aoqi@0: } aoqi@0: c = *sp++; aoqi@0: } aoqi@0: token[pos++] = '\0'; aoqi@0: parse_line(token); aoqi@0: } aoqi@0: aoqi@0: void CompilerOracle::append_comment_to_file(const char* message) { aoqi@0: assert(has_command_file(), "command file must be specified"); aoqi@0: fileStream stream(fopen(cc_file(), "at")); aoqi@0: stream.print("# "); aoqi@0: for (int index = 0; message[index] != '\0'; index++) { aoqi@0: stream.put(message[index]); aoqi@0: if (message[index] == '\n') stream.print("# "); aoqi@0: } aoqi@0: stream.cr(); aoqi@0: } aoqi@0: aoqi@0: void CompilerOracle::append_exclude_to_file(methodHandle method) { aoqi@0: assert(has_command_file(), "command file must be specified"); aoqi@0: fileStream stream(fopen(cc_file(), "at")); aoqi@0: stream.print("exclude "); aoqi@0: method->method_holder()->name()->print_symbol_on(&stream); aoqi@0: stream.print("."); aoqi@0: method->name()->print_symbol_on(&stream); aoqi@0: method->signature()->print_symbol_on(&stream); aoqi@0: stream.cr(); aoqi@0: stream.cr(); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: void compilerOracle_init() { aoqi@0: CompilerOracle::parse_from_string(CompileCommand, CompilerOracle::parse_from_line); aoqi@0: CompilerOracle::parse_from_string(CompileOnly, CompilerOracle::parse_compile_only); aoqi@0: if (CompilerOracle::has_command_file()) { aoqi@0: CompilerOracle::parse_from_file(); aoqi@0: } else { aoqi@0: struct stat buf; aoqi@0: if (os::stat(default_cc_file, &buf) == 0) { aoqi@0: warning("%s file is present but has been ignored. " aoqi@0: "Run with -XX:CompileCommandFile=%s to load the file.", aoqi@0: default_cc_file, default_cc_file); aoqi@0: } aoqi@0: } aoqi@0: if (lists[PrintCommand] != NULL) { aoqi@0: if (PrintAssembly) { aoqi@0: warning("CompileCommand and/or %s file contains 'print' commands, but PrintAssembly is also enabled", default_cc_file); aoqi@0: } else if (FLAG_IS_DEFAULT(DebugNonSafepoints)) { aoqi@0: warning("printing of assembly code is enabled; turning on DebugNonSafepoints to gain additional output"); aoqi@0: DebugNonSafepoints = true; aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: aoqi@0: void CompilerOracle::parse_compile_only(char * line) { aoqi@0: int i; aoqi@0: char name[1024]; aoqi@0: const char* className = NULL; aoqi@0: const char* methodName = NULL; aoqi@0: aoqi@0: bool have_colon = (strstr(line, "::") != NULL); aoqi@0: char method_sep = have_colon ? ':' : '.'; aoqi@0: aoqi@0: if (Verbose) { aoqi@0: tty->print_cr("%s", line); aoqi@0: } aoqi@0: aoqi@0: ResourceMark rm; aoqi@0: while (*line != '\0') { aoqi@0: MethodMatcher::Mode c_match = MethodMatcher::Exact; aoqi@0: MethodMatcher::Mode m_match = MethodMatcher::Exact; aoqi@0: aoqi@0: for (i = 0; aoqi@0: i < 1024 && *line != '\0' && *line != method_sep && *line != ',' && !isspace(*line); aoqi@0: line++, i++) { aoqi@0: name[i] = *line; aoqi@0: if (name[i] == '.') name[i] = '/'; // package prefix uses '/' aoqi@0: } aoqi@0: aoqi@0: if (i > 0) { aoqi@0: char* newName = NEW_RESOURCE_ARRAY( char, i + 1); aoqi@0: if (newName == NULL) aoqi@0: return; aoqi@0: strncpy(newName, name, i); aoqi@0: newName[i] = '\0'; aoqi@0: aoqi@0: if (className == NULL) { aoqi@0: className = newName; aoqi@0: c_match = MethodMatcher::Prefix; aoqi@0: } else { aoqi@0: methodName = newName; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: if (*line == method_sep) { aoqi@0: if (className == NULL) { aoqi@0: className = ""; aoqi@0: c_match = MethodMatcher::Any; aoqi@0: } else { aoqi@0: // foo/bar.blah is an exact match on foo/bar, bar.blah is a suffix match on bar aoqi@0: if (strchr(className, '/') != NULL) { aoqi@0: c_match = MethodMatcher::Exact; aoqi@0: } else { aoqi@0: c_match = MethodMatcher::Suffix; aoqi@0: } aoqi@0: } aoqi@0: } else { aoqi@0: // got foo or foo/bar aoqi@0: if (className == NULL) { aoqi@0: ShouldNotReachHere(); aoqi@0: } else { aoqi@0: // got foo or foo/bar aoqi@0: if (strchr(className, '/') != NULL) { aoqi@0: c_match = MethodMatcher::Prefix; aoqi@0: } else if (className[0] == '\0') { aoqi@0: c_match = MethodMatcher::Any; aoqi@0: } else { aoqi@0: c_match = MethodMatcher::Substring; aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // each directive is terminated by , or NUL or . followed by NUL aoqi@0: if (*line == ',' || *line == '\0' || (line[0] == '.' && line[1] == '\0')) { aoqi@0: if (methodName == NULL) { aoqi@0: methodName = ""; aoqi@0: if (*line != method_sep) { aoqi@0: m_match = MethodMatcher::Any; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: EXCEPTION_MARK; aoqi@0: Symbol* c_name = SymbolTable::new_symbol(className, CHECK); aoqi@0: Symbol* m_name = SymbolTable::new_symbol(methodName, CHECK); aoqi@0: Symbol* signature = NULL; aoqi@0: aoqi@0: add_predicate(CompileOnlyCommand, c_name, c_match, m_name, m_match, signature); aoqi@0: if (PrintVMOptions) { aoqi@0: tty->print("CompileOnly: compileonly "); aoqi@0: lists[CompileOnlyCommand]->print(); aoqi@0: } aoqi@0: aoqi@0: className = NULL; aoqi@0: methodName = NULL; aoqi@0: } aoqi@0: aoqi@0: line = *line == '\0' ? line : line + 1; aoqi@0: } aoqi@0: }