RFR: 8200697: Add utility for spin wait with fallback to yield/sleep
Kim Barrett
kim.barrett at oracle.com
Mon Apr 9 05:19:59 UTC 2018
> On Apr 4, 2018, at 3:33 PM, Daniel D. Daugherty <daniel.daugherty at oracle.com> wrote:
>
> On 4/4/18 2:53 PM, Kim Barrett wrote:
>> Please review this addition of SpinYield utility class.
>>
>> It initially supplies a very simple policy: spin a configured number
>> of times, then switch to yielding or (eventually) sleeping. Other
>> policies may replace this one or be provided as alternatives in the
>> future.
>>
>> This is joint work with Robbin Ehn.
>>
>> Robbin and I have immediate uses for this utility in changes we are
>> developing. In addition, there are some existing places that might be
>> converted to use this utility (or perhaps some extended version of
>> it), including SafepointSynchronize::begin, ReadStableMark,
>> Thread::SpinAcquire, and ParallelTaskTerminator::offer_termination.
>> Those existing potential uses are not being changed here; for now,
>> we're just adding the utility in support of our in-development
>> changes. We plan to file followup RFEs to consider converting those
>> potential uses.
>>
>> CR:
>> https://bugs.openjdk.java.net/browse/JDK-8200697
>>
>> Webrev:
>> http://cr.openjdk.java.net/~kbarrett/8200697/open.00/
>
> src/hotspot/share/utilities/spinYield.cpp
> L35: _spin_limit(os::is_MP() ? spin_limit : 0),
> Do you want to mention in the .hpp file that spin_limit
> only has meaning when os::is_MP() == true?
Done.
> L45: os::naked_short_sleep(1);
> Hmmm... I have a vague memory of a 10ms lower limit for
> sleeps on at least some versions of Win*. I realize that
> naked_short_sleep() doesn't complain, but does that break
> anything in your assumptions?
I don't think so. The way this sort of thing gets used, a call to
sleep is assumed to delay for "a long time" compared to the typical
delay, which ought to fall well within the spin period. Sleeping
generally means whatever event we're waiting for has missed our
latency goal.
> src/hotspot/share/utilities/spinYield.hpp
> No comments other than whether you want to talk about limitations
> in the .hpp file?
>
> test/hotspot/gtest/utilities/test_spinYield.cpp
> No comments.
>
> Thumbs up.
Thanks.
> Dan
> P.S.
> I think we've still got some spin/yield stuff in Java monitors
> and/or Mutexes so this could probably be used there also...
>
>
>>
>> Testing:
>> Added unit test of basic functionality.
>> Build and hs-tier1 (for gtest) on all Oracle platforms.
More information about the hotspot-dev
mailing list