src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListSet.java

Print this page
rev 12972 : 8140606: Update library code to use internal Unsafe
Reviewed-by: duke


 493      * <p>The spliterator's comparator (see
 494      * {@link java.util.Spliterator#getComparator()}) is {@code null} if
 495      * the set's comparator (see {@link #comparator()}) is {@code null}.
 496      * Otherwise, the spliterator's comparator is the same as or imposes the
 497      * same total ordering as the set's comparator.
 498      *
 499      * @return a {@code Spliterator} over the elements in this set
 500      * @since 1.8
 501      */
 502     public Spliterator<E> spliterator() {
 503         return (m instanceof ConcurrentSkipListMap)
 504             ? ((ConcurrentSkipListMap<E,?>)m).keySpliterator()
 505             : ((ConcurrentSkipListMap.SubMap<E,?>)m).new SubMapKeyIterator();
 506     }
 507 
 508     // Support for resetting map in clone
 509     private void setMap(ConcurrentNavigableMap<E,Object> map) {
 510         U.putObjectVolatile(this, MAP, map);
 511     }
 512 
 513     private static final sun.misc.Unsafe U = sun.misc.Unsafe.getUnsafe();
 514     private static final long MAP;
 515     static {
 516         try {
 517             MAP = U.objectFieldOffset
 518                 (ConcurrentSkipListSet.class.getDeclaredField("m"));
 519         } catch (ReflectiveOperationException e) {
 520             throw new Error(e);
 521         }
 522     }
 523 }


 493      * <p>The spliterator's comparator (see
 494      * {@link java.util.Spliterator#getComparator()}) is {@code null} if
 495      * the set's comparator (see {@link #comparator()}) is {@code null}.
 496      * Otherwise, the spliterator's comparator is the same as or imposes the
 497      * same total ordering as the set's comparator.
 498      *
 499      * @return a {@code Spliterator} over the elements in this set
 500      * @since 1.8
 501      */
 502     public Spliterator<E> spliterator() {
 503         return (m instanceof ConcurrentSkipListMap)
 504             ? ((ConcurrentSkipListMap<E,?>)m).keySpliterator()
 505             : ((ConcurrentSkipListMap.SubMap<E,?>)m).new SubMapKeyIterator();
 506     }
 507 
 508     // Support for resetting map in clone
 509     private void setMap(ConcurrentNavigableMap<E,Object> map) {
 510         U.putObjectVolatile(this, MAP, map);
 511     }
 512 
 513     private static final jdk.internal.misc.Unsafe U = jdk.internal.misc.Unsafe.getUnsafe();
 514     private static final long MAP;
 515     static {
 516         try {
 517             MAP = U.objectFieldOffset
 518                 (ConcurrentSkipListSet.class.getDeclaredField("m"));
 519         } catch (ReflectiveOperationException e) {
 520             throw new Error(e);
 521         }
 522     }
 523 }