From experience, almost every unoptimized Java application wastes between 10 and 50% of its memory due to common, easy-to-fix problems. But do you know a tool that would recognize and pinpoint all these problems instantly?




Your Java apps need more and more memory with every release. They crash suddenly with OutOfMemoryError. They spend a lot of time in garbage collection. What do you do?
The typical answers are: "increase memory", "tune the GC" and, finally, "use some tool to see what's inside that heap". But too often these measures don't quite work. A machine's RAM may be limited, the GC may be unable to keep up even after much tuning, and tools just present you with a vast object graph and leave it up to you to make sense of it. Frankly, the situation with tooling hasn't improved much in a decade. Can we really do better? Enter JXRay - the first Java memory analysis tool that's truly intelligent.
JXRay is different from all other memory profilers. These tools present users with little more than rough memory data, and let them make and test their guesses about it. Too often it's a hit-and-miss game. In contrast, JXRay proactively looks for all kinds of known, well understood Java memory problems and presents the user with concrete, actionable findings. These results are carefully aggregated and distilled to reveal data that may be scattered about many places in memory, but is ultimately managed by the same code. Thus, in most cases it's immediately obvious to the user what code they need to change to save the biggest amount of memory. With unoptimized apps, it's often enough to make small changes to 10-20 lines of code to save as much as 20-30% of memory and/or greatly reduce GC pressure. And all this can be achieved in half an hour rather than days!
JXRay works by analyzing JVM heap dumps - memory snapshot files that can be generated when the JVM crashes with OutOfMemoryError, or on demand. In addition to its intelligent analysis capabilities, JXRay has other big advantages:
  • It is extremely scalable: it processes 1..4 GB heap dumps in less than a minute, and it can handle dumps of up to 100GB.
  • It doesn't need to run on a machine that has a screen attached. Thus, JXRay can be used to process big heap dumps in place, for example right on a production machine where the dump was generated. It can even be integrated in production to run automatically.
  • We have used JXRay to improve memory consumption of many open source projects (Apache Hive, Spark, Sentry, HBase, HDFS etc.), as well as proprietary products. Thus, this tool is built, and continues to evolve, based on first-hand experience optimizing real-life Java applications.




JXRay is a memory analysis tool for Java that takes a JVM heap dump and produces a report in rich HTML format. The main advantages of JXRay are:


Detecting sources of memory waste right away. JXRay analyzes a heap dump upfront for many known, well understood problems. The most prevalent are memory leaks and various anti-patterns (duplicate strings and other objects, suboptimal collections and arrays, overused boxed numbers, etc.). This is especially relevant for Android applications, where memory is tight. All significant waste sources are highlighted, and you see them immediately.


Recommendations on changing code. JXRay is the only memory profiling tool that provides specific recommendations on how to change the code to address each of the specific detected problems.


Compact presentation. JXRay aggregates (merges) all identical reference chains, repeating data fields (think linked lists), similar GC roots, etc. The resulting compressed, clear view of even the biggest and most complex heaps allows you to easily understand where most memory goes, and what code manages it. Thus you can quickly figure out what classes and methods need to be changed to get the biggest memory improvement.


Knowledge of internals. JXRay knows the implementation details of most of the common Java and Scala collections: maps (e.g. java.util.HashMap), lists (e.g. java.util.ArrayList), etc. That allows it to present a streamlined view of the heap structure, omitting the unnecessary collection internals. Furthermore, the tool accurately calculates how much memory is taken by the implementation of collections themselves vs their payload - and it's often surprising how much memory collections themselves need.


Offline tool. While it may seem counterintuitive, the fact that JXRay has no GUI and produces HTML reports has big advantages. You can easily run the tool on any machine, e.g. big "headless" machines in the cloud (including a production machine where the dump was generated). Later, you can look at the report anywhere at any time, send it out by e-mail, attach to a JIRA ticket, or share on the wiki.


Tested in combat. JXRay has been used to identify and fix many real performance problems. We quickly found all sorts of problems that went undetected for years. See some Apache open source projects investigated and improved with JXRay.



If you would like to learn more about Java memory problems recognized by JXRay, why they are so common, and why they waste a lot of memory, check out these presentation slides.


For in-depth understanding of how Java applications can waste memory, and how to prevent that, take a look at the following articles:


Detecting Memory Leaks from a JVM Heap Dump

How to Prevent Your Java Collections from Wasting Memory

Duplicate Strings: How to Get Rid of Them and Save Memory


What's Wrong with Java Boxed Numbers?


What's Wrong with Small Objects in Java?


Duplicate Objects in Java: Not Just Strings

Troubleshooting Problems with Native (Off-Heap) Memory in Java Applications


Print Print | Sitemap