blob: 2feb28a7786a0f6d18fe1af49c8925a7d1d2bd60 [file] [log] [blame]
buzbee862a7602013-04-05 10:58:54 -07001/*
2 * Copyright (C) 2013 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Mathieu Chartierb666f482015-02-18 14:33:14 -080017#ifndef ART_RUNTIME_BASE_ARENA_ALLOCATOR_H_
18#define ART_RUNTIME_BASE_ARENA_ALLOCATOR_H_
buzbee862a7602013-04-05 10:58:54 -070019
20#include <stdint.h>
21#include <stddef.h>
Mathieu Chartierf6c4b3b2013-08-24 16:11:37 -070022
Vladimir Marko80afd022015-05-19 18:08:00 +010023#include "base/bit_utils.h"
Vladimir Marko2a408a32015-09-18 14:11:00 +010024#include "base/memory_tool.h"
Mathieu Chartierb666f482015-02-18 14:33:14 -080025#include "debug_stack.h"
26#include "macros.h"
Mathieu Chartierb666f482015-02-18 14:33:14 -080027#include "mutex.h"
buzbee862a7602013-04-05 10:58:54 -070028
29namespace art {
30
Mathieu Chartierf6c4b3b2013-08-24 16:11:37 -070031class Arena;
32class ArenaPool;
33class ArenaAllocator;
Vladimir Marko83cc7ae2014-02-12 18:02:05 +000034class ArenaStack;
35class ScopedArenaAllocator;
Vladimir Marko3481ba22015-04-13 12:22:36 +010036class MemMap;
Vladimir Marko83cc7ae2014-02-12 18:02:05 +000037class MemStats;
38
Vladimir Marko8081d2b2014-07-31 15:33:43 +010039template <typename T>
40class ArenaAllocatorAdapter;
41
Vladimir Marko83cc7ae2014-02-12 18:02:05 +000042static constexpr bool kArenaAllocatorCountAllocations = false;
43
44// Type of allocation for memory tuning.
45enum ArenaAllocKind {
46 kArenaAllocMisc,
Vladimir Markoe39c54e2014-09-22 14:50:02 +010047 kArenaAllocSwitchTable,
Vladimir Markoe39c54e2014-09-22 14:50:02 +010048 kArenaAllocSlowPaths,
Vladimir Marko83cc7ae2014-02-12 18:02:05 +000049 kArenaAllocGrowableBitMap,
Vladimir Marko83cc7ae2014-02-12 18:02:05 +000050 kArenaAllocSTL,
Vladimir Marko2aaa4b52015-09-17 17:03:26 +010051 kArenaAllocGraphBuilder,
Vladimir Markof9f64412015-09-02 14:05:49 +010052 kArenaAllocGraph,
53 kArenaAllocBasicBlock,
Vladimir Markofa6b93c2015-09-15 10:15:55 +010054 kArenaAllocBlockList,
55 kArenaAllocReversePostOrder,
56 kArenaAllocLinearOrder,
57 kArenaAllocConstantsMap,
Vladimir Marko60584552015-09-03 13:35:12 +000058 kArenaAllocPredecessors,
59 kArenaAllocSuccessors,
60 kArenaAllocDominated,
Vladimir Markof9f64412015-09-02 14:05:49 +010061 kArenaAllocInstruction,
Vladimir Markofa6b93c2015-09-15 10:15:55 +010062 kArenaAllocInvokeInputs,
63 kArenaAllocPhiInputs,
Vladimir Markof9f64412015-09-02 14:05:49 +010064 kArenaAllocLoopInfo,
Vladimir Markofa6b93c2015-09-15 10:15:55 +010065 kArenaAllocLoopInfoBackEdges,
Vladimir Markof9f64412015-09-02 14:05:49 +010066 kArenaAllocTryCatchInfo,
67 kArenaAllocUseListNode,
68 kArenaAllocEnvironment,
Vladimir Markofa6b93c2015-09-15 10:15:55 +010069 kArenaAllocEnvironmentVRegs,
70 kArenaAllocEnvironmentLocations,
Vladimir Marko2aaa4b52015-09-17 17:03:26 +010071 kArenaAllocLocationSummary,
Vladimir Marko71bf8092015-09-15 15:33:14 +010072 kArenaAllocSsaBuilder,
Vladimir Markof9f64412015-09-02 14:05:49 +010073 kArenaAllocMoveOperands,
74 kArenaAllocCodeBuffer,
75 kArenaAllocStackMaps,
Vladimir Markof9f64412015-09-02 14:05:49 +010076 kArenaAllocOptimization,
Vladimir Marko2aaa4b52015-09-17 17:03:26 +010077 kArenaAllocGvn,
Vladimir Marko5233f932015-09-29 19:01:15 +010078 kArenaAllocInductionVarAnalysis,
79 kArenaAllocBoundsCheckElimination,
Vladimir Markof6a35de2016-03-21 12:01:50 +000080 kArenaAllocDCE,
81 kArenaAllocLSE,
82 kArenaAllocLICM,
Aart Bik96202302016-10-04 17:33:56 -070083 kArenaAllocLoopOptimization,
Vladimir Marko2aaa4b52015-09-17 17:03:26 +010084 kArenaAllocSsaLiveness,
85 kArenaAllocSsaPhiElimination,
86 kArenaAllocReferenceTypePropagation,
Vladimir Marko2aaa4b52015-09-17 17:03:26 +010087 kArenaAllocSideEffectsAnalysis,
88 kArenaAllocRegisterAllocator,
Vladimir Markof6a35de2016-03-21 12:01:50 +000089 kArenaAllocRegisterAllocatorValidate,
Vladimir Marko225b6462015-09-28 12:17:40 +010090 kArenaAllocStackMapStream,
91 kArenaAllocCodeGenerator,
Vladimir Marko93205e32016-04-13 11:59:46 +010092 kArenaAllocAssembler,
Vladimir Marko225b6462015-09-28 12:17:40 +010093 kArenaAllocParallelMoveResolver,
Vladimir Marko655e5852015-10-12 10:38:28 +010094 kArenaAllocGraphChecker,
Mathieu Chartierde40d472015-10-15 17:47:48 -070095 kArenaAllocVerifier,
Vladimir Marko93205e32016-04-13 11:59:46 +010096 kArenaAllocCallingConvention,
Mingyao Yang063fc772016-08-02 11:02:54 -070097 kArenaAllocCHA,
Vladimir Marko83cc7ae2014-02-12 18:02:05 +000098 kNumArenaAllocKinds
99};
100
101template <bool kCount>
102class ArenaAllocatorStatsImpl;
103
104template <>
105class ArenaAllocatorStatsImpl<false> {
106 public:
107 ArenaAllocatorStatsImpl() = default;
108 ArenaAllocatorStatsImpl(const ArenaAllocatorStatsImpl& other) = default;
109 ArenaAllocatorStatsImpl& operator = (const ArenaAllocatorStatsImpl& other) = delete;
110
Roland Levillain4b8f1ec2015-08-26 18:34:03 +0100111 void Copy(const ArenaAllocatorStatsImpl& other ATTRIBUTE_UNUSED) {}
112 void RecordAlloc(size_t bytes ATTRIBUTE_UNUSED, ArenaAllocKind kind ATTRIBUTE_UNUSED) {}
Vladimir Marko83cc7ae2014-02-12 18:02:05 +0000113 size_t NumAllocations() const { return 0u; }
114 size_t BytesAllocated() const { return 0u; }
Roland Levillain4b8f1ec2015-08-26 18:34:03 +0100115 void Dump(std::ostream& os ATTRIBUTE_UNUSED,
116 const Arena* first ATTRIBUTE_UNUSED,
117 ssize_t lost_bytes_adjustment ATTRIBUTE_UNUSED) const {}
Vladimir Marko83cc7ae2014-02-12 18:02:05 +0000118};
119
120template <bool kCount>
121class ArenaAllocatorStatsImpl {
122 public:
123 ArenaAllocatorStatsImpl();
124 ArenaAllocatorStatsImpl(const ArenaAllocatorStatsImpl& other) = default;
125 ArenaAllocatorStatsImpl& operator = (const ArenaAllocatorStatsImpl& other) = delete;
126
127 void Copy(const ArenaAllocatorStatsImpl& other);
128 void RecordAlloc(size_t bytes, ArenaAllocKind kind);
129 size_t NumAllocations() const;
130 size_t BytesAllocated() const;
131 void Dump(std::ostream& os, const Arena* first, ssize_t lost_bytes_adjustment) const;
132
133 private:
134 size_t num_allocations_;
135 // TODO: Use std::array<size_t, kNumArenaAllocKinds> from C++11 when we upgrade the STL.
136 size_t alloc_stats_[kNumArenaAllocKinds]; // Bytes used by various allocation kinds.
Vladimir Markobd9e9db2014-03-07 19:41:05 +0000137
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100138 static const char* const kAllocNames[];
Vladimir Marko83cc7ae2014-02-12 18:02:05 +0000139};
140
141typedef ArenaAllocatorStatsImpl<kArenaAllocatorCountAllocations> ArenaAllocatorStats;
buzbee862a7602013-04-05 10:58:54 -0700142
Vladimir Marko2a408a32015-09-18 14:11:00 +0100143template <bool kAvailable, bool kValgrind>
144class ArenaAllocatorMemoryToolCheckImpl {
145 // This is the generic template but since there is a partial specialization
146 // for kValgrind == false, this can be instantiated only for kValgrind == true.
147 static_assert(kValgrind, "This template can be instantiated only for Valgrind.");
148 static_assert(kAvailable, "Valgrind implies memory tool availability.");
149
150 public:
151 ArenaAllocatorMemoryToolCheckImpl() : is_running_on_valgrind_(RUNNING_ON_MEMORY_TOOL) { }
152 bool IsRunningOnMemoryTool() { return is_running_on_valgrind_; }
153
154 private:
155 const bool is_running_on_valgrind_;
156};
157
158template <bool kAvailable>
159class ArenaAllocatorMemoryToolCheckImpl<kAvailable, false> {
160 public:
161 ArenaAllocatorMemoryToolCheckImpl() { }
162 bool IsRunningOnMemoryTool() { return kAvailable; }
163};
164
165typedef ArenaAllocatorMemoryToolCheckImpl<kMemoryToolIsAvailable, kMemoryToolIsValgrind>
166 ArenaAllocatorMemoryToolCheck;
167
168class ArenaAllocatorMemoryTool : private ArenaAllocatorMemoryToolCheck {
169 public:
170 using ArenaAllocatorMemoryToolCheck::IsRunningOnMemoryTool;
171
172 void MakeDefined(void* ptr, size_t size) {
Vladimir Marko7bda3b62015-10-07 12:44:31 +0000173 if (UNLIKELY(IsRunningOnMemoryTool())) {
174 DoMakeDefined(ptr, size);
Vladimir Marko2a408a32015-09-18 14:11:00 +0100175 }
176 }
177 void MakeUndefined(void* ptr, size_t size) {
Vladimir Marko7bda3b62015-10-07 12:44:31 +0000178 if (UNLIKELY(IsRunningOnMemoryTool())) {
179 DoMakeUndefined(ptr, size);
Vladimir Marko2a408a32015-09-18 14:11:00 +0100180 }
181 }
182 void MakeInaccessible(void* ptr, size_t size) {
Vladimir Marko7bda3b62015-10-07 12:44:31 +0000183 if (UNLIKELY(IsRunningOnMemoryTool())) {
184 DoMakeInaccessible(ptr, size);
Vladimir Marko2a408a32015-09-18 14:11:00 +0100185 }
186 }
Vladimir Marko7bda3b62015-10-07 12:44:31 +0000187
188 private:
189 void DoMakeDefined(void* ptr, size_t size);
190 void DoMakeUndefined(void* ptr, size_t size);
191 void DoMakeInaccessible(void* ptr, size_t size);
Vladimir Marko2a408a32015-09-18 14:11:00 +0100192};
193
Mathieu Chartierf6c4b3b2013-08-24 16:11:37 -0700194class Arena {
195 public:
196 static constexpr size_t kDefaultSize = 128 * KB;
Mathieu Chartierc6201fa2015-03-12 10:06:33 -0700197 Arena();
198 virtual ~Arena() { }
Mathieu Chartier9b34b242015-03-09 11:30:17 -0700199 // Reset is for pre-use and uses memset for performance.
Mathieu Chartierf6c4b3b2013-08-24 16:11:37 -0700200 void Reset();
Mathieu Chartier9b34b242015-03-09 11:30:17 -0700201 // Release is used inbetween uses and uses madvise for memory usage.
Mathieu Chartierc6201fa2015-03-12 10:06:33 -0700202 virtual void Release() { }
Mathieu Chartierf6c4b3b2013-08-24 16:11:37 -0700203 uint8_t* Begin() {
204 return memory_;
buzbee862a7602013-04-05 10:58:54 -0700205 }
206
Mathieu Chartierf6c4b3b2013-08-24 16:11:37 -0700207 uint8_t* End() {
208 return memory_ + size_;
209 }
210
211 size_t Size() const {
212 return size_;
213 }
214
215 size_t RemainingSpace() const {
216 return Size() - bytes_allocated_;
217 }
218
Mathieu Chartier49285c52014-12-02 15:43:48 -0800219 size_t GetBytesAllocated() const {
220 return bytes_allocated_;
221 }
222
Mathieu Chartiere401d142015-04-22 13:56:20 -0700223 // Return true if ptr is contained in the arena.
224 bool Contains(const void* ptr) const {
225 return memory_ <= ptr && ptr < memory_ + bytes_allocated_;
226 }
227
Mathieu Chartierc6201fa2015-03-12 10:06:33 -0700228 protected:
Mathieu Chartierf6c4b3b2013-08-24 16:11:37 -0700229 size_t bytes_allocated_;
230 uint8_t* memory_;
231 size_t size_;
Mathieu Chartierf6c4b3b2013-08-24 16:11:37 -0700232 Arena* next_;
233 friend class ArenaPool;
234 friend class ArenaAllocator;
Vladimir Marko83cc7ae2014-02-12 18:02:05 +0000235 friend class ArenaStack;
236 friend class ScopedArenaAllocator;
237 template <bool kCount> friend class ArenaAllocatorStatsImpl;
Mathieu Chartierc6201fa2015-03-12 10:06:33 -0700238
Vladimir Marko3e0e7172016-04-22 18:07:13 +0100239 friend class ArenaAllocatorTest;
240
Mathieu Chartierc6201fa2015-03-12 10:06:33 -0700241 private:
Mathieu Chartierf6c4b3b2013-08-24 16:11:37 -0700242 DISALLOW_COPY_AND_ASSIGN(Arena);
243};
244
Mathieu Chartierc6201fa2015-03-12 10:06:33 -0700245class MallocArena FINAL : public Arena {
246 public:
247 explicit MallocArena(size_t size = Arena::kDefaultSize);
248 virtual ~MallocArena();
249};
250
251class MemMapArena FINAL : public Arena {
252 public:
Nicolas Geoffray25e04562016-03-01 13:17:58 +0000253 MemMapArena(size_t size, bool low_4gb, const char* name);
Vladimir Marko3481ba22015-04-13 12:22:36 +0100254 virtual ~MemMapArena();
Mathieu Chartierc6201fa2015-03-12 10:06:33 -0700255 void Release() OVERRIDE;
256
257 private:
258 std::unique_ptr<MemMap> map_;
259};
260
Mathieu Chartierf6c4b3b2013-08-24 16:11:37 -0700261class ArenaPool {
262 public:
Chih-Hung Hsieha5931182016-09-01 15:08:13 -0700263 explicit ArenaPool(bool use_malloc = true,
264 bool low_4gb = false,
265 const char* name = "LinearAlloc");
Mathieu Chartierf6c4b3b2013-08-24 16:11:37 -0700266 ~ArenaPool();
Mathieu Chartier90443472015-07-16 20:32:27 -0700267 Arena* AllocArena(size_t size) REQUIRES(!lock_);
268 void FreeArenaChain(Arena* first) REQUIRES(!lock_);
269 size_t GetBytesAllocated() const REQUIRES(!lock_);
Jean-Philippe Halimica76a1a2016-02-02 19:48:52 +0100270 void ReclaimMemory() NO_THREAD_SAFETY_ANALYSIS;
271 void LockReclaimMemory() REQUIRES(!lock_);
Mathieu Chartierc6201fa2015-03-12 10:06:33 -0700272 // Trim the maps in arenas by madvising, used by JIT to reduce memory usage. This only works
273 // use_malloc is false.
Mathieu Chartier90443472015-07-16 20:32:27 -0700274 void TrimMaps() REQUIRES(!lock_);
Mathieu Chartierf6c4b3b2013-08-24 16:11:37 -0700275
276 private:
Mathieu Chartierc6201fa2015-03-12 10:06:33 -0700277 const bool use_malloc_;
Mathieu Chartier49285c52014-12-02 15:43:48 -0800278 mutable Mutex lock_ DEFAULT_MUTEX_ACQUIRED_AFTER;
Mathieu Chartierf6c4b3b2013-08-24 16:11:37 -0700279 Arena* free_arenas_ GUARDED_BY(lock_);
Mathieu Chartierc7853442015-03-27 14:35:38 -0700280 const bool low_4gb_;
Nicolas Geoffray25e04562016-03-01 13:17:58 +0000281 const char* name_;
Mathieu Chartierf6c4b3b2013-08-24 16:11:37 -0700282 DISALLOW_COPY_AND_ASSIGN(ArenaPool);
283};
284
Vladimir Markofda04322015-11-11 18:45:50 +0000285// Fast single-threaded allocator for zero-initialized memory chunks.
286//
287// Memory is allocated from ArenaPool in large chunks and then rationed through
288// the ArenaAllocator. It's returned to the ArenaPool only when the ArenaAllocator
289// is destroyed.
Vladimir Marko2a408a32015-09-18 14:11:00 +0100290class ArenaAllocator
291 : private DebugStackRefCounter, private ArenaAllocatorStats, private ArenaAllocatorMemoryTool {
Mathieu Chartierf6c4b3b2013-08-24 16:11:37 -0700292 public:
Mathieu Chartierf6c4b3b2013-08-24 16:11:37 -0700293 explicit ArenaAllocator(ArenaPool* pool);
294 ~ArenaAllocator();
295
Vladimir Marko2a408a32015-09-18 14:11:00 +0100296 using ArenaAllocatorMemoryTool::IsRunningOnMemoryTool;
297 using ArenaAllocatorMemoryTool::MakeDefined;
298 using ArenaAllocatorMemoryTool::MakeUndefined;
299 using ArenaAllocatorMemoryTool::MakeInaccessible;
300
Vladimir Marko8081d2b2014-07-31 15:33:43 +0100301 // Get adapter for use in STL containers. See arena_containers.h .
302 ArenaAllocatorAdapter<void> Adapter(ArenaAllocKind kind = kArenaAllocSTL);
303
Mathieu Chartierf6c4b3b2013-08-24 16:11:37 -0700304 // Returns zeroed memory.
Vladimir Markoe4fcc5b2015-02-13 10:28:29 +0000305 void* Alloc(size_t bytes, ArenaAllocKind kind = kArenaAllocMisc) ALWAYS_INLINE {
Vladimir Marko2a408a32015-09-18 14:11:00 +0100306 if (UNLIKELY(IsRunningOnMemoryTool())) {
307 return AllocWithMemoryTool(bytes, kind);
Mathieu Chartier75165d02013-09-12 14:00:31 -0700308 }
Mathieu Chartierb666f482015-02-18 14:33:14 -0800309 bytes = RoundUp(bytes, kAlignment);
Vladimir Marko83cc7ae2014-02-12 18:02:05 +0000310 ArenaAllocatorStats::RecordAlloc(bytes, kind);
Vladimir Marko3e0e7172016-04-22 18:07:13 +0100311 if (UNLIKELY(bytes > static_cast<size_t>(end_ - ptr_))) {
312 return AllocFromNewArena(bytes);
313 }
Mathieu Chartierf6c4b3b2013-08-24 16:11:37 -0700314 uint8_t* ret = ptr_;
Andreas Gampef6dd8292016-08-19 20:22:19 -0700315 DCHECK_ALIGNED(ret, kAlignment);
Mathieu Chartierf6c4b3b2013-08-24 16:11:37 -0700316 ptr_ += bytes;
317 return ret;
318 }
319
Mathieu Chartiere401d142015-04-22 13:56:20 -0700320 // Realloc never frees the input pointer, it is the caller's job to do this if necessary.
321 void* Realloc(void* ptr, size_t ptr_size, size_t new_size,
322 ArenaAllocKind kind = kArenaAllocMisc) ALWAYS_INLINE {
323 DCHECK_GE(new_size, ptr_size);
324 DCHECK_EQ(ptr == nullptr, ptr_size == 0u);
Andreas Gampef6dd8292016-08-19 20:22:19 -0700325 // We always allocate aligned.
326 const size_t aligned_ptr_size = RoundUp(ptr_size, kAlignment);
327 auto* end = reinterpret_cast<uint8_t*>(ptr) + aligned_ptr_size;
Mathieu Chartiere401d142015-04-22 13:56:20 -0700328 // If we haven't allocated anything else, we can safely extend.
329 if (end == ptr_) {
Vladimir Marko2a408a32015-09-18 14:11:00 +0100330 DCHECK(!IsRunningOnMemoryTool()); // Red zone prevents end == ptr_.
Andreas Gampef6dd8292016-08-19 20:22:19 -0700331 const size_t aligned_new_size = RoundUp(new_size, kAlignment);
332 const size_t size_delta = aligned_new_size - aligned_ptr_size;
Mathieu Chartiere401d142015-04-22 13:56:20 -0700333 // Check remain space.
334 const size_t remain = end_ - ptr_;
335 if (remain >= size_delta) {
336 ptr_ += size_delta;
337 ArenaAllocatorStats::RecordAlloc(size_delta, kind);
Andreas Gampef6dd8292016-08-19 20:22:19 -0700338 DCHECK_ALIGNED(ptr_, kAlignment);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700339 return ptr;
340 }
341 }
Andreas Gampef6dd8292016-08-19 20:22:19 -0700342 auto* new_ptr = Alloc(new_size, kind); // Note: Alloc will take care of aligning new_size.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700343 memcpy(new_ptr, ptr, ptr_size);
344 // TODO: Call free on ptr if linear alloc supports free.
345 return new_ptr;
346 }
347
Vladimir Markoe4fcc5b2015-02-13 10:28:29 +0000348 template <typename T>
Vladimir Markof6a35de2016-03-21 12:01:50 +0000349 T* Alloc(ArenaAllocKind kind = kArenaAllocMisc) {
350 return AllocArray<T>(1, kind);
351 }
352
353 template <typename T>
Vladimir Markoe4fcc5b2015-02-13 10:28:29 +0000354 T* AllocArray(size_t length, ArenaAllocKind kind = kArenaAllocMisc) {
355 return static_cast<T*>(Alloc(length * sizeof(T), kind));
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100356 }
357
Mathieu Chartierf6c4b3b2013-08-24 16:11:37 -0700358 size_t BytesAllocated() const;
Mathieu Chartiere401d142015-04-22 13:56:20 -0700359
Vladimir Marko83cc7ae2014-02-12 18:02:05 +0000360 MemStats GetMemStats() const;
Mathieu Chartiere401d142015-04-22 13:56:20 -0700361
Mathieu Chartierc7853442015-03-27 14:35:38 -0700362 // The BytesUsed method sums up bytes allocated from arenas in arena_head_ and nodes.
363 // TODO: Change BytesAllocated to this behavior?
364 size_t BytesUsed() const;
buzbee862a7602013-04-05 10:58:54 -0700365
Mathieu Chartiere401d142015-04-22 13:56:20 -0700366 ArenaPool* GetArenaPool() const {
367 return pool_;
368 }
369
370 bool Contains(const void* ptr) const;
371
Andreas Gampef6dd8292016-08-19 20:22:19 -0700372 static constexpr size_t kAlignment = 8;
373
Mathieu Chartierf6c4b3b2013-08-24 16:11:37 -0700374 private:
Vladimir Marko3e0e7172016-04-22 18:07:13 +0100375 void* AllocWithMemoryTool(size_t bytes, ArenaAllocKind kind);
Vladimir Marko3f84f2c2016-04-25 19:40:34 +0100376 uint8_t* AllocFromNewArena(size_t bytes);
Vladimir Marko3e0e7172016-04-22 18:07:13 +0100377
Mathieu Chartierb666f482015-02-18 14:33:14 -0800378
Mathieu Chartierf6c4b3b2013-08-24 16:11:37 -0700379 void UpdateBytesAllocated();
buzbee862a7602013-04-05 10:58:54 -0700380
Mathieu Chartierf6c4b3b2013-08-24 16:11:37 -0700381 ArenaPool* pool_;
382 uint8_t* begin_;
383 uint8_t* end_;
384 uint8_t* ptr_;
385 Arena* arena_head_;
Mathieu Chartierf6c4b3b2013-08-24 16:11:37 -0700386
Vladimir Marko8081d2b2014-07-31 15:33:43 +0100387 template <typename U>
388 friend class ArenaAllocatorAdapter;
389
Vladimir Marko3e0e7172016-04-22 18:07:13 +0100390 friend class ArenaAllocatorTest;
391
Mathieu Chartierf6c4b3b2013-08-24 16:11:37 -0700392 DISALLOW_COPY_AND_ASSIGN(ArenaAllocator);
buzbee862a7602013-04-05 10:58:54 -0700393}; // ArenaAllocator
394
Vladimir Marko83cc7ae2014-02-12 18:02:05 +0000395class MemStats {
396 public:
397 MemStats(const char* name, const ArenaAllocatorStats* stats, const Arena* first_arena,
398 ssize_t lost_bytes_adjustment = 0);
399 void Dump(std::ostream& os) const;
400
401 private:
402 const char* const name_;
403 const ArenaAllocatorStats* const stats_;
404 const Arena* const first_arena_;
405 const ssize_t lost_bytes_adjustment_;
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700406}; // MemStats
buzbee862a7602013-04-05 10:58:54 -0700407
408} // namespace art
409
Mathieu Chartierb666f482015-02-18 14:33:14 -0800410#endif // ART_RUNTIME_BASE_ARENA_ALLOCATOR_H_