openjdk/jdk · error

java.lang.instrument/-javaagent: allocation failure.\n

Error message

java.lang.instrument/-javaagent: allocation failure.\n

What it means

Emitted by the java.lang.instrument native library when agent initialization fails because a native memory allocation (malloc) failed while setting up the JPLIS agent (e.g. allocating the JPLISAgent structure or its buffers). The agent's Agent_OnLoad returns JNI_ERR, which aborts JVM startup for a -javaagent launched from the command line. It is mapped from JPLIS_INIT_ERROR_ALLOCATION_FAILURE.

Source

Thrown at src/java.instrument/share/native/libinstrument/InvocationAdapter.c:277

        free(jarfile);
    }
    if (options != NULL) free(options);

    switch (initerror) {
    case JPLIS_INIT_ERROR_NONE:
      result = JNI_OK;
      break;
    case JPLIS_INIT_ERROR_CANNOT_CREATE_NATIVE_AGENT:
      result = JNI_ERR;
      fprintf(stderr, "java.lang.instrument/-javaagent: cannot create native agent.\n");
      break;
    case JPLIS_INIT_ERROR_FAILURE:
      result = JNI_ERR;
      fprintf(stderr, "java.lang.instrument/-javaagent: initialization of native agent failed.\n");
      break;
    case JPLIS_INIT_ERROR_ALLOCATION_FAILURE:
      result = JNI_ERR;
      fprintf(stderr, "java.lang.instrument/-javaagent: allocation failure.\n");
      break;
    case JPLIS_INIT_ERROR_AGENT_CLASS_NOT_SPECIFIED:
      result = JNI_ERR;
      fprintf(stderr, "-javaagent: agent class not specified.\n");
      break;
    default:
      result = JNI_ERR;
      fprintf(stderr, "java.lang.instrument/-javaagent: unknown error\n");
      break;
    }
    return result;
}

/*
 * Agent_OnAttach returns a jint. 0/JNI_OK indicates success and non-0
 * indicates an error. To allow the attach mechanism throw an
 * AgentInitializationException with a reasonable exception message we define
 * a few specific errors here.

View on GitHub (pinned to 88dfb74bbe)

Solutions

  1. Raise the container/pod memory limit or system RAM available to the JVM process
  2. Reduce -Xmx/-Xms so more native (off-heap) memory remains for the agent and JVM internals
  3. Check ulimit -v (virtual memory) and raise it if it is capped
  4. Load fewer agents / drop unneeded -javaagent entries to reduce native allocations at startup
  5. Run with jcmd VM.native_memory or NMT to identify native consumers if the problem persists

Example fix

# before
java -Xmx4g -javaagent:app-agent.jar -jar app.jar   # 32-bit JVM, native OOM
# after (leave native headroom / use 64-bit)
java -Xmx1g -javaagent:app-agent.jar -jar app.jar
Defensive patterns

Strategy: validation

Validate before calling

// before launching the JVM, check available native headroom
Runtime rt = Runtime.getRuntime();
long maxHeap = Long.parseLong(System.getProperty("maxHeap", "0"));
if (inContainer() && containerMemLimit() - maxHeap < 256L*1024*1024) {
    throw new IllegalStateException("insufficient native memory headroom for agents/JVM internals");
}

Prevention

When it happens

Trigger: JVM launch with -javaagent (or native agent load via Agent_OnLoad) while the process is out of memory: container memory limits hit, ulimit -v exceeded, very large heap leaving no native space, or a huge number of agents/classpath entries.

Common situations: Running instrumented JVMs in Kubernetes/containers with tight memory caps; 32-bit JVMs with aggressive heap sizes; fork-heavy processes that momentarily exhaust address space.

Related errors


AI-assisted analysis of openjdk/jdk@88dfb74bbe (2026-08-14). Data as JSON: /api/errors/9a1c6c1cc6212fac. Report an issue: GitHub.