Java error - how to increase stack size in Eclipse?

I am running a program written in Java in Eclipse. The program has a very deep recursion level for very large inputs. For small inputs, the program works fine, but when large inputs are given, I get the following error:

Exception in thread "main" java.lang.StackOverflowError 

Can this be solved by increasing the size of the Java stack, and if so, how to do it in Eclipse?

Update:

@Jon Skeet

This code recursively traverses the parse tree to create a data structure. So, for example, the code will do some work using node in the parsing tree and call itself in node two children, combining their results to give a common result for the tree.

The overall depth of the recursion depends on the size of the parsing tree, but the code seems to fail (without a larger stack) when the number of recursive calls hits 1000.

I am also sure that the code does not fail due to an error, as it works for small inputs.

+54
java eclipse stack-overflow jvm jvm-arguments
Jan 24 '10 at 13:35
source share
7 answers

Open Run Configuration for your application (Run / Run Configurations ..., then find the application entry in the "Java Application").

On the arguments tab there is a Vm arguments text box, enter -Xss1m (or a larger parameter for the maximum stack size). The default value is 512 kB (SUN JDK 1.5 - I donโ€™t know if it depends on suppliers and versions).

+72
Jan 24 '10 at 13:52
source share

It can be cured by increasing the size of the stack, but the best solution would be to work out how to avoid recursion. A recursive solution can always be converted to an iterative solution that will greatly improve the scale of your code. Otherwise, you will really guess how much stack to provide, which may not even be obvious from the input.

Are you absolutely sure that this is not because of the size of the input, and not because of an error in the code, by the way? How deep is this recursion?

EDIT: Well, after seeing the update, I will personally try to rewrite it to avoid using recursion. Generally, having a Stack<T> โ€œthings that still doโ€ is a good starting point for removing recursion.

+37
Jan 24 '10 at 13:40
source share

Add the -Xss1024k flag to the VM arguments.

You can also increase the stack size in mb using -Xss1m , for example.

+9
Jan 24 '10 at 13:39
source share

i also has the same problem when parsing schema definition files (XSD) using the XSOM library,

i managed to increase the memory stack to 208 MB, then it showed heap_out_of_memory_error , for which I could only increase to 320 MB.

the final configuration was -Xmx320m -Xss208m , but then again it took some time and failed.

My function recursively prints the entire schema definition tree, it is surprising that the output file crossed 820 MB for the 4 MB definition file (Aixm library), which in turn uses the 50 MB protocol definition library (ISO gml).

with this, I am convinced that I need to avoid Recursion, and then start iteration and another way of presenting the output, but I have few problems converting all this recursion to iteration.

+5
Mar 09 2018-11-11T00:
source share

To configure JVM parameters, you need to have a startup configuration in Eclipse.

After starting your program with F11 or Ctrl-F11, open the run configuration in Run โ†’ Run Configurations ... and open your program in the "Java Applications" section. Select the Arguments panel, where you will find the VM Arguments.

Here -Xss1024k goes.

If you want the launch configuration to be a file in your workspace (so you can right-click and run it), select the "General panel" and select the "Save as โ†’ General file" checkbox and navigate to the location of the launch file. I usually use them in a separate folder, as we test them for CVS.

+3
Jan 24 '10 at 13:51
source share

If the -Xss argument -Xss not complete the task, try deleting the temporary files from:

 c:\Users\{user}\AppData\Local\Temp\. 

It helped me.

+2
Jul 17 '13 at 8:57
source share

Look at Morris tree traversal in order, which uses constant space and runs in O (n) (up to 3 times longer than your usual recursive traversal, but you save a lot of space). If nodes can be modified, you can save the calculated result of the subtree as you return to its root (by writing directly to Node).

0
Feb 27 '15 at 10:53
source share



All Articles