-
Bug
-
Resolution: Fixed
-
P3
-
None
-
None
-
b48
-
x86
-
linux_ubuntu
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8084412 | emb-9 | Peter Levart | P3 | Resolved | Fixed | team |
If I run this java program on Linux
public class SecureRandoms {
public static void main(String[] args) throws Throwable {
new java.security.SecureRandom();
}
}
it creates 6 file descriptors for /dev/random and /dev/urandom, as shown by:
strace -q -ff -e open java SecureRandoms |& grep /dev/
[pid 20769] open("/dev/random", O_RDONLY) = 5
[pid 20769] open("/dev/urandom", O_RDONLY) = 6
[pid 20769] open("/dev/random", O_RDONLY) = 7
[pid 20769] open("/dev/random", O_RDONLY) = 8
[pid 20769] open("/dev/urandom", O_RDONLY) = 9
[pid 20769] open("/dev/urandom", O_RDONLY) = 10
Looking at jdk/src/solaris/classes/sun/security/provider/NativePRNG.java
it looks like 2 file descriptors are created for every variant of NativePRNG, whether or not they are ever used. Which is wasteful. In fact, you only ever need at most two file descriptors, one for /dev/random and one for /dev/urandom.
Further, it would be nice if the file descriptors were closed when idle and lazily re-created. Especially /dev/random should typically be used at startup and never thereafter.
public class SecureRandoms {
public static void main(String[] args) throws Throwable {
new java.security.SecureRandom();
}
}
it creates 6 file descriptors for /dev/random and /dev/urandom, as shown by:
strace -q -ff -e open java SecureRandoms |& grep /dev/
[pid 20769] open("/dev/random", O_RDONLY) = 5
[pid 20769] open("/dev/urandom", O_RDONLY) = 6
[pid 20769] open("/dev/random", O_RDONLY) = 7
[pid 20769] open("/dev/random", O_RDONLY) = 8
[pid 20769] open("/dev/urandom", O_RDONLY) = 9
[pid 20769] open("/dev/urandom", O_RDONLY) = 10
Looking at jdk/src/solaris/classes/sun/security/provider/NativePRNG.java
it looks like 2 file descriptors are created for every variant of NativePRNG, whether or not they are ever used. Which is wasteful. In fact, you only ever need at most two file descriptors, one for /dev/random and one for /dev/urandom.
Further, it would be nice if the file descriptors were closed when idle and lazily re-created. Especially /dev/random should typically be used at startup and never thereafter.
- backported by
-
JDK-8084412 SecureRandom should be more frugal with file descriptors
-
- Resolved
-
- duplicates
-
JDK-8012042 NativePRNG is opening same file multiple times
-
- Closed
-
- relates to
-
JDK-8060435 Provide the capability to obtain a system seed to seed PRNGs
-
- Open
-