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_H 17 #define ECMASCRIPT_MEM_SHARED_HEAP_SHARED_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/work_manager.h" 26 #include "ecmascript/mem/shared_heap/shared_gc_marker.h" 27 28 namespace panda::ecmascript { 29 class SharedGCEvacuator; 30 class SharedGC : public GarbageCollector { 31 public: SharedGC(SharedHeap * heap)32 explicit SharedGC(SharedHeap *heap) : sHeap_(heap), sWorkManager_(heap->GetWorkManager()) {} 33 ~SharedGC() override = default; 34 NO_COPY_SEMANTIC(SharedGC); 35 NO_MOVE_SEMANTIC(SharedGC); 36 37 void RunPhases() override; 38 void ResetWorkManager(SharedGCWorkManager *workManager); 39 protected: 40 void Initialize() override; 41 void Mark() override; 42 void Sweep() override; 43 void Finish() override; 44 45 private: 46 void MarkRoots(SharedMarkType markType); 47 void UpdateRecordWeakReference(); 48 void Evacuate(); 49 void PreSweep(); 50 51 SharedHeap *sHeap_ {nullptr}; 52 SharedGCWorkManager *sWorkManager_ {nullptr}; 53 bool markingInProgress_ {false}; 54 }; 55 } // namespace panda::ecmascript 56 57 #endif // ECMASCRIPT_MEM_SHARED_HEAP_SHARED_GC_H 58