blob: 6d8eda6499a841826da8498d21fee8b4f3711268 [file] [log] [blame]
Mathieu Chartierc7853442015-03-27 14:35:38 -07001/*
2 * Copyright (C) 2015 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
17#ifndef ART_RUNTIME_LINEAR_ALLOC_H_
18#define ART_RUNTIME_LINEAR_ALLOC_H_
19
20#include "base/arena_allocator.h"
21
22namespace art {
23
24class ArenaPool;
25
26// TODO: Support freeing if we add poor man's class unloading.
27class LinearAlloc {
28 public:
29 explicit LinearAlloc(ArenaPool* pool);
30
31 void* Alloc(Thread* self, size_t size);
32
33 // Allocate and construct an array of structs of type T.
34 template<class T>
35 T* AllocArray(Thread* self, size_t elements) {
36 return reinterpret_cast<T*>(Alloc(self, elements * sizeof(T)));
37 }
38
39 // Return the number of bytes used in the allocator.
40 size_t GetUsedMemory() const;
41
42 private:
43 mutable Mutex lock_ DEFAULT_MUTEX_ACQUIRED_AFTER;
44 ArenaAllocator allocator_ GUARDED_BY(lock_);
45};
46
47} // namespace art
48
49#endif // ART_RUNTIME_LINEAR_ALLOC_H_