Bug 1895153 - Implement "Find in page..." menu functionality r=android-reviewers...
[gecko.git] / memory / build / mozjemalloc_types.h
blob5f8872ff4050166cf65224f6f192334fc0efbe58
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 // Portions of this file were originally under the following license:
8 //
9 // Copyright (C) 2006-2008 Jason Evans <jasone@FreeBSD.org>.
10 // All rights reserved.
12 // Redistribution and use in source and binary forms, with or without
13 // modification, are permitted provided that the following conditions
14 // are met:
15 // 1. Redistributions of source code must retain the above copyright
16 // notice(s), this list of conditions and the following disclaimer as
17 // the first lines of this file unmodified other than the possible
18 // addition of one or more copyright notices.
19 // 2. Redistributions in binary form must reproduce the above copyright
20 // notice(s), this list of conditions and the following disclaimer in
21 // the documentation and/or other materials provided with the
22 // distribution.
24 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
25 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
27 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
28 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
31 // BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
32 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
33 // OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
34 // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 #ifndef _JEMALLOC_TYPES_H_
37 #define _JEMALLOC_TYPES_H_
39 #include <stdint.h>
41 // grab size_t
42 #ifdef _MSC_VER
43 # include <crtdefs.h>
44 #else
45 # include <stddef.h>
46 #endif
47 #include <stdbool.h>
49 #ifdef __cplusplus
50 extern "C" {
51 #endif
53 #ifndef MALLOC_USABLE_SIZE_CONST_PTR
54 # define MALLOC_USABLE_SIZE_CONST_PTR const
55 #endif
57 typedef MALLOC_USABLE_SIZE_CONST_PTR void* usable_ptr_t;
59 typedef size_t arena_id_t;
61 #define ARENA_FLAG_RANDOMIZE_SMALL_MASK 0x3
62 #define ARENA_FLAG_RANDOMIZE_SMALL_DEFAULT 0
63 #define ARENA_FLAG_RANDOMIZE_SMALL_ENABLED 1
64 #define ARENA_FLAG_RANDOMIZE_SMALL_DISABLED 2
66 // Arenas are usually protected by a lock (ARENA_FLAG_THREAD_SAFE) however some
67 // arenas are accessed by only the main thread
68 // (ARENA_FLAG_THREAD_MAIN_THREAD_ONLY) and their locking can be skipped.
69 #define ARENA_FLAG_THREAD_MASK 0x4
70 #define ARENA_FLAG_THREAD_MAIN_THREAD_ONLY 0x4
71 #define ARENA_FLAG_THREAD_SAFE 0x0
73 typedef struct arena_params_s {
74 size_t mMaxDirty;
75 // Arena specific modifiers which override the value passed to
76 // moz_set_max_dirty_page_modifier. If value > 0 is passed to that function,
77 // and mMaxDirtyIncreaseOverride != 0, mMaxDirtyIncreaseOverride will be used
78 // instead, and similarly if value < 0 is passed and mMaxDirtyDecreaseOverride
79 // != 0, mMaxDirtyDecreaseOverride will be used as the modifier.
80 int32_t mMaxDirtyIncreaseOverride;
81 int32_t mMaxDirtyDecreaseOverride;
83 uint32_t mFlags;
85 #ifdef __cplusplus
86 arena_params_s()
87 : mMaxDirty(0),
88 mMaxDirtyIncreaseOverride(0),
89 mMaxDirtyDecreaseOverride(0),
90 mFlags(0) {}
91 #endif
92 } arena_params_t;
94 // jemalloc_stats() is not a stable interface. When using jemalloc_stats_t, be
95 // sure that the compiled results of jemalloc.c are in sync with this header
96 // file.
97 typedef struct {
98 // Run-time configuration settings.
99 bool opt_junk; // Fill allocated memory with kAllocJunk?
100 bool opt_zero; // Fill allocated memory with 0x0?
101 size_t narenas; // Number of arenas.
102 size_t quantum; // Allocation quantum.
103 size_t quantum_max; // Max quantum-spaced allocation size.
104 size_t quantum_wide; // Allocation quantum (QuantuWide).
105 size_t quantum_wide_max; // Max quantum-wide-spaced allocation size.
106 size_t subpage_max; // Max subpage allocation size.
107 size_t large_max; // Max sub-chunksize allocation size.
108 size_t chunksize; // Size of each virtual memory mapping.
109 size_t page_size; // Size of pages.
110 size_t dirty_max; // Max dirty pages per arena.
112 // Current memory usage statistics.
113 size_t mapped; // Bytes mapped (not necessarily committed).
114 size_t allocated; // Bytes allocated (committed, in use by application).
115 size_t waste; // Bytes committed, not in use by the
116 // application, and not intentionally left
117 // unused (i.e., not dirty).
118 size_t pages_dirty; // Committed, unused pages kept around as a cache.
119 size_t pages_fresh; // Unused pages that have never been touched.
120 size_t pages_madvised; // Unsed pages we told the kernel we don't need.
121 size_t bookkeeping; // Committed bytes used internally by the
122 // allocator.
123 size_t bin_unused; // Bytes committed to a bin but currently unused.
124 } jemalloc_stats_t;
126 typedef struct {
127 size_t size; // The size of objects in this bin, zero if this
128 // bin stats array entry is unused (no more bins).
129 size_t num_non_full_runs; // The number of non-full runs
130 size_t num_runs; // The number of runs in this bin
131 size_t bytes_unused; // The unallocated bytes across all these bins
132 size_t bytes_total; // The total storage area for runs in this bin,
133 size_t bytes_per_run; // The number of bytes per run, including headers.
134 } jemalloc_bin_stats_t;
136 enum PtrInfoTag {
137 // The pointer is not currently known to the allocator.
138 // 'addr', 'size', and 'arenaId' are always 0.
139 TagUnknown,
141 // The pointer is within a live allocation.
142 // 'addr', 'size', and 'arenaId' describe the allocation.
143 TagLiveAlloc,
145 // The pointer is within a small freed allocation.
146 // 'addr', 'size', and 'arenaId' describe the allocation.
147 TagFreedAlloc,
149 // The pointer is within a freed page. Details about the original
150 // allocation, including its size, are not available.
151 // 'addr', 'size', and 'arenaId' describe the page.
152 TagFreedPage,
155 // The information in jemalloc_ptr_info_t could be represented in a variety of
156 // ways. The chosen representation has the following properties.
157 // - The number of fields is minimized.
158 // - The 'tag' field unambiguously defines the meaning of the subsequent fields.
159 // Helper functions are used to group together related categories of tags.
160 typedef struct jemalloc_ptr_info_s {
161 enum PtrInfoTag tag;
162 void* addr; // meaning depends on tag; see above
163 size_t size; // meaning depends on tag; see above
165 #ifdef MOZ_DEBUG
166 arena_id_t arenaId; // meaning depends on tag; see above
167 #endif
169 #ifdef __cplusplus
170 jemalloc_ptr_info_s() = default;
171 jemalloc_ptr_info_s(enum PtrInfoTag aTag, void* aAddr, size_t aSize,
172 arena_id_t aArenaId)
173 : tag(aTag),
174 addr(aAddr),
175 size(aSize)
176 # ifdef MOZ_DEBUG
178 arenaId(aArenaId)
179 # endif
182 #endif
183 } jemalloc_ptr_info_t;
185 static inline bool jemalloc_ptr_is_live(jemalloc_ptr_info_t* info) {
186 return info->tag == TagLiveAlloc;
189 static inline bool jemalloc_ptr_is_freed(jemalloc_ptr_info_t* info) {
190 return info->tag == TagFreedAlloc || info->tag == TagFreedPage;
193 static inline bool jemalloc_ptr_is_freed_page(jemalloc_ptr_info_t* info) {
194 return info->tag == TagFreedPage;
197 #ifdef __cplusplus
198 } // extern "C"
199 #endif
201 #endif // _JEMALLOC_TYPES_H_