1 /* 2 * Copyright (c) 2005, 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 4486732 26 * @summary When a remote stub contains a client socket factory and a 27 * remote invocation is made using that stub, the factory should not 28 * be held strongly reachable by the RMI implementation forever; in 29 * particular, after the stub has become unreachable and all 30 * connections to its endpoint have been closed, then the factory 31 * should become unreachable too (through the RMI implementation). 32 * @author Peter Jones 33 * 34 * @run main/othervm -Dsun.rmi.transport.connectionTimeout=2000 35 * PinClientSocketFactory 36 */ 37 38 import java.io.IOException; 39 import java.io.ObjectInputStream; 40 import java.io.Serializable; 41 import java.lang.ref.Reference; 42 import java.lang.ref.WeakReference; 43 import java.net.ServerSocket; 44 import java.net.Socket; 45 import java.rmi.Remote; 46 import java.rmi.RemoteException; 47 import java.rmi.registry.LocateRegistry; 48 import java.rmi.registry.Registry; 49 import java.rmi.server.RMIClientSocketFactory; 50 import java.rmi.server.RMIServerSocketFactory; 51 import java.rmi.server.UnicastRemoteObject; 52 import java.util.ArrayList; 53 import java.util.Collections; 54 import java.util.List; 55 import java.util.concurrent.atomic.AtomicInteger; 56 57 public class PinClientSocketFactory { 58 59 private static final int PORT = 2345; 60 private static final int SESSIONS = 50; 61 62 public interface Factory extends Remote { 63 Session getSession() throws RemoteException; 64 } 65 66 public interface Session extends Remote { 67 void ping() throws RemoteException; 68 } 69 70 private static class FactoryImpl implements Factory { 71 FactoryImpl() { } 72 public Session getSession() throws RemoteException { 73 Session impl = new SessionImpl(); 74 UnicastRemoteObject.exportObject(impl, 0, new CSF(), new SSF()); 75 // return impl instead of stub to work around 4114579 76 return impl; 77 } 78 } 79 | 1 /* 2 * Copyright (c) 2005, 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 4486732 26 * @summary When a remote stub contains a client socket factory and a 27 * remote invocation is made using that stub, the factory should not 28 * be held strongly reachable by the RMI implementation forever; in 29 * particular, after the stub has become unreachable and all 30 * connections to its endpoint have been closed, then the factory 31 * should become unreachable too (through the RMI implementation). 32 * @author Peter Jones 33 * 34 * @library ../../testlibrary 35 * @build TestLibrary 36 * @run main/othervm -Dsun.rmi.transport.connectionTimeout=2000 37 * PinClientSocketFactory 38 */ 39 40 import java.io.IOException; 41 import java.io.ObjectInputStream; 42 import java.io.Serializable; 43 import java.lang.ref.Reference; 44 import java.lang.ref.WeakReference; 45 import java.net.ServerSocket; 46 import java.net.Socket; 47 import java.rmi.Remote; 48 import java.rmi.RemoteException; 49 import java.rmi.registry.LocateRegistry; 50 import java.rmi.registry.Registry; 51 import java.rmi.server.RMIClientSocketFactory; 52 import java.rmi.server.RMIServerSocketFactory; 53 import java.rmi.server.UnicastRemoteObject; 54 import java.util.ArrayList; 55 import java.util.Collections; 56 import java.util.List; 57 import java.util.concurrent.atomic.AtomicInteger; 58 59 public class PinClientSocketFactory { 60 61 private static final int PORT = TestLibrary.getUnusedRandomPort(); 62 private static final int SESSIONS = 50; 63 64 public interface Factory extends Remote { 65 Session getSession() throws RemoteException; 66 } 67 68 public interface Session extends Remote { 69 void ping() throws RemoteException; 70 } 71 72 private static class FactoryImpl implements Factory { 73 FactoryImpl() { } 74 public Session getSession() throws RemoteException { 75 Session impl = new SessionImpl(); 76 UnicastRemoteObject.exportObject(impl, 0, new CSF(), new SSF()); 77 // return impl instead of stub to work around 4114579 78 return impl; 79 } 80 } 81 |