blob: d52365df6dd705b5eb2db8ff1457e6d5855431f9 [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"
21
22namespace art {
23
24template<class Visitor>
25void ClassTable::VisitRoots(Visitor& visitor) {
Mathieu Chartier1609e3a2016-04-05 14:36:57 -070026 ReaderMutexLock mu(Thread::Current(), lock_);
Mathieu Chartiere4275c02015-08-06 15:34:15 -070027 for (ClassSet& class_set : classes_) {
28 for (GcRoot<mirror::Class>& root : class_set) {
29 visitor.VisitRoot(root.AddressWithoutBarrier());
30 }
31 }
Mathieu Chartierc9dbb1d2016-06-03 17:47:32 -070032 for (GcRoot<mirror::Object>& root : strong_roots_) {
Mathieu Chartier1aa8ec22016-02-01 10:34:47 -080033 visitor.VisitRoot(root.AddressWithoutBarrier());
34 }
Mathieu Chartiere4275c02015-08-06 15:34:15 -070035}
36
37template<class Visitor>
38void ClassTable::VisitRoots(const Visitor& visitor) {
Mathieu Chartier1609e3a2016-04-05 14:36:57 -070039 ReaderMutexLock mu(Thread::Current(), lock_);
Mathieu Chartiere4275c02015-08-06 15:34:15 -070040 for (ClassSet& class_set : classes_) {
41 for (GcRoot<mirror::Class>& root : class_set) {
42 visitor.VisitRoot(root.AddressWithoutBarrier());
43 }
44 }
Mathieu Chartierc9dbb1d2016-06-03 17:47:32 -070045 for (GcRoot<mirror::Object>& root : strong_roots_) {
Mathieu Chartier00310e02015-10-17 12:46:42 -070046 visitor.VisitRoot(root.AddressWithoutBarrier());
47 }
Mathieu Chartiere4275c02015-08-06 15:34:15 -070048}
49
Mathieu Chartier1aa8ec22016-02-01 10:34:47 -080050template <typename Visitor>
51bool ClassTable::Visit(Visitor& visitor) {
Mathieu Chartier1609e3a2016-04-05 14:36:57 -070052 ReaderMutexLock mu(Thread::Current(), lock_);
Mathieu Chartier1aa8ec22016-02-01 10:34:47 -080053 for (ClassSet& class_set : classes_) {
54 for (GcRoot<mirror::Class>& root : class_set) {
55 if (!visitor(root.Read())) {
56 return false;
57 }
58 }
59 }
60 return true;
61}
62
63
Mathieu Chartiere4275c02015-08-06 15:34:15 -070064} // namespace art
65
66#endif // ART_RUNTIME_CLASS_TABLE_INL_H_