You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@harmony.apache.org by Xiao-Feng Li <xi...@gmail.com> on 2005/09/01 04:55:06 UTC

[arch] voluntary vs. preemptive suspension of Java threads

Thread suspension happens in many situations in JVM, such as for GC,
for java.lang.Thread.suspend(), etc. There are various techniques to
suspend a thread. Basically we can classify them into two categories:
preemptive and voluntary.

The preemptive approach requires the suspender, say a GC thread,
suspend the execution of a target thread asynchronously with IPC
mechanism or OS APIs. If the suspended thread happened to be in a
region of code (Java or native) that could be enumerated, the live
references were collected. This kind of region is called safe-region,
and the suspended point is a safe-point. If the suspended point is not
in safe-region, the thread would be resumed and stopped again until it
ended up in a safe-region randomly or on purpose.

In the other approach that we are now considering, JIT will insert
code that polls a boolean. The boolean can be thread-specific and  is
set true by GC thread or VM if there is a need to prevent the Java
thread's forward progress. The JIT will put the polling code in such
places as back-edges, call sites and method returns. Actually we are
thinking of this mechnism in a more general sense. For example,
green-threads can be implemented in this way for Java threads to
downcall into JVM scheduler.

Does anyone have suggestions/data on better approaches?

Thanks,
xiaofeng

Re: [arch] voluntary vs. preemptive suspension of Java threads

Posted by Rodrigo Kumpera <ku...@gmail.com>.
I was wondering what similarities on-stack replacement of JITed code
have with suspension with code patching.


On 9/9/05, Xiao-Feng Li <xi...@gmail.com> wrote:
> Thanks, Rodrigo and Shudo. ORP had a similar approach as code patching
> previously, which we called "IP hijacking". We found, as you observed,
> it had some difficulties in maintenance and portability. I classified
> this approach into the preemptive category.
> 
> I suspect a given thread suspension algorithm will have different
> performance characteristics depending on processor architecture, and
> garbage collection algorithm as well. It deserves more study. Since
> the two approaches are not much conflicting, I suggest implementing
> voluntary mechanism at first for its cleanness and portability for the
> first few releases of Harmony.
> 
> Thanks,
> xiaofeng
> ==
> Intel Managed Runtime Division
> 
> On 9/1/05, shudo@computer.org <sh...@computer.org> wrote:
> > From: Xiao-Feng Li <xi...@gmail.com>
> >
> > > Thread suspension happens in many situations in JVM, such as for GC,
> > > for java.lang.Thread.suspend(), etc. There are various techniques to
> > > suspend a thread. Basically we can classify them into two categories:
> > > preemptive and voluntary.
> >
> > > The preemptive approach requires the suspender, say a GC thread,
> > > suspend the execution of a target thread asynchronously with IPC
> > > mechanism or OS APIs. If the suspended thread happened to be in a
> > > region of code (Java or native) that could be enumerated, the live
> > > references were collected. This kind of region is called safe-region,
> > > and the suspended point is a safe-point. If the suspended point is not
> > > in safe-region, the thread would be resumed and stopped again until it
> > > ended up in a safe-region randomly or on purpose.
> >
> > Sun's HotSpot VMs patch compiled native code to stop thread at the
> > safe points, on which a stack map is provided. It's smart but prone to
> > causes subtle problems, an engineer working on the VM said.
> >
> >   Kazuyuki Shudo        shudo@computer.org      http://www.shudo.net/
> >
>

Re: [arch] voluntary vs. preemptive suspension of Java threads

Posted by Xiao-Feng Li <xi...@gmail.com>.
Thanks, Rodrigo and Shudo. ORP had a similar approach as code patching
previously, which we called "IP hijacking". We found, as you observed,
it had some difficulties in maintenance and portability. I classified
this approach into the preemptive category.

I suspect a given thread suspension algorithm will have different
performance characteristics depending on processor architecture, and
garbage collection algorithm as well. It deserves more study. Since
the two approaches are not much conflicting, I suggest implementing
voluntary mechanism at first for its cleanness and portability for the
first few releases of Harmony.

Thanks,
xiaofeng
==
Intel Managed Runtime Division
 
