RFR: 8288627: [AIX] Implement WatchService using system library

Tyler Steele tsteele at openjdk.org
Thu Jul 7 16:50:39 UTC 2022


On Fri, 24 Jun 2022 15:17:47 GMT, Tyler Steele <tsteele at openjdk.org> wrote:

> This PR begins an effort to re-implement the WatchService API on AIX using 'AIX Event Infrastructure' (AHAFS). The initial motivation for doing so was to address errors found by some internal testing in the implementation based on PollingWatchService.java.
> 
> I am submitting these changes before they are fully complete because (1) it represents a fairly large change that mostly works well, and could easily be improved upon in the future; (2) to get some early feedback on the changes so the final review process is quicker. My expected plan is to merge these changes after review, add any remaining test failures to a problem list, and return to them soon.
> 
> ### Testing
> I am waiting for confirmation that this re-implementation passes the internal tests we saw failing. Initial results look promising. In addition, I see the following failing tests from `test/jdk/java/nio/file/WatchService`:
> 
> - Basic.java fails at testTwoWatchers. Having two WatchService instances registered with the same file, will require some additional work to be supported with AHAFS. This is currently a limitation of this implementation.
> - DeleteInterference.java fails for the same reason as above.
> - UpdateInterference.java fails for no good reason that I can deduce. Logging the test's progress shows that it doesn't seem to leave [the main loop](https://github.com/openjdk/jdk/blob/master/test/jdk/java/nio/file/WatchService/UpdateInterference.java#L97-L111), but that it makes is to within 1ms of doing so.

Thanks for your comments Alan:

> I suspect you really want toRealPath rather than normalise + toAbsolutePath.

Thanks for pointing that out. Yes, that method is what I was looking for. I have made this change. 

> Calling Files means you are calling the API from the provider which will be problematic if the default provider is configured to be something else.

I debated creating and using an instance of AixFileSystem directly. It didn't seem like it would be worth the trouble, but I'm open to changing that opinion. If this code is somehow being run on a non-AIX machine, I'm sure this would not be their only issue. There is another complication if we go this route: createDirectories is implemented in Files.java, so using createDirectory from AixFileSystem would mean duplicating this functionality in my implementation.

> Also I'm quite sure this won't work with a security manager as the code is missing a doPrivileged.

I'm sure you're right. I didn't think too hard about the Security Manager since it is now depreciated. I agree that there are a few places that would cause issues. If preferred, I am happy to work in any changes necessary to support it.

> The loops ... in the native methods in this patch can all be hoisted to the Java code which will make it much easier to maintain.

This is tricky, since the loops examine values in the c-struct. Without a StructLayout object or some other way of examining values in foreign memory, I'm not sure how to do this in a clean way. Maybe there is a solution for manipulating c-structs in Java that I am not aware of; the way to do this that I am familiar with is currently a preview API (JEP-424).

> Also lines of line 170+ characters are a pain for future side-by-side diffs so keeping lines to sane line would be helpful.

I've wrapped the longer lines. I am also happy to change any formatting, just let me know what you'd like changed.

-------------

PR: https://git.openjdk.org/jdk/pull/9281


More information about the nio-dev mailing list