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

Comparing jsr166/src/jsr166e/extra/AtomicDouble.java (file contents):
Revision 1.9 by jsr166, Thu Oct 20 16:33:25 2011 UTC vs.
Revision 1.15 by jsr166, Mon Feb 11 06:29:57 2013 UTC

# Line 25 | Line 25 | import static java.lang.Double.longBitsT
25   * which differs from both the primitive double {@code ==} operator
26   * and from {@link Double#equals}, as if implemented by:
27   *  <pre> {@code
28 < * boolean bitEquals(double x, double y) {
28 > * static boolean bitEquals(double x, double y) {
29   *   long xBits = Double.doubleToRawLongBits(x);
30   *   long yBits = Double.doubleToRawLongBits(y);
31   *   return xBits == yBits;
32 < * }}</pre>
32 > * }}</pre></a>
33   *
34   * @see jsr166e.DoubleAdder
35   * @see jsr166e.DoubleMaxUpdater
# Line 40 | Line 40 | import static java.lang.Double.longBitsT
40   public class AtomicDouble extends Number implements java.io.Serializable {
41      private static final long serialVersionUID = -8405198993435143622L;
42  
43 <    private volatile long value;
43 >    private transient volatile long value;
44  
45      /**
46       * Creates a new {@code AtomicDouble} with the given initial value.
# Line 210 | Line 210 | public class AtomicDouble extends Number
210          return get();
211      }
212  
213 +    /**
214 +     * Saves the state to a stream (that is, serializes it).
215 +     *
216 +     * @serialData The current value is emitted (a {@code double}).
217 +     */
218 +    private void writeObject(java.io.ObjectOutputStream s)
219 +        throws java.io.IOException {
220 +        s.defaultWriteObject();
221 +
222 +        s.writeDouble(get());
223 +    }
224 +
225 +    /**
226 +     * Reconstitutes the instance from a stream (that is, deserializes it).
227 +     */
228 +    private void readObject(java.io.ObjectInputStream s)
229 +        throws java.io.IOException, ClassNotFoundException {
230 +        s.defaultReadObject();
231 +
232 +        set(s.readDouble());
233 +    }
234 +
235      // Unsafe mechanics
236      private static final sun.misc.Unsafe unsafe = getUnsafe();
237      private static final long valueOffset;
# Line 231 | Line 253 | public class AtomicDouble extends Number
253      private static sun.misc.Unsafe getUnsafe() {
254          try {
255              return sun.misc.Unsafe.getUnsafe();
256 <        } catch (SecurityException se) {
257 <            try {
258 <                return java.security.AccessController.doPrivileged
259 <                    (new java.security
260 <                     .PrivilegedExceptionAction<sun.misc.Unsafe>() {
261 <                        public sun.misc.Unsafe run() throws Exception {
262 <                            java.lang.reflect.Field f = sun.misc
263 <                                .Unsafe.class.getDeclaredField("theUnsafe");
264 <                            f.setAccessible(true);
265 <                            return (sun.misc.Unsafe) f.get(null);
266 <                        }});
267 <            } catch (java.security.PrivilegedActionException e) {
268 <                throw new RuntimeException("Could not initialize intrinsics",
269 <                                           e.getCause());
270 <            }
256 >        } catch (SecurityException tryReflectionInstead) {}
257 >        try {
258 >            return java.security.AccessController.doPrivileged
259 >            (new java.security.PrivilegedExceptionAction<sun.misc.Unsafe>() {
260 >                public sun.misc.Unsafe run() throws Exception {
261 >                    Class<sun.misc.Unsafe> k = sun.misc.Unsafe.class;
262 >                    for (java.lang.reflect.Field f : k.getDeclaredFields()) {
263 >                        f.setAccessible(true);
264 >                        Object x = f.get(null);
265 >                        if (k.isInstance(x))
266 >                            return k.cast(x);
267 >                    }
268 >                    throw new NoSuchFieldError("the Unsafe");
269 >                }});
270 >        } catch (java.security.PrivilegedActionException e) {
271 >            throw new RuntimeException("Could not initialize intrinsics",
272 >                                       e.getCause());
273          }
274      }
275   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines