Changeset 282899 in webkit
- Timestamp:
- Sep 22, 2021 5:52:25 PM (3 years ago)
- Location:
- trunk/Source/bmalloc
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/bmalloc/ChangeLog
r282850 r282899 1 2021-09-22 Filip Pizlo <fpizlo@apple.com> 2 3 [libpas] fix DebugHeap 4 https://bugs.webkit.org/show_bug.cgi?id=230658 5 6 Reviewed by Yusuke Suzuki. 7 8 The previous DebugHeap integration with libpas assumed we didn't have a jit_heap. Now that 9 we have a jit_heap, we need to be able to do DebugHeap from the bmalloc_heap while we still 10 use jit_heap. 11 12 This was tricky, since previously, libpas could just follow bmalloc and say that if TLC is 13 not initialized, then we go slow, and the slow path checks for DebugHeap. Now, we might have 14 a TLC. This means having to push down the debug heap checks into other slow paths. 15 16 * bmalloc/DebugHeap.cpp: 17 (pas_debug_heap_is_enabled): 18 (pas_debug_heap_malloc): 19 (pas_debug_heap_memalign): 20 (pas_debug_heap_realloc): 21 (pas_debug_heap_free): 22 * libpas/src/libpas/bmalloc_heap_config.c: 23 (bmalloc_heap_config_activate): 24 * libpas/src/libpas/jit_heap.c: 25 (jit_heap_add_fresh_memory): 26 (jit_heap_try_allocate): 27 * libpas/src/libpas/jit_heap_config.c: 28 * libpas/src/libpas/pas_deallocate.c: 29 (pas_try_deallocate_slow_no_cache): 30 * libpas/src/libpas/pas_deallocate.h: 31 (pas_try_deallocate_not_small): 32 * libpas/src/libpas/pas_debug_heap.h: 33 (pas_debug_heap_is_enabled): 34 (pas_debug_heap_allocate): 35 * libpas/src/libpas/pas_local_allocator_inlines.h: 36 (pas_local_allocator_try_allocate_small_segregated_slow_impl): 37 (pas_local_allocator_try_allocate_slow_impl): 38 (pas_local_allocator_try_allocate): 39 * libpas/src/libpas/pas_thread_local_cache.c: 40 (allocate_cache): 41 (pas_thread_local_cache_get_local_allocator_if_can_set_cache_slow): 42 * libpas/src/libpas/pas_try_allocate.h: 43 (pas_try_allocate_impl): 44 * libpas/src/libpas/pas_try_allocate_common.h: 45 (pas_try_allocate_common_impl_slow): 46 * libpas/src/libpas/pas_try_allocate_intrinsic_primitive.h: 47 (pas_try_allocate_intrinsic_primitive_impl_medium_slow_case): 48 (pas_try_allocate_intrinsic_primitive_impl_inline_only): 49 * libpas/src/libpas/pas_try_reallocate.h: 50 (pas_try_reallocate): 51 1 52 2021-09-21 Basuke Suzuki <basuke.suzuki@sony.com> 2 53 -
trunk/Source/bmalloc/bmalloc/DebugHeap.cpp
r279867 r282899 186 186 #if BENABLE(LIBPAS) 187 187 188 // FIXME: Currently, we only use libpas for executable allocator. Thus libpas allocator is always enabled even when Malloc=1 is specified. 189 // To make it work, we disable debug heap for libpas completely. We need additional code to enable libpas only for executable allocator when 190 // Malloc=1 is specified when bmalloc is replaced with libpas. 191 192 bool pas_debug_heap_is_enabled(void) 193 { 188 #if BUSE(LIBPAS) 189 190 using namespace bmalloc; 191 192 bool pas_debug_heap_is_enabled(pas_heap_config_kind kind) 193 { 194 switch (kind) { 195 case pas_heap_config_kind_bmalloc: 196 return !!DebugHeap::tryGet(); 197 case pas_heap_config_kind_jit: 198 case pas_heap_config_kind_pas_utility: 199 return false; 200 default: 201 BCRASH(); 202 return false; 203 } 204 } 205 206 void* pas_debug_heap_malloc(size_t size) 207 { 208 return DebugHeap::getExisting()->malloc(size, FailureAction::ReturnNull); 209 } 210 211 void* pas_debug_heap_memalign(size_t alignment, size_t size) 212 { 213 return DebugHeap::getExisting()->memalign(alignment, size, FailureAction::ReturnNull); 214 } 215 216 void* pas_debug_heap_realloc(void* ptr, size_t size) 217 { 218 return DebugHeap::getExisting()->realloc(ptr, size, FailureAction::ReturnNull); 219 } 220 221 void pas_debug_heap_free(void* ptr) 222 { 223 DebugHeap::getExisting()->free(ptr); 224 } 225 226 #else // BUSE(LIBPAS) -> so !BUSE(LIBPAS) 227 228 bool pas_debug_heap_is_enabled(pas_heap_config_kind kind) 229 { 230 BUNUSED_PARAM(kind); 194 231 return false; 195 232 } … … 227 264 #pragma clang diagnostic pop 228 265 266 #endif // BUSE(LIBPAS) -> so end of !BUSE(LIBPAS) 267 229 268 #endif // BENABLE(LIBPAS) 230 269 -
trunk/Source/bmalloc/libpas/src/libpas/bmalloc_heap_config.c
r282556 r282899 46 46 void bmalloc_heap_config_activate(void) 47 47 { 48 // FIXME: Temporarily disable it for now until bmalloc is replaced with libpas. 49 static const bool register_with_libmalloc = false; 48 static const bool register_with_libmalloc = true; 50 49 51 50 pas_designated_intrinsic_heap_initialize(&bmalloc_common_primitive_heap.segregated_heap, 52 51 &bmalloc_heap_config); 53 52 54 if (register_with_libmalloc )53 if (register_with_libmalloc && !pas_debug_heap_is_enabled(pas_heap_config_kind_bmalloc)) 55 54 pas_root_ensure_for_libmalloc_enumeration(); 56 55 } -
trunk/Source/bmalloc/libpas/src/libpas/jit_heap.c
r282556 r282899 51 51 void jit_heap_add_fresh_memory(pas_range range) 52 52 { 53 static const bool verbose = false; 54 55 if (verbose) 56 pas_log("JIT heap at %p...%p\n", (void*)range.begin, (void*)range.end); 57 53 58 pas_heap_lock_lock(); 54 59 jit_heap_config_add_fresh_memory(range); … … 68 73 void* jit_heap_try_allocate(size_t size) 69 74 { 70 return (void*)jit_try_allocate_common_primitive_impl(size, 1).begin; 75 static const bool verbose = false; 76 void* result; 77 if (verbose) 78 pas_log("going to allocate in jit\n"); 79 result = (void*)jit_try_allocate_common_primitive_impl(size, 1).begin; 80 if (verbose) 81 pas_log("done allocating in jit, returning %p\n", result); 82 return result; 71 83 } 72 84 -
trunk/Source/bmalloc/libpas/src/libpas/jit_heap_config.c
r282556 r282899 39 39 #include "pas_root.h" 40 40 41 #if defined(PAS_BMALLOC) 42 #include "BPlatform.h" 43 #endif 44 41 45 pas_heap_config jit_heap_config = JIT_HEAP_CONFIG; 42 46 -
trunk/Source/bmalloc/libpas/src/libpas/pas_deallocate.c
r282556 r282899 99 99 if (verbose) 100 100 pas_log("Trying to deallocate %p.\n", ptr); 101 if (PAS_UNLIKELY(pas_debug_heap_is_enabled( ))) {101 if (PAS_UNLIKELY(pas_debug_heap_is_enabled(config_ptr->kind))) { 102 102 if (verbose) 103 103 pas_log("Deallocating %p with debug heap.\n", ptr); -
trunk/Source/bmalloc/libpas/src/libpas/pas_deallocate.h
r279867 r282899 1 1 /* 2 * Copyright (c) 2019-202 0Apple Inc. All rights reserved.2 * Copyright (c) 2019-2021 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 29 29 #include "pas_bitfit_page_inlines.h" 30 30 #include "pas_deallocation_mode.h" 31 #include "pas_debug_heap.h" 31 32 #include "pas_heap_config.h" 32 33 #include "pas_heap_lock.h" … … 84 85 { 85 86 pas_page_base* page_base; 87 88 if (pas_debug_heap_is_enabled(config.kind)) { 89 pas_debug_heap_free((void*)begin); 90 return true; 91 } 86 92 87 93 page_base = config.page_header_func(begin); -
trunk/Source/bmalloc/libpas/src/libpas/pas_debug_heap.h
r279867 r282899 27 27 #define PAS_DEBUG_HEAP_H 28 28 29 #include "pas_allocation_result.h" 30 #include "pas_heap_config_kind.h" 31 #include "pas_log.h" 29 32 #include "pas_utils.h" 30 33 … … 37 40 38 41 /* The implementations are provided by bmalloc. */ 39 PAS_API extern bool pas_debug_heap_is_enabled( void);42 PAS_API extern bool pas_debug_heap_is_enabled(pas_heap_config_kind kind); 40 43 PAS_API extern void* pas_debug_heap_malloc(size_t size); 41 44 PAS_API extern void* pas_debug_heap_memalign(size_t alignment, size_t size); … … 45 48 #else /* PAS_BMALLOC -> so !PAS_BMALLOC */ 46 49 47 static inline bool pas_debug_heap_is_enabled( void)50 static inline bool pas_debug_heap_is_enabled(pas_heap_config_kind kind) 48 51 { 52 PAS_UNUSED_PARAM(kind); 49 53 return false; 50 54 } … … 81 85 #endif /* PAS_BMALLOC -> so end of !PAS_BMALLOC */ 82 86 87 static inline pas_allocation_result pas_debug_heap_allocate(size_t size, size_t alignment) 88 { 89 static const bool verbose = false; 90 91 pas_allocation_result result; 92 void* raw_result; 93 94 if (alignment > sizeof(void*)) { 95 if (verbose) 96 pas_log("Going down debug memalign path.\n"); 97 raw_result = pas_debug_heap_memalign(alignment, size); 98 } else { 99 if (verbose) 100 pas_log("Going down debug malloc path.\n"); 101 raw_result = pas_debug_heap_malloc(size); 102 } 103 104 if (verbose) 105 pas_log("raw_result = %p\n", raw_result); 106 107 result.did_succeed = !!raw_result; 108 result.begin = (uintptr_t)raw_result; 109 result.zero_mode = pas_zero_mode_may_have_non_zero; 110 111 return result; 112 } 113 83 114 PAS_END_EXTERN_C; 84 115 -
trunk/Source/bmalloc/libpas/src/libpas/pas_local_allocator_inlines.h
r282556 r282899 32 32 #include "pas_bitfit_size_class.h" 33 33 #include "pas_config.h" 34 #include "pas_debug_heap.h" 34 35 #include "pas_epoch.h" 35 36 #include "pas_full_alloc_bits_inlines.h" … … 1490 1491 pas_allocator_counts* counts) 1491 1492 { 1493 PAS_ASSERT(!pas_debug_heap_is_enabled(config.kind)); 1494 1492 1495 for (;;) { 1493 1496 pas_allocation_result result; … … 1614 1617 pas_local_allocator_config_kind_get_string(allocator->config_kind)); 1615 1618 } 1619 1620 PAS_ASSERT(!pas_debug_heap_is_enabled(config.kind)); 1616 1621 1617 1622 for (;;) { … … 1746 1751 } 1747 1752 1753 if (PAS_UNLIKELY(pas_debug_heap_is_enabled(config.kind))) 1754 return pas_debug_heap_allocate(size_thunk(size_thunk_arg), alignment); 1755 1748 1756 if (config.small_segregated_config.base.is_enabled && 1749 1757 allocator->config_kind == pas_local_allocator_config_kind_create_normal( -
trunk/Source/bmalloc/libpas/src/libpas/pas_thread_local_cache.c
r282556 r282899 102 102 pas_thread_local_cache* result; 103 103 104 PAS_ASSERT(!pas_debug_heap_is_enabled());105 106 104 size = pas_thread_local_cache_size_for_allocator_index_capacity(allocator_index_capacity); 107 105 … … 309 307 pas_heap_config* heap_config) 310 308 { 311 if (!pas_thread_local_cache_can_set() || pas_debug_heap_is_enabled( ))309 if (!pas_thread_local_cache_can_set() || pas_debug_heap_is_enabled(heap_config->kind)) 312 310 return pas_local_allocator_result_create_failure(); 313 311 -
trunk/Source/bmalloc/libpas/src/libpas/pas_try_allocate.h
r282556 r282899 61 61 pas_try_allocate_common_slow try_allocate_common_slow) 62 62 { 63 static const bool verbose = false; 64 63 65 pas_heap_type* type; 64 66 size_t type_size; … … 66 68 unsigned allocator_index; 67 69 pas_thread_local_cache* cache; 70 pas_typed_allocation_result result; 68 71 69 72 allocator_index = heap_ref->allocator_index; … … 73 76 cache, 74 77 allocator_index); 78 79 if (verbose) 80 pas_log("Got an allocator.\n"); 81 75 82 if (PAS_LIKELY(allocator.did_succeed)) { 76 83 pas_allocation_result result; … … 91 98 result, type, config.get_type_size(type)); 92 99 } 100 101 if (verbose) 102 pas_log("Did not succeed at getting an allocator.\n"); 93 103 } 94 104 … … 96 106 type_size = config.get_type_size(type); 97 107 98 return pas_typed_allocation_result_create_with_intrinsic_allocation_result( 108 if (verbose) 109 pas_log("Allocating the slow way.\n"); 110 111 result = pas_typed_allocation_result_create_with_intrinsic_allocation_result( 99 112 try_allocate_common_slow(heap_ref, 1, type_size, 1), 100 113 type, type_size); 114 115 if (verbose) 116 pas_log("result.ptr = %p, result.did_succeed = %d\n", result.ptr, result.did_succeed); 117 118 return result; 101 119 } 102 120 -
trunk/Source/bmalloc/libpas/src/libpas/pas_try_allocate_common.h
r282556 r282899 108 108 alignment = PAS_MAX(alignment, config.get_type_alignment(type)); 109 109 110 if (PAS_UNLIKELY(pas_debug_heap_is_enabled())) { 111 void* raw_result; 112 113 if (alignment != 1) { 114 PAS_ASSERT(alignment > 1); 115 raw_result = pas_debug_heap_memalign(alignment, size); 116 } else 117 raw_result = pas_debug_heap_malloc(size); 118 119 if (raw_result) { 120 result.did_succeed = true; 121 result.begin = (uintptr_t)raw_result; 122 } 123 110 if (PAS_UNLIKELY(pas_debug_heap_is_enabled(config.kind))) { 111 if (verbose) 112 pas_log("Debug heap enabled, asking debug heap.\n"); 113 result = pas_debug_heap_allocate(size, alignment); 114 if (verbose) 115 pas_log("Got result.ptr = %p, did_succeed = %d\n", result.begin, result.did_succeed); 124 116 return result; 125 117 } 118 119 if (verbose) 120 pas_log("Not using debug heap.\n"); 126 121 127 122 heap = pas_ensure_heap(heap_ref, heap_ref_kind, config.config_ptr, runtime_config); -
trunk/Source/bmalloc/libpas/src/libpas/pas_try_allocate_intrinsic_primitive.h
r282556 r282899 81 81 PAS_ASSERT(alignment == 1 || !designation_mode); 82 82 83 if (verbose) 84 pas_log("in impl_medium_slow_case for %s\n", pas_heap_config_kind_get_string(config.kind)); 85 83 86 if (!pas_is_power_of_2(alignment)) 84 87 return pas_allocation_result_create_failure(); 88 89 if (PAS_UNLIKELY(pas_debug_heap_is_enabled(config.kind))) 90 return pas_debug_heap_allocate(size, alignment); 91 92 if (verbose) 93 pas_log("not doing debug heap in impl_medium_slow_case for %s\n", pas_heap_config_kind_get_string(config.kind)); 85 94 86 95 /* In the non-memalign case, we can happily handle zero-sized allocations with aligned_size … … 185 194 PAS_ASSERT(alignment == 1 || !designation_mode); 186 195 196 if (verbose) 197 pas_log("in impl_inline_only for %s\n", pas_heap_config_kind_get_string(config.kind)); 198 187 199 if (!pas_is_power_of_2(alignment)) 188 200 return pas_allocation_result_create_failure(); -
trunk/Source/bmalloc/libpas/src/libpas/pas_try_reallocate.h
r282556 r282899 312 312 return allocate_callback(heap, new_count, allocate_callback_arg); 313 313 314 if (PAS_UNLIKELY(pas_debug_heap_is_enabled( ))) {314 if (PAS_UNLIKELY(pas_debug_heap_is_enabled(config.kind))) { 315 315 void* raw_result; 316 316 size_t size;
Note: See TracChangeset
for help on using the changeset viewer.