I am getting a java.lang.StackOverflowError
, when I execute a Scala program.
I believe that the stack size can be set with -DXss=n
, but it does not work
on my system:
Scala compiler version 2.7.7final and
Linux 2.6.38-8-generic #42-Ubuntu
The attached program witnesses the problem on my system.
// scalac StackOverflow.scala
// scala StackOverflow 6000
// scala -DXms=200M -DXmx=200M -DXss=200M StackOverflow 6000
object StackOverflow {
def recur(k: Double): Double = {
// check effects of various commands
println(k)
// try to prevent tail recursion
if (k>0) return recur(k-1)+k/(k+1)
else return 0.0
}
def main(args: Array[String]) {
if (args.length == 0) println("Missing argument");
val k = args(0).toInt+0.1
recur(k)
}
}
Sergio
You may need to increase the stack size if your program gets stack-overflow messages at runtime. You can also set the stack size by: Using the /STACK linker option. For more information, see /STACK (Stack allocations).
To increase the stack size, define the new value in the -Xss setting in the JAVA_OPTS entry in your Tomcat start script file (/opt/netiq/idm/apps/tomcat/bin/setenv.sh or C:\NetIQ\idm\apps\tomcat\bin\setenv. bat). For example, to set the stack size to 4M, change the setting to -Xss4M.
Rhai, by default, limits function calls to a maximum depth of 64 levels (8 levels in debug build). This limit may be changed via the Engine::set_max_call_levels method. A script exceeding the maximum call stack depth will terminate with an error result.
Sets the maximum stack size for Java™ threads. The default is 320 KB for 31-bit or 32-bit JVMs and 1024 KB for 64-bit JVMs. The maximum value varies according to platform and specific machine configuration. If you exceed the maximum value, a java/lang/OutOfMemoryError message is reported.
I think what you want is scala -J-Xss200m
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With