You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@harmony.apache.org by Fan Bin <fa...@gmail.com> on 2006/08/28 04:50:29 UTC

[drlvm] how does drlvm insert the safe point into a method

Hi, I have a question about jit compiler in drlvm. I want to suspend the thread manually on a particular point. I know that the thread can only be suspended at safe point. I guess the safe point is inserted by jit compiler when it compile the method, but I can't prove it from the source code. So my question is whether it's true that it is the jit compiler which insert the safe point. If it is true, how does it do this?
Thank you for your help.

Re: [drlvm] how does drlvm insert the safe point into a method

Posted by Andrey Chernyshev <a....@gmail.com>.
On 8/28/06, Fan Bin <fa...@gmail.com> wrote:
> Thank you very much for your answer and your bearing my awful english:). and thanks to Egor and Mikhail. Yes, my question is about the safe point in JITed code. Your answer are really helps.
>
> I want to suspend a thread from another thead, not for the reason of GC, but for some other reasons. From your answer, I know that it is JIT who insert the polling code. So I think what should I do is modifying the JIT, insert the polling code at the point I want the suspendee to stop. I'll look for bbp in the source to see some details first. I'll ask if I meet some questions.


If I get it right, you can also try doing this without JIT polling
code modification. The TM module in DRLVM has a "safepoint callback"
mechanism which allows to call a user-defined code at a closest
safepoint. See hythread_set_safepoint_callback() defined in
vm/include/open/hythread_ext.h.

In other words, if you need to stop another thread at a particular
point and execute some code, you can try doing a sequence like this:
    hythread_suspend_other(t)
    hythread_set_safepoint_callback(t, your_callback_func)
    hythread_resume(t)

For example, this scheme is used for implementing j.l.Thread.stop()
method in DRLVM, you can also look at the jthread_exception_stop()
impl code in vm/thread/src/thread_java_basic.c.

The default action at the safepoint is just "do nothing" and wait for
the resume event (typically it will come from the GC after enumeration
is done).

Thanks,
Andrey.


>
> I still have a question to Wedlon: What do you mean that "As far as I know the DRLVM JIT you are looking at does not quite do this yet". Does it mean that the drlvm JIT(Jitrino.JET and OPT) I'm looking at can't insert the polling code, or just JET can't do this?
>
> Many thanks,
> fanbin
>
> ----- Original Message -----
> From: "Weldon Washburn" <we...@gmail.com>
> To: <ha...@incubator.apache.org>
> Sent: Monday, August 28, 2006 12:38 PM
> Subject: Re: [drlvm] how does drlvm insert the safe point into a method
>
>
> > Hi Fan,
> >
> > I think you are asking about safe instruction pointer addresses in
> > JITed code where the JIT is able to enumerate all live references.  If
> > this is the case, it turns out there are lots of subtle interactions
> > between all the pieces of the system.  In otherwords, I can't do
> > justice to the topic in an email.  But I will point you in the right
> > direction.
> >
> > The JIT can insert  polling code at points where it knows it can find
> > all live references on a thread's stack.  When the GC wants a thread
> > to suspend and report its live references, it can set a flag in the
> > thread-local context.  When the JITed code sees the flag set, it will
> > suspend the thread and report the live references. As far as I know
> > the DRLVM JIT you are looking at does not quite do this yet.
> >
> > An incomplete but useful for bringup approach is to let the targetted
> > thread continue executing until it tries to allocate an object.
> > Assuming there is no space available, the thread is vectored into the
> > garbage collector itself.  By design, object allocation sites are
> > places where the JIT can enumerate all live references on the stack.
> >
> > There are other schemes, such as suspending and resuming the targetted
> > thread until the JIT reports it can enumerate.  I won't bore you with
> > the details here.  Let me know if this helps.
> >
> >
> > On 8/27/06, Fan Bin <fa...@gmail.com> wrote:
> >> Hi, I have a question about jit compiler in drlvm. I want to suspend the thread manually on a particular point. I know that the thread can only be suspended at safe point. I guess the safe point is inserted by jit compiler when it compile the method, but I can't prove it from the source code. So my question is whether it's true that it is the jit compiler which insert the safe point. If it is true, how does it do this?
> >> Thank you for your help.
> >>
> >
> >
> > --
> > Weldon Washburn
> > Intel Middleware Products Division
> >
> > ---------------------------------------------------------------------
> > Terms of use : http://incubator.apache.org/harmony/mailing.html
> > To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
> > For additional commands, e-mail: harmony-dev-help@incubator.apache.org
> >


-- 
Andrey Chernyshev
Intel Middleware Products Division

---------------------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
For additional commands, e-mail: harmony-dev-help@incubator.apache.org


Re: [drlvm] how does drlvm insert the safe point into a method

