JVM Memory Usage....

Hi all,

1) I am facing problem with cpu memory usage with my program even if i am setting -Xmx1m flag to simple HelloWorld program, CPU usage is around 3.4 MB.

Is it should be like this only or what?

2) For my real program CPU usage is most important and for that i have several jars in my classpath do they affect memory usage and if it so how and how we can get rid of it?

Thanks

Mitul.

[441 byte] By [lmitul] at [2007-9-26 5:00:39]
# 1

> 1) I am facing problem with cpu memory usage with my

> program even if i am setting -Xmx1m flag to simple

> HelloWorld program, CPU usage is around 3.4 MB.

> Is it should be like this only or what?

>

The space the process consumes (the virtual space that is) is the total of the native code and data space to run the JVM, the size of all native thread stacks, plus the Java heap. On many OS's (NT, Solaris, etc.) execute-only pages are shared between processes, so they don't really count against real memory sizes.

3.4MB is pretty small for a Java process. Note that 1MB you allocated to the Java heap you have all of the Java classes needed to run your program, plus any data you allocated - you could probably go smaller, but you won't take that much off the minimum process virtual memory size.

> 2) For my real program CPU usage is most important and

> for that i have several jars in my classpath do they

> affect memory usage and if it so how and how we can

> get rid of it?

>

By CPU usage, I think you mean RAM or virtual memory usage?

Anyway, no, the Java only loads the classes that you actually use.. You can import extra classes into your code and it has no effect. This is like adding extra directories to the Unix LD_LIBRARY_PATH or the Windows PATH environment variables - worst case, it may take a little longer to find things, so it may *slightly* improve your startup time if you put the more likely candidates up front.

Chuck

cmccorvey at 2007-6-29 18:56:57 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 2

Hi,

Thanks alot for information but still i have doubt with my second issue.

> > 2) For my real program CPU usage is most important

> and

> > for that i have several jars in my classpath do

> they

> > affect memory usage and if it so how and how we can

> > get rid of it?

> By CPU usage, I think you mean RAM or virtual memory

> usage?

Sorry, about confusion but memory usage itself (RAM or Virtual).

> Anyway, no, the Java only loads the classes that you

> actually use.. You can import extra classes into your

> code and it has no effect. This is like adding extra

> directories to the Unix LD_LIBRARY_PATH or the Windows

> PATH environment variables - worst case, it may take a

> little longer to find things, so it may *slightly*

> improve your startup time if you put the more likely

> candidates up front.

Now, i am giving you more specific detail for this before my program was having 12 jars in class path and the memory usage was around 13 MB.

Then, i realized that some jars in my classpath are not required at all so i tried to remove from classpath and executed the program, program executed fine but i found interesting result i able to cut down memory upto 2 MB. i.e. my program memory usage was 11MB.

Before, i was thinking like you specified itself then this practical makes me crazy.

Can u clear me with this issue and if possible can u pass any documentation link so i can go in depth with this issue.

I really appreciated your way of reply and thanks alot for help.

Mitul

lmitul at 2007-6-29 18:56:57 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 3

> Then, i realized that some jars in my classpath are

> not required at all so i tried to remove from

> classpath and executed the program, program executed

> fine but i found interesting result i able to cut down

> memory upto 2 MB. i.e. my program memory usage was

> 11MB.

>

> Before, i was thinking like you specified itself then

> this practical makes me crazy.

>

> Can u clear me with this issue and if possible can u

> pass any documentation link so i can go in depth with

> this issue.

>

> I really appreciated your way of reply and thanks alot

> for help.

>

I don't have an link to much more info for you. One possibility is that the system classloader is retaining in memory the index information for the jar files and or directories it has searched to improve the performance of looking for the next file. In fact I believe it does just that.

Now, would this actually take up 2MB? Who knows. It is possible that only needing a few more bytes can cause the JVM to allocate a fairly large 'next block' from the OS in search of slightly better performance at the cost of larger allocation quanta. I am not sure if it does this however.

Chuck

cmccorvey at 2007-6-29 18:56:57 > top of Java-index,Java HotSpot Virtual Machine,Specifications...