blob: 39df375e1f964c956298307e0220d01a7ac8bed0 [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"
23#include "mirror/class-inl.h"
24#include "mirror/object-inl.h"
25
26namespace art {
27
28inline void VerifyObject(mirror::Object* obj) {
29 if (kVerifyObjectSupport > kVerifyObjectModeDisabled && obj != nullptr) {
30 if (kVerifyObjectSupport > kVerifyObjectModeFast) {
31 // Slow object verification, try the heap right away.
32 Runtime::Current()->GetHeap()->VerifyObjectBody(obj);
33 } else {
34 // Fast object verification, only call the heap if our quick sanity tests fail. The heap will
35 // print the diagnostic message.
36 bool failed = !IsAligned<kObjectAlignment>(obj);
37 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)) {
43 Runtime::Current()->GetHeap()->VerifyObjectBody(obj);
44 }
45 }
46 }
47}
48
49inline bool VerifyClassClass(mirror::Class* c) {
50 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_