We help IT Professionals succeed at work.

Sun's JVM and memory size

omers
omers asked
on
Hi,

Is there a way to tell the Sun JVM that it can take as much memory as needed (preferred dynamically but any way will help) ?

Our Java2 applet can sometimes require 100s of megas.

The -Xmx parameter is very inconvenient : It must be changed individually on every client machine, and doing this automatically is not easy as we need to find the exact amount of memory on that client and update the JVM params. And also consider memory upgrades when this Xmx has to be updated etc.

There must be a simpler way !?

The (late) Microsoft JVM handled this nicely, simply dynamically allocating the heap etc. as required by the application.

Thanx in advance, Omer.
Comment
Watch Question

Mick BarryJava Developer
BRONZE EXPERT
Top Expert 2010

Commented:
> It must be changed individually on every client machine

How else would you like to do it?


Sun's JVM in fact does take as much memory as need (dynamically) up to the maximum specified by -Xmx.

Author

Commented:
I want the JVM to take as much memory as it needs, and not more than the system has to offer - just like any other prog !

Without having the need to specify any parameter on every client. This need contradicts the "thin client" paradigm - the client user is dumb, he doesn't know how to update this parameter !

And this was the situation with the microdoft JVM.

Argh !!!!
Mick BarryJava Developer
BRONZE EXPERT
Top Expert 2010

Commented:
Not having a rampant program overtaking your boxes memory could actually be seen as a feature. Especially if their are more than one person using that box.

Why don't you just distribute a batch file for everyone that includes a large -Xmx.

Author

Commented:

Author

Commented:
objects,

Thanx for the help.
The problem is that a too high -Xmx can degrade performance severely once memory swaps start takingplace.

So I cannot just execute a batch file, I need to find out the real memory size, which is also not trivial with JDK1.3 (but better with JDK1.4).

And I need to reinstall when memory amount is changed..

Omer.

Mick BarryJava Developer
BRONZE EXPERT
Top Expert 2010

Commented:
> The problem is that a too high -Xmx can degrade
> performance severely once memory swaps start takingplace.

Now I'm confused, you want to let the process grow in size as needed, but you're also concerned about memory swapping.
I thought you wanted the JVM to grow as big as it needed to?

If you still want to limit the size the JVM grows to, but you want to make this size dependant on the memory available then look for a DOS utility that reports the amount of physical memory, and use this value in a batch file to caculate your mx value.





Author

Commented:
objects,

Somehow the problem did not rise with the MS JVM (Sheesh, am I praising MS ?) - it did not start swapping as well, maybe the MS JVM did just that - check the real memory etc.

Running a DOS util and then updating the file is exactly the thing I wanted to avoid, it is inconvenient with thousands of computer-illiterate users that will be frightened by a new dialog box they have never seen.

Thanx anyhow.
Java Developer
BRONZE EXPERT
Top Expert 2010
Commented:
What do you need a dialog box 4?
U just need your batch file to determine the amount of physical memory, and then calculate a suitable value for mx.

Author

Commented:
Hi objects,

Sorry for the delay,

Theoretically, such a batch file that will change the mx value in some file must have priviliges granted by the user, no ???

This is what we had in mind, it is strange that Sun has not yet come with a solution, can't be we are alone with this problem.

Do you know of such a common ready-made util that queries memory size and changes the file ?

Thanx for the help, the answer is not what I wanted it to be, but I guess it's not your fault :-)

Omer.
Mick BarryJava Developer
BRONZE EXPERT
Top Expert 2010

Commented:
No you just calculate your mx file inside the batch file.

set SIZE=...
java -xMx%SIZE% ...

The current setup from Sun where the JVM's heap sizes adjusts according to it's needs has always worked fine for me. And I don't think the intention of it is to be set according to the amount of memory available in the box, but rather the amount of memory required by the application (but I could be wrong).
The only time it may have problems is if you try to run an app with a big memory requirment on a box without much memory. But this is always going to give you problems.

Do the apps that your having trouble with require a lot of memory?

(Thanks for the points)

Author

Commented:
> Do the apps that your having trouble with require a lot of memory?

typical 200Megs, up to 500-1000Megs - we do not know beforehand how much, it depends what data the user loads in our applet (medical images of radiological scans)

And this is the whole problem - the user knows he cannot load more than the memory he has, and we want the JVM to occupy that without having to set it.

If we set it too high the JVM refuses to load if it fails to allocate it.

Thanx, Omer.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.