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