• 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_H
17 #define ECMASCRIPT_MEM_STW_YOUNG_GC_H
18 
19 #include "ecmascript/mem/allocator.h"
20 #include "ecmascript/mem/clock_scope.h"
21 #include "ecmascript/mem/garbage_collector.h"
22 #include "ecmascript/mem/heap.h"
23 #include "ecmascript/mem/mark_stack.h"
24 #include "ecmascript/mem/mark_word.h"
25 #include "ecmascript/mem/mem.h"
26 #include "ecmascript/mem/slots.h"
27 #include "ecmascript/mem/tlab_allocator.h"
28 #include "ecmascript/mem/visitor.h"
29 #include "ecmascript/mem/work_manager.h"
30 
31 #include "libpandabase/os/mutex.h"
32 
33 namespace panda {
34 namespace ecmascript {
35 class STWYoungGC : public GarbageCollector {
36 public:
37     STWYoungGC(Heap *heap, bool parallelGC);
38     ~STWYoungGC() override = default;
39     NO_COPY_SEMANTIC(STWYoungGC);
40     NO_MOVE_SEMANTIC(STWYoungGC);
41 
ConfigParallelGC(bool parallelGC)42     void ConfigParallelGC(bool parallelGC)
43     {
44         parallelGC_ = parallelGC;
45     }
46     virtual void RunPhases() override;
47 
48 protected:
49     virtual void Initialize() override;
50     virtual void Mark() override;
51     virtual void Sweep() override;
52     virtual void Finish() override;
53 
54 private:
UpdatePromotedSlot(TaggedObject * object,ObjectSlot slot)55     inline void UpdatePromotedSlot(TaggedObject *object, ObjectSlot slot)
56     {
57 #ifndef NDEBUG
58         JSTaggedValue value(slot.GetTaggedType());
59         ASSERT(value.IsHeapObject());
60 #endif
61         Region *objectRegion = Region::ObjectAddressToRange(object);
62         ASSERT(!objectRegion->InYoungSpace());
63         objectRegion->InsertOldToNewRSet(slot.SlotAddress());
64     }
65 
66     Heap *heap_;
67     size_t promotedSize_ {0};
68     size_t semiCopiedSize_ {0};
69     size_t commitSize_ {0};
70 
71     // obtain from heap
72     bool parallelGC_ {false};
73     WorkManager *workManager_ {nullptr};
74 
75     friend class TlabAllocator;
76     friend class WorkManager;
77     friend class Heap;
78 };
79 }  // namespace ecmascript
80 }  // namespace panda
81 
82 #endif  // ECMASCRIPT_MEM_STW_YOUNG_GC_H
83