blob: 5c665b34c454c9de18b0943a49faa119536bd362 [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_H_
18#define ART_RUNTIME_VERIFY_OBJECT_H_
19
Mathieu Chartier4e305412014-02-19 10:54:44 -080020#include <stdint.h>
21
Ian Rogers719d1a32014-03-06 12:13:39 -080022#include "base/macros.h"
Mathieu Chartiera058fdf2016-10-06 15:13:58 -070023#include "obj_ptr.h"
Ian Rogers719d1a32014-03-06 12:13:39 -080024
Mathieu Chartier4e305412014-02-19 10:54:44 -080025namespace art {
26
27namespace mirror {
Igor Murashkin2ffb7032017-11-08 13:35:21 -080028class Class;
29class Object;
Mathieu Chartier4e305412014-02-19 10:54:44 -080030} // namespace mirror
31
32// How we want to sanity check the heap's correctness.
33enum VerifyObjectMode {
34 kVerifyObjectModeDisabled, // Heap verification is disabled.
35 kVerifyObjectModeFast, // Sanity heap accesses quickly by using VerifyClassClass.
36 kVerifyObjectModeAll // Sanity heap accesses thoroughly.
37};
38
39enum 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
Mathieu Chartier4e305412014-02-19 10:54:44 -080051static constexpr VerifyObjectFlags kDefaultVerifyFlags = kVerifyNone;
52static constexpr VerifyObjectMode kVerifyObjectSupport =
53 kDefaultVerifyFlags != 0 ? kVerifyObjectModeFast : kVerifyObjectModeDisabled;
54
Andreas Gampe90b936d2017-01-31 08:58:55 -080055// Implements the actual object checks.
56void VerifyObjectImpl(ObjPtr<mirror::Object> obj) NO_THREAD_SAFETY_ANALYSIS;
57
58// Is a front to optimize out any calls if no verification is enabled.
59ALWAYS_INLINE
60static inline void VerifyObject(ObjPtr<mirror::Object> obj) NO_THREAD_SAFETY_ANALYSIS {
61 if (kVerifyObjectSupport > kVerifyObjectModeDisabled && obj != nullptr) {
62 VerifyObjectImpl(obj);
63 }
64}
Mathieu Chartier4e305412014-02-19 10:54:44 -080065
66// Check that c.getClass() == c.getClass().getClass().
Mathieu Chartiera058fdf2016-10-06 15:13:58 -070067ALWAYS_INLINE bool VerifyClassClass(ObjPtr<mirror::Class> c) NO_THREAD_SAFETY_ANALYSIS;
Mathieu Chartier4e305412014-02-19 10:54:44 -080068
69} // namespace art
70
71#endif // ART_RUNTIME_VERIFY_OBJECT_H_