Deduplicating code in BsdUserDefinedFileAttributeView and LinuxUserDefinedFileAttributeView

Sebastian Stenzel sebastian.stenzel at gmail.com
Mon Jan 25 08:30:41 UTC 2021


> On 21. Jan 2021, at 15:08, Alan Bateman <Alan.Bateman at oracle.com> wrote:
> 
>> 2. The main goal is, obviously, deduplication. I.e. a lot of code from the Linux* and Bsd* classes can be moved to their parent: Unix*. We have to keep in mind though, that their sibling Aix* doesn't support UserDefinedAttributeView. Since there are minor differences between BsdNativeDispatcher and LinuxNativeDispatcher, I'd like to know if it's ok to make UnixNativeDispatcher abstract or whether there is a reason why they shouldn't be (any problems with JNI and abstract classes?).
> That would be disruptive change. UnixNativeDispatcher.c already has to deal with issues like this and it's okay if the it compiles to JNU_ThrowInternalError on AIX. In modules/java.base/Java.gmk you'll seen a few examples where specific classes are included/excluded. In this case, I assume you will include UnixUserDefinedFileAttributeView in the Linux and macOS builds.

I have to admit, that I don't feel too comfortable with branching code based on preprocessor directives, therefore I preferred to keep native code OS specific. But let's give it a try:

I guess the pattern here is to assign the `my_methodhandle` to whatever applies during init(), as it is done e.g. for `my_futimens_func`? May I ask why this is done via dlsym()? Since the code is inside an #ifdef directive, so the compiler can't reach it if not applicable, can't I just assign my_futimens_func = futimens?

Am I right that we're dealing with four platforms (Linux, Aix, BSD and macOS, the latter being a "special" BSD), that can be distinguished via #ifdef using one of these:

```
__linux__
_AIX
_ALLBSD_SOURCE
MACOSX
```

What about `#ifdef __APPLE__`? I can see this used in various other places.

If `_ALLBSD_SOURCE` is supposed to include all BSD flavours, can I simplify this:

```
#if defined(__linux__) || defined(_AIX)
#include <string.h>
#endif

#ifdef _ALLBSD_SOURCE
#include <string.h>
...
#endif
```

to this:

```
#include <string.h>
```

?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/nio-dev/attachments/20210125/6debbc6a/attachment.htm>


More information about the nio-dev mailing list