test/java/rmi/transport/checkLeaseInfoLeak/CheckLeaseLeak.java

Print this page


   1 /*
   2  * Copyright (c) 1998, 2008, 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 CheckLeaseLeak 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 
  61     public CheckLeaseLeak() throws RemoteException { }
  62     public void ping () throws RemoteException { }
  63 
  64     /**
  65      * Id to fake the DGC_ID, so we can later get a reference to the
  66      * DGCImpl in the object table.
  67      */
  68     private final static int DGC_ID = 2;
  69 
  70     private final static int ITERATIONS = 10;
  71     private final static int numberPingCalls = 0;
  72     private final static int CHECK_INTERVAL = 400;
  73     private final static int LEASE_VALUE = 20;
  74 
  75     public static void main (String[] args) {
  76         CheckLeaseLeak leakServer = null;
  77         int numLeft =0;
  78 
  79         /*
  80          * we want DGC to collect leases *quickly*
  81          * decrease the lease check interval
  82          */
  83         TestLibrary.setInteger("sun.rmi.dgc.checkInterval",
  84                                CHECK_INTERVAL);
  85         TestLibrary.setInteger("java.rmi.dgc.leaseValue",
  86                                LEASE_VALUE);
  87 
  88         try {
  89             Registry registry =
  90                 java.rmi.registry.LocateRegistry.
  91                     createRegistry(TestLibrary.REGISTRY_PORT);
  92 
  93             leakServer = new CheckLeaseLeak();
  94             registry.rebind("/LeaseLeak", leakServer);
  95 
  96             /* create a bunch of clients in a *different* vm */
  97             for (int i = 0 ; i < ITERATIONS ; i ++ ) {
  98                 System.err.println("Created client: " + i);
  99 
 100                 JavaVM jvm = new JavaVM("LeaseLeakClient",
 101                                         " -Djava.security.policy=" +
 102                                         TestParams.defaultPolicy, "");



 103                 jvm.start();
 104 
 105                 if (jvm.getVM().waitFor() == 1 ) {
 106                     TestLibrary.bomb("Client process failed");
 107                 }
 108             }
 109             numLeft = getDGCLeaseTableSize();
 110             Thread.sleep(3000);
 111 
 112         } catch(Exception e) {
 113             TestLibrary.bomb("CheckLeaseLeak Error: ", e);
 114         } finally {
 115             if (leakServer != null) {
 116                 TestLibrary.unexport(leakServer);
 117                 leakServer = null;
 118             }
 119         }
 120 
 121         /* numLeft should be 2 - if 11 there is a problem. */
 122         if (numLeft > 2) {


   1 /*
   2  * Copyright (c) 1998, 2012, 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 CheckLeaseLeak CheckLeaseLeak_Stub LeaseLeakClient LeaseLeak
  32  * @build TestLibrary
  33  * @run main/othervm/timeout=240 CheckLeaseLeak
  34  *
  35  */
  36 
  37 /**
  38  * A bug in sun.rmi.transport.DGCImp.checkLeases() results in memory
  39  * leak of LeaseInfo objects.
  40  *
  41  * In order to verify that this problem no longer exists, we create a
  42  * remote object and a serveral clients in different VMs. The clients
  43  * call a remote method on an exported object. This will cause the rmi
  44  * runtime to create several references (all with different vmids) to
  45  * the remote object.  Each vmid needs a seperate LeaseInfo object in
  46  * the object table target DGCImpl.leaseTable.  If the leak is fixed,
  47  * the leaseTable field will contain no objects.  We use reflection to
  48  * find the number of objects contained in this table.
  49  */
  50 
  51 import java.rmi.*;
  52 import java.rmi.server.*;
  53 import sun.rmi.transport.*;
  54 import sun.rmi.*;
  55 import java.util.Map;
  56 import java.io.*;
  57 import java.lang.reflect.*;
  58 import java.rmi.registry.*;
  59 
  60 public class CheckLeaseLeak extends UnicastRemoteObject implements LeaseLeak {

  61     public CheckLeaseLeak() throws RemoteException { }
  62     public void ping () throws RemoteException { }
  63 
  64     /**
  65      * Id to fake the DGC_ID, so we can later get a reference to the
  66      * DGCImpl in the object table.
  67      */
  68     private final static int DGC_ID = 2;
  69 
  70     private final static int ITERATIONS = 10;
  71     private final static int numberPingCalls = 0;
  72     private final static int CHECK_INTERVAL = 400;
  73     private final static int LEASE_VALUE = 20;
  74 
  75     public static void main (String[] args) {
  76         CheckLeaseLeak leakServer = null;
  77         int numLeft =0;
  78 
  79         /*
  80          * we want DGC to collect leases *quickly*
  81          * decrease the lease check interval
  82          */
  83         TestLibrary.setInteger("sun.rmi.dgc.checkInterval",
  84                                CHECK_INTERVAL);
  85         TestLibrary.setInteger("java.rmi.dgc.leaseValue",
  86                                LEASE_VALUE);
  87 
  88         try {
  89             Registry registry =
  90                 TestLibrary.createRegistryOnUnusedPort();
  91             int registryPort = TestLibrary.getRegistryPort(registry);
  92 
  93             leakServer = new CheckLeaseLeak();
  94             registry.rebind("/LeaseLeak", leakServer);
  95 
  96             /* create a bunch of clients in a *different* vm */
  97             for (int i = 0 ; i < ITERATIONS ; i ++ ) {
  98                 System.err.println("Created client: " + i);
  99 
 100                 JavaVM jvm = new JavaVM("LeaseLeakClient",
 101                                         " -Djava.security.policy=" +
 102                                         TestParams.defaultPolicy +
 103                                         " -Drmi.registry.port=" +
 104                                         registryPort,
 105                                         "");
 106                 jvm.start();
 107 
 108                 if (jvm.getVM().waitFor() == 1 ) {
 109                     TestLibrary.bomb("Client process failed");
 110                 }
 111             }
 112             numLeft = getDGCLeaseTableSize();
 113             Thread.sleep(3000);
 114 
 115         } catch(Exception e) {
 116             TestLibrary.bomb("CheckLeaseLeak Error: ", e);
 117         } finally {
 118             if (leakServer != null) {
 119                 TestLibrary.unexport(leakServer);
 120                 leakServer = null;
 121             }
 122         }
 123 
 124         /* numLeft should be 2 - if 11 there is a problem. */
 125         if (numLeft > 2) {