/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef ART_RUNTIME_WRITE_BARRIER_INL_H_
#define ART_RUNTIME_WRITE_BARRIER_INL_H_

#include "write_barrier.h"

#include "gc/accounting/card_table-inl.h"
#include "gc/heap.h"
#include "obj_ptr-inl.h"
#include "runtime.h"

namespace art HIDDEN {

template <WriteBarrier::NullCheck kNullCheck>
inline void WriteBarrier::ForFieldWrite(ObjPtr<mirror::Object> dst,
                                        [[maybe_unused]] MemberOffset offset,
                                        ObjPtr<mirror::Object> new_value) {
  if (kNullCheck == kWithNullCheck && new_value == nullptr) {
    return;
  }
  DCHECK(new_value != nullptr);
  GetCardTable()->MarkCard(dst.Ptr());
}

inline void WriteBarrier::ForArrayWrite(ObjPtr<mirror::Object> dst,
                                        [[maybe_unused]] int start_offset,
                                        [[maybe_unused]] size_t length) {
  GetCardTable()->MarkCard(dst.Ptr());
}

inline void WriteBarrier::ForEveryFieldWrite(ObjPtr<mirror::Object> obj) {
  GetCardTable()->MarkCard(obj.Ptr());
}

inline gc::accounting::CardTable* WriteBarrier::GetCardTable() {
  return Runtime::Current()->GetHeap()->GetCardTable();
}

}  // namespace art

#endif  // ART_RUNTIME_WRITE_BARRIER_INL_H_
