1 /*
2 * Copyright (c) 2000, 2016, 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 */
57 LocateRegistry.getRegistry(registryPort).rebind("UnexportLeak", obj);
58 UnicastRemoteObject.unexportObject(obj, true);
59 obj = null;
60 flushRefs();
61 if (wr.get() != null) {
62 System.err.println("FAILED: unexported object not collected");
63 throw new RuntimeException(
64 "FAILED: unexported object not collected");
65 } else {
66 System.err.println("PASSED: unexported object collected");
67 }
68 } catch (RemoteException e) {
69 System.err.println(
70 "FAILED: RemoteException encountered: " + e.getMessage());
71 e.printStackTrace();
72 throw new RuntimeException("FAILED: RemoteException encountered");
73 }
74 }
75
76 /**
77 * Force desparate garbage collection so that all WeakReference instances
78 * will be cleared.
79 */
80 private static void flushRefs() {
81 java.util.Vector chain = new java.util.Vector();
82 try {
83 while (true) {
84 int[] hungry = new int[65536];
85 chain.addElement(hungry);
86 }
87 } catch (OutOfMemoryError e) {
88 }
89 }
90 }
|
1 /*
2 * Copyright (c) 2000, 2019, 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 */
57 LocateRegistry.getRegistry(registryPort).rebind("UnexportLeak", obj);
58 UnicastRemoteObject.unexportObject(obj, true);
59 obj = null;
60 flushRefs();
61 if (wr.get() != null) {
62 System.err.println("FAILED: unexported object not collected");
63 throw new RuntimeException(
64 "FAILED: unexported object not collected");
65 } else {
66 System.err.println("PASSED: unexported object collected");
67 }
68 } catch (RemoteException e) {
69 System.err.println(
70 "FAILED: RemoteException encountered: " + e.getMessage());
71 e.printStackTrace();
72 throw new RuntimeException("FAILED: RemoteException encountered");
73 }
74 }
75
76 /**
77 * Force desperate garbage collection so that all WeakReference instances
78 * will be cleared.
79 */
80 private static void flushRefs() {
81 java.util.Vector chain = new java.util.Vector();
82 try {
83 while (true) {
84 int[] hungry = new int[65536];
85 chain.addElement(hungry);
86 }
87 } catch (OutOfMemoryError e) {
88 // An inflated Java monitor can keep 'obj' alive so request
89 // an explicit GC to make sure things are cleaned up.
90 System.gc();
91 }
92 }
93 }
|