annotate src/share/vm/oops/instanceRefKlass.cpp @ 5223:edb5ab0f3fe5

8001107: @Stable annotation for constant folding of lazily evaluated variables Reviewed-by: rbackman, twisti, kvn Contributed-by: john.r.rose@oracle.com, vladimir.x.ivanov@oracle.com
author vlivanov
date Tue, 10 Sep 2013 14:51:48 -0700
parents aed758eda82a
children 190899198332
rev   line source
duke@0 1 /*
brutisso@3276 2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
duke@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@0 4 *
duke@0 5 * This code is free software; you can redistribute it and/or modify it
duke@0 6 * under the terms of the GNU General Public License version 2 only, as
duke@0 7 * published by the Free Software Foundation.
duke@0 8 *
duke@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@0 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@0 13 * accompanied this code).
duke@0 14 *
duke@0 15 * You should have received a copy of the GNU General Public License version
duke@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@0 18 *
trims@1472 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1472 20 * or visit www.oracle.com if you need additional information or have any
trims@1472 21 * questions.
duke@0 22 *
duke@0 23 */
duke@0 24
stefank@1879 25 #include "precompiled.hpp"
stefank@1879 26 #include "classfile/javaClasses.hpp"
stefank@1879 27 #include "classfile/systemDictionary.hpp"
stefank@1879 28 #include "gc_implementation/shared/markSweep.inline.hpp"
stefank@1879 29 #include "gc_interface/collectedHeap.hpp"
stefank@1879 30 #include "gc_interface/collectedHeap.inline.hpp"
stefank@1879 31 #include "memory/genCollectedHeap.hpp"
stefank@1879 32 #include "memory/genOopClosures.inline.hpp"
stefank@1879 33 #include "oops/instanceRefKlass.hpp"
stefank@1879 34 #include "oops/oop.inline.hpp"
stefank@1879 35 #include "utilities/preserveException.hpp"
jprovino@4107 36 #include "utilities/macros.hpp"
jprovino@4107 37 #if INCLUDE_ALL_GCS
stefank@1879 38 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
stefank@1879 39 #include "gc_implementation/g1/g1OopClosures.inline.hpp"
stefank@1879 40 #include "gc_implementation/g1/g1RemSet.inline.hpp"
stefank@1879 41 #include "gc_implementation/g1/heapRegionSeq.inline.hpp"
stefank@1879 42 #include "gc_implementation/parNew/parOopClosures.inline.hpp"
stefank@1879 43 #include "gc_implementation/parallelScavenge/psPromotionManager.inline.hpp"
stefank@1879 44 #include "gc_implementation/parallelScavenge/psScavenge.inline.hpp"
stefank@1879 45 #include "oops/oop.pcgc.inline.hpp"
jprovino@4107 46 #endif // INCLUDE_ALL_GCS
duke@0 47
coleenp@113 48 template <class T>
coleenp@3612 49 void specialized_oop_follow_contents(InstanceRefKlass* ref, oop obj) {
coleenp@113 50 T* referent_addr = (T*)java_lang_ref_Reference::referent_addr(obj);
ysr@845 51 T heap_oop = oopDesc::load_heap_oop(referent_addr);
duke@0 52 debug_only(
duke@0 53 if(TraceReferenceGC && PrintGCDetails) {
coleenp@3612 54 gclog_or_tty->print_cr("InstanceRefKlass::oop_follow_contents " INTPTR_FORMAT, obj);
duke@0 55 }
duke@0 56 )
ysr@845 57 if (!oopDesc::is_null(heap_oop)) {
ysr@845 58 oop referent = oopDesc::decode_heap_oop_not_null(heap_oop);
duke@0 59 if (!referent->is_gc_marked() &&
ysr@2682 60 MarkSweep::ref_processor()->discover_reference(obj, ref->reference_type())) {
ysr@2682 61 // reference was discovered, referent will be traversed later
coleenp@3602 62 ref->InstanceKlass::oop_follow_contents(obj);
duke@0 63 debug_only(
duke@0 64 if(TraceReferenceGC && PrintGCDetails) {
coleenp@113 65 gclog_or_tty->print_cr(" Non NULL enqueued " INTPTR_FORMAT, obj);
duke@0 66 }
duke@0 67 )
duke@0 68 return;
duke@0 69 } else {
duke@0 70 // treat referent as normal oop
duke@0 71 debug_only(
duke@0 72 if(TraceReferenceGC && PrintGCDetails) {
coleenp@113 73 gclog_or_tty->print_cr(" Non NULL normal " INTPTR_FORMAT, obj);
duke@0 74 }
duke@0 75 )
duke@0 76 MarkSweep::mark_and_push(referent_addr);
duke@0 77 }
duke@0 78 }
coleenp@113 79 T* next_addr = (T*)java_lang_ref_Reference::next_addr(obj);
ysr@2682 80 if (ReferenceProcessor::pending_list_uses_discovered_field()) {
ysr@2682 81 // Treat discovered as normal oop, if ref is not "active",
ysr@2682 82 // i.e. if next is non-NULL.
ysr@2682 83 T next_oop = oopDesc::load_heap_oop(next_addr);
ysr@2682 84 if (!oopDesc::is_null(next_oop)) { // i.e. ref is not "active"
ysr@2682 85 T* discovered_addr = (T*)java_lang_ref_Reference::discovered_addr(obj);
ysr@2682 86 debug_only(
ysr@2682 87 if(TraceReferenceGC && PrintGCDetails) {
ysr@2682 88 gclog_or_tty->print_cr(" Process discovered as normal "
ysr@2682 89 INTPTR_FORMAT, discovered_addr);
ysr@2682 90 }
ysr@2682 91 )
ysr@2682 92 MarkSweep::mark_and_push(discovered_addr);
ysr@2682 93 }
ysr@2682 94 } else {
ysr@2682 95 #ifdef ASSERT
ysr@2682 96 // In the case of older JDKs which do not use the discovered
ysr@2682 97 // field for the pending list, an inactive ref (next != NULL)
ysr@2682 98 // must always have a NULL discovered field.
ysr@2682 99 oop next = oopDesc::load_decode_heap_oop(next_addr);
ysr@2682 100 oop discovered = java_lang_ref_Reference::discovered(obj);
ysr@2682 101 assert(oopDesc::is_null(next) || oopDesc::is_null(discovered),
ysr@2682 102 err_msg("Found an inactive reference " PTR_FORMAT " with a non-NULL discovered field",
kvn@2693 103 (oopDesc*)obj));
ysr@2682 104 #endif
ysr@2682 105 }
ysr@2682 106 // treat next as normal oop. next is a link in the reference queue.
duke@0 107 debug_only(
duke@0 108 if(TraceReferenceGC && PrintGCDetails) {
duke@0 109 gclog_or_tty->print_cr(" Process next as normal " INTPTR_FORMAT, next_addr);
duke@0 110 }
duke@0 111 )
duke@0 112 MarkSweep::mark_and_push(next_addr);
coleenp@3602 113 ref->InstanceKlass::oop_follow_contents(obj);
coleenp@113 114 }
coleenp@113 115
coleenp@3612 116 void InstanceRefKlass::oop_follow_contents(oop obj) {
coleenp@113 117 if (UseCompressedOops) {
coleenp@113 118 specialized_oop_follow_contents<narrowOop>(this, obj);
coleenp@113 119 } else {
coleenp@113 120 specialized_oop_follow_contents<oop>(this, obj);
coleenp@113 121 }
duke@0 122 }
duke@0 123
jprovino@4107 124 #if INCLUDE_ALL_GCS
coleenp@113 125 template <class T>
coleenp@3612 126 void specialized_oop_follow_contents(InstanceRefKlass* ref,
phh@1123 127 ParCompactionManager* cm,
phh@1123 128 oop obj) {
coleenp@113 129 T* referent_addr = (T*)java_lang_ref_Reference::referent_addr(obj);
ysr@845 130 T heap_oop = oopDesc::load_heap_oop(referent_addr);
duke@0 131 debug_only(
duke@0 132 if(TraceReferenceGC && PrintGCDetails) {
coleenp@3612 133 gclog_or_tty->print_cr("InstanceRefKlass::oop_follow_contents " INTPTR_FORMAT, obj);
duke@0 134 }
duke@0 135 )
ysr@845 136 if (!oopDesc::is_null(heap_oop)) {
ysr@845 137 oop referent = oopDesc::decode_heap_oop_not_null(heap_oop);
duke@0 138 if (PSParallelCompact::mark_bitmap()->is_unmarked(referent) &&
duke@0 139 PSParallelCompact::ref_processor()->
coleenp@113 140 discover_reference(obj, ref->reference_type())) {
duke@0 141 // reference already enqueued, referent will be traversed later
coleenp@3602 142 ref->InstanceKlass::oop_follow_contents(cm, obj);
duke@0 143 debug_only(
duke@0 144 if(TraceReferenceGC && PrintGCDetails) {
coleenp@113 145 gclog_or_tty->print_cr(" Non NULL enqueued " INTPTR_FORMAT, obj);
duke@0 146 }
duke@0 147 )
duke@0 148 return;
duke@0 149 } else {
duke@0 150 // treat referent as normal oop
duke@0 151 debug_only(
duke@0 152 if(TraceReferenceGC && PrintGCDetails) {
coleenp@113 153 gclog_or_tty->print_cr(" Non NULL normal " INTPTR_FORMAT, obj);
duke@0 154 }
duke@0 155 )
duke@0 156 PSParallelCompact::mark_and_push(cm, referent_addr);
duke@0 157 }
duke@0 158 }
coleenp@113 159 T* next_addr = (T*)java_lang_ref_Reference::next_addr(obj);
ysr@2682 160 if (ReferenceProcessor::pending_list_uses_discovered_field()) {
ysr@2682 161 // Treat discovered as normal oop, if ref is not "active",
ysr@2682 162 // i.e. if next is non-NULL.
ysr@2682 163 T next_oop = oopDesc::load_heap_oop(next_addr);
ysr@2682 164 if (!oopDesc::is_null(next_oop)) { // i.e. ref is not "active"
ysr@2682 165 T* discovered_addr = (T*)java_lang_ref_Reference::discovered_addr(obj);
ysr@2682 166 debug_only(
ysr@2682 167 if(TraceReferenceGC && PrintGCDetails) {
ysr@2682 168 gclog_or_tty->print_cr(" Process discovered as normal "
ysr@2682 169 INTPTR_FORMAT, discovered_addr);
ysr@2682 170 }
ysr@2682 171 )
ysr@2682 172 PSParallelCompact::mark_and_push(cm, discovered_addr);
duke@0 173 }
ysr@2682 174 } else {
ysr@2682 175 #ifdef ASSERT
ysr@2682 176 // In the case of older JDKs which do not use the discovered
ysr@2682 177 // field for the pending list, an inactive ref (next != NULL)
ysr@2682 178 // must always have a NULL discovered field.
ysr@2682 179 T next = oopDesc::load_heap_oop(next_addr);
ysr@2682 180 oop discovered = java_lang_ref_Reference::discovered(obj);
ysr@2682 181 assert(oopDesc::is_null(next) || oopDesc::is_null(discovered),
ysr@2682 182 err_msg("Found an inactive reference " PTR_FORMAT " with a non-NULL discovered field",
kvn@2693 183 (oopDesc*)obj));
ysr@2682 184 #endif
ysr@2682 185 }
duke@0 186 PSParallelCompact::mark_and_push(cm, next_addr);
coleenp@3602 187 ref->InstanceKlass::oop_follow_contents(cm, obj);
coleenp@113 188 }
coleenp@113 189
coleenp@3612 190 void InstanceRefKlass::oop_follow_contents(ParCompactionManager* cm,
coleenp@113 191 oop obj) {
coleenp@113 192 if (UseCompressedOops) {
coleenp@113 193 specialized_oop_follow_contents<narrowOop>(this, cm, obj);
coleenp@113 194 } else {
coleenp@113 195 specialized_oop_follow_contents<oop>(this, cm, obj);
coleenp@113 196 }
duke@0 197 }
jprovino@4107 198 #endif // INCLUDE_ALL_GCS
duke@0 199
coleenp@113 200 #ifdef ASSERT
coleenp@113 201 template <class T> void trace_reference_gc(const char *s, oop obj,
coleenp@113 202 T* referent_addr,
coleenp@113 203 T* next_addr,
coleenp@113 204 T* discovered_addr) {
coleenp@113 205 if(TraceReferenceGC && PrintGCDetails) {
coleenp@113 206 gclog_or_tty->print_cr("%s obj " INTPTR_FORMAT, s, (address)obj);
coleenp@113 207 gclog_or_tty->print_cr(" referent_addr/* " INTPTR_FORMAT " / "
coleenp@113 208 INTPTR_FORMAT, referent_addr,
coleenp@113 209 referent_addr ?
coleenp@113 210 (address)oopDesc::load_decode_heap_oop(referent_addr) : NULL);
coleenp@113 211 gclog_or_tty->print_cr(" next_addr/* " INTPTR_FORMAT " / "
coleenp@113 212 INTPTR_FORMAT, next_addr,
coleenp@113 213 next_addr ? (address)oopDesc::load_decode_heap_oop(next_addr) : NULL);
coleenp@113 214 gclog_or_tty->print_cr(" discovered_addr/* " INTPTR_FORMAT " / "
coleenp@113 215 INTPTR_FORMAT, discovered_addr,
coleenp@113 216 discovered_addr ?
coleenp@113 217 (address)oopDesc::load_decode_heap_oop(discovered_addr) : NULL);
coleenp@113 218 }
coleenp@113 219 }
coleenp@113 220 #endif
coleenp@113 221
coleenp@3612 222 template <class T> void specialized_oop_adjust_pointers(InstanceRefKlass *ref, oop obj) {
coleenp@113 223 T* referent_addr = (T*)java_lang_ref_Reference::referent_addr(obj);
coleenp@113 224 MarkSweep::adjust_pointer(referent_addr);
coleenp@113 225 T* next_addr = (T*)java_lang_ref_Reference::next_addr(obj);
coleenp@113 226 MarkSweep::adjust_pointer(next_addr);
coleenp@113 227 T* discovered_addr = (T*)java_lang_ref_Reference::discovered_addr(obj);
coleenp@113 228 MarkSweep::adjust_pointer(discovered_addr);
coleenp@3612 229 debug_only(trace_reference_gc("InstanceRefKlass::oop_adjust_pointers", obj,
coleenp@113 230 referent_addr, next_addr, discovered_addr);)
coleenp@113 231 }
duke@0 232
coleenp@3612 233 int InstanceRefKlass::oop_adjust_pointers(oop obj) {
duke@0 234 int size = size_helper();
coleenp@3602 235 InstanceKlass::oop_adjust_pointers(obj);
duke@0 236
coleenp@113 237 if (UseCompressedOops) {
coleenp@113 238 specialized_oop_adjust_pointers<narrowOop>(this, obj);
coleenp@113 239 } else {
coleenp@113 240 specialized_oop_adjust_pointers<oop>(this, obj);
duke@0 241 }
duke@0 242 return size;
duke@0 243 }
duke@0 244
coleenp@113 245 #define InstanceRefKlass_SPECIALIZED_OOP_ITERATE(T, nv_suffix, contains) \
ysr@2682 246 T* disc_addr = (T*)java_lang_ref_Reference::discovered_addr(obj); \
ysr@342 247 if (closure->apply_to_weak_ref_discovered_field()) { \
ysr@342 248 closure->do_oop##nv_suffix(disc_addr); \
ysr@342 249 } \
ysr@342 250 \
coleenp@113 251 T* referent_addr = (T*)java_lang_ref_Reference::referent_addr(obj); \
ysr@845 252 T heap_oop = oopDesc::load_heap_oop(referent_addr); \
ysr@2682 253 ReferenceProcessor* rp = closure->_ref_processor; \
ysr@2682 254 if (!oopDesc::is_null(heap_oop)) { \
ysr@845 255 oop referent = oopDesc::decode_heap_oop_not_null(heap_oop); \
coleenp@113 256 if (!referent->is_gc_marked() && (rp != NULL) && \
coleenp@113 257 rp->discover_reference(obj, reference_type())) { \
coleenp@113 258 return size; \
ysr@2682 259 } else if (contains(referent_addr)) { \
coleenp@113 260 /* treat referent as normal oop */ \
coleenp@113 261 SpecializationStats::record_do_oop_call##nv_suffix(SpecializationStats::irk);\
coleenp@113 262 closure->do_oop##nv_suffix(referent_addr); \
coleenp@113 263 } \
coleenp@113 264 } \
ysr@2682 265 T* next_addr = (T*)java_lang_ref_Reference::next_addr(obj); \
ysr@2682 266 if (ReferenceProcessor::pending_list_uses_discovered_field()) { \
ysr@2682 267 T next_oop = oopDesc::load_heap_oop(next_addr); \
ysr@2682 268 /* Treat discovered as normal oop, if ref is not "active" (next non-NULL) */\
ysr@2682 269 if (!oopDesc::is_null(next_oop) && contains(disc_addr)) { \
ysr@2682 270 /* i.e. ref is not "active" */ \
ysr@2682 271 debug_only( \
ysr@2682 272 if(TraceReferenceGC && PrintGCDetails) { \
ysr@2682 273 gclog_or_tty->print_cr(" Process discovered as normal " \
ysr@2682 274 INTPTR_FORMAT, disc_addr); \
ysr@2682 275 } \
ysr@2682 276 ) \
ysr@2682 277 SpecializationStats::record_do_oop_call##nv_suffix(SpecializationStats::irk);\
ysr@2682 278 closure->do_oop##nv_suffix(disc_addr); \
ysr@2682 279 } \
ysr@2682 280 } else { \
ysr@2682 281 /* In the case of older JDKs which do not use the discovered field for */ \
ysr@2682 282 /* the pending list, an inactive ref (next != NULL) must always have a */ \
ysr@2682 283 /* NULL discovered field. */ \
ysr@2682 284 debug_only( \
ysr@2682 285 T next_oop = oopDesc::load_heap_oop(next_addr); \
ysr@2682 286 T disc_oop = oopDesc::load_heap_oop(disc_addr); \
ysr@2682 287 assert(oopDesc::is_null(next_oop) || oopDesc::is_null(disc_oop), \
ysr@2682 288 err_msg("Found an inactive reference " PTR_FORMAT " with a non-NULL" \
kvn@2693 289 "discovered field", (oopDesc*)obj)); \
ysr@2682 290 ) \
ysr@2682 291 } \
coleenp@113 292 /* treat next as normal oop */ \
coleenp@113 293 if (contains(next_addr)) { \
coleenp@113 294 SpecializationStats::record_do_oop_call##nv_suffix(SpecializationStats::irk); \
coleenp@113 295 closure->do_oop##nv_suffix(next_addr); \
coleenp@113 296 } \
coleenp@113 297 return size; \
coleenp@113 298
coleenp@113 299
coleenp@113 300 template <class T> bool contains(T *t) { return true; }
coleenp@113 301
coleenp@3612 302 // Macro to define InstanceRefKlass::oop_oop_iterate for virtual/nonvirtual for
coleenp@113 303 // all closures. Macros calling macros above for each oop size.
coleenp@113 304
duke@0 305 #define InstanceRefKlass_OOP_OOP_ITERATE_DEFN(OopClosureType, nv_suffix) \
duke@0 306 \
coleenp@3612 307 int InstanceRefKlass:: \
duke@0 308 oop_oop_iterate##nv_suffix(oop obj, OopClosureType* closure) { \
duke@0 309 /* Get size before changing pointers */ \
duke@0 310 SpecializationStats::record_iterate_call##nv_suffix(SpecializationStats::irk);\
duke@0 311 \
coleenp@3602 312 int size = InstanceKlass::oop_oop_iterate##nv_suffix(obj, closure); \
duke@0 313 \
coleenp@113 314 if (UseCompressedOops) { \
coleenp@113 315 InstanceRefKlass_SPECIALIZED_OOP_ITERATE(narrowOop, nv_suffix, contains); \
coleenp@113 316 } else { \
coleenp@113 317 InstanceRefKlass_SPECIALIZED_OOP_ITERATE(oop, nv_suffix, contains); \
duke@0 318 } \
duke@0 319 }
duke@0 320
jprovino@4107 321 #if INCLUDE_ALL_GCS
ysr@342 322 #define InstanceRefKlass_OOP_OOP_ITERATE_BACKWARDS_DEFN(OopClosureType, nv_suffix) \
ysr@342 323 \
coleenp@3612 324 int InstanceRefKlass:: \
ysr@342 325 oop_oop_iterate_backwards##nv_suffix(oop obj, OopClosureType* closure) { \
ysr@342 326 /* Get size before changing pointers */ \
ysr@342 327 SpecializationStats::record_iterate_call##nv_suffix(SpecializationStats::irk);\
ysr@342 328 \
coleenp@3602 329 int size = InstanceKlass::oop_oop_iterate_backwards##nv_suffix(obj, closure); \
ysr@342 330 \
ysr@342 331 if (UseCompressedOops) { \
ysr@342 332 InstanceRefKlass_SPECIALIZED_OOP_ITERATE(narrowOop, nv_suffix, contains); \
ysr@342 333 } else { \
ysr@342 334 InstanceRefKlass_SPECIALIZED_OOP_ITERATE(oop, nv_suffix, contains); \
ysr@342 335 } \
ysr@342 336 }
jprovino@4107 337 #endif // INCLUDE_ALL_GCS
ysr@342 338
ysr@342 339
duke@0 340 #define InstanceRefKlass_OOP_OOP_ITERATE_DEFN_m(OopClosureType, nv_suffix) \
duke@0 341 \
coleenp@3612 342 int InstanceRefKlass:: \
duke@0 343 oop_oop_iterate##nv_suffix##_m(oop obj, \
duke@0 344 OopClosureType* closure, \
duke@0 345 MemRegion mr) { \
duke@0 346 SpecializationStats::record_iterate_call##nv_suffix(SpecializationStats::irk);\
duke@0 347 \
coleenp@3602 348 int size = InstanceKlass::oop_oop_iterate##nv_suffix##_m(obj, closure, mr); \
coleenp@113 349 if (UseCompressedOops) { \
coleenp@113 350 InstanceRefKlass_SPECIALIZED_OOP_ITERATE(narrowOop, nv_suffix, mr.contains); \
coleenp@113 351 } else { \
coleenp@113 352 InstanceRefKlass_SPECIALIZED_OOP_ITERATE(oop, nv_suffix, mr.contains); \
duke@0 353 } \
duke@0 354 }
duke@0 355
duke@0 356 ALL_OOP_OOP_ITERATE_CLOSURES_1(InstanceRefKlass_OOP_OOP_ITERATE_DEFN)
ysr@342 357 ALL_OOP_OOP_ITERATE_CLOSURES_2(InstanceRefKlass_OOP_OOP_ITERATE_DEFN)
jprovino@4107 358 #if INCLUDE_ALL_GCS
ysr@342 359 ALL_OOP_OOP_ITERATE_CLOSURES_1(InstanceRefKlass_OOP_OOP_ITERATE_BACKWARDS_DEFN)
ysr@342 360 ALL_OOP_OOP_ITERATE_CLOSURES_2(InstanceRefKlass_OOP_OOP_ITERATE_BACKWARDS_DEFN)
jprovino@4107 361 #endif // INCLUDE_ALL_GCS
duke@0 362 ALL_OOP_OOP_ITERATE_CLOSURES_1(InstanceRefKlass_OOP_OOP_ITERATE_DEFN_m)
ysr@342 363 ALL_OOP_OOP_ITERATE_CLOSURES_2(InstanceRefKlass_OOP_OOP_ITERATE_DEFN_m)
duke@0 364
jprovino@4107 365 #if INCLUDE_ALL_GCS
coleenp@113 366 template <class T>
coleenp@3612 367 void specialized_oop_push_contents(InstanceRefKlass *ref,
coleenp@113 368 PSPromotionManager* pm, oop obj) {
coleenp@113 369 T* referent_addr = (T*)java_lang_ref_Reference::referent_addr(obj);
coleenp@113 370 if (PSScavenge::should_scavenge(referent_addr)) {
duke@0 371 ReferenceProcessor* rp = PSScavenge::reference_processor();
coleenp@113 372 if (rp->discover_reference(obj, ref->reference_type())) {
duke@0 373 // reference already enqueued, referent and next will be traversed later
coleenp@3602 374 ref->InstanceKlass::oop_push_contents(pm, obj);
duke@0 375 return;
duke@0 376 } else {
duke@0 377 // treat referent as normal oop
duke@0 378 pm->claim_or_forward_depth(referent_addr);
duke@0 379 }
duke@0 380 }
ysr@2682 381 // Treat discovered as normal oop, if ref is not "active",
ysr@2682 382 // i.e. if next is non-NULL.
coleenp@113 383 T* next_addr = (T*)java_lang_ref_Reference::next_addr(obj);
ysr@2682 384 if (ReferenceProcessor::pending_list_uses_discovered_field()) {
ysr@2682 385 T next_oop = oopDesc::load_heap_oop(next_addr);
ysr@2682 386 if (!oopDesc::is_null(next_oop)) { // i.e. ref is not "active"
ysr@2682 387 T* discovered_addr = (T*)java_lang_ref_Reference::discovered_addr(obj);
ysr@2682 388 debug_only(
ysr@2682 389 if(TraceReferenceGC && PrintGCDetails) {
ysr@2682 390 gclog_or_tty->print_cr(" Process discovered as normal "
ysr@2682 391 INTPTR_FORMAT, discovered_addr);
ysr@2682 392 }
ysr@2682 393 )
ysr@2682 394 if (PSScavenge::should_scavenge(discovered_addr)) {
ysr@2682 395 pm->claim_or_forward_depth(discovered_addr);
ysr@2682 396 }
ysr@2682 397 }
ysr@2682 398 } else {
ysr@2682 399 #ifdef ASSERT
ysr@2682 400 // In the case of older JDKs which do not use the discovered
ysr@2682 401 // field for the pending list, an inactive ref (next != NULL)
ysr@2682 402 // must always have a NULL discovered field.
ysr@2682 403 oop next = oopDesc::load_decode_heap_oop(next_addr);
ysr@2682 404 oop discovered = java_lang_ref_Reference::discovered(obj);
ysr@2682 405 assert(oopDesc::is_null(next) || oopDesc::is_null(discovered),
ysr@2682 406 err_msg("Found an inactive reference " PTR_FORMAT " with a non-NULL discovered field",
kvn@2693 407 (oopDesc*)obj));
ysr@2682 408 #endif
ysr@2682 409 }
ysr@2682 410
ysr@2682 411 // Treat next as normal oop; next is a link in the reference queue.
coleenp@113 412 if (PSScavenge::should_scavenge(next_addr)) {
duke@0 413 pm->claim_or_forward_depth(next_addr);
duke@0 414 }
coleenp@3602 415 ref->InstanceKlass::oop_push_contents(pm, obj);
coleenp@113 416 }
coleenp@113 417
coleenp@3612 418 void InstanceRefKlass::oop_push_contents(PSPromotionManager* pm, oop obj) {
coleenp@113 419 if (UseCompressedOops) {
coleenp@113 420 specialized_oop_push_contents<narrowOop>(this, pm, obj);
coleenp@113 421 } else {
coleenp@113 422 specialized_oop_push_contents<oop>(this, pm, obj);
coleenp@113 423 }
coleenp@113 424 }
coleenp@113 425
coleenp@113 426 template <class T>
coleenp@3612 427 void specialized_oop_update_pointers(InstanceRefKlass *ref,
coleenp@113 428 ParCompactionManager* cm, oop obj) {
coleenp@113 429 T* referent_addr = (T*)java_lang_ref_Reference::referent_addr(obj);
coleenp@113 430 PSParallelCompact::adjust_pointer(referent_addr);
coleenp@113 431 T* next_addr = (T*)java_lang_ref_Reference::next_addr(obj);
coleenp@113 432 PSParallelCompact::adjust_pointer(next_addr);
coleenp@113 433 T* discovered_addr = (T*)java_lang_ref_Reference::discovered_addr(obj);
coleenp@113 434 PSParallelCompact::adjust_pointer(discovered_addr);
coleenp@3612 435 debug_only(trace_reference_gc("InstanceRefKlass::oop_update_ptrs", obj,
coleenp@113 436 referent_addr, next_addr, discovered_addr);)
duke@0 437 }
duke@0 438
coleenp@3612 439 int InstanceRefKlass::oop_update_pointers(ParCompactionManager* cm, oop obj) {
coleenp@3602 440 InstanceKlass::oop_update_pointers(cm, obj);
coleenp@113 441 if (UseCompressedOops) {
coleenp@113 442 specialized_oop_update_pointers<narrowOop>(this, cm, obj);
coleenp@113 443 } else {
coleenp@113 444 specialized_oop_update_pointers<oop>(this, cm, obj);
coleenp@113 445 }
coleenp@113 446 return size_helper();
coleenp@113 447 }
jprovino@4107 448 #endif // INCLUDE_ALL_GCS
duke@0 449
coleenp@3612 450 void InstanceRefKlass::update_nonstatic_oop_maps(Klass* k) {
duke@0 451 // Clear the nonstatic oop-map entries corresponding to referent
duke@0 452 // and nextPending field. They are treated specially by the
duke@0 453 // garbage collector.
duke@0 454 // The discovered field is used only by the garbage collector
duke@0 455 // and is also treated specially.
coleenp@3602 456 InstanceKlass* ik = InstanceKlass::cast(k);
duke@0 457
duke@0 458 // Check that we have the right class
duke@0 459 debug_only(static bool first_time = true);
never@1142 460 assert(k == SystemDictionary::Reference_klass() && first_time,
duke@0 461 "Invalid update of maps");
duke@0 462 debug_only(first_time = false);
jcoomes@938 463 assert(ik->nonstatic_oop_map_count() == 1, "just checking");
duke@0 464
duke@0 465 OopMapBlock* map = ik->start_of_nonstatic_oop_maps();
duke@0 466
duke@0 467 // Check that the current map is (2,4) - currently points at field with
duke@0 468 // offset 2 (words) and has 4 map entries.
duke@0 469 debug_only(int offset = java_lang_ref_Reference::referent_offset);
jcoomes@939 470 debug_only(unsigned int count = ((java_lang_ref_Reference::discovered_offset -
coleenp@113 471 java_lang_ref_Reference::referent_offset)/heapOopSize) + 1);
duke@0 472
duke@0 473 if (UseSharedSpaces) {
duke@0 474 assert(map->offset() == java_lang_ref_Reference::queue_offset &&
jcoomes@938 475 map->count() == 1, "just checking");
duke@0 476 } else {
jcoomes@938 477 assert(map->offset() == offset && map->count() == count,
duke@0 478 "just checking");
duke@0 479
duke@0 480 // Update map to (3,1) - point to offset of 3 (words) with 1 map entry.
duke@0 481 map->set_offset(java_lang_ref_Reference::queue_offset);
jcoomes@938 482 map->set_count(1);
duke@0 483 }
duke@0 484 }
duke@0 485
duke@0 486
duke@0 487 // Verification
duke@0 488
coleenp@3612 489 void InstanceRefKlass::oop_verify_on(oop obj, outputStream* st) {
coleenp@3602 490 InstanceKlass::oop_verify_on(obj, st);
duke@0 491 // Verify referent field
duke@0 492 oop referent = java_lang_ref_Reference::referent(obj);
duke@0 493
duke@0 494 // We should make this general to all heaps
duke@0 495 GenCollectedHeap* gch = NULL;
duke@0 496 if (Universe::heap()->kind() == CollectedHeap::GenCollectedHeap)
duke@0 497 gch = GenCollectedHeap::heap();
duke@0 498
duke@0 499 if (referent != NULL) {
duke@0 500 guarantee(referent->is_oop(), "referent field heap failed");
duke@0 501 }
duke@0 502 // Verify next field
duke@0 503 oop next = java_lang_ref_Reference::next(obj);
duke@0 504 if (next != NULL) {
ysr@342 505 guarantee(next->is_oop(), "next field verify failed");
duke@0 506 guarantee(next->is_instanceRef(), "next field verify failed");
duke@0 507 }
duke@0 508 }
duke@0 509
coleenp@3612 510 bool InstanceRefKlass::owns_pending_list_lock(JavaThread* thread) {
coleenp@1932 511 if (java_lang_ref_Reference::pending_list_lock() == NULL) return false;
coleenp@1928 512 Handle h_lock(thread, java_lang_ref_Reference::pending_list_lock());
coleenp@1928 513 return ObjectSynchronizer::current_thread_holds_lock(thread, h_lock);
coleenp@1928 514 }
coleenp@1928 515
coleenp@3612 516 void InstanceRefKlass::acquire_pending_list_lock(BasicLock *pending_list_basic_lock) {
duke@0 517 // we may enter this with pending exception set
duke@0 518 PRESERVE_EXCEPTION_MARK; // exceptions are never thrown, needed for TRAPS argument
johnc@3376 519
johnc@3376 520 // Create a HandleMark in case we retry a GC multiple times.
johnc@3376 521 // Each time we attempt the GC, we allocate the handle below
johnc@3376 522 // to hold the pending list lock. We want to free this handle.
johnc@3376 523 HandleMark hm;
johnc@3376 524
duke@0 525 Handle h_lock(THREAD, java_lang_ref_Reference::pending_list_lock());
duke@0 526 ObjectSynchronizer::fast_enter(h_lock, pending_list_basic_lock, false, THREAD);
duke@0 527 assert(ObjectSynchronizer::current_thread_holds_lock(
duke@0 528 JavaThread::current(), h_lock),
duke@0 529 "Locking should have succeeded");
duke@0 530 if (HAS_PENDING_EXCEPTION) CLEAR_PENDING_EXCEPTION;
duke@0 531 }
duke@0 532
coleenp@3612 533 void InstanceRefKlass::release_and_notify_pending_list_lock(
duke@0 534 BasicLock *pending_list_basic_lock) {
duke@0 535 // we may enter this with pending exception set
duke@0 536 PRESERVE_EXCEPTION_MARK; // exceptions are never thrown, needed for TRAPS argument
johnc@3376 537
johnc@3376 538 // Create a HandleMark in case we retry a GC multiple times.
johnc@3376 539 // Each time we attempt the GC, we allocate the handle below
johnc@3376 540 // to hold the pending list lock. We want to free this handle.
johnc@3376 541 HandleMark hm;
johnc@3376 542
duke@0 543 Handle h_lock(THREAD, java_lang_ref_Reference::pending_list_lock());
duke@0 544 assert(ObjectSynchronizer::current_thread_holds_lock(
duke@0 545 JavaThread::current(), h_lock),
duke@0 546 "Lock should be held");
duke@0 547 // Notify waiters on pending lists lock if there is any reference.
duke@0 548 if (java_lang_ref_Reference::pending_list() != NULL) {
duke@0 549 ObjectSynchronizer::notifyall(h_lock, THREAD);
duke@0 550 }
duke@0 551 ObjectSynchronizer::fast_exit(h_lock(), pending_list_basic_lock, THREAD);
duke@0 552 if (HAS_PENDING_EXCEPTION) CLEAR_PENDING_EXCEPTION;
duke@0 553 }