1 /*
2  * Copyright (C) 2018 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_LIBARTBASE_BASE_MALLOC_ARENA_POOL_H_
18 #define ART_LIBARTBASE_BASE_MALLOC_ARENA_POOL_H_
19 
20 #include <mutex>
21 
22 #include "arena_allocator.h"
23 
24 namespace art {
25 
26 class MallocArenaPool final : public ArenaPool {
27  public:
28   MallocArenaPool();
29   ~MallocArenaPool();
30   Arena* AllocArena(size_t size) override;
31   void FreeArenaChain(Arena* first) override;
32   size_t GetBytesAllocated() const override;
33   void ReclaimMemory() override;
34   void LockReclaimMemory() override;
35   // Is a nop for malloc pools.
36   void TrimMaps() override;
37 
38  private:
39   Arena* free_arenas_;
40   // Use a std::mutex here as Arenas are at the bottom of the lock hierarchy when malloc is used.
41   mutable std::mutex lock_;
42 
43   DISALLOW_COPY_AND_ASSIGN(MallocArenaPool);
44 };
45 
46 }  // namespace art
47 
48 #endif  // ART_LIBARTBASE_BASE_MALLOC_ARENA_POOL_H_
49