• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 
16 #ifndef ECMASCRIPT_MEM_REMEMBERED_SET_H
17 #define ECMASCRIPT_MEM_REMEMBERED_SET_H
18 
19 #include "ecmascript/mem/gc_bitset.h"
20 
21 namespace panda::ecmascript {
22 class RememberedSet {
23 public:
24     static constexpr size_t GCBITSET_DATA_OFFSET = sizeof(size_t);
RememberedSet(size_t size)25     explicit RememberedSet(size_t size) : size_(size) {}
26 
27     NO_COPY_SEMANTIC(RememberedSet);
28     NO_MOVE_SEMANTIC(RememberedSet);
29 
GCBitsetData()30     GCBitset *GCBitsetData()
31     {
32         return reinterpret_cast<GCBitset *>(reinterpret_cast<uintptr_t>(this) + GCBITSET_DATA_OFFSET);
33     }
34 
GCBitsetData()35     const GCBitset *GCBitsetData() const
36     {
37         return reinterpret_cast<GCBitset *>(reinterpret_cast<uintptr_t>(this) + GCBITSET_DATA_OFFSET);
38     }
39 
ClearAll()40     void ClearAll()
41     {
42         GCBitsetData()->Clear(size_);
43     }
44 
Insert(uintptr_t begin,uintptr_t addr)45     bool Insert(uintptr_t begin, uintptr_t addr)
46     {
47         return GCBitsetData()->SetBit<AccessType::NON_ATOMIC>((addr - begin) >> TAGGED_TYPE_SIZE_LOG);
48     }
49 
AtomicInsert(uintptr_t begin,uintptr_t addr)50     bool AtomicInsert(uintptr_t begin, uintptr_t addr)
51     {
52         return GCBitsetData()->SetBit<AccessType::ATOMIC>((addr - begin) >> TAGGED_TYPE_SIZE_LOG);
53     }
54 
ClearBit(uintptr_t begin,uintptr_t addr)55     void ClearBit(uintptr_t begin, uintptr_t addr)
56     {
57         GCBitsetData()->ClearBit((addr - begin) >> TAGGED_TYPE_SIZE_LOG);
58     }
59 
ClearRange(uintptr_t begin,uintptr_t start,uintptr_t end)60     void ClearRange(uintptr_t begin, uintptr_t start, uintptr_t end)
61     {
62         GCBitsetData()->ClearBitRange<AccessType::NON_ATOMIC>(
63             (start - begin) >> TAGGED_TYPE_SIZE_LOG, (end - begin) >> TAGGED_TYPE_SIZE_LOG);
64     }
65 
AtomicClearRange(uintptr_t begin,uintptr_t start,uintptr_t end)66     void AtomicClearRange(uintptr_t begin, uintptr_t start, uintptr_t end)
67     {
68         GCBitsetData()->ClearBitRange<AccessType::ATOMIC>(
69             (start - begin) >> TAGGED_TYPE_SIZE_LOG, (end - begin) >> TAGGED_TYPE_SIZE_LOG);
70     }
71 
72     template <typename Visitor>
IterateAllMarkedBits(uintptr_t begin,Visitor visitor)73     void IterateAllMarkedBits(uintptr_t begin, Visitor visitor)
74     {
75         GCBitsetData()->IterateMarkedBits<Visitor, AccessType::NON_ATOMIC>(begin, size_, visitor);
76     }
77 
78     template <typename Visitor>
AtomicIterateAllMarkedBits(uintptr_t begin,Visitor visitor)79     void AtomicIterateAllMarkedBits(uintptr_t begin, Visitor visitor)
80     {
81         GCBitsetData()->IterateMarkedBits<Visitor, AccessType::ATOMIC>(begin, size_, visitor);
82     }
83 
84     template <typename Visitor>
IterateAllMarkedBitsConst(uintptr_t begin,Visitor visitor)85     void IterateAllMarkedBitsConst(uintptr_t begin, Visitor visitor) const
86     {
87         GCBitsetData()->IterateMarkedBitsConst(begin, size_, visitor);
88     }
89 
Merge(RememberedSet * rset)90     void Merge(RememberedSet *rset)
91     {
92         GCBitset *bitset = rset->GCBitsetData();
93         GCBitsetData()->Merge(bitset, size_);
94     }
95 
Size()96     size_t Size() const
97     {
98         return size_ + GCBITSET_DATA_OFFSET;
99     }
100 
101 private:
102     size_t size_;
103 };
104 }  // namespace panda::ecmascript
105 #endif  // ECMASCRIPT_MEM_REMEMBERED_SET_H
106