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_PARALLEL_MARKER_H 17 #define ECMASCRIPT_MEM_PARALLEL_MARKER_H 18 19 #include "ecmascript/js_hclass.h" 20 #include "ecmascript/mem/gc_bitset.h" 21 #include "ecmascript/mem/slots.h" 22 #include "ecmascript/mem/work_manager.h" 23 24 namespace panda::ecmascript { 25 class Heap; 26 class Region; 27 class TaggedObject; 28 29 class Marker { 30 public: 31 explicit Marker(Heap *heap); 32 virtual ~Marker() = default; 33 Initialize()34 virtual void Initialize() 35 { 36 LOG_GC(DEBUG) << "Marker::Initialize do nothing"; 37 } 38 39 void MarkRoots(RootVisitor &rootVisitor, VMRootVisitType type = VMRootVisitType::MARK); 40 MarkJitCodeMap(uint32_t threadId)41 virtual void MarkJitCodeMap([[maybe_unused]] uint32_t threadId) 42 { 43 LOG_GC(FATAL) << "can not call this method"; 44 } 45 ProcessMarkStack(uint32_t threadId)46 virtual void ProcessMarkStack([[maybe_unused]] uint32_t threadId) 47 { 48 LOG_GC(FATAL) << "can not call this method"; 49 } 50 ProcessIncrementalMarkStack(uint32_t threadId,uint32_t markStepSize)51 virtual void ProcessIncrementalMarkStack([[maybe_unused]] uint32_t threadId, 52 [[maybe_unused]] uint32_t markStepSize) 53 { 54 LOG_GC(FATAL) << "can not call this method"; 55 } 56 57 protected: 58 Heap *heap_ {nullptr}; 59 WorkManager *workManager_ {nullptr}; 60 61 friend class Heap; 62 friend class FullGCMarkRootVisitor; 63 }; 64 65 class NonMovableMarker final : public Marker { 66 public: NonMovableMarker(Heap * heap)67 explicit NonMovableMarker(Heap *heap) : Marker(heap) {} 68 ~NonMovableMarker() override = default; 69 70 void ProcessOldToNew(uint32_t threadId); // for non-concurrent YoungGC 71 void ProcessOldToNewNoMarkStack(uint32_t threadId); // for concurrent YoungGC 72 void ProcessSnapshotRSet(uint32_t threadId); // for non-concurrent YoungGC 73 void ProcessSnapshotRSetNoMarkStack(uint32_t threadId); // for concurrent YoungGC 74 75 protected: 76 void ProcessMarkStack(uint32_t threadId) override; 77 void MarkJitCodeMap(uint32_t threadId) override; 78 79 void ProcessIncrementalMarkStack(uint32_t threadId, uint32_t markStepSize) override; 80 private: 81 void ProcessYoungGCMarkStack(uint32_t threadId); 82 void ProcessOldGCMarkStack(uint32_t threadId); 83 }; 84 85 class CompressGCMarker final : public Marker { 86 public: CompressGCMarker(Heap * heap)87 explicit CompressGCMarker(Heap *heap) : Marker(heap) {} 88 ~CompressGCMarker() override = default; 89 SetAppSpawn(bool flag)90 void SetAppSpawn(bool flag) 91 { 92 isAppSpawn_ = flag; 93 } 94 95 protected: 96 void MarkJitCodeMap(uint32_t threadId) override; 97 void ProcessMarkStack(uint32_t threadId) override; 98 99 private: 100 bool isAppSpawn_ {false}; 101 Mutex mutex_; 102 }; 103 } // namespace panda::ecmascript 104 #endif // ECMASCRIPT_MEM_PARALLEL_MARKER_H 105