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