23
23
24
24
package jdk .test .lib .util ;
25
25
26
- import jdk .test .lib .Platform ;
27
-
28
26
import java .io .BufferedReader ;
29
- import java .io .InputStreamReader ;
30
27
import java .io .IOException ;
28
+ import java .io .InputStreamReader ;
31
29
import java .io .PrintStream ;
32
30
import java .io .UncheckedIOException ;
33
31
import java .lang .ProcessBuilder .Redirect ;
32
+ import java .lang .management .ManagementFactory ;
34
33
import java .nio .file .DirectoryNotEmptyException ;
35
34
import java .nio .file .FileVisitResult ;
36
35
import java .nio .file .Files ;
37
36
import java .nio .file .NoSuchFileException ;
38
37
import java .nio .file .Path ;
39
- import java .nio .file .Paths ;
40
38
import java .nio .file .SimpleFileVisitor ;
41
39
import java .nio .file .attribute .BasicFileAttributes ;
42
40
import java .time .Instant ;
43
- import java .time .Duration ;
44
- import java .util .Arrays ;
45
41
import java .util .ArrayList ;
46
- import java .util .ArrayDeque ;
42
+ import java .util .Arrays ;
47
43
import java .util .HashSet ;
48
44
import java .util .List ;
49
45
import java .util .Optional ;
50
46
import java .util .Set ;
47
+ import java .util .concurrent .TimeUnit ;
51
48
import java .util .concurrent .atomic .AtomicBoolean ;
52
49
import java .util .concurrent .atomic .AtomicReference ;
53
- import java .util .concurrent .TimeUnit ;
50
+
51
+ import jdk .test .lib .Platform ;
52
+
53
+ import com .sun .management .UnixOperatingSystemMXBean ;
54
54
55
55
/**
56
56
* Common library for various test file utility functions.
@@ -59,6 +59,7 @@ public final class FileUtils {
59
59
private static final boolean IS_WINDOWS = Platform .isWindows ();
60
60
private static final int RETRY_DELETE_MILLIS = IS_WINDOWS ? 500 : 0 ;
61
61
private static final int MAX_RETRY_DELETE_TIMES = IS_WINDOWS ? 15 : 0 ;
62
+ private static volatile boolean nativeLibLoaded ;
62
63
63
64
/**
64
65
* Deletes a file, retrying if necessary.
@@ -363,6 +364,21 @@ public static void listFileDescriptors(PrintStream ps) {
363
364
});
364
365
}
365
366
367
+ // Return the current process handle count
368
+ public static long getProcessHandleCount () {
369
+ if (IS_WINDOWS ) {
370
+ if (!nativeLibLoaded ) {
371
+ System .loadLibrary ("FileUtils" );
372
+ nativeLibLoaded = true ;
373
+ }
374
+ return getWinProcessHandleCount ();
375
+ } else {
376
+ return ((UnixOperatingSystemMXBean )ManagementFactory .getOperatingSystemMXBean ()).getOpenFileDescriptorCount ();
377
+ }
378
+ }
379
+
380
+ private static native long getWinProcessHandleCount ();
381
+
366
382
// Possible command locations and arguments
367
383
static String [][] lsCommands = new String [][] {
368
384
{"/usr/bin/lsof" , "-p" },
0 commit comments