On 9/1/05, shudo@computer.org <sh...@computer.org> wrote:
> From: Xiao-Feng Li <xi...@gmail.com>
> 
> > Thread suspension happens in many situations in JVM, such as for GC,
> > for java.lang.Thread.suspend(), etc. There are various techniques to
> > suspend a thread. Basically we can classify them into two categories:
> > preemptive and voluntary.
> 
> > The preemptive approach requires the suspender, say a GC thread,
> > suspend the execution of a target thread asynchronously with IPC
> > mechanism or OS APIs. If the suspended thread happened to be in a
> > region of code (Java or native) that could be enumerated, the live
> > references were collected. This kind of region is called safe-region,
> > and the suspended point is a safe-point. If the suspended point is not
> > in safe-region, the thread would be resumed and stopped again until it
> > ended up in a safe-region randomly or on purpose.
> 
> Sun's HotSpot VMs patch compiled native code to stop thread at the
> safe points, on which a stack map is provided. It's smart but prone to
> causes subtle problems, an engineer working on the VM said.
> 
>   Kazuyuki Shudo        shudo@computer.org      http://www.shudo.net/
>

Re: [arch] voluntary vs. preemptive suspension of Java threads

Posted by sh...@computer.org.
From: Xiao-Feng Li <xi...@gmail.com>

> Thread suspension happens in many situations in JVM, such as for GC,
> for java.lang.Thread.suspend(), etc. There are various techniques to
> suspend a thread. Basically we can classify them into two categories:
> preemptive and voluntary.

> The preemptive approach requires the suspender, say a GC thread,
> suspend the execution of a target thread asynchronously with IPC
> mechanism or OS APIs. If the suspended thread happened to be in a
> region of code (Java or native) that could be enumerated, the live
> references were collected. This kind of region is called safe-region,
> and the suspended point is a safe-point. If the suspended point is not
> in safe-region, the thread would be resumed and stopped again until it
> ended up in a safe-region randomly or on purpose.

Sun's HotSpot VMs patch compiled native code to stop thread at the
safe points, on which a stack map is provided. It's smart but prone to
causes subtle problems, an engineer working on the VM said.

  Kazuyuki Shudo	shudo@computer.org	http://www.shudo.net/

Re: [arch] voluntary vs. preemptive suspension of Java threads

Posted by Rodrigo Kumpera <ku...@gmail.com>.
Some time ago someone on this list pointed to a paper from Sun folks
about this subject.

>From what I remember, they tried the folllowing tecniques:

-Pooling on back-edges and call/return, using ether a boolean flag or
forcing a page-fault at a specific address. They noticed that
page-faulting has a huge latency.

-Dynamic code patching, the thread is stopped and the next reachable
safe-point site is patched to call into the VM instead of following
normal execution. This shown to be very tricky to implement on sparc,
but improves the runtime performance a lot.

Rodrigo

On 8/31/05, Xiao-Feng Li <xi...@gmail.com> wrote:
> Thread suspension happens in many situations in JVM, such as for GC,
> for java.lang.Thread.suspend(), etc. There are various techniques to
> suspend a thread. Basically we can classify them into two categories:
> preemptive and voluntary.
> 
> The preemptive approach requires the suspender, say a GC thread,
> suspend the execution of a target thread asynchronously with IPC
> mechanism or OS APIs. If the suspended thread happened to be in a
> region of code (Java or native) that could be enumerated, the live
> references were collected. This kind of region is called safe-region,
> and the suspended point is a safe-point. If the suspended point is not
> in safe-region, the thread would be resumed and stopped again until it
> ended up in a safe-region randomly or on purpose.
> 
> In the other approach that we are now considering, JIT will insert
> code that polls a boolean. The boolean can be thread-specific and  is
> set true by GC thread or VM if there is a need to prevent the Java
> thread's forward progress. The JIT will put the polling code in such
> places as back-edges, call sites and method returns. Actually we are
> thinking of this mechnism in a more general sense. For example,
> green-threads can be implemented in this way for Java threads to
> downcall into JVM scheduler.
> 
> Does anyone have suggestions/data on better approaches?
> 
> Thanks,
> xiaofeng
>