Commit graph

32623 commits

Author SHA1 Message Date
Andrew Kelley
7360be19a4 compiler: use std.heap.smp_allocator
In main, now this allocator is chosen by default when compiling without
libc in ReleaseFast or ReleaseSmall, and not targeting WebAssembly.
2025-02-07 14:41:49 -08:00
Andrew Kelley
84bf7a6701 std.heap.SmpAllocator: 256K slab_len
and no need for special handling of wasi and windows since we don't ask
for anything more than page-aligned.
2025-02-07 12:20:12 -08:00
Andrew Kelley
3d7c5cf64a std.heap: test smp_allocator 2025-02-07 12:20:12 -08:00
Andrew Kelley
51c4ffa410 add std.heap.SmpAllocator
An allocator intended to be used in -OReleaseFast mode when
multi-threading is enabled.
2025-02-07 12:20:12 -08:00
Andrew Kelley
6a6e72fff8
Merge pull request #20511 from archbirdplus
runtime page size detection
rework GeneralPurposeAllocator to reduce active mapping count
Allocator VTable API update
2025-02-07 06:21:51 -08:00
Alex Rønne Petersen
8ad0732954
Merge pull request #22771 from chouquette/chouquette/glibc_guard
glibc: guard more function declarations
2025-02-07 15:11:36 +01:00
Andrew Kelley
2d4954ad63
Merge pull request #22717 from jacobly0/x86_64-rewrite
x86_64: rewrite `@truncate`
2025-02-07 04:06:50 -08:00
Alex Rønne Petersen
42e48b83b1
Merge pull request #22787 from Rexicon226/add-hint
std.c: add `JIT` hint to macos `MAP`
2025-02-07 11:57:39 +01:00
Isaac Freund
87bbb49d5f test: check @tagName() in callconv C function
This is a regression test for an x86_64 backend miscompilation when
using @tagName() in a callconv(.c) function with -fPIC.
2025-02-07 07:20:53 +01:00
Jacob Young
043e3b29ce x86_64: fix calling convention typos 2025-02-07 07:20:53 +01:00
Kouosi Takayama
1ac97013db fix: getEndPos return end position 2025-02-07 07:20:35 +01:00
Isaac Freund
b3c63e5de0 Dwarf: fix cross_section_relocs capacity
This ensure capacity call does not match the number of
appendAssumeCapacity() calls that follow it. Fix this.

This was discovered due to hitting the assertion failure in
appendAssumeCapacity() while building river.

I'm not sure how to isolate a minimal reproducer for a test.
2025-02-07 07:20:13 +01:00
Frank Plowman
bf7bc4ff01 langref/errorset: Replace subset description with union
The previous language using subsets was really just stating a couple
of the properties of the union of a group of sets, and with a minor
error at that.
2025-02-07 03:38:44 +01:00
Andrew Kelley
b8f5cfed45 std.heap.SbrkAllocator: fix typo 2025-02-06 14:50:55 -08:00
Andrew Kelley
e630b20c62 std.mem.Allocator.VTable: improve doc comment wording 2025-02-06 14:50:20 -08:00
Andrew Kelley
1bb8b4ad61 std.heap: fix wrong deprecation date 2025-02-06 14:47:22 -08:00
Andrew Kelley
ff8e759705 std.testing: don't ask wasm to stack trace 2025-02-06 14:46:16 -08:00
Andrew Kelley
d0e1a6a23d std.heap.DebugAllocator: update unit tests for new impl
No longer need this windows-specific behavior.
2025-02-06 14:23:23 -08:00
Andrew Kelley
960190643a std.heap.DebugAllocator: make page size configurable 2025-02-06 14:23:23 -08:00
Andrew Kelley
cd99ab3229 std.heap: rename GeneralPurposeAllocator to DebugAllocator 2025-02-06 14:23:23 -08:00
Andrew Kelley
5e9b8c38d3 std.heap: remove HeapAllocator
Windows-only, depends on kernel32 in violation of zig std lib policy,
and redundant with other cross-platform APIs that perform the same
functionality.
2025-02-06 14:23:23 -08:00
Andrew Kelley
f82ec3f02a std.testing.allocator: different canary + enable resize traces
Accept a slight performance degradation when unit testing for better
debuggability when a leak or double-free is detected.
2025-02-06 14:23:23 -08:00
Andrew Kelley
8282565ce5 std.heap.GeneralPurposeAllocator: fix UAF in resizeLarge
There was an ensureUnusedCapacity() call that invalidated a looked-up
hash table entry. Move it earlier.
2025-02-06 14:23:23 -08:00
Andrew Kelley
6aab1ea256 std.heap: update Windows HeapAllocator 2025-02-06 14:23:23 -08:00
Andrew Kelley
8626191549 std.heap.GeneralPurposeAllocator: fix slot_counts calculation
In larger small buckets, the comptime logic that computed slot count did
not verify that the number it produced was valid. Now it verifies it,
which made this bug into a compile error. Then I fixed the bug by
introducing a "minimum slots per bucket" declaration.
2025-02-06 14:23:23 -08:00
Andrew Kelley
7320e8b3cd std.testing: make some things not pub
this looks like it was an accident to expose these
2025-02-06 14:23:23 -08:00
Andrew Kelley
d20d934a8a std: fix compilation under -lc 2025-02-06 14:23:23 -08:00
Andrew Kelley
def36f2e44 std.heap.GeneralPurposeAllocator: usize for used_bits
improves leak checking performance.
2025-02-06 14:23:23 -08:00
Andrew Kelley
c8e807c44e std.heap.GeneralPurposeAllocator: use for loops in leak check 2025-02-06 14:23:23 -08:00
Andrew Kelley
b14a350430 std.heap.GeneralPurposeAllocator: reduce page size to 512K
and fix compilation on 32-bit targets
2025-02-06 14:23:23 -08:00
Andrew Kelley
00b723dc9d std.heap.WasmAllocator: update to new Allocator API 2025-02-06 14:23:23 -08:00
Andrew Kelley
82b5a1d313 std.heap.GeneralPurposeAllocator: implement resize and remap 2025-02-06 14:23:23 -08:00
Andrew Kelley
0e0f0c9625 std.heap.GeneralPurposeAllocator: check canary in free 2025-02-06 14:23:23 -08:00
Andrew Kelley
8ff7481e82 std.heap.GeneralPurposeAllocator: inline small allocation metadata
Put the small allocation metadata directly into the (large) pages
allocated.
2025-02-06 14:23:23 -08:00
Andrew Kelley
1a6d87d699 std.heap.ThreadSafeAllocator: update to new Allocator API 2025-02-06 14:23:23 -08:00
Andrew Kelley
36e9b0f026 std.mem.Allocator: keep the undefined memset
Reversal on the decision: the Allocator interface is the correct place
for the memset to undefined because it allows Allocator implementations
to bypass the interface and use a backing allocator directly, skipping
the performance penalty of memsetting the entire allocation, which may
be very large, as well as having valuable zeroes on them.

