Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/compiler/compilerOracle.cpp
32285 views
/*1* Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "compiler/compilerOracle.hpp"26#include "memory/allocation.inline.hpp"27#include "memory/oopFactory.hpp"28#include "memory/resourceArea.hpp"29#include "oops/klass.hpp"30#include "oops/method.hpp"31#include "oops/oop.inline.hpp"32#include "oops/symbol.hpp"33#include "runtime/handles.inline.hpp"34#include "runtime/jniHandles.hpp"3536class MethodMatcher : public CHeapObj<mtCompiler> {37public:38enum Mode {39Exact,40Prefix = 1,41Suffix = 2,42Substring = Prefix | Suffix,43Any,44Unknown = -145};4647protected:48Symbol* _class_name;49Symbol* _method_name;50Symbol* _signature;51Mode _class_mode;52Mode _method_mode;53MethodMatcher* _next;5455static bool match(Symbol* candidate, Symbol* match, Mode match_mode);5657Symbol* class_name() const { return _class_name; }58Symbol* method_name() const { return _method_name; }59Symbol* signature() const { return _signature; }6061public:62MethodMatcher(Symbol* class_name, Mode class_mode,63Symbol* method_name, Mode method_mode,64Symbol* signature, MethodMatcher* next);65MethodMatcher(Symbol* class_name, Symbol* method_name, MethodMatcher* next);6667// utility method68MethodMatcher* find(methodHandle method) {69Symbol* class_name = method->method_holder()->name();70Symbol* method_name = method->name();71for (MethodMatcher* current = this; current != NULL; current = current->_next) {72if (match(class_name, current->class_name(), current->_class_mode) &&73match(method_name, current->method_name(), current->_method_mode) &&74(current->signature() == NULL || current->signature() == method->signature())) {75return current;76}77}78return NULL;79}8081bool match(methodHandle method) {82return find(method) != NULL;83}8485MethodMatcher* next() const { return _next; }8687static void print_symbol(Symbol* h, Mode mode) {88ResourceMark rm;8990if (mode == Suffix || mode == Substring || mode == Any) {91tty->print("*");92}93if (mode != Any) {94h->print_symbol_on(tty);95}96if (mode == Prefix || mode == Substring) {97tty->print("*");98}99}100101void print_base() {102print_symbol(class_name(), _class_mode);103tty->print(".");104print_symbol(method_name(), _method_mode);105if (signature() != NULL) {106tty->print(" ");107signature()->print_symbol_on(tty);108}109}110111virtual void print() {112print_base();113tty->cr();114}115};116117MethodMatcher::MethodMatcher(Symbol* class_name, Symbol* method_name, MethodMatcher* next) {118_class_name = class_name;119_method_name = method_name;120_next = next;121_class_mode = MethodMatcher::Exact;122_method_mode = MethodMatcher::Exact;123_signature = NULL;124}125126127MethodMatcher::MethodMatcher(Symbol* class_name, Mode class_mode,128Symbol* method_name, Mode method_mode,129Symbol* signature, MethodMatcher* next):130_class_mode(class_mode)131, _method_mode(method_mode)132, _next(next)133, _class_name(class_name)134, _method_name(method_name)135, _signature(signature) {136}137138bool MethodMatcher::match(Symbol* candidate, Symbol* match, Mode match_mode) {139if (match_mode == Any) {140return true;141}142143if (match_mode == Exact) {144return candidate == match;145}146147ResourceMark rm;148const char * candidate_string = candidate->as_C_string();149const char * match_string = match->as_C_string();150151switch (match_mode) {152case Prefix:153return strstr(candidate_string, match_string) == candidate_string;154155case Suffix: {156size_t clen = strlen(candidate_string);157size_t mlen = strlen(match_string);158return clen >= mlen && strcmp(candidate_string + clen - mlen, match_string) == 0;159}160161case Substring:162return strstr(candidate_string, match_string) != NULL;163164default:165return false;166}167}168169enum OptionType {170IntxType,171UintxType,172BoolType,173CcstrType,174UnknownType175};176177/* Methods to map real type names to OptionType */178template<typename T>179static OptionType get_type_for() {180return UnknownType;181};182183template<> OptionType get_type_for<intx>() {184return IntxType;185}186187template<> OptionType get_type_for<uintx>() {188return UintxType;189}190191template<> OptionType get_type_for<bool>() {192return BoolType;193}194195template<> OptionType get_type_for<ccstr>() {196return CcstrType;197}198199template<typename T>200static const T copy_value(const T value) {201return value;202}203204template<> const ccstr copy_value<ccstr>(const ccstr value) {205return (const ccstr)strdup(value);206}207208template <typename T>209class TypedMethodOptionMatcher : public MethodMatcher {210const char* _option;211OptionType _type;212const T _value;213214public:215TypedMethodOptionMatcher(Symbol* class_name, Mode class_mode,216Symbol* method_name, Mode method_mode,217Symbol* signature, const char* opt,218const T value, MethodMatcher* next) :219MethodMatcher(class_name, class_mode, method_name, method_mode, signature, next),220_type(get_type_for<T>()), _value(copy_value<T>(value)) {221_option = strdup(opt);222}223224~TypedMethodOptionMatcher() {225free((void*)_option);226}227228TypedMethodOptionMatcher* match(methodHandle method, const char* opt) {229TypedMethodOptionMatcher* current = this;230while (current != NULL) {231current = (TypedMethodOptionMatcher*)current->find(method);232if (current == NULL) {233return NULL;234}235if (strcmp(current->_option, opt) == 0) {236return current;237}238current = current->next();239}240return NULL;241}242243TypedMethodOptionMatcher* next() {244return (TypedMethodOptionMatcher*)_next;245}246247OptionType get_type(void) {248return _type;249};250251T value() { return _value; }252253void print() {254ttyLocker ttyl;255print_base();256tty->print(" %s", _option);257tty->print(" <unknown option type>");258tty->cr();259}260};261262template<>263void TypedMethodOptionMatcher<intx>::print() {264ttyLocker ttyl;265print_base();266tty->print(" intx %s", _option);267tty->print(" = " INTX_FORMAT, _value);268tty->cr();269};270271template<>272void TypedMethodOptionMatcher<uintx>::print() {273ttyLocker ttyl;274print_base();275tty->print(" uintx %s", _option);276tty->print(" = " UINTX_FORMAT, _value);277tty->cr();278};279280template<>281void TypedMethodOptionMatcher<bool>::print() {282ttyLocker ttyl;283print_base();284tty->print(" bool %s", _option);285tty->print(" = %s", _value ? "true" : "false");286tty->cr();287};288289template<>290void TypedMethodOptionMatcher<ccstr>::print() {291ttyLocker ttyl;292print_base();293tty->print(" const char* %s", _option);294tty->print(" = '%s'", _value);295tty->cr();296};297298// this must parallel the command_names below299enum OracleCommand {300UnknownCommand = -1,301OracleFirstCommand = 0,302BreakCommand = OracleFirstCommand,303PrintCommand,304ExcludeCommand,305InlineCommand,306DontInlineCommand,307CompileOnlyCommand,308LogCommand,309OptionCommand,310QuietCommand,311HelpCommand,312OracleCommandCount313};314315// this must parallel the enum OracleCommand316static const char * command_names[] = {317"break",318"print",319"exclude",320"inline",321"dontinline",322"compileonly",323"log",324"option",325"quiet",326"help"327};328329class MethodMatcher;330static MethodMatcher* lists[OracleCommandCount] = { 0, };331332333static bool check_predicate(OracleCommand command, methodHandle method) {334return ((lists[command] != NULL) &&335!method.is_null() &&336lists[command]->match(method));337}338339340static MethodMatcher* add_predicate(OracleCommand command,341Symbol* class_name, MethodMatcher::Mode c_mode,342Symbol* method_name, MethodMatcher::Mode m_mode,343Symbol* signature) {344assert(command != OptionCommand, "must use add_option_string");345if (command == LogCommand && !LogCompilation && lists[LogCommand] == NULL)346tty->print_cr("Warning: +LogCompilation must be enabled in order for individual methods to be logged.");347lists[command] = new MethodMatcher(class_name, c_mode, method_name, m_mode, signature, lists[command]);348return lists[command];349}350351template<typename T>352static MethodMatcher* add_option_string(Symbol* class_name, MethodMatcher::Mode c_mode,353Symbol* method_name, MethodMatcher::Mode m_mode,354Symbol* signature,355const char* option,356T value) {357lists[OptionCommand] = new TypedMethodOptionMatcher<T>(class_name, c_mode, method_name, m_mode,358signature, option, value, lists[OptionCommand]);359return lists[OptionCommand];360}361362template<typename T>363static bool get_option_value(methodHandle method, const char* option, T& value) {364TypedMethodOptionMatcher<T>* m;365if (lists[OptionCommand] != NULL366&& (m = ((TypedMethodOptionMatcher<T>*)lists[OptionCommand])->match(method, option)) != NULL367&& m->get_type() == get_type_for<T>()) {368value = m->value();369return true;370} else {371return false;372}373}374375bool CompilerOracle::has_option_string(methodHandle method, const char* option) {376bool value = false;377get_option_value(method, option, value);378return value;379}380381template<typename T>382bool CompilerOracle::has_option_value(methodHandle method, const char* option, T& value) {383return ::get_option_value(method, option, value);384}385386// Explicit instantiation for all OptionTypes supported.387template bool CompilerOracle::has_option_value<intx>(methodHandle method, const char* option, intx& value);388template bool CompilerOracle::has_option_value<uintx>(methodHandle method, const char* option, uintx& value);389template bool CompilerOracle::has_option_value<bool>(methodHandle method, const char* option, bool& value);390template bool CompilerOracle::has_option_value<ccstr>(methodHandle method, const char* option, ccstr& value);391392bool CompilerOracle::should_exclude(methodHandle method, bool& quietly) {393quietly = true;394if (lists[ExcludeCommand] != NULL) {395if (lists[ExcludeCommand]->match(method)) {396quietly = _quiet;397return true;398}399}400401if (lists[CompileOnlyCommand] != NULL) {402return !lists[CompileOnlyCommand]->match(method);403}404return false;405}406407408bool CompilerOracle::should_inline(methodHandle method) {409return (check_predicate(InlineCommand, method));410}411412413bool CompilerOracle::should_not_inline(methodHandle method) {414return (check_predicate(DontInlineCommand, method));415}416417418bool CompilerOracle::should_print(methodHandle method) {419return (check_predicate(PrintCommand, method));420}421422423bool CompilerOracle::should_log(methodHandle method) {424if (!LogCompilation) return false;425if (lists[LogCommand] == NULL) return true; // by default, log all426return (check_predicate(LogCommand, method));427}428429430bool CompilerOracle::should_break_at(methodHandle method) {431return check_predicate(BreakCommand, method);432}433434435static OracleCommand parse_command_name(const char * line, int* bytes_read) {436assert(ARRAY_SIZE(command_names) == OracleCommandCount,437"command_names size mismatch");438439*bytes_read = 0;440char command[33];441int result = sscanf(line, "%32[a-z]%n", command, bytes_read);442for (uint i = 0; i < ARRAY_SIZE(command_names); i++) {443if (strcmp(command, command_names[i]) == 0) {444return (OracleCommand)i;445}446}447return UnknownCommand;448}449450451static void usage() {452tty->print_cr(" CompileCommand and the CompilerOracle allows simple control over");453tty->print_cr(" what's allowed to be compiled. The standard supported directives");454tty->print_cr(" are exclude and compileonly. The exclude directive stops a method");455tty->print_cr(" from being compiled and compileonly excludes all methods except for");456tty->print_cr(" the ones mentioned by compileonly directives. The basic form of");457tty->print_cr(" all commands is a command name followed by the name of the method");458tty->print_cr(" in one of two forms: the standard class file format as in");459tty->print_cr(" class/name.methodName or the PrintCompilation format");460tty->print_cr(" class.name::methodName. The method name can optionally be followed");461tty->print_cr(" by a space then the signature of the method in the class file");462tty->print_cr(" format. Otherwise the directive applies to all methods with the");463tty->print_cr(" same name and class regardless of signature. Leading and trailing");464tty->print_cr(" *'s in the class and/or method name allows a small amount of");465tty->print_cr(" wildcarding. ");466tty->cr();467tty->print_cr(" Examples:");468tty->cr();469tty->print_cr(" exclude java/lang/StringBuffer.append");470tty->print_cr(" compileonly java/lang/StringBuffer.toString ()Ljava/lang/String;");471tty->print_cr(" exclude java/lang/String*.*");472tty->print_cr(" exclude *.toString");473}474475476// The characters allowed in a class or method name. All characters > 0x7f477// are allowed in order to handle obfuscated class files (e.g. Volano)478#define RANGEBASE "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789$_<>" \479"\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f" \480"\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f" \481"\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf" \482"\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf" \483"\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf" \484"\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf" \485"\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef" \486"\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff"487488#define RANGE0 "[*" RANGEBASE "]"489#define RANGESLASH "[*" RANGEBASE "/]"490491static MethodMatcher::Mode check_mode(char name[], const char*& error_msg) {492int match = MethodMatcher::Exact;493while (name[0] == '*') {494match |= MethodMatcher::Suffix;495strcpy(name, name + 1);496}497498if (strcmp(name, "*") == 0) return MethodMatcher::Any;499500size_t len = strlen(name);501while (len > 0 && name[len - 1] == '*') {502match |= MethodMatcher::Prefix;503name[--len] = '\0';504}505506if (strstr(name, "*") != NULL) {507error_msg = " Embedded * not allowed";508return MethodMatcher::Unknown;509}510return (MethodMatcher::Mode)match;511}512513static bool scan_line(const char * line,514char class_name[], MethodMatcher::Mode* c_mode,515char method_name[], MethodMatcher::Mode* m_mode,516int* bytes_read, const char*& error_msg) {517*bytes_read = 0;518error_msg = NULL;519if (2 == sscanf(line, "%*[ \t]%255" RANGESLASH "%*[ ]" "%255" RANGE0 "%n", class_name, method_name, bytes_read)) {520*c_mode = check_mode(class_name, error_msg);521*m_mode = check_mode(method_name, error_msg);522return *c_mode != MethodMatcher::Unknown && *m_mode != MethodMatcher::Unknown;523}524return false;525}526527528529// Scan next flag and value in line, return MethodMatcher object on success, NULL on failure.530// On failure, error_msg contains description for the first error.531// For future extensions: set error_msg on first error.532static MethodMatcher* scan_flag_and_value(const char* type, const char* line, int& total_bytes_read,533Symbol* c_name, MethodMatcher::Mode c_match,534Symbol* m_name, MethodMatcher::Mode m_match,535Symbol* signature,536char* errorbuf, const int buf_size) {537total_bytes_read = 0;538int bytes_read = 0;539char flag[256];540541// Read flag name.542if (sscanf(line, "%*[ \t]%255[a-zA-Z0-9]%n", flag, &bytes_read) == 1) {543line += bytes_read;544total_bytes_read += bytes_read;545546// Read value.547if (strcmp(type, "intx") == 0) {548intx value;549if (sscanf(line, "%*[ \t]" INTX_FORMAT "%n", &value, &bytes_read) == 1) {550total_bytes_read += bytes_read;551return add_option_string(c_name, c_match, m_name, m_match, signature, flag, value);552} else {553jio_snprintf(errorbuf, buf_size, " Value cannot be read for flag %s of type %s ", flag, type);554}555} else if (strcmp(type, "uintx") == 0) {556uintx value;557if (sscanf(line, "%*[ \t]" UINTX_FORMAT "%n", &value, &bytes_read) == 1) {558total_bytes_read += bytes_read;559return add_option_string(c_name, c_match, m_name, m_match, signature, flag, value);560} else {561jio_snprintf(errorbuf, buf_size, " Value cannot be read for flag %s of type %s", flag, type);562}563} else if (strcmp(type, "ccstr") == 0) {564ResourceMark rm;565char* value = NEW_RESOURCE_ARRAY(char, strlen(line) + 1);566if (sscanf(line, "%*[ \t]%255[_a-zA-Z0-9]%n", value, &bytes_read) == 1) {567total_bytes_read += bytes_read;568return add_option_string(c_name, c_match, m_name, m_match, signature, flag, (ccstr)value);569} else {570jio_snprintf(errorbuf, buf_size, " Value cannot be read for flag %s of type %s", flag, type);571}572} else if (strcmp(type, "ccstrlist") == 0) {573// Accumulates several strings into one. The internal type is ccstr.574ResourceMark rm;575char* value = NEW_RESOURCE_ARRAY(char, strlen(line) + 1);576char* next_value = value;577if (sscanf(line, "%*[ \t]%255[_a-zA-Z0-9]%n", next_value, &bytes_read) == 1) {578total_bytes_read += bytes_read;579line += bytes_read;580next_value += bytes_read;581char* end_value = next_value-1;582while (sscanf(line, "%*[ \t]%255[_a-zA-Z0-9]%n", next_value, &bytes_read) == 1) {583total_bytes_read += bytes_read;584line += bytes_read;585*end_value = ' '; // override '\0'586next_value += bytes_read;587end_value = next_value-1;588}589return add_option_string(c_name, c_match, m_name, m_match, signature, flag, (ccstr)value);590} else {591jio_snprintf(errorbuf, buf_size, " Value cannot be read for flag %s of type %s", flag, type);592}593} else if (strcmp(type, "bool") == 0) {594char value[256];595if (sscanf(line, "%*[ \t]%255[a-zA-Z]%n", value, &bytes_read) == 1) {596if (strcmp(value, "true") == 0) {597total_bytes_read += bytes_read;598return add_option_string(c_name, c_match, m_name, m_match, signature, flag, true);599} else if (strcmp(value, "false") == 0) {600total_bytes_read += bytes_read;601return add_option_string(c_name, c_match, m_name, m_match, signature, flag, false);602} else {603jio_snprintf(errorbuf, buf_size, " Value cannot be read for flag %s of type %s", flag, type);604}605} else {606jio_snprintf(errorbuf, sizeof(errorbuf), " Value cannot be read for flag %s of type %s", flag, type);607}608} else {609jio_snprintf(errorbuf, sizeof(errorbuf), " Type %s not supported ", type);610}611} else {612jio_snprintf(errorbuf, sizeof(errorbuf), " Flag name for type %s should be alphanumeric ", type);613}614return NULL;615}616617void CompilerOracle::parse_from_line(char* line) {618if (line[0] == '\0') return;619if (line[0] == '#') return;620621bool have_colon = (strstr(line, "::") != NULL);622for (char* lp = line; *lp != '\0'; lp++) {623// Allow '.' to separate the class name from the method name.624// This is the preferred spelling of methods:625// exclude java/lang/String.indexOf(I)I626// Allow ',' for spaces (eases command line quoting).627// exclude,java/lang/String.indexOf628// For backward compatibility, allow space as separator also.629// exclude java/lang/String indexOf630// exclude,java/lang/String,indexOf631// For easy cut-and-paste of method names, allow VM output format632// as produced by Method::print_short_name:633// exclude java.lang.String::indexOf634// For simple implementation convenience here, convert them all to space.635if (have_colon) {636if (*lp == '.') *lp = '/'; // dots build the package prefix637if (*lp == ':') *lp = ' ';638}639if (*lp == ',' || *lp == '.') *lp = ' ';640}641642char* original_line = line;643int bytes_read;644OracleCommand command = parse_command_name(line, &bytes_read);645line += bytes_read;646ResourceMark rm;647648if (command == UnknownCommand) {649ttyLocker ttyl;650tty->print_cr("CompilerOracle: unrecognized line");651tty->print_cr(" \"%s\"", original_line);652return;653}654655if (command == QuietCommand) {656_quiet = true;657return;658}659660if (command == HelpCommand) {661usage();662return;663}664665MethodMatcher::Mode c_match = MethodMatcher::Exact;666MethodMatcher::Mode m_match = MethodMatcher::Exact;667char class_name[256];668char method_name[256];669char sig[1024];670char errorbuf[1024];671const char* error_msg = NULL; // description of first error that appears672MethodMatcher* match = NULL;673674if (scan_line(line, class_name, &c_match, method_name, &m_match, &bytes_read, error_msg)) {675EXCEPTION_MARK;676Symbol* c_name = SymbolTable::new_symbol(class_name, CHECK);677Symbol* m_name = SymbolTable::new_symbol(method_name, CHECK);678Symbol* signature = NULL;679680line += bytes_read;681// there might be a signature following the method.682// signatures always begin with ( so match that by hand683if (1 == sscanf(line, "%*[ \t](%254[[);/" RANGEBASE "]%n", sig + 1, &bytes_read)) {684sig[0] = '(';685line += bytes_read;686signature = SymbolTable::new_symbol(sig, CHECK);687}688689if (command == OptionCommand) {690// Look for trailing options.691//692// Two types of trailing options are693// supported:694//695// (1) CompileCommand=option,Klass::method,flag696// (2) CompileCommand=option,Klass::method,type,flag,value697//698// Type (1) is used to support ciMethod::has_option("someflag")699// (i.e., to check if a flag "someflag" is enabled for a method).700//701// Type (2) is used to support options with a value. Values can have the702// the following types: intx, uintx, bool, ccstr, and ccstrlist.703//704// For future extensions: extend scan_flag_and_value()705char option[256]; // stores flag for Type (1) and type of Type (2)706while (sscanf(line, "%*[ \t]%255[a-zA-Z0-9]%n", option, &bytes_read) == 1) {707if (match != NULL && !_quiet) {708// Print out the last match added709ttyLocker ttyl;710tty->print("CompilerOracle: %s ", command_names[command]);711match->print();712}713line += bytes_read;714715if (strcmp(option, "intx") == 0716|| strcmp(option, "uintx") == 0717|| strcmp(option, "bool") == 0718|| strcmp(option, "ccstr") == 0719|| strcmp(option, "ccstrlist") == 0720) {721722// Type (2) option: parse flag name and value.723match = scan_flag_and_value(option, line, bytes_read,724c_name, c_match, m_name, m_match, signature,725errorbuf, sizeof(errorbuf));726if (match == NULL) {727error_msg = errorbuf;728break;729}730line += bytes_read;731} else {732// Type (1) option733match = add_option_string(c_name, c_match, m_name, m_match, signature, option, true);734}735} // while(736} else {737match = add_predicate(command, c_name, c_match, m_name, m_match, signature);738}739}740741ttyLocker ttyl;742if (error_msg != NULL) {743// an error has happened744tty->print_cr("CompilerOracle: unrecognized line");745tty->print_cr(" \"%s\"", original_line);746if (error_msg != NULL) {747tty->print_cr("%s", error_msg);748}749} else {750// check for remaining characters751bytes_read = 0;752sscanf(line, "%*[ \t]%n", &bytes_read);753if (line[bytes_read] != '\0') {754tty->print_cr("CompilerOracle: unrecognized line");755tty->print_cr(" \"%s\"", original_line);756tty->print_cr(" Unrecognized text %s after command ", line);757} else if (match != NULL && !_quiet) {758tty->print("CompilerOracle: %s ", command_names[command]);759match->print();760}761}762}763764static const char* default_cc_file = ".hotspot_compiler";765766static const char* cc_file() {767#ifdef ASSERT768if (CompileCommandFile == NULL)769return default_cc_file;770#endif771return CompileCommandFile;772}773774bool CompilerOracle::has_command_file() {775return cc_file() != NULL;776}777778bool CompilerOracle::_quiet = false;779780void CompilerOracle::parse_from_file() {781assert(has_command_file(), "command file must be specified");782FILE* stream = fopen(cc_file(), "rt");783if (stream == NULL) return;784785char token[1024];786int pos = 0;787int c = getc(stream);788while(c != EOF && pos < (int)(sizeof(token)-1)) {789if (c == '\n') {790token[pos++] = '\0';791parse_from_line(token);792pos = 0;793} else {794token[pos++] = c;795}796c = getc(stream);797}798token[pos++] = '\0';799parse_from_line(token);800801fclose(stream);802}803804void CompilerOracle::parse_from_string(const char* str, void (*parse_line)(char*)) {805char token[1024];806int pos = 0;807const char* sp = str;808int c = *sp++;809while (c != '\0' && pos < (int)(sizeof(token)-1)) {810if (c == '\n') {811token[pos++] = '\0';812parse_line(token);813pos = 0;814} else {815token[pos++] = c;816}817c = *sp++;818}819token[pos++] = '\0';820parse_line(token);821}822823void CompilerOracle::append_comment_to_file(const char* message) {824assert(has_command_file(), "command file must be specified");825fileStream stream(fopen(cc_file(), "at"));826stream.print("# ");827for (int index = 0; message[index] != '\0'; index++) {828stream.put(message[index]);829if (message[index] == '\n') stream.print("# ");830}831stream.cr();832}833834void CompilerOracle::append_exclude_to_file(methodHandle method) {835assert(has_command_file(), "command file must be specified");836fileStream stream(fopen(cc_file(), "at"));837stream.print("exclude ");838method->method_holder()->name()->print_symbol_on(&stream);839stream.print(".");840method->name()->print_symbol_on(&stream);841method->signature()->print_symbol_on(&stream);842stream.cr();843stream.cr();844}845846847void compilerOracle_init() {848CompilerOracle::parse_from_string(CompileCommand, CompilerOracle::parse_from_line);849CompilerOracle::parse_from_string(CompileOnly, CompilerOracle::parse_compile_only);850if (CompilerOracle::has_command_file()) {851CompilerOracle::parse_from_file();852} else {853struct stat buf;854if (os::stat(default_cc_file, &buf) == 0) {855warning("%s file is present but has been ignored. "856"Run with -XX:CompileCommandFile=%s to load the file.",857default_cc_file, default_cc_file);858}859}860if (lists[PrintCommand] != NULL) {861if (PrintAssembly) {862warning("CompileCommand and/or %s file contains 'print' commands, but PrintAssembly is also enabled", default_cc_file);863} else if (FLAG_IS_DEFAULT(DebugNonSafepoints)) {864warning("printing of assembly code is enabled; turning on DebugNonSafepoints to gain additional output");865DebugNonSafepoints = true;866}867}868}869870871void CompilerOracle::parse_compile_only(char * line) {872int i;873char name[1024];874const char* className = NULL;875const char* methodName = NULL;876877bool have_colon = (strstr(line, "::") != NULL);878char method_sep = have_colon ? ':' : '.';879880if (Verbose) {881tty->print_cr("%s", line);882}883884ResourceMark rm;885while (*line != '\0') {886MethodMatcher::Mode c_match = MethodMatcher::Exact;887MethodMatcher::Mode m_match = MethodMatcher::Exact;888889for (i = 0;890i < 1024 && *line != '\0' && *line != method_sep && *line != ',' && !isspace(*line);891line++, i++) {892name[i] = *line;893if (name[i] == '.') name[i] = '/'; // package prefix uses '/'894}895896if (i > 0) {897char* newName = NEW_RESOURCE_ARRAY( char, i + 1);898if (newName == NULL)899return;900strncpy(newName, name, i);901newName[i] = '\0';902903if (className == NULL) {904className = newName;905c_match = MethodMatcher::Prefix;906} else {907methodName = newName;908}909}910911if (*line == method_sep) {912if (className == NULL) {913className = "";914c_match = MethodMatcher::Any;915} else {916// foo/bar.blah is an exact match on foo/bar, bar.blah is a suffix match on bar917if (strchr(className, '/') != NULL) {918c_match = MethodMatcher::Exact;919} else {920c_match = MethodMatcher::Suffix;921}922}923} else {924// got foo or foo/bar925if (className == NULL) {926ShouldNotReachHere();927} else {928// got foo or foo/bar929if (strchr(className, '/') != NULL) {930c_match = MethodMatcher::Prefix;931} else if (className[0] == '\0') {932c_match = MethodMatcher::Any;933} else {934c_match = MethodMatcher::Substring;935}936}937}938939// each directive is terminated by , or NUL or . followed by NUL940if (*line == ',' || *line == '\0' || (line[0] == '.' && line[1] == '\0')) {941if (methodName == NULL) {942methodName = "";943if (*line != method_sep) {944m_match = MethodMatcher::Any;945}946}947948EXCEPTION_MARK;949Symbol* c_name = SymbolTable::new_symbol(className, CHECK);950Symbol* m_name = SymbolTable::new_symbol(methodName, CHECK);951Symbol* signature = NULL;952953add_predicate(CompileOnlyCommand, c_name, c_match, m_name, m_match, signature);954if (PrintVMOptions) {955tty->print("CompileOnly: compileonly ");956lists[CompileOnlyCommand]->print();957}958959className = NULL;960methodName = NULL;961}962963line = *line == '\0' ? line : line + 1;964}965}966967968