RFR: 8341282: (fs) Move creation time fallback logic to Java layer (Linux)

Severin Gehwolf sgehwolf at openjdk.org
Tue Oct 1 09:06:37 UTC 2024


On Mon, 30 Sep 2024 22:57:15 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:

> Move the decision as to whether `BasicFileAttributes.creationTime()` falls back to the modified time from the native layer to the Java layer.

As for the test, we should also consider getting https://github.com/openjdk/jdk/pull/20687 in since it currently doesn't handle all cases which this patch again touches. Specifically some systems with the correct kernel/glibc combination but on a filesystem without support the test is broken as-is.

src/java.base/unix/classes/sun/nio/fs/UnixFileAttributes.java line 61:

> 59:     private long    st_birthtime_sec;
> 60:     private long    st_birthtime_nsec;
> 61:     private boolean birthtime_invalid;

Suggestion:

    private boolean birthtime_filled_in;


Perhaps we should add a comment that this is Linux-only and will only be true for Linux filesystems that support birth time.

src/java.base/unix/classes/sun/nio/fs/UnixFileAttributes.java line 167:

> 165:     @Override
> 166:     public FileTime creationTime() {
> 167:         if (UnixNativeDispatcher.birthtimeSupported() && !birthtime_invalid) {

Suggestion:

        if (UnixNativeDispatcher.birthtimeSupported() && birthtime_filled_in) {

src/java.base/unix/native/libnio/fs/UnixNativeDispatcher.c line 186:

> 184: #if defined(__linux__) // Linux has nsec granularity if supported
> 185: static jfieldID attrs_st_birthtime_nsec;
> 186: static jfieldID attrs_birthtime_invalid;

Suggestion:

static jfieldID attrs_birthtime_filled_in;

src/java.base/unix/native/libnio/fs/UnixNativeDispatcher.c line 336:

> 334:     CHECK_NULL_RETURN(attrs_st_birthtime_nsec, 0);
> 335: 
> 336:     attrs_birthtime_invalid = (*env)->GetFieldID(env, clazz, "birthtime_invalid", "Z");

Suggestion:

    attrs_birthtime_filled_in = (*env)->GetFieldID(env, clazz, "birthtime_filled_in", "Z");

src/java.base/unix/native/libnio/fs/UnixNativeDispatcher.c line 337:

> 335: 
> 336:     attrs_birthtime_invalid = (*env)->GetFieldID(env, clazz, "birthtime_invalid", "Z");
> 337:     CHECK_NULL_RETURN(attrs_birthtime_invalid, 0);

Suggestion:

    CHECK_NULL_RETURN(attrs_birthtime_filled_in, 0);

src/java.base/unix/native/libnio/fs/UnixNativeDispatcher.c line 636:

> 634:         JNI_FALSE : JNI_TRUE;
> 635:     (*env)->SetBooleanField(env, attrs, attrs_birthtime_invalid,
> 636:                             birthtime_invalid);

Suggestion:

    // Only set birthtime_filled_in to true when the returned mask indicates so.
    // Note that on some (Linux) filesystems birth time is not supported while it is supported for others.
    jboolean birthtime_filled_in = (buf->stx_mask & STATX_BTIME) != 0 ?
        JNI_TRUE : JNI_FALSE;
    (*env)->SetBooleanField(env, attrs, attrs_birthtime_filled_in,
                            birthtime_filled_in);

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

PR Review: https://git.openjdk.org/jdk/pull/21274#pullrequestreview-2339565204
PR Review Comment: https://git.openjdk.org/jdk/pull/21274#discussion_r1782391038
PR Review Comment: https://git.openjdk.org/jdk/pull/21274#discussion_r1782395796
PR Review Comment: https://git.openjdk.org/jdk/pull/21274#discussion_r1782397239
PR Review Comment: https://git.openjdk.org/jdk/pull/21274#discussion_r1782397711
PR Review Comment: https://git.openjdk.org/jdk/pull/21274#discussion_r1782398381
PR Review Comment: https://git.openjdk.org/jdk/pull/21274#discussion_r1782402791


More information about the nio-dev mailing list