345 |
|
null, null, 1); |
346 |
|
} |
347 |
|
|
348 |
– |
/** Updater for casHead */ |
349 |
– |
private static final |
350 |
– |
AtomicReferenceFieldUpdater<ConcurrentSkipListMap, HeadIndex> |
351 |
– |
headUpdater = AtomicReferenceFieldUpdater.newUpdater |
352 |
– |
(ConcurrentSkipListMap.class, HeadIndex.class, "head"); |
353 |
– |
|
348 |
|
/** |
349 |
|
* compareAndSet head node |
350 |
|
*/ |
351 |
|
private boolean casHead(HeadIndex<K,V> cmp, HeadIndex<K,V> val) { |
352 |
< |
return headUpdater.compareAndSet(this, cmp, val); |
352 |
> |
return UNSAFE.compareAndSwapObject(this, headOffset, cmp, val); |
353 |
|
} |
354 |
|
|
355 |
|
/* ---------------- Nodes -------------- */ |
388 |
|
this.next = next; |
389 |
|
} |
390 |
|
|
397 |
– |
/** Updater for casNext */ |
398 |
– |
static final AtomicReferenceFieldUpdater<Node, Node> |
399 |
– |
nextUpdater = AtomicReferenceFieldUpdater.newUpdater |
400 |
– |
(Node.class, Node.class, "next"); |
401 |
– |
|
402 |
– |
/** Updater for casValue */ |
403 |
– |
static final AtomicReferenceFieldUpdater<Node, Object> |
404 |
– |
valueUpdater = AtomicReferenceFieldUpdater.newUpdater |
405 |
– |
(Node.class, Object.class, "value"); |
406 |
– |
|
391 |
|
/** |
392 |
|
* compareAndSet value field |
393 |
|
*/ |
394 |
|
boolean casValue(Object cmp, Object val) { |
395 |
< |
return valueUpdater.compareAndSet(this, cmp, val); |
395 |
> |
return UNSAFE.compareAndSwapObject(this, valueOffset, cmp, val); |
396 |
|
} |
397 |
< |
|
397 |
> |
|
398 |
|
/** |
399 |
|
* compareAndSet next field |
400 |
|
*/ |
401 |
|
boolean casNext(Node<K,V> cmp, Node<K,V> val) { |
402 |
< |
return nextUpdater.compareAndSet(this, cmp, val); |
402 |
> |
return UNSAFE.compareAndSwapObject(this, nextOffset, cmp, val); |
403 |
|
} |
404 |
|
|
405 |
|
/** |
477 |
|
return null; |
478 |
|
return new AbstractMap.SimpleImmutableEntry<K,V>(key, v); |
479 |
|
} |
480 |
+ |
|
481 |
+ |
// Unsafe mechanics |
482 |
+ |
private static final sun.misc.Unsafe UNSAFE = sun.misc.Unsafe.getUnsafe(); |
483 |
+ |
private static final long valueOffset = |
484 |
+ |
objectFieldOffset(UNSAFE, "value", Node.class); |
485 |
+ |
private static final long nextOffset = |
486 |
+ |
objectFieldOffset(UNSAFE, "next", Node.class); |
487 |
+ |
|
488 |
|
} |
489 |
|
|
490 |
|
/* ---------------- Indexing -------------- */ |
510 |
|
this.right = right; |
511 |
|
} |
512 |
|
|
521 |
– |
/** Updater for casRight */ |
522 |
– |
static final AtomicReferenceFieldUpdater<Index, Index> |
523 |
– |
rightUpdater = AtomicReferenceFieldUpdater.newUpdater |
524 |
– |
(Index.class, Index.class, "right"); |
525 |
– |
|
513 |
|
/** |
514 |
|
* compareAndSet right field |
515 |
|
*/ |
516 |
|
final boolean casRight(Index<K,V> cmp, Index<K,V> val) { |
517 |
< |
return rightUpdater.compareAndSet(this, cmp, val); |
517 |
> |
return UNSAFE.compareAndSwapObject(this, rightOffset, cmp, val); |
518 |
|
} |
519 |
|
|
520 |
|
/** |
549 |
|
final boolean unlink(Index<K,V> succ) { |
550 |
|
return !indexesDeletedNode() && casRight(succ, succ.right); |
551 |
|
} |
552 |
+ |
|
553 |
+ |
// Unsafe mechanics |
554 |
+ |
private static final sun.misc.Unsafe UNSAFE = sun.misc.Unsafe.getUnsafe(); |
555 |
+ |
private static final long rightOffset = |
556 |
+ |
objectFieldOffset(UNSAFE, "right", Index.class); |
557 |
+ |
|
558 |
|
} |
559 |
|
|
560 |
|
/* ---------------- Head nodes -------------- */ |
3105 |
|
} |
3106 |
|
} |
3107 |
|
} |
3108 |
+ |
|
3109 |
+ |
// Unsafe mechanics |
3110 |
+ |
private static final sun.misc.Unsafe UNSAFE = sun.misc.Unsafe.getUnsafe(); |
3111 |
+ |
private static final long headOffset = |
3112 |
+ |
objectFieldOffset(UNSAFE, "head", ConcurrentSkipListMap.class); |
3113 |
+ |
|
3114 |
+ |
static long objectFieldOffset(sun.misc.Unsafe UNSAFE, |
3115 |
+ |
String field, Class<?> klazz) { |
3116 |
+ |
try { |
3117 |
+ |
return UNSAFE.objectFieldOffset(klazz.getDeclaredField(field)); |
3118 |
+ |
} catch (NoSuchFieldException e) { |
3119 |
+ |
// Convert Exception to corresponding Error |
3120 |
+ |
NoSuchFieldError error = new NoSuchFieldError(field); |
3121 |
+ |
error.initCause(e); |
3122 |
+ |
throw error; |
3123 |
+ |
} |
3124 |
+ |
} |
3125 |
+ |
|
3126 |
|
} |