author | dbuck |
Tue, 18 Aug 2015 04:29:28 -0700 | |
changeset 32417 | 6859107fc6c3 |
parent 30376 | 2ccf2cf7ea48 |
child 42338 | a60f280f803c |
permissions | -rw-r--r-- |
19791
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
1 |
/* |
30376
2ccf2cf7ea48
8078896: Add @modules as needed to the jdk_svc tests
ykantser
parents:
19791
diff
changeset
|
2 |
* Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved. |
19791
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
4 |
* |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
8 |
* |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
13 |
* accompanied this code). |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
14 |
* |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
18 |
* |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
21 |
* questions. |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
22 |
*/ |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
23 |
|
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
24 |
import java.lang.management.ManagementFactory; |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
25 |
import java.lang.ref.WeakReference; |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
26 |
import java.lang.reflect.Field; |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
27 |
import javax.management.MBeanServer; |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
28 |
import javax.management.MBeanServerConnection; |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
29 |
import javax.management.remote.JMXConnector; |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
30 |
import javax.management.remote.JMXConnectorFactory; |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
31 |
import javax.management.remote.JMXConnectorServer; |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
32 |
import javax.management.remote.JMXConnectorServerFactory; |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
33 |
import javax.management.remote.JMXServiceURL; |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
34 |
import javax.management.remote.rmi.RMIConnector; |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
35 |
|
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
36 |
/* |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
37 |
* @test |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
38 |
* @bug 6566891 |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
39 |
* @summary Check no memory leak on RMIConnector's nullSubjectConn |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
40 |
* @author Shanliang JIANG |
30376
2ccf2cf7ea48
8078896: Add @modules as needed to the jdk_svc tests
ykantser
parents:
19791
diff
changeset
|
41 |
* @modules java.management |
19791
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
42 |
* @run clean RMIConnectorNullSubjectConnTest |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
43 |
* @run build RMIConnectorNullSubjectConnTest |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
44 |
* @run main RMIConnectorNullSubjectConnTest |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
45 |
*/ |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
46 |
|
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
47 |
public class RMIConnectorNullSubjectConnTest { |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
48 |
public static void main(String[] args) throws Exception { |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
49 |
System.out.println("---RMIConnectorNullSubjectConnTest starting..."); |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
50 |
|
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
51 |
JMXConnectorServer connectorServer = null; |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
52 |
JMXConnector connectorClient = null; |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
53 |
|
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
54 |
try { |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
55 |
MBeanServer mserver = ManagementFactory.getPlatformMBeanServer(); |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
56 |
JMXServiceURL serverURL = new JMXServiceURL("rmi", "localhost", 0); |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
57 |
connectorServer = JMXConnectorServerFactory.newJMXConnectorServer(serverURL, null, mserver); |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
58 |
connectorServer.start(); |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
59 |
|
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
60 |
JMXServiceURL serverAddr = connectorServer.getAddress(); |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
61 |
connectorClient = JMXConnectorFactory.connect(serverAddr, null); |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
62 |
connectorClient.connect(); |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
63 |
|
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
64 |
Field nullSubjectConnField = RMIConnector.class.getDeclaredField("nullSubjectConnRef"); |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
65 |
nullSubjectConnField.setAccessible(true); |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
66 |
|
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
67 |
WeakReference<MBeanServerConnection> weak = |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
68 |
(WeakReference<MBeanServerConnection>)nullSubjectConnField.get(connectorClient); |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
69 |
|
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
70 |
if (weak != null && weak.get() != null) { |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
71 |
throw new RuntimeException("nullSubjectConnRef must be null at initial time."); |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
72 |
} |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
73 |
|
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
74 |
MBeanServerConnection conn1 = connectorClient.getMBeanServerConnection(null); |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
75 |
MBeanServerConnection conn2 = connectorClient.getMBeanServerConnection(null); |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
76 |
if (conn1 == null) { |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
77 |
throw new RuntimeException("A connection with null subject should not be null."); |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
78 |
} else if (conn1 != conn2) { |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
79 |
throw new RuntimeException("The 2 connections with null subject are not equal."); |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
80 |
} |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
81 |
|
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
82 |
conn1 = null; |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
83 |
conn2 = null; |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
84 |
int i = 1; |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
85 |
do { |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
86 |
System.gc(); |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
87 |
Thread.sleep(100); |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
88 |
weak = (WeakReference<MBeanServerConnection>)nullSubjectConnField.get(connectorClient); |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
89 |
} while ((weak != null && weak.get() != null) && i++ < 60); |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
90 |
|
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
91 |
System.out.println("---GC times: " + i); |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
92 |
|
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
93 |
if (weak != null && weak.get() != null) { |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
94 |
throw new RuntimeException("Failed to clean RMIConnector's nullSubjectConn"); |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
95 |
} else { |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
96 |
System.out.println("---RMIConnectorNullSubjectConnTest: PASSED!"); |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
97 |
} |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
98 |
} finally { |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
99 |
try { |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
100 |
connectorClient.close(); |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
101 |
connectorServer.stop(); |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
102 |
} catch (Exception e) { |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
103 |
} |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
104 |
} |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
105 |
} |
d0bcc2086175
6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents:
diff
changeset
|
106 |
} |