{"record":{"id":"f79ea259b30c8bbd","repo":"alibaba/arthas","slug":"error-arthas-vmtool-jvmti-addcapabilities-failed","errorCode":null,"errorMessage":"ERROR: arthas vmtool JVMTI AddCapabilities failed!%u\n","messagePattern":"ERROR: arthas vmtool JVMTI AddCapabilities failed!%u\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"arthas-vmtool/src/main/native/src/jni-library.cpp","lineNumber":54,"sourceCode":"\n// 每次 IterateOverInstancesOfClass 调用前需要先 init\nstatic LimitCounter limitCounter = {0, 0};\n\nextern \"C\"\nint init_agent(JavaVM *vm, void *reserved) {\n    jint rc;\n    /* Get JVMTI environment */\n    rc = vm->GetEnv((void **)&jvmti, JVMTI_VERSION_1_2);\n    if (rc != JNI_OK) {\n        fprintf(stderr, \"ERROR: arthas vmtool Unable to create jvmtiEnv, GetEnv failed, error=%d\\n\", rc);\n        return -1;\n    }\n\n    jvmtiCapabilities capabilities = {0};\n    capabilities.can_tag_objects = 1;\n    jvmtiError error = jvmti->AddCapabilities(&capabilities);\n    if (error) {\n        fprintf(stderr, \"ERROR: arthas vmtool JVMTI AddCapabilities failed!%u\\n\", error);\n        return JNI_FALSE;\n    }\n\n    return JNI_OK;\n}\n\nextern \"C\" JNIEXPORT jint JNICALL\nAgent_OnLoad(JavaVM *vm, char *options, void *reserved) {\n    return init_agent(vm, reserved);\n}\n\nextern \"C\" JNIEXPORT jint JNICALL\nAgent_OnAttach(JavaVM* vm, char* options, void* reserved) {\n    return init_agent(vm, reserved);\n}\n\nextern \"C\" JNIEXPORT jint JNICALL\nJNI_OnLoad(JavaVM* vm, void* reserved) {","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/alibaba/arthas/blob/21cf2e9ba52b305290be7223b980ff504bb9cb5b/arthas-vmtool/src/main/native/src/jni-library.cpp#L36-L72","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Check for conflicting JVMTI agents (profilers, APM tools) loaded alongside Arthas and remove/reorder them.","Verify the JVM supports the can_tag_objects capability (standard HotSpot/OpenJDK do).","Upgrade to a fully-featured JDK if using a stripped/embedded runtime.","If capabilities cannot be granted, avoid vmtool instance-scanning commands and use alternative Arthas diagnostics."],"exampleFix":"// not a source-code fix — resolve agent/JVM conflict\n// before: two agents compete, AddCapabilities fails\njava -agentlib:otherprof -jar arthas-boot.jar <pid>\n// vmtool init: 'JVMTI AddCapabilities failed!'\n\n// after: remove conflicting agent\njava -jar arthas-boot.jar <pid>","handlingStrategy":"fallback","validationCode":"// Verify no conflicting JVMTI agents are loaded before attaching Arthas\n// Check JVM launch flags for -agentlib/-javaagent that claim tagging capabilities\nManagementFactory.getRuntimeMXBean().getInputArguments().stream()\n    .filter(a -> a.startsWith(\"-agentlib\") || a.startsWith(\"-javaagent\"))\n    .forEach(a -> log.info(\"Detected agent: \" + a));","typeGuard":null,"tryCatchPattern":"// Native error — handle by detecting init failure and degrading gracefully\nif (!vmtoolCapabilitiesAvailable()) {\n    log.warn(\"vmtool can_tag_objects unavailable — instance scanning disabled\");\n}","preventionTips":["Avoid loading multiple JVMTI agents that compete for object-tagging capabilities.","Use a standard HotSpot/OpenJDK JVM that supports can_tag_objects."],"tags":["arthas","vmtool","jvmti","native","jni","agent","capabilities"],"backgroundTag":null,"analyzedSha":"21cf2e9ba52b305290be7223b980ff504bb9cb5b","analyzedAt":"2026-08-14T00:57:07.243Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}