Honey, I shrank the JARs

After reading my blog posts like Femtocli: A small but mighty CLI library for small CLI tools in < 45KB, you probably know that I like small Java libraries and tools. But consider you have an existing CLI tool (like jstall in my case) and you want to reduce its JAR size. What are your options? This is what this short blog post is all about.

TL;DR: You can shrink your CLI tools by 50% use the femtojar project.

Continue reading

Calling jcmd Commands Programmatically

JCmd allows you to quickly get information on an existing JVM. This helpful for getting things like thread-dumps (see jstall for tool that heavily relies on this). In this blog post you’ll learn to send JCmd diagnostic commands programmatically. You can find the whole code of this blog post on GitHub.

Let’s get a sample application running:

> java Loop.java &
[1] 23462

Now we want to obtain the VM arguments and the Java command, that’s easy on the command line via jcmd:

> jcmd 23462 VM.command_line
23462:
VM Arguments:
jvm_args: --add-modules=ALL-DEFAULT 
java_command: jdk.compiler/com.sun.tools.javac.launcher.SourceLauncher Loop.java
java_class_path (initial): .
Launcher Type: SUN_STANDARD

But how can we do it programmatically? Calling jcmd always starts a new JVM, which we might not want.

This is where the Diagnostic MBean comes into play.

Continue reading

On HotSpot Error Files and Useful Tools

Ever crashed a JVM? Then you typically get a HotSpot error file, or hs err for short. These files contain information about which crash occurred and what the JVM’s state was at the time of the crash. In this short blog post, we’ll be diving into the components of a typical hs err file and show case a few custom-built tools to work with them.

But before we start: A crashing JVM is normal when you develop the JVM, e.g., adding a new CPU-time profiler, but normally it should not happen (except maybe when your JVM runs out of memory), so the hs err files are not a common sight. Still, they are important to me and my colleagues at SapMachine, which is why I’m writing this blog post.

TL;DR: I wrote an online tool for redacting hs err files and also a syntax highlighter extension for VSCode, all as part of the jhserr project on GitHub.

Continue reading