Path: blob/master/test/jdk/java/rmi/transport/pinLastArguments/PinLastArguments.java
41153 views
/*1* Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/* @test24* @bug 633234925* @summary Passing live remote references as part of the arguments of26* a remote invocation should not cause an AssertionError (on the27* second and subsequent attempts) when system assertions are enabled,28* nor should it cause the references to be pinned until a subsequent29* such remote invocation occurs (if the argument stream was not30* released cleanly because of a marshalling failure).31* @author Peter Jones32*33* @run main/othervm -esa PinLastArguments34*/3536import java.io.NotSerializableException;37import java.lang.ref.Reference;38import java.lang.ref.WeakReference;39import java.rmi.MarshalException;40import java.rmi.Remote;41import java.rmi.RemoteException;42import java.rmi.server.UnicastRemoteObject;4344public class PinLastArguments {4546public interface Ping extends Remote {47void ping(Object first, Object second) throws RemoteException;48}4950private static class PingImpl implements Ping {51PingImpl() { }52public void ping(Object first, Object second) {53System.err.println("ping invoked: " + first + ", " + second);54}55}5657public static void main(String[] args) throws Exception {58System.err.println("\nRegression test for bug 6332349\n");5960Ping impl = new PingImpl();61Reference<?> ref = new WeakReference<Ping>(impl);62try {63Ping stub = (Ping) UnicastRemoteObject.exportObject(impl, 0);64Object notSerializable = new Object();65stub.ping(impl, null);66try {67stub.ping(impl, notSerializable);68} catch (MarshalException e) {69if (e.getCause() instanceof NotSerializableException) {70System.err.println("ping invocation failed as expected");71} else {72throw e;73}74}75} finally {76UnicastRemoteObject.unexportObject(impl, true);77}78impl = null;7980// Might require multiple calls to System.gc() for weak-references81// processing to be complete. If the weak-reference is not cleared as82// expected we will hang here until timed out by the test harness.83while (true) {84System.gc();85Thread.sleep(20);86if (ref.get() == null) {87break;88}89}9091System.err.println("TEST PASSED");92}93}949596