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_GC_SHARED_WORKERDATAARRAY_INLINE_HPP
26 #define SHARE_GC_SHARED_WORKERDATAARRAY_INLINE_HPP
27
28 #include "gc/shared/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, bool is_serial) :
34 _data(NULL),
35 _length(length),
36 _title(title),
37 _is_serial(is_serial) {
38 assert(length > 0, "Must have some workers to store data for");
39 assert(!is_serial || length == 1, "Serial phase must only have a single entry.");
40 _data = NEW_C_HEAP_ARRAY(T, _length, mtGC);
41 for (uint i = 0; i < MaxThreadWorkItems; i++) {
42 _thread_work_items[i] = NULL;
43 }
44 reset();
45 }
46
47 template <typename T>
48 void WorkerDataArray<T>::set(uint worker_i, T value) {
49 assert(worker_i < _length, "Worker %d is greater than max: %d", worker_i, _length);
50 assert(_data[worker_i] == uninitialized(), "Overwriting data for worker %d in %s", worker_i, _title);
51 _data[worker_i] = value;
52 }
53
54 template <typename T>
55 T WorkerDataArray<T>::get(uint worker_i) const {
56 assert(worker_i < _length, "Worker %d is greater than max: %d", worker_i, _length);
57 return _data[worker_i];
58 }
59
60 template <typename T>
61 WorkerDataArray<T>::~WorkerDataArray() {
62 for (uint i = 0; i < MaxThreadWorkItems; i++) {
63 delete _thread_work_items[i];
64 }
65 FREE_C_HEAP_ARRAY(T, _data);
66 }
67
68 template <typename T>
69 void WorkerDataArray<T>::link_thread_work_items(WorkerDataArray<size_t>* thread_work_items, uint index) {
70 assert(index < MaxThreadWorkItems, "Tried to access thread work item %u (max %u)", index, MaxThreadWorkItems);
71 _thread_work_items[index] = thread_work_items;
72 }
73
74 template <typename T>
75 void WorkerDataArray<T>::set_thread_work_item(uint worker_i, size_t value, uint index) {
76 assert(index < MaxThreadWorkItems, "Tried to access thread work item %u (max %u)", index, MaxThreadWorkItems);
77 assert(_thread_work_items[index] != NULL, "No sub count");
78 _thread_work_items[index]->set(worker_i, value);
79 }
80
81 template <typename T>
82 void WorkerDataArray<T>::add_thread_work_item(uint worker_i, size_t value, uint index) {
83 assert(index < MaxThreadWorkItems, "Tried to access thread work item %u (max %u)", index, MaxThreadWorkItems);
84 assert(_thread_work_items[index] != NULL, "No sub count");
85 _thread_work_items[index]->add(worker_i, value);
86 }
87
88 template <typename T>
89 void WorkerDataArray<T>::set_or_add_thread_work_item(uint worker_i, size_t value, uint index) {
90 assert(index < MaxThreadWorkItems, "Tried to access thread work item %u (max %u)", index, MaxThreadWorkItems);
91 assert(_thread_work_items[index] != NULL, "No sub count");
|
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_GC_SHARED_WORKERDATAARRAY_INLINE_HPP
26 #define SHARE_GC_SHARED_WORKERDATAARRAY_INLINE_HPP
27
28 #include "gc/shared/workerDataArray.hpp"
29 #include "memory/allocation.inline.hpp"
30 #include "utilities/ostream.hpp"
31
32 template <typename T>
33 WorkerDataArray<T>::WorkerDataArray(const char* title, uint length, bool is_serial) :
34 _data(NULL),
35 _length(length),
36 _title(title),
37 _is_serial(is_serial) {
38 assert(length > 0, "Must have some workers to store data for");
39 assert(!is_serial || length == 1, "Serial phase must only have a single entry.");
40 _data = NEW_C_HEAP_ARRAY(T, _length, mtGC);
41 for (uint i = 0; i < MaxThreadWorkItems; i++) {
42 _thread_work_items[i] = NULL;
43 }
44 reset();
45 }
46
47 template <typename T>
48 void WorkerDataArray<T>::set(uint worker_i, T value) {
49 assert(worker_i < _length, "Worker %d is greater than max: %d", worker_i, _length);
50 assert(_data[worker_i] == uninitialized(), "Overwriting data for worker %d in %s", worker_i, _title);
51 _data[worker_i] = value;
52 }
53
54 template <typename T>
55 T WorkerDataArray<T>::get(uint worker_i) const {
56 assert(worker_i < _length, "Worker %d is greater than max: %d", worker_i, _length);
57 return _data[worker_i];
58 }
59
60 template <typename T>
61 WorkerDataArray<T>::~WorkerDataArray() {
62 for (uint i = 0; i < MaxThreadWorkItems; i++) {
63 delete _thread_work_items[i];
64 }
65 FREE_C_HEAP_ARRAY(T, _data);
66 }
67
68 template <typename T>
69 void WorkerDataArray<T>::create_thread_work_items(const char* title, uint index, uint length_override) {
70 assert(index < MaxThreadWorkItems, "Tried to access thread work item %u (max %u)", index, MaxThreadWorkItems);
71 assert(_thread_work_items[index] == NULL, "Tried to overwrite existing thread work item");
72 uint length = length_override != 0 ? length_override : _length;
73 _thread_work_items[index] = new WorkerDataArray<size_t>(title, length);
74 }
75
76 template <typename T>
77 void WorkerDataArray<T>::set_thread_work_item(uint worker_i, size_t value, uint index) {
78 assert(index < MaxThreadWorkItems, "Tried to access thread work item %u (max %u)", index, MaxThreadWorkItems);
79 assert(_thread_work_items[index] != NULL, "No sub count");
80 _thread_work_items[index]->set(worker_i, value);
81 }
82
83 template <typename T>
84 void WorkerDataArray<T>::add_thread_work_item(uint worker_i, size_t value, uint index) {
85 assert(index < MaxThreadWorkItems, "Tried to access thread work item %u (max %u)", index, MaxThreadWorkItems);
86 assert(_thread_work_items[index] != NULL, "No sub count");
87 _thread_work_items[index]->add(worker_i, value);
88 }
89
90 template <typename T>
91 void WorkerDataArray<T>::set_or_add_thread_work_item(uint worker_i, size_t value, uint index) {
92 assert(index < MaxThreadWorkItems, "Tried to access thread work item %u (max %u)", index, MaxThreadWorkItems);
93 assert(_thread_work_items[index] != NULL, "No sub count");
|