Skip to content

Implement WatchService for changes made inside the VM - #46

Merged
Project516 merged 14 commits into
masterfrom
p516/watch-service
Nov 5, 2026
Merged

Project516 merged 14 commits into
masterfrom
p516/watch-service

Conversation

@Project516

Copy link
Copy Markdown
Owner

WatchService now works. FileSystems.getDefault().newWatchService() returns the JDK's own LinuxWatchService, and this adds the inotify natives under it. Before this, those natives were missing, so creating a watch service failed.

How it works:

  • The VFS tells listeners when it creates, writes, deletes, renames or sets the time of a path (VFS.watchChanges).
  • Each inotifyInit gets its own state and an in-VM Sock that receives Linux-format inotify_event records. The JDK's poll, read and socketpair calls work on it like any other socket, so a blocked poller does not stall other threads.
  • Renames report the old name as deleted and the new one as created, which is what the JDK makes of IN_MOVED_FROM and IN_MOVED_TO. Removing a watched directory sends IN_IGNORED, so its key becomes invalid. Over 1 MB of queued events sends IN_Q_OVERFLOW, which reports OVERFLOW.
  • Relative watch paths resolve against the VM's working directory.

Tests:

  • test/java/WatchService.java compares create, modify and delete events with HotSpot.
  • 8 OpenJDK tests pass and go into passing.txt: Basic, LotsOfCancels, LotsOfCloses, LotsOfEntries, LotsOfEvents, MayFlies, SensitivityModifier, UpdateInterference.
  • pnpm typecheck, pnpm build and pnpm test pass.

Limits, also in docs/support.md:

  • Only changes made inside the VM are reported. A file another host program changes produces no event.
  • DeleteInterference times out at 120 s: its delete loop finishes, but the test does not end in time. Not in passing.txt.

@coderabbitai

coderabbitai Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 26 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: a4692e19-07dd-42b2-b532-9641879f1a84
Commits

Reviewing files that changed from the base of the PR and between 7ca3747 and 78bd09a.

Files selected for processing: 6

  • docs/support.md
  • src/fs.ts
  • src/natives/nio.ts
  • src/natives/sockets.ts
  • test/java/WatchService.java
  • test/jtreg/passing.txt
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@project516-review-bot project516-review-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR implements WatchService via inotify using an in-VM socket pair. The VFS notifies watchers on create/modify/delete/rename/setMtime; each inotifyInit gets a dedicated Sock that receives Linux-format inotify_event records. The JDK's poll/read/socketpair calls work on this socket. 8 OpenJDK WatchService tests pass. The limitation that only VM-internal changes are reported is documented.


review-bot, model nvidia/nemotron-3-ultra-550b-a55b:free, verdict approve

Comment thread src/natives/sockets.ts Resolved
Comment thread src/natives/sockets.ts Resolved

@project516-review-bot project516-review-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR implements WatchService using inotify over a virtual socket. The VFS notifies watchers on create/modify/delete/rename/setMtime; each inotifyInit gets a non-blocking socket that receives Linux-format inotify_event records. Eight OpenJDK tests pass. The implementation correctly handles the happy path but has a few edge-case gaps: non-directory watch returns ENOENT instead of ENOTDIR, watched directory deletion emits only IN_IGNORED (missing IN_DELETE_SELF), nativePath lacks bounds checking, and rename cookie is always zero (though MOVED_FROM/TO are not currently emitted).


review-bot, model nvidia/nemotron-3-ultra-550b-a55b:free, verdict approve

Comment thread src/natives/sockets.ts Resolved
Comment thread src/natives/sockets.ts Resolved
Comment thread src/natives/sockets.ts Resolved

@project516-review-bot project516-review-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR implements WatchService using an in-VM inotify emulation. The VFS notifies watchers on create/modify/delete/rename/setMtime; each inotifyInit gets a non-blocking Sock that receives Linux-format inotify_event records. The JDK's poll/read/socketpair calls work on these sockets. Eight OpenJDK WatchService tests pass. Two significant defects remain: nativePath reads native memory without bounds checks, and watched-directory deletion emits only IN_IGNORED without the preceding IN_DELETE_SELF that Linux produces.

Not approved: 3 earlier points are still open in the threads.


review-bot, model nvidia/nemotron-3-ultra-550b-a55b:free, verdict comment

Comment thread src/natives/sockets.ts Resolved
Comment thread src/natives/sockets.ts Resolved
Comment thread src/natives/sockets.ts Resolved

@project516-review-bot project516-review-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR implements WatchService by adding a VFS watcher mechanism and an inotify emulation layer over a socket pair. VFS notifies registered callbacks on create, modify, delete, and rename; the native layer translates these into Linux-format inotify events that the JDK's LinuxWatchService consumes. Eight OpenJDK WatchService tests pass. However, the implementation deviates from Linux inotify semantics in ways the passing tests do not cover: IN_DELETE_SELF is not emitted when a watched directory is deleted, the cookie field is always zero (breaking IN_MOVED_FROM/TO correlation), IN_Q_OVERFLOW events use wd=0 instead of -1, and nativePath lacks full address-bounds validation.


review-bot, model nvidia/nemotron-3-ultra-550b-a55b:free, verdict approve

@Project516
Project516 enabled auto-merge (squash) November 5, 2026 14:48
@Project516
Project516 merged commit cebd777 into master Nov 5, 2026
16 checks passed
@Project516
Project516 deleted the p516/watch-service branch November 5, 2026 14:57
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