Skip to content

Commit bd6259a

Browse files
committed
Fix clang scan-build findings in the tracker and engine
- collectStaticFieldAnchorsForRotation: the other tier is the last consumer of the anchor budget - stop accumulating its leftover back into budget_left (dead store). - buildCanaryChainEvent: capture the chain size before moving the vector into the event instead of reading the moved-from object for the log. - secondsToOOM: check ringThirdsStats()'s return for the time ring instead of reading time_stats uninitialized on its (unreachable-in- practice, but analyzer-visible) failure path - same head/fill/min-fill gate as the byte call, so it cannot trigger once the byte call passed.
1 parent de4603c commit bd6259a

2 files changed

Lines changed: 18 additions & 7 deletions

File tree

‎ddprof-lib/src/main/cpp/livenessTracker.cpp‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1374,10 +1374,18 @@ double LivenessTracker::secondsToOOM() const {
13741374
return -1;
13751375
}
13761376
RingThirdsStats time_stats;
1377-
ringThirdsStats(
1378-
head, fill, KLASS_POPULATION_RING_SIZE, KLASS_POPULATION_MIN_FILL_FOR_TREND,
1379-
[this](int i) { return (double)load(_heap_floor_time_ring[i]); },
1380-
&time_stats);
1377+
// Same head/fill/min-fill gate as the byte call above, so this cannot
1378+
// actually fail once have_byte_stats passed - but the analyzer cannot
1379+
// prove that equivalence across the two readers, and reading time_stats
1380+
// uninitialized on the (impossible) failure path is exactly the
1381+
// "garbage or undefined" finding. Check the result.
1382+
if (!ringThirdsStats(
1383+
head, fill, KLASS_POPULATION_RING_SIZE,
1384+
KLASS_POPULATION_MIN_FILL_FOR_TREND,
1385+
[this](int i) { return (double)load(_heap_floor_time_ring[i]); },
1386+
&time_stats)) {
1387+
return -1;
1388+
}
13811389

13821390
double bytes_delta = byte_stats.recent_mean - byte_stats.earliest_mean;
13831391
double time_delta_ns = time_stats.recent_mean - time_stats.earliest_mean;

‎ddprof-lib/src/main/cpp/referenceChains.cpp‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3674,8 +3674,10 @@ ReferenceChainTracker::collectStaticFieldAnchorsForRotation(int max_count) {
36743674
}
36753675
budget_left -= consume_tier_fair(container_picks, _anchor_container_cursor,
36763676
budget_left);
3677-
budget_left -= consume_tier_fair(other_picks, _anchor_other_cursor,
3678-
budget_left);
3677+
// The other tier is the last consumer of the budget - its leftover has no
3678+
// further reader, so don't accumulate it back into budget_left (a dead
3679+
// store clang scan-build flags).
3680+
consume_tier_fair(other_picks, _anchor_other_cursor, budget_left);
36793681
return selected;
36803682
}
36813683

@@ -6079,10 +6081,11 @@ bool ReferenceChainTracker::buildCanaryChainEvent(int candidate_idx,
60796081
out->_target_tag = (u64)frontier_tag;
60806082
out->_depth = _candidate_depths[candidate_idx];
60816083
out->_root_kind = root_kind;
6084+
const size_t chain_size = chain.size();
60826085
out->_chain = std::move(chain);
60836086
TEST_LOG_SUMMARY("ReferenceChainTracker::buildCanaryChainEvent candidate=%d "
60846087
"parent_tag=%lld chain_size=%zu",
6085-
candidate_idx, (long long)parent_tag, chain.size());
6088+
candidate_idx, (long long)parent_tag, chain_size);
60866089
return true;
60876090
}
60886091

0 commit comments

Comments
 (0)