Commit Graph

260 Commits

Author SHA1 Message Date
Feoramund
e038c3cf4e Make superpage caching linear time instead of quadratic 2025-05-08 11:06:03 -04:00
Feoramund
dcd9bd7888 Make slab map caching linear time instead of quadratic 2025-05-08 11:06:03 -04:00
Feoramund
fa1f6abe78 Don't atomically subtract zero from remote_free_count 2025-05-08 11:06:03 -04:00
Feoramund
a0425ca220 Do not return superpages that had remote frees to the OS 2025-05-08 11:06:03 -04:00
Feoramund
acd5d0d40b Fix slab iteration bug in the remote free collection phase
Previously, a wide slab could be freed during this phase which could
trigger the superpage itself to be freed, resulting in iteration across
potentially invalid memory if the superpage was returned to the host and
not placed in the orphanage.

`heap_free_wide_slab` has had its responsibilities reduced to just
freeing the wide slab, and `heap_free_superpage_if_empty_and_unused` has
been added to better clarify what is happening where.
2025-05-08 11:06:02 -04:00
Feoramund
2d0547dcaf Remove unneeded call to min
At this point, we know we're expanding the wide slab, so `old_size` will
always be the right size.
2025-05-08 11:06:02 -04:00
Feoramund
44a7015609 Fix in-place expansion of wide slabs 2025-05-08 11:06:02 -04:00
Feoramund
8638bd3b89 Fix slab iteration bug in heap_cache_register_superpage
Increment of `i` is handled near the start of this loop.
2025-05-08 11:06:02 -04:00
Feoramund
ee3d859c6b Remove HEAP_PANIC_ON_FREE_NIL 2025-05-08 11:06:02 -04:00
Feoramund
f5226d01f7 Revert to unoptimized behavior on Darwin 2025-05-08 11:06:02 -04:00
Feoramund
4a31e1f635 Ensure remapped memory has desired protection on Darwin 2025-05-08 11:06:02 -04:00
Feoramund
0947914e0d Use mach_task_self_ global instead 2025-05-08 11:06:02 -04:00
Feoramund
247ce3cc97 Favor rescheduling superpage cache entry instead
This should be more robust during merges that happen simultaneously with
remote frees.

Previously, we would preserve the cache entry, but there is an edge case
where a slab of a lower index could be remotely freed and missed during
a merge.
2025-05-08 11:06:02 -04:00
Feoramund
e86bd35387 Optimize virtual memory resizing on Darwin 2025-05-08 11:06:02 -04:00
Feoramund
c52c29856c Unify heap allocators
- Simplify the malloc-based allocator
- Correct the type signatures on malloc/calloc/realloc
- Make `heap_alloc/heap_free/heap_resize` API consistent across platforms
2025-05-08 11:06:02 -04:00
Feoramund
30e600699d Strengthen order to prevent reordering 2025-05-08 11:06:01 -04:00
Feoramund
0532b73563 Simplify loop 2025-05-08 11:06:01 -04:00
Feoramund
541443fe33 Don't build feoramalloc on web platforms
Their allocation pathways are already tuned for their respective
platforms.
2025-05-08 11:06:01 -04:00
Feoramund
e9bf350cca Add heap allocator exception for Orca
This is a copy of the libc malloc-based allocator that we previously
had. It's preferable to use the Orca runtime allocator over our own.
2025-05-08 11:06:01 -04:00
Feoramund
ef72a373b2 Use VM_INHERIT_COPY instead
This aligns with the use of `MAP_PRIVATE` in `mmap`-based
implementations.
2025-05-08 11:06:01 -04:00
Feoramund
4c59019a57 Restrict superpage allocation on Darwin to AMD64 and 2MiB
There's a possibility that Darwin does not support anything else, in
terms of size or architecture.
2025-05-08 11:06:01 -04:00
Feoramund
1e62f2c8c4 Rearrange slab iteration conditionals 2025-05-08 11:06:01 -04:00
Feoramund
76a2877d7d Hoist reused calculations out into variables 2025-05-08 11:06:01 -04:00
Feoramund
17b38c1bca Strengthen Consume to Acquire in heap allocator 2025-05-08 11:06:01 -04:00
Feoramund
6d99d9571c Fix indentation 2025-05-08 11:06:01 -04:00
Feoramund
a4a776634c Add native heap allocator
- Add the test bench for the allocator
- Move old allocator code to the test bench
- Fix `heap_resize` usage in `os2/env_linux.odin` to fit new API
  requiring `old_size`
