Is it possible to stop a specific application thread?

David Holmes david.holmes at oracle.com
Wed Nov 20 12:49:23 PST 2013


On 21/11/2013 2:16 AM, Lindenmaier, Goetz wrote:
> Hi,
>
> I prepared a webrev for our implementation of loading the poll address from
> the thread.
> http://cr.openjdk.java.net/~goetz/webrevs/loadpolladrfromthrd/
> This applies to hotspot-main.
>
> This feature is only implemented for the C2 compiler, C1 adaptions are missing.
> So you have to set -XX:-TieredCompilation to test it. Else the VM crashes on
> the first safepoint poll in C1-compiled code.
> The feature in on per default, you can switch it off by setting
> -XX:-LoadPollAddressFromThread
>
> For more details, see the comment in the webrev.
>
> If you want to submit this to hotspot, I can open a bug and send a proper
> RFR.  Which would be the appropriate mailing list? Hotspot-rt?
> I can not push it to JPRT, though.

This is not suitable for pushing to OpenJDK at this time. It would need 
to be complete, and the feature would also need a JEP in my opinion.

David
-----

> I would be happy if somebody contributes the adaptions for C1.
>
> Best regards,
>    Goetz.
>
>
>
> From: Keith Chapman [mailto:keithgchapman at gmail.com]
> Sent: Dienstag, 12. November 2013 14:27
> To: Lindenmaier, Goetz
> Cc: hotspot-dev at openjdk.java.net
> Subject: Re: Is it possible to stop a specific application thread?
>
>
>
> On Tue, Nov 12, 2013 at 3:24 AM, Lindenmaier, Goetz <goetz.lindenmaier at sap.com<mailto:goetz.lindenmaier at sap.com>> wrote:
> Hi,
>
> our VM is running with what we call PerThreadSafepoints for a long time.
>
> We implement this by loading the page from the thread as you propose.
> But we don't have a page per thread, as poisoning them seems to costly
> if there are many threads and all threads must be stopped.
>
> Instead, we adapt the field in the thread: usually it points to some
> valid address.  If a safepoint is required, the polling page is written
> into that field.
>
> We implemented this when we tried to improve BiasedLocking,
> but as we could not gain anything, we don't really use it any more.
>
> If you really have interest in this feature, I can prepare a webrev
> for it.
>
> That would be awesome.
>
>
> Best regards,
>    Goetz.
>
> -----Original Message-----
> From: hotspot-dev-bounces at openjdk.java.net<mailto:hotspot-dev-bounces at openjdk.java.net> [mailto:hotspot-dev-bounces at openjdk.java.net<mailto:hotspot-dev-bounces at openjdk.java.net>] On Behalf Of Keith McGuigan
> Sent: Dienstag, 12. November 2013 06:46
> To: David Holmes
> Cc: hotspot-dev at openjdk.java.net<mailto:hotspot-dev at openjdk.java.net>
> Subject: Re: Is it possible to stop a specific application thread?
>
> I had a prototype at one point that did #2, but I don't have the source for
> it anymore. If Karen or Coleen kept a copy of my workspace, perhaps they
> can reply with the diffs to give someone a leg up in doing this again.
>
> --
> - Keith (McGuigan)
>
> On Monday, November 11, 2013, David Holmes wrote:
>
>> On 12/11/2013 11:16 AM, Keith Chapman wrote:
>>
>>> Hi David,
>>>
>>> On Mon, Nov 11, 2013 at 7:26 PM, David Holmes <david.holmes at oracle.com<mailto:david.holmes at oracle.com>
>>> <mailto:david.holmes at oracle.com<mailto:david.holmes at oracle.com>>> wrote:
>>>
>>>      Hi Keith,
>>>
>>>
>>>      On 12/11/2013 6:29 AM, Keith Chapman wrote:
>>>
>>>          Hi,
>>>
>>>          I'm playing around with some research ideas on hotspot.
>>>
>>>          One of my runtime services of the VM needs to stop a specific
>>>          application
>>>          thread (I have a handle to the pthread of the application
>>>          thread). How can
>>>          the VM stop such a thread? Is there any mechanism in place to do
>>>          this?
>>>
>>>
>>>      There is no general purpose mechanism currently in place.
>>>
>>>
>>> Thats a bummer, having such a mechanism would have been useful for
>>> numerous VM services like biased locking revocation, concurrent GC.
>>>
>>
>> For which safepoints are generally used so a per-thread safepoint
>> mechanism is what you are looking for.
>>
>>
>>>      You could use the deprecated and inherently dangerous Thread.suspend
>>>      mechanism (either directly or via the JVMTI suspension interface).
>>>
>>>      Or if you are more adventurous with your VM hacking you could
>>>      introduce a per-thread safepoint operation to cause it to stop.
>>>
>>>
>>> I actually thought about that and explored the way safepoints are
>>> implemented. The place that I had most trouble was getting threads
>>> running compiled code to stop. The way it currently works is by
>>> allocating a polling page (at startup) and drilling in that address into
>>> the compiled code. Hence i I am to do it per thread I would have to make
>>> a call to the runtime to get the address of the polling page for that
>>> particular thread. I presume this would be too expensive (Making a VM
>>> call at the end of each method and through some loop iterations).
>>>
>>> Is there any insight you could offer on how this could be done?
>>>
>>
>> Two basic options I can think of:
>>
>> 1. Use a single shared page and have other threads simply ignore the
>> safepoint request. This might incur some overhead as not-wanted threads
>> could hit this multiple times.
>>
>> 2. Use a per-thread page accessed via the current thread. There would be a
>> little overhead for the indirection but the compiler knows how to access
>> the current JavaThread object. No need for runtime calls that I can see.
>>
>> Good luck.
>>
>> David
>>
>>   Thanks,
>>> Keith.
>>>
>>>      Or you could hack in a special "magic exception" type the processing
>>>      of which simply blocks the thread until "resumed" somehow (not sure
>>>      how ??). Or ...
>>>
>>>      Cheers,
>>>      David
>>>
>>>          Thanks,
>>>          Keith.
>>>
>>>
>>>
>>>
>>> --
>>>
>>> Keith Chapman
>>> blog: http://www.keith-chapman.org
>>>
>>
>
>
>
> --
>
> Keith Chapman
> blog: http://www.keith-chapman.org
>


More information about the hotspot-dev mailing list