1 /* 2 * Copyright (C) 2014 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_VERIFY_OBJECT_H_ 18 #define ART_RUNTIME_VERIFY_OBJECT_H_ 19 20 #include <stdint.h> 21 22 #include "base/macros.h" 23 #include "obj_ptr.h" 24 25 namespace art { 26 27 namespace mirror { 28 class Class; 29 class Object; 30 } // namespace mirror 31 32 // How we want to sanity check the heap's correctness. 33 enum VerifyObjectMode { 34 kVerifyObjectModeDisabled, // Heap verification is disabled. 35 kVerifyObjectModeFast, // Sanity heap accesses quickly by using VerifyClassClass. 36 kVerifyObjectModeAll // Sanity heap accesses thoroughly. 37 }; 38 39 enum VerifyObjectFlags { 40 kVerifyNone = 0x0, 41 // Verify self when we are doing an operation. 42 kVerifyThis = 0x1, 43 // Verify reads from objects. 44 kVerifyReads = 0x2, 45 // Verify writes to objects. 46 kVerifyWrites = 0x4, 47 // Verify all things. 48 kVerifyAll = kVerifyThis | kVerifyReads | kVerifyWrites, 49 }; 50 51 static constexpr bool kVerifyStack = kIsDebugBuild; 52 static constexpr VerifyObjectFlags kDefaultVerifyFlags = kVerifyNone; 53 static constexpr VerifyObjectMode kVerifyObjectSupport = 54 kDefaultVerifyFlags != 0 ? kVerifyObjectModeFast : kVerifyObjectModeDisabled; 55 56 // Implements the actual object checks. 57 void VerifyObjectImpl(ObjPtr<mirror::Object> obj) NO_THREAD_SAFETY_ANALYSIS; 58 59 // Is a front to optimize out any calls if no verification is enabled. 60 ALWAYS_INLINE 61 static inline void VerifyObject(ObjPtr<mirror::Object> obj) NO_THREAD_SAFETY_ANALYSIS { 62 if (kVerifyObjectSupport > kVerifyObjectModeDisabled && obj != nullptr) { 63 VerifyObjectImpl(obj); 64 } 65 } 66 67 // Check that c.getClass() == c.getClass().getClass(). 68 ALWAYS_INLINE bool VerifyClassClass(ObjPtr<mirror::Class> c) NO_THREAD_SAFETY_ANALYSIS; 69 70 } // namespace art 71 72 #endif // ART_RUNTIME_VERIFY_OBJECT_H_ 73