code wiki / _hdl_build / nx_js_octane_memcensus.nx

nx_js_octane_memcensus.nx source

↩ module page · 44 lines · 2998 B

1// nx_js_octane_memcensus.nx -- QUANTIFY the GC debt: run each real Octane benchmark ONCE and report the 2// per-benchmark pool growth (KB + alloc count). Since the object/array/string pool never frees, cumulative 3// allocation == resident growth for that run; ×N for the real Octane harness (which runs each ~1s). This 4// tells us EXACTLY which benchmarks need GC and how badly -- before building a (high-risk) collector. 5// expect_exit: 0 license_tier: ORIGINAL 6import "nx_js_vm.nx" 7const K_MAGIC_262144: i64 = 262144 8const K_MAGIC_1024: i64 = 1024 9func w(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 10func nn(v: i64) -> i64 { if v==0 { sys_write(1,"0" as *u8,1); return 0 } var m: i64=v; if m<0 { sys_write(1,"-" as *u8,1); m=0-m } let t: *u8=sys_mmap(24); var k: i64=0; while m>0 { t[k]=(48+(m%10)) as u8; m=m/10; k=k+1 } let o: *u8=sys_mmap(24); var q: i64=k-1; var x: i64=0; while q>=0 { o[x]=t[q]; x=x+1; q=q-1 } sys_write(1,o,x); return 0 } 11func run_one(path: *u8, label: *u8) -> i64 { 12 let kb0: i64 = nx_pool_total_kb() 13 let ac0: i64 = nx_pool_alloc_count() 14 let fd: i64 = sys_openat_rd(path) 15 if fd < 0 { w(" " as *u8); w(label); w(": (skip - no file)\n" as *u8); return 0 } 16 let cap: i64 = K_MAGIC_262144 17 let buf: *u8 = sys_mmap(cap + 8) 18 var total: i64 = 0 19 var done: i64 = 0 20 while done == 0 { let n: i64 = sys_read(fd, ((buf as i64) + total) as *u8, cap - total); if n <= 0 { done = 1 } else { total = total + n } } 21 sys_close(fd) 22 buf[total] = 0 as u8 23 let out: *i64 = sys_mmap(16) as *i64 24 let rc: i64 = compile_run(buf, out) 25 let dkb: i64 = nx_pool_total_kb() - kb0 26 let dac: i64 = nx_pool_alloc_count() - ac0 27 w(" " as *u8); w(label); w(": rc=" as *u8); nn(rc); w(" pool +" as *u8); nn(dkb); w("KB allocs +" as *u8); nn(dac) 28 if dac > 0 { w(" (~" as *u8); nn(dkb * K_MAGIC_1024 / dac); w("B/alloc)" as *u8) } 29 w("\n" as *u8) 30 return dkb 31} 32func main(argc: i64, argv: *i64) -> i64 { 33 gc_enable(0) // GC is default-ON now; this census measures UNCOLLECTED pool growth, so turn it off 34 w("=== nx_js_octane_memcensus: per-benchmark pool growth (1 iteration; pool never frees) ===\n" as *u8) 35 run_one("knowledge/octane/richards_eng.js\x00" as *u8, "Richards " as *u8) 36 run_one("knowledge/octane/splay_eng.js\x00" as *u8, "Splay " as *u8) 37 run_one("knowledge/octane/navier_eng.js\x00" as *u8, "NavierStokes" as *u8) 38 run_one("knowledge/octane/crypto_eng.js\x00" as *u8, "Crypto " as *u8) 39 run_one("knowledge/octane/deltablue_eng.js\x00" as *u8, "DeltaBlue " as *u8) 40 run_one("knowledge/octane/raytrace_eng.js\x00" as *u8, "RayTrace " as *u8) 41 w(" --- total pool now " as *u8); nn(nx_pool_total_mb()); w("MB over " as *u8); nn(nx_pool_alloc_count()); w(" allocs ---\n" as *u8) 42 w("=== interpret: single-iter KB x (Octane runs-per-second) = resident without GC; >~500MB/run = GC-blocked ===\n" as *u8) 43 return 0 44}