1 /* 2 * Copyright (c) 2007, 2014, 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_IMPLEMENTATION_PARNEW_PAROOPCLOSURES_INLINE_HPP 26 #define SHARE_VM_GC_IMPLEMENTATION_PARNEW_PAROOPCLOSURES_INLINE_HPP 27 28 #include "gc_implementation/parNew/parNewGeneration.hpp" 29 #include "gc_implementation/parNew/parOopClosures.hpp" 30 #include "memory/cardTableRS.hpp" 31 #include "memory/genCollectedHeap.hpp" 32 33 template <class T> inline void ParScanWeakRefClosure::do_oop_work(T* p) { 34 assert (!oopDesc::is_null(*p), "null weak reference?"); 35 oop obj = oopDesc::load_decode_heap_oop_not_null(p); 36 // weak references are sometimes scanned twice; must check 37 // that to-space doesn't already contain this object 38 if ((HeapWord*)obj < _boundary && !_g->to()->is_in_reserved(obj)) { 39 // we need to ensure that it is copied (see comment in 40 // ParScanClosure::do_oop_work). 41 Klass* objK = obj->klass(); 42 markOop m = obj->mark(); 43 oop new_obj; 44 if (m->is_marked()) { // Contains forwarding pointer. 45 new_obj = ParNewGeneration::real_forwardee(obj); 46 } else { 47 size_t obj_sz = obj->size_given_klass(objK); 48 new_obj = ((ParNewGeneration*)_g)->copy_to_survivor_space(_par_scan_state, 49 obj, obj_sz, m); 50 } 51 oopDesc::encode_store_heap_oop_not_null(p, new_obj); 52 } 53 } 54 55 inline void ParScanWeakRefClosure::do_oop_nv(oop* p) { ParScanWeakRefClosure::do_oop_work(p); } 56 inline void ParScanWeakRefClosure::do_oop_nv(narrowOop* p) { ParScanWeakRefClosure::do_oop_work(p); } 57 58 template <class T> inline void ParScanClosure::par_do_barrier(T* p) { 59 assert(generation()->is_in_reserved(p), "expected ref in generation"); 60 assert(!oopDesc::is_null(*p), "expected non-null object"); 61 oop obj = oopDesc::load_decode_heap_oop_not_null(p); 62 // If p points to a younger generation, mark the card. 63 if ((HeapWord*)obj < gen_boundary()) { 64 rs()->write_ref_field_gc_par(p, obj); 65 } 66 } 67 68 template <class T> 69 inline void ParScanClosure::do_oop_work(T* p, 70 bool gc_barrier, 71 bool root_scan) { 72 assert((!Universe::heap()->is_in_reserved(p) || 73 generation()->is_in_reserved(p)) 74 && (generation()->level() == 0 || gc_barrier), 75 "The gen must be right, and we must be doing the barrier " 76 "in older generations."); 77 T heap_oop = oopDesc::load_heap_oop(p); 78 if (!oopDesc::is_null(heap_oop)) { 79 oop obj = oopDesc::decode_heap_oop_not_null(heap_oop); 80 if ((HeapWord*)obj < _boundary) { 81 #ifndef PRODUCT 82 if (_g->to()->is_in_reserved(obj)) { 83 tty->print_cr("Scanning field (" PTR_FORMAT ") twice?", p2i(p)); 84 GenCollectedHeap* gch = (GenCollectedHeap*)Universe::heap(); 85 Space* sp = gch->space_containing(p); 86 oop obj = oop(sp->block_start(p)); 87 assert((HeapWord*)obj < (HeapWord*)p, "Error"); 88 tty->print_cr("Object: " PTR_FORMAT, p2i((void *)obj)); 89 tty->print_cr("-------"); 90 obj->print(); 91 tty->print_cr("-----"); 92 tty->print_cr("Heap:"); 93 tty->print_cr("-----"); 94 gch->print(); 95 ShouldNotReachHere(); 96 } 97 #endif 98 // OK, we need to ensure that it is copied. 99 // We read the klass and mark in this order, so that we can reliably 100 // get the size of the object: if the mark we read is not a 101 // forwarding pointer, then the klass is valid: the klass is only 102 // overwritten with an overflow next pointer after the object is 103 // forwarded. 104 Klass* objK = obj->klass(); 105 markOop m = obj->mark(); 106 oop new_obj; 107 if (m->is_marked()) { // Contains forwarding pointer. 108 new_obj = ParNewGeneration::real_forwardee(obj); 109 oopDesc::encode_store_heap_oop_not_null(p, new_obj); 110 #ifndef PRODUCT 111 if (TraceScavenge) { 112 gclog_or_tty->print_cr("{%s %s ( " PTR_FORMAT " ) " PTR_FORMAT " -> " PTR_FORMAT " (%d)}", 113 "forwarded ", 114 new_obj->klass()->internal_name(), p2i(p), p2i((void *)obj), p2i((void *)new_obj), new_obj->size()); 115 } 116 #endif 117 118 } else { 119 size_t obj_sz = obj->size_given_klass(objK); 120 new_obj = _g->copy_to_survivor_space(_par_scan_state, obj, obj_sz, m); 121 oopDesc::encode_store_heap_oop_not_null(p, new_obj); 122 if (root_scan) { 123 // This may have pushed an object. If we have a root 124 // category with a lot of roots, can't let the queue get too 125 // full: 126 (void)_par_scan_state->trim_queues(10 * ParallelGCThreads); 127 } 128 } 129 if (is_scanning_a_klass()) { 130 do_klass_barrier(); 131 } else if (gc_barrier) { 132 // Now call parent closure 133 par_do_barrier(p); 134 } 135 } 136 } 137 } 138 139 inline void ParScanWithBarrierClosure::do_oop_nv(oop* p) { ParScanClosure::do_oop_work(p, true, false); } 140 inline void ParScanWithBarrierClosure::do_oop_nv(narrowOop* p) { ParScanClosure::do_oop_work(p, true, false); } 141 142 inline void ParScanWithoutBarrierClosure::do_oop_nv(oop* p) { ParScanClosure::do_oop_work(p, false, false); } 143 inline void ParScanWithoutBarrierClosure::do_oop_nv(narrowOop* p) { ParScanClosure::do_oop_work(p, false, false); } 144 145 #endif // SHARE_VM_GC_IMPLEMENTATION_PARNEW_PAROOPCLOSURES_INLINE_HPP