blob: 43151dd4254074d31065ad6a7845ec9470a8bc1c [file] [log] [blame]
Mathieu Chartier4e305412014-02-19 10:54:44 -08001/*
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_INL_H_
18#define ART_RUNTIME_VERIFY_OBJECT_INL_H_
19
20#include "verify_object.h"
21
22#include "gc/heap.h"
Mathieu Chartier4e305412014-02-19 10:54:44 -080023#include "mirror/object-inl.h"
Mathieu Chartiera058fdf2016-10-06 15:13:58 -070024#include "obj_ptr-inl.h"
Mathieu Chartier4e305412014-02-19 10:54:44 -080025
26namespace art {
27
Mathieu Chartiera058fdf2016-10-06 15:13:58 -070028inline void VerifyObject(ObjPtr<mirror::Object> obj) {
Mathieu Chartier4e305412014-02-19 10:54:44 -080029 if (kVerifyObjectSupport > kVerifyObjectModeDisabled && obj != nullptr) {
30 if (kVerifyObjectSupport > kVerifyObjectModeFast) {
31 // Slow object verification, try the heap right away.
Mathieu Chartier9d156d52016-10-06 17:44:26 -070032 Runtime::Current()->GetHeap()->VerifyObjectBody(obj);
Mathieu Chartier4e305412014-02-19 10:54:44 -080033 } else {
34 // Fast object verification, only call the heap if our quick sanity tests fail. The heap will
35 // print the diagnostic message.
Mathieu Chartiera058fdf2016-10-06 15:13:58 -070036 bool failed = !IsAligned<kObjectAlignment>(obj.Ptr());
Mathieu Chartier4e305412014-02-19 10:54:44 -080037 if (!failed) {
38 mirror::Class* c = obj->GetClass<kVerifyNone>();
Mathieu Chartierafe49982014-03-27 10:55:04 -070039 failed = failed || !IsAligned<kObjectAlignment>(c);
40 failed = failed || !VerifyClassClass(c);
Mathieu Chartier4e305412014-02-19 10:54:44 -080041 }
42 if (UNLIKELY(failed)) {
Mathieu Chartier9d156d52016-10-06 17:44:26 -070043 Runtime::Current()->GetHeap()->VerifyObjectBody(obj);
Mathieu Chartier4e305412014-02-19 10:54:44 -080044 }
45 }
46 }
47}
48
Mathieu Chartiera058fdf2016-10-06 15:13:58 -070049inline bool VerifyClassClass(ObjPtr<mirror::Class> c) {
Mathieu Chartier4e305412014-02-19 10:54:44 -080050 if (UNLIKELY(c == nullptr)) {
51 return false;
52 }
53 // Note: We pass in flags to ensure that the accessors don't call VerifyObject.
54 mirror::Class* c_c = c->GetClass<kVerifyNone>();
55 return c_c != nullptr && c_c == c_c->GetClass<kVerifyNone>();
56}
57
58} // namespace art
59
60#endif // ART_RUNTIME_VERIFY_OBJECT_INL_H_