-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
8338884: java/nio/file/attribute/BasicFileAttributeView/CreationTime.…
…java#tmp fails on alinux3 Reviewed-by: sgehwolf, bpb
- Loading branch information
SendaoYan
committed
Oct 10, 2024
1 parent
475f8f9
commit 9d621d3
Showing
4 changed files
with
200 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
test/jdk/java/nio/file/attribute/BasicFileAttributeView/CreationTimeHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright (c) 2024 Alibaba Group Holding Limited. All Rights Reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
*/ | ||
|
||
import java.lang.foreign.Arena; | ||
import java.lang.foreign.FunctionDescriptor; | ||
import java.lang.foreign.Linker; | ||
import java.lang.foreign.MemorySegment; | ||
import java.lang.foreign.SymbolLookup; | ||
import java.lang.foreign.ValueLayout; | ||
import java.lang.invoke.MethodHandle; | ||
|
||
public class CreationTimeHelper extends NativeTestHelper { | ||
|
||
static { | ||
System.loadLibrary("CreationTimeHelper"); | ||
} | ||
|
||
final static Linker abi = Linker.nativeLinker(); | ||
static final SymbolLookup lookup = SymbolLookup.loaderLookup(); | ||
final static MethodHandle methodHandle = abi. | ||
downcallHandle(lookup.findOrThrow("linuxIsCreationTimeSupported"), | ||
FunctionDescriptor.of(C_BOOL, C_POINTER)); | ||
|
||
// Helper so as to determine birth time support or not on Linux. | ||
// Support is determined in a two-step process: | ||
// 1. Determine if `statx` system call is available. If available proceed, | ||
// otherwise return false. | ||
// 2. Perform an actual `statx` call on the given file and check for birth | ||
// time support in the mask returned from the call. This is needed, | ||
// since some file systems, like nfs/tmpfs etc., don't support birth | ||
// time even though the `statx` system call is available. | ||
static boolean linuxIsCreationTimeSupported(String file) throws Throwable { | ||
if (!abi.defaultLookup().find("statx").isPresent()) { | ||
return false; | ||
} | ||
try (var arena = Arena.ofConfined()) { | ||
MemorySegment s = arena.allocateFrom(file); | ||
return (boolean)methodHandle.invokeExact(s); | ||
} | ||
} | ||
} |
117 changes: 117 additions & 0 deletions
117
test/jdk/java/nio/file/attribute/BasicFileAttributeView/libCreationTimeHelper.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
/* | ||
* Copyright (c) 2024 Alibaba Group Holding Limited. All Rights Reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
*/ | ||
#include "export.h" | ||
#include <stdbool.h> | ||
#if defined(__linux__) | ||
#include <linux/fcntl.h> | ||
#include <stdio.h> | ||
#include <string.h> | ||
#include <sys/stat.h> | ||
#include <bits/types.h> | ||
#include <dlfcn.h> | ||
#ifndef STATX_BASIC_STATS | ||
#define STATX_BASIC_STATS 0x000007ffU | ||
#endif | ||
#ifndef STATX_BTIME | ||
#define STATX_BTIME 0x00000800U | ||
#endif | ||
#ifndef RTLD_DEFAULT | ||
#define RTLD_DEFAULT RTLD_LOCAL | ||
#endif | ||
|
||
/* | ||
* Timestamp structure for the timestamps in struct statx. | ||
*/ | ||
struct my_statx_timestamp { | ||
__int64_t tv_sec; | ||
__uint32_t tv_nsec; | ||
__int32_t __reserved; | ||
}; | ||
|
||
/* | ||
* struct statx used by statx system call on >= glibc 2.28 | ||
* systems | ||
*/ | ||
struct my_statx | ||
{ | ||
__uint32_t stx_mask; | ||
__uint32_t stx_blksize; | ||
__uint64_t stx_attributes; | ||
__uint32_t stx_nlink; | ||
__uint32_t stx_uid; | ||
__uint32_t stx_gid; | ||
__uint16_t stx_mode; | ||
__uint16_t __statx_pad1[1]; | ||
__uint64_t stx_ino; | ||
__uint64_t stx_size; | ||
__uint64_t stx_blocks; | ||
__uint64_t stx_attributes_mask; | ||
struct my_statx_timestamp stx_atime; | ||
struct my_statx_timestamp stx_btime; | ||
struct my_statx_timestamp stx_ctime; | ||
struct my_statx_timestamp stx_mtime; | ||
__uint32_t stx_rdev_major; | ||
__uint32_t stx_rdev_minor; | ||
__uint32_t stx_dev_major; | ||
__uint32_t stx_dev_minor; | ||
__uint64_t __statx_pad2[14]; | ||
}; | ||
|
||
typedef int statx_func(int dirfd, const char *restrict pathname, int flags, | ||
unsigned int mask, struct my_statx *restrict statxbuf); | ||
|
||
static statx_func* my_statx_func = NULL; | ||
#endif //#defined(__linux__) | ||
|
||
// static boolean linuxIsCreationTimeSupported(char* file) | ||
EXPORT bool linuxIsCreationTimeSupported(char* file) { | ||
#if defined(__linux__) | ||
struct my_statx stx = {0}; | ||
int ret, atflag = AT_SYMLINK_NOFOLLOW; | ||
unsigned int mask = STATX_BASIC_STATS | STATX_BTIME; | ||
|
||
my_statx_func = (statx_func*) dlsym(RTLD_DEFAULT, "statx"); | ||
if (my_statx_func == NULL) { | ||
return false; | ||
} | ||
|
||
if (file == NULL) { | ||
printf("input file error!\n"); | ||
return false; | ||
} | ||
|
||
ret = my_statx_func(AT_FDCWD, file, atflag, mask, &stx); | ||
if (ret != 0) { | ||
return false; | ||
} | ||
// On some systems where statx is available but birth time might still not | ||
// be supported as it's file system specific. The only reliable way to | ||
// check for supported or not is looking at the filled in STATX_BTIME bit | ||
// in the returned statx buffer mask. | ||
if ((stx.stx_mask & STATX_BTIME) != 0) | ||
return true; | ||
return false; | ||
#else | ||
return false; | ||
#endif | ||
} |
9d621d3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review
Issues
9d621d3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/backport jdk23u
9d621d3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sendaoYan the backport was successfully created on the branch backport-sendaoYan-9d621d39-master in my personal fork of openjdk/jdk23u. To create a pull request with this backport targeting openjdk/jdk23u:master, just click the following link:
➡️ Create pull request
The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:
If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk23u: