<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]--><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;
panose-1:2 11 0 4 2 2 2 2 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
font-size:12.0pt;
font-family:"Aptos",sans-serif;}
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.EmailStyle22
{mso-style-type:personal-reply;
font-family:"Aptos",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;
mso-ligatures:none;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</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">I see what happened here. The transformed method is invalid because the istore_1 is injected into the try block and consumed outside.<o:p></o:p></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.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></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.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></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.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Adam <o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></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 <chen.l.liang@oracle.com><br>
<b>Date: </b>Wednesday, 29 January 2025 at 18:44<br>
<b>To: </b>Adam Sotona <adam.sotona@oracle.com>, classfile-api-dev@openjdk.org <classfile-api-dev@openjdk.org><br>
<b>Subject: </b>Re: [External] : RE: StackMap problem<o:p></o:p></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.<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="color:black"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="color:black">Chen<o:p></o:p></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 <adam.sotona@oracle.com><br>
<b>Sent:</b> Wednesday, January 29, 2025 11:35 AM<br>
<b>To:</b> Mark Roberts <markro@cs.washington.edu>; classfile-api-dev@openjdk.org <classfile-api-dev@openjdk.org><br>
<b>Cc:</b> Chen Liang <chen.l.liang@oracle.com><br>
<b>Subject:</b> Re: [External] : RE: StackMap problem</span> <o:p></o:p></p>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="xmsonormal"><span style="font-size:11.0pt;font-family:"Aptos",sans-serif">I see, the
</span><span style="font-size:11.0pt">frame is listed at the end of the line.</span><o:p></o:p></p>
<p class="xmsonormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="xmsonormal"><span style="font-size:11.0pt">Key question still remains – how the instrumentation is done?</span><o:p></o:p></p>
<p class="xmsonormal"><span style="font-size:11.0pt;font-family:"Aptos",sans-serif">Class- File API regenerates the stack map when I create similar method and inject the istore_1 and iload_1 instructions.
</span><o:p></o:p></p>
<p class="xmsonormal"><span style="font-size:11.0pt;font-family:"Aptos",sans-serif"> </span><o:p></o:p></p>
<p class="xmsonormal"><span style="font-size:11.0pt;font-family:"Aptos",sans-serif">Adam</span><o:p></o:p></p>
<p class="xmsonormal"><span style="font-size:11.0pt;font-family:"Aptos",sans-serif"> </span><o:p></o:p></p>
<p class="xmsonormal"><span style="font-size:11.0pt;font-family:"Aptos",sans-serif"> </span><o:p></o:p></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",sans-serif;color:black">From:
</span></b><span style="font-size:12.0pt;font-family:"Aptos",sans-serif;color:black">Mark Roberts <markro@cs.washington.edu><br>
<b>Date: </b>Wednesday, 29 January 2025 at 17:45<br>
<b>To: </b>Adam Sotona <adam.sotona@oracle.com>, classfile-api-dev@openjdk.org <classfile-api-dev@openjdk.org><br>
<b>Cc: </b>Chen Liang <chen.l.liang@oracle.com><br>
<b>Subject: </b>[External] : RE: StackMap problem</span><o:p></o:p></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><o:p></o:p></p>
<p class="xmsonormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="xmsonormal"><span style="font-size:11.0pt"> StackMapTable:</span><o:p></o:p></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><o:p></o:p></p>
<p class="xmsonormal"><span style="font-size:11.0pt"> </span><o:p></o:p></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><o:p></o:p></p>
<p class="xmsonormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="xmsonormal"><span style="font-size:11.0pt">It all looks good to me.</span><o:p></o:p></p>
<p class="xmsonormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="xmsonormal"><span style="font-size:11.0pt">Mark</span><o:p></o:p></p>
<p class="xmsonormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="xmsonormal"><span style="font-size:11.0pt"> </span><o:p></o:p></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><o:p></o:p></p>
</div>
</div>
<p class="xmsonormal"> <o:p></o:p></p>
<p class="xmsonormal"><span style="font-size:11.0pt;font-family:"Aptos",sans-serif">Hi Mark,</span><o:p></o:p></p>
<p class="xmsonormal"><span style="font-size:11.0pt;font-family:"Aptos",sans-serif">Both attached class listings are missing stack map frames at branch targets, and they seem to be invalid.</span><o:p></o:p></p>
<p class="xmsonormal"><span style="font-size:11.0pt;font-family:"Aptos",sans-serif">I would like to ask what compiler generates the first class and how your tool adds the instrumentation code.</span><o:p></o:p></p>
<p class="xmsonormal"><span style="font-size:11.0pt;font-family:"Aptos",sans-serif">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><o:p></o:p></p>
<p class="xmsonormal"><span style="font-size:11.0pt;font-family:"Aptos",sans-serif"> </span><o:p></o:p></p>
<p class="xmsonormal"><span style="font-size:11.0pt;font-family:"Aptos",sans-serif">Thanks,</span><o:p></o:p></p>
<p class="xmsonormal"><span style="font-size:11.0pt;font-family:"Aptos",sans-serif">Adam</span><o:p></o:p></p>
<p class="xmsonormal"><span style="font-size:11.0pt;font-family:"Aptos",sans-serif"> </span><o:p></o:p></p>
<p class="xmsonormal"><span style="font-size:11.0pt;font-family:"Aptos",sans-serif"> </span><o:p></o:p></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",sans-serif;color:black">From:
</span></b><span style="font-size:12.0pt;font-family:"Aptos",sans-serif;color:black">classfile-api-dev <</span><a href="mailto:classfile-api-dev-retn@openjdk.org"><span style="font-size:12.0pt;font-family:"Aptos",sans-serif">classfile-api-dev-retn@openjdk.org</span></a><span style="font-size:12.0pt;font-family:"Aptos",sans-serif;color:black">>
on behalf of Mark Roberts <</span><a href="mailto:markro@cs.washington.edu"><span style="font-size:12.0pt;font-family:"Aptos",sans-serif">markro@cs.washington.edu</span></a><span style="font-size:12.0pt;font-family:"Aptos",sans-serif;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",sans-serif">classfile-api-dev@openjdk.org</span></a><span style="font-size:12.0pt;font-family:"Aptos",sans-serif;color:black"> <</span><a href="mailto:classfile-api-dev@openjdk.org"><span style="font-size:12.0pt;font-family:"Aptos",sans-serif">classfile-api-dev@openjdk.org</span></a><span style="font-size:12.0pt;font-family:"Aptos",sans-serif;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",sans-serif">chen.l.liang@oracle.com</span></a><span style="font-size:12.0pt;font-family:"Aptos",sans-serif;color:black">><br>
<b>Subject: </b>StackMap problem</span><o:p></o:p></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><o:p></o:p></p>
<p class="xmsonormal"><span style="font-size:11.0pt"> </span><o:p></o:p></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><o:p></o:p></p>
<p class="xmsonormal"><span style="font-size:11.0pt"> </span><o:p></o:p></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><o:p></o:p></p>
<p class="xmsonormal"><span style="font-size:11.0pt"> </span><o:p></o:p></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><o:p></o:p></p>
<p class="xmsonormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="xmsonormal"><span style="font-size:11.0pt">Mark</span><o:p></o:p></p>
<p class="xmsonormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="xmsonormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="xmsonormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>