Repository navigation
Resolve class references through the defining class loader - #25
Merged
Merged
Conversation
OpenLDK resolved the classes a method refers to, and a class's superclass and interfaces, by name in its own tables and on the classpath, never by asking the Java class loader that defined the class. A loader that defines classes only when findClass is asked, as ABCL's MemoryClassLoader does, never got asked: the JIT substituted an empty stub, and the code then called an undefined OPENLDK::%clinit-. This is why ABCL could not COMPILE a function containing a closure. %resolve-class looks in the defining loader's tables and its parents', then the global tables and classpath as before, and finally calls the user-defined loader's loadClass. The JIT's resolution sites and superclass/interface resolution go through it. Java code run by loadClass doesn't see the outer compile's *context*, a per-thread set stops resolution cycles, and a compile claim now records its thread, so a thread asking for a method it is already compiling gets an error instead of waiting on itself. Class.forName with a user loader now calls loadClass instead of findClass, as the JVM does, so an already-defined class isn't handed to findClass again; with initialize=true it initializes the class the loader returned. Also JDK 25 names that loadClass's findClass path needed: jdk/internal/perf/Perf.registerNatives, and DirectByteBuffer(long, long) in Perf.createLong. aaa/lazyloader.java covers lazily defined classes, a superclass only the loader can find, and forName through loadClass. The ABCL warm image's warmup calls COMPILE on closures again. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Oct 20, 2026
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the class loader bug behind ABCL's
compilefailures (from #24's known issues), and switchesClass.forNametoloadClass.The bug
When OpenLDK resolved a class reference, it looked only in its own tables and on the classpath, never asking the Java class loader that defined the referring class. That applies to the classes a method refers to, at JIT time, and to a class's superclass and interfaces, at definition time. Classes a custom loader had already defined were usually found, because every class is also registered in a global by-name table. A loader that defines classes only when its
findClassis asked, as ABCL'sMemoryClassLoaderdoes, never got asked. The JIT silently substituted an empty stub class (classfile.lisp:217), and the generated code then called an undefinedOPENLDK::%clinit-…. That's why(compile 'make-adder)on a closure failed, cold or in an image.The fix
%resolve-class name ldk-loader(src/openldk.lisp):loadClassThe JIT's resolution sites (class constants in
classfile.lisp, 13classloadcalls incodegen.lispandbc-to-ir.lisp) and superclass/interface resolution in%classload-from-streamgo through it, using the defining loader.Calling Java from inside the JIT needs guards:
loadClassruns with*context*bound to nil, so its Java code can't see the outer compile's context.loadClass→defineClass→ resolve the superclass →loadClass.%claim-method-compilationnow records its thread instead oft. A thread asking for a method it's already compiling gets aninternal-errorinstead of waiting on itself forever. The image cleanup incli.lispdrops any claim that isn't:done.Order: the Java loader is asked last, so a child-first loader that shadows a classpath class still gets the classpath version. That's part of the deferred problem of same-named classes in two loaders, which comes from the global by-name table.
Class.forNameforName0with a user loader now callsloadClass, which checks the loader's own already-loaded classes, delegates to its parent, and only then callsfindClass. Before, it calledfindClassdirectly. Withinitialize=true, it now initializes the class the loader returned rather than looking it up by name in the global table.JDK 25 leftovers this path hit
When
loadClassfalls through tofindClass, the JDK bumps aPerfCounter. That neededjdk/internal/perf/Perf.registerNatives(JDK 9+ package) andDirectByteBuffer(long, long)inPerf.createLong(was JDK 8's(long, int)).Tests
New
aaa/lazyloader.javahas a loader that defines classes only fromfindClass. Its classes exist nowhere else: they're made from nestedGen*classes by renaming them toHid*(same length, so the class files stay valid). The test checks:HidA's code reads a static ofHidBHidC's superclassHidBaseis found through the loaderClass.forName(…, loader)on an already-defined class doesn't callfindClassagain (counted), andforName("java.lang.String", …, loader)returnsStringResults:
OK.OPENLDK::|%clinit-aaa/lazyloader$HidB|is undefined.forName0change reverted:FAIL: …; false; true, thefindClasscount.zipfile,filestat,waitwake,monitorwakeandjitwakestill pass.ABCL, cold:
(compile 'make-adder)→(funcall (make-adder 3) 4)returns 7, a compiled pair of closures over one counter returns 2, anddefclass/defgeneric/defmethodwork with the compiler loaded.ABCL warm image: the warmup calls
compileon closures again. The image prints its prompt and quits in 0.1 s and runs all of the above correctly. It's 740 MB and builds in about 8.5 minutes.docs/ABCL.mdanddocs/IMAGES.mdare updated, and the closure limitation is gone from both.make check-regressioncouldn't run locally (no DejaGnu), so CI's gate is the full check.Still open
%compile-methodfinding classes by name.Field.get(null)returning null for statics of custom-loader classes.🤖 Generated with Claude Code