--- jsr166/src/jsr166y/LinkedTransferQueue.java 2011/05/27 23:41:19 1.85 +++ jsr166/src/jsr166y/LinkedTransferQueue.java 2013/01/09 02:51:37 1.92 @@ -301,8 +301,8 @@ public class LinkedTransferQueue exte * of less-contended queues. During spins threads check their * interrupt status and generate a thread-local random number * to decide to occasionally perform a Thread.yield. While - * yield has underdefined specs, we assume that might it help, - * and will not hurt in limiting impact of spinning on busy + * yield has underdefined specs, we assume that it might help, + * and will not hurt, in limiting impact of spinning on busy * systems. We also use smaller (1/2) spins for nodes that are * not known to be front but whose predecessors have not * blocked -- these "chained" spins avoid artifacts of @@ -513,7 +513,7 @@ public class LinkedTransferQueue exte static { try { UNSAFE = getUnsafe(); - Class k = Node.class; + Class k = Node.class; itemOffset = UNSAFE.objectFieldOffset (k.getDeclaredField("item")); nextOffset = UNSAFE.objectFieldOffset @@ -598,7 +598,7 @@ public class LinkedTransferQueue exte break; // unless slack < 2 } LockSupport.unpark(p.waiter); - return this.cast(item); + return LinkedTransferQueue.cast(item); } } Node n = p.next; @@ -676,7 +676,7 @@ public class LinkedTransferQueue exte if (item != e) { // matched // assert item != s; s.forgetContents(); // avoid garbage - return this.cast(item); + return LinkedTransferQueue.cast(item); } if ((w.isInterrupted() || (timed && nanos <= 0)) && s.casItem(e, s)) { // cancel @@ -757,7 +757,7 @@ public class LinkedTransferQueue exte Object item = p.item; if (p.isData) { if (item != null && item != p) - return this.cast(item); + return LinkedTransferQueue.cast(item); } else if (item == null) return null; @@ -1134,8 +1134,7 @@ public class LinkedTransferQueue exte if (c == this) throw new IllegalArgumentException(); int n = 0; - E e; - while ( (e = poll()) != null) { + for (E e; (e = poll()) != null;) { c.add(e); ++n; } @@ -1152,8 +1151,7 @@ public class LinkedTransferQueue exte if (c == this) throw new IllegalArgumentException(); int n = 0; - E e; - while (n < maxElements && (e = poll()) != null) { + for (E e; n < maxElements && (e = poll()) != null;) { c.add(e); ++n; } @@ -1293,7 +1291,8 @@ public class LinkedTransferQueue exte throws java.io.IOException, ClassNotFoundException { s.defaultReadObject(); for (;;) { - @SuppressWarnings("unchecked") E item = (E) s.readObject(); + @SuppressWarnings("unchecked") + E item = (E) s.readObject(); if (item == null) break; else @@ -1310,7 +1309,7 @@ public class LinkedTransferQueue exte static { try { UNSAFE = getUnsafe(); - Class k = LinkedTransferQueue.class; + Class k = LinkedTransferQueue.class; headOffset = UNSAFE.objectFieldOffset (k.getDeclaredField("head")); tailOffset = UNSAFE.objectFieldOffset @@ -1332,22 +1331,23 @@ public class LinkedTransferQueue exte static sun.misc.Unsafe getUnsafe() { try { return sun.misc.Unsafe.getUnsafe(); - } catch (SecurityException se) { - try { - return java.security.AccessController.doPrivileged - (new java.security - .PrivilegedExceptionAction() { - public sun.misc.Unsafe run() throws Exception { - java.lang.reflect.Field f = sun.misc - .Unsafe.class.getDeclaredField("theUnsafe"); - f.setAccessible(true); - return (sun.misc.Unsafe) f.get(null); - }}); - } catch (java.security.PrivilegedActionException e) { - throw new RuntimeException("Could not initialize intrinsics", - e.getCause()); - } + } catch (SecurityException tryReflectionInstead) {} + try { + return java.security.AccessController.doPrivileged + (new java.security.PrivilegedExceptionAction() { + public sun.misc.Unsafe run() throws Exception { + Class k = sun.misc.Unsafe.class; + for (java.lang.reflect.Field f : k.getDeclaredFields()) { + f.setAccessible(true); + Object x = f.get(null); + if (k.isInstance(x)) + return k.cast(x); + } + throw new NoSuchFieldError("the Unsafe"); + }}); + } catch (java.security.PrivilegedActionException e) { + throw new RuntimeException("Could not initialize intrinsics", + e.getCause()); } } - }