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 void do_universe(OopClosure* cl); 82 void do_object_synchronizer(OopClosure* cl); 83 void do_management(OopClosure* cl); 84 void do_jvmti_export(OopClosure* cl); 85 void do_jvmti_weak_export(OopClosure* cl); 86 void do_system_dictionary(OopClosure* cl); 87 void do_threads(OopClosure* cl); 88 void do_code_cache(OopClosure* cl); 89 90 ZSerialOopsDo<ZRootsIterator, &ZRootsIterator::do_universe> _universe; 91 ZSerialOopsDo<ZRootsIterator, &ZRootsIterator::do_object_synchronizer> _object_synchronizer; 92 ZSerialOopsDo<ZRootsIterator, &ZRootsIterator::do_management> _management; 93 ZSerialOopsDo<ZRootsIterator, &ZRootsIterator::do_jvmti_export> _jvmti_export; 94 ZSerialOopsDo<ZRootsIterator, &ZRootsIterator::do_jvmti_weak_export> _jvmti_weak_export; 95 ZSerialOopsDo<ZRootsIterator, &ZRootsIterator::do_system_dictionary> _system_dictionary; 96 ZParallelOopsDo<ZRootsIterator, &ZRootsIterator::do_threads> _threads; 97 ZParallelOopsDo<ZRootsIterator, &ZRootsIterator::do_code_cache> _code_cache; 98 99 public: 100 ZRootsIterator(); 101 ~ZRootsIterator(); 102 103 void oops_do(OopClosure* cl, bool visit_jvmti_weak_export = false); 104 }; 105 106 class ZConcurrentRootsIterator { 107 private: 108 ZConcurrentOopStorageIterator _jni_handles_iter; 109 110 void do_jni_handles(OopClosure* cl); 111 void do_class_loader_data_graph(OopClosure* cl); 112 113 ZParallelOopsDo<ZConcurrentRootsIterator, &ZConcurrentRootsIterator::do_jni_handles> _jni_handles; 114 ZParallelOopsDo<ZConcurrentRootsIterator, &ZConcurrentRootsIterator::do_class_loader_data_graph> _class_loader_data_graph; 115 116 public: 117 ZConcurrentRootsIterator(); 118 ~ZConcurrentRootsIterator(); 119 120 void oops_do(OopClosure* cl); 121 }; 122 123 class ZWeakRootsIterator { 124 private: 125 void do_jvmti_weak_export(BoolObjectClosure* is_alive, OopClosure* cl); 126 void do_jfr_weak(BoolObjectClosure* is_alive, OopClosure* cl); 127 128 ZSerialWeakOopsDo<ZWeakRootsIterator, &ZWeakRootsIterator::do_jvmti_weak_export> _jvmti_weak_export; 129 ZSerialWeakOopsDo<ZWeakRootsIterator, &ZWeakRootsIterator::do_jfr_weak> _jfr_weak; 130 131 public: 132 ZWeakRootsIterator(); 133 ~ZWeakRootsIterator(); 134 135 void weak_oops_do(BoolObjectClosure* is_alive, OopClosure* cl); 136 void oops_do(OopClosure* cl); 137 }; 138 139 class ZConcurrentWeakRootsIterator { 140 private: 141 ZConcurrentOopStorageIterator _vm_weak_handles_iter; 142 ZConcurrentOopStorageIterator _jni_weak_handles_iter; 143 ZConcurrentOopStorageIterator _string_table_iter; 144 145 void do_vm_weak_handles(OopClosure* cl); 146 void do_jni_weak_handles(OopClosure* cl); 147 void do_string_table(OopClosure* cl); 148 149 ZParallelOopsDo<ZConcurrentWeakRootsIterator, &ZConcurrentWeakRootsIterator::do_vm_weak_handles> _vm_weak_handles; 150 ZParallelOopsDo<ZConcurrentWeakRootsIterator, &ZConcurrentWeakRootsIterator::do_jni_weak_handles> _jni_weak_handles; 151 ZParallelOopsDo<ZConcurrentWeakRootsIterator, &ZConcurrentWeakRootsIterator::do_string_table> _string_table; 152 153 public: 154 ZConcurrentWeakRootsIterator(); 155 ~ZConcurrentWeakRootsIterator(); 156 157 void oops_do(OopClosure* cl); 158 }; 159 160 class ZThreadRootsIterator { 161 private: 162 void do_threads(OopClosure* cl); 163 164 ZParallelOopsDo<ZThreadRootsIterator, &ZThreadRootsIterator::do_threads> _threads; 165 166 public: 167 ZThreadRootsIterator(); 168 ~ZThreadRootsIterator(); 169 170 void oops_do(OopClosure* cl); 171 }; 172 173 #endif // SHARE_GC_Z_ZROOTSITERATOR_HPP