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 #include "read_barrier_option.h" 23 24 namespace art { 25 26 namespace mirror { 27 class Class; 28 class Object; 29 } // namespace mirror 30 31 namespace gc { 32 33 namespace space { 34 class Space; 35 } // namespace space 36 37 class Heap; 38 39 class Verification { 40 public: Verification(gc::Heap * heap)41 explicit Verification(gc::Heap* heap) : heap_(heap) {} 42 43 // Dump some reveant to debugging info about an object. 44 std::string DumpObjectInfo(const void* obj, const char* tag) const 45 REQUIRES_SHARED(Locks::mutator_lock_); 46 47 // Don't use ObjPtr for things that might not be aligned like the invalid reference. 48 void LogHeapCorruption(ObjPtr<mirror::Object> holder, 49 MemberOffset offset, 50 mirror::Object* ref, 51 bool fatal) const REQUIRES_SHARED(Locks::mutator_lock_); 52 53 // Return true if the klass is likely to be a valid mirror::Class. 54 // Returns true if the class is a valid mirror::Class or possibly spuriously. 55 template <ReadBarrierOption kReadBarrierOption = kWithoutReadBarrier> 56 bool IsValidClassUnchecked(mirror::Class* klass) const 57 REQUIRES_SHARED(Locks::mutator_lock_); 58 // Return true if the klass is likely to be a valid mirror::Class. 59 template <ReadBarrierOption kReadBarrierOption = kWithoutReadBarrier> 60 bool IsValidClass(mirror::Class* klass) const REQUIRES_SHARED(Locks::mutator_lock_); 61 // Return true if the obj is likely to be a valid obj with valid mirror::Class. 62 template <ReadBarrierOption kReadBarrierOption = kWithoutReadBarrier> 63 bool IsValidObject(mirror::Object* obj) const REQUIRES_SHARED(Locks::mutator_lock_); 64 65 // Does not allow null, checks alignment. 66 bool IsValidHeapObjectAddress(const void* addr, space::Space** out_space = nullptr) const 67 REQUIRES_SHARED(Locks::mutator_lock_); 68 69 // Find the first path to the target from the root set. Should be called while paused since 70 // visiting roots is not safe otherwise. 71 std::string FirstPathFromRootSet(ObjPtr<mirror::Object> target) const 72 REQUIRES_SHARED(Locks::mutator_lock_); 73 74 // Does not check alignment, used by DumpRAMAroundAddress. 75 bool IsAddressInHeapSpace(const void* addr, space::Space** out_space = nullptr) const 76 REQUIRES_SHARED(Locks::mutator_lock_); 77 78 // Dump bytes of RAM before and after an address. 79 std::string DumpRAMAroundAddress(uintptr_t addr, uintptr_t bytes) const 80 REQUIRES_SHARED(Locks::mutator_lock_); 81 82 private: 83 gc::Heap* const heap_; 84 85 class BFSFindReachable; 86 class CollectRootVisitor; 87 }; 88 89 } // namespace gc 90 } // namespace art 91 92 #endif // ART_RUNTIME_GC_VERIFICATION_H_ 93