<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">---------- Forwarded message ---------<br>From: <strong class="gmail_sendername" dir="auto">zhengxianwei</strong> <span dir="auto"><<a href="mailto:baikaishiuc@gmail.com">baikaishiuc@gmail.com</a>></span><br>Date: Sun, May 5, 2024 at 9:34 AM<br>Subject: Re: How can I correctly invoke external methods in the JVM interpreter?<br>To: Andrew Haley <<a href="mailto:aph-open@littlepinkcloud.com">aph-open@littlepinkcloud.com</a>><br></div><br><br><div dir="ltr">Thank you for your reply.<br><br>Yesterday, I analyzed the code and found that when CALL_VM is called, it needs to save and restore the register group, while I assumed that CALL_VM itself included the operation to restore the context. Now it's working fine<br><br><br>> Calls from the interpreter to<br>> native code use the C calling convention<br><br>This is something I really need<br><br>> Also, you must step through the generated code in a debugger<br><br>Yes, you're right. I need to track the generated assembly code. A few days ago, when I was analyzing the issue, I found debugging the JVM with both JDB and GDB to be cumbersome, so I was reluctant to spend time debugging the code. Now it seems I need to re-understand the entire process<br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, May 4, 2024 at 6:09 PM Andrew Haley <<a href="mailto:aph-open@littlepinkcloud.com" target="_blank">aph-open@littlepinkcloud.com</a>> 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">On 5/3/24 14:38, zhengxianwei wrote:<br>
> Could you please tell me what's incorrect about the method I implemented above ?<br>
<br>
Think about register contents. Calls from the interpreter to<br>
native code use the C calling convention, which preserves the<br>
contents of some registers but clobbers others. You need to know<br>
that calling convention, and ensure that anything in use gets<br>
saved when you call native code.<br>
<br>
Also, you must step through the generated code in a debugger.<br>
Then you would see what had gone wrong.<br>
<br>
-- <br>
Andrew Haley  (he/him)<br>
Java Platform Lead Engineer<br>
Red Hat UK Ltd. <<a href="https://www.redhat.com" rel="noreferrer" target="_blank">https://www.redhat.com</a>><br>
<a href="https://keybase.io/andrewhaley" rel="noreferrer" target="_blank">https://keybase.io/andrewhaley</a><br>
EAC8 43EB D3EF DB98 CC77 2FAD A5CD 6035 332F A671<br>
<br>
</blockquote></div>
</div></div>