Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Trying to understand better how JVM works.

 
Susan Smith
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a very simple program which I created just for testing purpose to understand JVM better.
My question is during Thread.sleep(...), I saw using JConsole that the program is still using a little bit more than 5 MB of memory. Why is that??



Thanks in advance for all the help.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34973
379
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Susan,
sleep means the JVM gives up the CPU and waits. Why would you expect the memory usage to change significantly?
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note, also, that sleep() pauses just one thread; other threads in the background (the garbage collector, for example) continue to run.
 
Susan Smith
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I'm wondering is what's that 5 MB memory used for?
Isn't it a little bit too much since the program doesn't have too many things (variables, etc, etc)?
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Run your program using

to get an idea of all the things the JVM needs to load into memory in order to get even the simplest class up and running.
 
Daniel Chemko
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On linux you can always look at all open file handles by calling:

/usr/sbin/lsof | grep java
or
/usr/sbin/lsof | grep my_java_app's_pid

And you can see all the files loaded into virtual memory. Of course there's a chance that the memory isn't allocated into physical ram, just that it has been internally mapped to the process space.

Just one example of an entry is:
java 17120 dchemko mem REG 8,19 50827455 7286804 /usr/java/jdk1.6.0_10/jre/lib/rt.jar

The virtual size of my rt.jar is 50MB, so if the JRE loaded the entire core java classes into memory, you'd be sitting idle at 50MB. Anyways, it is also possible that the system's default minimum stack is set higher than you wanted it to.. or maybe the memory allocated is also reflecting memory mapped files, but I couldn't think of any MMIO files that would open by your setup.
 
Henry Wong
author
Marshal
Pie
Posts: 21504
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Susan Smith:
What I'm wondering is what's that 5 MB memory used for?
Isn't it a little bit too much since the program doesn't have too many things (variables, etc, etc)?


5 MB does not sound like a lot to me. Heck, the byte arrays needed to hold the bytecodes, for the classes loaded by the classloader, could account for most of that alone.

Henry
[ August 06, 2008: Message edited by: Henry Wong ]
 
Susan Smith
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The reason I want to understand better about JVM is because I have a looping program like below.
I run it for a while and I saw the heap size keeps increasing and increasing (I use Java VisualVM from Java 6 to analyze the heap).
The stack size is constant but not the heap size. I'm trying to figure out why this happen.

 
Amaru Shakur
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is the reason you care about this is because your getting a java.lang.OutOfMemoryError exception? a temporary fix would be to increase the heap size
 
Susan Smith
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to understand why the heap size keeps increasing. I don't understand this.
I have around another 50+ programs doing similar looping process. If I have to increase the heap size again and again, the amount of memory needed for my server would be huge.
 
Susan Smith
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Probably this is already a separate question from my original question. I will post a separate question.

Thank you all for your help.
I really appreciate it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic