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