src/java.base/share/classes/java/util/concurrent/CountedCompleter.java

Print this page
rev 12972 : 8140606: Update library code to use internal Unsafe
Reviewed-by: duke


 737      * Returns the result of the computation.  By default,
 738      * returns {@code null}, which is appropriate for {@code Void}
 739      * actions, but in other cases should be overridden, almost
 740      * always to return a field or function of a field that
 741      * holds the result upon completion.
 742      *
 743      * @return the result of the computation
 744      */
 745     public T getRawResult() { return null; }
 746 
 747     /**
 748      * A method that result-bearing CountedCompleters may optionally
 749      * use to help maintain result data.  By default, does nothing.
 750      * Overrides are not recommended. However, if this method is
 751      * overridden to update existing objects or fields, then it must
 752      * in general be defined to be thread-safe.
 753      */
 754     protected void setRawResult(T t) { }
 755 
 756     // Unsafe mechanics
 757     private static final sun.misc.Unsafe U = sun.misc.Unsafe.getUnsafe();
 758     private static final long PENDING;
 759     static {
 760         try {
 761             PENDING = U.objectFieldOffset
 762                 (CountedCompleter.class.getDeclaredField("pending"));
 763         } catch (ReflectiveOperationException e) {
 764             throw new Error(e);
 765         }
 766     }
 767 }


 737      * Returns the result of the computation.  By default,
 738      * returns {@code null}, which is appropriate for {@code Void}
 739      * actions, but in other cases should be overridden, almost
 740      * always to return a field or function of a field that
 741      * holds the result upon completion.
 742      *
 743      * @return the result of the computation
 744      */
 745     public T getRawResult() { return null; }
 746 
 747     /**
 748      * A method that result-bearing CountedCompleters may optionally
 749      * use to help maintain result data.  By default, does nothing.
 750      * Overrides are not recommended. However, if this method is
 751      * overridden to update existing objects or fields, then it must
 752      * in general be defined to be thread-safe.
 753      */
 754     protected void setRawResult(T t) { }
 755 
 756     // Unsafe mechanics
 757     private static final jdk.internal.misc.Unsafe U = jdk.internal.misc.Unsafe.getUnsafe();
 758     private static final long PENDING;
 759     static {
 760         try {
 761             PENDING = U.objectFieldOffset
 762                 (CountedCompleter.class.getDeclaredField("pending"));
 763         } catch (ReflectiveOperationException e) {
 764             throw new Error(e);
 765         }
 766     }
 767 }