Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
89082bd
refchain: journal-based anchor observations, tiered selection and ind…
jbachorik Nov 23, 2026
73cd303
liveness: per-class thread-trend scratch with bounded challenger pool
jbachorik Nov 23, 2026
a13427f
test: reference-chain and liveness native coverage
jbachorik Nov 23, 2026
de80f88
test: reference-chain Java scenarios and quarantine refresh
jbachorik Nov 23, 2026
ab701fc
doc: live-heap reference chains implementation and collection summary
jbachorik Nov 23, 2026
c7addf3
doc: fold the anchor-index facts into one section
jbachorik Nov 22, 2026
2610bca
refchain: guard the class-tag map rebuild and fix the journal comment
jbachorik Nov 22, 2026
9d295a1
refchain+ liveness: address datadog-code-review findings on 343d09913
jbachorik Nov 22, 2026
3e6deb2
refchain+liveness: address the second datadog-code-review round on th…
jbachorik Nov 23, 2026
6dbf656
refchain: enforce the durable cap on re-enlist replay promotion and k…
jbachorik Nov 23, 2026
0db90ac
refchain: reclaim dead anchor entries in the rotation selection scan
jbachorik Nov 23, 2026
9dbceb3
refchain: trim oversized comments and drop stale quarantine header
jbachorik Nov 23, 2026
7834fbf
refchain: reserve the dead-entry scratch before the shared lock
jbachorik Nov 23, 2026
fb4a5f1
refchain: walk evicted non-container anchors on their preserved fresh…
jbachorik Nov 24, 2026
68a4522
refchain: keep sweep and enumeration report stamps separate and bound…
jbachorik Nov 24, 2026
6f6f011
test: drop the stale PROF-16305 quarantine history block
jbachorik Nov 24, 2026
b04e060
refchain: clear the sweep stamp on insert and bias it off the unstamp…
jbachorik Nov 24, 2026
ab1bec1
refchain: re-register existing threads when a failed BFS join reopens…
jbachorik Nov 24, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions ddprof-lib/src/main/cpp/counters.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,9 @@
* signal for spotting a recurrence. */ \
X(METADATA_TREE_NULL_CHILD, "metadata_tree_null_child") \
X(METADATA_TREE_DEPTH_EXCEEDED, "metadata_tree_depth_exceeded") \
/* A resolved datadog.ReferenceChain could not be cached in \
* ReferenceChainTracker::_resolved_chains (referenceChains.h): a brand-new \
* leak-candidate klass arrived with the cache already at \
* MAX_RESOLVED_CHAINS, so its chain is dropped rather than evicting some \
* other still-live sample's chain. See that constant's own comment. */ \
/* A reference-chain event could not be retained for a future dump: a \
* bounded cache or queue was full, or invalidation overflow cleared the \
* resolved-chain cache to avoid emitting stale output. */ \
X(REFERENCE_CHAIN_EVENTS_DROPPED, "reference_chain_events_dropped") \
/* ReferenceChainTracker::releaseSearchTags() (referenceChains.cpp) failed \
* to call GetObjectsWithTags() for at least one batch - the search's tag \
Expand Down
178 changes: 1 addition & 177 deletions ddprof-lib/src/main/cpp/livenessTracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -843,66 +843,6 @@ int LivenessTracker::tagLeakInstances(jvmtiEnv *jvmti,
return tagged;
}

void LivenessTracker::insertThreadGen(KlassCountScratch &scratch,
jint tid, u32 age) {
// Find or create the thread entry for this tid
for (int i = 0; i < scratch.thread_count; i++) {
if (scratch.threads[i].tid == tid) {
// Insert age into the thread's sorted distinct-age array
auto &t = scratch.threads[i];
// Every surviving object counts toward the per-tid retained-count
// bar (TID_RETAINED_COUNT_BAR) BEFORE the age-dedup early return
// below: the count is per-instance, the ages are per-cohort.
t.count++;
for (u32 j = 0; j < t.age_count; j++) {
if (t.ages[j] == age) {
return; // age already counted for this thread
}
}
if (t.age_count < KlassCountScratch::MAX_AGES_PER_THREAD) {
// Insert sorted (small array, linear scan + shift)
u32 pos = t.age_count;
for (u32 j = 0; j < t.age_count; j++) {
if (age < t.ages[j]) {
pos = j;
break;
}
}
for (u32 j = t.age_count; j > pos; j--) {
t.ages[j] = t.ages[j - 1];
}
t.ages[pos] = age;
t.age_count++;
}
return;
}
}
int idx;
if (scratch.thread_count < KlassCountScratch::MAX_THREADS_PER_KLASS) {
idx = scratch.thread_count++;
} else {
// Keeping only the first tids hides later, larger one-shot cohorts behind
// early small allocations. Replace the smallest observed retained set;
// ties prefer keeping the tid with more distinct surviving ages.
idx = 0;
for (int i = 1; i < scratch.thread_count; i++) {
const auto &candidate = scratch.threads[i];
const auto &victim = scratch.threads[idx];
if (candidate.count < victim.count ||
(candidate.count == victim.count && candidate.age_count < victim.age_count)) {
idx = i;
}
}
}
// Count only objects observed since this tid entered the scratch. Inherit
// neither the evicted tid's count nor its ages: both feed qualification.
// Reappearing tids can be undercounted at capacity, never overcounted.
scratch.threads[idx].tid = tid;
scratch.threads[idx].ages[0] = age;
scratch.threads[idx].age_count = 1;
scratch.threads[idx].count = 1;
}

void LivenessTracker::accumulateKlassCount(u32 klass_id, jlong age,
jweak sample_source,
jint tid) {
Expand Down Expand Up @@ -948,6 +888,7 @@ void LivenessTracker::accumulateKlassCount(u32 klass_id, jlong age,
slot.ages.push_back((u32)age);
slot.oldest_count = 0;
slot.thread_count = 0;
slot.challenger_count = 0;
insertOldestSample(slot, sample_source, (u32)age, tid);
insertThreadGen(slot, tid, (u32)age);
}
Expand Down Expand Up @@ -1380,123 +1321,6 @@ bool LivenessTracker::tidPushQualifies(
return hasQualifyingTidGrowth(trend);
}

void LivenessTracker::recordTidTrendSamplesLocked(
int slot, const KlassCountScratch &scratch) {
if (slot < 0 || slot >= _klass_population_size) {
return;
}
KlassPopulationEntry &entry = _klass_population[slot];
// Present tids first: find-or-create their trend and push this epoch's
// distinct-age count. (KlassCountScratch threads always carry >=1
// surviving instance, so every scratch thread has a real claim on a
// slot; a zero-count tid never reaches this fold.)
for (int ti = 0; ti < scratch.thread_count; ti++) {
jint tid = scratch.threads[ti].tid;
KlassPopulationEntry::TidTrend *trend = nullptr;
for (int i = 0; i < entry.tid_trend_count; i++) {
if (entry.tid_trends[i].tid == tid) {
trend = &entry.tid_trends[i];
break;
}
}
if (trend != nullptr && trend->synthetic) {
// Seam-owned history: the test maintains this ramp itself
// (seedTidTrendSample0), and a real fold interleaving its own low
// count for the same tid would reset the trend's hysteresis every
// System.gc() the scenario runs between rounds. Production data has
// no synthetic trends, so this exemption is inert there.
continue;
}
if (trend == nullptr) {
if (entry.tid_trend_count < KlassPopulationEntry::MAX_TID_TRENDS) {
trend = &entry.tid_trends[entry.tid_trend_count++];
} else {
// Full: evict the WEAKEST non-synthetic trend (lowest
// consecutive_positive, then lowest ring_fill) - a genuinely rising
// leak tid accumulates hysteresis fast and resists eviction, while
// machinery tids never build any. Synthetic (test-seeded) trends
// are never evicted by real data. If every slot is synthetic, the
// new tid is simply dropped - production data never marks
// anything synthetic, so this only caps a scenario's own seeding.
int victim = -1;
for (int i = 0; i < entry.tid_trend_count; i++) {
if (entry.tid_trends[i].synthetic) {
continue;
}
if (victim < 0 ||
(entry.tid_trends[i].consecutive_positive <
entry.tid_trends[victim].consecutive_positive) ||
(entry.tid_trends[i].consecutive_positive ==
entry.tid_trends[victim].consecutive_positive &&
entry.tid_trends[i].ring_fill <
entry.tid_trends[victim].ring_fill)) {
victim = i;
}
}
if (victim < 0) {
continue; // all slots synthetic - drop this tid's sample
}
trend = &entry.tid_trends[victim];
}
trend->tid = tid;
trend->ring_head = 0;
trend->ring_fill = 0;
trend->consecutive_positive = 0;
trend->synthetic = false;
}
trend->ring[trend->ring_head] = (u8)scratch.threads[ti].age_count;
trend->count_ring[trend->ring_head] =
(u8)std::min<u32>(scratch.threads[ti].count, UINT8_MAX);
trend->ring_head = (u8)((trend->ring_head + 1) %
KlassPopulationEntry::TID_TREND_RING_SIZE);
if (trend->ring_fill < KlassPopulationEntry::TID_TREND_RING_SIZE) {
trend->ring_fill++;
}
if (tidPushQualifies(*trend, scratch.threads[ti].count)) {
if (trend->consecutive_positive < UINT8_MAX) {
trend->consecutive_positive++;
}
} else {
trend->consecutive_positive = 0;
}
}
// Tracked tids ABSENT this epoch: a thread whose instances all died
// must not keep a stale rising ring - push 0 so the next
// hasQualifyingTidGrowth() fails and the trend's hysteresis resets (the
// per-tid analogue of the population simply stopping). Synthetic
// (test-seeded) trends are exempt: scenarios interleave real
// System.gc()-driven folds with their seeded ramps, and without the
// exemption every real fold would wipe the seeded qualification before
// the test could ever use it (see TidTrend::synthetic's own comment).
for (int i = 0; i < entry.tid_trend_count; i++) {
KlassPopulationEntry::TidTrend &trend = entry.tid_trends[i];
if (trend.synthetic) {
continue;
}
bool present = false;
for (int ti = 0; ti < scratch.thread_count; ti++) {
if (scratch.threads[ti].tid == trend.tid) {
present = true;
break;
}
}
if (present) {
continue;
}
trend.ring[trend.ring_head] = 0;
trend.count_ring[trend.ring_head] = 0;
trend.ring_head = (u8)((trend.ring_head + 1) %
KlassPopulationEntry::TID_TREND_RING_SIZE);
if (trend.ring_fill < KlassPopulationEntry::TID_TREND_RING_SIZE) {
trend.ring_fill++;
}
// A 0-count epoch cannot qualify as a rise - reset now rather than
// deferring to the next push, so a long-absent tid does not keep
// hysteresis from before its population died.
trend.consecutive_positive = 0;
}
}

u64 LivenessTracker::newestHeapFloorSample(u64 *seq_out) const {
// Per-slot seqlock read: the slot's seq validates the payload below it
// (writer: recordHeapFloorSampleUnchecked()). Bounded retry, never a torn
Expand Down
21 changes: 20 additions & 1 deletion ddprof-lib/src/main/cpp/livenessTracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ typedef struct KlassCandidate {
class alignas(alignof(SpinLock)) LivenessTracker {
friend Recording;
friend class LivenessTrackerTestAccessor;
friend class LivenessThreadTrendTestAccessor;

private:
// pre-c++17 we should mark these inline(or out of class)
Expand Down Expand Up @@ -572,6 +573,7 @@ class alignas(alignof(SpinLock)) LivenessTracker {
// generations. Thread ID is stable and naturally separates leak
// threads from noise threads.
static constexpr int MAX_THREADS_PER_KLASS = 16;
static constexpr int MAX_THREAD_CHALLENGERS_PER_KLASS = 4;
static constexpr int MAX_AGES_PER_THREAD = 32;
struct ThreadGens {
jint tid;
Expand All @@ -584,7 +586,15 @@ class alignas(alignof(SpinLock)) LivenessTracker {
};
ThreadGens threads[MAX_THREADS_PER_KLASS];
int thread_count;
// New tids accrue evidence separately when every incumbent meets the retained-count bar.
// At fold, only a challenger that outranks the weakest incumbent replaces a primary slot.
ThreadGens challengers[MAX_THREAD_CHALLENGERS_PER_KLASS];
int challenger_count;
} KlassCountScratch;
static_assert(sizeof(KlassCountScratch::ThreadGens) *
KlassCountScratch::MAX_THREAD_CHALLENGERS_PER_KLASS *
MAX_KLASS_POPULATION_ENTRIES == 143360,
"four-thread challenger scratch must stay within its approved budget");
KlassCountScratch _klass_count_scratch[MAX_KLASS_POPULATION_ENTRIES];
int _klass_count_scratch_size;

Expand Down Expand Up @@ -761,6 +771,15 @@ class alignas(alignof(SpinLock)) LivenessTracker {
void insertOldestSample(KlassCountScratch &scratch, jweak sample_source,
u32 age, jint tid);
void insertThreadGen(KlassCountScratch &scratch, jint tid, u32 age);
// `displaced` (optional, capacity MAX_THREAD_CHALLENGERS_PER_KLASS) receives the incumbents
// promotion replaced, with their pre-replacement epoch sample. `unpromoted` (same capacity)
// receives the challengers promotion could not place: the fold keeps their live sample for a
// tracked trend, like the displaced incumbents', instead of writing them a zero epoch.
void promoteThreadGenCandidates(
KlassCountScratch &scratch, KlassCountScratch::ThreadGens *displaced = nullptr,
int *displaced_count = nullptr,
KlassCountScratch::ThreadGens *unpromoted = nullptr,
int *unpromoted_count = nullptr);

// Pushes `count` into klass_id's ring buffer, creating the entry (evicting
// the least-recently-updated entry first if the table is already at
Expand Down Expand Up @@ -867,7 +886,7 @@ class alignas(alignof(SpinLock)) LivenessTracker {
// tracked tid from the scratch and push it a spurious 0 - the same
// fixed-capacity best-effort the scratch itself already accepts.
// _table_lock held exclusively by the caller (foldKlassCountsLocked()).
void recordTidTrendSamplesLocked(int slot, const KlassCountScratch &scratch);
void recordTidTrendSamplesLocked(int slot, KlassCountScratch &scratch);

// The sustained-trend gate (this class's own header comment above,
// "Sustained-trend gate") - both-required growth-magnitude and floor-rise
Expand Down
Loading
Loading