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

Comparing jsr166/src/jsr166y/ForkJoinTask.java (file contents):
Revision 1.15 by jsr166, Fri Jul 24 22:05:22 2009 UTC vs.
Revision 1.17 by jsr166, Sat Jul 25 00:34:00 2009 UTC

# Line 5 | Line 5
5   */
6  
7   package jsr166y;
8 < import java.io.Serializable;
9 < import java.util.*;
8 >
9   import java.util.concurrent.*;
10 < import java.util.concurrent.atomic.*;
11 < import sun.misc.Unsafe;
12 < import java.lang.reflect.*;
10 >
11 > import java.io.Serializable;
12 > import java.util.Collection;
13 > import java.util.Collections;
14 > import java.util.List;
15 > import java.util.Map;
16 > import java.util.WeakHashMap;
17  
18   /**
19   * Abstract base class for tasks that run within a {@link
# Line 1063 | Line 1066 | public abstract class ForkJoinTask<V> im
1066              setDoneExceptionally((Throwable) ex);
1067      }
1068  
1069 <    // Temporary Unsafe mechanics for preliminary release
1070 <    private static Unsafe getUnsafe() throws Throwable {
1069 >    // Unsafe mechanics for jsr166y 3rd party package.
1070 >    private static sun.misc.Unsafe getUnsafe() {
1071          try {
1072 <            return Unsafe.getUnsafe();
1072 >            return sun.misc.Unsafe.getUnsafe();
1073          } catch (SecurityException se) {
1074              try {
1075                  return java.security.AccessController.doPrivileged
1076 <                    (new java.security.PrivilegedExceptionAction<Unsafe>() {
1077 <                        public Unsafe run() throws Exception {
1078 <                            return getUnsafePrivileged();
1076 >                    (new java.security.PrivilegedExceptionAction<sun.misc.Unsafe>() {
1077 >                        public sun.misc.Unsafe run() throws Exception {
1078 >                            return getUnsafeByReflection();
1079                          }});
1080              } catch (java.security.PrivilegedActionException e) {
1081 <                throw e.getCause();
1081 >                throw new RuntimeException("Could not initialize intrinsics",
1082 >                                           e.getCause());
1083              }
1084          }
1085      }
1086  
1087 <    private static Unsafe getUnsafePrivileged()
1087 >    private static sun.misc.Unsafe getUnsafeByReflection()
1088              throws NoSuchFieldException, IllegalAccessException {
1089 <        Field f = Unsafe.class.getDeclaredField("theUnsafe");
1089 >        java.lang.reflect.Field f =
1090 >            sun.misc.Unsafe.class.getDeclaredField("theUnsafe");
1091          f.setAccessible(true);
1092 <        return (Unsafe) f.get(null);
1092 >        return (sun.misc.Unsafe) f.get(null);
1093      }
1094  
1095 <    private static long fieldOffset(String fieldName)
1091 <            throws NoSuchFieldException {
1092 <        return UNSAFE.objectFieldOffset
1093 <            (ForkJoinTask.class.getDeclaredField(fieldName));
1094 <    }
1095 <
1096 <    static final Unsafe UNSAFE;
1097 <    static final long statusOffset;
1098 <
1099 <    static {
1095 >    private static long fieldOffset(String fieldName, Class<?> klazz) {
1096          try {
1097 <            UNSAFE = getUnsafe();
1098 <            statusOffset = fieldOffset("status");
1099 <        } catch (Throwable e) {
1100 <            throw new RuntimeException("Could not initialize intrinsics", e);
1097 >            return UNSAFE.objectFieldOffset(klazz.getDeclaredField(fieldName));
1098 >        } catch (NoSuchFieldException e) {
1099 >            // Convert Exception to Error
1100 >            NoSuchFieldError error = new NoSuchFieldError(fieldName);
1101 >            error.initCause(e);
1102 >            throw error;
1103          }
1104      }
1105  
1106 +    private static final sun.misc.Unsafe UNSAFE = getUnsafe();
1107 +    static final long statusOffset =
1108 +        fieldOffset("status", ForkJoinTask.class);
1109 +
1110   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines