mirror of
https://github.com/oven-sh/bun
synced 2026-02-03 07:28:53 +00:00
Compare commits
70 Commits
dylan/byte
...
kai/memory
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
35ed97df45 | ||
|
|
9e0b1bc337 | ||
|
|
83704566e5 | ||
|
|
e19dc02220 | ||
|
|
aea0a2daad | ||
|
|
886164558e | ||
|
|
de975a9689 | ||
|
|
9616c88583 | ||
|
|
65714b0127 | ||
|
|
ad49ebf702 | ||
|
|
700942390a | ||
|
|
658406129a | ||
|
|
86aac268c2 | ||
|
|
fd0a783da0 | ||
|
|
0fe3ba3a45 | ||
|
|
82a32e632a | ||
|
|
8aaac791ff | ||
|
|
2cdc8abe12 | ||
|
|
ba9a49e3d6 | ||
|
|
5772f5daa5 | ||
|
|
a687d7553a | ||
|
|
8a4d76b43d | ||
|
|
1768fd7ec7 | ||
|
|
269d078862 | ||
|
|
0ecb121199 | ||
|
|
5fa4c6766c | ||
|
|
87160c88ef | ||
|
|
f61209114c | ||
|
|
b63bb99638 | ||
|
|
51578702b2 | ||
|
|
5322bd491c | ||
|
|
17bf13e72e | ||
|
|
7a46e4c000 | ||
|
|
a73bbcd150 | ||
|
|
71d9084252 | ||
|
|
3bfa2b2d06 | ||
|
|
50c0472f40 | ||
|
|
b7d8a41229 | ||
|
|
a8afab0a35 | ||
|
|
84f95f7072 | ||
|
|
cfe33ce99d | ||
|
|
d321cac3b2 | ||
|
|
6a0eb3890f | ||
|
|
48e1b43e59 | ||
|
|
a05509f024 | ||
|
|
af15c690cc | ||
|
|
a7640f3272 | ||
|
|
d022cea0bf | ||
|
|
8bd438611e | ||
|
|
9038282484 | ||
|
|
e01b794275 | ||
|
|
04f4be3f2a | ||
|
|
e12da98158 | ||
|
|
9724d14817 | ||
|
|
a0f66c93fc | ||
|
|
c2e4ce5824 | ||
|
|
38f63b73a6 | ||
|
|
b2d4f4af3f | ||
|
|
ce1addf292 | ||
|
|
187a44779e | ||
|
|
b27878cb51 | ||
|
|
fe6f462cdb | ||
|
|
0860131df4 | ||
|
|
d42a9dce6c | ||
|
|
86cce7458a | ||
|
|
67d2192f26 | ||
|
|
22e5078528 | ||
|
|
2fba712a7d | ||
|
|
ffe34a9a86 | ||
|
|
6145469875 |
@@ -315,3 +315,10 @@ if(NOT WIN32 AND NOT APPLE)
|
||||
set(CMAKE_CXX_EXTENSIONS ON)
|
||||
set(CMAKE_POSITION_INDEPENDENT_CODE OFF)
|
||||
endif()
|
||||
|
||||
if(USE_MIMALLOC)
|
||||
register_compiler_flags(
|
||||
DESCRIPTION "Use mimalloc"
|
||||
-DUSE_MIMALLOC=1
|
||||
)
|
||||
endif()
|
||||
|
||||
@@ -184,3 +184,5 @@ optionx(USE_WEBKIT_ICU BOOL "Use the ICU libraries from WebKit" DEFAULT ${DEFAUL
|
||||
optionx(ERROR_LIMIT STRING "Maximum number of errors to show when compiling C++ code" DEFAULT "100")
|
||||
|
||||
list(APPEND CMAKE_ARGS -DCMAKE_EXPORT_COMPILE_COMMANDS=ON)
|
||||
|
||||
optionx(USE_MIMALLOC BOOL "Whether mimalloc should be used" DEFAULT ON)
|
||||
|
||||
@@ -4,7 +4,7 @@ register_repository(
|
||||
REPOSITORY
|
||||
oven-sh/mimalloc
|
||||
COMMIT
|
||||
1beadf9651a7bfdec6b5367c380ecc3fe1c40d1a
|
||||
c1f17cd2538417620f60bff70bffe7e68d332aec
|
||||
)
|
||||
|
||||
set(MIMALLOC_CMAKE_ARGS
|
||||
@@ -14,7 +14,7 @@ set(MIMALLOC_CMAKE_ARGS
|
||||
-DMI_BUILD_TESTS=OFF
|
||||
-DMI_USE_CXX=ON
|
||||
-DMI_SKIP_COLLECT_ON_EXIT=ON
|
||||
|
||||
|
||||
# ```
|
||||
# ❯ mimalloc_allow_large_os_pages=0 BUN_PORT=3004 mem bun http-hello.js
|
||||
# Started development server: http://localhost:3004
|
||||
@@ -51,7 +51,7 @@ if(ENABLE_ASAN)
|
||||
list(APPEND MIMALLOC_CMAKE_ARGS -DMI_DEBUG_UBSAN=ON)
|
||||
elseif(APPLE OR LINUX)
|
||||
if(APPLE)
|
||||
list(APPEND MIMALLOC_CMAKE_ARGS -DMI_OVERRIDE=OFF)
|
||||
list(APPEND MIMALLOC_CMAKE_ARGS -DMI_OVERRIDE=OFF)
|
||||
list(APPEND MIMALLOC_CMAKE_ARGS -DMI_OSX_ZONE=OFF)
|
||||
list(APPEND MIMALLOC_CMAKE_ARGS -DMI_OSX_INTERPOSE=OFF)
|
||||
else()
|
||||
@@ -77,9 +77,9 @@ endif()
|
||||
|
||||
if(WIN32)
|
||||
if(DEBUG)
|
||||
set(MIMALLOC_LIBRARY mimalloc-static-debug)
|
||||
set(MIMALLOC_LIBRARY mimalloc-debug)
|
||||
else()
|
||||
set(MIMALLOC_LIBRARY mimalloc-static)
|
||||
set(MIMALLOC_LIBRARY mimalloc)
|
||||
endif()
|
||||
elseif(DEBUG)
|
||||
if (ENABLE_ASAN)
|
||||
|
||||
@@ -117,7 +117,7 @@ fn alignedAlloc(self: Self, len: usize, alignment: Alignment) ?[*]u8 {
|
||||
const ptr: ?*anyopaque = if (mimalloc.mustUseAlignedAlloc(alignment))
|
||||
mimalloc.mi_heap_malloc_aligned(heap, len, alignment.toByteUnits())
|
||||
else
|
||||
mimalloc.mi_heap_malloc(heap, len);
|
||||
mimalloc.mi_heap_malloc_aligned_at(heap, len, alignment.toByteUnits(), 0);
|
||||
|
||||
if (comptime bun.Environment.isDebug) {
|
||||
const usable = mimalloc.mi_malloc_usable_size(ptr);
|
||||
|
||||
@@ -33,11 +33,9 @@ const MimallocAllocator = struct {
|
||||
mimalloc.mi_malloc(len);
|
||||
|
||||
if (comptime Environment.isDebug) {
|
||||
if (ptr != null) {
|
||||
const usable = mimalloc.mi_malloc_usable_size(ptr);
|
||||
if (usable < len and ptr != null) {
|
||||
std.debug.panic("mimalloc: allocated size is too small: {d} < {d}", .{ usable, len });
|
||||
}
|
||||
const usable = mimalloc.mi_malloc_usable_size(ptr);
|
||||
if (usable < len) {
|
||||
std.debug.panic("mimalloc: allocated size is too small: {d} < {d}", .{ usable, len });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -97,7 +97,7 @@ pub fn fromBlob(
|
||||
if (mime_type.category.isTextLike()) {
|
||||
var output = MutableString.initEmpty(allocator);
|
||||
try JSPrinter.quoteForJSON(bytes, &output, true);
|
||||
var list = output.toOwnedSlice();
|
||||
var list = output.slice();
|
||||
// remove the quotes
|
||||
if (list.len > 0) {
|
||||
list = list[1 .. list.len - 1];
|
||||
|
||||
@@ -12,12 +12,6 @@ pub fn load() void {
|
||||
boring.SSL_load_error_strings();
|
||||
boring.ERR_load_BIO_strings();
|
||||
boring.OpenSSL_add_all_algorithms();
|
||||
|
||||
if (!builtin.is_test) {
|
||||
std.mem.doNotOptimizeAway(&OPENSSL_memory_alloc);
|
||||
std.mem.doNotOptimizeAway(&OPENSSL_memory_get_size);
|
||||
std.mem.doNotOptimizeAway(&OPENSSL_memory_free);
|
||||
}
|
||||
}
|
||||
|
||||
var ctx_store: ?*boring.SSL_CTX = null;
|
||||
@@ -58,19 +52,29 @@ pub fn initClient() *boring.SSL {
|
||||
// into the process, including pthreads locks. Failing to meet these constraints
|
||||
// may result in deadlocks, crashes, or memory corruption.
|
||||
|
||||
export fn OPENSSL_memory_alloc(size: usize) ?*anyopaque {
|
||||
return bun.mimalloc.mi_malloc(size);
|
||||
}
|
||||
comptime {
|
||||
if (bun.use_mimalloc) {
|
||||
@export(&struct {
|
||||
pub fn alloc(size: usize) callconv(.C) ?*anyopaque {
|
||||
return bun.mimalloc.mi_malloc(size);
|
||||
}
|
||||
}.alloc, .{ .name = "OPENSSL_memory_alloc" });
|
||||
|
||||
// BoringSSL always expects memory to be zero'd
|
||||
export fn OPENSSL_memory_free(ptr: *anyopaque) void {
|
||||
const len = bun.mimalloc.mi_usable_size(ptr);
|
||||
@memset(@as([*]u8, @ptrCast(ptr))[0..len], 0);
|
||||
bun.mimalloc.mi_free(ptr);
|
||||
}
|
||||
// BoringSSL always expects memory to be zero'd
|
||||
@export(&struct {
|
||||
pub fn free(ptr: *anyopaque) callconv(.C) void {
|
||||
const len = bun.mimalloc.mi_usable_size(ptr);
|
||||
@memset(@as([*]u8, @ptrCast(ptr))[0..len], 0);
|
||||
bun.mimalloc.mi_free(ptr);
|
||||
}
|
||||
}.free, .{ .name = "OPENSSL_memory_free" });
|
||||
|
||||
export fn OPENSSL_memory_get_size(ptr: ?*const anyopaque) usize {
|
||||
return bun.mimalloc.mi_usable_size(ptr);
|
||||
@export(&struct {
|
||||
pub fn get_size(ptr: ?*const anyopaque) callconv(.C) usize {
|
||||
return bun.mimalloc.mi_usable_size(ptr);
|
||||
}
|
||||
}.get_size, .{ .name = "OPENSSL_memory_get_size" });
|
||||
}
|
||||
}
|
||||
|
||||
const INET6_ADDRSTRLEN = if (bun.Environment.isWindows) 65 else 46;
|
||||
@@ -221,7 +225,6 @@ pub fn ERR_toJS(globalThis: *jsc.JSGlobalObject, err_code: u32) jsc.JSValue {
|
||||
|
||||
const X509 = @import("./bun.js/api/bun/x509.zig");
|
||||
const boring = @import("./deps/boringssl.translated.zig");
|
||||
const builtin = @import("builtin");
|
||||
const c_ares = @import("./deps/c_ares.zig");
|
||||
const std = @import("std");
|
||||
|
||||
|
||||
@@ -19,7 +19,11 @@ pub const BrotliAllocator = struct {
|
||||
return;
|
||||
}
|
||||
|
||||
mimalloc.mi_free(data);
|
||||
if (comptime bun.use_mimalloc) {
|
||||
mimalloc.mi_free(data);
|
||||
} else {
|
||||
std.c.free(data);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -440,7 +440,11 @@ pub const MatchedRoute = struct {
|
||||
}
|
||||
if (this.needs_deinit) {
|
||||
if (this.route.pathname.len > 0 and bun.mimalloc.mi_is_in_heap_region(this.route.pathname.ptr)) {
|
||||
bun.mimalloc.mi_free(@constCast(this.route.pathname.ptr));
|
||||
if (comptime bun.use_mimalloc) {
|
||||
bun.mimalloc.mi_free(@constCast(this.route.pathname.ptr));
|
||||
} else {
|
||||
std.c.free(@constCast(this.route.pathname.ptr));
|
||||
}
|
||||
}
|
||||
|
||||
this.params_list_holder.deinit(bun.default_allocator);
|
||||
|
||||
@@ -714,7 +714,11 @@ extern "C" BunString BunString__createExternalGloballyAllocatedLatin1(
|
||||
{
|
||||
ASSERT(length > 0);
|
||||
Ref<WTF::ExternalStringImpl> impl = WTF::ExternalStringImpl::create({ bytes, length }, nullptr, [](void*, void* ptr, size_t) {
|
||||
#ifdef USE_MIMALLOC
|
||||
mi_free(ptr);
|
||||
#else
|
||||
free(ptr);
|
||||
#endif
|
||||
});
|
||||
return { BunStringTag::WTFStringImpl, { .wtf = &impl.leakRef() } };
|
||||
}
|
||||
@@ -725,7 +729,11 @@ extern "C" BunString BunString__createExternalGloballyAllocatedUTF16(
|
||||
{
|
||||
ASSERT(length > 0);
|
||||
Ref<WTF::ExternalStringImpl> impl = WTF::ExternalStringImpl::create({ bytes, length }, nullptr, [](void*, void* ptr, size_t) {
|
||||
#ifdef USE_MIMALLOC
|
||||
mi_free(ptr);
|
||||
#else
|
||||
free(ptr);
|
||||
#endif
|
||||
});
|
||||
return { BunStringTag::WTFStringImpl, { .wtf = &impl.leakRef() } };
|
||||
}
|
||||
|
||||
@@ -1061,7 +1061,7 @@ JSC_DEFINE_HOST_FUNCTION(vmModuleRunInNewContext, (JSGlobalObject * globalObject
|
||||
|
||||
JSValue globalObjectDynamicImportCallback;
|
||||
|
||||
if (auto encodedException = getNodeVMContextOptions(globalObject, vm, scope, contextOptionsArg, contextOptions, "contextCodeGeneration", &globalObjectDynamicImportCallback)) {
|
||||
if (auto encodedException = getNodeVMContextOptions(globalObject, vm, scope, contextOptionsArg, contextOptions, "contextCodeGeneration"_s, &globalObjectDynamicImportCallback)) {
|
||||
return *encodedException;
|
||||
}
|
||||
|
||||
@@ -1085,7 +1085,7 @@ JSC_DEFINE_HOST_FUNCTION(vmModuleRunInNewContext, (JSGlobalObject * globalObject
|
||||
RETURN_IF_EXCEPTION(scope, {});
|
||||
}
|
||||
|
||||
RefPtr fetcher(NodeVMScriptFetcher::create(vm, scriptDynamicImportCallback, jsUndefined()));
|
||||
RefPtr fetcher(NodeVMScriptFetcher::create(vm, scriptDynamicImportCallback, nullptr));
|
||||
|
||||
SourceCode sourceCode(
|
||||
JSC::StringSourceProvider::create(
|
||||
@@ -1135,7 +1135,7 @@ JSC_DEFINE_HOST_FUNCTION(vmModuleRunInThisContext, (JSGlobalObject * globalObjec
|
||||
RETURN_IF_EXCEPTION(throwScope, encodedJSUndefined());
|
||||
}
|
||||
|
||||
RefPtr fetcher(NodeVMScriptFetcher::create(vm, importer, jsUndefined()));
|
||||
RefPtr fetcher(NodeVMScriptFetcher::create(vm, importer, nullptr));
|
||||
|
||||
SourceCode source(
|
||||
JSC::StringSourceProvider::create(sourceString, JSC::SourceOrigin(WTF::URL::fileURLWithFileSystemPath(options.filename), *fetcher), options.filename, JSC::SourceTaintedOrigin::Untainted, TextPosition(options.lineOffset, options.columnOffset)),
|
||||
@@ -1212,7 +1212,7 @@ JSC_DEFINE_HOST_FUNCTION(vmModuleCompileFunction, (JSGlobalObject * globalObject
|
||||
// Add the function body
|
||||
constructFunctionArgs.append(jsString(vm, sourceString));
|
||||
|
||||
RefPtr fetcher(NodeVMScriptFetcher::create(vm, importer, jsUndefined()));
|
||||
RefPtr fetcher(NodeVMScriptFetcher::create(vm, importer, nullptr));
|
||||
|
||||
// Create the source origin
|
||||
SourceOrigin sourceOrigin { WTF::URL::fileURLWithFileSystemPath(options.filename), *fetcher };
|
||||
@@ -1290,7 +1290,7 @@ JSC_DEFINE_HOST_FUNCTION(vmModule_createContext, (JSGlobalObject * globalObject,
|
||||
|
||||
JSValue importer;
|
||||
|
||||
if (auto encodedException = getNodeVMContextOptions(globalObject, vm, scope, optionsArg, contextOptions, "codeGeneration", &importer)) {
|
||||
if (auto encodedException = getNodeVMContextOptions(globalObject, vm, scope, optionsArg, contextOptions, "codeGeneration"_s, &importer)) {
|
||||
return *encodedException;
|
||||
}
|
||||
|
||||
|
||||
@@ -126,7 +126,7 @@ constructScript(JSGlobalObject* globalObject, CallFrame* callFrame, JSValue newT
|
||||
RETURN_IF_EXCEPTION(scope, {});
|
||||
}
|
||||
|
||||
RefPtr fetcher(NodeVMScriptFetcher::create(vm, importer, jsUndefined()));
|
||||
RefPtr fetcher(NodeVMScriptFetcher::create(vm, importer, nullptr));
|
||||
|
||||
SourceCode source = makeSource(sourceString, JSC::SourceOrigin(WTF::URL::fileURLWithFileSystemPath(options.filename), *fetcher), JSC::SourceTaintedOrigin::Untainted, options.filename, TextPosition(options.lineOffset, options.columnOffset));
|
||||
RETURN_IF_EXCEPTION(scope, {});
|
||||
|
||||
@@ -7,17 +7,19 @@
|
||||
|
||||
namespace Bun {
|
||||
|
||||
class NodeVMScript;
|
||||
|
||||
// The presence of this class in a JSFunction's sourceOrigin indicates that the function was compiled by Bun's node:vm implementation.
|
||||
class NodeVMScriptFetcher : public JSC::ScriptFetcher {
|
||||
public:
|
||||
static Ref<NodeVMScriptFetcher> create(JSC::VM& vm, JSC::JSValue dynamicImportCallback, JSC::JSValue owner) { return adoptRef(*new NodeVMScriptFetcher(vm, dynamicImportCallback, owner)); }
|
||||
static Ref<NodeVMScriptFetcher> create(JSC::VM& vm, JSC::JSValue dynamicImportCallback, JSCell* owner) { return adoptRef(*new NodeVMScriptFetcher(vm, dynamicImportCallback, owner)); }
|
||||
|
||||
Type fetcherType() const final { return Type::NodeVM; }
|
||||
|
||||
JSC::JSValue dynamicImportCallback() const { return m_dynamicImportCallback.get(); }
|
||||
|
||||
JSC::JSValue owner() const { return m_owner.get(); }
|
||||
void owner(JSC::VM& vm, JSC::JSValue value) { m_owner.set(vm, value); }
|
||||
JSCell* owner() const { return m_owner.get(); }
|
||||
void owner(JSC::VM& vm, JSCell* value) { m_owner.set(vm, value); }
|
||||
|
||||
bool isUsingDefaultLoader() const { return m_isUsingDefaultLoader; }
|
||||
auto temporarilyUseDefaultLoader()
|
||||
@@ -30,10 +32,10 @@ public:
|
||||
|
||||
private:
|
||||
JSC::Strong<JSC::Unknown> m_dynamicImportCallback;
|
||||
JSC::Strong<JSC::Unknown> m_owner;
|
||||
JSC::Weak<JSCell> m_owner;
|
||||
bool m_isUsingDefaultLoader = false;
|
||||
|
||||
NodeVMScriptFetcher(JSC::VM& vm, JSC::JSValue dynamicImportCallback, JSC::JSValue owner)
|
||||
NodeVMScriptFetcher(JSC::VM& vm, JSC::JSValue dynamicImportCallback, JSCell* owner)
|
||||
: m_dynamicImportCallback(vm, dynamicImportCallback)
|
||||
, m_owner(vm, owner)
|
||||
{
|
||||
|
||||
@@ -89,7 +89,7 @@ NodeVMSourceTextModule* NodeVMSourceTextModule::create(VM& vm, JSGlobalObject* g
|
||||
uint32_t columnOffset = columnOffsetValue.toUInt32(globalObject);
|
||||
RETURN_IF_EXCEPTION(scope, nullptr);
|
||||
|
||||
RefPtr fetcher(NodeVMScriptFetcher::create(vm, dynamicImportCallback, moduleWrapper));
|
||||
RefPtr fetcher(NodeVMScriptFetcher::create(vm, dynamicImportCallback, moduleWrapper.isUndefinedOrNull() ? nullptr : moduleWrapper.asCell()));
|
||||
RETURN_IF_EXCEPTION(scope, nullptr);
|
||||
|
||||
SourceOrigin sourceOrigin { {}, *fetcher };
|
||||
|
||||
@@ -12,7 +12,11 @@ extern "C" JSC::EncodedJSValue JSUint8Array__fromDefaultAllocator(JSC::JSGlobalO
|
||||
|
||||
if (length > 0) [[likely]] {
|
||||
auto buffer = ArrayBuffer::createFromBytes({ ptr, length }, createSharedTask<void(void*)>([](void* p) {
|
||||
#ifdef USE_MIMALLOC
|
||||
mi_free(p);
|
||||
#else
|
||||
free(p);
|
||||
#endif
|
||||
}));
|
||||
|
||||
uint8Array = JSC::JSUint8Array::create(lexicalGlobalObject, lexicalGlobalObject->typedArrayStructureWithTypedArrayType<JSC::TypeUint8>(), WTFMove(buffer), 0, length);
|
||||
@@ -30,7 +34,11 @@ extern "C" JSC::EncodedJSValue JSArrayBuffer__fromDefaultAllocator(JSC::JSGlobal
|
||||
|
||||
if (length > 0) [[likely]] {
|
||||
buffer = ArrayBuffer::createFromBytes({ ptr, length }, createSharedTask<void(void*)>([](void* p) {
|
||||
#ifdef USE_MIMALLOC
|
||||
mi_free(p);
|
||||
#else
|
||||
free(p);
|
||||
#endif
|
||||
}));
|
||||
} else {
|
||||
buffer = ArrayBuffer::create(0, 1);
|
||||
|
||||
@@ -94,7 +94,11 @@ Ref<SourceProvider> SourceProvider::create(
|
||||
const auto getProvider = [&]() -> Ref<SourceProvider> {
|
||||
if (resolvedSource.bytecode_cache != nullptr) {
|
||||
const auto destructorPtr = [](const void* ptr) {
|
||||
#ifdef USE_MIMALLOC
|
||||
mi_free(const_cast<void*>(ptr));
|
||||
#else
|
||||
free(const_cast<void*>(ptr));
|
||||
#endif
|
||||
};
|
||||
const auto destructorNoOp = [](const void* ptr) {
|
||||
// no-op, for bun build --compile.
|
||||
|
||||
@@ -743,7 +743,7 @@ pub const ZigString = extern struct {
|
||||
}
|
||||
|
||||
inline fn assertGlobal(this: *const ZigString) void {
|
||||
if (comptime bun.Environment.allow_assert) {
|
||||
if (comptime bun.Environment.allow_assert and bun.use_mimalloc) {
|
||||
bun.assert(this.len == 0 or
|
||||
bun.mimalloc.mi_is_in_heap_region(untagged(this._unsafe_ptr_do_not_use)) or
|
||||
bun.mimalloc.mi_check_owned(untagged(this._unsafe_ptr_do_not_use)));
|
||||
@@ -852,7 +852,7 @@ pub const StringPointer = struct {
|
||||
export fn ZigString__free(raw: [*]const u8, len: usize, allocator_: ?*anyopaque) void {
|
||||
var allocator: std.mem.Allocator = @as(*std.mem.Allocator, @ptrCast(@alignCast(allocator_ orelse return))).*;
|
||||
var ptr = ZigString.init(raw[0..len]).slice().ptr;
|
||||
if (comptime Environment.allow_assert) {
|
||||
if (comptime Environment.allow_assert and bun.use_mimalloc) {
|
||||
bun.assert(Mimalloc.mi_is_in_heap_region(ptr));
|
||||
}
|
||||
const str = ptr[0..len];
|
||||
@@ -862,11 +862,15 @@ export fn ZigString__free(raw: [*]const u8, len: usize, allocator_: ?*anyopaque)
|
||||
|
||||
export fn ZigString__freeGlobal(ptr: [*]const u8, len: usize) void {
|
||||
const untagged = @as(*anyopaque, @ptrFromInt(@intFromPtr(ZigString.init(ptr[0..len]).slice().ptr)));
|
||||
if (comptime Environment.allow_assert) {
|
||||
bun.assert(Mimalloc.mi_is_in_heap_region(ptr));
|
||||
if (comptime bun.use_mimalloc) {
|
||||
if (comptime Environment.allow_assert) {
|
||||
bun.assert(Mimalloc.mi_is_in_heap_region(ptr));
|
||||
}
|
||||
// we must untag the string pointer
|
||||
Mimalloc.mi_free(untagged);
|
||||
} else {
|
||||
std.c.free(untagged);
|
||||
}
|
||||
// we must untag the string pointer
|
||||
Mimalloc.mi_free(untagged);
|
||||
}
|
||||
|
||||
const string = []const u8;
|
||||
|
||||
@@ -628,7 +628,11 @@ pub export fn MarkedArrayBuffer_deallocator(bytes_: *anyopaque, _: *anyopaque) v
|
||||
// mimalloc.mi_heap_check_owned(jsc.VirtualMachine.get().arena.heap.?, bytes_));
|
||||
// }
|
||||
|
||||
mimalloc.mi_free(bytes_);
|
||||
if (comptime bun.use_mimalloc) {
|
||||
mimalloc.mi_free(bytes_);
|
||||
} else {
|
||||
std.c.free(bytes_);
|
||||
}
|
||||
}
|
||||
|
||||
pub export fn BlobArrayBuffer_deallocator(_: *anyopaque, blob: *anyopaque) void {
|
||||
|
||||
@@ -44,6 +44,15 @@ pub fn init(allocator: std.mem.Allocator, file_count: usize) !LinkerGraph {
|
||||
};
|
||||
}
|
||||
|
||||
pub fn deinit(this: *LinkerGraph) void {
|
||||
for (this.files.items(.quoted_source_contents)) |maybe_contents| {
|
||||
if (maybe_contents) |contents| {
|
||||
bun.default_allocator.free(contents);
|
||||
}
|
||||
}
|
||||
this.files.clearAndFree(bun.default_allocator);
|
||||
}
|
||||
|
||||
pub fn runtimeFunction(this: *const LinkerGraph, name: string) Ref {
|
||||
return this.ast.items(.named_exports)[Index.runtime.value].get(name).?.ref;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const vm_size_t = usize;
|
||||
|
||||
pub const enabled = Environment.allow_assert and Environment.isMac;
|
||||
pub const enabled = Environment.allow_assert and Environment.isMac and !Environment.enable_asan;
|
||||
|
||||
fn heapLabel(comptime T: type) [:0]const u8 {
|
||||
const base_name = if (@hasDecl(T, "heap_label"))
|
||||
|
||||
@@ -1683,6 +1683,10 @@ pub const Chunk = struct {
|
||||
return .{ .ctx = Type.init(allocator, prepend_count) };
|
||||
}
|
||||
|
||||
pub inline fn deinit(this: *Format) void {
|
||||
this.ctx.deinit();
|
||||
}
|
||||
|
||||
pub inline fn appendLineSeparator(this: *Format) anyerror!void {
|
||||
try this.ctx.appendLineSeparator();
|
||||
}
|
||||
@@ -1729,6 +1733,10 @@ pub const Chunk = struct {
|
||||
return map;
|
||||
}
|
||||
|
||||
pub fn deinit(this: *VLQSourceMap) void {
|
||||
this.data.deinit();
|
||||
}
|
||||
|
||||
pub fn appendLineSeparator(this: *VLQSourceMap) anyerror!void {
|
||||
try this.data.appendChar(';');
|
||||
}
|
||||
|
||||
22
src/zlib.zig
22
src/zlib.zig
@@ -136,7 +136,11 @@ pub fn NewZlibReader(comptime Writer: type, comptime buffer_size: usize) type {
|
||||
}
|
||||
|
||||
pub fn free(_: *anyopaque, data: *anyopaque) callconv(.C) void {
|
||||
mimalloc.mi_free(data);
|
||||
if (comptime bun.use_mimalloc) {
|
||||
mimalloc.mi_free(data);
|
||||
} else {
|
||||
std.c.free(data);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn deinit(this: *ZlibReader) void {
|
||||
@@ -300,6 +304,10 @@ const ZlibAllocator = struct {
|
||||
return zone.malloc_zone_calloc(items, len) orelse bun.outOfMemory();
|
||||
}
|
||||
|
||||
if (comptime !bun.use_mimalloc) {
|
||||
return std.c.calloc(items, len) orelse bun.outOfMemory();
|
||||
}
|
||||
|
||||
return mimalloc.mi_calloc(items, len) orelse bun.outOfMemory();
|
||||
}
|
||||
|
||||
@@ -310,7 +318,11 @@ const ZlibAllocator = struct {
|
||||
return;
|
||||
}
|
||||
|
||||
mimalloc.mi_free(data);
|
||||
if (comptime bun.use_mimalloc) {
|
||||
mimalloc.mi_free(data);
|
||||
} else {
|
||||
std.c.free(data);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -757,7 +769,11 @@ pub const ZlibCompressorArrayList = struct {
|
||||
}
|
||||
|
||||
pub fn free(_: *anyopaque, data: *anyopaque) callconv(.C) void {
|
||||
mimalloc.mi_free(data);
|
||||
if (comptime bun.use_mimalloc) {
|
||||
mimalloc.mi_free(data);
|
||||
} else {
|
||||
std.c.free(data);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn deinit(this: *ZlibCompressor) void {
|
||||
|
||||
Reference in New Issue
Block a user