Sun, 18 Dec 2011 22:12:41 +0400
7046238: new InitialContext(); hangs
Summary: Synchronization on a single monitor for contactInfo parameters with identical hashCode()
Reviewed-by: robm, skoppar
src/share/classes/com/sun/corba/se/impl/protocol/CorbaClientRequestDispatcherImpl.java | file | annotate | diff | comparison | revisions |
1.1 --- a/src/share/classes/com/sun/corba/se/impl/protocol/CorbaClientRequestDispatcherImpl.java Thu Dec 15 19:49:16 2011 -0800 1.2 +++ b/src/share/classes/com/sun/corba/se/impl/protocol/CorbaClientRequestDispatcherImpl.java Sun Dec 18 22:12:41 2011 +0400 1.3 @@ -1,5 +1,5 @@ 1.4 /* 1.5 - * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved. 1.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.8 * 1.9 * This code is free software; you can redistribute it and/or modify it 1.10 @@ -113,6 +113,9 @@ 1.11 import com.sun.corba.se.impl.transport.CorbaContactInfoListIteratorImpl; 1.12 import com.sun.corba.se.impl.util.JDKBridge; 1.13 1.14 +import java.util.concurrent.ConcurrentMap; 1.15 +import java.util.concurrent.ConcurrentHashMap; 1.16 + 1.17 /** 1.18 * ClientDelegate is the RMI client-side subcontract or representation 1.19 * It implements RMI delegate as well as our internal ClientRequestDispatcher 1.20 @@ -122,6 +125,9 @@ 1.21 implements 1.22 ClientRequestDispatcher 1.23 { 1.24 + private ConcurrentMap<ContactInfo, Object> locks = 1.25 + new ConcurrentHashMap<ContactInfo, Object>(); 1.26 + 1.27 public OutputObject beginRequest(Object self, String opName, 1.28 boolean isOneWay, ContactInfo contactInfo) 1.29 { 1.30 @@ -148,8 +154,21 @@ 1.31 1.32 // This locking is done so that multiple connections are not created 1.33 // for the same endpoint 1.34 - //6929137 - Synchronized on contactInfo to avoid blocking across multiple endpoints 1.35 - synchronized (contactInfo) { 1.36 + // 7046238 - Synchronization on a single monitor for contactInfo parameters 1.37 + // with identical hashCode(), so we lock on same monitor for equal parameters 1.38 + // (which can refer to equal (in terms of equals()) but not the same objects) 1.39 + 1.40 + Object lock = locks.get(contactInfo); 1.41 + 1.42 + if (lock == null) { 1.43 + Object newLock = new Object(); 1.44 + lock = locks.putIfAbsent(contactInfo, newLock); 1.45 + if (lock == null) { 1.46 + lock = newLock; 1.47 + } 1.48 + } 1.49 + 1.50 + synchronized (lock) { 1.51 if (contactInfo.isConnectionBased()) { 1.52 if (contactInfo.shouldCacheConnection()) { 1.53 connection = (CorbaConnection) 1.54 @@ -254,7 +273,7 @@ 1.55 registerWaiter(messageMediator); 1.56 1.57 // Do connection reclaim now 1.58 - synchronized (contactInfo) { 1.59 + synchronized (lock) { 1.60 if (contactInfo.isConnectionBased()) { 1.61 if (contactInfo.shouldCacheConnection()) { 1.62 OutboundConnectionCache connectionCache =