Skip to content

Commit

Permalink
8310606: Fix signed integer overflow, part 3
Browse files Browse the repository at this point in the history
Reviewed-by: kvn, thartmann
  • Loading branch information
dean-long committed Jun 28, 2023
1 parent f0c2f09 commit da0f832
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/hotspot/cpu/aarch64/vm_version_aarch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/cpu/riscv/vm_version_riscv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
26 changes: 21 additions & 5 deletions src/hotspot/share/c1/c1_RangeCheckElimination.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/compiler/compilationPolicy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/opto/mulnode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down
12 changes: 0 additions & 12 deletions src/hotspot/share/runtime/flags/jvmFlagConstraintsCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@

#define COMPILER_CONSTRAINTS(f) \
f(intx, CICompilerCountConstraintFunc) \
f(intx, AllocatePrefetchDistanceConstraintFunc) \
f(intx, AllocatePrefetchInstrConstraintFunc) \
f(intx, AllocatePrefetchStepSizeConstraintFunc) \
f(intx, CompileThresholdConstraintFunc) \
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/runtime/globals.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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") \
Expand Down

1 comment on commit da0f832

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.