Mathieu Chartier | 88ea61e | 2018-06-20 17:45:41 -0700 | [diff] [blame] | 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_H_ |
| 18 | #define ART_RUNTIME_WRITE_BARRIER_H_ |
| 19 | |
| 20 | #include "base/macros.h" |
| 21 | |
| 22 | namespace art { |
| 23 | |
| 24 | namespace gc { |
| 25 | namespace accounting { |
| 26 | class CardTable; |
| 27 | } // namespace accounting |
| 28 | } // namespace gc |
| 29 | |
| 30 | class WriteBarrier { |
| 31 | public: |
| 32 | enum NullCheck { |
| 33 | kWithoutNullCheck, |
| 34 | kWithNullCheck, |
| 35 | }; |
| 36 | |
Mathieu Chartier | 641c169 | 2018-06-20 17:45:41 -0700 | [diff] [blame] | 37 | // 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 Chartier | 88ea61e | 2018-06-20 17:45:41 -0700 | [diff] [blame] | 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 | |
Mathieu Chartier | 641c169 | 2018-06-20 17:45:41 -0700 | [diff] [blame] | 45 | // 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 Chartier | 88ea61e | 2018-06-20 17:45:41 -0700 | [diff] [blame] | 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 | |
Mathieu Chartier | 641c169 | 2018-06-20 17:45:41 -0700 | [diff] [blame] | 52 | // Write barrier for every reference field in an object. |
Mathieu Chartier | 88ea61e | 2018-06-20 17:45:41 -0700 | [diff] [blame] | 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_ |