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