• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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_DFX_HPROF_HEAP_MARKER_H
17 #define ECMASCRIPT_DFX_HPROF_HEAP_MARKER_H
18 
19 #include <functional>
20 
21 #include "common_components/heap/allocator/region_desc.h"
22 #include "ecmascript/mem/c_containers.h"
23 #include "ecmascript/mem/mem.h"
24 #include "ecmascript/mem/region.h"
25 
26 namespace panda::ecmascript {
27 class HeapMarker {
28 public:
29     HeapMarker() = default;
30     ~HeapMarker() = default;
31     NO_MOVE_SEMANTIC(HeapMarker);
32     NO_COPY_SEMANTIC(HeapMarker);
33 
34     bool Mark(JSTaggedType addr);
35     bool CMCMark(JSTaggedType addr);
36     bool IsMarked(JSTaggedType addr);
37     bool IsCMCMarked(JSTaggedType addr);
38     void Clear();
39     void IterateMarked(const std::function<void(JSTaggedType)> &cb);
40     void IterateCMCMarked(const std::function<void(JSTaggedType)> &cb);
41 
Count()42     uint32_t Count() const
43     {
44         return count_;
45     }
46 
47 private:
48     static constexpr size_t BITSET_SIZE = DEFAULT_REGION_SIZE >> TAGGED_TYPE_SIZE_LOG;
49     static constexpr size_t CMC_BITSET_SIZE = common::RegionDesc::UNIT_SIZE >> TAGGED_TYPE_SIZE_LOG;
50     CUnorderedMap<Region *, std::bitset<BITSET_SIZE>> regionBitsetMap_ {};
51     CUnorderedMap<JSTaggedType, std::bitset<CMC_BITSET_SIZE>> cmcRegionBitsetMap_ {};
52     uint32_t count_ {0};
53 };
54 }  // namespace panda::ecmascript
55 #endif  // ECMASCRIPT_DFX_HPROF_HEAP_MARKER_H
56