25 #include "precompiled.hpp" |
25 #include "precompiled.hpp" |
26 #include "gc/g1/workerDataArray.inline.hpp" |
26 #include "gc/g1/workerDataArray.inline.hpp" |
27 #include "utilities/ostream.hpp" |
27 #include "utilities/ostream.hpp" |
28 |
28 |
29 template <> |
29 template <> |
30 void WorkerDataArray<double>::WDAPrinter::summary(outputStream* out, const char* title, double min, double avg, double max, double diff, double sum, bool print_sum) { |
30 size_t WorkerDataArray<size_t>::uninitialized() { |
31 out->print("%-25s Min: %4.1lf, Avg: %4.1lf, Max: %4.1lf, Diff: %4.1lf", title, min * MILLIUNITS, avg * MILLIUNITS, max * MILLIUNITS, diff* MILLIUNITS); |
31 return (size_t)-1; |
|
32 } |
|
33 |
|
34 template <> |
|
35 double WorkerDataArray<double>::uninitialized() { |
|
36 return -1.0; |
|
37 } |
|
38 |
|
39 template <> |
|
40 void WorkerDataArray<double>::WDAPrinter::summary(outputStream* out, double min, double avg, double max, double diff, double sum, bool print_sum) { |
|
41 out->print(" Min: %4.1lf, Avg: %4.1lf, Max: %4.1lf, Diff: %4.1lf", min * MILLIUNITS, avg * MILLIUNITS, max * MILLIUNITS, diff* MILLIUNITS); |
32 if (print_sum) { |
42 if (print_sum) { |
33 out->print_cr(", Sum: %4.1lf", sum * MILLIUNITS); |
43 out->print(", Sum: %4.1lf", sum * MILLIUNITS); |
34 } else { |
44 } |
35 out->cr(); |
45 } |
36 } |
46 |
37 } |
47 template <> |
38 |
48 void WorkerDataArray<size_t>::WDAPrinter::summary(outputStream* out, size_t min, double avg, size_t max, size_t diff, size_t sum, bool print_sum) { |
39 template <> |
49 out->print(" Min: " SIZE_FORMAT ", Avg: %4.1lf, Max: " SIZE_FORMAT ", Diff: " SIZE_FORMAT, min, avg, max, diff); |
40 void WorkerDataArray<size_t>::WDAPrinter::summary(outputStream* out, const char* title, size_t min, double avg, size_t max, size_t diff, size_t sum, bool print_sum) { |
|
41 out->print("%-25s Min: " SIZE_FORMAT ", Avg: %4.1lf, Max: " SIZE_FORMAT ", Diff: " SIZE_FORMAT, title, min, avg, max, diff); |
|
42 if (print_sum) { |
50 if (print_sum) { |
43 out->print_cr(", Sum: " SIZE_FORMAT, sum); |
51 out->print(", Sum: " SIZE_FORMAT, sum); |
44 } else { |
52 } |
45 out->cr(); |
53 } |
46 } |
54 |
47 } |
55 template <> |
48 |
56 void WorkerDataArray<double>::WDAPrinter::details(const WorkerDataArray<double>* phase, outputStream* out) { |
49 template <> |
|
50 void WorkerDataArray<double>::WDAPrinter::details(const WorkerDataArray<double>* phase, outputStream* out, uint active_threads) { |
|
51 out->print("%-25s", ""); |
57 out->print("%-25s", ""); |
52 for (uint i = 0; i < active_threads; ++i) { |
58 for (uint i = 0; i < phase->_length; ++i) { |
53 out->print(" %4.1lf", phase->get(i) * 1000.0); |
59 double value = phase->get(i); |
|
60 if (value != phase->uninitialized()) { |
|
61 out->print(" %4.1lf", phase->get(i) * 1000.0); |
|
62 } else { |
|
63 out->print(" -"); |
|
64 } |
54 } |
65 } |
55 out->cr(); |
66 out->cr(); |
56 } |
67 } |
57 |
68 |
58 template <> |
69 template <> |
59 void WorkerDataArray<size_t>::WDAPrinter::details(const WorkerDataArray<size_t>* phase, outputStream* out, uint active_threads) { |
70 void WorkerDataArray<size_t>::WDAPrinter::details(const WorkerDataArray<size_t>* phase, outputStream* out) { |
60 out->print("%-25s", ""); |
71 out->print("%-25s", ""); |
61 for (uint i = 0; i < active_threads; ++i) { |
72 for (uint i = 0; i < phase->_length; ++i) { |
62 out->print(" " SIZE_FORMAT, phase->get(i)); |
73 size_t value = phase->get(i); |
|
74 if (value != phase->uninitialized()) { |
|
75 out->print(" " SIZE_FORMAT, phase->get(i)); |
|
76 } else { |
|
77 out->print(" -"); |
|
78 } |
63 } |
79 } |
64 out->cr(); |
80 out->cr(); |
65 } |
81 } |
66 |
82 |
67 #ifndef PRODUCT |
83 #ifndef PRODUCT |
|
84 |
|
85 #include "memory/resourceArea.hpp" |
|
86 |
|
87 void WorkerDataArray_test_verify_string(const char* expected_string, const char* actual_string) { |
|
88 const size_t expected_len = strlen(expected_string); |
|
89 |
|
90 assert(expected_len == strlen(actual_string), |
|
91 "Wrong string length, expected " SIZE_FORMAT " but got " SIZE_FORMAT "(Expected '%s' but got: '%s')", |
|
92 expected_len, strlen(actual_string), expected_string, actual_string); |
|
93 |
|
94 // Can't use strncmp here because floating point values use different decimal points for different locales. |
|
95 // Allow strings to differ in "." vs. "," only. This should still catch most errors. |
|
96 for (size_t i = 0; i < expected_len; i++) { |
|
97 char e = expected_string[i]; |
|
98 char a = actual_string[i]; |
|
99 if (e != a) { |
|
100 if ((e == '.' || e == ',') && (a == '.' || a == ',')) { |
|
101 // Most likely just a difference in locale |
|
102 } else { |
|
103 assert(false, "Expected '%s' but got: '%s'", expected_string, actual_string); |
|
104 } |
|
105 } |
|
106 } |
|
107 } |
|
108 |
|
109 void WorkerDataArray_test_verify_array(WorkerDataArray<size_t>& array, size_t expected_sum, double expected_avg, const char* expected_summary, const char* exected_details) { |
|
110 const double epsilon = 0.0001; |
|
111 assert(array.sum() == expected_sum, "Wrong sum, expected: " SIZE_FORMAT " but got: " SIZE_FORMAT, expected_sum, array.sum()); |
|
112 assert(fabs(array.average() - expected_avg) < epsilon, "Wrong average, expected: %f but got: %f", expected_avg, array.average()); |
|
113 |
|
114 ResourceMark rm; |
|
115 stringStream out; |
|
116 array.print_summary_on(&out); |
|
117 WorkerDataArray_test_verify_string(expected_summary, out.as_string()); |
|
118 out.reset(); |
|
119 array.print_details_on(&out); |
|
120 WorkerDataArray_test_verify_string(exected_details, out.as_string()); |
|
121 } |
|
122 |
|
123 void WorkerDataArray_test_verify_array(WorkerDataArray<double>& array, double expected_sum, double expected_avg, const char* expected_summary, const char* exected_details) { |
|
124 const double epsilon = 0.0001; |
|
125 assert(fabs(array.sum() - expected_sum) < epsilon, "Wrong sum, expected: %f but got: %f", expected_sum, array.sum()); |
|
126 assert(fabs(array.average() - expected_avg) < epsilon, "Wrong average, expected: %f but got: %f", expected_avg, array.average()); |
|
127 |
|
128 ResourceMark rm; |
|
129 stringStream out; |
|
130 array.print_summary_on(&out); |
|
131 WorkerDataArray_test_verify_string(expected_summary, out.as_string()); |
|
132 out.reset(); |
|
133 array.print_details_on(&out); |
|
134 WorkerDataArray_test_verify_string(exected_details, out.as_string()); |
|
135 } |
|
136 |
|
137 void WorkerDataArray_test_basic() { |
|
138 WorkerDataArray<size_t> array(3, "Test array"); |
|
139 array.set(0, 5); |
|
140 array.set(1, 3); |
|
141 array.set(2, 7); |
|
142 |
|
143 WorkerDataArray_test_verify_array(array, 15, 5.0, |
|
144 "Test array Min: 3, Avg: 5.0, Max: 7, Diff: 4, Sum: 15, Workers: 3\n", |
|
145 " 5 3 7\n" ); |
|
146 } |
|
147 |
|
148 void WorkerDataArray_test_add() { |
|
149 WorkerDataArray<size_t> array(3, "Test array"); |
|
150 array.set(0, 5); |
|
151 array.set(1, 3); |
|
152 array.set(2, 7); |
|
153 |
|
154 for (uint i = 0; i < 3; i++) { |
|
155 array.add(i, 1); |
|
156 } |
|
157 |
|
158 WorkerDataArray_test_verify_array(array, 18, 6.0, |
|
159 "Test array Min: 4, Avg: 6.0, Max: 8, Diff: 4, Sum: 18, Workers: 3\n", |
|
160 " 6 4 8\n" ); |
|
161 } |
|
162 |
|
163 void WorkerDataArray_test_with_uninitialized() { |
|
164 WorkerDataArray<size_t> array(3, "Test array"); |
|
165 array.set(0, 5); |
|
166 array.set(1, WorkerDataArray<size_t>::uninitialized()); |
|
167 array.set(2, 7); |
|
168 |
|
169 WorkerDataArray_test_verify_array(array, 12, 6, |
|
170 "Test array Min: 5, Avg: 6.0, Max: 7, Diff: 2, Sum: 12, Workers: 2\n", |
|
171 " 5 - 7\n" ); |
|
172 } |
|
173 |
|
174 void WorkerDataArray_test_uninitialized() { |
|
175 WorkerDataArray<size_t> array(3, "Test array"); |
|
176 array.set(0, WorkerDataArray<size_t>::uninitialized()); |
|
177 array.set(1, WorkerDataArray<size_t>::uninitialized()); |
|
178 array.set(2, WorkerDataArray<size_t>::uninitialized()); |
|
179 |
|
180 WorkerDataArray_test_verify_array(array, 0, 0.0, |
|
181 "Test array skipped\n", |
|
182 " - - -\n" ); |
|
183 } |
|
184 |
|
185 void WorkerDataArray_test_double_with_uninitialized() { |
|
186 WorkerDataArray<double> array(3, "Test array"); |
|
187 array.set(0, 5.1 / MILLIUNITS); |
|
188 array.set(1, WorkerDataArray<double>::uninitialized()); |
|
189 array.set(2, 7.2 / MILLIUNITS); |
|
190 |
|
191 WorkerDataArray_test_verify_array(array, 12.3 / MILLIUNITS, 6.15 / MILLIUNITS, |
|
192 "Test array Min: 5.1, Avg: 6.1, Max: 7.2, Diff: 2.1, Sum: 12.3, Workers: 2\n", |
|
193 " 5.1 - 7.2\n" ); |
|
194 } |
|
195 |
68 void WorkerDataArray_test() { |
196 void WorkerDataArray_test() { |
69 const uint length = 3; |
197 WorkerDataArray_test_basic(); |
70 const char* title = "Test array"; |
198 WorkerDataArray_test_add(); |
71 |
199 WorkerDataArray_test_with_uninitialized(); |
72 WorkerDataArray<size_t> array(length, title); |
200 WorkerDataArray_test_uninitialized(); |
73 assert(strncmp(array.title(), title, strlen(title)) == 0 , "Expected titles to match"); |
201 WorkerDataArray_test_double_with_uninitialized(); |
74 |
202 } |
75 const size_t expected[length] = {5, 3, 7}; |
203 |
76 for (uint i = 0; i < length; i++) { |
|
77 array.set(i, expected[i]); |
|
78 } |
|
79 for (uint i = 0; i < length; i++) { |
|
80 assert(array.get(i) == expected[i], "Expected elements to match"); |
|
81 } |
|
82 |
|
83 assert(array.sum(length) == (5 + 3 + 7), "Expected sums to match"); |
|
84 assert(array.average(length) == 5.0, "Expected averages to match"); |
|
85 |
|
86 for (uint i = 0; i < length; i++) { |
|
87 array.add(i, 1); |
|
88 } |
|
89 for (uint i = 0; i < length; i++) { |
|
90 assert(array.get(i) == expected[i] + 1, "Expected add to increment values"); |
|
91 } |
|
92 } |
|
93 #endif |
204 #endif |