Skip to content

Commit

Permalink
8294137: Review running times of java.math tests
Browse files Browse the repository at this point in the history
Reviewed-by: darcy
  • Loading branch information
Brian Burkhalter committed Mar 23, 2023
1 parent 46cca1a commit 51035a7
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 79 deletions.
86 changes: 51 additions & 35 deletions test/jdk/java/math/BigInteger/BigIntegerTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -1222,6 +1222,17 @@ public static void serialize() throws Exception {
*
*/
public static void main(String[] args) throws Exception {
// subset zero indicates to run all subsets
int subset = Integer.valueOf(System.getProperty("subset",
String.valueOf(1 + random.nextInt(3))));
if (subset < 0 || subset > 3) {
throw new RuntimeException("Unknown subset " + subset);
}
if (subset == 0)
System.out.println("Testing all subsets");
else
System.out.println("Testing subset " + subset);

// Some variables for sizing test numbers in bits
int order1 = ORDER_MEDIUM;
int order2 = ORDER_SMALL;
Expand All @@ -1237,52 +1248,57 @@ public static void main(String[] args) throws Exception {
if (args.length >3)
order4 = (int)((Integer.parseInt(args[3]))* 3.333);

constructor();

prime();
nextProbablePrime();
if (subset == 0 || subset == 1) {
constructor();

arithmetic(order1); // small numbers
arithmetic(order3); // Karatsuba range
arithmetic(order4); // Toom-Cook / Burnikel-Ziegler range
prime();
nextProbablePrime();

divideAndRemainder(order1); // small numbers
divideAndRemainder(order3); // Karatsuba range
divideAndRemainder(order4); // Toom-Cook / Burnikel-Ziegler range
arithmetic(order1); // small numbers
arithmetic(order3); // Karatsuba range
arithmetic(order4); // Toom-Cook / Burnikel-Ziegler range

pow(order1);
pow(order3);
pow(order4);
divideAndRemainder(order1); // small numbers
divideAndRemainder(order3); // Karatsuba range
divideAndRemainder(order4); // Toom-Cook / Burnikel-Ziegler range

square(ORDER_MEDIUM);
square(ORDER_KARATSUBA_SQUARE);
square(ORDER_TOOM_COOK_SQUARE);
pow(order1);
pow(order3);
pow(order4);

squareRoot();
squareRootAndRemainder();
square(ORDER_MEDIUM);
square(ORDER_KARATSUBA_SQUARE);
square(ORDER_TOOM_COOK_SQUARE);

bitCount();
bitLength();
bitOps(order1);
bitwise(order1);
squareRoot();
squareRootAndRemainder();

shift(order1);
bitCount();
bitLength();
bitOps(order1);
bitwise(order1);

byteArrayConv(order1);
shift(order1);

modInv(order1); // small numbers
modInv(order3); // Karatsuba range
modInv(order4); // Toom-Cook / Burnikel-Ziegler range
byteArrayConv(order1);

modExp(order1, order2);
modExp2(order1);
modInv(order1); // small numbers
modInv(order3); // Karatsuba range
}
if (subset == 0 || subset == 2) {
modInv(order4); // Toom-Cook / Burnikel-Ziegler range

stringConv();
serialize();
modExp(order1, order2);
modExp2(order1);
}
if (subset == 0 || subset == 3) {
stringConv();
serialize();

multiplyLarge();
squareLarge();
divideLarge();
multiplyLarge();
squareLarge();
divideLarge();
}

if (failure)
throw new RuntimeException("Failure in BigIntegerTest.");
Expand Down
11 changes: 10 additions & 1 deletion test/jdk/java/math/BigInteger/LargeValueExceptions.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -30,6 +30,8 @@
*/
import java.math.BigInteger;
import static java.math.BigInteger.ONE;
import org.testng.ITestResult;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;

//
Expand Down Expand Up @@ -62,6 +64,13 @@ public class LargeValueExceptions {
// Half BigInteger.MAX_MAG_LENGTH
private static final int MAX_INTS_HALF = MAX_INTS / 2;

// Print the run time of each sub-test in milliseconds
@AfterMethod
public void getRunTime(ITestResult tr) {
long time = tr.getEndMillis() - tr.getStartMillis();
System.out.printf("Run time: %d ms%n", time);
}

// --- squaring ---

// Largest no overflow determined by examining data lengths alone.
Expand Down
106 changes: 63 additions & 43 deletions test/jdk/java/math/BigInteger/largeMemory/SymmetricRangeTests.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -46,6 +46,8 @@ public class SymmetricRangeTests {
private static final BigInteger MAX_VALUE = makeMaxValue();
private static final BigInteger MIN_VALUE = MAX_VALUE.negate();

private static final Random RANDOM = RandomFactory.getRandom();

private static BigInteger makeMaxValue() {
byte[] ba = new byte[1 << 28];
Arrays.fill(ba, (byte) 0xFF);
Expand Down Expand Up @@ -117,8 +119,7 @@ private static void testOverflowInBitSieve() {
System.out.println("Testing overflow in BitSieve.sieveSingle");
int bitLength = (5 << 27) - 1;
try {
Random random = RandomFactory.getRandom();
BigInteger actual = new BigInteger(bitLength, 0, random);
BigInteger actual = new BigInteger(bitLength, 0, RANDOM);
throw new RuntimeException("new BigInteger(bitLength, 0, null).bitLength()=" + actual.bitLength());
} catch (ArithmeticException e) {
// expected
Expand Down Expand Up @@ -621,45 +622,64 @@ private static void testByteValueExact() {
}

public static void main(String... args) {
testOverflowInMakePositive();
testBug8021204();
testOverflowInBitSieve();
testAdd();
testSubtract();
testMultiply();
testDivide();
testDivideAndRemainder();
testBug9005933();
testRemainder();
testPow();
testGcd();
testAbs();
testNegate();
testMod();
testModPow();
// testModInverse();
testShiftLeft();
testShiftRight();
testAnd();
testOr();
testXor();
testNot();
testSetBit();
testClearBit();
testFlipBit();
testGetLowestSetBit();
testBitLength();
testBitCount();
testToString();
testToByteArrayWithConstructor();
testIntValue();
testLongValue();
testFloatValue();
testDoubleValue();
testSerialization();
testLongValueExact();
testIntValueExact();
testShortValueExact();
testByteValueExact();
// subset zero indicates to run all subsets
int subset = Integer.valueOf(System.getProperty("subset",
String.valueOf(1 + RANDOM.nextInt(4))));
if (subset < 0 || subset > 4) {
throw new RuntimeException("Unknown subset " + subset);
}
if (subset == 0)
System.out.println("Testing all subsets");
else
System.out.println("Testing subset " + subset);

if (subset == 0 || subset == 1) {
testOverflowInMakePositive();
testBug8021204();
testOverflowInBitSieve();
testAdd();
testSubtract();
}
if (subset == 0 || subset == 2) {
testMultiply();
testDivide();
testDivideAndRemainder();
testBug9005933();
}
if (subset == 0 || subset == 3) {
testRemainder();
testPow();
testGcd();
testAbs();
testNegate();
testMod();
testModPow();
// testModInverse();
testShiftLeft();
testShiftRight();
testAnd();
testOr();
testXor();
testNot();
testSetBit();
testClearBit();
testFlipBit();
testGetLowestSetBit();
testBitLength();
testBitCount();
}
if (subset == 0 || subset == 4) {
testToString();
testToByteArrayWithConstructor();
testIntValue();
testLongValue();
testFloatValue();
testDoubleValue();
testSerialization();
testLongValueExact();
testIntValueExact();
testShortValueExact();
testByteValueExact();
}
}
}

3 comments on commit 51035a7

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GoeLin
Copy link
Member

@GoeLin GoeLin commented on 51035a7 Apr 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk17u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on 51035a7 Apr 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GoeLin the backport was successfully created on the branch backport-GoeLin-51035a75 in my personal fork of openjdk/jdk17u-dev. To create a pull request with this backport targeting openjdk/jdk17u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 51035a75 from the openjdk/jdk repository.

The commit being backported was authored by Brian Burkhalter on 23 Mar 2023 and was reviewed by Joe Darcy.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk17u-dev:

$ git fetch https://github.com/openjdk-bots/jdk17u-dev.git backport-GoeLin-51035a75:backport-GoeLin-51035a75
$ git checkout backport-GoeLin-51035a75
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk17u-dev.git backport-GoeLin-51035a75

Please sign in to comment.