2007-12-01 00:00:00 +00:00
|
|
|
/*
|
2020-09-17 21:32:22 +00:00
|
|
|
* Copyright (c) 1998, 2020, Oracle and/or its affiliates. All rights reserved.
|
2007-12-01 00:00:00 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
*
|
|
|
|
* This code is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 only, as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* version 2 for more details (a copy is included in the LICENSE file that
|
|
|
|
* accompanied this code).
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License version
|
|
|
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
2010-05-27 19:08:38 -07:00
|
|
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
|
|
* or visit www.oracle.com if you need additional information or have any
|
|
|
|
* questions.
|
2007-12-01 00:00:00 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "precompiled.hpp"
|
2017-10-31 11:55:09 -04:00
|
|
|
#include "jvm.h"
|
2019-05-09 14:28:30 +02:00
|
|
|
#include "classfile/symbolTable.hpp"
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "compiler/compilerOracle.hpp"
|
2015-09-18 10:11:11 +02:00
|
|
|
#include "compiler/methodMatcher.hpp"
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "memory/allocation.inline.hpp"
|
|
|
|
#include "memory/oopFactory.hpp"
|
|
|
|
#include "memory/resourceArea.hpp"
|
|
|
|
#include "oops/klass.hpp"
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
#include "oops/method.hpp"
|
2011-01-27 16:11:27 -08:00
|
|
|
#include "oops/symbol.hpp"
|
2020-09-17 21:32:22 +00:00
|
|
|
#include "runtime/globals_extension.hpp"
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "runtime/handles.inline.hpp"
|
|
|
|
#include "runtime/jniHandles.hpp"
|
2014-08-11 10:18:09 -07:00
|
|
|
#include "runtime/os.hpp"
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2020-11-25 14:20:35 +00:00
|
|
|
static const char* optiontype_names[] = {
|
|
|
|
#define enum_of_types(type, name) name,
|
|
|
|
OPTION_TYPES(enum_of_types)
|
|
|
|
#undef enum_of_types
|
2014-08-29 15:32:16 +02:00
|
|
|
};
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2020-11-25 14:20:35 +00:00
|
|
|
const char* optiontype2name(enum OptionType type) {
|
|
|
|
return optiontype_names[static_cast<int>(type)];
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum OptionType option_types[] = {
|
|
|
|
#define enum_of_options(option, name, ctype) OptionType::ctype,
|
|
|
|
COMPILECOMMAND_OPTIONS(enum_of_options)
|
|
|
|
#undef enum_of_options
|
|
|
|
};
|
|
|
|
|
|
|
|
enum OptionType option2type(enum CompileCommand option) {
|
|
|
|
return option_types[static_cast<int>(option)];
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char* option_names[] = {
|
|
|
|
#define enum_of_options(option, name, ctype) name,
|
|
|
|
COMPILECOMMAND_OPTIONS(enum_of_options)
|
|
|
|
#undef enum_of_options
|
|
|
|
};
|
|
|
|
|
|
|
|
const char* option2name(enum CompileCommand option) {
|
|
|
|
return option_names[static_cast<int>(option)];
|
|
|
|
}
|
|
|
|
|
2014-08-29 15:32:16 +02:00
|
|
|
/* Methods to map real type names to OptionType */
|
|
|
|
template<typename T>
|
|
|
|
static OptionType get_type_for() {
|
2020-11-25 14:20:35 +00:00
|
|
|
return OptionType::Unknown;
|
2014-08-29 15:32:16 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
template<> OptionType get_type_for<intx>() {
|
2020-11-25 14:20:35 +00:00
|
|
|
return OptionType::Intx;
|
2014-08-29 15:32:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template<> OptionType get_type_for<uintx>() {
|
2020-11-25 14:20:35 +00:00
|
|
|
return OptionType::Uintx;
|
2014-08-29 15:32:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template<> OptionType get_type_for<bool>() {
|
2020-11-25 14:20:35 +00:00
|
|
|
return OptionType::Bool;
|
2014-08-29 15:32:16 +02:00
|
|
|
}
|
|
|
|
|
2014-09-02 10:26:48 -07:00
|
|
|
template<> OptionType get_type_for<ccstr>() {
|
2020-11-25 14:20:35 +00:00
|
|
|
return OptionType::Ccstr;
|
2014-09-02 10:26:48 -07:00
|
|
|
}
|
|
|
|
|
2014-10-10 14:48:30 +02:00
|
|
|
template<> OptionType get_type_for<double>() {
|
2020-11-25 14:20:35 +00:00
|
|
|
return OptionType::Double;
|
|
|
|
}
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
class MethodMatcher;
|
2015-09-18 10:11:11 +02:00
|
|
|
class TypedMethodOptionMatcher;
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2015-09-18 10:11:11 +02:00
|
|
|
static TypedMethodOptionMatcher* option_list = NULL;
|
2015-10-20 18:07:28 +02:00
|
|
|
static bool any_set = false;
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2015-09-18 10:11:11 +02:00
|
|
|
class TypedMethodOptionMatcher : public MethodMatcher {
|
|
|
|
private:
|
|
|
|
TypedMethodOptionMatcher* _next;
|
2020-11-25 14:20:35 +00:00
|
|
|
enum CompileCommand _option;
|
2015-09-18 10:11:11 +02:00
|
|
|
public:
|
|
|
|
|
|
|
|
union {
|
|
|
|
bool bool_value;
|
|
|
|
intx intx_value;
|
|
|
|
uintx uintx_value;
|
|
|
|
double double_value;
|
|
|
|
ccstr ccstr_value;
|
|
|
|
} _u;
|
|
|
|
|
|
|
|
TypedMethodOptionMatcher() : MethodMatcher(),
|
|
|
|
_next(NULL),
|
2020-12-01 21:08:45 +00:00
|
|
|
_option(CompileCommand::Unknown) {
|
2015-09-18 10:11:11 +02:00
|
|
|
memset(&_u, 0, sizeof(_u));
|
|
|
|
}
|
|
|
|
|
2020-11-25 14:20:35 +00:00
|
|
|
~TypedMethodOptionMatcher();
|
|
|
|
static TypedMethodOptionMatcher* parse_method_pattern(char*& line, char* errorbuf, const int buf_size);
|
2020-12-01 21:08:45 +00:00
|
|
|
TypedMethodOptionMatcher* match(const methodHandle &method, enum CompileCommand option);
|
2015-09-18 10:11:11 +02:00
|
|
|
|
2020-12-01 21:08:45 +00:00
|
|
|
void init(enum CompileCommand option, TypedMethodOptionMatcher* next) {
|
2015-09-18 10:11:11 +02:00
|
|
|
_next = next;
|
2020-11-25 14:20:35 +00:00
|
|
|
_option = option;
|
|
|
|
}
|
|
|
|
|
|
|
|
void init_matcher(Symbol* class_name, Mode class_mode,
|
|
|
|
Symbol* method_name, Mode method_mode,
|
|
|
|
Symbol* signature) {
|
|
|
|
MethodMatcher::init(class_name, class_mode, method_name, method_mode, signature);
|
2015-09-18 10:11:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void set_next(TypedMethodOptionMatcher* next) {_next = next; }
|
|
|
|
TypedMethodOptionMatcher* next() { return _next; }
|
2020-11-25 14:20:35 +00:00
|
|
|
enum CompileCommand option() { return _option; }
|
2015-09-18 10:11:11 +02:00
|
|
|
template<typename T> T value();
|
|
|
|
template<typename T> void set_value(T value);
|
|
|
|
void print();
|
|
|
|
void print_all();
|
|
|
|
TypedMethodOptionMatcher* clone();
|
|
|
|
};
|
|
|
|
|
|
|
|
// A few templated accessors instead of a full template class.
|
|
|
|
template<> intx TypedMethodOptionMatcher::value<intx>() {
|
|
|
|
return _u.intx_value;
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2015-09-18 10:11:11 +02:00
|
|
|
template<> uintx TypedMethodOptionMatcher::value<uintx>() {
|
|
|
|
return _u.uintx_value;
|
|
|
|
}
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2015-09-18 10:11:11 +02:00
|
|
|
template<> bool TypedMethodOptionMatcher::value<bool>() {
|
|
|
|
return _u.bool_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<> double TypedMethodOptionMatcher::value<double>() {
|
|
|
|
return _u.double_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<> ccstr TypedMethodOptionMatcher::value<ccstr>() {
|
|
|
|
return _u.ccstr_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<> void TypedMethodOptionMatcher::set_value(intx value) {
|
|
|
|
_u.intx_value = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<> void TypedMethodOptionMatcher::set_value(uintx value) {
|
|
|
|
_u.uintx_value = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<> void TypedMethodOptionMatcher::set_value(double value) {
|
|
|
|
_u.double_value = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<> void TypedMethodOptionMatcher::set_value(bool value) {
|
|
|
|
_u.bool_value = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<> void TypedMethodOptionMatcher::set_value(ccstr value) {
|
|
|
|
_u.ccstr_value = (const ccstr)os::strdup_check_oom(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TypedMethodOptionMatcher::print() {
|
|
|
|
ttyLocker ttyl;
|
|
|
|
print_base(tty);
|
2020-11-25 14:20:35 +00:00
|
|
|
const char* name = option2name(_option);
|
2020-12-01 21:08:45 +00:00
|
|
|
enum OptionType type = option2type(_option);
|
|
|
|
switch (type) {
|
|
|
|
case OptionType::Intx:
|
2020-11-25 14:20:35 +00:00
|
|
|
tty->print_cr(" intx %s = " INTX_FORMAT, name, value<intx>());
|
2015-09-18 10:11:11 +02:00
|
|
|
break;
|
2020-11-25 14:20:35 +00:00
|
|
|
case OptionType::Uintx:
|
|
|
|
tty->print_cr(" uintx %s = " UINTX_FORMAT, name, value<uintx>());
|
2015-09-18 10:11:11 +02:00
|
|
|
break;
|
2020-11-25 14:20:35 +00:00
|
|
|
case OptionType::Bool:
|
|
|
|
tty->print_cr(" bool %s = %s", name, value<bool>() ? "true" : "false");
|
2015-09-18 10:11:11 +02:00
|
|
|
break;
|
2020-11-25 14:20:35 +00:00
|
|
|
case OptionType::Double:
|
|
|
|
tty->print_cr(" double %s = %f", name, value<double>());
|
2015-09-18 10:11:11 +02:00
|
|
|
break;
|
2020-11-25 14:20:35 +00:00
|
|
|
case OptionType::Ccstr:
|
2020-12-01 21:08:45 +00:00
|
|
|
case OptionType::Ccstrlist:
|
2020-11-25 14:20:35 +00:00
|
|
|
tty->print_cr(" const char* %s = '%s'", name, value<ccstr>());
|
2015-09-18 10:11:11 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ShouldNotReachHere();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TypedMethodOptionMatcher::print_all() {
|
|
|
|
print();
|
|
|
|
if (_next != NULL) {
|
|
|
|
tty->print(" ");
|
|
|
|
_next->print_all();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TypedMethodOptionMatcher* TypedMethodOptionMatcher::clone() {
|
|
|
|
TypedMethodOptionMatcher* m = new TypedMethodOptionMatcher();
|
|
|
|
m->_class_mode = _class_mode;
|
|
|
|
m->_class_name = _class_name;
|
|
|
|
m->_method_mode = _method_mode;
|
|
|
|
m->_method_name = _method_name;
|
|
|
|
m->_signature = _signature;
|
|
|
|
// Need to ref count the symbols
|
|
|
|
if (_class_name != NULL) {
|
|
|
|
_class_name->increment_refcount();
|
|
|
|
}
|
|
|
|
if (_method_name != NULL) {
|
|
|
|
_method_name->increment_refcount();
|
|
|
|
}
|
|
|
|
if (_signature != NULL) {
|
|
|
|
_signature->increment_refcount();
|
|
|
|
}
|
|
|
|
return m;
|
|
|
|
}
|
|
|
|
|
|
|
|
TypedMethodOptionMatcher::~TypedMethodOptionMatcher() {
|
2020-12-01 21:08:45 +00:00
|
|
|
enum OptionType type = option2type(_option);
|
|
|
|
if (type == OptionType::Ccstr || type == OptionType::Ccstrlist) {
|
2020-11-23 13:44:43 +00:00
|
|
|
ccstr v = value<ccstr>();
|
|
|
|
os::free((void*)v);
|
|
|
|
}
|
2015-09-18 10:11:11 +02:00
|
|
|
}
|
|
|
|
|
2020-11-25 14:20:35 +00:00
|
|
|
TypedMethodOptionMatcher* TypedMethodOptionMatcher::parse_method_pattern(char*& line, char* errorbuf, const int buf_size) {
|
|
|
|
assert(*errorbuf == '\0', "Dont call here with error_msg already set");
|
|
|
|
const char* error_msg = NULL;
|
2015-09-18 10:11:11 +02:00
|
|
|
TypedMethodOptionMatcher* tom = new TypedMethodOptionMatcher();
|
|
|
|
MethodMatcher::parse_method_pattern(line, error_msg, tom);
|
|
|
|
if (error_msg != NULL) {
|
2020-11-25 14:20:35 +00:00
|
|
|
jio_snprintf(errorbuf, buf_size, error_msg);
|
2015-09-18 10:11:11 +02:00
|
|
|
delete tom;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return tom;
|
|
|
|
}
|
|
|
|
|
2020-12-01 21:08:45 +00:00
|
|
|
TypedMethodOptionMatcher* TypedMethodOptionMatcher::match(const methodHandle& method, enum CompileCommand option) {
|
2015-09-18 10:11:11 +02:00
|
|
|
TypedMethodOptionMatcher* current = this;
|
|
|
|
while (current != NULL) {
|
2020-11-25 14:20:35 +00:00
|
|
|
if (current->_option == option) {
|
|
|
|
if (current->matches(method)) {
|
|
|
|
return current;
|
2015-09-18 10:11:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
current = current->next();
|
|
|
|
}
|
|
|
|
return NULL;
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2014-08-29 15:32:16 +02:00
|
|
|
template<typename T>
|
2020-11-25 14:20:35 +00:00
|
|
|
static void register_command(TypedMethodOptionMatcher* matcher,
|
|
|
|
enum CompileCommand option,
|
|
|
|
T value) {
|
2015-09-18 10:11:11 +02:00
|
|
|
assert(matcher != option_list, "No circular lists please");
|
2020-11-25 14:20:35 +00:00
|
|
|
if (option == CompileCommand::Log && !LogCompilation) {
|
|
|
|
tty->print_cr("Warning: +LogCompilation must be enabled in order for individual methods to be logged with ");
|
|
|
|
tty->print_cr(" CompileCommand=log,<method pattern>");
|
|
|
|
}
|
2020-12-01 21:08:45 +00:00
|
|
|
assert(CompilerOracle::option_matches_type(option, value), "Value must match option type");
|
|
|
|
|
|
|
|
matcher->init(option, option_list);
|
2015-09-18 10:11:11 +02:00
|
|
|
matcher->set_value<T>(value);
|
|
|
|
option_list = matcher;
|
2020-11-25 14:20:35 +00:00
|
|
|
if ((option != CompileCommand::DontInline) &&
|
|
|
|
(option != CompileCommand::Inline) &&
|
|
|
|
(option != CompileCommand::Log)) {
|
2015-10-20 18:07:28 +02:00
|
|
|
any_set = true;
|
|
|
|
}
|
2020-11-25 14:20:35 +00:00
|
|
|
if (!CompilerOracle::be_quiet()) {
|
|
|
|
// Print out the succesful registration of a comile command
|
|
|
|
ttyLocker ttyl;
|
|
|
|
tty->print("CompileCommand: %s ", option2name(option));
|
|
|
|
matcher->print();
|
|
|
|
}
|
2015-09-18 10:11:11 +02:00
|
|
|
return;
|
2014-08-29 15:32:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
2020-12-01 21:08:45 +00:00
|
|
|
bool CompilerOracle::has_option_value(const methodHandle& method, enum CompileCommand option, T& value) {
|
|
|
|
assert(option_matches_type(option, value), "Value must match option type");
|
2015-09-18 10:11:11 +02:00
|
|
|
if (option_list != NULL) {
|
2020-12-01 21:08:45 +00:00
|
|
|
TypedMethodOptionMatcher* m = option_list->match(method, option);
|
2015-09-18 10:11:11 +02:00
|
|
|
if (m != NULL) {
|
|
|
|
value = m->value<T>();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2020-11-25 14:20:35 +00:00
|
|
|
static bool check_predicate(enum CompileCommand option, const methodHandle& method) {
|
|
|
|
bool value = false;
|
|
|
|
if (CompilerOracle::has_option_value(method, option, value)) {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool has_command(enum CompileCommand option) {
|
|
|
|
TypedMethodOptionMatcher* m = option_list;
|
|
|
|
while (m != NULL) {
|
|
|
|
if (m->option() == option) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
m = m->next();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CompilerOracle::has_any_command_set() {
|
2015-10-20 18:07:28 +02:00
|
|
|
return any_set;
|
|
|
|
}
|
|
|
|
|
2014-08-29 15:32:16 +02:00
|
|
|
// Explicit instantiation for all OptionTypes supported.
|
2020-12-01 21:08:45 +00:00
|
|
|
template bool CompilerOracle::has_option_value<intx>(const methodHandle& method, enum CompileCommand option, intx& value);
|
|
|
|
template bool CompilerOracle::has_option_value<uintx>(const methodHandle& method, enum CompileCommand option, uintx& value);
|
|
|
|
template bool CompilerOracle::has_option_value<bool>(const methodHandle& method, enum CompileCommand option, bool& value);
|
|
|
|
template bool CompilerOracle::has_option_value<ccstr>(const methodHandle& method, enum CompileCommand option, ccstr& value);
|
|
|
|
template bool CompilerOracle::has_option_value<double>(const methodHandle& method, enum CompileCommand option, double& value);
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
bool CompilerOracle::option_matches_type(enum CompileCommand option, T& value) {
|
|
|
|
enum OptionType option_type = option2type(option);
|
|
|
|
if (option_type == OptionType::Unknown) {
|
|
|
|
return false; // Can't query options with type Unknown.
|
|
|
|
}
|
|
|
|
if (option_type == OptionType::Ccstrlist) {
|
|
|
|
option_type = OptionType::Ccstr; // CCstrList type options are stored as Ccstr
|
|
|
|
}
|
|
|
|
return (get_type_for<T>() == option_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
template bool CompilerOracle::option_matches_type<intx>(enum CompileCommand option, intx& value);
|
|
|
|
template bool CompilerOracle::option_matches_type<uintx>(enum CompileCommand option, uintx& value);
|
|
|
|
template bool CompilerOracle::option_matches_type<bool>(enum CompileCommand option, bool& value);
|
|
|
|
template bool CompilerOracle::option_matches_type<ccstr>(enum CompileCommand option, ccstr& value);
|
|
|
|
template bool CompilerOracle::option_matches_type<double>(enum CompileCommand option, double& value);
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2020-11-25 14:20:35 +00:00
|
|
|
bool CompilerOracle::has_option(const methodHandle& method, enum CompileCommand option) {
|
2015-09-18 10:11:11 +02:00
|
|
|
bool value = false;
|
|
|
|
has_option_value(method, option, value);
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2015-11-05 19:31:57 +01:00
|
|
|
bool CompilerOracle::should_exclude(const methodHandle& method) {
|
2020-11-25 14:20:35 +00:00
|
|
|
if (check_predicate(CompileCommand::Exclude, method)) {
|
2015-10-20 18:07:28 +02:00
|
|
|
return true;
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
2020-11-25 14:20:35 +00:00
|
|
|
if (has_command(CompileCommand::CompileOnly)) {
|
|
|
|
return !check_predicate(CompileCommand::CompileOnly, method);
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-10-23 16:48:38 -04:00
|
|
|
bool CompilerOracle::should_inline(const methodHandle& method) {
|
2020-11-25 14:20:35 +00:00
|
|
|
return (check_predicate(CompileCommand::Inline, method));
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2015-10-23 16:48:38 -04:00
|
|
|
bool CompilerOracle::should_not_inline(const methodHandle& method) {
|
2020-11-25 14:20:35 +00:00
|
|
|
return check_predicate(CompileCommand::DontInline, method) || check_predicate(CompileCommand::Exclude, method);
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2015-10-23 16:48:38 -04:00
|
|
|
bool CompilerOracle::should_print(const methodHandle& method) {
|
2020-11-25 14:20:35 +00:00
|
|
|
return check_predicate(CompileCommand::Print, method);
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2014-05-21 14:36:18 -04:00
|
|
|
bool CompilerOracle::should_print_methods() {
|
2020-11-25 14:20:35 +00:00
|
|
|
return has_command(CompileCommand::Print);
|
2014-05-21 14:36:18 -04:00
|
|
|
}
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2015-10-23 16:48:38 -04:00
|
|
|
bool CompilerOracle::should_log(const methodHandle& method) {
|
2020-11-25 14:20:35 +00:00
|
|
|
if (!LogCompilation) return false;
|
|
|
|
if (!has_command(CompileCommand::Log)) {
|
|
|
|
return true; // by default, log all
|
|
|
|
}
|
|
|
|
return (check_predicate(CompileCommand::Log, method));
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2015-10-23 16:48:38 -04:00
|
|
|
bool CompilerOracle::should_break_at(const methodHandle& method) {
|
2020-11-25 14:20:35 +00:00
|
|
|
return check_predicate(CompileCommand::Break, method);
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2020-11-25 14:20:35 +00:00
|
|
|
static enum CompileCommand parse_option_name(const char* line, int* bytes_read, char* errorbuf, int bufsize) {
|
|
|
|
assert(ARRAY_SIZE(option_names) == static_cast<int>(CompileCommand::Count), "option_names size mismatch");
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
*bytes_read = 0;
|
2020-11-25 14:20:35 +00:00
|
|
|
char option_buf[256];
|
|
|
|
int matches = sscanf(line, "%255[a-zA-Z0-9]%n", option_buf, bytes_read);
|
2019-12-11 09:42:52 +01:00
|
|
|
if (matches > 0) {
|
2020-11-25 14:20:35 +00:00
|
|
|
for (uint i = 0; i < ARRAY_SIZE(option_names); i++) {
|
|
|
|
if (strcasecmp(option_buf, option_names[i]) == 0) {
|
|
|
|
return static_cast<enum CompileCommand>(i);
|
2019-12-11 09:42:52 +01:00
|
|
|
}
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|
2020-11-25 14:20:35 +00:00
|
|
|
jio_snprintf(errorbuf, bufsize, "Unrecognized option '%s'", option_buf);
|
|
|
|
return CompileCommand::Unknown;
|
|
|
|
}
|
|
|
|
|
|
|
|
void print_tip() { // CMH Update info
|
|
|
|
tty->cr();
|
|
|
|
tty->print_cr("Usage: '-XX:CompileCommand=<option>,<method pattern>' - to set boolean option to true");
|
|
|
|
tty->print_cr("Usage: '-XX:CompileCommand=<option>,<method pattern>,<value>'");
|
|
|
|
tty->print_cr("Use: '-XX:CompileCommand=help' for more information and to list all option.");
|
|
|
|
tty->cr();
|
|
|
|
}
|
|
|
|
|
|
|
|
void print_option(enum CompileCommand option, const char* name, enum OptionType type) {
|
|
|
|
if (type != OptionType::Unknown) {
|
|
|
|
tty->print_cr(" %s (%s)", name, optiontype2name(type));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void print_commands() {
|
|
|
|
tty->cr();
|
|
|
|
tty->print_cr("All available options:");
|
|
|
|
#define enum_of_options(option, name, ctype) print_option(CompileCommand::option, name, OptionType::ctype);
|
|
|
|
COMPILECOMMAND_OPTIONS(enum_of_options)
|
|
|
|
#undef enum_of_options
|
|
|
|
tty->cr();
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void usage() {
|
|
|
|
tty->cr();
|
2015-01-13 12:30:26 +01:00
|
|
|
tty->print_cr("The CompileCommand option enables the user of the JVM to control specific");
|
2020-11-25 14:20:35 +00:00
|
|
|
tty->print_cr("behavior of the dynamic compilers.");
|
2007-12-01 00:00:00 +00:00
|
|
|
tty->cr();
|
2020-11-25 14:20:35 +00:00
|
|
|
tty->print_cr("Compile commands has this general form:");
|
|
|
|
tty->print_cr("-XX:CompileCommand=<option><method pattern><value>");
|
|
|
|
tty->print_cr(" Sets <option> to the specified value for methods matching <method pattern>");
|
|
|
|
tty->print_cr(" All options are typed");
|
2015-01-13 12:30:26 +01:00
|
|
|
tty->cr();
|
2020-11-25 14:20:35 +00:00
|
|
|
tty->print_cr("-XX:CompileCommand=<option><method pattern>");
|
|
|
|
tty->print_cr(" Sets <option> to true for methods matching <method pattern>");
|
|
|
|
tty->print_cr(" Only applies to boolean options.");
|
|
|
|
tty->cr();
|
|
|
|
tty->print_cr("-XX:CompileCommand=quiet");
|
|
|
|
tty->print_cr(" Silence the compile command output");
|
|
|
|
tty->cr();
|
|
|
|
tty->print_cr("-XX:CompileCommand=help");
|
|
|
|
tty->print_cr(" Prints this help text");
|
|
|
|
tty->cr();
|
|
|
|
print_commands();
|
|
|
|
tty->cr();
|
|
|
|
tty->print_cr("Method patterns has the format:");
|
2015-01-13 12:30:26 +01:00
|
|
|
tty->print_cr(" package/Class.method()");
|
|
|
|
tty->cr();
|
|
|
|
tty->print_cr("For backward compatibility this form is also allowed:");
|
|
|
|
tty->print_cr(" package.Class::method()");
|
|
|
|
tty->cr();
|
|
|
|
tty->print_cr("The signature can be separated by an optional whitespace or comma:");
|
|
|
|
tty->print_cr(" package/Class.method ()");
|
|
|
|
tty->cr();
|
|
|
|
tty->print_cr("The class and method identifier can be used together with leading or");
|
2020-11-25 14:20:35 +00:00
|
|
|
tty->print_cr("trailing *'s for wildcard matching:");
|
2015-01-13 12:30:26 +01:00
|
|
|
tty->print_cr(" *ackage/Clas*.*etho*()");
|
|
|
|
tty->cr();
|
|
|
|
tty->print_cr("It is possible to use more than one CompileCommand on the command line:");
|
|
|
|
tty->print_cr(" -XX:CompileCommand=exclude,java/*.* -XX:CompileCommand=log,java*.*");
|
|
|
|
tty->cr();
|
|
|
|
tty->print_cr("The CompileCommands can be loaded from a file with the flag");
|
|
|
|
tty->print_cr("-XX:CompileCommandFile=<file> or be added to the file '.hotspot_compiler'");
|
|
|
|
tty->print_cr("Use the same format in the file as the argument to the CompileCommand flag.");
|
|
|
|
tty->print_cr("Add one command on each line.");
|
|
|
|
tty->print_cr(" exclude java/*.*");
|
|
|
|
tty->print_cr(" option java/*.* ReplayInline");
|
|
|
|
tty->cr();
|
|
|
|
tty->print_cr("The following commands have conflicting behavior: 'exclude', 'inline', 'dontinline',");
|
|
|
|
tty->print_cr("and 'compileonly'. There is no priority of commands. Applying (a subset of) these");
|
|
|
|
tty->print_cr("commands to the same method results in undefined behavior.");
|
|
|
|
tty->cr();
|
|
|
|
};
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2020-11-25 14:20:35 +00:00
|
|
|
int skip_whitespace(char* &line) {
|
|
|
|
// Skip any leading spaces
|
|
|
|
int whitespace_read = 0;
|
|
|
|
sscanf(line, "%*[ \t]%n", &whitespace_read);
|
|
|
|
line += whitespace_read;
|
|
|
|
return whitespace_read;
|
|
|
|
}
|
2014-08-29 15:32:16 +02:00
|
|
|
|
2020-11-25 14:20:35 +00:00
|
|
|
void skip_comma(char* &line) {
|
|
|
|
// Skip any leading spaces
|
|
|
|
if (*line == ',') {
|
|
|
|
line++;
|
|
|
|
}
|
|
|
|
}
|
2014-08-29 15:32:16 +02:00
|
|
|
|
2020-11-25 14:20:35 +00:00
|
|
|
static void scan_value(enum OptionType type, char* line, int& total_bytes_read,
|
|
|
|
TypedMethodOptionMatcher* matcher, enum CompileCommand option, char* errorbuf, const int buf_size) {
|
|
|
|
int bytes_read = 0;
|
|
|
|
const char* ccname = option2name(option);
|
|
|
|
const char* type_str = optiontype2name(type);
|
|
|
|
int skipped = skip_whitespace(line);
|
|
|
|
total_bytes_read += skipped;
|
|
|
|
if (type == OptionType::Intx) {
|
|
|
|
intx value;
|
|
|
|
if (sscanf(line, "" INTX_FORMAT "%n", &value, &bytes_read) == 1) {
|
|
|
|
total_bytes_read += bytes_read;
|
|
|
|
line += bytes_read;
|
|
|
|
register_command(matcher, option, value);
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
jio_snprintf(errorbuf, buf_size, "Value cannot be read for option '%s' of type '%s'", ccname, type_str);
|
|
|
|
}
|
|
|
|
} else if (type == OptionType::Uintx) {
|
|
|
|
uintx value;
|
|
|
|
if (sscanf(line, "" UINTX_FORMAT "%n", &value, &bytes_read) == 1) {
|
|
|
|
total_bytes_read += bytes_read;
|
|
|
|
line += bytes_read;
|
|
|
|
register_command(matcher, option, value);
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
jio_snprintf(errorbuf, buf_size, "Value cannot be read for option '%s' of type '%s'", ccname, type_str);
|
|
|
|
}
|
|
|
|
} else if (type == OptionType::Ccstr) {
|
|
|
|
ResourceMark rm;
|
|
|
|
char* value = NEW_RESOURCE_ARRAY(char, strlen(line) + 1);
|
|
|
|
if (sscanf(line, "%255[_a-zA-Z0-9]%n", value, &bytes_read) == 1) {
|
|
|
|
total_bytes_read += bytes_read;
|
|
|
|
line += bytes_read;
|
|
|
|
register_command(matcher, option, (ccstr) value);
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
jio_snprintf(errorbuf, buf_size, "Value cannot be read for option '%s' of type '%s'", ccname, type_str);
|
|
|
|
}
|
|
|
|
} else if (type == OptionType::Ccstrlist) {
|
|
|
|
// Accumulates several strings into one. The internal type is ccstr.
|
|
|
|
ResourceMark rm;
|
|
|
|
char* value = NEW_RESOURCE_ARRAY(char, strlen(line) + 1);
|
|
|
|
char* next_value = value;
|
|
|
|
if (sscanf(line, "%255[_a-zA-Z0-9+\\-]%n", next_value, &bytes_read) == 1) {
|
|
|
|
total_bytes_read += bytes_read;
|
|
|
|
line += bytes_read;
|
|
|
|
next_value += bytes_read + 1;
|
|
|
|
char* end_value = next_value - 1;
|
|
|
|
while (sscanf(line, "%*[ \t]%255[_a-zA-Z0-9+\\-]%n", next_value, &bytes_read) == 1) {
|
2014-09-02 10:26:48 -07:00
|
|
|
total_bytes_read += bytes_read;
|
2020-11-25 14:20:35 +00:00
|
|
|
line += bytes_read;
|
|
|
|
*end_value = ' '; // override '\0'
|
|
|
|
next_value += bytes_read;
|
|
|
|
end_value = next_value-1;
|
2014-09-02 10:26:48 -07:00
|
|
|
}
|
2020-11-25 14:20:35 +00:00
|
|
|
register_command(matcher, option, (ccstr) value);
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
jio_snprintf(errorbuf, buf_size, "Value cannot be read for option '%s' of type '%s'", ccname, type_str);
|
|
|
|
}
|
|
|
|
} else if (type == OptionType::Bool) {
|
|
|
|
char value[256];
|
|
|
|
if (*line == '\0') {
|
|
|
|
// Short version of a CompileCommand sets a boolean Option to true
|
|
|
|
// -XXCompileCommand=<Option>,<method pattern>
|
|
|
|
register_command(matcher, option, true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (sscanf(line, "%255[a-zA-Z]%n", value, &bytes_read) == 1) {
|
|
|
|
if (strcasecmp(value, "true") == 0) {
|
2014-09-02 10:26:48 -07:00
|
|
|
total_bytes_read += bytes_read;
|
|
|
|
line += bytes_read;
|
2020-11-25 14:20:35 +00:00
|
|
|
register_command(matcher, option, true);
|
2015-09-18 10:11:11 +02:00
|
|
|
return;
|
2020-11-25 14:20:35 +00:00
|
|
|
} else if (strcasecmp(value, "false") == 0) {
|
2014-10-10 14:48:30 +02:00
|
|
|
total_bytes_read += bytes_read;
|
2020-11-25 14:20:35 +00:00
|
|
|
line += bytes_read;
|
|
|
|
register_command(matcher, option, false);
|
2015-09-18 10:11:11 +02:00
|
|
|
return;
|
2014-10-10 14:48:30 +02:00
|
|
|
} else {
|
2020-11-25 14:20:35 +00:00
|
|
|
jio_snprintf(errorbuf, buf_size, "Value cannot be read for option '%s' of type '%s'", ccname, type_str);
|
2014-10-10 14:48:30 +02:00
|
|
|
}
|
2014-08-29 15:32:16 +02:00
|
|
|
} else {
|
2020-11-25 14:20:35 +00:00
|
|
|
jio_snprintf(errorbuf, buf_size, "Value cannot be read for option '%s' of type '%s'", ccname, type_str);
|
|
|
|
}
|
|
|
|
} else if (type == OptionType::Double) {
|
|
|
|
char buffer[2][256];
|
|
|
|
// Decimal separator '.' has been replaced with ' ' or '/' earlier,
|
|
|
|
// so read integer and fraction part of double value separately.
|
|
|
|
if (sscanf(line, "%255[0-9]%*[ /\t]%255[0-9]%n", buffer[0], buffer[1], &bytes_read) == 2) {
|
|
|
|
char value[512] = "";
|
|
|
|
jio_snprintf(value, sizeof(value), "%s.%s", buffer[0], buffer[1]);
|
|
|
|
total_bytes_read += bytes_read;
|
|
|
|
line += bytes_read;
|
|
|
|
register_command(matcher, option, atof(value));
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
jio_snprintf(errorbuf, buf_size, "Value cannot be read for option '%s' of type '%s'", ccname, type_str);
|
2014-08-29 15:32:16 +02:00
|
|
|
}
|
|
|
|
} else {
|
2020-11-25 14:20:35 +00:00
|
|
|
jio_snprintf(errorbuf, buf_size, "Type '%s' not supported ", type_str);
|
2014-08-29 15:32:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-25 14:20:35 +00:00
|
|
|
// Scan next option and value in line, return MethodMatcher object on success, NULL on failure.
|
|
|
|
// On failure, error_msg contains description for the first error.
|
|
|
|
// For future extensions: set error_msg on first error.
|
|
|
|
static void scan_option_and_value(enum OptionType type, char* line, int& total_bytes_read,
|
|
|
|
TypedMethodOptionMatcher* matcher,
|
|
|
|
char* errorbuf, const int buf_size) {
|
|
|
|
total_bytes_read = 0;
|
|
|
|
int bytes_read = 0;
|
|
|
|
char option_buf[256];
|
2015-01-22 11:23:13 +01:00
|
|
|
|
2020-11-25 14:20:35 +00:00
|
|
|
// Read option name.
|
|
|
|
if (sscanf(line, "%*[ \t]%255[a-zA-Z0-9]%n", option_buf, &bytes_read) == 1) {
|
|
|
|
line += bytes_read;
|
|
|
|
total_bytes_read += bytes_read;
|
|
|
|
int bytes_read2 = 0;
|
|
|
|
total_bytes_read += skip_whitespace(line);
|
|
|
|
enum CompileCommand option = parse_option_name(option_buf, &bytes_read2, errorbuf, buf_size);
|
|
|
|
if (option == CompileCommand::Unknown) {
|
|
|
|
assert(*errorbuf != '\0', "error must have been set");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
enum OptionType optiontype = option2type(option);
|
|
|
|
if (option2type(option) != type) {
|
|
|
|
const char* optiontype_name = optiontype2name(optiontype);
|
|
|
|
const char* type_name = optiontype2name(type);
|
|
|
|
jio_snprintf(errorbuf, buf_size, "Option '%s' with type '%s' doesn't match supplied type '%s'", option_buf, optiontype_name, type_name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
scan_value(type, line, total_bytes_read, matcher, option, errorbuf, buf_size);
|
|
|
|
} else {
|
|
|
|
const char* type_str = optiontype2name(type);
|
|
|
|
jio_snprintf(errorbuf, buf_size, "Option name for type '%s' should be alphanumeric ", type_str);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2015-09-18 10:11:11 +02:00
|
|
|
|
2020-11-25 14:20:35 +00:00
|
|
|
void CompilerOracle::print_parse_error(char* error_msg, char* original_line) {
|
|
|
|
assert(*error_msg != '\0', "Must have error_message");
|
2015-09-18 10:11:11 +02:00
|
|
|
ttyLocker ttyl;
|
|
|
|
tty->print_cr("CompileCommand: An error occurred during parsing");
|
|
|
|
tty->print_cr("Error: %s", error_msg);
|
2020-11-25 14:20:35 +00:00
|
|
|
tty->print_cr("Line: '%s'", original_line);
|
|
|
|
print_tip();
|
|
|
|
}
|
|
|
|
|
|
|
|
enum OptionType parse_option_type(const char* type_str) {
|
|
|
|
for (uint i = 0; i < ARRAY_SIZE(optiontype_names); i++) {
|
|
|
|
if (strcasecmp(type_str, optiontype_names[i]) == 0) {
|
|
|
|
return static_cast<enum OptionType>(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return OptionType::Unknown;
|
2015-09-18 10:11:11 +02:00
|
|
|
}
|
|
|
|
|
2020-11-25 14:20:35 +00:00
|
|
|
class LineCopy : StackObj {
|
|
|
|
const char* _copy;
|
|
|
|
public:
|
|
|
|
LineCopy(char* line) {
|
|
|
|
_copy = os::strdup(line, mtInternal);
|
|
|
|
}
|
|
|
|
~LineCopy() {
|
|
|
|
os::free((void*)_copy);
|
|
|
|
}
|
|
|
|
char* get() {
|
|
|
|
return (char*)_copy;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
void CompilerOracle::parse_from_line(char* line) {
|
|
|
|
if (line[0] == '\0') return;
|
|
|
|
if (line[0] == '#') return;
|
|
|
|
|
2020-11-25 14:20:35 +00:00
|
|
|
LineCopy original(line);
|
2007-12-01 00:00:00 +00:00
|
|
|
int bytes_read;
|
2020-11-25 14:20:35 +00:00
|
|
|
char error_buf[1024] = {0};
|
|
|
|
|
|
|
|
enum CompileCommand option = parse_option_name(line, &bytes_read, error_buf, sizeof(error_buf));
|
2007-12-01 00:00:00 +00:00
|
|
|
line += bytes_read;
|
2014-08-29 15:32:16 +02:00
|
|
|
ResourceMark rm;
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2020-11-25 14:20:35 +00:00
|
|
|
if (option == CompileCommand::Unknown) {
|
|
|
|
print_parse_error(error_buf, original.get());
|
2010-12-14 23:17:00 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-11-25 14:20:35 +00:00
|
|
|
if (option == CompileCommand::Quiet) {
|
2007-12-01 00:00:00 +00:00
|
|
|
_quiet = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-11-25 14:20:35 +00:00
|
|
|
if (option == CompileCommand::Help) {
|
2007-12-01 00:00:00 +00:00
|
|
|
usage();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-11-25 14:20:35 +00:00
|
|
|
if (option == CompileCommand::Option) {
|
2015-09-18 10:11:11 +02:00
|
|
|
// Look for trailing options.
|
|
|
|
//
|
|
|
|
// Two types of trailing options are
|
|
|
|
// supported:
|
|
|
|
//
|
2020-11-25 14:20:35 +00:00
|
|
|
// (1) CompileCommand=option,Klass::method,option
|
|
|
|
// (2) CompileCommand=option,Klass::method,type,option,value
|
2015-09-18 10:11:11 +02:00
|
|
|
//
|
2020-11-25 14:20:35 +00:00
|
|
|
// Type (1) is used to enable a boolean option for a method.
|
2015-09-18 10:11:11 +02:00
|
|
|
//
|
|
|
|
// Type (2) is used to support options with a value. Values can have the
|
|
|
|
// the following types: intx, uintx, bool, ccstr, ccstrlist, and double.
|
|
|
|
|
2020-11-25 14:20:35 +00:00
|
|
|
char option_type[256]; // stores option for Type (1) and type of Type (2)
|
|
|
|
skip_comma(line);
|
|
|
|
TypedMethodOptionMatcher* archetype = TypedMethodOptionMatcher::parse_method_pattern(line, error_buf, sizeof(error_buf));
|
2015-09-18 10:11:11 +02:00
|
|
|
if (archetype == NULL) {
|
2020-11-25 14:20:35 +00:00
|
|
|
print_parse_error(error_buf, original.get());
|
2015-09-18 10:11:11 +02:00
|
|
|
return;
|
|
|
|
}
|
2015-01-13 12:30:26 +01:00
|
|
|
|
2020-11-25 14:20:35 +00:00
|
|
|
skip_whitespace(line);
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2015-09-18 10:11:11 +02:00
|
|
|
// This is unnecessarily complex. Should retire multi-option lines and skip while loop
|
2020-11-25 14:20:35 +00:00
|
|
|
while (sscanf(line, "%255[a-zA-Z0-9]%n", option_type, &bytes_read) == 1) {
|
2015-09-18 10:11:11 +02:00
|
|
|
line += bytes_read;
|
2015-01-22 11:23:13 +01:00
|
|
|
|
2015-09-18 10:11:11 +02:00
|
|
|
// typed_matcher is used as a blueprint for each option, deleted at the end
|
|
|
|
TypedMethodOptionMatcher* typed_matcher = archetype->clone();
|
2020-11-25 14:20:35 +00:00
|
|
|
enum OptionType type = parse_option_type(option_type);
|
|
|
|
if (type != OptionType::Unknown) {
|
|
|
|
// Type (2) option: parse option name and value.
|
|
|
|
scan_option_and_value(type, line, bytes_read, typed_matcher, error_buf, sizeof(error_buf));
|
|
|
|
if (*error_buf != '\0') {
|
|
|
|
print_parse_error(error_buf, original.get());
|
2015-09-18 10:11:11 +02:00
|
|
|
return;
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
line += bytes_read;
|
2015-09-18 10:11:11 +02:00
|
|
|
} else {
|
2020-11-25 14:20:35 +00:00
|
|
|
// Type (1) option - option_type contains the option name -> bool value = true is implied
|
|
|
|
int bytes_read;
|
|
|
|
enum CompileCommand option = parse_option_name(option_type, &bytes_read, error_buf, sizeof(error_buf));
|
|
|
|
if (option == CompileCommand::Unknown) {
|
|
|
|
print_parse_error(error_buf, original.get());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
register_command(typed_matcher, option, true);
|
2015-09-18 10:11:11 +02:00
|
|
|
}
|
2020-11-25 14:20:35 +00:00
|
|
|
assert(typed_matcher != NULL, "sanity");
|
|
|
|
assert(*error_buf == '\0', "No error here");
|
|
|
|
skip_whitespace(line);
|
2015-09-18 10:11:11 +02:00
|
|
|
} // while(
|
|
|
|
delete archetype;
|
2020-11-25 14:20:35 +00:00
|
|
|
} else { // not an OptionCommand
|
|
|
|
// Command has the following form:
|
|
|
|
// CompileCommand=<option>,<method pattern><value>
|
|
|
|
// CompileCommand=<option>,<method pattern> (implies option is bool and value is true)
|
|
|
|
assert(*error_buf == '\0', "Don't call here with error_buf already set");
|
|
|
|
enum OptionType type = option2type(option);
|
|
|
|
int bytes_read = 0;
|
|
|
|
skip_comma(line);
|
|
|
|
TypedMethodOptionMatcher* matcher = TypedMethodOptionMatcher::parse_method_pattern(line, error_buf, sizeof(error_buf));
|
|
|
|
if (matcher == NULL) {
|
|
|
|
print_parse_error(error_buf, original.get());
|
2015-09-18 10:11:11 +02:00
|
|
|
return;
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
2020-11-25 14:20:35 +00:00
|
|
|
skip_whitespace(line);
|
|
|
|
if (*line == '\0') {
|
|
|
|
// if this is a bool option this implies true
|
|
|
|
if (option2type(option) == OptionType::Bool) {
|
|
|
|
register_command(matcher, option, true);
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
jio_snprintf(error_buf, sizeof(error_buf), " Option '%s' is not followed by a value", option2name(option));
|
|
|
|
print_parse_error(error_buf, original.get());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
scan_value(type, line, bytes_read, matcher, option, error_buf, sizeof(error_buf));
|
|
|
|
if (*error_buf != '\0') {
|
|
|
|
print_parse_error(error_buf, original.get());
|
|
|
|
return;
|
2014-08-29 15:32:16 +02:00
|
|
|
}
|
2020-11-25 14:20:35 +00:00
|
|
|
assert(matcher != NULL, "consistency");
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-02 10:54:17 -04:00
|
|
|
static const char* default_cc_file = ".hotspot_compiler";
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
static const char* cc_file() {
|
2012-03-29 18:55:32 -04:00
|
|
|
#ifdef ASSERT
|
2007-12-01 00:00:00 +00:00
|
|
|
if (CompileCommandFile == NULL)
|
2012-07-02 10:54:17 -04:00
|
|
|
return default_cc_file;
|
2012-03-29 18:55:32 -04:00
|
|
|
#endif
|
2007-12-01 00:00:00 +00:00
|
|
|
return CompileCommandFile;
|
|
|
|
}
|
2012-03-29 18:55:32 -04:00
|
|
|
|
|
|
|
bool CompilerOracle::has_command_file() {
|
|
|
|
return cc_file() != NULL;
|
|
|
|
}
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
bool CompilerOracle::_quiet = false;
|
|
|
|
|
|
|
|
void CompilerOracle::parse_from_file() {
|
2012-03-29 18:55:32 -04:00
|
|
|
assert(has_command_file(), "command file must be specified");
|
2007-12-01 00:00:00 +00:00
|
|
|
FILE* stream = fopen(cc_file(), "rt");
|
|
|
|
if (stream == NULL) return;
|
|
|
|
|
|
|
|
char token[1024];
|
|
|
|
int pos = 0;
|
|
|
|
int c = getc(stream);
|
2012-06-08 12:49:12 -04:00
|
|
|
while(c != EOF && pos < (int)(sizeof(token)-1)) {
|
2007-12-01 00:00:00 +00:00
|
|
|
if (c == '\n') {
|
|
|
|
token[pos++] = '\0';
|
|
|
|
parse_from_line(token);
|
|
|
|
pos = 0;
|
|
|
|
} else {
|
|
|
|
token[pos++] = c;
|
|
|
|
}
|
|
|
|
c = getc(stream);
|
|
|
|
}
|
|
|
|
token[pos++] = '\0';
|
|
|
|
parse_from_line(token);
|
|
|
|
|
|
|
|
fclose(stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CompilerOracle::parse_from_string(const char* str, void (*parse_line)(char*)) {
|
|
|
|
char token[1024];
|
|
|
|
int pos = 0;
|
|
|
|
const char* sp = str;
|
|
|
|
int c = *sp++;
|
2012-06-08 12:49:12 -04:00
|
|
|
while (c != '\0' && pos < (int)(sizeof(token)-1)) {
|
2007-12-01 00:00:00 +00:00
|
|
|
if (c == '\n') {
|
|
|
|
token[pos++] = '\0';
|
|
|
|
parse_line(token);
|
|
|
|
pos = 0;
|
|
|
|
} else {
|
|
|
|
token[pos++] = c;
|
|
|
|
}
|
|
|
|
c = *sp++;
|
|
|
|
}
|
|
|
|
token[pos++] = '\0';
|
|
|
|
parse_line(token);
|
|
|
|
}
|
|
|
|
|
|
|
|
void compilerOracle_init() {
|
|
|
|
CompilerOracle::parse_from_string(CompileCommand, CompilerOracle::parse_from_line);
|
|
|
|
CompilerOracle::parse_from_string(CompileOnly, CompilerOracle::parse_compile_only);
|
2012-03-29 18:55:32 -04:00
|
|
|
if (CompilerOracle::has_command_file()) {
|
|
|
|
CompilerOracle::parse_from_file();
|
2012-07-02 10:54:17 -04:00
|
|
|
} else {
|
|
|
|
struct stat buf;
|
|
|
|
if (os::stat(default_cc_file, &buf) == 0) {
|
|
|
|
warning("%s file is present but has been ignored. "
|
|
|
|
"Run with -XX:CompileCommandFile=%s to load the file.",
|
|
|
|
default_cc_file, default_cc_file);
|
|
|
|
}
|
2012-03-29 18:55:32 -04:00
|
|
|
}
|
2020-11-25 14:20:35 +00:00
|
|
|
if (has_command(CompileCommand::Print)) {
|
2010-01-08 13:47:01 -08:00
|
|
|
if (PrintAssembly) {
|
2012-07-02 10:54:17 -04:00
|
|
|
warning("CompileCommand and/or %s file contains 'print' commands, but PrintAssembly is also enabled", default_cc_file);
|
2010-01-08 13:47:01 -08:00
|
|
|
} else if (FLAG_IS_DEFAULT(DebugNonSafepoints)) {
|
|
|
|
warning("printing of assembly code is enabled; turning on DebugNonSafepoints to gain additional output");
|
|
|
|
DebugNonSafepoints = true;
|
|
|
|
}
|
|
|
|
}
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2020-11-25 14:20:35 +00:00
|
|
|
void CompilerOracle::parse_compile_only(char* line) {
|
2007-12-01 00:00:00 +00:00
|
|
|
int i;
|
|
|
|
char name[1024];
|
|
|
|
const char* className = NULL;
|
|
|
|
const char* methodName = NULL;
|
|
|
|
|
|
|
|
bool have_colon = (strstr(line, "::") != NULL);
|
|
|
|
char method_sep = have_colon ? ':' : '.';
|
|
|
|
|
|
|
|
if (Verbose) {
|
2014-05-09 16:50:54 -04:00
|
|
|
tty->print_cr("%s", line);
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ResourceMark rm;
|
|
|
|
while (*line != '\0') {
|
|
|
|
MethodMatcher::Mode c_match = MethodMatcher::Exact;
|
|
|
|
MethodMatcher::Mode m_match = MethodMatcher::Exact;
|
|
|
|
|
|
|
|
for (i = 0;
|
|
|
|
i < 1024 && *line != '\0' && *line != method_sep && *line != ',' && !isspace(*line);
|
|
|
|
line++, i++) {
|
|
|
|
name[i] = *line;
|
|
|
|
if (name[i] == '.') name[i] = '/'; // package prefix uses '/'
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i > 0) {
|
|
|
|
char* newName = NEW_RESOURCE_ARRAY( char, i + 1);
|
|
|
|
if (newName == NULL)
|
|
|
|
return;
|
|
|
|
strncpy(newName, name, i);
|
|
|
|
newName[i] = '\0';
|
|
|
|
|
|
|
|
if (className == NULL) {
|
|
|
|
className = newName;
|
|
|
|
} else {
|
|
|
|
methodName = newName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*line == method_sep) {
|
|
|
|
if (className == NULL) {
|
|
|
|
className = "";
|
|
|
|
c_match = MethodMatcher::Any;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// got foo or foo/bar
|
|
|
|
if (className == NULL) {
|
|
|
|
ShouldNotReachHere();
|
|
|
|
} else {
|
2016-07-20 19:35:08 +03:00
|
|
|
// missing class name handled as "Any" class match
|
|
|
|
if (className[0] == '\0') {
|
2007-12-01 00:00:00 +00:00
|
|
|
c_match = MethodMatcher::Any;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// each directive is terminated by , or NUL or . followed by NUL
|
|
|
|
if (*line == ',' || *line == '\0' || (line[0] == '.' && line[1] == '\0')) {
|
|
|
|
if (methodName == NULL) {
|
|
|
|
methodName = "";
|
|
|
|
if (*line != method_sep) {
|
|
|
|
m_match = MethodMatcher::Any;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
EXCEPTION_MARK;
|
2019-05-14 11:29:18 -04:00
|
|
|
Symbol* c_name = SymbolTable::new_symbol(className);
|
|
|
|
Symbol* m_name = SymbolTable::new_symbol(methodName);
|
2011-01-27 16:11:27 -08:00
|
|
|
Symbol* signature = NULL;
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2020-11-25 14:20:35 +00:00
|
|
|
TypedMethodOptionMatcher* tom = new TypedMethodOptionMatcher();
|
|
|
|
tom->init_matcher(c_name, c_match, m_name, m_match, signature);
|
|
|
|
register_command(tom, CompileCommand::CompileOnly, true);
|
2007-12-01 00:00:00 +00:00
|
|
|
if (PrintVMOptions) {
|
|
|
|
tty->print("CompileOnly: compileonly ");
|
2020-11-25 14:20:35 +00:00
|
|
|
tom->print();
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
className = NULL;
|
|
|
|
methodName = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
line = *line == '\0' ? line : line + 1;
|
|
|
|
}
|
|
|
|
}
|
2020-11-25 14:20:35 +00:00
|
|
|
|
|
|
|
enum CompileCommand CompilerOracle::string_to_option(const char* name) {
|
|
|
|
int bytes_read = 0;
|
|
|
|
char errorbuf[1024] = {0};
|
|
|
|
return parse_option_name(name, &bytes_read, errorbuf, sizeof(errorbuf));
|
|
|
|
}
|