blob: 3e54a647dccce0aac2e78541344ff88a72de08ea [file] [log] [blame]
Mathieu Chartiere4275c02015-08-06 15:34:15 -07001/*
2 * Copyright (C) 2015 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_CLASS_TABLE_INL_H_
18#define ART_RUNTIME_CLASS_TABLE_INL_H_
19
20#include "class_table.h"
Vladimir Markoaad75c62016-10-03 08:46:48 +000021#include "oat_file.h"
Mathieu Chartiere4275c02015-08-06 15:34:15 -070022
23namespace art {
24
25template<class Visitor>
26void ClassTable::VisitRoots(Visitor& visitor) {
Mathieu Chartier1609e3a2016-04-05 14:36:57 -070027 ReaderMutexLock mu(Thread::Current(), lock_);
Mathieu Chartiere4275c02015-08-06 15:34:15 -070028 for (ClassSet& class_set : classes_) {
29 for (GcRoot<mirror::Class>& root : class_set) {
30 visitor.VisitRoot(root.AddressWithoutBarrier());
31 }
32 }
Mathieu Chartierc9dbb1d2016-06-03 17:47:32 -070033 for (GcRoot<mirror::Object>& root : strong_roots_) {
Mathieu Chartier1aa8ec22016-02-01 10:34:47 -080034 visitor.VisitRoot(root.AddressWithoutBarrier());
35 }
Vladimir Markoaad75c62016-10-03 08:46:48 +000036 for (const OatFile* oat_file : oat_files_) {
37 for (GcRoot<mirror::Object>& root : oat_file->GetBssGcRoots()) {
38 visitor.VisitRootIfNonNull(root.AddressWithoutBarrier());
39 }
40 }
Mathieu Chartiere4275c02015-08-06 15:34:15 -070041}
42
43template<class Visitor>
44void ClassTable::VisitRoots(const Visitor& visitor) {
Mathieu Chartier1609e3a2016-04-05 14:36:57 -070045 ReaderMutexLock mu(Thread::Current(), lock_);
Mathieu Chartiere4275c02015-08-06 15:34:15 -070046 for (ClassSet& class_set : classes_) {
47 for (GcRoot<mirror::Class>& root : class_set) {
48 visitor.VisitRoot(root.AddressWithoutBarrier());
49 }
50 }
Mathieu Chartierc9dbb1d2016-06-03 17:47:32 -070051 for (GcRoot<mirror::Object>& root : strong_roots_) {
Mathieu Chartier00310e02015-10-17 12:46:42 -070052 visitor.VisitRoot(root.AddressWithoutBarrier());
53 }
Vladimir Markoaad75c62016-10-03 08:46:48 +000054 for (const OatFile* oat_file : oat_files_) {
55 for (GcRoot<mirror::Object>& root : oat_file->GetBssGcRoots()) {
56 visitor.VisitRootIfNonNull(root.AddressWithoutBarrier());
57 }
58 }
Mathieu Chartiere4275c02015-08-06 15:34:15 -070059}
60
Mathieu Chartier1aa8ec22016-02-01 10:34:47 -080061template <typename Visitor>
62bool ClassTable::Visit(Visitor& visitor) {
Mathieu Chartier1609e3a2016-04-05 14:36:57 -070063 ReaderMutexLock mu(Thread::Current(), lock_);
Mathieu Chartier1aa8ec22016-02-01 10:34:47 -080064 for (ClassSet& class_set : classes_) {
65 for (GcRoot<mirror::Class>& root : class_set) {
66 if (!visitor(root.Read())) {
67 return false;
68 }
69 }
70 }
71 return true;
72}
73
74
Mathieu Chartiere4275c02015-08-06 15:34:15 -070075} // namespace art
76
77#endif // ART_RUNTIME_CLASS_TABLE_INL_H_