Stack Overflow issue: is there a limit?
We have a COBOL program that was migrated from Bull mainframe syntax to Visual COBOL. It took some work to get it to run, because not all of the code is "optimal". It's over 17,000 lines, and calls other assemblies. We had to go away from Perform Thru using Sections in some parts, back to using GOTO to get it to run using Visual COBOL.
One of the other changes we made was to increase the stack size, using a compiler directive. Initially, we went to 200 megs (200 X 1024 X 1024) after receiving a stack overflow exception using the Visual COBOL default settings. After a couple of weekly runs, we experienced a Stack Overflow exception again. Since it was in production, and we needed the run for that night, the stack was increased to 300 megs. This happened a couple of times, until this last week it was increased to 500 megs. This has been the solution to a stack overflow without rewriting the program, which would be a daunting task. The compiler directive is this: $SET ILSTACKSIZE(524288000)
I realize that rewriting the program is the way to go. But for the time being, is there an upper limit to how big I can increase the stack size to? Is there an upper limit when this will no longer be an option?
Also, is there a way to monitor the stack size of a program, during execution? That way we might have an idea of what might be causing it, and when the stack size is getting too large and will need to be increased soon.
RE: Stack Overflow issue: is there a limit?
There can be a problem with this type of program where there may be overlapping perform ranges or GO TO statements that jump out of one section and into a different one, when compiling for managed code. This is because behind the scenes the compiler is generating these sections and paragraphs as OO methods and if there is no logical place to split these sections into methods then it will include the entire range within one large method which can cause this type of stack overflow you are seeing.
We would recommend that you try compiling with the directive PERFORMTYPE”OSVS” to see if you get a better behavior. If you still get a stack overflow then you can use the directives RESTRICT-GOTO and ILSHOWPERFORMOVERLAP to help you find the problem areas in your program. If the program is large like you say then there might be quite a few offending lines of code. I have seen cases where a single GO TO out of a performed section to the exit paragraph of a different section could cause a stack overflow condition.
If you would like help diagnosing this problem then please open up a support incident with customer care and attach this program and copybooks (or .lst file compiled with RAWLIST) to the incident so that we can take a look at it.