--- jsr166/src/jsr166e/extra/AtomicDouble.java 2011/10/20 16:33:25 1.9 +++ jsr166/src/jsr166e/extra/AtomicDouble.java 2013/07/22 16:47:46 1.19 @@ -19,13 +19,13 @@ import static java.lang.Double.longBitsT * this class does extend {@code Number} to allow uniform access by * tools and utilities that deal with numerically-based classes. * - *
This class compares primitive {@code double}
+ * This class compares primitive {@code double}
* values in methods such as {@link #compareAndSet} by comparing their
* bitwise representation using {@link Double#doubleToRawLongBits},
* which differs from both the primitive double {@code ==} operator
* and from {@link Double#equals}, as if implemented by:
* May
- * fail spuriously
- * and does not provide ordering guarantees, so is only rarely an
- * appropriate alternative to {@code compareAndSet}.
+ * May fail spuriously and does not provide ordering guarantees {@code
- * boolean bitEquals(double x, double y) {
+ * static boolean bitEquals(double x, double y) {
* long xBits = Double.doubleToRawLongBits(x);
* long yBits = Double.doubleToRawLongBits(y);
* return xBits == yBits;
@@ -40,7 +40,7 @@ import static java.lang.Double.longBitsT
public class AtomicDouble extends Number implements java.io.Serializable {
private static final long serialVersionUID = -8405198993435143622L;
- private volatile long value;
+ private transient volatile long value;
/**
* Creates a new {@code AtomicDouble} with the given initial value.
@@ -123,11 +123,10 @@ public class AtomicDouble extends Number
* if the current value is bitwise equal
* to the expected value.
*
- *
,
+ * so is only rarely an appropriate alternative to {@code compareAndSet}.
*
* @param expect the expected value
* @param update the new value
@@ -210,6 +209,34 @@ public class AtomicDouble extends Number
return get();
}
+ /**
+ * Saves the state to a stream (that is, serializes it).
+ *
+ * @param s the stream
+ * @throws java.io.IOException if an I/O error occurs
+ * @serialData The current value is emitted (a {@code double}).
+ */
+ private void writeObject(java.io.ObjectOutputStream s)
+ throws java.io.IOException {
+ s.defaultWriteObject();
+
+ s.writeDouble(get());
+ }
+
+ /**
+ * Reconstitutes the instance from a stream (that is, deserializes it).
+ * @param s the stream
+ * @throws ClassNotFoundException if the class of a serialized object
+ * could not be found
+ * @throws java.io.IOException if an I/O error occurs
+ */
+ private void readObject(java.io.ObjectInputStream s)
+ throws java.io.IOException, ClassNotFoundException {
+ s.defaultReadObject();
+
+ set(s.readDouble());
+ }
+
// Unsafe mechanics
private static final sun.misc.Unsafe unsafe = getUnsafe();
private static final long valueOffset;
@@ -231,21 +258,23 @@ public class AtomicDouble extends Number
private static sun.misc.Unsafe getUnsafe() {
try {
return sun.misc.Unsafe.getUnsafe();
- } catch (SecurityException se) {
- try {
- return java.security.AccessController.doPrivileged
- (new java.security
- .PrivilegedExceptionAction