1 /** 2 * Copyright (c) 2021-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 #ifndef PANDA_MEM_GC_CROSSING_MAP_SINGLETON_H 16 #define PANDA_MEM_GC_CROSSING_MAP_SINGLETON_H 17 18 #include <cstdlib> 19 20 #include "libpandabase/macros.h" 21 #include "libpandabase/mem/mem_range.h" 22 #include "libpandabase/os/mutex.h" 23 24 namespace ark::mem { 25 26 class CrossingMap; 27 /// Singleton for CrossingMap class. 28 class CrossingMapSingleton { 29 public: 30 CrossingMapSingleton() = delete; 31 ~CrossingMapSingleton() = delete; 32 NO_COPY_SEMANTIC(CrossingMapSingleton); 33 NO_MOVE_SEMANTIC(CrossingMapSingleton); 34 35 static bool Create(); 36 static bool IsCreated(); 37 GetCrossingMap()38 static CrossingMap *GetCrossingMap() 39 { 40 ASSERT(instance_ != nullptr); 41 return instance_; 42 } 43 44 static void AddObject(void *objAddr, size_t objSize); 45 static void RemoveObject(void *objAddr, size_t objSize, void *nextObjAddr, void *prevObjAddr, size_t prevObjSize); 46 static void *FindFirstObject(void *startAddr, void *endAddr); 47 48 static void InitializeCrossingMapForMemory(void *startAddr, size_t size); 49 static void RemoveCrossingMapForMemory(void *startAddr, size_t size); 50 51 static bool Destroy(); 52 53 static size_t GetCrossingMapGranularity(); 54 55 // NOTE(dtrubenkov): move it to the more proper place 56 static void MarkCardsAsYoung(const MemRange &memRange); 57 58 private: 59 static CrossingMap *instance_; 60 static os::memory::Mutex mutex_; 61 }; 62 63 } // namespace ark::mem 64 #endif // PANDA_MEM_GC_CROSSING_MAP_SINGLETON_H 65