--- old/src/share/classes/com/sun/corba/se/impl/encoding/CachedCodeBase.java Mon Jun 25 21:04:09 2012 +++ new/src/share/classes/com/sun/corba/se/impl/encoding/CachedCodeBase.java Mon Jun 25 21:04:09 2012 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2004, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2004, Oracle and/or its affiliates. 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 @@ -22,7 +22,6 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ - package com.sun.corba.se.impl.encoding; import java.util.Hashtable; @@ -32,7 +31,8 @@ import com.sun.org.omg.SendingContext._CodeBaseImplBase; import com.sun.org.omg.SendingContext._CodeBaseStub; import com.sun.corba.se.spi.transport.CorbaConnection; - +import com.sun.corba.se.spi.ior.IOR; +import com.sun.corba.se.spi.orb.ORB; /** * Provides the reading side with a per connection cache of * info obtained via calls to the remote CodeBase. @@ -51,15 +51,25 @@ * * Needs cache management. */ -// REVISIT: revert to package protected after framework merge. public class CachedCodeBase extends _CodeBaseImplBase { private Hashtable implementations, fvds, bases; - private CodeBase delegate; + private volatile CodeBase delegate; private CorbaConnection conn; - private static Hashtable iorToCodeBaseObjMap = new Hashtable(); + private static Object iorMapLock = new Object(); + private static Hashtable iorMap = new Hashtable<>(); + public static synchronized void cleanCache( ORB orb ) { + synchronized (iorMapLock) { + for (IOR ior : iorMap.keySet()) { + if (ior.getORB() == orb) { + iorMap.remove(ior); + } + } + } + } + public CachedCodeBase(CorbaConnection connection) { conn = connection; } @@ -67,8 +77,8 @@ public com.sun.org.omg.CORBA.Repository get_ir () { return null; } - - public String implementation (String repId) { + + public synchronized String implementation (String repId) { String urlResult = null; if (implementations == null) @@ -86,7 +96,7 @@ return urlResult; } - public String[] implementations (String[] repIds) { + public synchronized String[] implementations (String[] repIds) { String[] urlResults = new String[repIds.length]; for (int i = 0; i < urlResults.length; i++) @@ -95,7 +105,7 @@ return urlResults; } - public FullValueDescription meta (String repId) { + public synchronized FullValueDescription meta (String repId) { FullValueDescription result = null; if (fvds == null) @@ -113,8 +123,8 @@ return result; } - public FullValueDescription[] metas (String[] repIds) { - FullValueDescription[] results + public synchronized FullValueDescription[] metas (String[] repIds) { + FullValueDescription[] results = new FullValueDescription[repIds.length]; for (int i = 0; i < results.length; i++) @@ -123,7 +133,7 @@ return results; } - public String[] bases (String repId) { + public synchronized String[] bases (String repId) { String[] results = null; @@ -145,7 +155,7 @@ // Ensures that we've used the connection's IOR to create // a valid CodeBase delegate. If this returns false, then // it is not valid to access the delegate. - private boolean connectedCodeBase() { + private synchronized boolean connectedCodeBase() { if (delegate != null) return true; @@ -165,7 +175,7 @@ return false; } - synchronized(this) { + synchronized(iorMapLock) { // Recheck the condition to make sure another // thread didn't already do this while we waited @@ -173,16 +183,16 @@ return true; // Do we have a reference initialized by another connection? - delegate = (CodeBase)CachedCodeBase.iorToCodeBaseObjMap.get(conn.getCodeBaseIOR()); + delegate = CachedCodeBase.iorMap.get(conn.getCodeBaseIOR()); + if (delegate != null) return true; - + // Connect the delegate and update the cache delegate = CodeBaseHelper.narrow(getObjectFromIOR()); - + // Save it for the benefit of other connections - CachedCodeBase.iorToCodeBaseObjMap.put(conn.getCodeBaseIOR(), - delegate); + CachedCodeBase.iorMap.put(conn.getCodeBaseIOR(), delegate); } // It's now safe to use the delegate @@ -191,8 +201,9 @@ private final org.omg.CORBA.Object getObjectFromIOR() { return CDRInputStream_1_0.internalIORToObject( - conn.getCodeBaseIOR(), null /*stubFactory*/, conn.getBroker()); + conn.getCodeBaseIOR(), null /*stubFactory*/, conn.getBroker()); } } // End of file. +