src/share/classes/java/math/BigInteger.java

Print this page

        

@@ -3301,18 +3301,18 @@
                 message = "BigInteger: Magnitude not present in stream";
             throw new java.io.StreamCorruptedException(message);
         }
 
         // Commit final fields via Unsafe
-        unsafe.putIntVolatile(this, signumOffset, sign);
+        UnsafeHolder.putSign(this, sign);
 
         // Calculate mag field from magnitude and discard magnitude
-        unsafe.putObjectVolatile(this, magOffset,
-                                 stripLeadingZeroBytes(magnitude));
+        UnsafeHolder.putMag(this, stripLeadingZeroBytes(magnitude));
     }
 
     // Support for resetting final fields while deserializing
+    private static class UnsafeHolder {
     private static final sun.misc.Unsafe unsafe = sun.misc.Unsafe.getUnsafe();
     private static final long signumOffset;
     private static final long magOffset;
     static {
         try {

@@ -3323,10 +3323,19 @@
         } catch (Exception ex) {
             throw new Error(ex);
         }
     }
 
+        private static void putSign(BigInteger bi, int sign) {
+            unsafe.putIntVolatile(bi, signumOffset, sign);
+        }
+
+        private static void putMag(BigInteger bi, int[] magnitude) {
+            unsafe.putObjectVolatile(bi, magOffset, magnitude);
+        }
+    }
+
     /**
      * Save the {@code BigInteger} instance to a stream.
      * The magnitude of a BigInteger is serialized as a byte array for
      * historical reasons.
      *