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