19d04a20bde1b1855cefc64aebc1a44e253b1a13bHiroshi Yamauchi/*
29d04a20bde1b1855cefc64aebc1a44e253b1a13bHiroshi Yamauchi * Copyright (C) 2014 The Android Open Source Project
39d04a20bde1b1855cefc64aebc1a44e253b1a13bHiroshi Yamauchi *
49d04a20bde1b1855cefc64aebc1a44e253b1a13bHiroshi Yamauchi * Licensed under the Apache License, Version 2.0 (the "License");
59d04a20bde1b1855cefc64aebc1a44e253b1a13bHiroshi Yamauchi * you may not use this file except in compliance with the License.
69d04a20bde1b1855cefc64aebc1a44e253b1a13bHiroshi Yamauchi * You may obtain a copy of the License at
79d04a20bde1b1855cefc64aebc1a44e253b1a13bHiroshi Yamauchi *
89d04a20bde1b1855cefc64aebc1a44e253b1a13bHiroshi Yamauchi *      http://www.apache.org/licenses/LICENSE-2.0
99d04a20bde1b1855cefc64aebc1a44e253b1a13bHiroshi Yamauchi *
109d04a20bde1b1855cefc64aebc1a44e253b1a13bHiroshi Yamauchi * Unless required by applicable law or agreed to in writing, software
119d04a20bde1b1855cefc64aebc1a44e253b1a13bHiroshi Yamauchi * distributed under the License is distributed on an "AS IS" BASIS,
129d04a20bde1b1855cefc64aebc1a44e253b1a13bHiroshi Yamauchi * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
139d04a20bde1b1855cefc64aebc1a44e253b1a13bHiroshi Yamauchi * See the License for the specific language governing permissions and
149d04a20bde1b1855cefc64aebc1a44e253b1a13bHiroshi Yamauchi * limitations under the License.
159d04a20bde1b1855cefc64aebc1a44e253b1a13bHiroshi Yamauchi */
169d04a20bde1b1855cefc64aebc1a44e253b1a13bHiroshi Yamauchi
17624468cd401cc1ac0dd70c746301e0788a597759Hiroshi Yamauchi#ifndef ART_RUNTIME_READ_BARRIER_H_
18624468cd401cc1ac0dd70c746301e0788a597759Hiroshi Yamauchi#define ART_RUNTIME_READ_BARRIER_H_
199d04a20bde1b1855cefc64aebc1a44e253b1a13bHiroshi Yamauchi
20800ac2defde5d12b2f1f313c6b6162560cfa6fc7Hiroshi Yamauchi#include "base/mutex.h"
21800ac2defde5d12b2f1f313c6b6162560cfa6fc7Hiroshi Yamauchi#include "base/macros.h"
22800ac2defde5d12b2f1f313c6b6162560cfa6fc7Hiroshi Yamauchi#include "offsets.h"
23800ac2defde5d12b2f1f313c6b6162560cfa6fc7Hiroshi Yamauchi#include "read_barrier_c.h"
249d04a20bde1b1855cefc64aebc1a44e253b1a13bHiroshi Yamauchi
25800ac2defde5d12b2f1f313c6b6162560cfa6fc7Hiroshi Yamauchi// This is a C++ (not C) header file, separate from read_barrier_c.h
26800ac2defde5d12b2f1f313c6b6162560cfa6fc7Hiroshi Yamauchi// which needs to be a C header file for asm_support.h.
279d04a20bde1b1855cefc64aebc1a44e253b1a13bHiroshi Yamauchi
28800ac2defde5d12b2f1f313c6b6162560cfa6fc7Hiroshi Yamauchinamespace art {
29800ac2defde5d12b2f1f313c6b6162560cfa6fc7Hiroshi Yamauchinamespace mirror {
30800ac2defde5d12b2f1f313c6b6162560cfa6fc7Hiroshi Yamauchi  class Object;
31800ac2defde5d12b2f1f313c6b6162560cfa6fc7Hiroshi Yamauchi  template<typename MirrorType> class HeapReference;
32800ac2defde5d12b2f1f313c6b6162560cfa6fc7Hiroshi Yamauchi}  // namespace mirror
33624468cd401cc1ac0dd70c746301e0788a597759Hiroshi Yamauchi
34800ac2defde5d12b2f1f313c6b6162560cfa6fc7Hiroshi Yamauchiclass ReadBarrier {
35800ac2defde5d12b2f1f313c6b6162560cfa6fc7Hiroshi Yamauchi public:
36ea2e1bd713ca8295ba4fcd01e77a3ce532ea61e4Hiroshi Yamauchi  // It's up to the implementation whether the given field gets
37ea2e1bd713ca8295ba4fcd01e77a3ce532ea61e4Hiroshi Yamauchi  // updated whereas the return value must be an updated reference.
386e83c172f385cb45dd13bbcf41d2df8e410828c6Hiroshi Yamauchi  template <typename MirrorType, ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
39800ac2defde5d12b2f1f313c6b6162560cfa6fc7Hiroshi Yamauchi  ALWAYS_INLINE static MirrorType* Barrier(
40800ac2defde5d12b2f1f313c6b6162560cfa6fc7Hiroshi Yamauchi      mirror::Object* obj, MemberOffset offset, mirror::HeapReference<MirrorType>* ref_addr)
41800ac2defde5d12b2f1f313c6b6162560cfa6fc7Hiroshi Yamauchi      SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
424cba0d979a11f955e6ec3c0f1bf61478af7aa810Hiroshi Yamauchi
43ea2e1bd713ca8295ba4fcd01e77a3ce532ea61e4Hiroshi Yamauchi  // It's up to the implementation whether the given root gets updated
44ea2e1bd713ca8295ba4fcd01e77a3ce532ea61e4Hiroshi Yamauchi  // whereas the return value must be an updated reference.
454cba0d979a11f955e6ec3c0f1bf61478af7aa810Hiroshi Yamauchi  template <typename MirrorType, ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
46a91a4bc1f8960f64c5f7e4616d46e21b8e1bfba2Hiroshi Yamauchi  ALWAYS_INLINE static MirrorType* BarrierForRoot(MirrorType** root)
474cba0d979a11f955e6ec3c0f1bf61478af7aa810Hiroshi Yamauchi      SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
48800ac2defde5d12b2f1f313c6b6162560cfa6fc7Hiroshi Yamauchi};
49624468cd401cc1ac0dd70c746301e0788a597759Hiroshi Yamauchi
50800ac2defde5d12b2f1f313c6b6162560cfa6fc7Hiroshi Yamauchi}  // namespace art
51624468cd401cc1ac0dd70c746301e0788a597759Hiroshi Yamauchi
52624468cd401cc1ac0dd70c746301e0788a597759Hiroshi Yamauchi#endif  // ART_RUNTIME_READ_BARRIER_H_
53