Communicator e3000 MPE/iX Release 6.0 Express 1 (C.60.01) (30216-90286)
Chapter 3 51
Technical Articles
Java Developers Kit for MPE/iX Version 1.1.7B Release Notes
• At start-up, the VM will determine what ;NMSTACK= value is in effect, and will allow
allocation of as many thread stacks as will fit within this limit. When the limit is
exceeded, an OutOfMemoryException will be thrown. The default ;NMSTACK= value of
2MB for the POSIX shell means that approximately three threads can be created before
a larger ;NMSTACK= will need to be specified by the user. This is enough to run the javac
java compiler and non-threaded java programs. Programs that use AWT create several
internal threads and will require a larger VM STACK. The JAVA executable has a
default NMSTACK of 10MB, which will be in effect if the VM is invoked directly from the
CI, and should be enough for most applications.
• Ordinary thread stacks have been reduced from 1MB to 128KB in size. The JIT now has
its own dedicated stack which is sized as needed by the particular JIT version.
• Functions like Runtime.exec are now able to successfully fork from inside the VM.
Setting the NMSTACK Size for the Java VM Process
As noted above, it is no longer necessary to run the shell with a 40 million byte stack limit
in order to then run Java. Programs which need to create a large number of threads will
need a larger stack limit.
When a process is created in the “MPE style” by calling the CREATE or CREATEPROCESS
intrinsics, the new process will have its ;NMSTACK= limit set by the default value linked
into the program file, unless it is overridden by a CREATEPROCESS option. So if you are
invoking the Java VM directly from the CI through a command file like JAVA.PUB.SYS, or
the :RUN command, the new VM process will get the 10MB NMSTACK value of the JAVA
executable, which should be enough for approximately 65 threads.
When a new process is started via the POSIX fork and exec sequence, the new son
process inherits the NMSTACK limit of its father process. The NMSTACK limit of the last
process that was created by CREATE[PROCESS] affects all forked descendants of that
process. To see why, we have to look at what fork and exec do. fork creates a new process
that is an exact copy of the calling process, so obviously it should and must have the same
NMSTACK limit as the old process that it is a copy of. Once the fork is complete, exec is
called to change the program being executed by the process from the copy of the original to
the new program we wish to run. Unfortunately at this point the stack for the process has
been set up (based on the copy of the original process) and there is no opportunity to
change it, even if the new program would like to specify a different limit.
When executing program from inside the POSIX shell, the fork and exec sequence is used
by the shell (and most other “POSIX” type programs), which means that the same NMSTACK
limit will apply to every one of these processes. This means that whatever ;NMSTACK= was
in effect when you entered the shell from the CI using the :RUN SH.HPBIN.SYS command
(or equivalent) will apply to everything (like Java) that you run from inside the shell.
If you will be invoking Java from within the shell, and you need more than approximately
three threads for your program. Then you will need to arrange to have specified a larger
;NMSTACK= value when you ran the first shell. Java requires approximately 1.5MB of
NMSTACK for a single thread program, and 128KB more for each additional thread.
If you want to use 100 simultaneous threads in your Java program, you would want to
enter the shell with a command such as:
:RUN SH.HPBIN.SYS;INFO=”-L”;NMSTACK=14000000