< prev index next >

src/java.base/share/classes/jdk/internal/math/FDBigInteger.java

Print this page
rev 55787 : 8228507: Archive FDBigInteger
Reviewed-by: TBD

*** 22,31 **** --- 22,33 ---- * or visit www.oracle.com if you need additional information or have any * questions. */ package jdk.internal.math; + import jdk.internal.misc.VM; + import java.math.BigInteger; import java.util.Arrays; //@ model import org.jmlspecs.models.JMLMath; /**
*** 62,89 **** @ public pure model static \bigint pow10(int p10) { @ return pow52(p10, p10); @ } @*/ ! static final int[] SMALL_5_POW = { ! 1, ! 5, ! 5 * 5, ! 5 * 5 * 5, ! 5 * 5 * 5 * 5, ! 5 * 5 * 5 * 5 * 5, ! 5 * 5 * 5 * 5 * 5 * 5, ! 5 * 5 * 5 * 5 * 5 * 5 * 5, ! 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5, ! 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5, ! 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5, ! 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5, ! 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5, ! 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 ! }; ! static final long[] LONG_5_POW = { 1L, 5L, 5L * 5, 5L * 5 * 5, 5L * 5 * 5 * 5, --- 64,91 ---- @ public pure model static \bigint pow10(int p10) { @ return pow52(p10, p10); @ } @*/ ! static final int[] SMALL_5_POW; ! static final long[] LONG_5_POW; ! ! // Maximum size of cache of powers of 5 as FDBigIntegers. ! private static final int MAX_FIVE_POW = 340; ! ! // Cache of big powers of 5 as FDBigIntegers. ! private static final FDBigInteger POW_5_CACHE[]; ! ! // Archive proxy ! private static Object[] archivedCaches; ! ! // Initialize FDBigInteger cache of powers of 5. ! static { ! VM.initializeFromArchive(FDBigInteger.class); ! if (archivedCaches == null) { ! long[] long5pow = { 1L, 5L, 5L * 5, 5L * 5 * 5, 5L * 5 * 5 * 5,
*** 108,149 **** 5L * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5, 5L * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5, 5L * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5, 5L * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5, }; ! ! // Maximum size of cache of powers of 5 as FDBigIntegers. ! private static final int MAX_FIVE_POW = 340; ! ! // Cache of big powers of 5 as FDBigIntegers. ! private static final FDBigInteger POW_5_CACHE[]; ! ! // Initialize FDBigInteger cache of powers of 5. ! static { ! POW_5_CACHE = new FDBigInteger[MAX_FIVE_POW]; int i = 0; ! while (i < SMALL_5_POW.length) { ! FDBigInteger pow5 = new FDBigInteger(new int[]{SMALL_5_POW[i]}, 0); pow5.makeImmutable(); ! POW_5_CACHE[i] = pow5; i++; } ! FDBigInteger prev = POW_5_CACHE[i - 1]; while (i < MAX_FIVE_POW) { ! POW_5_CACHE[i] = prev = prev.mult(5); prev.makeImmutable(); i++; } } // Zero as an FDBigInteger. ! public static final FDBigInteger ZERO = new FDBigInteger(new int[0], 0); ! ! // Ensure ZERO is immutable. ! static { ! ZERO.makeImmutable(); ! } // Constant for casting an int to a long via bitwise AND. private static final long LONG_MASK = 0xffffffffL; //@ spec_public non_null; --- 110,161 ---- 5L * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5, 5L * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5, 5L * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5, 5L * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5, }; ! int[] small5pow = { ! 1, ! 5, ! 5 * 5, ! 5 * 5 * 5, ! 5 * 5 * 5 * 5, ! 5 * 5 * 5 * 5 * 5, ! 5 * 5 * 5 * 5 * 5 * 5, ! 5 * 5 * 5 * 5 * 5 * 5 * 5, ! 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5, ! 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5, ! 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5, ! 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5, ! 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5, ! 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 ! }; ! FDBigInteger[] pow5cache = new FDBigInteger[MAX_FIVE_POW]; int i = 0; ! while (i < small5pow.length) { ! FDBigInteger pow5 = new FDBigInteger(new int[] { small5pow[i] }, 0); pow5.makeImmutable(); ! pow5cache[i] = pow5; i++; } ! FDBigInteger prev = pow5cache[i - 1]; while (i < MAX_FIVE_POW) { ! pow5cache[i] = prev = prev.mult(5); prev.makeImmutable(); i++; } + FDBigInteger zero = new FDBigInteger(new int[0], 0); + zero.makeImmutable(); + archivedCaches = new Object[] {small5pow, long5pow, pow5cache, zero}; + } + SMALL_5_POW = (int[])archivedCaches[0]; + LONG_5_POW = (long[])archivedCaches[1]; + POW_5_CACHE = (FDBigInteger[])archivedCaches[2]; + ZERO = (FDBigInteger)archivedCaches[3]; } // Zero as an FDBigInteger. ! public static final FDBigInteger ZERO; // Constant for casting an int to a long via bitwise AND. private static final long LONG_MASK = 0xffffffffL; //@ spec_public non_null;
< prev index next >