Skip to content

Lean NativeObject: NativeObjectChild/Parent split, lock-free plain close - #353

Merged
dfa1 merged 3 commits into
mainfrom
lean-native-object
Nov 16, 2026
Merged

dfa1 merged 3 commits into
mainfrom
lean-native-object

Conversation

@dfa1

@dfa1 dfa1 commented Nov 16, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • New package-private NativeObjectChild (extended by the 7 wrappers that borrow from an owner) holds parents, borrowedFrom, release(), its private monitor and the wait for an in-progress release. NativeObjectWithChildren is renamed NativeObjectParent and extends it (a Transaction is both).
  • Plain NativeObject (45 classes, including PinnableHandle on every get) holds its pointer in a volatile field swapped with a VarHandle: no AtomicReference allocation and no synchronized on close(). A racing close() loser returns at once, as before.
  • NativeObjectParent creates its children set on the first registerChild.
  • The release hook is afterRelease(); doRelease() is the one shared swap, tryClose, hook sequence.

Test plan

  • ./mvnw test -pl core -am, ./mvnw package -pl core -am -DskipTests (javadoc), java scripts/CheckPrototypes.java
  • CI on all platforms
  • No JMH run yet, so the saving on the get path is unmeasured

🤖 Generated with Claude Code

dfa1 and others added 2 commits November 16, 2026 08:14
NativeObject keeps only the pointer, close-once and immortal state; the parents
array and borrowedFrom move to NativeChild, which only the wrappers that borrow
from an owner extend. NativeObjectWithChildren creates its children set on the
first registerChild, so a parent that never gets a child allocates none.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
…oses lock-free

NativeObject holds its pointer in a volatile field swapped with a VarHandle, so
it allocates no AtomicReference and takes no monitor. release(), the private
monitor and the wait-for-an-in-progress-release behavior move to NativeObjectChild,
the only class a parent's sweep releases. The hook is now afterRelease().

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@dfa1 dfa1 changed the title Lean NativeObject: split NativeChild out, allocate children lazily Lean NativeObject: NativeObjectChild/Parent split, lock-free plain close Nov 16, 2026
…the second only if the first kept us

The two-parent form no longer keeps the caller's varargs array; childOf takes one
or two parents. If the first parent abandoned the child there is nothing to
register with the second.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@dfa1
dfa1 merged commit f4a758b into main Nov 16, 2026
7 checks passed
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.

1 participant