Stack overflow errors ought to be caught #709
Labels
enhancement
Not a bug, but nice to have
language
Issues in parser, TC, interpreter, POG or CG
Mergable
A fix is available on a branch to merge for release
Currently, stack overflow problems - usually caused by recursive loops, often implicitly via invariants that reference themselves - are not caught by the Overture runtime and simply drop out to the Java default exception handling. This dumps the Java stack to the console, but that is not helpful from a modelling perspective since it does not include the names of VDM variables and functions.
Handling stack overflows in Java is difficult because when they occur, by definition, you do not have very much stack available to handle the error! The trick is to pop a certain number of frames off the stack, while still handling the exception, and then process the remaining VDM stack with a minimum of new Java frame usage (ie. not recursing!). This is reasonable since, if you have broken the stack limit, you are probably in a recursive loop anyway and the remaining frames on the stack will be enough to identify the loop problem, even if strictly they were not the top of the stack when the limit was reached.
Experiments seem to verify that this approach is workable. It is certainly better than letting Java crash. Pushing this change to ncb/development for further testing.
The text was updated successfully, but these errors were encountered: