Repository navigation
Implement WatchService for changes made inside the VM - #46
Conversation
|
Warning Review limit reachedYou'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. View limit details
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. |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
WatchServicenow works.FileSystems.getDefault().newWatchService()returns the JDK's ownLinuxWatchService, and this adds the inotify natives under it. Before this, those natives were missing, so creating a watch service failed.How it works:
VFS.watchChanges).inotifyInitgets its own state and an in-VMSockthat receives Linux-formatinotify_eventrecords. The JDK'spoll,readandsocketpaircalls work on it like any other socket, so a blocked poller does not stall other threads.IN_MOVED_FROMandIN_MOVED_TO. Removing a watched directory sendsIN_IGNORED, so its key becomes invalid. Over 1 MB of queued events sendsIN_Q_OVERFLOW, which reportsOVERFLOW.Tests:
test/java/WatchService.javacompares create, modify and delete events with HotSpot.passing.txt:Basic,LotsOfCancels,LotsOfCloses,LotsOfEntries,LotsOfEvents,MayFlies,SensitivityModifier,UpdateInterference.pnpm typecheck,pnpm buildandpnpm testpass.Limits, also in
docs/support.md:DeleteInterferencetimes out at 120 s: its delete loop finishes, but the test does not end in time. Not inpassing.txt.