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

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


1484     public String toString() {
1485         int c = sync.getCount();
1486         int w = Sync.exclusiveCount(c);
1487         int r = Sync.sharedCount(c);
1488 
1489         return super.toString() +
1490             "[Write locks = " + w + ", Read locks = " + r + "]";
1491     }
1492 
1493     /**
1494      * Returns the thread id for the given thread.  We must access
1495      * this directly rather than via method Thread.getId() because
1496      * getId() is not final, and has been known to be overridden in
1497      * ways that do not preserve unique mappings.
1498      */
1499     static final long getThreadId(Thread thread) {
1500         return U.getLongVolatile(thread, TID);
1501     }
1502 
1503     // Unsafe mechanics
1504     private static final sun.misc.Unsafe U = sun.misc.Unsafe.getUnsafe();
1505     private static final long TID;
1506     static {
1507         try {
1508             TID = U.objectFieldOffset
1509                 (Thread.class.getDeclaredField("tid"));
1510         } catch (ReflectiveOperationException e) {
1511             throw new Error(e);
1512         }
1513     }
1514 
1515 }


1484     public String toString() {
1485         int c = sync.getCount();
1486         int w = Sync.exclusiveCount(c);
1487         int r = Sync.sharedCount(c);
1488 
1489         return super.toString() +
1490             "[Write locks = " + w + ", Read locks = " + r + "]";
1491     }
1492 
1493     /**
1494      * Returns the thread id for the given thread.  We must access
1495      * this directly rather than via method Thread.getId() because
1496      * getId() is not final, and has been known to be overridden in
1497      * ways that do not preserve unique mappings.
1498      */
1499     static final long getThreadId(Thread thread) {
1500         return U.getLongVolatile(thread, TID);
1501     }
1502 
1503     // Unsafe mechanics
1504     private static final jdk.internal.misc.Unsafe U = jdk.internal.misc.Unsafe.getUnsafe();
1505     private static final long TID;
1506     static {
1507         try {
1508             TID = U.objectFieldOffset
1509                 (Thread.class.getDeclaredField("tid"));
1510         } catch (ReflectiveOperationException e) {
1511             throw new Error(e);
1512         }
1513     }
1514 
1515 }