{"record":{"id":"3e64980cb87b7ecf","repo":"openjdk/jdk","slug":"javaagent-memory-allocation-failed-n","errorCode":null,"errorMessage":"-javaagent: memory allocation failed\\n","messagePattern":"-javaagent: memory allocation failed\\\\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"src/java.instrument/share/native/libinstrument/InvocationAdapter.c","lineNumber":225,"sourceCode":"         */\n        if (oldLen < 0 || newLen < 0 || newLen > 0xFFFF) {\n            fprintf(stderr, \"-javaagent: Premain-Class value is too big\\n\");\n            free(jarfile);\n            if (options != NULL) free(options);\n            freeAttributes(attributes);\n            return JNI_ERR;\n        }\n        if (newLen == oldLen) {\n            premainClass = strdup(premainClass);\n        } else {\n            char* str = (char*)malloc( newLen+1 );\n            if (str != NULL) {\n                convertUtf8ToModifiedUtf8(premainClass, oldLen, str, newLen);\n            }\n            premainClass = str;\n        }\n        if (premainClass == NULL) {\n            fprintf(stderr, \"-javaagent: memory allocation failed\\n\");\n            free(jarfile);\n            if (options != NULL) free(options);\n            freeAttributes(attributes);\n            return JNI_ERR;\n        }\n\n        /*\n         * If the Boot-Class-Path attribute is specified then we process\n         * each relative URL and add it to the bootclasspath.\n         */\n        bootClassPath = getAttribute(attributes, \"Boot-Class-Path\");\n        if (bootClassPath != NULL) {\n            appendBootClassPath(agent, jarfile, bootClassPath);\n        }\n\n        /*\n         * Convert JAR attributes into agent capabilities\n         */","sourceCodeStart":207,"sourceCodeEnd":243,"githubUrl":"https://github.com/openjdk/jdk/blob/88dfb74bbeefcf2b0aa11835183bcd949998fc8f/src/java.instrument/share/native/libinstrument/InvocationAdapter.c#L207-L243","documentation":"After validating the Premain-Class name, the launcher duplicates or re-encodes it (strdup, or malloc+convertUtf8ToModifiedUtf8 for names containing non-ASCII) and the allocation returned NULL. Startup aborts with JNI_ERR. Like error 133 this is an early-startup native OOM, just at a later step — the message has no trailing period, distinguishing it from the parse-time one.","triggerScenarios":"Same launch path (DEF_Agent_OnLoad) as 133-136, reached with a valid jar/manifest, but malloc(newLen+1) or strdup fails — 32-bit address space exhausted, container memory limit, or extreme memory pressure during JVM init. Very rare in normal operation.","commonSituations":"32-bit JVM with oversized -Xmx; cgroup memory ceiling; swap disabled under pressure; the same conditions that produce error 133 but striking a few allocations later.","solutions":["Relieve memory pressure before launch: stop other processes or raise the container/host memory","Use a 64-bit JVM or reduce -Xmx to leave native allocation room","Retry the launch after freeing resources — transient pressure at init is the usual cause","If persistent, capture native memory usage to rule out a launcher-level leak in custom launchers"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// script-level: only attempt launch when memory is available\n// free -m | awk '/Mem:/{exit ($4 < 256) ? 1 : 0}' || { echo 'wait for memory'; exit 1; }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Retry JVM launch after transient memory pressure passes","Size -Xmx conservatively on 32-bit JVMs","Run agents on hosts with adequate free memory at startup"],"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"}