blob: 6b456fd349c0f70b4102b3698d87c50f971cdde1 [file] [log] [blame]
Mathieu Chartier1ca68902017-04-18 11:26:22 -07001/*
2 * Copyright (C) 2017 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_H_
18#define ART_RUNTIME_GC_VERIFICATION_H_
19
20#include "obj_ptr.h"
21#include "offsets.h"
22
23namespace art {
24
25namespace mirror {
26class Class;
27class Object;
28} // namespace mirror
29
30namespace gc {
31
32namespace space {
33class Space;
34} // namespace space
35
36class Heap;
37
38class Verification {
39 public:
40 explicit Verification(gc::Heap* heap) : heap_(heap) {}
41
42 // Dump some reveant to debugging info about an object.
43 std::string DumpObjectInfo(const void* obj, const char* tag) const
44 REQUIRES_SHARED(Locks::mutator_lock_);
45
46 // Don't use ObjPtr for things that might not be aligned like the invalid reference.
47 void LogHeapCorruption(ObjPtr<mirror::Object> holder,
48 MemberOffset offset,
49 mirror::Object* ref,
50 bool fatal) const REQUIRES_SHARED(Locks::mutator_lock_);
51
Mathieu Chartier1ca68902017-04-18 11:26:22 -070052 // Return true if the klass is likely to be a valid mirror::Class.
53 bool IsValidClass(const void* klass) const REQUIRES_SHARED(Locks::mutator_lock_);
54
Mathieu Chartierb814ef52017-06-27 12:56:00 -070055 // Does not allow null, checks alignment.
Mathieu Chartier1ca68902017-04-18 11:26:22 -070056 bool IsValidHeapObjectAddress(const void* addr, space::Space** out_space = nullptr) const
57 REQUIRES_SHARED(Locks::mutator_lock_);
58
Mathieu Chartier4f5e3cb2017-06-12 13:10:01 -070059 // Find the first path to the target from the root set. Should be called while paused since
60 // visiting roots is not safe otherwise.
61 std::string FirstPathFromRootSet(ObjPtr<mirror::Object> target) const
62 REQUIRES_SHARED(Locks::mutator_lock_);
63
Mathieu Chartierb814ef52017-06-27 12:56:00 -070064 // Does not check alignment, used by DumpRAMAroundAddress.
65 bool IsAddressInHeapSpace(const void* addr, space::Space** out_space = nullptr) const
66 REQUIRES_SHARED(Locks::mutator_lock_);
67
68 // Dump bytes of RAM before and after an address.
69 std::string DumpRAMAroundAddress(uintptr_t addr, uintptr_t bytes) const
70 REQUIRES_SHARED(Locks::mutator_lock_);
71
Mathieu Chartier1ca68902017-04-18 11:26:22 -070072 private:
73 gc::Heap* const heap_;
Mathieu Chartier4f5e3cb2017-06-12 13:10:01 -070074
75 class BFSFindReachable;
76 class CollectRootVisitor;
Mathieu Chartier1ca68902017-04-18 11:26:22 -070077};
78
79} // namespace gc
80} // namespace art
81
82#endif // ART_RUNTIME_GC_VERIFICATION_H_