Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/rmi/transport/checkLeaseInfoLeak/CheckLeaseLeak.java
38828 views
1
/*
2
* Copyright (c) 1998, 2013, Oracle and/or its affiliates. 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
/* @test
25
* @bug 4116437
26
* @summary Distributed Garbage Collector Memory Leak
27
*
28
* @author Laird Dornin
29
*
30
* @library ../../testlibrary
31
* @build TestLibrary CheckLeaseLeak_Stub LeaseLeakClient LeaseLeak
32
* @run main/othervm/timeout=240 CheckLeaseLeak
33
*
34
*/
35
36
/**
37
* A bug in sun.rmi.transport.DGCImp.checkLeases() results in memory
38
* leak of LeaseInfo objects.
39
*
40
* In order to verify that this problem no longer exists, we create a
41
* remote object and a serveral clients in different VMs. The clients
42
* call a remote method on an exported object. This will cause the rmi
43
* runtime to create several references (all with different vmids) to
44
* the remote object. Each vmid needs a seperate LeaseInfo object in
45
* the object table target DGCImpl.leaseTable. If the leak is fixed,
46
* the leaseTable field will contain no objects. We use reflection to
47
* find the number of objects contained in this table.
48
*/
49
50
import java.rmi.*;
51
import java.rmi.server.*;
52
import sun.rmi.transport.*;
53
import sun.rmi.*;
54
import java.util.Map;
55
import java.io.*;
56
import java.lang.reflect.*;
57
import java.rmi.registry.*;
58
59
public class CheckLeaseLeak extends UnicastRemoteObject implements LeaseLeak {
60
public CheckLeaseLeak() throws RemoteException { }
61
public void ping () throws RemoteException { }
62
63
/**
64
* Id to fake the DGC_ID, so we can later get a reference to the
65
* DGCImpl in the object table.
66
*/
67
private final static int DGC_ID = 2;
68
69
private final static int ITERATIONS = 10;
70
private final static int numberPingCalls = 0;
71
private final static int CHECK_INTERVAL = 400;
72
private final static int LEASE_VALUE = 20;
73
74
public static void main (String[] args) {
75
CheckLeaseLeak leakServer = null;
76
int numLeft =0;
77
78
/*
79
* we want DGC to collect leases *quickly*
80
* decrease the lease check interval
81
*/
82
TestLibrary.setInteger("sun.rmi.dgc.checkInterval",
83
CHECK_INTERVAL);
84
TestLibrary.setInteger("java.rmi.dgc.leaseValue",
85
LEASE_VALUE);
86
87
try {
88
Registry registry =
89
TestLibrary.createRegistryOnUnusedPort();
90
int registryPort = TestLibrary.getRegistryPort(registry);
91
92
leakServer = new CheckLeaseLeak();
93
registry.rebind("/LeaseLeak", leakServer);
94
95
/* create a bunch of clients in a *different* vm */
96
for (int i = 0 ; i < ITERATIONS ; i ++ ) {
97
System.err.println("Created client: " + i);
98
99
JavaVM jvm = new JavaVM("LeaseLeakClient",
100
" -Djava.security.policy=" +
101
TestParams.defaultPolicy +
102
" -Drmi.registry.port=" +
103
registryPort,
104
"");
105
106
if (jvm.execute() != 0) {
107
TestLibrary.bomb("Client process failed");
108
}
109
}
110
numLeft = getDGCLeaseTableSize();
111
Thread.sleep(3000);
112
113
} catch(Exception e) {
114
TestLibrary.bomb("CheckLeaseLeak Error: ", e);
115
} finally {
116
if (leakServer != null) {
117
TestLibrary.unexport(leakServer);
118
leakServer = null;
119
}
120
}
121
122
/* numLeft should be 2 - if 11 there is a problem. */
123
if (numLeft > 2) {
124
TestLibrary.bomb("Too many objects in DGCImpl.leaseTable: "+
125
numLeft);
126
} else {
127
System.err.println("Check leaseInfo leak passed with " +
128
numLeft
129
+ " object(s) in the leaseTable");
130
}
131
}
132
133
/**
134
* Obtain a reference to the main DGCImpl via reflection. Extract
135
* the DGCImpl using the ObjectTable and the well known ID of the
136
* DGCImpl.
137
*/
138
private static int getDGCLeaseTableSize () {
139
int numLeaseInfosLeft = 0;
140
141
/**
142
* Will eventually be set to point at the leaseTable inside
143
* DGCImpl.
144
*/
145
Map leaseTable = null;
146
final Remote[] dgcImpl = new Remote[1];
147
Field f;
148
149
try {
150
f = (Field) java.security.AccessController.doPrivileged
151
(new java.security.PrivilegedExceptionAction() {
152
public Object run() throws Exception {
153
154
ObjID dgcID = new ObjID(DGC_ID);
155
156
/*
157
* Construct an ObjectEndpoint containing DGC's
158
* ObjID.
159
*/
160
Class oeClass =
161
Class.forName("sun.rmi.transport.ObjectEndpoint");
162
Class[] constrParams =
163
new Class[]{ ObjID.class, Transport.class };
164
Constructor oeConstructor =
165
oeClass.getDeclaredConstructor(constrParams);
166
oeConstructor.setAccessible(true);
167
Object oe =
168
oeConstructor.newInstance(
169
new Object[]{ dgcID, null });
170
171
/*
172
* Get Target that contains DGCImpl in ObjectTable
173
*/
174
Class objTableClass =
175
Class.forName("sun.rmi.transport.ObjectTable");
176
Class getTargetParams[] = new Class[] { oeClass };
177
Method objTableGetTarget =
178
objTableClass.getDeclaredMethod("getTarget",
179
getTargetParams);
180
objTableGetTarget.setAccessible(true);
181
Target dgcTarget = (Target)
182
objTableGetTarget.invoke(null, new Object[]{ oe });
183
184
/* get the DGCImpl from its Target */
185
Method targetGetImpl =
186
dgcTarget.getClass().getDeclaredMethod
187
("getImpl", null);
188
targetGetImpl.setAccessible(true);
189
dgcImpl[0] =
190
(Remote) targetGetImpl.invoke(dgcTarget, null);
191
192
/* Get the lease table from the DGCImpl. */
193
Field reflectedLeaseTable =
194
dgcImpl[0].getClass().getDeclaredField
195
("leaseTable");
196
reflectedLeaseTable.setAccessible(true);
197
198
return reflectedLeaseTable;
199
}
200
});
201
202
/**
203
* This is the leaseTable that will fill up with LeaseInfo
204
* objects if the LeaseInfo memory leak is not fixed.
205
*/
206
leaseTable = (Map) f.get(dgcImpl[0]);
207
208
numLeaseInfosLeft = leaseTable.size();
209
210
} catch(Exception e) {
211
if (e instanceof java.security.PrivilegedActionException)
212
e = ((java.security.PrivilegedActionException) e).
213
getException();
214
TestLibrary.bomb(e);
215
}
216
217
return numLeaseInfosLeft;
218
}
219
}
220
221