1/*
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
20#include "base/mutex.h"
21#include "base/macros.h"
22#include "offsets.h"
23#include "read_barrier_c.h"
24
25// 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.
27
28namespace art {
29namespace mirror {
30  class Object;
31  template<typename MirrorType> class HeapReference;
32}  // namespace mirror
33
34class ReadBarrier {
35 public:
36  // It's up to the implementation whether the given field gets
37  // updated whereas the return value must be an updated reference.
38  template <typename MirrorType, ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
39  ALWAYS_INLINE static MirrorType* Barrier(
40      mirror::Object* obj, MemberOffset offset, mirror::HeapReference<MirrorType>* ref_addr)
41      SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
42
43  // It's up to the implementation whether the given root gets updated
44  // whereas the return value must be an updated reference.
45  template <typename MirrorType, ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
46  ALWAYS_INLINE static MirrorType* BarrierForRoot(MirrorType** root)
47      SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
48};
49
50}  // namespace art
51
52#endif  // ART_RUNTIME_READ_BARRIER_H_
53