Skip to content

Commit a710083

Browse files
authored
Merge pull request #1553 from filipe-norte-red/wpe-2.46-malloc-zone-heap-breakdown
[wpe-2.46] Support malloc-zone for non-Darwin OS for debug heap breakdown
2 parents 2dad30b + a731ec9 commit a710083

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
@@ -117,6 +117,9 @@ WEBKIT_OPTION_DEFINE(ENABLE_JSC_RESTRICTED_OPTIONS_BY_DEFAULT "Whether to enable
117117
WEBKIT_OPTION_DEFINE(USE_FLITE "Whether to use Flite library for SpeechSynthesis" PRIVATE ${ENABLE_EXPERIMENTAL_FEATURES})
118118
WEBKIT_OPTION_DEFINE(USE_TTS_CLIENT "Whether to use TTSClient API for SpeechSynthesis" PRIVATE OFF)
119119

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

122125
WEBKIT_OPTION_DEPEND(ENABLE_DOCUMENTATION ENABLE_INTROSPECTION)
@@ -485,5 +488,16 @@ EXPOSE_STRING_VARIABLE_TO_BUILD(WPE_WEB_PROCESS_EXTENSION_PC_MODULE)
485488
set(WPEWebProcessExtension_PKGCONFIG_FILE ${CMAKE_BINARY_DIR}/${WPE_WEB_PROCESS_EXTENSION_PC_MODULE}.pc)
486489
set(WPEWebProcessExtension_Uninstalled_PKGCONFIG_FILE ${CMAKE_BINARY_DIR}/${WPE_WEB_PROCESS_EXTENSION_PC_MODULE}-uninstalled.pc)
487490

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

0 commit comments

Comments
 (0)