Fix some "possible" divide by 0
Bug: 28529431
Change-Id: I61f638926b2ae63c5f883fc2cfdce19b00ce79c8
diff --git a/oatdump/oatdump.cc b/oatdump/oatdump.cc
index aa4635d..7239a47 100644
--- a/oatdump/oatdump.cc
+++ b/oatdump/oatdump.cc
@@ -1978,7 +1978,7 @@
size_t sum_of_expansion = 0;
size_t sum_of_expansion_squared = 0;
size_t n = method_outlier_size.size();
- if (n == 0) {
+ if (n <= 1) {
return;
}
for (size_t i = 0; i < n; i++) {
diff --git a/runtime/gc/space/region_space.cc b/runtime/gc/space/region_space.cc
index 5d710bf..2d71294 100644
--- a/runtime/gc/space/region_space.cc
+++ b/runtime/gc/space/region_space.cc
@@ -126,15 +126,20 @@
} else {
bool is_live_percent_valid = live_bytes_ != static_cast<size_t>(-1);
if (is_live_percent_valid) {
- uint live_percent = GetLivePercent();
+ DCHECK(IsInToSpace());
+ DCHECK(!IsLargeTail());
+ DCHECK_NE(live_bytes_, static_cast<size_t>(-1));
+ DCHECK_LE(live_bytes_, BytesAllocated());
+ const size_t bytes_allocated = RoundUp(BytesAllocated(), kRegionSize);
+ DCHECK_LE(live_bytes_, bytes_allocated);
if (IsAllocated()) {
// Side node: live_percent == 0 does not necessarily mean
// there's no live objects due to rounding (there may be a
// few).
- result = live_percent < kEvaculateLivePercentThreshold;
+ result = live_bytes_ * 100U < kEvaculateLivePercentThreshold * bytes_allocated;
} else {
DCHECK(IsLarge());
- result = live_percent == 0U;
+ result = live_bytes_ == 0U;
}
} else {
result = false;
diff --git a/runtime/gc/space/region_space.h b/runtime/gc/space/region_space.h
index 4e8dfe8..823aa38 100644
--- a/runtime/gc/space/region_space.h
+++ b/runtime/gc/space/region_space.h
@@ -395,18 +395,6 @@
return live_bytes_;
}
- uint GetLivePercent() const {
- DCHECK(IsInToSpace());
- DCHECK(!IsLargeTail());
- DCHECK_NE(live_bytes_, static_cast<size_t>(-1));
- DCHECK_LE(live_bytes_, BytesAllocated());
- size_t bytes_allocated = RoundUp(BytesAllocated(), kRegionSize);
- DCHECK_GE(bytes_allocated, 0U);
- uint result = (live_bytes_ * 100U) / bytes_allocated;
- DCHECK_LE(result, 100U);
- return result;
- }
-
size_t BytesAllocated() const {
if (IsLarge()) {
DCHECK_LT(begin_ + kRegionSize, top_);