Dispatch an exception backward?

Remi Forax forax at univ-mlv.fr
Thu Jan 19 13:51:17 UTC 2023


----- Original Message -----
> From: "Xin Liu" <xxinliu at amazon.com>
> To: hotspot-compiler-dev at openjdk.org
> Sent: Wednesday, January 18, 2023 2:32:35 AM
> Subject: Dispatch an exception backward?

> Hi,
> 
> From Parse::merge_exception(int target_bci), I found that it is possible
> to have 'target_bci < bci()'. It suggests that C2 may dispatch the
> exception backward to an matched exception handler. Is it paranoid or
> legitimate case?

There is nothing in the VM spec that forbids such bytecode shapes.

> 
> void Parse::merge_exception(int target_bci) {
> #ifdef ASSERT
>  if (target_bci < bci()) {
>    C->set_exception_backedge();
>  }
> #endif
> 
> I am not familiar with javac codegen. My intuition is that the exception
> handler should come after the place it throws an exception. The class
> files I read so far confirm this impression. From perspective of a
> programming language, they are causal relationship. Fire alarm goes off
> first (exception), call 911 later(exception handler). I feel that an
> exception should always dispatch forward.

Jumping on an exception is a kind of goto, it can be forward, it can be backward.

javac does not produce such bytecode shapes but javac is not the only producer of bytecodes in town.

Using exceptions for the control flow is sometimes necessary, i think the first versions of scalac were using exceptions to implement "continue" and "break" in loop.
A "continue" is clearly a goto backward.

regards,
Rémi


More information about the hotspot-compiler-dev mailing list