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 PANDA_PLUGINS_ETS_RUNTIME_INTRINSICS_GC_TASK_TRACKER_H 17 #define PANDA_PLUGINS_ETS_RUNTIME_INTRINSICS_GC_TASK_TRACKER_H 18 19 #include "runtime/mem/gc/gc.h" 20 21 namespace ark::ets::intrinsics { 22 23 /** 24 * Class tracks GC tasks already processed by GC. 25 * Also the class tracks concurrent mark GC phase and calls 26 * the callback if it specified. 27 */ 28 class GCTaskTracker : public mem::GCListener { 29 public: 30 static GCTaskTracker &InitIfNeededAndGet(mem::GC *gc); 31 static bool IsInitialized(); 32 33 void AddTaskId(uint64_t id); 34 bool HasId(uint64_t id); 35 void SetCallbackForTask(uint32_t taskId, mem::Reference *callbackRef); 36 void GCStarted(const GCTask &task, size_t heapSize) override; 37 void GCPhaseStarted(mem::GCPhase phase) override; 38 void GCFinished(const GCTask &task, size_t heapSizeBeforeGc, size_t heapSize) override; 39 void RemoveId(uint64_t id); 40 41 private: 42 static bool initialized_; 43 static os::memory::Mutex lock_; 44 45 std::vector<uint64_t> taskIds_ GUARDED_BY(lock_); 46 uint32_t currentTaskId_ = 0; 47 uint32_t callbackTaskId_ = 0; 48 mem::Reference *callbackRef_ = nullptr; 49 }; 50 51 } // namespace ark::ets::intrinsics 52 53 #endif // PANDA_PLUGINS_ETS_RUNTIME_INTRINSICS_GC_TASK_TRACKER_H 54