8047714: Fix for JDK-6546236 made Solaris os::yield() a no-op

Reviewed-by: hseigel, lfoltan
This commit is contained in:
Frederic Parain 2014-07-08 08:04:06 -07:00
parent 4f7e4160a0
commit 5a8cc5f33d
15 changed files with 23 additions and 47 deletions

View File

@ -2808,12 +2808,10 @@ bool os::dont_yield() {
return DontYieldALot;
}
void os::yield() {
void os::naked_yield() {
sched_yield();
}
os::YieldResult os::NakedYield() { sched_yield(); return os::YIELD_UNKNOWN; }
////////////////////////////////////////////////////////////////////////////////
// thread priority support
@ -3070,7 +3068,7 @@ static bool do_suspend(OSThread* osthread) {
for (int n = 0; !osthread->sr.is_suspended(); n++) {
for (int i = 0; i < RANDOMLY_LARGE_INTEGER2 && !osthread->sr.is_suspended(); i++) {
os::yield();
os::naked_yield();
}
// timeout, try to cancel the request
@ -3104,7 +3102,7 @@ static void do_resume(OSThread* osthread) {
if (sr_notify(osthread) == 0) {
for (int n = 0; n < RANDOMLY_LARGE_INTEGER && !osthread->sr.is_running(); n++) {
for (int i = 0; i < 100 && !osthread->sr.is_running(); i++) {
os::yield();
os::naked_yield();
}
}
} else {

View File

@ -2596,12 +2596,10 @@ bool os::dont_yield() {
return DontYieldALot;
}
void os::yield() {
void os::naked_yield() {
sched_yield();
}
os::YieldResult os::NakedYield() { sched_yield(); return os::YIELD_UNKNOWN; }
////////////////////////////////////////////////////////////////////////////////
// thread priority support

View File

@ -3791,12 +3791,10 @@ bool os::dont_yield() {
return DontYieldALot;
}
void os::yield() {
void os::naked_yield() {
sched_yield();
}
os::YieldResult os::NakedYield() { sched_yield(); return os::YIELD_UNKNOWN; }
////////////////////////////////////////////////////////////////////////////////
// thread priority support

View File

@ -3173,20 +3173,14 @@ bool os::dont_yield() {
}
}
// Caveat: Solaris os::yield() causes a thread-state transition whereas
// the linux and win32 implementations do not. This should be checked.
void os::yield() {
// Yields to all threads with same or greater priority
os::sleep(Thread::current(), 0, false);
}
// Note that yield semantics are defined by the scheduling class to which
// the thread currently belongs. Typically, yield will _not yield to
// other equal or higher priority threads that reside on the dispatch queues
// of other CPUs.
os::YieldResult os::NakedYield() { thr_yield(); return os::YIELD_UNKNOWN; }
void os::naked_yield() {
thr_yield();
}
// Interface for setting lwp priorities. If we are using T2 libthread,
// which forces the use of BoundThreads or we manually set UseBoundThreads,

View File

@ -3515,19 +3515,16 @@ void os::infinite_sleep() {
typedef BOOL (WINAPI * STTSignature)(void);
os::YieldResult os::NakedYield() {
void os::naked_yield() {
// Use either SwitchToThread() or Sleep(0)
// Consider passing back the return value from SwitchToThread().
if (os::Kernel32Dll::SwitchToThreadAvailable()) {
return SwitchToThread() ? os::YIELD_SWITCHED : os::YIELD_NONEREADY;
SwitchToThread();
} else {
Sleep(0);
}
return os::YIELD_UNKNOWN;
}
void os::yield() { os::NakedYield(); }
// Win32 only gives you access to seven real priorities at a time,
// so we compress Java's ten down to seven. It would be better
// if we dynamically adjusted relative priorities.

View File

@ -1048,7 +1048,7 @@ CompilerThread* CompileBroker::make_compiler_thread(const char* name, CompileQue
}
// Let go of Threads_lock before yielding
os::yield(); // make sure that the compiler thread is started early (especially helpful on SOLARIS)
os::naked_yield(); // make sure that the compiler thread is started early (especially helpful on SOLARIS)
return compiler_thread;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2014, 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
@ -134,7 +134,7 @@ SurrogateLockerThread* SurrogateLockerThread::make(TRAPS) {
Threads::add(res);
Thread::start(res);
}
os::yield(); // This seems to help with initial start-up of SLT
os::naked_yield(); // This seems to help with initial start-up of SLT
return res;
}

View File

@ -3325,7 +3325,7 @@ static bool initializeDirectBufferSupport(JNIEnv* env, JavaThread* thread) {
directBufferSupportInitializeEnded = 1;
} else {
while (!directBufferSupportInitializeEnded && !directBufferSupportInitializeFailed) {
os::yield();
os::naked_yield();
}
}

View File

@ -3042,7 +3042,7 @@ JVM_ENTRY(void, JVM_Yield(JNIEnv *env, jclass threadClass))
if (ConvertYieldToSleep) {
os::sleep(thread, MinSleepInterval, false);
} else {
os::yield();
os::naked_yield();
}
JVM_END
@ -3072,7 +3072,7 @@ JVM_ENTRY(void, JVM_Sleep(JNIEnv* env, jclass threadClass, jlong millis))
// It appears that in certain GUI contexts, it may be beneficial to do a short sleep
// for SOLARIS
if (ConvertSleepToYield) {
os::yield();
os::naked_yield();
} else {
ThreadState old_state = thread->osthread()->get_state();
thread->osthread()->set_state(SLEEPING);

View File

@ -442,16 +442,7 @@ class os: AllStatic {
// ms = 0, will sleep for the least amount of time allowed by the OS.
static void naked_short_sleep(jlong ms);
static void infinite_sleep(); // never returns, use with CAUTION
static void yield(); // Yields to all threads with same priority
enum YieldResult {
YIELD_SWITCHED = 1, // caller descheduled, other ready threads exist & ran
YIELD_NONEREADY = 0, // No other runnable/ready threads.
// platform-specific yield return immediately
YIELD_UNKNOWN = -1 // Unknown: platform doesn't support _SWITCHED or _NONEREADY
// YIELD_SWITCHED and YIELD_NONREADY imply the platform supports a "strong"
// yield that can be used in lieu of blocking.
} ;
static YieldResult NakedYield () ;
static void naked_yield () ;
static OSReturn set_priority(Thread* thread, ThreadPriority priority);
static OSReturn get_priority(const Thread* const thread, ThreadPriority& priority);

View File

@ -322,7 +322,7 @@ void SafepointSynchronize::begin() {
SpinPause() ; // MP-Polite spin
} else
if (steps < DeferThrSuspendLoopCount) {
os::NakedYield() ;
os::naked_yield() ;
} else {
os::naked_short_sleep(1);
}

View File

@ -449,7 +449,7 @@ static markOop ReadStableMark (oop obj) {
++its;
if (its > 10000 || !os::is_MP()) {
if (its & 1) {
os::NakedYield();
os::naked_yield();
TEVENT(Inflate: INFLATING - yield);
} else {
// Note that the following code attenuates the livelock problem but is not
@ -479,7 +479,7 @@ static markOop ReadStableMark (oop obj) {
if ((YieldThenBlock++) >= 16) {
Thread::current()->_ParkEvent->park(1);
} else {
os::NakedYield();
os::naked_yield();
}
}
Thread::muxRelease(InflationLocks + ix);

View File

@ -4374,7 +4374,7 @@ void Thread::SpinAcquire (volatile int * adr, const char * LockName) {
if (Yields > 5) {
os::naked_short_sleep(1);
} else {
os::NakedYield();
os::naked_yield();
++Yields;
}
} else {

View File

@ -484,7 +484,7 @@ class MemTracker : AllStatic {
// as short sleep.
os::naked_short_sleep(1);
#else
os::NakedYield();
os::naked_yield();
#endif
}
}

View File

@ -142,7 +142,7 @@ bool ParallelTaskTerminator::peek_in_queue_set() {
void ParallelTaskTerminator::yield() {
assert(_offered_termination <= _n_threads, "Invariant");
os::yield();
os::naked_yield();
}
void ParallelTaskTerminator::sleep(uint millis) {