implement PLN-0034 internal allocation evidence

This commit is contained in:
2026-04-20 08:50:01 +01:00
parent 09821cf9cc
commit 811af09ea7
13 changed files with 125 additions and 8 deletions
+9 -1
View File
@@ -3,7 +3,7 @@ use crate::object::{ObjectHeader, ObjectKind};
use prometeu_bytecode::{HeapRef, Value};
use std::sync::Arc;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::atomic::{AtomicU64, AtomicUsize, Ordering};
/// Internal stored object: header plus opaque payload bytes.
#[derive(Debug, Clone)]
@@ -79,6 +79,8 @@ pub struct Heap {
/// Total bytes currently used by all objects in the heap.
pub used_bytes: Arc<AtomicUsize>,
/// Monotonic count of heap allocation events for internal engineering telemetry.
pub allocation_count: Arc<AtomicU64>,
}
impl Heap {
@@ -87,11 +89,13 @@ impl Heap {
objects: Vec::new(),
free_list: Vec::new(),
used_bytes: Arc::new(AtomicUsize::new(0)),
allocation_count: Arc::new(AtomicU64::new(0)),
}
}
fn insert_object(&mut self, obj: StoredObject) -> HeapRef {
self.used_bytes.fetch_add(obj.bytes(), Ordering::Relaxed);
self.allocation_count.fetch_add(1, Ordering::Relaxed);
if let Some(idx) = self.free_list.pop() {
debug_assert!(self.objects.get(idx).is_some_and(|slot| slot.is_none()));
self.objects[idx] = Some(obj);
@@ -411,6 +415,10 @@ impl Heap {
self.objects.iter().filter(|s| s.is_some()).count()
}
pub fn allocation_count(&self) -> u64 {
self.allocation_count.load(Ordering::Relaxed)
}
/// Enumerate handles of coroutines that are currently suspended (i.e., not running):
/// Ready or Sleeping. These must be treated as GC roots by the runtime so their
/// stacks/frames are scanned during mark.