1 /*
   2  * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_GC_G1_G1BARRIERSET_INLINE_HPP
  26 #define SHARE_GC_G1_G1BARRIERSET_INLINE_HPP
  27 
  28 #include "gc/g1/g1BarrierSet.hpp"
  29 #include "gc/g1/g1CardTable.hpp"
  30 #include "gc/shared/accessBarrierSupport.inline.hpp"
  31 #include "oops/access.inline.hpp"
  32 #include "oops/compressedOops.inline.hpp"
  33 #include "oops/oop.hpp"
  34 
  35 template <DecoratorSet decorators, typename T>
  36 inline void G1BarrierSet::write_ref_field_pre(T* field) {
  37   if (HasDecorator<decorators, IS_DEST_UNINITIALIZED>::value ||
  38       HasDecorator<decorators, AS_NO_KEEPALIVE>::value) {
  39     return;
  40   }
  41 
  42   T heap_oop = RawAccess<MO_VOLATILE>::oop_load(field);
  43   if (!CompressedOops::is_null(heap_oop)) {
  44     enqueue(CompressedOops::decode_not_null(heap_oop));
  45   }
  46 }
  47 
  48 template <DecoratorSet decorators, typename T>
  49 inline void G1BarrierSet::write_ref_field_post(T* field, oop new_val) {
  50   volatile CardValue* byte = _card_table->byte_for(field);
  51   if (*byte != G1CardTable::g1_young_card_val()) {
  52     // Take a slow path for cards in old
  53     write_ref_field_post_slow(byte);
  54   }
  55 }
  56 
  57 inline void G1BarrierSet::enqueue_if_weak(DecoratorSet decorators, oop value) {
  58   assert((decorators & ON_UNKNOWN_OOP_REF) == 0, "Reference strength must be known");
  59   // Loading from a weak or phantom reference needs enqueueing, as
  60   // the object may not have been reachable (part of the snapshot)
  61   // when marking started.
  62   const bool on_strong_oop_ref = (decorators & ON_STRONG_OOP_REF) != 0;
  63   const bool peek              = (decorators & AS_NO_KEEPALIVE) != 0;
  64   const bool needs_enqueue     = (!peek && !on_strong_oop_ref);
  65 
  66   if (needs_enqueue && value != NULL) {
  67     enqueue(value);
  68   }
  69 }
  70 
  71 template <DecoratorSet decorators, typename BarrierSetT>
  72 template <typename T>
  73 inline oop G1BarrierSet::AccessBarrier<decorators, BarrierSetT>::
  74 oop_load_not_in_heap(T* addr) {
  75   oop value = ModRef::oop_load_not_in_heap(addr);
  76   enqueue_if_weak(decorators, value);
  77   return value;
  78 }
  79 
  80 template <DecoratorSet decorators, typename BarrierSetT>
  81 template <typename T>
  82 inline oop G1BarrierSet::AccessBarrier<decorators, BarrierSetT>::
  83 oop_load_in_heap(T* addr) {
  84   oop value = ModRef::oop_load_in_heap(addr);
  85   enqueue_if_weak(decorators, value);
  86   return value;
  87 }
  88 
  89 template <DecoratorSet decorators, typename BarrierSetT>
  90 inline oop G1BarrierSet::AccessBarrier<decorators, BarrierSetT>::
  91 oop_load_in_heap_at(oop base, ptrdiff_t offset) {
  92   oop value = ModRef::oop_load_in_heap_at(base, offset);
  93   enqueue_if_weak(AccessBarrierSupport::resolve_possibly_unknown_oop_ref_strength<decorators>(base, offset), value);
  94   return value;
  95 }
  96 
  97 template <DecoratorSet decorators, typename BarrierSetT>
  98 template <typename T>
  99 inline void G1BarrierSet::AccessBarrier<decorators, BarrierSetT>::
 100 oop_store_not_in_heap(T* addr, oop new_value) {
 101   // Apply SATB barriers for all non-heap references, to allow
 102   // concurrent scanning of such references.
 103   G1BarrierSet *bs = barrier_set_cast<G1BarrierSet>(BarrierSet::barrier_set());
 104   bs->write_ref_field_pre<decorators>(addr);
 105   Raw::oop_store(addr, new_value);
 106 }
 107 
 108 #endif // SHARE_GC_G1_G1BARRIERSET_INLINE_HPP