• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include "common_components/heap/heap_manager.h"
16 
17 #include "common_components/heap/heap.h"
18 #include "common_components/heap/collector/collector.h"
19 #include "common_components/heap/allocator/region_manager.h"
20 #include "common_components/heap/allocator/region_space.h"
21 
22 namespace common {
HeapManager()23 HeapManager::HeapManager() {}
RequestGC(GCReason reason,bool async,GCType gcType)24 void HeapManager::RequestGC(GCReason reason, bool async, GCType gcType)
25 {
26     if (!Heap::GetHeap().IsGCEnabled()) {
27         return;
28     }
29     Collector& collector = Heap::GetHeap().GetCollector();
30     collector.RequestGC(reason, async, gcType);
31 }
32 
Allocate(size_t allocSize,AllocType allocType,bool allowGC)33 HeapAddress HeapManager::Allocate(size_t allocSize, AllocType allocType, bool allowGC)
34 {
35     return Heap::GetHeap().Allocate(allocSize, allocType, allowGC);
36 }
37 
Init(const RuntimeParam & param)38 void HeapManager::Init(const RuntimeParam& param) { Heap::GetHeap().Init(param); }
39 
Fini()40 void HeapManager::Fini() { Heap::GetHeap().Fini(); }
41 
StartRuntimeThreads()42 void HeapManager::StartRuntimeThreads() { Heap::GetHeap().StartRuntimeThreads(); }
43 
StopRuntimeThreads()44 void HeapManager::StopRuntimeThreads() { Heap::GetHeap().StopRuntimeThreads(); }
45 
MarkJitFortMemInstalled(void * vm,void * obj)46 void HeapManager::MarkJitFortMemInstalled(void *vm, void *obj)
47 {
48     RegionManager &manager = reinterpret_cast<RegionSpace &>(Heap::GetHeap().GetAllocator()).GetRegionManager();
49     manager.MarkJitFortMemInstalled(vm, reinterpret_cast<BaseObject *>(obj));
50 }
51 
SetReadOnlyToROSpace()52 void HeapManager::SetReadOnlyToROSpace()
53 {
54     RegionManager& manager = reinterpret_cast<RegionSpace&>(Heap::GetHeap().GetAllocator()).GetRegionManager();
55     manager.SetReadOnlyToRORegionList();
56 }
57 
ClearReadOnlyFromROSpace()58 void HeapManager::ClearReadOnlyFromROSpace()
59 {
60     RegionManager& manager = reinterpret_cast<RegionSpace&>(Heap::GetHeap().GetAllocator()).GetRegionManager();
61     manager.ClearReadOnlyFromRORegionList();
62 }
63 
IsInROSpace(BaseObject * obj)64 bool HeapManager::IsInROSpace(BaseObject *obj)
65 {
66     return RegionSpace::IsReadOnlyObject(obj);
67 }
68 } // namespace common
69