<html><body><div style="font-family: arial, helvetica, sans-serif; font-size: 12pt; color: #000000"><div><br></div><div><br></div><hr id="zwchr" data-marker="__DIVIDER__"><div data-marker="__HEADERS__"><blockquote style="border-left:2px solid #1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;"><b>From: </b>"Brian Goetz" <brian.goetz@oracle.com><br><b>To: </b>"Adam Sotona" <adam.sotona@oracle.com>, "classfile-api-dev" <classfile-api-dev@openjdk.org><br><b>Sent: </b>Wednesday, April 19, 2023 5:21:52 PM<br><b>Subject: </b>Re: Classfile API support for JSR and RET instructions<br></blockquote></div><div><style>@font-face
{font-family:Wingdings;
panose-1:5 0 0 0 0 0 0 0 0 0;}@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;}p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
font-size:11.0pt;
font-family:"Calibri",sans-serif;
mso-ligatures:standardcontextual;
mso-fareast-language:EN-US;}a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
{mso-style-priority:34;
margin-top:0cm;
margin-right:0cm;
margin-bottom:0cm;
margin-left:36.0pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;
mso-ligatures:standardcontextual;
mso-fareast-language:EN-US;}span.EmailStyle17
{mso-style-type:personal-compose;
font-family:"Calibri",sans-serif;
color:windowtext;}.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri",sans-serif;
mso-fareast-language:EN-US;}div.WordSection1
{page:WordSection1;}ol
{margin-bottom:0cm;}ul
{margin-bottom:0cm;}</style></div><div data-marker="__QUOTED_TEXT__"><blockquote style="border-left:2px solid #1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;"><font size="4"><font face="monospace">Overall this is a good plan.
There's a small gap regarding control of stack map generation.
<br><br>
The stack map attribute was introduced in classfile version 50;
JSR and RET were eliminated in classfile version 51. So there's
a small window where stackmaps and JSR/RET can co-exist. <br><br>
Our strategy with stackmaps is to generate based on an option,
whose default is to generate. You are right that we should
refine this so that we never generate stack maps for classfiles
< 50 because the stackmap attribute wasn't defined until
then. </font></font></blockquote><div><br></div><div>Why ? StackMapTable is an attribute, it can be present in class file version < 50 and it will be ignored by the VM.</div><div>Generating stack map is quite costly so generating them beforehand even if the class file version is < 50 is a trick to make agents that upgrade the class file version at runtime faster (because for most transformations, patching the stack maps is linear).<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><div>Rémi<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><blockquote style="border-left:2px solid #1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;"><font size="4"><font face="monospace"><br><br></font></font><br>
<div class="moz-cite-prefix">On 4/19/2023 9:29 AM, Adam Sotona
wrote:<br>
</div>
<blockquote cite="mid:CY4PR1001MB2150AC33FDE9291AE3121B628C629@CY4PR1001MB2150.namprd10.prod.outlook.com">
<div class="WordSection1">
<p class="MsoNormal"><span lang="EN-US">Hi,</span></p>
<p class="MsoNormal"><span lang="EN-US">Work on javap conversion
from ASM to Classfile API and recent bug (<a href="https://bugs.openjdk.org/browse/JDK-8305990" target="_blank">JDK-8305990</a>) discovered in
StripJavaDebugAttributesPlugin brought attention to missing
JSR and RET instructions support in Classfile API.</span></p>
<p class="MsoNormal"><span lang="EN-US">I’m proposing following
changes to Classfile API:</span></p>
<ul style="margin-top:0cm" type="disc">
<li class="MsoListParagraph" style="margin-left:0cm;mso-list:l0 level1 lfo2"><span lang="EN-US">Drop Opcode.Kind.UNSUPPORTED and add
Opcode.Kind.DISCONTINUED_JSR and DISCONTINUED_RET</span></li>
<li class="MsoListParagraph" style="margin-left:0cm;mso-list:l0 level1 lfo2"><span lang="EN-US">Add DiscontinuedInstruction interface with
inner JsrInstruction and RetInstruction with standard
factory methods</span></li>
<li class="MsoListParagraph" style="margin-left:0cm;mso-list:l0 level1 lfo2"><span lang="EN-US">CodeImpl will parse and stream these
instructions when present in the Code attribute</span></li>
<li class="MsoListParagraph" style="margin-left:0cm;mso-list:l0 level1 lfo2"><span lang="EN-US">Do not add any new conveniency methods to
CodeBuilder, the only way to build a code with these
instructions will be cob.with(DiscontinuedInstruction.
JsrInstruction.of(…)) and similar for RetInstruction</span></li>
<li class="MsoListParagraph" style="margin-left:0cm;mso-list:l0 level1 lfo2"><span lang="EN-US">Fix DirectCodeBuilder so it invokes
StackMapGenerator only for class file version >= 51.0
(BufWriterImpl must hold class version for that purpose)</span></li>
<li class="MsoListParagraph" style="margin-left:0cm;mso-list:l0 level1 lfo2"><span lang="EN-US">Fix StackMapGenerator error message when
these instruction appear in during generation</span></li>
<li class="MsoListParagraph" style="margin-left:0cm;mso-list:l0 level1 lfo2"><span lang="EN-US">Implement fallback to jump target inflation
in CodeImpl when the StackMapTable attribute is missing
and class file version is < 51.0</span></li>
<li class="MsoListParagraph" style="margin-left:0cm;mso-list:l0 level1 lfo2"><span lang="EN-US">Extend tests to verify JSR and RET
instructions are correctly generated, transformed and
reported as error (based on class file version).</span></li>
</ul>
<p class="MsoNormal"><span lang="EN-US">Please review and
comment this proposal under following pull request:</span></p>
<p class="MsoNormal"><span lang="EN-US"><a href="https://github.com/openjdk/jdk/pull/13478" class="moz-txt-link-freetext" target="_blank">https://github.com/openjdk/jdk/pull/13478</a></span><br data-mce-bogus="1"></p>
<p class="MsoNormal"><span lang="EN-US">Next step is to
implement simple maxStack and maxLocals counter into
DirectCodeBuilder for the cases where StackMapGenerator is
not involved. Actual default to maxStack = maxLocals = 255
is not correct.</span></p>
<p class="MsoNormal"><span lang="EN-US">Thanks,</span></p>
<p class="MsoNormal"><span lang="EN-US">Adam</span></p>
</div>
</blockquote>
<br><br></blockquote></div></div></body></html>