Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/rmi/activation/Activatable/nestedActivate/NestedActivate.java
38829 views
/*1* Copyright (c) 1998, 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 413805625* @summary synopsis: Activating objects from an Activatable constructor causes deadlock26* @author Ann Wollrath27*28* @library ../../../testlibrary29* @build TestLibrary RMID ActivationLibrary ActivateMe NestedActivate_Stub30* @run main/othervm/policy=security.policy/timeout=240 NestedActivate31*/3233import java.io.*;34import java.rmi.*;35import java.rmi.activation.*;36import java.rmi.server.*;37import java.rmi.registry.*;38import java.util.Properties;3940public class NestedActivate41extends Activatable42implements ActivateMe, Runnable43{4445private static Exception exception = null;46private static boolean done = false;47private ActivateMe obj = null;4849public NestedActivate(ActivationID id, MarshalledObject mobj)50throws Exception51{52super(id, 0);53System.err.println("NestedActivate<>: activating object");54if (mobj != null) {55System.err.println("NestedActivate<>: ping obj to activate");56obj = (ActivateMe) mobj.get();57obj.ping();58System.err.println("NestedActivate<>: ping completed");59}60}6162public void ping()63{}6465public void unregister() throws Exception {66super.unregister(super.getID());67}6869/**70* Spawns a thread to deactivate the object.71*/72public void shutdown() throws Exception73{74(new Thread(this,"NestedActivate")).start();75if (obj != null)76obj.shutdown();77}7879/**80* Thread to deactivate object. First attempts to make object81* inactive (via the inactive method). If that fails (the82* object may still have pending/executing calls), then83* unexport the object forcibly.84*/85public void run() {86ActivationLibrary.deactivate(this, getID());87}8889public static void main(String[] args) {9091System.err.println("\nRegression test for bug 4138056\n");9293TestLibrary.suggestSecurityManager("java.rmi.RMISecurityManager");9495RMID rmid = null;9697try {98RMID.removeLog();99rmid = RMID.createRMID();100rmid.start();101102/* Cause activation groups to have a security policy that will103* allow security managers to be downloaded and installed104*/105final Properties p = new Properties();106// this test must always set policies/managers in its107// activation groups108p.put("java.security.policy",109TestParams.defaultGroupPolicy);110p.put("java.security.manager",111TestParams.defaultSecurityManager);112113Thread t = new Thread() {114public void run () {115try {116System.err.println("Creating group descriptor");117ActivationGroupDesc groupDesc =118new ActivationGroupDesc(p, null);119ActivationGroupID groupID =120ActivationGroup.getSystem().121registerGroup(groupDesc);122123System.err.println("Creating descriptor: object 1");124ActivationDesc desc1 =125new ActivationDesc(groupID, "NestedActivate",126null, null);127128System.err.println("Registering descriptor: object 1");129ActivateMe obj1 =130(ActivateMe) Activatable.register(desc1);131132System.err.println("Creating descriptor: object 2");133ActivationDesc desc2 =134new ActivationDesc(groupID, "NestedActivate", null,135new MarshalledObject(obj1));136137System.err.println("Registering descriptor: object 2");138ActivateMe obj2 =139(ActivateMe) Activatable.register(desc2);140141System.err.println("Activating object 2");142obj2.ping();143144System.err.println("Deactivating objects");145obj2.shutdown();146} catch (Exception e) {147exception = e;148}149done = true;150}151};152153t.start();154t.join(35000);155156if (exception != null) {157TestLibrary.bomb("test failed", exception);158} else if (!done) {159TestLibrary.bomb("test failed: not completed before timeout", null);160} else {161System.err.println("Test passed");162}163164} catch (Exception e) {165TestLibrary.bomb("test failed", e);166} finally {167ActivationLibrary.rmidCleanup(rmid);168}169}170}171172173