< prev index next >

src/share/vm/gc/g1/workerDataArray.inline.hpp

Print this page




   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 
  25 #include "gc/g1/workerDataArray.hpp"
  26 #include "memory/allocation.inline.hpp"
  27 
  28 template <typename T>
  29 WorkerDataArray<T>::WorkerDataArray(uint length,
  30                                     const char* title,
  31                                     bool print_sum,
  32                                     uint indent_level) :
  33  _title(title),
  34  _length(0),
  35  _print_sum(print_sum),
  36  _indent_level(indent_level),
  37  _thread_work_items(NULL),
  38  _enabled(true) {
  39   assert(length > 0, "Must have some workers to store data for");
  40   _length = length;
  41   _data = NEW_C_HEAP_ARRAY(T, _length, mtGC);
  42   reset();
  43 }
  44 
  45 template <typename T>
  46 void WorkerDataArray<T>::set(uint worker_i, T value) {
  47   assert(worker_i < _length, "Worker %d is greater than max: %d", worker_i, _length);
  48   assert(_data[worker_i] == uninitialized(), "Overwriting data for worker %d in %s", worker_i, _title);
  49   _data[worker_i] = value;
  50 }
  51 
  52 template <typename T>
  53 T WorkerDataArray<T>::get(uint worker_i) const {
  54   assert(worker_i < _length, "Worker %d is greater than max: %d", worker_i, _length);
  55   assert(_data[worker_i] != uninitialized(), "No data added for worker %d", worker_i);
  56   return _data[worker_i];
  57 }
  58 


 122 }
 123 
 124 template <typename T>
 125 void WorkerDataArray<T>::set_all(T value) {
 126   for (uint i = 0; i < _length; i++) {
 127     _data[i] = value;
 128   }
 129 }
 130 
 131 #ifndef PRODUCT
 132 template <typename T>
 133 void WorkerDataArray<T>::reset() {
 134   set_all(uninitialized());
 135   if (_thread_work_items != NULL) {
 136     _thread_work_items->reset();
 137   }
 138 }
 139 
 140 template <typename T>
 141 void WorkerDataArray<T>::verify(uint active_threads) const {
 142   if (!_enabled) {
 143     return;
 144   }
 145 
 146   assert(active_threads <= _length, "Wrong number of active threads");
 147   for (uint i = 0; i < active_threads; i++) {
 148     assert(_data[i] != uninitialized(),
 149            "Invalid data for worker %u in '%s'", i, _title);
 150   }
 151   if (_thread_work_items != NULL) {
 152     _thread_work_items->verify(active_threads);
 153   }
 154 }
 155 
 156 template <>
 157 inline size_t WorkerDataArray<size_t>::uninitialized() const {
 158   return (size_t)-1;
 159 }
 160 
 161 template <>
 162 inline double WorkerDataArray<double>::uninitialized() const {
 163   return -1.0;
 164 }
 165 #endif


   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 
  25 #include "gc/g1/workerDataArray.hpp"
  26 #include "memory/allocation.inline.hpp"
  27 
  28 template <typename T>
  29 WorkerDataArray<T>::WorkerDataArray(uint length, const char* title) :



  30  _title(title),
  31  _length(0),
  32  _thread_work_items(NULL) {



  33   assert(length > 0, "Must have some workers to store data for");
  34   _length = length;
  35   _data = NEW_C_HEAP_ARRAY(T, _length, mtGC);
  36   reset();
  37 }
  38 
  39 template <typename T>
  40 void WorkerDataArray<T>::set(uint worker_i, T value) {
  41   assert(worker_i < _length, "Worker %d is greater than max: %d", worker_i, _length);
  42   assert(_data[worker_i] == uninitialized(), "Overwriting data for worker %d in %s", worker_i, _title);
  43   _data[worker_i] = value;
  44 }
  45 
  46 template <typename T>
  47 T WorkerDataArray<T>::get(uint worker_i) const {
  48   assert(worker_i < _length, "Worker %d is greater than max: %d", worker_i, _length);
  49   assert(_data[worker_i] != uninitialized(), "No data added for worker %d", worker_i);
  50   return _data[worker_i];
  51 }
  52 


 116 }
 117 
 118 template <typename T>
 119 void WorkerDataArray<T>::set_all(T value) {
 120   for (uint i = 0; i < _length; i++) {
 121     _data[i] = value;
 122   }
 123 }
 124 
 125 #ifndef PRODUCT
 126 template <typename T>
 127 void WorkerDataArray<T>::reset() {
 128   set_all(uninitialized());
 129   if (_thread_work_items != NULL) {
 130     _thread_work_items->reset();
 131   }
 132 }
 133 
 134 template <typename T>
 135 void WorkerDataArray<T>::verify(uint active_threads) const {




 136   assert(active_threads <= _length, "Wrong number of active threads");
 137   for (uint i = 0; i < active_threads; i++) {
 138     assert(_data[i] != uninitialized(),
 139            "Invalid data for worker %u in '%s'", i, _title);
 140   }
 141   if (_thread_work_items != NULL) {
 142     _thread_work_items->verify(active_threads);
 143   }
 144 }
 145 
 146 template <>
 147 inline size_t WorkerDataArray<size_t>::uninitialized() const {
 148   return (size_t)-1;
 149 }
 150 
 151 template <>
 152 inline double WorkerDataArray<double>::uninitialized() const {
 153   return -1.0;
 154 }
 155 #endif
< prev index next >