6 |
|
|
7 |
|
package java.util.concurrent; |
8 |
|
|
9 |
+ |
import java.lang.invoke.MethodHandles; |
10 |
+ |
import java.lang.invoke.VarHandle; |
11 |
|
import java.util.AbstractQueue; |
12 |
|
import java.util.Arrays; |
13 |
|
import java.util.Collection; |
262 |
|
lock.unlock(); // must release and then re-acquire main lock |
263 |
|
Object[] newArray = null; |
264 |
|
if (allocationSpinLock == 0 && |
265 |
< |
U.compareAndSwapInt(this, ALLOCATIONSPINLOCK, 0, 1)) { |
265 |
> |
ALLOCATIONSPINLOCK.compareAndSet(this, 0, 1)) { |
266 |
|
try { |
267 |
|
int newCap = oldCap + ((oldCap < 64) ? |
268 |
|
(oldCap + 2) : // grow faster if small |
982 |
|
return new PBQSpliterator<E>(this, null, 0, -1); |
983 |
|
} |
984 |
|
|
985 |
< |
// Unsafe mechanics |
986 |
< |
private static final jdk.internal.misc.Unsafe U = jdk.internal.misc.Unsafe.getUnsafe(); |
985 |
< |
private static final long ALLOCATIONSPINLOCK; |
985 |
> |
// VarHandle mechanics |
986 |
> |
private static final VarHandle ALLOCATIONSPINLOCK; |
987 |
|
static { |
988 |
|
try { |
989 |
< |
ALLOCATIONSPINLOCK = U.objectFieldOffset |
990 |
< |
(PriorityBlockingQueue.class.getDeclaredField("allocationSpinLock")); |
989 |
> |
MethodHandles.Lookup l = MethodHandles.lookup(); |
990 |
> |
ALLOCATIONSPINLOCK = l.findVarHandle(PriorityBlockingQueue.class, |
991 |
> |
"allocationSpinLock", |
992 |
> |
int.class); |
993 |
|
} catch (ReflectiveOperationException e) { |
994 |
|
throw new Error(e); |
995 |
|
} |