61 |
|
* @author Martin Buchholz |
62 |
|
* @param <E> the type of elements held in this collection |
63 |
|
*/ |
64 |
– |
|
64 |
|
public class ConcurrentLinkedDeque<E> |
65 |
|
extends AbstractCollection<E> |
66 |
|
implements Deque<E>, java.io.Serializable { |
305 |
|
static { |
306 |
|
try { |
307 |
|
UNSAFE = getUnsafe(); |
308 |
< |
Class k = Node.class; |
308 |
> |
Class<?> k = Node.class; |
309 |
|
prevOffset = UNSAFE.objectFieldOffset |
310 |
|
(k.getDeclaredField("prev")); |
311 |
|
itemOffset = UNSAFE.objectFieldOffset |
1220 |
|
* The following code can be used to dump the deque into a newly |
1221 |
|
* allocated array of {@code String}: |
1222 |
|
* |
1223 |
< |
* <pre> |
1225 |
< |
* String[] y = x.toArray(new String[0]);</pre> |
1223 |
> |
* <pre> {@code String[] y = x.toArray(new String[0]);}</pre> |
1224 |
|
* |
1225 |
|
* Note that {@code toArray(new Object[0])} is identical in function to |
1226 |
|
* {@code toArray()}. |
1426 |
|
NEXT_TERMINATOR.prev = NEXT_TERMINATOR; |
1427 |
|
try { |
1428 |
|
UNSAFE = getUnsafe(); |
1429 |
< |
Class k = ConcurrentLinkedDeque.class; |
1429 |
> |
Class<?> k = ConcurrentLinkedDeque.class; |
1430 |
|
headOffset = UNSAFE.objectFieldOffset |
1431 |
|
(k.getDeclaredField("head")); |
1432 |
|
tailOffset = UNSAFE.objectFieldOffset |
1446 |
|
static sun.misc.Unsafe getUnsafe() { |
1447 |
|
try { |
1448 |
|
return sun.misc.Unsafe.getUnsafe(); |
1449 |
< |
} catch (SecurityException se) { |
1450 |
< |
try { |
1451 |
< |
return java.security.AccessController.doPrivileged |
1452 |
< |
(new java.security |
1453 |
< |
.PrivilegedExceptionAction<sun.misc.Unsafe>() { |
1454 |
< |
public sun.misc.Unsafe run() throws Exception { |
1455 |
< |
java.lang.reflect.Field f = sun.misc |
1456 |
< |
.Unsafe.class.getDeclaredField("theUnsafe"); |
1457 |
< |
f.setAccessible(true); |
1458 |
< |
return (sun.misc.Unsafe) f.get(null); |
1459 |
< |
}}); |
1460 |
< |
} catch (java.security.PrivilegedActionException e) { |
1461 |
< |
throw new RuntimeException("Could not initialize intrinsics", |
1462 |
< |
e.getCause()); |
1463 |
< |
} |
1449 |
> |
} catch (SecurityException tryReflectionInstead) {} |
1450 |
> |
try { |
1451 |
> |
return java.security.AccessController.doPrivileged |
1452 |
> |
(new java.security.PrivilegedExceptionAction<sun.misc.Unsafe>() { |
1453 |
> |
public sun.misc.Unsafe run() throws Exception { |
1454 |
> |
Class<sun.misc.Unsafe> k = sun.misc.Unsafe.class; |
1455 |
> |
for (java.lang.reflect.Field f : k.getDeclaredFields()) { |
1456 |
> |
f.setAccessible(true); |
1457 |
> |
Object x = f.get(null); |
1458 |
> |
if (k.isInstance(x)) |
1459 |
> |
return k.cast(x); |
1460 |
> |
} |
1461 |
> |
throw new NoSuchFieldError("the Unsafe"); |
1462 |
> |
}}); |
1463 |
> |
} catch (java.security.PrivilegedActionException e) { |
1464 |
> |
throw new RuntimeException("Could not initialize intrinsics", |
1465 |
> |
e.getCause()); |
1466 |
|
} |
1467 |
|
} |
1468 |
– |
|
1468 |
|
} |