Arthas 4 Unveiled: JDK 25 Support, Wall-Clock Profiling, and MCP for AI Debugging

This article explores Arthas 4, Alibaba's open-source Java diagnostic tool, covering its core commands, troubleshooting workflow, new features including JDK 8-25 support, improved flame graphs with wall-clock profiling, Metaspace analysis by classloader, and experimental MCP integration for AI-assisted debugging, with three practical command examples for CPU analysis, method tracing, and memory profiling.

java1234
java1234
java1234
Arthas 4 Unveiled: JDK 25 Support, Wall-Clock Profiling, and MCP for AI Debugging

What Is Arthas

Arthas is Alibaba's open-source Java diagnostic tool (repository: alibaba/arthas). It runs on Linux, macOS, and Windows, providing a command-line interface with Tab completion for commands and class names. Think of it as a stethoscope you can attach to a running Java process without modifying business code or pre-configuring JVM parameters.

Attach with the boot JAR:

curl -O https://arthas.aliyun.com/arthas-boot.jar
java -jar arthas-boot.jar

The tool lists local Java processes; enter the index to connect. Windows uses the same java -jar command.

Core Commands for On-Call Debugging

dashboard

— JVM overview panel: threads, memory, GC at a glance thread — Thread stacks and top CPU-consuming threads watch / trace — Method arguments, return values, and internal latency jad / sc — Decompile loaded classes, verify class loading profiler — Sampling and flame graph generation

Production Troubleshooting Workflow

The author recommends a fixed sequence: first see the big picture ( dashboard), then drill into methods and call stacks ( thread, trace, watch), finally pin down hotspots with sampling ( profiler). The three examples below follow this flow.

What's New in Arthas 4

JDK 8 through 25 Support

Arthas 4 requires JDK 8+. Official docs confirm support for JDK 17, 21, and 25. Dependencies (Jackson, Fastjson2, OGNL, Netty) were upgraded, reducing security risks in the diagnostic tool itself.

Complete Flame Graph Pipeline

The bundled async-profiler was upgraded to 4.4 in version 4.2.0. Since 4.0.2, --wall enables wall-clock profiling, exposing lock contention and network stalls — cases where CPU looks low but latency is high. Default session timeout extended from 30 minutes to 3 hours, reducing mid-sampling disconnects.

Metaspace Breakdown by ClassLoader

New command classloader-metaspace leverages JFR's jdk.ClassLoaderStatistics to show per-ClassLoader loaded class count, metaspace chunk and block sizes. It targets metadata-heavy scenarios: dynamic proxies, scripting engines, repeated class generation that slowly exhaust Metaspace. The command only appears when the running JDK provides JFR.

Diagnostics via AI Assistant (MCP)

Arthas MCP Server is experimental. Configure arthas.mcpEndpoint=/mcp and arthas.httpPort=8563 in arthas.properties to expose 29 diagnostic tools ( dashboard, thread, trace, jad, profiler, etc.) over HTTP. Clients like Cherry Studio or Cline can then invoke commands via natural language. When arthas.password is set, requests require a Bearer token.

Version 4.1 added LoongArch64 ( loongarch64) support and external command loading from the boot JAR.

Three Hands-On Examples

Assume attached to target process with a method demo.UserService.login (replace with your class).

Example 1: Identify Busy Threads

CPU alert fires; check panel once, then grab top 3 CPU threads.

dashboard -n 1
thread -n 3
dashboard -n 1

refreshes once and exits, good for snapshots. thread -n 3 prints stacks of the three highest-CPU threads. If the stack top repeatedly stops at a business method, investigate that method next.

Example 2: Where Does the Login Method Spend Time?

When calls are slow and logs don't show the branch, use trace for internal latency and watch for real arguments.

trace demo.UserService login
watch demo.UserService login '{params,returnObj,throwExp}' -x 2 -n 5
trace

expands internal call nodes with timings — reveals whether validation or a remote call is the bottleneck. watch with -x 2 expands objects two levels deep; -n 5 captures only 5 invocations to avoid flooding. For high-volume traffic, filter by cost:

trace demo.UserService login '#cost > 100'

Example 3: Flame Graphs and Metaspace

When hotspots are scattered across many small methods, sample and emit an HTML flame graph.

profiler start --event cpu
profiler status
profiler stop --format html

Output path prints on stop (typically under arthas-output); open in browser — wider bars mean more time spent.

For low CPU but threads blocked on locks or network, switch to wall-clock sampling:

profiler start --wall
profiler stop --format html

When Metaspace grows continuously, inspect per-ClassLoader usage:

classloader-metaspace --duration 2500ms --limit 10

Results sorted by chunk size descending. A business ClassLoader with unusually high classes and chunkSize suggests runaway dynamic class generation.

Enabling MCP for AI Assistants

In arthas.properties:

# Enable MCP, default port 8563
arthas.mcpEndpoint=/mcp
arthas.httpPort=8563
arthas.password=your-secure-password

Client configuration example:

{
  "mcpServers": {
    "arthas-mcp": {
      "type": "streamableHttp",
      "url": "http://localhost:8563/mcp",
      "headers": {
        "Authorization": "Bearer your-secure-password"
      }
    }
  }
}

This capability is still experimental; the author advises mastering commands in a test environment before wiring them to an assistant.

Open-source repository: https://github.com/alibaba/arthas

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

MCPproduction-debuggingmetaspaceArthasflame-graphsjdk-25Java Diagnosticsjvm-troubleshooting
java1234
Written by

java1234

Former senior programmer at a Fortune Global 500 company, dedicated to sharing Java expertise. Visit Feng's site: Java Knowledge Sharing, www.java1234.com

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.