• 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_STW_YOUNG_GC_FOR_TESTING_H
17 #define ECMASCRIPT_MEM_STW_YOUNG_GC_FOR_TESTING_H
18 
19 #include "ecmascript/mem/clock_scope.h"
20 #include "ecmascript/mem/mem.h"
21 #include "ecmascript/mem/heap.h"
22 #include "ecmascript/mem/allocator.h"
23 #include "ecmascript/mem/mark_stack-inl.h"
24 #include "ecmascript/mem/mark_word.h"
25 #include "ecmascript/mem/slots.h"
26 #include "ecmascript/mem/object_xray.h"
27 #include "ecmascript/mem/remembered_set.h"
28 #include "ecmascript/mem/chunk_containers.h"
29 #include "ecmascript/mem/tlab_allocator.h"
30 
31 #include "os/mutex.h"
32 
33 namespace panda {
34 namespace ecmascript {
35 class Heap;
36 class JSHClass;
37 class WorkerHelper;
38 
39 class GarbageCollector {
40 public:
41     GarbageCollector() = default;
42     virtual ~GarbageCollector() = default;
43     DEFAULT_COPY_SEMANTIC(GarbageCollector);
44     DEFAULT_MOVE_SEMANTIC(GarbageCollector);
45 };
46 
47 class STWYoungGC : public GarbageCollector {
48 public:
49     explicit STWYoungGC(Heap *heap, bool paralledGc);
50     ~STWYoungGC() override = default;
51     NO_COPY_SEMANTIC(STWYoungGC);
52     NO_MOVE_SEMANTIC(STWYoungGC);
53 
54     void RunPhases();
55 
56 private:
57     void InitializePhase();
58     void ParallelMarkingPhase();
59     void SweepPhases();
60     void FinishPhase();
61 
62     inline void UpdatePromotedSlot(TaggedObject *object, ObjectSlot slot);
63 
64     Heap *heap_;
65     size_t promotedSize_{0};
66     size_t semiCopiedSize_{0};
67     size_t commitSize_ = 0;
68 
69     // obtain from heap
70     bool paralledGc_ {false};
71     WorkerHelper *workList_ {nullptr};
72 
73     friend class TlabAllocator;
74     friend class WorkerHelper;
75     friend class Heap;
76 };
77 }  // namespace ecmascript
78 }  // namespace panda
79 
80 #endif  // ECMASCRIPT_MEM_STW_YOUNG_GC_FOR_TESTING_H
81