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