< prev index next >

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

Print this page




   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 



  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>


  71   assert(worker_i < _length, "Worker %d is greater than max: %d", worker_i, _length);
  72   assert(_data[worker_i] != uninitialized(), "No data to add to for worker %d", worker_i);
  73   _data[worker_i] += value;
  74 }
  75 
  76 template <typename T>
  77 double WorkerDataArray<T>::average(uint active_threads) const {
  78   return sum(active_threads) / (double) active_threads;
  79 }
  80 
  81 template <typename T>
  82 T WorkerDataArray<T>::sum(uint active_threads) const {
  83   T s = get(0);
  84   for (uint i = 1; i < active_threads; ++i) {
  85     s += get(i);
  86   }
  87   return s;
  88 }
  89 
  90 template <typename T>
  91 T WorkerDataArray<T>::minimum(uint active_threads) const {
  92   T min = get(0);
  93   for (uint i = 1; i < active_threads; ++i) {
  94     min = MIN2(min, get(i));
  95   }
  96   return min;
  97 }
  98 
  99 template <typename T>
 100 T WorkerDataArray<T>::maximum(uint active_threads) const {
 101   T max = get(0);
 102   for (uint i = 1; i < active_threads; ++i) {
 103     max = MAX2(max, get(i));
 104   }
 105   return max;
 106 }
 107 
 108 template <typename T>
 109 T WorkerDataArray<T>::diff(uint active_threads) const {
 110   return maximum(active_threads) - minimum(active_threads);
 111 }
 112 
 113 template <typename T>
 114 void WorkerDataArray<T>::clear() {
 115   set_all(0);
 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




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


  75   assert(worker_i < _length, "Worker %d is greater than max: %d", worker_i, _length);
  76   assert(_data[worker_i] != uninitialized(), "No data to add to for worker %d", worker_i);
  77   _data[worker_i] += value;
  78 }
  79 
  80 template <typename T>
  81 double WorkerDataArray<T>::average(uint active_threads) const {
  82   return sum(active_threads) / (double) active_threads;
  83 }
  84 
  85 template <typename T>
  86 T WorkerDataArray<T>::sum(uint active_threads) const {
  87   T s = get(0);
  88   for (uint i = 1; i < active_threads; ++i) {
  89     s += get(i);
  90   }
  91   return s;
  92 }
  93 
  94 template <typename T>























  95 void WorkerDataArray<T>::clear() {
  96   set_all(0);
  97 }
  98 
  99 template <typename T>
 100 void WorkerDataArray<T>::set_all(T value) {
 101   for (uint i = 0; i < _length; i++) {
 102     _data[i] = value;
 103   }
 104 }
 105 
 106 template <class T>
 107 void WorkerDataArray<T>::print_summary_on(outputStream* out, uint active_threads, bool print_sum) const {
 108   T max = get(0);
 109   T min = max;
 110   T sum = 0;
 111   for (uint i = 1; i < active_threads; ++i) {
 112     T value = get(i);
 113     max = MAX2(max, value);
 114     min = MIN2(min, value);
 115     sum += value;
 116   }
 117   T diff = max - min;
 118   double avg = sum / (double) active_threads;
 119   WDAPrinter::summary(out, title(), min, avg, max, diff, sum, print_sum);
 120 }
 121 
 122 template <class T>
 123 void WorkerDataArray<T>::print_details_on(outputStream* out, uint active_threads) const {
 124   WDAPrinter::details(this, out, active_threads);
 125 }
 126 
 127 #ifndef PRODUCT
 128 template <typename T>
 129 void WorkerDataArray<T>::reset() {
 130   set_all(uninitialized());
 131   if (_thread_work_items != NULL) {
 132     _thread_work_items->reset();
 133   }
 134 }
 135 
 136 template <typename T>
 137 void WorkerDataArray<T>::verify(uint active_threads) const {
 138   assert(active_threads <= _length, "Wrong number of active threads");
 139   for (uint i = 0; i < active_threads; i++) {
 140     assert(_data[i] != uninitialized(),
 141            "Invalid data for worker %u in '%s'", i, _title);
 142   }
 143   if (_thread_work_items != NULL) {
 144     _thread_work_items->verify(active_threads);
 145   }
 146 }
 147 
 148 template <>
 149 inline size_t WorkerDataArray<size_t>::uninitialized() const {
 150   return (size_t)-1;
 151 }
 152 
 153 template <>
 154 inline double WorkerDataArray<double>::uninitialized() const {
 155   return -1.0;
 156 }
 157 #endif
 158 
 159 #endif // SHARE_VM_GC_G1_WORKERDATAARRAY_INLINE_HPP
< prev index next >