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 #ifndef SHARE_GC_Z_ZROOTSITERATOR_HPP 25 #define SHARE_GC_Z_ZROOTSITERATOR_HPP 26 27 #include "gc/shared/oopStorageParState.hpp" 28 #include "memory/allocation.hpp" 29 #include "memory/iterator.hpp" 30 #include "utilities/globalDefinitions.hpp" 31 32 typedef OopStorage::ParState<false /* concurrent */, false /* is_const */> ZOopStorageIterator; 33 typedef OopStorage::ParState<true /* concurrent */, false /* is_const */> ZConcurrentOopStorageIterator; 34 35 template <typename T, void (T::*F)(OopClosure*)> 36 class ZSerialOopsDo { 37 private: 38 T* const _iter; 39 volatile bool _claimed; 40 41 public: 42 ZSerialOopsDo(T* iter); 43 void oops_do(OopClosure* cl); 44 }; 45 46 template <typename T, void (T::*F)(OopClosure*)> 47 class ZParallelOopsDo { 48 private: 49 T* const _iter; 50 volatile bool _completed; 51 52 public: 53 ZParallelOopsDo(T* iter); 54 void oops_do(OopClosure* cl); 55 }; 56 57 template <typename T, void (T::*F)(BoolObjectClosure*, OopClosure*)> 58 class ZSerialWeakOopsDo { 59 private: 60 T* const _iter; 61 volatile bool _claimed; 62 63 public: 64 ZSerialWeakOopsDo(T* iter); 65 void weak_oops_do(BoolObjectClosure* is_alive, OopClosure* cl); 66 }; 67 68 template <typename T, void (T::*F)(BoolObjectClosure*, OopClosure*)> 69 class ZParallelWeakOopsDo { 70 private: 71 T* const _iter; 72 volatile bool _completed; 73 74 public: 75 ZParallelWeakOopsDo(T* iter); 76 void weak_oops_do(BoolObjectClosure* is_alive, OopClosure* cl); 77 }; 78 79 class ZRootsIterator { 80 private: 81 ZOopStorageIterator _vm_weak_handles_iter; 82 ZOopStorageIterator _jni_handles_iter; 83 ZOopStorageIterator _jni_weak_handles_iter; 84 85 void do_universe(OopClosure* cl); 86 void do_vm_weak_handles(OopClosure* cl); 87 void do_jni_handles(OopClosure* cl); 88 void do_jni_weak_handles(OopClosure* cl); 89 void do_object_synchronizer(OopClosure* cl); 90 void do_management(OopClosure* cl); 91 void do_jvmti_export(OopClosure* cl); 92 void do_jvmti_weak_export(OopClosure* cl); 93 void do_jfr_weak(OopClosure* cl); 94 void do_system_dictionary(OopClosure* cl); 95 void do_class_loader_data_graph(OopClosure* cl); 96 void do_threads(OopClosure* cl); 97 void do_code_cache(OopClosure* cl); 98 void do_string_table(OopClosure* cl); 99 100 ZSerialOopsDo<ZRootsIterator, &ZRootsIterator::do_universe> _universe; 101 ZSerialOopsDo<ZRootsIterator, &ZRootsIterator::do_object_synchronizer> _object_synchronizer; 102 ZSerialOopsDo<ZRootsIterator, &ZRootsIterator::do_management> _management; 103 ZSerialOopsDo<ZRootsIterator, &ZRootsIterator::do_jvmti_export> _jvmti_export; 104 ZSerialOopsDo<ZRootsIterator, &ZRootsIterator::do_jvmti_weak_export> _jvmti_weak_export; 105 ZSerialOopsDo<ZRootsIterator, &ZRootsIterator::do_jfr_weak> _jfr_weak; 106 ZSerialOopsDo<ZRootsIterator, &ZRootsIterator::do_system_dictionary> _system_dictionary; 107 ZParallelOopsDo<ZRootsIterator, &ZRootsIterator::do_vm_weak_handles> _vm_weak_handles; 108 ZParallelOopsDo<ZRootsIterator, &ZRootsIterator::do_jni_handles> _jni_handles; 109 ZParallelOopsDo<ZRootsIterator, &ZRootsIterator::do_jni_weak_handles> _jni_weak_handles; 110 ZParallelOopsDo<ZRootsIterator, &ZRootsIterator::do_class_loader_data_graph> _class_loader_data_graph; 111 ZParallelOopsDo<ZRootsIterator, &ZRootsIterator::do_threads> _threads; 112 ZParallelOopsDo<ZRootsIterator, &ZRootsIterator::do_code_cache> _code_cache; 113 ZParallelOopsDo<ZRootsIterator, &ZRootsIterator::do_string_table> _string_table; 114 115 public: 116 ZRootsIterator(); 117 ~ZRootsIterator(); 118 119 void oops_do(OopClosure* cl, bool visit_jvmti_weak_export = false); 120 }; 121 122 class ZWeakRootsIterator { 123 private: 124 ZOopStorageIterator _vm_weak_handles_iter; 125 ZOopStorageIterator _jni_weak_handles_iter; 126 127 void do_vm_weak_handles(BoolObjectClosure* is_alive, OopClosure* cl); 128 void do_jni_weak_handles(BoolObjectClosure* is_alive, OopClosure* cl); 129 void do_jvmti_weak_export(BoolObjectClosure* is_alive, OopClosure* cl); 130 void do_jfr_weak(BoolObjectClosure* is_alive, OopClosure* cl); 131 void do_symbol_table(BoolObjectClosure* is_alive, OopClosure* cl); 132 void do_string_table(BoolObjectClosure* is_alive, OopClosure* cl); 133 134 ZSerialWeakOopsDo<ZWeakRootsIterator, &ZWeakRootsIterator::do_jvmti_weak_export> _jvmti_weak_export; 135 ZSerialWeakOopsDo<ZWeakRootsIterator, &ZWeakRootsIterator::do_jfr_weak> _jfr_weak; 136 ZParallelWeakOopsDo<ZWeakRootsIterator, &ZWeakRootsIterator::do_vm_weak_handles> _vm_weak_handles; 137 ZParallelWeakOopsDo<ZWeakRootsIterator, &ZWeakRootsIterator::do_jni_weak_handles> _jni_weak_handles; 138 ZParallelWeakOopsDo<ZWeakRootsIterator, &ZWeakRootsIterator::do_symbol_table> _symbol_table; 139 ZParallelWeakOopsDo<ZWeakRootsIterator, &ZWeakRootsIterator::do_string_table> _string_table; 140 141 public: 142 ZWeakRootsIterator(); 143 ~ZWeakRootsIterator(); 144 145 void weak_oops_do(BoolObjectClosure* is_alive, OopClosure* cl); 146 void oops_do(OopClosure* cl); 147 }; 148 149 class ZConcurrentWeakRootsIterator { 150 private: 151 ZConcurrentOopStorageIterator _vm_weak_handles_iter; 152 ZConcurrentOopStorageIterator _jni_weak_handles_iter; 153 154 void do_vm_weak_handles(OopClosure* cl); 155 void do_jni_weak_handles(OopClosure* cl); 156 157 ZParallelOopsDo<ZConcurrentWeakRootsIterator, &ZConcurrentWeakRootsIterator::do_vm_weak_handles> _vm_weak_handles; 158 ZParallelOopsDo<ZConcurrentWeakRootsIterator, &ZConcurrentWeakRootsIterator::do_jni_weak_handles> _jni_weak_handles; 159 160 public: 161 ZConcurrentWeakRootsIterator(); 162 163 void oops_do(OopClosure* cl); 164 }; 165 166 class ZThreadRootsIterator { 167 private: 168 void do_threads(OopClosure* cl); 169 170 ZParallelOopsDo<ZThreadRootsIterator, &ZThreadRootsIterator::do_threads> _threads; 171 172 public: 173 ZThreadRootsIterator(); 174 ~ZThreadRootsIterator(); 175 176 void oops_do(OopClosure* cl); 177 }; 178 179 #endif // SHARE_GC_Z_ZROOTSITERATOR_HPP