src/java.base/share/classes/java/util/concurrent/locks/AbstractQueuedLongSynchronizer.java

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


1804             for (Node w = firstWaiter; w != null; w = w.nextWaiter) {
1805                 if (w.waitStatus == Node.CONDITION) {
1806                     Thread t = w.thread;
1807                     if (t != null)
1808                         list.add(t);
1809                 }
1810             }
1811             return list;
1812         }
1813     }
1814 
1815     /**
1816      * Setup to support compareAndSet. We need to natively implement
1817      * this here: For the sake of permitting future enhancements, we
1818      * cannot explicitly subclass AtomicLong, which would be
1819      * efficient and useful otherwise. So, as the lesser of evils, we
1820      * natively implement using hotspot intrinsics API. And while we
1821      * are at it, we do the same for other CASable fields (which could
1822      * otherwise be done with atomic field updaters).
1823      */
1824     private static final sun.misc.Unsafe U = sun.misc.Unsafe.getUnsafe();
1825     private static final long STATE;
1826     private static final long HEAD;
1827     private static final long TAIL;
1828 
1829     static {
1830         try {
1831             STATE = U.objectFieldOffset
1832                 (AbstractQueuedLongSynchronizer.class.getDeclaredField("state"));
1833             HEAD = U.objectFieldOffset
1834                 (AbstractQueuedLongSynchronizer.class.getDeclaredField("head"));
1835             TAIL = U.objectFieldOffset
1836                 (AbstractQueuedLongSynchronizer.class.getDeclaredField("tail"));
1837         } catch (ReflectiveOperationException e) {
1838             throw new Error(e);
1839         }
1840 
1841         // Reduce the risk of rare disastrous classloading in first call to
1842         // LockSupport.park: https://bugs.openjdk.java.net/browse/JDK-8074773
1843         Class<?> ensureLoaded = LockSupport.class;
1844     }


1804             for (Node w = firstWaiter; w != null; w = w.nextWaiter) {
1805                 if (w.waitStatus == Node.CONDITION) {
1806                     Thread t = w.thread;
1807                     if (t != null)
1808                         list.add(t);
1809                 }
1810             }
1811             return list;
1812         }
1813     }
1814 
1815     /**
1816      * Setup to support compareAndSet. We need to natively implement
1817      * this here: For the sake of permitting future enhancements, we
1818      * cannot explicitly subclass AtomicLong, which would be
1819      * efficient and useful otherwise. So, as the lesser of evils, we
1820      * natively implement using hotspot intrinsics API. And while we
1821      * are at it, we do the same for other CASable fields (which could
1822      * otherwise be done with atomic field updaters).
1823      */
1824     private static final jdk.internal.misc.Unsafe U = jdk.internal.misc.Unsafe.getUnsafe();
1825     private static final long STATE;
1826     private static final long HEAD;
1827     private static final long TAIL;
1828 
1829     static {
1830         try {
1831             STATE = U.objectFieldOffset
1832                 (AbstractQueuedLongSynchronizer.class.getDeclaredField("state"));
1833             HEAD = U.objectFieldOffset
1834                 (AbstractQueuedLongSynchronizer.class.getDeclaredField("head"));
1835             TAIL = U.objectFieldOffset
1836                 (AbstractQueuedLongSynchronizer.class.getDeclaredField("tail"));
1837         } catch (ReflectiveOperationException e) {
1838             throw new Error(e);
1839         }
1840 
1841         // Reduce the risk of rare disastrous classloading in first call to
1842         // LockSupport.park: https://bugs.openjdk.java.net/browse/JDK-8074773
1843         Class<?> ensureLoaded = LockSupport.class;
1844     }