diff --git a/src/share/classes/com/sun/corba/se/impl/encoding/BufferManagerReadStream.java b/src/share/classes/com/sun/corba/se/impl/encoding/BufferManagerReadStream.java index 4925c735495e6a4194aa3435a808b80d1e348d6b..c57942f0da1eb75c4765b1c1889975bef698fce0 100644 --- a/src/share/classes/com/sun/corba/se/impl/encoding/BufferManagerReadStream.java +++ b/src/share/classes/com/sun/corba/se/impl/encoding/BufferManagerReadStream.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2000-2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -44,6 +44,7 @@ public class BufferManagerReadStream // We should convert endOfStream to a final static dummy end node private boolean endOfStream = true; private BufferQueue fragmentQueue = new BufferQueue(); + private long FRAGMENT_TIMEOUT = 60000; // REVISIT - This should go in BufferManagerRead. But, since // BufferManagerRead is an interface. BufferManagerRead @@ -111,9 +112,16 @@ public class BufferManagerReadStream throw wrapper.endOfStream() ; } + boolean interrupted = false; try { - fragmentQueue.wait(); - } catch (InterruptedException e) {} + fragmentQueue.wait(FRAGMENT_TIMEOUT); + } catch (InterruptedException e) { + interrupted = true; + } + + if (!interrupted && fragmentQueue.size() == 0) { + throw wrapper.bufferReadManagerTimeout(); + } if (receivedCancel) { throw new RequestCanceledException(cancelReqId); diff --git a/src/share/classes/com/sun/corba/se/impl/io/ObjectStreamClass.java b/src/share/classes/com/sun/corba/se/impl/io/ObjectStreamClass.java index c9b79dfe52679cb721d8676842b2979507f5942b..b23049c08bc45892a9e9abe56908b386f748f0c2 100644 --- a/src/share/classes/com/sun/corba/se/impl/io/ObjectStreamClass.java +++ b/src/share/classes/com/sun/corba/se/impl/io/ObjectStreamClass.java @@ -1,5 +1,5 @@ /* - * Copyright 1998-2004 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 1998-2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -153,22 +153,22 @@ public class ObjectStreamClass implements java.io.Serializable { desc = new ObjectStreamClass(cl, superdesc, serializable, externalizable); } + // Must always call init. See bug 4488137. This code was + // incorrectly changed to return immediately on a non-null + // cache result. That allowed threads to gain access to + // unintialized instances. + // + // History: Note, the following init() call was originally within + // the synchronization block, as it currently is now. Later, the + // init() call was moved outside the synchronization block, and + // the init() method used a private member variable lock, to + // avoid performance problems. See bug 4165204. But that lead to + // a deadlock situation, see bug 5104239. Hence, the init() method + // has now been moved back into the synchronization block. The + // right approach to solving these problems would be to rewrite + // this class, based on the latest java.io.ObjectStreamClass. + desc.init(); } - - // Must always call init. See bug 4488137. This code was - // incorrectly changed to return immediately on a non-null - // cache result. That allowed threads to gain access to - // unintialized instances. - // - // All threads must sync on the member variable lock - // and check the initialization state. - // - // Another possibility is to continue to synchronize on the - // descriptorFor array, but that leads to poor performance - // (see bug 4165204 "ObjectStreamClass can hold global lock - // for a very long time"). - desc.init(); - return desc; } diff --git a/src/share/classes/com/sun/corba/se/impl/oa/poa/POAFactory.java b/src/share/classes/com/sun/corba/se/impl/oa/poa/POAFactory.java index 5cde4bf0ec3fb35c81919bba44278af409c23c7c..c0cb1d8c100272ac560fdae2a788264161033241 100644 --- a/src/share/classes/com/sun/corba/se/impl/oa/poa/POAFactory.java +++ b/src/share/classes/com/sun/corba/se/impl/oa/poa/POAFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2004 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2002-2007 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -76,6 +76,7 @@ public class POAFactory implements ObjectAdapterFactory private ORB orb ; private POASystemException wrapper ; private OMGSystemException omgWrapper ; + private boolean isShuttingDown = false; public POASystemException getWrapper() { @@ -166,6 +167,7 @@ public class POAFactory implements ObjectAdapterFactory // pm.deactivate removes itself from poaManagers! Iterator managers = null ; synchronized (this) { + isShuttingDown = true ; managers = (new HashSet(poaManagers)).iterator(); } @@ -208,9 +210,15 @@ public class POAFactory implements ObjectAdapterFactory ClosureFactory.makeFuture( rpClosure ) ) ; } + public synchronized POA getRootPOA() { if (rootPOA == null) { + // See if we are trying to getRootPOA while shutting down the ORB. + if (isShuttingDown) { + throw omgWrapper.noObjectAdaptor( ) ; + } + try { Object obj = orb.resolve_initial_references( ORBConstants.ROOT_POA_NAME ) ; diff --git a/src/share/classes/com/sun/corba/se/impl/orb/ORBImpl.java b/src/share/classes/com/sun/corba/se/impl/orb/ORBImpl.java index 52b5cbf38f37127a59decd4a0fb9c0938c644738..45fa6dde3731fbeecde60720efa74ec9b57bd2b6 100644 --- a/src/share/classes/com/sun/corba/se/impl/orb/ORBImpl.java +++ b/src/share/classes/com/sun/corba/se/impl/orb/ORBImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2006 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2002-2007 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -185,7 +185,6 @@ public class ORBImpl extends com.sun.corba.se.spi.orb.ORB private java.lang.Object runObj = new java.lang.Object(); private java.lang.Object shutdownObj = new java.lang.Object(); - private java.lang.Object waitForCompletionObj = new java.lang.Object(); private static final byte STATUS_OPERATING = 1; private static final byte STATUS_SHUTTING_DOWN = 2; private static final byte STATUS_SHUTDOWN = 3; @@ -194,7 +193,6 @@ public class ORBImpl extends com.sun.corba.se.spi.orb.ORB // XXX Should we move invocation tracking to the first level server dispatcher? private java.lang.Object invocationObj = new java.lang.Object(); - private int numInvocations = 0; // thread local variable to store a boolean to detect deadlock in // ORB.shutdown(true). @@ -1245,37 +1243,48 @@ public class ORBImpl extends com.sun.corba.se.spi.orb.ORB public void shutdown(boolean wait_for_completion) { + // to wait for completion, we would deadlock, so throw a standard + // OMG exception. + if (wait_for_completion && ((Boolean)isProcessingInvocation.get()).booleanValue()) { + throw omgWrapper.shutdownWaitForCompletionDeadlock() ; + } + + boolean doShutdown = false ; + synchronized (this) { - checkShutdownState(); + checkShutdownState() ; + + if (status == STATUS_SHUTTING_DOWN) { + if (!wait_for_completion) + // If we are already shutting down and don't want + // to wait, nothing to do: return. + return ; + } else { + // The ORB status was STATUS_OPERATING, so start the shutdown. + status = STATUS_SHUTTING_DOWN ; + doShutdown = true ; + } } - // Avoid more than one thread performing shutdown at a time. + // At this point, status is SHUTTING_DOWN. + // All shutdown calls with wait_for_completion == true must synchronize + // here. Only the first call will be made with doShutdown == true. synchronized (shutdownObj) { - checkShutdownState(); - // This is to avoid deadlock - if (wait_for_completion && - isProcessingInvocation.get() == Boolean.TRUE) { - throw omgWrapper.shutdownWaitForCompletionDeadlock() ; - } + if (doShutdown) { + // shutdownServants will set all POAManagers into the + // INACTIVE state, causing request to be rejected. + // If wait_for_completion is true, this will not return until + // all invocations have completed. + shutdownServants(wait_for_completion); + + synchronized (runObj) { + runObj.notifyAll(); + } - status = STATUS_SHUTTING_DOWN; - // XXX access to requestDispatcherRegistry should be protected - // by the ORBImpl instance monitor, but is not here in the - // shutdownServants call. - shutdownServants(wait_for_completion); - if (wait_for_completion) { - synchronized ( waitForCompletionObj ) { - while (numInvocations > 0) { - try { - waitForCompletionObj.wait(); - } catch (InterruptedException ex) {} - } + synchronized (this) { + status = STATUS_SHUTDOWN; } } - synchronized ( runObj ) { - runObj.notifyAll(); - } - status = STATUS_SHUTDOWN; } } @@ -1314,23 +1323,13 @@ public class ORBImpl extends com.sun.corba.se.spi.orb.ORB { synchronized (invocationObj) { isProcessingInvocation.set(Boolean.TRUE); - numInvocations++; } } public void finishedDispatch() { synchronized (invocationObj) { - numInvocations--; isProcessingInvocation.set(Boolean.FALSE); - if (numInvocations == 0) { - synchronized (waitForCompletionObj) { - waitForCompletionObj.notifyAll(); - } - } else if (numInvocations < 0) { - throw wrapper.numInvocationsAlreadyZero( - CompletionStatus.COMPLETED_YES ) ; - } } } @@ -1341,12 +1340,24 @@ public class ORBImpl extends com.sun.corba.se.spi.orb.ORB */ public synchronized void destroy() { - if (status == STATUS_OPERATING) { + boolean shutdownFirst = false ; + + synchronized (this) { + shutdownFirst = (status == STATUS_OPERATING) ; + } + + if (shutdownFirst) { shutdown(true); } - getCorbaTransportManager().close(); - getPIHandler().destroyInterceptors() ; - status = STATUS_DESTROYED; + + synchronized (this) { + if (status < STATUS_DESTROYED) { + getCorbaTransportManager().close(); + getPIHandler().destroyInterceptors() ; + status = STATUS_DESTROYED; + } + } + } /** diff --git a/src/share/classes/com/sun/corba/se/impl/orb/ORBSingleton.java b/src/share/classes/com/sun/corba/se/impl/orb/ORBSingleton.java index 4c43ee67e5b1dcba4c74db1fbb1d0637d484b486..ecd9539b8aac2fd66843490c9accfd0631468ff1 100644 --- a/src/share/classes/com/sun/corba/se/impl/orb/ORBSingleton.java +++ b/src/share/classes/com/sun/corba/se/impl/orb/ORBSingleton.java @@ -1,5 +1,5 @@ /* - * Copyright 1997-2004 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -135,7 +135,7 @@ import com.sun.corba.se.spi.legacy.connection.LegacyServerSocketEndPointInfo; public class ORBSingleton extends ORB { // This is used to support read_Object. - private static ORB fullORB; + private ORB fullORB; private static PresentationManager.StubFactoryFactory staticStubFactoryFactory = PresentationDefaults.getStaticStubFactoryFactory() ; diff --git a/src/share/classes/com/sun/corba/se/impl/orbutil/ORBUtility.java b/src/share/classes/com/sun/corba/se/impl/orbutil/ORBUtility.java index ab5106d580b0011b8c055f81514eace574709a0f..dd5af6e8b3b8f478a3d5efdc61b5dacf08aec76b 100644 --- a/src/share/classes/com/sun/corba/se/impl/orbutil/ORBUtility.java +++ b/src/share/classes/com/sun/corba/se/impl/orbutil/ORBUtility.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2004 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2000-2006 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -806,25 +806,6 @@ public final class ORBUtility { return result ; } - public static void setDaemon(Thread thread) - { - // Catch exceptions since setDaemon can cause a - // security exception to be thrown under netscape - // in the Applet mode - final Thread finalThread = thread; - try { - AccessController.doPrivileged(new PrivilegedAction() { - public java.lang.Object run() { - finalThread.setDaemon(true); - return null; - } - }); - } catch (Exception e) { - // REVISIT: Object to get static method. Ignore it. - dprint(new Object(), "setDaemon: Exception: " + e); - } - } - public static String operationNameAndRequestId(CorbaMessageMediator m) { return "op/" + m.getOperationName() + " id/" + m.getRequestId(); diff --git a/src/share/classes/com/sun/corba/se/impl/resolver/INSURLOperationImpl.java b/src/share/classes/com/sun/corba/se/impl/resolver/INSURLOperationImpl.java index 9d07b453fc9625fc9f0c3bae10216083d5ea1753..0bb9d94a1fde9cb43641d8e5b352b69338fec5a2 100644 --- a/src/share/classes/com/sun/corba/se/impl/resolver/INSURLOperationImpl.java +++ b/src/share/classes/com/sun/corba/se/impl/resolver/INSURLOperationImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 1998-2004 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 1998-2007 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -53,7 +53,8 @@ import com.sun.corba.se.spi.orb.ORB; import com.sun.corba.se.spi.resolver.Resolver; import com.sun.corba.se.impl.encoding.EncapsInputStream; -import com.sun.corba.se.impl.logging.ORBUtilSystemException ; +import com.sun.corba.se.impl.logging.ORBUtilSystemException; +import com.sun.corba.se.impl.logging.OMGSystemException; import com.sun.corba.se.impl.naming.namingutil.INSURLHandler; import com.sun.corba.se.impl.naming.namingutil.IIOPEndpointInfo; import com.sun.corba.se.impl.naming.namingutil.INSURL; @@ -76,6 +77,7 @@ public class INSURLOperationImpl implements Operation { ORB orb; ORBUtilSystemException wrapper ; + OMGSystemException omgWrapper ; Resolver bootstrapResolver ; // Root Naming Context for default resolution of names. @@ -90,6 +92,8 @@ public class INSURLOperationImpl implements Operation this.orb = orb ; wrapper = ORBUtilSystemException.get( orb, CORBALogDomains.ORB_RESOLVER ) ; + omgWrapper = OMGSystemException.get( orb, + CORBALogDomains.ORB_RESOLVER ) ; this.bootstrapResolver = bootstrapResolver ; } @@ -126,6 +130,8 @@ public class INSURLOperationImpl implements Operation return getIORFromString( str ) ; else { INSURL insURL = insURLHandler.parseURL( str ) ; + if (insURL == null) + throw omgWrapper.soBadSchemeName() ; return resolveINSURL( insURL ) ; } } diff --git a/src/share/classes/com/sun/corba/se/impl/transport/SocketOrChannelConnectionImpl.java b/src/share/classes/com/sun/corba/se/impl/transport/SocketOrChannelConnectionImpl.java index e160eec73c4f911c304ff26175d842bee5334784..5dbfedb9fea9809990ae33f0e6456fd1ed766806 100644 --- a/src/share/classes/com/sun/corba/se/impl/transport/SocketOrChannelConnectionImpl.java +++ b/src/share/classes/com/sun/corba/se/impl/transport/SocketOrChannelConnectionImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2001-2004 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2001-2007 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -1057,7 +1057,9 @@ public class SocketOrChannelConnectionImpl // IIOPOutputStream will cleanup the connection info when it // sees this exception. - throw wrapper.writeErrorSend(e1) ; + SystemException exc = wrapper.writeErrorSend(e1); + purgeCalls(exc, false, true); + throw exc; } } diff --git a/src/share/classes/com/sun/corba/se/spi/logging/data/ORBUtil.mc b/src/share/classes/com/sun/corba/se/spi/logging/data/ORBUtil.mc index 40cdb885a2696d746bba02705087d234711b1dc1..7c46f35a117e28c2629cfd78c31871767e173d25 100644 --- a/src/share/classes/com/sun/corba/se/spi/logging/data/ORBUtil.mc +++ b/src/share/classes/com/sun/corba/se/spi/logging/data/ORBUtil.mc @@ -1,6 +1,6 @@ ; -; Copyright 2003-2006 Sun Microsystems, Inc. All Rights Reserved. +; Copyright 2003-2008 Sun Microsystems, Inc. All Rights Reserved. ; DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. ; ; This code is free software; you can redistribute it and/or modify it @@ -144,6 +144,8 @@ 15 WARNING "Read of full message failed : bytes requested = {0} bytes read = {1} max wait time = {2} total time spent waiting = {3}") (CREATE_LISTENER_FAILED 16 SEVERE "Unable to create listener thread on the specified port: {0}") + (BUFFER_READ_MANAGER_TIMEOUT + 17 WARNING "Timeout while reading data in buffer manager") ) (DATA_CONVERSION (BAD_STRINGIFIED_IOR_LEN 1 WARNING "A character did not map to the transmission code set") diff --git a/src/share/classes/com/sun/tools/corba/se/idl/Parser.java b/src/share/classes/com/sun/tools/corba/se/idl/Parser.java index 20432edf142ec128707a06c3fc88f1cd4fe4ccd3..17221825f62f0f104b6872cdf6105b313c1e3886 100644 --- a/src/share/classes/com/sun/tools/corba/se/idl/Parser.java +++ b/src/share/classes/com/sun/tools/corba/se/idl/Parser.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2004 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 1999-2007 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -2086,8 +2086,8 @@ class Parser if (token.type == Token.LeftBrace) { repIDStack.push(((IDLID)repIDStack.peek ()).clone ()) ; - ((IDLID)repIDStack.peek ()).appendToName (name); structEntry = makeStructEntry( name, entry, false ) ; + ((IDLID)repIDStack.peek ()).appendToName (name); prep.openScope (structEntry); match (Token.LeftBrace) ; member (structEntry) ; @@ -2174,8 +2174,8 @@ class Parser if (token.type == Token.Switch) { repIDStack.push (((IDLID)repIDStack.peek ()).clone ()); - ((IDLID)repIDStack.peek ()).appendToName (name); unionEntry = makeUnionEntry( name, entry, false ) ; + ((IDLID)repIDStack.peek ()).appendToName (name); match (Token.Switch); match (Token.LeftParen); unionEntry.type (switchTypeSpec (unionEntry)); @@ -2641,8 +2641,8 @@ class Parser private void exceptDcl (SymtabEntry entry) throws IOException, ParseException { match (Token.Exception); - ExceptionEntry exceptEntry = stFactory.exceptionEntry (entry, (IDLID)repIDStack.peek ()); repIDStack.push (((IDLID)repIDStack.peek ()).clone ()); + ExceptionEntry exceptEntry = stFactory.exceptionEntry (entry, (IDLID)repIDStack.peek ()); ((IDLID)repIDStack.peek ()).appendToName (token.name); exceptEntry.sourceFile (scanner.fileEntry ()); // Comment must immediately precede "exception" keyword diff --git a/src/share/classes/com/sun/tools/corba/se/logutil/InputException.java b/src/share/classes/com/sun/tools/corba/se/logutil/InputException.java index 5c1f4984e57663e7285a720e5c403c7f000402a8..597d3185a6b81ef1a6b083435c17afec1548e757 100644 --- a/src/share/classes/com/sun/tools/corba/se/logutil/InputException.java +++ b/src/share/classes/com/sun/tools/corba/se/logutil/InputException.java @@ -91,4 +91,3 @@ public class InputException { } } - diff --git a/src/share/classes/org/omg/CORBA/ORB.java b/src/share/classes/org/omg/CORBA/ORB.java index cecdefeb3e5a3895447a479fb7516879f7b951dd..dde09300f2ff1d96e86767c3b951dfdbc5628b3f 100644 --- a/src/share/classes/org/omg/CORBA/ORB.java +++ b/src/share/classes/org/omg/CORBA/ORB.java @@ -1,5 +1,5 @@ /* - * Copyright 1995-2005 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 1995-2006 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -289,7 +289,7 @@ abstract public class ORB { * * @return the singleton ORB */ - public static ORB init() { + public static synchronized ORB init() { if (singleton == null) { String className = getSystemProperty(ORBSingletonClassKey); if (className == null)