- Start
jstatdon the remote host. You need to specify a policy file, otherwise you will get anAccessControlException: access deniedexception. Create a policy file e.g./tmp/tools.policycontaining:grant codebase "file:${java.home}/../lib/tools.jar" { permission java.security.AllPermission; };Then startjstatdusing the command below:jstatd -J-Djava.security.policy=/tmp/tools.policy
- Start Visual VM. Add a Remote Host and then add a "jstatd connection" to it. Your JVM should appear in the list. You can then click on it and look at the "Visual GC" tab for garbage collection information.
Showing posts with label GC. Show all posts
Showing posts with label GC. Show all posts
Saturday, February 04, 2012
Visual GC Error: Not Supported for this JVM
The Visual GC plugin for Visual VM graphically displays garbage collection, class loader, and HotSpot compiler performance data.
If you install this plugin and, like me, get the error "Not Supported for this JVM", when you try to start Visual GC, try the following steps:
Labels:
GC,
Java,
programming
Friday, April 18, 2008
Garbage Collection Performance Tips
The purpose of Java's Garbage Collector is to find and reclaim unreachable objects. This post will show you how you can write readable and clean code that makes the most out of the garbage collector (in terms of throughput, responsiveness etc)
- Do not be afraid to allocate small objects for intermediate results. Typically, object allocation is very cheap and reclamation of new objects is very cheap too! GCs love small, immutable objects and generational GCs love small, short-lived objects. You should use short-lived immutable objects instead of long-lived mutable ones. Use clearer, simpler code with more allocations instead of more obscure code with fewer allocations.
- Avoid large objects as they are expensive to allocate and initialise.
- Nulling references rarely helps the GC. Instead it creates clutter and in the worst case may introduce a bug. The JIT can do liveness analysis very well.
- Avoid explicit GCs. Applications do not have enough information, but GC does. Calling System.gc() at the wrong time, may start a full stop-the-world GC (in HotSpot) which can hurt performance with no benefit.
- Avoid frequent resizing of array-based data structures as this will allocate several large-ish arrays and will cause a lot of array copying. Try to size them, on initialisation, as realistically as possible.
- Only use object pools for objects that are expensive to allocate/initialise or for those that represent scarce resources e.g. database connection pools or thread pools. Use existing libraries wherever possible. Unused objects in pools are bad; they are live and so the GC must process them and they provide no benefit to the application.
- Use finalization as a last resort. Finalizable object allocation is much slower and reclamation takes at least two GC cycles; the first cycle identifies object as garbage and enqueues object on finalization queue, the second cycle reclaims space after finalize() completes. Finalizers are not like C++ destructors! There is no guarantee if or when they will be called.
- Memory leaks occur because objects are reachable but unused. This may be due to objects in the wrong scope, lapsed listeners, exceptions changing control flow, instances of inner classes, reference objects etc. You should perform reachability analysis to clear up these objects.
Labels:
garbage collection,
GC,
Java,
programming,
tips
Subscribe to:
Posts (Atom)