Simultaneously run Java Virtual Machines - java

I am trying to run some different Eclipse RCP implementations simultaneously, and I receive the following error message: "Java was started but returned exit code=1".
I understand that happens when a xmx or xms parameter greater than between 1.2 and 1.8 GB is set (this quantity depends on the machine). But my problem is not only how big is this parameter for a single machine, I don't always receive this error message when I am trying to execute more than one virtual machine at the same time, I don't know which conditions are evaluated by the java virtual machine in order to launch this error message.
Do you know how could I see which conditions are evaluated from the Java VMs in order to launch this error message? This way I could establish the right xmx and xms parameters.
Thank you for your time.

The JVM needs a continuous memory space to have its Object Heap allocated.
Trying to have more than one JVM in execution at a time, makes quite more difficult to find such a memory block. Even by having free GBs of memory.
I found the answer here:
Tools to view/solve Windows XP memory fragmentation

Related

Check Java JVM Memory Limit on Windows XP

I want to see how much memory is allocated to my Java JVM on my Windows XP installation. I'm running an executable jar that has a main class that makes some JNI calls to a C library via a dll that is loaded using the System.loadLibrary("SampleJni"). Some calls are working and some are not. Whenever there are more than one String parameters passed I get a system dump. If I just have one String, one int, two ints..etc, no crashes. The machine only has .99 GB of ram, so I'm thinking the JVM can't allocate the need memory.
Use jconsole to check the memory used by your program. Jconsole comes with the JDK so you already have it. This memory won't include memory used by your JNI C code, but it will tell you what memory Java is using. Your more likely culprit is JNI mapping isn't correct when using multiple parameters.
I've run JVMs (Java 6) on machines with less memory than that. IIRC the default for the JVM on windows was 64Mb, but that may have changed. Even if it did, it should be enough to start up. You'd also see OutOfMemoryErrors if this were the case rather than hard crashes.
There are various methods in java.lang.Runtime that will let you inspect how much memory you have.
The likely cause is the JNI interface. Its very easy to crash the JVM if the JNI code isn't 100% correct.

how to increase java memory (algorithms runs on ubuntu but not on mac; same machine configuration)

Recently I've been getting the notorious error message: OutOfMemoryError. I've a 64Bit Mac with 16GB Ram and 2X2.6 GH quad core. Getting this error message simply doesn't make sense to me because the same algoritm that I'm running (that causes this error message) is running smoothly on another machine (ubuntu 16GB Ram).
System.out.println(java.lang.Runtime.getRuntime().maxMemory());
When I run the above code on my mac I get: 129,957,888 (without the comma of course :-))
And when running this code on the ubuntu machine I get: 1,856,700,416
Can anyone tell me how I can increase my max memory in order to run my algorithm? Thanks!
I tried to set on my eclipse: default VM arguments -Xms512m -Xmx4g, but nothing changed.
-Xmx and -Xms are the correct arguments to the java command to change heap size, but Eclipse has to be configured differently.
You're going to have to elaborate. Are you running a test in Eclipse, or outside of Eclipse? Just passing the "-Xmx" parameter to Eclipse won't do what you want, even if you do it in the correct way to actually change the max mem value for Eclipse (that requires prefixing it with "-vmargs"). If you want to change the max mem value for the forked JVM that's running your algorithm, you have to change the parameters in the run configuration.
It looks like matt b has this one covered. I just wanted to mention that you might not want to set the max heap size as high as 4GB unless your program will really need that much. From what I understand the JVM allocates all of that memory for itself when it starts, and then uses it to run code as needed. Making it allocate that much memory might cause performance problems with other applications you're running. Instead, try stepping it up in increments of 128MB, or more if your code takes a long time to fail. Alternatively, maybe you can use a memory profiler to see how much space you actually use? I have no idea if such a thing exists.
This is probably not a problem on your setup, but for mere mortals like me, blithely allocating that much memory could be problematic.

How many JVM we can have in one machine?

I have a class that run infinit (do nothing, just loop and sleep), called NeverReturn. I try to run it using following command in Windows XP 32bit:
java -Xms1200M NeverReturn
I find with the command I can create only 4 java instance at same time. The 5th and next java command will failed to create jvm.
If I change the command to -Xms600M, I can create 8 java instance. The 9th will failed.
Could anyone explain that? I'm using sun jdk1.6 update 23 and jdk1.5 update 22.
If you have four instances of the JVM each using 1200M of memory, that gives you 4800M of memory allocated.
If you have eight instances of the JVM each using up to 600M of memory, that gives you 4800M of memory as well.
If I had to guess, it looks like the problem is that you're trying to promise more memory to the JVM instances than exists on your system. Dropping the amount of memory you promise should have a corresponding increase in the number of instances you can run.
Simple answer:
as many JVMs as you want; of course as long as your machine can provide the necessary resources (read memory).
If you wanted to ask how many JDK/JREs you can use in a machine (different JDK/JRE versions); the answer is "there is no constraint".
So you can have many JDKs as well, I am not sure of the windows installers though. You can always choose to use a dump instead.
Hope this helps.
For every instance of the virtual machine launched in this way, 600 MB of memory is dedicated to it, meaning if you only had 1 GB of memory, you could only successfully launch one instance of JVM if you allowed each instance to consume 600 MB of memory. By the sounds of it, you had roughly 4.6 GB of memory free at the time of running 8 instances of 600 MB each.

java heap space problem in remote desktop

I have remote logged into my machine and trying to start tomcat server. But, I get the following error.
Error occurred during initialization of VM
Could not reserve enough space for object heap
Could not create the Java virtual machine.
Apparently there are some memory restrictions when logged into remote desktop. Is there any way I can start the tomcat from RDP?
Thanks
Remote desktop could be causing the problem if you are using a 32-bit system. Java requires a single continuous block of memory to start Java. If you start Java with close to the maximum amount of memory, whether you get that memory as a single block depends on what you have already running on that server.
Solutions include
start Java as a service on start up.
use a 64-bit version of the OS and Java.
use less memory in the JVM, even 100 Mb could make a difference.
increase the amount of main memory in the machine.
In starting up the Tomcat server, you can change the program parameters when running Java. You can add to the VM arguments -Xmx###m to a smaller number that may work on your machine. Also, you may want to see if you're running other memory intensive Java apps.

Unexpected JVM behaviour on 64bit linux

i tried to compare my java web app behaviour on 32 bit windows and 64 bit linux.
When i view the memory usage via jconsole i find very different graph of memory usage.
On windows the appl never touches 512m.
However when i run on linux 64bit with 64 bit VM the memory keeps invcreasing gradually and reaches peak value about1000m very quickly and i also get oome error related to GC over head limit exceeded. on linux whenever i do manual run GC it drops below to less than 100m.
Its like the GC does seem to run so well as it does on windows.
On windows the app runs better with even more load.
How do i find the reason behind this?
Iam using jdk1.6.0.13
min heap:512m and max heap 1024m
EDIT:
Are you using the same JVM versions on both Windows and Linux?
yes.1.6.0.13.
Are you using the same garbage collectors on both systems?
I noticed in jconsole and i see that the gc are different.
Are you using the same web containers on both systems?
yes.Tomcat.
Does your webapp rely on native libraries?
Not sure. I use tomcat+spring+hibernate+jsf.
Are there other differences in the configuration of your webapp on the two platforms?
No
What exactly was the error message associated with the OOME?
java.lang.OutOfMemoryError: GC overhead limit exceeded
How long does it take for your webapp to start misbehaving / reporting errors on Linux?
The difference in usage pattern is seen after i leave it running for say 3hrs. The error appears after like a day or 2 days since by then avg memory usage is seen around 900 mb mark.
A 64bit JVM will naturally use a lot more memory than a 32bit JVM, that's to be expected (the internal pointers are twice the size, after all). You can't keep the same heap settings when moving from 32bit to 64bit and expect the same behaviour.
If your app runs happily in 512m on a 32bit JVM, there are no reasons whatsoever to use a 64bit JVM. The only rationale for doing that is to take advantage of giant heap sizes.
Remeber, it's perfectly valid to run a 32bit JVM on a 64bit operating system. The two are not related.
There are too many unknowns to be able to explain this:
Are you using the same JVM versions on both Windows and Linux?
Are you using the same garbage collectors on both systems?
Are you using the same web containers on both systems?
Does your webapp rely on native libraries?
Are there other differences in the configuration of your webapp on the two platforms?
What exactly was the error message associated with the OOME?
How long does it take for your webapp to start misbehaving / reporting errors on Linux?
Also, I agree with #skaffman ... don't use a 64bit JVM unless your application really requires it.

Categories