1 /*
   2  * Copyright (c) 2015, 2017, 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 "memory/allocation.hpp"
  28 #include "memory/iterator.hpp"
  29 #include "utilities/globalDefinitions.hpp"
  30 
  31 template <typename T, void (T::*F)(OopClosure*)>
  32 class ZSerialOopsDo VALUE_OBJ_CLASS_SPEC {
  33 private:
  34   T* const      _iter;
  35   volatile bool _claimed;
  36 
  37 public:
  38   ZSerialOopsDo(T* iter);
  39   void oops_do(OopClosure* cl);
  40 } ATTRIBUTE_ALIGNED(DEFAULT_CACHE_LINE_SIZE);
  41 
  42 template <typename T, void (T::*F)(OopClosure*)>
  43 class ZParallelOopsDo VALUE_OBJ_CLASS_SPEC {
  44 private:
  45   T* const      _iter;
  46   volatile bool _completed;
  47 
  48 public:
  49   ZParallelOopsDo(T* iter);
  50   void oops_do(OopClosure* cl);
  51 } ATTRIBUTE_ALIGNED(DEFAULT_CACHE_LINE_SIZE);
  52 
  53 template <typename T, void (T::*F)(BoolObjectClosure*, OopClosure*)>
  54 class ZSerialUnlinkOrOopsDo VALUE_OBJ_CLASS_SPEC {
  55 private:
  56   T* const      _iter;
  57   volatile bool _claimed;
  58 
  59 public:
  60   ZSerialUnlinkOrOopsDo(T* iter);
  61   void unlink_or_oops_do(BoolObjectClosure* is_alive, OopClosure* cl);
  62 } ATTRIBUTE_ALIGNED(DEFAULT_CACHE_LINE_SIZE);
  63 
  64 template <typename T, void (T::*F)(BoolObjectClosure*, OopClosure*)>
  65 class ZParallelUnlinkOrOopsDo VALUE_OBJ_CLASS_SPEC {
  66 private:
  67   T* const      _iter;
  68   volatile bool _completed;
  69 
  70 public:
  71   ZParallelUnlinkOrOopsDo(T* iter);
  72   void unlink_or_oops_do(BoolObjectClosure* is_alive, OopClosure* cl);
  73 } ATTRIBUTE_ALIGNED(DEFAULT_CACHE_LINE_SIZE);
  74 
  75 class ZRootsIterator VALUE_OBJ_CLASS_SPEC {
  76 private:
  77   void do_universe(OopClosure* cl);
  78   void do_jni_handles(OopClosure* cl);
  79   void do_jni_weak_handles(OopClosure* cl);
  80   void do_object_synchronizer(OopClosure* cl);
  81   void do_management(OopClosure* cl);
  82   void do_jvmti_export(OopClosure* cl);
  83   void do_jvmti_weak_export(OopClosure* cl);
  84   void do_trace(OopClosure* cl);
  85   void do_system_dictionary(OopClosure* cl);
  86   void do_class_loader_data_graph(OopClosure* cl);
  87   void do_threads(OopClosure* cl);
  88   void do_code_cache(OopClosure* cl);
  89   void do_string_table(OopClosure* cl);
  90 
  91   ZSerialOopsDo<ZRootsIterator, &ZRootsIterator::do_universe>                  _universe;
  92   ZSerialOopsDo<ZRootsIterator, &ZRootsIterator::do_jni_handles>               _jni_handles;
  93   ZSerialOopsDo<ZRootsIterator, &ZRootsIterator::do_jni_weak_handles>          _jni_weak_handles;
  94   ZSerialOopsDo<ZRootsIterator, &ZRootsIterator::do_object_synchronizer>       _object_synchronizer;
  95   ZSerialOopsDo<ZRootsIterator, &ZRootsIterator::do_management>                _management;
  96   ZSerialOopsDo<ZRootsIterator, &ZRootsIterator::do_jvmti_export>              _jvmti_export;
  97   ZSerialOopsDo<ZRootsIterator, &ZRootsIterator::do_jvmti_weak_export>         _jvmti_weak_export;
  98   ZSerialOopsDo<ZRootsIterator, &ZRootsIterator::do_trace>                     _trace;
  99   ZSerialOopsDo<ZRootsIterator, &ZRootsIterator::do_system_dictionary>         _system_dictionary;
 100   ZParallelOopsDo<ZRootsIterator, &ZRootsIterator::do_class_loader_data_graph> _class_loader_data_graph;
 101   ZParallelOopsDo<ZRootsIterator, &ZRootsIterator::do_threads>                 _threads;
 102   ZParallelOopsDo<ZRootsIterator, &ZRootsIterator::do_code_cache>              _code_cache;
 103   ZParallelOopsDo<ZRootsIterator, &ZRootsIterator::do_string_table>            _string_table;
 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 VALUE_OBJ_CLASS_SPEC {
 113 private:
 114   void do_jni_weak_handles(BoolObjectClosure* is_alive, OopClosure* cl);
 115   void do_jvmti_weak_export(BoolObjectClosure* is_alive, OopClosure* cl);
 116   void do_trace(BoolObjectClosure* is_alive, OopClosure* cl);
 117   void do_symbol_table(BoolObjectClosure* is_alive, OopClosure* cl);
 118   void do_string_table(BoolObjectClosure* is_alive, OopClosure* cl);
 119 
 120   ZSerialUnlinkOrOopsDo<ZWeakRootsIterator, &ZWeakRootsIterator::do_jni_weak_handles>  _jni_weak_handles;
 121   ZSerialUnlinkOrOopsDo<ZWeakRootsIterator, &ZWeakRootsIterator::do_jvmti_weak_export> _jvmti_weak_export;
 122   ZSerialUnlinkOrOopsDo<ZWeakRootsIterator, &ZWeakRootsIterator::do_trace>             _trace;
 123   ZParallelUnlinkOrOopsDo<ZWeakRootsIterator, &ZWeakRootsIterator::do_symbol_table>    _symbol_table;
 124   ZParallelUnlinkOrOopsDo<ZWeakRootsIterator, &ZWeakRootsIterator::do_string_table>    _string_table;
 125 
 126 public:
 127   ZWeakRootsIterator();
 128   ~ZWeakRootsIterator();
 129 
 130   void unlink_or_oops_do(BoolObjectClosure* is_alive, OopClosure* cl);
 131   void oops_do(OopClosure* cl);
 132 };
 133 
 134 class ZThreadRootsIterator VALUE_OBJ_CLASS_SPEC {
 135 private:
 136   void do_threads(OopClosure* cl);
 137 
 138   ZParallelOopsDo<ZThreadRootsIterator, &ZThreadRootsIterator::do_threads> _threads;
 139 
 140 public:
 141   ZThreadRootsIterator();
 142   ~ZThreadRootsIterator();
 143 
 144   void oops_do(OopClosure* cl);
 145 };
 146 
 147 #endif // SHARE_GC_Z_ZROOTSITERATOR_HPP