blob: 112154e14afb7c1ca321975086c8eccd7cc38435 [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
Mathieu Chartier641c1692018-06-20 17:45:41 -070037 // Must be called if a reference field of an Object in the heap changes, and before any GC
38 // safe-point. The call is not needed if null is stored in the field.
Mathieu Chartier88ea61e2018-06-20 17:45:41 -070039 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
Mathieu Chartier641c1692018-06-20 17:45:41 -070045 // Must be called if a reference field of an ObjectArray in the heap changes, and before any GC
46 // safe-point. The call is not needed if null is stored in the field.
Mathieu Chartier88ea61e2018-06-20 17:45:41 -070047 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
Mathieu Chartier641c1692018-06-20 17:45:41 -070052 // Write barrier for every reference field in an object.
Mathieu Chartier88ea61e2018-06-20 17:45:41 -070053 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_