2025-05-08 11:06:00 -04:00
Feoramund
f142043db9 Add virtual memory procedures to base 2025-05-08 11:06:00 -04:00
Feoramund
13dca77d3d Add get_current_thread_id to base 2025-05-08 11:06:00 -04:00
gingerBill
92df892f25 Merge pull request #5064 from harold-b/hb/objc-classes
Add support for Objective-C class implementation
2025-05-08 12:58:33 +01:00
gingerBill
90a30a145a Merge pull request #5122 from Lperlind/asan-allocators
Add asan support for various allocators and stack unpoisoning
2025-05-07 10:21:16 +01:00
Lucas Perlind
46e0c7ad74 Cleanup 2025-05-07 11:30:58 +10:00
Lucas Perlind
fd05f55691 Fix wasi_wasm 2025-05-06 15:23:44 +10:00
Lucas Perlind
83bc2d3c4a Add asan support for various allocators 2025-05-06 14:55:50 +10:00
Barinzaya
dd5b7852ce Added alternate reduce-add/reduce-mul intrinsics.
The new reduce_add/reduce_mul procs perform the corresponding arithmetic
reduction in different orders than sequential order. These alternative
orders can often offer better SIMD hardware utilization.

Two different orders are added: pair-wise (operating on pairs of
adjacent elements) or bisection-wise (operating element-wise on the
first and last N/2 elements of the vector).
2025-05-05 16:38:45 -04:00
gingerBill
c4719e75fd Add simd.indices and docs 2025-05-05 11:43:19 +01:00
Harold Brenes
5f0b47c373 Implement all checker specification for Objective-C class implementations and objc_ivar_get intrinsic 2025-05-03 00:59:33 -04:00
Harold Brenes
998ed79738 Go back to objc_ivar_get instead of ivar_get. 2025-04-30 20:43:05 -04:00
Lucas Perlind
4763da4b0d Document base:sanitizer 2025-04-29 19:06:09 +10:00
Lucas Perlind
5e985bcd74 Remove dependency on runtime; Add to examples 2025-04-24 20:34:32 +10:00
Lucas Perlind
5c117bde6d Add base:sanitizer package 2025-04-24 20:28:32 +10:00
Lucas Perlind
7502e7f2bc make asan procs contextless 2025-04-24 19:56:40 +10:00
Lucas Perlind
4a0be1f3a8 make vet happy 2025-04-24 16:02:31 +10:00
Lucas Perlind
ab0b26e876 Add more asan support to the odin runtime and begin sanitizing
allocators

This adds various bindings to the asan runtime which can be used
to poison/unpoison memory handed out by various allocators. This
means we can catch use after free memory bugs when using operations
such as free_all during runtime.

Asan poisoning are added for the follow allocators in mem:
Arena (including temporary arenas)
Scratch
Stack
Small_Stack

Additionally a bug in the stack allocator was fixed to disallow freeing
in the middle of the stack (caught by the asan!).

I plan on adding support for all the allocators in core. This is just
a good starting point and were some of the easiest ones to implement
asan for.
2025-04-24 15:17:51 +10:00
Harold Brenes
a3de9c8de4 Add initial support for Objective-C class implementation 2025-04-20 21:53:46 -04:00
gingerBill
3dcc22fa6d Change hashing rules for float-like types to make 0 == -0 2025-04-16 10:52:35 +01:00
Jeroen van Rijn
bb38775fb1 Remove Type_Info_Tuple 2025-04-13 21:51:57 +02:00
gingerBill
1f814c33dc Support subtargets in build tags: #build darwin:generic and #build linux:android, darwin:ios 2025-04-10 11:36:03 +01:00
Dave Voutila
18988b5f94 Fix use of errno on OpenBSD. 2025-03-27 10:36:40 -04:00
gingerBill
539e9bd2e3 Merge pull request #4836 from laytan/fix-wrong-out-of-memory
fix wrong out of memory in edge cases, just try allocate from block for one source of truth
2025-03-20 17:20:26 +00:00
gingerBill
21a6648cde Fix #4903 2025-03-03 15:16:50 +00:00