Dispatch an exception backward?

Liu, Xin xxinliu at amazon.com
Fri Jan 20 19:50:28 UTC 2023


hi, Remi,

Thanks you for explanation. I am surprised that some front-end compilers
use exception to control, but it's fair enough.

I think I also understand why C2 parser refrains from creating phi via
backedge after the block is parsed. It's not just phi insertion, it has
to substitute all appearances of the original node. If we create phi
before parsing, we ensure the SSA property.

thanks,
--lx

On 1/19/23 5:51 AM, Remi Forax wrote:
> CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you can confirm the sender and know the content is safe.
> 
> 
> 
> ----- 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_0xB9D934C61E047B0D.asc
Type: application/pgp-keys
Size: 3675 bytes
Desc: OpenPGP public key
URL: <https://mail.openjdk.org/pipermail/hotspot-compiler-dev/attachments/20230120/ed243f76/OpenPGP_0xB9D934C61E047B0D.asc>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature
Type: application/pgp-signature
Size: 665 bytes
Desc: OpenPGP digital signature
URL: <https://mail.openjdk.org/pipermail/hotspot-compiler-dev/attachments/20230120/ed243f76/OpenPGP_signature.sig>


More information about the hotspot-compiler-dev mailing list