Repository navigation
Keep classes of the same name in different class loaders apart - #27
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]>
Java identifies a class by name and defining loader, but several OpenLDK paths identified it by name alone, so a second loader's class of the same name could replace, or be mistaken for, the first: - User loaders shared their parent's Lisp package, so a second loader's DEFCLASS redefined the first loader's class in place. Each user loader now gets its own package (OPENLDK.L<n>); *ldk-loaders-by-package* maps it back to the loader. - The boot loader's tables are the global tables, which hold every loader's classes, so delegating to the boot loader found unrelated loaders' classes: a second loader's defineClass reused the first's java.lang.Class and overwrote its classLoader. Delegation to the boot loader, classload and findBootstrapClass no longer return a class a user loader defined. - getClass(), reflective construction, allocateInstance, static field storage, isInstance, isAssignableFrom and static-method reflection found the package by class name; they now go through the class's loader. class-package defaults to the loader of the class being compiled. - Method stubs called %compile-method with the class name, and compile claims were keyed by name; stubs now pass the <class>, and a user loader's claims carry the loader. A loader that overrides loadClass (child-first) is now asked before the classpath, so it can supply its own class of a name the classpath has. New aaa/siblingloaders.java and aaa/childfirst.java. docs/CLASSLOADER.md, an early design transcript, now describes the current model. Co-Authored-By: Claude Opus 5.5 <[email protected]>
It was not a class loader bug: Field.get never initialized the declaring class, which #26 fixes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Owner
Author
|
Added |
atgreen
added a commit
that referenced
this pull request
Oct 20, 2026
PRs #19-#21 and #23-#27 added aaa/jitwake, monitorwake, waitwake, zipfile, filestat, lazyloader, reflstatic, siblingloaders and childfirst. check-regression.sh only fails on lost passes and new failures, so a new test is not enforced until it is in the baseline. Core suites now 528 expected passes, up from 501; no test changed state. Generated with make check-regression at 2e5e6db; the Running lines keep the existing baseline's paths. Co-Authored-By: Claude Opus 5.5 <[email protected]>
atgreen
added a commit
that referenced
this pull request
Oct 21, 2026
Fix Clojure protocols on records (a #27 regression), and an unloaded ClassCastException
Closed
Passw
pushed a commit
to Passw/atgreen-openldk
that referenced
this pull request
Oct 23, 2026
emit-<class> names a class's superclass and interfaces with class-symbol-for-reference, which only searched the defining loader's parent chain. A class from a loader outside that chain -- Clojure makes a DynamicClassLoader per evaluation, so a defprotocol's interface and a defrecord implementing it come from sibling loaders -- was missed, a fresh symbol was interned in the new class's package, and the interface was then dropped from its supers. The record was no instance of the protocol's interface: (instance? user.Area (->Sq 5)) was false and calling the protocol method failed. This came in with atgreen#27, when user loaders stopped sharing a package. class-symbol-for-reference now falls back to %resolve-class, which asks the defining loader's loadClass, and names the class in its own package. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
Builds on #25, which it includes as its first commit (
86a10ed). Merge #25 first, and this PR's diff shrinks to789a386.Java identifies a class by its name and its defining loader. Several OpenLDK paths used the name alone, so a second loader's class of the same name could replace, or be mistaken for, the first. Two sibling loaders each defining
HidXX, on master plus #25:The second loader got the first loader's class.
What was wrong, and the fix
The plan in the #25 discussion named three layers. Tracing the test turned up five places that went by name:
defclassredefined the first loader's class in place. Each user loader now gets its own package (OPENLDK.L<n>), and*ldk-loaders-by-package*maps a package back to its loader.defineClassthen reused the first loader'sjava.lang.Classand overwrote itsclassLoader. Delegation to the boot loader (%lookup-class-with-delegation),classloadandfindBootstrapClassno longer return a class a user loader defined.classloadgoes on to the classpath instead, so an app class named like a user loader's class still loads.getClass(), reflective construction (newInstance0via%make-java-instance), bothallocateInstances, static field storage,isInstance,isAssignableFromand static-method reflection. They now go through the class's loader (%java-class-package,ldk-class-package).class-packagenow defaults to the loader of the class being compiled, which covers the JIT's call sites.%compile-methodwith the class name, so the wrong class could be compiled, and compile claims were keyed by name, so a same-named class's method could be marked done and never compile. Stubs now pass the<class>(the name under AOT, whose output is Lisp source). A user loader's claim keys carry the loader.loadClassis now asked before the classpath (%overrides-load-class-p, cached per class), so it can supply its own class of a name the classpath also has. Parent-first loaders keep the cheaper order.docs/CLASSLOADER.mdwas an early design transcript; it now describes how loaders actually work.Tests
New, using
lazyloader's same-length renaming trick:aaa/siblingloaders.java: two loaders each define a class of the same name from different bytecode, and each keeps its own static state, static and instance methods. JVMOK; beforeFAIL: one1 one2 one3 one4 distinct=false; afterOK.aaa/childfirst.java: a child-first loader shadows a classpath class, and its class's reference resolves to the shadow while the app's own class still gets the classpath version. JVMOK; beforeFAIL: parent parent; afterOK.Still passing locally:
lazyloader,zipfile,filestat,jitwake,waitwake,monitorwake.javaclbuilds with no warmup errors and compilesHello.java.Cost of one package per loader
ABCL creates a loader for every compile, so I compared it cold against #25's build. The script ran 30 closure compiles in a loop plus other compiles and CLOS:
time)Results are identical. No measurable cost; the speedup is probably run-to-run noise.
make check-regressioncouldn't run locally (no DejaGnu), so CI's gate is the full check.🤖 Generated with Claude Code