--- old/src/share/classes/java/math/BigDecimal.java 2011-09-02 20:42:20.000000000 -0700 +++ new/src/share/classes/java/math/BigDecimal.java 2011-09-02 20:42:20.000000000 -0700 @@ -3716,28 +3716,30 @@ } } - private static final sun.misc.Unsafe unsafe = sun.misc.Unsafe.getUnsafe(); - private static final long intCompactOffset; - private static final long intValOffset; - static { - try { - intCompactOffset = unsafe.objectFieldOffset - (BigDecimal.class.getDeclaredField("intCompact")); - intValOffset = unsafe.objectFieldOffset - (BigDecimal.class.getDeclaredField("intVal")); - } catch (Exception ex) { - throw new Error(ex); + private static class UnsafeHolder { + private static final sun.misc.Unsafe unsafe; + private static final long intCompactOffset; + private static final long intValOffset; + static { + try { + unsafe = sun.misc.Unsafe.getUnsafe(); + intCompactOffset = unsafe.objectFieldOffset + (BigDecimal.class.getDeclaredField("intCompact")); + intValOffset = unsafe.objectFieldOffset + (BigDecimal.class.getDeclaredField("intVal")); + } catch (Exception ex) { + throw new ExceptionInInitializerError(ex); + } + } + private static void setIntCompactVolatile(BigDecimal bd, long val) { + unsafe.putLongVolatile(bd, intCompactOffset, val); + } + + private static void setIntValVolatile(BigDecimal bd, BigInteger val) { + unsafe.putObjectVolatile(bd, intValOffset, val); } } - private void setIntCompactVolatile(long val) { - unsafe.putLongVolatile(this, intCompactOffset, val); - } - - private void setIntValVolatile(BigInteger val) { - unsafe.putObjectVolatile(this, intValOffset, val); - } - /** * Reconstitute the {@code BigDecimal} instance from a stream (that is, * deserialize it). @@ -3754,7 +3756,7 @@ throw new java.io.StreamCorruptedException(message); // [all values of scale are now allowed] } - setIntCompactVolatile(compactValFor(intVal)); + UnsafeHolder.setIntCompactVolatile(this, compactValFor(intVal)); } /** @@ -3766,7 +3768,7 @@ throws java.io.IOException { // Must inflate to maintain compatible serial form. if (this.intVal == null) - this.setIntValVolatile(BigInteger.valueOf(this.intCompact)); + UnsafeHolder.setIntValVolatile(this, BigInteger.valueOf(this.intCompact)); // Could reset intVal back to null if it has to be set. s.defaultWriteObject(); }