Commit Graph

75 Commits

Author SHA1 Message Date
Greg Parker
fe8618a3d2 Scrap the custom allocator until we have time to fix it.
The allocator's crimes include:
* It uses OS SPI that must not be used by non-OS apps.
* It does not play well with memory debugging tools like Instruments.
* It does not return memory to the OS in response to memory pressure.
* It is less tested than we would like because many configurations 
  inadvertently turn it off (such as running from Xcode).
* Its per-thread magazine implementation does not actually work.
* Its "try alloc" flag is incompletely implemented and never used.
* Its "zero fill" flag is unimplemented and inconsistently used.



Swift SVN r20757
2014-07-30 14:11:40 +00:00
Doug Gregor
37d69a4207 Allocator: round the size of an allocation up to the alignment on all allocation and deallocation paths.
We were rounding the size up to the alignment when allocating a new object (swift_allocObject) but not when directly allocating memory for a non-object (swift_slowAlloc). The deallocation code wasn’t rounding the size up to the alignment at all. Overall, this meant that we would get the wrong index into the allocation cache when deallocating an object whose size got rounded in a way that affects the index.

Fixes <rdar://problem/17542859>, where println(5) would fail on the 32-bit iOS simulator when building the runtime without NDEBUG (so we get extra checking) and the standard library is built without optimization (which keeps a certain 33-byte allocation on the heap). The Interpreter/SDK/objc_cast.swift test triggers this when built under those conditions.

Swift SVN r19499
2014-07-03 02:11:50 +00:00
Dave Zarzycki
d713c55268 Heap: Sniff out *any* Malloc knobs and fall back on the system malloc
Swift SVN r18574
2014-05-22 21:40:10 +00:00
Dave Zarzycki
631e89d205 Heap: enable some runtime asserts that double check the compiler
This double checks:
<rdar://problem/16979846> Array backing store is leaking
<rdar://problem/16989632> Array backing store sizing is still buggy

Swift SVN r18554
2014-05-22 05:00:58 +00:00
John McCall
329abe543d Pass an alignment mask during heap array allocation,
not an alignment value.

Assert that various entrypoints get an alignment mask.

Get everything uniformly passing an assertion about
dealloating an object with the correct allocation
size; don't actually enable the assertion yet, though.

rdar://16989632

Swift SVN r18550
2014-05-22 01:58:05 +00:00
Dave Zarzycki
842e288377 Heap: pre-compute pthread layout details
This function is hot enough that this is worth it.

Swift SVN r18521
2014-05-21 21:14:03 +00:00
Dave Zarzycki
74f29d5138 Heap: cache dlsym() result
This fixes: <rdar://problem/16991267>

Swift SVN r18520
2014-05-21 20:59:26 +00:00
Dave Zarzycki
98ce4f3956 Heap: add an assert that would have caught 16979846
Once 16979846 is fixed, we can double check sizes at free time to ensure
that we're putting them on the right free list.

Swift SVN r18471
2014-05-20 23:23:57 +00:00
Dave Zarzycki
b46851397c Heap: add missing lock/unlock
Swift SVN r18468
2014-05-20 21:26:25 +00:00
Dave Zarzycki
46a77283e1 Heap: track the last allocation per arena correctly
Swift SVN r18466
2014-05-20 21:21:13 +00:00
Dave Zarzycki
94d5c81b4b Heap: ignore arena tail loss during enumeration
<rdar://problem/16953578> SwiftZone malloc enumeration is returning "PTR_IN_USE" blocks that extend past their VM region

Swift SVN r18352
2014-05-18 21:12:21 +00:00
Dave Zarzycki
732486f8a0 Heap: simplify forEach logic
Swift SVN r18228
2014-05-16 23:57:22 +00:00
Dave Zarzycki
46f36e19df Heap: hashing bug feedback
I personally like ~(cast)0, but (cast)-1 felt more consistent with LLVM
style; and the waffling before finishing my coffee this morning made the
code wrong. Whoops.

Swift SVN r18221
2014-05-16 22:39:34 +00:00
Dave Zarzycki
dbd023029e Heap: delete dead code
Swift SVN r18200
2014-05-16 17:30:23 +00:00
Dave Zarzycki
4bd4a4a6bc Heap: Add tombstones to make the not-found case faster
This should fix: <rdar://problem/16936107>

Swift SVN r18199
2014-05-16 17:19:13 +00:00
Dave Zarzycki
5455014d96 Heap: fix pointer-to-arena lookup
Swift SVN r18198
2014-05-16 16:43:48 +00:00
John McCall
059ed4cd10 Propagate alignment arguments around through the
slow allocation/deallocation APIs.

Swift SVN r18160
2014-05-16 01:40:36 +00:00
Dave Zarzycki
60b4a57b4d Heap: Delete old constant that was fixed in an earlier commit
Swift SVN r18153
2014-05-16 00:46:46 +00:00
Dave Zarzycki
5030fe1f83 Heap: make the introspection future proofing build on the buildbot simulator
Swift SVN r18152
2014-05-16 00:46:44 +00:00
Dave Zarzycki
792e9bd6f2 Heap: make introspection future proof against OS changes
Swift SVN r18133
2014-05-15 22:43:14 +00:00
Dave Zarzycki
6b04e56cce Heap: better hash function names and better hashing
Swift SVN r18124
2014-05-15 20:40:21 +00:00
Dave Zarzycki
9dd82e3373 Heap: slowDealloc() design feedback from John
Swift SVN r18083
2014-05-14 23:04:33 +00:00
Dave Zarzycki
03d8c146e5 Heap: walk the threads when running leaks and ignore the per-thread caches
Swift SVN r18030
2014-05-13 22:09:56 +00:00
Dave Zarzycki
49a5348df2 Heap: DaveP says that this is not needed
Swift SVN r18029
2014-05-13 22:09:49 +00:00
Dave Zarzycki
a8d814cfca Heap: Make leaks and friends more accurate
Swift SVN r18014
2014-05-13 18:15:19 +00:00
Dave Zarzycki
699ccd21a7 Heap: dead code deletion
Swift SVN r18013
2014-05-13 18:15:16 +00:00
Dave Zarzycki
cf4fbe33f5 Heap: Checkpoint leaks/heap/vm_map support
Huge allocation leaks are detected correctly.
Tiny allocation leaks are problematic, both false positive and false negative.

