{"record":{"id":"a92f7706b103a4c1","repo":"openjdk/jdk","slug":"javaagent-memory-allocation-failure-n","errorCode":null,"errorMessage":"-javaagent: memory allocation failure.\\n","messagePattern":"-javaagent: memory allocation failure\\.\\\\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"src/java.instrument/share/native/libinstrument/InvocationAdapter.c","lineNumber":157,"sourceCode":" *  options components. The jarfile manifest is parsed and the value of the\n *  Premain-Class attribute will become the agent's premain class. The jar\n *  file is then added to the system class path, and if the Boot-Class-Path\n *  attribute is present then all relative URLs in the value are processed\n *  to create boot class path segments to append to the boot class path.\n */\nJNIEXPORT jint JNICALL\nDEF_Agent_OnLoad(JavaVM *vm, char *tail, void * reserved) {\n    JPLISInitializationError initerror  = JPLIS_INIT_ERROR_NONE;\n    jint                     result     = JNI_OK;\n    JPLISAgent *             agent      = NULL;\n    char *                   jarfile    = NULL;\n    char *                   options    = NULL;\n\n    /*\n     * Parse <jarfile>[=options] into jarfile and options\n     */\n    if (parseArgumentTail(tail, &jarfile, &options) != 0) {\n        fprintf(stderr, \"-javaagent: memory allocation failure.\\n\");\n        return JNI_ERR;\n    }\n\n    initerror = createNewJPLISAgent(vm, &agent, jarfile, JNI_FALSE);\n    if ( initerror == JPLIS_INIT_ERROR_NONE ) {\n        int             oldLen, newLen;\n        jarAttribute*   attributes;\n        char *          premainClass;\n        char *          bootClassPath;\n\n        /*\n         * Agent_OnLoad is specified to provide the agent options\n         * argument tail in modified UTF8. However for 1.5.0 this is\n         * actually in the platform encoding - see 5049313.\n         *\n         * Open zip/jar file and parse archive. If can't be opened or\n         * not a zip file return error. Also if Premain-Class attribute\n         * isn't present we return an error.","sourceCodeStart":139,"sourceCodeEnd":175,"githubUrl":"https://github.com/openjdk/jdk/blob/88dfb74bbeefcf2b0aa11835183bcd949998fc8f/src/java.instrument/share/native/libinstrument/InvocationAdapter.c#L139-L175","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Free memory / raise the container memory limit and retry launching the JVM","Use a 64-bit JVM or reduce -Xmx on 32-bit so early native allocations succeed","Shorten the agent option string (options after '=') — pass configuration via system properties or files","Verify the -javaagent syntax: exactly one jar path, options after '='; malformed tails may take failure paths"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// pre-launch sanity for -javaagent options\nString tail = \"/path/agent.jar=opt1,opt2\";\nString jar = tail.split(\"=\", 2)[0];\nif (!Files.isReadable(Path.of(jar)) || jar.length() > 4096) {\n    throw new IllegalArgumentException(\"bad -javaagent tail: \" + tail);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate agent jar path and option length in launch scripts/CI before invoking java","Keep memory headroom at JVM start, especially in containers","Use a 64-bit JVM to avoid early-startup address-space OOM"],"tags":["javaagent","instrumentation","out-of-memory","jvm-startup","native"],"backgroundTag":null,"analyzedSha":"88dfb74bbeefcf2b0aa11835183bcd949998fc8f","analyzedAt":"2026-08-14T11:45:09.665Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}