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