4005N/A/*
4248N/A * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
4005N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4005N/A *
4005N/A * This code is free software; you can redistribute it and/or modify it
4005N/A * under the terms of the GNU General Public License version 2 only, as
4005N/A * published by the Free Software Foundation.
4005N/A *
4005N/A * This code is distributed in the hope that it will be useful, but WITHOUT
4005N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4005N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
4005N/A * version 2 for more details (a copy is included in the LICENSE file that
4005N/A * accompanied this code).
4005N/A *
4005N/A * You should have received a copy of the GNU General Public License version
4005N/A * 2 along with this work; if not, write to the Free Software Foundation,
4005N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4005N/A *
4005N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4005N/A * or visit www.oracle.com if you need additional information or have any
4005N/A * questions.
4005N/A */
4005N/A
4005N/A/*
4005N/A * Portions Copyright (c) 2011 IBM Corporation
4005N/A */
4005N/A
4005N/A/*
4005N/A * @test
4005N/A * @bug 6597112
4005N/A * @summary GC'ing objects whilst being exported to RMI should not cause exceptions
4005N/A * @author Neil Richards <neil.richards@ngmr.net>, <neil_richards@uk.ibm.com>
5551N/A * @run main GcDuringExport
4005N/A */
4005N/A
4005N/Aimport java.rmi.Remote;
4005N/Aimport java.rmi.server.UnicastRemoteObject;
4005N/A
4005N/Apublic class GcDuringExport {
4005N/A private static final long MAX_EXPORT_ITERATIONS = 50000;
4005N/A
4005N/A public static void main(String[] args) throws Exception {
4005N/A Thread gcInducingThread = new Thread() {
4005N/A public void run() {
4005N/A while (true) {
4005N/A System.gc();
4005N/A try { Thread.sleep(1); } catch (InterruptedException e) { }
4005N/A }
4005N/A }
4005N/A };
4005N/A gcInducingThread.setDaemon(true);
4005N/A gcInducingThread.start();
4005N/A
4005N/A long i = 0;
4005N/A try {
4005N/A while (i < MAX_EXPORT_ITERATIONS) {
4005N/A i++;
4005N/A UnicastRemoteObject.exportObject(new Remote() { }, 0);
4005N/A }
4005N/A } catch (Throwable e) {
4005N/A throw new RuntimeException("Test FAILED on iteration " + i + ".", e);
4005N/A }
4005N/A
4005N/A System.out.println("Test successfully exported " + i + " objects.");
4005N/A }
4005N/A}