1 /*
   2  * Copyright (c) 2017, 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_VM_GC_G1_G1FULLGCOOPCLOSURES_INLINE_HPP
  26 #define SHARE_VM_GC_G1_G1FULLGCOOPCLOSURES_INLINE_HPP
  27 
  28 #include "gc/g1/g1Allocator.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 "oops/access.inline.hpp"
  35 #include "oops/compressedOops.inline.hpp"
  36 
  37 template <typename T>
  38 inline void G1MarkAndPushClosure::do_oop_nv(T* p) {
  39   _marker->mark_and_push(p);
  40 }
  41 
  42 inline bool G1MarkAndPushClosure::do_metadata_nv() {
  43   return true;
  44 }
  45 
  46 inline void G1MarkAndPushClosure::do_klass_nv(Klass* k) {
  47   _marker->follow_klass(k);
  48 }
  49 
  50 inline void G1MarkAndPushClosure::do_cld_nv(ClassLoaderData* cld) {
  51   _marker->follow_cld(cld);
  52 }
  53 
  54 template <class T> inline oop G1AdjustClosure::adjust_pointer(T* p) {
  55   T heap_oop = RawAccess<>::oop_load(p);
  56   if (CompressedOops::is_null(heap_oop)) {
  57     // NULL reference, return NULL.
  58     return NULL;
  59   }
  60 
  61   oop obj = CompressedOops::decode_not_null(heap_oop);
  62   assert(Universe::heap()->is_in(obj), "should be in heap");
  63   if (G1ArchiveAllocator::is_archive_object(obj)) {
  64     // Never forwarding archive objects, return current reference.
  65     return obj;
  66   }
  67 
  68   oop forwardee = obj->forwardee();
  69   if (forwardee == NULL) {
  70     // Not forwarded, return current reference.
  71     assert(obj->mark() == markOopDesc::prototype_for_object(obj) || // Correct mark
  72            obj->mark()->must_be_preserved(obj) || // Will be restored by PreservedMarksSet
  73            (UseBiasedLocking && obj->has_bias_pattern()), // Will be restored by BiasedLocking
  74            "Must have correct prototype or be preserved, obj: " PTR_FORMAT ", mark: " PTR_FORMAT ", prototype: " PTR_FORMAT,
  75            p2i(obj), p2i(obj->mark()), p2i(markOopDesc::prototype_for_object(obj)));
  76     return obj;
  77   }
  78 
  79   // Forwarded, update and return new reference.
  80   assert(Universe::heap()->is_in_reserved(forwardee), "should be in object space");
  81   RawAccess<OOP_NOT_NULL>::oop_store(p, forwardee);
  82   return forwardee;
  83 }
  84 
  85 template <class T>
  86 inline void G1AdjustAndRebuildClosure::add_reference(T* from_field, oop reference, uint worker_id) {
  87   if (HeapRegion::is_in_same_region(from_field, reference)) {
  88     return;
  89   }
  90   _g1h->heap_region_containing(reference)->rem_set()->add_reference(from_field, worker_id);
  91 }
  92 
  93 inline size_t G1AdjustAndRebuildClosure::calculate_compaction_delta(oop current, oop forwardee) {
  94   return pointer_delta((HeapWord*)forwardee, (HeapWord*)current);
  95 }
  96 
  97 template <class T>
  98 inline T* G1AdjustAndRebuildClosure::add_compaction_delta(T* p) {
  99   return (T*)((HeapWord*)p + _compaction_delta);
 100 }
 101 
 102 template<typename T>
 103 void G1AdjustAndRebuildClosure::do_oop_nv(T* p) {
 104   oop new_reference = G1AdjustClosure::adjust_pointer(p);
 105   if (new_reference == NULL) {
 106     return;
 107   }
 108 
 109   // Update p using the calculated compaction delta to
 110   // get the new field address.
 111   T* new_field = add_compaction_delta(p);
 112   // Update the remembered set.
 113   add_reference(new_field, new_reference, _worker_id);
 114 }
 115 
 116 inline int G1AdjustObjectClosure::adjust_object(oop obj) {
 117   _closure->update_compaction_delta(obj);
 118   return obj->oop_iterate_size(_closure);
 119 }
 120 
 121 inline bool G1IsAliveClosure::do_object_b(oop p) {
 122   return _bitmap->is_marked(p) || G1ArchiveAllocator::is_closed_archive_object(p);
 123 }
 124 
 125 template<typename T>
 126 inline void G1FullKeepAliveClosure::do_oop_work(T* p) {
 127   _marker->mark_and_push(p);
 128 }
 129 
 130 #endif