Posted by Weldon Washburn <we...@gmail.com>.
On 8/28/06, Fan Bin <fa...@gmail.com> wrote:
> I still have a question to Wedlon: What do you mean that "As far as I know the DRLVM JIT you are looking at does not quite do this yet". Does it mean that the drlvm JIT(Jitrino.JET and OPT) I'm looking at can't insert the polling code, or just JET can't do this?
>

What I really mean is that I have not looked at Jitrino code recently.
 Please see Mikhail Fursov's answer.  It looks like Jitrino might have
what you need.  You may want to also look in Harmony JIRA.  Feel free
to continue to ask questions.

> Many thanks,
> fanbin
>
> ----- Original Message -----
> From: "Weldon Washburn" <we...@gmail.com>
> To: <ha...@incubator.apache.org>
> Sent: Monday, August 28, 2006 12:38 PM
> Subject: Re: [drlvm] how does drlvm insert the safe point into a method
>
>
> > Hi Fan,
> >
> > I think you are asking about safe instruction pointer addresses in
> > JITed code where the JIT is able to enumerate all live references.  If
> > this is the case, it turns out there are lots of subtle interactions
> > between all the pieces of the system.  In otherwords, I can't do
> > justice to the topic in an email.  But I will point you in the right
> > direction.
> >
> > The JIT can insert  polling code at points where it knows it can find
> > all live references on a thread's stack.  When the GC wants a thread
> > to suspend and report its live references, it can set a flag in the
> > thread-local context.  When the JITed code sees the flag set, it will
> > suspend the thread and report the live references. As far as I know
> > the DRLVM JIT you are looking at does not quite do this yet.
> >
> > An incomplete but useful for bringup approach is to let the targetted
> > thread continue executing until it tries to allocate an object.
> > Assuming there is no space available, the thread is vectored into the
> > garbage collector itself.  By design, object allocation sites are
> > places where the JIT can enumerate all live references on the stack.
> >
> > There are other schemes, such as suspending and resuming the targetted
> > thread until the JIT reports it can enumerate.  I won't bore you with
> > the details here.  Let me know if this helps.
> >
> >
> > On 8/27/06, Fan Bin <fa...@gmail.com> wrote:
> >> Hi, I have a question about jit compiler in drlvm. I want to suspend the thread manually on a particular point. I know that the thread can only be suspended at safe point. I guess the safe point is inserted by jit compiler when it compile the method, but I can't prove it from the source code. So my question is whether it's true that it is the jit compiler which insert the safe point. If it is true, how does it do this?
> >> Thank you for your help.
> >>
> >
> >
> > --
> > Weldon Washburn
> > Intel Middleware Products Division
> >
> > ---------------------------------------------------------------------
> > Terms of use : http://incubator.apache.org/harmony/mailing.html
> > To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
> > For additional commands, e-mail: harmony-dev-help@incubator.apache.org
> >


-- 
Weldon Washburn
Intel Middleware Products Division

---------------------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
For additional commands, e-mail: harmony-dev-help@incubator.apache.org


Re: [drlvm] how does drlvm insert the safe point into a method

Posted by Fan Bin <fa...@gmail.com>.
Thank you very much for your answer and your bearing my awful english:). and thanks to Egor and Mikhail. Yes, my question is about the safe point in JITed code. Your answer are really helps. 

I want to suspend a thread from another thead, not for the reason of GC, but for some other reasons. From your answer, I know that it is JIT who insert the polling code. So I think what should I do is modifying the JIT, insert the polling code at the point I want the suspendee to stop. I'll look for bbp in the source to see some details first. I'll ask if I meet some questions.

I still have a question to Wedlon: What do you mean that "As far as I know the DRLVM JIT you are looking at does not quite do this yet". Does it mean that the drlvm JIT(Jitrino.JET and OPT) I'm looking at can't insert the polling code, or just JET can't do this?

Many thanks, 
fanbin

----- Original Message ----- 
From: "Weldon Washburn" <we...@gmail.com>
To: <ha...@incubator.apache.org>
Sent: Monday, August 28, 2006 12:38 PM
Subject: Re: [drlvm] how does drlvm insert the safe point into a method


