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

Comparing jsr166/src/jsr166y/ForkJoinPool.java (file contents):
Revision 1.26 by jsr166, Sun Jul 26 13:34:25 2009 UTC vs.
Revision 1.27 by jsr166, Sun Jul 26 17:33:37 2009 UTC

# Line 1876 | Line 1876 | public class ForkJoinPool extends Abstra
1876          return new AdaptedCallable<T>(callable);
1877      }
1878  
1879 <
1880 <    // Unsafe mechanics for jsr166y 3rd party package.
1881 <    private static sun.misc.Unsafe getUnsafe() {
1882 <        try {
1883 <            return sun.misc.Unsafe.getUnsafe();
1884 <        } catch (SecurityException se) {
1885 <            try {
1886 <                return java.security.AccessController.doPrivileged
1887 <                    (new java.security.PrivilegedExceptionAction<sun.misc.Unsafe>() {
1888 <                        public sun.misc.Unsafe run() throws Exception {
1889 <                            return getUnsafeByReflection();
1890 <                        }});
1891 <            } catch (java.security.PrivilegedActionException e) {
1892 <                throw new RuntimeException("Could not initialize intrinsics",
1893 <                                           e.getCause());
1894 <            }
1895 <        }
1896 <    }
1897 <
1898 <    private static sun.misc.Unsafe getUnsafeByReflection()
1899 <            throws NoSuchFieldException, IllegalAccessException {
1900 <        java.lang.reflect.Field f =
1901 <            sun.misc.Unsafe.class.getDeclaredField("theUnsafe");
1902 <        f.setAccessible(true);
1903 <        return (sun.misc.Unsafe) f.get(null);
1904 <    }
1905 <
1906 <    private static long fieldOffset(String fieldName, Class<?> klazz) {
1907 <        try {
1908 <            return UNSAFE.objectFieldOffset(klazz.getDeclaredField(fieldName));
1909 <        } catch (NoSuchFieldException e) {
1910 <            // Convert Exception to Error
1911 <            NoSuchFieldError error = new NoSuchFieldError(fieldName);
1912 <            error.initCause(e);
1913 <            throw error;
1914 <        }
1915 <    }
1879 >    // Unsafe mechanics
1880  
1881      private static final sun.misc.Unsafe UNSAFE = getUnsafe();
1882      private static final long eventCountOffset =
1883 <        fieldOffset("eventCount", ForkJoinPool.class);
1883 >        objectFieldOffset("eventCount", ForkJoinPool.class);
1884      private static final long workerCountsOffset =
1885 <        fieldOffset("workerCounts", ForkJoinPool.class);
1885 >        objectFieldOffset("workerCounts", ForkJoinPool.class);
1886      private static final long runControlOffset =
1887 <        fieldOffset("runControl", ForkJoinPool.class);
1887 >        objectFieldOffset("runControl", ForkJoinPool.class);
1888      private static final long syncStackOffset =
1889 <        fieldOffset("syncStack",ForkJoinPool.class);
1889 >        objectFieldOffset("syncStack",ForkJoinPool.class);
1890      private static final long spareStackOffset =
1891 <        fieldOffset("spareStack", ForkJoinPool.class);
1891 >        objectFieldOffset("spareStack", ForkJoinPool.class);
1892  
1893      private boolean casEventCount(long cmp, long val) {
1894          return UNSAFE.compareAndSwapLong(this, eventCountOffset, cmp, val);
# Line 1941 | Line 1905 | public class ForkJoinPool extends Abstra
1905      private boolean casBarrierStack(WaitQueueNode cmp, WaitQueueNode val) {
1906          return UNSAFE.compareAndSwapObject(this, syncStackOffset, cmp, val);
1907      }
1908 +
1909 +    private static long objectFieldOffset(String field, Class<?> klazz) {
1910 +        try {
1911 +            return UNSAFE.objectFieldOffset(klazz.getDeclaredField(field));
1912 +        } catch (NoSuchFieldException e) {
1913 +            // Convert Exception to corresponding Error
1914 +            NoSuchFieldError error = new NoSuchFieldError(field);
1915 +            error.initCause(e);
1916 +            throw error;
1917 +        }
1918 +    }
1919 +
1920 +    /**
1921 +     * Returns a sun.misc.Unsafe.  Suitable for use in a 3rd party package.
1922 +     * Replace with a simple call to Unsafe.getUnsafe when integrating
1923 +     * into a jdk.
1924 +     *
1925 +     * @return a sun.misc.Unsafe
1926 +     */
1927 +    private static sun.misc.Unsafe getUnsafe() {
1928 +        try {
1929 +            return sun.misc.Unsafe.getUnsafe();
1930 +        } catch (SecurityException se) {
1931 +            try {
1932 +                return java.security.AccessController.doPrivileged
1933 +                    (new java.security
1934 +                     .PrivilegedExceptionAction<sun.misc.Unsafe>() {
1935 +                        public sun.misc.Unsafe run() throws Exception {
1936 +                            java.lang.reflect.Field f = sun.misc
1937 +                                .Unsafe.class.getDeclaredField("theUnsafe");
1938 +                            f.setAccessible(true);
1939 +                            return (sun.misc.Unsafe) f.get(null);
1940 +                        }});
1941 +            } catch (java.security.PrivilegedActionException e) {
1942 +                throw new RuntimeException("Could not initialize intrinsics",
1943 +                                           e.getCause());
1944 +            }
1945 +        }
1946 +    }
1947   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines