luagc: 5.1 incremental GC with timing, stress tests, pre-alloc hooks (BROKEN)

Current state CRASHES on load due to pre-alloc hooks with wrong calling
conventions. pushcclosure hook is still enabled with partially disabled
others. Needs all pre-alloc hooks disabled or CCs fixed before use.

Implemented:
- Full 5.1 tri-color incremental GC
- 5.1-style singlestep budget loop (replaces chunk-based approach)
- Per-step rdtsc timing (ZGCStats returns max_step_us, atomic_us)
- Configurable gcstepsize/gcstepmul/gcpause via ZGCTune()
- Pre-alloc GC hooks for 7 API functions (5.1 luaC_checkGC pattern)
- Stress test addon: /gclife, /gcsweep, /gccompare

Broken:
- Pre-alloc hooks have CC mismatches causing immediate crash on load
- pushfstring is cdecl variadic, not fastcall (removed)
- pushstring has ambiguous CC (removed, covered by pushlstring)
- pushcclosure hook still active -- may be causing the crash
- Half-initialized objects cause garbage gcptr under heavy stress

weirdperformance: re-enabled luagc.install() + luastr + luavm
This commit is contained in:
MarcelineVQ
2026-04-11 13:03:37 -07:00
parent 8d3460cf1e
commit 039cec1806
7 changed files with 1255 additions and 136 deletions
+7 -3
View File
@@ -24,7 +24,7 @@ const build_opts = struct {
const silicon = @import("build_options").enable_silicon;
const weirdperformance = @import("build_options").enable_weirdperformance;
const superweirdo = @import("build_options").enable_superweirdo;
const luavm = @import("build_options").enable_luavm;
const luagc = @import("build_options").enable_luagc;
};
// Conditional module imports
@@ -47,7 +47,7 @@ const ssemaths = if (build_opts.ssemaths) @import("ssemaths/ssemaths.zig") else
const silicon = if (build_opts.silicon) @import("silicon/silicon.zig") else struct {};
const weirdperformance = if (build_opts.weirdperformance) @import("weirdperformance/weirdperformance.zig") else struct {};
const superweirdo = if (build_opts.superweirdo) @import("superweirdo/superweirdo.zig") else struct {};
const luavm = if (build_opts.luavm) @import("luavm/luavm.zig") else struct {};
const luagc_mod = if (build_opts.luagc) @import("luagc/luagc.zig") else struct {};
const module_active = @import("module_active.zig");
@@ -127,6 +127,10 @@ fn registerLuaFunctions() void {
registerFunction("ResetAddOnCPUUsage", @intFromPtr(&addonperf.luaResetAddOnCPUUsage));
registerFunction("GetScriptCPUUsage", @intFromPtr(&addonperf.luaGetScriptCPUUsage));
}
if (build_opts.luagc and luagc_mod.isActive()) {
registerFunction("ZGCStats", @intFromPtr(&luagc_mod.luaZGCStats));
registerFunction("ZGCTune", @intFromPtr(&luagc_mod.luaZGCTune));
}
if (build_opts.worldmarkers and markers.isActive()) {
// User-facing functions stay global
registerFunction("WorldMarker", @intFromPtr(&markers.luaWorldMarker));
@@ -788,7 +792,7 @@ const modules = [_]ModuleHooks{
if (build_opts.silicon) .{ .name = silicon.module_name, .install = silicon.installHooks, .remove = silicon.removeHooks, .is_active = silicon.isActive } else .{},
if (build_opts.weirdperformance) .{ .name = weirdperformance.module_name, .install = weirdperformance.installHooks, .remove = weirdperformance.removeHooks, .is_active = weirdperformance.isActive, .remove_on_shutdown = true } else .{},
if (build_opts.superweirdo) .{ .name = superweirdo.module_name, .install = superweirdo.installHooks, .remove = superweirdo.removeHooks, .is_active = superweirdo.isActive } else .{},
if (build_opts.luavm) .{ .name = luavm.module_name, .install = luavm.installHooks, .remove = luavm.removeHooks, .is_active = luavm.isActive } else .{},
if (build_opts.luagc) .{ .name = luagc_mod.module_name, .install = luagc_mod.installHooks, .remove = luagc_mod.removeHooks, .is_active = luagc_mod.isActive } else .{},
};
fn shutdownDetour() callconv(hook.cc.stdcall) void {