RFR: JDK-8214114: Switch expressions with try-catch statements

Jan Lahoda jan.lahoda at oracle.com
Thu Dec 6 16:51:25 UTC 2018


Hi,

Switch expressions that contain try-catch statements don't work 
currently, as the catch handlers require that the stack is empty when 
the handler is invoked, but this may not be true when the switch 
expression is inside an expression evaluation (and so some values are 
already on the stack).

The proposed solution is to stash the stack content to local variables 
before "running" the switch expression, and fill the stack content back 
when breaking out of the switch expression. This is done only if the 
try-catch statement is present in the switch expression, as it produces 
longer bytecode.

Also, it turned out variables inside switch expressions in field 
initializers don't work properly (as their owner is the field, not a 
method), attempted to fix that as well.

JBS: https://bugs.openjdk.java.net/browse/JDK-8214114
Webrev: http://cr.openjdk.java.net/~jlahoda/8214114/webrev.00/

How does this look?

Thanks,
     Jan


More information about the compiler-dev mailing list