Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to increase scala stack size?

Tags:

stack

scala

size

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

like image 904
Sergio Avatar asked Jul 06 '11 04:07

Sergio


People also ask

Can stack size increase?

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).

How to increase stack size in java?

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.

What would be the maximum depth of the call stack?

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.

What is the maximum stack size for Java?

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.


1 Answers

I think what you want is scala -J-Xss200m

like image 73
Joseph Shraibman Avatar answered Sep 21 '22 21:09

Joseph Shraibman