Move ASan flag settings from DebugRelease.xcconfig to Base.xcconfig
[WebKit-https.git] / Source / bmalloc / ChangeLog
1 2015-01-28  Dana Burkart  <dburkart@apple.com>
2
3         Move ASan flag settings from DebugRelease.xcconfig to Base.xcconfig
4         https://bugs.webkit.org/show_bug.cgi?id=136765
5
6         Reviewed by Alexey Proskuryakov.
7
8         * Configurations/Base.xcconfig:
9         * Configurations/DebugRelease.xcconfig:
10
11 2015-01-21  Geoffrey Garen  <ggaren@apple.com>
12
13         bmalloc: support aligned allocation
14         https://bugs.webkit.org/show_bug.cgi?id=140732
15
16         Reviewed by Andreas Kling.
17
18         * bmalloc/Allocator.cpp:
19         (bmalloc::Allocator::allocate): New function for aligned allocation.
20
21         Small and medium requests just allocate and free until they find an
22         aligned pointer. This is slightly inefficient in the worst case, but
23         still constant-time with little-to-no space overhead.
24
25         Large requests use a new API that requires the client to specify both
26         its ideal size and alignment, and the worst-case size you would have to
27         allocate in order to produce some interior pointer of the requested size
28         and alignment. We put the burden of this calculation on the client
29         because it simplifies things if we guarantee that allocation won't fail.
30
31         XLarge requests are easy: we just forward them to vmAllocate, which
32         already supported aligned requests.
33
34         * bmalloc/BoundaryTag.h:
35         * bmalloc/BoundaryTagInlines.h:
36         (bmalloc::BoundaryTag::mergeLeft):
37         (bmalloc::BoundaryTag::mergeRight):
38         (bmalloc::BoundaryTag::merge):
39         (bmalloc::BoundaryTag::deallocate):
40         (bmalloc::BoundaryTag::split):
41         (bmalloc::BoundaryTag::allocate): No behavior change here. I just
42         refactored the interface to remove some reference out parameters in
43         order to clarify what changes and what doesn't.
44
45         * bmalloc/Heap.cpp:
46         (bmalloc::Heap::allocateXLarge): Added an alignment API.
47
48         (bmalloc::Heap::allocateLarge):
49         * bmalloc/Heap.h: Added an alignment API. I split out allocateLarge into
50         a few variants, so aligned and unaligned allocation could share some code.
51
52         * bmalloc/SegregatedFreeList.cpp:
53         (bmalloc::SegregatedFreeList::take):
54         * bmalloc/SegregatedFreeList.h: Changed to use a separate, explicit API
55         for aligned allocation. It turns out that the aligned path is pretty
56         different, since it ends up searching for two potential ways to satisfy
57         an allocation: either large enough and aligned, or large enough to split
58         into something not aligned and something large enough and aligned.
59
60         * bmalloc/VMAllocate.h:
61         (bmalloc::vmAllocate): Switched alignment to come before size because
62         that's how the memalign API specifies it.
63
64         * bmalloc/VMHeap.h:
65         (bmalloc::VMHeap::allocateLargeRange): Added an alignment API.
66
67 2015-01-20  Geoffrey Garen  <ggaren@apple.com>
68
69         bmalloc: a little bit of cleanup
70         https://bugs.webkit.org/show_bug.cgi?id=140687
71
72         Reviewed by Anders Carlsson.
73
74         * bmalloc/Algorithm.h:
75         (bmalloc::isPowerOfTwo): Added a check for 0, since 0 would break a lot
76         of code.
77
78         * bmalloc/BoundaryTag.h:
79         * bmalloc/BoundaryTagInlines.h:
80         (bmalloc::BoundaryTag::mergeLeft):
81         (bmalloc::BoundaryTag::mergeRight):
82         (bmalloc::BoundaryTag::merge):
83         (bmalloc::BoundaryTag::deallocate):
84         (bmalloc::BoundaryTag::split):
85         (bmalloc::BoundaryTag::allocate):
86         (bmalloc::BoundaryTag::mergeLargeLeft): Deleted.
87         (bmalloc::BoundaryTag::mergeLargeRight): Deleted.
88         (bmalloc::BoundaryTag::mergeLarge): Deleted.
89         (bmalloc::BoundaryTag::splitLarge): Deleted. Removed the word "Large"
90         from all these functions, since boundary tags always pertain to large
91         objects, and putting the word "Large" everywhere wasn't helping to
92         explain that.
93
94         * bmalloc/Heap.cpp:
95         (bmalloc::Heap::allocateXLarge):
96         (bmalloc::Heap::findXLarge):
97         (bmalloc::Heap::deallocateXLarge):
98         * bmalloc/Heap.h:
99         * bmalloc/VMHeap.h:
100         (bmalloc::VMHeap::allocateXLarge): Deleted.
101         (bmalloc::VMHeap::findXLarge): Deleted.
102         (bmalloc::VMHeap::deallocateXLarge): Deleted. Moved XLarge allocation
103         from VMHeap to Heap. Since the purpose of the VMHeap is to cache VM
104         ranges, and the VMHeap never caches any XLarge ranges, it doesn't
105         really make sense for the VMHeap to be involved.
106
107 2015-01-16  Geoffrey Garen  <ggaren@apple.com>
108
109         bmalloc: refactored XLarge allocation for better alignment
110         https://bugs.webkit.org/show_bug.cgi?id=140582
111
112         Reviewed by Andreas Kling.
113
114         XLarge objects used to be Large objects with an extra bit of metadata
115         that said "actually, I'm not large -- I'm extra large".
116
117         The metadata header in an XLarge allocation made it impossible for the
118         XLarge object to honor a very large alignment request.
119
120         The solution is to stop using a metadata header for XLarge objects, and
121         instead to store explicit metadata on the side.
122
123         This is a bit less astonishing, which is also nice.
124
125         Finding XLarge metadata is now a linear search. That's probably OK, since
126         it was always so in TCMalloc, and the usual number of XLarge allocations
127         in a process is 0.
128
129         This design makes it possible for the heap to cache XLarge allocations
130         with and/or without physical pages. I haven't actually done that yet
131         because the tradeoffs are subtle, so I don't want to do anything without
132         a motivating test case.
133
134         * bmalloc.xcodeproj/project.pbxproj:
135         * bmalloc/Allocator.cpp:
136         (bmalloc::Allocator::reallocate): Removed the concept of an XLargeChunk,
137         since an XLarge allocation is now just a naked buffer without a header.
138
139         (bmalloc::Allocator::allocateXLarge): Added an explicit qualifier for
140         XLarge alignment, since XLargeChunk won't give this to us implicitly
141         anymore.
142
143         * bmalloc/BoundaryTag.h:
144         (bmalloc::BoundaryTag::setRange):
145         (bmalloc::BoundaryTag::isXLarge): Deleted.
146         (bmalloc::BoundaryTag::setXLarge): Deleted.
147         * bmalloc/BoundaryTagInlines.h:
148         (bmalloc::validate):
149         (bmalloc::BoundaryTag::deallocate): Removed the XLarge hacks from Large allocations.
150
151         * bmalloc/Deallocator.cpp:
152         (bmalloc::Deallocator::deallocateXLarge):
153         (bmalloc::Deallocator::deallocateSlowCase):
154         * bmalloc/Heap.cpp:
155         (bmalloc::Heap::findXLarge):
156         (bmalloc::Heap::allocateXLarge):
157         (bmalloc::Heap::deallocateXLarge):
158         * bmalloc/Heap.h: Updated for interface changes.
159
160         * bmalloc/ObjectType.cpp:
161         (bmalloc::objectType):
162         * bmalloc/ObjectType.h:
163         (bmalloc::isXLarge): We can now tell if a pointer is XLarge just by
164         examining its bit pattern -- just like we do for other kinds of
165         allocations -- which is nice.
166
167         * bmalloc/Sizes.h:
168         * bmalloc/VMHeap.h:
169         (bmalloc::VMHeap::allocateXLarge):
170         (bmalloc::VMHeap::findXLarge):
171         (bmalloc::VMHeap::deallocateXLarge): Keep an explicit vector of metadata
172         for XLarge allocations.
173
174         * bmalloc/XLargeChunk.h: Removed.
175
176 2015-01-16  Geoffrey Garen  <ggaren@apple.com>
177
178         bmalloc: added some infrastructure for aligned allocation
179         https://bugs.webkit.org/show_bug.cgi?id=140572
180
181         Reviewed by Andreas Kling.
182
183         * bmalloc/Algorithm.h:
184         (bmalloc::isPowerOfTwo):
185         (bmalloc::roundUpToMultipleOf):
186         (bmalloc::roundDownToMultipleOf): Refactored some duplicate code to use our
187         isPowerOfTwo helper function.
188
189         * bmalloc/Allocator.cpp:
190         (bmalloc::Allocator::allocate):
191         * bmalloc/Allocator.h: Stubbed out an implementation of aligned allocation.
192         Doesn't do anything yet, but does correctly forward to system malloc
193         when bmalloc is disabled.
194
195         * bmalloc/Cache.cpp:
196         (bmalloc::Cache::allocateSlowCaseNullCache):
197         * bmalloc/Cache.h:
198         (bmalloc::Cache::allocate):
199         * bmalloc/bmalloc.h:
200         (bmalloc::api::memalign):
201         * bmalloc/mbmalloc.cpp: Stubbed out an API for aligned allocation.
202
203 2015-01-13  Geoffrey Garen  <ggaren@apple.com>
204
205         Consider alignment when allocating from a SegregatedFreeList
206         https://bugs.webkit.org/show_bug.cgi?id=140408
207
208         Reviewed by Sam Weinig.
209
210         In preparation for supporting aligned allocation.
211
212         No performance change.
213
214         Since this is just one extra branch in an already expensive function,
215         I decided not to duplicate the function just to avoid the branch in
216         the un-aligned case.
217
218         * bmalloc/SegregatedFreeList.cpp:
219         (bmalloc::SegregatedFreeList::take):
220         * bmalloc/SegregatedFreeList.h:
221
222 2015-01-13  Geoffrey Garen  <ggaren@apple.com>
223
224         Renamed minimum to size in SegregatedFreeList
225         https://bugs.webkit.org/show_bug.cgi?id=140406
226
227         Reviewed by Sam Weinig.
228
229         In preparation for supporting aligned allocation.
230
231         * bmalloc/SegregatedFreeList.cpp:
232         (bmalloc::SegregatedFreeList::takeGreedy):
233         (bmalloc::SegregatedFreeList::take): Every size passed to malloc is
234         really just a minimum. Let's not imply that this value is special.
235
236 2015-01-11  Dan Bernstein  <mitz@apple.com>
237
238         Geoff is organized, but he is not an organization.
239
240         Rubber-stamped by Anders Carlsson.
241
242         * bmalloc.xcodeproj/project.pbxproj: Removed the ORGANIZATIONNAME project attribute.
243
244 2015-01-07  Geoffrey Garen  <ggaren@apple.com>
245
246         Make bmalloc work with ASan
247         https://bugs.webkit.org/show_bug.cgi?id=140194
248
249         Reviewed by Mark Lam.
250
251         * bmalloc/BPlatform.h: Added a way to detect Darwin OSes, since we need
252         an OS-specific API to test for loaded runtime libraries.
253
254         * bmalloc/Environment.cpp:
255         (bmalloc::isASanEnabled):
256         (bmalloc::Environment::computeIsBmallocEnabled): Disabled bmalloc if
257         ASan is enabled, since system malloc has the Asan hooks we need.
258
259         You could check for the ASan compile-time flag instead, but doing this
260         check at runtime prepares bmalloc for a world where it is a dynamic
261         library that might be loaded into projects it did not compile with.
262
263 2015-01-05  Geoffrey Garen  <ggaren@apple.com>
264
265         Fix up bmalloc's PerThread for use on Linux
266         https://bugs.webkit.org/show_bug.cgi?id=139804
267
268         Reviewed by Anders Carlsson.
269
270         The previous implementation was a bit slow.
271
272         * bmalloc/PerThread.h:
273         (bmalloc::PerThreadStorage<Cache>::get):
274         (bmalloc::PerThreadStorage::get):
275         (bmalloc::PerThreadStorage::init): Added a catch-all cross-platform Unix
276         way to do fast per-thread access without taking a lock every time. This
277         probably works on all the platforms we care about, and it matches other
278         techniques we use elsewhere in WebKit.
279
280         (bmalloc::PerThread<T>::getFastCase): Removed the conditional from
281         this class because PerThreadStorage now encapsulates everything that
282         needs to be conditional.
283
284         (bmalloc::PerThreadStorage::initSharedKeyIfNeeded): Deleted.
285
286 2014-12-26  Dan Bernstein  <mitz@apple.com>
287
288         <rdar://problem/19348208> REGRESSION (r177027): iOS builds use the wrong toolchain
289         https://bugs.webkit.org/show_bug.cgi?id=139950
290
291         Reviewed by David Kilzer.
292
293         * Configurations/Base.xcconfig: Only define TOOLCHAINS when building for OS X, doing so
294         in a manner that works with Xcode 5.1.1.
295
296 2014-12-15  Geoffrey Garen  <ggaren@apple.com>
297
298         Safari crashes when you set Malloc environment variables
299         https://bugs.webkit.org/show_bug.cgi?id=139656
300
301         Reviewed by Michael Saboff.
302
303         I forgot to cover the realloc() case. Whoops. (OoPS?)
304
305         This time around, I ran the full MallocBench test suite in Malloc=1
306         mode, and it passed.
307
308         * bmalloc/Allocator.cpp:
309         (bmalloc::Allocator::reallocate):
310         * bmalloc/Allocator.h: Pushed realloc() logic down into the allocator.
311         It needs to be down there so that we can do the short-circuiting check
312         for whether bmalloc is enabled first.
313
314         Also added the check.
315
316         * bmalloc/Cache.cpp:
317         (bmalloc::Cache::scavenge):
318         (bmalloc::Cache::Cache):
319         (bmalloc::Cache::reallocateSlowCaseNullCache):
320         * bmalloc/Cache.h:
321         (bmalloc::Cache::deallocator):
322         (bmalloc::Cache::reallocate): Ditto.
323
324         * bmalloc/bmalloc.h:
325         (bmalloc::api::free):
326         (bmalloc::api::realloc): Ditto.
327
328         (bmalloc::api::scavenge): Pushed this down into Cache to match the
329         surrounding functions.
330
331 2014-12-11  Geoffrey Garen  <ggaren@apple.com>
332
333         bmalloc should support system memory analysis tools (part 2)
334         https://bugs.webkit.org/show_bug.cgi?id=139565
335
336         Reviewed by Mark Lam.
337
338         This patch actually queries the environment to see if memory analysis
339         tools have been enabled.
340
341         * bmalloc/Deallocator.cpp:
342         (bmalloc::Deallocator::scavenge): Don't process the object log if
343         we've disabled bmalloc because it will be full of invalid nullptrs.
344
345         * bmalloc/Environment.cpp:
346         (bmalloc::isMallocEnvironmentVariableSet): Test for the list of known
347         Malloc debugging flags. I also added a plain "Malloc" catch-all for
348         when you want to disable bmalloc without enabling any kind of funny
349         business.
350
351         It would be slightly nicer just to iterate the list of environment
352         variables and strstr them, but getenv is the more portable option,
353         and performance here doesn't really matter.
354
355         (bmalloc::isLibgmallocEnabled): Test for the libgmalloc insertion
356         environment variable.
357
358         (bmalloc::Environment::computeIsBmallocEnabled):
359
360 2014-12-11  Geoffrey Garen  <ggaren@apple.com>
361
362         Try to fix the iOS simulator build.
363
364         #include the declaration of malloc / free.
365
366         * bmalloc/Allocator.cpp:
367         * bmalloc/Deallocator.cpp:
368
369 2014-12-11  Geoffrey Garen  <ggaren@apple.com>
370
371         Try to fix the build.
372
373         * bmalloc.xcodeproj/project.pbxproj: Marked a header exported.
374
375 2014-12-11  Geoffrey Garen  <ggaren@apple.com>
376
377         bmalloc should support system memory analysis tools (part 1)
378         https://bugs.webkit.org/show_bug.cgi?id=139559
379
380         Reviewed by Mark Lam.
381
382         This patch adds the hooks to disable bmalloc at runtime if certain
383         environment variables are set, but doesn't actually read from the
384         environment yet.
385
386         No performance change.
387
388         * bmalloc.xcodeproj/project.pbxproj: Added the Environment class, which
389         we'll use to read environment variables and see if memory analysis tools
390         have been enabled.
391
392         * bmalloc/Allocator.cpp:
393         (bmalloc::Allocator::Allocator):
394         (bmalloc::Allocator::allocateSlowCase): Added a hook to disable bmalloc
395         on the allocation path. We cache the setting to make the check fast.
396
397         * bmalloc/Allocator.h: Interface changes.
398
399         * bmalloc/Cache.cpp:
400         (bmalloc::Cache::Cache): Pass a heap pointer through to our allocator
401         and deallocator. This main purpose is to enable them to query the
402         environment for whether bmalloc is enabled; but this is also a slightly
403         cleaner way to guarantee to them that the Heap has been pre-initialized.
404
405         * bmalloc/Deallocator.cpp:
406         (bmalloc::Deallocator::Deallocator): If bmalloc is disable, artificially
407         fill the object log to force us to take the slow path on all deallocations.
408
409         (bmalloc::Deallocator::deallocateSlowCase): Do the disabled check.
410
411         * bmalloc/Deallocator.h: Interface changes.
412
413         * bmalloc/Environment.cpp: Added.
414         (bmalloc::Environment::Environment):
415         (bmalloc::Environment::computeIsBmallocEnabled):
416         * bmalloc/Environment.h: Added.
417         (bmalloc::Environment::isBmallocEnabled): This is the class that will
418         encapsulate looking for environment variables that turn on heap
419         analysis tools.
420
421         * bmalloc/Heap.h:
422         (bmalloc::Heap::environment):
423
424         * bmalloc/Mutex.h:
425         (bmalloc::Mutex::Mutex):
426         * bmalloc/StaticMutex.h: A little refactoring to clarify these comments,
427         since I got super confused about them while writing this patch.
428
429         * bmalloc/VMHeap.cpp: Fixed an #include.
430
431 2014-12-09  David Kilzer  <ddkilzer@apple.com>
432
433         Switch from using PLATFORM_NAME to SDK selectors in ANGLE, bmalloc, gtest, JavaScriptCore, WTF
434         <http://webkit.org/b/139212>
435
436         Reviewed by Joseph Pecoraro.
437
438         * Configurations/Base.xcconfig:
439         - Only set GCC_ENABLE_OBJC_GC, GCC_MODEL_TUNING and TOOLCHAINS
440           on OS X.
441         * Configurations/DebugRelease.xcconfig:
442         - Only set MACOSX_DEPLOYMENT_TARGET and SDKROOT on OS X.
443
444 2014-11-07  Geoffrey Garen  <ggaren@apple.com>
445
446         bmalloc uses 8X more virtual memory than necessary
447         https://bugs.webkit.org/show_bug.cgi?id=138495
448
449         Reviewed by Mark Lam.
450
451         iOS has a per-process virtual memory cap around 1GB, so there's some
452         value to not going totally ham with virtual memory.
453
454         We currently use about 8X the necessary amount:
455             - 2X to align our VM allocation
456             - 4X to reserve small / medium / (2) large chunk VM ranges per superchunk
457
458         We can cut that down:
459             - Return the unaligned portion of our VM allocation (-2X)
460             - Use all the chunks in a superchunk, instead of allocating one
461               chunk per superchunk (-4X)
462
463         * bmalloc/Algorithm.h:
464         (bmalloc::roundUpToMultipleOf): Added a non-constant version of this
465         function so we can call it with getpagesize() at runtime.
466
467         * bmalloc/Chunk.h:
468         * bmalloc/LargeChunk.h:
469         (bmalloc::LargeChunk::create): Deleted. Instead of each chunk allocating
470         its own VM, VMHeap allocates the superchunk and all the chunks in it at a time.
471
472         * bmalloc/VMAllocate.h:
473         (bmalloc::vmValidate):
474         (bmalloc::vmAllocate): ASSERT that mmap succeeds to make crashes clearer
475         if it does not succeed. Allocate precisely, and give back the extra.
476
477         * bmalloc/VMHeap.cpp:
478         (bmalloc::VMHeap::allocateSuperChunk):
479         (bmalloc::VMHeap::allocateSmallChunk): Deleted.
480         (bmalloc::VMHeap::allocateMediumChunk): Deleted.
481         (bmalloc::VMHeap::allocateLargeChunk): Deleted. Use all the chunks
482         in a superchunk, instead of just one.
483
484         * bmalloc/VMHeap.h:
485         (bmalloc::VMHeap::allocateSmallPage):
486         (bmalloc::VMHeap::allocateMediumPage):
487         (bmalloc::VMHeap::allocateLargeRange):
488         * bmalloc/XLargeChunk.h:
489         (bmalloc::XLargeChunk::create): Updated to match changes above.
490
491 2014-11-01  David Kilzer  <ddkilzer@apple.com>
492
493         JavaScriptCore is missing debug info for bmalloc because libbmalloc.a is stripped
494         <https://webkit.org/b/138286>
495         <rdar://problem/18847087>
496
497         Reviewed by Dan Bernstein.
498
499         * Configurations/bmalloc.xcconfig: Set STRIP_INSTALLED_PRODUCT
500         to NO for the target that produces libbmalloc.a so that the
501         debug symbols will be linked into JavaScriptCore and end up in
502         its dSYM file.
503
504 2014-10-30  Dana Burkart  <dburkart@apple.com>
505
506         <rdar://problem/18821260> Prepare for the mysterious future
507
508         Reviewed by Lucas Forschler.
509
510         * Configurations/Base.xcconfig:
511         * Configurations/DebugRelease.xcconfig:
512
513 2014-09-24  Geoffrey Garen  <ggaren@apple.com>
514
515         bmalloc: cleaned up fast path vs slow path
516         https://bugs.webkit.org/show_bug.cgi?id=137081
517
518         Reviewed by Sam Weinig.
519
520         Might be a 1% speedup on MallocBench. Also cleans up the code a bit.
521
522         * bmalloc/Allocator.cpp:
523         (bmalloc::Allocator::Allocator): Merged the small and medium range
524         caches, just like the small and medium allocators. Ranges are abstract
525         objects that don't really care whether they hold small or medium objects,
526         so they don't need to be segregated.
527
528         (bmalloc::Allocator::scavenge): Ditto.
529
530         (bmalloc::Allocator::allocateBumpRangeSlowCase):
531         (bmalloc::Allocator::allocateBumpRange): Same thing here, except that
532         we do care a tiny bit, because we need to specify small vs medium when
533         allocating new ranges from the heap, to ensure that the heap allocates
534         from the right segment of VM.
535
536         (bmalloc::Allocator::allocateLarge):
537         (bmalloc::Allocator::allocateXLarge): NO_INLINE because this was clouding
538         up the fast path. Large allocation performance is dominated by allocation
539         logic and initialization, so inlining it doesn't help.
540
541         (bmalloc::Allocator::allocateSlowCase): Slow path got a bit cleaner since
542         it doesn't need to distinguish small vs medium objects.
543
544         (bmalloc::Allocator::allocateSmallBumpRange): Deleted.
545         (bmalloc::Allocator::allocateMediumBumpRange): Deleted.
546
547         * bmalloc/Allocator.h:
548         * bmalloc/BumpRange.h:
549
550         * bmalloc/Cache.cpp:
551         (bmalloc::Cache::allocateSlowCase): Deleted.
552         (bmalloc::Cache::deallocateSlowCase): Deleted.
553         * bmalloc/Cache.h:
554         (bmalloc::Cache::allocate):
555         (bmalloc::Cache::deallocate):
556         (bmalloc::Cache::allocateFastCase): Deleted.
557         (bmalloc::Cache::deallocateFastCase): Deleted. Removed the Cache slow
558         paths. The downside to this change is that the fast path branches to two
559         distinct failure cases instead of one. The upside is that the slow path
560         doesn't need to re-read the segment register, which is not as cheap as a
561         normal register, and it doesn't need to do an extra level of function 
562         call. Seems to be worth it.
563
564         * bmalloc/Deallocator.h:
565         * bmalloc/Heap.cpp:
566         (bmalloc::Heap::refillSmallBumpRangeCache):
567         (bmalloc::Heap::refillMediumBumpRangeCache):
568         * bmalloc/Heap.h: Updated for interface changes.
569
570         * bmalloc/Sizes.h: The most ranges a cache will hold is the number of
571         small lines in a page / 2, since any other free lines will coalesce
572         with their neighbors.
573
574 2014-09-23  Geoffrey Garen  <ggaren@apple.com>
575
576         Rolled out r173346.
577
578             bmalloc should honor the FastMalloc statistics API
579             https://bugs.webkit.org/show_bug.cgi?id=136592
580
581         This didn't really work. Because we allow ranges with and without
582         physical pages to merge, and we allow double-committing and
583         double-decommitting, we can't rely on commit actions to track memory
584         footprint.
585
586         * bmalloc/Heap.cpp:
587         (bmalloc::Heap::size): Deleted.
588         (bmalloc::Heap::capacity): Deleted.
589         * bmalloc/Heap.h:
590         * bmalloc/VMHeap.cpp:
591         (bmalloc::VMHeap::VMHeap):
592         (bmalloc::VMHeap::allocateSmallChunk):
593         (bmalloc::VMHeap::allocateMediumChunk):
594         (bmalloc::VMHeap::allocateLargeChunk):
595         * bmalloc/VMHeap.h:
596         (bmalloc::VMHeap::allocateSmallPage):
597         (bmalloc::VMHeap::allocateMediumPage):
598         (bmalloc::VMHeap::allocateLargeRange):
599         (bmalloc::VMHeap::deallocateSmallPage):
600         (bmalloc::VMHeap::deallocateMediumPage):
601         (bmalloc::VMHeap::deallocateLargeRange):
602         (bmalloc::VMHeap::size): Deleted.
603         (bmalloc::VMHeap::capacity): Deleted.
604         * bmalloc/bmalloc.h:
605         (bmalloc::api::heapSize): Deleted.
606         (bmalloc::api::heapCapacity): Deleted.
607
608 2014-09-23  Geoffrey Garen  <ggaren@apple.com>
609
610         bmalloc: Allocation should be more precise
611         https://bugs.webkit.org/show_bug.cgi?id=136993
612
613         Reviewed by Gavin Barraclough.
614
615         13% reduction in heap size on the MallocBench *_memory_warning benchmarks.
616
617         This patch teaches the allocator to merge adjacent free lines into a
618         single allocatable range. This allows us to shrink the size of an
619         individual line without increasing fragmentation or the rate of allocator
620         slow paths.
621
622         We'll only take more slow paths when available memory is sparse, which
623         is exactly when it's worth it. When available memory is dense, we'll
624         take fewer slow paths.
625
626         * bmalloc.xcodeproj/project.pbxproj:
627         * bmalloc/Algorithm.h:
628         (bmalloc::divideRoundingUp):
629
630         * bmalloc/Allocator.cpp:
631         (bmalloc::Allocator::Allocator): Updated for interface changes.
632
633         (bmalloc::Allocator::scavenge): Scavenge by object instead of by line.
634         Now that we merge lines, it's not convenient to scavenge by line.
635
636         (bmalloc::Allocator::allocateSmallBumpRange):
637         (bmalloc::Allocator::allocateMediumBumpRange): Allocate whole ranges
638         instead of individual lines.
639
640         (bmalloc::Allocator::allocateSlowCase):
641         (bmalloc::Allocator::allocateSmallLine): Deleted.
642         (bmalloc::Allocator::allocateMediumLine): Deleted.
643         (bmalloc::Allocator::allocateMedium): Deleted.
644         * bmalloc/Allocator.h:
645         (bmalloc::Allocator::allocateFastCase): Folded medium allocations
646         into the standard fast path with small allocations. Since a BumpAllocator
647         just allocates out of an arbitrary range, it doesn't need to distinguish
648         between small and medium lines.
649
650         * bmalloc/BumpAllocator.h:
651         (bmalloc::BumpAllocator::size):
652         (bmalloc::BumpAllocator::BumpAllocator):
653         (bmalloc::BumpAllocator::init):
654         (bmalloc::BumpAllocator::refill):
655         (bmalloc::BumpAllocator::line): Deleted. No need to track line information
656         anymore: the heap just gives us a pointer and a pre-computed number of
657         objects, and we allocate them.
658
659         * bmalloc/Deallocator.cpp:
660         (bmalloc::Deallocator::processObjectLog): Updated for interface changes.
661
662         * bmalloc/Heap.cpp:
663         (bmalloc::Heap::Heap):
664         (bmalloc::Heap::initializeLineMetadata): Pre-compute precise metadata
665         detailing where all objects will lie in memory. After we merge two lines,
666         we might allocate an object that spans from one line to the next. This
667         metadata details which bits of memory overlap in that way, and how they
668         overlap.
669
670         (bmalloc::Heap::refillSmallBumpRangeCache):
671         (bmalloc::Heap::refillMediumBumpRangeCache): Scan a whole page at a time,
672         and merge adjacent free lines into BumpRanges.
673
674         (bmalloc::Heap::allocateSmallPage):
675         (bmalloc::Heap::allocateMediumPage):
676         (bmalloc::Heap::deallocateSmallLine):
677         (bmalloc::Heap::deallocateMediumLine): Track pages rather than lines,
678         since we scan for free memory a page at a time.
679
680         (bmalloc::Heap::allocateSmallLineSlowCase): Deleted.
681         (bmalloc::Heap::allocateMediumLineSlowCase): Deleted. Folded into the
682         fast path.
683
684         * bmalloc/Heap.h:
685         (bmalloc::Heap::derefSmallLine):
686         (bmalloc::Heap::derefMediumLine):
687         (bmalloc::Heap::deallocateSmallLine): Deleted.
688         (bmalloc::Heap::allocateSmallLine): Deleted.
689         (bmalloc::Heap::deallocateMediumLine): Deleted.
690         (bmalloc::Heap::allocateMediumLine): Deleted. Updated for interface changes.
691
692         * bmalloc/Line.h:
693         (bmalloc::Line<Traits>::ref):
694         (bmalloc::Line<Traits>::deref):
695         (bmalloc::Line<Traits>::concurrentRef): Deleted. We don't pass a derefCount
696         anymore, since we only ever deref by 1 now.
697
698         * bmalloc/MediumAllocator.h:
699         (bmalloc::MediumAllocator::isNull): Deleted.
700         (bmalloc::MediumAllocator::MediumAllocator): Deleted.
701         (bmalloc::MediumAllocator::line): Deleted.
702         (bmalloc::MediumAllocator::allocate): Deleted.
703         (bmalloc::MediumAllocator::derefCount): Deleted.
704         (bmalloc::MediumAllocator::refill): Deleted.
705         (bmalloc::MediumAllocator::clear): Deleted. Deleted some code that's
706         been dead for a while, since it doesn't build anymore with this patch.
707
708         * bmalloc/Page.h:
709         (bmalloc::Page::sizeClass):
710         (bmalloc::Page::setSizeClass):
711         (bmalloc::Page::smallSizeClass): Deleted.
712         (bmalloc::Page::setSmallSizeClass): Deleted. Renamed setSmallSizeClass
713         to sizeClass, since we use it for medium sizes too.
714
715         * bmalloc/Sizes.h:
716         (bmalloc::Sizes::sizeClass):
717         (bmalloc::Sizes::objectSize): Shrank line sizes to save memory.
718
719         (bmalloc::Sizes::smallSizeClassFor): Deleted.
720         (bmalloc::Sizes::mediumSizeClassFor): Deleted.
721
722         * bmalloc/bmalloc.h:
723         (bmalloc::api::realloc): Now that we have precise objects sizes, realloc
724         can be a bit more precise. It also has to be, since we can't guarantee
725         that an object ends at the end of a line anymore.
726
727 2014-09-19  Daniel Bates  <dabates@apple.com>
728
729         Always assume internal SDK when building configuration Production
730         https://bugs.webkit.org/show_bug.cgi?id=136925
731         <rdar://problem/18362399>
732
733         Reviewed by Dan Bernstein.
734
735         * Configurations/Base.xcconfig:
736
737 2014-09-16  Geoffrey Garen  <ggaren@apple.com>
738
739         bmalloc: moved line caches from the deallocator to the allocator
740         https://bugs.webkit.org/show_bug.cgi?id=136868
741
742         Reviewed by Gavin Barraclough.
743
744         I did this mostly as a simplification, to make it easier to change the
745         allocation strategy.
746
747         No throughput change on MallocBench. Saves about 50kB.
748
749         Since the deallocator needs to lock the heap when freeing lines anyway,
750         there isn't much benefit to giving the deallocator a local cache of
751         deallocated lines.
752
753         We still give the allocator a local cache of lines because that does
754         reduce the frequency at which it needs to lock the heap in order to
755         acquire more lines.
756
757         * bmalloc/Allocator.cpp:
758         (bmalloc::Allocator::scavenge):
759         (bmalloc::Allocator::allocateSmallLine):
760         (bmalloc::Allocator::allocateMediumLine):
761         (bmalloc::Allocator::allocateMedium):
762         (bmalloc::Allocator::allocateSlowCase):
763         * bmalloc/Allocator.h:
764         * bmalloc/Deallocator.cpp:
765         (bmalloc::Deallocator::Deallocator):
766         (bmalloc::Deallocator::scavenge):
767         (bmalloc::Deallocator::processObjectLog):
768         (bmalloc::Deallocator::deallocateSmallLine): Deleted.
769         (bmalloc::Deallocator::allocateSmallLine): Deleted.
770         (bmalloc::Deallocator::deallocateMediumLine): Deleted.
771         (bmalloc::Deallocator::allocateMediumLine): Deleted.
772         * bmalloc/Deallocator.h:
773
774         * bmalloc/Sizes.h:
775         * bmalloc/VMAllocate.h: Took the opportunity to make the line cache size
776         exactly one page in size. That's about what we were shooting for anyway,
777         and it may make it easier to switch to per-page allocation in future.
778
779 2014-09-15  Geoffrey Garen  <ggaren@apple.com>
780
781         bmalloc: allocate small and medium objects using the same bump pointer class
782         https://bugs.webkit.org/show_bug.cgi?id=136843
783
784         Reviewed by Gavin Barraclough.
785
786         4% speedup on MallocBench.
787
788         Now that medium-sized objects have dedicated per-size allocators, they
789         don't need to use an arbitrary bump pointer allocator. This means that
790         every allocator knows how many objects it will allocate from the start,
791         and we don't need a post-processing step to adjust refcounts based on
792         real allocation count.
793
794         * bmalloc.xcodeproj/project.pbxproj: Renamed SmallAllocator to BumpAllocator
795         since it's used for small and medium objects now.
796
797         * bmalloc/Allocator.cpp:
798         (bmalloc::Allocator::Allocator): Updated to use new interface.
799         (bmalloc::Allocator::scavenge): To "retire" an allocator, we just need
800         to make sure that we finish allocating all the objects in it.
801
802         (bmalloc::Allocator::allocateMedium):
803         (bmalloc::Allocator::allocateSlowCase):
804         (bmalloc::Allocator::retire): Deleted.
805         (bmalloc::Allocator::processSmallAllocatorLog): Deleted.
806         (bmalloc::Allocator::processMediumAllocatorLog): Deleted.
807         * bmalloc/Allocator.h:
808         (bmalloc::Allocator::allocateFastCase): Removed abstractions and data
809         used to post-process an allocator based on how many objects it allocated.
810
811         * bmalloc/BumpAllocator.h: Copied from Source/bmalloc/bmalloc/SmallAllocator.h.
812         (bmalloc::BumpAllocator::BumpAllocator):
813         (bmalloc::BumpAllocator::init):
814         (bmalloc::BumpAllocator::line):
815         (bmalloc::BumpAllocator::validate):
816         (bmalloc::BumpAllocator::allocate):
817         (bmalloc::BumpAllocator::refill):
818         (bmalloc::BumpAllocator::clear): Updated these functions to be agnostic
819         about the kinds of lines they allocate into. In some cases, the line
820         type must be provided as a template parameter by the caller.
821
822         (bmalloc::SmallAllocator::SmallAllocator): Deleted.
823         (bmalloc::SmallAllocator::line): Deleted.
824         (bmalloc::SmallAllocator::allocate): Deleted.
825         (bmalloc::SmallAllocator::objectCount): Deleted.
826         (bmalloc::SmallAllocator::derefCount): Deleted.
827         (bmalloc::SmallAllocator::refill): Deleted.
828         (bmalloc::SmallAllocator::clear): Deleted.
829
830         * bmalloc/ObjectType.h:
831         (bmalloc::isMedium):
832
833         * bmalloc/SmallAllocator.h:
834         (bmalloc::SmallAllocator::isNull): Deleted.
835         (bmalloc::SmallAllocator::canAllocate): Deleted.
836         (bmalloc::SmallAllocator::SmallAllocator): Deleted.
837         (bmalloc::SmallAllocator::line): Deleted.
838         (bmalloc::SmallAllocator::allocate): Deleted.
839         (bmalloc::SmallAllocator::objectCount): Deleted.
840         (bmalloc::SmallAllocator::derefCount): Deleted.
841         (bmalloc::SmallAllocator::refill): Deleted.
842         (bmalloc::SmallAllocator::clear): Deleted.
843
844 2014-09-12  Geoffrey Garen  <ggaren@apple.com>
845
846         Fixed a goof in bmalloc Vector sizing
847         https://bugs.webkit.org/show_bug.cgi?id=136795
848
849         Reviewed by Gavin Barraclough and Sam Weinig.
850
851         We want our minimum vector to be page-sized since the OS will give us
852         a page no matter what -- but we want that many bytes, and not enough
853         bytes to store that many elements.
854
855         * bmalloc/Vector.h: Math is hard.
856
857 2014-09-11  Geoffrey Garen  <ggaren@apple.com>
858
859         bmalloc should segregate medium-sized objects by line like it does for small-sized objects
860         https://bugs.webkit.org/show_bug.cgi?id=136693
861
862         Reviewed by Gavin Barraclough.
863
864         4% reduction in heap size on the MallocBench *_memory_warning benchmarks.
865
866         No throughput change.
867
868         We keep an array of medium allocators, just like our array of small
869         allocators.
870
871         In future, we can simplify the allocation fast path by merging the small
872         and medium allocator arrays. For now, this is the simplest change that
873         gets the win.
874
875         * bmalloc/Allocator.cpp:
876         (bmalloc::Allocator::Allocator):
877         (bmalloc::Allocator::scavenge):
878         (bmalloc::Allocator::allocateMedium):
879         * bmalloc/Allocator.h:
880         * bmalloc/Sizes.h:
881         (bmalloc::Sizes::mediumSizeClassFor):
882
883 2014-09-11  Geoffrey Garen  <ggaren@apple.com>
884
885         Reviewed by Sam Weinig.
886
887         Renamed log => retire for clarity.
888
889         * bmalloc/Allocator.cpp:
890         (bmalloc::Allocator::scavenge):
891         (bmalloc::Allocator::retire):
892         (bmalloc::Allocator::allocateMedium):
893         (bmalloc::Allocator::allocateSlowCase):
894         (bmalloc::Allocator::log): Deleted.
895         * bmalloc/Allocator.h:
896
897 2014-09-11  Geoffrey Garen  <ggaren@apple.com>
898
899         bmalloc: eager scavenge leaves behind a bogus allocator
900         https://bugs.webkit.org/show_bug.cgi?id=136743
901
902         Reviewed by Sam Weinig.
903
904         Be sure to clear the allocator after logging it in the eager scavenge
905         case, so that we don't later try to allocate out of the lines that we
906         have thrown away.
907
908         We didn't need to do this previously because scavenge would only happen
909         at thread exit time, after which no further allocation from the per-thread
910         cache would take place.
911
912         * bmalloc/Allocator.cpp:
913         (bmalloc::Allocator::scavenge):
914         * bmalloc/MediumAllocator.h:
915         (bmalloc::MediumAllocator::clear):
916         * bmalloc/SmallAllocator.h:
917         (bmalloc::SmallAllocator::clear):
918
919 2014-09-05  Geoffrey Garen  <ggaren@apple.com>
920
921         bmalloc should honor the FastMalloc statistics API
922         https://bugs.webkit.org/show_bug.cgi?id=136592
923
924         Reviewed by Gavin Barraclough.
925
926         We do this by tracking "size" and "capacity" in the VM heap.
927
928         The VM heap's "capacity" is all the VM we ever allocated.
929
930         The VM heap's "size" the subset of VM currently held onto by the
931         VM heap (and therefore not in use by the regular heap).
932
933         Somewhat ironically, reducing the process's memory footprint, increases
934         the size of the VM heap, since the VM heap holds the pages that are
935         purely virtual and not physical.
936
937         * bmalloc/Heap.cpp:
938         (bmalloc::Heap::size):
939         (bmalloc::Heap::capacity):
940         * bmalloc/Heap.h:
941         * bmalloc/VMHeap.cpp:
942         (bmalloc::VMHeap::VMHeap):
943         (bmalloc::VMHeap::allocateSmallChunk):
944         (bmalloc::VMHeap::allocateMediumChunk):
945         (bmalloc::VMHeap::allocateLargeChunk):
946         * bmalloc/VMHeap.h:
947         (bmalloc::VMHeap::size):
948         (bmalloc::VMHeap::capacity):
949         (bmalloc::VMHeap::allocateSmallPage):
950         (bmalloc::VMHeap::allocateMediumPage):
951         (bmalloc::VMHeap::allocateLargeRange):
952         (bmalloc::VMHeap::deallocateSmallPage):
953         (bmalloc::VMHeap::deallocateMediumPage):
954         (bmalloc::VMHeap::deallocateLargeRange):
955         * bmalloc/bmalloc.h:
956         (bmalloc::api::heapSize):
957         (bmalloc::api::heapCapacity):
958
959 2014-09-02  Geoffrey Garen  <ggaren@apple.com>
960
961         bmalloc crashes on the EWS bots (due to bad large object allocation)
962         https://bugs.webkit.org/show_bug.cgi?id=136469
963
964         Reviewed by Andreas Kling.
965
966         It's possible to convince bmalloc to perform a bad large object allocation,
967         through these steps:
968
969         (1) Insert object A into freelist F0.
970
971         (2) Split, merge and split again A's neighbors such that object B is
972         inserted into freelist F0, with boundary tag and size equal to object A,
973         but pointer not completely equal to object A. Put object B at the head of F0.
974
975         (3) Allocate some other object from F0, swapping its position in the
976         freelist with object B, such that object A is now ahead of object B.
977
978         --> Now, the next allocation for size A/B will allocate object A, which
979         has a slightly wrong idea about where the object actually begins.
980         Immediately, you'll corrupt a little memory, and over time, you'll also
981         corrupt boundary tag metadata.
982
983         The solution is to store the begin pointer in the boundary tag. Luckily,
984         this doesn't make the tag any bigger, and it's not a noticeable slowdown
985         on MallocBench.
986
987         * bmalloc/Algorithm.h:
988         (bmalloc::rightShift):
989         * bmalloc/BeginTag.h:
990         (bmalloc::BeginTag::isInFreeList): This is the bug fix. Make sure to
991         validate the start pointer when popping off the free list. Through a
992         very uncommon set of steps, it is possible to have an item in the free
993         list that is valid by all accounts except for its start pointer.
994
995         * bmalloc/BoundaryTag.h:
996         (bmalloc::BoundaryTag::compactBegin):
997         (bmalloc::BoundaryTag::setRange):
998         (bmalloc::BoundaryTag::setSize): Deleted. Record a compact version of the
999         start pointer. We don't need the whole pointer -- just the offset, in
1000         largeAlignment increments, into the relevant boundary tag bucket.
1001
1002         * bmalloc/BoundaryTagInlines.h:
1003         (bmalloc::validateNext):
1004         (bmalloc::BoundaryTag::init):
1005         (bmalloc::BoundaryTag::mergeLarge):
1006         (bmalloc::BoundaryTag::splitLarge):
1007         * bmalloc/SegregatedFreeList.cpp:
1008         (bmalloc::SegregatedFreeList::insert):
1009         (bmalloc::SegregatedFreeList::takeGreedy):
1010         (bmalloc::SegregatedFreeList::take): Provide the whole range instead of
1011         the size when establishing a boundary tag, as required by the new
1012         interface.
1013
1014         * bmalloc/Sizes.h:
1015
1016 2014-08-14  Geoffrey Garen  <ggaren@apple.com>
1017
1018         Fixed a bmalloc crash seen on the EWS bot
1019         https://bugs.webkit.org/show_bug.cgi?id=135955
1020
1021         Reviewed by Andreas Kling.
1022
1023         * bmalloc/Syscall.h: Some CG APIs vm_copy their input buffers. If the
1024         input buffer is a malloc region, that region will get marked Copy-On-Write
1025         by the kernel. Calls to madvise() for COW regions fail and return EINVAL
1026         on older OS X's. In 10.10, they still fail, but they do not return
1027         EINVAL.
1028
1029         So, we can only ASSERT that our syscalls succeed starting with 10.10.
1030
1031 2014-08-14  Geoffrey Garen  <ggaren@apple.com>
1032
1033         Fixed the bmalloc build
1034         https://bugs.webkit.org/show_bug.cgi?id=135953
1035
1036         Reviewed by Andreas Kling.
1037
1038         * bmalloc.xcodeproj/project.pbxproj: Marked a few headers as private.
1039         These headers are used, so they must be available outside the project.
1040
1041 2014-08-13  Daniel Bates  <dabates@apple.com>
1042
1043         Attempt to fix the build following <http://trac.webkit.org/changeset/172576>
1044         (https://bugs.webkit.org/show_bug.cgi?id=135895)
1045
1046         Substitute PerThreadStorage<T>::initSharedKeyIfNeeded() for initSharedKeyIfNeeded() in
1047         implementation of PerThread<T>::getFastCase().
1048
1049         * bmalloc/PerThread.h:
1050         (bmalloc::PerThread<T>::getFastCase):
1051
1052 2014-08-13  Daniel Bates  <dabates@apple.com>
1053
1054         Make bmalloc::PerThread work without C++ thread local storage
1055         https://bugs.webkit.org/show_bug.cgi?id=135895
1056
1057         Reviewed by Geoffrey Garen.
1058
1059         Implement support for building bmalloc without C++ thread local storage.
1060
1061         * bmalloc/BPlatform.h: Remove macro define BPLATFORM_IOS_SIMULATOR. Added macro function
1062         BCOMPILER_SUPPORTS() and macro define BCOMPILER_SUPPORTS_CXX_THREAD_LOCAL that can be used
1063         to determine whether the compiler supports C++ thread local storage.
1064         * bmalloc/PerThread.h:
1065         (bmalloc::PerThreadStorage::get): Modified to call pthread_getspecific() when building
1066         without C++ thread local storage.
1067         (bmalloc::PerThreadStorage::initSharedKeyIfNeeded): Added.
1068         (bmalloc::PerThreadStorage::init): Moved logic to initialize shared Pthread key from here to
1069         PerThreadStorage::initSharedKeyIfNeeded().
1070         (bmalloc::PerThread<T>::getFastCase): Modified to call PerThreadStorage::initSharedKeyIfNeeded()
1071         before querying PerThreadStorage::get() when building without C++ thread local storage so as to
1072         ensure that the shared key has been initialized.
1073         (_pthread_setspecific_direct): Deleted.
1074         (_pthread_getspecific_direct): Deleted.
1075
1076 2014-08-13  Daniel Bates  <dabates@apple.com>
1077
1078         [iOS] Make JavaScriptCore and bmalloc build with the public SDK
1079         https://bugs.webkit.org/show_bug.cgi?id=135848
1080
1081         Reviewed by Geoffrey Garen.
1082
1083         * bmalloc/BPlatform.h: Added macro BPLATFORM_IOS_SIMULATOR, which evaluates to true
1084         when building for the iOS Simulator.
1085         * bmalloc/PerThread.h: Use pthread_machdep.h code path when building for iOS Simulator
1086         using the public SDK.
1087         (_pthread_setspecific_direct): Added; only defined when building for the iOS Simulator
1088         using the public SDK.
1089         (_pthread_getspecific_direct): Added; only defined when building for the iOS Simulator
1090         using the public SDK.
1091
1092 2014-08-12  Daniel Bates  <dabates@apple.com>
1093
1094         BPLATFORM(IOS) always evaluates to false
1095         https://bugs.webkit.org/show_bug.cgi?id=135843
1096
1097         Reviewed by Geoffrey Garen.
1098
1099         Fix typo in definition of BPLATFORM() and include system header TargetConditionals.h
1100         (when building on an Apple platform) so that BPLATFORM(X) evaluates to true when
1101         building for platform X. In particular, so that BPLATFORM(IOS) evaluates to true when
1102         building for iOS.
1103
1104         As a side effect of this change, the change made in <http://trac.webkit.org/changeset/167289>
1105         will be honored and iOS will assume a VM page size of 16kB (again) instead of 4kB.
1106
1107         * bmalloc/BPlatform.h:
1108
1109 2014-08-11  Andy Estes  <aestes@apple.com>
1110
1111         [iOS] Get rid of iOS.xcconfig
1112         https://bugs.webkit.org/show_bug.cgi?id=135809
1113
1114         Reviewed by Joseph Pecoraro.
1115
1116         All iOS.xcconfig did was include AspenFamily.xcconfig, so there's no need for the indirection.
1117
1118         * Configurations/Base.xcconfig:
1119         * Configurations/iOS.xcconfig: Removed.
1120         * bmalloc.xcodeproj/project.pbxproj:
1121
1122 2014-05-01  Dan Bernstein  <mitz@apple.com>
1123
1124         Fixed production builds for the iOS Simulator.
1125         <rdar://problem/16792221>
1126
1127         * Configurations/bmalloc.xcconfig: Include INSTALL_PATH_PREFIX in
1128         PRIVATE_HEADERS_FOLDER_PATH when installing.
1129
1130 2014-04-20  Geoffrey Garen  <ggaren@apple.com>
1131
1132         bmalloc: Segregate pages by objects size
1133         https://bugs.webkit.org/show_bug.cgi?id=131909
1134
1135         Reviewed by Andreas Kling.
1136
1137         2% reduction in memory-at-end on the Membuster memory_warning benchmarks.
1138
1139         * bmalloc/Allocator.cpp:
1140         (bmalloc::Allocator::allocateSlowCase):
1141         * bmalloc/Allocator.h:
1142         (bmalloc::Allocator::allocateFastCase):
1143         (bmalloc::Allocator::smallAllocatorFor): Use the new shared helper
1144         function for size class calculation.
1145
1146         * bmalloc/Deallocator.cpp:
1147         (bmalloc::Deallocator::Deallocator):
1148         (bmalloc::Deallocator::scavenge):
1149         (bmalloc::Deallocator::deallocateSmallLine):
1150         (bmalloc::Deallocator::allocateSmallLine):
1151         * bmalloc/Deallocator.h: Keep a cache for every size class, since the
1152         cache can't be shared anymore.
1153
1154         * bmalloc/Heap.cpp:
1155         (bmalloc::Heap::allocateSmallLineSlowCase):
1156         * bmalloc/Heap.h:
1157         (bmalloc::Heap::deallocateSmallLine): Ditto.
1158
1159         (bmalloc::Heap::allocateSmallLine): Check size class in addition to
1160         page refcount when allocating a line because we might have deallocated
1161         the page and the recycled it for another size class.
1162
1163         (bmalloc::Heap::deallocateMediumLine):
1164         (bmalloc::Heap::allocateMediumLine):
1165         * bmalloc/Line.h:
1166         (bmalloc::Line::refCount):
1167         * bmalloc/Page.h:
1168         (bmalloc::Page::refCount):
1169         (bmalloc::Page::smallSizeClass):
1170         (bmalloc::Page::setSmallSizeClass):
1171         (bmalloc::Page<Traits>::refCount): Deleted.
1172         * bmalloc/Sizes.h:
1173         (bmalloc::Sizes::smallSizeClassFor): New shared API for computing
1174         an index into an array from a size.
1175
1176 2014-04-19  Geoffrey Garen  <ggaren@apple.com>
1177
1178         bmalloc: Improved alignment in LargeChunk
1179         https://bugs.webkit.org/show_bug.cgi?id=131895
1180
1181         Reviewed by Andreas Kling.
1182
1183         * bmalloc/Chunk.h:
1184         * bmalloc/LargeChunk.h: Align to vmPageSize just like Chunk does.
1185         Technically, the previous alignment was harmless, but I would prefer,
1186         dear reader, not to have to explain the interlocking set of
1187         circumstances that made it so.
1188
1189 2014-04-19  Geoffrey Garen  <ggaren@apple.com>
1190
1191         Rolled out r167502 because it caused a crash on the facebook benchmark.
1192
1193         Unreviewed.
1194
1195             bmalloc: Added an XSmall line size
1196             https://bugs.webkit.org/show_bug.cgi?id=131851
1197
1198             Reviewed by Sam Weinig.
1199
1200 2014-04-19  Geoffrey Garen  <ggaren@apple.com>
1201
1202         bmalloc: Mutex should be harder to use wrong
1203         https://bugs.webkit.org/show_bug.cgi?id=131879
1204
1205         Reviewed by Andreas Kling.
1206
1207         Mutex now has a proper constructor, so you can't deadlock by forgetting
1208         to initialize it.
1209
1210         * bmalloc.xcodeproj/project.pbxproj:
1211         * bmalloc/Allocator.cpp:
1212         (bmalloc::Allocator::processXSmallAllocatorLog):
1213         (bmalloc::Allocator::processSmallAllocatorLog):
1214         (bmalloc::Allocator::processMediumAllocatorLog):
1215         (bmalloc::Allocator::allocateLarge):
1216         (bmalloc::Allocator::allocateXLarge): Global replace Mutex => StaticMutex,
1217         since the Heap mutex is a static.
1218
1219         * bmalloc/AsyncTask.h:
1220         (bmalloc::Function>::AsyncTask): Use Mutex, since we're not static. No
1221         need for explicit initialization anymore.
1222
1223         * bmalloc/Deallocator.cpp:
1224         (bmalloc::Deallocator::scavenge):
1225         (bmalloc::Deallocator::deallocateLarge):
1226         (bmalloc::Deallocator::deallocateXLarge):
1227         (bmalloc::Deallocator::processObjectLog):
1228         (bmalloc::Deallocator::deallocateSmallLine):
1229         (bmalloc::Deallocator::deallocateXSmallLine):
1230         (bmalloc::Deallocator::allocateSmallLine):
1231         (bmalloc::Deallocator::allocateXSmallLine):
1232         (bmalloc::Deallocator::deallocateMediumLine):
1233         (bmalloc::Deallocator::allocateMediumLine):
1234         * bmalloc/Deallocator.h:
1235         * bmalloc/Heap.cpp:
1236         (bmalloc::sleep):
1237         (bmalloc::Heap::Heap):
1238         (bmalloc::Heap::concurrentScavenge):
1239         (bmalloc::Heap::scavenge):
1240         (bmalloc::Heap::scavengeSmallPages):
1241         (bmalloc::Heap::scavengeXSmallPages):
1242         (bmalloc::Heap::scavengeMediumPages):
1243         (bmalloc::Heap::scavengeLargeRanges):
1244         (bmalloc::Heap::allocateXSmallLineSlowCase):
1245         (bmalloc::Heap::allocateSmallLineSlowCase):
1246         (bmalloc::Heap::allocateMediumLineSlowCase):
1247         (bmalloc::Heap::allocateXLarge):
1248         (bmalloc::Heap::deallocateXLarge):
1249         (bmalloc::Heap::allocateLarge):
1250         (bmalloc::Heap::deallocateLarge):
1251         * bmalloc/Heap.h:
1252         (bmalloc::Heap::deallocateXSmallLine):
1253         (bmalloc::Heap::allocateXSmallLine):
1254         (bmalloc::Heap::deallocateSmallLine):
1255         (bmalloc::Heap::allocateSmallLine):
1256         (bmalloc::Heap::deallocateMediumLine):
1257         (bmalloc::Heap::allocateMediumLine):
1258         * bmalloc/Line.h:
1259         (bmalloc::Line<Traits>::deref):
1260         * bmalloc/Mutex.cpp: Removed.
1261         * bmalloc/Mutex.h:
1262         (bmalloc::Mutex::Mutex):
1263         (bmalloc::Mutex::init): Deleted.
1264         (bmalloc::Mutex::try_lock): Deleted.
1265         (bmalloc::Mutex::lock): Deleted.
1266         (bmalloc::Mutex::unlock): Deleted.
1267         * bmalloc/Page.h:
1268         (bmalloc::Page<Traits>::ref):
1269         (bmalloc::Page<Traits>::deref):
1270         (bmalloc::Page<Traits>::refCount):
1271         * bmalloc/PerProcess.h:
1272         (bmalloc::PerProcess::mutex):
1273         (bmalloc::PerProcess<T>::getSlowCase):
1274         * bmalloc/StaticMutex.cpp: Added.
1275         (bmalloc::StaticMutex::lockSlowCase):
1276         * bmalloc/StaticMutex.h: Added.
1277         (bmalloc::StaticMutex::init):
1278         (bmalloc::StaticMutex::try_lock):
1279         (bmalloc::StaticMutex::lock):
1280         (bmalloc::StaticMutex::unlock):
1281         * bmalloc/VMHeap.h:
1282         (bmalloc::VMHeap::deallocateXSmallPage):
1283         (bmalloc::VMHeap::deallocateSmallPage):
1284         (bmalloc::VMHeap::deallocateMediumPage):
1285         (bmalloc::VMHeap::deallocateLargeRange):
1286         * bmalloc/bmalloc.h:
1287         (bmalloc::api::scavenge): Global replace Mutex => StaticMutex,
1288         since the Heap mutex is a static.
1289
1290 2014-04-18  Geoffrey Garen  <ggaren@apple.com>
1291
1292         bmalloc: AsyncTask should use Mutex instead of std::mutex
1293         https://bugs.webkit.org/show_bug.cgi?id=131865
1294
1295         Reviewed by Gavin Barraclough.
1296
1297         std::mutex is so slow that it makes parallelizing simple tasks through
1298         AsyncTask a net regression. Mutex fixes this.
1299
1300         * bmalloc/AsyncTask.h:
1301         (bmalloc::Function>::AsyncTask):
1302         (bmalloc::Function>::join):
1303         (bmalloc::Function>::runSlowCase):
1304         (bmalloc::Function>::entryPoint):
1305         * bmalloc/Mutex.h:
1306         (bmalloc::Mutex::init):
1307
1308 2014-04-18  Geoffrey Garen  <ggaren@apple.com>
1309
1310         bmalloc: Added an XSmall line size
1311         https://bugs.webkit.org/show_bug.cgi?id=131851
1312
1313         Reviewed by Sam Weinig.
1314
1315         Reduces malloc footprint on Membuster recordings by 10%.
1316
1317         This is a throughput regression, but we're still way ahead of TCMalloc.
1318         I have some ideas for how to recover the regression -- but I wanted to
1319         get this win in first.
1320
1321         Full set of benchmark results:
1322
1323                 bmalloc> ~/webkit/PerformanceTests/MallocBench/run-malloc-benchmarks --measure-heap nopatch:~/scratch/Build-nopatch/Release/ patch:~/webkit/WebKitBuild/Release/
1324                                                                                                 
1325                                                                nopatch                      patch                                Δ
1326                 Peak Memory:
1327                     reddit_memory_warning                      7,896kB                    7,532kB                  ^ 1.05x smaller
1328                     flickr_memory_warning                     12,968kB                   12,324kB                  ^ 1.05x smaller
1329                     theverge_memory_warning                   16,672kB                   15,200kB                   ^ 1.1x smaller
1330
1331                     <geometric mean>                          11,952kB                   11,216kB                  ^ 1.07x smaller
1332                     <arithmetic mean>                         12,512kB                   11,685kB                  ^ 1.07x smaller
1333                     <harmonic mean>                           11,375kB                   10,726kB                  ^ 1.06x smaller
1334
1335                 Memory at End:
1336                     reddit_memory_warning                      7,320kB                    6,856kB                  ^ 1.07x smaller
1337                     flickr_memory_warning                     10,848kB                    9,692kB                  ^ 1.12x smaller
1338                     theverge_memory_warning                   16,380kB                   14,872kB                   ^ 1.1x smaller
1339
1340                     <geometric mean>                          10,916kB                    9,961kB                   ^ 1.1x smaller
1341                     <arithmetic mean>                         11,516kB                   10,473kB                   ^ 1.1x smaller
1342                     <harmonic mean>                           10,350kB                    9,485kB                  ^ 1.09x smaller
1343
1344                 MallocBench> ~/webkit/PerformanceTests/MallocBench/run-malloc-benchmarks nopatch:~/scratch/Build-nopatch/Release/ patch:~/webkit/WebKitBuild/Release/
1345                                                                                                 
1346                                                    nopatch                patch                         Δ
1347                 Execution Time:
1348                     churn                            127ms                151ms            ! 1.19x slower
1349                     list_allocate                    130ms                164ms            ! 1.26x slower
1350                     tree_allocate                    109ms                127ms            ! 1.17x slower
1351                     tree_churn                       115ms                120ms            ! 1.04x slower
1352                     facebook                         240ms                259ms            ! 1.08x slower
1353                     fragment                          91ms                131ms            ! 1.44x slower
1354                     fragment_iterate                 105ms                106ms            ! 1.01x slower
1355                     message_one                      260ms                259ms             ^ 1.0x faster
1356                     message_many                     149ms                154ms            ! 1.03x slower
1357                     medium                           194ms                248ms            ! 1.28x slower
1358                     big                              157ms                160ms            ! 1.02x slower
1359
1360                     <geometric mean>                 144ms                163ms            ! 1.13x slower
1361                     <arithmetic mean>                152ms                171ms            ! 1.12x slower
1362                     <harmonic mean>                  137ms                156ms            ! 1.14x slower
1363
1364                 MallocBench> ~/webkit/PerformanceTests/MallocBench/run-malloc-benchmarks nopatch:~/scratch/Build-nopatch/Release/ patch:~/webkit/WebKitBuild/Release/
1365                                                                                                 
1366                                                                        nopatch                          patch                                     Δ
1367                 Execution Time:
1368                     churn                                                126ms                          148ms                        ! 1.17x slower
1369                     churn --parallel                                      62ms                           76ms                        ! 1.23x slower
1370                     list_allocate                                        130ms                          164ms                        ! 1.26x slower
1371                     list_allocate --parallel                             120ms                          175ms                        ! 1.46x slower
1372                     tree_allocate                                        111ms                          127ms                        ! 1.14x slower
1373                     tree_allocate --parallel                              95ms                          135ms                        ! 1.42x slower
1374                     tree_churn                                           115ms                          124ms                        ! 1.08x slower
1375                     tree_churn --parallel                                107ms                          126ms                        ! 1.18x slower
1376                     facebook                                             240ms                          276ms                        ! 1.15x slower
1377                     facebook --parallel                                  802ms                        1,088ms                        ! 1.36x slower
1378                     fragment                                              92ms                          130ms                        ! 1.41x slower
1379                     fragment --parallel                                   66ms                          124ms                        ! 1.88x slower
1380                     fragment_iterate                                     109ms                          127ms                        ! 1.17x slower
1381                     fragment_iterate --parallel                           55ms                           64ms                        ! 1.16x slower
1382                     message_one                                          260ms                          260ms                                      
1383                     message_many                                         170ms                          238ms                         ! 1.4x slower
1384                     medium                                               185ms                          250ms                        ! 1.35x slower
1385                     medium --parallel                                    210ms                          334ms                        ! 1.59x slower
1386                     big                                                  150ms                          169ms                        ! 1.13x slower
1387                     big --parallel                                       138ms                          144ms                        ! 1.04x slower
1388
1389                     <geometric mean>                                     135ms                          170ms                        ! 1.26x slower
1390                     <arithmetic mean>                                    167ms                          214ms                        ! 1.28x slower
1391                     <harmonic mean>                                      117ms                          148ms                        ! 1.26x slower
1392
1393                 MallocBench> ~/webkit/PerformanceTests/MallocBench/run-malloc-benchmarks TC:~/scratch/Build-TCMalloc/Release/ patch:~/webkit/WebKitBuild/Release/
1394
1395                                                                     TC                      patch                                Δ
1396                 Peak Memory:
1397                     reddit_memory_warning                     13,836kB                   13,436kB                  ^ 1.03x smaller
1398                     flickr_memory_warning                     24,868kB                   25,188kB                   ! 1.01x bigger
1399                     theverge_memory_warning                   24,504kB                   26,636kB                   ! 1.09x bigger
1400
1401                     <geometric mean>                          20,353kB                   20,812kB                   ! 1.02x bigger
1402                     <arithmetic mean>                         21,069kB                   21,753kB                   ! 1.03x bigger
1403                     <harmonic mean>                           19,570kB                   19,780kB                   ! 1.01x bigger
1404
1405                 Memory at End:
1406                     reddit_memory_warning                      8,656kB                   10,016kB                   ! 1.16x bigger
1407                     flickr_memory_warning                     11,844kB                   13,784kB                   ! 1.16x bigger
1408                     theverge_memory_warning                   18,516kB                   22,748kB                   ! 1.23x bigger
1409
1410                     <geometric mean>                          12,382kB                   14,644kB                   ! 1.18x bigger
1411                     <arithmetic mean>                         13,005kB                   15,516kB                   ! 1.19x bigger
1412                     <harmonic mean>                           11,813kB                   13,867kB                   ! 1.17x bigger
1413
1414                 MallocBench> ~/webkit/PerformanceTests/MallocBench/run-malloc-benchmarks TC:~/scratch/Build-TCMalloc/Release/ patch:~/webkit/WebKitBuild/Release/
1415                                                                                                 
1416                                                         TC                patch                         Δ
1417                 Execution Time:
1418                     churn                            416ms                148ms            ^ 2.81x faster
1419                     list_allocate                    463ms                164ms            ^ 2.82x faster
1420                     tree_allocate                    292ms                127ms             ^ 2.3x faster
1421                     tree_churn                       157ms                120ms            ^ 1.31x faster
1422                     facebook                         327ms                276ms            ^ 1.18x faster
1423                     fragment                         335ms                129ms             ^ 2.6x faster
1424                     fragment_iterate                 344ms                108ms            ^ 3.19x faster
1425                     message_one                      386ms                258ms             ^ 1.5x faster
1426                     message_many                     410ms                154ms            ^ 2.66x faster
1427                     medium                           391ms                245ms             ^ 1.6x faster
1428                     big                              261ms                167ms            ^ 1.56x faster
1429
1430                     <geometric mean>                 332ms                164ms            ^ 2.02x faster
1431                     <arithmetic mean>                344ms                172ms            ^ 1.99x faster
1432                     <harmonic mean>                  317ms                157ms            ^ 2.02x faster
1433
1434         * bmalloc.xcodeproj/project.pbxproj:
1435         * bmalloc/Allocator.cpp:
1436         (bmalloc::Allocator::Allocator): Don't assume that each allocator's
1437         index corresponds with its size. Instead, use the size selection function
1438         explicitly. Now that we have XSmall, some small allocator entries are
1439         unused.
1440
1441         (bmalloc::Allocator::scavenge):
1442         (bmalloc::Allocator::log):
1443         (bmalloc::Allocator::processXSmallAllocatorLog):
1444         (bmalloc::Allocator::allocateSlowCase):
1445         * bmalloc/Allocator.h:
1446         (bmalloc::Allocator::xSmallAllocatorFor):
1447         (bmalloc::Allocator::allocateFastCase):
1448         * bmalloc/Chunk.h:
1449         * bmalloc/Deallocator.cpp:
1450         (bmalloc::Deallocator::scavenge):
1451         (bmalloc::Deallocator::processObjectLog):
1452         (bmalloc::Deallocator::deallocateSlowCase):
1453         (bmalloc::Deallocator::deallocateXSmallLine):
1454         (bmalloc::Deallocator::allocateXSmallLine):
1455         * bmalloc/Deallocator.h:
1456         (bmalloc::Deallocator::deallocateFastCase):
1457         * bmalloc/Heap.cpp:
1458         (bmalloc::Heap::scavenge):
1459         (bmalloc::Heap::scavengeXSmallPages):
1460         (bmalloc::Heap::allocateXSmallLineSlowCase):
1461         * bmalloc/Heap.h:
1462         (bmalloc::Heap::deallocateXSmallLine):
1463         (bmalloc::Heap::allocateXSmallLine):
1464         * bmalloc/LargeChunk.h:
1465         (bmalloc::LargeChunk::get):
1466         (bmalloc::LargeChunk::endTag):
1467         * bmalloc/Line.h:
1468         * bmalloc/MediumAllocator.h:
1469         (bmalloc::MediumAllocator::allocate):
1470         (bmalloc::MediumAllocator::refill):
1471         * bmalloc/ObjectType.cpp:
1472         (bmalloc::objectType):
1473         * bmalloc/ObjectType.h:
1474         (bmalloc::isXSmall):
1475         (bmalloc::isSmall):
1476         (bmalloc::isMedium):
1477         (bmalloc::isLarge):
1478         (bmalloc::isSmallOrMedium): Deleted.
1479         * bmalloc/SegregatedFreeList.h: I boiler-plate copied existing code for
1480         handling small objects. There's probably a reasonable way to share this
1481         code in the future -- I'll look into that once it's stopped changing.
1482
1483         * bmalloc/Sizes.h: Tweaked size classes to make Membuster happy. This
1484         is the main reason things got slower.
1485
1486         * bmalloc/SmallAllocator.h:
1487         (bmalloc::SmallAllocator::allocate):
1488         * bmalloc/SmallTraits.h:
1489         * bmalloc/VMHeap.cpp:
1490         (bmalloc::VMHeap::allocateXSmallChunk):
1491         * bmalloc/VMHeap.h:
1492         (bmalloc::VMHeap::allocateXSmallPage):
1493         (bmalloc::VMHeap::deallocateXSmallPage):
1494         * bmalloc/XSmallAllocator.h: Added.
1495         (bmalloc::XSmallAllocator::isNull):
1496         (bmalloc::XSmallAllocator::canAllocate):
1497         (bmalloc::XSmallAllocator::XSmallAllocator):
1498         (bmalloc::XSmallAllocator::line):
1499         (bmalloc::XSmallAllocator::allocate):
1500         (bmalloc::XSmallAllocator::objectCount):
1501         (bmalloc::XSmallAllocator::derefCount):
1502         (bmalloc::XSmallAllocator::refill):
1503         * bmalloc/XSmallChunk.h: Added.
1504         * bmalloc/XSmallLine.h: Added.
1505         * bmalloc/XSmallPage.h: Added.
1506         * bmalloc/XSmallTraits.h: Added.
1507         * bmalloc/bmalloc.h:
1508         (bmalloc::api::realloc): Boiler-plate copy, as above.
1509
1510 2014-04-14  Geoffrey Garen  <ggaren@apple.com>
1511
1512         MallocBench should scavenge explicitly instead of waiting
1513         https://bugs.webkit.org/show_bug.cgi?id=131661
1514
1515         Reviewed by Andreas Kling.
1516
1517         Added explicit scavenge support to bmalloc. This isn't a memory win,
1518         since bmalloc's per-thread cache is so small. But it makes testing
1519         simpler.
1520
1521         * bmalloc/Allocator.cpp:
1522         (bmalloc::Allocator::~Allocator):
1523         (bmalloc::Allocator::scavenge):
1524         * bmalloc/Allocator.h:
1525         * bmalloc/Cache.cpp:
1526         (bmalloc::Cache::operator new):
1527         (bmalloc::Cache::operator delete):
1528         (bmalloc::Cache::Cache):
1529         (bmalloc::Cache::scavenge):
1530         * bmalloc/Cache.h:
1531         * bmalloc/Deallocator.cpp:
1532         (bmalloc::Deallocator::~Deallocator):
1533         (bmalloc::Deallocator::scavenge):
1534         * bmalloc/Deallocator.h: Factored existing scavenging code into helper
1535         functions, for reuse.
1536
1537         * bmalloc/Heap.cpp:
1538         (bmalloc::sleep):
1539         (bmalloc::Heap::concurrentScavenge):
1540         (bmalloc::Heap::scavenge):
1541         (bmalloc::Heap::scavengeSmallPages):
1542         (bmalloc::Heap::scavengeMediumPages):
1543         (bmalloc::Heap::scavengeLargeRanges):
1544         * bmalloc/Heap.h: Made scavenge sleep duration a parameter. Forced
1545         scavenging -- in response to a benchmark or a low memory warning --
1546         wants to complete as soon as possible, so its sleep duration is 0.
1547
1548         * bmalloc/bmalloc.h:
1549         (bmalloc::api::scavenge):
1550         * bmalloc/mbmalloc.cpp: Exported the scavenge API for MallocBench's use.
1551
1552 2014-04-14  Geoffrey Garen  <ggaren@apple.com>
1553
1554         Use 4kB pages on Mac
1555         https://bugs.webkit.org/show_bug.cgi?id=131658
1556
1557         Reviewed by Sam Weinig.
1558
1559         This reduces memory use a lot on Membuster:
1560
1561                                                                   base                      patch                                Δ
1562                 Execution Time:
1563                     reddit_memory_warning                         18ms                       17ms                   ^ 1.06x faster
1564                     flickr_memory_warning                         34ms                       36ms                   ! 1.06x slower
1565                     theverge_memory_warning                       39ms                       41ms                   ! 1.05x slower
1566
1567                     <geometric mean>                              29ms                       29ms                   ! 1.02x slower
1568                     <arithmetic mean>                             30ms                       31ms                   ! 1.03x slower
1569                     <harmonic mean>                               27ms                       27ms                    ^ 1.0x faster
1570
1571                 Peak Memory:
1572                     reddit_memory_warning                     16,412kB                   16,436kB                    ! 1.0x bigger
1573                     flickr_memory_warning                     30,120kB                   30,184kB                    ! 1.0x bigger
1574                     theverge_memory_warning                   33,408kB                   33,420kB                    ! 1.0x bigger
1575
1576                     <geometric mean>                          25,466kB                   25,499kB                    ! 1.0x bigger
1577                     <arithmetic mean>                         26,647kB                   26,680kB                    ! 1.0x bigger
1578                     <harmonic mean>                           24,181kB                   24,214kB                    ! 1.0x bigger
1579
1580                 Memory at End:
1581                     reddit_memory_warning                      2,404kB                    1,920kB                  ^ 1.25x smaller
1582                     flickr_memory_warning                      3,764kB                    3,072kB                  ^ 1.23x smaller
1583                     theverge_memory_warning                    3,648kB                    3,132kB                  ^ 1.16x smaller
1584
1585                     <geometric mean>                           3,208kB                    2,644kB                  ^ 1.21x smaller
1586                     <arithmetic mean>                          3,272kB                    2,708kB                  ^ 1.21x smaller
1587                     <harmonic mean>                            3,139kB                    2,574kB                  ^ 1.22x smaller
1588
1589
1590         * bmalloc.xcodeproj/project.pbxproj:
1591         * bmalloc/BPlatform.h: Added.
1592         * bmalloc/VMAllocate.h: Only use 16kB pages on iOS because the page size
1593         is 4kB on Mac.
1594
1595 2014-04-14  Alexey Proskuryakov  <ap@apple.com>
1596
1597         Fixed svn:ignore on bmalloc.xcodeproj, it had erroneous leading spaces.
1598
1599         * bmalloc.xcodeproj: Modified property svn:ignore.
1600
1601 2014-04-13  Geoffrey Garen  <ggaren@apple.com>
1602
1603         Fixed some mbmalloc exports
1604         https://bugs.webkit.org/show_bug.cgi?id=131599
1605
1606         Reviewed by Ryosuke Niwa.
1607
1608         * bmalloc.xcodeproj/project.pbxproj: Made some headers a private part
1609         of the project, so we can call them from API.
1610
1611         * bmalloc/mbmalloc.cpp: Marked the mbmalloc functions with default
1612         visibility, so they show up as exported in the .dylib.
1613
1614 2014-04-09  Geoffrey Garen  <ggaren@apple.com>
1615
1616         Put bmalloc headers in the right place
1617         https://bugs.webkit.org/show_bug.cgi?id=131464
1618
1619         Reviewed by Mark Rowe.
1620
1621         * Configurations/bmalloc.xcconfig: Set PRIVATE_HEADERS_FOLDER_PATH to
1622         specify that we don't just want to dump all of our generically-named
1623         headers into /usr/local/include.
1624
1625 2014-04-08  Geoffrey Garen  <ggaren@apple.com>
1626
1627         Made bmalloc more #include friendly
1628         https://bugs.webkit.org/show_bug.cgi?id=131386
1629
1630         Reviewed by Andreas Kling.
1631
1632         Marked a bunch of headers private so they can be used from client code
1633         that #includes bmalloc.h.
1634
1635         Renamed ASSERT macros to BASSERT. This matches their header, which already
1636         had to be renamed, and fixes conflicts with WTF's ASSERT macros.
1637
1638         * bmalloc.xcodeproj/project.pbxproj:
1639         * bmalloc/Allocator.cpp:
1640         (bmalloc::Allocator::allocateSlowCase):
1641         * bmalloc/AsyncTask.h:
1642         (bmalloc::Function>::runSlowCase):
1643         * bmalloc/BAssert.h:
1644         * bmalloc/BoundaryTag.h:
1645         (bmalloc::BoundaryTag::setSize):
1646         * bmalloc/BoundaryTagInlines.h:
1647         (bmalloc::validate):
1648         (bmalloc::BoundaryTag::init):
1649         (bmalloc::BoundaryTag::deallocate):
1650         (bmalloc::BoundaryTag::splitLarge):
1651         (bmalloc::BoundaryTag::allocate):
1652         * bmalloc/Chunk.h:
1653         * bmalloc/Deallocator.cpp:
1654         (bmalloc::Deallocator::processObjectLog):
1655         (bmalloc::Deallocator::deallocateSlowCase):
1656         * bmalloc/Deallocator.h:
1657         (bmalloc::Deallocator::deallocateFastCase):
1658         * bmalloc/FixedVector.h:
1659         (bmalloc::Capacity>::operator):
1660         (bmalloc::Capacity>::push):
1661         (bmalloc::Capacity>::pop):
1662         (bmalloc::Capacity>::shrink):
1663         * bmalloc/Heap.cpp:
1664         (bmalloc::Heap::allocateLarge):
1665         * bmalloc/LargeChunk.h:
1666         (bmalloc::LargeChunk::get):
1667         (bmalloc::LargeChunk::endTag):
1668         * bmalloc/Line.h:
1669         (bmalloc::Line<Traits>::concurrentRef):
1670         (bmalloc::Line<Traits>::deref):
1671         * bmalloc/MediumAllocator.h:
1672         (bmalloc::MediumAllocator::allocate):
1673         * bmalloc/ObjectType.h:
1674         (bmalloc::isSmall):
1675         * bmalloc/Page.h:
1676         (bmalloc::Page<Traits>::ref):
1677         (bmalloc::Page<Traits>::deref):
1678         * bmalloc/PerThread.h:
1679         (bmalloc::PerThread<T>::getSlowCase):
1680         * bmalloc/SegregatedFreeList.cpp:
1681         (bmalloc::SegregatedFreeList::SegregatedFreeList):
1682         (bmalloc::SegregatedFreeList::insert):
1683         * bmalloc/SmallAllocator.h:
1684         (bmalloc::SmallAllocator::allocate):
1685         (bmalloc::SmallAllocator::refill):
1686         * bmalloc/Syscall.h:
1687         * bmalloc/VMAllocate.h:
1688         (bmalloc::vmValidate):
1689         (bmalloc::vmAllocate):
1690         (bmalloc::vmDeallocatePhysicalPagesSloppy):
1691         * bmalloc/Vector.h:
1692         (bmalloc::Vector<T>::operator):
1693         (bmalloc::Vector<T>::pop):
1694         (bmalloc::Vector<T>::shrink):
1695         * bmalloc/XLargeChunk.h:
1696         (bmalloc::XLargeChunk::range):
1697         (bmalloc::XLargeChunk::size):
1698
1699 2014-04-08  Geoffrey Garen  <ggaren@apple.com>
1700
1701         Removed an unused file.
1702
1703         Unreviewed.
1704
1705         * bmalloc/AsyncTask.cpp: Removed.
1706
1707 2014-04-07  Geoffrey Garen  <ggaren@apple.com>
1708
1709         Build bmalloc on Mac
1710         https://bugs.webkit.org/show_bug.cgi?id=131333
1711
1712         Reviewed by Mark Rowe.
1713
1714         * Makefile: Added. For make clients.
1715
1716         These files are required for building any project in WebKit. I copied
1717         them from WTF:
1718         * Configurations: Added.
1719         * Configurations/Base.xcconfig: Added.
1720         * Configurations/DebugRelease.xcconfig: Added.
1721         * Configurations/bmalloc.xcconfig: Added.
1722         * Configurations/iOS.xcconfig: Added.
1723         * Configurations/mbmalloc.xcconfig: Added.
1724
1725         * bmalloc.xcodeproj/project.pbxproj: I removed per-project-file stuff
1726         from here because everything is in .xcconfig files now.
1727
1728         I had to fix a bunch of minor warnings, since they're enabled in our
1729         .xcconfig files:
1730
1731         * bmalloc/AsyncTask.h:
1732         (bmalloc::Function>::AsyncTask):
1733         * bmalloc/BAssert.h:
1734         * bmalloc/BoundaryTagInlines.h:
1735         (bmalloc::validate):
1736         * bmalloc/Heap.cpp:
1737         (bmalloc::Heap::Heap):
1738         (bmalloc::Heap::allocateLarge):
1739         (bmalloc::Heap::deallocateLarge):
1740         * bmalloc/Mutex.h:
1741         (bmalloc::Mutex::Mutex): Deleted.
1742         * bmalloc/VMAllocate.h:
1743         (bmalloc::vmValidate):
1744         * bmalloc/mbmalloc.cpp:
1745
1746 2014-04-07  Geoffrey Garen  <ggaren@apple.com>
1747
1748         bmalloc: Fixed a leak in the per-thread cache
1749         https://bugs.webkit.org/show_bug.cgi?id=131330
1750
1751         Reviewed by Andreas Kling.
1752
1753         Remember to deallocate our line caches upon thread exit.
1754
1755         * bmalloc/Deallocator.cpp:
1756         (bmalloc::Deallocator::~Deallocator):
1757
1758 2014-04-07  Geoffrey Garen  <ggaren@apple.com>
1759
1760         bmalloc: rolled out the tryLock experiment
1761         https://bugs.webkit.org/show_bug.cgi?id=131328
1762
1763         Reviewed by Andreas Kling.
1764
1765         It wasn't a speedup.
1766
1767         * bmalloc.xcodeproj/project.pbxproj:
1768         * bmalloc/Allocator.cpp:
1769         (bmalloc::Allocator::processSmallAllocatorLog):
1770         (bmalloc::Allocator::processMediumAllocatorLog):
1771         * bmalloc/Deallocator.cpp:
1772         (bmalloc::Deallocator::processObjectLog):
1773         (bmalloc::Deallocator::deallocateSlowCase):
1774         (bmalloc::Deallocator::deallocateSmallLine):
1775         (bmalloc::Deallocator::deallocateMediumLine):
1776         * bmalloc/Deallocator.h:
1777         (bmalloc::Deallocator::deallocateFastCase):
1778         * bmalloc/Heap.h:
1779         (bmalloc::Heap::deallocateSmallLine):
1780         (bmalloc::Heap::deallocateMediumLine):
1781         * bmalloc/Line.h:
1782         (bmalloc::Line<Traits>::deref):
1783         * bmalloc/Page.h:
1784         (bmalloc::Page<Traits>::deref):
1785
1786 2014-04-07  Geoffrey Garen  <ggaren@apple.com>
1787
1788         bmalloc
1789         https://bugs.webkit.org/show_bug.cgi?id=131170
1790
1791         Reviewed by Andreas Kling.
1792
1793         Initial commit.
1794
1795         * bmalloc: Added.
1796         * bmalloc.xcodeproj: Added.
1797         * bmalloc.xcodeproj/project.pbxproj: Added.
1798         * bmalloc/Algorithm.h: Added.
1799         (bmalloc::max):
1800         (bmalloc::min):
1801         (bmalloc::mask):
1802         (bmalloc::test):
1803         (bmalloc::roundUpToMultipleOf):
1804         (bmalloc::roundDownToMultipleOf):
1805         (bmalloc::sizeOf):
1806         (bmalloc::bitCount):
1807         (bmalloc::isPowerOfTwo):
1808         * bmalloc/Allocator.cpp: Added.
1809         (bmalloc::Allocator::Allocator):
1810         (bmalloc::Allocator::~Allocator):
1811         (bmalloc::Allocator::log):
1812         (bmalloc::Allocator::processSmallAllocatorLog):
1813         (bmalloc::Allocator::processMediumAllocatorLog):
1814         (bmalloc::Allocator::allocateLarge):
1815         (bmalloc::Allocator::allocateXLarge):
1816         (bmalloc::Allocator::allocateMedium):
1817         (bmalloc::Allocator::allocateSlowCase):
1818         * bmalloc/Allocator.h: Added.
1819         (bmalloc::Allocator::smallAllocatorFor):
1820         (bmalloc::Allocator::allocateFastCase):
1821         (bmalloc::Allocator::allocate):
1822         * bmalloc/AsyncTask.cpp: Added.
1823         (bmalloc::AsyncTask<Function>::runSlowCase):
1824         (bmalloc::AsyncTask<Function>::pthreadEntryPoint):
1825         (bmalloc::AsyncTask<Function>::entryPoint):
1826         * bmalloc/AsyncTask.h: Added.
1827         (bmalloc::Function>::AsyncTask):
1828         (bmalloc::Function>::join):
1829         (bmalloc::Function>::run):
1830         (bmalloc::Function>::runSlowCase):
1831         (bmalloc::Function>::pthreadEntryPoint):
1832         (bmalloc::Function>::entryPoint):
1833         * bmalloc/BAssert.h: Added.
1834         * bmalloc/BeginTag.h: Added.
1835         (bmalloc::BeginTag::isInFreeList):
1836         * bmalloc/BoundaryTag.h: Added.
1837         (bmalloc::BoundaryTag::isXLarge):
1838         (bmalloc::BoundaryTag::setXLarge):
1839         (bmalloc::BoundaryTag::isFree):
1840         (bmalloc::BoundaryTag::setFree):
1841         (bmalloc::BoundaryTag::isEnd):
1842         (bmalloc::BoundaryTag::setEnd):
1843         (bmalloc::BoundaryTag::hasPhysicalPages):
1844         (bmalloc::BoundaryTag::setHasPhysicalPages):
1845         (bmalloc::BoundaryTag::isNull):
1846         (bmalloc::BoundaryTag::clear):
1847         (bmalloc::BoundaryTag::size):
1848         (bmalloc::BoundaryTag::setSize):
1849         (bmalloc::BoundaryTag::prev):
1850         (bmalloc::BoundaryTag::next):
1851         * bmalloc/BoundaryTagInlines.h: Added.
1852         (bmalloc::validate):
1853         (bmalloc::validatePrev):
1854         (bmalloc::validateNext):
1855         (bmalloc::BoundaryTag::init):
1856         (bmalloc::BoundaryTag::mergeLargeLeft):
1857         (bmalloc::BoundaryTag::mergeLargeRight):
1858         (bmalloc::BoundaryTag::mergeLarge):
1859         (bmalloc::BoundaryTag::deallocate):
1860         (bmalloc::BoundaryTag::splitLarge):
1861         (bmalloc::BoundaryTag::allocate):
1862         * bmalloc/Cache.cpp: Added.
1863         (bmalloc::Cache::operator new):
1864         (bmalloc::Cache::operator delete):
1865         (bmalloc::Cache::Cache):
1866         (bmalloc::Cache::allocateSlowCase):
1867         (bmalloc::Cache::allocateSlowCaseNullCache):
1868         (bmalloc::Cache::deallocateSlowCase):
1869         (bmalloc::Cache::deallocateSlowCaseNullCache):
1870         * bmalloc/Cache.h: Added.
1871         (bmalloc::Cache::allocator):
1872         (bmalloc::Cache::deallocator):
1873         (bmalloc::Cache::allocateFastCase):
1874         (bmalloc::Cache::deallocateFastCase):
1875         (bmalloc::Cache::allocate):
1876         (bmalloc::Cache::deallocate):
1877         * bmalloc/Chunk.h: Added.
1878         (bmalloc::Chunk::begin):
1879         (bmalloc::Chunk::end):
1880         (bmalloc::Chunk::lines):
1881         (bmalloc::Chunk::pages):
1882         * bmalloc/Deallocator.cpp: Added.
1883         (bmalloc::Deallocator::Deallocator):
1884         (bmalloc::Deallocator::~Deallocator):
1885         (bmalloc::Deallocator::deallocateLarge):
1886         (bmalloc::Deallocator::deallocateXLarge):
1887         (bmalloc::Deallocator::processObjectLog):
1888         (bmalloc::Deallocator::deallocateSlowCase):
1889         (bmalloc::Deallocator::deallocateSmallLine):
1890         (bmalloc::Deallocator::allocateSmallLine):
1891         (bmalloc::Deallocator::deallocateMediumLine):
1892         (bmalloc::Deallocator::allocateMediumLine):
1893         * bmalloc/Deallocator.h: Added.
1894         (bmalloc::Deallocator::deallocateFastCase):
1895         (bmalloc::Deallocator::deallocate):
1896         * bmalloc/EndTag.h: Added.
1897         (bmalloc::EndTag::operator=):
1898         * bmalloc/FixedVector.h: Added.
1899         (bmalloc::FixedVector::begin):
1900         (bmalloc::FixedVector::end):
1901         (bmalloc::FixedVector::size):
1902         (bmalloc::FixedVector::capacity):
1903         (bmalloc::FixedVector::clear):
1904         (bmalloc::FixedVector::isEmpty):
1905         (bmalloc::Capacity>::FixedVector):
1906         (bmalloc::Capacity>::operator):
1907         (bmalloc::Capacity>::push):
1908         (bmalloc::Capacity>::pop):
1909         (bmalloc::Capacity>::shrink):
1910         * bmalloc/Heap.cpp: Added.
1911         (bmalloc::sleep):
1912         (bmalloc::Heap::Heap):
1913         (bmalloc::Heap::concurrentScavenge):
1914         (bmalloc::Heap::scavengeSmallPages):
1915         (bmalloc::Heap::scavengeMediumPages):
1916         (bmalloc::Heap::scavengeLargeRanges):
1917         (bmalloc::Heap::allocateSmallLineSlowCase):
1918         (bmalloc::Heap::allocateMediumLineSlowCase):
1919         (bmalloc::Heap::allocateXLarge):
1920         (bmalloc::Heap::deallocateXLarge):
1921         (bmalloc::Heap::allocateLarge):
1922         (bmalloc::Heap::deallocateLarge):
1923         * bmalloc/Heap.h: Added.
1924         (bmalloc::Heap::deallocateSmallLine):
1925         (bmalloc::Heap::allocateSmallLine):
1926         (bmalloc::Heap::deallocateMediumLine):
1927         (bmalloc::Heap::allocateMediumLine):
1928         * bmalloc/Inline.h: Added.
1929         * bmalloc/LargeChunk.h: Added.
1930         (bmalloc::LargeChunk::begin):
1931         (bmalloc::LargeChunk::end):
1932         (bmalloc::LargeChunk::create):
1933         (bmalloc::LargeChunk::get):
1934         (bmalloc::LargeChunk::beginTag):
1935         (bmalloc::LargeChunk::endTag):
1936         * bmalloc/Line.h: Added.
1937         (bmalloc::Line<Traits>::begin):
1938         (bmalloc::Line<Traits>::end):
1939         (bmalloc::Line<Traits>::concurrentRef):
1940         (bmalloc::Line<Traits>::deref):
1941         * bmalloc/MediumAllocator.h: Added.
1942         (bmalloc::MediumAllocator::isNull):
1943         (bmalloc::MediumAllocator::MediumAllocator):
1944         (bmalloc::MediumAllocator::line):
1945         (bmalloc::MediumAllocator::allocate):
1946         (bmalloc::MediumAllocator::derefCount):
1947         (bmalloc::MediumAllocator::refill):
1948         * bmalloc/MediumChunk.h: Added.
1949         * bmalloc/MediumLine.h: Added.
1950         * bmalloc/MediumPage.h: Added.
1951         * bmalloc/MediumTraits.h: Added.
1952         * bmalloc/Mutex.cpp: Added.
1953         (bmalloc::Mutex::lockSlowCase):
1954         * bmalloc/Mutex.h: Added.
1955         (bmalloc::Mutex::Mutex):
1956         (bmalloc::Mutex::try_lock):
1957         (bmalloc::Mutex::lock):
1958         (bmalloc::Mutex::unlock):
1959         * bmalloc/ObjectType.cpp: Added.
1960         (bmalloc::objectType):
1961         * bmalloc/ObjectType.h: Added.
1962         (bmalloc::isSmallOrMedium):
1963         (bmalloc::isSmall):
1964         * bmalloc/Page.h: Added.
1965         (bmalloc::Page<Traits>::ref):
1966         (bmalloc::Page<Traits>::deref):
1967         (bmalloc::Page<Traits>::refCount):
1968         * bmalloc/PerProcess.h: Added.
1969         (bmalloc::PerProcess::mutex):
1970         (bmalloc::PerProcess<T>::getFastCase):
1971         (bmalloc::PerProcess<T>::get):
1972         (bmalloc::PerProcess<T>::getSlowCase):
1973         * bmalloc/PerThread.h: Added.
1974         (bmalloc::PerThreadStorage<Cache>::get):
1975         (bmalloc::PerThreadStorage<Cache>::init):
1976         (bmalloc::PerThreadStorage::get):
1977         (bmalloc::PerThreadStorage::init):
1978         (bmalloc::PerThread<T>::getFastCase):
1979         (bmalloc::PerThread<T>::get):
1980         (bmalloc::PerThread<T>::destructor):
1981         (bmalloc::PerThread<T>::getSlowCase):
1982         * bmalloc/Range.h: Added.
1983         (bmalloc::Range::Range):
1984         (bmalloc::Range::begin):
1985         (bmalloc::Range::end):
1986         (bmalloc::Range::size):
1987         (bmalloc::Range::operator!):
1988         (bmalloc::Range::operator<):
1989         * bmalloc/SegregatedFreeList.cpp: Added.
1990         (bmalloc::SegregatedFreeList::SegregatedFreeList):
1991         (bmalloc::SegregatedFreeList::insert):
1992         (bmalloc::SegregatedFreeList::takeGreedy):
1993         (bmalloc::SegregatedFreeList::take):
1994         * bmalloc/SegregatedFreeList.h: Added.
1995         * bmalloc/Sizes.h: Added.
1996         * bmalloc/SmallAllocator.h: Added.
1997         (bmalloc::SmallAllocator::isNull):
1998         (bmalloc::SmallAllocator::canAllocate):
1999         (bmalloc::SmallAllocator::SmallAllocator):
2000         (bmalloc::SmallAllocator::line):
2001         (bmalloc::SmallAllocator::allocate):
2002         (bmalloc::SmallAllocator::objectCount):
2003         (bmalloc::SmallAllocator::derefCount):
2004         (bmalloc::SmallAllocator::refill):
2005         * bmalloc/SmallChunk.h: Added.
2006         * bmalloc/SmallLine.h: Added.
2007         * bmalloc/SmallPage.h: Added.
2008         * bmalloc/SmallTraits.h: Added.
2009         * bmalloc/Syscall.h: Added.
2010         * bmalloc/VMAllocate.h: Added.
2011         (bmalloc::vmSize):
2012         (bmalloc::vmValidate):
2013         (bmalloc::vmAllocate):
2014         (bmalloc::vmDeallocate):
2015         (bmalloc::vmDeallocatePhysicalPages):
2016         (bmalloc::vmAllocatePhysicalPages):
2017         (bmalloc::vmDeallocatePhysicalPagesSloppy):
2018         (bmalloc::vmAllocatePhysicalPagesSloppy):
2019         * bmalloc/VMHeap.cpp: Added.
2020         (bmalloc::VMHeap::VMHeap):
2021         (bmalloc::VMHeap::allocateSmallChunk):
2022         (bmalloc::VMHeap::allocateMediumChunk):
2023         (bmalloc::VMHeap::allocateLargeChunk):
2024         * bmalloc/VMHeap.h: Added.
2025         (bmalloc::VMHeap::allocateSmallPage):
2026         (bmalloc::VMHeap::allocateMediumPage):
2027         (bmalloc::VMHeap::allocateLargeRange):
2028         (bmalloc::VMHeap::deallocateSmallPage):
2029         (bmalloc::VMHeap::deallocateMediumPage):
2030         (bmalloc::VMHeap::deallocateLargeRange):
2031         * bmalloc/Vector.h: Added.
2032         (bmalloc::Vector::begin):
2033         (bmalloc::Vector::end):
2034         (bmalloc::Vector::size):
2035         (bmalloc::Vector::capacity):
2036         (bmalloc::Vector::last):
2037         (bmalloc::Vector::pop):
2038         (bmalloc::Vector<T>::Vector):
2039         (bmalloc::Vector<T>::~Vector):
2040         (bmalloc::Vector<T>::operator):
2041         (bmalloc::Vector<T>::push):
2042         (bmalloc::Vector<T>::pop):
2043         (bmalloc::Vector<T>::shrink):
2044         (bmalloc::Vector<T>::reallocateBuffer):
2045         (bmalloc::Vector<T>::shrinkCapacity):
2046         (bmalloc::Vector<T>::growCapacity):
2047         * bmalloc/XLargeChunk.h: Added.
2048         (bmalloc::XLargeChunk::get):
2049         (bmalloc::XLargeChunk::begin):
2050         (bmalloc::XLargeChunk::XLargeChunk):
2051         (bmalloc::XLargeChunk::create):
2052         (bmalloc::XLargeChunk::destroy):
2053         (bmalloc::XLargeChunk::range):
2054         (bmalloc::XLargeChunk::size):
2055         * bmalloc/bmalloc.h: Added.
2056         (bmalloc::api::malloc):
2057         (bmalloc::api::free):
2058         (bmalloc::api::realloc):
2059         * bmalloc/mbmalloc.cpp: Added.
2060