1 /* 2 * Copyright 2021 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_INL_H_ 18 #define ART_RUNTIME_GC_VERIFICATION_INL_H_ 19 20 #include "verification.h" 21 22 #include "mirror/class-inl.h" 23 24 namespace art HIDDEN { 25 namespace gc { 26 27 template <ReadBarrierOption kReadBarrierOption> IsValidClassUnchecked(mirror::Class * klass)28bool Verification::IsValidClassUnchecked(mirror::Class* klass) const { 29 mirror::Class* k1 = klass->GetClass<kVerifyNone, kReadBarrierOption>(); 30 if (!IsValidHeapObjectAddress(k1)) { 31 return false; 32 } 33 // `k1` should be class class, take the class again to verify. 34 // Note that this check may not be valid for the no image space 35 // since the class class might move around from moving GC. 36 mirror::Class* k2 = k1->GetClass<kVerifyNone, kReadBarrierOption>(); 37 if (!IsValidHeapObjectAddress(k2)) { 38 return false; 39 } 40 return k1 == k2; 41 } 42 43 template <ReadBarrierOption kReadBarrierOption> IsValidClass(mirror::Class * klass)44bool Verification::IsValidClass(mirror::Class* klass) const { 45 if (!IsValidHeapObjectAddress(klass)) { 46 return false; 47 } 48 return IsValidClassUnchecked<kReadBarrierOption>(klass); 49 } 50 51 template <ReadBarrierOption kReadBarrierOption> IsValidObject(mirror::Object * obj)52bool Verification::IsValidObject(mirror::Object* obj) const { 53 if (!IsValidHeapObjectAddress(obj)) { 54 return false; 55 } 56 mirror::Class* klass = obj->GetClass<kVerifyNone, kReadBarrierOption>(); 57 return IsValidClass(klass); 58 } 59 60 } // namespace gc 61 } // namespace art 62 63 #endif // ART_RUNTIME_GC_VERIFICATION_INL_H_ 64