• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 ECMASCRIPT_MEM_HEAP_VERIFICATION_H
17 #define ECMASCRIPT_MEM_HEAP_VERIFICATION_H
18 
19 #include <cstdint>
20 
21 #include "ecmascript/js_tagged_value.h"
22 #include "ecmascript/mem/heap.h"
23 #include "ecmascript/mem/object_xray.h"
24 #include "ecmascript/mem/mem.h"
25 #include "ecmascript/mem/slots.h"
26 
27 namespace panda::ecmascript {
28 // Verify the object body
29 // NOLINTNEXTLINE(cppcoreguidelines-special-member-functions, hicpp-special-member-functions)
30 class VerifyObjectVisitor {
31 public:
VerifyObjectVisitor(const Heap * heap,size_t * failCount)32     VerifyObjectVisitor(const Heap *heap, size_t *failCount)
33         : heap_(heap), failCount_(failCount), objXRay_(heap->GetEcmaVM())
34     {
35     }
36     ~VerifyObjectVisitor() = default;
37 
operator()38     void operator()(TaggedObject *obj)
39     {
40         VisitAllObjects(obj);
41     }
42 
43     void operator()(TaggedObject *obj, JSTaggedValue value);
44 
GetFailedCount()45     size_t GetFailedCount() const
46     {
47         return *failCount_;
48     }
49 
50 private:
51     void VisitAllObjects(TaggedObject *obj);
52 
53     const Heap* const heap_ {nullptr};
54     size_t* const failCount_ {nullptr};
55     ObjectXRay objXRay_;
56 };
57 
58 class Verification {
59 public:
Verification(const Heap * heap)60     explicit Verification(const Heap *heap) : heap_(heap), objXRay_(heap->GetEcmaVM()) {}
61     ~Verification() = default;
62 
VerifyAll()63     size_t VerifyAll() const
64     {
65         size_t result = VerifyRoot();
66         result += VerifyHeap();
67         return result;
68     }
69 
70     size_t VerifyRoot() const;
71     size_t VerifyHeap() const;
72     size_t VerifyOldToNewRSet() const;
73 private:
74     void VerifyObjectSlot(const ObjectSlot &slot, size_t *failCount) const;
75 
76     NO_COPY_SEMANTIC(Verification);
77     NO_MOVE_SEMANTIC(Verification);
78 
79     const Heap *heap_ {nullptr};
80     ObjectXRay objXRay_;
81 };
82 }  // namespace panda::ecmascript
83 
84 #endif  // ECMASCRIPT_MEM_HEAP_VERIFICATION_H
85