closes #4298
2025-02-06 14:23:23 -08:00
Andrew Kelley
2c5113f6d1 std.os.linux.mmap: remove logic that does not belong here 2025-02-06 14:23:23 -08:00
Andrew Kelley
601f632c27 std.heap.GeneralPurposeAllocator: fix large alloc accounting
when mremap relocates an allocation
2025-02-06 14:23:23 -08:00
Andrew Kelley
becd16859d std.hash_map: placeholder for doc comments 2025-02-06 14:23:23 -08:00
Andrew Kelley
f1717777a2 std.heap: delete LoggingAllocator and friends
I don't think these belong in std, at least not in their current form.

If someone wants to add these back I'd like to review the patch before
it lands.

Reverts 629e2e7844
2025-02-06 14:23:23 -08:00
Andrew Kelley
0d8166be3f std: update to new Allocator API 2025-02-06 14:23:23 -08:00
Andrew Kelley
a4d4e086c5 introduce std.posix.mremap and use it
in std.heap.page_allocator
2025-02-06 14:23:23 -08:00
Andrew Kelley
a0b2a18648 std.testing.FailingAllocator: flatten namespace 2025-02-06 14:23:23 -08:00
Andrew Kelley
7eeef5fb2b std.mem.Allocator: introduce remap function to the interface
This one changes the size of an allocation, allowing it to be relocated.
However, the implementation will still return `null` if it would be
equivalent to

new = alloc
memcpy(new, old)
free(old)

Mainly this prepares for taking advantage of `mremap` which I thought
would be a bigger deal but apparently is only available on Linux. Still,
we should use it on Linux.
2025-02-06 14:23:23 -08:00
Andrew Kelley
dd2fa4f75d std.heap.GeneralPurposeAllocator: runtime-known page size
no longer causes compilation failure.

This also addresses the problem of high map count causing OOM by
choosing a page size of 2MiB for most targets when the page_size_max is
smaller than this number.
2025-02-06 14:23:23 -08:00
Andrew Kelley
b23662feeb std.heap.WasmAllocator: use @splat syntax
preferred over array multiplication where possible.
2025-02-06 14:23:23 -08:00
Andrew Kelley
91f41bdc70 std.heap.PageAllocator: restore high alignment functionality
This allocator now supports alignments greater than page size, with the
same implementation as it used before.

This is a partial revert of ceb0a632cf.

It looks like VirtualAlloc2 has better solutions to this problem,
including features such as MEM_RESERVE_PLACEHOLDER and MEM_LARGE_PAGES.
This possibility can be investigated as a follow-up task.
2025-02-06 14:23:23 -08:00
Andrew Kelley
5c63884539 add std.mem.Alignment API 2025-02-06 14:23:23 -08:00
Andrew Kelley
4913de3c88 GeneralPurposeAllocator: minimal fix
This keeps the implementation matching master branch, however,
introduces a compile error that applications can work around by
explicitly setting page_size_max and page_size_min to match their
computer's settings, in the case that those values are not already
equal.

I plan to rework this allocator in a follow-up enhancement with the goal
of reducing total active memory mappings.
2025-02-06 14:23:23 -08:00
Andrew Kelley
95a0474dc6 revert GPA to before this branch 2025-02-06 14:23:23 -08:00