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