Skip to content

Fix a JIT-failure loop, and read JMODs with file-absolute zip offsets - #14

Merged
atgreen merged 2 commits into
atgreen:masterfrom
burinc:fix/jit-error-stub-and-jmod-prefix
Oct 18, 2026
Merged

atgreen merged 2 commits into
atgreen:masterfrom
burinc:fix/jit-error-stub-and-jmod-prefix

Conversation

@burinc

@burinc burinc commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Two bugs that together made a call hang at full CPU on GraalVM CE 25.0.1. Each reproduces on OpenLDK alone.

1. A failed JIT compile of an instance method loops forever. %install-jit-error-stub interns the stub in the class loader's package (OPENLDK.APP for the classpath), but instance methods dispatch on a generic function in :openldk. The error stub lands on the wrong function, the lazy stub survives, and every call finds the method already marked compiled and calls the stub again. The fix interns instance-method stubs in :openldk. Static methods are unchanged.

2. JMODs whose zip offsets count from the start of the file. open-jmod-zipfile always skips the 4-byte JM\1\0 header. That's right for all 69 jmods in Oracle OpenJDK 25.0.2, but 30 of the 84 in GraalVM CE 25.0.1 count from the file start, so they fail zip's signature check, and initialize can't start on that JDK. The new zip-prefix-length computes the prefix from the end record, Info-ZIP's way, and keeps 4 when it can't tell (no end record, zip64). The file is also closed if reading it fails.

q.JsrMain (an instance method using jsr) OpenJDK 25.0.2 GraalVM CE 25.0.1
master hangs initialize fails the zip check
this branch "JIT compilation failed for p/Jsr.m()V" in 6 s the same

Checks: unit tests 25/25 (5 new), ocicl lint matches master, and make check-regression gives the same per-test results as master. macOS arm64, SBCL 2.6.9.

Reproduction

jsr.py writes the class:

# Writes p/Jsr.class: version 49, public Jsr() { super(); m(); },
# void m() { jsr L; return; L: astore_1; ret 1 }
import struct, os
u2 = lambda x: struct.pack(">H", x)
u4 = lambda x: struct.pack(">I", x)
utf8 = lambda s: b"\x01" + u2(len(s)) + s.encode()
cp = [utf8("p/Jsr"), b"\x07" + u2(1), utf8("java/lang/Object"), b"\x07" + u2(3),
      utf8("<init>"), utf8("()V"), b"\x0c" + u2(5) + u2(6), b"\x0a" + u2(4) + u2(7),
      utf8("m"), b"\x0c" + u2(9) + u2(6), b"\x0a" + u2(2) + u2(10), utf8("Code")]
def code(stack, locals_, bc):
    body = u2(stack) + u2(locals_) + u4(len(bc)) + bytes(bc) + u2(0) + u2(0)
    return u2(12) + u4(len(body)) + body
def method(flags, name, attr):
    return u2(flags) + u2(name) + u2(6) + u2(1) + attr
b = (u4(0xCAFEBABE) + u2(0) + u2(49) + u2(len(cp) + 1) + b"".join(cp)
     + u2(0x21) + u2(2) + u2(4) + u2(0) + u2(0) + u2(2)
     + method(0x0001, 5, code(1, 1, [0x2a, 0xb7, 0, 8, 0x2a, 0xb6, 0, 11, 0xb1]))
     + method(0x0000, 9, code(1, 2, [0xa8, 0, 4, 0xb1, 0x4c, 0xa9, 1]))
     + u2(0))
os.makedirs("classes/p", exist_ok=True)
open("classes/p/Jsr.class", "wb").write(b)

q/JsrMain.java:

package q;
public class JsrMain {
  public static void main(String[] a) {
    try { new p.Jsr(); System.out.println("MAIN: constructed"); }
    catch (Throwable t) { System.out.println("MAIN: threw " + t); }
    System.out.println("MAIN: done");
  }
}
python3 jsr.py
javac --release 8 -cp classes -d classes q/JsrMain.java
(cd classes && jar cf ../jsrmain.jar q/JsrMain.class p/Jsr.class)

Run with (openldk::main "q.JsrMain" nil :classpath "jsrmain.jar") after (openldk::initialize).

When %compile-method fails, %install-jit-error-stub replaces the lazy
compile stub with one that signals.  It interned the method's name in
the class loader's package, but instance methods dispatch on a generic
function in :openldk: that is where the lazy stub's defmethod goes and
where %build-method-definition puts a compiled method.

For a class from a user loader (OPENLDK.APP for the classpath) the error
stub therefore went onto an unrelated generic function and the lazy stub
survived.  Each call then ran %compile-method, which returns at once for
a method already marked :done, and invoked the same stub again, so the
call never returned and the process spun at full CPU.

Static methods were unaffected: their stub and their error stub both
live in the loader's package.

Reproduced with a version-49 class whose constructor calls an instance
method that uses jsr, which OpenLDK does not translate.  Before: hangs
after "JIT-ERROR in p/Jsr.m()V: The function :JSR is undefined."  After:
signals OPENLDK-INTERNAL-ERROR "JIT compilation failed for p/Jsr.m()V".
open-jmod-zipfile always skipped 4 bytes, the JM\1\0 header, so it
expected the zip offsets inside a JMOD to count from after the header.
That holds for all 69 JMODs in Oracle OpenJDK 25.0.2, but 30 of the 84
in GraalVM CE 25.0.1 (java.desktop, java.instrument, java.management,
java.prefs, jdk.compiler and others) count from the start of the file.
Those were read 4 bytes past their central directory and failed zip's
signature assertion.  Since OpenLDK reads the JDK from jmods/ when it
exists, any class lookup that reached one of them failed, including
INITIALIZE's preload of jdk/internal/org/objectweb/asm/ClassWriter,
which JDK 24 removed, so OpenLDK could not start on that JDK.

The new ZIP-PREFIX-LENGTH computes the prefix the way Info-ZIP does for
an archive with one: the end record's position less the end of the
central directory it describes.  It gives 4 or 0 for the two layouts,
and NIL (keep 4) when there is no end record or it is a zip64 one.

open-jmod-zipfile also closes the file if reading it fails.

- Unit test ZIP-PREFIX-LENGTH in test/tests.lisp
burinc added a commit to jlt-commons/jolt-openldk that referenced this pull request Oct 14, 2026
burinc added a commit to jlt-commons/jolt-openldk that referenced this pull request Oct 14, 2026
@burinc burinc changed the title Fix a JIT-failure loop for instance methods, and read JMODs whose zip offsets count from the file start Fix a JIT-failure loop, and read JMODs with file-absolute zip offsets Oct 14, 2026
@atgreen
atgreen merged commit edc475d into atgreen:master Oct 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants