src/java.base/share/classes/java/math/BigInteger.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File
*** old/src/java.base/share/classes/java/math/BigInteger.java	Thu Jul  2 17:26:55 2015
--- new/src/java.base/share/classes/java/math/BigInteger.java	Thu Jul  2 17:26:54 2015

*** 32,45 **** --- 32,48 ---- import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.ObjectStreamField; import java.util.Arrays; + import java.util.Objects; import java.util.Random; import java.util.concurrent.ThreadLocalRandom; + import sun.misc.DoubleConsts; import sun.misc.FloatConsts; + import jdk.internal.HotSpotIntrinsicCandidate; /** * Immutable arbitrary-precision integers. All operations behave as if * BigIntegers were represented in two's-complement notation (like Java's * primitive integer types). BigInteger provides analogues to all of Java's
*** 1647,1656 **** --- 1650,1666 ---- /** * Multiplies int arrays x and y to the specified lengths and places * the result into z. There will be no leading zeros in the resultant array. */ private static int[] multiplyToLen(int[] x, int xlen, int[] y, int ylen, int[] z) { + multiplyToLenCheck(x, xlen); + multiplyToLenCheck(y, ylen); + return implMultiplyToLen(x, xlen, y, ylen, z); + } + + @HotSpotIntrinsicCandidate + private static int[] implMultiplyToLen(int[] x, int xlen, int[] y, int ylen, int[] z) { int xstart = xlen - 1; int ystart = ylen - 1; if (z == null || z.length < (xlen+ ylen)) z = new int[xlen+ylen];
*** 1676,1685 **** --- 1686,1707 ---- z[i] = (int)carry; } return z; } + private static void multiplyToLenCheck(int[] array, int length) { + if (length <= 0) { + return; // not an error because multiplyToLen won't execute if len <= 0 + } + + Objects.requireNonNull(array); + + if (length > array.length) { + throw new ArrayIndexOutOfBoundsException(length - 1); + } + } + /** * Multiplies two BigIntegers using the Karatsuba multiplication * algorithm. This is a recursive divide-and-conquer algorithm which is * more efficient for large numbers than what is commonly called the * "grade-school" algorithm used in multiplyToLen. If the numbers to be
*** 2006,2015 **** --- 2028,2038 ---- } /** * Java Runtime may use intrinsic for this method. */ + @HotSpotIntrinsicCandidate private static final int[] implSquareToLen(int[] x, int len, int[] z, int zlen) { /* * The algorithm used here is adapted from Colin Plumb's C library. * Technique: Consider the partial products in the multiplication * of "abcde" by itself:
*** 2666,2680 **** --- 2689,2705 ---- return z; } // These methods are intended to be be replaced by virtual machine // intrinsics. + @HotSpotIntrinsicCandidate private static int[] implMontgomeryMultiply(int[] a, int[] b, int[] n, int len, long inv, int[] product) { product = multiplyToLen(a, len, b, len, product); return montReduce(product, n, len, (int)inv); } + @HotSpotIntrinsicCandidate private static int[] implMontgomerySquare(int[] a, int[] n, int len, long inv, int[] product) { product = squareToLen(a, len, product); return montReduce(product, n, len, (int)inv); }
*** 3002,3011 **** --- 3027,3037 ---- } /** * Java Runtime may use intrinsic for this method. */ + @HotSpotIntrinsicCandidate private static int implMulAdd(int[] out, int[] in, int offset, int len, int k) { long kLong = k & LONG_MASK; long carry = 0; offset = out.length-offset - 1;

src/java.base/share/classes/java/math/BigInteger.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File