1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef ART_RUNTIME_GC_VERIFICATION_H_
18 #define ART_RUNTIME_GC_VERIFICATION_H_
19 
20 #include "obj_ptr.h"
21 #include "offsets.h"
22 
23 namespace art {
24 
25 namespace mirror {
26 class Class;
27 class Object;
28 }  // namespace mirror
29 
30 namespace gc {
31 
32 namespace space {
33 class Space;
34 }  // namespace space
35 
36 class Heap;
37 
38 class Verification {
39  public:
Verification(gc::Heap * heap)40   explicit Verification(gc::Heap* heap) : heap_(heap) {}
41 
42   // Dump some reveant to debugging info about an object.
43   std::string DumpObjectInfo(const void* obj, const char* tag) const
44       REQUIRES_SHARED(Locks::mutator_lock_);
45 
46   // Don't use ObjPtr for things that might not be aligned like the invalid reference.
47   void LogHeapCorruption(ObjPtr<mirror::Object> holder,
48                          MemberOffset offset,
49                          mirror::Object* ref,
50                          bool fatal) const REQUIRES_SHARED(Locks::mutator_lock_);
51 
52   // Return true if the klass is likely to be a valid mirror::Class.
53   bool IsValidClass(const void* klass) const REQUIRES_SHARED(Locks::mutator_lock_);
54 
55   // Does not allow null, checks alignment.
56   bool IsValidHeapObjectAddress(const void* addr, space::Space** out_space = nullptr) const
57       REQUIRES_SHARED(Locks::mutator_lock_);
58 
59   // Find the first path to the target from the root set. Should be called while paused since
60   // visiting roots is not safe otherwise.
61   std::string FirstPathFromRootSet(ObjPtr<mirror::Object> target) const
62       REQUIRES_SHARED(Locks::mutator_lock_);
63 
64   // Does not check alignment, used by DumpRAMAroundAddress.
65   bool IsAddressInHeapSpace(const void* addr, space::Space** out_space = nullptr) const
66       REQUIRES_SHARED(Locks::mutator_lock_);
67 
68   // Dump bytes of RAM before and after an address.
69   std::string DumpRAMAroundAddress(uintptr_t addr, uintptr_t bytes) const
70       REQUIRES_SHARED(Locks::mutator_lock_);
71 
72  private:
73   gc::Heap* const heap_;
74 
75   class BFSFindReachable;
76   class CollectRootVisitor;
77 };
78 
79 }  // namespace gc
80 }  // namespace art
81 
82 #endif  // ART_RUNTIME_GC_VERIFICATION_H_
83