• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2021-2022 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 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     // TODO(dtrubenkov): move it to the more proper place
59     static void MarkCardsAsYoung(const MemRange &mem_range);
60 
61 private:
62     static CrossingMap *instance;
63     static os::memory::Mutex mutex;
64 };
65 
66 }  // namespace panda::mem
67 #endif  // PANDA_MEM_GC_CROSSING_MAP_SINGLETON_H
68