1 /* 2 * Copyright (c) 2021 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_RUNTIME_MEM_GC_CROSSING_MAP_SINGLETON_H_ 17 #define PANDA_RUNTIME_MEM_GC_CROSSING_MAP_SINGLETON_H_ 18 19 #include <cstdlib> 20 21 #include "libpandabase/macros.h" 22 #include "libpandabase/os/mutex.h" 23 24 namespace panda::mem { 25 26 class CrossingMap; 27 /** 28 * Singleton for CrossingMap class. 29 */ 30 class CrossingMapSingleton { 31 public: 32 CrossingMapSingleton() = delete; 33 ~CrossingMapSingleton() = delete; 34 NO_COPY_SEMANTIC(CrossingMapSingleton); 35 NO_MOVE_SEMANTIC(CrossingMapSingleton); 36 37 static bool Create(); 38 static bool IsCreated(); 39 GetCrossingMap()40 static CrossingMap *GetCrossingMap() 41 { 42 ASSERT(instance != nullptr); 43 return instance; 44 } 45 46 static void AddObject(void *obj_addr, size_t obj_size); 47 static void RemoveObject(void *obj_addr, size_t obj_size, void *next_obj_addr, void *prev_obj_addr, 48 size_t prev_obj_size); 49 static void *FindFirstObject(void *start_addr, void *end_addr); 50 51 static void InitializeCrossingMapForMemory(void *start_addr, size_t size); 52 static void RemoveCrossingMapForMemory(void *start_addr, size_t size); 53 54 static bool Destroy(); 55 56 static size_t GetCrossingMapGranularity(); 57 58 private: 59 static CrossingMap *instance; 60 static os::memory::Mutex mutex; 61 }; 62 63 } // namespace panda::mem 64 65 #endif // PANDA_RUNTIME_MEM_GC_CROSSING_MAP_SINGLETON_H_ 66