/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* 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 "oops/oop.inline.hpp"
#include "utilities/stack.inline.hpp"
#include "utilities/taskqueue.hpp"
#ifdef TARGET_OS_FAMILY_linux
# include "thread_linux.inline.hpp"
#endif
#ifdef TARGET_OS_FAMILY_solaris
# include "thread_solaris.inline.hpp"
#endif
#ifdef TARGET_OS_FAMILY_windows
# include "thread_windows.inline.hpp"
#endif
#ifdef TARGET_OS_FAMILY_bsd
# include "thread_bsd.inline.hpp"
#endif
#ifdef TRACESPINNING
#endif
#if TASKQUEUE_STATS
"qpush", "qpop", "qpop-s", "qattempt", "qsteal", "opush", "omax"
};
{
for (unsigned int i = 0; i < last_stat_id; ++i) {
}
return *this;
}
unsigned int width)
{
// Use a width w: 1 <= w <= max_width
if (line == 0) { // spaces equal in width to the header
for (unsigned int i = 1; i < last_stat_id; ++i) {
}
dashes[w] = '\0';
for (unsigned int i = 1; i < last_stat_id; ++i) {
}
}
}
{
for (unsigned int i = 1; i < last_stat_id; ++i) {
}
}
#ifdef ASSERT
// Invariants which should hold after a TaskQueue has been emptied and is
// quiescent; they do not hold at arbitrary times.
{
}
#endif // ASSERT
#endif // TASKQUEUE_STATS
const int a = 16807;
const int m = 2147483647;
const int q = 127773; /* m div a */
const int r = 2836; /* m mod a */
if (test > 0)
else
return seed;
}
_offered_termination(0) {}
return _queue_set->peek();
}
}
}
bool
uint yield_count = 0;
// Number of hard spin loops done since last yield
uint hard_spin_count = 0;
// Number of iterations in the hard spin loop.
// If WorkStealingSpinToYieldRatio is 0, no hard spinning is done.
// If it is greater than 0, then start with a small number
// of spins and increase number with each turn at spinning until
// the count of hard spins exceeds WorkStealingSpinToYieldRatio.
// Then do a yield() call and start spinning afresh.
if (WorkStealingSpinToYieldRatio > 0) {
}
// Remember the initial spin limit.
// Loop waiting for all threads to offer termination or
// more work.
while (true) {
// Are all threads offering termination?
if (_offered_termination == _n_threads) {
return true;
} else {
// Look for more work.
// Periodically sleep() instead of yield() to give threads
// waiting on the cores the chance to grab this code
if (yield_count <= WorkStealingYieldsBeforeSleep) {
// Do a yield or hardspin. For purposes of deciding whether
// to sleep, count this as a yield.
yield_count++;
// Periodically call yield() instead spinning
// After WorkStealingSpinToYieldRatio spins, do a yield() call
// and reset the counts and starting limit.
yield();
hard_spin_count = 0;
#ifdef TRACESPINNING
#endif
} else {
// Hard spin this time
// Increase the hard spinning period but only up to a limit.
for (uint j = 0; j < hard_spin_limit; j++) {
SpinPause();
}
#ifdef TRACESPINNING
_total_spins++;
#endif
}
} else {
if (PrintGCDetails && Verbose) {
"thread %d sleeps after %d yields",
}
yield_count = 0;
// A sleep will cause this processor to seek work on another processor's
// runqueue, if it has nothing else to run (as opposed to the yield
// which may only move the thread to the end of the this processor's
// runqueue).
}
#ifdef TRACESPINNING
_total_peeks++;
#endif
if (peek_in_queue_set() ||
return false;
}
}
}
}
#ifdef TRACESPINNING
"Total spins: %lld Total peeks: %lld",
total_yields(),
total_spins(),
total_peeks());
}
#endif
if (_offered_termination != 0) {
"Terminator may still be in use");
_offered_termination = 0;
}
}
#ifdef ASSERT
}
#endif // ASSERT
}