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