--- old/src/share/vm/gc/cms/concurrentMarkSweepGeneration.cpp 2017-06-12 16:18:28.859226278 -0700 +++ new/src/share/vm/gc/cms/concurrentMarkSweepGeneration.cpp 2017-06-12 16:18:28.731226282 -0700 @@ -5264,7 +5264,7 @@ CMSRefProcTaskExecutor task_executor(*this); rp->enqueue_discovered_references(&task_executor, _gc_timer_cm); } else { - rp->enqueue_discovered_references(NULL); + rp->enqueue_discovered_references(NULL, _gc_timer_cm); } rp->verify_no_references_recorded(); assert(!rp->discovery_enabled(), "should have been disabled"); --- old/src/share/vm/gc/cms/parNewGeneration.cpp 2017-06-12 16:18:29.623226251 -0700 +++ new/src/share/vm/gc/cms/parNewGeneration.cpp 2017-06-12 16:18:29.499226256 -0700 @@ -1048,7 +1048,7 @@ ParNewRefProcTaskExecutor task_executor(*this, *_old_gen, thread_state_set); rp->enqueue_discovered_references(&task_executor, _gc_timer); } else { - rp->enqueue_discovered_references(NULL); + rp->enqueue_discovered_references(NULL, _gc_timer); } rp->verify_no_references_recorded(); --- old/src/share/vm/gc/g1/g1CollectedHeap.cpp 2017-06-12 16:18:30.263226229 -0700 +++ new/src/share/vm/gc/g1/g1CollectedHeap.cpp 2017-06-12 16:18:30.139226233 -0700 @@ -1283,7 +1283,7 @@ // Enqueue any discovered reference objects that have // not been removed from the discovered lists. - ref_processor_stw()->enqueue_discovered_references(); + ref_processor_stw()->enqueue_discovered_references(NULL, gc_timer); #if defined(COMPILER2) || INCLUDE_JVMCI DerivedPointerTable::update_pointers(); @@ -4421,7 +4421,7 @@ // the pending list. if (!rp->processing_is_mt()) { // Serial reference processing... - rp->enqueue_discovered_references(); + rp->enqueue_discovered_references(NULL, _gc_timer_stw); } else { // Parallel reference enqueueing --- old/src/share/vm/gc/parallel/psMarkSweep.cpp 2017-06-12 16:18:31.011226203 -0700 +++ new/src/share/vm/gc/parallel/psMarkSweep.cpp 2017-06-12 16:18:30.887226207 -0700 @@ -253,7 +253,7 @@ DerivedPointerTable::update_pointers(); #endif - ref_processor()->enqueue_discovered_references(NULL); + ref_processor()->enqueue_discovered_references(NULL, _gc_timer); // Update time of last GC reset_millis_since_last_gc(); --- old/src/share/vm/gc/parallel/psParallelCompact.cpp 2017-06-12 16:18:31.675226180 -0700 +++ new/src/share/vm/gc/parallel/psParallelCompact.cpp 2017-06-12 16:18:31.547226184 -0700 @@ -1037,7 +1037,7 @@ DerivedPointerTable::update_pointers(); #endif - ref_processor()->enqueue_discovered_references(NULL); + ref_processor()->enqueue_discovered_references(NULL, &_gc_timer); if (ZapUnusedHeapArea) { heap->gen_mangle_unused_area(); --- old/src/share/vm/gc/parallel/psScavenge.cpp 2017-06-12 16:18:32.379226155 -0700 +++ new/src/share/vm/gc/parallel/psScavenge.cpp 2017-06-12 16:18:32.255226160 -0700 @@ -432,7 +432,7 @@ PSRefProcTaskExecutor task_executor; reference_processor()->enqueue_discovered_references(&task_executor, &_gc_timer); } else { - reference_processor()->enqueue_discovered_references(NULL); + reference_processor()->enqueue_discovered_references(NULL, &_gc_timer); } } --- old/src/share/vm/gc/shared/referenceProcessorPhaseTimes.cpp 2017-06-12 16:18:33.063226131 -0700 +++ new/src/share/vm/gc/shared/referenceProcessorPhaseTimes.cpp 2017-06-12 16:18:32.939226136 -0700 @@ -92,7 +92,7 @@ if (phase_times()->processing_is_mt() && log.is_level(LogLevel::Trace)) { outputStream* out = log.trace_stream(); - out->print("%s", " "); + out->print("%s", Indents[2]); // worker_time_sec is recorded in seconds but it will be printed in milliseconds. phase_times()->worker_time_sec(phase)->print_summary_on(out, true); } @@ -191,7 +191,7 @@ print_phase(ReferenceProcessorPhaseTimes::RefEnqueue, 0); phase_times()->reset(); - log_debug(gc, ref)(" Counts: Soft: " SIZE_FORMAT " Weak: " SIZE_FORMAT + log_debug(gc, ref)(" Ref Counts: Soft: " SIZE_FORMAT " Weak: " SIZE_FORMAT " Final: " SIZE_FORMAT " Phantom: " SIZE_FORMAT , _stats.soft_count(), _stats.weak_count(), _stats.final_count(), _stats.phantom_count()); --- old/test/gc/logging/TestPrintReferences.java 2017-06-12 16:18:33.727226108 -0700 +++ new/test/gc/logging/TestPrintReferences.java 2017-06-12 16:18:33.603226113 -0700 @@ -63,7 +63,7 @@ /* Enqueue Reference Lists */ gcLogTimeRegex + " Enqueue reference lists " + timeRegex + /* Enqueued Stats */ - gcLogTimeRegex + " Counts: Soft: " + countRegex + " Weak: " + countRegex + + gcLogTimeRegex + " Ref Counts: Soft: " + countRegex + " Weak: " + countRegex + " Final: " + countRegex + " Phantom: " + countRegex ); --- old/src/share/vm/gc/g1/workerDataArray.cpp 2017-06-12 16:18:34.483226082 -0700 +++ /dev/null 2017-06-09 15:42:47.034680681 -0700 @@ -1,81 +0,0 @@ -/* - * Copyright (c) 2015, 2016, 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" -#include "utilities/ostream.hpp" - -template <> -size_t WorkerDataArray::uninitialized() { - return (size_t)-1; -} - -template <> -double WorkerDataArray::uninitialized() { - return -1.0; -} - -template <> -void WorkerDataArray::WDAPrinter::summary(outputStream* out, double min, double avg, double max, double diff, double sum, bool print_sum) { - out->print(" Min: %4.1lf, Avg: %4.1lf, Max: %4.1lf, Diff: %4.1lf", min * MILLIUNITS, avg * MILLIUNITS, max * MILLIUNITS, diff* MILLIUNITS); - if (print_sum) { - out->print(", Sum: %4.1lf", sum * MILLIUNITS); - } -} - -template <> -void WorkerDataArray::WDAPrinter::summary(outputStream* out, size_t min, double avg, size_t max, size_t diff, size_t sum, bool print_sum) { - out->print(" Min: " SIZE_FORMAT ", Avg: %4.1lf, Max: " SIZE_FORMAT ", Diff: " SIZE_FORMAT, min, avg, max, diff); - if (print_sum) { - out->print(", Sum: " SIZE_FORMAT, sum); - } -} - -template <> -void WorkerDataArray::WDAPrinter::details(const WorkerDataArray* phase, outputStream* out) { - out->print("%-25s", ""); - for (uint i = 0; i < phase->_length; ++i) { - double value = phase->get(i); - if (value != phase->uninitialized()) { - out->print(" %4.1lf", phase->get(i) * 1000.0); - } else { - out->print(" -"); - } - } - out->cr(); -} - -template <> -void WorkerDataArray::WDAPrinter::details(const WorkerDataArray* phase, outputStream* out) { - out->print("%-25s", ""); - for (uint i = 0; i < phase->_length; ++i) { - size_t value = phase->get(i); - if (value != phase->uninitialized()) { - out->print(" " SIZE_FORMAT, phase->get(i)); - } else { - out->print(" -"); - } - } - out->cr(); -} --- /dev/null 2017-06-09 15:42:47.034680681 -0700 +++ new/src/share/vm/gc/shared/workerDataArray.cpp 2017-06-12 16:18:34.295226089 -0700 @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2015, 2017, 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/shared/workerDataArray.inline.hpp" +#include "utilities/ostream.hpp" + +template <> +size_t WorkerDataArray::uninitialized() { + return (size_t)-1; +} + +template <> +double WorkerDataArray::uninitialized() { + return -1.0; +} + +template <> +void WorkerDataArray::WDAPrinter::summary(outputStream* out, double min, double avg, double max, double diff, double sum, bool print_sum) { + out->print(" Min: %4.1lf, Avg: %4.1lf, Max: %4.1lf, Diff: %4.1lf", min * MILLIUNITS, avg * MILLIUNITS, max * MILLIUNITS, diff* MILLIUNITS); + if (print_sum) { + out->print(", Sum: %4.1lf", sum * MILLIUNITS); + } +} + +template <> +void WorkerDataArray::WDAPrinter::summary(outputStream* out, size_t min, double avg, size_t max, size_t diff, size_t sum, bool print_sum) { + out->print(" Min: " SIZE_FORMAT ", Avg: %4.1lf, Max: " SIZE_FORMAT ", Diff: " SIZE_FORMAT, min, avg, max, diff); + if (print_sum) { + out->print(", Sum: " SIZE_FORMAT, sum); + } +} + +template <> +void WorkerDataArray::WDAPrinter::details(const WorkerDataArray* phase, outputStream* out) { + out->print("%-25s", ""); + for (uint i = 0; i < phase->_length; ++i) { + double value = phase->get(i); + if (value != phase->uninitialized()) { + out->print(" %4.1lf", phase->get(i) * 1000.0); + } else { + out->print(" -"); + } + } + out->cr(); +} + +template <> +void WorkerDataArray::WDAPrinter::details(const WorkerDataArray* phase, outputStream* out) { + out->print("%-25s", ""); + for (uint i = 0; i < phase->_length; ++i) { + size_t value = phase->get(i); + if (value != phase->uninitialized()) { + out->print(" " SIZE_FORMAT, phase->get(i)); + } else { + out->print(" -"); + } + } + out->cr(); +} --- old/src/share/vm/gc/g1/workerDataArray.hpp 2017-06-12 16:18:35.251226055 -0700 +++ /dev/null 2017-06-09 15:42:47.034680681 -0700 @@ -1,86 +0,0 @@ -/* - * Copyright (c) 2015, 2016, 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. - * - */ - -#ifndef SHARE_VM_GC_G1_WORKERDATAARRAY_HPP -#define SHARE_VM_GC_G1_WORKERDATAARRAY_HPP - -#include "memory/allocation.hpp" -#include "utilities/debug.hpp" - -class outputStream; - -template -class WorkerDataArray : public CHeapObj { - friend class WDAPrinter; - T* _data; - uint _length; - const char* _title; - - WorkerDataArray* _thread_work_items; - - public: - WorkerDataArray(uint length, const char* title); - ~WorkerDataArray(); - - void link_thread_work_items(WorkerDataArray* thread_work_items); - void set_thread_work_item(uint worker_i, size_t value); - WorkerDataArray* thread_work_items() const { - return _thread_work_items; - } - - static T uninitialized(); - - void set(uint worker_i, T value); - T get(uint worker_i) const; - - void add(uint worker_i, T value); - - // The sum() and average() methods below consider uninitialized slots to be 0. - double average() const; - T sum() const; - - const char* title() const { - return _title; - } - - void reset(); - void set_all(T value); - - - private: - class WDAPrinter { - public: - static void summary(outputStream* out, double min, double avg, double max, double diff, double sum, bool print_sum); - static void summary(outputStream* out, size_t min, double avg, size_t max, size_t diff, size_t sum, bool print_sum); - - static void details(const WorkerDataArray* phase, outputStream* out); - static void details(const WorkerDataArray* phase, outputStream* out); - }; - - public: - void print_summary_on(outputStream* out, bool print_sum = true) const; - void print_details_on(outputStream* out) const; -}; - -#endif // SHARE_VM_GC_G1_WORKERDATAARRAY_HPP --- /dev/null 2017-06-09 15:42:47.034680681 -0700 +++ new/src/share/vm/gc/shared/workerDataArray.hpp 2017-06-12 16:18:35.063226062 -0700 @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2015, 2017, 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. + * + */ + +#ifndef SHARE_VM_GC_SHARED_WORKERDATAARRAY_HPP +#define SHARE_VM_GC_SHARED_WORKERDATAARRAY_HPP + +#include "memory/allocation.hpp" +#include "utilities/debug.hpp" + +class outputStream; + +template +class WorkerDataArray : public CHeapObj { + friend class WDAPrinter; + T* _data; + uint _length; + const char* _title; + + WorkerDataArray* _thread_work_items; + + public: + WorkerDataArray(uint length, const char* title); + ~WorkerDataArray(); + + void link_thread_work_items(WorkerDataArray* thread_work_items); + void set_thread_work_item(uint worker_i, size_t value); + WorkerDataArray* thread_work_items() const { + return _thread_work_items; + } + + static T uninitialized(); + + void set(uint worker_i, T value); + T get(uint worker_i) const; + + void add(uint worker_i, T value); + + // The sum() and average() methods below consider uninitialized slots to be 0. + double average() const; + T sum() const; + + const char* title() const { + return _title; + } + + void reset(); + void set_all(T value); + + + private: + class WDAPrinter { + public: + static void summary(outputStream* out, double min, double avg, double max, double diff, double sum, bool print_sum); + static void summary(outputStream* out, size_t min, double avg, size_t max, size_t diff, size_t sum, bool print_sum); + + static void details(const WorkerDataArray* phase, outputStream* out); + static void details(const WorkerDataArray* phase, outputStream* out); + }; + + public: + void print_summary_on(outputStream* out, bool print_sum = true) const; + void print_details_on(outputStream* out) const; +}; + +#endif // SHARE_VM_GC_SHARED_WORKERDATAARRAY_HPP --- old/src/share/vm/gc/g1/workerDataArray.inline.hpp 2017-06-12 16:18:35.975226030 -0700 +++ /dev/null 2017-06-09 15:42:47.034680681 -0700 @@ -1,156 +0,0 @@ -/* - * Copyright (c) 2015, 2016, 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. - * - */ - -#ifndef SHARE_VM_GC_G1_WORKERDATAARRAY_INLINE_HPP -#define SHARE_VM_GC_G1_WORKERDATAARRAY_INLINE_HPP - -#include "gc/g1/workerDataArray.hpp" -#include "memory/allocation.inline.hpp" -#include "utilities/ostream.hpp" - -template -WorkerDataArray::WorkerDataArray(uint length, const char* title) : - _title(title), - _length(0), - _thread_work_items(NULL) { - assert(length > 0, "Must have some workers to store data for"); - _length = length; - _data = NEW_C_HEAP_ARRAY(T, _length, mtGC); - reset(); -} - -template -void WorkerDataArray::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 -T WorkerDataArray::get(uint worker_i) const { - assert(worker_i < _length, "Worker %d is greater than max: %d", worker_i, _length); - return _data[worker_i]; -} - -template -WorkerDataArray::~WorkerDataArray() { - FREE_C_HEAP_ARRAY(T, _data); -} - -template -void WorkerDataArray::link_thread_work_items(WorkerDataArray* thread_work_items) { - _thread_work_items = thread_work_items; -} - -template -void WorkerDataArray::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 -void WorkerDataArray::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 -double WorkerDataArray::average() const { - uint contributing_threads = 0; - for (uint i = 0; i < _length; ++i) { - if (get(i) != uninitialized()) { - contributing_threads++; - } - } - if (contributing_threads == 0) { - return 0.0; - } - return sum() / (double) contributing_threads; -} - -template -T WorkerDataArray::sum() const { - T s = 0; - for (uint i = 0; i < _length; ++i) { - if (get(i) != uninitialized()) { - s += get(i); - } - } - return s; -} - -template -void WorkerDataArray::set_all(T value) { - for (uint i = 0; i < _length; i++) { - _data[i] = value; - } -} - -template -void WorkerDataArray::print_summary_on(outputStream* out, bool print_sum) const { - out->print("%-25s", title()); - uint start = 0; - while (start < _length && get(start) == uninitialized()) { - start++; - } - if (start < _length) { - T min = get(start); - T max = min; - T sum = 0; - uint contributing_threads = 0; - for (uint i = start; i < _length; ++i) { - T value = get(i); - if (value != uninitialized()) { - max = MAX2(max, value); - min = MIN2(min, value); - sum += value; - contributing_threads++; - } - } - T diff = max - min; - assert(contributing_threads != 0, "Must be since we found a used value for the start index"); - double avg = sum / (double) contributing_threads; - WDAPrinter::summary(out, min, avg, max, diff, sum, print_sum); - out->print_cr(", Workers: %d", contributing_threads); - } else { - // No data for this phase. - out->print_cr(" skipped"); - } -} - -template -void WorkerDataArray::print_details_on(outputStream* out) const { - WDAPrinter::details(this, out); -} - -template -void WorkerDataArray::reset() { - set_all(uninitialized()); - if (_thread_work_items != NULL) { - _thread_work_items->reset(); - } -} - -#endif // SHARE_VM_GC_G1_WORKERDATAARRAY_INLINE_HPP --- /dev/null 2017-06-09 15:42:47.034680681 -0700 +++ new/src/share/vm/gc/shared/workerDataArray.inline.hpp 2017-06-12 16:18:35.787226037 -0700 @@ -0,0 +1,156 @@ +/* + * Copyright (c) 2015, 2017, 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. + * + */ + +#ifndef SHARE_VM_GC_SHARED_WORKERDATAARRAY_INLINE_HPP +#define SHARE_VM_GC_SHARED_WORKERDATAARRAY_INLINE_HPP + +#include "gc/shared/workerDataArray.hpp" +#include "memory/allocation.inline.hpp" +#include "utilities/ostream.hpp" + +template +WorkerDataArray::WorkerDataArray(uint length, const char* title) : + _title(title), + _length(0), + _thread_work_items(NULL) { + assert(length > 0, "Must have some workers to store data for"); + _length = length; + _data = NEW_C_HEAP_ARRAY(T, _length, mtGC); + reset(); +} + +template +void WorkerDataArray::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 +T WorkerDataArray::get(uint worker_i) const { + assert(worker_i < _length, "Worker %d is greater than max: %d", worker_i, _length); + return _data[worker_i]; +} + +template +WorkerDataArray::~WorkerDataArray() { + FREE_C_HEAP_ARRAY(T, _data); +} + +template +void WorkerDataArray::link_thread_work_items(WorkerDataArray* thread_work_items) { + _thread_work_items = thread_work_items; +} + +template +void WorkerDataArray::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 +void WorkerDataArray::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 +double WorkerDataArray::average() const { + uint contributing_threads = 0; + for (uint i = 0; i < _length; ++i) { + if (get(i) != uninitialized()) { + contributing_threads++; + } + } + if (contributing_threads == 0) { + return 0.0; + } + return sum() / (double) contributing_threads; +} + +template +T WorkerDataArray::sum() const { + T s = 0; + for (uint i = 0; i < _length; ++i) { + if (get(i) != uninitialized()) { + s += get(i); + } + } + return s; +} + +template +void WorkerDataArray::set_all(T value) { + for (uint i = 0; i < _length; i++) { + _data[i] = value; + } +} + +template +void WorkerDataArray::print_summary_on(outputStream* out, bool print_sum) const { + out->print("%-25s", title()); + uint start = 0; + while (start < _length && get(start) == uninitialized()) { + start++; + } + if (start < _length) { + T min = get(start); + T max = min; + T sum = 0; + uint contributing_threads = 0; + for (uint i = start; i < _length; ++i) { + T value = get(i); + if (value != uninitialized()) { + max = MAX2(max, value); + min = MIN2(min, value); + sum += value; + contributing_threads++; + } + } + T diff = max - min; + assert(contributing_threads != 0, "Must be since we found a used value for the start index"); + double avg = sum / (double) contributing_threads; + WDAPrinter::summary(out, min, avg, max, diff, sum, print_sum); + out->print_cr(", Workers: %d", contributing_threads); + } else { + // No data for this phase. + out->print_cr(" skipped"); + } +} + +template +void WorkerDataArray::print_details_on(outputStream* out) const { + WDAPrinter::details(this, out); +} + +template +void WorkerDataArray::reset() { + set_all(uninitialized()); + if (_thread_work_items != NULL) { + _thread_work_items->reset(); + } +} + +#endif // SHARE_VM_GC_SHARED_WORKERDATAARRAY_INLINE_HPP --- old/test/native/gc/g1/test_workerDataArray.cpp 2017-06-12 16:18:36.711226004 -0700 +++ /dev/null 2017-06-09 15:42:47.034680681 -0700 @@ -1,282 +0,0 @@ -/* - * Copyright (c) 2016, 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" -#include "memory/resourceArea.hpp" -#include "unittest.hpp" -#include "utilities/ostream.hpp" - -static const double epsilon = 0.0001; - -template -class WorkerDataArrayTest : public ::testing::Test { - protected: - WorkerDataArrayTest() : - title("Test array"), - array(3, title) { - } - - const char* print_summary() { - stringStream out; - array.print_summary_on(&out); - return out.as_string(); - } - - const char* print_details() { - stringStream out; - array.print_details_on(&out); - return out.as_string(); - } - - const char* print_expected_summary() { - return prepend_with(title, expected_summary()); - } - - const char* print_expected_details() { - return prepend_with("", expected_details()); - } - - // returns expected summary for array without uninitialized elements - // used it because string representation of double depends on locale - static const char* format_summary( - T min, double avg, T max, T diff, T sum, size_t workers); - - const char* title; - WorkerDataArray array; - - private: - virtual const char* expected_summary() = 0; - virtual const char* expected_details() = 0; - - static const char* prepend_with(const char* str, const char* orig) { - stringStream out; - out.print("%-25s", str); - out.print("%s", orig); - return out.as_string(); - } - - ResourceMark rm; -}; - -template<> -const char* WorkerDataArrayTest::format_summary( - size_t min, double avg, size_t max, size_t diff, size_t sum, size_t workers) { - - stringStream out; - out.print(" Min: " SIZE_FORMAT - ", Avg: %4.1lf, Max: " SIZE_FORMAT - ", Diff: " SIZE_FORMAT ", Sum: " SIZE_FORMAT - ", Workers: " SIZE_FORMAT "\n", - min, avg, max, diff, sum, workers); - return out.as_string(); -} - -template<> -const char* WorkerDataArrayTest::format_summary( - double min, double avg, double max, double diff, double sum, size_t workers) { - - stringStream out; - out.print(" Min: %4.1lf" - ", Avg: %4.1lf, Max: %4.1lf" - ", Diff: %4.1lf, Sum: %4.1lf" - ", Workers: " SIZE_FORMAT "\n", - min, avg, max, diff, sum, workers); - return out.as_string(); -} - -class BasicWorkerDataArrayTest : public WorkerDataArrayTest { - protected: - BasicWorkerDataArrayTest() { - array.set(0, 5); - array.set(1, 3); - array.set(2, 7); - } - - private: - virtual const char* expected_summary() { - return format_summary(3, 5.0, 7, 4, 15, 3); - } - - virtual const char* expected_details() { - return " 5 3 7\n"; - } -}; - -TEST_VM_F(BasicWorkerDataArrayTest, sum_test) { - ASSERT_EQ(15u, array.sum()); -} - -TEST_VM_F(BasicWorkerDataArrayTest, average_test) { - ASSERT_NEAR(5.0, array.average(), epsilon); -} - -TEST_VM_F(BasicWorkerDataArrayTest, print_summary_on_test) { - ASSERT_STREQ(print_expected_summary(), print_summary()); -} - -TEST_VM_F(BasicWorkerDataArrayTest, print_details_on_test) { - ASSERT_STREQ(print_expected_details(), print_details()); -} - -class AddWorkerDataArrayTest : public WorkerDataArrayTest { - protected: - AddWorkerDataArrayTest() { - array.set(0, 5); - array.set(1, 3); - array.set(2, 7); - - for (uint i = 0; i < 3; i++) { - array.add(i, 1); - } - } - - private: - virtual const char* expected_summary() { - return format_summary(4, 6.0, 8, 4, 18, 3); - } - - virtual const char* expected_details() { - return " 6 4 8\n"; - } -}; - -TEST_VM_F(AddWorkerDataArrayTest, sum_test) { - ASSERT_EQ(18u, array.sum()); -} - -TEST_VM_F(AddWorkerDataArrayTest, average_test) { - ASSERT_NEAR(6.0, array.average(), epsilon); -} - -TEST_VM_F(AddWorkerDataArrayTest, print_summary_on_test) { - ASSERT_STREQ(print_expected_summary(), print_summary()); -} - -TEST_VM_F(AddWorkerDataArrayTest, print_details_on_test) { - ASSERT_STREQ(print_expected_details(), print_details()); -} - -class UninitializedElementWorkerDataArrayTest : public WorkerDataArrayTest { - protected: - UninitializedElementWorkerDataArrayTest() { - array.set(0, 5); - array.set(1, WorkerDataArray::uninitialized()); - array.set(2, 7); - } - - private: - virtual const char* expected_summary() { - return format_summary(5, 6.0, 7, 2, 12, 2); - } - - virtual const char* expected_details() { - return " 5 - 7\n"; - } -}; - -TEST_VM_F(UninitializedElementWorkerDataArrayTest, sum_test) { - ASSERT_EQ(12u, array.sum()); -} - -TEST_VM_F(UninitializedElementWorkerDataArrayTest, average_test) { - ASSERT_NEAR(6.0, array.average(), epsilon); -} - -TEST_VM_F(UninitializedElementWorkerDataArrayTest, print_summary_on_test) { - ASSERT_STREQ(print_expected_summary(), print_summary()); -} - -TEST_VM_F(UninitializedElementWorkerDataArrayTest, print_details_on_test) { - ASSERT_STREQ(print_expected_details(), print_details()); -} - -class UninitializedWorkerDataArrayTest : public WorkerDataArrayTest { - protected: - UninitializedWorkerDataArrayTest() { - array.set(0, WorkerDataArray::uninitialized()); - array.set(1, WorkerDataArray::uninitialized()); - array.set(2, WorkerDataArray::uninitialized()); - } - - private: - virtual const char* expected_summary() { - return " skipped\n"; - } - - virtual const char* expected_details() { - return " - - -\n"; - } -}; - -TEST_VM_F(UninitializedWorkerDataArrayTest, sum_test) { - ASSERT_EQ(0u, array.sum()); -} - -TEST_VM_F(UninitializedWorkerDataArrayTest, average_test) { - ASSERT_NEAR(0.0, array.average(), epsilon); -} - -TEST_VM_F(UninitializedWorkerDataArrayTest, print_summary_on_test) { - ASSERT_STREQ(print_expected_summary(), print_summary()); -} - -TEST_VM_F(UninitializedWorkerDataArrayTest, print_details_on_test) { - ASSERT_STREQ(print_expected_details(), print_details()); -} - -class UninitializedDoubleElementWorkerDataArrayTest : public WorkerDataArrayTest { - protected: - UninitializedDoubleElementWorkerDataArrayTest() { - array.set(0, 5.1 / MILLIUNITS); - array.set(1, WorkerDataArray::uninitialized()); - array.set(2, 7.2 / MILLIUNITS); - } - - private: - virtual const char* expected_summary() { - return format_summary(5.1, 6.1, 7.2, 2.1, 12.3, 2); - } - - virtual const char* expected_details() { - stringStream out; - out.print(" %4.1lf - %4.1lf\n", 5.1, 7.2); - return out.as_string(); - } -}; - -TEST_VM_F(UninitializedDoubleElementWorkerDataArrayTest, sum_test) { - ASSERT_NEAR(12.3 / MILLIUNITS, array.sum(), epsilon); -} - -TEST_VM_F(UninitializedDoubleElementWorkerDataArrayTest, average_test) { - ASSERT_NEAR(6.15 / MILLIUNITS, array.average(), epsilon); -} - -TEST_VM_F(UninitializedDoubleElementWorkerDataArrayTest, print_summary_on_test) { - ASSERT_STREQ(print_expected_summary(), print_summary()); -} - -TEST_VM_F(UninitializedDoubleElementWorkerDataArrayTest, print_details_on_test) { - ASSERT_STREQ(print_expected_details(), print_details()); -} --- /dev/null 2017-06-09 15:42:47.034680681 -0700 +++ new/test/native/gc/shared/test_workerDataArray.cpp 2017-06-12 16:18:36.523226011 -0700 @@ -0,0 +1,282 @@ +/* + * Copyright (c) 2016, 2017, 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/shared/workerDataArray.inline.hpp" +#include "memory/resourceArea.hpp" +#include "unittest.hpp" +#include "utilities/ostream.hpp" + +static const double epsilon = 0.0001; + +template +class WorkerDataArrayTest : public ::testing::Test { + protected: + WorkerDataArrayTest() : + title("Test array"), + array(3, title) { + } + + const char* print_summary() { + stringStream out; + array.print_summary_on(&out); + return out.as_string(); + } + + const char* print_details() { + stringStream out; + array.print_details_on(&out); + return out.as_string(); + } + + const char* print_expected_summary() { + return prepend_with(title, expected_summary()); + } + + const char* print_expected_details() { + return prepend_with("", expected_details()); + } + + // returns expected summary for array without uninitialized elements + // used it because string representation of double depends on locale + static const char* format_summary( + T min, double avg, T max, T diff, T sum, size_t workers); + + const char* title; + WorkerDataArray array; + + private: + virtual const char* expected_summary() = 0; + virtual const char* expected_details() = 0; + + static const char* prepend_with(const char* str, const char* orig) { + stringStream out; + out.print("%-25s", str); + out.print("%s", orig); + return out.as_string(); + } + + ResourceMark rm; +}; + +template<> +const char* WorkerDataArrayTest::format_summary( + size_t min, double avg, size_t max, size_t diff, size_t sum, size_t workers) { + + stringStream out; + out.print(" Min: " SIZE_FORMAT + ", Avg: %4.1lf, Max: " SIZE_FORMAT + ", Diff: " SIZE_FORMAT ", Sum: " SIZE_FORMAT + ", Workers: " SIZE_FORMAT "\n", + min, avg, max, diff, sum, workers); + return out.as_string(); +} + +template<> +const char* WorkerDataArrayTest::format_summary( + double min, double avg, double max, double diff, double sum, size_t workers) { + + stringStream out; + out.print(" Min: %4.1lf" + ", Avg: %4.1lf, Max: %4.1lf" + ", Diff: %4.1lf, Sum: %4.1lf" + ", Workers: " SIZE_FORMAT "\n", + min, avg, max, diff, sum, workers); + return out.as_string(); +} + +class BasicWorkerDataArrayTest : public WorkerDataArrayTest { + protected: + BasicWorkerDataArrayTest() { + array.set(0, 5); + array.set(1, 3); + array.set(2, 7); + } + + private: + virtual const char* expected_summary() { + return format_summary(3, 5.0, 7, 4, 15, 3); + } + + virtual const char* expected_details() { + return " 5 3 7\n"; + } +}; + +TEST_VM_F(BasicWorkerDataArrayTest, sum_test) { + ASSERT_EQ(15u, array.sum()); +} + +TEST_VM_F(BasicWorkerDataArrayTest, average_test) { + ASSERT_NEAR(5.0, array.average(), epsilon); +} + +TEST_VM_F(BasicWorkerDataArrayTest, print_summary_on_test) { + ASSERT_STREQ(print_expected_summary(), print_summary()); +} + +TEST_VM_F(BasicWorkerDataArrayTest, print_details_on_test) { + ASSERT_STREQ(print_expected_details(), print_details()); +} + +class AddWorkerDataArrayTest : public WorkerDataArrayTest { + protected: + AddWorkerDataArrayTest() { + array.set(0, 5); + array.set(1, 3); + array.set(2, 7); + + for (uint i = 0; i < 3; i++) { + array.add(i, 1); + } + } + + private: + virtual const char* expected_summary() { + return format_summary(4, 6.0, 8, 4, 18, 3); + } + + virtual const char* expected_details() { + return " 6 4 8\n"; + } +}; + +TEST_VM_F(AddWorkerDataArrayTest, sum_test) { + ASSERT_EQ(18u, array.sum()); +} + +TEST_VM_F(AddWorkerDataArrayTest, average_test) { + ASSERT_NEAR(6.0, array.average(), epsilon); +} + +TEST_VM_F(AddWorkerDataArrayTest, print_summary_on_test) { + ASSERT_STREQ(print_expected_summary(), print_summary()); +} + +TEST_VM_F(AddWorkerDataArrayTest, print_details_on_test) { + ASSERT_STREQ(print_expected_details(), print_details()); +} + +class UninitializedElementWorkerDataArrayTest : public WorkerDataArrayTest { + protected: + UninitializedElementWorkerDataArrayTest() { + array.set(0, 5); + array.set(1, WorkerDataArray::uninitialized()); + array.set(2, 7); + } + + private: + virtual const char* expected_summary() { + return format_summary(5, 6.0, 7, 2, 12, 2); + } + + virtual const char* expected_details() { + return " 5 - 7\n"; + } +}; + +TEST_VM_F(UninitializedElementWorkerDataArrayTest, sum_test) { + ASSERT_EQ(12u, array.sum()); +} + +TEST_VM_F(UninitializedElementWorkerDataArrayTest, average_test) { + ASSERT_NEAR(6.0, array.average(), epsilon); +} + +TEST_VM_F(UninitializedElementWorkerDataArrayTest, print_summary_on_test) { + ASSERT_STREQ(print_expected_summary(), print_summary()); +} + +TEST_VM_F(UninitializedElementWorkerDataArrayTest, print_details_on_test) { + ASSERT_STREQ(print_expected_details(), print_details()); +} + +class UninitializedWorkerDataArrayTest : public WorkerDataArrayTest { + protected: + UninitializedWorkerDataArrayTest() { + array.set(0, WorkerDataArray::uninitialized()); + array.set(1, WorkerDataArray::uninitialized()); + array.set(2, WorkerDataArray::uninitialized()); + } + + private: + virtual const char* expected_summary() { + return " skipped\n"; + } + + virtual const char* expected_details() { + return " - - -\n"; + } +}; + +TEST_VM_F(UninitializedWorkerDataArrayTest, sum_test) { + ASSERT_EQ(0u, array.sum()); +} + +TEST_VM_F(UninitializedWorkerDataArrayTest, average_test) { + ASSERT_NEAR(0.0, array.average(), epsilon); +} + +TEST_VM_F(UninitializedWorkerDataArrayTest, print_summary_on_test) { + ASSERT_STREQ(print_expected_summary(), print_summary()); +} + +TEST_VM_F(UninitializedWorkerDataArrayTest, print_details_on_test) { + ASSERT_STREQ(print_expected_details(), print_details()); +} + +class UninitializedDoubleElementWorkerDataArrayTest : public WorkerDataArrayTest { + protected: + UninitializedDoubleElementWorkerDataArrayTest() { + array.set(0, 5.1 / MILLIUNITS); + array.set(1, WorkerDataArray::uninitialized()); + array.set(2, 7.2 / MILLIUNITS); + } + + private: + virtual const char* expected_summary() { + return format_summary(5.1, 6.1, 7.2, 2.1, 12.3, 2); + } + + virtual const char* expected_details() { + stringStream out; + out.print(" %4.1lf - %4.1lf\n", 5.1, 7.2); + return out.as_string(); + } +}; + +TEST_VM_F(UninitializedDoubleElementWorkerDataArrayTest, sum_test) { + ASSERT_NEAR(12.3 / MILLIUNITS, array.sum(), epsilon); +} + +TEST_VM_F(UninitializedDoubleElementWorkerDataArrayTest, average_test) { + ASSERT_NEAR(6.15 / MILLIUNITS, array.average(), epsilon); +} + +TEST_VM_F(UninitializedDoubleElementWorkerDataArrayTest, print_summary_on_test) { + ASSERT_STREQ(print_expected_summary(), print_summary()); +} + +TEST_VM_F(UninitializedDoubleElementWorkerDataArrayTest, print_details_on_test) { + ASSERT_STREQ(print_expected_details(), print_details()); +}