• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
29 namespace panda {
30 namespace ecmascript {
31 class PartialGC : public GarbageCollector {
32 public:
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 
GetHeap()40     Heap *GetHeap() const
41     {
42         return heap_;
43     }
44 
45 protected:
46     void Initialize() override;
47     void Mark() override;
48     void Sweep() override;
49     void Finish() override;
50 
51 private:
52     void Evacuate();
53     void ProcessNativeDelete();
54 
55     Heap *heap_;
56     size_t freeSize_ {0};
57     size_t hugeSpaceFreeSize_ = 0;
58     size_t oldSpaceCommitSize_ = 0;
59     size_t nonMoveSpaceCommitSize_ = 0;
60     bool markingInProgress_ {false};
61     // Obtained from the shared heap instance.
62     WorkManager *workManager_ {nullptr};
63 
64     friend class WorkManager;
65     friend class Heap;
66 };
67 }  // namespace ecmascript
68 }  // namespace panda
69 
70 #endif  // ECMASCRIPT_MEM_PARTIAL_GC_H
71