Skip to content

Commit 74b6c74

Browse files
committed
use a ConcurrentHashMap as suggested by M. Bruch on mailing list
git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@3779 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
1 parent 23f99d6 commit 74b6c74

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

com.ibm.wala.core/src/com/ibm/wala/ipa/cha/ClassHierarchy.java

+11-7
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@
1313
import java.io.IOException;
1414
import java.util.Collection;
1515
import java.util.Collections;
16+
import java.util.ConcurrentModificationException;
1617
import java.util.HashMap;
1718
import java.util.HashSet;
1819
import java.util.Iterator;
1920
import java.util.Map;
2021
import java.util.Set;
22+
import java.util.concurrent.ConcurrentHashMap;
2123

2224
import org.eclipse.core.runtime.IProgressMonitor;
2325
import org.eclipse.core.runtime.NullProgressMonitor;
@@ -54,8 +56,8 @@
5456
/**
5557
* Simple implementation of a class hierarchy.
5658
*
57-
* Note that this class hierarchy implementation is mutable. You can add classes via addClass(). You can add
58-
* a class even if c.getClassLoader() does not appear in getLoaders().
59+
* Note that this class hierarchy implementation is mutable. You can add classes via addClass(). You can add a class even if
60+
* c.getClassLoader() does not appear in getLoaders().
5961
*/
6062
public class ClassHierarchy implements IClassHierarchy {
6163

@@ -69,8 +71,14 @@ public class ClassHierarchy implements IClassHierarchy {
6971

7072
/**
7173
* For each {@link IClass} c in this class hierarchy, this map maps c.getReference() to the {@link Node}
74+
*
75+
* Note that this class provides an iterator() over this map, and that some WALA utilities (e.g. ReferenceCleanser) must iterate
76+
* over all classes. But also note that the class hierarchy is mutable (addClass()). So, when trying to run multiple threads, we
77+
* could see a race condition between iterator() and addClass(). With a normal {@link HashMap}, this would result in a
78+
* {@link ConcurrentModificationException}. But with a {@link ConcurrentHashMap}, at least the code merrily chugs along,
79+
* tolerating the race.
7280
*/
73-
final private HashMap<TypeReference, Node> map = HashMapFactory.make();
81+
final private Map<TypeReference, Node> map = new ConcurrentHashMap<TypeReference, Node>();
7482

7583
/**
7684
* {@link TypeReference} for the root type
@@ -358,9 +366,6 @@ public boolean addClass(IClass klass) {
358366

359367
/**
360368
* Record that a klass implements a particular interface
361-
*
362-
* @param klass
363-
* @param iface
364369
*/
365370
private void recordImplements(IClass klass, IClass iface) {
366371
Set<IClass> impls = MapUtil.findOrCreateSet(implementors, iface);
@@ -1078,7 +1083,6 @@ public AnalysisScope getScope() {
10781083
}
10791084

10801085
/**
1081-
* @param klass
10821086
* @return the number of classes that immediately extend klass. if klass is an array class A[][]...[], we return number of
10831087
* immediate subclasses of A. If A is primitive, we return 0.
10841088
*/

0 commit comments

Comments
 (0)