Stack size

How do I set a larger stack size in the HotSpot client?

I've programmed a really simple recursive program, but it only gets through about 5500 recursions. I'm working on an algorithms project, so I need to be able to call a procedure recursively tens of thousands of times without the Stack overflowing. It looks like there's no easy way to increase the stack size, and only allowing 5500 basically empty recursions is really pathetic.

Any help very much appreciated.

Todd

[507 byte] By [toddobryan92103] at [2007-9-26 11:42:54]
# 1
I think this is an OS dependent issue. HotSpot uses the native stack.
jodamoju at 2007-7-2 1:51:59 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 2

I've tried both Mac OSX (my home machine) and a Solaris server (at school). Strangely, my Mac gets a deeper level of recursion before the Stack overflows (roughly 5500 levels versus only about 4500 on Solaris). Both of these are pretty pathetic (at least according to my algorithms teacher).

Todd

toddobryan92103 at 2007-7-2 1:51:59 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 3
c:\> java -X... -Xss<size>set java thread stack size...looks like what you want.-ed
eporter at 2007-7-2 1:51:59 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 4

Apparently that option doesn't actually do anything with HotSpot. I crash with the same number of level of recursion with

java -100M StackOverflowor

java -1b StackOverflow.

The StackOverflow.java file is just:

public final class StackOverflow {

private static int depth;

public static void main(String[] args) {

try {

depth = 0;

method();

} catch (StackOverflowError err) {

System.out.println(err);

}

System.out.println("depth: "+depth);

}

public static void method() {

depth++;

method();

}

}

Other people, using C and C++ are getting similar pathetic results so it may be that the stack size is fairly small. Anybody know of a way to increase the possible stack size on a Unix machine?

If not, I may have to do the project in Perl (kinda makes you shiver, doesn't it).

Thanks all,

Todd

toddobryan92103 at 2007-7-2 1:51:59 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 5

Interesting question.

I tried running your example program on JDK 1.4 on Linux with and without hotspot, and with and without the Xss parameter. In all cases I get a segmentation failure somewhere between 500 and 600 calls to method().

However on IRIX 6.5 using JDK 1.3 and the SGI mips jit with the standard parameters I get a StackOverflowError at 130867 calls to make.

I don't have the jdk 1.3 for Linux installed so I cannot cross check.

tychoS at 2007-7-2 1:51:59 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 6

Todd,

I tested your code on Solaris 8 and JDK 1.3.1 and got it to work

for a large number of method calls by tweaking both the java

and unix stack size limits.

The java stack size depends on the system(shell) defined stack segment size.

1) using the default 8M stack size set (from ulimit)

#ulimit -s

8192

#java StackOverflow

java.lang.StackOverflowError

depth: 4446

# java -Xss8M StackOverflow

java.lang.StackOverflowError

depth: 80065

#java -Xss16M StackOverflow

Stack size of 16384 Kb exceeds current limit of 8192 Kb.

(Stack sizes are rounded up to a multiple of the system page size.)

See limit(1) to increase the stack size limit.

2) Increase the uniz(shell) stack size to 16M.

#ulimit -s 16384

#ulimit -a

....

stack(kbytes)16384

...

#java StackOverflow<

java.lang.StackOverflowError

depth: 4449

#java -Xss16M StackOverflow<

java.lang.StackOverflowError

depth: 160727

As you can see by changing the default stack size (both at the

unix shell level and java arguments), you can achieve the

desired result.

Hope this helps.

Cheers!

Sun-DTS

jdcusr1 at 2007-7-2 1:51:59 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 7
Please ignore some small typos in my last posting..uniz,and '<' at the end of java cmd line^--> x Thanks!
jdcusr1 at 2007-7-2 1:51:59 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 8

Note 1:

on Linux, (RH 7.2, JSE 1.4.2_02) the "limit stack size" has no effect unless you make the stack too small to even load the JVM

the -Xss flag does work (up to some limit)

On Windows, NOTHING effectively changes the stack size,

-Xss999 fails to load

-Xss1000 is the same as the default, as is:

-Xss1000000

so the only control is >= 1000

Sun should provide an explicit and well documented way of :

1) using all of the available stack on any architecture

2) limiting the stack size effectively (i.e. incrementally) via a flag

Apperson at 2007-7-2 1:51:59 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 9

-Xss option's usage

1. usage : -Xss<size>m or -Xss<size>k

2. example : -Xss10m, -Xss128k

how about execution the method, method(), in multi-thread ?

in one thread, it will be same result-stackoverflow error.

but if method() can be run individual thread, is it possible?

dhseong at 2007-7-2 1:51:59 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 10
What I've been finding is that the -Xss option only seems to affect threads other than the main thread (at least for 1.4.2)
grubbyfoobar at 2007-7-2 1:51:59 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 11

Most of time you can achieve better perfromance of your algorithm (though with slightly more code) if you get rid of recursion, especailly in cases where extremely deep recursion is happening. Performance gain is even more impressive in Java than in C/C++. I can help if you describe your particular case.

elizarov at 2007-7-2 1:51:59 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 12

Hey All,

I have been having a problem related to the stack and heap size (see [url=http://forum.java.sun.com/thread.jsp?forum=37&thread=486077&start=0&range=15]my posting[/url] for more details) and I have been following a number of forums relating to the -X options, but I have never successful managed to configure the -X options to run my program.

When I reduced the memory requirements of the C code (by reducing the array sizes, see [url=http://forum.java.sun.com/thread.jsp?forum=37&thread=486077&start=0&range=15#2279755]here[/url]) called by the JNI, the code worked but when I increased the JVM memory, it didn't make any difference. It doesn't add up in my head! Surely it should have worked?

This makes me wonder if the -X option work at all. I am using windows 2000 and java version "1.4.2_01" and I tried a series of combinations of the -X options. None worked.

I would apreciate any comments regarding this,

Thanks,

Stef

stefarg at 2007-7-2 1:51:59 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 13

Hi All

I am executing a script file on a unix box, getting the following error

"

Stack size of 8200 Kb exceeds current limit of 8192 Kb.

(Stack sizes are rounded up to a multiple of the system page size.)

See limit(1) to increase the stack size limit.

"

the script goes something like this

java -Xss8192k -Xms128m -Xmx640m -classpath .....

As you can see the stack size is set to 8192 also ulimit gives me 8192 ...

Not sure from where is it getting the number 8200

Went through all the posts in this section.. am not able to find a sure shot way ...

Kallol

Kallol_Bose at 2007-7-2 1:51:59 > top of Java-index,Java HotSpot Virtual Machine,Specifications...