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