blob: ed5db4e4a545550db381be9af7c5bff433d7793a [file] [log] [blame]
Hiroshi Yamauchi624468c2014-03-31 15:14:47 -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_READ_BARRIER_H_
18#define ART_RUNTIME_READ_BARRIER_H_
19
Hiroshi Yamauchi800ac2d2014-04-02 17:32:54 -070020#include "base/mutex.h"
21#include "base/macros.h"
22#include "offsets.h"
23#include "read_barrier_c.h"
Hiroshi Yamauchi624468c2014-03-31 15:14:47 -070024
Hiroshi Yamauchi800ac2d2014-04-02 17:32:54 -070025// This is a C++ (not C) header file, separate from read_barrier_c.h
26// which needs to be a C header file for asm_support.h.
Hiroshi Yamauchi624468c2014-03-31 15:14:47 -070027
Hiroshi Yamauchi800ac2d2014-04-02 17:32:54 -070028namespace art {
29namespace mirror {
30 class Object;
31 template<typename MirrorType> class HeapReference;
32} // namespace mirror
Hiroshi Yamauchi624468c2014-03-31 15:14:47 -070033
Hiroshi Yamauchi800ac2d2014-04-02 17:32:54 -070034class ReadBarrier {
35 public:
Hiroshi Yamauchiea2e1bd2014-06-18 13:47:35 -070036 // It's up to the implementation whether the given field gets
37 // updated whereas the return value must be an updated reference.
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -070038 template <typename MirrorType, ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Hiroshi Yamauchi800ac2d2014-04-02 17:32:54 -070039 ALWAYS_INLINE static MirrorType* Barrier(
40 mirror::Object* obj, MemberOffset offset, mirror::HeapReference<MirrorType>* ref_addr)
41 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Hiroshi Yamauchi4cba0d92014-05-21 21:10:23 -070042
Hiroshi Yamauchiea2e1bd2014-06-18 13:47:35 -070043 // It's up to the implementation whether the given root gets updated
44 // whereas the return value must be an updated reference.
Hiroshi Yamauchi4cba0d92014-05-21 21:10:23 -070045 template <typename MirrorType, ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Hiroshi Yamauchia91a4bc2014-06-13 16:44:55 -070046 ALWAYS_INLINE static MirrorType* BarrierForRoot(MirrorType** root)
Hiroshi Yamauchi4cba0d92014-05-21 21:10:23 -070047 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Hiroshi Yamauchi800ac2d2014-04-02 17:32:54 -070048};
Hiroshi Yamauchi624468c2014-03-31 15:14:47 -070049
Hiroshi Yamauchi800ac2d2014-04-02 17:32:54 -070050} // namespace art
Hiroshi Yamauchi624468c2014-03-31 15:14:47 -070051
52#endif // ART_RUNTIME_READ_BARRIER_H_