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_PARTIAL_GC_H
17#define ECMASCRIPT_MEM_PARTIAL_GC_H
18
19#include "ecmascript/mem/allocator.h"
20#include "ecmascript/mem/garbage_collector.h"
21#include "ecmascript/mem/heap.h"
22#include "ecmascript/mem/mark_stack.h"
23#include "ecmascript/mem/mark_word.h"
24#include "ecmascript/mem/mem.h"
25#include "ecmascript/mem/slots.h"
26#include "ecmascript/mem/visitor.h"
27#include "ecmascript/mem/work_manager.h"
28
29namespace panda {
30namespace ecmascript {
31class PartialGC : public GarbageCollector {
32public:
33    explicit PartialGC(Heap *heap);
34    ~PartialGC() override = default;
35    NO_COPY_SEMANTIC(PartialGC);
36    NO_MOVE_SEMANTIC(PartialGC);
37
38    void RunPhases() override;
39
40    Heap *GetHeap() const
41    {
42        return heap_;
43    }
44
45protected:
46    void Initialize() override;
47    void Mark() override;
48    void Sweep() override;
49    void Finish() override;
50
51private:
52    void ProcessSharedGCRSetWorkList();
53    void Evacuate();
54    void ProcessNativeDelete();
55
56    Heap *heap_;
57    size_t freeSize_ {0};
58    size_t hugeSpaceFreeSize_ = 0;
59    size_t oldSpaceCommitSize_ = 0;
60    size_t nonMoveSpaceCommitSize_ = 0;
61    bool markingInProgress_ {false};
62    // Obtained from the shared heap instance.
63    WorkManager *workManager_ {nullptr};
64
65    friend class WorkManager;
66    friend class Heap;
67};
68}  // namespace ecmascript
69}  // namespace panda
70
71#endif  // ECMASCRIPT_MEM_PARTIAL_GC_H
72