1 /*
2 * Copyright (C) 2018 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_WRITE_BARRIER_INL_H_
18 #define ART_RUNTIME_WRITE_BARRIER_INL_H_
19
20 #include "write_barrier.h"
21
22 #include "gc/accounting/card_table-inl.h"
23 #include "gc/heap.h"
24 #include "obj_ptr-inl.h"
25 #include "runtime.h"
26
27 namespace art {
28
29 template <WriteBarrier::NullCheck kNullCheck>
ForFieldWrite(ObjPtr<mirror::Object> dst,MemberOffset offset ATTRIBUTE_UNUSED,ObjPtr<mirror::Object> new_value)30 inline void WriteBarrier::ForFieldWrite(ObjPtr<mirror::Object> dst,
31 MemberOffset offset ATTRIBUTE_UNUSED,
32 ObjPtr<mirror::Object> new_value) {
33 if (kNullCheck == kWithNullCheck && new_value == nullptr) {
34 return;
35 }
36 DCHECK(new_value != nullptr);
37 GetCardTable()->MarkCard(dst.Ptr());
38 }
39
ForArrayWrite(ObjPtr<mirror::Object> dst,int start_offset ATTRIBUTE_UNUSED,size_t length ATTRIBUTE_UNUSED)40 inline void WriteBarrier::ForArrayWrite(ObjPtr<mirror::Object> dst,
41 int start_offset ATTRIBUTE_UNUSED,
42 size_t length ATTRIBUTE_UNUSED) {
43 GetCardTable()->MarkCard(dst.Ptr());
44 }
45
ForEveryFieldWrite(ObjPtr<mirror::Object> obj)46 inline void WriteBarrier::ForEveryFieldWrite(ObjPtr<mirror::Object> obj) {
47 GetCardTable()->MarkCard(obj.Ptr());
48 }
49
GetCardTable()50 inline gc::accounting::CardTable* WriteBarrier::GetCardTable() {
51 return Runtime::Current()->GetHeap()->GetCardTable();
52 }
53
54 } // namespace art
55
56 #endif // ART_RUNTIME_WRITE_BARRIER_INL_H_
57