1 /*
2  * Copyright (c) 2021 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 #ifndef ECMASCRIPT_MEM_FULL_GC_H
17 #define ECMASCRIPT_MEM_FULL_GC_H
18 
19 #include "ecmascript/mem/garbage_collector.h"
20 #include "ecmascript/mem/heap.h"
21 #include "ecmascript/mem/work_manager.h"
22 
23 namespace panda {
24 namespace ecmascript {
25 class FullGC : public GarbageCollector {
26 public:
27     explicit FullGC(Heap *heap);
28     ~FullGC() override = default;
29 
30     NO_COPY_SEMANTIC(FullGC);
31     NO_MOVE_SEMANTIC(FullGC);
32 
33     void RunPhases() override;
34     void RunPhasesForAppSpawn();
35     void SetForAppSpawn(bool flag);
36 protected:
37     void Initialize() override;
38     void Mark() override;
39     void Sweep() override;
40     void Finish() override;
41 
42 private:
43     void ProcessSharedGCRSetWorkList();
44     bool HasEvacuated(Region *region);
45 
46     Heap *heap_;
47     size_t youngAndOldAliveSize_ = 0;
48     size_t nonMoveSpaceFreeSize_ = 0;
49     size_t youngSpaceCommitSize_ = 0;
50     size_t oldSpaceCommitSize_ = 0;
51     size_t nonMoveSpaceCommitSize_ = 0;
52     bool forAppSpawn_ {false};
53     // obtain from heap
54     WorkManager *workManager_ {nullptr};
55 
56     friend class WorkManager;
57     friend class Heap;
58 };
59 }  // namespace ecmascript
60 }  // namespace panda
61 
62 #endif  // ECMASCRIPT_MEM_FULL_GC_H
63