Operations 8 min read

Master JDK Command-Line Tools for JVM Performance Tuning: A Practical Guide

This guide explores the JDK command‑line utilities located in %JAVA_HOME%\bin, explaining how tools such as jps, jstat, jinfo, jmap, jhat and jstack can be used to monitor JVM processes, analyze performance bottlenecks, inspect memory usage, generate heap dumps, and adjust runtime parameters for more efficient and stable Java applications.

Spring Full-Stack Practical Cases
Spring Full-Stack Practical Cases
Spring Full-Stack Practical Cases
Master JDK Command-Line Tools for JVM Performance Tuning: A Practical Guide

Introduction

This article provides an in‑depth analysis of JDK command‑line tools and demonstrates how to use them for JVM performance tuning. By learning the various utilities supplied with the JDK, readers can monitor JVM runtime status, identify performance bottlenecks, and adjust JVM parameters to improve application stability and efficiency.

The tools are located in the %JAVA_HOME%\bin directory.

Most of these executables are lightweight wrappers around classes found in %JAVA_HOME%\bin\tools.jar .

Tool Overview

The following commonly used tools are covered:

jps – Lists all currently running HotSpot JVM processes.

jstat – Monitors various runtime metrics such as class loading, memory usage, and garbage collection.

jinfo – Displays and modifies JVM parameters at runtime.

jmap – Generates heap dump snapshots and provides heap information.

jhat – Analyzes heap dump files.

jstack – Produces thread stack snapshots of a running JVM.

jps

Usage example:

<code>public class JpsMain {
  public static void main(String[] args) throws Exception {
    System.out.println(java.util.Arrays.toString(args));
    System.in.read();
  }
}
</code>

Run the program with three arguments (a, b, c) and then execute:

Common options:

-l – Shows full package and class name; for JARs, displays the JAR path.

-m – Shows the arguments passed to the JVM at startup.

-v – Shows JVM arguments used to start the process.

-q – Displays only the process ID.

jstat

Syntax:

<code>jstat -&lt;option&gt; [-t] [-h&lt;lines&gt;] &lt;vmid&gt; [&lt;interval&gt; [&lt;count&gt;]]</code>

Parameters:

vmid – JVM process ID.

interval – Query interval (seconds or milliseconds).

count – Number of queries.

Key options:

-class – Shows class loading statistics.

-compiler – Shows JIT compilation information.

-gc – Monitors heap usage and GC times.

-gcutil – Similar to -gc but focuses on usage percentages.

-gcnew – Monitors young generation GC.

-gcold – Monitors old generation GC.

Example:

<code>jstat -gc 16480 3s</code>

This command reports GC statistics every 3 seconds.

jinfo

Usage:

<code>jinfo &lt;option&gt; &lt;pid&gt;</code>

Example to display all JVM parameters for process 16480:

<code>jinfo -flag CICompilerCount 16480</code>

jmap

Syntax:

<code>jmap [option] &lt;pid&gt;</code>

Important options:

-dump – Generates a live heap dump (e.g., jmap -dump:live,format=b,file=heap.bin &lt;pid&gt; ).

-heap – Shows detailed heap information, including GC algorithms and generation sizes.

-histo – Displays a histogram of objects in the heap.

jhat

Usage:

<code>jhat &lt;heap-dump-file&gt;</code>

After generating a heap dump with jmap -dump , run jhat to start a web service (default port 7000) for interactive analysis.

jstack

Syntax:

<code>jstack [option] &lt;pid&gt;</code>

Common options:

-F – Forces a thread dump when the JVM is unresponsive.

-l – Includes lock information.

-m – Shows native C/C++ stack frames for native methods.

Conclusion

By mastering these JDK command‑line utilities—jps, jstat, jinfo, jmap, jhat, and jstack—developers can effectively monitor JVM health, diagnose performance issues, and fine‑tune runtime parameters, leading to more reliable and high‑performing Java applications.

JavaJVMperformance tuningJDKcommand line tools
Spring Full-Stack Practical Cases
Written by

Spring Full-Stack Practical Cases

Full-stack Java development with Vue 2/3 front-end suite; hands-on examples and source code analysis for Spring, Spring Boot 2/3, and Spring Cloud.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.