How can I tell JVM to use as much memory as you can?

If I specific a -Xmx value bigger than what VM can get, it will just refuse to start. How can I tell VM to use as much memory as system have?
[148 byte] By [carfielda] at [2007-11-26 22:09:17]
# 1
I would guess you would have to deal with that outside of the VM. Create an OS loop and increase the size until it fails.Noting of course that just because it accepts a value for Xmx doesn't mean that the VM will be able to use that much memory.
jschella at 2007-7-10 10:55:55 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 2
> I would guess you would have to deal with that> outside of the VM. Create an OS loop and increase> the size until it fails.> That would be very tedious to do... however if that the only way then I have to accept...
carfielda at 2007-7-10 10:55:55 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 3

Hi,

A few years ago at JavaOne (it was maybe 2003?) I was on stage during the HS BOF. A developer asked "why do I have to explicitly set my heap size? can't you just look at how much memory my machine has and just take 90% of it?" (which is what you're asking...).

At that moment (and in answer to your question) another developer gets up and says "don't do this! I run 30 VMs on my machine, if you do this my machine will grind down to a halt."

To elaborate a bit more: the HotSpot JVM runs on many different platforms and in many different environments. And we feel that, if we simply take over a machine's memory, in many environments this would be the wrong thing to do.

Hope this clarifies our approach a bit more,

Tony

TonyPrintezisa at 2007-7-10 10:55:55 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 4

> Hi,

>

> A few years ago at JavaOne (it was maybe 2003?) I was

> on stage during the HS BOF. A developer asked "why

> do I have to explicitly set my heap size? can't you

> just look at how much memory my machine has and just

> take 90% of it?" (which is what you're

> asking...).

>

Of course there are several alternatives which would meet the needs of both.

For example a command line option that takes a percentage and only attempts to acquire that much memory.

Or a command line option that acquires all the memory it can.

Or even a command line option that does nothing but determine how much memory could be allocated and just prints that and exits the VM.

jschella at 2007-7-10 10:55:55 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 5

> Of course there are several alternatives which would

> meet the needs of both.

Of course!

> For example a command line option that takes a

> percentage and only attempts to acquire that much

> memory.

Well, this might not always be helpful, given that your app might get an OOM or not depending on how much memory the machine you run it on has. Having said that, we do something like that and our ergonomic framework uses a more generous heap size when detecting a server-style machine.

> Or a command line option that acquires all the memory

> it can.

Again, as I said, we're worried about users running with that parameter on shared machines.

> Or even a command line option that does nothing but

> determine how much memory could be allocated and just

> prints that and exits the VM.

You can probably work that out very easily using a quick shell script?

Tony

TonyPrintezisa at 2007-7-10 10:55:55 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 6

>

> > Or a command line option that acquires all the

> memory

> > it can.

>

> Again, as I said, we're worried about users running

> with that parameter on shared machines.

>

Errr....then your argument is wrong.

Your previous suggestion along those lines was why a VM couldn't automatically grab the space, at least that is how I read it.

This suggestion is that it only goes when a specific parameter is used.

The fact that other apps are running doesn't impact how much memory one application can request or even acquire. You can run 20 VMs on a windows box all of which grab 1.4 gig. The performance might not be what you want but then the performance might not be what you want with each of them only getting 64 meg either. Tuning that sort of set up is outside the domain space of the VM. And it is something that would have to be done regardless of any possible solution suggested.

> > Or even a command line option that does nothing but

> > determine how much memory could be allocated and just

> > prints that and exits the VM.

>

> You can probably work that out very easily using a

> quick shell script?

Which, as I previously suggested, is the only possibility with the current VM. Printing it out would require less start up time.

jschella at 2007-7-10 10:55:55 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 7
Find Total and Free memory using Runtime classusejava -Xms100m -Xmx150m ClassNamewhere the first arg is min memory, second one is the max. memory for heap
bmdibrahima at 2007-7-10 10:55:55 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 8

> Hi,

>

> A few years ago at JavaOne (it was maybe 2003?) I was

> on stage during the HS BOF. A developer asked "why

> do I have to explicitly set my heap size? can't you

> just look at how much memory my machine has and just

> take 90% of it?" (which is what you're

> asking...).

>

> At that moment (and in answer to your question)

> another developer gets up and says "don't do this!

> I run 30 VMs on my machine, if you do this my machine

> will grind down to a halt."

>

> To elaborate a bit more: the HotSpot JVM runs on many

> different platforms and in many different

> environments. And we feel that, if we simply take

> over a machine's memory, in many environments this

> would be the wrong thing to do.

>

> Hope this clarifies our approach a bit more,

>

> Tony

Sorry for late reply, I can understand that, thanks. However, for my case, I am pretty sure that my client machine will run that single JVM, (in fact, even more, he will run that single application at that computer) . Is it possible for future version of java runtime have an argument like -useallavailable memory, and user use it as his own risk?

carfielda at 2007-7-10 10:55:55 > top of Java-index,Java HotSpot Virtual Machine,Specifications...