8310606: Fix signed integer overflow, part 3

Reviewed-by: kvn, thartmann
This commit is contained in:
Dean Long 2023-06-28 20:31:08 +00:00
parent f0c2f09815
commit da0f8325de
9 changed files with 28 additions and 25 deletions

View File

@ -79,7 +79,7 @@ void VM_Version::initialize() {
int dcache_line = VM_Version::dcache_line_size();
// Limit AllocatePrefetchDistance so that it does not exceed the
// constraint in AllocatePrefetchDistanceConstraintFunc.
// static constraint of 512 defined in runtime/globals.hpp.
if (FLAG_IS_DEFAULT(AllocatePrefetchDistance))
FLAG_SET_DEFAULT(AllocatePrefetchDistance, MIN2(512, 3*dcache_line));

View File

@ -275,7 +275,7 @@ void VM_Version::c2_initialize() {
FLAG_SET_DEFAULT(AllocatePrefetchStyle, 0);
} else {
// Limit AllocatePrefetchDistance so that it does not exceed the
// constraint in AllocatePrefetchDistanceConstraintFunc.
// static constraint of 512 defined in runtime/globals.hpp.
if (FLAG_IS_DEFAULT(AllocatePrefetchDistance)) {
FLAG_SET_DEFAULT(AllocatePrefetchDistance, MIN2(512, 3 * (int)CacheLineSize));
}

View File

@ -351,12 +351,29 @@ RangeCheckEliminator::Bound *RangeCheckEliminator::get_bound(Value v) {
// Update bound
void RangeCheckEliminator::update_bound(IntegerStack &pushed, Value v, Instruction::Condition cond, Value value, int constant) {
assert(sizeof(constant) == sizeof(jint), "wrong size");
if (cond == Instruction::gtr) {
cond = Instruction::geq;
constant++;
if (constant == INT_MAX) {
if (value == nullptr) {
// Cannot represent c > INT_MAX, do not update bounds
return;
}
constant = java_add((jint)constant, 1); // Java wrap semantics
} else {
constant++;
}
} else if (cond == Instruction::lss) {
cond = Instruction::leq;
constant--;
if (constant == INT_MIN) {
if (value == nullptr) {
// Cannot represent c < INT_MIN, do not update bounds
return;
}
constant = java_subtract((jint)constant, 1); // Java wrap semantics
} else {
constant--;
}
}
Bound *bound = new Bound(cond, value, constant);
update_bound(pushed, v, bound);
@ -694,8 +711,7 @@ void RangeCheckEliminator::insert_deoptimization(ValueStack *state, Instruction
} else {
assert(lower < 0, "");
// Add 1
lower++;
lower = -lower;
lower = java_subtract(-1, (jint)lower); // lower++; lower = -lower;
// Compare for smaller or equal 0
insert_position = predicate_cmp_with_const(lower_instr, Instruction::leq, lower, state, insert_position, bci);
}
@ -739,7 +755,7 @@ void RangeCheckEliminator::insert_deoptimization(ValueStack *state, Instruction
insert_position = predicate_add(upper_instr, upper, Instruction::geq, length_instr, state, insert_position, bci);
} else {
assert(upper > 0, "");
upper = -upper;
upper = java_negate((jint)upper); // upper = -upper;
// Compare for geq array.length
insert_position = predicate_add(length_instr, upper, Instruction::leq, upper_instr, state, insert_position, bci);
}

View File

@ -306,7 +306,7 @@ double CompilationPolicy::threshold_scale(CompLevel level, int feedback_k) {
int comp_count = compiler_count(level);
if (comp_count > 0) {
double queue_size = CompileBroker::queue_size(level);
double k = queue_size / (feedback_k * comp_count) + 1;
double k = (double)queue_size / ((double)feedback_k * (double)comp_count) + 1;
// Increase C1 compile threshold when the code cache is filled more
// than specified by IncreaseFirstTierCompileThresholdAt percentage.

View File

@ -36,8 +36,8 @@ void GranularTimer::start(jlong duration_ticks, long granularity) {
_granularity = granularity;
_counter = granularity;
_start_time_ticks = JfrTicks::now();
const jlong end_time_ticks = _start_time_ticks.value() + duration_ticks;
_finish_time_ticks = end_time_ticks < 0 ? JfrTicks(max_jlong) : JfrTicks(end_time_ticks);
const julong end_time_ticks = (julong)_start_time_ticks.value() + (julong)duration_ticks;
_finish_time_ticks = end_time_ticks > (julong)max_jlong ? JfrTicks(max_jlong) : JfrTicks(end_time_ticks);
_finished = _finish_time_ticks == _start_time_ticks;
assert(_finish_time_ticks.value() >= 0, "invariant");
assert(_finish_time_ticks >= _start_time_ticks, "invariant");

View File

@ -898,7 +898,7 @@ Node *LShiftINode::Ideal(PhaseGVN *phase, bool can_reshape) {
if (con > add1Con) {
// Creates "(x << (C2 - C1)) & -(1 << C2)"
Node* lshift = phase->transform(new LShiftINode(add1->in(1), phase->intcon(con - add1Con)));
return new AndINode(lshift, phase->intcon(-(1 << con)));
return new AndINode(lshift, phase->intcon(java_negate((jint)(1 << con))));
} else {
assert(con < add1Con, "must be (%d < %d)", con, add1Con);
// Creates "(x >> (C1 - C2)) & -(1 << C2)"

View File

@ -67,18 +67,6 @@ JVMFlag::Error CICompilerCountConstraintFunc(intx value, bool verbose) {
}
}
JVMFlag::Error AllocatePrefetchDistanceConstraintFunc(intx value, bool verbose) {
if (value < 0 || value > 512) {
JVMFlag::printError(verbose,
"AllocatePrefetchDistance (" INTX_FORMAT ") must be "
"between 0 and %d\n",
AllocatePrefetchDistance, 512);
return JVMFlag::VIOLATES_CONSTRAINT;
}
return JVMFlag::SUCCESS;
}
JVMFlag::Error AllocatePrefetchStepSizeConstraintFunc(intx value, bool verbose) {
if (AllocatePrefetchStyle == 3) {
if (value % wordSize != 0) {

View File

@ -36,7 +36,6 @@
#define COMPILER_CONSTRAINTS(f) \
f(intx, CICompilerCountConstraintFunc) \
f(intx, AllocatePrefetchDistanceConstraintFunc) \
f(intx, AllocatePrefetchInstrConstraintFunc) \
f(intx, AllocatePrefetchStepSizeConstraintFunc) \
f(intx, CompileThresholdConstraintFunc) \

View File

@ -1239,7 +1239,7 @@ const int ObjectAlignmentInBytes = 8;
product(intx, AllocatePrefetchDistance, -1, \
"Distance to prefetch ahead of allocation pointer. " \
"-1: use system-specific value (automatically determined") \
constraint(AllocatePrefetchDistanceConstraintFunc,AfterMemoryInit)\
range(-1, 512) \
\
product(intx, AllocatePrefetchLines, 3, \
"Number of lines to prefetch ahead of array allocation pointer") \