8211034: OnStackReplacePercentage option checking has bugs

Fixed the constraint checks

Reviewed-by: kvn
This commit is contained in:
Jamsheed Mohammed C M 2018-12-12 23:08:01 -08:00
parent 966aaa1f9b
commit 79d7ae7633
5 changed files with 39 additions and 33 deletions

View File

@ -153,9 +153,9 @@ void InvocationCounter::reinitialize(bool delay_overflow) {
// don't need the shift by number_of_noncount_bits, but we do need to adjust
// the factor by which we scale the threshold.
if (ProfileInterpreter) {
InterpreterBackwardBranchLimit = (CompileThreshold * (OnStackReplacePercentage - InterpreterProfilePercentage)) / 100;
InterpreterBackwardBranchLimit = (int)((int64_t)CompileThreshold * (OnStackReplacePercentage - InterpreterProfilePercentage) / 100);
} else {
InterpreterBackwardBranchLimit = ((CompileThreshold * OnStackReplacePercentage) / 100) << number_of_noncount_bits;
InterpreterBackwardBranchLimit = (int)(((int64_t)CompileThreshold * OnStackReplacePercentage / 100) << number_of_noncount_bits);
}
assert(0 <= InterpreterBackwardBranchLimit,

View File

@ -103,9 +103,9 @@ class MethodCounters : public Metadata {
// If interpreter profiling is enabled, the backward branch limit
// is compared against the method data counter rather than an invocation
// counter, therefore no shifting of bits is required.
_interpreter_backward_branch_limit = (compile_threshold * (OnStackReplacePercentage - InterpreterProfilePercentage)) / 100;
_interpreter_backward_branch_limit = (int)((int64_t)compile_threshold * (OnStackReplacePercentage - InterpreterProfilePercentage) / 100);
} else {
_interpreter_backward_branch_limit = ((compile_threshold * OnStackReplacePercentage) / 100) << InvocationCounter::count_shift;
_interpreter_backward_branch_limit = (int)(((int64_t)compile_threshold * OnStackReplacePercentage / 100) << InvocationCounter::count_shift);
}
_interpreter_profile_limit = ((compile_threshold * InterpreterProfilePercentage) / 100) << InvocationCounter::count_shift;
_invoke_mask = right_n_bits(CompilerConfig::scaled_freq_log(Tier0InvokeNotifyFreqLog, scale)) << InvocationCounter::count_shift;

View File

@ -471,15 +471,15 @@ void Parse::profile_taken_branch(int target_bci, bool force_update) {
if (osr_site) {
ciProfileData* data = md->bci_to_data(cur_bci);
assert(data != NULL && data->is_JumpData(), "need JumpData for taken branch");
int limit = (CompileThreshold
* (OnStackReplacePercentage - InterpreterProfilePercentage)) / 100;
int limit = (int)((int64_t)CompileThreshold
* (OnStackReplacePercentage - InterpreterProfilePercentage) / 100);
test_for_osr_md_counter_at(md, data, JumpData::taken_offset(), limit);
}
} else {
// With method data update off, use the invocation counter to trigger an
// OSR compilation, as done in the interpreter.
if (osr_site) {
int limit = (CompileThreshold * OnStackReplacePercentage) / 100;
int limit = (int)((int64_t)CompileThreshold * OnStackReplacePercentage / 100);
increment_and_test_invocation_counter(limit);
}
}

View File

@ -145,47 +145,42 @@ JVMFlag::Error CompileThresholdConstraintFunc(intx value, bool verbose) {
}
JVMFlag::Error OnStackReplacePercentageConstraintFunc(intx value, bool verbose) {
int backward_branch_limit;
int64_t max_percentage_limit = INT_MAX;
if (!ProfileInterpreter) {
max_percentage_limit = (max_percentage_limit>>InvocationCounter::count_shift);
}
max_percentage_limit = CompileThreshold == 0 ? max_percentage_limit*100 : max_percentage_limit*100/CompileThreshold;
if (ProfileInterpreter) {
if (OnStackReplacePercentage < InterpreterProfilePercentage) {
if (value < InterpreterProfilePercentage) {
JVMFlag::printError(verbose,
"OnStackReplacePercentage (" INTX_FORMAT ") must be "
"larger than InterpreterProfilePercentage (" INTX_FORMAT ")\n",
OnStackReplacePercentage, InterpreterProfilePercentage);
value, InterpreterProfilePercentage);
return JVMFlag::VIOLATES_CONSTRAINT;
}
backward_branch_limit = ((CompileThreshold * (OnStackReplacePercentage - InterpreterProfilePercentage)) / 100)
<< InvocationCounter::count_shift;
if (backward_branch_limit < 0) {
max_percentage_limit += InterpreterProfilePercentage;
if (value > max_percentage_limit) {
JVMFlag::printError(verbose,
"CompileThreshold * (InterpreterProfilePercentage - OnStackReplacePercentage) / 100 = "
INTX_FORMAT " "
"must be between 0 and %d, try changing "
"CompileThreshold, InterpreterProfilePercentage, and/or OnStackReplacePercentage\n",
(CompileThreshold * (OnStackReplacePercentage - InterpreterProfilePercentage)) / 100,
INT_MAX >> InvocationCounter::count_shift);
"OnStackReplacePercentage (" INTX_FORMAT ") must be between 0 and " INT64_FORMAT "\n",
value,
max_percentage_limit);
return JVMFlag::VIOLATES_CONSTRAINT;
}
} else {
if (OnStackReplacePercentage < 0 ) {
if (value < 0) {
JVMFlag::printError(verbose,
"OnStackReplacePercentage (" INTX_FORMAT ") must be "
"non-negative\n", OnStackReplacePercentage);
"non-negative\n", value);
return JVMFlag::VIOLATES_CONSTRAINT;
}
backward_branch_limit = ((CompileThreshold * OnStackReplacePercentage) / 100)
<< InvocationCounter::count_shift;
if (backward_branch_limit < 0) {
if (value > max_percentage_limit) {
JVMFlag::printError(verbose,
"CompileThreshold * OnStackReplacePercentage / 100 = " INTX_FORMAT " "
"must be between 0 and %d, try changing "
"CompileThreshold and/or OnStackReplacePercentage\n",
(CompileThreshold * OnStackReplacePercentage) / 100,
INT_MAX >> InvocationCounter::count_shift);
"OnStackReplacePercentage (" INTX_FORMAT ") must be between 0 and " INT64_FORMAT "\n",
value,
max_percentage_limit);
return JVMFlag::VIOLATES_CONSTRAINT;
}
}

View File

@ -34,17 +34,28 @@
* @summary testing of WB::set/getIntxVMFlag()
* @author igor.ignatyev@oracle.com
*/
import jdk.test.lib.Platform;
public class IntxTest {
private static final String FLAG_NAME = "OnStackReplacePercentage";
private static final String FLAG_DEBUG_NAME = "InlineFrequencyCount";
private static final Long[] TESTS = {0L, 100L, (long) Integer.MAX_VALUE};
private static final long COMPILE_THRESHOLD = VmFlagTest.WHITE_BOX.getIntxVMFlag("CompileThreshold");
private static final Long[] TESTS = {0L, 100L, (long)(Integer.MAX_VALUE>>3)*100L};
public static void main(String[] args) throws Exception {
find_and_set_max_osrp();
VmFlagTest.runTest(FLAG_NAME, TESTS,
VmFlagTest.WHITE_BOX::setIntxVMFlag,
VmFlagTest.WHITE_BOX::getIntxVMFlag);
VmFlagTest.runTest(FLAG_DEBUG_NAME, VmFlagTest.WHITE_BOX::getIntxVMFlag);
}
static void find_and_set_max_osrp() {
long max_percentage_limit = (long)(Integer.MAX_VALUE>>3)*100L;
max_percentage_limit = COMPILE_THRESHOLD == 0 ? max_percentage_limit : max_percentage_limit/COMPILE_THRESHOLD;
if (Platform.is32bit() && max_percentage_limit > Integer.MAX_VALUE) {
max_percentage_limit = Integer.MAX_VALUE;
}
TESTS[2] = max_percentage_limit;
}
}