Operations 16 min read

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.

Programmer DD
Programmer DD
Programmer DD
Master JVM Debugging with Arthas: Essential Commands and Real‑World Use Cases

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.jar

Start 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 getOne

Useful for locating where a method is invoked.

2. jad

Decompiles the source of a loaded class.

jad cn.test.mobile.controller.order.OrderController

Can decompile a specific method as well.

jad cn.test.mobile.controller.order.OrderController getOrderInfo

3. 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.OrderController

4. watch

Observes method parameters and return values, optionally with conditions.

watch cn.test.mobile.controller.order.OrderController getOrderInfo "{params,returnObj}" -x 2

5. 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 76

7. logger

Shows logger information and updates logger levels.

logger
logger --name ROOT --level debug

8. dashboard

Shows a real‑time panel of JVM metrics such as thread states, CPU usage, and memory statistics.

dashboard

9. 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.class

Additional 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.

JavaRuntime monitoringArthasbackend operationsdiagnostic toolsJVM debugging
Programmer DD
Written by

Programmer DD

A tinkering programmer and author of "Spring Cloud Microservices in Action"

0 followers
Reader feedback

How this landed with the community

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.