From de838850e5800500f5aa6f60b142ff76cecf7540 Mon Sep 17 00:00:00 2001 From: Shawn M Emery Date: Thu, 23 Jul 2026 00:29:03 -0600 Subject: [PATCH 1/5] 8388706: PolynomialP256Bench::benchAssign regression after JDK-8355216 --- .../javax/crypto/full/PolynomialP256Bench.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/test/micro/org/openjdk/bench/javax/crypto/full/PolynomialP256Bench.java b/test/micro/org/openjdk/bench/javax/crypto/full/PolynomialP256Bench.java index 34a6bd761ff98..15a048d356838 100644 --- a/test/micro/org/openjdk/bench/javax/crypto/full/PolynomialP256Bench.java +++ b/test/micro/org/openjdk/bench/javax/crypto/full/PolynomialP256Bench.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2024, 2026,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 @@ -35,6 +35,7 @@ import org.openjdk.jmh.annotations.Benchmark; import java.math.BigInteger; import java.util.concurrent.TimeUnit; +import java.util.Random; import sun.security.util.math.intpoly.MontgomeryIntegerPolynomialP256; import sun.security.util.math.intpoly.IntegerPolynomialP256; import sun.security.util.math.MutableIntegerModuloP; @@ -94,11 +95,13 @@ public MutableIntegerModuloP benchSquare() { public MutableIntegerModuloP benchAssign() { MutableIntegerModuloP test1 = X.mutable(); MutableIntegerModuloP test2 = one.mutable(); + long seed = 1234567890L; + Random rand = new Random(seed); for (int i = 0; i< 10000; i++) { - test1.conditionalSet(test2, 0); - test1.conditionalSet(test2, 1); - test2.conditionalSet(test1, 0); - test2.conditionalSet(test1, 1); + test1.conditionalSet(test2, rand.nextInt(2)); + test1.conditionalSet(test2, rand.nextInt(2)); + test2.conditionalSet(test1, rand.nextInt(2)); + test2.conditionalSet(test1, rand.nextInt(2)); } return test2; } From 7111a170dbdb6321e2fb2e5542365c0085ae49aa Mon Sep 17 00:00:00 2001 From: Shawn M Emery Date: Fri, 24 Jul 2026 16:16:25 -0600 Subject: [PATCH 2/5] Update to non-constants --- .../javax/crypto/full/PolynomialP256Bench.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/test/micro/org/openjdk/bench/javax/crypto/full/PolynomialP256Bench.java b/test/micro/org/openjdk/bench/javax/crypto/full/PolynomialP256Bench.java index 15a048d356838..0c359eada9cc5 100644 --- a/test/micro/org/openjdk/bench/javax/crypto/full/PolynomialP256Bench.java +++ b/test/micro/org/openjdk/bench/javax/crypto/full/PolynomialP256Bench.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024, 2026,Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2024, 2026, 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 @@ -35,7 +35,6 @@ import org.openjdk.jmh.annotations.Benchmark; import java.math.BigInteger; import java.util.concurrent.TimeUnit; -import java.util.Random; import sun.security.util.math.intpoly.MontgomeryIntegerPolynomialP256; import sun.security.util.math.intpoly.IntegerPolynomialP256; import sun.security.util.math.MutableIntegerModuloP; @@ -57,6 +56,10 @@ public class PolynomialP256Bench { final ImmutableIntegerModuloP x = residueField.getElement(refx); final ImmutableIntegerModuloP X = montField.getElement(refx); final ImmutableIntegerModuloP one = montField.get1(); + @Param({"0"}) + private int pZero = 0; + @Param({"1"}) + private int pOne = 1; @Param({"true", "false"}) private boolean isMontBench; @@ -95,13 +98,11 @@ public MutableIntegerModuloP benchSquare() { public MutableIntegerModuloP benchAssign() { MutableIntegerModuloP test1 = X.mutable(); MutableIntegerModuloP test2 = one.mutable(); - long seed = 1234567890L; - Random rand = new Random(seed); for (int i = 0; i< 10000; i++) { - test1.conditionalSet(test2, rand.nextInt(2)); - test1.conditionalSet(test2, rand.nextInt(2)); - test2.conditionalSet(test1, rand.nextInt(2)); - test2.conditionalSet(test1, rand.nextInt(2)); + test1.conditionalSet(test2, vZero); + test1.conditionalSet(test2, vOne); + test2.conditionalSet(test1, vZero); + test2.conditionalSet(test1, vOne); } return test2; } From 550f060d20fc59d6d01505436f7f5735ccf58ec7 Mon Sep 17 00:00:00 2001 From: Shawn M Emery Date: Sat, 25 Jul 2026 15:32:51 -0600 Subject: [PATCH 3/5] Switch to @Param solution for non-constants --- .../crypto/full/PolynomialP256Bench.java | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/test/micro/org/openjdk/bench/javax/crypto/full/PolynomialP256Bench.java b/test/micro/org/openjdk/bench/javax/crypto/full/PolynomialP256Bench.java index 0c359eada9cc5..4c788872491d0 100644 --- a/test/micro/org/openjdk/bench/javax/crypto/full/PolynomialP256Bench.java +++ b/test/micro/org/openjdk/bench/javax/crypto/full/PolynomialP256Bench.java @@ -56,10 +56,14 @@ public class PolynomialP256Bench { final ImmutableIntegerModuloP x = residueField.getElement(refx); final ImmutableIntegerModuloP X = montField.getElement(refx); final ImmutableIntegerModuloP one = montField.get1(); + + // Here we assign conditional set arguments as non-constants in order to + // prevent constant folding. Previously, C2 would perform constant + // propagation and remove the subsequent dead-code where 0 was input. @Param({"0"}) - private int pZero = 0; + private int pZero; @Param({"1"}) - private int pOne = 1; + private int pOne; @Param({"true", "false"}) private boolean isMontBench; @@ -73,7 +77,7 @@ public MutableIntegerModuloP benchMultiply() { test = x.mutable(); } - for (int i = 0; i< 10000; i++) { + for (int i = 0; i < 10000; i++) { test = test.setProduct(test); } return test; @@ -88,7 +92,7 @@ public MutableIntegerModuloP benchSquare() { test = x.mutable(); } - for (int i = 0; i< 10000; i++) { + for (int i = 0; i < 10000; i++) { test = test.setSquare(); } return test; @@ -98,11 +102,14 @@ public MutableIntegerModuloP benchSquare() { public MutableIntegerModuloP benchAssign() { MutableIntegerModuloP test1 = X.mutable(); MutableIntegerModuloP test2 = one.mutable(); - for (int i = 0; i< 10000; i++) { - test1.conditionalSet(test2, vZero); - test1.conditionalSet(test2, vOne); - test2.conditionalSet(test1, vZero); - test2.conditionalSet(test1, vOne); + int lpZero = pZero; + int lpOne = pOne; + + for (int i = 0; i < 10000; i++) { + test1.conditionalSet(test2, lpZero); + test1.conditionalSet(test2, lpOne); + test2.conditionalSet(test1, lpZero); + test2.conditionalSet(test1, lpOne); } return test2; } From e9ab6be938c6616a30764f22724049e37bc92b3a Mon Sep 17 00:00:00 2001 From: Shawn M Emery Date: Mon, 27 Jul 2026 19:11:44 -0600 Subject: [PATCH 4/5] Update based on Vladimir's comments --- .../crypto/full/PolynomialP256Bench.java | 42 +++++++++++-------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/test/micro/org/openjdk/bench/javax/crypto/full/PolynomialP256Bench.java b/test/micro/org/openjdk/bench/javax/crypto/full/PolynomialP256Bench.java index 4c788872491d0..656582a71904e 100644 --- a/test/micro/org/openjdk/bench/javax/crypto/full/PolynomialP256Bench.java +++ b/test/micro/org/openjdk/bench/javax/crypto/full/PolynomialP256Bench.java @@ -56,18 +56,22 @@ public class PolynomialP256Bench { final ImmutableIntegerModuloP x = residueField.getElement(refx); final ImmutableIntegerModuloP X = montField.getElement(refx); final ImmutableIntegerModuloP one = montField.get1(); - - // Here we assign conditional set arguments as non-constants in order to - // prevent constant folding. Previously, C2 would perform constant - // propagation and remove the subsequent dead-code where 0 was input. - @Param({"0"}) - private int pZero; - @Param({"1"}) - private int pOne; + final int ITERATIONS = 10_000; + final int[] scalarBits = new int[ITERATIONS]; @Param({"true", "false"}) private boolean isMontBench; + // Here we assign conditional set bits as non-constants in order to + // prevent constant folding. Previously, C2 would perform constant + // propagation and remove the subsequent dead-code where 0 was input. + @Setup + public void setup() { + for (int i = 0; i < ITERATIONS; i++) { + scalarBits[i] = i & 1; + } + } + @Benchmark public MutableIntegerModuloP benchMultiply() { MutableIntegerModuloP test; @@ -77,7 +81,7 @@ public MutableIntegerModuloP benchMultiply() { test = x.mutable(); } - for (int i = 0; i < 10000; i++) { + for (int i = 0; i < ITERATIONS; i++) { test = test.setProduct(test); } return test; @@ -92,7 +96,7 @@ public MutableIntegerModuloP benchSquare() { test = x.mutable(); } - for (int i = 0; i < 10000; i++) { + for (int i = 0; i < ITERATIONS; i++) { test = test.setSquare(); } return test; @@ -100,16 +104,18 @@ public MutableIntegerModuloP benchSquare() { @Benchmark public MutableIntegerModuloP benchAssign() { - MutableIntegerModuloP test1 = X.mutable(); + MutableIntegerModuloP test1; MutableIntegerModuloP test2 = one.mutable(); - int lpZero = pZero; - int lpOne = pOne; + int[] lScalarBits = scalarBits; + + for (int i = 0; i < ITERATIONS; i++) { + int bit = lScalarBits[i]; + int bitCom = bit ^ 1; - for (int i = 0; i < 10000; i++) { - test1.conditionalSet(test2, lpZero); - test1.conditionalSet(test2, lpOne); - test2.conditionalSet(test1, lpZero); - test2.conditionalSet(test1, lpOne); + test1.conditionalSet(test2, bit); + test1.conditionalSet(test2, bitCom); + test2.conditionalSet(test1, bit); + test2.conditionalSet(test1, bitCom); } return test2; } From 5e7a26d20d07c05f2dc61a774ae7bd329ed65ca4 Mon Sep 17 00:00:00 2001 From: Shawn M Emery Date: Mon, 27 Jul 2026 22:51:59 -0600 Subject: [PATCH 5/5] Missing initialization --- .../openjdk/bench/javax/crypto/full/PolynomialP256Bench.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/micro/org/openjdk/bench/javax/crypto/full/PolynomialP256Bench.java b/test/micro/org/openjdk/bench/javax/crypto/full/PolynomialP256Bench.java index 656582a71904e..4fed10a6d0949 100644 --- a/test/micro/org/openjdk/bench/javax/crypto/full/PolynomialP256Bench.java +++ b/test/micro/org/openjdk/bench/javax/crypto/full/PolynomialP256Bench.java @@ -104,7 +104,7 @@ public MutableIntegerModuloP benchSquare() { @Benchmark public MutableIntegerModuloP benchAssign() { - MutableIntegerModuloP test1; + MutableIntegerModuloP test1 = X.mutable(); MutableIntegerModuloP test2 = one.mutable(); int[] lScalarBits = scalarBits;