ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/jsr166e/StampedLock.java
(Generate patch)

Comparing jsr166/src/jsr166e/StampedLock.java (file contents):
Revision 1.25 by jsr166, Sat Dec 15 22:26:29 2012 UTC vs.
Revision 1.26 by jsr166, Wed Jan 9 02:51:37 2013 UTC

# Line 1204 | Line 1204 | public class StampedLock implements java
1204      private static sun.misc.Unsafe getUnsafe() {
1205          try {
1206              return sun.misc.Unsafe.getUnsafe();
1207 <        } catch (SecurityException se) {
1208 <            try {
1209 <                return java.security.AccessController.doPrivileged
1210 <                    (new java.security
1211 <                     .PrivilegedExceptionAction<sun.misc.Unsafe>() {
1212 <                        public sun.misc.Unsafe run() throws Exception {
1213 <                            java.lang.reflect.Field f = sun.misc
1214 <                                .Unsafe.class.getDeclaredField("theUnsafe");
1215 <                            f.setAccessible(true);
1216 <                            return (sun.misc.Unsafe) f.get(null);
1217 <                        }});
1218 <            } catch (java.security.PrivilegedActionException e) {
1219 <                throw new RuntimeException("Could not initialize intrinsics",
1220 <                                           e.getCause());
1221 <            }
1207 >        } catch (SecurityException tryReflectionInstead) {}
1208 >        try {
1209 >            return java.security.AccessController.doPrivileged
1210 >            (new java.security.PrivilegedExceptionAction<sun.misc.Unsafe>() {
1211 >                public sun.misc.Unsafe run() throws Exception {
1212 >                    Class<sun.misc.Unsafe> k = sun.misc.Unsafe.class;
1213 >                    for (java.lang.reflect.Field f : k.getDeclaredFields()) {
1214 >                        f.setAccessible(true);
1215 >                        Object x = f.get(null);
1216 >                        if (k.isInstance(x))
1217 >                            return k.cast(x);
1218 >                    }
1219 >                    throw new NoSuchFieldError("the Unsafe");
1220 >                }});
1221 >        } catch (java.security.PrivilegedActionException e) {
1222 >            throw new RuntimeException("Could not initialize intrinsics",
1223 >                                       e.getCause());
1224          }
1225      }
1224
1226   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines