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_RUNTIME_BASE_MEM_MAP_ARENA_POOL_H_
18 #define ART_RUNTIME_BASE_MEM_MAP_ARENA_POOL_H_
19 
20 #include "base/arena_allocator.h"
21 
22 namespace art {
23 
24 class MemMapArenaPool final : public ArenaPool {
25  public:
26   explicit MemMapArenaPool(bool low_4gb = false, const char* name = "LinearAlloc");
27   virtual ~MemMapArenaPool();
28   Arena* AllocArena(size_t size) override;
29   void FreeArenaChain(Arena* first) override;
30   size_t GetBytesAllocated() const override;
31   void ReclaimMemory() override;
32   void LockReclaimMemory() override;
33   // Trim the maps in arenas by madvising, used by JIT to reduce memory usage.
34   void TrimMaps() override;
35 
36  private:
37   const bool low_4gb_;
38   const char* name_;
39   Arena* free_arenas_;
40   // Use a std::mutex here as Arenas are second-from-the-bottom when using MemMaps, and MemMap
41   // itself uses std::mutex scoped to within an allocate/free only.
42   mutable std::mutex lock_;
43 
44   DISALLOW_COPY_AND_ASSIGN(MemMapArenaPool);
45 };
46 
47 }  // namespace art
48 
49 #endif  // ART_RUNTIME_BASE_MEM_MAP_ARENA_POOL_H_
50