1 /**
2 * Copyright (c) 2022-2024 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
16 #include "runtime/mem/gc/g1/g1-helpers.h"
17 #include "runtime/mem/gc/epsilon-g1/epsilon-g1.h"
18 #include "runtime/include/panda_vm.h"
19 #include "runtime/include/runtime.h"
20
21 namespace ark::mem {
22 template <class LanguageConfig>
EpsilonG1GC(ObjectAllocatorBase * objectAllocator,const GCSettings & settings)23 EpsilonG1GC<LanguageConfig>::EpsilonG1GC(ObjectAllocatorBase *objectAllocator, const GCSettings &settings)
24 : G1GC<LanguageConfig>(objectAllocator, settings)
25 {
26 this->SetType(GCType::EPSILON_G1_GC);
27 }
28
29 template <class LanguageConfig>
StartGC()30 void EpsilonG1GC<LanguageConfig>::StartGC()
31 {
32 // NOLINTNEXTLINE(bugprone-parent-virtual-call)
33 GC::StartGC();
34 }
35
36 template <class LanguageConfig>
StopGC()37 void EpsilonG1GC<LanguageConfig>::StopGC()
38 {
39 // NOLINTNEXTLINE(bugprone-parent-virtual-call)
40 GC::StopGC();
41 }
42
43 template <class LanguageConfig>
InitializeImpl()44 void EpsilonG1GC<LanguageConfig>::InitializeImpl()
45 {
46 // GC saved the PandaVM instance, so we get allocator from the PandaVM.
47 InternalAllocatorPtr allocator = this->GetInternalAllocator();
48 this->CreateCardTable(allocator, PoolManager::GetMmapMemPool()->GetMinObjectAddress(),
49 PoolManager::GetMmapMemPool()->GetTotalObjectSize());
50
51 auto barrierSet =
52 allocator->New<GCG1BarrierSet>(allocator, &PreWrbFuncEntrypoint, &PostWrbUpdateCardFuncEntrypoint,
53 ark::helpers::math::GetIntLog2(this->GetG1ObjectAllocator()->GetRegionSize()),
54 this->GetCardTable(), this->updatedRefsQueue_, &this->queueLock_);
55 ASSERT(barrierSet != nullptr);
56 this->SetGCBarrierSet(barrierSet);
57
58 LOG(DEBUG, GC) << "EpsilonG1 GC initialized...";
59 }
60
61 template <class LanguageConfig>
OnThreadTerminate(ManagedThread * thread,mem::BuffersKeepingFlag keepBuffers)62 void EpsilonG1GC<LanguageConfig>::OnThreadTerminate(ManagedThread *thread,
63 [[maybe_unused]] mem::BuffersKeepingFlag keepBuffers)
64 {
65 LOG(DEBUG, GC) << "Call OnThreadTerminate";
66 // Clearing buffers to remove memory leaks in internal allocator
67
68 auto preBuff = thread->MovePreBuff();
69 ASSERT(preBuff != nullptr);
70 this->GetInternalAllocator()->Delete(preBuff);
71
72 auto *localBuffer = thread->GetG1PostBarrierBuffer();
73 thread->ResetG1PostBarrierBuffer();
74 ASSERT(localBuffer != nullptr);
75 this->GetInternalAllocator()->Delete(localBuffer);
76 }
77
78 template <class LanguageConfig>
RunPhasesImpl(GCTask & task)79 void EpsilonG1GC<LanguageConfig>::RunPhasesImpl([[maybe_unused]] GCTask &task)
80 {
81 LOG(DEBUG, GC) << "EpsilonG1 GC RunPhases...";
82 GCScopedPauseStats scopedPauseStats(this->GetPandaVm()->GetGCStats());
83 }
84
85 template <class LanguageConfig>
WaitForGC(GCTask task)86 bool EpsilonG1GC<LanguageConfig>::WaitForGC([[maybe_unused]] GCTask task)
87 {
88 return false;
89 }
90
91 template <class LanguageConfig>
InitGCBits(ark::ObjectHeader * objHeader)92 void EpsilonG1GC<LanguageConfig>::InitGCBits([[maybe_unused]] ark::ObjectHeader *objHeader)
93 {
94 }
95
96 template <class LanguageConfig>
Trigger(PandaUniquePtr<GCTask> task)97 bool EpsilonG1GC<LanguageConfig>::Trigger([[maybe_unused]] PandaUniquePtr<GCTask> task)
98 {
99 return false;
100 }
101
102 template <class LanguageConfig>
MarkReferences(GCMarkingStackType * references,GCPhase gcPhase)103 void EpsilonG1GC<LanguageConfig>::MarkReferences([[maybe_unused]] GCMarkingStackType *references,
104 [[maybe_unused]] GCPhase gcPhase)
105 {
106 }
107
108 TEMPLATE_CLASS_LANGUAGE_CONFIG(EpsilonG1GC);
109
110 } // namespace ark::mem
111