<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="Generator" content="Microsoft Word 15 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:Aptos;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
font-size:12.0pt;
font-family:Aptos;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
p.xmsonormal, li.xmsonormal, div.xmsonormal
{mso-style-name:x_msonormal;
margin:0in;
font-size:10.0pt;
font-family:"Calibri",sans-serif;}
span.EmailStyle21
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style></head><body lang="EN-US" link="blue" vlink="purple" style="word-wrap:break-word"><div class="WordSection1"><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">Oh I see – I should have changed the exception handler range to 17-33. This relates to my problem adding new labels that Chen has addressed in another thread.</span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> </span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">Thanks</span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> </span></p><div><div style="border:none;border-top:solid #e1e1e1 1.0pt;padding:3.0pt 0in 0in 0in"><p class="MsoNormal"><b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> classfile-api-dev <<a href="mailto:classfile-api-dev-retn@openjdk.org">classfile-api-dev-retn@openjdk.org</a>> <b>On Behalf Of </b>Adam Sotona<br><b>Sent:</b> Wednesday, January 29, 2025 10:02 AM<br><b>To:</b> Chen Liang <<a href="mailto:chen.l.liang@oracle.com">chen.l.liang@oracle.com</a>>; <a href="mailto:classfile-api-dev@openjdk.org">classfile-api-dev@openjdk.org</a><br><b>Subject:</b> Re: [External] : RE: StackMap problem</span></p></div></div><p class="MsoNormal"> </p><p class="MsoNormal"><span style="font-size:11.0pt">I see what happened here. The transformed method is invalid because the istore_1 is injected into the try block and consumed outside.</span></p><p class="MsoNormal"><span style="font-size:11.0pt">As I used CodeTransform::atStart to inject the istore_1 – I injected it before the try block and stack maps are valid.</span></p><p class="MsoNormal"><span style="font-size:11.0pt"> </span></p><p class="MsoNormal"><span style="font-size:11.0pt">It is not guaranteed Class-File API will always fail eagerly when generating stack maps for invalid bytecode. ClassFile::verify is recommended to verify the generated class file is valid.</span></p><p class="MsoNormal"><span style="font-size:11.0pt"> </span></p><p class="MsoNormal"><span style="font-size:11.0pt">Your instrumentation should inject code introducing new locals before any try block (if consumed outside of the try block). Otherwise valid stack maps are unable to compute.</span></p><p class="MsoNormal"><span style="font-size:11.0pt"> </span></p><p class="MsoNormal"><span style="font-size:11.0pt">Adam </span></p><p class="MsoNormal"><span style="font-size:11.0pt"> </span></p><div id="mail-editor-reference-message-container"><div><div><div style="border:none;border-top:solid #b5c4df 1.0pt;padding:3.0pt 0in 0in 0in"><p class="MsoNormal" style="margin-bottom:12.0pt"><b><span style="color:black">From: </span></b><span style="color:black">Chen Liang <<a href="mailto:chen.l.liang@oracle.com">chen.l.liang@oracle.com</a>><br><b>Date: </b>Wednesday, 29 January 2025 at 18:44<br><b>To: </b>Adam Sotona <<a href="mailto:adam.sotona@oracle.com">adam.sotona@oracle.com</a>>, <a href="mailto:classfile-api-dev@openjdk.org">classfile-api-dev@openjdk.org</a> <<a href="mailto:classfile-api-dev@openjdk.org">classfile-api-dev@openjdk.org</a>><br><b>Subject: </b>Re: [External] : RE: StackMap problem</span></p></div><div><p class="MsoNormal"><span style="color:black">Indeed, I noted that our StackMapGenerator eagerly checks if a newly encountered store instruction (the istore_1 in the exception handler range) breaks the stack maps, and our StackMapGenerator would have failed fast in that case.</span></p></div><div><p class="MsoNormal"><span style="color:black"> </span></p></div><div><p class="MsoNormal"><span style="color:black">Chen</span></p></div><div class="MsoNormal" align="center" style="text-align:center"><hr size="2" width="98%" align="center"></div><div id="divRplyFwdMsg"><p class="MsoNormal"><b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:black">From:</span></b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:black"> Adam Sotona <<a href="mailto:adam.sotona@oracle.com">adam.sotona@oracle.com</a>><br><b>Sent:</b> Wednesday, January 29, 2025 11:35 AM<br><b>To:</b> Mark Roberts <<a href="mailto:markro@cs.washington.edu">markro@cs.washington.edu</a>>; <a href="mailto:classfile-api-dev@openjdk.org">classfile-api-dev@openjdk.org</a> <<a href="mailto:classfile-api-dev@openjdk.org">classfile-api-dev@openjdk.org</a>><br><b>Cc:</b> Chen Liang <<a href="mailto:chen.l.liang@oracle.com">chen.l.liang@oracle.com</a>><br><b>Subject:</b> Re: [External] : RE: StackMap problem</span> </p><div><p class="MsoNormal"> </p></div></div><div><div><p class="xmsonormal"><span style="font-size:11.0pt;font-family:Aptos">I see, the </span><span style="font-size:11.0pt">frame is listed at the end of the line.</span></p><p class="xmsonormal"><span style="font-size:11.0pt"> </span></p><p class="xmsonormal"><span style="font-size:11.0pt">Key question still remains – how the instrumentation is done?</span></p><p class="xmsonormal"><span style="font-size:11.0pt;font-family:Aptos">Class- File API regenerates the stack map when I create similar method and inject the istore_1 and iload_1 instructions. </span></p><p class="xmsonormal"><span style="font-size:11.0pt;font-family:Aptos"> </span></p><p class="xmsonormal"><span style="font-size:11.0pt;font-family:Aptos">Adam</span></p><p class="xmsonormal"><span style="font-size:11.0pt;font-family:Aptos"> </span></p><p class="xmsonormal"><span style="font-size:11.0pt;font-family:Aptos"> </span></p><div id="x_mail-editor-reference-message-container"><div><div><div style="border:none;border-top:solid #b5c4df 1.0pt;padding:3.0pt 0in 0in 0in"><p class="xmsonormal" style="margin-bottom:12.0pt"><b><span style="font-size:12.0pt;font-family:Aptos;color:black">From: </span></b><span style="font-size:12.0pt;font-family:Aptos;color:black">Mark Roberts <<a href="mailto:markro@cs.washington.edu">markro@cs.washington.edu</a>><br><b>Date: </b>Wednesday, 29 January 2025 at 17:45<br><b>To: </b>Adam Sotona <<a href="mailto:adam.sotona@oracle.com">adam.sotona@oracle.com</a>>, <a href="mailto:classfile-api-dev@openjdk.org">classfile-api-dev@openjdk.org</a> <<a href="mailto:classfile-api-dev@openjdk.org">classfile-api-dev@openjdk.org</a>><br><b>Cc: </b>Chen Liang <<a href="mailto:chen.l.liang@oracle.com">chen.l.liang@oracle.com</a>><br><b>Subject: </b>[External] : RE: StackMap problem</span></p></div><div><p class="xmsonormal"><span style="font-size:11.0pt">The ‘before’ was compiled with javac version 24-ea+22-269, but I compiled with javac version 17.0.11 and got the exact same binary. The stack map frames are there:</span></p><p class="xmsonormal"><span style="font-size:11.0pt"> </span></p><p class="xmsonormal"><span style="font-size:11.0pt"> StackMapTable:</span></p><p class="xmsonormal"><span style="font-size:11.0pt"> StackMap((SAME_LOCALS_1_STACK, offset delta=19, stack items={(type=Object, class=DataStructures.Overflow)}), (SAME, offset delta=0))</span></p><p class="xmsonormal"><span style="font-size:11.0pt"> </span></p><p class="xmsonormal"><span style="font-size:11.0pt">The first (@19) is the target of the exception handler, the second (@20) is the target of the branch @16.</span></p><p class="xmsonormal"><span style="font-size:11.0pt"> </span></p><p class="xmsonormal"><span style="font-size:11.0pt">It all looks good to me.</span></p><p class="xmsonormal"><span style="font-size:11.0pt"> </span></p><p class="xmsonormal"><span style="font-size:11.0pt">Mark</span></p><p class="xmsonormal"><span style="font-size:11.0pt"> </span></p><p class="xmsonormal"><span style="font-size:11.0pt"> </span></p><div><div style="border:none;border-top:solid #e1e1e1 1.0pt;padding:3.0pt 0in 0in 0in"><p class="xmsonormal"><b><span style="font-size:11.0pt">From:</span></b><span style="font-size:11.0pt"> Adam Sotona <</span><a href="mailto:adam.sotona@oracle.com"><span style="font-size:11.0pt">adam.sotona@oracle.com</span></a><span style="font-size:11.0pt">> <br><b>Sent:</b> Wednesday, January 29, 2025 1:07 AM<br><b>To:</b> Mark Roberts <</span><a href="mailto:markro@cs.washington.edu"><span style="font-size:11.0pt">markro@cs.washington.edu</span></a><span style="font-size:11.0pt">>; </span><a href="mailto:classfile-api-dev@openjdk.org"><span style="font-size:11.0pt">classfile-api-dev@openjdk.org</span></a><span style="font-size:11.0pt"><br><b>Cc:</b> Chen Liang <</span><a href="mailto:chen.l.liang@oracle.com"><span style="font-size:11.0pt">chen.l.liang@oracle.com</span></a><span style="font-size:11.0pt">><br><b>Subject:</b> Re: StackMap problem</span></p></div></div><p class="xmsonormal"> </p><p class="xmsonormal"><span style="font-size:11.0pt;font-family:Aptos">Hi Mark,</span></p><p class="xmsonormal"><span style="font-size:11.0pt;font-family:Aptos">Both attached class listings are missing stack map frames at branch targets, and they seem to be invalid.</span></p><p class="xmsonormal"><span style="font-size:11.0pt;font-family:Aptos">I would like to ask what compiler generates the first class and how your tool adds the instrumentation code.</span></p><p class="xmsonormal"><span style="font-size:11.0pt;font-family:Aptos">My first impression is that I don’t see any trace of Class-File API stack map generator involment. Transformation of a method with missing or invalid stack map would generate new stack maps, unless explicitly disabled.</span></p><p class="xmsonormal"><span style="font-size:11.0pt;font-family:Aptos"> </span></p><p class="xmsonormal"><span style="font-size:11.0pt;font-family:Aptos">Thanks,</span></p><p class="xmsonormal"><span style="font-size:11.0pt;font-family:Aptos">Adam</span></p><p class="xmsonormal"><span style="font-size:11.0pt;font-family:Aptos"> </span></p><p class="xmsonormal"><span style="font-size:11.0pt;font-family:Aptos"> </span></p><div id="x_mail-editor-reference-message-container"><div><div><div style="border:none;border-top:solid #b5c4df 1.0pt;padding:3.0pt 0in 0in 0in"><p class="xmsonormal" style="margin-bottom:12.0pt"><b><span style="font-size:12.0pt;font-family:Aptos;color:black">From: </span></b><span style="font-size:12.0pt;font-family:Aptos;color:black">classfile-api-dev <</span><a href="mailto:classfile-api-dev-retn@openjdk.org"><span style="font-size:12.0pt;font-family:Aptos">classfile-api-dev-retn@openjdk.org</span></a><span style="font-size:12.0pt;font-family:Aptos;color:black">> on behalf of Mark Roberts <</span><a href="mailto:markro@cs.washington.edu"><span style="font-size:12.0pt;font-family:Aptos">markro@cs.washington.edu</span></a><span style="font-size:12.0pt;font-family:Aptos;color:black">><br><b>Date: </b>Tuesday, 28 January 2025 at 21:45<br><b>To: </b></span><a href="mailto:classfile-api-dev@openjdk.org"><span style="font-size:12.0pt;font-family:Aptos">classfile-api-dev@openjdk.org</span></a><span style="font-size:12.0pt;font-family:Aptos;color:black"> <</span><a href="mailto:classfile-api-dev@openjdk.org"><span style="font-size:12.0pt;font-family:Aptos">classfile-api-dev@openjdk.org</span></a><span style="font-size:12.0pt;font-family:Aptos;color:black">><br><b>Cc: </b>Chen Liang <</span><a href="mailto:chen.l.liang@oracle.com"><span style="font-size:12.0pt;font-family:Aptos">chen.l.liang@oracle.com</span></a><span style="font-size:12.0pt;font-family:Aptos;color:black">><br><b>Subject: </b>StackMap problem</span></p></div><div><p class="xmsonormal"><span style="font-size:11.0pt">The existence of compiler generated, unnamed local temps (no LocalVariable code element) seems to cause a problem with stack maps.</span></p><p class="xmsonormal"><span style="font-size:11.0pt"> </span></p><p class="xmsonormal"><span style="font-size:11.0pt">The ‘source’ attachment shows the problem method. The ‘before’ attachment shows the generated code before instrumentation. Note that the compiler generates an unnamed temp at slot 0 to store the exception code. The stackmap for the branch target says same locals, which is correct.</span></p><p class="xmsonormal"><span style="font-size:11.0pt"> </span></p><p class="xmsonormal"><span style="font-size:11.0pt">The ‘after’ attachment shows the code generated after our tool has added instrumentation code – note the addition of a new local variable at slot 1. The stackmap for the branch target still says same locals, which is no longer correct. This causes the iload_1 @41 to fail.</span></p><p class="xmsonormal"><span style="font-size:11.0pt"> </span></p><p class="xmsonormal"><span style="font-size:11.0pt">I tried to see if this issue has already been reported, but I was unable to figure out how to search </span><a href="https://urldefense.com/v3/__https:/bugs.java.com/bugdatabase/__;!!ACWV5N9M2RV99hQ!Oxj6SR2NV9Ad-EfEdNCFmjPL0gx3yAPgZ8jQoj8jWrlF9W-NohRiSuxWzqdOPpnNxoTuYr4zSmL9s1LDi14H1ymI$"><span style="font-size:11.0pt">https://bugs.java.com/bugdatabase/</span></a><span style="font-size:11.0pt"> by keyword.</span></p><p class="xmsonormal"><span style="font-size:11.0pt"> </span></p><p class="xmsonormal"><span style="font-size:11.0pt">Mark</span></p><p class="xmsonormal"><span style="font-size:11.0pt"> </span></p><p class="xmsonormal"><span style="font-size:11.0pt"> </span></p><p class="xmsonormal"><span style="font-size:11.0pt"> </span></p></div></div></div></div></div></div></div></div></div></div></div></div></div></div></body></html>