/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/* @test
* @bug 4116437
* @summary Distributed Garbage Collector Memory Leak
*
* @author Laird Dornin
*
* @library ../../testlibrary
* @build TestLibrary CheckLeaseLeak_Stub LeaseLeakClient LeaseLeak
*
*/
/**
* A bug in sun.rmi.transport.DGCImp.checkLeases() results in memory
* leak of LeaseInfo objects.
*
* In order to verify that this problem no longer exists, we create a
* remote object and a serveral clients in different VMs. The clients
* call a remote method on an exported object. This will cause the rmi
* runtime to create several references (all with different vmids) to
* the remote object. Each vmid needs a seperate LeaseInfo object in
* the object table target DGCImpl.leaseTable. If the leak is fixed,
* the leaseTable field will contain no objects. We use reflection to
* find the number of objects contained in this table.
*/
/**
* Id to fake the DGC_ID, so we can later get a reference to the
* DGCImpl in the object table.
*/
int numLeft =0;
/*
* we want DGC to collect leases *quickly*
* decrease the lease check interval
*/
try {
leakServer = new CheckLeaseLeak();
/* create a bunch of clients in a *different* vm */
for (int i = 0 ; i < ITERATIONS ; i ++ ) {
" -Djava.security.policy=" +
" -Drmi.registry.port=" +
"");
}
}
} catch(Exception e) {
} finally {
if (leakServer != null) {
leakServer = null;
}
}
/* numLeft should be 2 - if 11 there is a problem. */
if (numLeft > 2) {
numLeft);
} else {
+ " object(s) in the leaseTable");
}
}
/**
* Obtain a reference to the main DGCImpl via reflection. Extract
* the DGCImpl using the ObjectTable and the well known ID of the
* DGCImpl.
*/
private static int getDGCLeaseTableSize () {
int numLeaseInfosLeft = 0;
/**
* Will eventually be set to point at the leaseTable inside
* DGCImpl.
*/
Field f;
try {
/*
* Construct an ObjectEndpoint containing DGC's
* ObjID.
*/
Class[] constrParams =
oeConstructor.setAccessible(true);
/*
* Get Target that contains DGCImpl in ObjectTable
*/
objTableGetTarget.setAccessible(true);
/* get the DGCImpl from its Target */
("getImpl", null);
targetGetImpl.setAccessible(true);
dgcImpl[0] =
/* Get the lease table from the DGCImpl. */
("leaseTable");
reflectedLeaseTable.setAccessible(true);
return reflectedLeaseTable;
}
});
/**
* This is the leaseTable that will fill up with LeaseInfo
* objects if the LeaseInfo memory leak is not fixed.
*/
} catch(Exception e) {
getException();
TestLibrary.bomb(e);
}
return numLeaseInfosLeft;
}
}