Using Arthas for Java Monitoring, Debugging, and Hot Code Update
This article introduces Alibaba’s open‑source Java diagnostic tool Arthas, explains how to install and use it for JVM monitoring, class loading inspection, and performing hot code updates via memory compilation and the redefine command, while noting its limitations.
Arthas Overview
Arthas is an Alibaba open‑source Java diagnostic tool that allows monitoring, troubleshooting, and hot‑update of Java applications without restarting the JVM.
Key Features
Arthas can help when you encounter problems such as:
Which JAR loaded a class and why class‑related exceptions occur.
Why code changes are not taking effect.
Inability to debug online without adding logs.
Production issues that cannot be reproduced locally.
Need for a global view of system status.
Monitoring JVM real‑time state.
Quickly locating hot spots and generating flame graphs.
Arthas supports JDK 6+, runs on Linux/Mac/Windows, uses an interactive command‑line interface with tab completion.
Installation and Startup
1. Download Arthas : obtain the arthas-boot.jar from https://alibaba.github.io/arthas/arthas-boot.jar.
2. Start Arthas with the standard jar command: java -jar arthas-boot.jar After startup you will see the Arthas console.
Using Arthas
Choose a Java process to attach to (e.g., input "4" to select a test program). Once attached, you can execute various commands to inspect the JVM.
Inspecting Application Version
Without Arthas you would need to locate, download, and decompile JAR/WAR files manually. With Arthas you can simply run the jad command to decompile a class and verify its version.
Hot Updating Java Code
To change a field value (e.g., change flag from true to false) you can use Arthas’s memory compilation and redefine command.
Compile the new Java source to bytecode using the mc (Memory Compiler) command:
[arthas@3478]$ mc /Users/admin/Desktop/App.java -d /Users/admin/Desktop
Memory compiler output:
/Users/admin/Desktop/com/example/App.class
Affect(row‑cnt:1) cost in 390 ms.Apply the hot update with redefine:
[arthas@51787]$ redefine /Users/admin/Desktop/com/example/App.class
redefine success, size: 1The update succeeds only when the modified method is not currently executing; adding fields, adding/removing methods, or redefining a running method will fail.
Precautions for Hot Update
Hot update can only modify business code inside a method. It cannot add class fields, add or delete methods, or replace a method that is actively running.
Summary
Arthas is a lightweight Java program that can be started with java -jar arthas-boot.jar, attached to a target JVM, and used for real‑time monitoring, class inspection, decompilation, and hot code replacement via the redefine command, provided the changes respect its limitations.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Full-Stack Internet Architecture
Introducing full-stack Internet architecture technologies centered on Java
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
