1 /* 2 * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #ifndef SHARE_VM_GC_G1_G1ROOTPROCESSOR_HPP 26 #define SHARE_VM_GC_G1_G1ROOTPROCESSOR_HPP 27 28 #include "gc/shared/oopStorageParState.hpp" 29 #include "gc/shared/strongRootsScope.hpp" 30 #include "memory/allocation.hpp" 31 #include "runtime/mutex.hpp" 32 33 class CLDClosure; 34 class CodeBlobClosure; 35 class G1CollectedHeap; 36 class G1EvacuationRootClosures; 37 class G1GCPhaseTimes; 38 class G1ParScanThreadState; 39 class G1RootClosures; 40 class Monitor; 41 class OopClosure; 42 class SubTasksDone; 43 44 // Scoped object to assist in applying oop, CLD and code blob closures to 45 // root locations. Handles claiming of different root scanning tasks 46 // and takes care of global state for root scanning via a StrongRootsScope. 47 // In the parallel case there is a shared G1RootProcessor object where all 48 // worker thread call the process_roots methods. 49 class G1RootProcessor : public StackObj { 50 G1CollectedHeap* _g1h; 51 SubTasksDone _process_strong_tasks; 52 StrongRootsScope _srs; 53 OopStorage::ParState<false, false> _par_state_string; 54 55 // Used to implement the Thread work barrier. 56 Monitor _lock; 57 volatile jint _n_workers_discovered_strong_classes; 58 59 enum G1H_process_roots_tasks { 60 G1RP_PS_Universe_oops_do, 61 G1RP_PS_JNIHandles_oops_do, 62 G1RP_PS_ObjectSynchronizer_oops_do, 63 G1RP_PS_Management_oops_do, 64 G1RP_PS_SystemDictionary_oops_do, 65 G1RP_PS_ClassLoaderDataGraph_oops_do, 66 G1RP_PS_jvmti_oops_do, 67 G1RP_PS_CodeCache_oops_do, 68 G1RP_PS_aot_oops_do, 69 G1RP_PS_filter_satb_buffers, 70 G1RP_PS_refProcessor_oops_do, 71 G1RP_PS_weakProcessor_oops_do, 72 // Leave this one last. 73 G1RP_PS_NumElements 74 }; 75 76 void worker_has_discovered_all_strong_classes(); 77 void wait_until_all_strong_classes_discovered(); 78 79 void process_all_roots(OopClosure* oops, 80 CLDClosure* clds, 81 CodeBlobClosure* blobs, 82 bool process_string_table); 83 84 void process_java_roots(G1RootClosures* closures, 85 G1GCPhaseTimes* phase_times, 86 uint worker_i); 87 88 void process_vm_roots(G1RootClosures* closures, 89 G1GCPhaseTimes* phase_times, 90 uint worker_i); 91 92 void process_string_table_roots(G1RootClosures* closures, 93 G1GCPhaseTimes* phase_times, 94 uint worker_i); 95 96 void process_code_cache_roots(CodeBlobClosure* code_closure, 97 G1GCPhaseTimes* phase_times, 98 uint worker_i); 99 100 public: 101 G1RootProcessor(G1CollectedHeap* g1h, uint n_workers); 102 103 // Apply correct closures from pss to the strongly and weakly reachable roots in the system 104 // in a single pass. 105 // Record and report timing measurements for sub phases using the worker_i 106 void evacuate_roots(G1ParScanThreadState* pss, uint worker_id); 107 108 // Apply oops, clds and blobs to all strongly reachable roots in the system 109 void process_strong_roots(OopClosure* oops, 110 CLDClosure* clds, 111 CodeBlobClosure* blobs); 112 113 // Apply oops, clds and blobs to strongly and weakly reachable roots in the system 114 void process_all_roots(OopClosure* oops, 115 CLDClosure* clds, 116 CodeBlobClosure* blobs); 117 118 // Apply oops, clds and blobs to strongly and weakly reachable roots in the system, 119 // the only thing different from process_all_roots is that we skip the string table 120 // to avoid keeping every string live when doing class unloading. 121 void process_all_roots_no_string_table(OopClosure* oops, 122 CLDClosure* clds, 123 CodeBlobClosure* blobs); 124 125 // Apply closure to weak roots in the system. Used during the adjust phase 126 // for the Full GC. 127 void process_full_gc_weak_roots(OopClosure* oops); 128 129 // Number of worker threads used by the root processor. 130 uint n_workers() const; 131 }; 132 133 #endif // SHARE_VM_GC_G1_G1ROOTPROCESSOR_HPP