• 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:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Ways to reduce memory footprint of JVM

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Is there any way to reduce the memory footprint of a full blown JVM. I am trying to launch a Java application and keep it running for a long time and would love to make it lean in terms of footprint. I have tried to do some research, but unfortunately couldn't gather anything useful. It would be great if someone could share some pointers or experiences.

Regards,
Sandeep
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since so much of the memory footprint of a running jvm is due to loaded classes, it seems to me that the first line of defense would be using as few classes as possible.
JVMs for reallllly small environment that I have looked at have left out long and double math functions to reduce the core code.

Bill
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The only ways I'm aware of is

a) reducing the amount of free heap space, for example using the following start up parameters:

-XX:MinHeapFreeRatio=10 -XX:MaxHeapFreeRatio=20

This means that the JVM will keep the heap at a size so that 10-20% of the heap will be free. The default values are 40-70%. You might want to test the impact on the performance of the garbage collector when you do this.


b) reducing the size of the permanent generation

XX:MaxPermSize=...

Default is 64 MB - a too low value will lead to an OutOfMemoryError: permgen


c) reducing the size of the hot spot engine's code cache:

-Xmaxjitcodesize...

Default is 32 MB - a too low value will result in lost performance.


Since Java 5, you can use the JConsole to see how much of the available space is actually used by your application.
 
Sandeep Deb
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Many thanks Ilja. I will check out your suggestions tomorrow and update the post with my findings. I went through the documentation of the options you have suggested and they look quite promising.

Thanks again,
- Sandeep
 
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by William Brogden:
Since so much of the memory footprint of a running jvm is due to loaded classes, it seems to me that the first line of defense would be using as few classes as possible.



The effect of directly using one more class can vary greatly. If that class has no dependencies on other yet-unloaded classes, the effect will be small. If that class depends on whole frameworks that are not yet loaded, huge amounts of memory will be used. For instance, as soon as you use any Swing class, loads of other classes will get loaded.

There's an option on the JVM to report information about loaded classes. I forget what it is, but it could be very useful here - look it up.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic