src/share/vm/gc_implementation/g1/g1RootProcessor.cpp

Thu, 14 Jun 2018 09:15:08 -0700

author
kevinw
date
Thu, 14 Jun 2018 09:15:08 -0700
changeset 9327
f96fcd9e1e1b
parent 8070
c0205eddb317
child 9358
6a4a6c499e89
permissions
-rw-r--r--

8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
Summary: Need to add a space between macro identifier and string literal
Reviewed-by: bpittore, stefank, dholmes, kbarrett

mgerdin@7659 1 /*
mgerdin@7659 2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
mgerdin@7659 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
mgerdin@7659 4 *
mgerdin@7659 5 * This code is free software; you can redistribute it and/or modify it
mgerdin@7659 6 * under the terms of the GNU General Public License version 2 only, as
mgerdin@7659 7 * published by the Free Software Foundation.
mgerdin@7659 8 *
mgerdin@7659 9 * This code is distributed in the hope that it will be useful, but WITHOUT
mgerdin@7659 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
mgerdin@7659 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
mgerdin@7659 12 * version 2 for more details (a copy is included in the LICENSE file that
mgerdin@7659 13 * accompanied this code).
mgerdin@7659 14 *
mgerdin@7659 15 * You should have received a copy of the GNU General Public License version
mgerdin@7659 16 * 2 along with this work; if not, write to the Free Software Foundation,
mgerdin@7659 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
mgerdin@7659 18 *
mgerdin@7659 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
mgerdin@7659 20 * or visit www.oracle.com if you need additional information or have any
mgerdin@7659 21 * questions.
mgerdin@7659 22 *
mgerdin@7659 23 */
mgerdin@7659 24
mgerdin@7659 25 #include "precompiled.hpp"
mgerdin@7659 26
mgerdin@7659 27 #include "classfile/symbolTable.hpp"
mgerdin@7659 28 #include "classfile/systemDictionary.hpp"
mgerdin@7659 29 #include "code/codeCache.hpp"
mgerdin@7659 30 #include "gc_implementation/g1/bufferingOopClosure.hpp"
mgerdin@7659 31 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
mgerdin@7659 32 #include "gc_implementation/g1/g1CollectorPolicy.hpp"
mgerdin@7659 33 #include "gc_implementation/g1/g1GCPhaseTimes.hpp"
mgerdin@7659 34 #include "gc_implementation/g1/g1RemSet.inline.hpp"
mgerdin@7659 35 #include "gc_implementation/g1/g1RootProcessor.hpp"
mgerdin@7659 36 #include "memory/allocation.inline.hpp"
mgerdin@7659 37 #include "runtime/fprofiler.hpp"
mgerdin@7659 38 #include "runtime/mutex.hpp"
mgerdin@7659 39 #include "services/management.hpp"
mgerdin@7659 40
mgerdin@7659 41 class G1CodeBlobClosure : public CodeBlobClosure {
mgerdin@7659 42 class HeapRegionGatheringOopClosure : public OopClosure {
mgerdin@7659 43 G1CollectedHeap* _g1h;
mgerdin@7659 44 OopClosure* _work;
mgerdin@7659 45 nmethod* _nm;
mgerdin@7659 46
mgerdin@7659 47 template <typename T>
mgerdin@7659 48 void do_oop_work(T* p) {
mgerdin@7659 49 _work->do_oop(p);
mgerdin@7659 50 T oop_or_narrowoop = oopDesc::load_heap_oop(p);
mgerdin@7659 51 if (!oopDesc::is_null(oop_or_narrowoop)) {
mgerdin@7659 52 oop o = oopDesc::decode_heap_oop_not_null(oop_or_narrowoop);
mgerdin@7659 53 HeapRegion* hr = _g1h->heap_region_containing_raw(o);
mgerdin@7659 54 assert(!_g1h->obj_in_cs(o) || hr->rem_set()->strong_code_roots_list_contains(_nm), "if o still in CS then evacuation failed and nm must already be in the remset");
mgerdin@7659 55 hr->add_strong_code_root(_nm);
mgerdin@7659 56 }
mgerdin@7659 57 }
mgerdin@7659 58
mgerdin@7659 59 public:
mgerdin@7659 60 HeapRegionGatheringOopClosure(OopClosure* oc) : _g1h(G1CollectedHeap::heap()), _work(oc), _nm(NULL) {}
mgerdin@7659 61
mgerdin@7659 62 void do_oop(oop* o) {
mgerdin@7659 63 do_oop_work(o);
mgerdin@7659 64 }
mgerdin@7659 65
mgerdin@7659 66 void do_oop(narrowOop* o) {
mgerdin@7659 67 do_oop_work(o);
mgerdin@7659 68 }
mgerdin@7659 69
mgerdin@7659 70 void set_nm(nmethod* nm) {
mgerdin@7659 71 _nm = nm;
mgerdin@7659 72 }
mgerdin@7659 73 };
mgerdin@7659 74
mgerdin@7659 75 HeapRegionGatheringOopClosure _oc;
mgerdin@7659 76 public:
mgerdin@7659 77 G1CodeBlobClosure(OopClosure* oc) : _oc(oc) {}
mgerdin@7659 78
mgerdin@7659 79 void do_code_blob(CodeBlob* cb) {
mgerdin@7659 80 nmethod* nm = cb->as_nmethod_or_null();
mgerdin@7659 81 if (nm != NULL) {
mgerdin@7659 82 if (!nm->test_set_oops_do_mark()) {
mgerdin@7659 83 _oc.set_nm(nm);
mgerdin@7659 84 nm->oops_do(&_oc);
mgerdin@7659 85 nm->fix_oop_relocations();
mgerdin@7659 86 }
mgerdin@7659 87 }
mgerdin@7659 88 }
mgerdin@7659 89 };
mgerdin@7659 90
mgerdin@7659 91
mgerdin@7659 92 void G1RootProcessor::worker_has_discovered_all_strong_classes() {
mgerdin@7659 93 uint n_workers = _g1h->n_par_threads();
mgerdin@7659 94 assert(ClassUnloadingWithConcurrentMark, "Currently only needed when doing G1 Class Unloading");
mgerdin@7659 95
sangheki@7764 96 if (n_workers > 0) {
sangheki@7764 97 uint new_value = (uint)Atomic::add(1, &_n_workers_discovered_strong_classes);
sangheki@7764 98 if (new_value == n_workers) {
sangheki@7764 99 // This thread is last. Notify the others.
sangheki@7764 100 MonitorLockerEx ml(&_lock, Mutex::_no_safepoint_check_flag);
sangheki@7764 101 _lock.notify_all();
sangheki@7764 102 }
mgerdin@7659 103 }
mgerdin@7659 104 }
mgerdin@7659 105
mgerdin@7659 106 void G1RootProcessor::wait_until_all_strong_classes_discovered() {
mgerdin@7659 107 uint n_workers = _g1h->n_par_threads();
mgerdin@7659 108 assert(ClassUnloadingWithConcurrentMark, "Currently only needed when doing G1 Class Unloading");
mgerdin@7659 109
sangheki@7764 110 if (n_workers > 0 && (uint)_n_workers_discovered_strong_classes != n_workers) {
mgerdin@7659 111 MonitorLockerEx ml(&_lock, Mutex::_no_safepoint_check_flag);
mgerdin@7659 112 while ((uint)_n_workers_discovered_strong_classes != n_workers) {
mgerdin@7659 113 _lock.wait(Mutex::_no_safepoint_check_flag, 0, false);
mgerdin@7659 114 }
mgerdin@7659 115 }
mgerdin@7659 116 }
mgerdin@7659 117
mgerdin@7659 118 G1RootProcessor::G1RootProcessor(G1CollectedHeap* g1h) :
mgerdin@7659 119 _g1h(g1h),
mgerdin@8070 120 _process_strong_tasks(G1RP_PS_NumElements),
mgerdin@7659 121 _srs(g1h),
mgerdin@7659 122 _lock(Mutex::leaf, "G1 Root Scanning barrier lock", false),
mgerdin@7659 123 _n_workers_discovered_strong_classes(0) {}
mgerdin@7659 124
mgerdin@7659 125 void G1RootProcessor::evacuate_roots(OopClosure* scan_non_heap_roots,
mgerdin@7659 126 OopClosure* scan_non_heap_weak_roots,
mgerdin@7659 127 CLDClosure* scan_strong_clds,
mgerdin@7659 128 CLDClosure* scan_weak_clds,
mgerdin@7659 129 bool trace_metadata,
mgerdin@7659 130 uint worker_i) {
mgerdin@7659 131 // First scan the shared roots.
mgerdin@7659 132 double ext_roots_start = os::elapsedTime();
brutisso@7660 133 G1GCPhaseTimes* phase_times = _g1h->g1_policy()->phase_times();
mgerdin@7659 134
mgerdin@7659 135 BufferingOopClosure buf_scan_non_heap_roots(scan_non_heap_roots);
mgerdin@7659 136 BufferingOopClosure buf_scan_non_heap_weak_roots(scan_non_heap_weak_roots);
mgerdin@7659 137
mgerdin@7659 138 OopClosure* const weak_roots = &buf_scan_non_heap_weak_roots;
mgerdin@7659 139 OopClosure* const strong_roots = &buf_scan_non_heap_roots;
mgerdin@7659 140
mgerdin@7659 141 // CodeBlobClosures are not interoperable with BufferingOopClosures
mgerdin@7659 142 G1CodeBlobClosure root_code_blobs(scan_non_heap_roots);
mgerdin@7659 143
mgerdin@7659 144 process_java_roots(strong_roots,
mgerdin@7659 145 trace_metadata ? scan_strong_clds : NULL,
mgerdin@7659 146 scan_strong_clds,
mgerdin@7659 147 trace_metadata ? NULL : scan_weak_clds,
brutisso@7660 148 &root_code_blobs,
brutisso@7660 149 phase_times,
brutisso@7660 150 worker_i);
mgerdin@7659 151
mgerdin@7659 152 // This is the point where this worker thread will not find more strong CLDs/nmethods.
mgerdin@7659 153 // Report this so G1 can synchronize the strong and weak CLDs/nmethods processing.
mgerdin@7659 154 if (trace_metadata) {
mgerdin@7659 155 worker_has_discovered_all_strong_classes();
mgerdin@7659 156 }
mgerdin@7659 157
brutisso@7660 158 process_vm_roots(strong_roots, weak_roots, phase_times, worker_i);
mgerdin@7659 159
brutisso@7660 160 {
brutisso@7660 161 // Now the CM ref_processor roots.
brutisso@7660 162 G1GCParPhaseTimesTracker x(phase_times, G1GCPhaseTimes::CMRefRoots, worker_i);
mgerdin@8070 163 if (!_process_strong_tasks.is_task_claimed(G1RP_PS_refProcessor_oops_do)) {
brutisso@7660 164 // We need to treat the discovered reference lists of the
brutisso@7660 165 // concurrent mark ref processor as roots and keep entries
brutisso@7660 166 // (which are added by the marking threads) on them live
brutisso@7660 167 // until they can be processed at the end of marking.
brutisso@7660 168 _g1h->ref_processor_cm()->weak_oops_do(&buf_scan_non_heap_roots);
brutisso@7660 169 }
mgerdin@7659 170 }
mgerdin@7659 171
mgerdin@7659 172 if (trace_metadata) {
brutisso@7660 173 {
brutisso@7660 174 G1GCParPhaseTimesTracker x(phase_times, G1GCPhaseTimes::WaitForStrongCLD, worker_i);
brutisso@7660 175 // Barrier to make sure all workers passed
brutisso@7660 176 // the strong CLD and strong nmethods phases.
brutisso@7660 177 wait_until_all_strong_classes_discovered();
brutisso@7660 178 }
mgerdin@7659 179
mgerdin@7659 180 // Now take the complement of the strong CLDs.
brutisso@7660 181 G1GCParPhaseTimesTracker x(phase_times, G1GCPhaseTimes::WeakCLDRoots, worker_i);
mgerdin@7659 182 ClassLoaderDataGraph::roots_cld_do(NULL, scan_weak_clds);
brutisso@7660 183 } else {
brutisso@7660 184 phase_times->record_time_secs(G1GCPhaseTimes::WaitForStrongCLD, worker_i, 0.0);
brutisso@7660 185 phase_times->record_time_secs(G1GCPhaseTimes::WeakCLDRoots, worker_i, 0.0);
mgerdin@7659 186 }
mgerdin@7659 187
mgerdin@7659 188 // Finish up any enqueued closure apps (attributed as object copy time).
mgerdin@7659 189 buf_scan_non_heap_roots.done();
mgerdin@7659 190 buf_scan_non_heap_weak_roots.done();
mgerdin@7659 191
mgerdin@7659 192 double obj_copy_time_sec = buf_scan_non_heap_roots.closure_app_seconds()
mgerdin@7659 193 + buf_scan_non_heap_weak_roots.closure_app_seconds();
mgerdin@7659 194
mgerdin@7659 195 phase_times->record_time_secs(G1GCPhaseTimes::ObjCopy, worker_i, obj_copy_time_sec);
mgerdin@7659 196
mgerdin@7659 197 double ext_root_time_sec = os::elapsedTime() - ext_roots_start - obj_copy_time_sec;
mgerdin@7659 198
mgerdin@7659 199 phase_times->record_time_secs(G1GCPhaseTimes::ExtRootScan, worker_i, ext_root_time_sec);
mgerdin@7659 200
mgerdin@7659 201 // During conc marking we have to filter the per-thread SATB buffers
mgerdin@7659 202 // to make sure we remove any oops into the CSet (which will show up
mgerdin@7659 203 // as implicitly live).
mgerdin@7659 204 {
mgerdin@7659 205 G1GCParPhaseTimesTracker x(phase_times, G1GCPhaseTimes::SATBFiltering, worker_i);
mgerdin@8070 206 if (!_process_strong_tasks.is_task_claimed(G1RP_PS_filter_satb_buffers) && _g1h->mark_in_progress()) {
mgerdin@7659 207 JavaThread::satb_mark_queue_set().filter_thread_buffers();
mgerdin@7659 208 }
mgerdin@7659 209 }
mgerdin@7659 210
mgerdin@8070 211 _process_strong_tasks.all_tasks_completed();
mgerdin@7659 212 }
mgerdin@7659 213
mgerdin@7659 214 void G1RootProcessor::process_strong_roots(OopClosure* oops,
mgerdin@7659 215 CLDClosure* clds,
mgerdin@7659 216 CodeBlobClosure* blobs) {
mgerdin@7659 217
brutisso@7660 218 process_java_roots(oops, clds, clds, NULL, blobs, NULL, 0);
brutisso@7660 219 process_vm_roots(oops, NULL, NULL, 0);
mgerdin@7659 220
mgerdin@8070 221 _process_strong_tasks.all_tasks_completed();
mgerdin@7659 222 }
mgerdin@7659 223
mgerdin@7659 224 void G1RootProcessor::process_all_roots(OopClosure* oops,
mgerdin@7659 225 CLDClosure* clds,
mgerdin@7659 226 CodeBlobClosure* blobs) {
mgerdin@7659 227
brutisso@7660 228 process_java_roots(oops, NULL, clds, clds, NULL, NULL, 0);
brutisso@7660 229 process_vm_roots(oops, oops, NULL, 0);
mgerdin@7659 230
mgerdin@8070 231 if (!_process_strong_tasks.is_task_claimed(G1RP_PS_CodeCache_oops_do)) {
mgerdin@7659 232 CodeCache::blobs_do(blobs);
mgerdin@7659 233 }
mgerdin@7659 234
mgerdin@8070 235 _process_strong_tasks.all_tasks_completed();
mgerdin@7659 236 }
mgerdin@7659 237
mgerdin@7659 238 void G1RootProcessor::process_java_roots(OopClosure* strong_roots,
mgerdin@7659 239 CLDClosure* thread_stack_clds,
mgerdin@7659 240 CLDClosure* strong_clds,
mgerdin@7659 241 CLDClosure* weak_clds,
brutisso@7660 242 CodeBlobClosure* strong_code,
brutisso@7660 243 G1GCPhaseTimes* phase_times,
brutisso@7660 244 uint worker_i) {
mgerdin@7659 245 assert(thread_stack_clds == NULL || weak_clds == NULL, "There is overlap between those, only one may be set");
mgerdin@7659 246 // Iterating over the CLDG and the Threads are done early to allow us to
mgerdin@7659 247 // first process the strong CLDs and nmethods and then, after a barrier,
mgerdin@7659 248 // let the thread process the weak CLDs and nmethods.
brutisso@7660 249 {
brutisso@7660 250 G1GCParPhaseTimesTracker x(phase_times, G1GCPhaseTimes::CLDGRoots, worker_i);
mgerdin@8070 251 if (!_process_strong_tasks.is_task_claimed(G1RP_PS_ClassLoaderDataGraph_oops_do)) {
brutisso@7660 252 ClassLoaderDataGraph::roots_cld_do(strong_clds, weak_clds);
brutisso@7660 253 }
mgerdin@7659 254 }
mgerdin@7659 255
brutisso@7660 256 {
brutisso@7660 257 G1GCParPhaseTimesTracker x(phase_times, G1GCPhaseTimes::ThreadRoots, worker_i);
brutisso@7660 258 Threads::possibly_parallel_oops_do(strong_roots, thread_stack_clds, strong_code);
brutisso@7660 259 }
mgerdin@7659 260 }
mgerdin@7659 261
mgerdin@7659 262 void G1RootProcessor::process_vm_roots(OopClosure* strong_roots,
brutisso@7660 263 OopClosure* weak_roots,
brutisso@7660 264 G1GCPhaseTimes* phase_times,
brutisso@7660 265 uint worker_i) {
brutisso@7660 266 {
brutisso@7660 267 G1GCParPhaseTimesTracker x(phase_times, G1GCPhaseTimes::UniverseRoots, worker_i);
mgerdin@8070 268 if (!_process_strong_tasks.is_task_claimed(G1RP_PS_Universe_oops_do)) {
brutisso@7660 269 Universe::oops_do(strong_roots);
brutisso@7660 270 }
mgerdin@7659 271 }
mgerdin@7659 272
brutisso@7660 273 {
brutisso@7660 274 G1GCParPhaseTimesTracker x(phase_times, G1GCPhaseTimes::JNIRoots, worker_i);
mgerdin@8070 275 if (!_process_strong_tasks.is_task_claimed(G1RP_PS_JNIHandles_oops_do)) {
brutisso@7660 276 JNIHandles::oops_do(strong_roots);
brutisso@7660 277 }
mgerdin@7659 278 }
mgerdin@7659 279
brutisso@7660 280 {
brutisso@7660 281 G1GCParPhaseTimesTracker x(phase_times, G1GCPhaseTimes::ObjectSynchronizerRoots, worker_i);
mgerdin@8070 282 if (!_process_strong_tasks.is_task_claimed(G1RP_PS_ObjectSynchronizer_oops_do)) {
brutisso@7660 283 ObjectSynchronizer::oops_do(strong_roots);
brutisso@7660 284 }
mgerdin@7659 285 }
mgerdin@7659 286
brutisso@7660 287 {
brutisso@7660 288 G1GCParPhaseTimesTracker x(phase_times, G1GCPhaseTimes::FlatProfilerRoots, worker_i);
mgerdin@8070 289 if (!_process_strong_tasks.is_task_claimed(G1RP_PS_FlatProfiler_oops_do)) {
brutisso@7660 290 FlatProfiler::oops_do(strong_roots);
brutisso@7660 291 }
mgerdin@7659 292 }
mgerdin@7659 293
brutisso@7660 294 {
brutisso@7660 295 G1GCParPhaseTimesTracker x(phase_times, G1GCPhaseTimes::ManagementRoots, worker_i);
mgerdin@8070 296 if (!_process_strong_tasks.is_task_claimed(G1RP_PS_Management_oops_do)) {
brutisso@7660 297 Management::oops_do(strong_roots);
brutisso@7660 298 }
mgerdin@7659 299 }
mgerdin@7659 300
brutisso@7660 301 {
brutisso@7660 302 G1GCParPhaseTimesTracker x(phase_times, G1GCPhaseTimes::JVMTIRoots, worker_i);
mgerdin@8070 303 if (!_process_strong_tasks.is_task_claimed(G1RP_PS_jvmti_oops_do)) {
brutisso@7660 304 JvmtiExport::oops_do(strong_roots);
brutisso@7660 305 }
mgerdin@7659 306 }
mgerdin@7659 307
brutisso@7660 308 {
brutisso@7660 309 G1GCParPhaseTimesTracker x(phase_times, G1GCPhaseTimes::SystemDictionaryRoots, worker_i);
mgerdin@8070 310 if (!_process_strong_tasks.is_task_claimed(G1RP_PS_SystemDictionary_oops_do)) {
brutisso@7660 311 SystemDictionary::roots_oops_do(strong_roots, weak_roots);
brutisso@7660 312 }
mgerdin@7659 313 }
mgerdin@7659 314
brutisso@7660 315 {
brutisso@7660 316 G1GCParPhaseTimesTracker x(phase_times, G1GCPhaseTimes::StringTableRoots, worker_i);
brutisso@7660 317 // All threads execute the following. A specific chunk of buckets
brutisso@7660 318 // from the StringTable are the individual tasks.
brutisso@7660 319 if (weak_roots != NULL) {
brutisso@7660 320 StringTable::possibly_parallel_oops_do(weak_roots);
brutisso@7660 321 }
mgerdin@7659 322 }
mgerdin@7659 323 }
mgerdin@7659 324
mgerdin@7659 325 void G1RootProcessor::scan_remembered_sets(G1ParPushHeapRSClosure* scan_rs,
mgerdin@7659 326 OopClosure* scan_non_heap_weak_roots,
mgerdin@7659 327 uint worker_i) {
brutisso@7660 328 G1GCPhaseTimes* phase_times = _g1h->g1_policy()->phase_times();
brutisso@7660 329 G1GCParPhaseTimesTracker x(phase_times, G1GCPhaseTimes::CodeCacheRoots, worker_i);
brutisso@7660 330
mgerdin@7659 331 // Now scan the complement of the collection set.
mgerdin@7659 332 G1CodeBlobClosure scavenge_cs_nmethods(scan_non_heap_weak_roots);
mgerdin@7659 333
mgerdin@7659 334 _g1h->g1_rem_set()->oops_into_collection_set_do(scan_rs, &scavenge_cs_nmethods, worker_i);
mgerdin@7659 335 }
mgerdin@7659 336
mgerdin@7659 337 void G1RootProcessor::set_num_workers(int active_workers) {
mgerdin@8070 338 _process_strong_tasks.set_n_threads(active_workers);
mgerdin@7659 339 }

mercurial