1 /*
2 * Copyright (c) 2015, 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 *
61 template <typename T>
62 void WorkerDataArray<T>::link_thread_work_items(WorkerDataArray<size_t>* thread_work_items) {
63 _thread_work_items = thread_work_items;
64 }
65
66 template <typename T>
67 void WorkerDataArray<T>::set_thread_work_item(uint worker_i, size_t value) {
68 assert(_thread_work_items != NULL, "No sub count");
69 _thread_work_items->set(worker_i, value);
70 }
71
72 template <typename T>
73 void WorkerDataArray<T>::add(uint worker_i, T value) {
74 assert(worker_i < _length, "Worker %d is greater than max: %d", worker_i, _length);
75 assert(_data[worker_i] != uninitialized(), "No data to add to for worker %d", worker_i);
76 _data[worker_i] += value;
77 }
78
79 template <typename T>
80 double WorkerDataArray<T>::average() const {
81 uint active_threads = 0;
82 for (uint i = 0; i < _length; ++i) {
83 if (get(i) != uninitialized()) {
84 active_threads++;
85 }
86 }
87 if (active_threads == 0) {
88 return 0.0;
89 }
90 return sum() / (double) active_threads;
91 }
92
93 template <typename T>
94 T WorkerDataArray<T>::sum() const {
95 T s = 0;
96 for (uint i = 0; i < _length; ++i) {
97 if (get(i) != uninitialized()) {
98 s += get(i);
99 }
100 }
101 return s;
102 }
103
104 template <typename T>
105 void WorkerDataArray<T>::set_all(T value) {
106 for (uint i = 0; i < _length; i++) {
107 _data[i] = value;
108 }
109 }
110
111 template <class T>
112 void WorkerDataArray<T>::print_summary_on(outputStream* out, bool print_sum) const {
113 out->print("%-25s", title());
114 uint start = 0;
115 while (start < _length && get(start) == uninitialized()) {
116 start++;
117 }
118 if (start < _length) {
119 T min = get(start);
120 T max = min;
121 T sum = 0;
122 uint active_threads = 0;
123 for (uint i = start; i < _length; ++i) {
124 T value = get(i);
125 if (value != uninitialized()) {
126 max = MAX2(max, value);
127 min = MIN2(min, value);
128 sum += value;
129 active_threads++;
130 }
131 }
132 T diff = max - min;
133 assert(active_threads != 0, "Must be since we found a used value for the start index");
134 double avg = sum / (double) active_threads;
135 WDAPrinter::summary(out, min, avg, max, diff, sum, print_sum);
136 out->print_cr(", Workers: %d", active_threads);
137 } else {
138 // No data for this phase.
139 out->print_cr(" skipped");
140 }
141 }
142
143 template <class T>
144 void WorkerDataArray<T>::print_details_on(outputStream* out) const {
145 WDAPrinter::details(this, out);
146 }
147
148 template <typename T>
149 void WorkerDataArray<T>::reset() {
150 set_all(uninitialized());
151 if (_thread_work_items != NULL) {
152 _thread_work_items->reset();
153 }
154 }
155
156 #endif // SHARE_VM_GC_G1_WORKERDATAARRAY_INLINE_HPP
|
1 /*
2 * Copyright (c) 2015, 2016, 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 *
61 template <typename T>
62 void WorkerDataArray<T>::link_thread_work_items(WorkerDataArray<size_t>* thread_work_items) {
63 _thread_work_items = thread_work_items;
64 }
65
66 template <typename T>
67 void WorkerDataArray<T>::set_thread_work_item(uint worker_i, size_t value) {
68 assert(_thread_work_items != NULL, "No sub count");
69 _thread_work_items->set(worker_i, value);
70 }
71
72 template <typename T>
73 void WorkerDataArray<T>::add(uint worker_i, T value) {
74 assert(worker_i < _length, "Worker %d is greater than max: %d", worker_i, _length);
75 assert(_data[worker_i] != uninitialized(), "No data to add to for worker %d", worker_i);
76 _data[worker_i] += value;
77 }
78
79 template <typename T>
80 double WorkerDataArray<T>::average() const {
81 uint contributing_threads = 0;
82 for (uint i = 0; i < _length; ++i) {
83 if (get(i) != uninitialized()) {
84 contributing_threads++;
85 }
86 }
87 if (contributing_threads == 0) {
88 return 0.0;
89 }
90 return sum() / (double) contributing_threads;
91 }
92
93 template <typename T>
94 T WorkerDataArray<T>::sum() const {
95 T s = 0;
96 for (uint i = 0; i < _length; ++i) {
97 if (get(i) != uninitialized()) {
98 s += get(i);
99 }
100 }
101 return s;
102 }
103
104 template <typename T>
105 void WorkerDataArray<T>::set_all(T value) {
106 for (uint i = 0; i < _length; i++) {
107 _data[i] = value;
108 }
109 }
110
111 template <class T>
112 void WorkerDataArray<T>::print_summary_on(outputStream* out, bool print_sum) const {
113 out->print("%-25s", title());
114 uint start = 0;
115 while (start < _length && get(start) == uninitialized()) {
116 start++;
117 }
118 if (start < _length) {
119 T min = get(start);
120 T max = min;
121 T sum = 0;
122 uint contributing_threads = 0;
123 for (uint i = start; i < _length; ++i) {
124 T value = get(i);
125 if (value != uninitialized()) {
126 max = MAX2(max, value);
127 min = MIN2(min, value);
128 sum += value;
129 contributing_threads++;
130 }
131 }
132 T diff = max - min;
133 assert(contributing_threads != 0, "Must be since we found a used value for the start index");
134 double avg = sum / (double) contributing_threads;
135 WDAPrinter::summary(out, min, avg, max, diff, sum, print_sum);
136 out->print_cr(", Workers: %d", contributing_threads);
137 } else {
138 // No data for this phase.
139 out->print_cr(" skipped");
140 }
141 }
142
143 template <class T>
144 void WorkerDataArray<T>::print_details_on(outputStream* out) const {
145 WDAPrinter::details(this, out);
146 }
147
148 template <typename T>
149 void WorkerDataArray<T>::reset() {
150 set_all(uninitialized());
151 if (_thread_work_items != NULL) {
152 _thread_work_items->reset();
153 }
154 }
155
156 #endif // SHARE_VM_GC_G1_WORKERDATAARRAY_INLINE_HPP
|