Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
f52404a
Fix reference-chain revisits and leak candidate admission
kaahos Oct 23, 2026
7bb0c88
Index durable holders and stabilize reference-chain test prerequisites
kaahos Oct 23, 2026
5196c0e
Isolate seeded class histories to debug test hooks
kaahos Oct 23, 2026
6c08cec
referencechains: refresh indexed class tags, prune dead anchors, guar…
jbachorik Nov 13, 2026
f0e9900
liveness: pin scratch-overflow victim selection among equal retained …
jbachorik Nov 13, 2026
ce33cd8
leaking-cache: fix spotless formatting of the padded fixture
jbachorik Nov 13, 2026
26943f7
test-accessors: include livenessTracker.h for the fuzz target's Track…
jbachorik Nov 13, 2026
82113af
referencechains: prune ABANDONED frontier slots from the anchor index
jbachorik Nov 13, 2026
07a4e1b
test-accessors: keep fuzz-compatible tracker teardown
jbachorik Nov 16, 2026
19759fa
referencechains: harden anchor and liveness tracking
jbachorik Nov 19, 2026
571e449
tests: flush cached reference chains before failing
jbachorik Nov 19, 2026
fc4756b
referencechains: tighten tracker comments
jbachorik Nov 19, 2026
94ffce2
referencechains: preserve bounded anchor classification
jbachorik Nov 19, 2026
681359f
referencechains: keep incomplete shape lookups unclassified
jbachorik Nov 19, 2026
9ff697b
referencechains: treat null interface entries as incomplete
jbachorik Nov 19, 2026
803e7bf
refchain test: widen external-process leak-cache tail window (stacked…
jbachorik Nov 19, 2026
5dfc814
refchain test: trim tail comments to budget
jbachorik Nov 19, 2026
5c4467b
referencechains: count static fresh-queue overflow drops
jbachorik Nov 19, 2026
ecb5321
refchain test: rewrap javadoc for spotless
jbachorik Nov 19, 2026
a55a95d
referencechains: count budget-exhausted fresh-lane drops too
jbachorik Nov 19, 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
6 changes: 6 additions & 0 deletions ddprof-lib/src/main/cpp/counters.h
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,12 @@
* almost all classes" — if this tracks the total class count per lap, \
* the cap is too low; if it stays near zero, the cap is fine. */ \
X(REFERENCE_CHAIN_STATIC_SWEEP_CLASSES_CAPPED, "reference_chain_static_sweep_classes_capped") \
/* indexAnchorForRotation() fresh-queue overflow: a newly indexed anchor's \
* prioritized first look was lost, to a STATIC_ANCHOR_FRESH_CAP eviction or \
* to a rotation drain that exhausted its budget before the queue emptied - \
* the anchor keeps fair-tier coverage via _static_anchor_index, so this \
* gauges how often anchor bursts outpace the rotation drain. */ \
X(REFERENCE_CHAIN_STATIC_FRESH_DROPPED, "reference_chain_static_fresh_dropped") \
DD_COUNTER_TABLE_FAULT_INJECTION(X) \
DD_COUNTER_TABLE_FI_DEBUG(X) \
DD_COUNTER_TABLE_SAMPLER_PERF(X) \
Expand Down
6 changes: 2 additions & 4 deletions ddprof-lib/src/main/cpp/javaApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1226,12 +1226,10 @@ extern "C" DLLEXPORT void JNICALL
Java_com_datadoghq_profiler_JavaProfiler_seedKlassPopulationSample0(
JNIEnv *env, jclass unused, jint klassId, jint count, jlong epoch) {
ProfiledThread::initCurrentThreadSignalSafe();
int slot;
bool created;
jweak evicted[KlassPopulationEntry::MAX_REPRESENTATIVES_PER_KLASS];
int evicted_count = 0;
LivenessTracker::instance()->klassPopulationRecordForTest(
(u32)klassId, (u32)count, (u64)epoch, &slot, &created, evicted,
LivenessTracker::instance()->seedKlassPopulationSampleForTest(
(u32)klassId, (u32)count, (u64)epoch, evicted,
&evicted_count, KlassPopulationEntry::MAX_REPRESENTATIVES_PER_KLASS);
for (int i = 0; i < evicted_count; i++) {
if (evicted[i] != nullptr) {
Expand Down
44 changes: 36 additions & 8 deletions ddprof-lib/src/main/cpp/livenessTracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -877,15 +877,30 @@ void LivenessTracker::insertThreadGen(KlassCountScratch &scratch,
return;
}
}
int idx;
if (scratch.thread_count < KlassCountScratch::MAX_THREADS_PER_KLASS) {
int idx = scratch.thread_count++;
scratch.threads[idx].tid = tid;
scratch.threads[idx].ages[0] = age;
scratch.threads[idx].age_count = 1;
scratch.threads[idx].count = 1; // this object is the tid's first this epoch
}
// else: thread table full — additional threads are not tracked, but
// the oldest[] array still captures instances from all threads.
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;
Comment thread
jbachorik marked this conversation as resolved.
Resolved
}

void LivenessTracker::accumulateKlassCount(u32 klass_id, jlong age,
Expand Down Expand Up @@ -994,6 +1009,9 @@ jweak LivenessTracker::recordKlassPopulationSampleLocked(
_klass_population[slot].ring_head = 0;
_klass_population[slot].ring_fill = 0;
_klass_population[slot].consecutive_positive = 0;
#ifdef DEBUG
_klass_population[slot].test_seeded_history = false;
#endif
_klass_population[slot].cached_slope = 0.0;
// A reused (evicted) slot's previous class's per-tid trends must not
// leak onto the new one, same as the fields above.
Expand All @@ -1006,6 +1024,16 @@ jweak LivenessTracker::recordKlassPopulationSampleLocked(
}

KlassPopulationEntry &entry = _klass_population[slot];
#ifdef DEBUG
if (entry.test_seeded_history) {
// Real GC folds must not replace a JNI test fixture's seeded ramp with
// the sampled cohort's generation count. Keep its LRU epoch current.
entry.last_updated_epoch = epoch;
*out_slot = slot;
*out_created = created;
return evicted_ref;
}
#endif
entry.count_ring[entry.ring_head] = count;
entry.ring_head = (u8)((entry.ring_head + 1) % KLASS_POPULATION_RING_SIZE);
if (entry.ring_fill < KLASS_POPULATION_RING_SIZE) {
Expand Down
30 changes: 30 additions & 0 deletions ddprof-lib/src/main/cpp/livenessTracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ typedef struct KlassPopulationEntry {
// without this counter it gets reported as a leak candidate almost as
// often as a real leak does.
u8 consecutive_positive;
#ifdef DEBUG
// Explicit JNI test seeds own their class trend. Real GC folds preserve it
// until the test resets the population table or the entry is evicted.
bool test_seeded_history;
#endif
// Slope (regression value at the ring's newest sample minus the value at
// its oldest sample - see ringWindowStats, livenessTracker.cpp) as of the
// last push, computed and cached by hasQualifyingGrowth() alongside
Expand Down Expand Up @@ -1430,6 +1435,7 @@ class alignas(alignof(SpinLock)) LivenessTracker {
_klass_population_size--;
}

// Ordinary algorithm-test histories remain subject to GC updates and decay.
jweak klassPopulationRecordForTest(u32 klass_id, u32 count, u64 epoch,
int *out_slot, bool *out_created,
jweak *out_evicted = nullptr,
Expand All @@ -1446,6 +1452,30 @@ class alignas(alignof(SpinLock)) LivenessTracker {
return evicted;
}

#ifdef DEBUG
/**
* Protects explicit fixture class history from real GC updates.
* Later explicit seeds update the same ring and qualification counters.
*/
void seedKlassPopulationSampleForTest(
u32 klass_id, u32 count, u64 epoch, jweak *out_evicted = nullptr,
int *out_evicted_count = nullptr, int max_evicted = 0) {
ExclusiveLockGuard guard(&_table_lock);
klass_id = resolveTestKlassAliasLocked(klass_id);
for (int i = 0; i < _klass_population_size; i++) {
if (_klass_population[i].klass_id == klass_id) {
_klass_population[i].test_seeded_history = false;
break;
}
}
int slot;
bool created;
recordKlassPopulationSampleLocked(klass_id, count, epoch, &slot, &created,
out_evicted, out_evicted_count, max_evicted);
_klass_population[slot].test_seeded_history = true;
}
#endif

// Seeds one per-tid trend sample for tests/scenarios: pushes `count` as
// tid's epoch sample on klass_id's KlassPopulationEntry, marking the
// trend SYNTHETIC (exempt from the real fold's absent-tid decay and slot
Expand Down
Loading
Loading