1 /* 2 * Copyright (c) 2024 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_SHARED_HEAP_SHARED_GC_VISITOR_H 17 #define ECMASCRIPT_MEM_SHARED_HEAP_SHARED_GC_VISITOR_H 18 19 #include "ecmascript/mem/slots.h" 20 #include <ecmascript/mem/visitor.h> 21 #include <ecmascript/mem/work_manager.h> 22 23 namespace panda::ecmascript { 24 class SharedGCMarkRootVisitor final : public RootVisitor { 25 public: 26 inline explicit SharedGCMarkRootVisitor(SharedGCWorkManager *sWorkManager, uint32_t threadId); 27 ~SharedGCMarkRootVisitor() override = default; 28 29 inline void VisitRoot([[maybe_unused]] Root type, ObjectSlot slot) override; 30 31 inline void VisitRangeRoot([[maybe_unused]] Root type, ObjectSlot start, ObjectSlot end) override; 32 33 inline void VisitBaseAndDerivedRoot([[maybe_unused]] Root type, ObjectSlot base, ObjectSlot derived, 34 uintptr_t baseOldObject) override; 35 private: 36 inline void MarkObject(TaggedObject *object); 37 38 SharedGCWorkManager *sWorkManager_ {nullptr}; 39 uint32_t threadId_ {-1}; 40 }; 41 42 class SharedGCMarkObjectVisitor final : public BaseObjectVisitor<SharedGCMarkObjectVisitor> { 43 public: 44 inline explicit SharedGCMarkObjectVisitor(SharedGCWorkManager *sWorkManager, uint32_t threadId); 45 ~SharedGCMarkObjectVisitor() override = default; 46 47 inline void VisitObjectRangeImpl(BaseObject *root, uintptr_t start, uintptr_t end, 48 VisitObjectArea area) override; 49 50 inline void VisitObjectHClassImpl(BaseObject *hclass) override; 51 52 private: 53 inline void HandleSlot(ObjectSlot slot, Region *rootRegion); 54 55 inline void MarkAndPush(TaggedObject *object, Region *objectRegion); 56 57 inline void RecordWeakReference(JSTaggedType *weak); 58 59 SharedGCWorkManager *sWorkManager_ {nullptr}; 60 uint32_t threadId_ {-1}; 61 }; 62 63 } // namespace panda::ecmascript 64 #endif // ECMASCRIPT_MEM_SHARED_HEAP_SHARED_GC_VISITOR_H 65