[prev in list] [next in list] [prev in thread] [next in thread] 

List:       openjdk-serviceability-dev
Subject:    Re: Suggested improvement to X86Frame.getInterpreterFrameBCI
From:       JC Beyler <jcbeyler () google ! com>
Date:       2018-12-12 17:08:33
Message-ID: CAF9BGBxBVPAp1dmYR-AEMGQtwKCNgecWxnowtmuFBTH4VrTUmw () mail ! gmail ! com
[Download RAW message or body]

Hi David,

Thanks for the changes! Your latest patch looks good to me (I think a
follow-up could/might be to go to a builder system for the frame because
the various constructors are a bit confusing but that might be out of scope
of this :-)),
Jc

On Wed, Dec 5, 2018 at 3:10 AM David Griffiths <david.griffiths@gmail.com>
wrote:

> Hi, thanks for reviewing. I have made the changes you suggested and also
> tidied up the constructors a bit (there was already a 4x Address
> constructor), hope that's ok.
>
> Cheers,
>
> David
>
> On Fri, 30 Nov 2018 at 17:06, JC Beyler <jcbeyler@google.com> wrote:
>
>> Hi both,
>>
>> The webrev looks good to me but I could see gains of just adding a new
>> constructor instead of doing a new + set.
>>
>> LinuxAMD64JavaThreadPDAccess.java would become consistent with the rest
>> of the code:
>> +    } else if (VM.getVM().getInterpreter().contains(guesser.getPC())) {
>> +      // pass the value of R13 which contains the bcp for the top level
>> frame
>> +      return new X86Frame(guesser.getSP(), guesser.getFP(),
>> guesser.getPC(),
>> +          context.getRegisterAsAddress(AMD64ThreadContext.R13));
>>      } else {
>>
>> - And for X86Frame.java, that means there is no set method (there isn't a
>> single one yet there so we are consistent there).
>> - Finally, instead of just r13 internally to the Frame, we could just
>> call it the bcp since that is what you are saying it is and then adapt the
>> getInterpreterFrameBCI a bit because a bcp local variable is there :-)
>>
>> But these are nits :),
>> Jc
>>
>> On Fri, Nov 30, 2018 at 6:21 AM Jini George <jini.george@oracle.com>
>> wrote:
>>
>>> Your patch looks good to me, David. I can sponsor this for you if we get
>>> one more review.
>>>
>>> Thanks,
>>> Jini.
>>>
>>> On 11/22/2018 5:42 PM, David Griffiths wrote:
>>> > Thanks Jini, please find patch for Java 9 attached (I don't have
>>> author
>>> > access to the bug itself).
>>> >
>>> > Cheers,
>>> >
>>> > David
>>> >
>>> > On Thu, 22 Nov 2018 at 09:02, Jini George <jini.george@oracle.com
>>> > <mailto:jini.george@oracle.com>> wrote:
>>> >
>>> >     Thank you very much for working on the fix for this issue, David.
>>> It
>>> >     would be great if you can send in a complete patch for the review
>>> (With
>>> >     a first cut look, there seems to be missing pieces).
>>> >
>>> >     I have created a bug for this:
>>> >
>>> >     https://bugs.openjdk.java.net/browse/JDK-8214226
>>> >
>>> >     Thank you,
>>> >     Jini
>>> >
>>> >     On 11/22/2018 12:50 AM, David Griffiths wrote:
>>> >      > PS: should have added a new X86Frame constructor really, may
>>> have
>>> >     just
>>> >      > been put off because there is already a four address
>>> constructor so
>>> >      > would have had to add dummy argument or something.
>>> >      >
>>> >      > On Wed, 21 Nov 2018 at 19:15, David Griffiths
>>> >     <david.griffiths@gmail.com <mailto:david.griffiths@gmail.com>
>>> >      > <mailto:david.griffiths@gmail.com
>>> >     <mailto:david.griffiths@gmail.com>>> wrote:
>>> >      >
>>> >      >     Hi, thanks, apart from adding a setter for R13 in X86Frame,
>>> the
>>> >      >     other half of the fix is this:
>>> >      >
>>> >      >        public    Frame getCurrentFrameGuess(JavaThread thread,
>>> >     Address
>>> >      >     addr) {
>>> >      >          ThreadProxy t = getThreadProxy(addr);
>>> >      >          AMD64ThreadContext context = (AMD64ThreadContext)
>>> >     t.getContext();
>>> >      >          AMD64CurrentFrameGuess guesser = new
>>> >      >     AMD64CurrentFrameGuess(context, thread);
>>> >      >          if (!guesser.run(GUESS_SCAN_RANGE)) {
>>> >      >            return null;
>>> >      >          }
>>> >      >          if (guesser.getPC() == null) {
>>> >      >            return new X86Frame(guesser.getSP(),
>>> guesser.getFP());
>>> >      >          } else if
>>> >     (VM.getVM().getInterpreter().contains(guesser.getPC())) {
>>> >      >            // pass the value of R13 which contains the bcp for
>>> >     the top
>>> >      >     level frame
>>> >      >            Address r13 =
>>> >      >     context.getRegisterAsAddress(AMD64ThreadContext.R13);
>>> >      >            X86Frame frame = new X86Frame(guesser.getSP(),
>>> >      >     guesser.getFP(), guesser.getPC());
>>> >      >            frame.setR13(r13);
>>> >      >            return frame;
>>> >      >          } else {
>>> >      >            return new X86Frame(guesser.getSP(), guesser.getFP(),
>>> >      >     guesser.getPC());
>>> >      >          }
>>> >      >        }
>>> >      >
>>> >      >     (the whole "if pc in interpreter" block is new)
>>> >      >
>>> >      >     Overhead likely to be low as this is only used in diagnostic
>>> >     code.
>>> >      >     Can't think of any risk but I'm not an expert on this code.
>>> >      >
>>> >      >     Cheers,
>>> >      >
>>> >      >     David
>>> >      >
>>> >      >     On Wed, 21 Nov 2018 at 19:01, JC Beyler <
>>> jcbeyler@google.com
>>> >     <mailto:jcbeyler@google.com>
>>> >      >     <mailto:jcbeyler@google.com <mailto:jcbeyler@google.com>>>
>>> wrote:
>>> >      >
>>> >      >         Hi David,
>>> >      >
>>> >      >         I think the easiest would be to see whole change to
>>> >     understand
>>> >      >         the repercussions of the change. I would imagine that
>>> any
>>> >     change
>>> >      >         that helps stacktraces being more precise is a good
>>> thing but
>>> >      >         there are questions that arise every time:
>>> >      >            - What is the overhead of adding this?
>>> >      >            - Does this add any risk of failure?
>>> >      >
>>> >      >         I'd imagine that the change is relatively small and
>>> should be
>>> >      >         easy to assess this but seeing it would make things
>>> easier to
>>> >      >         determine.
>>> >      >
>>> >      >         That being said, I'm not a reviewer for OpenJDK so this
>>> is
>>> >      >         really just my 2cents,
>>> >      >         Jc
>>> >      >
>>> >      >         On Wed, Nov 21, 2018 at 9:17 AM David Griffiths
>>> >      >         <david.griffiths@gmail.com
>>> >     <mailto:david.griffiths@gmail.com> <mailto:
>>> david.griffiths@gmail.com
>>> >     <mailto:david.griffiths@gmail.com>>>
>>> >      >         wrote:
>>> >      >
>>> >      >             Hi, I'm new to this mailing list and working on a
>>> project
>>> >      >             that makes use of the SA classes to get stack traces
>>> >     from a
>>> >      >             paused in flight JVM (we can't use JDWP). I have
>>> observed
>>> >      >             that if the top frame is in the interpreter it
>>> >     reports the
>>> >      >             BCI and line number incorrectly. This is because
>>> >      >             X86Frame.getInterpreterFrameBCI uses the value
>>> stored
>>> >     on the
>>> >      >             stack rather than the actual live value stored in
>>> R13.
>>> >      >
>>> >      >             I have a patch for this which lets
>>> >      >             LinuxAMD64JavaThreadPDAccess.getCurrentFrameGuess
>>> >     pass the
>>> >      >             R13 value to X86Frame so that the latter can then
>>> do:
>>> >      >
>>> >      >                public int getInterpreterFrameBCI() {
>>> >      >                  Address bcp =
>>> >      >             addressOfInterpreterFrameBCX().getAddressAt(0);
>>> >      >                  // If we are in the top level frame then R13
>>> may
>>> >     have
>>> >      >             been set for us which contains
>>> >      >                  // the BCP. If so then let it take priority. If
>>> >     we are
>>> >      >             in a top level interpreter frame,
>>> >      >                  // the BCP is live in R13 (on x86) and not
>>> saved
>>> >     in the
>>> >      >             BCX stack slot.
>>> >      >                  if (r13 != null) {
>>> >      >                      bcp = r13;
>>> >      >                  }
>>> >      >                  Address methodHandle =
>>> >      >             addressOfInterpreterFrameMethod().getAddressAt(0);
>>> >      >
>>> >      >             and this fixes the problem.
>>> >      >
>>> >      >             Does this sound like a good idea and if so should I
>>> >     submit a
>>> >      >             patch?
>>> >      >
>>> >      >             Cheers,
>>> >      >
>>> >      >             David
>>> >      >
>>> >      >
>>> >      >
>>> >      >         --
>>> >      >
>>> >      >         Thanks,
>>> >      >         Jc
>>> >      >
>>> >
>>>
>>
>>
>> --
>>
>> Thanks,
>> Jc
>>
>

-- 

Thanks,
Jc

[Attachment #3 (text/html)]

<div dir="ltr">Hi David,<div><br></div><div>Thanks for the changes! Your latest patch \
looks good to me (I think a follow-up could/might be to go to a builder system for \
the frame because the various constructors are a bit confusing but that might be out \
of scope of this :-)),</div><div>Jc</div></div><br><div class="gmail_quote"><div \
dir="ltr">On Wed, Dec 5, 2018 at 3:10 AM David Griffiths &lt;<a \
href="mailto:david.griffiths@gmail.com">david.griffiths@gmail.com</a>&gt; \
wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px \
0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div \
dir="ltr"><div>Hi, thanks for reviewing. I have made the changes you suggested and \
also tidied up the constructors a bit (there was already a 4x Address constructor), \
hope that&#39;s ok.</div><div><br></div><div>Cheers,</div><div><br></div><div>David<br></div></div><br><div \
class="gmail_quote"><div dir="ltr">On Fri, 30 Nov 2018 at 17:06, JC Beyler &lt;<a \
href="mailto:jcbeyler@google.com" target="_blank">jcbeyler@google.com</a>&gt; \
wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px \
0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div \
dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">Hi \
both,<div><br></div><div>The webrev looks good to me but I could see gains of just \
adding a new constructor instead of doing a new  + \
set.</div><div><br></div><div>LinuxAMD64JavaThreadPDAccess.java would become \
consistent with the rest of the code:<br></div><div><div>+      } else if \
(VM.getVM().getInterpreter().contains(guesser.getPC())) {</div><div>+         // pass \
the value of R13 which contains the bcp for the top level frame</div><div>+         \
return new X86Frame(guesser.getSP(), guesser.getFP(), guesser.getPC(),</div><div>+    \
context.getRegisterAsAddress(AMD64ThreadContext.R13));</div><div>        } else \
{<br></div></div><div><br></div><div>- And for  X86Frame.java, that means there is no \
set method (there isn&#39;t a single one yet there so we are consistent \
there).</div><div>- Finally, instead of just r13 internally to the Frame, we could \
just call it the bcp since that is what you are saying it is and then adapt the \
getInterpreterFrameBCI a bit because a bcp local variable is there \
:-)</div><div><br></div><div>But these are nits \
:),</div><div>Jc</div></div></div></div></div></div><br><div class="gmail_quote"><div \
dir="ltr">On Fri, Nov 30, 2018 at 6:21 AM Jini George &lt;<a \
href="mailto:jini.george@oracle.com" target="_blank">jini.george@oracle.com</a>&gt; \
wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px \
0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Your patch looks good \
to me, David. I can sponsor this for you if we get <br> one more review.<br>
<br>
Thanks,<br>
Jini.<br>
<br>
On 11/22/2018 5:42 PM, David Griffiths wrote:<br>
&gt; Thanks Jini, please find patch for Java 9 attached (I don&#39;t have author <br>
&gt; access to the bug itself).<br>
&gt; <br>
&gt; Cheers,<br>
&gt; <br>
&gt; David<br>
&gt; <br>
&gt; On Thu, 22 Nov 2018 at 09:02, Jini George &lt;<a \
href="mailto:jini.george@oracle.com" target="_blank">jini.george@oracle.com</a> <br> \
&gt; &lt;mailto:<a href="mailto:jini.george@oracle.com" \
target="_blank">jini.george@oracle.com</a>&gt;&gt; wrote:<br> &gt; <br>
&gt;        Thank you very much for working on the fix for this issue, David. It<br>
&gt;        would be great if you can send in a complete patch for the review \
(With<br> &gt;        a first cut look, there seems to be missing pieces).<br>
&gt; <br>
&gt;        I have created a bug for this:<br>
&gt; <br>
&gt;        <a href="https://bugs.openjdk.java.net/browse/JDK-8214226" \
rel="noreferrer" target="_blank">https://bugs.openjdk.java.net/browse/JDK-8214226</a><br>
 &gt; <br>
&gt;        Thank you,<br>
&gt;        Jini<br>
&gt; <br>
&gt;        On 11/22/2018 12:50 AM, David Griffiths wrote:<br>
&gt;         &gt; PS: should have added a new X86Frame constructor really, may \
have<br> &gt;        just<br>
&gt;         &gt; been put off because there is already a four address constructor \
so<br> &gt;         &gt; would have had to add dummy argument or something.<br>
&gt;         &gt;<br>
&gt;         &gt; On Wed, 21 Nov 2018 at 19:15, David Griffiths<br>
&gt;        &lt;<a href="mailto:david.griffiths@gmail.com" \
target="_blank">david.griffiths@gmail.com</a> &lt;mailto:<a \
href="mailto:david.griffiths@gmail.com" \
target="_blank">david.griffiths@gmail.com</a>&gt;<br> &gt;         &gt; &lt;mailto:<a \
href="mailto:david.griffiths@gmail.com" \
target="_blank">david.griffiths@gmail.com</a><br> &gt;        &lt;mailto:<a \
href="mailto:david.griffiths@gmail.com" \
target="_blank">david.griffiths@gmail.com</a>&gt;&gt;&gt; wrote:<br> &gt;         \
&gt;<br> &gt;         &gt;        Hi, thanks, apart from adding a setter for R13 in \
X86Frame, the<br> &gt;         &gt;        other half of the fix is this:<br>
&gt;         &gt;<br>
&gt;         &gt;            public       Frame getCurrentFrameGuess(JavaThread \
thread,<br> &gt;        Address<br>
&gt;         &gt;        addr) {<br>
&gt;         &gt;                ThreadProxy t = getThreadProxy(addr);<br>
&gt;         &gt;                AMD64ThreadContext context = \
(AMD64ThreadContext)<br> &gt;        t.getContext();<br>
&gt;         &gt;                AMD64CurrentFrameGuess guesser = new<br>
&gt;         &gt;        AMD64CurrentFrameGuess(context, thread);<br>
&gt;         &gt;                if (!guesser.run(GUESS_SCAN_RANGE)) {<br>
&gt;         &gt;                    return null;<br>
&gt;         &gt;                }<br>
&gt;         &gt;                if (guesser.getPC() == null) {<br>
&gt;         &gt;                    return new X86Frame(guesser.getSP(), \
guesser.getFP());<br> &gt;         &gt;                } else if<br>
&gt;        (VM.getVM().getInterpreter().contains(guesser.getPC())) {<br>
&gt;         &gt;                    // pass the value of R13 which contains the bcp \
for<br> &gt;        the top<br>
&gt;         &gt;        level frame<br>
&gt;         &gt;                    Address r13 =<br>
&gt;         &gt;        context.getRegisterAsAddress(AMD64ThreadContext.R13);<br>
&gt;         &gt;                    X86Frame frame = new \
X86Frame(guesser.getSP(),<br> &gt;         &gt;        guesser.getFP(), \
guesser.getPC());<br> &gt;         &gt;                    frame.setR13(r13);<br>
&gt;         &gt;                    return frame;<br>
&gt;         &gt;                } else {<br>
&gt;         &gt;                    return new X86Frame(guesser.getSP(), \
guesser.getFP(),<br> &gt;         &gt;        guesser.getPC());<br>
&gt;         &gt;                }<br>
&gt;         &gt;            }<br>
&gt;         &gt;<br>
&gt;         &gt;        (the whole &quot;if pc in interpreter&quot; block is \
new)<br> &gt;         &gt;<br>
&gt;         &gt;        Overhead likely to be low as this is only used in \
diagnostic<br> &gt;        code.<br>
&gt;         &gt;        Can&#39;t think of any risk but I&#39;m not an expert on \
this code.<br> &gt;         &gt;<br>
&gt;         &gt;        Cheers,<br>
&gt;         &gt;<br>
&gt;         &gt;        David<br>
&gt;         &gt;<br>
&gt;         &gt;        On Wed, 21 Nov 2018 at 19:01, JC Beyler &lt;<a \
href="mailto:jcbeyler@google.com" target="_blank">jcbeyler@google.com</a><br> &gt;    \
&lt;mailto:<a href="mailto:jcbeyler@google.com" \
target="_blank">jcbeyler@google.com</a>&gt;<br> &gt;         &gt;        \
&lt;mailto:<a href="mailto:jcbeyler@google.com" \
target="_blank">jcbeyler@google.com</a> &lt;mailto:<a \
href="mailto:jcbeyler@google.com" target="_blank">jcbeyler@google.com</a>&gt;&gt;&gt; \
wrote:<br> &gt;         &gt;<br>
&gt;         &gt;              Hi David,<br>
&gt;         &gt;<br>
&gt;         &gt;              I think the easiest would be to see whole change \
to<br> &gt;        understand<br>
&gt;         &gt;              the repercussions of the change. I would imagine that \
any<br> &gt;        change<br>
&gt;         &gt;              that helps stacktraces being more precise is a good \
thing but<br> &gt;         &gt;              there are questions that arise every \
time:<br> &gt;         &gt;                  - What is the overhead of adding \
this?<br> &gt;         &gt;                  - Does this add any risk of failure?<br>
&gt;         &gt;<br>
&gt;         &gt;              I&#39;d imagine that the change is relatively small \
and should be<br> &gt;         &gt;              easy to assess this but seeing it \
would make things easier to<br> &gt;         &gt;              determine.<br>
&gt;         &gt;<br>
&gt;         &gt;              That being said, I&#39;m not a reviewer for OpenJDK so \
this is<br> &gt;         &gt;              really just my 2cents,<br>
&gt;         &gt;              Jc<br>
&gt;         &gt;<br>
&gt;         &gt;              On Wed, Nov 21, 2018 at 9:17 AM David Griffiths<br>
&gt;         &gt;              &lt;<a href="mailto:david.griffiths@gmail.com" \
target="_blank">david.griffiths@gmail.com</a><br> &gt;        &lt;mailto:<a \
href="mailto:david.griffiths@gmail.com" \
target="_blank">david.griffiths@gmail.com</a>&gt; &lt;mailto:<a \
href="mailto:david.griffiths@gmail.com" \
target="_blank">david.griffiths@gmail.com</a><br> &gt;        &lt;mailto:<a \
href="mailto:david.griffiths@gmail.com" \
target="_blank">david.griffiths@gmail.com</a>&gt;&gt;&gt;<br> &gt;         &gt;       \
wrote:<br> &gt;         &gt;<br>
&gt;         &gt;                    Hi, I&#39;m new to this mailing list and working \
on a project<br> &gt;         &gt;                    that makes use of the SA \
classes to get stack traces<br> &gt;        from a<br>
&gt;         &gt;                    paused in flight JVM (we can&#39;t use JDWP). I \
have observed<br> &gt;         &gt;                    that if the top frame is in \
the interpreter it<br> &gt;        reports the<br>
&gt;         &gt;                    BCI and line number incorrectly. This is \
because<br> &gt;         &gt;                    X86Frame.getInterpreterFrameBCI uses \
the value stored<br> &gt;        on the<br>
&gt;         &gt;                    stack rather than the actual live value stored \
in R13.<br> &gt;         &gt;<br>
&gt;         &gt;                    I have a patch for this which lets<br>
&gt;         &gt;                    \
LinuxAMD64JavaThreadPDAccess.getCurrentFrameGuess<br> &gt;        pass the<br>
&gt;         &gt;                    R13 value to X86Frame so that the latter can \
then do:<br> &gt;         &gt;<br>
&gt;         &gt;                        public int getInterpreterFrameBCI() {<br>
&gt;         &gt;                            Address bcp =<br>
&gt;         &gt;                    \
addressOfInterpreterFrameBCX().getAddressAt(0);<br> &gt;         &gt;                 \
// If we are in the top level frame then R13 may<br> &gt;        have<br>
&gt;         &gt;                    been set for us which contains<br>
&gt;         &gt;                            // the BCP. If so then let it take \
priority. If<br> &gt;        we are<br>
&gt;         &gt;                    in a top level interpreter frame,<br>
&gt;         &gt;                            // the BCP is live in R13 (on x86) and \
not saved<br> &gt;        in the<br>
&gt;         &gt;                    BCX stack slot.<br>
&gt;         &gt;                            if (r13 != null) {<br>
&gt;         &gt;                                    bcp = r13;<br>
&gt;         &gt;                            }<br>
&gt;         &gt;                            Address methodHandle =<br>
&gt;         &gt;                    \
addressOfInterpreterFrameMethod().getAddressAt(0);<br> &gt;         &gt;<br>
&gt;         &gt;                    and this fixes the problem.<br>
&gt;         &gt;<br>
&gt;         &gt;                    Does this sound like a good idea and if so \
should I<br> &gt;        submit a<br>
&gt;         &gt;                    patch?<br>
&gt;         &gt;<br>
&gt;         &gt;                    Cheers,<br>
&gt;         &gt;<br>
&gt;         &gt;                    David<br>
&gt;         &gt;<br>
&gt;         &gt;<br>
&gt;         &gt;<br>
&gt;         &gt;              --<br>
&gt;         &gt;<br>
&gt;         &gt;              Thanks,<br>
&gt;         &gt;              Jc<br>
&gt;         &gt;<br>
&gt; <br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" \
class="gmail-m_-9023471760572052622m_-7540626310054304673gmail_signature"><div \
dir="ltr"><div><br></div>Thanks,<div>Jc</div></div></div> </blockquote></div>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" \
class="gmail_signature"><div \
dir="ltr"><div><br></div>Thanks,<div>Jc</div></div></div>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic