Learning goals of this exercise
In this exercise you will learn:
Background for this exercise
Please see Exercise 1 for an overview of running
the javaperf GUI launcher.
Setting the maximum heap
size is important for optimal performance... especially if you want
multiple instances of the JVM to co-exist on the same system without
swapping memory.
Generally speaking it is
not a performance problem to have the maximum heap size set too big,
but if it is too high then the application may not even start (you could
see errors like Error occurred during initialization of VM, Could not reserve enough space for object heap).
Setting the max heap size too big may waste memory (that could be used
for other system resources or applications) and it may lead to long GC
times once the heap does fill up.
Steps to follow
compiler=
|
. You will see the Java 2D Demo application start.... Immediately click on the "Transforms" tab.
Then click into the "Shear" area so it fills the entire window.![[Stop]](Stop.png)
Summary
How do you know the old
gen is too big (the maximum heap size is set to big)? One way the
JVM doesn't even start. Another is if you see that it seems
hardly any of the old gen space is used. Another may be that the
old space is used, but when there is a full GC it has a very long pause time
(stay tuned for an exercise on the concurrent collector!).
Why
is an oversized heap a
problem? It generally isn't a performance problem, but you may
not be able to start the application (if there isn't enough RAM) or you
are wasting memory. In can be useful to test your application
with a deliberately oversized heap to get a feeling for what the
"right" heap size is.
Why shouldn't I just let the JVM figure out with the best old gen size
is? In practice that is often what you want to do... By setting
the initial (Xms) and maximum values (Xmx) for the heap you allow the
JVM to reserve the maximum amount, but only the memory that is needed is committed.
For the purpose of the hands-on lab, however, we've opted instead to
set these values the same to lead to more predictable results.
For more about reserved vs. committed memory and resizing please see
the
Total Heap section of the Tuning
Garbage Collection with the 5.0 Java™ Virtual Machine
document.
Next Steps
This lab documentation is licensed under a
Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License.