Skip to content

Commit 015e6e5

Browse files
author
Nils Eliasson
committedDec 1, 2020
8257460: Further CompilerOracle cleanup
Reviewed-by: kvn, redestad, thartmann
1 parent 29d90b9 commit 015e6e5

File tree

4 files changed

+49
-44
lines changed

4 files changed

+49
-44
lines changed
 

‎src/hotspot/share/compiler/compilerDirectives.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ DirectiveSet* DirectiveSet::compilecommand_compatibility_init(const methodHandle
359359
}
360360

361361
// inline and dontinline (including exclude) are implemented in the directiveset accessors
362-
#define init_default_cc(name, type, dvalue, cc_flag) { type v; if (!_modified[name##Index] && CompilerOracle::has_option_value(method, CompileCommand::cc_flag, v) && v != this->name##Option) { set.cloned()->name##Option = v; } }
362+
#define init_default_cc(name, type, dvalue, cc_flag) { type v; if (!_modified[name##Index] && CompileCommand::cc_flag != CompileCommand::Unknown && CompilerOracle::has_option_value(method, CompileCommand::cc_flag, v) && v != this->name##Option) { set.cloned()->name##Option = v; } }
363363
compilerdirectives_common_flags(init_default_cc)
364364
compilerdirectives_c2_flags(init_default_cc)
365365
compilerdirectives_c1_flags(init_default_cc)

‎src/hotspot/share/compiler/compilerOracle.cpp

+39-41
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ class TypedMethodOptionMatcher : public MethodMatcher {
104104
private:
105105
TypedMethodOptionMatcher* _next;
106106
enum CompileCommand _option;
107-
OptionType _type;
108107
public:
109108

110109
union {
@@ -117,18 +116,16 @@ class TypedMethodOptionMatcher : public MethodMatcher {
117116

118117
TypedMethodOptionMatcher() : MethodMatcher(),
119118
_next(NULL),
120-
_option(CompileCommand::Unknown),
121-
_type(OptionType::Unknown) {
119+
_option(CompileCommand::Unknown) {
122120
memset(&_u, 0, sizeof(_u));
123121
}
124122

125123
~TypedMethodOptionMatcher();
126124
static TypedMethodOptionMatcher* parse_method_pattern(char*& line, char* errorbuf, const int buf_size);
127-
TypedMethodOptionMatcher* match(const methodHandle &method, enum CompileCommand option, OptionType type);
125+
TypedMethodOptionMatcher* match(const methodHandle &method, enum CompileCommand option);
128126

129-
void init(enum CompileCommand option, OptionType type, TypedMethodOptionMatcher* next) {
127+
void init(enum CompileCommand option, TypedMethodOptionMatcher* next) {
130128
_next = next;
131-
_type = type;
132129
_option = option;
133130
}
134131

@@ -140,7 +137,6 @@ class TypedMethodOptionMatcher : public MethodMatcher {
140137

141138
void set_next(TypedMethodOptionMatcher* next) {_next = next; }
142139
TypedMethodOptionMatcher* next() { return _next; }
143-
OptionType type() { return _type; }
144140
enum CompileCommand option() { return _option; }
145141
template<typename T> T value();
146142
template<typename T> void set_value(T value);
@@ -194,8 +190,9 @@ void TypedMethodOptionMatcher::print() {
194190
ttyLocker ttyl;
195191
print_base(tty);
196192
const char* name = option2name(_option);
197-
switch (_type) {
198-
case OptionType::Intx:
193+
enum OptionType type = option2type(_option);
194+
switch (type) {
195+
case OptionType::Intx:
199196
tty->print_cr(" intx %s = " INTX_FORMAT, name, value<intx>());
200197
break;
201198
case OptionType::Uintx:
@@ -208,6 +205,7 @@ void TypedMethodOptionMatcher::print() {
208205
tty->print_cr(" double %s = %f", name, value<double>());
209206
break;
210207
case OptionType::Ccstr:
208+
case OptionType::Ccstrlist:
211209
tty->print_cr(" const char* %s = '%s'", name, value<ccstr>());
212210
break;
213211
default:
@@ -244,7 +242,8 @@ TypedMethodOptionMatcher* TypedMethodOptionMatcher::clone() {
244242
}
245243

246244
TypedMethodOptionMatcher::~TypedMethodOptionMatcher() {
247-
if (type() == OptionType::Ccstr) {
245+
enum OptionType type = option2type(_option);
246+
if (type == OptionType::Ccstr || type == OptionType::Ccstrlist) {
248247
ccstr v = value<ccstr>();
249248
os::free((void*)v);
250249
}
@@ -263,7 +262,7 @@ TypedMethodOptionMatcher* TypedMethodOptionMatcher::parse_method_pattern(char*&
263262
return tom;
264263
}
265264

266-
TypedMethodOptionMatcher* TypedMethodOptionMatcher::match(const methodHandle& method, enum CompileCommand option, OptionType type) {
265+
TypedMethodOptionMatcher* TypedMethodOptionMatcher::match(const methodHandle& method, enum CompileCommand option) {
267266
TypedMethodOptionMatcher* current = this;
268267
while (current != NULL) {
269268
if (current->_option == option) {
@@ -285,12 +284,9 @@ static void register_command(TypedMethodOptionMatcher* matcher,
285284
tty->print_cr("Warning: +LogCompilation must be enabled in order for individual methods to be logged with ");
286285
tty->print_cr(" CompileCommand=log,<method pattern>");
287286
}
288-
enum OptionType type = option2type(option);
289-
if (type == OptionType::Ccstrlist) {
290-
type = OptionType::Ccstr; // ccstrlists are stores as ccstr
291-
}
292-
assert(type == get_type_for<T>(), "sanity");
293-
matcher->init(option, type, option_list);
287+
assert(CompilerOracle::option_matches_type(option, value), "Value must match option type");
288+
289+
matcher->init(option, option_list);
294290
matcher->set_value<T>(value);
295291
option_list = matcher;
296292
if ((option != CompileCommand::DontInline) &&
@@ -308,26 +304,10 @@ static void register_command(TypedMethodOptionMatcher* matcher,
308304
}
309305

310306
template<typename T>
311-
bool CompilerOracle::has_option_value(const methodHandle& method, enum CompileCommand option, T& value, bool verify_type) {
312-
enum OptionType type = option2type(option);
313-
if (type == OptionType::Unknown) {
314-
return false; // Can't query options with type Unknown.
315-
}
316-
if (type == OptionType::Ccstrlist) {
317-
type = OptionType::Ccstr; // CCstrList type options are stored as Ccstr
318-
}
319-
if (verify_type) {
320-
if (type != get_type_for<T>()) {
321-
// Whitebox API expects false if option and type doesn't match
322-
return false;
323-
}
324-
} else {
325-
assert(type == get_type_for<T>(), "Value type (%s) must match option %s (%s)",
326-
optiontype2name(get_type_for<T>()),
327-
option2name(option), optiontype2name(option2type(option)));
328-
}
307+
bool CompilerOracle::has_option_value(const methodHandle& method, enum CompileCommand option, T& value) {
308+
assert(option_matches_type(option, value), "Value must match option type");
329309
if (option_list != NULL) {
330-
TypedMethodOptionMatcher* m = option_list->match(method, option, type);
310+
TypedMethodOptionMatcher* m = option_list->match(method, option);
331311
if (m != NULL) {
332312
value = m->value<T>();
333313
return true;
@@ -361,11 +341,29 @@ bool CompilerOracle::has_any_command_set() {
361341
}
362342

363343
// Explicit instantiation for all OptionTypes supported.
364-
template bool CompilerOracle::has_option_value<intx>(const methodHandle& method, enum CompileCommand option, intx& value, bool verify_type);
365-
template bool CompilerOracle::has_option_value<uintx>(const methodHandle& method, enum CompileCommand option, uintx& value, bool verify_type);
366-
template bool CompilerOracle::has_option_value<bool>(const methodHandle& method, enum CompileCommand option, bool& value, bool verify_type);
367-
template bool CompilerOracle::has_option_value<ccstr>(const methodHandle& method, enum CompileCommand option, ccstr& value, bool verify_type);
368-
template bool CompilerOracle::has_option_value<double>(const methodHandle& method, enum CompileCommand option, double& value, bool verify_type);
344+
template bool CompilerOracle::has_option_value<intx>(const methodHandle& method, enum CompileCommand option, intx& value);
345+
template bool CompilerOracle::has_option_value<uintx>(const methodHandle& method, enum CompileCommand option, uintx& value);
346+
template bool CompilerOracle::has_option_value<bool>(const methodHandle& method, enum CompileCommand option, bool& value);
347+
template bool CompilerOracle::has_option_value<ccstr>(const methodHandle& method, enum CompileCommand option, ccstr& value);
348+
template bool CompilerOracle::has_option_value<double>(const methodHandle& method, enum CompileCommand option, double& value);
349+
350+
template<typename T>
351+
bool CompilerOracle::option_matches_type(enum CompileCommand option, T& value) {
352+
enum OptionType option_type = option2type(option);
353+
if (option_type == OptionType::Unknown) {
354+
return false; // Can't query options with type Unknown.
355+
}
356+
if (option_type == OptionType::Ccstrlist) {
357+
option_type = OptionType::Ccstr; // CCstrList type options are stored as Ccstr
358+
}
359+
return (get_type_for<T>() == option_type);
360+
}
361+
362+
template bool CompilerOracle::option_matches_type<intx>(enum CompileCommand option, intx& value);
363+
template bool CompilerOracle::option_matches_type<uintx>(enum CompileCommand option, uintx& value);
364+
template bool CompilerOracle::option_matches_type<bool>(enum CompileCommand option, bool& value);
365+
template bool CompilerOracle::option_matches_type<ccstr>(enum CompileCommand option, ccstr& value);
366+
template bool CompilerOracle::option_matches_type<double>(enum CompileCommand option, double& value);
369367

370368
bool CompilerOracle::has_option(const methodHandle& method, enum CompileCommand option) {
371369
bool value = false;

‎src/hotspot/share/compiler/compilerOracle.hpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,11 @@ class CompilerOracle : AllStatic {
149149
// Check if method has option and value set. If yes, overwrite value and return true,
150150
// otherwise leave value unchanged and return false.
151151
template<typename T>
152-
static bool has_option_value(const methodHandle& method, enum CompileCommand option, T& value, bool verfiy_type = false);
152+
static bool has_option_value(const methodHandle& method, enum CompileCommand option, T& value);
153+
154+
// This check is currently only needed by whitebox API
155+
template<typename T>
156+
static bool option_matches_type(enum CompileCommand option, T& value);
153157

154158
// Reads from string instead of file
155159
static void parse_from_string(const char* option_string, void (*parser)(char*));

‎src/hotspot/share/prims/whitebox.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -1814,7 +1814,10 @@ static bool GetMethodOption(JavaThread* thread, JNIEnv* env, jobject method, jst
18141814
if (option == CompileCommand::Unknown) {
18151815
return false;
18161816
}
1817-
return CompilerOracle::has_option_value(mh, option, *value, true /* verify type*/);
1817+
if (!CompilerOracle::option_matches_type(option, *value)) {
1818+
return false;
1819+
}
1820+
return CompilerOracle::has_option_value(mh, option, *value);
18181821
}
18191822

18201823
WB_ENTRY(jobject, WB_GetMethodBooleaneOption(JNIEnv* env, jobject wb, jobject method, jstring name))

0 commit comments

Comments
 (0)
Please sign in to comment.