Use typed allocators in more places (#12899)

This commit is contained in:
Jarred Sumner
2024-07-28 18:37:35 -07:00
committed by GitHub
parent 4199fd4515
commit a5ba02804f
16 changed files with 189 additions and 191 deletions

View File

@@ -646,6 +646,10 @@ export fn Bun__getVerboseFetchValue() i32 {
};
}
const body_value_pool_size = if (bun.heap_breakdown.enabled) 0 else 256;
pub const BodyValueRef = bun.HiveRef(JSC.WebCore.Body.Value, body_value_pool_size);
const BodyValueHiveAllocator = bun.HiveArray(BodyValueRef, body_value_pool_size).Fallback;
/// TODO: rename this to ScriptExecutionContext
/// This is the shared global state for a single JS instance execution
/// Today, Bun is one VM per thread, so the name "VirtualMachine" sort of makes sense
@@ -781,10 +785,16 @@ pub const VirtualMachine = struct {
debug_thread_id: if (Environment.allow_assert) std.Thread.Id else void,
body_value_hive_allocator: BodyValueHiveAllocator = undefined,
pub const OnUnhandledRejection = fn (*VirtualMachine, globalObject: *JSC.JSGlobalObject, JSC.JSValue) void;
pub const OnException = fn (*ZigException) void;
pub fn initRequestBodyValue(this: *VirtualMachine, body: JSC.WebCore.Body.Value) !*BodyValueRef {
return BodyValueRef.init(body, &this.body_value_hive_allocator);
}
pub fn uwsLoop(this: *const VirtualMachine) *uws.Loop {
if (comptime Environment.isPosix) {
if (Environment.allow_assert) {
@@ -1485,7 +1495,7 @@ pub const VirtualMachine = struct {
vm.* = VirtualMachine{
.global = undefined,
.transpiler_store = RuntimeTranspilerStore.init(allocator),
.transpiler_store = RuntimeTranspilerStore.init(),
.allocator = allocator,
.entry_point = ServerEntryPoint{},
.bundler = bundler,
@@ -1555,6 +1565,7 @@ pub const VirtualMachine = struct {
}
vm.configureDebugger(opts.debugger);
vm.body_value_hive_allocator = BodyValueHiveAllocator.init(bun.typedAllocator(JSC.WebCore.Body.Value));
return vm;
}
@@ -1600,7 +1611,7 @@ pub const VirtualMachine = struct {
vm.* = VirtualMachine{
.global = undefined,
.transpiler_store = RuntimeTranspilerStore.init(allocator),
.transpiler_store = RuntimeTranspilerStore.init(),
.allocator = allocator,
.entry_point = ServerEntryPoint{},
.bundler = bundler,
@@ -1674,6 +1685,7 @@ pub const VirtualMachine = struct {
}
vm.configureDebugger(opts.debugger);
vm.body_value_hive_allocator = BodyValueHiveAllocator.init(bun.typedAllocator(JSC.WebCore.Body.Value));
return vm;
}
@@ -1748,7 +1760,7 @@ pub const VirtualMachine = struct {
vm.* = VirtualMachine{
.global = undefined,
.allocator = allocator,
.transpiler_store = RuntimeTranspilerStore.init(allocator),
.transpiler_store = RuntimeTranspilerStore.init(),
.entry_point = ServerEntryPoint{},
.bundler = bundler,
.console = console,
@@ -1816,6 +1828,7 @@ pub const VirtualMachine = struct {
source_code_printer.?.* = js_printer.BufferPrinter.init(writer);
source_code_printer.?.ctx.append_null_byte = false;
}
vm.body_value_hive_allocator = BodyValueHiveAllocator.init(bun.typedAllocator(JSC.WebCore.Body.Value));
return vm;
}