alibaba/arthas · critical
ERROR: arthas vmtool Unable to create jvmtiEnv, GetEnv faile
Error message
ERROR: arthas vmtool Unable to create jvmtiEnv, GetEnv failed, error=%d
What it means
In the arthas-vmtool native agent (jni-library.cpp), init_agent() calls JavaVM::GetEnv() to obtain a JVMTI 1.2 environment. If GetEnv returns anything other than JNI_OK (e.g. JNI_EDETACHED, JNI_EVERSION), the agent cannot function and prints this error to stderr, returning -1. Without a JVMTI env, the agent cannot tag objects or iterate the heap.
Source
Thrown at arthas-vmtool/src/main/native/src/jni-library.cpp:46
bool allow() {
if (limitValue < 0) {
return true;
}
return limitValue > currentCounter;
}
};
// 每次 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);
}View on GitHub (pinned to 21cf2e9ba5)
Solutions
- Ensure the agent is loaded through the supported Arthas attach mechanism which handles thread attachment.
- Verify you are running on a standard JDK (HotSpot/OpenJ9) that provides JVMTI 1.2.
- Check the JVM version and that JVMTI is not disabled by JVM flags.
- If attaching programmatically, ensure the attaching thread is attached via AttachCurrentThread before loading the agent.
Example fix
// not a source-code fix — environment/JVM fix // before: agent loaded on detached thread or unsupported JVM -> error rc=-2 (JNI_EDETACHED) // after: attach thread first, or use arthas standard attach // arthas-boot.jar handles attach correctly: java -jar arthas-boot.jar <pid>
Defensive patterns
Strategy: fallback
Validate before calling
// Not fixable in application code — verify JVM/JVMTI availability
String jvmName = System.getProperty("java.vm.name");
if (!jvmName.contains("HotSpot") && !jvmName.contains("OpenJDK") && !jvmName.contains("J9")) {
log.warn("vmtool may not be supported on JVM: " + jvmName);
} Try / catch
// Native error — no Java try-catch. Handle by checking stderr output
// or disabling vmtool features when the agent fails to init.
if (!vmtoolAgentAvailable()) {
log.warn("vmtool JVMTI init failed — heap scanning disabled");
} Prevention
- Run Arthas vmtool on a standard JDK with JVMTI support.
- Use the standard arthas-boot.jar attach mechanism which handles thread attachment correctly.
When it happens
Trigger: The vmtool agent is loaded/initialized in a context where the JVM cannot provide a JVMTI 1.2 environment: the calling thread is not attached to the JVM (JNI_EDETACHED), the JVM doesn't support the requested JVMTI version (JNI_EVERSION), or the VM is in a state that rejects GetEnv.
Common situations: Agent loaded via Agent_OnAttach from a thread not attached to the JVM; running on a JVM that lacks or disables JVMTI (some minimal/embedded JVMs); JVM version mismatch where JVMTI_VERSION_1_2 is unsupported; the agent was loaded too early or too late in the VM lifecycle.
Related errors
- ERROR: arthas vmtool JVMTI AddCapabilities failed!%u
- Arthas server port binding failed! Please check $HOME/logs/a
- Unsupported platform: {}-{}
- can not getResources arthas-bin.zip from classloader: ${clas
- can not find arthas-core.jar under arthasHome: ${arthasHome}
AI-assisted analysis of alibaba/arthas@21cf2e9ba5 (2026-08-14).
Data as JSON: /api/errors/e803771245311571.
Report an issue: GitHub.