JVM exceptions are weird: a decompiler perspective

purplesyringa.moe

136 points by vrnvu 6 days ago


marginalia_nu - 14 hours ago

On the subject

  void foo() {
    for (;;) {
      try { return; } 
      finally { continue; }
    }
  }
is my favorite cursed Java exceptions construct.
pron - 15 hours ago

Nice post!

A minor point:

> monitors are incompatible with coroutines

If by coroutines the author meant virtual threads, then monitors have always been compatible with virtual threads (which have always needed to adhere to the Thread specification). Monitors could, for a short while, degrade the scalability of virtual threads (and in some situations even lead to deadlocks), but that has since been resolved in JDK 24 (https://openjdk.org/jeps/491).

- 15 hours ago
[deleted]
Joker_vD - 14 hours ago

Doesn't JRE has some limited form of decompilation in its JIT, as a pre-pass? IIRC, it reconstructs the basic blocks and CFG from the bytecode and does some minor optimizations before going on to regalloc and codegen.

immibis - 13 hours ago

Older versions of Java did try to have only one copy of the finally block code. To implement this, there were "jsr" and "ret" instructions, which allowed a method (a subroutine) to contain subroutines inside it. This even curseder implementation of finally is prohibited starting from version 51 class files (Java 7).