1 /* 2 * Copyright (c) 2025 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_UNIFIED_GC_UNIFIED_GC_H 17 #define ECMASCRIPT_MEM_UNIFIED_GC_UNIFIED_GC_H 18 19 #include <atomic> 20 21 #ifdef PANDA_JS_ETS_HYBRID_MODE 22 #include "ecmascript/cross_vm/cross_vm_operator.h" 23 #endif // PANDA_JS_ETS_HYBRID_MODE 24 25 namespace panda::ecmascript { 26 class UnifiedGC { 27 public: UnifiedGC()28 explicit UnifiedGC() {} 29 ~UnifiedGC() = default; 30 31 void RunPhases(); 32 void Initialize(); 33 void Mark(); 34 void Finish(); 35 36 #ifdef PANDA_JS_ETS_HYBRID_MODE SetSTSVMInterface(arkplatform::STSVMInterface * stsIface)37 void SetSTSVMInterface(arkplatform::STSVMInterface *stsIface) 38 { 39 stsVMInterface_ = stsIface; 40 } 41 GetSTSVMInterface()42 arkplatform::STSVMInterface *GetSTSVMInterface() const 43 { 44 return stsVMInterface_; 45 } 46 SetInterruptUnifiedGC(bool isInterruptUnifiedGC)47 void SetInterruptUnifiedGC(bool isInterruptUnifiedGC) 48 { 49 isInterruptUnifiedGC_.store(isInterruptUnifiedGC, std::memory_order_relaxed); 50 } 51 StartXGCBarrier()52 bool StartXGCBarrier() 53 { 54 static const auto StartXGCCheck = []() -> bool { 55 return !isInterruptUnifiedGC_.load(std::memory_order_acquire); 56 }; 57 return stsVMInterface_->StartXGCBarrier(StartXGCCheck); 58 } 59 FinishXGCBarrier()60 void FinishXGCBarrier() 61 { 62 stsVMInterface_->FinishXGCBarrier(); 63 } 64 #endif // PANDA_JS_ETS_HYBRID_MODE 65 66 private: 67 #ifdef PANDA_JS_ETS_HYBRID_MODE 68 arkplatform::STSVMInterface *stsVMInterface_ {nullptr}; 69 static std::atomic<bool> isInterruptUnifiedGC_; 70 #endif // PANDA_JS_ETS_HYBRID_MODE 71 }; 72 } // namespace panda::ecmascript 73 74 #endif // ECMASCRIPT_MEM_UNIFIED_GC_UNIFIED_GC_H