diff --git a/core/interpreter/src/main/java/org/overture/interpreter/VDMPP.java b/core/interpreter/src/main/java/org/overture/interpreter/VDMPP.java index e89322ae79..531217ec57 100644 --- a/core/interpreter/src/main/java/org/overture/interpreter/VDMPP.java +++ b/core/interpreter/src/main/java/org/overture/interpreter/VDMPP.java @@ -313,7 +313,16 @@ protected ExitStatus interpret(List filenames, String defaultName) } catch (ContextException e) { println("Initialization: " + e); - e.ctxt.printStackTrace(Console.out, true); + + if (e.isStackOverflow()) + { + e.ctxt.printStackFrames(Console.out); + } + else + { + e.ctxt.printStackTrace(Console.out, true); + } + dumpLogs(); return ExitStatus.EXIT_ERRORS; } catch (Exception e) @@ -348,7 +357,15 @@ protected ExitStatus interpret(List filenames, String defaultName) } catch (ContextException e) { println("Execution: " + e); - e.ctxt.printStackTrace(Console.out, true); + + if (e.isStackOverflow()) + { + e.ctxt.printStackFrames(Console.out); + } + else + { + e.ctxt.printStackTrace(Console.out, true); + } } catch (Exception e) { println("Execution: " + e); diff --git a/core/interpreter/src/main/java/org/overture/interpreter/VDMSL.java b/core/interpreter/src/main/java/org/overture/interpreter/VDMSL.java index 0ad8b483bc..d013df564c 100644 --- a/core/interpreter/src/main/java/org/overture/interpreter/VDMSL.java +++ b/core/interpreter/src/main/java/org/overture/interpreter/VDMSL.java @@ -286,7 +286,16 @@ protected ExitStatus interpret(List filenames, String defaultName) } catch (ContextException e) { println("Initialization: " + e); - e.ctxt.printStackTrace(Console.out, true); + + if (e.isStackOverflow()) + { + e.ctxt.printStackFrames(Console.out); + } + else + { + e.ctxt.printStackTrace(Console.out, true); + } + return ExitStatus.EXIT_ERRORS; } catch (Exception e) { @@ -309,7 +318,15 @@ protected ExitStatus interpret(List filenames, String defaultName) } catch (ContextException e) { println("Execution: " + e); - e.ctxt.printStackTrace(Console.out, true); + + if (e.isStackOverflow()) + { + e.ctxt.printStackFrames(Console.out); + } + else + { + e.ctxt.printStackTrace(Console.out, true); + } } catch (Exception e) { println("Execution: " + e); diff --git a/core/interpreter/src/main/java/org/overture/interpreter/assistant/module/AModuleModulesAssistantInterpreter.java b/core/interpreter/src/main/java/org/overture/interpreter/assistant/module/AModuleModulesAssistantInterpreter.java index fa4e8e0600..8104e3d687 100644 --- a/core/interpreter/src/main/java/org/overture/interpreter/assistant/module/AModuleModulesAssistantInterpreter.java +++ b/core/interpreter/src/main/java/org/overture/interpreter/assistant/module/AModuleModulesAssistantInterpreter.java @@ -160,6 +160,13 @@ public Set initialize(AModuleModules m, initialContext.putList(af.createPDefinitionAssistant().getNamedValues(d, initialContext)); } catch (ContextException e) { + if (e.isStackOverflow()) // Stack overflow returns immediately + { + trouble.clear(); + trouble.add(e); + return trouble; + } + trouble.add(e); // Carry on... } } @@ -172,6 +179,13 @@ public Set initialize(AModuleModules m, initialContext.putList(af.createPDefinitionAssistant().getNamedValues(d, initialContext)); } catch (ContextException e) { + if (e.isStackOverflow()) // Stack overflow returns immediately + { + trouble.clear(); + trouble.add(e); + return trouble; + } + trouble.add(e); // Carry on... } } @@ -186,6 +200,13 @@ public Set initialize(AModuleModules m, } } catch (ContextException e) { + if (e.isStackOverflow()) // Stack overflow returns immediately + { + trouble.clear(); + trouble.add(e); + return trouble; + } + trouble.add(e); // Carry on... } diff --git a/core/interpreter/src/main/java/org/overture/interpreter/assistant/module/ModuleListAssistantInterpreter.java b/core/interpreter/src/main/java/org/overture/interpreter/assistant/module/ModuleListAssistantInterpreter.java index 6132b888cb..9c0893a38d 100644 --- a/core/interpreter/src/main/java/org/overture/interpreter/assistant/module/ModuleListAssistantInterpreter.java +++ b/core/interpreter/src/main/java/org/overture/interpreter/assistant/module/ModuleListAssistantInterpreter.java @@ -62,6 +62,12 @@ public void initialize(RootContext ctxt, ModuleList modules, DBGPReader dbgp) if (e != null) { problems.addAll(e); + + if (e.size() == 1 && e.iterator().next().isStackOverflow()) + { + retries = 0; + break; + } } } } while (--retries > 0 && !problems.isEmpty()); diff --git a/core/interpreter/src/main/java/org/overture/interpreter/debug/DBGPReader.java b/core/interpreter/src/main/java/org/overture/interpreter/debug/DBGPReader.java index 08d2c094dc..76c0d3bb5b 100644 --- a/core/interpreter/src/main/java/org/overture/interpreter/debug/DBGPReader.java +++ b/core/interpreter/src/main/java/org/overture/interpreter/debug/DBGPReader.java @@ -460,7 +460,16 @@ public static void main(String[] args) } catch (ContextException e) { System.out.println("Initialization: " + e); - e.ctxt.printStackTrace(Console.out, true); + + if (e.isStackOverflow()) + { + e.ctxt.printStackFrames(Console.out); + } + else + { + e.ctxt.printStackTrace(Console.out, true); + } + RTLogger.dump(true); System.exit(3); } catch (Exception e) diff --git a/core/interpreter/src/main/java/org/overture/interpreter/debug/DBGPReaderV2.java b/core/interpreter/src/main/java/org/overture/interpreter/debug/DBGPReaderV2.java index 30562bfe04..8b9fd9e3d8 100644 --- a/core/interpreter/src/main/java/org/overture/interpreter/debug/DBGPReaderV2.java +++ b/core/interpreter/src/main/java/org/overture/interpreter/debug/DBGPReaderV2.java @@ -542,7 +542,16 @@ public static void main(String[] args) } catch (ContextException e) { System.err.println("Initialization: " + e); - e.ctxt.printStackTrace(Console.out, true); + + if (e.isStackOverflow()) + { + e.ctxt.printStackFrames(Console.out); + } + else + { + e.ctxt.printStackTrace(Console.out, true); + } + RTLogger.dump(true); System.exit(3); } catch (Exception e) diff --git a/core/interpreter/src/main/java/org/overture/interpreter/runtime/Context.java b/core/interpreter/src/main/java/org/overture/interpreter/runtime/Context.java index 7e8ee11eeb..042de828d6 100644 --- a/core/interpreter/src/main/java/org/overture/interpreter/runtime/Context.java +++ b/core/interpreter/src/main/java/org/overture/interpreter/runtime/Context.java @@ -341,7 +341,7 @@ protected String format(String indent, Context what) * @param out */ - private static final int FRAMES_LIMIT = 100; + private static final int FRAMES_LIMIT = 50; public void printStackFrames(PrintWriter out) { diff --git a/core/interpreter/src/main/java/org/overture/interpreter/runtime/ContextException.java b/core/interpreter/src/main/java/org/overture/interpreter/runtime/ContextException.java index 15cd4810c2..10ad511d58 100644 --- a/core/interpreter/src/main/java/org/overture/interpreter/runtime/ContextException.java +++ b/core/interpreter/src/main/java/org/overture/interpreter/runtime/ContextException.java @@ -51,4 +51,9 @@ public String toString() { return getMessage(); } + + public boolean isStackOverflow() + { + return number == 4174; + } } diff --git a/core/interpreter/src/main/java/org/overture/interpreter/scheduler/MainThread.java b/core/interpreter/src/main/java/org/overture/interpreter/scheduler/MainThread.java index 083f53ce7a..31f6782704 100644 --- a/core/interpreter/src/main/java/org/overture/interpreter/scheduler/MainThread.java +++ b/core/interpreter/src/main/java/org/overture/interpreter/scheduler/MainThread.java @@ -91,6 +91,12 @@ private void runCmd() { setException(e); suspendOthers(); + + if (e.isStackOverflow()) + { + e.ctxt.printStackFrames(Console.out); + } + DebuggerReader.stopped(e.ctxt, e.location); } catch (Exception e) { diff --git a/core/interpreter/src/main/java/org/overture/interpreter/values/FunctionValue.java b/core/interpreter/src/main/java/org/overture/interpreter/values/FunctionValue.java index b86a94c50e..78fd197efd 100644 --- a/core/interpreter/src/main/java/org/overture/interpreter/values/FunctionValue.java +++ b/core/interpreter/src/main/java/org/overture/interpreter/values/FunctionValue.java @@ -270,25 +270,6 @@ public String toString() return type.toString(); } - private static Integer stackUnwind = null; - private static final int UNWIND_COUNT = 20; // Needed by printStackFrames - - private ContextException stackOverflow(StackOverflowError e, Context ctxt) - { - if (stackUnwind == null) // First time - { - stackUnwind = new Integer(UNWIND_COUNT); - } - else if (--stackUnwind <= 0) - { - Console.out.printf("Stack overflow %s\n", location); - ctxt.printStackFrames(Console.out); - return new ContextException(4174, "Stack overflow", location, ctxt); - } - - throw e; // Unwind further to make space for printStackFrames - } - public Value eval(ILexLocation from, Value arg, Context ctxt) throws AnalysisException { @@ -299,7 +280,7 @@ public Value eval(ILexLocation from, Value arg, Context ctxt) } catch (StackOverflowError e) { - throw stackOverflow(e, ctxt); + throw new ContextException(4174, "Stack overflow", location, ctxt); } } @@ -312,7 +293,7 @@ public Value eval(ILexLocation from, ValueList argValues, Context ctxt) } catch (StackOverflowError e) { - throw stackOverflow(e, ctxt); + throw new ContextException(4174, "Stack overflow", location, ctxt); } } @@ -337,8 +318,6 @@ public void setClass(SClassDefinition classdef) public Value eval(ILexLocation from, ValueList argValues, Context ctxt, Context sctxt) throws AnalysisException { - stackUnwind = null; - if (uninstantiated) { abort(3033, "Polymorphic function has not been instantiated: " diff --git a/core/interpreter/src/main/java/org/overture/interpreter/values/OperationValue.java b/core/interpreter/src/main/java/org/overture/interpreter/values/OperationValue.java index efd606d345..eff7ea2c47 100644 --- a/core/interpreter/src/main/java/org/overture/interpreter/values/OperationValue.java +++ b/core/interpreter/src/main/java/org/overture/interpreter/values/OperationValue.java @@ -255,25 +255,6 @@ public void prepareGuard(ObjectContext ctxt) } } - private static Integer stackUnwind = null; - private static final int UNWIND_COUNT = 20; // Needed by printStackFrames - - private ContextException stackOverflow(ILexLocation location, StackOverflowError e, Context ctxt) - { - if (stackUnwind == null) // First time - { - stackUnwind = new Integer(UNWIND_COUNT); - } - else if (--stackUnwind <= 0) - { - Console.out.printf("Stack overflow %s\n", location); - ctxt.printStackFrames(Console.out); - return new ContextException(4174, "Stack overflow", location, ctxt); - } - - throw e; // Unwind further to make space for printStackFrames - } - public Value eval(ILexLocation from, ValueList argValues, Context ctxt) throws AnalysisException { @@ -299,7 +280,7 @@ public Value eval(ILexLocation from, ValueList argValues, Context ctxt) } catch (StackOverflowError e) { - throw stackOverflow(from, e, ctxt); + throw new ContextException(4174, "Stack overflow", from, ctxt); } }