Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stack overflow errors ought to be caught #709

Closed
nickbattle opened this issue Nov 29, 2019 · 3 comments
Closed

Stack overflow errors ought to be caught #709

nickbattle opened this issue Nov 29, 2019 · 3 comments
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

Comments

@nickbattle
Copy link
Contributor

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.

@nickbattle nickbattle added the enhancement Not a bug, but nice to have label Nov 29, 2019
@nickbattle
Copy link
Contributor Author

Now available in ncb/development.

@nickbattle nickbattle added the Mergable A fix is available on a branch to merge for release label Nov 29, 2019
@nickbattle
Copy link
Contributor Author

Pushed a slightly enhanced fix, which doesn't produce multiple stack dumps on the console.

@nickbattle
Copy link
Contributor Author

Pushed another small tweak to make a more sensible trim of the stack dump. It now prints the top 50 frames, which should be enough to identify any looping, and an indication of how many frames were skipped, followed by the last 5 frames to give you some idea of the root of the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
None yet
Development

No branches or pull requests

1 participant