1 /**
2 * Copyright (c) 2021-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/epsilon/epsilon.h"
17
18 #include "libpandabase/utils/logger.h"
19 #include "runtime/include/runtime.h"
20 #include "runtime/include/panda_vm.h"
21
22 namespace ark::mem {
23 template <class LanguageConfig>
EpsilonGC(ObjectAllocatorBase * objectAllocator,const GCSettings & settings)24 EpsilonGC<LanguageConfig>::EpsilonGC(ObjectAllocatorBase *objectAllocator, const GCSettings &settings)
25 : GCLang<LanguageConfig>(objectAllocator, settings)
26 {
27 this->SetType(GCType::EPSILON_GC);
28 }
29
30 template <class LanguageConfig>
InitializeImpl()31 void EpsilonGC<LanguageConfig>::InitializeImpl()
32 {
33 InternalAllocatorPtr allocator = this->GetInternalAllocator();
34 auto barrierSet = allocator->New<GCDummyBarrierSet>(allocator);
35 ASSERT(barrierSet != nullptr);
36 this->SetGCBarrierSet(barrierSet);
37 LOG(DEBUG, GC) << "Epsilon GC initialized...";
38 }
39
40 template <class LanguageConfig>
RunPhasesImpl(GCTask & task)41 void EpsilonGC<LanguageConfig>::RunPhasesImpl([[maybe_unused]] GCTask &task)
42 {
43 LOG(DEBUG, GC) << "Epsilon GC RunPhases...";
44 GCScopedPauseStats scopedPauseStats(this->GetPandaVm()->GetGCStats());
45 }
46
47 // NOLINTNEXTLINE(misc-unused-parameters)
48 template <class LanguageConfig>
WaitForGC(GCTask task)49 bool EpsilonGC<LanguageConfig>::WaitForGC([[maybe_unused]] GCTask task)
50 {
51 return false;
52 }
53
54 template <class LanguageConfig>
InitGCBits(ark::ObjectHeader * objHeader)55 void EpsilonGC<LanguageConfig>::InitGCBits([[maybe_unused]] ark::ObjectHeader *objHeader)
56 {
57 }
58
59 template <class LanguageConfig>
InitGCBitsForAllocationInTLAB(ark::ObjectHeader * objHeader)60 void EpsilonGC<LanguageConfig>::InitGCBitsForAllocationInTLAB([[maybe_unused]] ark::ObjectHeader *objHeader)
61 {
62 LOG(FATAL, GC) << "TLABs are not supported by this GC";
63 }
64
65 template <class LanguageConfig>
Trigger(PandaUniquePtr<GCTask> task)66 bool EpsilonGC<LanguageConfig>::Trigger([[maybe_unused]] PandaUniquePtr<GCTask> task)
67 {
68 return false;
69 }
70
71 template <class LanguageConfig>
IsPostponeGCSupported() const72 bool EpsilonGC<LanguageConfig>::IsPostponeGCSupported() const
73 {
74 return true;
75 }
76
77 template <class LanguageConfig>
MarkObject(ObjectHeader * object)78 void EpsilonGC<LanguageConfig>::MarkObject(ObjectHeader *object)
79 {
80 object->SetMarkedForGC<true>();
81 }
82
83 template <class LanguageConfig>
IsMarked(const ObjectHeader * object) const84 bool EpsilonGC<LanguageConfig>::IsMarked(const ObjectHeader *object) const
85 {
86 return object->IsMarkedForGC<true>();
87 }
88
89 template <class LanguageConfig>
MarkReferences(GCMarkingStackType * references,GCPhase gcPhase)90 void EpsilonGC<LanguageConfig>::MarkReferences([[maybe_unused]] GCMarkingStackType *references,
91 [[maybe_unused]] GCPhase gcPhase)
92 {
93 }
94
95 TEMPLATE_CLASS_LANGUAGE_CONFIG(EpsilonGC);
96
97 } // namespace ark::mem
98