Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/security/ssl/SSLSocketImpl/SSLSocketLeak.java
41152 views
1
/*
2
* Copyright (c) 2020 SAP SE. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
import java.io.IOException;
25
26
import javax.net.SocketFactory;
27
import javax.net.ssl.SSLSocketFactory;
28
29
import jdk.test.lib.Platform;
30
import jdk.test.lib.util.FileUtils;
31
32
/*
33
* @test
34
* @bug 8256818 8257670 8257884 8257997
35
* @summary Test that creating and closing SSL Sockets without bind/connect
36
* will not leave leaking socket file descriptors
37
* @library /test/lib
38
* @run main/othervm SSLSocketLeak
39
*/
40
public class SSLSocketLeak {
41
42
// number of sockets to open/close
43
private static final int NUM_TEST_SOCK = 500;
44
45
// percentage of accepted growth of open handles
46
private static final int OPEN_HANDLE_GROWTH_THRESHOLD_PERCENTAGE = Platform.isWindows() ? 25 : 10;
47
48
public static void main(String[] args) throws IOException {
49
long fds_start = FileUtils.getProcessHandleCount();
50
System.out.println("FDs at the beginning: " + fds_start);
51
52
SocketFactory f = SSLSocketFactory.getDefault();
53
for (int i = 0; i < NUM_TEST_SOCK; i++) {
54
f.createSocket().close();
55
}
56
57
long fds_end = FileUtils.getProcessHandleCount();
58
System.out.println("FDs in the end: " + fds_end);
59
60
if ((fds_end - fds_start) > ((NUM_TEST_SOCK * OPEN_HANDLE_GROWTH_THRESHOLD_PERCENTAGE)) / 100) {
61
throw new RuntimeException("Too many open file descriptors. Looks leaky.");
62
}
63
}
64
}
65
66