Skip to content

Commit 034297a

Browse files
fgualliniBradford Wetmore
authored and
Bradford Wetmore
committedJul 26, 2024
8336240: Test com/sun/crypto/provider/Cipher/DES/PerformanceTest.java fails with java.lang.ArithmeticException
Reviewed-by: wetmore
1 parent abc4ca5 commit 034297a

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed
 

‎test/jdk/ProblemList.txt

-1
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,6 @@ sun/security/smartcardio/TestExclusive.java 8039280 generic-
606606
sun/security/smartcardio/TestMultiplePresent.java 8039280 generic-all
607607
sun/security/smartcardio/TestPresent.java 8039280 generic-all
608608
sun/security/smartcardio/TestTransmit.java 8039280 generic-all
609-
com/sun/crypto/provider/Cipher/DES/PerformanceTest.java 8039280 generic-all
610609
com/sun/security/auth/callback/TextCallbackHandler/Password.java 8039280 generic-all
611610
com/sun/security/sasl/gsskerb/AuthOnly.java 8039280 generic-all
612611
com/sun/security/sasl/gsskerb/ConfSecurityLayer.java 8039280 generic-all

‎test/jdk/TEST.groups

-1
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,6 @@ jdk_core_manual_no_input = \
621621

622622
jdk_security_manual_no_input = \
623623
:jdk_security_infra \
624-
com/sun/crypto/provider/Cipher/DES/PerformanceTest.java \
625624
com/sun/crypto/provider/Cipher/AEAD/GCMIncrementByte4.java \
626625
com/sun/crypto/provider/Cipher/AEAD/GCMIncrementDirect4.java \
627626
com/sun/security/auth/callback/TextCallbackHandler/Password.java \

‎test/jdk/com/sun/crypto/provider/Cipher/DES/PerformanceTest.java

+11-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -26,11 +26,8 @@
2626
* @bug 0000000
2727
* @summary This test checks performance of various ciphers.
2828
* @author Jan Luehe
29-
* @run main/manual PerformanceTest
3029
*/
31-
import java.security.*;
3230
import java.security.spec.*;
33-
import java.io.*;
3431
import javax.crypto.*;
3532
import javax.crypto.spec.*;
3633

@@ -178,14 +175,16 @@ public void runTest(byte[] data, int count) throws Exception {
178175
long start, end;
179176
cipher.init(Cipher.ENCRYPT_MODE, cipherKey, params);
180177

181-
start = System.currentTimeMillis();
178+
start = getTimeInMicroseconds();
182179
for (int i=0; i<count-1; i++) {
183180
cipher.update(data, 0, data.length);
184181
}
185182
cipher.doFinal(data, 0, data.length);
186-
end = System.currentTimeMillis();
183+
end = getTimeInMicroseconds();
187184

188-
int speed = (int)((data.length * count)/(end - start));
185+
// To avoid dividing by zero in the rare case where end is equal to start
186+
long executionTime = end != start ? end - start : 1L;
187+
int speed = (int) ((data.length * count) / executionTime);
189188
sum += speed;
190189
col.append(speed);
191190
}
@@ -198,8 +197,12 @@ public void printHeadings() {
198197
System.out.println
199198
("=========================================================");
200199
System.out.println
201-
("Algorithm DataSize Rounds Kbytes/sec");
200+
("Algorithm DataSize Rounds Bytes/microsec");
202201

203202
}
204203

204+
private static long getTimeInMicroseconds() {
205+
return System.nanoTime() / 1000;
206+
}
207+
205208
}

0 commit comments

Comments
 (0)
Please sign in to comment.