[jmm-dev] VarHandle.safepoint() methods

Andrew Haley aph at redhat.com
Fri Jan 6 09:42:44 UTC 2017


On 05/01/17 20:57, David Holmes wrote:
> <trimming>
> 
> On 5/01/2017 11:49 PM, Andrew Haley wrote:
>> On 05/01/17 13:03, David Holmes wrote:
>>>> Sure.  I was thinking of a version of VarHandle.safepoint() which took a
>>>> timeout: if a safepoint didn't arrive after N seconds, force one.
>>>
>>> I'd be interested to hear what mechanism you envisage for waiting for,
>>> and detecting, that a safepoint has arrived.
>>
>> I'm a bit bewildered by this question.  When a thread is safepointed
>> it gets told by the VM to safepoint.  All it has to do is wait for that
>> to happen.  Why does that matter anyway?
> 
> Taking a thread to a safe-point is a side-effect of its execution, 
> imposed on it by the VM. You now want to add an API that is something 
> like waitForsafepoint() and my question is how would you implement that? 
>
> As we previously mentioned you might do something simplistic like a 
> polling sleep with some kind of check of a safepoint count, and as soon 
> as we see an updated count we know a safepoint has occurred. But that is 
> a bit crude/inefficient and I was wondering if you had considered a more 
> explicit mechanism?

I've considered it.  The simplest implementation would be a condition
variable with a timeout: the safepoint mechanism wakes any waiting
threads.  This provides for an implementation which forces a safepoint
if one hasn't happened in a reasonable period.

Andrew.



More information about the jmm-dev mailing list