wip
Some checks failed
📊 Benchmark the Runtime / release (pull_request) Failing after 1m16s
🚀 Lint & Test & Deploy / release (pull_request) Failing after 1m19s

This commit is contained in:
2026-01-23 14:11:27 +01:00
parent 4cb24e8ff9
commit be8161ec8d
4 changed files with 25 additions and 24 deletions

View File

@@ -82,14 +82,14 @@ export type Pointer = {
perf?: PerformanceStore;
constructor(
private readonly registry: NodeRegistry,
public cache?: SyncCache<Int32Array>
) {
this.cache = undefined;
this.refreshView();
log.info('MemoryRuntimeExecutor initialized');
}
constructor(
private readonly registry: NodeRegistry,
public cache?: SyncCache<Int32Array>
) {
this.cache = undefined;
this.refreshView();
log.info('MemoryRuntimeExecutor initialized');
}
private refreshView(): void {
this.memoryView = new Int32Array(this.memory.buffer);

View File

@@ -125,7 +125,7 @@ pub fn nodarium_execute(_attr: TokenStream, item: TokenStream) -> TokenStream {
unsafe {
let src = result.as_ptr() as *const u8;
let dst = output_pos as *mut u8;
// nodarium_utils::log!("writing output_pos={:?} src={:?} len_bytes={:?}", output_pos, src, len_bytes);
nodarium_utils::log!("writing output_pos={:?} src={:?} len_bytes={:?}", output_pos, src, len_bytes);
dst.copy_from_nonoverlapping(src, len_bytes);
}

View File

@@ -9,52 +9,52 @@ extern "C" {
#[allow(dead_code)]
const WASM_PAGE_SIZE: usize = 64 * 1024;
pub struct DownwardBumpAllocator {
heap_top: AtomicUsize,
pub struct UpwardBumpAllocator {
heap_base: AtomicUsize,
}
impl Default for DownwardBumpAllocator {
impl Default for UpwardBumpAllocator {
fn default() -> Self {
Self::new()
}
}
impl DownwardBumpAllocator {
impl UpwardBumpAllocator {
pub const fn new() -> Self {
Self {
heap_top: AtomicUsize::new(0),
heap_base: AtomicUsize::new(0),
}
}
#[allow(dead_code)]
pub fn init(&self) {
let pages = unsafe { __wasm_memory_size() };
let mem_size = pages * WASM_PAGE_SIZE;
self.heap_top.store(mem_size, Ordering::Relaxed);
// Start heap at 10000 to leave space for data sections
self.heap_base.store(10000, Ordering::Relaxed);
}
}
#[global_allocator]
pub static ALLOCATOR: DownwardBumpAllocator = DownwardBumpAllocator::new();
pub static ALLOCATOR: UpwardBumpAllocator = UpwardBumpAllocator::new();
unsafe impl GlobalAlloc for DownwardBumpAllocator {
unsafe impl GlobalAlloc for UpwardBumpAllocator {
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
let align = layout.align();
let size = layout.size();
let mut current = self.heap_top.load(Ordering::Relaxed);
let mut current = self.heap_base.load(Ordering::Relaxed);
loop {
let aligned = (current - size) & !(align - 1);
let aligned = (current + align - 1) & !(align - 1);
let new_current = aligned + size;
let manual_end = unsafe { __nodarium_manual_end() };
if aligned < manual_end {
if new_current > manual_end {
return core::ptr::null_mut();
}
match self.heap_top.compare_exchange(
match self.heap_base.compare_exchange(
current,
aligned,
new_current,
Ordering::SeqCst,
Ordering::Relaxed,
) {

View File

@@ -31,6 +31,7 @@ pub fn read_f32(ptr: i32) -> f32 {
#[inline]
pub fn read_i32_slice(range: (i32, i32)) -> Vec<i32> {
log!("read_i32_slice ptr: {:?}", range);
let (start, end) = range;
assert!(end >= start);
let byte_len = (end - start) as usize;