Skip to content

Commit

Permalink
[JSC] Add more profiling macro invocations to libPAS
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=269528
rdar://122974187

Reviewed by Justin Michaud and Yusuke Suzuki.

Adds PAS_PROFILE invocations to more places throughout libPAS,
and standardizes the PAS_PROFILE interface - a discriminator is
expected in the first parameter (like the similar BPROFILE_ALLOCATION
macro in bmalloc), followed by any number of arguments that are
expected to be uintptr_t lvalues.

* Source/bmalloc/libpas/src/libpas/pas_allocation_result.c:
(pas_allocation_result_zero_large_slow):
* Source/bmalloc/libpas/src/libpas/pas_allocation_result.h:
(pas_allocation_result_zero):
* Source/bmalloc/libpas/src/libpas/pas_deallocate.c:
(pas_try_deallocate_known_large):
* Source/bmalloc/libpas/src/libpas/pas_deallocate.h:
(pas_try_deallocate):
* Source/bmalloc/libpas/src/libpas/pas_fast_megapage_table.h:
(pas_fast_megapage_table_get):
* Source/bmalloc/libpas/src/libpas/pas_free_granules.c:
(pas_free_granules_compute_and_mark_decommitted):
* Source/bmalloc/libpas/src/libpas/pas_heap.c:
(pas_heap_create):
* Source/bmalloc/libpas/src/libpas/pas_large_map.c:
(pas_large_map_find):
(pas_large_map_add):
(pas_large_map_take):
* Source/bmalloc/libpas/src/libpas/pas_page_base_config_utils.h:
* Source/bmalloc/libpas/src/libpas/pas_page_base_config_utils_inlines.h:
* Source/bmalloc/libpas/src/libpas/pas_page_malloc.c:
(pas_page_malloc_try_allocate_without_deallocating_padding):
(pas_page_malloc_deallocate):
* Source/bmalloc/libpas/src/libpas/pas_try_reallocate.h:
(pas_try_reallocate):
* Source/bmalloc/libpas/src/libpas/pas_utils.h:
(pas_zero_memory):

Canonical link: https://commits.webkit.org/274843@main
  • Loading branch information
