Master JVM Debugging with Arthas: Essential Commands and Real‑World Use Cases
Arthas, Alibaba’s open‑source Java diagnostic tool, enables dynamic code tracing, real‑time JVM monitoring, and on‑the‑fly debugging without stopping applications; this guide covers installation, common scenarios, and core commands such as stack, jad, sc, watch, trace, jobs, logger, dashboard, and redefine for effective troubleshooting.
Introduction
Arthas is Alibaba’s open‑source Java diagnostic tool that dynamically traces Java code and monitors JVM status in real time, allowing you to investigate JVM‑related issues without interrupting the running program. It supports JDK 6+, Linux/Mac/Windows.
Typical Use Cases
Identify which JAR a class was loaded from and resolve class‑related exceptions.
Determine why modified code is not being executed (e.g., wrong branch or uncommitted changes).
Debug issues that cannot be reproduced online without adding logs.
Investigate data‑processing problems that occur only in production and cannot be reproduced locally.
Obtain a global view of system runtime status.
Monitor real‑time JVM metrics.
Installation
Download the agent:
wget https://alibaba.github.io/arthas/arthas-boot.jarStart it with java -jar: java -jar arthas-boot.jar Choose the target Java process by entering its number.
Common Commands
1. stack
Shows the call stack of the current method.
[arthas@79952]$ stack com.baomidou.mybatisplus.extension.service.IService getOneUseful for locating where a method is invoked.
2. jad
Decompiles the source of a loaded class.
jad cn.test.mobile.controller.order.OrderControllerCan decompile a specific method as well.
jad cn.test.mobile.controller.order.OrderController getOrderInfo3. sc (Search‑Class)
Searches for loaded classes using a pattern and can display detailed class information.
sc *OrderController* sc -d cn.test.mobile.controller.order.OrderController4. watch
Observes method parameters and return values, optionally with conditions.
watch cn.test.mobile.controller.order.OrderController getOrderInfo "{params,returnObj}" -x 25. trace
Displays the internal call path of a method and the time spent on each node.
trace -j cn.test.mobile.controller.order.OrderController getOrderInfo trace -j cn.test.mobile.controller.order.OrderController getOrderInfo '#cost > 10'6. jobs
Lists background asynchronous tasks started with & and allows management (e.g., kill).
jobs kill 767. logger
Shows logger information and updates logger levels.
logger logger --name ROOT --level debug8. dashboard
Shows a real‑time panel of JVM metrics such as thread states, CPU usage, and memory statistics.
dashboard9. redefine
Hot‑updates already loaded classes without restarting the application.
jad --source-only cn.test.mobile.controller.order.OrderController > OrderController.java sc -d cn.test.mobile.controller.order.OrderController | grep classLoaderHash mc -c 18b4aac2 OrderController.java -d ./ redefine -c 18b4aac2 OrderController.classAdditional Tips
If the chosen process conflicts with the default telnet port, restart Arthas with a different port, e.g., java -jar arthas-boot.jar --telnet-port 9998 --http-port -1, and shut down the conflicting process using the shutdown command.
Programmer DD
A tinkering programmer and author of "Spring Cloud Microservices in Action"
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.
