Mathieu Chartier | 1ca6890 | 2017-04-18 11:26:22 -0700 | [diff] [blame] | 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: |
| 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 | |
Mathieu Chartier | 1ca6890 | 2017-04-18 11:26:22 -0700 | [diff] [blame] | 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 | |
Mathieu Chartier | b814ef5 | 2017-06-27 12:56:00 -0700 | [diff] [blame] | 55 | // Does not allow null, checks alignment. |
Mathieu Chartier | 1ca6890 | 2017-04-18 11:26:22 -0700 | [diff] [blame] | 56 | bool IsValidHeapObjectAddress(const void* addr, space::Space** out_space = nullptr) const |
| 57 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 58 | |
Mathieu Chartier | 4f5e3cb | 2017-06-12 13:10:01 -0700 | [diff] [blame] | 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 | |
Mathieu Chartier | b814ef5 | 2017-06-27 12:56:00 -0700 | [diff] [blame] | 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 | |
Mathieu Chartier | 1ca6890 | 2017-04-18 11:26:22 -0700 | [diff] [blame] | 72 | private: |
| 73 | gc::Heap* const heap_; |
Mathieu Chartier | 4f5e3cb | 2017-06-12 13:10:01 -0700 | [diff] [blame] | 74 | |
| 75 | class BFSFindReachable; |
| 76 | class CollectRootVisitor; |
Mathieu Chartier | 1ca6890 | 2017-04-18 11:26:22 -0700 | [diff] [blame] | 77 | }; |
| 78 | |
| 79 | } // namespace gc |
| 80 | } // namespace art |
| 81 | |
| 82 | #endif // ART_RUNTIME_GC_VERIFICATION_H_ |