Changeset 287968 in webkit
- Timestamp:
- Jan 12, 2022 6:52:00 PM (2 years ago)
- Location:
- trunk/Source/bmalloc
- Files:
-
- 5 added
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/bmalloc/ChangeLog
r287956 r287968 1 2022-01-12 Filip Pizlo <fpizlo@apple.com> 2 3 [libpas] thread_local_cache should not be allocated in the compact heap (cherry pick 11afcedfb5968f6894379ff1a41dd449ba7745f6) 4 https://bugs.webkit.org/show_bug.cgi?id=235096 5 6 Reviewed by Yusuke Suzuki. 7 8 Thread local caches can get quite large because of how libpas uses them, we can allocate one per 9 thread, and we reallocate them with exponential resizing, so there's a lot of wasted space and a 10 decent amount of fragmentation. This shows up as occasional crashes trying to allocate a thread local 11 cache out of the compact heap. 12 13 This moves thread local caches out of the compact heap. They were only ever there because partial views 14 sometimes need to point to the local_allocator's bitvector, but that's part of the thread local cache. 15 So, that means that either the partial views' bits pointer cannot be a compact pointer, or the 16 thread_local_cache needs to be in the compact heap. So, the thread_local_cache ended up in the compact 17 heap to keep that pointer small. 18 19 This change works around the problem: it's rare that the partial views' bits pointer points at 20 the local_allocator's bits, and none of the fast path cases where we access that pointer will ever see 21 it in that state. So, this makes the pointer either point to a utility-heap-allocated box that contains 22 the full pointer, or it points at the actual array allocated in the compact heap. The utility heap is 23 in the compact heap, so the compact pointer can point at either one. The implementation of this is 24 encapsulated as pas_lenient_compact_ptr. It's a bit gross; storing to it only works when you're holding 25 the heap lock, for example. 26 27 This is perf-neutral on Speedometer. This is perf-neutral on JS2 cli with full JSC isoheaps (i.e. the 28 patch from bug 231938). It's a 0.4% regression on RAMification with full JSC isoheaps, but I'm not 29 going to worry about that because trunk doesn't have full JSC isoheaps, and JSC isoheaps requires some 30 change like this to work reliably (currently it'll randomly run out of compact heap). 31 32 * bmalloc.xcodeproj/project.pbxproj: 33 * libpas/libpas.xcodeproj/project.pbxproj: 34 * libpas/src/libpas/pas_enumerate_segregated_heaps.c: 35 (enumerate_partial_view): 36 * libpas/src/libpas/pas_full_alloc_bits_inlines.h: 37 (pas_full_alloc_bits_create_for_partial_but_not_primordial): 38 (pas_full_alloc_bits_create_for_partial): 39 * libpas/src/libpas/pas_lenient_compact_ptr.h: Added. 40 * libpas/src/libpas/pas_lenient_compact_ptr_inlines.h: Added. 41 * libpas/src/libpas/pas_lenient_compact_unsigned_ptr.c: Added. 42 * libpas/src/libpas/pas_lenient_compact_unsigned_ptr.h: Added. 43 * libpas/src/libpas/pas_local_allocator.c: 44 (pas_local_allocator_move): 45 * libpas/src/libpas/pas_local_allocator_inlines.h: 46 (pas_local_allocator_set_up_free_bits): 47 (pas_local_allocator_start_allocating_in_primordial_partial_view): 48 (pas_local_allocator_bless_primordial_partial_view_before_stopping): 49 * libpas/src/libpas/pas_segregated_partial_view.c: 50 (pas_segregated_partial_view_create): 51 (compute_summary): 52 * libpas/src/libpas/pas_segregated_partial_view.h: 53 * libpas/src/libpas/pas_segregated_view_allocator_inlines.h: 54 (pas_segregated_view_will_start_allocating): 55 * libpas/src/libpas/pas_thread_local_cache.c: 56 (deallocate): 57 (allocate_cache): 58 * libpas/src/test/LotsOfHeapsAndThreads.cpp: Added. 59 (std::testLotsOfHeapsAndThreads): 60 (addLotsOfHeapsAndThreadsTests): 61 * libpas/src/test/TestHarness.cpp: 62 (main): 63 1 64 2022-01-12 Elliott Williams <emw@apple.com> 2 65 -
trunk/Source/bmalloc/bmalloc.xcodeproj/project.pbxproj
r287956 r287968 617 617 2C48134527406A3E006CAB55 /* pas_large_expendable_memory.h in Headers */ = {isa = PBXBuildFile; fileRef = 2C48133F27406A3E006CAB55 /* pas_large_expendable_memory.h */; settings = {ATTRIBUTES = (Private, ); }; }; 618 618 2C91E552271CE47A00D67FF9 /* pas_size_lookup_mode.h in Headers */ = {isa = PBXBuildFile; fileRef = 2C91E551271CE47A00D67FF9 /* pas_size_lookup_mode.h */; settings = {ATTRIBUTES = (Private, ); }; }; 619 2C971D04278E798700C9E129 /* pas_lenient_compact_ptr_inlines.h in Headers */ = {isa = PBXBuildFile; fileRef = 2C971D00278E798700C9E129 /* pas_lenient_compact_ptr_inlines.h */; }; 620 2C971D05278E798700C9E129 /* pas_lenient_compact_ptr.h in Headers */ = {isa = PBXBuildFile; fileRef = 2C971D01278E798700C9E129 /* pas_lenient_compact_ptr.h */; settings = {ATTRIBUTES = (Private, ); }; }; 621 2C971D06278E798700C9E129 /* pas_lenient_compact_unsigned_ptr.h in Headers */ = {isa = PBXBuildFile; fileRef = 2C971D02278E798700C9E129 /* pas_lenient_compact_unsigned_ptr.h */; settings = {ATTRIBUTES = (Private, ); }; }; 622 2C971D07278E798700C9E129 /* pas_lenient_compact_unsigned_ptr.c in Sources */ = {isa = PBXBuildFile; fileRef = 2C971D03278E798700C9E129 /* pas_lenient_compact_unsigned_ptr.c */; }; 619 623 2CE2AE2D27596DEB00D02BBC /* pas_segregated_page_role.h in Headers */ = {isa = PBXBuildFile; fileRef = 2CE2AE2627596DEA00D02BBC /* pas_segregated_page_role.h */; settings = {ATTRIBUTES = (Private, ); }; }; 620 624 2CE2AE2E27596DEB00D02BBC /* pas_page_base_and_kind.h in Headers */ = {isa = PBXBuildFile; fileRef = 2CE2AE2727596DEA00D02BBC /* pas_page_base_and_kind.h */; settings = {ATTRIBUTES = (Private, ); }; }; … … 1276 1280 2C48133F27406A3E006CAB55 /* pas_large_expendable_memory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = pas_large_expendable_memory.h; path = libpas/src/libpas/pas_large_expendable_memory.h; sourceTree = "<group>"; }; 1277 1281 2C91E551271CE47A00D67FF9 /* pas_size_lookup_mode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = pas_size_lookup_mode.h; path = libpas/src/libpas/pas_size_lookup_mode.h; sourceTree = "<group>"; }; 1282 2C971D00278E798700C9E129 /* pas_lenient_compact_ptr_inlines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = pas_lenient_compact_ptr_inlines.h; path = libpas/src/libpas/pas_lenient_compact_ptr_inlines.h; sourceTree = "<group>"; }; 1283 2C971D01278E798700C9E129 /* pas_lenient_compact_ptr.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = pas_lenient_compact_ptr.h; path = libpas/src/libpas/pas_lenient_compact_ptr.h; sourceTree = "<group>"; }; 1284 2C971D02278E798700C9E129 /* pas_lenient_compact_unsigned_ptr.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = pas_lenient_compact_unsigned_ptr.h; path = libpas/src/libpas/pas_lenient_compact_unsigned_ptr.h; sourceTree = "<group>"; }; 1285 2C971D03278E798700C9E129 /* pas_lenient_compact_unsigned_ptr.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = pas_lenient_compact_unsigned_ptr.c; path = libpas/src/libpas/pas_lenient_compact_unsigned_ptr.c; sourceTree = "<group>"; }; 1278 1286 2CE2AE2627596DEA00D02BBC /* pas_segregated_page_role.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = pas_segregated_page_role.h; path = libpas/src/libpas/pas_segregated_page_role.h; sourceTree = "<group>"; }; 1279 1287 2CE2AE2727596DEA00D02BBC /* pas_page_base_and_kind.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = pas_page_base_and_kind.h; path = libpas/src/libpas/pas_page_base_and_kind.h; sourceTree = "<group>"; }; … … 1702 1710 0FC40AA32451498E00876DA0 /* pas_large_utility_free_heap.c */, 1703 1711 0FC40AF12451499300876DA0 /* pas_large_utility_free_heap.h */, 1712 2C971D00278E798700C9E129 /* pas_lenient_compact_ptr_inlines.h */, 1713 2C971D01278E798700C9E129 /* pas_lenient_compact_ptr.h */, 1714 2C971D03278E798700C9E129 /* pas_lenient_compact_unsigned_ptr.c */, 1715 2C971D02278E798700C9E129 /* pas_lenient_compact_unsigned_ptr.h */, 1704 1716 0F8A812425F83E2400790B4A /* pas_line_word_config.h */, 1705 1717 0FC40A7D2451498B00876DA0 /* pas_list_direction.h */, … … 2180 2192 0F7EB8351F9541B000F1ABCB /* IsoTLSEntryInlines.h in Headers */, 2181 2193 0F7EB8461F9541B000F1ABCB /* IsoTLSInlines.h in Headers */, 2194 2C971D04278E798700C9E129 /* pas_lenient_compact_ptr_inlines.h in Headers */, 2182 2195 0F7EB8401F9541B000F1ABCB /* IsoTLSLayout.h in Headers */, 2183 2196 0F5193EF266C42AD00483A2C /* jit_heap.h in Headers */, … … 2187 2200 14C8992D1CC578330027A057 /* LargeRange.h in Headers */, 2188 2201 140FA00519CE4B6800FFD3C8 /* LineMetadata.h in Headers */, 2202 2C971D06278E798700C9E129 /* pas_lenient_compact_unsigned_ptr.h in Headers */, 2189 2203 141D9B001C8E51C0000ABBA0 /* List.h in Headers */, 2190 2204 4426E2811C838EE0008EB042 /* Logging.h in Headers */, … … 2313 2327 0FC409E92451496400876DA0 /* pas_ensure_heap_with_page_caches.h in Headers */, 2314 2328 0F87002C25AF89C9000E1ABF /* pas_enumerable_page_malloc.h in Headers */, 2329 2C971D05278E798700C9E129 /* pas_lenient_compact_ptr.h in Headers */, 2315 2330 0F87002E25AF89C9000E1ABF /* pas_enumerable_range_list.h in Headers */, 2316 2331 0F87FFEC25AF897C000E1ABF /* pas_enumerate_bitfit_heaps.h in Headers */, … … 2684 2699 E378A9DF246B68720029C2BB /* ObjectTypeTable.cpp in Sources */, 2685 2700 0F18F84725C3467700721C2A /* pagesize64k_heap.c in Sources */, 2701 2C971D07278E798700C9E129 /* pas_lenient_compact_unsigned_ptr.c in Sources */, 2686 2702 0F18F84925C3467700721C2A /* pagesize64k_heap_config.c in Sources */, 2687 2703 0FC4095D2451494400876DA0 /* pas_alignment.c in Sources */, -
trunk/Source/bmalloc/libpas/libpas.xcodeproj/project.pbxproj
r287192 r287968 572 572 2C85DC4127128F0F00367905 /* pas_try_allocate_intrinsic.h in Headers */ = {isa = PBXBuildFile; fileRef = 2C85DC4027128F0F00367905 /* pas_try_allocate_intrinsic.h */; }; 573 573 2C91E5502718DA9A00D67FF9 /* pas_size_lookup_mode.h in Headers */ = {isa = PBXBuildFile; fileRef = 2C91E54F2718DA9A00D67FF9 /* pas_size_lookup_mode.h */; }; 574 2C971CFA278E11C300C9E129 /* pas_lenient_compact_ptr.h in Headers */ = {isa = PBXBuildFile; fileRef = 2C971CF8278E11C300C9E129 /* pas_lenient_compact_ptr.h */; }; 575 2C971CFB278E11C300C9E129 /* pas_lenient_compact_unsigned_ptr.h in Headers */ = {isa = PBXBuildFile; fileRef = 2C971CF9278E11C300C9E129 /* pas_lenient_compact_unsigned_ptr.h */; }; 576 2C971CFE278E136300C9E129 /* pas_lenient_compact_unsigned_ptr.c in Sources */ = {isa = PBXBuildFile; fileRef = 2C971CFC278E136300C9E129 /* pas_lenient_compact_unsigned_ptr.c */; }; 577 2C971CFF278E136300C9E129 /* pas_lenient_compact_ptr_inlines.h in Headers */ = {isa = PBXBuildFile; fileRef = 2C971CFD278E136300C9E129 /* pas_lenient_compact_ptr_inlines.h */; }; 578 2CB9B153278F6C85003A8C1B /* LotsOfHeapsAndThreads.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2CB9B152278F6C85003A8C1B /* LotsOfHeapsAndThreads.cpp */; }; 574 579 2CE2AE35275A953E00D02BBC /* BitfitTests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2CE2AE34275A953E00D02BBC /* BitfitTests.cpp */; }; 575 580 /* End PBXBuildFile section */ … … 1260 1265 2C85DC4027128F0F00367905 /* pas_try_allocate_intrinsic.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = pas_try_allocate_intrinsic.h; sourceTree = "<group>"; }; 1261 1266 2C91E54F2718DA9A00D67FF9 /* pas_size_lookup_mode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = pas_size_lookup_mode.h; sourceTree = "<group>"; }; 1267 2C971CF8278E11C300C9E129 /* pas_lenient_compact_ptr.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = pas_lenient_compact_ptr.h; sourceTree = "<group>"; }; 1268 2C971CF9278E11C300C9E129 /* pas_lenient_compact_unsigned_ptr.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = pas_lenient_compact_unsigned_ptr.h; sourceTree = "<group>"; }; 1269 2C971CFC278E136300C9E129 /* pas_lenient_compact_unsigned_ptr.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = pas_lenient_compact_unsigned_ptr.c; sourceTree = "<group>"; }; 1270 2C971CFD278E136300C9E129 /* pas_lenient_compact_ptr_inlines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = pas_lenient_compact_ptr_inlines.h; sourceTree = "<group>"; }; 1271 2CB9B152278F6C85003A8C1B /* LotsOfHeapsAndThreads.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LotsOfHeapsAndThreads.cpp; sourceTree = "<group>"; }; 1262 1272 2CE2AE34275A953E00D02BBC /* BitfitTests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = BitfitTests.cpp; sourceTree = "<group>"; }; 1263 1273 /* End PBXFileReference section */ … … 1355 1365 2CE2AE34275A953E00D02BBC /* BitfitTests.cpp */, 1356 1366 0F53181022C954ED003F7B6A /* BitvectorTests.cpp */, 1357 2B2A589B2742D815005EE07C /* PGMTests.cpp */,1358 1367 0F31A66723E8B336002C0CA3 /* CartesianTreeTests.cpp */, 1359 1368 0FC682362129D4EB003C6A13 /* CoalignTests.cpp */, … … 1369 1378 0F5B6093235E919900CAE629 /* IsoHeapReservedMemoryTests.cpp */, 1370 1379 0F5193E6266AE5D400483A2C /* JITHeapTests.cpp */, 1371 2B8BCAC62739A47900B1A46F /* PGMTests.cpp */,1372 1380 0FC64190213745FA0040CE5E /* LargeFreeHeapTests.cpp */, 1373 1381 0FEB6666231C87BC009C001B /* LargeSharingPoolDump.cpp */, … … 1375 1383 0FEB6669231DA86F009C001B /* LargeSharingPoolTests.cpp */, 1376 1384 0FEA45BE236CDAED00B5A375 /* LockFreeReadPtrPtrHashtableTests.cpp */, 1385 2CB9B152278F6C85003A8C1B /* LotsOfHeapsAndThreads.cpp */, 1377 1386 0FD22D0722CD8A7500B21841 /* MinHeapTests.cpp */, 1387 2B2A589B2742D815005EE07C /* PGMTests.cpp */, 1378 1388 0F5E483923D69F610046DA5C /* RaceTests.cpp */, 1379 1389 0FF08F3522A59DB300386575 /* RedBlackTreeTests.cpp */, … … 1411 1421 0F516EE624561A60004E2B8D /* iso_heap_innards.h */, 1412 1422 0F529DDE2455460C00385A8C /* iso_heap_ref.h */, 1413 2B2A58982742D802005EE07C /* pas_probabilistic_guard_malloc_allocator.c */,1414 2B2A58972742D802005EE07C /* pas_probabilistic_guard_malloc_allocator.h */,1415 1423 0FE7EE74229F010F004F4166 /* iso_heap.c */, 1416 1424 0FE7EE75229F010F004F4166 /* iso_heap.h */, … … 1686 1694 0F6D547523C573E000F40DBB /* pas_large_utility_free_heap.c */, 1687 1695 0F6D547223C573E000F40DBB /* pas_large_utility_free_heap.h */, 1696 2C971CFD278E136300C9E129 /* pas_lenient_compact_ptr_inlines.h */, 1697 2C971CF8278E11C300C9E129 /* pas_lenient_compact_ptr.h */, 1698 2C971CFC278E136300C9E129 /* pas_lenient_compact_unsigned_ptr.c */, 1699 2C971CF9278E11C300C9E129 /* pas_lenient_compact_unsigned_ptr.h */, 1688 1700 0F8A802725EC588800790B4A /* pas_line_word_config.h */, 1689 1701 0F31A64323E3509E002C0CA3 /* pas_list_direction.h */, … … 1743 1755 0F4F61C925A4CD3B008B4A82 /* pas_payload_reservation_page_list.c */, 1744 1756 0F4F61C825A4CD3B008B4A82 /* pas_payload_reservation_page_list.h */, 1745 2B8BCAC32739A45900B1A46F /* pas_probabilistic_guard_malloc_allocator.c */,1746 2B8BCAC22739A45900B1A46F /* pas_probabilistic_guard_malloc_allocator.h */,1747 1757 0F6D547323C573E000F40DBB /* pas_physical_memory_synchronization_style.h */, 1748 1758 0FF248F722FC9EDA0077202E /* pas_physical_memory_transaction.c */, … … 1750 1760 0FDEA578228E23450085E340 /* pas_primitive_heap_ref.c */, 1751 1761 0FDEA577228E23440085E340 /* pas_primitive_heap_ref.h */, 1762 2B2A58982742D802005EE07C /* pas_probabilistic_guard_malloc_allocator.c */, 1763 2B2A58972742D802005EE07C /* pas_probabilistic_guard_malloc_allocator.h */, 1752 1764 0F9A1CAD2559961300C8D11B /* pas_promote_intrinsic_heap.h */, 1753 1765 0F4F615A259BF6EC008B4A82 /* pas_ptr_hash_map.h */, … … 2051 2063 0FE7EE0422960142004F4166 /* pas_bitvector.h in Headers */, 2052 2064 0FE7EE0522960142004F4166 /* pas_bootstrap_free_heap.h in Headers */, 2065 2C971CFB278E11C300C9E129 /* pas_lenient_compact_unsigned_ptr.h in Headers */, 2053 2066 0F5B6084235E572000CAE629 /* pas_bootstrap_heap_page_provider.h in Headers */, 2054 2067 0FE7EE0822960142004F4166 /* pas_cares_about_size_mode.h in Headers */, … … 2147 2160 0FD48B3A23A9ABB30026C46D /* pas_full_alloc_bits_inlines.h in Headers */, 2148 2161 0FF08F3A22A5B40300386575 /* pas_generic_large_free_heap.h in Headers */, 2162 2C971CFA278E11C300C9E129 /* pas_lenient_compact_ptr.h in Headers */, 2149 2163 0FE7EE60229E14FA004F4166 /* pas_get_allocation_size.h in Headers */, 2150 2164 0FE7EE64229E14FA004F4166 /* pas_get_heap.h in Headers */, … … 2254 2268 0F19326C22F73E8500FBA713 /* pas_scavenger.h in Headers */, 2255 2269 0F68127222BD4BF40036A02B /* pas_segmented_vector.h in Headers */, 2270 2C971CFF278E136300C9E129 /* pas_lenient_compact_ptr_inlines.h in Headers */, 2256 2271 0F148710269B7518006887A9 /* pas_segregated_deallocation_mode.h in Headers */, 2257 2272 0FD48B5623A9ABB30026C46D /* pas_segregated_directory.h in Headers */, … … 2600 2615 0FF248FD230CC4CB0077202E /* IsoHeapPageSharingTests.cpp in Sources */, 2601 2616 0FD48B6723B589910026C46D /* IsoHeapPartialAndBaselineTests.cpp in Sources */, 2617 2CB9B153278F6C85003A8C1B /* LotsOfHeapsAndThreads.cpp in Sources */, 2602 2618 0F5B6094235E919900CAE629 /* IsoHeapReservedMemoryTests.cpp in Sources */, 2603 2619 2CE2AE35275A953E00D02BBC /* BitfitTests.cpp in Sources */, … … 2682 2698 0F19325622ED04A600FBA713 /* pas_epoch.c in Sources */, 2683 2699 0FD48B3423A9ABB30026C46D /* pas_exclusive_view_template_memo_table.c in Sources */, 2700 2C971CFE278E136300C9E129 /* pas_lenient_compact_unsigned_ptr.c in Sources */, 2684 2701 2C481328273F341A006CAB55 /* pas_expendable_memory.c in Sources */, 2685 2702 0FE7EDBA22960142004F4166 /* pas_extended_gcd.c in Sources */, -
trunk/Source/bmalloc/libpas/src/libpas/pas_enumerate_segregated_heaps.c
r287192 r287968 1 1 /* 2 * Copyright (c) 2020-202 1Apple Inc. All rights reserved.2 * Copyright (c) 2020-2022 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 516 516 pas_log("Found allocator = %p\n", allocator); 517 517 518 full_alloc_bits.bits = pas_compact_tagged_unsigned_ptr_load_remote(enumerator, &view->alloc_bits); 518 /* This is so weird: the size we pass is only valid when view->alloc_bits is pointing at the 519 local_allocator's bits. But that's the only time that load_remote will go down the path where it needs 520 to know the size. So, it's fine, I guess. */ 521 full_alloc_bits.bits = pas_lenient_compact_unsigned_ptr_load_remote( 522 enumerator, &view->alloc_bits, pas_segregated_page_config_num_alloc_bytes(*page_config)); 519 523 full_alloc_bits.word_index_begin = view->alloc_bits_offset; 520 524 full_alloc_bits.word_index_end = view->alloc_bits_offset + view->alloc_bits_size; -
trunk/Source/bmalloc/libpas/src/libpas/pas_full_alloc_bits_inlines.h
r282556 r287968 1 1 /* 2 * Copyright (c) 2019-202 0Apple Inc. All rights reserved.2 * Copyright (c) 2019-2022 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 50 50 51 51 static PAS_ALWAYS_INLINE pas_full_alloc_bits 52 pas_full_alloc_bits_create_for_partial_but_not_primordial(pas_segregated_view view) 53 { 54 pas_segregated_partial_view* partial_view; 55 56 partial_view = pas_segregated_view_get_partial(view); 57 58 return pas_full_alloc_bits_create( 59 pas_lenient_compact_unsigned_ptr_load_compact_non_null(&partial_view->alloc_bits), 60 partial_view->alloc_bits_offset, 61 partial_view->alloc_bits_offset + partial_view->alloc_bits_size); 62 } 63 64 static PAS_ALWAYS_INLINE pas_full_alloc_bits 52 65 pas_full_alloc_bits_create_for_partial(pas_segregated_view view) 53 66 { … … 57 70 58 71 return pas_full_alloc_bits_create( 59 pas_ compact_tagged_unsigned_ptr_load_non_null(&partial_view->alloc_bits),72 pas_lenient_compact_unsigned_ptr_load(&partial_view->alloc_bits), 60 73 partial_view->alloc_bits_offset, 61 74 partial_view->alloc_bits_offset + partial_view->alloc_bits_size); -
trunk/Source/bmalloc/libpas/src/libpas/pas_local_allocator.c
r286493 r287968 1 1 /* 2 * Copyright (c) 2018-202 1Apple Inc. All rights reserved.2 * Copyright (c) 2018-2022 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 119 119 pas_segregated_shared_view* shared_view; 120 120 121 pas_heap_lock_assert_held(); /* Needed to modify a lenient_compact_ptr. */ 122 121 123 directory = pas_segregated_view_get_size_directory(src->view); 122 124 … … 136 138 happens to hold the ownership lock. */ 137 139 pas_lock_lock(&shared_view->ownership_lock); 138 if (pas_ compact_tagged_unsigned_ptr_load(&partial_view->alloc_bits) == (unsigned*)src->bits)139 pas_ compact_tagged_unsigned_ptr_store(&partial_view->alloc_bits, (unsigned*)dst->bits);140 if (pas_lenient_compact_unsigned_ptr_load(&partial_view->alloc_bits) == (unsigned*)src->bits) 141 pas_lenient_compact_unsigned_ptr_store(&partial_view->alloc_bits, (unsigned*)dst->bits); 140 142 pas_lock_unlock(&shared_view->ownership_lock); 141 143 } -
trunk/Source/bmalloc/libpas/src/libpas/pas_local_allocator_inlines.h
r287192 r287968 1 1 /* 2 * Copyright (c) 2018-202 1Apple Inc. All rights reserved.2 * Copyright (c) 2018-2022 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 353 353 partial_view_as_view = pas_segregated_partial_view_as_view((pas_segregated_partial_view*)view); 354 354 355 full_alloc_bits = pas_full_alloc_bits_create_for_partial (partial_view_as_view);355 full_alloc_bits = pas_full_alloc_bits_create_for_partial_but_not_primordial(partial_view_as_view); 356 356 357 357 allocator->view = partial_view_as_view; … … 600 600 601 601 shared_view = pas_segregated_shared_page_directory_find_first_eligible( 602 shared_page_directory, size, alignment, 603 pas_segregated_page_config_heap_lock_hold_mode(page_config)); 602 shared_page_directory, size, alignment, pas_lock_is_not_held); 604 603 605 604 PAS_ASSERT(shared_view); 606 605 607 pas_lock_lock_conditionally( 608 &shared_view->commit_lock, 609 pas_segregated_page_config_heap_lock_hold_mode(page_config)); 606 pas_lock_lock(&shared_view->commit_lock); 610 607 611 608 handle = pas_segregated_shared_view_commit_page_if_necessary( 612 609 shared_view, heap, shared_page_directory, view, page_config); 613 610 if (!handle) { 614 pas_lock_unlock_conditionally( 615 &shared_view->commit_lock, 616 pas_segregated_page_config_heap_lock_hold_mode(page_config)); 611 pas_lock_unlock(&shared_view->commit_lock); 617 612 return false; 618 613 } … … 664 659 pas_zero_memory(allocator->bits, pas_segregated_page_config_num_alloc_bytes(page_config)); 665 660 666 /* Doing this helps heap introspection but isn't otherwise necessary. */667 pas_compact_tagged_unsigned_ptr_store(&view->alloc_bits, (unsigned*)allocator->bits);668 PAS_ASSERT(!view->alloc_bits_offset);669 PAS_ASSERT((uint8_t)pas_segregated_page_config_num_alloc_words(page_config)670 == pas_segregated_page_config_num_alloc_words(page_config));671 view->alloc_bits_size = (uint8_t)pas_segregated_page_config_num_alloc_words(page_config);672 673 661 pas_local_allocator_set_up_primordial_bump( 674 662 allocator, view, handle, page, &held_lock, bump_result, … … 680 668 view->is_attached_to_shared_handle = true; 681 669 670 pas_lock_unlock(&shared_view->commit_lock); 671 672 /* This code to set the view's alloc_bits is primarily for heap enumeration. 673 674 If the enumerator ran right now then (before we do this stuff), then it would see: 675 676 - A bunch of page alloc bits set for the objects we are about to allocate. 677 - No partial views say that they own those objects. 678 - Local allocator claims to own those objects. 679 680 So, we would report that those objects are not live right now. I believe they would show up 681 as "meta" allocations, not even as objects. 682 683 Immediately after settings the view's alloc_bits and alloc_bits_size, we will know that the 684 objects exist (view alloc bits are set), but they are dead (despite page alloc bits also being 685 set, the objects are part of the bump range). */ 686 if (!pas_heap_lock_try_lock()) { 687 pas_lock_switch(&held_lock, NULL); 688 pas_heap_lock_lock(); 689 pas_segregated_page_switch_lock(page, &held_lock, page_config); 690 } 691 692 pas_lenient_compact_unsigned_ptr_store(&view->alloc_bits, (unsigned*)allocator->bits); 693 PAS_ASSERT(!view->alloc_bits_offset); 694 PAS_ASSERT((uint8_t)pas_segregated_page_config_num_alloc_words(page_config) 695 == pas_segregated_page_config_num_alloc_words(page_config)); 696 pas_compiler_fence(); 697 view->alloc_bits_size = (uint8_t)pas_segregated_page_config_num_alloc_words(page_config); 682 698 pas_lock_switch(&held_lock, NULL); 683 pas_lock_unlock_conditionally( 684 &shared_view->commit_lock, 685 pas_segregated_page_config_heap_lock_hold_mode(page_config)); 686 699 pas_heap_lock_unlock(); 700 687 701 return true; 688 702 } … … 776 790 PAS_ASSERT((uint8_t)alloc_bits_offset == alloc_bits_offset); 777 791 view->alloc_bits_offset = (uint8_t)alloc_bits_offset; 792 793 /* We hold the page lock. Lock ordering says that we cannot acquire the heap lock when 794 we are holding the page lock. 795 796 Luckily, this is a fine place to drop the page lock. 797 798 Therefore, we try-lock the heap lock. It's always safe to do that. Usually it will just 799 succeed. But if it fails, we will drop the page lock and then acquire both of them. */ 800 if (!pas_heap_lock_try_lock_conditionally(heap_lock_hold_mode)) { 801 pas_segregated_page_unlock(page, page_config); 802 pas_heap_lock_lock(); 803 pas_segregated_page_lock(page, page_config); 804 } 778 805 779 806 if (alloc_bits_size == 1) 780 807 alloc_bits = &view->inline_alloc_bits - alloc_bits_offset; 781 808 else { 782 /* We hold the page lock. Lock ordering says that we cannot acquire the heap lock when783 we are holding the page lock.784 785 Luckily, this is a fine place to drop the page lock.786 787 Therefore, we try-lock the heap lock. It's always safe to do that. Usually it will just788 succeed. But if it fails, we will drop the page lock and then acquire both of them. */789 if (!pas_heap_lock_try_lock_conditionally(heap_lock_hold_mode)) {790 pas_segregated_page_unlock(page, page_config);791 pas_heap_lock_lock();792 pas_segregated_page_lock(page, page_config);793 }794 795 809 alloc_bits = (unsigned*)pas_immortal_heap_allocate_with_manual_alignment( 796 810 alloc_bits_size * sizeof(unsigned), … … 798 812 "pas_segregated_partial_view/alloc_bits", 799 813 pas_object_allocation) - alloc_bits_offset; 800 801 pas_heap_lock_unlock_conditionally(heap_lock_hold_mode);802 814 } 803 815 … … 808 820 pas_store_store_fence(); 809 821 810 pas_compact_tagged_unsigned_ptr_store(&view->alloc_bits, alloc_bits); 822 pas_lenient_compact_unsigned_ptr_store(&view->alloc_bits, alloc_bits); 823 824 pas_heap_lock_unlock_conditionally(heap_lock_hold_mode); 811 825 } 812 826 -
trunk/Source/bmalloc/libpas/src/libpas/pas_segregated_partial_view.c
r285853 r287968 1 1 /* 2 * Copyright (c) 2019-202 0Apple Inc. All rights reserved.2 * Copyright (c) 2019-2022 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 65 65 result->alloc_bits_offset = 0; 66 66 result->alloc_bits_size = 0; 67 pas_ compact_tagged_unsigned_ptr_store(&result->alloc_bits, NULL);67 pas_lenient_compact_unsigned_ptr_store(&result->alloc_bits, NULL); 68 68 69 69 result->inline_alloc_bits = 0; /* There isn't a real big need to do this, but it helps keep … … 187 187 shared_view = pas_compact_segregated_shared_view_ptr_load_non_null(&view->shared_view); 188 188 189 full_alloc_bits = pas_ compact_tagged_unsigned_ptr_load_non_null(&view->alloc_bits);189 full_alloc_bits = pas_lenient_compact_unsigned_ptr_load(&view->alloc_bits); 190 190 191 191 if (shared_view->is_owned) { -
trunk/Source/bmalloc/libpas/src/libpas/pas_segregated_partial_view.h
r282556 r287968 1 1 /* 2 * Copyright (c) 2019-202 0Apple Inc. All rights reserved.2 * Copyright (c) 2019-2022 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 29 29 #include "pas_compact_segregated_shared_view_ptr.h" 30 30 #include "pas_compact_segregated_size_directory_ptr.h" 31 #include "pas_compact_tagged_unsigned_ptr.h" 31 #include "pas_lenient_compact_unsigned_ptr.h" 32 #include "pas_page_granule_use_count.h" 32 33 #include "pas_segregated_page_config.h" 33 #include "pas_page_granule_use_count.h"34 34 #include "pas_segregated_view.h" 35 35 #include "pas_utils.h" … … 49 49 pas_compact_segregated_shared_view_ptr shared_view; 50 50 pas_compact_segregated_size_directory_ptr directory; 51 pas_ compact_tagged_unsigned_ptr alloc_bits;51 pas_lenient_compact_unsigned_ptr alloc_bits; 52 52 53 53 /* The index can be small since we would never create a high-indexed partial view. That would not -
trunk/Source/bmalloc/libpas/src/libpas/pas_segregated_view_allocator_inlines.h
r287192 r287968 1 1 /* 2 * Copyright (c) 2021 Apple Inc. All rights reserved.2 * Copyright (c) 2021-2022 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 263 263 unsigned word_index; 264 264 265 full_alloc_bits = pas_ compact_tagged_unsigned_ptr_load_non_null(&partial->alloc_bits);265 full_alloc_bits = pas_lenient_compact_unsigned_ptr_load_compact_non_null(&partial->alloc_bits); 266 266 267 267 begin_word_index = partial->alloc_bits_offset; -
trunk/Source/bmalloc/libpas/src/libpas/pas_thread_local_cache.c
r286587 r287968 31 31 32 32 #include "pas_all_heap_configs.h" 33 #include "pas_compact_large_utility_free_heap.h"34 33 #include "pas_debug_heap.h" 35 34 #include "pas_heap_lock.h" 35 #include "pas_large_utility_free_heap.h" 36 36 #include "pas_log.h" 37 37 #include "pas_monotonic_time.h" … … 64 64 char* begin; 65 65 66 pas_ compact_large_utility_free_heap_deallocate(66 pas_large_utility_free_heap_deallocate( 67 67 thread_local_cache->should_stop_bitvector, 68 68 PAS_BITVECTOR_NUM_BYTES(thread_local_cache->allocator_index_capacity)); 69 69 70 70 begin = (char*)thread_local_cache; 71 pas_ compact_large_utility_free_heap_deallocate(71 pas_large_utility_free_heap_deallocate( 72 72 begin, 73 73 pas_thread_local_cache_size_for_allocator_index_capacity( … … 130 130 printf("Cache size: %zu\n", size); 131 131 132 result = (pas_thread_local_cache*)pas_ compact_large_utility_free_heap_allocate(size, "pas_thread_local_cache");132 result = (pas_thread_local_cache*)pas_large_utility_free_heap_allocate(size, "pas_thread_local_cache"); 133 133 134 134 pas_zero_memory(result, size); 135 135 136 result->should_stop_bitvector = (unsigned int*)pas_ compact_large_utility_free_heap_allocate(136 result->should_stop_bitvector = (unsigned int*)pas_large_utility_free_heap_allocate( 137 137 PAS_BITVECTOR_NUM_BYTES(allocator_index_capacity), 138 138 "pas_thread_local_cache/should_stop_bitvector"); -
trunk/Source/bmalloc/libpas/src/test/TestHarness.cpp
r287192 r287968 1 1 /* 2 * Copyright (c) 2018-202 1Apple Inc. All rights reserved.2 * Copyright (c) 2018-2022 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 354 354 void addLargeSharingPoolTests(); 355 355 void addLockFreeReadPtrPtrHashtableTests(); 356 void addLotsOfHeapsAndThreadsTests(); 356 357 void addMinHeapTests(); 357 358 void addPGMTests(); … … 718 719 ADD_SUITE(LargeSharingPool); 719 720 ADD_SUITE(LockFreeReadPtrPtrHashtable); 721 ADD_SUITE(LotsOfHeapsAndThreads); 720 722 ADD_SUITE(MinHeap); 721 723 ADD_SUITE(PGM);
Note: See TracChangeset
for help on using the changeset viewer.