1 /* 2 * Copyright (c) 2015, 2020, 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 #ifndef SHARE_GC_Z_ZROOTSITERATOR_HPP 25 #define SHARE_GC_Z_ZROOTSITERATOR_HPP 26 27 #include "gc/shared/oopStorageParState.hpp" 28 #include "gc/shared/suspendibleThreadSet.hpp" 29 #include "memory/allocation.hpp" 30 #include "memory/iterator.hpp" 31 #include "runtime/thread.hpp" 32 #include "runtime/threadSMR.hpp" 33 #include "utilities/globalDefinitions.hpp" 34 35 class ZRootsIteratorClosure; 36 37 typedef OopStorage::ParState<true /* concurrent */, false /* is_const */> ZOopStorageIterator; 38 39 template <typename T, void (T::*F)(ZRootsIteratorClosure*)> 40 class ZSerialOopsDo { 41 private: 42 T* const _iter; 43 volatile bool _claimed; 44 45 public: 46 ZSerialOopsDo(T* iter); 47 void oops_do(ZRootsIteratorClosure* cl); 48 }; 49 50 template <typename T, void (T::*F)(ZRootsIteratorClosure*)> 51 class ZParallelOopsDo { 52 private: 53 T* const _iter; 54 volatile bool _completed; 55 56 public: 57 ZParallelOopsDo(T* iter); 58 void oops_do(ZRootsIteratorClosure* cl); 59 }; 60 61 template <typename T, void (T::*F)(BoolObjectClosure*, ZRootsIteratorClosure*)> 62 class ZSerialWeakOopsDo { 63 private: 64 T* const _iter; 65 volatile bool _claimed; 66 67 public: 68 ZSerialWeakOopsDo(T* iter); 69 void weak_oops_do(BoolObjectClosure* is_alive, ZRootsIteratorClosure* cl); 70 }; 71 72 template <typename T, void (T::*F)(BoolObjectClosure*, ZRootsIteratorClosure*)> 73 class ZParallelWeakOopsDo { 74 private: 75 T* const _iter; 76 volatile bool _completed; 77 78 public: 79 ZParallelWeakOopsDo(T* iter); 80 void weak_oops_do(BoolObjectClosure* is_alive, ZRootsIteratorClosure* cl); 81 }; 82 83 class ZRootsIteratorClosure : public OopClosure { 84 public: 85 virtual void do_thread(Thread* thread) {} 86 87 virtual bool should_disarm_nmethods() const { 88 return false; 89 } 90 }; 91 92 class ZJavaThreadsIterator { 93 private: 94 ThreadsListHandle _threads; 95 volatile uint _claimed; 96 97 uint claim(); 98 99 public: 100 ZJavaThreadsIterator(); 101 102 void threads_do(ThreadClosure* cl); 103 }; 104 105 class ZRootsIterator { 106 private: 107 const bool _visit_jvmti_weak_export; 108 ZJavaThreadsIterator _java_threads_iter; 109 110 void do_universe(ZRootsIteratorClosure* cl); 111 void do_object_synchronizer(ZRootsIteratorClosure* cl); 112 void do_management(ZRootsIteratorClosure* cl); 113 void do_jvmti_export(ZRootsIteratorClosure* cl); 114 void do_jvmti_weak_export(ZRootsIteratorClosure* cl); 115 void do_vm_thread(ZRootsIteratorClosure* cl); 116 void do_java_threads(ZRootsIteratorClosure* cl); 117 void do_code_cache(ZRootsIteratorClosure* cl); 118 119 ZSerialOopsDo<ZRootsIterator, &ZRootsIterator::do_universe> _universe; 120 ZSerialOopsDo<ZRootsIterator, &ZRootsIterator::do_object_synchronizer> _object_synchronizer; 121 ZSerialOopsDo<ZRootsIterator, &ZRootsIterator::do_management> _management; 122 ZSerialOopsDo<ZRootsIterator, &ZRootsIterator::do_jvmti_export> _jvmti_export; 123 ZSerialOopsDo<ZRootsIterator, &ZRootsIterator::do_jvmti_weak_export> _jvmti_weak_export; 124 ZSerialOopsDo<ZRootsIterator, &ZRootsIterator::do_vm_thread> _vm_thread; 125 ZParallelOopsDo<ZRootsIterator, &ZRootsIterator::do_java_threads> _java_threads; 126 ZParallelOopsDo<ZRootsIterator, &ZRootsIterator::do_code_cache> _code_cache; 127 128 public: 129 ZRootsIterator(bool visit_jvmti_weak_export = false); 130 ~ZRootsIterator(); 131 132 void oops_do(ZRootsIteratorClosure* cl); 133 }; 134 135 class ZConcurrentRootsIterator { 136 private: 137 ZOopStorageIterator _jni_handles_iter; 138 ZOopStorageIterator _vm_handles_iter; 139 const int _cld_claim; 140 141 void do_jni_handles(ZRootsIteratorClosure* cl); 142 void do_vm_handles(ZRootsIteratorClosure* cl); 143 void do_class_loader_data_graph(ZRootsIteratorClosure* cl); 144 145 ZParallelOopsDo<ZConcurrentRootsIterator, &ZConcurrentRootsIterator::do_jni_handles> _jni_handles; 146 ZParallelOopsDo<ZConcurrentRootsIterator, &ZConcurrentRootsIterator::do_vm_handles> _vm_handles; 147 ZParallelOopsDo<ZConcurrentRootsIterator, &ZConcurrentRootsIterator::do_class_loader_data_graph> _class_loader_data_graph; 148 149 public: 150 ZConcurrentRootsIterator(int cld_claim); 151 ~ZConcurrentRootsIterator(); 152 153 void oops_do(ZRootsIteratorClosure* cl); 154 }; 155 156 class ZConcurrentRootsIteratorClaimStrong : public ZConcurrentRootsIterator { 157 public: 158 ZConcurrentRootsIteratorClaimStrong() : 159 ZConcurrentRootsIterator(ClassLoaderData::_claim_strong) {} 160 }; 161 162 class ZConcurrentRootsIteratorClaimOther : public ZConcurrentRootsIterator { 163 public: 164 ZConcurrentRootsIteratorClaimOther() : 165 ZConcurrentRootsIterator(ClassLoaderData::_claim_other) {} 166 }; 167 168 class ZConcurrentRootsIteratorClaimNone : public ZConcurrentRootsIterator { 169 public: 170 ZConcurrentRootsIteratorClaimNone() : 171 ZConcurrentRootsIterator(ClassLoaderData::_claim_none) {} 172 }; 173 174 class ZWeakRootsIterator { 175 private: 176 void do_jvmti_weak_export(BoolObjectClosure* is_alive, ZRootsIteratorClosure* cl); 177 void do_jfr_weak(BoolObjectClosure* is_alive, ZRootsIteratorClosure* cl); 178 179 ZSerialWeakOopsDo<ZWeakRootsIterator, &ZWeakRootsIterator::do_jvmti_weak_export> _jvmti_weak_export; 180 ZSerialWeakOopsDo<ZWeakRootsIterator, &ZWeakRootsIterator::do_jfr_weak> _jfr_weak; 181 182 public: 183 ZWeakRootsIterator(); 184 ~ZWeakRootsIterator(); 185 186 void weak_oops_do(BoolObjectClosure* is_alive, ZRootsIteratorClosure* cl); 187 void oops_do(ZRootsIteratorClosure* cl); 188 }; 189 190 class ZConcurrentWeakRootsIterator { 191 private: 192 ZOopStorageIterator _vm_weak_handles_iter; 193 ZOopStorageIterator _jni_weak_handles_iter; 194 ZOopStorageIterator _string_table_iter; 195 ZOopStorageIterator _resolved_method_table_iter; 196 197 void do_vm_weak_handles(ZRootsIteratorClosure* cl); 198 void do_jni_weak_handles(ZRootsIteratorClosure* cl); 199 void do_string_table(ZRootsIteratorClosure* cl); 200 void do_resolved_method_table(ZRootsIteratorClosure* cl); 201 202 ZParallelOopsDo<ZConcurrentWeakRootsIterator, &ZConcurrentWeakRootsIterator::do_vm_weak_handles> _vm_weak_handles; 203 ZParallelOopsDo<ZConcurrentWeakRootsIterator, &ZConcurrentWeakRootsIterator::do_jni_weak_handles> _jni_weak_handles; 204 ZParallelOopsDo<ZConcurrentWeakRootsIterator, &ZConcurrentWeakRootsIterator::do_string_table> _string_table; 205 ZParallelOopsDo<ZConcurrentWeakRootsIterator, &ZConcurrentWeakRootsIterator::do_resolved_method_table> _resolved_method_table; 206 207 public: 208 ZConcurrentWeakRootsIterator(); 209 ~ZConcurrentWeakRootsIterator(); 210 211 void oops_do(ZRootsIteratorClosure* cl); 212 }; 213 214 #endif // SHARE_GC_Z_ZROOTSITERATOR_HPP