author | tschatzl |
Wed, 14 Jun 2017 11:26:44 +0200 | |
changeset 46571 | c70b36f0730d |
parent 37214 | bc4e0e0995e6 |
permissions | -rw-r--r-- |
33623 | 1 |
/* |
37214
bc4e0e0995e6
8152952: Allow G1 phase logging to use individual number of threads
brutisso
parents:
36374
diff
changeset
|
2 |
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. |
33623 | 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 |
||
36374 | 25 |
#ifndef SHARE_VM_GC_G1_WORKERDATAARRAY_INLINE_HPP |
26 |
#define SHARE_VM_GC_G1_WORKERDATAARRAY_INLINE_HPP |
|
27 |
||
33623 | 28 |
#include "gc/g1/workerDataArray.hpp" |
29 |
#include "memory/allocation.inline.hpp" |
|
36374 | 30 |
#include "utilities/ostream.hpp" |
33623 | 31 |
|
32 |
template <typename T> |
|
36374 | 33 |
WorkerDataArray<T>::WorkerDataArray(uint length, const char* title) : |
33623 | 34 |
_title(title), |
46571
c70b36f0730d
8178148: Log more detailed information about scan rs phase
tschatzl
parents:
37214
diff
changeset
|
35 |
_length(0) { |
33623 | 36 |
assert(length > 0, "Must have some workers to store data for"); |
37 |
_length = length; |
|
38 |
_data = NEW_C_HEAP_ARRAY(T, _length, mtGC); |
|
46571
c70b36f0730d
8178148: Log more detailed information about scan rs phase
tschatzl
parents:
37214
diff
changeset
|
39 |
for (uint i = 0; i < MaxThreadWorkItems; i++) { |
c70b36f0730d
8178148: Log more detailed information about scan rs phase
tschatzl
parents:
37214
diff
changeset
|
40 |
_thread_work_items[i] = NULL; |
c70b36f0730d
8178148: Log more detailed information about scan rs phase
tschatzl
parents:
37214
diff
changeset
|
41 |
} |
33623 | 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 |
return _data[worker_i]; |
|
56 |
} |
|
57 |
||
58 |
template <typename T> |
|
59 |
WorkerDataArray<T>::~WorkerDataArray() { |
|
60 |
FREE_C_HEAP_ARRAY(T, _data); |
|
61 |
} |
|
62 |
||
63 |
template <typename T> |
|
46571
c70b36f0730d
8178148: Log more detailed information about scan rs phase
tschatzl
parents:
37214
diff
changeset
|
64 |
void WorkerDataArray<T>::link_thread_work_items(WorkerDataArray<size_t>* thread_work_items, uint index) { |
c70b36f0730d
8178148: Log more detailed information about scan rs phase
tschatzl
parents:
37214
diff
changeset
|
65 |
assert(index < MaxThreadWorkItems, "Tried to access thread work item %u (max %u)", index, MaxThreadWorkItems); |
c70b36f0730d
8178148: Log more detailed information about scan rs phase
tschatzl
parents:
37214
diff
changeset
|
66 |
_thread_work_items[index] = thread_work_items; |
33623 | 67 |
} |
68 |
||
69 |
template <typename T> |
|
46571
c70b36f0730d
8178148: Log more detailed information about scan rs phase
tschatzl
parents:
37214
diff
changeset
|
70 |
void WorkerDataArray<T>::set_thread_work_item(uint worker_i, size_t value, uint index) { |
c70b36f0730d
8178148: Log more detailed information about scan rs phase
tschatzl
parents:
37214
diff
changeset
|
71 |
assert(index < MaxThreadWorkItems, "Tried to access thread work item %u (max %u)", index, MaxThreadWorkItems); |
c70b36f0730d
8178148: Log more detailed information about scan rs phase
tschatzl
parents:
37214
diff
changeset
|
72 |
assert(_thread_work_items[index] != NULL, "No sub count"); |
c70b36f0730d
8178148: Log more detailed information about scan rs phase
tschatzl
parents:
37214
diff
changeset
|
73 |
_thread_work_items[index]->set(worker_i, value); |
c70b36f0730d
8178148: Log more detailed information about scan rs phase
tschatzl
parents:
37214
diff
changeset
|
74 |
} |
c70b36f0730d
8178148: Log more detailed information about scan rs phase
tschatzl
parents:
37214
diff
changeset
|
75 |
|
c70b36f0730d
8178148: Log more detailed information about scan rs phase
tschatzl
parents:
37214
diff
changeset
|
76 |
template <typename T> |
c70b36f0730d
8178148: Log more detailed information about scan rs phase
tschatzl
parents:
37214
diff
changeset
|
77 |
void WorkerDataArray<T>::add_thread_work_item(uint worker_i, size_t value, uint index) { |
c70b36f0730d
8178148: Log more detailed information about scan rs phase
tschatzl
parents:
37214
diff
changeset
|
78 |
assert(index < MaxThreadWorkItems, "Tried to access thread work item %u (max %u)", index, MaxThreadWorkItems); |
c70b36f0730d
8178148: Log more detailed information about scan rs phase
tschatzl
parents:
37214
diff
changeset
|
79 |
assert(_thread_work_items[index] != NULL, "No sub count"); |
c70b36f0730d
8178148: Log more detailed information about scan rs phase
tschatzl
parents:
37214
diff
changeset
|
80 |
_thread_work_items[index]->add(worker_i, value); |
33623 | 81 |
} |
82 |
||
83 |
template <typename T> |
|
84 |
void WorkerDataArray<T>::add(uint worker_i, T value) { |
|
85 |
assert(worker_i < _length, "Worker %d is greater than max: %d", worker_i, _length); |
|
86 |
assert(_data[worker_i] != uninitialized(), "No data to add to for worker %d", worker_i); |
|
87 |
_data[worker_i] += value; |
|
88 |
} |
|
89 |
||
90 |
template <typename T> |
|
37214
bc4e0e0995e6
8152952: Allow G1 phase logging to use individual number of threads
brutisso
parents:
36374
diff
changeset
|
91 |
double WorkerDataArray<T>::average() const { |
bc4e0e0995e6
8152952: Allow G1 phase logging to use individual number of threads
brutisso
parents:
36374
diff
changeset
|
92 |
uint contributing_threads = 0; |
bc4e0e0995e6
8152952: Allow G1 phase logging to use individual number of threads
brutisso
parents:
36374
diff
changeset
|
93 |
for (uint i = 0; i < _length; ++i) { |
bc4e0e0995e6
8152952: Allow G1 phase logging to use individual number of threads
brutisso
parents:
36374
diff
changeset
|
94 |
if (get(i) != uninitialized()) { |
bc4e0e0995e6
8152952: Allow G1 phase logging to use individual number of threads
brutisso
parents:
36374
diff
changeset
|
95 |
contributing_threads++; |
bc4e0e0995e6
8152952: Allow G1 phase logging to use individual number of threads
brutisso
parents:
36374
diff
changeset
|
96 |
} |
bc4e0e0995e6
8152952: Allow G1 phase logging to use individual number of threads
brutisso
parents:
36374
diff
changeset
|
97 |
} |
bc4e0e0995e6
8152952: Allow G1 phase logging to use individual number of threads
brutisso
parents:
36374
diff
changeset
|
98 |
if (contributing_threads == 0) { |
bc4e0e0995e6
8152952: Allow G1 phase logging to use individual number of threads
brutisso
parents:
36374
diff
changeset
|
99 |
return 0.0; |
bc4e0e0995e6
8152952: Allow G1 phase logging to use individual number of threads
brutisso
parents:
36374
diff
changeset
|
100 |
} |
bc4e0e0995e6
8152952: Allow G1 phase logging to use individual number of threads
brutisso
parents:
36374
diff
changeset
|
101 |
return sum() / (double) contributing_threads; |
33623 | 102 |
} |
103 |
||
104 |
template <typename T> |
|
37214
bc4e0e0995e6
8152952: Allow G1 phase logging to use individual number of threads
brutisso
parents:
36374
diff
changeset
|
105 |
T WorkerDataArray<T>::sum() const { |
bc4e0e0995e6
8152952: Allow G1 phase logging to use individual number of threads
brutisso
parents:
36374
diff
changeset
|
106 |
T s = 0; |
bc4e0e0995e6
8152952: Allow G1 phase logging to use individual number of threads
brutisso
parents:
36374
diff
changeset
|
107 |
for (uint i = 0; i < _length; ++i) { |
bc4e0e0995e6
8152952: Allow G1 phase logging to use individual number of threads
brutisso
parents:
36374
diff
changeset
|
108 |
if (get(i) != uninitialized()) { |
bc4e0e0995e6
8152952: Allow G1 phase logging to use individual number of threads
brutisso
parents:
36374
diff
changeset
|
109 |
s += get(i); |
bc4e0e0995e6
8152952: Allow G1 phase logging to use individual number of threads
brutisso
parents:
36374
diff
changeset
|
110 |
} |
33623 | 111 |
} |
112 |
return s; |
|
113 |
} |
|
114 |
||
115 |
template <typename T> |
|
116 |
void WorkerDataArray<T>::set_all(T value) { |
|
117 |
for (uint i = 0; i < _length; i++) { |
|
118 |
_data[i] = value; |
|
119 |
} |
|
120 |
} |
|
121 |
||
36374 | 122 |
template <class T> |
37214
bc4e0e0995e6
8152952: Allow G1 phase logging to use individual number of threads
brutisso
parents:
36374
diff
changeset
|
123 |
void WorkerDataArray<T>::print_summary_on(outputStream* out, bool print_sum) const { |
bc4e0e0995e6
8152952: Allow G1 phase logging to use individual number of threads
brutisso
parents:
36374
diff
changeset
|
124 |
out->print("%-25s", title()); |
bc4e0e0995e6
8152952: Allow G1 phase logging to use individual number of threads
brutisso
parents:
36374
diff
changeset
|
125 |
uint start = 0; |
bc4e0e0995e6
8152952: Allow G1 phase logging to use individual number of threads
brutisso
parents:
36374
diff
changeset
|
126 |
while (start < _length && get(start) == uninitialized()) { |
bc4e0e0995e6
8152952: Allow G1 phase logging to use individual number of threads
brutisso
parents:
36374
diff
changeset
|
127 |
start++; |
36374 | 128 |
} |
37214
bc4e0e0995e6
8152952: Allow G1 phase logging to use individual number of threads
brutisso
parents:
36374
diff
changeset
|
129 |
if (start < _length) { |
bc4e0e0995e6
8152952: Allow G1 phase logging to use individual number of threads
brutisso
parents:
36374
diff
changeset
|
130 |
T min = get(start); |
bc4e0e0995e6
8152952: Allow G1 phase logging to use individual number of threads
brutisso
parents:
36374
diff
changeset
|
131 |
T max = min; |
bc4e0e0995e6
8152952: Allow G1 phase logging to use individual number of threads
brutisso
parents:
36374
diff
changeset
|
132 |
T sum = 0; |
bc4e0e0995e6
8152952: Allow G1 phase logging to use individual number of threads
brutisso
parents:
36374
diff
changeset
|
133 |
uint contributing_threads = 0; |
bc4e0e0995e6
8152952: Allow G1 phase logging to use individual number of threads
brutisso
parents:
36374
diff
changeset
|
134 |
for (uint i = start; i < _length; ++i) { |
bc4e0e0995e6
8152952: Allow G1 phase logging to use individual number of threads
brutisso
parents:
36374
diff
changeset
|
135 |
T value = get(i); |
bc4e0e0995e6
8152952: Allow G1 phase logging to use individual number of threads
brutisso
parents:
36374
diff
changeset
|
136 |
if (value != uninitialized()) { |
bc4e0e0995e6
8152952: Allow G1 phase logging to use individual number of threads
brutisso
parents:
36374
diff
changeset
|
137 |
max = MAX2(max, value); |
bc4e0e0995e6
8152952: Allow G1 phase logging to use individual number of threads
brutisso
parents:
36374
diff
changeset
|
138 |
min = MIN2(min, value); |
bc4e0e0995e6
8152952: Allow G1 phase logging to use individual number of threads
brutisso
parents:
36374
diff
changeset
|
139 |
sum += value; |
bc4e0e0995e6
8152952: Allow G1 phase logging to use individual number of threads
brutisso
parents:
36374
diff
changeset
|
140 |
contributing_threads++; |
bc4e0e0995e6
8152952: Allow G1 phase logging to use individual number of threads
brutisso
parents:
36374
diff
changeset
|
141 |
} |
bc4e0e0995e6
8152952: Allow G1 phase logging to use individual number of threads
brutisso
parents:
36374
diff
changeset
|
142 |
} |
bc4e0e0995e6
8152952: Allow G1 phase logging to use individual number of threads
brutisso
parents:
36374
diff
changeset
|
143 |
T diff = max - min; |
bc4e0e0995e6
8152952: Allow G1 phase logging to use individual number of threads
brutisso
parents:
36374
diff
changeset
|
144 |
assert(contributing_threads != 0, "Must be since we found a used value for the start index"); |
bc4e0e0995e6
8152952: Allow G1 phase logging to use individual number of threads
brutisso
parents:
36374
diff
changeset
|
145 |
double avg = sum / (double) contributing_threads; |
bc4e0e0995e6
8152952: Allow G1 phase logging to use individual number of threads
brutisso
parents:
36374
diff
changeset
|
146 |
WDAPrinter::summary(out, min, avg, max, diff, sum, print_sum); |
bc4e0e0995e6
8152952: Allow G1 phase logging to use individual number of threads
brutisso
parents:
36374
diff
changeset
|
147 |
out->print_cr(", Workers: %d", contributing_threads); |
bc4e0e0995e6
8152952: Allow G1 phase logging to use individual number of threads
brutisso
parents:
36374
diff
changeset
|
148 |
} else { |
bc4e0e0995e6
8152952: Allow G1 phase logging to use individual number of threads
brutisso
parents:
36374
diff
changeset
|
149 |
// No data for this phase. |
bc4e0e0995e6
8152952: Allow G1 phase logging to use individual number of threads
brutisso
parents:
36374
diff
changeset
|
150 |
out->print_cr(" skipped"); |
bc4e0e0995e6
8152952: Allow G1 phase logging to use individual number of threads
brutisso
parents:
36374
diff
changeset
|
151 |
} |
36374 | 152 |
} |
153 |
||
154 |
template <class T> |
|
37214
bc4e0e0995e6
8152952: Allow G1 phase logging to use individual number of threads
brutisso
parents:
36374
diff
changeset
|
155 |
void WorkerDataArray<T>::print_details_on(outputStream* out) const { |
bc4e0e0995e6
8152952: Allow G1 phase logging to use individual number of threads
brutisso
parents:
36374
diff
changeset
|
156 |
WDAPrinter::details(this, out); |
36374 | 157 |
} |
158 |
||
33623 | 159 |
template <typename T> |
160 |
void WorkerDataArray<T>::reset() { |
|
161 |
set_all(uninitialized()); |
|
46571
c70b36f0730d
8178148: Log more detailed information about scan rs phase
tschatzl
parents:
37214
diff
changeset
|
162 |
for (uint i = 0; i < MaxThreadWorkItems; i++) { |
c70b36f0730d
8178148: Log more detailed information about scan rs phase
tschatzl
parents:
37214
diff
changeset
|
163 |
if (_thread_work_items[i] != NULL) { |
c70b36f0730d
8178148: Log more detailed information about scan rs phase
tschatzl
parents:
37214
diff
changeset
|
164 |
_thread_work_items[i]->reset(); |
c70b36f0730d
8178148: Log more detailed information about scan rs phase
tschatzl
parents:
37214
diff
changeset
|
165 |
} |
33623 | 166 |
} |
167 |
} |
|
168 |
||
36374 | 169 |
#endif // SHARE_VM_GC_G1_WORKERDATAARRAY_INLINE_HPP |