author | phedlin |
Fri, 15 Nov 2019 16:39:08 +0100 | |
changeset 59291 | 54cf02d52c1b |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
23043
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
1 |
/* |
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
2 |
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
4 |
* |
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
8 |
* |
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
13 |
* accompanied this code). |
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
14 |
* |
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
18 |
* |
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
21 |
* questions. |
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
22 |
*/ |
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
23 |
|
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
24 |
/* |
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
25 |
* @test |
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
26 |
* @bug 8035897 |
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
27 |
* @summary FD_SETSIZE should be set on macosx |
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
28 |
* @run main/othervm AnotherSelectFdsLimit 1023 |
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
29 |
* @run main/othervm AnotherSelectFdsLimit 1024 |
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
30 |
* @run main/othervm AnotherSelectFdsLimit 1025 |
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
31 |
* @run main/othervm AnotherSelectFdsLimit 1600 |
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
32 |
*/ |
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
33 |
|
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
34 |
import java.io.IOException; |
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
35 |
import java.net.ServerSocket; |
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
36 |
import java.net.SocketTimeoutException; |
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
37 |
import java.util.ArrayList; |
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
38 |
import java.util.List; |
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
39 |
|
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
40 |
public class AnotherSelectFdsLimit { |
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
41 |
static final int DEFAULT_FDS_TO_USE = 1600; |
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
42 |
|
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
43 |
public static void main(String [] args) throws Exception { |
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
44 |
if (!System.getProperty("os.name").contains("OS X")) { |
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
45 |
System.out.println("Test only run on MAC. Exiting."); |
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
46 |
return; |
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
47 |
} |
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
48 |
|
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
49 |
int fdsToUse = DEFAULT_FDS_TO_USE; |
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
50 |
if (args.length == 1) |
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
51 |
fdsToUse = Integer.parseInt(args[0]); |
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
52 |
|
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
53 |
System.out.println("Using " + fdsToUse + " fds."); |
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
54 |
|
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
55 |
List<Thread> threads = new ArrayList<>(); |
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
56 |
for (int i=0; i<fdsToUse; i++) |
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
57 |
threads.add(new WorkerThread()); |
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
58 |
|
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
59 |
for (Thread t : threads) |
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
60 |
t.start(); |
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
61 |
|
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
62 |
for (Thread t : threads) |
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
63 |
t.join(); |
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
64 |
} |
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
65 |
|
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
66 |
static class WorkerThread extends Thread { |
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
67 |
public void run() { |
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
68 |
try (ServerSocket ss = new ServerSocket(0)) { |
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
69 |
ss.setSoTimeout(2000); |
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
70 |
ss.accept(); |
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
71 |
} catch (SocketTimeoutException x) { |
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
72 |
// expected |
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
73 |
} catch (IOException x) { |
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
74 |
throw new java.io.UncheckedIOException(x); |
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
75 |
} |
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
76 |
} |
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
77 |
} |
15face72cb3b
8035897: Better memory allocation for file descriptors greater than 1024 on macosx
chegar
parents:
diff
changeset
|
78 |
} |