ddegazio committed Feb 16, 2024
1 parent f76e442 commit f2c960f
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 9 deletions.
2 changes: 2 additions & 0 deletions Source/bmalloc/libpas/src/libpas/pas_allocation_result.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ pas_allocation_result pas_allocation_result_zero_large_slow(pas_allocation_resul
{
size_t page_size;

PAS_PROFILE(ZERO_ALLOCATION_RESULT, result.begin);

page_size = pas_page_malloc_alignment();
if (pas_is_aligned(size, page_size) && pas_is_aligned(result.begin, page_size))
pas_page_malloc_zero_fill((void*)result.begin, size);
Expand Down
5 changes: 4 additions & 1 deletion Source/bmalloc/libpas/src/libpas/pas_allocation_result.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ pas_allocation_result_zero(pas_allocation_result result,
if (size >= (1ULL << PAS_VA_BASED_ZERO_MEMORY_SHIFT))
return pas_allocation_result_zero_large_slow(result, size);

pas_zero_memory((void*)result.begin, size);
PAS_PROFILE(ZERO_ALLOCATION_RESULT, result.begin);
void* memory = (void*)result.begin;
pas_zero_memory(memory, size);

return pas_allocation_result_create_success_with_zero_mode(result.begin, pas_zero_mode_is_all_zero);
}

Expand Down
1 change: 1 addition & 0 deletions Source/bmalloc/libpas/src/libpas/pas_deallocate.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ bool pas_try_deallocate_known_large(void* ptr,
uintptr_t begin;

begin = (uintptr_t)ptr;
PAS_PROFILE(TRY_DEALLOCATE_KNOWN_LARGE, begin);

pas_heap_lock_lock();

Expand Down
8 changes: 6 additions & 2 deletions Source/bmalloc/libpas/src/libpas/pas_deallocate.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,13 @@ static PAS_ALWAYS_INLINE bool pas_try_deallocate(void* ptr,
pas_deallocation_mode deallocation_mode)
{
static const bool verbose = false;

PAS_PROFILE(ptr, TRY_DEALLOCATE);

pas_thread_local_cache* thread_local_cache;
uintptr_t begin;

begin = (uintptr_t)ptr;
PAS_PROFILE(TRY_DEALLOCATE, begin);
ptr = (void*)begin;

if (verbose)
pas_log("try_deallocate for %p\n", ptr);
Expand Down
1 change: 1 addition & 0 deletions Source/bmalloc/libpas/src/libpas/pas_fast_megapage_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ static inline pas_fast_megapage_kind pas_fast_megapage_table_get(
pas_fast_megapage_table* table,
uintptr_t begin)
{
PAS_PROFILE(MEGAPAGE_GET, begin);
return pas_fast_megapage_table_get_by_index(table, begin >> PAS_FAST_MEGAPAGE_SHIFT);
}

Expand Down
5 changes: 5 additions & 0 deletions Source/bmalloc/libpas/src/libpas/pas_free_granules.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,15 @@ void pas_free_granules_compute_and_mark_decommitted(pas_free_granules* free_gran
static const bool verbose = false;

size_t granule_index;
uintptr_t granule_begin;

PAS_ASSERT(num_granules >= 2); /* If there is only one granule then we don't have use counts. */
PAS_ASSERT(num_granules <= PAS_MAX_GRANULES);

granule_begin = (uintptr_t)free_granules;
PAS_PROFILE(ZERO_FREE_GRANULES, granule_begin);
free_granules = (pas_free_granules*)granule_begin;

pas_zero_memory(free_granules, sizeof(pas_free_granules));

for (granule_index = num_granules; granule_index--;) {
Expand Down
6 changes: 6 additions & 0 deletions Source/bmalloc/libpas/src/libpas/pas_heap.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ pas_heap* pas_heap_create(pas_heap_ref* heap_ref,
{
static const bool verbose = false;
pas_heap* heap;
uintptr_t begin;

if (verbose) {
pas_log("Creating heap for size = %lu, alignment = %lu.\n",
Expand All @@ -61,6 +62,11 @@ pas_heap* pas_heap_create(pas_heap_ref* heap_ref,
config->get_type_alignment(heap_ref->type)));

heap = pas_immortal_heap_allocate(sizeof(pas_heap), "pas_heap", pas_object_allocation);

begin = (uintptr_t)heap;
PAS_PROFILE(CREATE_HEAP, begin);
heap = (void*)begin;

pas_zero_memory(heap, sizeof(pas_heap));
heap->type = heap_ref->type;
pas_segregated_heap_construct(
Expand Down
6 changes: 6 additions & 0 deletions Source/bmalloc/libpas/src/libpas/pas_large_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ pas_tiny_large_map_second_level_hashtable_in_flux_stash pas_tiny_large_map_secon

pas_large_map_entry pas_large_map_find(uintptr_t begin)
{
PAS_PROFILE(LARGE_MAP_FIND, begin);

uintptr_t tiny_base;
pas_first_level_tiny_large_map_entry* first_level_tiny_entry;
pas_small_large_map_entry* small_entry;
Expand Down Expand Up @@ -76,6 +78,8 @@ void pas_large_map_add(pas_large_map_entry entry)

pas_heap_lock_assert_held();

PAS_PROFILE(LARGE_MAP_ADD, entry.begin, entry.end);

if (verbose)
pas_log("adding %p...%p, heap = %p.\n", (void*)entry.begin, (void*)entry.end, entry.heap);

Expand Down Expand Up @@ -152,6 +156,8 @@ pas_large_map_entry pas_large_map_take(uintptr_t begin)
pas_first_level_tiny_large_map_entry* first_level_tiny_entry;
pas_small_large_map_entry small_entry;

PAS_PROFILE(LARGE_MAP_TAKE, begin);

pas_heap_lock_assert_held();

if (verbose)
Expand Down
5 changes: 3 additions & 2 deletions Source/bmalloc/libpas/src/libpas/pas_page_base_config_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ typedef struct {
\
switch (arguments.header_placement_mode) { \
case pas_page_header_at_head_of_page: { \
PAS_PROFILE(boundary, PAGE_HEADER); \
return (pas_page_base*)boundary; \
uintptr_t ptr = (uintptr_t)boundary; \
PAS_PROFILE(PAGE_HEADER, ptr); \
return (pas_page_base*)ptr; \
} \
\
case pas_page_header_in_table: { \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ typedef struct {
\
switch (name ## _header_placement_mode) { \
case pas_page_header_at_head_of_page: { \
PAS_PROFILE(boundary, PAGE_HEADER); \
return (pas_page_base*)boundary; \
uintptr_t ptr = (uintptr_t)boundary; \
PAS_PROFILE(PAGE_HEADER, ptr); \
return (pas_page_base*)ptr; \
} \
\
case pas_page_header_in_table: { \
Expand Down
6 changes: 6 additions & 0 deletions Source/bmalloc/libpas/src/libpas/pas_page_malloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ pas_page_malloc_try_allocate_without_deallocating_padding(
do that explicitly. */
return result;
}

uintptr_t pages_begin = (uintptr_t)mmap_result;
PAS_PROFILE(PAGE_ALLOCATION, pages_begin);
mmap_result = (void*)pages_begin;

mapped = (char*)mmap_result;
mapped_end = mapped + mapped_size;
Expand Down Expand Up @@ -287,8 +291,10 @@ void pas_page_malloc_deallocate(void* ptr, size_t size)
uintptr_t ptr_as_int;

ptr_as_int = (uintptr_t)ptr;
PAS_PROFILE(PAGE_DEALLOCATION, ptr_as_int);
PAS_ASSERT(pas_is_aligned(ptr_as_int, pas_page_malloc_alignment()));
PAS_ASSERT(pas_is_aligned(size, pas_page_malloc_alignment()));
ptr = (void*)ptr_as_int;

if (!size)
return;
Expand Down
3 changes: 2 additions & 1 deletion Source/bmalloc/libpas/src/libpas/pas_try_reallocate.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,9 @@ pas_try_reallocate(void* old_ptr,
void* allocate_callback_arg)
{
uintptr_t begin;
PAS_PROFILE(old_ptr, REALLOCATE);
begin = (uintptr_t)old_ptr;
PAS_PROFILE(TRY_REALLOCATE, begin);
old_ptr = (void*)begin;

switch (config.fast_megapage_kind_func(begin)) {
case pas_small_exclusive_segregated_fast_megapage_kind: {
Expand Down
1 change: 0 additions & 1 deletion Source/bmalloc/libpas/src/libpas/pas_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ PAS_BEGIN_EXTERN_C;

static PAS_ALWAYS_INLINE void pas_zero_memory(void* memory, size_t size)
{
PAS_PROFILE(memory, ZERO_MEMORY);
memset(memory, 0, size);
}

Expand Down

0 comments on commit f2c960f

Please sign in to comment.