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 #include "precompiled.hpp" 26 #include "gc/g1/g1CollectedHeap.hpp" 27 #include "gc/g1/g1FullGCMarker.inline.hpp" 28 #include "gc/g1/g1FullGCOopClosures.inline.hpp" 29 #include "gc/g1/g1_specialized_oop_closures.hpp" 30 #include "logging/logStream.hpp" 31 #include "oops/access.inline.hpp" 32 #include "oops/compressedOops.inline.hpp" 33 34 void G1MarkAndPushClosure::do_oop(oop* p) { 35 do_oop_nv(p); 36 } 37 38 void G1MarkAndPushClosure::do_oop(narrowOop* p) { 39 do_oop_nv(p); 40 } 41 42 bool G1MarkAndPushClosure::do_metadata() { 43 return do_metadata_nv(); 44 } 45 46 void G1MarkAndPushClosure::do_klass(Klass* k) { 47 do_klass_nv(k); 48 } 49 50 void G1MarkAndPushClosure::do_cld(ClassLoaderData* cld) { 51 do_cld_nv(cld); 52 } 53 54 G1AdjustAndRebuildClosure::G1AdjustAndRebuildClosure(uint worker_id) : 55 _worker_id(worker_id), 56 _compaction_delta(0), 57 _g1h(G1CollectedHeap::heap()) { } 58 59 void G1AdjustAndRebuildClosure::update_compaction_delta(oop obj) { 60 if (G1ArchiveAllocator::is_open_archive_object(obj)) { 61 _compaction_delta = 0; 62 return; 63 } 64 oop forwardee = obj->forwardee(); 65 if (forwardee == NULL) { 66 // Object not moved. 67 _compaction_delta = 0; 68 } else { 69 // Object moved to forwardee, calculate delta. 70 _compaction_delta = calculate_compaction_delta(obj, forwardee); 71 } 72 } 73 74 void G1AdjustClosure::do_oop(oop* p) { adjust_pointer(p); } 75 void G1AdjustClosure::do_oop(narrowOop* p) { adjust_pointer(p); } 76 77 void G1AdjustAndRebuildClosure::do_oop(oop* p) { do_oop_nv(p); } 78 void G1AdjustAndRebuildClosure::do_oop(narrowOop* p) { do_oop_nv(p); } 79 80 void G1FollowStackClosure::do_void() { _marker->drain_stack(); } 81 82 void G1FullKeepAliveClosure::do_oop(oop* p) { do_oop_work(p); } 83 void G1FullKeepAliveClosure::do_oop(narrowOop* p) { do_oop_work(p); } 84 85 G1VerifyOopClosure::G1VerifyOopClosure(VerifyOption option) : 86 _g1h(G1CollectedHeap::heap()), 87 _containing_obj(NULL), 88 _verify_option(option), 89 _cc(0), 90 _failures(false) { 91 } 92 93 void G1VerifyOopClosure::print_object(outputStream* out, oop obj) { 94 #ifdef PRODUCT 95 Klass* k = obj->klass(); 96 const char* class_name = InstanceKlass::cast(k)->external_name(); 97 out->print_cr("class name %s", class_name); 98 #else // PRODUCT 99 obj->print_on(out); 100 #endif // PRODUCT 101 } 102 103 template <class T> void G1VerifyOopClosure::do_oop_nv(T* p) { 104 T heap_oop = RawAccess<>::oop_load(p); 105 if (!CompressedOops::is_null(heap_oop)) { 106 _cc++; 107 oop obj = CompressedOops::decode_not_null(heap_oop); 108 bool failed = false; 109 if (!_g1h->is_in_closed_subset(obj) || _g1h->is_obj_dead_cond(obj, _verify_option)) { 110 MutexLockerEx x(ParGCRareEvent_lock, 111 Mutex::_no_safepoint_check_flag); 112 LogStreamHandle(Error, gc, verify) yy; 113 if (!_failures) { 114 yy.cr(); 115 yy.print_cr("----------"); 116 } 117 if (!_g1h->is_in_closed_subset(obj)) { 118 HeapRegion* from = _g1h->heap_region_containing((HeapWord*)p); 119 yy.print_cr("Field " PTR_FORMAT 120 " of live obj " PTR_FORMAT " in region " 121 "[" PTR_FORMAT ", " PTR_FORMAT ")", 122 p2i(p), p2i(_containing_obj), 123 p2i(from->bottom()), p2i(from->end())); 124 print_object(&yy, _containing_obj); 125 yy.print_cr("points to obj " PTR_FORMAT " not in the heap", 126 p2i(obj)); 127 } else { 128 HeapRegion* from = _g1h->heap_region_containing((HeapWord*)p); 129 HeapRegion* to = _g1h->heap_region_containing((HeapWord*)obj); 130 yy.print_cr("Field " PTR_FORMAT 131 " of live obj " PTR_FORMAT " in region " 132 "[" PTR_FORMAT ", " PTR_FORMAT ")", 133 p2i(p), p2i(_containing_obj), 134 p2i(from->bottom()), p2i(from->end())); 135 print_object(&yy, _containing_obj); 136 yy.print_cr("points to dead obj " PTR_FORMAT " in region " 137 "[" PTR_FORMAT ", " PTR_FORMAT ")", 138 p2i(obj), p2i(to->bottom()), p2i(to->end())); 139 print_object(&yy, obj); 140 } 141 yy.print_cr("----------"); 142 yy.flush(); 143 _failures = true; 144 failed = true; 145 } 146 } 147 } 148 149 template void G1VerifyOopClosure::do_oop_nv(oop*); 150 template void G1VerifyOopClosure::do_oop_nv(narrowOop*); 151 152 // Generate G1 full GC specialized oop_oop_iterate functions. 153 SPECIALIZED_OOP_OOP_ITERATE_CLOSURES_G1FULL(ALL_KLASS_OOP_OOP_ITERATE_DEFN)