<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>"jan lahoda" <jan.lahoda@oracle.com><br><b>To: </b>"Amber Expert Group Observers" <amber-spec-observers@openjdk.org>, "Remi Forax" <forax@univ-mlv.fr>, "Brian Goetz" <brian.goetz@oracle.com><br><b>Sent: </b>Wednesday, December 13, 2023 3:15:17 PM<br><b>Subject: </b>Re: Effect cases in switch<br></blockquote></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;"><p>On 13. 12. 23 13:49, <a class="moz-txt-link-abbreviated" href="mailto:forax@univ-mlv.fr" target="_blank">forax@univ-mlv.fr</a> wrote:</p>
<div class="moz-cite-prefix">[snip]<br>
</div>
<blockquote cite="mid:1882982839.81146561.1702471762200.JavaMail.zimbra@univ-eiffel.fr">
<div style="font-family: arial, helvetica, sans-serif; font-size: 12pt; color: #000000"><br>
<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;">
<blockquote cite="mid:327307323.80228032.1702420883408.JavaMail.zimbra@univ-eiffel.fr">
<div style="font-family: arial, helvetica, sans-serif; font-size: 12pt; color: #000000">
<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;">
Exception cases have the obvious dominance order
with other exception cases (the<br>
same one used to validate order of `catch` clauses
in `try-catch`), and do not<br>
participate in dominance ordering with
non-exceptional cases. It is a<br>
compile-time error if an exception case specifies an
exception type that cannot<br>
be thrown by the selector expression, or a type that
does not extend<br>
`Throwable`. For clarity, exception cases should
probably come after all other<br>
non-exceptional cases. <br>
<br>
When evaluating a `switch` statement or expression,
the selector expression is<br>
evaluated. If evaluation of the selector expression
throws an exception, and<br>
one of the exception cases in the `switch` matches
the exception, then control<br>
is transferred to the first exception case matching
the exception. If no<br>
exception case matches the exception, then the
switch completes abruptly with<br>
that same exception. </blockquote>
<div><br>
</div>
<div>I don't want to be the guy implementing this :)</div>
</div>
</div>
</blockquote>
<br>
Good news, Jan has volunteered to be that guy :)</blockquote>
<div><br>
</div>
<div>Are you sure you do not want a VM guy too ?<br>
</div>
</div>
</div>
</blockquote>
<p><br>
</p>
<p>FWIW, we already run in the "try-catch with values on stack"
problem in the case of a try-catch inside a switch expression. The
current solution is to stash the stack to locals (which I suspect
is similar to what you did in your case). It is not very pretty,
but I think we can start with this and see if it poses problems in
practice.</p></blockquote><div><br></div><div>I tried to be clever which is in retrospect may have not be not a good idea, i.e. not stash constants and things that were already in a local variable and effectively final. Anyway, the main issue I had (it was 10 years ago) was c1 deciding to not inline the method anymore because of the code bloat with as a direct consequence a reference on the stack that was previously GCed that was not anymore (because the interpreter was now keeping a reference in the locals).<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;">
<p><br>
</p>
<p>(I am a bit more concerned about the switch-with-case-throws used
as a conditional e.g. in an if - that may be tricky, as the code
needs to have some particular shape. I think we have some ideas on
how to implement that in the compiler, but didn't try them yet.)</p>
<p><br>
</p>
<p>Jan</p></blockquote><div><br></div><div>RĂ©mi</div><div><br data-mce-bogus="1"></div></div></div></body></html>