Code Tools: jol

JOL (Java Object Layout) is the tiny toolbox to analyze object layout schemes in JVMs. These tools are using Unsafe, JVMTI, and Serviceability Agent (SA) heavily to decoder the actual object layout, footprint, and references. This makes JOL much more accurate than other tools relying on heap dumps, specification assumptions, etc.

Building JOL from source

You may skip this step and use the published binaries instead, see the usage below. It is generally preferred to use the latest source version, that hopefully has the most issues fixed. Follow these steps to compile JOL from the source.
  1. Check out the JOL source with Mercurial:
    $ hg clone http://hg.openjdk.java.net/code-tools/jol/ jol
    
  2. Build JOL with Maven:
    $ cd jol/
    $ mvn clean install
    

    You only need to do this step once, and Maven will deploy JOL into your local repo. If you have the Maven repository manager installed, it might be a good idea to deploy the artifact there. If not, you can just go with the local build.

There are two major ways to use this project.

Use as Library Dependency

OpenJDK Community semi-regularly pushes the releases to Maven Central. Therefore, you can use it right away by setting up the Maven dependency:
<dependency>
    <groupId>org.openjdk.jol</groupId>
    <artifactId>jol-core</artifactId>
    <version>put-the-version-here</version>
</dependency>

It is a good idea to review JOL Samples and CLI tools source before using the tool at its full capacity as the library.

Use as Command Line Tool

Build produces the self-contained executable JAR in jol-cli/target/jol-cli.jar. Published Maven artifacts also include the executable JAR that one can download and start using right away. To do that, look for the latest version of jol-cli-$version-full.jar here.

Run it with help argument to get the list of operations it has. The brief list of operations we have goes below:

Links