<div dir="ltr">Sorry again: Now I mess up: it's possible like this:<br><br> - At labelBinding what is in the 

'come-from' list  is checked<br> - With a later backward jump to this label, it is checked again<br><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Mar 10, 2024 at 3:54 PM Øystein Myhre Andersen <<a href="mailto:o.myhre@gmail.com">o.myhre@gmail.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"><div dir="ltr">Sorry: This does not handle backward jumps.<div><br></div><div>But 

 a 'come-from' list  might be useful for the <span style="color:rgb(80,0,80)">StackMapGenerator.</span></div><div>And, maybe speed it up.<span style="color:rgb(80,0,80)"><br></span></div><div><br></div><div>P.S. In the byte code of Simula, we had the rule that a label only had one and only one associated goto.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Mar 10, 2024 at 3:21 PM Øystein Myhre Andersen <<a href="mailto:o.myhre@gmail.com" target="_blank">o.myhre@gmail.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"><div dir="ltr"><br>Yes, I know which method builder is called.<br>I have a class file builder like:<br><br>     byte[] bytes = ClassFile.of().build(currentClassDesc(),<br>      classBuilder -> {<br>            classBuilder<br>                  ....<br>                  .withMethodBody("_STM", MTD_STM, ClassFile.ACC_PUBLIC,<br>                        codeBuilder -> buildMethod_STM(codeBuilder));<br>      }<br>        );<br><br>Within 'buildMethod_STM' I traverse a syntax tree building code from each node.<br>Somewhere there a mistake is made that leads to 'stack size mismatch'.<br><br>When I return from 'buildMethod_STM', the method builder will finalize its work.<br>It generates the bytecode and builds the stack map table.<br>I assume that it checks the stack size at all labels, it must do so to build a correct stack map table.<br><br>Along with the error message comes a complete dump of the entire method.<br><br>Checking for 'Stack size mismatch' is currently done in 'java.base/jdk.internal.classfile.impl.StackMapGenerator'.<br>It would have been nice if this was tested earlier by Codebuilder when the labelBinding pseudo instruction was created.<br><div><br></div><div>One way it might be done is to build a 'come-from' list within labelBinding pseudo instruction.<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Mar 9, 2024 at 10:10 PM - <<a href="mailto:liangchenblue@gmail.com" target="_blank">liangchenblue@gmail.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"><div dir="ltr">What are you trying to do? So you are writing a class and there's a stack size error, but you don't know which method builder this stack size error is from?</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Mar 9, 2024 at 2:04 PM Øystein Myhre Andersen <<a href="mailto:o.myhre@gmail.com" target="_blank">o.myhre@gmail.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"><div dir="ltr">You said: 

as this error can only be detected at run time.<div>That is wrong. It occurs when building stack-map.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Mar 9, 2024 at 7:38 PM - <<a href="mailto:liangchenblue@gmail.com" target="_blank">liangchenblue@gmail.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"><div dir="ltr">Hi Øystein,<div>ClassFile API does not always ensure the created bytecode is valid, and allowing creation of code with invalid stack size is a feature instead of a bug. A stack size mismatch problem, in essence, is closer to the error which a user forgot to call a builder method. And putting this check earlier doesn't really help, as this error can only be detected at run time. You can always use ClassFile.verify to verify your generated class files.</div><div><br></div><div>In addition, CodeBuilder supports chaining; if we add the size checking in each item of the chain, it will introduce a performance penalty.</div><div><br></div><div>Chen</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Mar 9, 2024 at 8:42 AM Øystein Myhre Andersen <<a href="mailto:o.myhre@gmail.com" target="_blank">o.myhre@gmail.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"><div dir="ltr"><pre style="box-sizing:border-box;overflow:auto;font-family:"Helvetica Neue","Segoe UI",Arial,sans-serif-regular;font-size:14px;padding:9.5px;margin-top:0px;margin-bottom:10px;line-height:1.42857;color:rgb(51,51,51);word-break:break-all">Checking for 'Stack size mismatch' is currently done in 'java.base/jdk.internal.classfile.impl.StackMapGenerator'.
It would have been nice if this was tested earlier by Codebuilder when the instructions was created.

For example, by keeping track of the stack size curing code building.

It is good programming practice to catch errors as early as possible.</pre></div>
</blockquote></div>
</blockquote></div>
</blockquote></div>
</blockquote></div>
</blockquote></div>
</blockquote></div>