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

Print this page

        

*** 3301,3329 **** message = "BigInteger: Magnitude not present in stream"; throw new java.io.StreamCorruptedException(message); } // Commit final fields via Unsafe ! unsafe.putIntVolatile(this, signumOffset, sign); // Calculate mag field from magnitude and discard magnitude ! unsafe.putObjectVolatile(this, magOffset, ! stripLeadingZeroBytes(magnitude)); } // Support for resetting final fields while deserializing ! private static final sun.misc.Unsafe unsafe = sun.misc.Unsafe.getUnsafe(); private static final long signumOffset; private static final long magOffset; static { try { signumOffset = unsafe.objectFieldOffset (BigInteger.class.getDeclaredField("signum")); magOffset = unsafe.objectFieldOffset (BigInteger.class.getDeclaredField("mag")); } catch (Exception ex) { ! throw new Error(ex); } } /** * Save the {@code BigInteger} instance to a stream. --- 3301,3339 ---- message = "BigInteger: Magnitude not present in stream"; throw new java.io.StreamCorruptedException(message); } // Commit final fields via Unsafe ! UnsafeHolder.putSign(this, sign); // Calculate mag field from magnitude and discard magnitude ! UnsafeHolder.putMag(this, stripLeadingZeroBytes(magnitude)); } // Support for resetting final fields while deserializing ! private static class UnsafeHolder { ! private static final sun.misc.Unsafe unsafe; private static final long signumOffset; private static final long magOffset; static { try { + unsafe = sun.misc.Unsafe.getUnsafe(); signumOffset = unsafe.objectFieldOffset (BigInteger.class.getDeclaredField("signum")); magOffset = unsafe.objectFieldOffset (BigInteger.class.getDeclaredField("mag")); } catch (Exception ex) { ! throw new ExceptionInInitializerError(ex); ! } ! } ! ! static void putSign(BigInteger bi, int sign) { ! unsafe.putIntVolatile(bi, signumOffset, sign); ! } ! ! static void putMag(BigInteger bi, int[] magnitude) { ! unsafe.putObjectVolatile(bi, magOffset, magnitude); } } /** * Save the {@code BigInteger} instance to a stream.