Skip to content

Commit a731ec9

Browse files
Support malloc-zone for non-Darwin OS for debug heap breakdown
Darwin OS allows using malloc-zone for heap breakdown for finer granularity. The changes allow use of malloc-zone via a library implementing the required interface for non-Darwin platforms. Original author: Andrzej Surdej <Andrzej_Surdej@comcast.com>
1 parent 23491c2 commit a731ec9

8 files changed

Lines changed: 30 additions & 8 deletions

File tree

Source/WTF/wtf/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,10 @@ if (NOT USE_SYSTEM_MALLOC)
742742
set(WTF_FRAMEWORKS bmalloc)
743743
endif ()
744744

745+
if (ENABLE_MALLOC_HEAP_BREAKDOWN)
746+
list(APPEND WTF_LIBRARIES ${MALLOC_ZONE_LIBRARIES})
747+
endif ()
748+
745749
if (ATOMICS_REQUIRE_LIBATOMIC)
746750
list(APPEND WTF_LIBRARIES atomic)
747751
endif ()

Source/WTF/wtf/DebugHeap.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,8 @@
3030

3131
#if ENABLE(MALLOC_HEAP_BREAKDOWN)
3232
#include <mutex>
33-
#if OS(DARWIN)
3433
#include <malloc/malloc.h>
3534
#endif
36-
#endif
3735

3836
namespace WTF {
3937

@@ -53,9 +51,7 @@ class DebugHeap {
5351
WTF_EXPORT_PRIVATE void free(void*);
5452

5553
private:
56-
#if OS(DARWIN)
5754
malloc_zone_t* m_zone;
58-
#endif
5955
};
6056

6157
#define DECLARE_ALLOCATOR_WITH_HEAP_IDENTIFIER_AND_EXPORT(Type, Export) \

Source/bmalloc/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,12 @@ set(bmalloc_LIBRARIES
678678
${CMAKE_DL_LIBS}
679679
)
680680

681+
if (ENABLE_MALLOC_HEAP_BREAKDOWN)
682+
list(APPEND bmalloc_LIBRARIES
683+
${MALLOC_ZONE_LIBRARIES}
684+
)
685+
endif ()
686+
681687
if (ATOMICS_REQUIRE_LIBATOMIC)
682688
list(APPEND bmalloc_LIBRARIES atomic)
683689
endif ()

Source/bmalloc/bmalloc/BPlatform.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,9 @@
331331
#endif
332332

333333
/* Enable this to put each IsoHeap and other allocation categories into their own malloc heaps, so that tools like vmmap can show how big each heap is. */
334+
#if !defined(BENABLE_MALLOC_HEAP_BREAKDOWN)
334335
#define BENABLE_MALLOC_HEAP_BREAKDOWN 0
336+
#endif
335337

336338
/* This is used for debugging when hacking on how bmalloc calculates its physical footprint. */
337339
#define ENABLE_PHYSICAL_PAGE_MAP 0

Source/bmalloc/bmalloc/DebugHeap.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ DebugHeap* debugHeapCache { nullptr };
4242

4343
DEFINE_STATIC_PER_PROCESS_STORAGE(DebugHeap);
4444

45-
#if BOS(DARWIN)
45+
#if BENABLE_MALLOC_HEAP_BREAKDOWN
4646

4747
static bool shouldUseDefaultMallocZone()
4848
{

Source/bmalloc/bmalloc/DebugHeap.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#include <mutex>
3333
#include <unordered_map>
3434

35-
#if BOS(DARWIN)
35+
#if BENABLE_MALLOC_HEAP_BREAKDOWN
3636
#include <malloc/malloc.h>
3737
#endif
3838

@@ -67,7 +67,7 @@ class DebugHeap : private StaticPerProcess<DebugHeap> {
6767
private:
6868
static DebugHeap* tryGetSlow();
6969

70-
#if BOS(DARWIN)
70+
#if BENABLE_MALLOC_HEAP_BREAKDOWN
7171
malloc_zone_t* m_zone;
7272
#endif
7373

Source/bmalloc/bmalloc/IsoTLSInlines.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
#if !BUSE(LIBPAS)
3535

36-
#if BOS(DARWIN)
36+
#if BENABLE_MALLOC_HEAP_BREAKDOWN
3737
#include <malloc/malloc.h>
3838
#endif
3939

Source/cmake/OptionsWPE.cmake

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ WEBKIT_OPTION_DEFINE(ENABLE_JSC_RESTRICTED_OPTIONS_BY_DEFAULT "Whether to enable
116116
WEBKIT_OPTION_DEFINE(USE_FLITE "Whether to use Flite library for SpeechSynthesis" PRIVATE ${ENABLE_EXPERIMENTAL_FEATURES})
117117
WEBKIT_OPTION_DEFINE(USE_TTS_CLIENT "Whether to use TTSClient API for SpeechSynthesis" PRIVATE OFF)
118118

119+
# Debug memory heap breakdown with malloc-zone allocator
120+
WEBKIT_OPTION_DEFINE(ENABLE_MALLOC_HEAP_BREAKDOWN "Whether to enable malloc heap breakdown" PRIVATE OFF)
121+
119122
WEBKIT_OPTION_CONFLICT(ENABLE_WPE_PLATFORM ENABLE_WPE_1_1_API)
120123

121124
WEBKIT_OPTION_DEPEND(ENABLE_DOCUMENTATION ENABLE_INTROSPECTION)
@@ -484,5 +487,16 @@ EXPOSE_STRING_VARIABLE_TO_BUILD(WPE_WEB_PROCESS_EXTENSION_PC_MODULE)
484487
set(WPEWebProcessExtension_PKGCONFIG_FILE ${CMAKE_BINARY_DIR}/${WPE_WEB_PROCESS_EXTENSION_PC_MODULE}.pc)
485488
set(WPEWebProcessExtension_Uninstalled_PKGCONFIG_FILE ${CMAKE_BINARY_DIR}/${WPE_WEB_PROCESS_EXTENSION_PC_MODULE}-uninstalled.pc)
486489

490+
if (ENABLE_MALLOC_HEAP_BREAKDOWN)
491+
# Use same heap breakdown setting for bmalloc
492+
add_definitions(-DBENABLE_MALLOC_HEAP_BREAKDOWN=1)
493+
494+
# Darwin OS has support for malloc zones without additional libraries. On non Darwin OS
495+
# targets, the library needs to be provided if heap breakdown is enabled
496+
if (NOT CMAKE_SYSTEM_NAME MATCHES "Darwin")
497+
set(MALLOC_ZONE_LIBRARIES malloc-zone)
498+
endif()
499+
endif()
500+
487501
include(BubblewrapSandboxChecks)
488502
include(GStreamerChecks)

0 commit comments

Comments
 (0)