openjdk/jdk · critical

-javaagent: memory allocation failure.\n

Error message

-javaagent: memory allocation failure.\n

What it means

While JVM startup parsed the -javaagent option, parseArgumentTail() failed to split '<jarfile>[=options]' — in practice it fails when it cannot allocate memory for the copies of jarfile/options strings. The launcher prints this message and returns JNI_ERR, so the JVM refuses to start. It is an early-startup OOM/malloc failure, distinct from later agent class loading errors.

Source

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

 *  options components. The jarfile manifest is parsed and the value of the
 *  Premain-Class attribute will become the agent's premain class. The jar
 *  file is then added to the system class path, and if the Boot-Class-Path
 *  attribute is present then all relative URLs in the value are processed
 *  to create boot class path segments to append to the boot class path.
 */
JNIEXPORT jint JNICALL
DEF_Agent_OnLoad(JavaVM *vm, char *tail, void * reserved) {
    JPLISInitializationError initerror  = JPLIS_INIT_ERROR_NONE;
    jint                     result     = JNI_OK;
    JPLISAgent *             agent      = NULL;
    char *                   jarfile    = NULL;
    char *                   options    = NULL;

    /*
     * Parse <jarfile>[=options] into jarfile and options
     */
    if (parseArgumentTail(tail, &jarfile, &options) != 0) {
        fprintf(stderr, "-javaagent: memory allocation failure.\n");
        return JNI_ERR;
    }

    initerror = createNewJPLISAgent(vm, &agent, jarfile, JNI_FALSE);
    if ( initerror == JPLIS_INIT_ERROR_NONE ) {
        int             oldLen, newLen;
        jarAttribute*   attributes;
        char *          premainClass;
        char *          bootClassPath;

        /*
         * Agent_OnLoad is specified to provide the agent options
         * argument tail in modified UTF8. However for 1.5.0 this is
         * actually in the platform encoding - see 5049313.
         *
         * Open zip/jar file and parse archive. If can't be opened or
         * not a zip file return error. Also if Premain-Class attribute
         * isn't present we return an error.

View on GitHub (pinned to 88dfb74bbe)

Solutions

  1. Free memory / raise the container memory limit and retry launching the JVM
  2. Use a 64-bit JVM or reduce -Xmx on 32-bit so early native allocations succeed
  3. Shorten the agent option string (options after '=') — pass configuration via system properties or files
  4. Verify the -javaagent syntax: exactly one jar path, options after '='; malformed tails may take failure paths
Defensive patterns

Strategy: validation

Validate before calling

// pre-launch sanity for -javaagent options
String tail = "/path/agent.jar=opt1,opt2";
String jar = tail.split("=", 2)[0];
if (!Files.isReadable(Path.of(jar)) || jar.length() > 4096) {
    throw new IllegalArgumentException("bad -javaagent tail: " + tail);
}

Prevention

When it happens

Trigger: java -javaagent:/path/agent.jar=options at process start with the process unable to malloc a few hundred bytes — address space exhausted (32-bit), container memory cap hit before JVM init, or a corrupted/absurdly long option tail that behaves pathologically. Def_Agent_OnLoad runs inside the launcher before the JVM is fully up.

Common situations: 32-bit JVM with -Xmx leaving no native room; containers with memory limits killing/constraining early allocation; extremely long -javaagent option strings from build tooling (Gradle/Maven inject agents); system under memory pressure at JVM launch.

Related errors


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