[9] RFR of 8080589: (fs) FileChannel.force should use fcntl(F_FULLFSYNC) instead of fsync on OS X

Brian Burkhalter brian.burkhalter at oracle.com
Wed May 20 14:28:17 UTC 2015


On May 19, 2015, at 12:55 PM, Robert Muir <rcmuir at gmail.com> wrote:

>> JNIEXPORT jint JNICALL
>> Java_sun_nio_ch_FileDispatcherImpl_force0(JNIEnv *env, jobject this,
>>                                           jobject fdo, jboolean md)
>> {
>>     jint fd = fdval(env, fdo);
>>     int result = 0;
>> 
>> 
>> 
>> +#ifdef MACOSX
>> +#if defined(F_FULLFSYNC)
>> +    result = fcntl(fd, F_FULLFSYNC);
>> +    if (result == -1 && errno == ENOTSUP) {
>> +        /* Try fsync() in case F_FULLSYUNC is not implemented on the file
>> system. */
>> +        result = fsync(fd);
>> +    }
>> +#else
>> +    result = fsync(fd);
>> +#endif /* defined(F_FULLSYNC) */
>> +#else
>>     if (md == JNI_FALSE) {
>>         result = fdatasync(fd);
> 
> for the MACOSX case, fdatasync is not available (and mapped to fsync),
> so in the case some code calls force(false) it appears it will make an
> additional unnecessary call to fsync.

I don’t understand your comment as unless I am mistaken the Mac OS X case will compile per the above either to

 JNIEXPORT jint JNICALL
 Java_sun_nio_ch_FileDispatcherImpl_force0(JNIEnv *env, jobject this,
                                           jobject fdo, jboolean md)
 {
     jint fd = fdval(env, fdo);
     int result = 0;
 
     result = fcntl(fd, F_FULLFSYNC);
     if (result == -1 && errno == ENOTSUP) {
         /* Try fsync() in case F_FULLSYUNC is not implemented on the file system. */
         result = fsync(fd);
     }
     return handle(env, result, "Force failed");
 }

if F_FULLSYNC is defined or to

 JNIEXPORT jint JNICALL
 Java_sun_nio_ch_FileDispatcherImpl_force0(JNIEnv *env, jobject this,
                                           jobject fdo, jboolean md)
 {
     jint fd = fdval(env, fdo);
     int result = 0;
     result = fsync(fd);
     return handle(env, result, "Force failed");
 }

if it is not and in neither case is the variable ‘md’ used.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/nio-dev/attachments/20150520/3e3d56b0/attachment-0001.html>


More information about the nio-dev mailing list