For example:

leaks Report Version:  2.0
Process 73345: 4980 nodes malloced for 1677 KB
Process 73345: 1 leak for 1048576 total leaked bytes.
Leak: 0x10aed0000  size=1048576  zone: SwiftZone_0x10adc35d8

Swift SVN r18007
2014-05-13 16:28:44 +00:00
Dave Zarzycki
806d2decd2 Runtime: Fix an oversight with the previous gmalloc fix
Swift SVN r17951
2014-05-12 19:30:17 +00:00
Dave Zarzycki
504701bda5 Runtime heap: defer to gmalloc when gmalloc is loaded
<rdar://problem/13318927> jDisable allocation cache when using gmalloc

Swift SVN r17950
2014-05-12 19:24:03 +00:00
Dave Zarzycki
b92b64617b Heap: avoid reentrancy when Instruments enables ObjectAlloc
We need a custom but simple map table for two reasons:
1) To precisely control our allocations to avoid reentrancy via Instruments.
2) To prepare for out-of-process introspection via Mach VM calls.

This fixes: <rdar://problem/16718231> Swift allocator must not call malloc nor global operator new

Swift SVN r17769
2014-05-09 08:56:37 +00:00
Dave Zarzycki
06731bbe21 Heap feedback: rename _swift_zone_init_ to _swift_zone_initImpl
Swift SVN r17729
2014-05-08 23:20:49 +00:00
Dave Zarzycki
8b0c9d4e74 Heap: Let Instruments ensure that the heap is setup correctly at launch
Swift SVN r17723
2014-05-08 23:12:57 +00:00
Dave Zarzycki
1326006ed8 Runtime heap/introspection: Instruments team feedback
Swift SVN r17274
2014-05-02 21:41:16 +00:00
Dave Zarzycki
1930222f3b Runtime: Instruments support plan B
Rather than go through reentrant and problematic contortions to make Swift
work with the existing Instruments hooks, they agreed to just patch some
globals that we provide to get their logic to be activated.

Swift SVN r17144
2014-05-01 06:39:45 +00:00
Dave Zarzycki
fcd4667f08 Runtime heap: add some missing locking
Swift SVN r17104
2014-04-30 19:29:56 +00:00
Dave Zarzycki
ff84cce42b Runtime: conditional fallback to pthreads given we don't ship with the OS
<rdar://problem/15169581> Custom allocation cache cannot assume OS implementation details for 1.0

Swift SVN r16842
2014-04-25 20:57:03 +00:00
Dave Zarzycki
211afa943f Runtime: better crash debugging/reporting
Swift SVN r16426
2014-04-16 21:37:16 +00:00
Dave Zarzycki
3e4f388b1f Runtime: allow realloc
Nothing should call this. We'll eventually log a warning. For now, this
silences a build warning.

Swift SVN r16061
2014-04-08 17:54:01 +00:00
Dave Zarzycki
2e76e91466 Runtime: corner case heap policy tweak
Only the compiler calls this API and the compiler never needs
placeholder heap allocations.

Swift SVN r16060
2014-04-08 17:54:00 +00:00
Adrian Prantl
af7198811c silence warnings.
Swift SVN r15839
2014-04-02 22:54:34 +00:00
Dave Zarzycki
4c97c67a82 Runtime: remove stray debugging hook
Swift SVN r15819
2014-04-02 18:46:02 +00:00
Dave Zarzycki
96d1f4760e Runtime heap: mixed fixes that make debugging easier
Swift SVN r15818
2014-04-02 18:46:00 +00:00
Dave Zarzycki
e1a60eae86 Runtime: Use 'auto' more. NFC.
Swift SVN r15817
2014-04-02 18:45:59 +00:00
Dave Zarzycki
0e8de87f05 Runtime: more SwiftObject API completeness
Swift SVN r15696
2014-03-31 22:50:19 +00:00
Dave Zarzycki
09f2e9ed57 WIP Runtime: Zone cleanup to use C++ more. NFC.
All of the malloc zone APIs are clumsy object-oriented design in C, but that
does not mean we should be too. This should clarify the design more too.

Swift SVN r15690
2014-03-31 20:06:16 +00:00
Dave Zarzycki
095633f4ba Runtime: Enable Instruments object lifecycle support
One needs to either set SWIFT_ZONE_DEBUG before launch or call SPI.

Swift SVN r15586
2014-03-28 20:46:40 +00:00
Dave Zarzycki
ce0c5899d8 Runtime: crude enumeration to generate statistics
This is foundational work for 'leaks', etc.

Swift SVN r15490
2014-03-26 06:13:03 +00:00
Dave Zarzycki
c2b486fb91 Runtime: assert on trivial double-free()s
Swift SVN r15336
2014-03-21 21:32:10 +00:00
Dave Zarzycki
c9d5bd8a92 Runtime: fix a leak during thread exit
Swift SVN r15334
2014-03-21 20:59:10 +00:00
Dave Zarzycki
2b412b4626 Runtime: fix a copy-and-paste error
<rdar://problem/16386805> Assertion failed: (bytes != 0), function swift_slowDealloc

Swift SVN r15325
2014-03-21 05:52:04 +00:00