blob: 390ed3c664b8670be92dd035d1647b8b55dc9c16 [file] [log] [blame]
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -07001/*
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_GC_ROOT_INL_H_
18#define ART_RUNTIME_GC_ROOT_INL_H_
19
20#include "gc_root.h"
21
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -070022#include <sstream>
23
Mathieu Chartier3398c782016-09-30 10:27:43 -070024#include "obj_ptr-inl.h"
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -070025#include "read_barrier-inl.h"
26
27namespace art {
28
29template<class MirrorType>
30template<ReadBarrierOption kReadBarrierOption>
Hiroshi Yamauchi3f64f252015-06-12 18:35:06 -070031inline MirrorType* GcRoot<MirrorType>::Read(GcRootSource* gc_root_source) const {
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -070032 return down_cast<MirrorType*>(
Hiroshi Yamauchi3f64f252015-06-12 18:35:06 -070033 ReadBarrier::BarrierForRoot<mirror::Object, kReadBarrierOption>(&root_, gc_root_source));
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -070034}
Mathieu Chartier3398c782016-09-30 10:27:43 -070035
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -070036template<class MirrorType>
37inline GcRoot<MirrorType>::GcRoot(MirrorType* ref)
38 : root_(mirror::CompressedReference<mirror::Object>::FromMirrorPtr(ref)) { }
39
Mathieu Chartier3398c782016-09-30 10:27:43 -070040template<class MirrorType>
41inline GcRoot<MirrorType>::GcRoot(ObjPtr<MirrorType, kIsDebugBuild> ref)
Mathieu Chartier1cc62e42016-10-03 18:01:28 -070042 : GcRoot(ref.Ptr()) { }
Mathieu Chartier3398c782016-09-30 10:27:43 -070043
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -070044inline std::string RootInfo::ToString() const {
45 std::ostringstream oss;
46 Describe(oss);
47 return oss.str();
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -070048}
49
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -070050} // namespace art
51#endif // ART_RUNTIME_GC_ROOT_INL_H_