1 /*
  2  * Copyright (c) 2017, 2021, 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_G1FULLGCOOPCLOSURES_INLINE_HPP
 26 #define SHARE_GC_G1_G1FULLGCOOPCLOSURES_INLINE_HPP
 27 
 28 #include "gc/g1/g1FullGCOopClosures.hpp"
 29 
 30 #include "gc/g1/g1Allocator.inline.hpp"
 31 #include "gc/g1/g1FullCollector.inline.hpp"
 32 #include "gc/g1/g1ConcurrentMarkBitMap.inline.hpp"
 33 #include "gc/g1/g1FullGCMarker.inline.hpp"
 34 #include "gc/g1/heapRegionRemSet.inline.hpp"
 35 #include "memory/iterator.inline.hpp"
 36 #include "memory/universe.hpp"
 37 #include "oops/access.inline.hpp"
 38 #include "oops/compressedOops.inline.hpp"
 39 #include "oops/oop.inline.hpp"
 40 
 41 template <typename T>
 42 inline void G1MarkAndPushClosure::do_oop_work(T* p) {
 43   _marker->mark_and_push(p);
 44 }
 45 
 46 inline void G1MarkAndPushClosure::do_oop(oop* p) {
 47   do_oop_work(p);
 48 }
 49 
 50 inline void G1MarkAndPushClosure::do_oop(narrowOop* p) {
 51   do_oop_work(p);
 52 }
 53 
 54 inline bool G1MarkAndPushClosure::do_metadata() {
 55   return true;
 56 }
 57 
 58 inline void G1MarkAndPushClosure::do_klass(Klass* k) {
 59   _marker->follow_klass(k);
 60 }
 61 
 62 inline void G1MarkAndPushClosure::do_cld(ClassLoaderData* cld) {
 63   _marker->follow_cld(cld);
 64 }
 65 
 66 inline void G1MarkAndPushClosure::do_method(Method* m) {
 67   m->record_marking_cycle();
 68 }
 69 
 70 inline void G1MarkAndPushClosure::do_nmethod(nmethod* nm) {
 71   nm->follow_nmethod(this);
 72 }
 73 
 74 template <class T> inline void G1AdjustClosure::adjust_pointer(T* p) {
 75   T heap_oop = RawAccess<>::oop_load(p);
 76   if (CompressedOops::is_null(heap_oop)) {
 77     return;
 78   }
 79 
 80   oop obj = CompressedOops::decode_not_null(heap_oop);
 81   assert(Universe::heap()->is_in(obj), "should be in heap");
 82   if (!_collector->is_compacting(obj)) {
 83     // We never forward objects in non-compacting regions so there is no need to
 84     // process them further.
 85     return;
 86   }
 87 
 88   oop forwardee = obj->forwardee();
 89   if (forwardee == NULL) {
 90     // Not forwarded, return current reference.
 91     assert(obj->mark() == markWord::prototype() || // Correct mark
 92            obj->mark_must_be_preserved(), // Will be restored by PreservedMarksSet
 93            "Must have correct prototype or be preserved, obj: " PTR_FORMAT ", mark: " PTR_FORMAT ", prototype: " PTR_FORMAT,
 94            p2i(obj), obj->mark().value(), markWord::prototype().value());
 95     return;
 96   }
 97 
 98   // Forwarded, just update.
 99   assert(G1CollectedHeap::heap()->is_in_reserved(forwardee), "should be in object space");
100   RawAccess<IS_NOT_NULL>::oop_store(p, forwardee);
101 }
102 
103 inline void G1AdjustClosure::do_oop(oop* p)       { do_oop_work(p); }
104 inline void G1AdjustClosure::do_oop(narrowOop* p) { do_oop_work(p); }
105 
106 inline bool G1IsAliveClosure::do_object_b(oop p) {
107   return _bitmap->is_marked(p) || _collector->is_skip_marking(p);
108 }
109 
110 template<typename T>
111 inline void G1FullKeepAliveClosure::do_oop_work(T* p) {
112   _marker->mark_and_push(p);
113 }
114 
115 #endif // SHARE_GC_G1_G1FULLGCOOPCLOSURES_INLINE_HPP