1 /*
   2  * Copyright (c) 2015, 2019, 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_ZVALUE_HPP
  25 #define SHARE_GC_Z_ZVALUE_HPP
  26 
  27 #include "memory/allocation.hpp"
  28 #include "utilities/globalDefinitions.hpp"
  29 
  30 //
  31 // Storage
  32 //
  33 
  34 template <typename S>
  35 class ZValueStorage : public AllStatic {
  36 private:
  37   static uintptr_t _top;
  38   static uintptr_t _end;
  39 
  40 public:
  41   static const size_t offset = 4 * K;
  42 
  43   static uintptr_t alloc(size_t size);
  44 };
  45 
  46 class ZContendedStorage : public ZValueStorage<ZContendedStorage> {
  47 public:
  48   static size_t alignment();
  49   static uint32_t count();
  50   static uint32_t id();
  51 };
  52 
  53 class ZPerCPUStorage : public ZValueStorage<ZPerCPUStorage> {
  54 public:
  55   static size_t alignment();
  56   static uint32_t count();
  57   static uint32_t id();
  58 };
  59 
  60 class ZPerNUMAStorage : public ZValueStorage<ZPerNUMAStorage> {
  61 public:
  62   static size_t alignment();
  63   static uint32_t count();
  64   static uint32_t id();
  65 };
  66 
  67 class ZPerWorkerStorage : public ZValueStorage<ZPerWorkerStorage> {
  68 public:
  69   static size_t alignment();
  70   static uint32_t count();
  71   static uint32_t id();
  72 };
  73 
  74 //
  75 // Value
  76 //
  77 
  78 template <typename S, typename T>
  79 class ZValue : public CHeapObj<mtGC> {
  80 private:
  81   const uintptr_t _addr;
  82 
  83   uintptr_t value_addr(uint32_t value_id) const;
  84 
  85 public:
  86   ZValue();
  87   ZValue(const T& value);
  88 
  89   const T* addr(uint32_t value_id = S::id()) const;
  90   T* addr(uint32_t value_id = S::id());
  91 
  92   const T& get(uint32_t value_id = S::id()) const;
  93   T& get(uint32_t value_id = S::id());
  94 
  95   void set(const T& value, uint32_t value_id = S::id());
  96   void set_all(const T& value);
  97 };
  98 
  99 template <typename T>
 100 class ZContended : public ZValue<ZContendedStorage, T> {
 101 public:
 102   ZContended();
 103   ZContended(const T& value);
 104 };
 105 
 106 template <typename T>
 107 class ZPerCPU : public ZValue<ZPerCPUStorage, T> {
 108 public:
 109   ZPerCPU();
 110   ZPerCPU(const T& value);
 111 };
 112 
 113 template <typename T>
 114 class ZPerNUMA : public ZValue<ZPerNUMAStorage, T> {
 115 public:
 116   ZPerNUMA();
 117   ZPerNUMA(const T& value);
 118 };
 119 
 120 template <typename T>
 121 class ZPerWorker : public ZValue<ZPerWorkerStorage, T> {
 122 public:
 123   ZPerWorker();
 124   ZPerWorker(const T& value);
 125 };
 126 
 127 //
 128 // Iterator
 129 //
 130 
 131 template <typename S, typename T>
 132 class ZValueIterator {
 133 private:
 134   ZValue<S, T>* const _value;
 135   uint32_t            _value_id;
 136 
 137 public:
 138   ZValueIterator(ZValue<S, T>* value);
 139 
 140   bool next(T** value);
 141 };
 142 
 143 template <typename T>
 144 class ZPerCPUIterator : public ZValueIterator<ZPerCPUStorage, T> {
 145 public:
 146   ZPerCPUIterator(ZPerCPU<T>* value);
 147 };
 148 
 149 template <typename T>
 150 class ZPerNUMAIterator : public ZValueIterator<ZPerNUMAStorage, T> {
 151 public:
 152   ZPerNUMAIterator(ZPerNUMA<T>* value);
 153 };
 154 
 155 template <typename T>
 156 class ZPerWorkerIterator : public ZValueIterator<ZPerWorkerStorage, T> {
 157 public:
 158   ZPerWorkerIterator(ZPerWorker<T>* value);
 159 };
 160 
 161 template <typename S, typename T>
 162 class ZValueConstIterator {
 163 private:
 164   const ZValue<S, T>* const _value;
 165   uint32_t                  _value_id;
 166 
 167 public:
 168   ZValueConstIterator(const ZValue<S, T>* value);
 169 
 170   bool next(const T** value);
 171 };
 172 
 173 template <typename T>
 174 class ZPerCPUConstIterator : public ZValueConstIterator<ZPerCPUStorage, T> {
 175 public:
 176   ZPerCPUConstIterator(const ZPerCPU<T>* value);
 177 };
 178 
 179 template <typename T>
 180 class ZPerNUMAConstIterator : public ZValueConstIterator<ZPerNUMAStorage, T> {
 181 public:
 182   ZPerNUMAConstIterator(const ZPerNUMA<T>* value);
 183 };
 184 
 185 template <typename T>
 186 class ZPerWorkerConstIterator : public ZValueConstIterator<ZPerWorkerStorage, T> {
 187 public:
 188   ZPerWorkerConstIterator(const ZPerWorker<T>* value);
 189 };
 190 
 191 #endif // SHARE_GC_Z_ZVALUE_HPP