Sun.misc.Unsafe usage in WindowsNativeDisppatcher

Alan Bateman Alan.Bateman at Sun.COM
Mon Apr 6 12:17:08 PDT 2009


Salter, Thomas A wrote:
> I was surprised that the implementation of WindowsFileAttributes.get uses Unsafe functions to directly access fields in the Windows structure returned by GetFileAttributesEx.  Does this give a large performance gain over a series of SetField calls in the C code?
> -- If not, why add the maintenance issues of keeping Java code in sync with future Windows releases?
> -- If so, why not do the same thing in the Unix implementation?
>   
The Unix/Linux implementation will likely be ported to other 
architectures and Unix implementations so having it reasonably portable 
is useful. Windows is very unique and I wouldn't expect the code to be 
used as a porting base to other operating systems. In terms of 
performance, WindowsFileAttributes.get is dominated by the Win32 call so 
it could have been implemented in native code as you suggest. However, 
maintenance-wise it's a bit of coin toss because a native implementation 
could have a dependency on field type/names like the Unix implementation.

-Alan.




More information about the nio-dev mailing list