1 /* 2 * Copyright (c) 1997, 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_OOPS_INSTANCEREFKLASS_INLINE_HPP 26 #define SHARE_VM_OOPS_INSTANCEREFKLASS_INLINE_HPP 27 28 #include "utilities/templateIdioms.hpp" 29 #include "memory/specialized_oop_closures.inline.hpp" 30 #include "oops/instanceRefKlass.hpp" 31 #include "oops/instanceKlass.inline.hpp" 32 33 template<class OopClosureType> 34 inline int InstanceRefKlass::oop_iterate_and_dispatch(oop obj, OopClosureType *cl) { 35 SpecializationStats::record_iterate_call_nv(SpecializationStats::irk); 36 int size = InstanceKlass::oop_iterate_and_dispatch<OopClosureType>(obj, cl); 37 38 if (UseCompressedOops) { 39 do_metadata_if_applicable<OopClosureType, narrowOop, is_kind_of<OopClosureType, ExtendedOopClosure>::value>(obj, cl); 40 } else { 41 do_metadata_if_applicable<OopClosureType, oop, is_kind_of<OopClosureType, ExtendedOopClosure>::value>(obj, cl); 42 } 43 44 return size; 45 } 46 47 48 template<class OopClosureType, class OopType, bool is_extended> 49 inline void InstanceRefKlass::do_metadata_if_applicable(oop obj, OopClosureType *cl) { 50 OopType *disc_addr = (OopType*)java_lang_ref_Reference::discovered_addr(obj); 51 if (is_extended && reinterpret_cast<ExtendedOopClosure*>(cl)->apply_to_weak_ref_discovered_field()) { 52 OopClosureDispatcher::do_oop<OopClosureType, OopType>(cl, disc_addr); 53 } 54 OopType *referent_addr = (OopType*)java_lang_ref_Reference::discovered_addr(obj); 55 OopType heap_oop = oopDesc::load_heap_oop(referent_addr); 56 ReferenceProcessor *rp = is_extended ? reinterpret_cast<ExtendedOopClosure*>(cl)->_ref_processor : NULL; 57 if (!oopDesc::is_null(heap_oop)) { 58 oop referent = oopDesc::decode_heap_oop_not_null(heap_oop); 59 if (!referent->is_gc_marked() && rp != NULL && rp->discover_reference(obj, reference_type())) { 60 return; 61 } else { 62 /* treat referent as normal oop */ 63 SpecializationStats::record_do_oop_call_nv(SpecializationStats::irk); 64 OopClosureDispatcher::do_oop<OopClosureType, OopType>(cl, referent_addr); 65 } 66 } 67 68 OopType *next_addr = (OopType*)java_lang_ref_Reference::next_addr(obj); 69 if (ReferenceProcessor::pending_list_uses_discovered_field()) { 70 OopType next_oop = oopDesc::load_heap_oop(next_addr); 71 /* Treat discovered as normal oop, if ref is not "active" (next non-NULL) */ 72 if (!oopDesc::is_null(next_oop)) { 73 /* i.e. ref is not "active" */ 74 debug_only( 75 if (TraceReferenceGC && PrintGCDetails) { 76 gclog_or_tty->print_cr(" Process discovered as normal ", INTPTR_FORMAT, disc_addr); 77 } 78 ) 79 } 80 } else { 81 /* In the case of older JDKs which do not use the discovered field for */ 82 /* the pending list, an inactive ref (next != NULL) must always have a */ 83 /* NULL discovered field. */ 84 debug_only( 85 OopType next_oop = oopDesc::load_heap_oop(next_addr); 86 OopType disc_oop = oopDesc::load_heap_oop(disc_addr); 87 assert(oopDesc::is_null(next_oop) || oopDesc::is_null(disc_oop), 88 err_msg("Found an inactive reference " PTR_FORMAT " with a non-NULL discovered field", (oopDesc*)obj)); 89 ) 90 } 91 92 /* treat next as normal oop */ 93 SpecializationStats::record_do_oop_call_nv(SpecializationStats::irk); 94 OopClosureDispatcher::do_oop<OopClosureType, OopType>(cl, next_addr); 95 } 96 97 #endif // SHARE_VM_OOPS_INSTANCEREFKLASS_INLINE_HPP 98