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

Comparing jsr166/src/jsr166y/CountedCompleter.java (file contents):
Revision 1.26 by jsr166, Mon Nov 26 12:08:49 2012 UTC vs.
Revision 1.32 by jsr166, Sat Jul 27 19:53:27 2013 UTC

# Line 83 | Line 83 | package jsr166y;
83   * subdivided) to each element of an array or collection; especially
84   * when the operation takes a significantly different amount of time
85   * to complete for some elements than others, either because of
86 < * intrinsic variation (for example IO) or auxiliary effects such as
86 > * intrinsic variation (for example I/O) or auxiliary effects such as
87   * garbage collection.  Because CountedCompleters provide their own
88   * continuations, other threads need not block waiting to perform
89   * them.
# Line 224 | Line 224 | package jsr166y;
224   *   public static <E> E search(E[] array) {
225   *       return new Searcher<E>(null, array, new AtomicReference<E>(), 0, array.length).invoke();
226   *   }
227 < *}}</pre>
227 > * }}</pre>
228   *
229   * In this example, as well as others in which tasks have no other
230   * effects except to compareAndSet a common result, the trailing
# Line 431 | Line 431 | public abstract class CountedCompleter<T
431       * (and/or links to other results) to combine.
432       *
433       * @param caller the task invoking this method (which may
434 <     * be this task itself).
434 >     * be this task itself)
435       */
436      public void onCompletion(CountedCompleter<?> caller) {
437      }
# Line 449 | Line 449 | public abstract class CountedCompleter<T
449       *
450       * @param ex the exception
451       * @param caller the task invoking this method (which may
452 <     * be this task itself).
452 >     * be this task itself)
453       * @return true if this exception should be propagated to this
454 <     * task's completer, if one exists.
454 >     * task's completer, if one exists
455       */
456      public boolean onExceptionalCompletion(Throwable ex, CountedCompleter<?> caller) {
457          return true;
# Line 680 | Line 680 | public abstract class CountedCompleter<T
680      }
681  
682      /**
683 <     * Returns the result of the computation. By default
683 >     * Returns the result of the computation.  By default,
684       * returns {@code null}, which is appropriate for {@code Void}
685       * actions, but in other cases should be overridden, almost
686       * always to return a field or function of a field that
# Line 704 | Line 704 | public abstract class CountedCompleter<T
704      private static final long PENDING;
705      static {
706          try {
707 <            U = sun.misc.Unsafe.getUnsafe();
707 >            U = getUnsafe();
708              PENDING = U.objectFieldOffset
709                  (CountedCompleter.class.getDeclaredField("pending"));
710          } catch (Exception e) {
# Line 722 | Line 722 | public abstract class CountedCompleter<T
722      private static sun.misc.Unsafe getUnsafe() {
723          try {
724              return sun.misc.Unsafe.getUnsafe();
725 <        } catch (SecurityException se) {
726 <            try {
727 <                return java.security.AccessController.doPrivileged
728 <                    (new java.security
729 <                     .PrivilegedExceptionAction<sun.misc.Unsafe>() {
730 <                        public sun.misc.Unsafe run() throws Exception {
731 <                            java.lang.reflect.Field f = sun.misc
732 <                                .Unsafe.class.getDeclaredField("theUnsafe");
733 <                            f.setAccessible(true);
734 <                            return (sun.misc.Unsafe) f.get(null);
735 <                        }});
736 <            } catch (java.security.PrivilegedActionException e) {
737 <                throw new RuntimeException("Could not initialize intrinsics",
738 <                                           e.getCause());
739 <            }
725 >        } catch (SecurityException tryReflectionInstead) {}
726 >        try {
727 >            return java.security.AccessController.doPrivileged
728 >            (new java.security.PrivilegedExceptionAction<sun.misc.Unsafe>() {
729 >                public sun.misc.Unsafe run() throws Exception {
730 >                    Class<sun.misc.Unsafe> k = sun.misc.Unsafe.class;
731 >                    for (java.lang.reflect.Field f : k.getDeclaredFields()) {
732 >                        f.setAccessible(true);
733 >                        Object x = f.get(null);
734 >                        if (k.isInstance(x))
735 >                            return k.cast(x);
736 >                    }
737 >                    throw new NoSuchFieldError("the Unsafe");
738 >                }});
739 >        } catch (java.security.PrivilegedActionException e) {
740 >            throw new RuntimeException("Could not initialize intrinsics",
741 >                                       e.getCause());
742          }
743      }
744   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines