This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Rust Web Development and have Bastian Gruber on-line!
See this thread for details.
Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Java Memory Usage

 
Ranch Hand
Posts: 441
2
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Suppose we provide -Xms 512m -Xmx 1024m, then, I understand that this allocates memory to heap area.

How much total memory will be allocated to java process? Will it be in this range or it will be higher since we have other memory areas such as stack, pcr, and needs memory for execution engine, class loaders etc.
 
Marshal
Posts: 74683
335
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Vaibhav Gargs wrote:Suppose we provide -Xms 512m -Xmx 1024m, then, I understand that this allocates memory to heap area.

No, it doesn't. It allocates limits for how much heap memory should be available

How much total memory will be allocated to java process? . . .

Don't know, Try a profiling tool; there is one installed with the standard Java® installation. I think it is called jconsole. Run an ordinary application and call jconsole from another terminal. I hope I have given you the right name for the program.
 
Sheriff
Posts: 26957
84
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you're running Windows, then Task Manager will tell you how much memory is assigned to your Java.exe process. Other operating systems no doubt have similar features.

On my machine I can run a Java application with -Xmx4G and Java doesn't complain at all, even though my machine only has 1.4 gigabytes of memory. If you're interested in performance you might more usefully ask whether Java or the operating system will use virtual memory to fill in the 2.6 gigabyte gap.
 
Marshal
Posts: 3760
536
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
VisualVM is a nice profiling tool, but might take a bit of learning depending on what features you want to use.
 
Saloon Keeper
Posts: 24842
173
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've got a Java process that claims 12.5G virtual memory on a 32GB machine! However, the active memory of the JVM is only 500MB. This was under default VM options as far as I can tell - it there are explicit -M options they're well hidden.
 
Campbell Ritchie
Marshal
Posts: 74683
335
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:. . . Task Manager . . . . Other operating systems no doubt have similar features. . . ..

I have at least two kinds of system monitor running on my Linux box.
 
Tim Holloway
Saloon Keeper
Posts: 24842
173
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:

Paul Clapham wrote:. . . Task Manager . . . . Other operating systems no doubt have similar features. . . ..

I have at least two kinds of system monitor running on my Linux box.



I've got something like 5 different flavours of top alone. That's before you get into I/O monitors, network monitors, etc.
 
Vaibhav Gargs
Ranch Hand
Posts: 441
2
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you all for your responses. So, if we declare -Xmx 512m then actual java runtime can have more memory than this limit due to other memory areas, correct?

But heap memory max size would be 512m which is defined by -Xmx, right?

In case we have RAM only 256MB, and if we declare -Xmx 512m, then what would happen?
 
Campbell Ritchie
Marshal
Posts: 74683
335
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What do you think will happen? Try it with bigger figures on your computer and see what happens.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic