jdk/src/share/classes/java/util/concurrent/ConcurrentHashMap.java
author psandoz
Tue, 06 Aug 2013 14:26:34 +0100
changeset 19428 83f87aff7b07
parent 19413 56082c988815
child 19855 bfe130545fe0
permissions -rw-r--r--
8022318: Document Spliterator characteristics and binding policy of java util concurrent collection impls Reviewed-by: chegar Contributed-by: Martin Buchholz <martinrb@google.com>, Paul Sandoz <paul.sandoz@oracle.com>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     6
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     8
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * This file is available under and governed by the GNU General Public
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * License version 2 only, as published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * However, the following notice accompanied the original version of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * file:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * Written by Doug Lea with assistance from members of JCP JSR-166
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * Expert Group and released to the public domain, as explained at
9242
ef138d47df58 7034657: Update Creative Commons license URL in legal notices
dl
parents: 7518
diff changeset
    33
 * http://creativecommons.org/publicdomain/zero/1.0/
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
package java.util.concurrent;
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
    37
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
    38
import java.io.ObjectStreamField;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.io.Serializable;
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
    40
import java.lang.reflect.ParameterizedType;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
    41
import java.lang.reflect.Type;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
    42
import java.util.AbstractMap;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
    43
import java.util.Arrays;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
    44
import java.util.Collection;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
    45
import java.util.Comparator;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
    46
import java.util.Enumeration;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
    47
import java.util.HashMap;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
    48
import java.util.Hashtable;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
    49
import java.util.Iterator;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
    50
import java.util.Map;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
    51
import java.util.NoSuchElementException;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
    52
import java.util.Set;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
    53
import java.util.Spliterator;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
    54
import java.util.concurrent.ConcurrentMap;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
    55
import java.util.concurrent.ForkJoinPool;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
    56
import java.util.concurrent.atomic.AtomicReference;
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
    57
import java.util.concurrent.locks.LockSupport;
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
    58
import java.util.concurrent.locks.ReentrantLock;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
    59
import java.util.function.BiConsumer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
    60
import java.util.function.BiFunction;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
    61
import java.util.function.BinaryOperator;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
    62
import java.util.function.Consumer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
    63
import java.util.function.DoubleBinaryOperator;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
    64
import java.util.function.Function;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
    65
import java.util.function.IntBinaryOperator;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
    66
import java.util.function.LongBinaryOperator;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
    67
import java.util.function.ToDoubleBiFunction;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
    68
import java.util.function.ToDoubleFunction;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
    69
import java.util.function.ToIntBiFunction;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
    70
import java.util.function.ToIntFunction;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
    71
import java.util.function.ToLongBiFunction;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
    72
import java.util.function.ToLongFunction;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
    73
import java.util.stream.Stream;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * A hash table supporting full concurrency of retrievals and
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
    77
 * high expected concurrency for updates. This class obeys the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * same functional specification as {@link java.util.Hashtable}, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * includes versions of methods corresponding to each method of
17717
fe0b28a1a3bd 8015439: Minor/sync/cleanup of ConcurrentHashMap
chegar
parents: 16883
diff changeset
    80
 * {@code Hashtable}. However, even though all operations are
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * thread-safe, retrieval operations do <em>not</em> entail locking,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * and there is <em>not</em> any support for locking the entire table
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * in a way that prevents all access.  This class is fully
17717
fe0b28a1a3bd 8015439: Minor/sync/cleanup of ConcurrentHashMap
chegar
parents: 16883
diff changeset
    84
 * interoperable with {@code Hashtable} in programs that rely on its
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * thread safety but not on its synchronization details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 *
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
    87
 * <p>Retrieval operations (including {@code get}) generally do not
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
    88
 * block, so may overlap with update operations (including {@code put}
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
    89
 * and {@code remove}). Retrievals reflect the results of the most
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
    90
 * recently <em>completed</em> update operations holding upon their
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
    91
 * onset. (More formally, an update operation for a given key bears a
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
    92
 * <em>happens-before</em> relation with any (non-null) retrieval for
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
    93
 * that key reporting the updated value.)  For aggregate operations
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
    94
 * such as {@code putAll} and {@code clear}, concurrent retrievals may
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
    95
 * reflect insertion or removal of only some entries.  Similarly,
19428
83f87aff7b07 8022318: Document Spliterator characteristics and binding policy of java util concurrent collection impls
psandoz
parents: 19413
diff changeset
    96
 * Iterators, Spliterators and Enumerations return elements reflecting the
83f87aff7b07 8022318: Document Spliterator characteristics and binding policy of java util concurrent collection impls
psandoz
parents: 19413
diff changeset
    97
 * state of the hash table at some point at or since the creation of the
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
    98
 * iterator/enumeration.  They do <em>not</em> throw {@link
19428
83f87aff7b07 8022318: Document Spliterator characteristics and binding policy of java util concurrent collection impls
psandoz
parents: 19413
diff changeset
    99
 * java.util.ConcurrentModificationException ConcurrentModificationException}.
83f87aff7b07 8022318: Document Spliterator characteristics and binding policy of java util concurrent collection impls
psandoz
parents: 19413
diff changeset
   100
 * However, iterators are designed to be used by only one thread at a time.
83f87aff7b07 8022318: Document Spliterator characteristics and binding policy of java util concurrent collection impls
psandoz
parents: 19413
diff changeset
   101
 * Bear in mind that the results of aggregate status methods including
83f87aff7b07 8022318: Document Spliterator characteristics and binding policy of java util concurrent collection impls
psandoz
parents: 19413
diff changeset
   102
 * {@code size}, {@code isEmpty}, and {@code containsValue} are typically
83f87aff7b07 8022318: Document Spliterator characteristics and binding policy of java util concurrent collection impls
psandoz
parents: 19413
diff changeset
   103
 * useful only when a map is not undergoing concurrent updates in other threads.
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   104
 * Otherwise the results of these methods reflect transient states
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   105
 * that may be adequate for monitoring or estimation purposes, but not
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   106
 * for program control.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 *
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   108
 * <p>The table is dynamically expanded when there are too many
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   109
 * collisions (i.e., keys that have distinct hash codes but fall into
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   110
 * the same slot modulo the table size), with the expected average
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   111
 * effect of maintaining roughly two bins per mapping (corresponding
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   112
 * to a 0.75 load factor threshold for resizing). There may be much
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   113
 * variance around this average as mappings are added and removed, but
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   114
 * overall, this maintains a commonly accepted time/space tradeoff for
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   115
 * hash tables.  However, resizing this or any other kind of hash
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   116
 * table may be a relatively slow operation. When possible, it is a
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   117
 * good idea to provide a size estimate as an optional {@code
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   118
 * initialCapacity} constructor argument. An additional optional
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   119
 * {@code loadFactor} constructor argument provides a further means of
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   120
 * customizing initial table capacity by specifying the table density
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   121
 * to be used in calculating the amount of space to allocate for the
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   122
 * given number of elements.  Also, for compatibility with previous
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   123
 * versions of this class, constructors may optionally specify an
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   124
 * expected {@code concurrencyLevel} as an additional hint for
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   125
 * internal sizing.  Note that using many keys with exactly the same
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   126
 * {@code hashCode()} is a sure way to slow down performance of any
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   127
 * hash table. To ameliorate impact, when keys are {@link Comparable},
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   128
 * this class may use comparison order among keys to help break ties.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   129
 *
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   130
 * <p>A {@link Set} projection of a ConcurrentHashMap may be created
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   131
 * (using {@link #newKeySet()} or {@link #newKeySet(int)}), or viewed
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   132
 * (using {@link #keySet(Object)} when only keys are of interest, and the
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   133
 * mapped values are (perhaps transiently) not used or all take the
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   134
 * same mapping value.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   135
 *
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   136
 * <p>A ConcurrentHashMap can be used as scalable frequency map (a
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   137
 * form of histogram or multiset) by using {@link
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   138
 * java.util.concurrent.atomic.LongAdder} values and initializing via
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   139
 * {@link #computeIfAbsent computeIfAbsent}. For example, to add a count
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   140
 * to a {@code ConcurrentHashMap<String,LongAdder> freqs}, you can use
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   141
 * {@code freqs.computeIfAbsent(k -> new LongAdder()).increment();}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
 * <p>This class and its views and iterators implement all of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
 * <em>optional</em> methods of the {@link Map} and {@link Iterator}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
 * interfaces.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
 *
17717
fe0b28a1a3bd 8015439: Minor/sync/cleanup of ConcurrentHashMap
chegar
parents: 16883
diff changeset
   147
 * <p>Like {@link Hashtable} but unlike {@link HashMap}, this class
fe0b28a1a3bd 8015439: Minor/sync/cleanup of ConcurrentHashMap
chegar
parents: 16883
diff changeset
   148
 * does <em>not</em> allow {@code null} to be used as a key or value.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
 *
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   150
 * <p>ConcurrentHashMaps support a set of sequential and parallel bulk
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   151
 * operations that, unlike most {@link Stream} methods, are designed
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   152
 * to be safely, and often sensibly, applied even with maps that are
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   153
 * being concurrently updated by other threads; for example, when
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   154
 * computing a snapshot summary of the values in a shared registry.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   155
 * There are three kinds of operation, each with four forms, accepting
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   156
 * functions with Keys, Values, Entries, and (Key, Value) arguments
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   157
 * and/or return values. Because the elements of a ConcurrentHashMap
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   158
 * are not ordered in any particular way, and may be processed in
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   159
 * different orders in different parallel executions, the correctness
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   160
 * of supplied functions should not depend on any ordering, or on any
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   161
 * other objects or values that may transiently change while
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   162
 * computation is in progress; and except for forEach actions, should
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   163
 * ideally be side-effect-free. Bulk operations on {@link java.util.Map.Entry}
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   164
 * objects do not support method {@code setValue}.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   165
 *
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   166
 * <ul>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   167
 * <li> forEach: Perform a given action on each element.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   168
 * A variant form applies a given transformation on each element
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   169
 * before performing the action.</li>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   170
 *
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   171
 * <li> search: Return the first available non-null result of
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   172
 * applying a given function on each element; skipping further
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   173
 * search when a result is found.</li>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   174
 *
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   175
 * <li> reduce: Accumulate each element.  The supplied reduction
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   176
 * function cannot rely on ordering (more formally, it should be
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   177
 * both associative and commutative).  There are five variants:
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   178
 *
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   179
 * <ul>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   180
 *
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   181
 * <li> Plain reductions. (There is not a form of this method for
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   182
 * (key, value) function arguments since there is no corresponding
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   183
 * return type.)</li>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   184
 *
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   185
 * <li> Mapped reductions that accumulate the results of a given
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   186
 * function applied to each element.</li>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   187
 *
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   188
 * <li> Reductions to scalar doubles, longs, and ints, using a
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   189
 * given basis value.</li>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   190
 *
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   191
 * </ul>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   192
 * </li>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   193
 * </ul>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   194
 *
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   195
 * <p>These bulk operations accept a {@code parallelismThreshold}
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   196
 * argument. Methods proceed sequentially if the current map size is
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   197
 * estimated to be less than the given threshold. Using a value of
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   198
 * {@code Long.MAX_VALUE} suppresses all parallelism.  Using a value
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   199
 * of {@code 1} results in maximal parallelism by partitioning into
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   200
 * enough subtasks to fully utilize the {@link
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   201
 * ForkJoinPool#commonPool()} that is used for all parallel
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   202
 * computations. Normally, you would initially choose one of these
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   203
 * extreme values, and then measure performance of using in-between
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   204
 * values that trade off overhead versus throughput.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   205
 *
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   206
 * <p>The concurrency properties of bulk operations follow
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   207
 * from those of ConcurrentHashMap: Any non-null result returned
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   208
 * from {@code get(key)} and related access methods bears a
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   209
 * happens-before relation with the associated insertion or
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   210
 * update.  The result of any bulk operation reflects the
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   211
 * composition of these per-element relations (but is not
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   212
 * necessarily atomic with respect to the map as a whole unless it
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   213
 * is somehow known to be quiescent).  Conversely, because keys
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   214
 * and values in the map are never null, null serves as a reliable
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   215
 * atomic indicator of the current lack of any result.  To
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   216
 * maintain this property, null serves as an implicit basis for
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   217
 * all non-scalar reduction operations. For the double, long, and
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   218
 * int versions, the basis should be one that, when combined with
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   219
 * any other value, returns that other value (more formally, it
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   220
 * should be the identity element for the reduction). Most common
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   221
 * reductions have these properties; for example, computing a sum
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   222
 * with basis 0 or a minimum with basis MAX_VALUE.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   223
 *
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   224
 * <p>Search and transformation functions provided as arguments
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   225
 * should similarly return null to indicate the lack of any result
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   226
 * (in which case it is not used). In the case of mapped
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   227
 * reductions, this also enables transformations to serve as
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   228
 * filters, returning null (or, in the case of primitive
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   229
 * specializations, the identity basis) if the element should not
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   230
 * be combined. You can create compound transformations and
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   231
 * filterings by composing them yourself under this "null means
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   232
 * there is nothing there now" rule before using them in search or
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   233
 * reduce operations.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   234
 *
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   235
 * <p>Methods accepting and/or returning Entry arguments maintain
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   236
 * key-value associations. They may be useful for example when
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   237
 * finding the key for the greatest value. Note that "plain" Entry
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   238
 * arguments can be supplied using {@code new
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   239
 * AbstractMap.SimpleEntry(k,v)}.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   240
 *
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   241
 * <p>Bulk operations may complete abruptly, throwing an
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   242
 * exception encountered in the application of a supplied
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   243
 * function. Bear in mind when handling such exceptions that other
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   244
 * concurrently executing functions could also have thrown
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   245
 * exceptions, or would have done so if the first exception had
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   246
 * not occurred.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   247
 *
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   248
 * <p>Speedups for parallel compared to sequential forms are common
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   249
 * but not guaranteed.  Parallel operations involving brief functions
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   250
 * on small maps may execute more slowly than sequential forms if the
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   251
 * underlying work to parallelize the computation is more expensive
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   252
 * than the computation itself.  Similarly, parallelization may not
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   253
 * lead to much actual parallelism if all processors are busy
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   254
 * performing unrelated tasks.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   255
 *
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   256
 * <p>All arguments to all task methods must be non-null.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   257
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
 * <p>This class is a member of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
 * <a href="{@docRoot}/../technotes/guides/collections/index.html">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
 * Java Collections Framework</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
 * @author Doug Lea
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
 * @param <K> the type of keys maintained by this map
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
 * @param <V> the type of mapped values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
 */
19036
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
   267
public class ConcurrentHashMap<K,V> extends AbstractMap<K,V>
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
   268
    implements ConcurrentMap<K,V>, Serializable {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    private static final long serialVersionUID = 7249069246763182397L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    /*
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   272
     * Overview:
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   273
     *
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   274
     * The primary design goal of this hash table is to maintain
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   275
     * concurrent readability (typically method get(), but also
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   276
     * iterators and related methods) while minimizing update
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   277
     * contention. Secondary goals are to keep space consumption about
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   278
     * the same or better than java.util.HashMap, and to support high
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   279
     * initial insertion rates on an empty table by many threads.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   280
     *
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   281
     * This map usually acts as a binned (bucketed) hash table.  Each
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   282
     * key-value mapping is held in a Node.  Most nodes are instances
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   283
     * of the basic Node class with hash, key, value, and next
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   284
     * fields. However, various subclasses exist: TreeNodes are
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   285
     * arranged in balanced trees, not lists.  TreeBins hold the roots
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   286
     * of sets of TreeNodes. ForwardingNodes are placed at the heads
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   287
     * of bins during resizing. ReservationNodes are used as
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   288
     * placeholders while establishing values in computeIfAbsent and
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   289
     * related methods.  The types TreeBin, ForwardingNode, and
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   290
     * ReservationNode do not hold normal user keys, values, or
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   291
     * hashes, and are readily distinguishable during search etc
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   292
     * because they have negative hash fields and null key and value
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   293
     * fields. (These special nodes are either uncommon or transient,
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   294
     * so the impact of carrying around some unused fields is
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   295
     * insignificant.)
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   296
     *
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   297
     * The table is lazily initialized to a power-of-two size upon the
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   298
     * first insertion.  Each bin in the table normally contains a
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   299
     * list of Nodes (most often, the list has only zero or one Node).
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   300
     * Table accesses require volatile/atomic reads, writes, and
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   301
     * CASes.  Because there is no other way to arrange this without
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   302
     * adding further indirections, we use intrinsics
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   303
     * (sun.misc.Unsafe) operations.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   304
     *
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   305
     * We use the top (sign) bit of Node hash fields for control
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   306
     * purposes -- it is available anyway because of addressing
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   307
     * constraints.  Nodes with negative hash fields are specially
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   308
     * handled or ignored in map methods.
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   309
     *
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   310
     * Insertion (via put or its variants) of the first node in an
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   311
     * empty bin is performed by just CASing it to the bin.  This is
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   312
     * by far the most common case for put operations under most
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   313
     * key/hash distributions.  Other update operations (insert,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   314
     * delete, and replace) require locks.  We do not want to waste
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   315
     * the space required to associate a distinct lock object with
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   316
     * each bin, so instead use the first node of a bin list itself as
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   317
     * a lock. Locking support for these locks relies on builtin
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   318
     * "synchronized" monitors.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   319
     *
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   320
     * Using the first node of a list as a lock does not by itself
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   321
     * suffice though: When a node is locked, any update must first
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   322
     * validate that it is still the first node after locking it, and
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   323
     * retry if not. Because new nodes are always appended to lists,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   324
     * once a node is first in a bin, it remains first until deleted
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   325
     * or the bin becomes invalidated (upon resizing).
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   326
     *
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   327
     * The main disadvantage of per-bin locks is that other update
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   328
     * operations on other nodes in a bin list protected by the same
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   329
     * lock can stall, for example when user equals() or mapping
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   330
     * functions take a long time.  However, statistically, under
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   331
     * random hash codes, this is not a common problem.  Ideally, the
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   332
     * frequency of nodes in bins follows a Poisson distribution
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   333
     * (http://en.wikipedia.org/wiki/Poisson_distribution) with a
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   334
     * parameter of about 0.5 on average, given the resizing threshold
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   335
     * of 0.75, although with a large variance because of resizing
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   336
     * granularity. Ignoring variance, the expected occurrences of
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   337
     * list size k are (exp(-0.5) * pow(0.5, k) / factorial(k)). The
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   338
     * first values are:
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   339
     *
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   340
     * 0:    0.60653066
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   341
     * 1:    0.30326533
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   342
     * 2:    0.07581633
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   343
     * 3:    0.01263606
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   344
     * 4:    0.00157952
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   345
     * 5:    0.00015795
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   346
     * 6:    0.00001316
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   347
     * 7:    0.00000094
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   348
     * 8:    0.00000006
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   349
     * more: less than 1 in ten million
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   350
     *
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   351
     * Lock contention probability for two threads accessing distinct
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   352
     * elements is roughly 1 / (8 * #elements) under random hashes.
9279
5f5d493d30a0 7036559: ConcurrentHashMap footprint and contention improvements
dl
parents: 9242
diff changeset
   353
     *
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   354
     * Actual hash code distributions encountered in practice
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   355
     * sometimes deviate significantly from uniform randomness.  This
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   356
     * includes the case when N > (1<<30), so some keys MUST collide.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   357
     * Similarly for dumb or hostile usages in which multiple keys are
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   358
     * designed to have identical hash codes or ones that differs only
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   359
     * in masked-out high bits. So we use a secondary strategy that
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   360
     * applies when the number of nodes in a bin exceeds a
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   361
     * threshold. These TreeBins use a balanced tree to hold nodes (a
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   362
     * specialized form of red-black trees), bounding search time to
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   363
     * O(log N).  Each search step in a TreeBin is at least twice as
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   364
     * slow as in a regular list, but given that N cannot exceed
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   365
     * (1<<64) (before running out of addresses) this bounds search
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   366
     * steps, lock hold times, etc, to reasonable constants (roughly
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   367
     * 100 nodes inspected per operation worst case) so long as keys
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   368
     * are Comparable (which is very common -- String, Long, etc).
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   369
     * TreeBin nodes (TreeNodes) also maintain the same "next"
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   370
     * traversal pointers as regular nodes, so can be traversed in
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   371
     * iterators in the same way.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   372
     *
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   373
     * The table is resized when occupancy exceeds a percentage
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   374
     * threshold (nominally, 0.75, but see below).  Any thread
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   375
     * noticing an overfull bin may assist in resizing after the
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   376
     * initiating thread allocates and sets up the replacement
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   377
     * array. However, rather than stalling, these other threads may
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   378
     * proceed with insertions etc.  The use of TreeBins shields us
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   379
     * from the worst case effects of overfilling while resizes are in
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   380
     * progress.  Resizing proceeds by transferring bins, one by one,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   381
     * from the table to the next table. To enable concurrency, the
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   382
     * next table must be (incrementally) prefilled with place-holders
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   383
     * serving as reverse forwarders to the old table.  Because we are
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   384
     * using power-of-two expansion, the elements from each bin must
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   385
     * either stay at same index, or move with a power of two
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   386
     * offset. We eliminate unnecessary node creation by catching
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   387
     * cases where old nodes can be reused because their next fields
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   388
     * won't change.  On average, only about one-sixth of them need
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   389
     * cloning when a table doubles. The nodes they replace will be
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   390
     * garbage collectable as soon as they are no longer referenced by
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   391
     * any reader thread that may be in the midst of concurrently
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   392
     * traversing table.  Upon transfer, the old table bin contains
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   393
     * only a special forwarding node (with hash field "MOVED") that
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   394
     * contains the next table as its key. On encountering a
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   395
     * forwarding node, access and update operations restart, using
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   396
     * the new table.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   397
     *
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   398
     * Each bin transfer requires its bin lock, which can stall
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   399
     * waiting for locks while resizing. However, because other
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   400
     * threads can join in and help resize rather than contend for
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   401
     * locks, average aggregate waits become shorter as resizing
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   402
     * progresses.  The transfer operation must also ensure that all
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   403
     * accessible bins in both the old and new table are usable by any
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   404
     * traversal.  This is arranged by proceeding from the last bin
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   405
     * (table.length - 1) up towards the first.  Upon seeing a
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   406
     * forwarding node, traversals (see class Traverser) arrange to
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   407
     * move to the new table without revisiting nodes.  However, to
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   408
     * ensure that no intervening nodes are skipped, bin splitting can
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   409
     * only begin after the associated reverse-forwarders are in
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   410
     * place.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   411
     *
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   412
     * The traversal scheme also applies to partial traversals of
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   413
     * ranges of bins (via an alternate Traverser constructor)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   414
     * to support partitioned aggregate operations.  Also, read-only
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   415
     * operations give up if ever forwarded to a null table, which
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   416
     * provides support for shutdown-style clearing, which is also not
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   417
     * currently implemented.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   418
     *
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   419
     * Lazy table initialization minimizes footprint until first use,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   420
     * and also avoids resizings when the first operation is from a
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   421
     * putAll, constructor with map argument, or deserialization.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   422
     * These cases attempt to override the initial capacity settings,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   423
     * but harmlessly fail to take effect in cases of races.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   424
     *
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   425
     * The element count is maintained using a specialization of
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   426
     * LongAdder. We need to incorporate a specialization rather than
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   427
     * just use a LongAdder in order to access implicit
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   428
     * contention-sensing that leads to creation of multiple
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   429
     * CounterCells.  The counter mechanics avoid contention on
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   430
     * updates but can encounter cache thrashing if read too
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   431
     * frequently during concurrent access. To avoid reading so often,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   432
     * resizing under contention is attempted only upon adding to a
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   433
     * bin already holding two or more nodes. Under uniform hash
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   434
     * distributions, the probability of this occurring at threshold
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   435
     * is around 13%, meaning that only about 1 in 8 puts check
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   436
     * threshold (and after resizing, many fewer do so).
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   437
     *
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   438
     * TreeBins use a special form of comparison for search and
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   439
     * related operations (which is the main reason we cannot use
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   440
     * existing collections such as TreeMaps). TreeBins contain
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   441
     * Comparable elements, but may contain others, as well as
19036
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
   442
     * elements that are Comparable but not necessarily Comparable for
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
   443
     * the same T, so we cannot invoke compareTo among them. To handle
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
   444
     * this, the tree is ordered primarily by hash value, then by
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
   445
     * Comparable.compareTo order if applicable.  On lookup at a node,
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
   446
     * if elements are not comparable or compare as 0 then both left
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
   447
     * and right children may need to be searched in the case of tied
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
   448
     * hash values. (This corresponds to the full list search that
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
   449
     * would be necessary if all elements were non-Comparable and had
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
   450
     * tied hashes.) On insertion, to keep a total ordering (or as
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
   451
     * close as is required here) across rebalancings, we compare
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
   452
     * classes and identityHashCodes as tie-breakers. The red-black
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
   453
     * balancing code is updated from pre-jdk-collections
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   454
     * (http://gee.cs.oswego.edu/dl/classes/collections/RBCell.java)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   455
     * based in turn on Cormen, Leiserson, and Rivest "Introduction to
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   456
     * Algorithms" (CLR).
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   457
     *
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   458
     * TreeBins also require an additional locking mechanism.  While
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   459
     * list traversal is always possible by readers even during
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   460
     * updates, tree traversal is not, mainly because of tree-rotations
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   461
     * that may change the root node and/or its linkages.  TreeBins
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   462
     * include a simple read-write lock mechanism parasitic on the
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   463
     * main bin-synchronization strategy: Structural adjustments
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   464
     * associated with an insertion or removal are already bin-locked
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   465
     * (and so cannot conflict with other writers) but must wait for
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   466
     * ongoing readers to finish. Since there can be only one such
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   467
     * waiter, we use a simple scheme using a single "waiter" field to
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   468
     * block writers.  However, readers need never block.  If the root
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   469
     * lock is held, they proceed along the slow traversal path (via
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   470
     * next-pointers) until the lock becomes available or the list is
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   471
     * exhausted, whichever comes first. These cases are not fast, but
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   472
     * maximize aggregate expected throughput.
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   473
     *
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   474
     * Maintaining API and serialization compatibility with previous
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   475
     * versions of this class introduces several oddities. Mainly: We
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   476
     * leave untouched but unused constructor arguments refering to
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   477
     * concurrencyLevel. We accept a loadFactor constructor argument,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   478
     * but apply it only to initial table capacity (which is the only
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   479
     * time that we can guarantee to honor it.) We also declare an
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   480
     * unused "Segment" class that is instantiated in minimal form
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   481
     * only when serializing.
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   482
     *
19036
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
   483
     * Also, solely for compatibility with previous versions of this
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
   484
     * class, it extends AbstractMap, even though all of its methods
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
   485
     * are overridden, so it is just useless baggage.
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
   486
     *
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   487
     * This file is organized to make things a little easier to follow
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   488
     * while reading than they might otherwise: First the main static
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   489
     * declarations and utilities, then fields, then main public
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   490
     * methods (with a few factorings of multiple public methods into
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   491
     * internal ones), then sizing methods, trees, traversers, and
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   492
     * bulk operations.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    /* ---------------- Constants -------------- */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    /**
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   498
     * The largest possible table capacity.  This value must be
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   499
     * exactly 1<<30 to stay within Java array allocation and indexing
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   500
     * bounds for power of two table sizes, and is further required
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   501
     * because the top two bits of 32bit hash fields are used for
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   502
     * control purposes.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     */
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   504
    private static final int MAXIMUM_CAPACITY = 1 << 30;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   505
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   506
    /**
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   507
     * The default initial table capacity.  Must be a power of 2
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   508
     * (i.e., at least 1) and at most MAXIMUM_CAPACITY.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   509
     */
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   510
    private static final int DEFAULT_CAPACITY = 16;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
    /**
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   513
     * The largest possible (non-power of two) array size.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   514
     * Needed by toArray and related methods.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     */
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   516
    static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
    /**
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   519
     * The default concurrency level for this table. Unused but
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   520
     * defined for compatibility with previous versions of this class.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     */
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   522
    private static final int DEFAULT_CONCURRENCY_LEVEL = 16;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   523
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   524
    /**
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   525
     * The load factor for this table. Overrides of this value in
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   526
     * constructors affect only the initial table capacity.  The
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   527
     * actual floating point value isn't normally used -- it is
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   528
     * simpler to use expressions such as {@code n - (n >>> 2)} for
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   529
     * the associated resizing threshold.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   530
     */
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   531
    private static final float LOAD_FACTOR = 0.75f;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    /**
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   534
     * The bin count threshold for using a tree rather than list for a
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   535
     * bin.  Bins are converted to trees when adding an element to a
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   536
     * bin with at least this many nodes. The value must be greater
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   537
     * than 2, and should be at least 8 to mesh with assumptions in
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   538
     * tree removal about conversion back to plain bins upon
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   539
     * shrinkage.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     */
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   541
    static final int TREEIFY_THRESHOLD = 8;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   542
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   543
    /**
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   544
     * The bin count threshold for untreeifying a (split) bin during a
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   545
     * resize operation. Should be less than TREEIFY_THRESHOLD, and at
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   546
     * most 6 to mesh with shrinkage detection under removal.
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   547
     */
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   548
    static final int UNTREEIFY_THRESHOLD = 6;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   549
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   550
    /**
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   551
     * The smallest table capacity for which bins may be treeified.
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   552
     * (Otherwise the table is resized if too many nodes in a bin.)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   553
     * The value should be at least 4 * TREEIFY_THRESHOLD to avoid
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   554
     * conflicts between resizing and treeification thresholds.
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   555
     */
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   556
    static final int MIN_TREEIFY_CAPACITY = 64;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
    /**
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   559
     * Minimum number of rebinnings per transfer step. Ranges are
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   560
     * subdivided to allow multiple resizer threads.  This value
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   561
     * serves as a lower bound to avoid resizers encountering
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   562
     * excessive memory contention.  The value should be at least
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   563
     * DEFAULT_CAPACITY.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   564
     */
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   565
    private static final int MIN_TRANSFER_STRIDE = 16;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   566
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   567
    /*
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   568
     * Encodings for Node hash fields. See above for explanation.
9279
5f5d493d30a0 7036559: ConcurrentHashMap footprint and contention improvements
dl
parents: 9242
diff changeset
   569
     */
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   570
    static final int MOVED     = -1; // hash for forwarding nodes
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   571
    static final int TREEBIN   = -2; // hash for roots of trees
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   572
    static final int RESERVED  = -3; // hash for transient reservations
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   573
    static final int HASH_BITS = 0x7fffffff; // usable bits of normal node hash
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   574
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   575
    /** Number of CPUS, to place bounds on some sizings */
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   576
    static final int NCPU = Runtime.getRuntime().availableProcessors();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   577
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   578
    /** For serialization compatibility. */
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   579
    private static final ObjectStreamField[] serialPersistentFields = {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   580
        new ObjectStreamField("segments", Segment[].class),
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   581
        new ObjectStreamField("segmentMask", Integer.TYPE),
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   582
        new ObjectStreamField("segmentShift", Integer.TYPE)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   583
    };
9279
5f5d493d30a0 7036559: ConcurrentHashMap footprint and contention improvements
dl
parents: 9242
diff changeset
   584
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   585
    /* ---------------- Nodes -------------- */
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   586
9279
5f5d493d30a0 7036559: ConcurrentHashMap footprint and contention improvements
dl
parents: 9242
diff changeset
   587
    /**
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   588
     * Key-value entry.  This class is never exported out as a
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   589
     * user-mutable Map.Entry (i.e., one supporting setValue; see
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   590
     * MapEntry below), but can be used for read-only traversals used
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   591
     * in bulk tasks.  Subclasses of Node with a negative hash field
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   592
     * are special, and contain null keys and values (but are never
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   593
     * exported).  Otherwise, keys and vals are never null.
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   594
     */
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   595
    static class Node<K,V> implements Map.Entry<K,V> {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   596
        final int hash;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   597
        final K key;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   598
        volatile V val;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   599
        volatile Node<K,V> next;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   600
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   601
        Node(int hash, K key, V val, Node<K,V> next) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   602
            this.hash = hash;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   603
            this.key = key;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   604
            this.val = val;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   605
            this.next = next;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   606
        }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   607
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   608
        public final K getKey()       { return key; }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   609
        public final V getValue()     { return val; }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   610
        public final int hashCode()   { return key.hashCode() ^ val.hashCode(); }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   611
        public final String toString(){ return key + "=" + val; }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   612
        public final V setValue(V value) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   613
            throw new UnsupportedOperationException();
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   614
        }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   615
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   616
        public final boolean equals(Object o) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   617
            Object k, v, u; Map.Entry<?,?> e;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   618
            return ((o instanceof Map.Entry) &&
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   619
                    (k = (e = (Map.Entry<?,?>)o).getKey()) != null &&
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   620
                    (v = e.getValue()) != null &&
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   621
                    (k == key || k.equals(key)) &&
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   622
                    (v == (u = val) || v.equals(u)));
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   623
        }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   624
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   625
        /**
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   626
         * Virtualized support for map.get(); overridden in subclasses.
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   627
         */
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   628
        Node<K,V> find(int h, Object k) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   629
            Node<K,V> e = this;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   630
            if (k != null) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   631
                do {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   632
                    K ek;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   633
                    if (e.hash == h &&
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   634
                        ((ek = e.key) == k || (ek != null && k.equals(ek))))
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   635
                        return e;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   636
                } while ((e = e.next) != null);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   637
            }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   638
            return null;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   639
        }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   640
    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   641
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   642
    /* ---------------- Static utilities -------------- */
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   643
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   644
    /**
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   645
     * Spreads (XORs) higher bits of hash to lower and also forces top
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   646
     * bit to 0. Because the table uses power-of-two masking, sets of
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   647
     * hashes that vary only in bits above the current mask will
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   648
     * always collide. (Among known examples are sets of Float keys
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   649
     * holding consecutive whole numbers in small tables.)  So we
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   650
     * apply a transform that spreads the impact of higher bits
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   651
     * downward. There is a tradeoff between speed, utility, and
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   652
     * quality of bit-spreading. Because many common sets of hashes
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   653
     * are already reasonably distributed (so don't benefit from
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   654
     * spreading), and because we use trees to handle large sets of
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   655
     * collisions in bins, we just XOR some shifted bits in the
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   656
     * cheapest possible way to reduce systematic lossage, as well as
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   657
     * to incorporate impact of the highest bits that would otherwise
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   658
     * never be used in index calculations because of table bounds.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     */
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   660
    static final int spread(int h) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   661
        return (h ^ (h >>> 16)) & HASH_BITS;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   662
    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   663
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   664
    /**
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   665
     * Returns a power of two table size for the given desired capacity.
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   666
     * See Hackers Delight, sec 3.2
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   667
     */
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   668
    private static final int tableSizeFor(int c) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   669
        int n = c - 1;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   670
        n |= n >>> 1;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   671
        n |= n >>> 2;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   672
        n |= n >>> 4;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   673
        n |= n >>> 8;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   674
        n |= n >>> 16;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   675
        return (n < 0) ? 1 : (n >= MAXIMUM_CAPACITY) ? MAXIMUM_CAPACITY : n + 1;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   676
    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   677
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   678
    /**
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   679
     * Returns x's Class if it is of the form "class C implements
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   680
     * Comparable<C>", else null.
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   681
     */
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   682
    static Class<?> comparableClassFor(Object x) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   683
        if (x instanceof Comparable) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   684
            Class<?> c; Type[] ts, as; Type t; ParameterizedType p;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   685
            if ((c = x.getClass()) == String.class) // bypass checks
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   686
                return c;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   687
            if ((ts = c.getGenericInterfaces()) != null) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   688
                for (int i = 0; i < ts.length; ++i) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   689
                    if (((t = ts[i]) instanceof ParameterizedType) &&
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   690
                        ((p = (ParameterizedType)t).getRawType() ==
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   691
                         Comparable.class) &&
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   692
                        (as = p.getActualTypeArguments()) != null &&
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   693
                        as.length == 1 && as[0] == c) // type arg is c
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   694
                        return c;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   695
                }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   696
            }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   697
        }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   698
        return null;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   699
    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   700
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   701
    /**
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   702
     * Returns k.compareTo(x) if x matches kc (k's screened comparable
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   703
     * class), else 0.
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   704
     */
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   705
    @SuppressWarnings({"rawtypes","unchecked"}) // for cast to Comparable
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   706
    static int compareComparables(Class<?> kc, Object k, Object x) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   707
        return (x == null || x.getClass() != kc ? 0 :
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   708
                ((Comparable)k).compareTo(x));
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   709
    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   710
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   711
    /* ---------------- Table element access -------------- */
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   712
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   713
    /*
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   714
     * Volatile access methods are used for table elements as well as
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   715
     * elements of in-progress next table while resizing.  All uses of
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   716
     * the tab arguments must be null checked by callers.  All callers
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   717
     * also paranoically precheck that tab's length is not zero (or an
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   718
     * equivalent check), thus ensuring that any index argument taking
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   719
     * the form of a hash value anded with (length - 1) is a valid
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   720
     * index.  Note that, to be correct wrt arbitrary concurrency
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   721
     * errors by users, these checks must operate on local variables,
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   722
     * which accounts for some odd-looking inline assignments below.
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   723
     * Note that calls to setTabAt always occur within locked regions,
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   724
     * and so in principle require only release ordering, not need
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   725
     * full volatile semantics, but are currently coded as volatile
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   726
     * writes to be conservative.
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   727
     */
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   728
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   729
    @SuppressWarnings("unchecked")
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   730
    static final <K,V> Node<K,V> tabAt(Node<K,V>[] tab, int i) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   731
        return (Node<K,V>)U.getObjectVolatile(tab, ((long)i << ASHIFT) + ABASE);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   732
    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   733
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   734
    static final <K,V> boolean casTabAt(Node<K,V>[] tab, int i,
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   735
                                        Node<K,V> c, Node<K,V> v) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   736
        return U.compareAndSwapObject(tab, ((long)i << ASHIFT) + ABASE, c, v);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   737
    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   738
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   739
    static final <K,V> void setTabAt(Node<K,V>[] tab, int i, Node<K,V> v) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   740
        U.putObjectVolatile(tab, ((long)i << ASHIFT) + ABASE, v);
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   741
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
    /* ---------------- Fields -------------- */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
    /**
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   746
     * The array of bins. Lazily initialized upon first insertion.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   747
     * Size is always a power of two. Accessed directly by iterators.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   748
     */
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   749
    transient volatile Node<K,V>[] table;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   750
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   751
    /**
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   752
     * The next table to use; non-null only while resizing.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   753
     */
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   754
    private transient volatile Node<K,V>[] nextTable;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   755
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   756
    /**
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   757
     * Base counter value, used mainly when there is no contention,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   758
     * but also as a fallback during table initialization
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   759
     * races. Updated via CAS.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   760
     */
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   761
    private transient volatile long baseCount;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   762
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   763
    /**
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   764
     * Table initialization and resizing control.  When negative, the
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   765
     * table is being initialized or resized: -1 for initialization,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   766
     * else -(1 + the number of active resizing threads).  Otherwise,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   767
     * when table is null, holds the initial table size to use upon
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   768
     * creation, or 0 for default. After initialization, holds the
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   769
     * next element count value upon which to resize the table.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   770
     */
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   771
    private transient volatile int sizeCtl;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   772
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   773
    /**
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   774
     * The next table index (plus one) to split while resizing.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   775
     */
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   776
    private transient volatile int transferIndex;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   777
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   778
    /**
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   779
     * The least available table index to split while resizing.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   780
     */
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   781
    private transient volatile int transferOrigin;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   782
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   783
    /**
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   784
     * Spinlock (locked via CAS) used when resizing and/or creating CounterCells.
12859
c44b88bb9b5e 7126277: Alternative String hashing implementation
mduigou
parents: 11279
diff changeset
   785
     */
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   786
    private transient volatile int cellsBusy;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   787
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   788
    /**
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   789
     * Table of counter cells. When non-null, size is a power of 2.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   790
     */
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   791
    private transient volatile CounterCell[] counterCells;
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   792
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   793
    // views
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   794
    private transient KeySetView<K,V> keySet;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   795
    private transient ValuesView<K,V> values;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   796
    private transient EntrySetView<K,V> entrySet;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   797
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   798
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   799
    /* ---------------- Public operations -------------- */
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   800
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   801
    /**
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   802
     * Creates a new, empty map with the default initial table size (16).
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   803
     */
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   804
    public ConcurrentHashMap() {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   805
    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   806
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   807
    /**
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   808
     * Creates a new, empty map with an initial table size
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   809
     * accommodating the specified number of elements without the need
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   810
     * to dynamically resize.
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   811
     *
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   812
     * @param initialCapacity The implementation performs internal
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   813
     * sizing to accommodate this many elements.
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   814
     * @throws IllegalArgumentException if the initial capacity of
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   815
     * elements is negative
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   816
     */
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   817
    public ConcurrentHashMap(int initialCapacity) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   818
        if (initialCapacity < 0)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   819
            throw new IllegalArgumentException();
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   820
        int cap = ((initialCapacity >= (MAXIMUM_CAPACITY >>> 1)) ?
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   821
                   MAXIMUM_CAPACITY :
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   822
                   tableSizeFor(initialCapacity + (initialCapacity >>> 1) + 1));
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   823
        this.sizeCtl = cap;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   824
    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   825
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   826
    /**
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   827
     * Creates a new map with the same mappings as the given map.
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   828
     *
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   829
     * @param m the map
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   830
     */
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   831
    public ConcurrentHashMap(Map<? extends K, ? extends V> m) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   832
        this.sizeCtl = DEFAULT_CAPACITY;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   833
        putAll(m);
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   834
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   835
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   836
    /**
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   837
     * Creates a new, empty map with an initial table size based on
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   838
     * the given number of elements ({@code initialCapacity}) and
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   839
     * initial table density ({@code loadFactor}).
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   840
     *
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   841
     * @param initialCapacity the initial capacity. The implementation
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   842
     * performs internal sizing to accommodate this many elements,
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   843
     * given the specified load factor.
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   844
     * @param loadFactor the load factor (table density) for
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   845
     * establishing the initial table size
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   846
     * @throws IllegalArgumentException if the initial capacity of
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   847
     * elements is negative or the load factor is nonpositive
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   848
     *
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   849
     * @since 1.6
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   850
     */
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   851
    public ConcurrentHashMap(int initialCapacity, float loadFactor) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   852
        this(initialCapacity, loadFactor, 1);
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   853
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   854
12859
c44b88bb9b5e 7126277: Alternative String hashing implementation
mduigou
parents: 11279
diff changeset
   855
    /**
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   856
     * Creates a new, empty map with an initial table size based on
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   857
     * the given number of elements ({@code initialCapacity}), table
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   858
     * density ({@code loadFactor}), and number of concurrently
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   859
     * updating threads ({@code concurrencyLevel}).
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   860
     *
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   861
     * @param initialCapacity the initial capacity. The implementation
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   862
     * performs internal sizing to accommodate this many elements,
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   863
     * given the specified load factor.
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   864
     * @param loadFactor the load factor (table density) for
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   865
     * establishing the initial table size
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   866
     * @param concurrencyLevel the estimated number of concurrently
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   867
     * updating threads. The implementation may use this value as
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   868
     * a sizing hint.
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   869
     * @throws IllegalArgumentException if the initial capacity is
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   870
     * negative or the load factor or concurrencyLevel are
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   871
     * nonpositive
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   872
     */
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   873
    public ConcurrentHashMap(int initialCapacity,
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   874
                             float loadFactor, int concurrencyLevel) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   875
        if (!(loadFactor > 0.0f) || initialCapacity < 0 || concurrencyLevel <= 0)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   876
            throw new IllegalArgumentException();
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   877
        if (initialCapacity < concurrencyLevel)   // Use at least as many bins
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   878
            initialCapacity = concurrencyLevel;   // as estimated threads
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   879
        long size = (long)(1.0 + (long)initialCapacity / loadFactor);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   880
        int cap = (size >= (long)MAXIMUM_CAPACITY) ?
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   881
            MAXIMUM_CAPACITY : tableSizeFor((int)size);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   882
        this.sizeCtl = cap;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   883
    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   884
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   885
    // Original (since JDK1.2) Map methods
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   886
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   887
    /**
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   888
     * {@inheritDoc}
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   889
     */
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   890
    public int size() {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   891
        long n = sumCount();
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   892
        return ((n < 0L) ? 0 :
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   893
                (n > (long)Integer.MAX_VALUE) ? Integer.MAX_VALUE :
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   894
                (int)n);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   895
    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   896
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   897
    /**
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   898
     * {@inheritDoc}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
     */
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   900
    public boolean isEmpty() {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   901
        return sumCount() <= 0L; // ignore transient negative values
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   902
    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   903
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   904
    /**
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   905
     * Returns the value to which the specified key is mapped,
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   906
     * or {@code null} if this map contains no mapping for the key.
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   907
     *
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   908
     * <p>More formally, if this map contains a mapping from a key
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   909
     * {@code k} to a value {@code v} such that {@code key.equals(k)},
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   910
     * then this method returns {@code v}; otherwise it returns
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   911
     * {@code null}.  (There can be at most one such mapping.)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   912
     *
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   913
     * @throws NullPointerException if the specified key is null
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   914
     */
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   915
    public V get(Object key) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   916
        Node<K,V>[] tab; Node<K,V> e, p; int n, eh; K ek;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   917
        int h = spread(key.hashCode());
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   918
        if ((tab = table) != null && (n = tab.length) > 0 &&
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   919
            (e = tabAt(tab, (n - 1) & h)) != null) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   920
            if ((eh = e.hash) == h) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   921
                if ((ek = e.key) == key || (ek != null && key.equals(ek)))
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   922
                    return e.val;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   923
            }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   924
            else if (eh < 0)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   925
                return (p = e.find(h, key)) != null ? p.val : null;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   926
            while ((e = e.next) != null) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   927
                if (e.hash == h &&
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   928
                    ((ek = e.key) == key || (ek != null && key.equals(ek))))
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   929
                    return e.val;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   930
            }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   931
        }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   932
        return null;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   933
    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   934
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   935
    /**
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   936
     * Tests if the specified object is a key in this table.
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   937
     *
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   938
     * @param  key possible key
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   939
     * @return {@code true} if and only if the specified object
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   940
     *         is a key in this table, as determined by the
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   941
     *         {@code equals} method; {@code false} otherwise
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   942
     * @throws NullPointerException if the specified key is null
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   943
     */
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   944
    public boolean containsKey(Object key) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   945
        return get(key) != null;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   946
    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   947
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   948
    /**
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   949
     * Returns {@code true} if this map maps one or more keys to the
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   950
     * specified value. Note: This method may require a full traversal
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   951
     * of the map, and is much slower than method {@code containsKey}.
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   952
     *
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   953
     * @param value value whose presence in this map is to be tested
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   954
     * @return {@code true} if this map maps one or more keys to the
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   955
     *         specified value
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   956
     * @throws NullPointerException if the specified value is null
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   957
     */
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   958
    public boolean containsValue(Object value) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   959
        if (value == null)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   960
            throw new NullPointerException();
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   961
        Node<K,V>[] t;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   962
        if ((t = table) != null) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   963
            Traverser<K,V> it = new Traverser<K,V>(t, t.length, 0, t.length);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   964
            for (Node<K,V> p; (p = it.advance()) != null; ) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   965
                V v;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   966
                if ((v = p.val) == value || (v != null && value.equals(v)))
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   967
                    return true;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   968
            }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   969
        }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   970
        return false;
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   971
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
    /**
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   974
     * Maps the specified key to the specified value in this table.
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   975
     * Neither the key nor the value can be null.
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   976
     *
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   977
     * <p>The value can be retrieved by calling the {@code get} method
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   978
     * with a key that is equal to the original key.
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   979
     *
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   980
     * @param key key with which the specified value is to be associated
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   981
     * @param value value to be associated with the specified key
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   982
     * @return the previous value associated with {@code key}, or
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   983
     *         {@code null} if there was no mapping for {@code key}
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   984
     * @throws NullPointerException if the specified key or value is null
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
     */
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   986
    public V put(K key, V value) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   987
        return putVal(key, value, false);
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   988
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
   989
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   990
    /** Implementation for put and putIfAbsent */
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   991
    final V putVal(K key, V value, boolean onlyIfAbsent) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   992
        if (key == null || value == null) throw new NullPointerException();
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   993
        int hash = spread(key.hashCode());
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   994
        int binCount = 0;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   995
        for (Node<K,V>[] tab = table;;) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   996
            Node<K,V> f; int n, i, fh;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   997
            if (tab == null || (n = tab.length) == 0)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   998
                tab = initTable();
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
   999
            else if ((f = tabAt(tab, i = (n - 1) & hash)) == null) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1000
                if (casTabAt(tab, i, null,
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1001
                             new Node<K,V>(hash, key, value, null)))
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1002
                    break;                   // no lock when adding to empty bin
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1003
            }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1004
            else if ((fh = f.hash) == MOVED)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1005
                tab = helpTransfer(tab, f);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1006
            else {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1007
                V oldVal = null;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1008
                synchronized (f) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1009
                    if (tabAt(tab, i) == f) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1010
                        if (fh >= 0) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1011
                            binCount = 1;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1012
                            for (Node<K,V> e = f;; ++binCount) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1013
                                K ek;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1014
                                if (e.hash == hash &&
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1015
                                    ((ek = e.key) == key ||
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1016
                                     (ek != null && key.equals(ek)))) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1017
                                    oldVal = e.val;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1018
                                    if (!onlyIfAbsent)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1019
                                        e.val = value;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1020
                                    break;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1021
                                }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1022
                                Node<K,V> pred = e;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1023
                                if ((e = e.next) == null) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1024
                                    pred.next = new Node<K,V>(hash, key,
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1025
                                                              value, null);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1026
                                    break;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1027
                                }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1028
                            }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1029
                        }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1030
                        else if (f instanceof TreeBin) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1031
                            Node<K,V> p;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1032
                            binCount = 2;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1033
                            if ((p = ((TreeBin<K,V>)f).putTreeVal(hash, key,
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1034
                                                           value)) != null) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1035
                                oldVal = p.val;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1036
                                if (!onlyIfAbsent)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1037
                                    p.val = value;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1038
                            }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1039
                        }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1040
                    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1041
                }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1042
                if (binCount != 0) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1043
                    if (binCount >= TREEIFY_THRESHOLD)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1044
                        treeifyBin(tab, i);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1045
                    if (oldVal != null)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1046
                        return oldVal;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1047
                    break;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1048
                }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1049
            }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1050
        }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1051
        addCount(1L, binCount);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1052
        return null;
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1053
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1054
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1055
    /**
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1056
     * Copies all of the mappings from the specified map to this one.
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1057
     * These mappings replace any mappings that this map had for any of the
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1058
     * keys currently in the specified map.
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1059
     *
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1060
     * @param m mappings to be stored in this map
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1061
     */
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1062
    public void putAll(Map<? extends K, ? extends V> m) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1063
        tryPresize(m.size());
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1064
        for (Map.Entry<? extends K, ? extends V> e : m.entrySet())
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1065
            putVal(e.getKey(), e.getValue(), false);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1066
    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1067
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1068
    /**
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1069
     * Removes the key (and its corresponding value) from this map.
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1070
     * This method does nothing if the key is not in the map.
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1071
     *
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1072
     * @param  key the key that needs to be removed
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1073
     * @return the previous value associated with {@code key}, or
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1074
     *         {@code null} if there was no mapping for {@code key}
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1075
     * @throws NullPointerException if the specified key is null
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1076
     */
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1077
    public V remove(Object key) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1078
        return replaceNode(key, null, null);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1079
    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1080
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1081
    /**
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1082
     * Implementation for the four public remove/replace methods:
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1083
     * Replaces node value with v, conditional upon match of cv if
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1084
     * non-null.  If resulting value is null, delete.
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1085
     */
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1086
    final V replaceNode(Object key, V value, Object cv) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1087
        int hash = spread(key.hashCode());
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1088
        for (Node<K,V>[] tab = table;;) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1089
            Node<K,V> f; int n, i, fh;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1090
            if (tab == null || (n = tab.length) == 0 ||
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1091
                (f = tabAt(tab, i = (n - 1) & hash)) == null)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1092
                break;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1093
            else if ((fh = f.hash) == MOVED)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1094
                tab = helpTransfer(tab, f);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1095
            else {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1096
                V oldVal = null;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1097
                boolean validated = false;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1098
                synchronized (f) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1099
                    if (tabAt(tab, i) == f) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1100
                        if (fh >= 0) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1101
                            validated = true;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1102
                            for (Node<K,V> e = f, pred = null;;) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1103
                                K ek;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1104
                                if (e.hash == hash &&
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1105
                                    ((ek = e.key) == key ||
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1106
                                     (ek != null && key.equals(ek)))) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1107
                                    V ev = e.val;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1108
                                    if (cv == null || cv == ev ||
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1109
                                        (ev != null && cv.equals(ev))) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1110
                                        oldVal = ev;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1111
                                        if (value != null)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1112
                                            e.val = value;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1113
                                        else if (pred != null)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1114
                                            pred.next = e.next;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1115
                                        else
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1116
                                            setTabAt(tab, i, e.next);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1117
                                    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1118
                                    break;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1119
                                }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1120
                                pred = e;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1121
                                if ((e = e.next) == null)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1122
                                    break;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1123
                            }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1124
                        }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1125
                        else if (f instanceof TreeBin) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1126
                            validated = true;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1127
                            TreeBin<K,V> t = (TreeBin<K,V>)f;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1128
                            TreeNode<K,V> r, p;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1129
                            if ((r = t.root) != null &&
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1130
                                (p = r.findTreeNode(hash, key, null)) != null) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1131
                                V pv = p.val;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1132
                                if (cv == null || cv == pv ||
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1133
                                    (pv != null && cv.equals(pv))) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1134
                                    oldVal = pv;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1135
                                    if (value != null)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1136
                                        p.val = value;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1137
                                    else if (t.removeTreeNode(p))
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1138
                                        setTabAt(tab, i, untreeify(t.first));
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1139
                                }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1140
                            }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1141
                        }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1142
                    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1143
                }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1144
                if (validated) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1145
                    if (oldVal != null) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1146
                        if (value == null)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1147
                            addCount(-1L, -1);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1148
                        return oldVal;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1149
                    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1150
                    break;
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1151
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1152
            }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1153
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1154
        return null;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1155
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
    /**
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1158
     * Removes all of the mappings from this map.
9279
5f5d493d30a0 7036559: ConcurrentHashMap footprint and contention improvements
dl
parents: 9242
diff changeset
  1159
     */
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1160
    public void clear() {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1161
        long delta = 0L; // negative number of deletions
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1162
        int i = 0;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1163
        Node<K,V>[] tab = table;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1164
        while (tab != null && i < tab.length) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1165
            int fh;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1166
            Node<K,V> f = tabAt(tab, i);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1167
            if (f == null)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1168
                ++i;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1169
            else if ((fh = f.hash) == MOVED) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1170
                tab = helpTransfer(tab, f);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1171
                i = 0; // restart
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1172
            }
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1173
            else {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1174
                synchronized (f) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1175
                    if (tabAt(tab, i) == f) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1176
                        Node<K,V> p = (fh >= 0 ? f :
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1177
                                       (f instanceof TreeBin) ?
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1178
                                       ((TreeBin<K,V>)f).first : null);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1179
                        while (p != null) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1180
                            --delta;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1181
                            p = p.next;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1182
                        }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1183
                        setTabAt(tab, i++, null);
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1184
                    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1185
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1186
            }
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1187
        }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1188
        if (delta != 0L)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1189
            addCount(delta, -1);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1190
    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1191
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1192
    /**
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1193
     * Returns a {@link Set} view of the keys contained in this map.
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1194
     * The set is backed by the map, so changes to the map are
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1195
     * reflected in the set, and vice-versa. The set supports element
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1196
     * removal, which removes the corresponding mapping from this map,
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1197
     * via the {@code Iterator.remove}, {@code Set.remove},
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1198
     * {@code removeAll}, {@code retainAll}, and {@code clear}
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1199
     * operations.  It does not support the {@code add} or
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1200
     * {@code addAll} operations.
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1201
     *
19428
83f87aff7b07 8022318: Document Spliterator characteristics and binding policy of java util concurrent collection impls
psandoz
parents: 19413
diff changeset
  1202
     * <p>The view's iterators and spliterators are
83f87aff7b07 8022318: Document Spliterator characteristics and binding policy of java util concurrent collection impls
psandoz
parents: 19413
diff changeset
  1203
     * <a href="package-summary.html#Weakly"><i>weakly consistent</i></a>.
83f87aff7b07 8022318: Document Spliterator characteristics and binding policy of java util concurrent collection impls
psandoz
parents: 19413
diff changeset
  1204
     *
83f87aff7b07 8022318: Document Spliterator characteristics and binding policy of java util concurrent collection impls
psandoz
parents: 19413
diff changeset
  1205
     * <p>The view's {@code spliterator} reports {@link Spliterator#CONCURRENT},
83f87aff7b07 8022318: Document Spliterator characteristics and binding policy of java util concurrent collection impls
psandoz
parents: 19413
diff changeset
  1206
     * {@link Spliterator#DISTINCT}, and {@link Spliterator#NONNULL}.
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1207
     *
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1208
     * @return the set view
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1209
     */
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1210
    public KeySetView<K,V> keySet() {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1211
        KeySetView<K,V> ks;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1212
        return (ks = keySet) != null ? ks : (keySet = new KeySetView<K,V>(this, null));
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1213
    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1214
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1215
    /**
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1216
     * Returns a {@link Collection} view of the values contained in this map.
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1217
     * The collection is backed by the map, so changes to the map are
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1218
     * reflected in the collection, and vice-versa.  The collection
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1219
     * supports element removal, which removes the corresponding
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1220
     * mapping from this map, via the {@code Iterator.remove},
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1221
     * {@code Collection.remove}, {@code removeAll},
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1222
     * {@code retainAll}, and {@code clear} operations.  It does not
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1223
     * support the {@code add} or {@code addAll} operations.
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1224
     *
19428
83f87aff7b07 8022318: Document Spliterator characteristics and binding policy of java util concurrent collection impls
psandoz
parents: 19413
diff changeset
  1225
     * <p>The view's iterators and spliterators are
83f87aff7b07 8022318: Document Spliterator characteristics and binding policy of java util concurrent collection impls
psandoz
parents: 19413
diff changeset
  1226
     * <a href="package-summary.html#Weakly"><i>weakly consistent</i></a>.
83f87aff7b07 8022318: Document Spliterator characteristics and binding policy of java util concurrent collection impls
psandoz
parents: 19413
diff changeset
  1227
     *
83f87aff7b07 8022318: Document Spliterator characteristics and binding policy of java util concurrent collection impls
psandoz
parents: 19413
diff changeset
  1228
     * <p>The view's {@code spliterator} reports {@link Spliterator#CONCURRENT}
83f87aff7b07 8022318: Document Spliterator characteristics and binding policy of java util concurrent collection impls
psandoz
parents: 19413
diff changeset
  1229
     * and {@link Spliterator#NONNULL}.
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1230
     *
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1231
     * @return the collection view
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1232
     */
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1233
    public Collection<V> values() {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1234
        ValuesView<K,V> vs;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1235
        return (vs = values) != null ? vs : (values = new ValuesView<K,V>(this));
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1236
    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1237
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1238
    /**
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1239
     * Returns a {@link Set} view of the mappings contained in this map.
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1240
     * The set is backed by the map, so changes to the map are
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1241
     * reflected in the set, and vice-versa.  The set supports element
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1242
     * removal, which removes the corresponding mapping from the map,
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1243
     * via the {@code Iterator.remove}, {@code Set.remove},
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1244
     * {@code removeAll}, {@code retainAll}, and {@code clear}
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1245
     * operations.
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1246
     *
19428
83f87aff7b07 8022318: Document Spliterator characteristics and binding policy of java util concurrent collection impls
psandoz
parents: 19413
diff changeset
  1247
     * <p>The view's iterators and spliterators are
83f87aff7b07 8022318: Document Spliterator characteristics and binding policy of java util concurrent collection impls
psandoz
parents: 19413
diff changeset
  1248
     * <a href="package-summary.html#Weakly"><i>weakly consistent</i></a>.
83f87aff7b07 8022318: Document Spliterator characteristics and binding policy of java util concurrent collection impls
psandoz
parents: 19413
diff changeset
  1249
     *
83f87aff7b07 8022318: Document Spliterator characteristics and binding policy of java util concurrent collection impls
psandoz
parents: 19413
diff changeset
  1250
     * <p>The view's {@code spliterator} reports {@link Spliterator#CONCURRENT},
83f87aff7b07 8022318: Document Spliterator characteristics and binding policy of java util concurrent collection impls
psandoz
parents: 19413
diff changeset
  1251
     * {@link Spliterator#DISTINCT}, and {@link Spliterator#NONNULL}.
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1252
     *
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1253
     * @return the set view
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1254
     */
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1255
    public Set<Map.Entry<K,V>> entrySet() {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1256
        EntrySetView<K,V> es;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1257
        return (es = entrySet) != null ? es : (entrySet = new EntrySetView<K,V>(this));
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1258
    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1259
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1260
    /**
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1261
     * Returns the hash code value for this {@link Map}, i.e.,
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1262
     * the sum of, for each key-value pair in the map,
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1263
     * {@code key.hashCode() ^ value.hashCode()}.
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1264
     *
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1265
     * @return the hash code value for this map
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1266
     */
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1267
    public int hashCode() {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1268
        int h = 0;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1269
        Node<K,V>[] t;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1270
        if ((t = table) != null) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1271
            Traverser<K,V> it = new Traverser<K,V>(t, t.length, 0, t.length);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1272
            for (Node<K,V> p; (p = it.advance()) != null; )
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1273
                h += p.key.hashCode() ^ p.val.hashCode();
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1274
        }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1275
        return h;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1276
    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1277
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1278
    /**
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1279
     * Returns a string representation of this map.  The string
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1280
     * representation consists of a list of key-value mappings (in no
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1281
     * particular order) enclosed in braces ("{@code {}}").  Adjacent
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1282
     * mappings are separated by the characters {@code ", "} (comma
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1283
     * and space).  Each key-value mapping is rendered as the key
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1284
     * followed by an equals sign ("{@code =}") followed by the
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1285
     * associated value.
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1286
     *
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1287
     * @return a string representation of this map
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1288
     */
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1289
    public String toString() {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1290
        Node<K,V>[] t;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1291
        int f = (t = table) == null ? 0 : t.length;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1292
        Traverser<K,V> it = new Traverser<K,V>(t, f, 0, f);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1293
        StringBuilder sb = new StringBuilder();
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1294
        sb.append('{');
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1295
        Node<K,V> p;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1296
        if ((p = it.advance()) != null) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1297
            for (;;) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1298
                K k = p.key;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1299
                V v = p.val;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1300
                sb.append(k == this ? "(this Map)" : k);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1301
                sb.append('=');
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1302
                sb.append(v == this ? "(this Map)" : v);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1303
                if ((p = it.advance()) == null)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1304
                    break;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1305
                sb.append(',').append(' ');
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1306
            }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1307
        }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1308
        return sb.append('}').toString();
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1309
    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1310
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1311
    /**
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1312
     * Compares the specified object with this map for equality.
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1313
     * Returns {@code true} if the given object is a map with the same
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1314
     * mappings as this map.  This operation may return misleading
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1315
     * results if either map is concurrently modified during execution
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1316
     * of this method.
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1317
     *
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1318
     * @param o object to be compared for equality with this map
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1319
     * @return {@code true} if the specified object is equal to this map
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1320
     */
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1321
    public boolean equals(Object o) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1322
        if (o != this) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1323
            if (!(o instanceof Map))
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1324
                return false;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1325
            Map<?,?> m = (Map<?,?>) o;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1326
            Node<K,V>[] t;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1327
            int f = (t = table) == null ? 0 : t.length;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1328
            Traverser<K,V> it = new Traverser<K,V>(t, f, 0, f);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1329
            for (Node<K,V> p; (p = it.advance()) != null; ) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1330
                V val = p.val;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1331
                Object v = m.get(p.key);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1332
                if (v == null || (v != val && !v.equals(val)))
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1333
                    return false;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1334
            }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1335
            for (Map.Entry<?,?> e : m.entrySet()) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1336
                Object mk, mv, v;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1337
                if ((mk = e.getKey()) == null ||
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1338
                    (mv = e.getValue()) == null ||
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1339
                    (v = get(mk)) == null ||
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1340
                    (mv != v && !mv.equals(v)))
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1341
                    return false;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1342
            }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1343
        }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1344
        return true;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1345
    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1346
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1347
    /**
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1348
     * Stripped-down version of helper class used in previous version,
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1349
     * declared for the sake of serialization compatibility
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1350
     */
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1351
    static class Segment<K,V> extends ReentrantLock implements Serializable {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1352
        private static final long serialVersionUID = 2249069246763182397L;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1353
        final float loadFactor;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1354
        Segment(float lf) { this.loadFactor = lf; }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1355
    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1356
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1357
    /**
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1358
     * Saves the state of the {@code ConcurrentHashMap} instance to a
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1359
     * stream (i.e., serializes it).
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1360
     * @param s the stream
19036
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
  1361
     * @throws java.io.IOException if an I/O error occurs
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1362
     * @serialData
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1363
     * the key (Object) and value (Object)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1364
     * for each key-value mapping, followed by a null pair.
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1365
     * The key-value mappings are emitted in no particular order.
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1366
     */
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1367
    private void writeObject(java.io.ObjectOutputStream s)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1368
        throws java.io.IOException {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1369
        // For serialization compatibility
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1370
        // Emulate segment calculation from previous version of this class
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1371
        int sshift = 0;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1372
        int ssize = 1;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1373
        while (ssize < DEFAULT_CONCURRENCY_LEVEL) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1374
            ++sshift;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1375
            ssize <<= 1;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1376
        }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1377
        int segmentShift = 32 - sshift;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1378
        int segmentMask = ssize - 1;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1379
        @SuppressWarnings("unchecked") Segment<K,V>[] segments = (Segment<K,V>[])
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1380
            new Segment<?,?>[DEFAULT_CONCURRENCY_LEVEL];
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1381
        for (int i = 0; i < segments.length; ++i)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1382
            segments[i] = new Segment<K,V>(LOAD_FACTOR);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1383
        s.putFields().put("segments", segments);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1384
        s.putFields().put("segmentShift", segmentShift);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1385
        s.putFields().put("segmentMask", segmentMask);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1386
        s.writeFields();
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1387
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1388
        Node<K,V>[] t;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1389
        if ((t = table) != null) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1390
            Traverser<K,V> it = new Traverser<K,V>(t, t.length, 0, t.length);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1391
            for (Node<K,V> p; (p = it.advance()) != null; ) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1392
                s.writeObject(p.key);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1393
                s.writeObject(p.val);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1394
            }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1395
        }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1396
        s.writeObject(null);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1397
        s.writeObject(null);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1398
        segments = null; // throw away
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1399
    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1400
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1401
    /**
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1402
     * Reconstitutes the instance from a stream (that is, deserializes it).
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1403
     * @param s the stream
19036
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
  1404
     * @throws ClassNotFoundException if the class of a serialized object
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
  1405
     *         could not be found
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
  1406
     * @throws java.io.IOException if an I/O error occurs
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1407
     */
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1408
    private void readObject(java.io.ObjectInputStream s)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1409
        throws java.io.IOException, ClassNotFoundException {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1410
        /*
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1411
         * To improve performance in typical cases, we create nodes
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1412
         * while reading, then place in table once size is known.
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1413
         * However, we must also validate uniqueness and deal with
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1414
         * overpopulated bins while doing so, which requires
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1415
         * specialized versions of putVal mechanics.
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1416
         */
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1417
        sizeCtl = -1; // force exclusion for table construction
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1418
        s.defaultReadObject();
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1419
        long size = 0L;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1420
        Node<K,V> p = null;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1421
        for (;;) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1422
            @SuppressWarnings("unchecked") K k = (K) s.readObject();
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1423
            @SuppressWarnings("unchecked") V v = (V) s.readObject();
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1424
            if (k != null && v != null) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1425
                p = new Node<K,V>(spread(k.hashCode()), k, v, p);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1426
                ++size;
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1427
            }
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1428
            else
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1429
                break;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1430
        }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1431
        if (size == 0L)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1432
            sizeCtl = 0;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1433
        else {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1434
            int n;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1435
            if (size >= (long)(MAXIMUM_CAPACITY >>> 1))
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1436
                n = MAXIMUM_CAPACITY;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1437
            else {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1438
                int sz = (int)size;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1439
                n = tableSizeFor(sz + (sz >>> 1) + 1);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1440
            }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1441
            @SuppressWarnings({"rawtypes","unchecked"})
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1442
                Node<K,V>[] tab = (Node<K,V>[])new Node[n];
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1443
            int mask = n - 1;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1444
            long added = 0L;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1445
            while (p != null) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1446
                boolean insertAtFront;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1447
                Node<K,V> next = p.next, first;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1448
                int h = p.hash, j = h & mask;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1449
                if ((first = tabAt(tab, j)) == null)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1450
                    insertAtFront = true;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1451
                else {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1452
                    K k = p.key;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1453
                    if (first.hash < 0) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1454
                        TreeBin<K,V> t = (TreeBin<K,V>)first;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1455
                        if (t.putTreeVal(h, k, p.val) == null)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1456
                            ++added;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1457
                        insertAtFront = false;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1458
                    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1459
                    else {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1460
                        int binCount = 0;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1461
                        insertAtFront = true;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1462
                        Node<K,V> q; K qk;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1463
                        for (q = first; q != null; q = q.next) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1464
                            if (q.hash == h &&
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1465
                                ((qk = q.key) == k ||
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1466
                                 (qk != null && k.equals(qk)))) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1467
                                insertAtFront = false;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1468
                                break;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1469
                            }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1470
                            ++binCount;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1471
                        }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1472
                        if (insertAtFront && binCount >= TREEIFY_THRESHOLD) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1473
                            insertAtFront = false;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1474
                            ++added;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1475
                            p.next = first;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1476
                            TreeNode<K,V> hd = null, tl = null;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1477
                            for (q = p; q != null; q = q.next) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1478
                                TreeNode<K,V> t = new TreeNode<K,V>
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1479
                                    (q.hash, q.key, q.val, null, null);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1480
                                if ((t.prev = tl) == null)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1481
                                    hd = t;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1482
                                else
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1483
                                    tl.next = t;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1484
                                tl = t;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1485
                            }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1486
                            setTabAt(tab, j, new TreeBin<K,V>(hd));
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1487
                        }
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1488
                    }
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1489
                }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1490
                if (insertAtFront) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1491
                    ++added;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1492
                    p.next = first;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1493
                    setTabAt(tab, j, p);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1494
                }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1495
                p = next;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1496
            }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1497
            table = tab;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1498
            sizeCtl = n - (n >>> 2);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1499
            baseCount = added;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1500
        }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1501
    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1502
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1503
    // ConcurrentMap methods
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1504
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1505
    /**
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1506
     * {@inheritDoc}
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1507
     *
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1508
     * @return the previous value associated with the specified key,
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1509
     *         or {@code null} if there was no mapping for the key
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1510
     * @throws NullPointerException if the specified key or value is null
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1511
     */
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1512
    public V putIfAbsent(K key, V value) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1513
        return putVal(key, value, true);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1514
    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1515
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1516
    /**
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1517
     * {@inheritDoc}
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1518
     *
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1519
     * @throws NullPointerException if the specified key is null
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1520
     */
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1521
    public boolean remove(Object key, Object value) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1522
        if (key == null)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1523
            throw new NullPointerException();
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1524
        return value != null && replaceNode(key, null, value) != null;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1525
    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1526
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1527
    /**
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1528
     * {@inheritDoc}
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1529
     *
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1530
     * @throws NullPointerException if any of the arguments are null
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1531
     */
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1532
    public boolean replace(K key, V oldValue, V newValue) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1533
        if (key == null || oldValue == null || newValue == null)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1534
            throw new NullPointerException();
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1535
        return replaceNode(key, newValue, oldValue) != null;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1536
    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1537
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1538
    /**
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1539
     * {@inheritDoc}
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1540
     *
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1541
     * @return the previous value associated with the specified key,
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1542
     *         or {@code null} if there was no mapping for the key
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1543
     * @throws NullPointerException if the specified key or value is null
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1544
     */
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1545
    public V replace(K key, V value) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1546
        if (key == null || value == null)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1547
            throw new NullPointerException();
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1548
        return replaceNode(key, value, null);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1549
    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1550
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1551
    // Overrides of JDK8+ Map extension method defaults
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1552
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1553
    /**
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1554
     * Returns the value to which the specified key is mapped, or the
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1555
     * given default value if this map contains no mapping for the
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1556
     * key.
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1557
     *
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1558
     * @param key the key whose associated value is to be returned
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1559
     * @param defaultValue the value to return if this map contains
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1560
     * no mapping for the given key
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1561
     * @return the mapping for the key, if present; else the default value
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1562
     * @throws NullPointerException if the specified key is null
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1563
     */
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1564
    public V getOrDefault(Object key, V defaultValue) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1565
        V v;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1566
        return (v = get(key)) == null ? defaultValue : v;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1567
    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1568
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1569
    public void forEach(BiConsumer<? super K, ? super V> action) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1570
        if (action == null) throw new NullPointerException();
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1571
        Node<K,V>[] t;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1572
        if ((t = table) != null) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1573
            Traverser<K,V> it = new Traverser<K,V>(t, t.length, 0, t.length);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1574
            for (Node<K,V> p; (p = it.advance()) != null; ) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1575
                action.accept(p.key, p.val);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1576
            }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1577
        }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1578
    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1579
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1580
    public void replaceAll(BiFunction<? super K, ? super V, ? extends V> function) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1581
        if (function == null) throw new NullPointerException();
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1582
        Node<K,V>[] t;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1583
        if ((t = table) != null) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1584
            Traverser<K,V> it = new Traverser<K,V>(t, t.length, 0, t.length);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1585
            for (Node<K,V> p; (p = it.advance()) != null; ) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1586
                V oldValue = p.val;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1587
                for (K key = p.key;;) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1588
                    V newValue = function.apply(key, oldValue);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1589
                    if (newValue == null)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1590
                        throw new NullPointerException();
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1591
                    if (replaceNode(key, newValue, oldValue) != null ||
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1592
                        (oldValue = get(key)) == null)
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1593
                        break;
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1594
                }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1595
            }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1596
        }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1597
    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1598
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1599
    /**
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1600
     * If the specified key is not already associated with a value,
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1601
     * attempts to compute its value using the given mapping function
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1602
     * and enters it into this map unless {@code null}.  The entire
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1603
     * method invocation is performed atomically, so the function is
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1604
     * applied at most once per key.  Some attempted update operations
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1605
     * on this map by other threads may be blocked while computation
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1606
     * is in progress, so the computation should be short and simple,
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1607
     * and must not attempt to update any other mappings of this map.
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1608
     *
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1609
     * @param key key with which the specified value is to be associated
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1610
     * @param mappingFunction the function to compute a value
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1611
     * @return the current (existing or computed) value associated with
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1612
     *         the specified key, or null if the computed value is null
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1613
     * @throws NullPointerException if the specified key or mappingFunction
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1614
     *         is null
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1615
     * @throws IllegalStateException if the computation detectably
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1616
     *         attempts a recursive update to this map that would
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1617
     *         otherwise never complete
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1618
     * @throws RuntimeException or Error if the mappingFunction does so,
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1619
     *         in which case the mapping is left unestablished
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1620
     */
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1621
    public V computeIfAbsent(K key, Function<? super K, ? extends V> mappingFunction) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1622
        if (key == null || mappingFunction == null)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1623
            throw new NullPointerException();
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1624
        int h = spread(key.hashCode());
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1625
        V val = null;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1626
        int binCount = 0;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1627
        for (Node<K,V>[] tab = table;;) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1628
            Node<K,V> f; int n, i, fh;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1629
            if (tab == null || (n = tab.length) == 0)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1630
                tab = initTable();
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1631
            else if ((f = tabAt(tab, i = (n - 1) & h)) == null) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1632
                Node<K,V> r = new ReservationNode<K,V>();
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1633
                synchronized (r) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1634
                    if (casTabAt(tab, i, null, r)) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1635
                        binCount = 1;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1636
                        Node<K,V> node = null;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1637
                        try {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1638
                            if ((val = mappingFunction.apply(key)) != null)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1639
                                node = new Node<K,V>(h, key, val, null);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1640
                        } finally {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1641
                            setTabAt(tab, i, node);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1642
                        }
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1643
                    }
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1644
                }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1645
                if (binCount != 0)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1646
                    break;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1647
            }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1648
            else if ((fh = f.hash) == MOVED)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1649
                tab = helpTransfer(tab, f);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1650
            else {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1651
                boolean added = false;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1652
                synchronized (f) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1653
                    if (tabAt(tab, i) == f) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1654
                        if (fh >= 0) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1655
                            binCount = 1;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1656
                            for (Node<K,V> e = f;; ++binCount) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1657
                                K ek; V ev;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1658
                                if (e.hash == h &&
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1659
                                    ((ek = e.key) == key ||
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1660
                                     (ek != null && key.equals(ek)))) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1661
                                    val = e.val;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1662
                                    break;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1663
                                }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1664
                                Node<K,V> pred = e;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1665
                                if ((e = e.next) == null) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1666
                                    if ((val = mappingFunction.apply(key)) != null) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1667
                                        added = true;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1668
                                        pred.next = new Node<K,V>(h, key, val, null);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1669
                                    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1670
                                    break;
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1671
                                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1672
                            }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1673
                        }
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1674
                        else if (f instanceof TreeBin) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1675
                            binCount = 2;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1676
                            TreeBin<K,V> t = (TreeBin<K,V>)f;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1677
                            TreeNode<K,V> r, p;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1678
                            if ((r = t.root) != null &&
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1679
                                (p = r.findTreeNode(h, key, null)) != null)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1680
                                val = p.val;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1681
                            else if ((val = mappingFunction.apply(key)) != null) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1682
                                added = true;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1683
                                t.putTreeVal(h, key, val);
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1684
                            }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1685
                        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1686
                    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1687
                }
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1688
                if (binCount != 0) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1689
                    if (binCount >= TREEIFY_THRESHOLD)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1690
                        treeifyBin(tab, i);
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1691
                    if (!added)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1692
                        return val;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1693
                    break;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1694
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1695
            }
9279
5f5d493d30a0 7036559: ConcurrentHashMap footprint and contention improvements
dl
parents: 9242
diff changeset
  1696
        }
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1697
        if (val != null)
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1698
            addCount(1L, binCount);
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1699
        return val;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1700
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1701
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1702
    /**
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1703
     * If the value for the specified key is present, attempts to
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1704
     * compute a new mapping given the key and its current mapped
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1705
     * value.  The entire method invocation is performed atomically.
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1706
     * Some attempted update operations on this map by other threads
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1707
     * may be blocked while computation is in progress, so the
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1708
     * computation should be short and simple, and must not attempt to
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1709
     * update any other mappings of this map.
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1710
     *
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1711
     * @param key key with which a value may be associated
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1712
     * @param remappingFunction the function to compute a value
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1713
     * @return the new value associated with the specified key, or null if none
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1714
     * @throws NullPointerException if the specified key or remappingFunction
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1715
     *         is null
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1716
     * @throws IllegalStateException if the computation detectably
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1717
     *         attempts a recursive update to this map that would
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1718
     *         otherwise never complete
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1719
     * @throws RuntimeException or Error if the remappingFunction does so,
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1720
     *         in which case the mapping is unchanged
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1721
     */
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1722
    public V computeIfPresent(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1723
        if (key == null || remappingFunction == null)
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1724
            throw new NullPointerException();
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1725
        int h = spread(key.hashCode());
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1726
        V val = null;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1727
        int delta = 0;
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1728
        int binCount = 0;
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1729
        for (Node<K,V>[] tab = table;;) {
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1730
            Node<K,V> f; int n, i, fh;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1731
            if (tab == null || (n = tab.length) == 0)
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1732
                tab = initTable();
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1733
            else if ((f = tabAt(tab, i = (n - 1) & h)) == null)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1734
                break;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1735
            else if ((fh = f.hash) == MOVED)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1736
                tab = helpTransfer(tab, f);
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1737
            else {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1738
                synchronized (f) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1739
                    if (tabAt(tab, i) == f) {
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1740
                        if (fh >= 0) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1741
                            binCount = 1;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1742
                            for (Node<K,V> e = f, pred = null;; ++binCount) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1743
                                K ek;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1744
                                if (e.hash == h &&
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1745
                                    ((ek = e.key) == key ||
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1746
                                     (ek != null && key.equals(ek)))) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1747
                                    val = remappingFunction.apply(key, e.val);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1748
                                    if (val != null)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1749
                                        e.val = val;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1750
                                    else {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1751
                                        delta = -1;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1752
                                        Node<K,V> en = e.next;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1753
                                        if (pred != null)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1754
                                            pred.next = en;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1755
                                        else
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1756
                                            setTabAt(tab, i, en);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1757
                                    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1758
                                    break;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1759
                                }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1760
                                pred = e;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1761
                                if ((e = e.next) == null)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1762
                                    break;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1763
                            }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1764
                        }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1765
                        else if (f instanceof TreeBin) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1766
                            binCount = 2;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1767
                            TreeBin<K,V> t = (TreeBin<K,V>)f;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1768
                            TreeNode<K,V> r, p;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1769
                            if ((r = t.root) != null &&
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1770
                                (p = r.findTreeNode(h, key, null)) != null) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1771
                                val = remappingFunction.apply(key, p.val);
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1772
                                if (val != null)
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1773
                                    p.val = val;
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1774
                                else {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1775
                                    delta = -1;
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1776
                                    if (t.removeTreeNode(p))
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1777
                                        setTabAt(tab, i, untreeify(t.first));
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1778
                                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1779
                            }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1780
                        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1781
                    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1782
                }
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1783
                if (binCount != 0)
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1784
                    break;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1785
            }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1786
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1787
        if (delta != 0)
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1788
            addCount((long)delta, binCount);
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1789
        return val;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1790
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1791
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1792
    /**
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1793
     * Attempts to compute a mapping for the specified key and its
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1794
     * current mapped value (or {@code null} if there is no current
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1795
     * mapping). The entire method invocation is performed atomically.
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1796
     * Some attempted update operations on this map by other threads
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1797
     * may be blocked while computation is in progress, so the
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1798
     * computation should be short and simple, and must not attempt to
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1799
     * update any other mappings of this Map.
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1800
     *
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1801
     * @param key key with which the specified value is to be associated
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1802
     * @param remappingFunction the function to compute a value
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1803
     * @return the new value associated with the specified key, or null if none
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1804
     * @throws NullPointerException if the specified key or remappingFunction
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1805
     *         is null
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1806
     * @throws IllegalStateException if the computation detectably
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1807
     *         attempts a recursive update to this map that would
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1808
     *         otherwise never complete
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1809
     * @throws RuntimeException or Error if the remappingFunction does so,
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1810
     *         in which case the mapping is unchanged
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1811
     */
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1812
    public V compute(K key,
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1813
                     BiFunction<? super K, ? super V, ? extends V> remappingFunction) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1814
        if (key == null || remappingFunction == null)
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1815
            throw new NullPointerException();
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1816
        int h = spread(key.hashCode());
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1817
        V val = null;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1818
        int delta = 0;
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1819
        int binCount = 0;
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1820
        for (Node<K,V>[] tab = table;;) {
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1821
            Node<K,V> f; int n, i, fh;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1822
            if (tab == null || (n = tab.length) == 0)
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1823
                tab = initTable();
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1824
            else if ((f = tabAt(tab, i = (n - 1) & h)) == null) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1825
                Node<K,V> r = new ReservationNode<K,V>();
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1826
                synchronized (r) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1827
                    if (casTabAt(tab, i, null, r)) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1828
                        binCount = 1;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1829
                        Node<K,V> node = null;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1830
                        try {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1831
                            if ((val = remappingFunction.apply(key, null)) != null) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1832
                                delta = 1;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1833
                                node = new Node<K,V>(h, key, val, null);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1834
                            }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1835
                        } finally {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1836
                            setTabAt(tab, i, node);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1837
                        }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1838
                    }
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1839
                }
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1840
                if (binCount != 0)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1841
                    break;
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1842
            }
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1843
            else if ((fh = f.hash) == MOVED)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1844
                tab = helpTransfer(tab, f);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1845
            else {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1846
                synchronized (f) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1847
                    if (tabAt(tab, i) == f) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1848
                        if (fh >= 0) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1849
                            binCount = 1;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1850
                            for (Node<K,V> e = f, pred = null;; ++binCount) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1851
                                K ek;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1852
                                if (e.hash == h &&
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1853
                                    ((ek = e.key) == key ||
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1854
                                     (ek != null && key.equals(ek)))) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1855
                                    val = remappingFunction.apply(key, e.val);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1856
                                    if (val != null)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1857
                                        e.val = val;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1858
                                    else {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1859
                                        delta = -1;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1860
                                        Node<K,V> en = e.next;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1861
                                        if (pred != null)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1862
                                            pred.next = en;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1863
                                        else
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1864
                                            setTabAt(tab, i, en);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1865
                                    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1866
                                    break;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1867
                                }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1868
                                pred = e;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1869
                                if ((e = e.next) == null) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1870
                                    val = remappingFunction.apply(key, null);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1871
                                    if (val != null) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1872
                                        delta = 1;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1873
                                        pred.next =
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1874
                                            new Node<K,V>(h, key, val, null);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1875
                                    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1876
                                    break;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1877
                                }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1878
                            }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1879
                        }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1880
                        else if (f instanceof TreeBin) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1881
                            binCount = 1;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1882
                            TreeBin<K,V> t = (TreeBin<K,V>)f;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1883
                            TreeNode<K,V> r, p;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1884
                            if ((r = t.root) != null)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1885
                                p = r.findTreeNode(h, key, null);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1886
                            else
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1887
                                p = null;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1888
                            V pv = (p == null) ? null : p.val;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1889
                            val = remappingFunction.apply(key, pv);
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1890
                            if (val != null) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1891
                                if (p != null)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1892
                                    p.val = val;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1893
                                else {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1894
                                    delta = 1;
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1895
                                    t.putTreeVal(h, key, val);
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1896
                                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1897
                            }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1898
                            else if (p != null) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1899
                                delta = -1;
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1900
                                if (t.removeTreeNode(p))
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1901
                                    setTabAt(tab, i, untreeify(t.first));
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1902
                            }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1903
                        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1904
                    }
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1905
                }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1906
                if (binCount != 0) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1907
                    if (binCount >= TREEIFY_THRESHOLD)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1908
                        treeifyBin(tab, i);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1909
                    break;
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1910
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1911
            }
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1912
        }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1913
        if (delta != 0)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1914
            addCount((long)delta, binCount);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1915
        return val;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1916
    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1917
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1918
    /**
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1919
     * If the specified key is not already associated with a
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1920
     * (non-null) value, associates it with the given value.
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1921
     * Otherwise, replaces the value with the results of the given
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1922
     * remapping function, or removes if {@code null}. The entire
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1923
     * method invocation is performed atomically.  Some attempted
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1924
     * update operations on this map by other threads may be blocked
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1925
     * while computation is in progress, so the computation should be
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1926
     * short and simple, and must not attempt to update any other
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1927
     * mappings of this Map.
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1928
     *
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1929
     * @param key key with which the specified value is to be associated
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1930
     * @param value the value to use if absent
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1931
     * @param remappingFunction the function to recompute a value if present
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1932
     * @return the new value associated with the specified key, or null if none
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1933
     * @throws NullPointerException if the specified key or the
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1934
     *         remappingFunction is null
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1935
     * @throws RuntimeException or Error if the remappingFunction does so,
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1936
     *         in which case the mapping is unchanged
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1937
     */
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1938
    public V merge(K key, V value, BiFunction<? super V, ? super V, ? extends V> remappingFunction) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1939
        if (key == null || value == null || remappingFunction == null)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1940
            throw new NullPointerException();
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1941
        int h = spread(key.hashCode());
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1942
        V val = null;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1943
        int delta = 0;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1944
        int binCount = 0;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1945
        for (Node<K,V>[] tab = table;;) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1946
            Node<K,V> f; int n, i, fh;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1947
            if (tab == null || (n = tab.length) == 0)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1948
                tab = initTable();
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1949
            else if ((f = tabAt(tab, i = (n - 1) & h)) == null) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1950
                if (casTabAt(tab, i, null, new Node<K,V>(h, key, value, null))) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1951
                    delta = 1;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1952
                    val = value;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1953
                    break;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1954
                }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1955
            }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1956
            else if ((fh = f.hash) == MOVED)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1957
                tab = helpTransfer(tab, f);
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1958
            else {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1959
                synchronized (f) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  1960
                    if (tabAt(tab, i) == f) {
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1961
                        if (fh >= 0) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1962
                            binCount = 1;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1963
                            for (Node<K,V> e = f, pred = null;; ++binCount) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1964
                                K ek;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1965
                                if (e.hash == h &&
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1966
                                    ((ek = e.key) == key ||
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1967
                                     (ek != null && key.equals(ek)))) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1968
                                    val = remappingFunction.apply(e.val, value);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1969
                                    if (val != null)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1970
                                        e.val = val;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1971
                                    else {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1972
                                        delta = -1;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1973
                                        Node<K,V> en = e.next;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1974
                                        if (pred != null)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1975
                                            pred.next = en;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1976
                                        else
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1977
                                            setTabAt(tab, i, en);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1978
                                    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1979
                                    break;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1980
                                }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1981
                                pred = e;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1982
                                if ((e = e.next) == null) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1983
                                    delta = 1;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1984
                                    val = value;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1985
                                    pred.next =
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1986
                                        new Node<K,V>(h, key, val, null);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1987
                                    break;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1988
                                }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1989
                            }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1990
                        }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1991
                        else if (f instanceof TreeBin) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1992
                            binCount = 2;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1993
                            TreeBin<K,V> t = (TreeBin<K,V>)f;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1994
                            TreeNode<K,V> r = t.root;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1995
                            TreeNode<K,V> p = (r == null) ? null :
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1996
                                r.findTreeNode(h, key, null);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1997
                            val = (p == null) ? value :
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1998
                                remappingFunction.apply(p.val, value);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  1999
                            if (val != null) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2000
                                if (p != null)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2001
                                    p.val = val;
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2002
                                else {
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2003
                                    delta = 1;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2004
                                    t.putTreeVal(h, key, val);
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2005
                                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2006
                            }
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2007
                            else if (p != null) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2008
                                delta = -1;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2009
                                if (t.removeTreeNode(p))
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2010
                                    setTabAt(tab, i, untreeify(t.first));
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2011
                            }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2012
                        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2013
                    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2014
                }
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2015
                if (binCount != 0) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2016
                    if (binCount >= TREEIFY_THRESHOLD)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2017
                        treeifyBin(tab, i);
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2018
                    break;
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2019
                }
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2020
            }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2021
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2022
        if (delta != 0)
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2023
            addCount((long)delta, binCount);
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2024
        return val;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2025
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2026
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2027
    // Hashtable legacy methods
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2028
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2029
    /**
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2030
     * Legacy method testing if some key maps into the specified value
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2031
     * in this table.  This method is identical in functionality to
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2032
     * {@link #containsValue(Object)}, and exists solely to ensure
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2033
     * full compatibility with class {@link java.util.Hashtable},
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2034
     * which supported this method prior to introduction of the
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2035
     * Java Collections framework.
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2036
     *
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2037
     * @param  value a value to search for
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2038
     * @return {@code true} if and only if some key maps to the
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2039
     *         {@code value} argument in this table as
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2040
     *         determined by the {@code equals} method;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2041
     *         {@code false} otherwise
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2042
     * @throws NullPointerException if the specified value is null
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2043
     */
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2044
    public boolean contains(Object value) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2045
        return containsValue(value);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2046
    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2047
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2048
    /**
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2049
     * Returns an enumeration of the keys in this table.
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2050
     *
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2051
     * @return an enumeration of the keys in this table
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2052
     * @see #keySet()
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2053
     */
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2054
    public Enumeration<K> keys() {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2055
        Node<K,V>[] t;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2056
        int f = (t = table) == null ? 0 : t.length;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2057
        return new KeyIterator<K,V>(t, f, 0, f, this);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2058
    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2059
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2060
    /**
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2061
     * Returns an enumeration of the values in this table.
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2062
     *
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2063
     * @return an enumeration of the values in this table
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2064
     * @see #values()
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2065
     */
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2066
    public Enumeration<V> elements() {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2067
        Node<K,V>[] t;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2068
        int f = (t = table) == null ? 0 : t.length;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2069
        return new ValueIterator<K,V>(t, f, 0, f, this);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2070
    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2071
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2072
    // ConcurrentHashMap-only methods
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2073
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2074
    /**
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2075
     * Returns the number of mappings. This method should be used
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2076
     * instead of {@link #size} because a ConcurrentHashMap may
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2077
     * contain more mappings than can be represented as an int. The
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2078
     * value returned is an estimate; the actual count may differ if
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2079
     * there are concurrent insertions or removals.
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2080
     *
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2081
     * @return the number of mappings
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2082
     * @since 1.8
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2083
     */
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2084
    public long mappingCount() {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2085
        long n = sumCount();
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2086
        return (n < 0L) ? 0L : n; // ignore transient negative values
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2087
    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2088
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2089
    /**
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2090
     * Creates a new {@link Set} backed by a ConcurrentHashMap
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2091
     * from the given type to {@code Boolean.TRUE}.
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2092
     *
19036
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
  2093
     * @param <K> the element type of the returned set
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2094
     * @return the new set
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2095
     * @since 1.8
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2096
     */
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2097
    public static <K> KeySetView<K,Boolean> newKeySet() {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2098
        return new KeySetView<K,Boolean>
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2099
            (new ConcurrentHashMap<K,Boolean>(), Boolean.TRUE);
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2100
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2101
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2102
    /**
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2103
     * Creates a new {@link Set} backed by a ConcurrentHashMap
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2104
     * from the given type to {@code Boolean.TRUE}.
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2105
     *
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2106
     * @param initialCapacity The implementation performs internal
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2107
     * sizing to accommodate this many elements.
19036
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
  2108
     * @param <K> the element type of the returned set
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
  2109
     * @return the new set
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2110
     * @throws IllegalArgumentException if the initial capacity of
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2111
     * elements is negative
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2112
     * @since 1.8
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2113
     */
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2114
    public static <K> KeySetView<K,Boolean> newKeySet(int initialCapacity) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2115
        return new KeySetView<K,Boolean>
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2116
            (new ConcurrentHashMap<K,Boolean>(initialCapacity), Boolean.TRUE);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2117
    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2118
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2119
    /**
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2120
     * Returns a {@link Set} view of the keys in this map, using the
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2121
     * given common mapped value for any additions (i.e., {@link
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2122
     * Collection#add} and {@link Collection#addAll(Collection)}).
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2123
     * This is of course only appropriate if it is acceptable to use
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2124
     * the same value for all additions from this view.
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2125
     *
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2126
     * @param mappedValue the mapped value to use for any additions
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2127
     * @return the set view
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2128
     * @throws NullPointerException if the mappedValue is null
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2129
     */
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2130
    public KeySetView<K,V> keySet(V mappedValue) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2131
        if (mappedValue == null)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2132
            throw new NullPointerException();
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2133
        return new KeySetView<K,V>(this, mappedValue);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2134
    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2135
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2136
    /* ---------------- Special Nodes -------------- */
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2137
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2138
    /**
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2139
     * A node inserted at head of bins during transfer operations.
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2140
     */
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2141
    static final class ForwardingNode<K,V> extends Node<K,V> {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2142
        final Node<K,V>[] nextTable;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2143
        ForwardingNode(Node<K,V>[] tab) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2144
            super(MOVED, null, null, null);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2145
            this.nextTable = tab;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2146
        }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2147
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2148
        Node<K,V> find(int h, Object k) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2149
            // loop to avoid arbitrarily deep recursion on forwarding nodes
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2150
            outer: for (Node<K,V>[] tab = nextTable;;) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2151
                Node<K,V> e; int n;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2152
                if (k == null || tab == null || (n = tab.length) == 0 ||
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2153
                    (e = tabAt(tab, (n - 1) & h)) == null)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2154
                    return null;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2155
                for (;;) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2156
                    int eh; K ek;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2157
                    if ((eh = e.hash) == h &&
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2158
                        ((ek = e.key) == k || (ek != null && k.equals(ek))))
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2159
                        return e;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2160
                    if (eh < 0) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2161
                        if (e instanceof ForwardingNode) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2162
                            tab = ((ForwardingNode<K,V>)e).nextTable;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2163
                            continue outer;
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2164
                        }
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2165
                        else
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2166
                            return e.find(h, k);
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2167
                    }
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2168
                    if ((e = e.next) == null)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2169
                        return null;
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2170
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2171
            }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2172
        }
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2173
    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2174
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2175
    /**
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2176
     * A place-holder node used in computeIfAbsent and compute
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2177
     */
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2178
    static final class ReservationNode<K,V> extends Node<K,V> {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2179
        ReservationNode() {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2180
            super(RESERVED, null, null, null);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2181
        }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2182
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2183
        Node<K,V> find(int h, Object k) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2184
            return null;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2185
        }
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2186
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2187
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2188
    /* ---------------- Table Initialization and Resizing -------------- */
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2189
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2190
    /**
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2191
     * Initializes table, using the size recorded in sizeCtl.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2192
     */
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2193
    private final Node<K,V>[] initTable() {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2194
        Node<K,V>[] tab; int sc;
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2195
        while ((tab = table) == null || tab.length == 0) {
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2196
            if ((sc = sizeCtl) < 0)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2197
                Thread.yield(); // lost initialization race; just spin
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2198
            else if (U.compareAndSwapInt(this, SIZECTL, sc, -1)) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2199
                try {
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2200
                    if ((tab = table) == null || tab.length == 0) {
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2201
                        int n = (sc > 0) ? sc : DEFAULT_CAPACITY;
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2202
                        @SuppressWarnings({"rawtypes","unchecked"})
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2203
                            Node<K,V>[] nt = (Node<K,V>[])new Node[n];
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2204
                        table = tab = nt;
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2205
                        sc = n - (n >>> 2);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2206
                    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2207
                } finally {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2208
                    sizeCtl = sc;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2209
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2210
                break;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2211
            }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2212
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2213
        return tab;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2214
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2215
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2216
    /**
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2217
     * Adds to count, and if table is too small and not already
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2218
     * resizing, initiates transfer. If already resizing, helps
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2219
     * perform transfer if work is available.  Rechecks occupancy
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2220
     * after a transfer to see if another resize is already needed
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2221
     * because resizings are lagging additions.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2222
     *
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2223
     * @param x the count to add
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2224
     * @param check if <0, don't check resize, if <= 1 only check if uncontended
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2225
     */
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2226
    private final void addCount(long x, int check) {
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2227
        CounterCell[] as; long b, s;
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2228
        if ((as = counterCells) != null ||
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2229
            !U.compareAndSwapLong(this, BASECOUNT, b = baseCount, s = b + x)) {
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2230
            CounterCell a; long v; int m;
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2231
            boolean uncontended = true;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2232
            if (as == null || (m = as.length - 1) < 0 ||
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2233
                (a = as[ThreadLocalRandom.getProbe() & m]) == null ||
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2234
                !(uncontended =
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2235
                  U.compareAndSwapLong(a, CELLVALUE, v = a.value, v + x))) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2236
                fullAddCount(x, uncontended);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2237
                return;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2238
            }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2239
            if (check <= 1)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2240
                return;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2241
            s = sumCount();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2242
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2243
        if (check >= 0) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2244
            Node<K,V>[] tab, nt; int sc;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2245
            while (s >= (long)(sc = sizeCtl) && (tab = table) != null &&
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2246
                   tab.length < MAXIMUM_CAPACITY) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2247
                if (sc < 0) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2248
                    if (sc == -1 || transferIndex <= transferOrigin ||
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2249
                        (nt = nextTable) == null)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2250
                        break;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2251
                    if (U.compareAndSwapInt(this, SIZECTL, sc, sc - 1))
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2252
                        transfer(tab, nt);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2253
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2254
                else if (U.compareAndSwapInt(this, SIZECTL, sc, -2))
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2255
                    transfer(tab, null);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2256
                s = sumCount();
9279
5f5d493d30a0 7036559: ConcurrentHashMap footprint and contention improvements
dl
parents: 9242
diff changeset
  2257
            }
5f5d493d30a0 7036559: ConcurrentHashMap footprint and contention improvements
dl
parents: 9242
diff changeset
  2258
        }
5f5d493d30a0 7036559: ConcurrentHashMap footprint and contention improvements
dl
parents: 9242
diff changeset
  2259
    }
5f5d493d30a0 7036559: ConcurrentHashMap footprint and contention improvements
dl
parents: 9242
diff changeset
  2260
5f5d493d30a0 7036559: ConcurrentHashMap footprint and contention improvements
dl
parents: 9242
diff changeset
  2261
    /**
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2262
     * Helps transfer if a resize is in progress.
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2263
     */
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2264
    final Node<K,V>[] helpTransfer(Node<K,V>[] tab, Node<K,V> f) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2265
        Node<K,V>[] nextTab; int sc;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2266
        if ((f instanceof ForwardingNode) &&
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2267
            (nextTab = ((ForwardingNode<K,V>)f).nextTable) != null) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2268
            if (nextTab == nextTable && tab == table &&
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2269
                transferIndex > transferOrigin && (sc = sizeCtl) < -1 &&
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2270
                U.compareAndSwapInt(this, SIZECTL, sc, sc - 1))
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2271
                transfer(tab, nextTab);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2272
            return nextTab;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2273
        }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2274
        return table;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2275
    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2276
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2277
    /**
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2278
     * Tries to presize table to accommodate the given number of elements.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2279
     *
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2280
     * @param size number of elements (doesn't need to be perfectly accurate)
9279
5f5d493d30a0 7036559: ConcurrentHashMap footprint and contention improvements
dl
parents: 9242
diff changeset
  2281
     */
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2282
    private final void tryPresize(int size) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2283
        int c = (size >= (MAXIMUM_CAPACITY >>> 1)) ? MAXIMUM_CAPACITY :
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2284
            tableSizeFor(size + (size >>> 1) + 1);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2285
        int sc;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2286
        while ((sc = sizeCtl) >= 0) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2287
            Node<K,V>[] tab = table; int n;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2288
            if (tab == null || (n = tab.length) == 0) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2289
                n = (sc > c) ? sc : c;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2290
                if (U.compareAndSwapInt(this, SIZECTL, sc, -1)) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2291
                    try {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2292
                        if (table == tab) {
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2293
                            @SuppressWarnings({"rawtypes","unchecked"})
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2294
                                Node<K,V>[] nt = (Node<K,V>[])new Node[n];
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2295
                            table = nt;
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2296
                            sc = n - (n >>> 2);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2297
                        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2298
                    } finally {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2299
                        sizeCtl = sc;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2300
                    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2301
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2302
            }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2303
            else if (c <= sc || n >= MAXIMUM_CAPACITY)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2304
                break;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2305
            else if (tab == table &&
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2306
                     U.compareAndSwapInt(this, SIZECTL, sc, -2))
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2307
                transfer(tab, null);
12859
c44b88bb9b5e 7126277: Alternative String hashing implementation
mduigou
parents: 11279
diff changeset
  2308
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2309
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2310
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2311
    /**
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2312
     * Moves and/or copies the nodes in each bin to new table. See
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2313
     * above for explanation.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2314
     */
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2315
    private final void transfer(Node<K,V>[] tab, Node<K,V>[] nextTab) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2316
        int n = tab.length, stride;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2317
        if ((stride = (NCPU > 1) ? (n >>> 3) / NCPU : n) < MIN_TRANSFER_STRIDE)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2318
            stride = MIN_TRANSFER_STRIDE; // subdivide range
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2319
        if (nextTab == null) {            // initiating
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2320
            try {
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2321
                @SuppressWarnings({"rawtypes","unchecked"})
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2322
                    Node<K,V>[] nt = (Node<K,V>[])new Node[n << 1];
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2323
                nextTab = nt;
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2324
            } catch (Throwable ex) {      // try to cope with OOME
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2325
                sizeCtl = Integer.MAX_VALUE;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2326
                return;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2327
            }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2328
            nextTable = nextTab;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2329
            transferOrigin = n;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2330
            transferIndex = n;
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2331
            ForwardingNode<K,V> rev = new ForwardingNode<K,V>(tab);
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2332
            for (int k = n; k > 0;) {    // progressively reveal ready slots
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2333
                int nextk = (k > stride) ? k - stride : 0;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2334
                for (int m = nextk; m < k; ++m)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2335
                    nextTab[m] = rev;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2336
                for (int m = n + nextk; m < n + k; ++m)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2337
                    nextTab[m] = rev;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2338
                U.putOrderedInt(this, TRANSFERORIGIN, k = nextk);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2339
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2340
        }
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2341
        int nextn = nextTab.length;
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2342
        ForwardingNode<K,V> fwd = new ForwardingNode<K,V>(nextTab);
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2343
        boolean advance = true;
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2344
        boolean finishing = false; // to ensure sweep before committing nextTab
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2345
        for (int i = 0, bound = 0;;) {
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2346
            int nextIndex, nextBound, fh; Node<K,V> f;
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2347
            while (advance) {
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2348
                if (--i >= bound || finishing)
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2349
                    advance = false;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2350
                else if ((nextIndex = transferIndex) <= transferOrigin) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2351
                    i = -1;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2352
                    advance = false;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2353
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2354
                else if (U.compareAndSwapInt
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2355
                         (this, TRANSFERINDEX, nextIndex,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2356
                          nextBound = (nextIndex > stride ?
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2357
                                       nextIndex - stride : 0))) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2358
                    bound = nextBound;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2359
                    i = nextIndex - 1;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2360
                    advance = false;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2361
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2362
            }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2363
            if (i < 0 || i >= n || i + n >= nextn) {
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2364
                if (finishing) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2365
                    nextTable = null;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2366
                    table = nextTab;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2367
                    sizeCtl = (n << 1) - (n >>> 1);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2368
                    return;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2369
                }
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2370
                for (int sc;;) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2371
                    if (U.compareAndSwapInt(this, SIZECTL, sc = sizeCtl, ++sc)) {
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2372
                        if (sc != -1)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2373
                            return;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2374
                        finishing = advance = true;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2375
                        i = n; // recheck before commit
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2376
                        break;
9279
5f5d493d30a0 7036559: ConcurrentHashMap footprint and contention improvements
dl
parents: 9242
diff changeset
  2377
                    }
5f5d493d30a0 7036559: ConcurrentHashMap footprint and contention improvements
dl
parents: 9242
diff changeset
  2378
                }
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2379
            }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2380
            else if ((f = tabAt(tab, i)) == null) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2381
                if (casTabAt(tab, i, null, fwd)) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2382
                    setTabAt(nextTab, i, null);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2383
                    setTabAt(nextTab, i + n, null);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2384
                    advance = true;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2385
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2386
            }
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2387
            else if ((fh = f.hash) == MOVED)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2388
                advance = true; // already processed
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2389
            else {
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2390
                synchronized (f) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2391
                    if (tabAt(tab, i) == f) {
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2392
                        Node<K,V> ln, hn;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2393
                        if (fh >= 0) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2394
                            int runBit = fh & n;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2395
                            Node<K,V> lastRun = f;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2396
                            for (Node<K,V> p = f.next; p != null; p = p.next) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2397
                                int b = p.hash & n;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2398
                                if (b != runBit) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2399
                                    runBit = b;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2400
                                    lastRun = p;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2401
                                }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2402
                            }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2403
                            if (runBit == 0) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2404
                                ln = lastRun;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2405
                                hn = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2406
                            }
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2407
                            else {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2408
                                hn = lastRun;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2409
                                ln = null;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2410
                            }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2411
                            for (Node<K,V> p = f; p != lastRun; p = p.next) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2412
                                int ph = p.hash; K pk = p.key; V pv = p.val;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2413
                                if ((ph & n) == 0)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2414
                                    ln = new Node<K,V>(ph, pk, pv, ln);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2415
                                else
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2416
                                    hn = new Node<K,V>(ph, pk, pv, hn);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2417
                            }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2418
                            setTabAt(nextTab, i, ln);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2419
                            setTabAt(nextTab, i + n, hn);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2420
                            setTabAt(tab, i, fwd);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2421
                            advance = true;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2422
                        }
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2423
                        else if (f instanceof TreeBin) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2424
                            TreeBin<K,V> t = (TreeBin<K,V>)f;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2425
                            TreeNode<K,V> lo = null, loTail = null;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2426
                            TreeNode<K,V> hi = null, hiTail = null;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2427
                            int lc = 0, hc = 0;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2428
                            for (Node<K,V> e = t.first; e != null; e = e.next) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2429
                                int h = e.hash;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2430
                                TreeNode<K,V> p = new TreeNode<K,V>
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2431
                                    (h, e.key, e.val, null, null);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2432
                                if ((h & n) == 0) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2433
                                    if ((p.prev = loTail) == null)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2434
                                        lo = p;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2435
                                    else
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2436
                                        loTail.next = p;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2437
                                    loTail = p;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2438
                                    ++lc;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2439
                                }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2440
                                else {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2441
                                    if ((p.prev = hiTail) == null)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2442
                                        hi = p;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2443
                                    else
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2444
                                        hiTail.next = p;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2445
                                    hiTail = p;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2446
                                    ++hc;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2447
                                }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2448
                            }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2449
                            ln = (lc <= UNTREEIFY_THRESHOLD) ? untreeify(lo) :
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2450
                                (hc != 0) ? new TreeBin<K,V>(lo) : t;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2451
                            hn = (hc <= UNTREEIFY_THRESHOLD) ? untreeify(hi) :
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2452
                                (lc != 0) ? new TreeBin<K,V>(hi) : t;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2453
                            setTabAt(nextTab, i, ln);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2454
                            setTabAt(nextTab, i + n, hn);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2455
                            setTabAt(tab, i, fwd);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2456
                            advance = true;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2457
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2458
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2459
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2460
            }
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2461
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2462
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2463
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2464
    /* ---------------- Counter support -------------- */
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2465
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2466
    /**
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2467
     * A padded cell for distributing counts.  Adapted from LongAdder
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2468
     * and Striped64.  See their internal docs for explanation.
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2469
     */
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2470
    @sun.misc.Contended static final class CounterCell {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2471
        volatile long value;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2472
        CounterCell(long x) { value = x; }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2473
    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2474
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2475
    final long sumCount() {
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2476
        CounterCell[] as = counterCells; CounterCell a;
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2477
        long sum = baseCount;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2478
        if (as != null) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2479
            for (int i = 0; i < as.length; ++i) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2480
                if ((a = as[i]) != null)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2481
                    sum += a.value;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2482
            }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2483
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2484
        return sum;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2485
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2486
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2487
    // See LongAdder version for explanation
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2488
    private final void fullAddCount(long x, boolean wasUncontended) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2489
        int h;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2490
        if ((h = ThreadLocalRandom.getProbe()) == 0) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2491
            ThreadLocalRandom.localInit();      // force initialization
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2492
            h = ThreadLocalRandom.getProbe();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2493
            wasUncontended = true;
9279
5f5d493d30a0 7036559: ConcurrentHashMap footprint and contention improvements
dl
parents: 9242
diff changeset
  2494
        }
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2495
        boolean collide = false;                // True if last slot nonempty
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2496
        for (;;) {
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2497
            CounterCell[] as; CounterCell a; int n; long v;
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2498
            if ((as = counterCells) != null && (n = as.length) > 0) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2499
                if ((a = as[(n - 1) & h]) == null) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2500
                    if (cellsBusy == 0) {            // Try to attach new Cell
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2501
                        CounterCell r = new CounterCell(x); // Optimistic create
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2502
                        if (cellsBusy == 0 &&
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2503
                            U.compareAndSwapInt(this, CELLSBUSY, 0, 1)) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2504
                            boolean created = false;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2505
                            try {               // Recheck under lock
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2506
                                CounterCell[] rs; int m, j;
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2507
                                if ((rs = counterCells) != null &&
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2508
                                    (m = rs.length) > 0 &&
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2509
                                    rs[j = (m - 1) & h] == null) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2510
                                    rs[j] = r;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2511
                                    created = true;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2512
                                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2513
                            } finally {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2514
                                cellsBusy = 0;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2515
                            }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2516
                            if (created)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2517
                                break;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2518
                            continue;           // Slot is now non-empty
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2519
                        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2520
                    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2521
                    collide = false;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2522
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2523
                else if (!wasUncontended)       // CAS already known to fail
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2524
                    wasUncontended = true;      // Continue after rehash
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2525
                else if (U.compareAndSwapLong(a, CELLVALUE, v = a.value, v + x))
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2526
                    break;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2527
                else if (counterCells != as || n >= NCPU)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2528
                    collide = false;            // At max size or stale
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2529
                else if (!collide)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2530
                    collide = true;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2531
                else if (cellsBusy == 0 &&
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2532
                         U.compareAndSwapInt(this, CELLSBUSY, 0, 1)) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2533
                    try {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2534
                        if (counterCells == as) {// Expand table unless stale
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2535
                            CounterCell[] rs = new CounterCell[n << 1];
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2536
                            for (int i = 0; i < n; ++i)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2537
                                rs[i] = as[i];
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2538
                            counterCells = rs;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2539
                        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2540
                    } finally {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2541
                        cellsBusy = 0;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2542
                    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2543
                    collide = false;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2544
                    continue;                   // Retry with expanded table
9279
5f5d493d30a0 7036559: ConcurrentHashMap footprint and contention improvements
dl
parents: 9242
diff changeset
  2545
                }
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2546
                h = ThreadLocalRandom.advanceProbe(h);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2547
            }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2548
            else if (cellsBusy == 0 && counterCells == as &&
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2549
                     U.compareAndSwapInt(this, CELLSBUSY, 0, 1)) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2550
                boolean init = false;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2551
                try {                           // Initialize table
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2552
                    if (counterCells == as) {
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2553
                        CounterCell[] rs = new CounterCell[2];
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2554
                        rs[h & 1] = new CounterCell(x);
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2555
                        counterCells = rs;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2556
                        init = true;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2557
                    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2558
                } finally {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2559
                    cellsBusy = 0;
9279
5f5d493d30a0 7036559: ConcurrentHashMap footprint and contention improvements
dl
parents: 9242
diff changeset
  2560
                }
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2561
                if (init)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2562
                    break;
9279
5f5d493d30a0 7036559: ConcurrentHashMap footprint and contention improvements
dl
parents: 9242
diff changeset
  2563
            }
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2564
            else if (U.compareAndSwapLong(this, BASECOUNT, v = baseCount, v + x))
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2565
                break;                          // Fall back on using base
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2566
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2567
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  2568
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2569
    /* ---------------- Conversion from/to TreeBins -------------- */
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2570
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2571
    /**
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2572
     * Replaces all linked nodes in bin at given index unless table is
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2573
     * too small, in which case resizes instead.
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2574
     */
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2575
    private final void treeifyBin(Node<K,V>[] tab, int index) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2576
        Node<K,V> b; int n, sc;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2577
        if (tab != null) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2578
            if ((n = tab.length) < MIN_TREEIFY_CAPACITY) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2579
                if (tab == table && (sc = sizeCtl) >= 0 &&
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2580
                    U.compareAndSwapInt(this, SIZECTL, sc, -2))
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2581
                    transfer(tab, null);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2582
            }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2583
            else if ((b = tabAt(tab, index)) != null && b.hash >= 0) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2584
                synchronized (b) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2585
                    if (tabAt(tab, index) == b) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2586
                        TreeNode<K,V> hd = null, tl = null;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2587
                        for (Node<K,V> e = b; e != null; e = e.next) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2588
                            TreeNode<K,V> p =
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2589
                                new TreeNode<K,V>(e.hash, e.key, e.val,
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2590
                                                  null, null);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2591
                            if ((p.prev = tl) == null)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2592
                                hd = p;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2593
                            else
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2594
                                tl.next = p;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2595
                            tl = p;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2596
                        }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2597
                        setTabAt(tab, index, new TreeBin<K,V>(hd));
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2598
                    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2599
                }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2600
            }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2601
        }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2602
    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2603
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2604
    /**
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2605
     * Returns a list on non-TreeNodes replacing those in given list.
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2606
     */
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2607
    static <K,V> Node<K,V> untreeify(Node<K,V> b) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2608
        Node<K,V> hd = null, tl = null;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2609
        for (Node<K,V> q = b; q != null; q = q.next) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2610
            Node<K,V> p = new Node<K,V>(q.hash, q.key, q.val, null);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2611
            if (tl == null)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2612
                hd = p;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2613
            else
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2614
                tl.next = p;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2615
            tl = p;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2616
        }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2617
        return hd;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2618
    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2619
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2620
    /* ---------------- TreeNodes -------------- */
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2621
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2622
    /**
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2623
     * Nodes for use in TreeBins
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2624
     */
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2625
    static final class TreeNode<K,V> extends Node<K,V> {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2626
        TreeNode<K,V> parent;  // red-black tree links
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2627
        TreeNode<K,V> left;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2628
        TreeNode<K,V> right;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2629
        TreeNode<K,V> prev;    // needed to unlink next upon deletion
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2630
        boolean red;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2631
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2632
        TreeNode(int hash, K key, V val, Node<K,V> next,
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2633
                 TreeNode<K,V> parent) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2634
            super(hash, key, val, next);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2635
            this.parent = parent;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2636
        }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2637
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2638
        Node<K,V> find(int h, Object k) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2639
            return findTreeNode(h, k, null);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2640
        }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2641
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2642
        /**
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2643
         * Returns the TreeNode (or null if not found) for the given key
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2644
         * starting at given root.
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2645
         */
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2646
        final TreeNode<K,V> findTreeNode(int h, Object k, Class<?> kc) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2647
            if (k != null) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2648
                TreeNode<K,V> p = this;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2649
                do  {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2650
                    int ph, dir; K pk; TreeNode<K,V> q;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2651
                    TreeNode<K,V> pl = p.left, pr = p.right;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2652
                    if ((ph = p.hash) > h)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2653
                        p = pl;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2654
                    else if (ph < h)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2655
                        p = pr;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2656
                    else if ((pk = p.key) == k || (pk != null && k.equals(pk)))
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2657
                        return p;
19036
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
  2658
                    else if (pl == null)
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
  2659
                        p = pr;
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
  2660
                    else if (pr == null)
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
  2661
                        p = pl;
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2662
                    else if ((kc != null ||
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2663
                              (kc = comparableClassFor(k)) != null) &&
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2664
                             (dir = compareComparables(kc, k, pk)) != 0)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2665
                        p = (dir < 0) ? pl : pr;
19036
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
  2666
                    else if ((q = pr.findTreeNode(h, k, kc)) != null)
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
  2667
                        return q;
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
  2668
                    else
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2669
                        p = pl;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2670
                } while (p != null);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2671
            }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2672
            return null;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2673
        }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2674
    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2675
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2676
    /* ---------------- TreeBins -------------- */
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2677
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2678
    /**
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2679
     * TreeNodes used at the heads of bins. TreeBins do not hold user
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2680
     * keys or values, but instead point to list of TreeNodes and
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2681
     * their root. They also maintain a parasitic read-write lock
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2682
     * forcing writers (who hold bin lock) to wait for readers (who do
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2683
     * not) to complete before tree restructuring operations.
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2684
     */
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2685
    static final class TreeBin<K,V> extends Node<K,V> {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2686
        TreeNode<K,V> root;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2687
        volatile TreeNode<K,V> first;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2688
        volatile Thread waiter;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2689
        volatile int lockState;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2690
        // values for lockState
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2691
        static final int WRITER = 1; // set while holding write lock
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2692
        static final int WAITER = 2; // set when waiting for write lock
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2693
        static final int READER = 4; // increment value for setting read lock
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2694
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2695
        /**
19036
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
  2696
         * Tie-breaking utility for ordering insertions when equal
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
  2697
         * hashCodes and non-comparable. We don't require a total
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
  2698
         * order, just a consistent insertion rule to maintain
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
  2699
         * equivalence across rebalancings. Tie-breaking further than
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
  2700
         * necessary simplifies testing a bit.
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
  2701
         */
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
  2702
        static int tieBreakOrder(Object a, Object b) {
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
  2703
            int d;
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
  2704
            if (a == null || b == null ||
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
  2705
                (d = a.getClass().getName().
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
  2706
                 compareTo(b.getClass().getName())) == 0)
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
  2707
                d = (System.identityHashCode(a) <= System.identityHashCode(b) ?
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
  2708
                     -1 : 1);
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
  2709
            return d;
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
  2710
        }
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
  2711
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
  2712
        /**
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2713
         * Creates bin with initial set of nodes headed by b.
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2714
         */
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2715
        TreeBin(TreeNode<K,V> b) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2716
            super(TREEBIN, null, null, null);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2717
            this.first = b;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2718
            TreeNode<K,V> r = null;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2719
            for (TreeNode<K,V> x = b, next; x != null; x = next) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2720
                next = (TreeNode<K,V>)x.next;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2721
                x.left = x.right = null;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2722
                if (r == null) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2723
                    x.parent = null;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2724
                    x.red = false;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2725
                    r = x;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2726
                }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2727
                else {
19036
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
  2728
                    K k = x.key;
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
  2729
                    int h = x.hash;
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2730
                    Class<?> kc = null;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2731
                    for (TreeNode<K,V> p = r;;) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2732
                        int dir, ph;
19036
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
  2733
                        K pk = p.key;
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
  2734
                        if ((ph = p.hash) > h)
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2735
                            dir = -1;
19036
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
  2736
                        else if (ph < h)
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2737
                            dir = 1;
19036
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
  2738
                        else if ((kc == null &&
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
  2739
                                  (kc = comparableClassFor(k)) == null) ||
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
  2740
                                 (dir = compareComparables(kc, k, pk)) == 0)
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
  2741
                            dir = tieBreakOrder(k, pk);
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
  2742
                            TreeNode<K,V> xp = p;
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2743
                        if ((p = (dir <= 0) ? p.left : p.right) == null) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2744
                            x.parent = xp;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2745
                            if (dir <= 0)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2746
                                xp.left = x;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2747
                            else
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2748
                                xp.right = x;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2749
                            r = balanceInsertion(r, x);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2750
                            break;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2751
                        }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2752
                    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2753
                }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2754
            }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2755
            this.root = r;
19036
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
  2756
            assert checkInvariants(root);
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2757
        }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2758
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2759
        /**
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2760
         * Acquires write lock for tree restructuring.
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2761
         */
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2762
        private final void lockRoot() {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2763
            if (!U.compareAndSwapInt(this, LOCKSTATE, 0, WRITER))
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2764
                contendedLock(); // offload to separate method
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2765
        }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2766
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2767
        /**
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2768
         * Releases write lock for tree restructuring.
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2769
         */
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2770
        private final void unlockRoot() {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2771
            lockState = 0;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2772
        }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2773
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2774
        /**
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2775
         * Possibly blocks awaiting root lock.
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2776
         */
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2777
        private final void contendedLock() {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2778
            boolean waiting = false;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2779
            for (int s;;) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2780
                if (((s = lockState) & WRITER) == 0) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2781
                    if (U.compareAndSwapInt(this, LOCKSTATE, s, WRITER)) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2782
                        if (waiting)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2783
                            waiter = null;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2784
                        return;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2785
                    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2786
                }
19413
56082c988815 8023104: ConcurrentHashMap typo
dl
parents: 19380
diff changeset
  2787
                else if ((s & WAITER) == 0) {
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2788
                    if (U.compareAndSwapInt(this, LOCKSTATE, s, s | WAITER)) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2789
                        waiting = true;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2790
                        waiter = Thread.currentThread();
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2791
                    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2792
                }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2793
                else if (waiting)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2794
                    LockSupport.park(this);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2795
            }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2796
        }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2797
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2798
        /**
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2799
         * Returns matching node or null if none. Tries to search
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2800
         * using tree comparisons from root, but continues linear
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2801
         * search when lock not available.
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2802
         */
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2803
        final Node<K,V> find(int h, Object k) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2804
            if (k != null) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2805
                for (Node<K,V> e = first; e != null; e = e.next) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2806
                    int s; K ek;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2807
                    if (((s = lockState) & (WAITER|WRITER)) != 0) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2808
                        if (e.hash == h &&
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2809
                            ((ek = e.key) == k || (ek != null && k.equals(ek))))
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2810
                            return e;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2811
                    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2812
                    else if (U.compareAndSwapInt(this, LOCKSTATE, s,
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2813
                                                 s + READER)) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2814
                        TreeNode<K,V> r, p;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2815
                        try {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2816
                            p = ((r = root) == null ? null :
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2817
                                 r.findTreeNode(h, k, null));
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2818
                        } finally {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2819
                            Thread w;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2820
                            if (U.getAndAddInt(this, LOCKSTATE, -READER) ==
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2821
                                (READER|WAITER) && (w = waiter) != null)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2822
                                LockSupport.unpark(w);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2823
                        }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2824
                        return p;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2825
                    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2826
                }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2827
            }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2828
            return null;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2829
        }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2830
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2831
        /**
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2832
         * Finds or adds a node.
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2833
         * @return null if added
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2834
         */
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2835
        final TreeNode<K,V> putTreeVal(int h, K k, V v) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2836
            Class<?> kc = null;
19036
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
  2837
            boolean searched = false;
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2838
            for (TreeNode<K,V> p = root;;) {
19036
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
  2839
                int dir, ph; K pk;
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2840
                if (p == null) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2841
                    first = root = new TreeNode<K,V>(h, k, v, null, null);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2842
                    break;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2843
                }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2844
                else if ((ph = p.hash) > h)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2845
                    dir = -1;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2846
                else if (ph < h)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2847
                    dir = 1;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2848
                else if ((pk = p.key) == k || (pk != null && k.equals(pk)))
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2849
                    return p;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2850
                else if ((kc == null &&
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2851
                          (kc = comparableClassFor(k)) == null) ||
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2852
                         (dir = compareComparables(kc, k, pk)) == 0) {
19036
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
  2853
                    if (!searched) {
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
  2854
                        TreeNode<K,V> q, ch;
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
  2855
                        searched = true;
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
  2856
                        if (((ch = p.left) != null &&
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
  2857
                             (q = ch.findTreeNode(h, k, kc)) != null) ||
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
  2858
                            ((ch = p.right) != null &&
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
  2859
                             (q = ch.findTreeNode(h, k, kc)) != null))
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
  2860
                            return q;
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
  2861
                    }
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
  2862
                    dir = tieBreakOrder(k, pk);
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2863
                }
19036
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
  2864
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2865
                TreeNode<K,V> xp = p;
19036
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
  2866
                if ((p = (dir <= 0) ? p.left : p.right) == null) {
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2867
                    TreeNode<K,V> x, f = first;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2868
                    first = x = new TreeNode<K,V>(h, k, v, f, xp);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2869
                    if (f != null)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2870
                        f.prev = x;
19036
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
  2871
                    if (dir <= 0)
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2872
                        xp.left = x;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2873
                    else
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2874
                        xp.right = x;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2875
                    if (!xp.red)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2876
                        x.red = true;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2877
                    else {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2878
                        lockRoot();
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2879
                        try {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2880
                            root = balanceInsertion(root, x);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2881
                        } finally {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2882
                            unlockRoot();
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2883
                        }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2884
                    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2885
                    break;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2886
                }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2887
            }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2888
            assert checkInvariants(root);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2889
            return null;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2890
        }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2891
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2892
        /**
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2893
         * Removes the given node, that must be present before this
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2894
         * call.  This is messier than typical red-black deletion code
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2895
         * because we cannot swap the contents of an interior node
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2896
         * with a leaf successor that is pinned by "next" pointers
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2897
         * that are accessible independently of lock. So instead we
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2898
         * swap the tree linkages.
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2899
         *
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2900
         * @return true if now too small, so should be untreeified
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2901
         */
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2902
        final boolean removeTreeNode(TreeNode<K,V> p) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2903
            TreeNode<K,V> next = (TreeNode<K,V>)p.next;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2904
            TreeNode<K,V> pred = p.prev;  // unlink traversal pointers
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2905
            TreeNode<K,V> r, rl;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2906
            if (pred == null)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2907
                first = next;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2908
            else
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2909
                pred.next = next;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2910
            if (next != null)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2911
                next.prev = pred;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2912
            if (first == null) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2913
                root = null;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2914
                return true;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2915
            }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2916
            if ((r = root) == null || r.right == null || // too small
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2917
                (rl = r.left) == null || rl.left == null)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2918
                return true;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2919
            lockRoot();
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2920
            try {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2921
                TreeNode<K,V> replacement;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2922
                TreeNode<K,V> pl = p.left;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2923
                TreeNode<K,V> pr = p.right;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2924
                if (pl != null && pr != null) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2925
                    TreeNode<K,V> s = pr, sl;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2926
                    while ((sl = s.left) != null) // find successor
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2927
                        s = sl;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2928
                    boolean c = s.red; s.red = p.red; p.red = c; // swap colors
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2929
                    TreeNode<K,V> sr = s.right;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2930
                    TreeNode<K,V> pp = p.parent;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2931
                    if (s == pr) { // p was s's direct parent
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2932
                        p.parent = s;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2933
                        s.right = p;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2934
                    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2935
                    else {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2936
                        TreeNode<K,V> sp = s.parent;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2937
                        if ((p.parent = sp) != null) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2938
                            if (s == sp.left)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2939
                                sp.left = p;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2940
                            else
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2941
                                sp.right = p;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2942
                        }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2943
                        if ((s.right = pr) != null)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2944
                            pr.parent = s;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2945
                    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2946
                    p.left = null;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2947
                    if ((p.right = sr) != null)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2948
                        sr.parent = p;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2949
                    if ((s.left = pl) != null)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2950
                        pl.parent = s;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2951
                    if ((s.parent = pp) == null)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2952
                        r = s;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2953
                    else if (p == pp.left)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2954
                        pp.left = s;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2955
                    else
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2956
                        pp.right = s;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2957
                    if (sr != null)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2958
                        replacement = sr;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2959
                    else
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2960
                        replacement = p;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2961
                }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2962
                else if (pl != null)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2963
                    replacement = pl;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2964
                else if (pr != null)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2965
                    replacement = pr;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2966
                else
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2967
                    replacement = p;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2968
                if (replacement != p) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2969
                    TreeNode<K,V> pp = replacement.parent = p.parent;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2970
                    if (pp == null)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2971
                        r = replacement;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2972
                    else if (p == pp.left)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2973
                        pp.left = replacement;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2974
                    else
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2975
                        pp.right = replacement;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2976
                    p.left = p.right = p.parent = null;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2977
                }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2978
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2979
                root = (p.red) ? r : balanceDeletion(r, replacement);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2980
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2981
                if (p == replacement) {  // detach pointers
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2982
                    TreeNode<K,V> pp;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2983
                    if ((pp = p.parent) != null) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2984
                        if (p == pp.left)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2985
                            pp.left = null;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2986
                        else if (p == pp.right)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2987
                            pp.right = null;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2988
                        p.parent = null;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2989
                    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2990
                }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2991
            } finally {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2992
                unlockRoot();
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2993
            }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2994
            assert checkInvariants(root);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2995
            return false;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2996
        }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2997
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2998
        /* ------------------------------------------------------------ */
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  2999
        // Red-black tree methods, all adapted from CLR
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3000
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3001
        static <K,V> TreeNode<K,V> rotateLeft(TreeNode<K,V> root,
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3002
                                              TreeNode<K,V> p) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3003
            TreeNode<K,V> r, pp, rl;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3004
            if (p != null && (r = p.right) != null) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3005
                if ((rl = p.right = r.left) != null)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3006
                    rl.parent = p;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3007
                if ((pp = r.parent = p.parent) == null)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3008
                    (root = r).red = false;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3009
                else if (pp.left == p)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3010
                    pp.left = r;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3011
                else
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3012
                    pp.right = r;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3013
                r.left = p;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3014
                p.parent = r;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3015
            }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3016
            return root;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3017
        }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3018
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3019
        static <K,V> TreeNode<K,V> rotateRight(TreeNode<K,V> root,
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3020
                                               TreeNode<K,V> p) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3021
            TreeNode<K,V> l, pp, lr;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3022
            if (p != null && (l = p.left) != null) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3023
                if ((lr = p.left = l.right) != null)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3024
                    lr.parent = p;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3025
                if ((pp = l.parent = p.parent) == null)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3026
                    (root = l).red = false;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3027
                else if (pp.right == p)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3028
                    pp.right = l;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3029
                else
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3030
                    pp.left = l;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3031
                l.right = p;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3032
                p.parent = l;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3033
            }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3034
            return root;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3035
        }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3036
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3037
        static <K,V> TreeNode<K,V> balanceInsertion(TreeNode<K,V> root,
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3038
                                                    TreeNode<K,V> x) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3039
            x.red = true;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3040
            for (TreeNode<K,V> xp, xpp, xppl, xppr;;) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3041
                if ((xp = x.parent) == null) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3042
                    x.red = false;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3043
                    return x;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3044
                }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3045
                else if (!xp.red || (xpp = xp.parent) == null)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3046
                    return root;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3047
                if (xp == (xppl = xpp.left)) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3048
                    if ((xppr = xpp.right) != null && xppr.red) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3049
                        xppr.red = false;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3050
                        xp.red = false;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3051
                        xpp.red = true;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3052
                        x = xpp;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3053
                    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3054
                    else {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3055
                        if (x == xp.right) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3056
                            root = rotateLeft(root, x = xp);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3057
                            xpp = (xp = x.parent) == null ? null : xp.parent;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3058
                        }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3059
                        if (xp != null) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3060
                            xp.red = false;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3061
                            if (xpp != null) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3062
                                xpp.red = true;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3063
                                root = rotateRight(root, xpp);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3064
                            }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3065
                        }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3066
                    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3067
                }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3068
                else {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3069
                    if (xppl != null && xppl.red) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3070
                        xppl.red = false;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3071
                        xp.red = false;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3072
                        xpp.red = true;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3073
                        x = xpp;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3074
                    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3075
                    else {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3076
                        if (x == xp.left) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3077
                            root = rotateRight(root, x = xp);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3078
                            xpp = (xp = x.parent) == null ? null : xp.parent;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3079
                        }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3080
                        if (xp != null) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3081
                            xp.red = false;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3082
                            if (xpp != null) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3083
                                xpp.red = true;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3084
                                root = rotateLeft(root, xpp);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3085
                            }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3086
                        }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3087
                    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3088
                }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3089
            }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3090
        }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3091
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3092
        static <K,V> TreeNode<K,V> balanceDeletion(TreeNode<K,V> root,
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3093
                                                   TreeNode<K,V> x) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3094
            for (TreeNode<K,V> xp, xpl, xpr;;)  {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3095
                if (x == null || x == root)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3096
                    return root;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3097
                else if ((xp = x.parent) == null) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3098
                    x.red = false;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3099
                    return x;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3100
                }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3101
                else if (x.red) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3102
                    x.red = false;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3103
                    return root;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3104
                }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3105
                else if ((xpl = xp.left) == x) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3106
                    if ((xpr = xp.right) != null && xpr.red) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3107
                        xpr.red = false;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3108
                        xp.red = true;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3109
                        root = rotateLeft(root, xp);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3110
                        xpr = (xp = x.parent) == null ? null : xp.right;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3111
                    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3112
                    if (xpr == null)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3113
                        x = xp;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3114
                    else {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3115
                        TreeNode<K,V> sl = xpr.left, sr = xpr.right;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3116
                        if ((sr == null || !sr.red) &&
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3117
                            (sl == null || !sl.red)) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3118
                            xpr.red = true;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3119
                            x = xp;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3120
                        }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3121
                        else {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3122
                            if (sr == null || !sr.red) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3123
                                if (sl != null)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3124
                                    sl.red = false;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3125
                                xpr.red = true;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3126
                                root = rotateRight(root, xpr);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3127
                                xpr = (xp = x.parent) == null ?
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3128
                                    null : xp.right;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3129
                            }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3130
                            if (xpr != null) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3131
                                xpr.red = (xp == null) ? false : xp.red;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3132
                                if ((sr = xpr.right) != null)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3133
                                    sr.red = false;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3134
                            }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3135
                            if (xp != null) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3136
                                xp.red = false;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3137
                                root = rotateLeft(root, xp);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3138
                            }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3139
                            x = root;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3140
                        }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3141
                    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3142
                }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3143
                else { // symmetric
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3144
                    if (xpl != null && xpl.red) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3145
                        xpl.red = false;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3146
                        xp.red = true;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3147
                        root = rotateRight(root, xp);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3148
                        xpl = (xp = x.parent) == null ? null : xp.left;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3149
                    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3150
                    if (xpl == null)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3151
                        x = xp;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3152
                    else {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3153
                        TreeNode<K,V> sl = xpl.left, sr = xpl.right;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3154
                        if ((sl == null || !sl.red) &&
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3155
                            (sr == null || !sr.red)) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3156
                            xpl.red = true;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3157
                            x = xp;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3158
                        }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3159
                        else {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3160
                            if (sl == null || !sl.red) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3161
                                if (sr != null)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3162
                                    sr.red = false;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3163
                                xpl.red = true;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3164
                                root = rotateLeft(root, xpl);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3165
                                xpl = (xp = x.parent) == null ?
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3166
                                    null : xp.left;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3167
                            }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3168
                            if (xpl != null) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3169
                                xpl.red = (xp == null) ? false : xp.red;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3170
                                if ((sl = xpl.left) != null)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3171
                                    sl.red = false;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3172
                            }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3173
                            if (xp != null) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3174
                                xp.red = false;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3175
                                root = rotateRight(root, xp);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3176
                            }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3177
                            x = root;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3178
                        }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3179
                    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3180
                }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3181
            }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3182
        }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3183
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3184
        /**
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3185
         * Recursive invariant check
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3186
         */
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3187
        static <K,V> boolean checkInvariants(TreeNode<K,V> t) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3188
            TreeNode<K,V> tp = t.parent, tl = t.left, tr = t.right,
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3189
                tb = t.prev, tn = (TreeNode<K,V>)t.next;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3190
            if (tb != null && tb.next != t)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3191
                return false;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3192
            if (tn != null && tn.prev != t)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3193
                return false;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3194
            if (tp != null && t != tp.left && t != tp.right)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3195
                return false;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3196
            if (tl != null && (tl.parent != t || tl.hash > t.hash))
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3197
                return false;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3198
            if (tr != null && (tr.parent != t || tr.hash < t.hash))
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3199
                return false;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3200
            if (t.red && tl != null && tl.red && tr != null && tr.red)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3201
                return false;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3202
            if (tl != null && !checkInvariants(tl))
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3203
                return false;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3204
            if (tr != null && !checkInvariants(tr))
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3205
                return false;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3206
            return true;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3207
        }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3208
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3209
        private static final sun.misc.Unsafe U;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3210
        private static final long LOCKSTATE;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3211
        static {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3212
            try {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3213
                U = sun.misc.Unsafe.getUnsafe();
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3214
                Class<?> k = TreeBin.class;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3215
                LOCKSTATE = U.objectFieldOffset
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3216
                    (k.getDeclaredField("lockState"));
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3217
            } catch (Exception e) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3218
                throw new Error(e);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3219
            }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3220
        }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3221
    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3222
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3223
    /* ----------------Table Traversal -------------- */
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3224
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3225
    /**
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3226
     * Encapsulates traversal for methods such as containsValue; also
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3227
     * serves as a base class for other iterators and spliterators.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3228
     *
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3229
     * Method advance visits once each still-valid node that was
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3230
     * reachable upon iterator construction. It might miss some that
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3231
     * were added to a bin after the bin was visited, which is OK wrt
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3232
     * consistency guarantees. Maintaining this property in the face
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3233
     * of possible ongoing resizes requires a fair amount of
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3234
     * bookkeeping state that is difficult to optimize away amidst
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3235
     * volatile accesses.  Even so, traversal maintains reasonable
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3236
     * throughput.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3237
     *
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3238
     * Normally, iteration proceeds bin-by-bin traversing lists.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3239
     * However, if the table has been resized, then all future steps
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3240
     * must traverse both the bin at the current index as well as at
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3241
     * (index + baseSize); and so on for further resizings. To
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3242
     * paranoically cope with potential sharing by users of iterators
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3243
     * across threads, iteration terminates if a bounds checks fails
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3244
     * for a table read.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3245
     */
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3246
    static class Traverser<K,V> {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3247
        Node<K,V>[] tab;        // current table; updated if resized
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3248
        Node<K,V> next;         // the next entry to use
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3249
        int index;              // index of bin to use next
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3250
        int baseIndex;          // current index of initial table
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3251
        int baseLimit;          // index bound for initial table
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3252
        final int baseSize;     // initial table size
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3253
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3254
        Traverser(Node<K,V>[] tab, int size, int index, int limit) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3255
            this.tab = tab;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3256
            this.baseSize = size;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3257
            this.baseIndex = this.index = index;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3258
            this.baseLimit = limit;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3259
            this.next = null;
9279
5f5d493d30a0 7036559: ConcurrentHashMap footprint and contention improvements
dl
parents: 9242
diff changeset
  3260
        }
5f5d493d30a0 7036559: ConcurrentHashMap footprint and contention improvements
dl
parents: 9242
diff changeset
  3261
5f5d493d30a0 7036559: ConcurrentHashMap footprint and contention improvements
dl
parents: 9242
diff changeset
  3262
        /**
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3263
         * Advances if possible, returning next valid node, or null if none.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3264
         */
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3265
        final Node<K,V> advance() {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3266
            Node<K,V> e;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3267
            if ((e = next) != null)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3268
                e = e.next;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3269
            for (;;) {
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3270
                Node<K,V>[] t; int i, n; K ek;  // must use locals in checks
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3271
                if (e != null)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3272
                    return next = e;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3273
                if (baseIndex >= baseLimit || (t = tab) == null ||
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3274
                    (n = t.length) <= (i = index) || i < 0)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3275
                    return next = null;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3276
                if ((e = tabAt(t, index)) != null && e.hash < 0) {
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3277
                    if (e instanceof ForwardingNode) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3278
                        tab = ((ForwardingNode<K,V>)e).nextTable;
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3279
                        e = null;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3280
                        continue;
9279
5f5d493d30a0 7036559: ConcurrentHashMap footprint and contention improvements
dl
parents: 9242
diff changeset
  3281
                    }
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3282
                    else if (e instanceof TreeBin)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3283
                        e = ((TreeBin<K,V>)e).first;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3284
                    else
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3285
                        e = null;
9279
5f5d493d30a0 7036559: ConcurrentHashMap footprint and contention improvements
dl
parents: 9242
diff changeset
  3286
                }
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3287
                if ((index += baseSize) >= n)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3288
                    index = ++baseIndex;    // visit upper slots if present
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3289
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3290
        }
9279
5f5d493d30a0 7036559: ConcurrentHashMap footprint and contention improvements
dl
parents: 9242
diff changeset
  3291
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3292
9279
5f5d493d30a0 7036559: ConcurrentHashMap footprint and contention improvements
dl
parents: 9242
diff changeset
  3293
    /**
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3294
     * Base of key, value, and entry Iterators. Adds fields to
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3295
     * Traverser to support iterator.remove.
9279
5f5d493d30a0 7036559: ConcurrentHashMap footprint and contention improvements
dl
parents: 9242
diff changeset
  3296
     */
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3297
    static class BaseIterator<K,V> extends Traverser<K,V> {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3298
        final ConcurrentHashMap<K,V> map;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3299
        Node<K,V> lastReturned;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3300
        BaseIterator(Node<K,V>[] tab, int size, int index, int limit,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3301
                    ConcurrentHashMap<K,V> map) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3302
            super(tab, size, index, limit);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3303
            this.map = map;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3304
            advance();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3305
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3306
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3307
        public final boolean hasNext() { return next != null; }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3308
        public final boolean hasMoreElements() { return next != null; }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3309
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3310
        public final void remove() {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3311
            Node<K,V> p;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3312
            if ((p = lastReturned) == null)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3313
                throw new IllegalStateException();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3314
            lastReturned = null;
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3315
            map.replaceNode(p.key, null, null);
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3316
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3317
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3318
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3319
    static final class KeyIterator<K,V> extends BaseIterator<K,V>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3320
        implements Iterator<K>, Enumeration<K> {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3321
        KeyIterator(Node<K,V>[] tab, int index, int size, int limit,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3322
                    ConcurrentHashMap<K,V> map) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3323
            super(tab, index, size, limit, map);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3324
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3325
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3326
        public final K next() {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3327
            Node<K,V> p;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3328
            if ((p = next) == null)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3329
                throw new NoSuchElementException();
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3330
            K k = p.key;
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3331
            lastReturned = p;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3332
            advance();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3333
            return k;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3334
        }
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3335
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3336
        public final K nextElement() { return next(); }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3337
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3338
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3339
    static final class ValueIterator<K,V> extends BaseIterator<K,V>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3340
        implements Iterator<V>, Enumeration<V> {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3341
        ValueIterator(Node<K,V>[] tab, int index, int size, int limit,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3342
                      ConcurrentHashMap<K,V> map) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3343
            super(tab, index, size, limit, map);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3344
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3345
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3346
        public final V next() {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3347
            Node<K,V> p;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3348
            if ((p = next) == null)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3349
                throw new NoSuchElementException();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3350
            V v = p.val;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3351
            lastReturned = p;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3352
            advance();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3353
            return v;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3354
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3355
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3356
        public final V nextElement() { return next(); }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3357
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3358
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3359
    static final class EntryIterator<K,V> extends BaseIterator<K,V>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3360
        implements Iterator<Map.Entry<K,V>> {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3361
        EntryIterator(Node<K,V>[] tab, int index, int size, int limit,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3362
                      ConcurrentHashMap<K,V> map) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3363
            super(tab, index, size, limit, map);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3364
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3365
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3366
        public final Map.Entry<K,V> next() {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3367
            Node<K,V> p;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3368
            if ((p = next) == null)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3369
                throw new NoSuchElementException();
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3370
            K k = p.key;
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3371
            V v = p.val;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3372
            lastReturned = p;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3373
            advance();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3374
            return new MapEntry<K,V>(k, v, map);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3375
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3376
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3377
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3378
    /**
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3379
     * Exported Entry for EntryIterator
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3380
     */
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3381
    static final class MapEntry<K,V> implements Map.Entry<K,V> {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3382
        final K key; // non-null
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3383
        V val;       // non-null
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3384
        final ConcurrentHashMap<K,V> map;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3385
        MapEntry(K key, V val, ConcurrentHashMap<K,V> map) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3386
            this.key = key;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3387
            this.val = val;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3388
            this.map = map;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3389
        }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3390
        public K getKey()        { return key; }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3391
        public V getValue()      { return val; }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3392
        public int hashCode()    { return key.hashCode() ^ val.hashCode(); }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3393
        public String toString() { return key + "=" + val; }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3394
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3395
        public boolean equals(Object o) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3396
            Object k, v; Map.Entry<?,?> e;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3397
            return ((o instanceof Map.Entry) &&
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3398
                    (k = (e = (Map.Entry<?,?>)o).getKey()) != null &&
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3399
                    (v = e.getValue()) != null &&
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3400
                    (k == key || k.equals(key)) &&
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3401
                    (v == val || v.equals(val)));
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3402
        }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3403
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3404
        /**
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3405
         * Sets our entry's value and writes through to the map. The
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3406
         * value to return is somewhat arbitrary here. Since we do not
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3407
         * necessarily track asynchronous changes, the most recent
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3408
         * "previous" value could be different from what we return (or
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3409
         * could even have been removed, in which case the put will
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3410
         * re-establish). We do not and cannot guarantee more.
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3411
         */
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3412
        public V setValue(V value) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3413
            if (value == null) throw new NullPointerException();
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3414
            V v = val;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3415
            val = value;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3416
            map.put(key, value);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3417
            return v;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3418
        }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3419
    }
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3420
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3421
    static final class KeySpliterator<K,V> extends Traverser<K,V>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3422
        implements Spliterator<K> {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3423
        long est;               // size estimate
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3424
        KeySpliterator(Node<K,V>[] tab, int size, int index, int limit,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3425
                       long est) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3426
            super(tab, size, index, limit);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3427
            this.est = est;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3428
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3429
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3430
        public Spliterator<K> trySplit() {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3431
            int i, f, h;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3432
            return (h = ((i = baseIndex) + (f = baseLimit)) >>> 1) <= i ? null :
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3433
                new KeySpliterator<K,V>(tab, baseSize, baseLimit = h,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3434
                                        f, est >>>= 1);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3435
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3436
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3437
        public void forEachRemaining(Consumer<? super K> action) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3438
            if (action == null) throw new NullPointerException();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3439
            for (Node<K,V> p; (p = advance()) != null;)
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3440
                action.accept(p.key);
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3441
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3442
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3443
        public boolean tryAdvance(Consumer<? super K> action) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3444
            if (action == null) throw new NullPointerException();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3445
            Node<K,V> p;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3446
            if ((p = advance()) == null)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3447
                return false;
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3448
            action.accept(p.key);
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3449
            return true;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3450
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3451
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3452
        public long estimateSize() { return est; }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3453
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3454
        public int characteristics() {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3455
            return Spliterator.DISTINCT | Spliterator.CONCURRENT |
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3456
                Spliterator.NONNULL;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3457
        }
9279
5f5d493d30a0 7036559: ConcurrentHashMap footprint and contention improvements
dl
parents: 9242
diff changeset
  3458
    }
5f5d493d30a0 7036559: ConcurrentHashMap footprint and contention improvements
dl
parents: 9242
diff changeset
  3459
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3460
    static final class ValueSpliterator<K,V> extends Traverser<K,V>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3461
        implements Spliterator<V> {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3462
        long est;               // size estimate
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3463
        ValueSpliterator(Node<K,V>[] tab, int size, int index, int limit,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3464
                         long est) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3465
            super(tab, size, index, limit);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3466
            this.est = est;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3467
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3468
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3469
        public Spliterator<V> trySplit() {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3470
            int i, f, h;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3471
            return (h = ((i = baseIndex) + (f = baseLimit)) >>> 1) <= i ? null :
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3472
                new ValueSpliterator<K,V>(tab, baseSize, baseLimit = h,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3473
                                          f, est >>>= 1);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3474
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3475
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3476
        public void forEachRemaining(Consumer<? super V> action) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3477
            if (action == null) throw new NullPointerException();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3478
            for (Node<K,V> p; (p = advance()) != null;)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3479
                action.accept(p.val);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3480
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3481
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3482
        public boolean tryAdvance(Consumer<? super V> action) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3483
            if (action == null) throw new NullPointerException();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3484
            Node<K,V> p;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3485
            if ((p = advance()) == null)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3486
                return false;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3487
            action.accept(p.val);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3488
            return true;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3489
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3490
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3491
        public long estimateSize() { return est; }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3492
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3493
        public int characteristics() {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3494
            return Spliterator.CONCURRENT | Spliterator.NONNULL;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3495
        }
9279
5f5d493d30a0 7036559: ConcurrentHashMap footprint and contention improvements
dl
parents: 9242
diff changeset
  3496
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3497
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3498
    static final class EntrySpliterator<K,V> extends Traverser<K,V>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3499
        implements Spliterator<Map.Entry<K,V>> {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3500
        final ConcurrentHashMap<K,V> map; // To export MapEntry
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3501
        long est;               // size estimate
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3502
        EntrySpliterator(Node<K,V>[] tab, int size, int index, int limit,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3503
                         long est, ConcurrentHashMap<K,V> map) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3504
            super(tab, size, index, limit);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3505
            this.map = map;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3506
            this.est = est;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3507
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3508
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3509
        public Spliterator<Map.Entry<K,V>> trySplit() {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3510
            int i, f, h;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3511
            return (h = ((i = baseIndex) + (f = baseLimit)) >>> 1) <= i ? null :
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3512
                new EntrySpliterator<K,V>(tab, baseSize, baseLimit = h,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3513
                                          f, est >>>= 1, map);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3514
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3515
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3516
        public void forEachRemaining(Consumer<? super Map.Entry<K,V>> action) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3517
            if (action == null) throw new NullPointerException();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3518
            for (Node<K,V> p; (p = advance()) != null; )
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3519
                action.accept(new MapEntry<K,V>(p.key, p.val, map));
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3520
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3521
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3522
        public boolean tryAdvance(Consumer<? super Map.Entry<K,V>> action) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3523
            if (action == null) throw new NullPointerException();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3524
            Node<K,V> p;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3525
            if ((p = advance()) == null)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3526
                return false;
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3527
            action.accept(new MapEntry<K,V>(p.key, p.val, map));
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3528
            return true;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3529
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3530
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3531
        public long estimateSize() { return est; }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3532
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3533
        public int characteristics() {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3534
            return Spliterator.DISTINCT | Spliterator.CONCURRENT |
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3535
                Spliterator.NONNULL;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3536
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3537
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3538
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3539
    // Parallel bulk operations
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3540
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3541
    /**
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3542
     * Computes initial batch value for bulk tasks. The returned value
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3543
     * is approximately exp2 of the number of times (minus one) to
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3544
     * split task by two before executing leaf action. This value is
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3545
     * faster to compute and more convenient to use as a guide to
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3546
     * splitting than is the depth, since it is used while dividing by
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3547
     * two anyway.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3548
     */
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3549
    final int batchFor(long b) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3550
        long n;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3551
        if (b == Long.MAX_VALUE || (n = sumCount()) <= 1L || n < b)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3552
            return 0;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3553
        int sp = ForkJoinPool.getCommonPoolParallelism() << 2; // slack of 4
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3554
        return (b <= 0L || (n /= b) >= sp) ? sp : (int)n;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3555
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3556
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3557
    /**
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3558
     * Performs the given action for each (key, value).
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3559
     *
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3560
     * @param parallelismThreshold the (estimated) number of elements
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3561
     * needed for this operation to be executed in parallel
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3562
     * @param action the action
17953
9a56976d1ab2 8015963: Add at since tags to new ConcurrentHashMap methods
chegar
parents: 17945
diff changeset
  3563
     * @since 1.8
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3564
     */
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3565
    public void forEach(long parallelismThreshold,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3566
                        BiConsumer<? super K,? super V> action) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3567
        if (action == null) throw new NullPointerException();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3568
        new ForEachMappingTask<K,V>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3569
            (null, batchFor(parallelismThreshold), 0, 0, table,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3570
             action).invoke();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3571
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3572
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3573
    /**
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3574
     * Performs the given action for each non-null transformation
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3575
     * of each (key, value).
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3576
     *
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3577
     * @param parallelismThreshold the (estimated) number of elements
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3578
     * needed for this operation to be executed in parallel
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3579
     * @param transformer a function returning the transformation
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3580
     * for an element, or null if there is no transformation (in
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3581
     * which case the action is not applied)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3582
     * @param action the action
19036
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
  3583
     * @param <U> the return type of the transformer
17953
9a56976d1ab2 8015963: Add at since tags to new ConcurrentHashMap methods
chegar
parents: 17945
diff changeset
  3584
     * @since 1.8
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3585
     */
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3586
    public <U> void forEach(long parallelismThreshold,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3587
                            BiFunction<? super K, ? super V, ? extends U> transformer,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3588
                            Consumer<? super U> action) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3589
        if (transformer == null || action == null)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3590
            throw new NullPointerException();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3591
        new ForEachTransformedMappingTask<K,V,U>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3592
            (null, batchFor(parallelismThreshold), 0, 0, table,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3593
             transformer, action).invoke();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3594
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3595
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3596
    /**
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3597
     * Returns a non-null result from applying the given search
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3598
     * function on each (key, value), or null if none.  Upon
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3599
     * success, further element processing is suppressed and the
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3600
     * results of any other parallel invocations of the search
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3601
     * function are ignored.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3602
     *
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3603
     * @param parallelismThreshold the (estimated) number of elements
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3604
     * needed for this operation to be executed in parallel
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3605
     * @param searchFunction a function returning a non-null
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3606
     * result on success, else null
19036
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
  3607
     * @param <U> the return type of the search function
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3608
     * @return a non-null result from applying the given search
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3609
     * function on each (key, value), or null if none
17953
9a56976d1ab2 8015963: Add at since tags to new ConcurrentHashMap methods
chegar
parents: 17945
diff changeset
  3610
     * @since 1.8
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3611
     */
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3612
    public <U> U search(long parallelismThreshold,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3613
                        BiFunction<? super K, ? super V, ? extends U> searchFunction) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3614
        if (searchFunction == null) throw new NullPointerException();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3615
        return new SearchMappingsTask<K,V,U>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3616
            (null, batchFor(parallelismThreshold), 0, 0, table,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3617
             searchFunction, new AtomicReference<U>()).invoke();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3618
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3619
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3620
    /**
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3621
     * Returns the result of accumulating the given transformation
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3622
     * of all (key, value) pairs using the given reducer to
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3623
     * combine values, or null if none.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3624
     *
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3625
     * @param parallelismThreshold the (estimated) number of elements
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3626
     * needed for this operation to be executed in parallel
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3627
     * @param transformer a function returning the transformation
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3628
     * for an element, or null if there is no transformation (in
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3629
     * which case it is not combined)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3630
     * @param reducer a commutative associative combining function
19036
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
  3631
     * @param <U> the return type of the transformer
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3632
     * @return the result of accumulating the given transformation
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3633
     * of all (key, value) pairs
17953
9a56976d1ab2 8015963: Add at since tags to new ConcurrentHashMap methods
chegar
parents: 17945
diff changeset
  3634
     * @since 1.8
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3635
     */
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3636
    public <U> U reduce(long parallelismThreshold,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3637
                        BiFunction<? super K, ? super V, ? extends U> transformer,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3638
                        BiFunction<? super U, ? super U, ? extends U> reducer) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3639
        if (transformer == null || reducer == null)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3640
            throw new NullPointerException();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3641
        return new MapReduceMappingsTask<K,V,U>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3642
            (null, batchFor(parallelismThreshold), 0, 0, table,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3643
             null, transformer, reducer).invoke();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3644
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3645
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3646
    /**
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3647
     * Returns the result of accumulating the given transformation
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3648
     * of all (key, value) pairs using the given reducer to
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3649
     * combine values, and the given basis as an identity value.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3650
     *
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3651
     * @param parallelismThreshold the (estimated) number of elements
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3652
     * needed for this operation to be executed in parallel
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3653
     * @param transformer a function returning the transformation
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3654
     * for an element
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3655
     * @param basis the identity (initial default value) for the reduction
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3656
     * @param reducer a commutative associative combining function
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3657
     * @return the result of accumulating the given transformation
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3658
     * of all (key, value) pairs
17953
9a56976d1ab2 8015963: Add at since tags to new ConcurrentHashMap methods
chegar
parents: 17945
diff changeset
  3659
     * @since 1.8
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3660
     */
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3661
    public double reduceToDouble(long parallelismThreshold,
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3662
                                 ToDoubleBiFunction<? super K, ? super V> transformer,
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3663
                                 double basis,
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  3664
                                 DoubleBinaryOperator reducer) {
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3665
        if (transformer == null || reducer == null)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3666
            throw new NullPointerException();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3667
        return new MapReduceMappingsToDoubleTask<K,V>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3668
            (null, batchFor(parallelismThreshold), 0, 0, table,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3669
             null, transformer, basis, reducer).invoke();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3670
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3671
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3672
    /**
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3673
     * Returns the result of accumulating the given transformation
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3674
     * of all (key, value) pairs using the given reducer to
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3675
     * combine values, and the given basis as an identity value.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3676
     *
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3677
     * @param parallelismThreshold the (estimated) number of elements
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3678
     * needed for this operation to be executed in parallel
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3679
     * @param transformer a function returning the transformation
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3680
     * for an element
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3681
     * @param basis the identity (initial default value) for the reduction
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3682
     * @param reducer a commutative associative combining function
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3683
     * @return the result of accumulating the given transformation
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3684
     * of all (key, value) pairs
17953
9a56976d1ab2 8015963: Add at since tags to new ConcurrentHashMap methods
chegar
parents: 17945
diff changeset
  3685
     * @since 1.8
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3686
     */
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3687
    public long reduceToLong(long parallelismThreshold,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3688
                             ToLongBiFunction<? super K, ? super V> transformer,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3689
                             long basis,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3690
                             LongBinaryOperator reducer) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3691
        if (transformer == null || reducer == null)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3692
            throw new NullPointerException();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3693
        return new MapReduceMappingsToLongTask<K,V>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3694
            (null, batchFor(parallelismThreshold), 0, 0, table,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3695
             null, transformer, basis, reducer).invoke();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3696
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3697
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3698
    /**
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3699
     * Returns the result of accumulating the given transformation
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3700
     * of all (key, value) pairs using the given reducer to
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3701
     * combine values, and the given basis as an identity value.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3702
     *
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3703
     * @param parallelismThreshold the (estimated) number of elements
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3704
     * needed for this operation to be executed in parallel
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3705
     * @param transformer a function returning the transformation
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3706
     * for an element
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3707
     * @param basis the identity (initial default value) for the reduction
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3708
     * @param reducer a commutative associative combining function
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3709
     * @return the result of accumulating the given transformation
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3710
     * of all (key, value) pairs
17953
9a56976d1ab2 8015963: Add at since tags to new ConcurrentHashMap methods
chegar
parents: 17945
diff changeset
  3711
     * @since 1.8
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3712
     */
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3713
    public int reduceToInt(long parallelismThreshold,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3714
                           ToIntBiFunction<? super K, ? super V> transformer,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3715
                           int basis,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3716
                           IntBinaryOperator reducer) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3717
        if (transformer == null || reducer == null)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3718
            throw new NullPointerException();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3719
        return new MapReduceMappingsToIntTask<K,V>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3720
            (null, batchFor(parallelismThreshold), 0, 0, table,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3721
             null, transformer, basis, reducer).invoke();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3722
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3723
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3724
    /**
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3725
     * Performs the given action for each key.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3726
     *
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3727
     * @param parallelismThreshold the (estimated) number of elements
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3728
     * needed for this operation to be executed in parallel
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3729
     * @param action the action
17953
9a56976d1ab2 8015963: Add at since tags to new ConcurrentHashMap methods
chegar
parents: 17945
diff changeset
  3730
     * @since 1.8
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3731
     */
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3732
    public void forEachKey(long parallelismThreshold,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3733
                           Consumer<? super K> action) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3734
        if (action == null) throw new NullPointerException();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3735
        new ForEachKeyTask<K,V>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3736
            (null, batchFor(parallelismThreshold), 0, 0, table,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3737
             action).invoke();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3738
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3739
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3740
    /**
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3741
     * Performs the given action for each non-null transformation
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3742
     * of each key.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3743
     *
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3744
     * @param parallelismThreshold the (estimated) number of elements
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3745
     * needed for this operation to be executed in parallel
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3746
     * @param transformer a function returning the transformation
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3747
     * for an element, or null if there is no transformation (in
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3748
     * which case the action is not applied)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3749
     * @param action the action
19036
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
  3750
     * @param <U> the return type of the transformer
17953
9a56976d1ab2 8015963: Add at since tags to new ConcurrentHashMap methods
chegar
parents: 17945
diff changeset
  3751
     * @since 1.8
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3752
     */
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3753
    public <U> void forEachKey(long parallelismThreshold,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3754
                               Function<? super K, ? extends U> transformer,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3755
                               Consumer<? super U> action) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3756
        if (transformer == null || action == null)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3757
            throw new NullPointerException();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3758
        new ForEachTransformedKeyTask<K,V,U>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3759
            (null, batchFor(parallelismThreshold), 0, 0, table,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3760
             transformer, action).invoke();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3761
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3762
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3763
    /**
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3764
     * Returns a non-null result from applying the given search
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3765
     * function on each key, or null if none. Upon success,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3766
     * further element processing is suppressed and the results of
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3767
     * any other parallel invocations of the search function are
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3768
     * ignored.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3769
     *
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3770
     * @param parallelismThreshold the (estimated) number of elements
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3771
     * needed for this operation to be executed in parallel
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3772
     * @param searchFunction a function returning a non-null
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3773
     * result on success, else null
19036
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
  3774
     * @param <U> the return type of the search function
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3775
     * @return a non-null result from applying the given search
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3776
     * function on each key, or null if none
17953
9a56976d1ab2 8015963: Add at since tags to new ConcurrentHashMap methods
chegar
parents: 17945
diff changeset
  3777
     * @since 1.8
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3778
     */
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3779
    public <U> U searchKeys(long parallelismThreshold,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3780
                            Function<? super K, ? extends U> searchFunction) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3781
        if (searchFunction == null) throw new NullPointerException();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3782
        return new SearchKeysTask<K,V,U>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3783
            (null, batchFor(parallelismThreshold), 0, 0, table,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3784
             searchFunction, new AtomicReference<U>()).invoke();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3785
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3786
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3787
    /**
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3788
     * Returns the result of accumulating all keys using the given
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3789
     * reducer to combine values, or null if none.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3790
     *
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3791
     * @param parallelismThreshold the (estimated) number of elements
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3792
     * needed for this operation to be executed in parallel
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3793
     * @param reducer a commutative associative combining function
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3794
     * @return the result of accumulating all keys using the given
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3795
     * reducer to combine values, or null if none
17953
9a56976d1ab2 8015963: Add at since tags to new ConcurrentHashMap methods
chegar
parents: 17945
diff changeset
  3796
     * @since 1.8
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3797
     */
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3798
    public K reduceKeys(long parallelismThreshold,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3799
                        BiFunction<? super K, ? super K, ? extends K> reducer) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3800
        if (reducer == null) throw new NullPointerException();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3801
        return new ReduceKeysTask<K,V>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3802
            (null, batchFor(parallelismThreshold), 0, 0, table,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3803
             null, reducer).invoke();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3804
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3805
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3806
    /**
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3807
     * Returns the result of accumulating the given transformation
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3808
     * of all keys using the given reducer to combine values, or
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3809
     * null if none.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3810
     *
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3811
     * @param parallelismThreshold the (estimated) number of elements
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3812
     * needed for this operation to be executed in parallel
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3813
     * @param transformer a function returning the transformation
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3814
     * for an element, or null if there is no transformation (in
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3815
     * which case it is not combined)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3816
     * @param reducer a commutative associative combining function
19036
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
  3817
     * @param <U> the return type of the transformer
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3818
     * @return the result of accumulating the given transformation
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3819
     * of all keys
17953
9a56976d1ab2 8015963: Add at since tags to new ConcurrentHashMap methods
chegar
parents: 17945
diff changeset
  3820
     * @since 1.8
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3821
     */
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3822
    public <U> U reduceKeys(long parallelismThreshold,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3823
                            Function<? super K, ? extends U> transformer,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3824
         BiFunction<? super U, ? super U, ? extends U> reducer) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3825
        if (transformer == null || reducer == null)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3826
            throw new NullPointerException();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3827
        return new MapReduceKeysTask<K,V,U>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3828
            (null, batchFor(parallelismThreshold), 0, 0, table,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3829
             null, transformer, reducer).invoke();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3830
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3831
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3832
    /**
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3833
     * Returns the result of accumulating the given transformation
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3834
     * of all keys using the given reducer to combine values, and
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3835
     * the given basis as an identity value.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3836
     *
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3837
     * @param parallelismThreshold the (estimated) number of elements
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3838
     * needed for this operation to be executed in parallel
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3839
     * @param transformer a function returning the transformation
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3840
     * for an element
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3841
     * @param basis the identity (initial default value) for the reduction
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3842
     * @param reducer a commutative associative combining function
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3843
     * @return the result of accumulating the given transformation
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3844
     * of all keys
17953
9a56976d1ab2 8015963: Add at since tags to new ConcurrentHashMap methods
chegar
parents: 17945
diff changeset
  3845
     * @since 1.8
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3846
     */
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3847
    public double reduceKeysToDouble(long parallelismThreshold,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3848
                                     ToDoubleFunction<? super K> transformer,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3849
                                     double basis,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3850
                                     DoubleBinaryOperator reducer) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3851
        if (transformer == null || reducer == null)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3852
            throw new NullPointerException();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3853
        return new MapReduceKeysToDoubleTask<K,V>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3854
            (null, batchFor(parallelismThreshold), 0, 0, table,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3855
             null, transformer, basis, reducer).invoke();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3856
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3857
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3858
    /**
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3859
     * Returns the result of accumulating the given transformation
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3860
     * of all keys using the given reducer to combine values, and
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3861
     * the given basis as an identity value.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3862
     *
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3863
     * @param parallelismThreshold the (estimated) number of elements
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3864
     * needed for this operation to be executed in parallel
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3865
     * @param transformer a function returning the transformation
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3866
     * for an element
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3867
     * @param basis the identity (initial default value) for the reduction
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3868
     * @param reducer a commutative associative combining function
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3869
     * @return the result of accumulating the given transformation
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3870
     * of all keys
17953
9a56976d1ab2 8015963: Add at since tags to new ConcurrentHashMap methods
chegar
parents: 17945
diff changeset
  3871
     * @since 1.8
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3872
     */
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3873
    public long reduceKeysToLong(long parallelismThreshold,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3874
                                 ToLongFunction<? super K> transformer,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3875
                                 long basis,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3876
                                 LongBinaryOperator reducer) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3877
        if (transformer == null || reducer == null)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3878
            throw new NullPointerException();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3879
        return new MapReduceKeysToLongTask<K,V>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3880
            (null, batchFor(parallelismThreshold), 0, 0, table,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3881
             null, transformer, basis, reducer).invoke();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3882
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3883
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3884
    /**
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3885
     * Returns the result of accumulating the given transformation
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3886
     * of all keys using the given reducer to combine values, and
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3887
     * the given basis as an identity value.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3888
     *
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3889
     * @param parallelismThreshold the (estimated) number of elements
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3890
     * needed for this operation to be executed in parallel
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3891
     * @param transformer a function returning the transformation
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3892
     * for an element
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3893
     * @param basis the identity (initial default value) for the reduction
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3894
     * @param reducer a commutative associative combining function
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3895
     * @return the result of accumulating the given transformation
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3896
     * of all keys
17953
9a56976d1ab2 8015963: Add at since tags to new ConcurrentHashMap methods
chegar
parents: 17945
diff changeset
  3897
     * @since 1.8
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3898
     */
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3899
    public int reduceKeysToInt(long parallelismThreshold,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3900
                               ToIntFunction<? super K> transformer,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3901
                               int basis,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3902
                               IntBinaryOperator reducer) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3903
        if (transformer == null || reducer == null)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3904
            throw new NullPointerException();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3905
        return new MapReduceKeysToIntTask<K,V>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3906
            (null, batchFor(parallelismThreshold), 0, 0, table,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3907
             null, transformer, basis, reducer).invoke();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3908
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3909
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3910
    /**
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3911
     * Performs the given action for each value.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3912
     *
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3913
     * @param parallelismThreshold the (estimated) number of elements
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3914
     * needed for this operation to be executed in parallel
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3915
     * @param action the action
17953
9a56976d1ab2 8015963: Add at since tags to new ConcurrentHashMap methods
chegar
parents: 17945
diff changeset
  3916
     * @since 1.8
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3917
     */
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3918
    public void forEachValue(long parallelismThreshold,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3919
                             Consumer<? super V> action) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3920
        if (action == null)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3921
            throw new NullPointerException();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3922
        new ForEachValueTask<K,V>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3923
            (null, batchFor(parallelismThreshold), 0, 0, table,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3924
             action).invoke();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3925
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3926
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3927
    /**
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3928
     * Performs the given action for each non-null transformation
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3929
     * of each value.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3930
     *
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3931
     * @param parallelismThreshold the (estimated) number of elements
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3932
     * needed for this operation to be executed in parallel
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3933
     * @param transformer a function returning the transformation
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3934
     * for an element, or null if there is no transformation (in
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3935
     * which case the action is not applied)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3936
     * @param action the action
19036
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
  3937
     * @param <U> the return type of the transformer
17953
9a56976d1ab2 8015963: Add at since tags to new ConcurrentHashMap methods
chegar
parents: 17945
diff changeset
  3938
     * @since 1.8
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3939
     */
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3940
    public <U> void forEachValue(long parallelismThreshold,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3941
                                 Function<? super V, ? extends U> transformer,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3942
                                 Consumer<? super U> action) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3943
        if (transformer == null || action == null)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3944
            throw new NullPointerException();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3945
        new ForEachTransformedValueTask<K,V,U>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3946
            (null, batchFor(parallelismThreshold), 0, 0, table,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3947
             transformer, action).invoke();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3948
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3949
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3950
    /**
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3951
     * Returns a non-null result from applying the given search
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3952
     * function on each value, or null if none.  Upon success,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3953
     * further element processing is suppressed and the results of
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3954
     * any other parallel invocations of the search function are
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3955
     * ignored.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3956
     *
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3957
     * @param parallelismThreshold the (estimated) number of elements
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3958
     * needed for this operation to be executed in parallel
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3959
     * @param searchFunction a function returning a non-null
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3960
     * result on success, else null
19036
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
  3961
     * @param <U> the return type of the search function
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3962
     * @return a non-null result from applying the given search
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3963
     * function on each value, or null if none
17953
9a56976d1ab2 8015963: Add at since tags to new ConcurrentHashMap methods
chegar
parents: 17945
diff changeset
  3964
     * @since 1.8
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3965
     */
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3966
    public <U> U searchValues(long parallelismThreshold,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3967
                              Function<? super V, ? extends U> searchFunction) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3968
        if (searchFunction == null) throw new NullPointerException();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3969
        return new SearchValuesTask<K,V,U>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3970
            (null, batchFor(parallelismThreshold), 0, 0, table,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3971
             searchFunction, new AtomicReference<U>()).invoke();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3972
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3973
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3974
    /**
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3975
     * Returns the result of accumulating all values using the
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3976
     * given reducer to combine values, or null if none.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3977
     *
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3978
     * @param parallelismThreshold the (estimated) number of elements
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3979
     * needed for this operation to be executed in parallel
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3980
     * @param reducer a commutative associative combining function
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3981
     * @return the result of accumulating all values
17953
9a56976d1ab2 8015963: Add at since tags to new ConcurrentHashMap methods
chegar
parents: 17945
diff changeset
  3982
     * @since 1.8
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3983
     */
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3984
    public V reduceValues(long parallelismThreshold,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3985
                          BiFunction<? super V, ? super V, ? extends V> reducer) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3986
        if (reducer == null) throw new NullPointerException();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3987
        return new ReduceValuesTask<K,V>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3988
            (null, batchFor(parallelismThreshold), 0, 0, table,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3989
             null, reducer).invoke();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3990
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3991
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3992
    /**
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3993
     * Returns the result of accumulating the given transformation
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3994
     * of all values using the given reducer to combine values, or
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3995
     * null if none.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3996
     *
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3997
     * @param parallelismThreshold the (estimated) number of elements
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3998
     * needed for this operation to be executed in parallel
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  3999
     * @param transformer a function returning the transformation
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4000
     * for an element, or null if there is no transformation (in
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4001
     * which case it is not combined)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4002
     * @param reducer a commutative associative combining function
19036
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
  4003
     * @param <U> the return type of the transformer
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4004
     * @return the result of accumulating the given transformation
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4005
     * of all values
17953
9a56976d1ab2 8015963: Add at since tags to new ConcurrentHashMap methods
chegar
parents: 17945
diff changeset
  4006
     * @since 1.8
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4007
     */
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4008
    public <U> U reduceValues(long parallelismThreshold,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4009
                              Function<? super V, ? extends U> transformer,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4010
                              BiFunction<? super U, ? super U, ? extends U> reducer) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4011
        if (transformer == null || reducer == null)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4012
            throw new NullPointerException();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4013
        return new MapReduceValuesTask<K,V,U>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4014
            (null, batchFor(parallelismThreshold), 0, 0, table,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4015
             null, transformer, reducer).invoke();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4016
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4017
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4018
    /**
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4019
     * Returns the result of accumulating the given transformation
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4020
     * of all values using the given reducer to combine values,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4021
     * and the given basis as an identity value.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4022
     *
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4023
     * @param parallelismThreshold the (estimated) number of elements
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4024
     * needed for this operation to be executed in parallel
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4025
     * @param transformer a function returning the transformation
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4026
     * for an element
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4027
     * @param basis the identity (initial default value) for the reduction
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4028
     * @param reducer a commutative associative combining function
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4029
     * @return the result of accumulating the given transformation
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4030
     * of all values
17953
9a56976d1ab2 8015963: Add at since tags to new ConcurrentHashMap methods
chegar
parents: 17945
diff changeset
  4031
     * @since 1.8
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4032
     */
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4033
    public double reduceValuesToDouble(long parallelismThreshold,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4034
                                       ToDoubleFunction<? super V> transformer,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4035
                                       double basis,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4036
                                       DoubleBinaryOperator reducer) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4037
        if (transformer == null || reducer == null)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4038
            throw new NullPointerException();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4039
        return new MapReduceValuesToDoubleTask<K,V>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4040
            (null, batchFor(parallelismThreshold), 0, 0, table,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4041
             null, transformer, basis, reducer).invoke();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4042
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4043
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4044
    /**
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4045
     * Returns the result of accumulating the given transformation
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4046
     * of all values using the given reducer to combine values,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4047
     * and the given basis as an identity value.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4048
     *
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4049
     * @param parallelismThreshold the (estimated) number of elements
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4050
     * needed for this operation to be executed in parallel
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4051
     * @param transformer a function returning the transformation
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4052
     * for an element
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4053
     * @param basis the identity (initial default value) for the reduction
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4054
     * @param reducer a commutative associative combining function
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4055
     * @return the result of accumulating the given transformation
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4056
     * of all values
17953
9a56976d1ab2 8015963: Add at since tags to new ConcurrentHashMap methods
chegar
parents: 17945
diff changeset
  4057
     * @since 1.8
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4058
     */
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4059
    public long reduceValuesToLong(long parallelismThreshold,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4060
                                   ToLongFunction<? super V> transformer,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4061
                                   long basis,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4062
                                   LongBinaryOperator reducer) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4063
        if (transformer == null || reducer == null)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4064
            throw new NullPointerException();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4065
        return new MapReduceValuesToLongTask<K,V>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4066
            (null, batchFor(parallelismThreshold), 0, 0, table,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4067
             null, transformer, basis, reducer).invoke();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4068
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4069
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4070
    /**
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4071
     * Returns the result of accumulating the given transformation
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4072
     * of all values using the given reducer to combine values,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4073
     * and the given basis as an identity value.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4074
     *
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4075
     * @param parallelismThreshold the (estimated) number of elements
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4076
     * needed for this operation to be executed in parallel
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4077
     * @param transformer a function returning the transformation
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4078
     * for an element
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4079
     * @param basis the identity (initial default value) for the reduction
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4080
     * @param reducer a commutative associative combining function
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4081
     * @return the result of accumulating the given transformation
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4082
     * of all values
17953
9a56976d1ab2 8015963: Add at since tags to new ConcurrentHashMap methods
chegar
parents: 17945
diff changeset
  4083
     * @since 1.8
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4084
     */
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4085
    public int reduceValuesToInt(long parallelismThreshold,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4086
                                 ToIntFunction<? super V> transformer,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4087
                                 int basis,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4088
                                 IntBinaryOperator reducer) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4089
        if (transformer == null || reducer == null)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4090
            throw new NullPointerException();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4091
        return new MapReduceValuesToIntTask<K,V>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4092
            (null, batchFor(parallelismThreshold), 0, 0, table,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4093
             null, transformer, basis, reducer).invoke();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4094
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4095
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4096
    /**
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4097
     * Performs the given action for each entry.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4098
     *
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4099
     * @param parallelismThreshold the (estimated) number of elements
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4100
     * needed for this operation to be executed in parallel
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4101
     * @param action the action
17953
9a56976d1ab2 8015963: Add at since tags to new ConcurrentHashMap methods
chegar
parents: 17945
diff changeset
  4102
     * @since 1.8
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4103
     */
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4104
    public void forEachEntry(long parallelismThreshold,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4105
                             Consumer<? super Map.Entry<K,V>> action) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4106
        if (action == null) throw new NullPointerException();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4107
        new ForEachEntryTask<K,V>(null, batchFor(parallelismThreshold), 0, 0, table,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4108
                                  action).invoke();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4109
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4110
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4111
    /**
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4112
     * Performs the given action for each non-null transformation
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4113
     * of each entry.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4114
     *
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4115
     * @param parallelismThreshold the (estimated) number of elements
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4116
     * needed for this operation to be executed in parallel
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4117
     * @param transformer a function returning the transformation
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4118
     * for an element, or null if there is no transformation (in
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4119
     * which case the action is not applied)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4120
     * @param action the action
19036
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
  4121
     * @param <U> the return type of the transformer
17953
9a56976d1ab2 8015963: Add at since tags to new ConcurrentHashMap methods
chegar
parents: 17945
diff changeset
  4122
     * @since 1.8
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4123
     */
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4124
    public <U> void forEachEntry(long parallelismThreshold,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4125
                                 Function<Map.Entry<K,V>, ? extends U> transformer,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4126
                                 Consumer<? super U> action) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4127
        if (transformer == null || action == null)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4128
            throw new NullPointerException();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4129
        new ForEachTransformedEntryTask<K,V,U>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4130
            (null, batchFor(parallelismThreshold), 0, 0, table,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4131
             transformer, action).invoke();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4132
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4133
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4134
    /**
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4135
     * Returns a non-null result from applying the given search
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4136
     * function on each entry, or null if none.  Upon success,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4137
     * further element processing is suppressed and the results of
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4138
     * any other parallel invocations of the search function are
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4139
     * ignored.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4140
     *
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4141
     * @param parallelismThreshold the (estimated) number of elements
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4142
     * needed for this operation to be executed in parallel
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4143
     * @param searchFunction a function returning a non-null
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4144
     * result on success, else null
19036
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
  4145
     * @param <U> the return type of the search function
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4146
     * @return a non-null result from applying the given search
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4147
     * function on each entry, or null if none
17953
9a56976d1ab2 8015963: Add at since tags to new ConcurrentHashMap methods
chegar
parents: 17945
diff changeset
  4148
     * @since 1.8
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4149
     */
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4150
    public <U> U searchEntries(long parallelismThreshold,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4151
                               Function<Map.Entry<K,V>, ? extends U> searchFunction) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4152
        if (searchFunction == null) throw new NullPointerException();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4153
        return new SearchEntriesTask<K,V,U>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4154
            (null, batchFor(parallelismThreshold), 0, 0, table,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4155
             searchFunction, new AtomicReference<U>()).invoke();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4156
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4157
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4158
    /**
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4159
     * Returns the result of accumulating all entries using the
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4160
     * given reducer to combine values, or null if none.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4161
     *
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4162
     * @param parallelismThreshold the (estimated) number of elements
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4163
     * needed for this operation to be executed in parallel
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4164
     * @param reducer a commutative associative combining function
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4165
     * @return the result of accumulating all entries
17953
9a56976d1ab2 8015963: Add at since tags to new ConcurrentHashMap methods
chegar
parents: 17945
diff changeset
  4166
     * @since 1.8
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4167
     */
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4168
    public Map.Entry<K,V> reduceEntries(long parallelismThreshold,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4169
                                        BiFunction<Map.Entry<K,V>, Map.Entry<K,V>, ? extends Map.Entry<K,V>> reducer) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4170
        if (reducer == null) throw new NullPointerException();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4171
        return new ReduceEntriesTask<K,V>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4172
            (null, batchFor(parallelismThreshold), 0, 0, table,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4173
             null, reducer).invoke();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4174
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4175
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4176
    /**
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4177
     * Returns the result of accumulating the given transformation
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4178
     * of all entries using the given reducer to combine values,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4179
     * or null if none.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4180
     *
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4181
     * @param parallelismThreshold the (estimated) number of elements
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4182
     * needed for this operation to be executed in parallel
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4183
     * @param transformer a function returning the transformation
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4184
     * for an element, or null if there is no transformation (in
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4185
     * which case it is not combined)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4186
     * @param reducer a commutative associative combining function
19036
7e9050510b51 8020976: Ensure consistent insertion for ConcurrentHashMap
dl
parents: 18802
diff changeset
  4187
     * @param <U> the return type of the transformer
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4188
     * @return the result of accumulating the given transformation
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4189
     * of all entries
17953
9a56976d1ab2 8015963: Add at since tags to new ConcurrentHashMap methods
chegar
parents: 17945
diff changeset
  4190
     * @since 1.8
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4191
     */
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4192
    public <U> U reduceEntries(long parallelismThreshold,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4193
                               Function<Map.Entry<K,V>, ? extends U> transformer,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4194
                               BiFunction<? super U, ? super U, ? extends U> reducer) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4195
        if (transformer == null || reducer == null)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4196
            throw new NullPointerException();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4197
        return new MapReduceEntriesTask<K,V,U>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4198
            (null, batchFor(parallelismThreshold), 0, 0, table,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4199
             null, transformer, reducer).invoke();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4200
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4201
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4202
    /**
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4203
     * Returns the result of accumulating the given transformation
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4204
     * of all entries using the given reducer to combine values,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4205
     * and the given basis as an identity value.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4206
     *
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4207
     * @param parallelismThreshold the (estimated) number of elements
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4208
     * needed for this operation to be executed in parallel
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4209
     * @param transformer a function returning the transformation
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4210
     * for an element
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4211
     * @param basis the identity (initial default value) for the reduction
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4212
     * @param reducer a commutative associative combining function
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4213
     * @return the result of accumulating the given transformation
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4214
     * of all entries
17953
9a56976d1ab2 8015963: Add at since tags to new ConcurrentHashMap methods
chegar
parents: 17945
diff changeset
  4215
     * @since 1.8
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4216
     */
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4217
    public double reduceEntriesToDouble(long parallelismThreshold,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4218
                                        ToDoubleFunction<Map.Entry<K,V>> transformer,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4219
                                        double basis,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4220
                                        DoubleBinaryOperator reducer) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4221
        if (transformer == null || reducer == null)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4222
            throw new NullPointerException();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4223
        return new MapReduceEntriesToDoubleTask<K,V>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4224
            (null, batchFor(parallelismThreshold), 0, 0, table,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4225
             null, transformer, basis, reducer).invoke();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4226
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4227
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4228
    /**
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4229
     * Returns the result of accumulating the given transformation
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4230
     * of all entries using the given reducer to combine values,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4231
     * and the given basis as an identity value.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4232
     *
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4233
     * @param parallelismThreshold the (estimated) number of elements
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4234
     * needed for this operation to be executed in parallel
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4235
     * @param transformer a function returning the transformation
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4236
     * for an element
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4237
     * @param basis the identity (initial default value) for the reduction
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4238
     * @param reducer a commutative associative combining function
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4239
     * @return the result of accumulating the given transformation
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4240
     * of all entries
17953
9a56976d1ab2 8015963: Add at since tags to new ConcurrentHashMap methods
chegar
parents: 17945
diff changeset
  4241
     * @since 1.8
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4242
     */
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4243
    public long reduceEntriesToLong(long parallelismThreshold,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4244
                                    ToLongFunction<Map.Entry<K,V>> transformer,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4245
                                    long basis,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4246
                                    LongBinaryOperator reducer) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4247
        if (transformer == null || reducer == null)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4248
            throw new NullPointerException();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4249
        return new MapReduceEntriesToLongTask<K,V>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4250
            (null, batchFor(parallelismThreshold), 0, 0, table,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4251
             null, transformer, basis, reducer).invoke();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4252
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4253
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4254
    /**
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4255
     * Returns the result of accumulating the given transformation
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4256
     * of all entries using the given reducer to combine values,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4257
     * and the given basis as an identity value.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4258
     *
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4259
     * @param parallelismThreshold the (estimated) number of elements
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4260
     * needed for this operation to be executed in parallel
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4261
     * @param transformer a function returning the transformation
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4262
     * for an element
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4263
     * @param basis the identity (initial default value) for the reduction
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4264
     * @param reducer a commutative associative combining function
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4265
     * @return the result of accumulating the given transformation
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4266
     * of all entries
17953
9a56976d1ab2 8015963: Add at since tags to new ConcurrentHashMap methods
chegar
parents: 17945
diff changeset
  4267
     * @since 1.8
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4268
     */
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4269
    public int reduceEntriesToInt(long parallelismThreshold,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4270
                                  ToIntFunction<Map.Entry<K,V>> transformer,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4271
                                  int basis,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4272
                                  IntBinaryOperator reducer) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4273
        if (transformer == null || reducer == null)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4274
            throw new NullPointerException();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4275
        return new MapReduceEntriesToIntTask<K,V>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4276
            (null, batchFor(parallelismThreshold), 0, 0, table,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4277
             null, transformer, basis, reducer).invoke();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4278
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4279
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4280
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4281
    /* ----------------Views -------------- */
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4282
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4283
    /**
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4284
     * Base class for views.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4285
     */
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4286
    abstract static class CollectionView<K,V,E>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4287
        implements Collection<E>, java.io.Serializable {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4288
        private static final long serialVersionUID = 7249069246763182397L;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4289
        final ConcurrentHashMap<K,V> map;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4290
        CollectionView(ConcurrentHashMap<K,V> map)  { this.map = map; }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4291
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4292
        /**
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4293
         * Returns the map backing this view.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4294
         *
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4295
         * @return the map backing this view
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4296
         */
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4297
        public ConcurrentHashMap<K,V> getMap() { return map; }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4298
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4299
        /**
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4300
         * Removes all of the elements from this view, by removing all
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4301
         * the mappings from the map backing this view.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4302
         */
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4303
        public final void clear()      { map.clear(); }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4304
        public final int size()        { return map.size(); }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4305
        public final boolean isEmpty() { return map.isEmpty(); }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4306
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4307
        // implementations below rely on concrete classes supplying these
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4308
        // abstract methods
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4309
        /**
19428
83f87aff7b07 8022318: Document Spliterator characteristics and binding policy of java util concurrent collection impls
psandoz
parents: 19413
diff changeset
  4310
         * Returns an iterator over the elements in this collection.
83f87aff7b07 8022318: Document Spliterator characteristics and binding policy of java util concurrent collection impls
psandoz
parents: 19413
diff changeset
  4311
         *
83f87aff7b07 8022318: Document Spliterator characteristics and binding policy of java util concurrent collection impls
psandoz
parents: 19413
diff changeset
  4312
         * <p>The returned iterator is
83f87aff7b07 8022318: Document Spliterator characteristics and binding policy of java util concurrent collection impls
psandoz
parents: 19413
diff changeset
  4313
         * <a href="package-summary.html#Weakly"><i>weakly consistent</i></a>.
83f87aff7b07 8022318: Document Spliterator characteristics and binding policy of java util concurrent collection impls
psandoz
parents: 19413
diff changeset
  4314
         *
83f87aff7b07 8022318: Document Spliterator characteristics and binding policy of java util concurrent collection impls
psandoz
parents: 19413
diff changeset
  4315
         * @return an iterator over the elements in this collection
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4316
         */
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4317
        public abstract Iterator<E> iterator();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4318
        public abstract boolean contains(Object o);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4319
        public abstract boolean remove(Object o);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4320
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4321
        private static final String oomeMsg = "Required array size too large";
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4322
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4323
        public final Object[] toArray() {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4324
            long sz = map.mappingCount();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4325
            if (sz > MAX_ARRAY_SIZE)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4326
                throw new OutOfMemoryError(oomeMsg);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4327
            int n = (int)sz;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4328
            Object[] r = new Object[n];
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4329
            int i = 0;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4330
            for (E e : this) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4331
                if (i == n) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4332
                    if (n >= MAX_ARRAY_SIZE)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4333
                        throw new OutOfMemoryError(oomeMsg);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4334
                    if (n >= MAX_ARRAY_SIZE - (MAX_ARRAY_SIZE >>> 1) - 1)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4335
                        n = MAX_ARRAY_SIZE;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4336
                    else
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4337
                        n += (n >>> 1) + 1;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4338
                    r = Arrays.copyOf(r, n);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4339
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4340
                r[i++] = e;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4341
            }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4342
            return (i == n) ? r : Arrays.copyOf(r, i);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4343
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4344
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  4345
        @SuppressWarnings("unchecked")
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4346
        public final <T> T[] toArray(T[] a) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4347
            long sz = map.mappingCount();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4348
            if (sz > MAX_ARRAY_SIZE)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4349
                throw new OutOfMemoryError(oomeMsg);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4350
            int m = (int)sz;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4351
            T[] r = (a.length >= m) ? a :
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4352
                (T[])java.lang.reflect.Array
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4353
                .newInstance(a.getClass().getComponentType(), m);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4354
            int n = r.length;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4355
            int i = 0;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4356
            for (E e : this) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4357
                if (i == n) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4358
                    if (n >= MAX_ARRAY_SIZE)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4359
                        throw new OutOfMemoryError(oomeMsg);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4360
                    if (n >= MAX_ARRAY_SIZE - (MAX_ARRAY_SIZE >>> 1) - 1)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4361
                        n = MAX_ARRAY_SIZE;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4362
                    else
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4363
                        n += (n >>> 1) + 1;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4364
                    r = Arrays.copyOf(r, n);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4365
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4366
                r[i++] = (T)e;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4367
            }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4368
            if (a == r && i < n) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4369
                r[i] = null; // null-terminate
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4370
                return r;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4371
            }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4372
            return (i == n) ? r : Arrays.copyOf(r, i);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4373
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4374
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4375
        /**
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4376
         * Returns a string representation of this collection.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4377
         * The string representation consists of the string representations
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4378
         * of the collection's elements in the order they are returned by
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4379
         * its iterator, enclosed in square brackets ({@code "[]"}).
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4380
         * Adjacent elements are separated by the characters {@code ", "}
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4381
         * (comma and space).  Elements are converted to strings as by
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4382
         * {@link String#valueOf(Object)}.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4383
         *
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4384
         * @return a string representation of this collection
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4385
         */
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4386
        public final String toString() {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4387
            StringBuilder sb = new StringBuilder();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4388
            sb.append('[');
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4389
            Iterator<E> it = iterator();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4390
            if (it.hasNext()) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4391
                for (;;) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4392
                    Object e = it.next();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4393
                    sb.append(e == this ? "(this Collection)" : e);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4394
                    if (!it.hasNext())
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4395
                        break;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4396
                    sb.append(',').append(' ');
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4397
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4398
            }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4399
            return sb.append(']').toString();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4400
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4401
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4402
        public final boolean containsAll(Collection<?> c) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4403
            if (c != this) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4404
                for (Object e : c) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4405
                    if (e == null || !contains(e))
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4406
                        return false;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4407
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4408
            }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4409
            return true;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4410
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4411
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4412
        public final boolean removeAll(Collection<?> c) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4413
            boolean modified = false;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4414
            for (Iterator<E> it = iterator(); it.hasNext();) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4415
                if (c.contains(it.next())) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4416
                    it.remove();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4417
                    modified = true;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4418
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4419
            }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4420
            return modified;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4421
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4422
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4423
        public final boolean retainAll(Collection<?> c) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4424
            boolean modified = false;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4425
            for (Iterator<E> it = iterator(); it.hasNext();) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4426
                if (!c.contains(it.next())) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4427
                    it.remove();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4428
                    modified = true;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4429
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4430
            }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4431
            return modified;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4432
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4433
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4434
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4435
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4436
    /**
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4437
     * A view of a ConcurrentHashMap as a {@link Set} of keys, in
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4438
     * which additions may optionally be enabled by mapping to a
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4439
     * common value.  This class cannot be directly instantiated.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4440
     * See {@link #keySet() keySet()},
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4441
     * {@link #keySet(Object) keySet(V)},
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4442
     * {@link #newKeySet() newKeySet()},
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4443
     * {@link #newKeySet(int) newKeySet(int)}.
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  4444
     *
17953
9a56976d1ab2 8015963: Add at since tags to new ConcurrentHashMap methods
chegar
parents: 17945
diff changeset
  4445
     * @since 1.8
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4446
     */
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4447
    public static class KeySetView<K,V> extends CollectionView<K,V,K>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4448
        implements Set<K>, java.io.Serializable {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4449
        private static final long serialVersionUID = 7249069246763182397L;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4450
        private final V value;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4451
        KeySetView(ConcurrentHashMap<K,V> map, V value) {  // non-public
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4452
            super(map);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4453
            this.value = value;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4454
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4455
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4456
        /**
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4457
         * Returns the default mapped value for additions,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4458
         * or {@code null} if additions are not supported.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4459
         *
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4460
         * @return the default mapped value for additions, or {@code null}
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4461
         * if not supported
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4462
         */
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4463
        public V getMappedValue() { return value; }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4464
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4465
        /**
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4466
         * {@inheritDoc}
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4467
         * @throws NullPointerException if the specified key is null
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4468
         */
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4469
        public boolean contains(Object o) { return map.containsKey(o); }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4470
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4471
        /**
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4472
         * Removes the key from this map view, by removing the key (and its
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4473
         * corresponding value) from the backing map.  This method does
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4474
         * nothing if the key is not in the map.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4475
         *
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4476
         * @param  o the key to be removed from the backing map
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4477
         * @return {@code true} if the backing map contained the specified key
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4478
         * @throws NullPointerException if the specified key is null
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4479
         */
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4480
        public boolean remove(Object o) { return map.remove(o) != null; }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4481
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4482
        /**
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4483
         * @return an iterator over the keys of the backing map
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4484
         */
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4485
        public Iterator<K> iterator() {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4486
            Node<K,V>[] t;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4487
            ConcurrentHashMap<K,V> m = map;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4488
            int f = (t = m.table) == null ? 0 : t.length;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4489
            return new KeyIterator<K,V>(t, f, 0, f, m);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4490
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4491
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4492
        /**
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4493
         * Adds the specified key to this set view by mapping the key to
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4494
         * the default mapped value in the backing map, if defined.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4495
         *
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4496
         * @param e key to be added
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4497
         * @return {@code true} if this set changed as a result of the call
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4498
         * @throws NullPointerException if the specified key is null
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4499
         * @throws UnsupportedOperationException if no default mapped value
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4500
         * for additions was provided
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4501
         */
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4502
        public boolean add(K e) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4503
            V v;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4504
            if ((v = value) == null)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4505
                throw new UnsupportedOperationException();
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  4506
            return map.putVal(e, v, true) == null;
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4507
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4508
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4509
        /**
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4510
         * Adds all of the elements in the specified collection to this set,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4511
         * as if by calling {@link #add} on each one.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4512
         *
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4513
         * @param c the elements to be inserted into this set
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4514
         * @return {@code true} if this set changed as a result of the call
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4515
         * @throws NullPointerException if the collection or any of its
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4516
         * elements are {@code null}
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4517
         * @throws UnsupportedOperationException if no default mapped value
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4518
         * for additions was provided
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4519
         */
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4520
        public boolean addAll(Collection<? extends K> c) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4521
            boolean added = false;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4522
            V v;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4523
            if ((v = value) == null)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4524
                throw new UnsupportedOperationException();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4525
            for (K e : c) {
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  4526
                if (map.putVal(e, v, true) == null)
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4527
                    added = true;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4528
            }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4529
            return added;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4530
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4531
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4532
        public int hashCode() {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4533
            int h = 0;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4534
            for (K e : this)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4535
                h += e.hashCode();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4536
            return h;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4537
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4538
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4539
        public boolean equals(Object o) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4540
            Set<?> c;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4541
            return ((o instanceof Set) &&
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4542
                    ((c = (Set<?>)o) == this ||
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4543
                     (containsAll(c) && c.containsAll(this))));
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4544
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4545
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4546
        public Spliterator<K> spliterator() {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4547
            Node<K,V>[] t;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4548
            ConcurrentHashMap<K,V> m = map;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4549
            long n = m.sumCount();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4550
            int f = (t = m.table) == null ? 0 : t.length;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4551
            return new KeySpliterator<K,V>(t, f, 0, f, n < 0L ? 0L : n);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4552
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4553
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4554
        public void forEach(Consumer<? super K> action) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4555
            if (action == null) throw new NullPointerException();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4556
            Node<K,V>[] t;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4557
            if ((t = map.table) != null) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4558
                Traverser<K,V> it = new Traverser<K,V>(t, t.length, 0, t.length);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4559
                for (Node<K,V> p; (p = it.advance()) != null; )
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  4560
                    action.accept(p.key);
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4561
            }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4562
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4563
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4564
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4565
    /**
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4566
     * A view of a ConcurrentHashMap as a {@link Collection} of
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4567
     * values, in which additions are disabled. This class cannot be
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4568
     * directly instantiated. See {@link #values()}.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4569
     */
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4570
    static final class ValuesView<K,V> extends CollectionView<K,V,V>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4571
        implements Collection<V>, java.io.Serializable {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4572
        private static final long serialVersionUID = 2249069246763182397L;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4573
        ValuesView(ConcurrentHashMap<K,V> map) { super(map); }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4574
        public final boolean contains(Object o) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4575
            return map.containsValue(o);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4576
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4577
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4578
        public final boolean remove(Object o) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4579
            if (o != null) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4580
                for (Iterator<V> it = iterator(); it.hasNext();) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4581
                    if (o.equals(it.next())) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4582
                        it.remove();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4583
                        return true;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4584
                    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4585
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4586
            }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4587
            return false;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4588
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4589
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4590
        public final Iterator<V> iterator() {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4591
            ConcurrentHashMap<K,V> m = map;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4592
            Node<K,V>[] t;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4593
            int f = (t = m.table) == null ? 0 : t.length;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4594
            return new ValueIterator<K,V>(t, f, 0, f, m);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4595
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4596
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4597
        public final boolean add(V e) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4598
            throw new UnsupportedOperationException();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4599
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4600
        public final boolean addAll(Collection<? extends V> c) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4601
            throw new UnsupportedOperationException();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4602
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4603
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4604
        public Spliterator<V> spliterator() {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4605
            Node<K,V>[] t;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4606
            ConcurrentHashMap<K,V> m = map;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4607
            long n = m.sumCount();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4608
            int f = (t = m.table) == null ? 0 : t.length;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4609
            return new ValueSpliterator<K,V>(t, f, 0, f, n < 0L ? 0L : n);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4610
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4611
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4612
        public void forEach(Consumer<? super V> action) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4613
            if (action == null) throw new NullPointerException();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4614
            Node<K,V>[] t;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4615
            if ((t = map.table) != null) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4616
                Traverser<K,V> it = new Traverser<K,V>(t, t.length, 0, t.length);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4617
                for (Node<K,V> p; (p = it.advance()) != null; )
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4618
                    action.accept(p.val);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4619
            }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4620
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4621
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4622
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4623
    /**
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4624
     * A view of a ConcurrentHashMap as a {@link Set} of (key, value)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4625
     * entries.  This class cannot be directly instantiated. See
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4626
     * {@link #entrySet()}.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4627
     */
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4628
    static final class EntrySetView<K,V> extends CollectionView<K,V,Map.Entry<K,V>>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4629
        implements Set<Map.Entry<K,V>>, java.io.Serializable {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4630
        private static final long serialVersionUID = 2249069246763182397L;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4631
        EntrySetView(ConcurrentHashMap<K,V> map) { super(map); }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4632
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4633
        public boolean contains(Object o) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4634
            Object k, v, r; Map.Entry<?,?> e;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4635
            return ((o instanceof Map.Entry) &&
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4636
                    (k = (e = (Map.Entry<?,?>)o).getKey()) != null &&
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4637
                    (r = map.get(k)) != null &&
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4638
                    (v = e.getValue()) != null &&
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4639
                    (v == r || v.equals(r)));
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4640
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4641
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4642
        public boolean remove(Object o) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4643
            Object k, v; Map.Entry<?,?> e;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4644
            return ((o instanceof Map.Entry) &&
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4645
                    (k = (e = (Map.Entry<?,?>)o).getKey()) != null &&
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4646
                    (v = e.getValue()) != null &&
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4647
                    map.remove(k, v));
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4648
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4649
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4650
        /**
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4651
         * @return an iterator over the entries of the backing map
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4652
         */
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4653
        public Iterator<Map.Entry<K,V>> iterator() {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4654
            ConcurrentHashMap<K,V> m = map;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4655
            Node<K,V>[] t;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4656
            int f = (t = m.table) == null ? 0 : t.length;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4657
            return new EntryIterator<K,V>(t, f, 0, f, m);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4658
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4659
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4660
        public boolean add(Entry<K,V> e) {
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  4661
            return map.putVal(e.getKey(), e.getValue(), false) == null;
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4662
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4663
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4664
        public boolean addAll(Collection<? extends Entry<K,V>> c) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4665
            boolean added = false;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4666
            for (Entry<K,V> e : c) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4667
                if (add(e))
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4668
                    added = true;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4669
            }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4670
            return added;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4671
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4672
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4673
        public final int hashCode() {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4674
            int h = 0;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4675
            Node<K,V>[] t;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4676
            if ((t = map.table) != null) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4677
                Traverser<K,V> it = new Traverser<K,V>(t, t.length, 0, t.length);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4678
                for (Node<K,V> p; (p = it.advance()) != null; ) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4679
                    h += p.hashCode();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4680
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4681
            }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4682
            return h;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4683
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4684
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4685
        public final boolean equals(Object o) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4686
            Set<?> c;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4687
            return ((o instanceof Set) &&
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4688
                    ((c = (Set<?>)o) == this ||
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4689
                     (containsAll(c) && c.containsAll(this))));
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4690
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4691
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4692
        public Spliterator<Map.Entry<K,V>> spliterator() {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4693
            Node<K,V>[] t;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4694
            ConcurrentHashMap<K,V> m = map;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4695
            long n = m.sumCount();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4696
            int f = (t = m.table) == null ? 0 : t.length;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4697
            return new EntrySpliterator<K,V>(t, f, 0, f, n < 0L ? 0L : n, m);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4698
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4699
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4700
        public void forEach(Consumer<? super Map.Entry<K,V>> action) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4701
            if (action == null) throw new NullPointerException();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4702
            Node<K,V>[] t;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4703
            if ((t = map.table) != null) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4704
                Traverser<K,V> it = new Traverser<K,V>(t, t.length, 0, t.length);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4705
                for (Node<K,V> p; (p = it.advance()) != null; )
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  4706
                    action.accept(new MapEntry<K,V>(p.key, p.val, map));
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4707
            }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4708
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4709
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4710
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4711
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4712
    // -------------------------------------------------------
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4713
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4714
    /**
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4715
     * Base class for bulk tasks. Repeats some fields and code from
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4716
     * class Traverser, because we need to subclass CountedCompleter.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4717
     */
19380
22eefc44fad6 8022724: lint warnings in j.u.concurrent packages
dl
parents: 19036
diff changeset
  4718
    @SuppressWarnings("serial")
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4719
    abstract static class BulkTask<K,V,R> extends CountedCompleter<R> {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4720
        Node<K,V>[] tab;        // same as Traverser
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4721
        Node<K,V> next;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4722
        int index;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4723
        int baseIndex;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4724
        int baseLimit;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4725
        final int baseSize;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4726
        int batch;              // split control
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4727
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4728
        BulkTask(BulkTask<K,V,?> par, int b, int i, int f, Node<K,V>[] t) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4729
            super(par);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4730
            this.batch = b;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4731
            this.index = this.baseIndex = i;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4732
            if ((this.tab = t) == null)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4733
                this.baseSize = this.baseLimit = 0;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4734
            else if (par == null)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4735
                this.baseSize = this.baseLimit = t.length;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4736
            else {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4737
                this.baseLimit = f;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4738
                this.baseSize = par.baseSize;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4739
            }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4740
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4741
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4742
        /**
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4743
         * Same as Traverser version
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4744
         */
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4745
        final Node<K,V> advance() {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4746
            Node<K,V> e;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4747
            if ((e = next) != null)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4748
                e = e.next;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4749
            for (;;) {
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  4750
                Node<K,V>[] t; int i, n; K ek;  // must use locals in checks
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4751
                if (e != null)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4752
                    return next = e;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4753
                if (baseIndex >= baseLimit || (t = tab) == null ||
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4754
                    (n = t.length) <= (i = index) || i < 0)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4755
                    return next = null;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4756
                if ((e = tabAt(t, index)) != null && e.hash < 0) {
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  4757
                    if (e instanceof ForwardingNode) {
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  4758
                        tab = ((ForwardingNode<K,V>)e).nextTable;
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4759
                        e = null;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4760
                        continue;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4761
                    }
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  4762
                    else if (e instanceof TreeBin)
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  4763
                        e = ((TreeBin<K,V>)e).first;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  4764
                    else
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  4765
                        e = null;
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4766
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4767
                if ((index += baseSize) >= n)
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  4768
                    index = ++baseIndex;    // visit upper slots if present
9279
5f5d493d30a0 7036559: ConcurrentHashMap footprint and contention improvements
dl
parents: 9242
diff changeset
  4769
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4770
        }
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4771
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4772
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4773
    /*
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4774
     * Task classes. Coded in a regular but ugly format/style to
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4775
     * simplify checks that each variant differs in the right way from
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4776
     * others. The null screenings exist because compilers cannot tell
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4777
     * that we've already null-checked task arguments, so we force
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4778
     * simplest hoisted bypass to help avoid convoluted traps.
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4779
     */
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  4780
    @SuppressWarnings("serial")
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4781
    static final class ForEachKeyTask<K,V>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4782
        extends BulkTask<K,V,Void> {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4783
        final Consumer<? super K> action;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4784
        ForEachKeyTask
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4785
            (BulkTask<K,V,?> p, int b, int i, int f, Node<K,V>[] t,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4786
             Consumer<? super K> action) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4787
            super(p, b, i, f, t);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4788
            this.action = action;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4789
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4790
        public final void compute() {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4791
            final Consumer<? super K> action;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4792
            if ((action = this.action) != null) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4793
                for (int i = baseIndex, f, h; batch > 0 &&
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4794
                         (h = ((f = baseLimit) + i) >>> 1) > i;) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4795
                    addToPendingCount(1);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4796
                    new ForEachKeyTask<K,V>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4797
                        (this, batch >>>= 1, baseLimit = h, f, tab,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4798
                         action).fork();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4799
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4800
                for (Node<K,V> p; (p = advance()) != null;)
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  4801
                    action.accept(p.key);
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4802
                propagateCompletion();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4803
            }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4804
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4805
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4806
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  4807
    @SuppressWarnings("serial")
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4808
    static final class ForEachValueTask<K,V>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4809
        extends BulkTask<K,V,Void> {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4810
        final Consumer<? super V> action;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4811
        ForEachValueTask
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4812
            (BulkTask<K,V,?> p, int b, int i, int f, Node<K,V>[] t,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4813
             Consumer<? super V> action) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4814
            super(p, b, i, f, t);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4815
            this.action = action;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4816
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4817
        public final void compute() {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4818
            final Consumer<? super V> action;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4819
            if ((action = this.action) != null) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4820
                for (int i = baseIndex, f, h; batch > 0 &&
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4821
                         (h = ((f = baseLimit) + i) >>> 1) > i;) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4822
                    addToPendingCount(1);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4823
                    new ForEachValueTask<K,V>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4824
                        (this, batch >>>= 1, baseLimit = h, f, tab,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4825
                         action).fork();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4826
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4827
                for (Node<K,V> p; (p = advance()) != null;)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4828
                    action.accept(p.val);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4829
                propagateCompletion();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4830
            }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4831
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4832
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4833
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  4834
    @SuppressWarnings("serial")
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4835
    static final class ForEachEntryTask<K,V>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4836
        extends BulkTask<K,V,Void> {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4837
        final Consumer<? super Entry<K,V>> action;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4838
        ForEachEntryTask
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4839
            (BulkTask<K,V,?> p, int b, int i, int f, Node<K,V>[] t,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4840
             Consumer<? super Entry<K,V>> action) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4841
            super(p, b, i, f, t);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4842
            this.action = action;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4843
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4844
        public final void compute() {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4845
            final Consumer<? super Entry<K,V>> action;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4846
            if ((action = this.action) != null) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4847
                for (int i = baseIndex, f, h; batch > 0 &&
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4848
                         (h = ((f = baseLimit) + i) >>> 1) > i;) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4849
                    addToPendingCount(1);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4850
                    new ForEachEntryTask<K,V>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4851
                        (this, batch >>>= 1, baseLimit = h, f, tab,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4852
                         action).fork();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4853
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4854
                for (Node<K,V> p; (p = advance()) != null; )
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4855
                    action.accept(p);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4856
                propagateCompletion();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4857
            }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4858
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4859
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4860
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  4861
    @SuppressWarnings("serial")
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4862
    static final class ForEachMappingTask<K,V>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4863
        extends BulkTask<K,V,Void> {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4864
        final BiConsumer<? super K, ? super V> action;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4865
        ForEachMappingTask
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4866
            (BulkTask<K,V,?> p, int b, int i, int f, Node<K,V>[] t,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4867
             BiConsumer<? super K,? super V> action) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4868
            super(p, b, i, f, t);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4869
            this.action = action;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4870
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4871
        public final void compute() {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4872
            final BiConsumer<? super K, ? super V> action;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4873
            if ((action = this.action) != null) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4874
                for (int i = baseIndex, f, h; batch > 0 &&
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4875
                         (h = ((f = baseLimit) + i) >>> 1) > i;) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4876
                    addToPendingCount(1);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4877
                    new ForEachMappingTask<K,V>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4878
                        (this, batch >>>= 1, baseLimit = h, f, tab,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4879
                         action).fork();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4880
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4881
                for (Node<K,V> p; (p = advance()) != null; )
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  4882
                    action.accept(p.key, p.val);
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4883
                propagateCompletion();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4884
            }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4885
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4886
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4887
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  4888
    @SuppressWarnings("serial")
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4889
    static final class ForEachTransformedKeyTask<K,V,U>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4890
        extends BulkTask<K,V,Void> {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4891
        final Function<? super K, ? extends U> transformer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4892
        final Consumer<? super U> action;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4893
        ForEachTransformedKeyTask
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4894
            (BulkTask<K,V,?> p, int b, int i, int f, Node<K,V>[] t,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4895
             Function<? super K, ? extends U> transformer, Consumer<? super U> action) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4896
            super(p, b, i, f, t);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4897
            this.transformer = transformer; this.action = action;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4898
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4899
        public final void compute() {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4900
            final Function<? super K, ? extends U> transformer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4901
            final Consumer<? super U> action;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4902
            if ((transformer = this.transformer) != null &&
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4903
                (action = this.action) != null) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4904
                for (int i = baseIndex, f, h; batch > 0 &&
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4905
                         (h = ((f = baseLimit) + i) >>> 1) > i;) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4906
                    addToPendingCount(1);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4907
                    new ForEachTransformedKeyTask<K,V,U>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4908
                        (this, batch >>>= 1, baseLimit = h, f, tab,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4909
                         transformer, action).fork();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4910
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4911
                for (Node<K,V> p; (p = advance()) != null; ) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4912
                    U u;
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  4913
                    if ((u = transformer.apply(p.key)) != null)
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4914
                        action.accept(u);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4915
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4916
                propagateCompletion();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4917
            }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4918
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4919
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4920
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  4921
    @SuppressWarnings("serial")
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4922
    static final class ForEachTransformedValueTask<K,V,U>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4923
        extends BulkTask<K,V,Void> {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4924
        final Function<? super V, ? extends U> transformer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4925
        final Consumer<? super U> action;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4926
        ForEachTransformedValueTask
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4927
            (BulkTask<K,V,?> p, int b, int i, int f, Node<K,V>[] t,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4928
             Function<? super V, ? extends U> transformer, Consumer<? super U> action) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4929
            super(p, b, i, f, t);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4930
            this.transformer = transformer; this.action = action;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4931
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4932
        public final void compute() {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4933
            final Function<? super V, ? extends U> transformer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4934
            final Consumer<? super U> action;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4935
            if ((transformer = this.transformer) != null &&
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4936
                (action = this.action) != null) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4937
                for (int i = baseIndex, f, h; batch > 0 &&
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4938
                         (h = ((f = baseLimit) + i) >>> 1) > i;) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4939
                    addToPendingCount(1);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4940
                    new ForEachTransformedValueTask<K,V,U>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4941
                        (this, batch >>>= 1, baseLimit = h, f, tab,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4942
                         transformer, action).fork();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4943
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4944
                for (Node<K,V> p; (p = advance()) != null; ) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4945
                    U u;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4946
                    if ((u = transformer.apply(p.val)) != null)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4947
                        action.accept(u);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4948
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4949
                propagateCompletion();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4950
            }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4951
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4952
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4953
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  4954
    @SuppressWarnings("serial")
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4955
    static final class ForEachTransformedEntryTask<K,V,U>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4956
        extends BulkTask<K,V,Void> {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4957
        final Function<Map.Entry<K,V>, ? extends U> transformer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4958
        final Consumer<? super U> action;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4959
        ForEachTransformedEntryTask
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4960
            (BulkTask<K,V,?> p, int b, int i, int f, Node<K,V>[] t,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4961
             Function<Map.Entry<K,V>, ? extends U> transformer, Consumer<? super U> action) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4962
            super(p, b, i, f, t);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4963
            this.transformer = transformer; this.action = action;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4964
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4965
        public final void compute() {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4966
            final Function<Map.Entry<K,V>, ? extends U> transformer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4967
            final Consumer<? super U> action;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4968
            if ((transformer = this.transformer) != null &&
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4969
                (action = this.action) != null) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4970
                for (int i = baseIndex, f, h; batch > 0 &&
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4971
                         (h = ((f = baseLimit) + i) >>> 1) > i;) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4972
                    addToPendingCount(1);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4973
                    new ForEachTransformedEntryTask<K,V,U>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4974
                        (this, batch >>>= 1, baseLimit = h, f, tab,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4975
                         transformer, action).fork();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4976
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4977
                for (Node<K,V> p; (p = advance()) != null; ) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4978
                    U u;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4979
                    if ((u = transformer.apply(p)) != null)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4980
                        action.accept(u);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4981
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4982
                propagateCompletion();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4983
            }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4984
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4985
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4986
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  4987
    @SuppressWarnings("serial")
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4988
    static final class ForEachTransformedMappingTask<K,V,U>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4989
        extends BulkTask<K,V,Void> {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4990
        final BiFunction<? super K, ? super V, ? extends U> transformer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4991
        final Consumer<? super U> action;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4992
        ForEachTransformedMappingTask
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4993
            (BulkTask<K,V,?> p, int b, int i, int f, Node<K,V>[] t,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4994
             BiFunction<? super K, ? super V, ? extends U> transformer,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4995
             Consumer<? super U> action) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4996
            super(p, b, i, f, t);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4997
            this.transformer = transformer; this.action = action;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4998
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  4999
        public final void compute() {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5000
            final BiFunction<? super K, ? super V, ? extends U> transformer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5001
            final Consumer<? super U> action;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5002
            if ((transformer = this.transformer) != null &&
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5003
                (action = this.action) != null) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5004
                for (int i = baseIndex, f, h; batch > 0 &&
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5005
                         (h = ((f = baseLimit) + i) >>> 1) > i;) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5006
                    addToPendingCount(1);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5007
                    new ForEachTransformedMappingTask<K,V,U>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5008
                        (this, batch >>>= 1, baseLimit = h, f, tab,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5009
                         transformer, action).fork();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5010
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5011
                for (Node<K,V> p; (p = advance()) != null; ) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5012
                    U u;
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  5013
                    if ((u = transformer.apply(p.key, p.val)) != null)
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5014
                        action.accept(u);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5015
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5016
                propagateCompletion();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5017
            }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5018
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5019
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5020
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  5021
    @SuppressWarnings("serial")
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5022
    static final class SearchKeysTask<K,V,U>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5023
        extends BulkTask<K,V,U> {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5024
        final Function<? super K, ? extends U> searchFunction;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5025
        final AtomicReference<U> result;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5026
        SearchKeysTask
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5027
            (BulkTask<K,V,?> p, int b, int i, int f, Node<K,V>[] t,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5028
             Function<? super K, ? extends U> searchFunction,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5029
             AtomicReference<U> result) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5030
            super(p, b, i, f, t);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5031
            this.searchFunction = searchFunction; this.result = result;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5032
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5033
        public final U getRawResult() { return result.get(); }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5034
        public final void compute() {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5035
            final Function<? super K, ? extends U> searchFunction;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5036
            final AtomicReference<U> result;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5037
            if ((searchFunction = this.searchFunction) != null &&
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5038
                (result = this.result) != null) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5039
                for (int i = baseIndex, f, h; batch > 0 &&
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5040
                         (h = ((f = baseLimit) + i) >>> 1) > i;) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5041
                    if (result.get() != null)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5042
                        return;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5043
                    addToPendingCount(1);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5044
                    new SearchKeysTask<K,V,U>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5045
                        (this, batch >>>= 1, baseLimit = h, f, tab,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5046
                         searchFunction, result).fork();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5047
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5048
                while (result.get() == null) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5049
                    U u;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5050
                    Node<K,V> p;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5051
                    if ((p = advance()) == null) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5052
                        propagateCompletion();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5053
                        break;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5054
                    }
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  5055
                    if ((u = searchFunction.apply(p.key)) != null) {
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5056
                        if (result.compareAndSet(null, u))
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5057
                            quietlyCompleteRoot();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5058
                        break;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5059
                    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5060
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5061
            }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5062
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5063
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5064
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  5065
    @SuppressWarnings("serial")
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5066
    static final class SearchValuesTask<K,V,U>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5067
        extends BulkTask<K,V,U> {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5068
        final Function<? super V, ? extends U> searchFunction;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5069
        final AtomicReference<U> result;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5070
        SearchValuesTask
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5071
            (BulkTask<K,V,?> p, int b, int i, int f, Node<K,V>[] t,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5072
             Function<? super V, ? extends U> searchFunction,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5073
             AtomicReference<U> result) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5074
            super(p, b, i, f, t);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5075
            this.searchFunction = searchFunction; this.result = result;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5076
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5077
        public final U getRawResult() { return result.get(); }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5078
        public final void compute() {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5079
            final Function<? super V, ? extends U> searchFunction;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5080
            final AtomicReference<U> result;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5081
            if ((searchFunction = this.searchFunction) != null &&
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5082
                (result = this.result) != null) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5083
                for (int i = baseIndex, f, h; batch > 0 &&
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5084
                         (h = ((f = baseLimit) + i) >>> 1) > i;) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5085
                    if (result.get() != null)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5086
                        return;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5087
                    addToPendingCount(1);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5088
                    new SearchValuesTask<K,V,U>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5089
                        (this, batch >>>= 1, baseLimit = h, f, tab,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5090
                         searchFunction, result).fork();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5091
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5092
                while (result.get() == null) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5093
                    U u;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5094
                    Node<K,V> p;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5095
                    if ((p = advance()) == null) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5096
                        propagateCompletion();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5097
                        break;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5098
                    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5099
                    if ((u = searchFunction.apply(p.val)) != null) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5100
                        if (result.compareAndSet(null, u))
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5101
                            quietlyCompleteRoot();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5102
                        break;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5103
                    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5104
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5105
            }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5106
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5107
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5108
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  5109
    @SuppressWarnings("serial")
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5110
    static final class SearchEntriesTask<K,V,U>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5111
        extends BulkTask<K,V,U> {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5112
        final Function<Entry<K,V>, ? extends U> searchFunction;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5113
        final AtomicReference<U> result;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5114
        SearchEntriesTask
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5115
            (BulkTask<K,V,?> p, int b, int i, int f, Node<K,V>[] t,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5116
             Function<Entry<K,V>, ? extends U> searchFunction,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5117
             AtomicReference<U> result) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5118
            super(p, b, i, f, t);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5119
            this.searchFunction = searchFunction; this.result = result;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5120
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5121
        public final U getRawResult() { return result.get(); }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5122
        public final void compute() {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5123
            final Function<Entry<K,V>, ? extends U> searchFunction;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5124
            final AtomicReference<U> result;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5125
            if ((searchFunction = this.searchFunction) != null &&
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5126
                (result = this.result) != null) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5127
                for (int i = baseIndex, f, h; batch > 0 &&
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5128
                         (h = ((f = baseLimit) + i) >>> 1) > i;) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5129
                    if (result.get() != null)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5130
                        return;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5131
                    addToPendingCount(1);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5132
                    new SearchEntriesTask<K,V,U>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5133
                        (this, batch >>>= 1, baseLimit = h, f, tab,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5134
                         searchFunction, result).fork();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5135
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5136
                while (result.get() == null) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5137
                    U u;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5138
                    Node<K,V> p;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5139
                    if ((p = advance()) == null) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5140
                        propagateCompletion();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5141
                        break;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5142
                    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5143
                    if ((u = searchFunction.apply(p)) != null) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5144
                        if (result.compareAndSet(null, u))
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5145
                            quietlyCompleteRoot();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5146
                        return;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5147
                    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5148
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5149
            }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5150
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5151
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5152
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  5153
    @SuppressWarnings("serial")
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5154
    static final class SearchMappingsTask<K,V,U>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5155
        extends BulkTask<K,V,U> {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5156
        final BiFunction<? super K, ? super V, ? extends U> searchFunction;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5157
        final AtomicReference<U> result;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5158
        SearchMappingsTask
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5159
            (BulkTask<K,V,?> p, int b, int i, int f, Node<K,V>[] t,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5160
             BiFunction<? super K, ? super V, ? extends U> searchFunction,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5161
             AtomicReference<U> result) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5162
            super(p, b, i, f, t);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5163
            this.searchFunction = searchFunction; this.result = result;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5164
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5165
        public final U getRawResult() { return result.get(); }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5166
        public final void compute() {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5167
            final BiFunction<? super K, ? super V, ? extends U> searchFunction;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5168
            final AtomicReference<U> result;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5169
            if ((searchFunction = this.searchFunction) != null &&
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5170
                (result = this.result) != null) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5171
                for (int i = baseIndex, f, h; batch > 0 &&
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5172
                         (h = ((f = baseLimit) + i) >>> 1) > i;) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5173
                    if (result.get() != null)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5174
                        return;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5175
                    addToPendingCount(1);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5176
                    new SearchMappingsTask<K,V,U>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5177
                        (this, batch >>>= 1, baseLimit = h, f, tab,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5178
                         searchFunction, result).fork();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5179
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5180
                while (result.get() == null) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5181
                    U u;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5182
                    Node<K,V> p;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5183
                    if ((p = advance()) == null) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5184
                        propagateCompletion();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5185
                        break;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5186
                    }
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  5187
                    if ((u = searchFunction.apply(p.key, p.val)) != null) {
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5188
                        if (result.compareAndSet(null, u))
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5189
                            quietlyCompleteRoot();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5190
                        break;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5191
                    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5192
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5193
            }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5194
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5195
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5196
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  5197
    @SuppressWarnings("serial")
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5198
    static final class ReduceKeysTask<K,V>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5199
        extends BulkTask<K,V,K> {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5200
        final BiFunction<? super K, ? super K, ? extends K> reducer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5201
        K result;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5202
        ReduceKeysTask<K,V> rights, nextRight;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5203
        ReduceKeysTask
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5204
            (BulkTask<K,V,?> p, int b, int i, int f, Node<K,V>[] t,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5205
             ReduceKeysTask<K,V> nextRight,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5206
             BiFunction<? super K, ? super K, ? extends K> reducer) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5207
            super(p, b, i, f, t); this.nextRight = nextRight;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5208
            this.reducer = reducer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5209
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5210
        public final K getRawResult() { return result; }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5211
        public final void compute() {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5212
            final BiFunction<? super K, ? super K, ? extends K> reducer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5213
            if ((reducer = this.reducer) != null) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5214
                for (int i = baseIndex, f, h; batch > 0 &&
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5215
                         (h = ((f = baseLimit) + i) >>> 1) > i;) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5216
                    addToPendingCount(1);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5217
                    (rights = new ReduceKeysTask<K,V>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5218
                     (this, batch >>>= 1, baseLimit = h, f, tab,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5219
                      rights, reducer)).fork();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5220
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5221
                K r = null;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5222
                for (Node<K,V> p; (p = advance()) != null; ) {
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  5223
                    K u = p.key;
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5224
                    r = (r == null) ? u : u == null ? r : reducer.apply(r, u);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5225
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5226
                result = r;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5227
                CountedCompleter<?> c;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5228
                for (c = firstComplete(); c != null; c = c.nextComplete()) {
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  5229
                    @SuppressWarnings("unchecked") ReduceKeysTask<K,V>
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5230
                        t = (ReduceKeysTask<K,V>)c,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5231
                        s = t.rights;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5232
                    while (s != null) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5233
                        K tr, sr;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5234
                        if ((sr = s.result) != null)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5235
                            t.result = (((tr = t.result) == null) ? sr :
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5236
                                        reducer.apply(tr, sr));
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5237
                        s = t.rights = s.nextRight;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5238
                    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5239
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5240
            }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5241
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5242
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5243
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  5244
    @SuppressWarnings("serial")
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5245
    static final class ReduceValuesTask<K,V>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5246
        extends BulkTask<K,V,V> {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5247
        final BiFunction<? super V, ? super V, ? extends V> reducer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5248
        V result;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5249
        ReduceValuesTask<K,V> rights, nextRight;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5250
        ReduceValuesTask
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5251
            (BulkTask<K,V,?> p, int b, int i, int f, Node<K,V>[] t,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5252
             ReduceValuesTask<K,V> nextRight,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5253
             BiFunction<? super V, ? super V, ? extends V> reducer) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5254
            super(p, b, i, f, t); this.nextRight = nextRight;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5255
            this.reducer = reducer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5256
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5257
        public final V getRawResult() { return result; }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5258
        public final void compute() {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5259
            final BiFunction<? super V, ? super V, ? extends V> reducer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5260
            if ((reducer = this.reducer) != null) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5261
                for (int i = baseIndex, f, h; batch > 0 &&
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5262
                         (h = ((f = baseLimit) + i) >>> 1) > i;) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5263
                    addToPendingCount(1);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5264
                    (rights = new ReduceValuesTask<K,V>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5265
                     (this, batch >>>= 1, baseLimit = h, f, tab,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5266
                      rights, reducer)).fork();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5267
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5268
                V r = null;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5269
                for (Node<K,V> p; (p = advance()) != null; ) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5270
                    V v = p.val;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5271
                    r = (r == null) ? v : reducer.apply(r, v);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5272
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5273
                result = r;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5274
                CountedCompleter<?> c;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5275
                for (c = firstComplete(); c != null; c = c.nextComplete()) {
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  5276
                    @SuppressWarnings("unchecked") ReduceValuesTask<K,V>
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5277
                        t = (ReduceValuesTask<K,V>)c,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5278
                        s = t.rights;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5279
                    while (s != null) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5280
                        V tr, sr;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5281
                        if ((sr = s.result) != null)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5282
                            t.result = (((tr = t.result) == null) ? sr :
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5283
                                        reducer.apply(tr, sr));
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5284
                        s = t.rights = s.nextRight;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5285
                    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5286
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5287
            }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5288
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5289
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5290
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  5291
    @SuppressWarnings("serial")
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5292
    static final class ReduceEntriesTask<K,V>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5293
        extends BulkTask<K,V,Map.Entry<K,V>> {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5294
        final BiFunction<Map.Entry<K,V>, Map.Entry<K,V>, ? extends Map.Entry<K,V>> reducer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5295
        Map.Entry<K,V> result;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5296
        ReduceEntriesTask<K,V> rights, nextRight;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5297
        ReduceEntriesTask
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5298
            (BulkTask<K,V,?> p, int b, int i, int f, Node<K,V>[] t,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5299
             ReduceEntriesTask<K,V> nextRight,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5300
             BiFunction<Entry<K,V>, Map.Entry<K,V>, ? extends Map.Entry<K,V>> reducer) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5301
            super(p, b, i, f, t); this.nextRight = nextRight;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5302
            this.reducer = reducer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5303
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5304
        public final Map.Entry<K,V> getRawResult() { return result; }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5305
        public final void compute() {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5306
            final BiFunction<Map.Entry<K,V>, Map.Entry<K,V>, ? extends Map.Entry<K,V>> reducer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5307
            if ((reducer = this.reducer) != null) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5308
                for (int i = baseIndex, f, h; batch > 0 &&
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5309
                         (h = ((f = baseLimit) + i) >>> 1) > i;) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5310
                    addToPendingCount(1);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5311
                    (rights = new ReduceEntriesTask<K,V>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5312
                     (this, batch >>>= 1, baseLimit = h, f, tab,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5313
                      rights, reducer)).fork();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5314
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5315
                Map.Entry<K,V> r = null;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5316
                for (Node<K,V> p; (p = advance()) != null; )
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5317
                    r = (r == null) ? p : reducer.apply(r, p);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5318
                result = r;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5319
                CountedCompleter<?> c;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5320
                for (c = firstComplete(); c != null; c = c.nextComplete()) {
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  5321
                    @SuppressWarnings("unchecked") ReduceEntriesTask<K,V>
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5322
                        t = (ReduceEntriesTask<K,V>)c,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5323
                        s = t.rights;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5324
                    while (s != null) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5325
                        Map.Entry<K,V> tr, sr;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5326
                        if ((sr = s.result) != null)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5327
                            t.result = (((tr = t.result) == null) ? sr :
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5328
                                        reducer.apply(tr, sr));
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5329
                        s = t.rights = s.nextRight;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5330
                    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5331
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5332
            }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5333
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5334
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5335
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  5336
    @SuppressWarnings("serial")
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5337
    static final class MapReduceKeysTask<K,V,U>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5338
        extends BulkTask<K,V,U> {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5339
        final Function<? super K, ? extends U> transformer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5340
        final BiFunction<? super U, ? super U, ? extends U> reducer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5341
        U result;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5342
        MapReduceKeysTask<K,V,U> rights, nextRight;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5343
        MapReduceKeysTask
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5344
            (BulkTask<K,V,?> p, int b, int i, int f, Node<K,V>[] t,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5345
             MapReduceKeysTask<K,V,U> nextRight,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5346
             Function<? super K, ? extends U> transformer,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5347
             BiFunction<? super U, ? super U, ? extends U> reducer) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5348
            super(p, b, i, f, t); this.nextRight = nextRight;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5349
            this.transformer = transformer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5350
            this.reducer = reducer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5351
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5352
        public final U getRawResult() { return result; }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5353
        public final void compute() {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5354
            final Function<? super K, ? extends U> transformer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5355
            final BiFunction<? super U, ? super U, ? extends U> reducer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5356
            if ((transformer = this.transformer) != null &&
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5357
                (reducer = this.reducer) != null) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5358
                for (int i = baseIndex, f, h; batch > 0 &&
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5359
                         (h = ((f = baseLimit) + i) >>> 1) > i;) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5360
                    addToPendingCount(1);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5361
                    (rights = new MapReduceKeysTask<K,V,U>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5362
                     (this, batch >>>= 1, baseLimit = h, f, tab,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5363
                      rights, transformer, reducer)).fork();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5364
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5365
                U r = null;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5366
                for (Node<K,V> p; (p = advance()) != null; ) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5367
                    U u;
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  5368
                    if ((u = transformer.apply(p.key)) != null)
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5369
                        r = (r == null) ? u : reducer.apply(r, u);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5370
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5371
                result = r;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5372
                CountedCompleter<?> c;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5373
                for (c = firstComplete(); c != null; c = c.nextComplete()) {
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  5374
                    @SuppressWarnings("unchecked") MapReduceKeysTask<K,V,U>
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5375
                        t = (MapReduceKeysTask<K,V,U>)c,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5376
                        s = t.rights;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5377
                    while (s != null) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5378
                        U tr, sr;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5379
                        if ((sr = s.result) != null)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5380
                            t.result = (((tr = t.result) == null) ? sr :
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5381
                                        reducer.apply(tr, sr));
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5382
                        s = t.rights = s.nextRight;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5383
                    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5384
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5385
            }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5386
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5387
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5388
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  5389
    @SuppressWarnings("serial")
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5390
    static final class MapReduceValuesTask<K,V,U>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5391
        extends BulkTask<K,V,U> {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5392
        final Function<? super V, ? extends U> transformer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5393
        final BiFunction<? super U, ? super U, ? extends U> reducer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5394
        U result;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5395
        MapReduceValuesTask<K,V,U> rights, nextRight;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5396
        MapReduceValuesTask
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5397
            (BulkTask<K,V,?> p, int b, int i, int f, Node<K,V>[] t,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5398
             MapReduceValuesTask<K,V,U> nextRight,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5399
             Function<? super V, ? extends U> transformer,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5400
             BiFunction<? super U, ? super U, ? extends U> reducer) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5401
            super(p, b, i, f, t); this.nextRight = nextRight;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5402
            this.transformer = transformer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5403
            this.reducer = reducer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5404
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5405
        public final U getRawResult() { return result; }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5406
        public final void compute() {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5407
            final Function<? super V, ? extends U> transformer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5408
            final BiFunction<? super U, ? super U, ? extends U> reducer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5409
            if ((transformer = this.transformer) != null &&
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5410
                (reducer = this.reducer) != null) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5411
                for (int i = baseIndex, f, h; batch > 0 &&
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5412
                         (h = ((f = baseLimit) + i) >>> 1) > i;) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5413
                    addToPendingCount(1);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5414
                    (rights = new MapReduceValuesTask<K,V,U>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5415
                     (this, batch >>>= 1, baseLimit = h, f, tab,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5416
                      rights, transformer, reducer)).fork();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5417
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5418
                U r = null;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5419
                for (Node<K,V> p; (p = advance()) != null; ) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5420
                    U u;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5421
                    if ((u = transformer.apply(p.val)) != null)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5422
                        r = (r == null) ? u : reducer.apply(r, u);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5423
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5424
                result = r;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5425
                CountedCompleter<?> c;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5426
                for (c = firstComplete(); c != null; c = c.nextComplete()) {
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  5427
                    @SuppressWarnings("unchecked") MapReduceValuesTask<K,V,U>
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5428
                        t = (MapReduceValuesTask<K,V,U>)c,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5429
                        s = t.rights;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5430
                    while (s != null) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5431
                        U tr, sr;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5432
                        if ((sr = s.result) != null)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5433
                            t.result = (((tr = t.result) == null) ? sr :
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5434
                                        reducer.apply(tr, sr));
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5435
                        s = t.rights = s.nextRight;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5436
                    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5437
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5438
            }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5439
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5440
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5441
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  5442
    @SuppressWarnings("serial")
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5443
    static final class MapReduceEntriesTask<K,V,U>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5444
        extends BulkTask<K,V,U> {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5445
        final Function<Map.Entry<K,V>, ? extends U> transformer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5446
        final BiFunction<? super U, ? super U, ? extends U> reducer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5447
        U result;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5448
        MapReduceEntriesTask<K,V,U> rights, nextRight;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5449
        MapReduceEntriesTask
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5450
            (BulkTask<K,V,?> p, int b, int i, int f, Node<K,V>[] t,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5451
             MapReduceEntriesTask<K,V,U> nextRight,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5452
             Function<Map.Entry<K,V>, ? extends U> transformer,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5453
             BiFunction<? super U, ? super U, ? extends U> reducer) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5454
            super(p, b, i, f, t); this.nextRight = nextRight;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5455
            this.transformer = transformer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5456
            this.reducer = reducer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5457
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5458
        public final U getRawResult() { return result; }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5459
        public final void compute() {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5460
            final Function<Map.Entry<K,V>, ? extends U> transformer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5461
            final BiFunction<? super U, ? super U, ? extends U> reducer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5462
            if ((transformer = this.transformer) != null &&
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5463
                (reducer = this.reducer) != null) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5464
                for (int i = baseIndex, f, h; batch > 0 &&
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5465
                         (h = ((f = baseLimit) + i) >>> 1) > i;) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5466
                    addToPendingCount(1);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5467
                    (rights = new MapReduceEntriesTask<K,V,U>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5468
                     (this, batch >>>= 1, baseLimit = h, f, tab,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5469
                      rights, transformer, reducer)).fork();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5470
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5471
                U r = null;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5472
                for (Node<K,V> p; (p = advance()) != null; ) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5473
                    U u;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5474
                    if ((u = transformer.apply(p)) != null)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5475
                        r = (r == null) ? u : reducer.apply(r, u);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5476
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5477
                result = r;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5478
                CountedCompleter<?> c;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5479
                for (c = firstComplete(); c != null; c = c.nextComplete()) {
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  5480
                    @SuppressWarnings("unchecked") MapReduceEntriesTask<K,V,U>
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5481
                        t = (MapReduceEntriesTask<K,V,U>)c,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5482
                        s = t.rights;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5483
                    while (s != null) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5484
                        U tr, sr;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5485
                        if ((sr = s.result) != null)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5486
                            t.result = (((tr = t.result) == null) ? sr :
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5487
                                        reducer.apply(tr, sr));
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5488
                        s = t.rights = s.nextRight;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5489
                    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5490
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5491
            }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5492
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5493
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5494
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  5495
    @SuppressWarnings("serial")
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5496
    static final class MapReduceMappingsTask<K,V,U>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5497
        extends BulkTask<K,V,U> {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5498
        final BiFunction<? super K, ? super V, ? extends U> transformer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5499
        final BiFunction<? super U, ? super U, ? extends U> reducer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5500
        U result;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5501
        MapReduceMappingsTask<K,V,U> rights, nextRight;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5502
        MapReduceMappingsTask
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5503
            (BulkTask<K,V,?> p, int b, int i, int f, Node<K,V>[] t,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5504
             MapReduceMappingsTask<K,V,U> nextRight,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5505
             BiFunction<? super K, ? super V, ? extends U> transformer,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5506
             BiFunction<? super U, ? super U, ? extends U> reducer) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5507
            super(p, b, i, f, t); this.nextRight = nextRight;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5508
            this.transformer = transformer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5509
            this.reducer = reducer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5510
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5511
        public final U getRawResult() { return result; }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5512
        public final void compute() {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5513
            final BiFunction<? super K, ? super V, ? extends U> transformer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5514
            final BiFunction<? super U, ? super U, ? extends U> reducer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5515
            if ((transformer = this.transformer) != null &&
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5516
                (reducer = this.reducer) != null) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5517
                for (int i = baseIndex, f, h; batch > 0 &&
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5518
                         (h = ((f = baseLimit) + i) >>> 1) > i;) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5519
                    addToPendingCount(1);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5520
                    (rights = new MapReduceMappingsTask<K,V,U>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5521
                     (this, batch >>>= 1, baseLimit = h, f, tab,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5522
                      rights, transformer, reducer)).fork();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5523
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5524
                U r = null;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5525
                for (Node<K,V> p; (p = advance()) != null; ) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5526
                    U u;
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  5527
                    if ((u = transformer.apply(p.key, p.val)) != null)
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5528
                        r = (r == null) ? u : reducer.apply(r, u);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5529
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5530
                result = r;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5531
                CountedCompleter<?> c;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5532
                for (c = firstComplete(); c != null; c = c.nextComplete()) {
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  5533
                    @SuppressWarnings("unchecked") MapReduceMappingsTask<K,V,U>
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5534
                        t = (MapReduceMappingsTask<K,V,U>)c,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5535
                        s = t.rights;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5536
                    while (s != null) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5537
                        U tr, sr;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5538
                        if ((sr = s.result) != null)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5539
                            t.result = (((tr = t.result) == null) ? sr :
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5540
                                        reducer.apply(tr, sr));
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5541
                        s = t.rights = s.nextRight;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5542
                    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5543
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5544
            }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5545
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5546
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5547
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  5548
    @SuppressWarnings("serial")
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5549
    static final class MapReduceKeysToDoubleTask<K,V>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5550
        extends BulkTask<K,V,Double> {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5551
        final ToDoubleFunction<? super K> transformer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5552
        final DoubleBinaryOperator reducer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5553
        final double basis;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5554
        double result;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5555
        MapReduceKeysToDoubleTask<K,V> rights, nextRight;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5556
        MapReduceKeysToDoubleTask
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5557
            (BulkTask<K,V,?> p, int b, int i, int f, Node<K,V>[] t,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5558
             MapReduceKeysToDoubleTask<K,V> nextRight,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5559
             ToDoubleFunction<? super K> transformer,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5560
             double basis,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5561
             DoubleBinaryOperator reducer) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5562
            super(p, b, i, f, t); this.nextRight = nextRight;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5563
            this.transformer = transformer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5564
            this.basis = basis; this.reducer = reducer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5565
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5566
        public final Double getRawResult() { return result; }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5567
        public final void compute() {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5568
            final ToDoubleFunction<? super K> transformer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5569
            final DoubleBinaryOperator reducer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5570
            if ((transformer = this.transformer) != null &&
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5571
                (reducer = this.reducer) != null) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5572
                double r = this.basis;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5573
                for (int i = baseIndex, f, h; batch > 0 &&
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5574
                         (h = ((f = baseLimit) + i) >>> 1) > i;) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5575
                    addToPendingCount(1);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5576
                    (rights = new MapReduceKeysToDoubleTask<K,V>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5577
                     (this, batch >>>= 1, baseLimit = h, f, tab,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5578
                      rights, transformer, r, reducer)).fork();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5579
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5580
                for (Node<K,V> p; (p = advance()) != null; )
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  5581
                    r = reducer.applyAsDouble(r, transformer.applyAsDouble(p.key));
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5582
                result = r;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5583
                CountedCompleter<?> c;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5584
                for (c = firstComplete(); c != null; c = c.nextComplete()) {
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  5585
                    @SuppressWarnings("unchecked") MapReduceKeysToDoubleTask<K,V>
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5586
                        t = (MapReduceKeysToDoubleTask<K,V>)c,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5587
                        s = t.rights;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5588
                    while (s != null) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5589
                        t.result = reducer.applyAsDouble(t.result, s.result);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5590
                        s = t.rights = s.nextRight;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5591
                    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5592
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5593
            }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5594
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5595
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5596
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  5597
    @SuppressWarnings("serial")
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5598
    static final class MapReduceValuesToDoubleTask<K,V>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5599
        extends BulkTask<K,V,Double> {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5600
        final ToDoubleFunction<? super V> transformer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5601
        final DoubleBinaryOperator reducer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5602
        final double basis;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5603
        double result;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5604
        MapReduceValuesToDoubleTask<K,V> rights, nextRight;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5605
        MapReduceValuesToDoubleTask
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5606
            (BulkTask<K,V,?> p, int b, int i, int f, Node<K,V>[] t,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5607
             MapReduceValuesToDoubleTask<K,V> nextRight,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5608
             ToDoubleFunction<? super V> transformer,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5609
             double basis,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5610
             DoubleBinaryOperator reducer) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5611
            super(p, b, i, f, t); this.nextRight = nextRight;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5612
            this.transformer = transformer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5613
            this.basis = basis; this.reducer = reducer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5614
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5615
        public final Double getRawResult() { return result; }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5616
        public final void compute() {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5617
            final ToDoubleFunction<? super V> transformer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5618
            final DoubleBinaryOperator reducer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5619
            if ((transformer = this.transformer) != null &&
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5620
                (reducer = this.reducer) != null) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5621
                double r = this.basis;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5622
                for (int i = baseIndex, f, h; batch > 0 &&
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5623
                         (h = ((f = baseLimit) + i) >>> 1) > i;) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5624
                    addToPendingCount(1);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5625
                    (rights = new MapReduceValuesToDoubleTask<K,V>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5626
                     (this, batch >>>= 1, baseLimit = h, f, tab,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5627
                      rights, transformer, r, reducer)).fork();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5628
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5629
                for (Node<K,V> p; (p = advance()) != null; )
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5630
                    r = reducer.applyAsDouble(r, transformer.applyAsDouble(p.val));
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5631
                result = r;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5632
                CountedCompleter<?> c;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5633
                for (c = firstComplete(); c != null; c = c.nextComplete()) {
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  5634
                    @SuppressWarnings("unchecked") MapReduceValuesToDoubleTask<K,V>
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5635
                        t = (MapReduceValuesToDoubleTask<K,V>)c,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5636
                        s = t.rights;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5637
                    while (s != null) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5638
                        t.result = reducer.applyAsDouble(t.result, s.result);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5639
                        s = t.rights = s.nextRight;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5640
                    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5641
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5642
            }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5643
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5644
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5645
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  5646
    @SuppressWarnings("serial")
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5647
    static final class MapReduceEntriesToDoubleTask<K,V>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5648
        extends BulkTask<K,V,Double> {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5649
        final ToDoubleFunction<Map.Entry<K,V>> transformer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5650
        final DoubleBinaryOperator reducer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5651
        final double basis;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5652
        double result;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5653
        MapReduceEntriesToDoubleTask<K,V> rights, nextRight;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5654
        MapReduceEntriesToDoubleTask
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5655
            (BulkTask<K,V,?> p, int b, int i, int f, Node<K,V>[] t,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5656
             MapReduceEntriesToDoubleTask<K,V> nextRight,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5657
             ToDoubleFunction<Map.Entry<K,V>> transformer,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5658
             double basis,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5659
             DoubleBinaryOperator reducer) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5660
            super(p, b, i, f, t); this.nextRight = nextRight;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5661
            this.transformer = transformer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5662
            this.basis = basis; this.reducer = reducer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5663
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5664
        public final Double getRawResult() { return result; }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5665
        public final void compute() {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5666
            final ToDoubleFunction<Map.Entry<K,V>> transformer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5667
            final DoubleBinaryOperator reducer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5668
            if ((transformer = this.transformer) != null &&
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5669
                (reducer = this.reducer) != null) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5670
                double r = this.basis;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5671
                for (int i = baseIndex, f, h; batch > 0 &&
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5672
                         (h = ((f = baseLimit) + i) >>> 1) > i;) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5673
                    addToPendingCount(1);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5674
                    (rights = new MapReduceEntriesToDoubleTask<K,V>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5675
                     (this, batch >>>= 1, baseLimit = h, f, tab,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5676
                      rights, transformer, r, reducer)).fork();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5677
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5678
                for (Node<K,V> p; (p = advance()) != null; )
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5679
                    r = reducer.applyAsDouble(r, transformer.applyAsDouble(p));
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5680
                result = r;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5681
                CountedCompleter<?> c;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5682
                for (c = firstComplete(); c != null; c = c.nextComplete()) {
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  5683
                    @SuppressWarnings("unchecked") MapReduceEntriesToDoubleTask<K,V>
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5684
                        t = (MapReduceEntriesToDoubleTask<K,V>)c,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5685
                        s = t.rights;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5686
                    while (s != null) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5687
                        t.result = reducer.applyAsDouble(t.result, s.result);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5688
                        s = t.rights = s.nextRight;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5689
                    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5690
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5691
            }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5692
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5693
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5694
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  5695
    @SuppressWarnings("serial")
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5696
    static final class MapReduceMappingsToDoubleTask<K,V>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5697
        extends BulkTask<K,V,Double> {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5698
        final ToDoubleBiFunction<? super K, ? super V> transformer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5699
        final DoubleBinaryOperator reducer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5700
        final double basis;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5701
        double result;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5702
        MapReduceMappingsToDoubleTask<K,V> rights, nextRight;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5703
        MapReduceMappingsToDoubleTask
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5704
            (BulkTask<K,V,?> p, int b, int i, int f, Node<K,V>[] t,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5705
             MapReduceMappingsToDoubleTask<K,V> nextRight,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5706
             ToDoubleBiFunction<? super K, ? super V> transformer,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5707
             double basis,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5708
             DoubleBinaryOperator reducer) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5709
            super(p, b, i, f, t); this.nextRight = nextRight;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5710
            this.transformer = transformer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5711
            this.basis = basis; this.reducer = reducer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5712
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5713
        public final Double getRawResult() { return result; }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5714
        public final void compute() {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5715
            final ToDoubleBiFunction<? super K, ? super V> transformer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5716
            final DoubleBinaryOperator reducer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5717
            if ((transformer = this.transformer) != null &&
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5718
                (reducer = this.reducer) != null) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5719
                double r = this.basis;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5720
                for (int i = baseIndex, f, h; batch > 0 &&
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5721
                         (h = ((f = baseLimit) + i) >>> 1) > i;) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5722
                    addToPendingCount(1);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5723
                    (rights = new MapReduceMappingsToDoubleTask<K,V>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5724
                     (this, batch >>>= 1, baseLimit = h, f, tab,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5725
                      rights, transformer, r, reducer)).fork();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5726
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5727
                for (Node<K,V> p; (p = advance()) != null; )
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  5728
                    r = reducer.applyAsDouble(r, transformer.applyAsDouble(p.key, p.val));
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5729
                result = r;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5730
                CountedCompleter<?> c;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5731
                for (c = firstComplete(); c != null; c = c.nextComplete()) {
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  5732
                    @SuppressWarnings("unchecked") MapReduceMappingsToDoubleTask<K,V>
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5733
                        t = (MapReduceMappingsToDoubleTask<K,V>)c,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5734
                        s = t.rights;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5735
                    while (s != null) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5736
                        t.result = reducer.applyAsDouble(t.result, s.result);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5737
                        s = t.rights = s.nextRight;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5738
                    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5739
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5740
            }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5741
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5742
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5743
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  5744
    @SuppressWarnings("serial")
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5745
    static final class MapReduceKeysToLongTask<K,V>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5746
        extends BulkTask<K,V,Long> {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5747
        final ToLongFunction<? super K> transformer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5748
        final LongBinaryOperator reducer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5749
        final long basis;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5750
        long result;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5751
        MapReduceKeysToLongTask<K,V> rights, nextRight;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5752
        MapReduceKeysToLongTask
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5753
            (BulkTask<K,V,?> p, int b, int i, int f, Node<K,V>[] t,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5754
             MapReduceKeysToLongTask<K,V> nextRight,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5755
             ToLongFunction<? super K> transformer,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5756
             long basis,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5757
             LongBinaryOperator reducer) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5758
            super(p, b, i, f, t); this.nextRight = nextRight;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5759
            this.transformer = transformer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5760
            this.basis = basis; this.reducer = reducer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5761
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5762
        public final Long getRawResult() { return result; }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5763
        public final void compute() {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5764
            final ToLongFunction<? super K> transformer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5765
            final LongBinaryOperator reducer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5766
            if ((transformer = this.transformer) != null &&
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5767
                (reducer = this.reducer) != null) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5768
                long r = this.basis;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5769
                for (int i = baseIndex, f, h; batch > 0 &&
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5770
                         (h = ((f = baseLimit) + i) >>> 1) > i;) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5771
                    addToPendingCount(1);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5772
                    (rights = new MapReduceKeysToLongTask<K,V>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5773
                     (this, batch >>>= 1, baseLimit = h, f, tab,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5774
                      rights, transformer, r, reducer)).fork();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5775
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5776
                for (Node<K,V> p; (p = advance()) != null; )
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  5777
                    r = reducer.applyAsLong(r, transformer.applyAsLong(p.key));
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5778
                result = r;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5779
                CountedCompleter<?> c;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5780
                for (c = firstComplete(); c != null; c = c.nextComplete()) {
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  5781
                    @SuppressWarnings("unchecked") MapReduceKeysToLongTask<K,V>
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5782
                        t = (MapReduceKeysToLongTask<K,V>)c,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5783
                        s = t.rights;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5784
                    while (s != null) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5785
                        t.result = reducer.applyAsLong(t.result, s.result);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5786
                        s = t.rights = s.nextRight;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5787
                    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5788
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5789
            }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5790
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5791
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5792
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  5793
    @SuppressWarnings("serial")
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5794
    static final class MapReduceValuesToLongTask<K,V>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5795
        extends BulkTask<K,V,Long> {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5796
        final ToLongFunction<? super V> transformer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5797
        final LongBinaryOperator reducer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5798
        final long basis;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5799
        long result;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5800
        MapReduceValuesToLongTask<K,V> rights, nextRight;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5801
        MapReduceValuesToLongTask
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5802
            (BulkTask<K,V,?> p, int b, int i, int f, Node<K,V>[] t,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5803
             MapReduceValuesToLongTask<K,V> nextRight,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5804
             ToLongFunction<? super V> transformer,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5805
             long basis,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5806
             LongBinaryOperator reducer) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5807
            super(p, b, i, f, t); this.nextRight = nextRight;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5808
            this.transformer = transformer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5809
            this.basis = basis; this.reducer = reducer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5810
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5811
        public final Long getRawResult() { return result; }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5812
        public final void compute() {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5813
            final ToLongFunction<? super V> transformer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5814
            final LongBinaryOperator reducer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5815
            if ((transformer = this.transformer) != null &&
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5816
                (reducer = this.reducer) != null) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5817
                long r = this.basis;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5818
                for (int i = baseIndex, f, h; batch > 0 &&
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5819
                         (h = ((f = baseLimit) + i) >>> 1) > i;) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5820
                    addToPendingCount(1);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5821
                    (rights = new MapReduceValuesToLongTask<K,V>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5822
                     (this, batch >>>= 1, baseLimit = h, f, tab,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5823
                      rights, transformer, r, reducer)).fork();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5824
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5825
                for (Node<K,V> p; (p = advance()) != null; )
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5826
                    r = reducer.applyAsLong(r, transformer.applyAsLong(p.val));
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5827
                result = r;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5828
                CountedCompleter<?> c;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5829
                for (c = firstComplete(); c != null; c = c.nextComplete()) {
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  5830
                    @SuppressWarnings("unchecked") MapReduceValuesToLongTask<K,V>
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5831
                        t = (MapReduceValuesToLongTask<K,V>)c,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5832
                        s = t.rights;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5833
                    while (s != null) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5834
                        t.result = reducer.applyAsLong(t.result, s.result);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5835
                        s = t.rights = s.nextRight;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5836
                    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5837
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5838
            }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5839
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5840
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5841
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  5842
    @SuppressWarnings("serial")
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5843
    static final class MapReduceEntriesToLongTask<K,V>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5844
        extends BulkTask<K,V,Long> {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5845
        final ToLongFunction<Map.Entry<K,V>> transformer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5846
        final LongBinaryOperator reducer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5847
        final long basis;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5848
        long result;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5849
        MapReduceEntriesToLongTask<K,V> rights, nextRight;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5850
        MapReduceEntriesToLongTask
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5851
            (BulkTask<K,V,?> p, int b, int i, int f, Node<K,V>[] t,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5852
             MapReduceEntriesToLongTask<K,V> nextRight,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5853
             ToLongFunction<Map.Entry<K,V>> transformer,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5854
             long basis,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5855
             LongBinaryOperator reducer) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5856
            super(p, b, i, f, t); this.nextRight = nextRight;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5857
            this.transformer = transformer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5858
            this.basis = basis; this.reducer = reducer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5859
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5860
        public final Long getRawResult() { return result; }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5861
        public final void compute() {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5862
            final ToLongFunction<Map.Entry<K,V>> transformer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5863
            final LongBinaryOperator reducer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5864
            if ((transformer = this.transformer) != null &&
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5865
                (reducer = this.reducer) != null) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5866
                long r = this.basis;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5867
                for (int i = baseIndex, f, h; batch > 0 &&
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5868
                         (h = ((f = baseLimit) + i) >>> 1) > i;) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5869
                    addToPendingCount(1);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5870
                    (rights = new MapReduceEntriesToLongTask<K,V>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5871
                     (this, batch >>>= 1, baseLimit = h, f, tab,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5872
                      rights, transformer, r, reducer)).fork();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5873
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5874
                for (Node<K,V> p; (p = advance()) != null; )
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5875
                    r = reducer.applyAsLong(r, transformer.applyAsLong(p));
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5876
                result = r;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5877
                CountedCompleter<?> c;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5878
                for (c = firstComplete(); c != null; c = c.nextComplete()) {
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  5879
                    @SuppressWarnings("unchecked") MapReduceEntriesToLongTask<K,V>
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5880
                        t = (MapReduceEntriesToLongTask<K,V>)c,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5881
                        s = t.rights;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5882
                    while (s != null) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5883
                        t.result = reducer.applyAsLong(t.result, s.result);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5884
                        s = t.rights = s.nextRight;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5885
                    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5886
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5887
            }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5888
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5889
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5890
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  5891
    @SuppressWarnings("serial")
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5892
    static final class MapReduceMappingsToLongTask<K,V>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5893
        extends BulkTask<K,V,Long> {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5894
        final ToLongBiFunction<? super K, ? super V> transformer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5895
        final LongBinaryOperator reducer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5896
        final long basis;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5897
        long result;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5898
        MapReduceMappingsToLongTask<K,V> rights, nextRight;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5899
        MapReduceMappingsToLongTask
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5900
            (BulkTask<K,V,?> p, int b, int i, int f, Node<K,V>[] t,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5901
             MapReduceMappingsToLongTask<K,V> nextRight,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5902
             ToLongBiFunction<? super K, ? super V> transformer,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5903
             long basis,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5904
             LongBinaryOperator reducer) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5905
            super(p, b, i, f, t); this.nextRight = nextRight;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5906
            this.transformer = transformer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5907
            this.basis = basis; this.reducer = reducer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5908
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5909
        public final Long getRawResult() { return result; }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5910
        public final void compute() {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5911
            final ToLongBiFunction<? super K, ? super V> transformer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5912
            final LongBinaryOperator reducer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5913
            if ((transformer = this.transformer) != null &&
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5914
                (reducer = this.reducer) != null) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5915
                long r = this.basis;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5916
                for (int i = baseIndex, f, h; batch > 0 &&
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5917
                         (h = ((f = baseLimit) + i) >>> 1) > i;) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5918
                    addToPendingCount(1);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5919
                    (rights = new MapReduceMappingsToLongTask<K,V>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5920
                     (this, batch >>>= 1, baseLimit = h, f, tab,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5921
                      rights, transformer, r, reducer)).fork();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5922
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5923
                for (Node<K,V> p; (p = advance()) != null; )
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  5924
                    r = reducer.applyAsLong(r, transformer.applyAsLong(p.key, p.val));
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5925
                result = r;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5926
                CountedCompleter<?> c;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5927
                for (c = firstComplete(); c != null; c = c.nextComplete()) {
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  5928
                    @SuppressWarnings("unchecked") MapReduceMappingsToLongTask<K,V>
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5929
                        t = (MapReduceMappingsToLongTask<K,V>)c,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5930
                        s = t.rights;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5931
                    while (s != null) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5932
                        t.result = reducer.applyAsLong(t.result, s.result);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5933
                        s = t.rights = s.nextRight;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5934
                    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5935
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5936
            }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5937
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5938
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5939
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  5940
    @SuppressWarnings("serial")
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5941
    static final class MapReduceKeysToIntTask<K,V>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5942
        extends BulkTask<K,V,Integer> {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5943
        final ToIntFunction<? super K> transformer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5944
        final IntBinaryOperator reducer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5945
        final int basis;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5946
        int result;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5947
        MapReduceKeysToIntTask<K,V> rights, nextRight;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5948
        MapReduceKeysToIntTask
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5949
            (BulkTask<K,V,?> p, int b, int i, int f, Node<K,V>[] t,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5950
             MapReduceKeysToIntTask<K,V> nextRight,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5951
             ToIntFunction<? super K> transformer,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5952
             int basis,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5953
             IntBinaryOperator reducer) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5954
            super(p, b, i, f, t); this.nextRight = nextRight;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5955
            this.transformer = transformer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5956
            this.basis = basis; this.reducer = reducer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5957
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5958
        public final Integer getRawResult() { return result; }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5959
        public final void compute() {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5960
            final ToIntFunction<? super K> transformer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5961
            final IntBinaryOperator reducer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5962
            if ((transformer = this.transformer) != null &&
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5963
                (reducer = this.reducer) != null) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5964
                int r = this.basis;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5965
                for (int i = baseIndex, f, h; batch > 0 &&
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5966
                         (h = ((f = baseLimit) + i) >>> 1) > i;) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5967
                    addToPendingCount(1);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5968
                    (rights = new MapReduceKeysToIntTask<K,V>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5969
                     (this, batch >>>= 1, baseLimit = h, f, tab,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5970
                      rights, transformer, r, reducer)).fork();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5971
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5972
                for (Node<K,V> p; (p = advance()) != null; )
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  5973
                    r = reducer.applyAsInt(r, transformer.applyAsInt(p.key));
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5974
                result = r;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5975
                CountedCompleter<?> c;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5976
                for (c = firstComplete(); c != null; c = c.nextComplete()) {
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  5977
                    @SuppressWarnings("unchecked") MapReduceKeysToIntTask<K,V>
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5978
                        t = (MapReduceKeysToIntTask<K,V>)c,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5979
                        s = t.rights;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5980
                    while (s != null) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5981
                        t.result = reducer.applyAsInt(t.result, s.result);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5982
                        s = t.rights = s.nextRight;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5983
                    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5984
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5985
            }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5986
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5987
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5988
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  5989
    @SuppressWarnings("serial")
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5990
    static final class MapReduceValuesToIntTask<K,V>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5991
        extends BulkTask<K,V,Integer> {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5992
        final ToIntFunction<? super V> transformer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5993
        final IntBinaryOperator reducer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5994
        final int basis;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5995
        int result;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5996
        MapReduceValuesToIntTask<K,V> rights, nextRight;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5997
        MapReduceValuesToIntTask
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5998
            (BulkTask<K,V,?> p, int b, int i, int f, Node<K,V>[] t,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  5999
             MapReduceValuesToIntTask<K,V> nextRight,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6000
             ToIntFunction<? super V> transformer,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6001
             int basis,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6002
             IntBinaryOperator reducer) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6003
            super(p, b, i, f, t); this.nextRight = nextRight;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6004
            this.transformer = transformer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6005
            this.basis = basis; this.reducer = reducer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6006
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6007
        public final Integer getRawResult() { return result; }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6008
        public final void compute() {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6009
            final ToIntFunction<? super V> transformer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6010
            final IntBinaryOperator reducer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6011
            if ((transformer = this.transformer) != null &&
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6012
                (reducer = this.reducer) != null) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6013
                int r = this.basis;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6014
                for (int i = baseIndex, f, h; batch > 0 &&
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6015
                         (h = ((f = baseLimit) + i) >>> 1) > i;) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6016
                    addToPendingCount(1);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6017
                    (rights = new MapReduceValuesToIntTask<K,V>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6018
                     (this, batch >>>= 1, baseLimit = h, f, tab,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6019
                      rights, transformer, r, reducer)).fork();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6020
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6021
                for (Node<K,V> p; (p = advance()) != null; )
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6022
                    r = reducer.applyAsInt(r, transformer.applyAsInt(p.val));
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6023
                result = r;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6024
                CountedCompleter<?> c;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6025
                for (c = firstComplete(); c != null; c = c.nextComplete()) {
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  6026
                    @SuppressWarnings("unchecked") MapReduceValuesToIntTask<K,V>
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6027
                        t = (MapReduceValuesToIntTask<K,V>)c,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6028
                        s = t.rights;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6029
                    while (s != null) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6030
                        t.result = reducer.applyAsInt(t.result, s.result);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6031
                        s = t.rights = s.nextRight;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6032
                    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6033
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6034
            }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6035
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6036
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6037
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  6038
    @SuppressWarnings("serial")
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6039
    static final class MapReduceEntriesToIntTask<K,V>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6040
        extends BulkTask<K,V,Integer> {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6041
        final ToIntFunction<Map.Entry<K,V>> transformer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6042
        final IntBinaryOperator reducer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6043
        final int basis;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6044
        int result;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6045
        MapReduceEntriesToIntTask<K,V> rights, nextRight;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6046
        MapReduceEntriesToIntTask
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6047
            (BulkTask<K,V,?> p, int b, int i, int f, Node<K,V>[] t,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6048
             MapReduceEntriesToIntTask<K,V> nextRight,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6049
             ToIntFunction<Map.Entry<K,V>> transformer,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6050
             int basis,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6051
             IntBinaryOperator reducer) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6052
            super(p, b, i, f, t); this.nextRight = nextRight;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6053
            this.transformer = transformer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6054
            this.basis = basis; this.reducer = reducer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6055
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6056
        public final Integer getRawResult() { return result; }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6057
        public final void compute() {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6058
            final ToIntFunction<Map.Entry<K,V>> transformer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6059
            final IntBinaryOperator reducer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6060
            if ((transformer = this.transformer) != null &&
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6061
                (reducer = this.reducer) != null) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6062
                int r = this.basis;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6063
                for (int i = baseIndex, f, h; batch > 0 &&
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6064
                         (h = ((f = baseLimit) + i) >>> 1) > i;) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6065
                    addToPendingCount(1);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6066
                    (rights = new MapReduceEntriesToIntTask<K,V>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6067
                     (this, batch >>>= 1, baseLimit = h, f, tab,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6068
                      rights, transformer, r, reducer)).fork();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6069
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6070
                for (Node<K,V> p; (p = advance()) != null; )
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6071
                    r = reducer.applyAsInt(r, transformer.applyAsInt(p));
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6072
                result = r;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6073
                CountedCompleter<?> c;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6074
                for (c = firstComplete(); c != null; c = c.nextComplete()) {
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  6075
                    @SuppressWarnings("unchecked") MapReduceEntriesToIntTask<K,V>
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6076
                        t = (MapReduceEntriesToIntTask<K,V>)c,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6077
                        s = t.rights;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6078
                    while (s != null) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6079
                        t.result = reducer.applyAsInt(t.result, s.result);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6080
                        s = t.rights = s.nextRight;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6081
                    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6082
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6083
            }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6084
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6085
    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6086
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  6087
    @SuppressWarnings("serial")
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6088
    static final class MapReduceMappingsToIntTask<K,V>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6089
        extends BulkTask<K,V,Integer> {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6090
        final ToIntBiFunction<? super K, ? super V> transformer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6091
        final IntBinaryOperator reducer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6092
        final int basis;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6093
        int result;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6094
        MapReduceMappingsToIntTask<K,V> rights, nextRight;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6095
        MapReduceMappingsToIntTask
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6096
            (BulkTask<K,V,?> p, int b, int i, int f, Node<K,V>[] t,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6097
             MapReduceMappingsToIntTask<K,V> nextRight,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6098
             ToIntBiFunction<? super K, ? super V> transformer,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6099
             int basis,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6100
             IntBinaryOperator reducer) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6101
            super(p, b, i, f, t); this.nextRight = nextRight;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6102
            this.transformer = transformer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6103
            this.basis = basis; this.reducer = reducer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6104
        }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6105
        public final Integer getRawResult() { return result; }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6106
        public final void compute() {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6107
            final ToIntBiFunction<? super K, ? super V> transformer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6108
            final IntBinaryOperator reducer;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6109
            if ((transformer = this.transformer) != null &&
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6110
                (reducer = this.reducer) != null) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6111
                int r = this.basis;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6112
                for (int i = baseIndex, f, h; batch > 0 &&
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6113
                         (h = ((f = baseLimit) + i) >>> 1) > i;) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6114
                    addToPendingCount(1);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6115
                    (rights = new MapReduceMappingsToIntTask<K,V>
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6116
                     (this, batch >>>= 1, baseLimit = h, f, tab,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6117
                      rights, transformer, r, reducer)).fork();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6118
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6119
                for (Node<K,V> p; (p = advance()) != null; )
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  6120
                    r = reducer.applyAsInt(r, transformer.applyAsInt(p.key, p.val));
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6121
                result = r;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6122
                CountedCompleter<?> c;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6123
                for (c = firstComplete(); c != null; c = c.nextComplete()) {
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  6124
                    @SuppressWarnings("unchecked") MapReduceMappingsToIntTask<K,V>
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6125
                        t = (MapReduceMappingsToIntTask<K,V>)c,
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6126
                        s = t.rights;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6127
                    while (s != null) {
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6128
                        t.result = reducer.applyAsInt(t.result, s.result);
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6129
                        s = t.rights = s.nextRight;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6130
                    }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6131
                }
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6132
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6133
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6134
    }
9279
5f5d493d30a0 7036559: ConcurrentHashMap footprint and contention improvements
dl
parents: 9242
diff changeset
  6135
5f5d493d30a0 7036559: ConcurrentHashMap footprint and contention improvements
dl
parents: 9242
diff changeset
  6136
    // Unsafe mechanics
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6137
    private static final sun.misc.Unsafe U;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6138
    private static final long SIZECTL;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6139
    private static final long TRANSFERINDEX;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6140
    private static final long TRANSFERORIGIN;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6141
    private static final long BASECOUNT;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6142
    private static final long CELLSBUSY;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6143
    private static final long CELLVALUE;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6144
    private static final long ABASE;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6145
    private static final int ASHIFT;
9279
5f5d493d30a0 7036559: ConcurrentHashMap footprint and contention improvements
dl
parents: 9242
diff changeset
  6146
5f5d493d30a0 7036559: ConcurrentHashMap footprint and contention improvements
dl
parents: 9242
diff changeset
  6147
    static {
5f5d493d30a0 7036559: ConcurrentHashMap footprint and contention improvements
dl
parents: 9242
diff changeset
  6148
        try {
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6149
            U = sun.misc.Unsafe.getUnsafe();
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6150
            Class<?> k = ConcurrentHashMap.class;
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6151
            SIZECTL = U.objectFieldOffset
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6152
                (k.getDeclaredField("sizeCtl"));
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6153
            TRANSFERINDEX = U.objectFieldOffset
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6154
                (k.getDeclaredField("transferIndex"));
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6155
            TRANSFERORIGIN = U.objectFieldOffset
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6156
                (k.getDeclaredField("transferOrigin"));
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6157
            BASECOUNT = U.objectFieldOffset
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6158
                (k.getDeclaredField("baseCount"));
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6159
            CELLSBUSY = U.objectFieldOffset
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6160
                (k.getDeclaredField("cellsBusy"));
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  6161
            Class<?> ck = CounterCell.class;
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6162
            CELLVALUE = U.objectFieldOffset
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6163
                (ck.getDeclaredField("value"));
18802
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  6164
            Class<?> ak = Node[].class;
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  6165
            ABASE = U.arrayBaseOffset(ak);
68564211d16b 8019484: Sync j.u.c.ConcurrentHashMap from 166 to tl
psandoz
parents: 17953
diff changeset
  6166
            int scale = U.arrayIndexScale(ak);
17945
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6167
            if ((scale & (scale - 1)) != 0)
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6168
                throw new Error("data type scale not a power of two");
97634ef9dd1c 8005704: Update ConcurrentHashMap to v8
dl
parents: 17717
diff changeset
  6169
            ASHIFT = 31 - Integer.numberOfLeadingZeros(scale);
9279
5f5d493d30a0 7036559: ConcurrentHashMap footprint and contention improvements
dl
parents: 9242
diff changeset
  6170
        } catch (Exception e) {
5f5d493d30a0 7036559: ConcurrentHashMap footprint and contention improvements
dl
parents: 9242
diff changeset
  6171
            throw new Error(e);
5f5d493d30a0 7036559: ConcurrentHashMap footprint and contention improvements
dl
parents: 9242
diff changeset
  6172
        }
5f5d493d30a0 7036559: ConcurrentHashMap footprint and contention improvements
dl
parents: 9242
diff changeset
  6173
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  6174
}