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