alibaba/arthas · critical

ERROR: arthas vmtool JVMTI AddCapabilities failed!%u

Error message

ERROR: arthas vmtool JVMTI AddCapabilities failed!%u

What it means

In the arthas-vmtool native agent, after obtaining a JVMTI environment, init_agent() requests the can_tag_objects capability via AddCapabilities. This capability is required for heap iteration with object tagging (used by vmtool to find/count live objects). If AddCapabilities returns a non-zero jvmtiError, the agent prints this error and returns JNI_FALSE, rendering vmtool's instance-scanning features non-functional.

Source

Thrown at arthas-vmtool/src/main/native/src/jni-library.cpp:54

// 每次 IterateOverInstancesOfClass 调用前需要先 init
static LimitCounter limitCounter = {0, 0};

extern "C"
int init_agent(JavaVM *vm, void *reserved) {
    jint rc;
    /* Get JVMTI environment */
    rc = vm->GetEnv((void **)&jvmti, JVMTI_VERSION_1_2);
    if (rc != JNI_OK) {
        fprintf(stderr, "ERROR: arthas vmtool Unable to create jvmtiEnv, GetEnv failed, error=%d\n", rc);
        return -1;
    }

    jvmtiCapabilities capabilities = {0};
    capabilities.can_tag_objects = 1;
    jvmtiError error = jvmti->AddCapabilities(&capabilities);
    if (error) {
        fprintf(stderr, "ERROR: arthas vmtool JVMTI AddCapabilities failed!%u\n", error);
        return JNI_FALSE;
    }

    return JNI_OK;
}

extern "C" JNIEXPORT jint JNICALL
Agent_OnLoad(JavaVM *vm, char *options, void *reserved) {
    return init_agent(vm, reserved);
}

extern "C" JNIEXPORT jint JNICALL
Agent_OnAttach(JavaVM* vm, char* options, void* reserved) {
    return init_agent(vm, reserved);
}

extern "C" JNIEXPORT jint JNICALL
JNI_OnLoad(JavaVM* vm, void* reserved) {

View on GitHub (pinned to 21cf2e9ba5)

Solutions

  1. Check for conflicting JVMTI agents (profilers, APM tools) loaded alongside Arthas and remove/reorder them.
  2. Verify the JVM supports the can_tag_objects capability (standard HotSpot/OpenJDK do).
  3. Upgrade to a fully-featured JDK if using a stripped/embedded runtime.
  4. If capabilities cannot be granted, avoid vmtool instance-scanning commands and use alternative Arthas diagnostics.

Example fix

// not a source-code fix — resolve agent/JVM conflict
// before: two agents compete, AddCapabilities fails
java -agentlib:otherprof -jar arthas-boot.jar <pid>
// vmtool init: 'JVMTI AddCapabilities failed!'

// after: remove conflicting agent
java -jar arthas-boot.jar <pid>
Defensive patterns

Strategy: fallback

Validate before calling

// Verify no conflicting JVMTI agents are loaded before attaching Arthas
// Check JVM launch flags for -agentlib/-javaagent that claim tagging capabilities
ManagementFactory.getRuntimeMXBean().getInputArguments().stream()
    .filter(a -> a.startsWith("-agentlib") || a.startsWith("-javaagent"))
    .forEach(a -> log.info("Detected agent: " + a));

Try / catch

// Native error — handle by detecting init failure and degrading gracefully
if (!vmtoolCapabilitiesAvailable()) {
    log.warn("vmtool can_tag_objects unavailable — instance scanning disabled");
}

Prevention

When it happens

Trigger: The JVMTI environment refuses to grant can_tag_objects — typically because another agent or the JVM configuration disallows it, or the capability is not supported by the current JVMTI implementation.

Common situations: Running under a JVM or container that restricts JVMTI capabilities; a conflicting profiling/monitoring agent already claimed or denied tagging; running on a JVM build with reduced JVMTI capability support; certain J9/legacy JVMs that don't implement object tagging.

Related errors


AI-assisted analysis of alibaba/arthas@21cf2e9ba5 (2026-08-14). Data as JSON: /api/errors/f79ea259b30c8bbd. Report an issue: GitHub.