1 /*
   2  * Copyright (c) 2015, 2018, 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 #ifndef SHARE_GC_Z_ZOOPCLOSURES_INLINE_HPP
  25 #define SHARE_GC_Z_ZOOPCLOSURES_INLINE_HPP
  26 
  27 #include "gc/z/zBarrier.inline.hpp"
  28 #include "gc/z/zHeap.inline.hpp"
  29 #include "gc/z/zOop.inline.hpp"
  30 #include "gc/z/zOopClosures.hpp"
  31 #include "oops/oop.inline.hpp"
  32 #include "runtime/atomic.hpp"
  33 #include "utilities/debug.hpp"
  34 
  35 inline void ZLoadBarrierOopClosure::do_oop_nv(oop* p) {
  36   ZBarrier::load_barrier_on_oop_field(p);
  37 }
  38 
  39 inline void ZLoadBarrierOopClosure::do_oop_nv(narrowOop* p) {
  40   ShouldNotReachHere();
  41 }
  42 
  43 inline void ZLoadBarrierOopClosure::do_oop(oop* p) {
  44   do_oop_nv(p);
  45 }
  46 
  47 inline void ZLoadBarrierOopClosure::do_oop(narrowOop* p) {
  48   do_oop_nv(p);
  49 }
  50 
  51 inline void ZMarkRootOopClosure::do_oop(oop* p) {
  52   ZBarrier::mark_barrier_on_root_oop_field(p);
  53 }
  54 
  55 inline void ZMarkRootOopClosure::do_oop(narrowOop* p) {
  56   ShouldNotReachHere();
  57 }
  58 
  59 inline void ZRelocateRootOopClosure::do_oop(oop* p) {
  60   ZBarrier::relocate_barrier_on_root_oop_field(p);
  61 }
  62 
  63 inline void ZRelocateRootOopClosure::do_oop(narrowOop* p) {
  64   ShouldNotReachHere();
  65 }
  66 
  67 template <bool finalizable>
  68 inline ZMarkBarrierOopClosure<finalizable>::ZMarkBarrierOopClosure() :
  69     ExtendedOopClosure(finalizable ? NULL : ZHeap::heap()->reference_discoverer()) {}
  70 
  71 template <bool finalizable>
  72 inline void ZMarkBarrierOopClosure<finalizable>::do_oop_nv(oop* p) {
  73   ZBarrier::mark_barrier_on_oop_field(p, finalizable);
  74 }
  75 
  76 template <bool finalizable>
  77 inline void ZMarkBarrierOopClosure<finalizable>::do_oop_nv(narrowOop* p) {
  78   ShouldNotReachHere();
  79 }
  80 
  81 template <bool finalizable>
  82 inline void ZMarkBarrierOopClosure<finalizable>::do_oop(oop* p) {
  83   do_oop_nv(p);
  84 }
  85 
  86 template <bool finalizable>
  87 inline void ZMarkBarrierOopClosure<finalizable>::do_oop(narrowOop* p) {
  88   do_oop_nv(p);
  89 }
  90 
  91 inline bool ZPhantomIsAliveObjectClosure::do_object_b(oop o) {
  92   return ZBarrier::is_alive_barrier_on_phantom_oop(o);
  93 }
  94 
  95 inline void ZPhantomKeepAliveOopClosure::do_oop(oop* p) {
  96   ZBarrier::keep_alive_barrier_on_phantom_oop_field(p);
  97 }
  98 
  99 inline void ZPhantomKeepAliveOopClosure::do_oop(narrowOop* p) {
 100   ShouldNotReachHere();
 101 }
 102 
 103 inline void ZPhantomCleanOopClosure::do_oop(oop* p) {
 104   // Read the oop once, to make sure the liveness check
 105   // and the later clearing uses the same value.
 106   const oop obj = *(volatile oop*)p;
 107   if (ZBarrier::is_alive_barrier_on_phantom_oop(obj)) {
 108     ZBarrier::keep_alive_barrier_on_phantom_oop_field(p);
 109   } else {
 110     // The destination could have been modified/reused, in which case
 111     // we don't want to clear it. However, no one could write the same
 112     // oop here again (the object would be strongly live and we would
 113     // not consider clearing such oops), so therefore we don't have an
 114     // ABA problem here.
 115     Atomic::cmpxchg(oop(NULL), p, obj);
 116   }
 117 }
 118 
 119 inline void ZPhantomCleanOopClosure::do_oop(narrowOop* p) {
 120   ShouldNotReachHere();
 121 }
 122 
 123 #endif // SHARE_GC_Z_ZOOPCLOSURES_INLINE_HPP