Java Performance Tuning

Java(TM) - see bottom of page

|home |services |training |newsletter |tuning tips |tool reports |articles |resources |about us |site map |contact us |
Tools: | GC log analysers| Multi-tenancy tools| Books| SizeOf| Thread analysers| Heap dump analysers|

Our valued sponsors who help make this site possible
JProfiler: Get rid of your performance problems and memory leaks! 

Training online: Concurrency, Threading, GC, Advanced Java and more ... 

News September 2014

Get rid of your performance problems and memory leaks!

Modern Garbage Collection Tuning
Shows tuning flow chart for GC tuning

Java Performance Training Courses
COURSES AVAILABLE NOW. We can provide training courses to handle all your Java performance needs

Java Performance Tuning, 2nd ed
The classic and most comprehensive book on tuning Java

Java Performance Tuning Newsletter
Your source of Java performance news. Subscribe now!
Enter email:

Training online
Threading Essentials course

Get rid of your performance problems and memory leaks!

Back to newsletter 166 contents

I recently needed to get a sizeof implementation for Java objects. I needed to get a "deep" size, so that I could see how much memory a particular object was retaining. So I searched for implementations and found several different approaches. I ignored the ones that needed to use native calls of one type or another, I was looking for a Java implementation; and I found three main types of implementations.

A note from this newsletter's sponsor

New Relic - Try New Relic today and get your free Data Nerd shirt!
Free SaaS APM tool to monitor, troubleshoot, and tune apps
running on Websphere, Weblogic, Tomcat, Jetty, JBoss, Solr, Resin

Firstly, there's the old "use reflection and guess based on the known primitive data sizes and overheads" technique, which goes back about 15 years, though seems to have been most popularised by some Javaworld articles (see the tools section below for that and all the rest). Next is the "agent" based technique which Heinz Kabutz first popularised in his newsletter about 7 years ago. And lastly, more recently, are "unsafe" techniques developed in the last few of years.

After going through them, I tested them for my purposes and found that the carrotsearch 'unsafe' one was both the fastest and churned the least memory (ehcache's 'unsafe' implementation was close).

Note the drawback is that using unsafe is potentially dangerous - if the implementation is flakey or the JVM internals change, it'll most likely crash the JVM. Whenever using 'unsafe' based tools, it's worth bearing in mind Gil Tene's graphic description of using unsafe: like using scissors which have the obvious warning label saying "not safe for poking at one's own eye" to then poke at an itch in your eye.

See the tools section below for the links to those sizeof tools, and see all our usual sections: links to articles, news and as ever, all the extracted tips from all of this month's referenced articles.

A note from this newsletter's sponsor

Get total visibility in just 15 minutes with AppDynamics PRO,
A performance monitoring tool for Java/.NET apps.
It installs in minutes. Start your FREE TRIAL today.


Java performance tuning related news.


Java performance tuning related tools.

(Note the Lucene one is not listed as the carrotsearch one is an extracted version of that.)

A note from this newsletter's sponsor : Deep dive Application Performance Monitoring
Fix performance issues with Java, .NET and Ruby platforms.
*** Monitor one app instance starting at $9 ***.


Jack Shirazi

Back to newsletter 166 contents

Last Updated: 2024-03-29
Copyright © 2000-2024 All Rights Reserved.
All trademarks and registered trademarks appearing on are the property of their respective owners.
Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries. is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.
RSS Feed:
Trouble with this page? Please contact us