RFR: 8315735: VerifyError when switch statement used with synchronized block
Rémi Forax
forax at openjdk.org
Wed Sep 6 09:40:40 UTC 2023
On Wed, 6 Sep 2023 08:29:40 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:
> (When there's a try statement inside a switch expression, the pre-existing stack is stored in local variables, and restored at return from the case. This is because catch clauses start with an empty stack.)
Technically, the stack is not empty, you have the exception on top of the stack.
src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Gen.java line 1292:
> 1290: hasTry[0] = true;
> 1291: }
> 1292:
You can make this code slightly more efficient by using the fact that 'var' is enable to reference the type of an anonymous class.
private boolean hasTry(JCSwitchExpression tree) {
var treeScanner = new TreeScanner() {
private boolean hasTry;
@Override
public void visitTry(JCTry tree) {
hasTry = true;
}
@Override
public void visitSynchronized(JCSynchronized tree) {
hasTry = true;
}
@Override
public void visitClassDef(JCClassDecl tree) {
}
@Override
public void visitLambda(JCLambda tree) {
}
};
treeScanner.scan(tree);
return treeScanner.hasTry;
}
-------------
PR Comment: https://git.openjdk.org/jdk/pull/15584#issuecomment-1708007664
PR Review Comment: https://git.openjdk.org/jdk/pull/15584#discussion_r1317019442
More information about the compiler-dev
mailing list