LCOV - code coverage report
Current view: top level - memory/build - mozmemory.h (source / functions) Hit Total Coverage
Test: output.info Lines: 3 4 75.0 %
Date: 2017-07-14 16:53:18 Functions: 1 1 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* This Source Code Form is subject to the terms of the Mozilla Public
       2             :  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
       3             :  * You can obtain one at http://mozilla.org/MPL/2.0/. */
       4             : 
       5             : #ifndef mozmemory_h
       6             : #define mozmemory_h
       7             : 
       8             : /*
       9             :  * This header is meant to be used when the following functions are
      10             :  * necessary:
      11             :  *   - malloc_good_size (used to be called je_malloc_usable_in_advance)
      12             :  *   - jemalloc_stats
      13             :  *   - jemalloc_purge_freed_pages
      14             :  *   - jemalloc_free_dirty_pages
      15             :  *   - jemalloc_thread_local_arena
      16             :  */
      17             : 
      18             : #ifndef MOZ_MEMORY
      19             : #  error Should not include mozmemory.h when MOZ_MEMORY is not set
      20             : #endif
      21             : 
      22             : #include "mozmemory_wrap.h"
      23             : #include "mozilla/Attributes.h"
      24             : #include "mozilla/Types.h"
      25             : #include "mozjemalloc_types.h"
      26             : 
      27             : /*
      28             :  * On OSX, malloc/malloc.h contains the declaration for malloc_good_size,
      29             :  * which will call back in jemalloc, through the zone allocator so just use it.
      30             :  */
      31             : #ifdef XP_DARWIN
      32             : #  include <malloc/malloc.h>
      33             : #else
      34             : MOZ_MEMORY_API size_t malloc_good_size_impl(size_t size);
      35             : 
      36             : /* Note: the MOZ_GLUE_IN_PROGRAM ifdef below is there to avoid -Werror turning
      37             :  * the protective if into errors. MOZ_GLUE_IN_PROGRAM is what triggers MFBT_API
      38             :  * to use weak imports. */
      39             : 
      40        8846 : static inline size_t _malloc_good_size(size_t size) {
      41             : #  if defined(MOZ_GLUE_IN_PROGRAM) && !defined(IMPL_MFBT)
      42        8846 :   if (!malloc_good_size)
      43           0 :     return size;
      44             : #  endif
      45        8846 :   return malloc_good_size_impl(size);
      46             : }
      47             : 
      48             : #  define malloc_good_size _malloc_good_size
      49             : #endif
      50             : 
      51             : MOZ_JEMALLOC_API void jemalloc_stats(jemalloc_stats_t *stats);
      52             : 
      53             : /*
      54             :  * On some operating systems (Mac), we use madvise(MADV_FREE) to hand pages
      55             :  * back to the operating system.  On Mac, the operating system doesn't take
      56             :  * this memory back immediately; instead, the OS takes it back only when the
      57             :  * machine is running out of physical memory.
      58             :  *
      59             :  * This is great from the standpoint of efficiency, but it makes measuring our
      60             :  * actual RSS difficult, because pages which we've MADV_FREE'd shouldn't count
      61             :  * against our RSS.
      62             :  *
      63             :  * This function explicitly purges any MADV_FREE'd pages from physical memory,
      64             :  * causing our reported RSS match the amount of memory we're actually using.
      65             :  *
      66             :  * Note that this call is expensive in two ways.  First, it may be slow to
      67             :  * execute, because it may make a number of slow syscalls to free memory.  This
      68             :  * function holds the big jemalloc locks, so basically all threads are blocked
      69             :  * while this function runs.
      70             :  *
      71             :  * This function is also expensive in that the next time we go to access a page
      72             :  * which we've just explicitly decommitted, the operating system has to attach
      73             :  * to it a physical page!  If we hadn't run this function, the OS would have
      74             :  * less work to do.
      75             :  *
      76             :  * If MALLOC_DOUBLE_PURGE is not defined, this function does nothing.
      77             :  */
      78             : MOZ_JEMALLOC_API void jemalloc_purge_freed_pages();
      79             : 
      80             : /*
      81             :  * Free all unused dirty pages in all arenas. Calling this function will slow
      82             :  * down subsequent allocations so it is recommended to use it only when
      83             :  * memory needs to be reclaimed at all costs (see bug 805855). This function
      84             :  * provides functionality similar to mallctl("arenas.purge") in jemalloc 3.
      85             :  */
      86             : MOZ_JEMALLOC_API void jemalloc_free_dirty_pages();
      87             : 
      88             : MOZ_JEMALLOC_API void jemalloc_thread_local_arena(jemalloc_bool enabled);
      89             : 
      90             : #endif /* mozmemory_h */

Generated by: LCOV version 1.13