blob: e64012a70678e1e376dcf7af27c6b2b531d3cd71 [file] [log] [blame]
Mathieu Chartier88ea61e2018-06-20 17:45:41 -07001/*
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_H_
18#define ART_RUNTIME_WRITE_BARRIER_H_
19
20#include "base/macros.h"
21
22namespace art {
23
24namespace gc {
25namespace accounting {
26class CardTable;
27} // namespace accounting
28} // namespace gc
29
30class WriteBarrier {
31 public:
32 enum NullCheck {
33 kWithoutNullCheck,
34 kWithNullCheck,
35 };
36
37 // Must be called if a field of an Object in the heap changes, and before any GC safe-point.
38 // The call is not needed if null is stored in the field.
39 template <NullCheck kNullCheck = kWithNullCheck>
40 ALWAYS_INLINE static void ForFieldWrite(ObjPtr<mirror::Object> dst,
41 MemberOffset offset ATTRIBUTE_UNUSED,
42 ObjPtr<mirror::Object> new_value ATTRIBUTE_UNUSED)
43 REQUIRES_SHARED(Locks::mutator_lock_);
44
45 // Must be called if a field of an Object in the heap changes, and before any GC safe-point.
46 // The call is not needed if null is stored in the field.
47 ALWAYS_INLINE static void ForArrayWrite(ObjPtr<mirror::Object> dst,
48 int start_offset ATTRIBUTE_UNUSED,
49 size_t length ATTRIBUTE_UNUSED)
50 REQUIRES_SHARED(Locks::mutator_lock_);
51
52 // Write barrier for every field in an object.
53 ALWAYS_INLINE static void ForEveryFieldWrite(ObjPtr<mirror::Object> obj)
54 REQUIRES_SHARED(Locks::mutator_lock_);
55
56 private:
57 ALWAYS_INLINE static gc::accounting::CardTable* GetCardTable();
58};
59
60} // namespace art
61
62#endif // ART_RUNTIME_WRITE_BARRIER_H_