8140393: Move WorkerDataArray to its own file
Reviewed-by: tschatzl, mgerdin, tbenson
--- a/hotspot/src/share/vm/gc/g1/g1GCPhaseTimes.cpp Thu Oct 29 11:33:43 2015 +0100
+++ b/hotspot/src/share/vm/gc/g1/g1GCPhaseTimes.cpp Thu Oct 29 14:58:44 2015 +0100
@@ -28,6 +28,7 @@
#include "gc/g1/g1GCPhaseTimes.hpp"
#include "gc/g1/g1Log.hpp"
#include "gc/g1/g1StringDedup.hpp"
+#include "gc/g1/workerDataArray.inline.hpp"
#include "memory/allocation.hpp"
#include "runtime/os.hpp"
@@ -86,168 +87,6 @@
}
};
-template <class T>
-class WorkerDataArray : public CHeapObj<mtGC> {
- friend class G1GCParPhasePrinter;
- T* _data;
- uint _length;
- const char* _title;
- bool _print_sum;
- int _log_level;
- uint _indent_level;
- bool _enabled;
-
- WorkerDataArray<size_t>* _thread_work_items;
-
- NOT_PRODUCT(inline T uninitialized() const;)
-
- void set_all(T value) {
- for (uint i = 0; i < _length; i++) {
- _data[i] = value;
- }
- }
-
- public:
- WorkerDataArray(uint length,
- const char* title,
- bool print_sum,
- int log_level,
- uint indent_level) :
- _title(title),
- _length(0),
- _print_sum(print_sum),
- _log_level(log_level),
- _indent_level(indent_level),
- _thread_work_items(NULL),
- _enabled(true) {
- assert(length > 0, "Must have some workers to store data for");
- _length = length;
- _data = NEW_C_HEAP_ARRAY(T, _length, mtGC);
- reset();
- }
-
- ~WorkerDataArray() {
- FREE_C_HEAP_ARRAY(T, _data);
- }
-
- void link_thread_work_items(WorkerDataArray<size_t>* thread_work_items) {
- _thread_work_items = thread_work_items;
- }
-
- WorkerDataArray<size_t>* thread_work_items() const {
- return _thread_work_items;
- }
-
- void set(uint worker_i, T value) {
- assert(worker_i < _length, "Worker %d is greater than max: %d", worker_i, _length);
- assert(_data[worker_i] == uninitialized(), "Overwriting data for worker %d in %s", worker_i, _title);
- _data[worker_i] = value;
- }
-
- void set_thread_work_item(uint worker_i, size_t value) {
- assert(_thread_work_items != NULL, "No sub count");
- _thread_work_items->set(worker_i, value);
- }
-
- T get(uint worker_i) const {
- assert(worker_i < _length, "Worker %d is greater than max: %d", worker_i, _length);
- assert(_data[worker_i] != uninitialized(), "No data added for worker %d", worker_i);
- return _data[worker_i];
- }
-
- void add(uint worker_i, T value) {
- assert(worker_i < _length, "Worker %d is greater than max: %d", worker_i, _length);
- assert(_data[worker_i] != uninitialized(), "No data to add to for worker %d", worker_i);
- _data[worker_i] += value;
- }
-
- double average(uint active_threads) const {
- return sum(active_threads) / (double) active_threads;
- }
-
- T sum(uint active_threads) const {
- T s = get(0);
- for (uint i = 1; i < active_threads; ++i) {
- s += get(i);
- }
- return s;
- }
-
- T minimum(uint active_threads) const {
- T min = get(0);
- for (uint i = 1; i < active_threads; ++i) {
- min = MIN2(min, get(i));
- }
- return min;
- }
-
- T maximum(uint active_threads) const {
- T max = get(0);
- for (uint i = 1; i < active_threads; ++i) {
- max = MAX2(max, get(i));
- }
- return max;
- }
-
- T diff(uint active_threads) const {
- return maximum(active_threads) - minimum(active_threads);
- }
-
- void reset() PRODUCT_RETURN;
- void verify(uint active_threads) PRODUCT_RETURN;
-
- void set_enabled(bool enabled) {
- _enabled = enabled;
- }
-
- int log_level() const {
- return _log_level;
- }
-
- void clear() {
- set_all(0);
- }
-};
-
-
-#ifndef PRODUCT
-
-template <>
-inline size_t WorkerDataArray<size_t>::uninitialized() const {
- return (size_t)-1;
-}
-
-template <>
-inline double WorkerDataArray<double>::uninitialized() const {
- return -1.0;
-}
-
-template <class T>
-void WorkerDataArray<T>::reset() {
- set_all(uninitialized());
- if (_thread_work_items != NULL) {
- _thread_work_items->reset();
- }
-}
-
-template <class T>
-void WorkerDataArray<T>::verify(uint active_threads) {
- if (!_enabled) {
- return;
- }
-
- assert(active_threads <= _length, "Wrong number of active threads");
- for (uint i = 0; i < active_threads; i++) {
- assert(_data[i] != uninitialized(),
- "Invalid data for worker %u in '%s'", i, _title);
- }
- if (_thread_work_items != NULL) {
- _thread_work_items->verify(active_threads);
- }
-}
-
-#endif
-
G1GCPhaseTimes::G1GCPhaseTimes(uint max_gc_threads) :
_max_gc_threads(max_gc_threads)
{
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/src/share/vm/gc/g1/workerDataArray.cpp Thu Oct 29 14:58:44 2015 +0100
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#include "precompiled.hpp"
+#include "gc/g1/workerDataArray.inline.hpp"
+
+#ifndef PRODUCT
+void WorkerDataArray_test() {
+ const uint length = 3;
+ const char* title = "Test array";
+ const bool print_sum = false;
+ const int log_level = 3;
+ const uint indent_level = 2;
+
+ WorkerDataArray<size_t> array(length, title, print_sum, log_level, indent_level);
+ assert(strncmp(array.title(), title, strlen(title)) == 0 , "Expected titles to match");
+ assert(array.should_print_sum() == print_sum, "Expected should_print_sum to match print_sum");
+ assert(array.log_level() == log_level, "Expected log levels to match");
+ assert(array.indentation() == indent_level, "Expected indentation to match");
+
+ const size_t expected[length] = {5, 3, 7};
+ for (uint i = 0; i < length; i++) {
+ array.set(i, expected[i]);
+ }
+ for (uint i = 0; i < length; i++) {
+ assert(array.get(i) == expected[i], "Expected elements to match");
+ }
+
+ assert(array.sum(length) == (5 + 3 + 7), "Expected sums to match");
+ assert(array.minimum(length) == 3, "Expected mininum to match");
+ assert(array.maximum(length) == 7, "Expected maximum to match");
+ assert(array.diff(length) == (7 - 3), "Expected diffs to match");
+ assert(array.average(length) == 5, "Expected averages to match");
+
+ for (uint i = 0; i < length; i++) {
+ array.add(i, 1);
+ }
+ for (uint i = 0; i < length; i++) {
+ assert(array.get(i) == expected[i] + 1, "Expected add to increment values");
+ }
+}
+#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/src/share/vm/gc/g1/workerDataArray.hpp Thu Oct 29 14:58:44 2015 +0100
@@ -0,0 +1,94 @@
+/*
+ * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#include "memory/allocation.hpp"
+#include "utilities/debug.hpp"
+
+template <class T>
+class WorkerDataArray : public CHeapObj<mtGC> {
+ friend class G1GCParPhasePrinter;
+ T* _data;
+ uint _length;
+ const char* _title;
+ bool _print_sum;
+ int _log_level;
+ uint _indent_level;
+ bool _enabled;
+
+ WorkerDataArray<size_t>* _thread_work_items;
+
+ NOT_PRODUCT(inline T uninitialized() const;)
+
+ void set_all(T value);
+
+ public:
+ WorkerDataArray(uint length,
+ const char* title,
+ bool print_sum,
+ int log_level,
+ uint indent_level);
+
+ ~WorkerDataArray();
+
+ void link_thread_work_items(WorkerDataArray<size_t>* thread_work_items);
+ void set_thread_work_item(uint worker_i, size_t value);
+ WorkerDataArray<size_t>* thread_work_items() const {
+ return _thread_work_items;
+ }
+
+ void set(uint worker_i, T value);
+ T get(uint worker_i) const;
+
+ void add(uint worker_i, T value);
+
+ double average(uint active_threads) const;
+ T sum(uint active_threads) const;
+ T minimum(uint active_threads) const;
+ T maximum(uint active_threads) const;
+ T diff(uint active_threads) const;
+
+ uint indentation() const {
+ return _indent_level;
+ }
+
+ const char* title() const {
+ return _title;
+ }
+
+ bool should_print_sum() const {
+ return _print_sum;
+ }
+
+ int log_level() const {
+ return _log_level;
+ }
+
+ void clear();
+ void set_enabled(bool enabled) {
+ _enabled = enabled;
+ }
+
+ void reset() PRODUCT_RETURN;
+ void verify(uint active_threads) const PRODUCT_RETURN;
+};
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/src/share/vm/gc/g1/workerDataArray.inline.hpp Thu Oct 29 14:58:44 2015 +0100
@@ -0,0 +1,167 @@
+/*
+ * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#include "gc/g1/workerDataArray.hpp"
+#include "memory/allocation.inline.hpp"
+
+template <typename T>
+WorkerDataArray<T>::WorkerDataArray(uint length,
+ const char* title,
+ bool print_sum,
+ int log_level,
+ uint indent_level) :
+ _title(title),
+ _length(0),
+ _print_sum(print_sum),
+ _log_level(log_level),
+ _indent_level(indent_level),
+ _thread_work_items(NULL),
+ _enabled(true) {
+ assert(length > 0, "Must have some workers to store data for");
+ _length = length;
+ _data = NEW_C_HEAP_ARRAY(T, _length, mtGC);
+ reset();
+}
+
+template <typename T>
+void WorkerDataArray<T>::set(uint worker_i, T value) {
+ assert(worker_i < _length, "Worker %d is greater than max: %d", worker_i, _length);
+ assert(_data[worker_i] == uninitialized(), "Overwriting data for worker %d in %s", worker_i, _title);
+ _data[worker_i] = value;
+}
+
+template <typename T>
+T WorkerDataArray<T>::get(uint worker_i) const {
+ assert(worker_i < _length, "Worker %d is greater than max: %d", worker_i, _length);
+ assert(_data[worker_i] != uninitialized(), "No data added for worker %d", worker_i);
+ return _data[worker_i];
+}
+
+template <typename T>
+WorkerDataArray<T>::~WorkerDataArray() {
+ FREE_C_HEAP_ARRAY(T, _data);
+}
+
+template <typename T>
+void WorkerDataArray<T>::link_thread_work_items(WorkerDataArray<size_t>* thread_work_items) {
+ _thread_work_items = thread_work_items;
+}
+
+template <typename T>
+void WorkerDataArray<T>::set_thread_work_item(uint worker_i, size_t value) {
+ assert(_thread_work_items != NULL, "No sub count");
+ _thread_work_items->set(worker_i, value);
+}
+
+template <typename T>
+void WorkerDataArray<T>::add(uint worker_i, T value) {
+ assert(worker_i < _length, "Worker %d is greater than max: %d", worker_i, _length);
+ assert(_data[worker_i] != uninitialized(), "No data to add to for worker %d", worker_i);
+ _data[worker_i] += value;
+}
+
+template <typename T>
+double WorkerDataArray<T>::average(uint active_threads) const {
+ return sum(active_threads) / (double) active_threads;
+}
+
+template <typename T>
+T WorkerDataArray<T>::sum(uint active_threads) const {
+ T s = get(0);
+ for (uint i = 1; i < active_threads; ++i) {
+ s += get(i);
+ }
+ return s;
+}
+
+template <typename T>
+T WorkerDataArray<T>::minimum(uint active_threads) const {
+ T min = get(0);
+ for (uint i = 1; i < active_threads; ++i) {
+ min = MIN2(min, get(i));
+ }
+ return min;
+}
+
+template <typename T>
+T WorkerDataArray<T>::maximum(uint active_threads) const {
+ T max = get(0);
+ for (uint i = 1; i < active_threads; ++i) {
+ max = MAX2(max, get(i));
+ }
+ return max;
+}
+
+template <typename T>
+T WorkerDataArray<T>::diff(uint active_threads) const {
+ return maximum(active_threads) - minimum(active_threads);
+}
+
+template <typename T>
+void WorkerDataArray<T>::clear() {
+ set_all(0);
+}
+
+template <typename T>
+void WorkerDataArray<T>::set_all(T value) {
+ for (uint i = 0; i < _length; i++) {
+ _data[i] = value;
+ }
+}
+
+#ifndef PRODUCT
+template <typename T>
+void WorkerDataArray<T>::reset() {
+ set_all(uninitialized());
+ if (_thread_work_items != NULL) {
+ _thread_work_items->reset();
+ }
+}
+
+template <typename T>
+void WorkerDataArray<T>::verify(uint active_threads) const {
+ if (!_enabled) {
+ return;
+ }
+
+ assert(active_threads <= _length, "Wrong number of active threads");
+ for (uint i = 0; i < active_threads; i++) {
+ assert(_data[i] != uninitialized(),
+ "Invalid data for worker %u in '%s'", i, _title);
+ }
+ if (_thread_work_items != NULL) {
+ _thread_work_items->verify(active_threads);
+ }
+}
+
+template <>
+inline size_t WorkerDataArray<size_t>::uninitialized() const {
+ return (size_t)-1;
+}
+
+template <>
+inline double WorkerDataArray<double>::uninitialized() const {
+ return -1.0;
+}
+#endif
--- a/hotspot/src/share/vm/prims/jni.cpp Thu Oct 29 11:33:43 2015 +0100
+++ b/hotspot/src/share/vm/prims/jni.cpp Thu Oct 29 14:58:44 2015 +0100
@@ -3876,6 +3876,7 @@
void FreeRegionList_test();
void test_memset_with_concurrent_readers();
void TestPredictions_test();
+void WorkerDataArray_test();
#endif
void execute_internal_vm_tests() {
@@ -3920,6 +3921,7 @@
}
run_unit_test(test_memset_with_concurrent_readers());
run_unit_test(TestPredictions_test());
+ run_unit_test(WorkerDataArray_test());
#endif
tty->print_cr("All internal VM tests passed");
}