Gnash  0.8.11dev
jemalloc_gnash.h
Go to the documentation of this file.
1 #ifndef GNASH_JEMALLOC_H
2 #define GNASH_JEMALLOC_H
3 
4 #ifdef HAVE_CONFIG_H
5 # include "gnashconfig.h"
6 #endif
7 
8 /* Compiling for user mode application, not operating system */
9 #define MOZ_MEMORY
10 
11 #ifdef LINUX_HOST
12 #define MOZ_MEMORY_LINUX
13 #endif
14 
15 #ifdef WIN32_HOST
16 #define MOZ_MEMORY_WINDOWS
17 #endif
18 
19 /* OpenBSD and others are excluded here to mimic what Mozilla does. */
20 #if defined(FREEBSD_HOST) || defined(NETBSD_HOST)
21 #define MOZ_MEMORY_BSD
22 #endif
23 
24 #ifdef DARWIN_HOST
25 #define MOZ_MEMORY_DARWIN
26 #endif
27 
28 #ifdef SOLARIS_HOST
29 #define MOZ_MEMORY_SOLARIS
30 #endif
31 
32 #ifdef WINCE_HOST
33 #define MOZ_MEMORY_WINCE
34 #endif
35 
36 #ifdef WINCE6_HOST
37 #define MOZ_MEMORY_WINCE6
38 #endif
39 
40 #ifdef ANDROID_HOST
41 #define MOZ_MEMORY_ANDROID
42 #endif
43 
44 #if SIZEOF_VOID_P == 4
45 # define MOZ_MEMORY_SIZEOF_PTR_2POW 2
46 #elif SIZEOF_VOID_P == 8
47 # define MOZ_MEMORY_SIZEOF_PTR_2POW 3
48 #endif
49 
50 #if 0
51 /* Unfortunately, even though jemalloc has valgrind hooks, it still produces
52  * false positives. See https://bugzilla.mozilla.org/show_bug.cgi?id=503249
53  */
54 #define MOZ_VALGRIND
55 #endif
56 
57 #include "jemalloc.h"
58 
59 #ifdef USE_STATS_MEMORY
60 
61 /* Enable statistics tracking plus API in jemalloc. */
62 #define MALLOC_STATS
63 
64 /* Borrowed from malloc.h, as this is Linux specific. This has been
65  * added to jemalloc so the existing memory profiling in Gnash will
66  * continue to work. Most of these fields aren't used by the Gnash
67  * memory profiling, but we leave them here for a semblance of
68  * portability. The only fields Gnash uses are arena, uordblks. and
69  * fordblks.
70  */
71 struct mallinfo {
72  int arena; /* non-mmapped space allocated from system */
73  int ordblks; /* number of free chunks UNUSED */
74  int smblks; /* number of fastbin blocks UNUSED */
75  int hblks; /* number of mmapped regions UNUSED */
76  int hblkhd; /* space in mmapped regions UNUSED */
77  int usmblks; /* maximum total allocated space UNUSED */
78  int fsmblks; /* space available in freed fastbin blocks UNUSED */
79  int uordblks; /* total allocated space */
80  int fordblks; /* total free space */
81  int keepcost; /* top-most, releasable space UNUSED */
82 };
83 
84 struct mallinfo
85 mallinfo(void)
86 {
87  struct mallinfo mi;
88  jemalloc_stats_t stats;
89 
90  jemalloc_stats(&stats);
91 
92  /* clear unused fields */
93  mi.keepcost = mi.ordblks = mi.smblks = mi.usmblks = mi.fsmblks =
94  mi.hblks = mi.hblkhd = 0;
95 
96  mi.arena = stats.mapped;
97  mi.uordblks = stats.allocated;
98  mi.fordblks = stats.mapped - mi.uordblks;
99 
100  return mi;
101 }
102 
103 #endif /* USE_STATS_MEMORY */
104 
105 #endif /* GNASH_JEMALLOC_H */