Is it possible to stop a specific application thread?

Keith Chapman keithgchapman at gmail.com
Mon Nov 11 17:16:09 PST 2013


Hi David,

On Mon, Nov 11, 2013 at 7:26 PM, David Holmes <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.


>
> 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?

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


More information about the hotspot-dev mailing list