> Hi Fan,
> 
> I think you are asking about safe instruction pointer addresses in
> JITed code where the JIT is able to enumerate all live references.  If
> this is the case, it turns out there are lots of subtle interactions
> between all the pieces of the system.  In otherwords, I can't do
> justice to the topic in an email.  But I will point you in the right
> direction.
> 
> The JIT can insert  polling code at points where it knows it can find
> all live references on a thread's stack.  When the GC wants a thread
> to suspend and report its live references, it can set a flag in the
> thread-local context.  When the JITed code sees the flag set, it will
> suspend the thread and report the live references. As far as I know
> the DRLVM JIT you are looking at does not quite do this yet.
> 
> An incomplete but useful for bringup approach is to let the targetted
> thread continue executing until it tries to allocate an object.
> Assuming there is no space available, the thread is vectored into the
> garbage collector itself.  By design, object allocation sites are
> places where the JIT can enumerate all live references on the stack.
> 
> There are other schemes, such as suspending and resuming the targetted
> thread until the JIT reports it can enumerate.  I won't bore you with
> the details here.  Let me know if this helps.
> 
> 
> On 8/27/06, Fan Bin <fa...@gmail.com> wrote:
>> Hi, I have a question about jit compiler in drlvm. I want to suspend the thread manually on a particular point. I know that the thread can only be suspended at safe point. I guess the safe point is inserted by jit compiler when it compile the method, but I can't prove it from the source code. So my question is whether it's true that it is the jit compiler which insert the safe point. If it is true, how does it do this?
>> Thank you for your help.
>>
> 
> 
> -- 
> Weldon Washburn
> Intel Middleware Products Division
> 
> ---------------------------------------------------------------------
> Terms of use : http://incubator.apache.org/harmony/mailing.html
> To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
> For additional commands, e-mail: harmony-dev-help@incubator.apache.org
>

Re: [drlvm] how does drlvm insert the safe point into a method

Posted by Mikhail Fursov <mi...@gmail.com>.
On 8/28/06, Weldon Washburn <we...@gmail.com> wrote:
>
> When the JITed code sees the flag set, it will
> suspend the thread and report the live references. As far as I know
> the DRLVM JIT you are looking at does not quite do this yet.
>

Weldon, AFAIK both DRLVM JITs: Jitrino.JET & Jitrino.OPT do back branch
polling.
In other words once JIT founds a method or a loop without any
VM-helper-calls (that are suspension points) it inserts special code (look
for "back branch polling or bbp" in sources), checks TLS flag (with a helper
call or directly)  and calls VM helper to suspend the thread if needed.
All thread suspensions points are enumeration points from GC's point of
view.

Also I know that Jitrino.OPT BBP (back-branch-polling) algorithm could be
optimized to avoid insertion of BBP checking code in to the finite loops. I
hope we will back to this problem because solving it we get a real percents
in performance.


-- 
Mikhail Fursov

Re: [drlvm] how does drlvm insert the safe point into a method

Posted by Weldon Washburn <we...@gmail.com>.
Hi Fan,

I think you are asking about safe instruction pointer addresses in
JITed code where the JIT is able to enumerate all live references.  If
this is the case, it turns out there are lots of subtle interactions
between all the pieces of the system.  In otherwords, I can't do
justice to the topic in an email.  But I will point you in the right
direction.

The JIT can insert  polling code at points where it knows it can find
all live references on a thread's stack.  When the GC wants a thread
to suspend and report its live references, it can set a flag in the
thread-local context.  When the JITed code sees the flag set, it will
suspend the thread and report the live references. As far as I know
the DRLVM JIT you are looking at does not quite do this yet.

An incomplete but useful for bringup approach is to let the targetted
thread continue executing until it tries to allocate an object.
Assuming there is no space available, the thread is vectored into the
garbage collector itself.  By design, object allocation sites are
places where the JIT can enumerate all live references on the stack.

There are other schemes, such as suspending and resuming the targetted
thread until the JIT reports it can enumerate.  I won't bore you with
the details here.  Let me know if this helps.


On 8/27/06, Fan Bin <fa...@gmail.com> wrote:
> Hi, I have a question about jit compiler in drlvm. I want to suspend the thread manually on a particular point. I know that the thread can only be suspended at safe point. I guess the safe point is inserted by jit compiler when it compile the method, but I can't prove it from the source code. So my question is whether it's true that it is the jit compiler which insert the safe point. If it is true, how does it do this?
> Thank you for your help.
>


-- 
Weldon Washburn
Intel Middleware Products Division

---------------------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
For additional commands, e-mail: harmony-dev-help@incubator.apache.org


Re: [drlvm] how does drlvm insert the safe point into a method

Posted by Egor Pasko <eg...@gmail.com>.
On the 0x1D3 day of Apache Harmony Fan Bin wrote:
> Hi, I have a question about jit compiler in drlvm. I want to suspend
> the thread manually on a particular point. I know that the thread
> can only be suspended at safe point. I guess the safe point is
> inserted by jit compiler when it compile the method, but I can't
> prove it from the source code. So my question is whether it's true
> that it is the jit compiler which insert the safe point. If it is
> true, how does it do this?  Thank you for your help.

Hi, Fan Bin,

Weldon's story is great! But I wonder.. do you need to suspend a
thread from within itself or from another thread? 

For the first case you can do almost the same thing as insertion of
Object.wait() does. Suspending from another thread happens just like
during GC enumeration from Weldon's message (a flag in 'thread local
storage' is checked via a special 'VM helper' call inserted by JIT).

Call for more details if you need to.

-- 
Egor Pasko, Intel Managed Runtime Division


---------------------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
For additional commands, e-mail: harmony-dev-help@incubator.apache.org