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