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 
53   // Return true if the klass is likely to be a valid mirror::Class.
54   bool IsValidClass(const void* klass) const REQUIRES_SHARED(Locks::mutator_lock_);
55 
56   // Does not allow null.
57   bool IsValidHeapObjectAddress(const void* addr, space::Space** out_space = nullptr) const
58       REQUIRES_SHARED(Locks::mutator_lock_);
59 
60  private:
61   gc::Heap* const heap_;
62 };
63 
64 }  // namespace gc
65 }  // namespace art
66 
67 #endif  // ART_RUNTIME_GC_VERIFICATION_H_
68