This discussion is archived
5 Replies Latest reply: Aug 24, 2012 2:41 AM by RenévanWijk RSS

Why Can't I allocated more than 128m as stack Size

956919 Newbie
Currently Being Moderated
There is a requirement of high stack size in the application but when I try to set the stack size > 128m , I get the below error

[ERROR] Argument error: -Xss130m
[ERROR] -Xss: Stack size too large
Could not create the Java virtual machine.

Is there a upper limit of 128m on stack size. The Jrockit version is 64 bit.

Please help
  • 1. Re: Why Can't I allocated more than 128m as stack Size
    Kalyan Pasupuleti-Oracle Expert
    Currently Being Moderated
    Hi,

    Are you running OS in 32 bit or 64 bit.
    eg:

    O/S 32-bit Default 64-bit Default

    Windows 64 kB 320 kB

    Linux 128 kB 1 mB


    Please check your stack size you mentioned it is 128m please change to KB it will work.

    Regards,
    Kal
  • 2. Re: Why Can't I allocated more than 128m as stack Size
    956919 Newbie
    Currently Being Moderated
    The application require a High Stack Size , may be greater than 128MB.

    It is a 64 Bit OS but when I give a value higher than 128MB , if fails. I am looking for reasons.
  • 3. Re: Why Can't I allocated more than 128m as stack Size
    RenévanWijk Oracle ACE
    Currently Being Moderated
    Are you sure you want to set the stack size to 128m?

    The -Xss flag specifies how much stack each thread should be allocated. Thread
    stacks are the memory areas allocated for each Java thread for their internal use.
    This is where the thread stores its execution state. It normally makes little sense to
    increase this size, unless there is plenty of recursion or a large amount of stack local
    information. The default stack size varies between platforms
    - http://docs.oracle.com/cd/E15289_01/doc.40/e15062/optionx.htm#BABIHAFH
    StackOverflowError(s) in a Java program might be resolved by using larger thread
    stacks, unless they are the product of infinite recursion. Are you experiencing such
    type of errors?

    Note that with your setting it means that each thread allocates 128m. The following will happen (a little schematic)

    ---- Memory (total present in the machine)

    ---- Operating System Memory (and maybe other processes that consume memory)

    ---- Java Memory (JVM Memory)


    ---- Java Stack (Xss per thread)

    ---- Metadata (Classes etc.)

    ---- Maximum Heap (Xmx)



    ---- Initial Heap (Xms)


    ---- 0

    Note that when you have a lot of threads (each taking 128m) you could get into memory problems.

    Note that the Operating System you are running on has a stack size setting. In general the Operating System maximum per process
    stack size is available from the ulimit shell command, for example,
    # ulimit -all
    core file size          (blocks, -c) 0
    data seg size           (kbytes, -d) unlimited
    scheduling priority             (-e) 0
    file size               (blocks, -f) unlimited
    pending signals                 (-i) 24055
    max locked memory       (kbytes, -l) 64
    max memory size         (kbytes, -m) unlimited
    open files                      (-n) 8192
    pipe size            (512 bytes, -p) 8
    POSIX message queues     (bytes, -q) 819200
    real-time priority              (-r) 0
    stack size              (kbytes, -s) 8192
    cpu time               (seconds, -t) unlimited
    max user processes              (-u) 24055
    virtual memory          (kbytes, -v) unlimited
    file locks                      (-x) unlimited
    The stack size here is 8192kB. When on Linux     the stack can be set by the parameter ‘stack’ (KB) in file /etc/security/limits.conf.
    When you want a stack of 128m, you can set stack to 131072 (128*1024). You can also use ulimit -s 131072 (but this is temporary).
  • 4. Re: Why Can't I allocated more than 128m as stack Size
    956919 Newbie
    Currently Being Moderated
    ulimit -s gives 10 mb in my machine . But I am able to allocate till 128 MB . What is the relation between 10 MB and 128 MB.

    I know the stack size requirement is very high ( probably because of high recursions) but I need to test the application with more that 128 mb , say 150 MB. Currenly I don't know as to how set up it to 150 MB.
  • 5. Re: Why Can't I allocated more than 128m as stack Size
    RenévanWijk Oracle ACE
    Currently Being Moderated
    To my knowledge Linux does expand the stack space as needed. Note that the stack is stored contiguously in memory, and if it grows too big, it
    will start overwriting the heap. Increasing the stack size would involve moving the heap, which would invalidate every single heap pointer in
    the program. If your program is expected to use a lot of stack, provide a safe margin up front. The stack limit basically keeps the stack from overwriting
    the heap. It also keeps an infinite recursion from eating all your memory and crashing your system (setting an unlimited stack size (ulimit -s unlimited) will
    probably remove that protection). Some more insight in the stack can be found here: http://linuxgazette.net/112/krishnakumar.html

    Some experiments. First with HotSpot:
    ./java -Xss1500m -version
    java version "1.6.0_31"
    Java(TM) SE Runtime Environment (build 1.6.0_31-b04)
    Java HotSpot(TM) 64-Bit Server VM (build 20.6-b01, mixed mode)
    
    ./java -Xss15000m -version
    Error occurred during initialization of VM
    java.lang.OutOfMemoryError: unable to create new native thread
            at java.lang.Thread.start0(Native Method)
            at java.lang.Thread.start(Thread.java:640)
            at java.lang.ref.Reference.<clinit>(Reference.java:145)
    Now with JRockit:
    ./java -Xss1500m -version
    [ERROR] Argument error: -Xss1500m
    [ERROR] -Xss: Stack size too large
    Could not create the Java virtual machine.
    
    ./java -Xss128m -version
    java version "1.6.0_29"
    Java(TM) SE Runtime Environment (build 1.6.0_29-b11)
    Oracle JRockit(R) (build R28.2.2-7-148152-1.6.0_29-20111221-2104-linux-x86_64, compiled mode)
    Looks like JRockit itself has a protection, for creating (too) large a stack per thread (somehow I like this)

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points