Skip to content
This repository

Exception-related beam verification error #43

eriksoe opened this Issue · 7 comments

2 participants

Erik Søe Sørensen Kresten Krab Thorup
Erik Søe Sørensen

The code:
exn() -> try erlang:error(x)
catch E -> {caught,E}
after io:format("after\n")

results in this error:
13-11-2010 10:36:10 erjang.m.erlang.ErlBif load_module
SEVERE: cannot load module exntest
java.lang.RuntimeException: Verify error. Expected word in stack, but stack is empty
at kilim.analysis.Frame.pop(
at kilim.analysis.Frame.popWord(
at kilim.analysis.BasicBlock.interpret(
at kilim.analysis.MethodFlow.dataFlow(
at kilim.analysis.MethodFlow.analyze(
at kilim.analysis.ClassFlow.analyze(
at kilim.analysis.ClassWeaver.weave(
at kilim.analysis.ClassWeaver.(
at erjang.beam.Compiler.compile(

Erik Søe Sørensen

Appears to be related to beam-level knowledge that erlang:error() never returns.
The compiler omits "try_end" in the beam code, for example; "try_end" is present if some other function is called instead:
- {call_ext,1,{extfunc,e,error,1}}.
- {try_end,{y,0}}.
- {jump,{f,5}}.
+ {call_ext,1,{extfunc,erlang,error,1}}.

Erik Søe Sørensen

Oops - wrong button. How to reopen?

Kresten Krab Thorup

Yeo. There's some logic in the codegen for call_ext calling isTerminal or something and then injects a return insn in that case. Perhaps erlang:error/1 is missing there.

Erik Søe Sørensen

Yes - I remember introducing it, but failed to quickly locate it when searching for 'error' - no wonder then. I'll try to fix.

Erik Søe Sørensen

isTerminal is gone, apparently - I think the issue is that only tail calls has this special treatment at present.

Erik Søe Sørensen

This appears to be a kilim issue; the 'dup' in question is the first instruction in an exception handler block - where the stack isn't empty.
FTR, the input to kilim passes jvmverifier.

Erik Søe Sørensen

Verified: It's not a beam verification issue at all; it is a kilim shortcoming.
Kilim patch written, tested and sent to the maintainer.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.