<html 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=us-ascii">
<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:Aptos;
        panose-1:2 11 0 4 2 2 2 2 2 4;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 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;}
pre
        {mso-style-priority:99;
        mso-style-link:"HTML Preformatted Char";
        margin:0in;
        font-size:10.0pt;
        font-family:"Courier New";}
span.HTMLPreformattedChar
        {mso-style-name:"HTML Preformatted Char";
        mso-style-priority:99;
        mso-style-link:"HTML Preformatted";
        font-family:"Consolas",serif;}
span.EmailStyle21
        {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>
</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">Hi David,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Provided test case also calculates the maxstack correctly for me (with the recent codebase).<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Thanks,<o:p></o:p></p>
<p class="MsoNormal">Adam<span style="font-size:11.0pt"><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">classfile-api-dev <classfile-api-dev-retn@openjdk.org> on behalf of david32768@btinternet.com david32768@btinternet.com <david32768@btinternet.com><br>
<b>Date: </b>Wednesday, 30 October 2024 at 2:56<br>
<b>To: </b>classfile-api-dev@openjdk.org <classfile-api-dev@openjdk.org><br>
<b>Subject: </b>Re: Stack size miscalculated with try-catch blocks<o:p></o:p></span></p>
</div>
<p>The problem is in StackMapGenerate.<o:p></o:p></p>
<p>The original method name of Frame.CheckStack is misleading as it adds 1 to index.<o:p></o:p></p>
<p>The recent changes assume it does not but there are still calls which assume this.<o:p></o:p></p>
<p> <o:p></o:p></p>
<p>testcode<br>
```<br>
import module java.base;<o:p></o:p></p>
<p>public class MaxStack  {<o:p></o:p></p>
<p>   private static void build(CodeBuilder cob) {<br>
       cob<br>
          .iload(0)<br>
          .i2l()<br>
          .lreturn();<br>
   }<br>
<br>
   public static void main(String[] args) throws IOException {<br>
       ClassFile cf = v; // MaxStack = 3<br>
//        ClassFile cf = v; // MaxStack = 2<br>
       byte[] bytes = cf<br>
               .build(ClassDesc.of("TestMaxStack"),<br>
           clb -> clb.withFlags(ClassFile.ACC_PUBLIC  | ClassFile.ACC_SUPER)<br>
        .withVersion(49,0)<br>
               .withMethodBody("Table", MethodTypeDesc.ofDescriptor("(I)J"),<br>
                    ClassFile.ACC_STATIC,<br>
             MaxStack::build));<br>
       cf = ClassFile.of();<br>
       ClassModel cm = cf.parse(bytes);<br>
       cm.methods().stream()<br>
               .flatMap(m -> m.attributes().stream())<br>
        .filter(attr -> attr instanceof CodeAttribute)<br>
        .map(attr -> ((CodeAttribute)attr).maxStack())<br>
        .map(sz -> "MaxStack = " + sz)<br>
               .forEach(System.out::println);<br>
   }<br>
}<br>
```<br>
<br>
<br>
 <o:p></o:p></p>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<p>------ Original Message ------<br>
From: rafael.wth@gmail.com<br>
To: classfile-api-dev@openjdk.org<br>
Sent: Thursday, October 24th 2024, 07:33<br>
Subject: Stack size miscalculated with try-catch blocks<br>
 <o:p></o:p></p>
<div>
<div>
<p class="MsoNormal">Hello,<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">when testing a recent build of the JDK with my bridge to ASM, I encountered some test failures. This is related to the stack size of a method being calculated with an additional, unnecessary slot. This can be reproduced using
<a href="https://github.com/raphw/asm-jdk-bridge" target="_blank">https://github.com/raphw/asm-jdk-bridge</a><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">This can also be reproduced by inspecting the computed stack for:<o:p></o:p></p>
</div>
<div>
<div>
<pre style="background:#1E1F22"><span style="color:#CF8E6D">void </span><span style="color:#56A8F5">c</span><span style="color:#BCBEC4">() {<br>    </span><span style="color:#CF8E6D">try </span><span style="color:#BCBEC4">{<br>        </span><span style="color:#CF8E6D">throw new </span><span style="color:#BCBEC4">RuntimeException();<br>    } </span><span style="color:#CF8E6D">catch </span><span style="color:#BCBEC4">(RuntimeException e) {<br>    }<br>}<o:p></o:p></span></pre>
</div>
</div>
<div>
<p class="MsoNormal">which will be computed as 3 and not 2.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Best regards, Rafael<br>
 <o:p></o:p></p>
</div>
</div>
</blockquote>
</div>
</div>
</div>
</div>
</body>
</html>