Repository navigation
Thread: make the thread-local map on first use - #65
Open
duncanmcqueen wants to merge 1 commit into
Open
duncanmcqueen wants to merge 1 commit into
duncanmcqueen wants to merge 1 commit into
Conversation
This was referenced Oct 14, 2026
duncanmcqueen
marked this pull request as ready for review
October 14, 2026 23:52
Some VMs (for example Kaffe) make the Thread object of the main thread without running a constructor, so its locals field is null and every ThreadLocal fails. Make the field non-final and create the map in getThreadLocals() when it is null. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: duncanmcqueen <dwmcqueen@gmail.com>
duncanmcqueen
force-pushed
the
fix-thread-locals
branch
from
October 15, 2026 13:51
242d7aa to
a1a8c44
Compare
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.
Split from #59.
Problem and fix
ThreadLocalusesThread.locals, which aThreadconstructor sets. Kaffe makes theThreadobject of the main thread without a constructor:KaffeVM_attachFakedThreadInstance()inkaffe/kaffevm/thread.ccallsnewObject(ThreadClass)and sets the fields from C. It does not setlocals. Thus eachThreadLocalon the main thread throwsNullPointerException. Kaffe uses the same function for native threads that attach through JNI.Classpath itself uses
ThreadLocalduring startup (VMAccessController), so Kaffe cannot start any program.This change makes
localsnon-final, andThread.getThreadLocals()makes the map whenlocalsisnull.How to reproduce
This problem occurs only on a VM that makes
Threadobjects without a constructor. JamVM does not, so the test passes on JamVM with and without this change.MainThreadLocal.javaResults
Linux x86_64, ingelabs/classpath
master(0406074), JamVMmaster,javacfrom JDK 8, autoconf 2.73, automake 1.19, theconfigureoptions of the CI Linux job, out-of-tree build. "Before" ismaster. "After" ismasterwith this commit.On Kaffe 1.1.10-pre, the last version in its repository (Haiku x86_64), with the
Threadclasses ofmasterbeforeglibj.zip, Kaffe stops beforemain():With this change:
PASS: get() = value.On JamVM (Linux):
PASS: get() = valuebefore and after.Platforms
Not specific to Haiku, but specific to the VM. The problem occurs with Kaffe on all systems. Kaffe's repository is archived, so I cannot fix it in Kaffe.
I understand if you prefer not to have a workaround for one VM in
Thread. The change is small, and it has no effect on VMs that run aThreadconstructor.AI assistance
An AI model (Claude Code, by Anthropic) wrote this change, the test and this text. The repository owner directed the work and checked the results. Please review it as you review other contributions.
🤖 Generated with Claude Code