ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/concurrent/ConcurrentHashMap.java
(Generate patch)

Comparing jsr166/src/main/java/util/concurrent/ConcurrentHashMap.java (file contents):
Revision 1.207 by jsr166, Tue Apr 16 05:45:59 2013 UTC vs.
Revision 1.208 by dl, Thu Apr 25 16:15:11 2013 UTC

# Line 5 | Line 5
5   */
6  
7   package java.util.concurrent;
8 < import java.util.concurrent.ForkJoinPool;
9 < import java.util.concurrent.CountedCompleter;
10 < import java.util.Spliterator;
11 < import java.util.stream.Stream;
12 < import java.util.stream.Streams;
13 < import java.util.function.*;
14 < import java.util.function.Consumer;
15 < import java.util.function.Function;
16 < import java.util.function.BiFunction;
17 <
18 < import java.util.Comparator;
19 < import java.util.Arrays;
20 < import java.util.Map;
21 < import java.util.Set;
22 < import java.util.Collection;
8 > import java.io.Serializable;
9 > import java.io.ObjectStreamField;
10 > import java.lang.reflect.ParameterizedType;
11 > import java.lang.reflect.Type;
12 > import java.util.AbstractCollection;
13   import java.util.AbstractMap;
14   import java.util.AbstractSet;
15 < import java.util.AbstractCollection;
16 < import java.util.Hashtable;
15 > import java.util.Arrays;
16 > import java.util.Collection;
17 > import java.util.Comparator;
18 > import java.util.ConcurrentModificationException;
19 > import java.util.Enumeration;
20   import java.util.HashMap;
21 + import java.util.Hashtable;
22   import java.util.Iterator;
23 < import java.util.Enumeration;
30 < import java.util.ConcurrentModificationException;
23 > import java.util.Map;
24   import java.util.NoSuchElementException;
25 + import java.util.Set;
26 + import java.util.Spliterator;
27   import java.util.concurrent.ConcurrentMap;
28 < import java.util.concurrent.locks.AbstractQueuedSynchronizer;
34 < import java.util.concurrent.atomic.AtomicInteger;
28 > import java.util.concurrent.ForkJoinPool;
29   import java.util.concurrent.atomic.AtomicReference;
30 < import java.io.Serializable;
31 < import java.lang.reflect.Type;
32 < import java.lang.reflect.ParameterizedType;
30 > import java.util.concurrent.locks.AbstractQueuedSynchronizer;
31 > import java.util.concurrent.locks.ReentrantLock;
32 > import java.util.function.BiConsumer;
33 > import java.util.function.BiFunction;
34 > import java.util.function.BinaryOperator;
35 > import java.util.function.Consumer;
36 > import java.util.function.DoubleBinaryOperator;
37 > import java.util.function.Function;
38 > import java.util.function.IntBinaryOperator;
39 > import java.util.function.LongBinaryOperator;
40 > import java.util.function.ToDoubleBiFunction;
41 > import java.util.function.ToDoubleFunction;
42 > import java.util.function.ToIntBiFunction;
43 > import java.util.function.ToIntFunction;
44 > import java.util.function.ToLongBiFunction;
45 > import java.util.function.ToLongFunction;
46  
47   /**
48   * A hash table supporting full concurrency of retrievals and
# Line 471 | Line 478 | public class ConcurrentHashMap<K,V>
478      /** Number of CPUS, to place bounds on some sizings */
479      static final int NCPU = Runtime.getRuntime().availableProcessors();
480  
481 +    /** For serialization compatibility. */
482 +    private static final ObjectStreamField[] serialPersistentFields = {
483 +        new ObjectStreamField("segments", Segment[].class)
484 +    };
485 +
486      /* ---------------- Counters -------------- */
487  
488      // Adapted from LongAdder and Striped64.
# Line 539 | Line 551 | public class ConcurrentHashMap<K,V>
551      private transient ValuesView<K,V> values;
552      private transient EntrySetView<K,V> entrySet;
553  
542    /** For serialization compatibility. Null unless serialized; see below */
543    private Segment<K,V>[] segments;
544
554      /* ---------------- Table element access -------------- */
555  
556      /*
# Line 615 | Line 624 | public class ConcurrentHashMap<K,V>
624          }
625      }
626  
618
627      /**
628       * Returns a Class for the given object of the form "class C
629       * implements Comparable<C>", if one exists, else null.  See below
# Line 3277 | Line 3285 | public class ConcurrentHashMap<K,V>
3285       * Stripped-down version of helper class used in previous version,
3286       * declared for the sake of serialization compatibility
3287       */
3288 <    static class Segment<K,V> implements Serializable {
3288 >    static class Segment<K,V> extends ReentrantLock implements Serializable {
3289          private static final long serialVersionUID = 2249069246763182397L;
3290          final float loadFactor;
3291          Segment(float lf) { this.loadFactor = lf; }
# Line 3295 | Line 3303 | public class ConcurrentHashMap<K,V>
3303      @SuppressWarnings("unchecked") private void writeObject
3304          (java.io.ObjectOutputStream s)
3305          throws java.io.IOException {
3306 <        if (segments == null) { // for serialization compatibility
3307 <            segments = (Segment<K,V>[])
3308 <                new Segment<?,?>[DEFAULT_CONCURRENCY_LEVEL];
3309 <            for (int i = 0; i < segments.length; ++i)
3310 <                segments[i] = new Segment<K,V>(LOAD_FACTOR);
3311 <        }
3312 <        s.defaultWriteObject();
3306 >        // For serialization compatibility
3307 >        Segment<K,V>[] segments = (Segment<K,V>[])
3308 >            new Segment<?,?>[DEFAULT_CONCURRENCY_LEVEL];
3309 >        for (int i = 0; i < segments.length; ++i)
3310 >            segments[i] = new Segment<K,V>(LOAD_FACTOR);
3311 >        s.putFields().put("segments", segments);
3312 >        s.writeFields();
3313          Traverser<K,V,Object> it = new Traverser<K,V,Object>(this);
3314          V v;
3315          while ((v = it.advanceValue()) != null) {
# Line 3321 | Line 3329 | public class ConcurrentHashMap<K,V>
3329          (java.io.ObjectInputStream s)
3330          throws java.io.IOException, ClassNotFoundException {
3331          s.defaultReadObject();
3324        this.segments = null; // unneeded
3332  
3333          // Create all nodes, then place in table once size is known
3334          long size = 0L;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines