From 058392ab20adc804447bb6948e8aa9e929a53237 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 24 Mar 2026 04:14:15 +0000 Subject: [PATCH 1/4] Fix OOM in BigInteger OuterLoop tests: use 1<<24 instead of int.MaxValue/10 Co-authored-by: danmoseley <6385855+danmoseley@users.noreply.github.com> Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/3875817a-ab5d-4e0e-a906-e8d6e2162043 --- .../System.Runtime.Numerics/tests/BigInteger/cast_from.cs | 6 +++--- .../System.Runtime.Numerics/tests/BigInteger/log.cs | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/libraries/System.Runtime.Numerics/tests/BigInteger/cast_from.cs b/src/libraries/System.Runtime.Numerics/tests/BigInteger/cast_from.cs index d6343326642bda..319e0232025f6f 100644 --- a/src/libraries/System.Runtime.Numerics/tests/BigInteger/cast_from.cs +++ b/src/libraries/System.Runtime.Numerics/tests/BigInteger/cast_from.cs @@ -706,8 +706,8 @@ public static void RunDecimalExplicitCastFromBigIntegerTests() } /// - /// Test cast to Double on Very Large BigInteger more than (1 << Int.MaxValue) - /// Tested BigInteger are: +/-pow(2, startShift + smallLoopShift * [1..smallLoopLimit] + Int32.MaxValue * [1..bigLoopLimit]) + /// Test cast to Double on Very Large BigInteger more than (1 << (1 << 24)) + /// Tested BigInteger are: +/-pow(2, startShift + smallLoopShift * [1..smallLoopLimit] + (1 << 24) * [1..bigLoopLimit]) /// Expected double is positive and negative infinity /// Note: /// ToString() can not operate such large values @@ -722,7 +722,7 @@ private static void DoubleExplicitCastFromLargeBigIntegerTests(int startShift, i for (int j = 0; j < bigShiftLoopLimit; j++) { - temp = temp << (int.MaxValue / 10); + temp = temp << (1 << 24); VerifyDoubleExplicitCastFromBigInteger(double.PositiveInfinity, temp); VerifyDoubleExplicitCastFromBigInteger(double.NegativeInfinity, -temp); } diff --git a/src/libraries/System.Runtime.Numerics/tests/BigInteger/log.cs b/src/libraries/System.Runtime.Numerics/tests/BigInteger/log.cs index 37cae18d6c85c2..416fddb98739e9 100644 --- a/src/libraries/System.Runtime.Numerics/tests/BigInteger/log.cs +++ b/src/libraries/System.Runtime.Numerics/tests/BigInteger/log.cs @@ -139,8 +139,8 @@ public static void RunLargeValueLogTests() } /// - /// Test Log Method on Very Large BigInteger more than (1 << Int.MaxValue) by base 2 - /// Tested BigInteger are: pow(2, startShift + smallLoopShift * [1..smallLoopLimit] + Int32.MaxValue * [1..bigLoopLimit]) + /// Test Log Method on Very Large BigInteger more than (1 << (1 << 24)) by base 2 + /// Tested BigInteger are: pow(2, startShift + smallLoopShift * [1..smallLoopLimit] + (1 << 24) * [1..bigLoopLimit]) /// Note: /// ToString() can not operate such large values /// VerifyLogString() can not operate such large values, @@ -157,11 +157,11 @@ private static void LargeValueLogTests(int startShift, int bigShiftLoopLimit, in for (int j = 0; j Date: Wed, 25 Mar 2026 00:58:51 +0000 Subject: [PATCH 2/4] Address review feedback: clarify XML docs and introduce named const for bit shift Co-authored-by: danmoseley <6385855+danmoseley@users.noreply.github.com> Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/763c2d49-b5a3-4483-ae1e-484fe34e0b4f --- .../tests/BigInteger/cast_from.cs | 9 ++++++--- .../System.Runtime.Numerics/tests/BigInteger/log.cs | 11 +++++++---- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/libraries/System.Runtime.Numerics/tests/BigInteger/cast_from.cs b/src/libraries/System.Runtime.Numerics/tests/BigInteger/cast_from.cs index 319e0232025f6f..816080968e92cc 100644 --- a/src/libraries/System.Runtime.Numerics/tests/BigInteger/cast_from.cs +++ b/src/libraries/System.Runtime.Numerics/tests/BigInteger/cast_from.cs @@ -706,14 +706,17 @@ public static void RunDecimalExplicitCastFromBigIntegerTests() } /// - /// Test cast to Double on Very Large BigInteger more than (1 << (1 << 24)) - /// Tested BigInteger are: +/-pow(2, startShift + smallLoopShift * [1..smallLoopLimit] + (1 << 24) * [1..bigLoopLimit]) + /// Test cast to Double on very large BigInteger values with magnitude greater than 2^(1 << 24), that is, values with more than 16,777,216 bits. + /// Tested BigInteger values are: +/-2^(startShift + smallLoopShift * [1..smallLoopLimit] + (1 << 24) * [1..bigLoopLimit]) /// Expected double is positive and negative infinity /// Note: /// ToString() can not operate such large values /// private static void DoubleExplicitCastFromLargeBigIntegerTests(int startShift, int bigShiftLoopLimit, int smallShift = 0, int smallShiftLoopLimit = 1) { + // Use 1<<24 (16,777,216) bits per iteration rather than int.MaxValue/10 to keep + // per-iteration allocations around 2 MB instead of ~107 MB, avoiding OOM in CI containers. + const int LargeBitShift = 1 << 24; BigInteger init = BigInteger.One << startShift; for (int i = 0; i < smallShiftLoopLimit; i++) @@ -722,7 +725,7 @@ private static void DoubleExplicitCastFromLargeBigIntegerTests(int startShift, i for (int j = 0; j < bigShiftLoopLimit; j++) { - temp = temp << (1 << 24); + temp = temp << LargeBitShift; VerifyDoubleExplicitCastFromBigInteger(double.PositiveInfinity, temp); VerifyDoubleExplicitCastFromBigInteger(double.NegativeInfinity, -temp); } diff --git a/src/libraries/System.Runtime.Numerics/tests/BigInteger/log.cs b/src/libraries/System.Runtime.Numerics/tests/BigInteger/log.cs index 416fddb98739e9..1b28757ddb8c90 100644 --- a/src/libraries/System.Runtime.Numerics/tests/BigInteger/log.cs +++ b/src/libraries/System.Runtime.Numerics/tests/BigInteger/log.cs @@ -139,8 +139,8 @@ public static void RunLargeValueLogTests() } /// - /// Test Log Method on Very Large BigInteger more than (1 << (1 << 24)) by base 2 - /// Tested BigInteger are: pow(2, startShift + smallLoopShift * [1..smallLoopLimit] + (1 << 24) * [1..bigLoopLimit]) + /// Test Log method on very large BigInteger values greater than 2^(1 << 24), that is, values with more than 16,777,216 bits, using base 2. + /// Tested BigInteger values are 2^(startShift + smallShift * [1..smallShiftLoopLimit] + (1 << 24) * [1..bigShiftLoopLimit]). /// Note: /// ToString() can not operate such large values /// VerifyLogString() can not operate such large values, @@ -148,6 +148,9 @@ public static void RunLargeValueLogTests() /// private static void LargeValueLogTests(int startShift, int bigShiftLoopLimit, int smallShift = 0, int smallShiftLoopLimit = 1) { + // Use 1<<24 (16,777,216) bits per iteration rather than int.MaxValue/10 to keep + // per-iteration allocations around 2 MB instead of ~107 MB, avoiding OOM in CI containers. + const int LargeBitShift = 1 << 24; BigInteger init = BigInteger.One << startShift; double logbase = 2D; @@ -157,11 +160,11 @@ private static void LargeValueLogTests(int startShift, int bigShiftLoopLimit, in for (int j = 0; j Date: Wed, 25 Mar 2026 01:35:08 +0000 Subject: [PATCH 3/4] Revert XML doc and const changes, keep only the core fix from first commit Co-authored-by: danmoseley <6385855+danmoseley@users.noreply.github.com> Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/d2473d7c-9ab4-431e-bd7d-948a40220e50 --- .../tests/BigInteger/cast_from.cs | 9 +++------ .../System.Runtime.Numerics/tests/BigInteger/log.cs | 11 ++++------- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/libraries/System.Runtime.Numerics/tests/BigInteger/cast_from.cs b/src/libraries/System.Runtime.Numerics/tests/BigInteger/cast_from.cs index 816080968e92cc..319e0232025f6f 100644 --- a/src/libraries/System.Runtime.Numerics/tests/BigInteger/cast_from.cs +++ b/src/libraries/System.Runtime.Numerics/tests/BigInteger/cast_from.cs @@ -706,17 +706,14 @@ public static void RunDecimalExplicitCastFromBigIntegerTests() } /// - /// Test cast to Double on very large BigInteger values with magnitude greater than 2^(1 << 24), that is, values with more than 16,777,216 bits. - /// Tested BigInteger values are: +/-2^(startShift + smallLoopShift * [1..smallLoopLimit] + (1 << 24) * [1..bigLoopLimit]) + /// Test cast to Double on Very Large BigInteger more than (1 << (1 << 24)) + /// Tested BigInteger are: +/-pow(2, startShift + smallLoopShift * [1..smallLoopLimit] + (1 << 24) * [1..bigLoopLimit]) /// Expected double is positive and negative infinity /// Note: /// ToString() can not operate such large values /// private static void DoubleExplicitCastFromLargeBigIntegerTests(int startShift, int bigShiftLoopLimit, int smallShift = 0, int smallShiftLoopLimit = 1) { - // Use 1<<24 (16,777,216) bits per iteration rather than int.MaxValue/10 to keep - // per-iteration allocations around 2 MB instead of ~107 MB, avoiding OOM in CI containers. - const int LargeBitShift = 1 << 24; BigInteger init = BigInteger.One << startShift; for (int i = 0; i < smallShiftLoopLimit; i++) @@ -725,7 +722,7 @@ private static void DoubleExplicitCastFromLargeBigIntegerTests(int startShift, i for (int j = 0; j < bigShiftLoopLimit; j++) { - temp = temp << LargeBitShift; + temp = temp << (1 << 24); VerifyDoubleExplicitCastFromBigInteger(double.PositiveInfinity, temp); VerifyDoubleExplicitCastFromBigInteger(double.NegativeInfinity, -temp); } diff --git a/src/libraries/System.Runtime.Numerics/tests/BigInteger/log.cs b/src/libraries/System.Runtime.Numerics/tests/BigInteger/log.cs index 1b28757ddb8c90..416fddb98739e9 100644 --- a/src/libraries/System.Runtime.Numerics/tests/BigInteger/log.cs +++ b/src/libraries/System.Runtime.Numerics/tests/BigInteger/log.cs @@ -139,8 +139,8 @@ public static void RunLargeValueLogTests() } /// - /// Test Log method on very large BigInteger values greater than 2^(1 << 24), that is, values with more than 16,777,216 bits, using base 2. - /// Tested BigInteger values are 2^(startShift + smallShift * [1..smallShiftLoopLimit] + (1 << 24) * [1..bigShiftLoopLimit]). + /// Test Log Method on Very Large BigInteger more than (1 << (1 << 24)) by base 2 + /// Tested BigInteger are: pow(2, startShift + smallLoopShift * [1..smallLoopLimit] + (1 << 24) * [1..bigLoopLimit]) /// Note: /// ToString() can not operate such large values /// VerifyLogString() can not operate such large values, @@ -148,9 +148,6 @@ public static void RunLargeValueLogTests() /// private static void LargeValueLogTests(int startShift, int bigShiftLoopLimit, int smallShift = 0, int smallShiftLoopLimit = 1) { - // Use 1<<24 (16,777,216) bits per iteration rather than int.MaxValue/10 to keep - // per-iteration allocations around 2 MB instead of ~107 MB, avoiding OOM in CI containers. - const int LargeBitShift = 1 << 24; BigInteger init = BigInteger.One << startShift; double logbase = 2D; @@ -160,11 +157,11 @@ private static void LargeValueLogTests(int startShift, int bigShiftLoopLimit, in for (int j = 0; j Date: Wed, 25 Mar 2026 20:41:27 -0600 Subject: [PATCH 4/4] Revert comment changes to minimize diff Remove the 4 comment-only changes, keeping only the 3 code lines that actually fix the OOM (int.MaxValue / 10 -> 1 << 24). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../System.Runtime.Numerics/tests/BigInteger/cast_from.cs | 4 ++-- src/libraries/System.Runtime.Numerics/tests/BigInteger/log.cs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libraries/System.Runtime.Numerics/tests/BigInteger/cast_from.cs b/src/libraries/System.Runtime.Numerics/tests/BigInteger/cast_from.cs index 319e0232025f6f..3caf827da7bb4f 100644 --- a/src/libraries/System.Runtime.Numerics/tests/BigInteger/cast_from.cs +++ b/src/libraries/System.Runtime.Numerics/tests/BigInteger/cast_from.cs @@ -706,8 +706,8 @@ public static void RunDecimalExplicitCastFromBigIntegerTests() } /// - /// Test cast to Double on Very Large BigInteger more than (1 << (1 << 24)) - /// Tested BigInteger are: +/-pow(2, startShift + smallLoopShift * [1..smallLoopLimit] + (1 << 24) * [1..bigLoopLimit]) + /// Test cast to Double on Very Large BigInteger more than (1 << Int.MaxValue) + /// Tested BigInteger are: +/-pow(2, startShift + smallLoopShift * [1..smallLoopLimit] + Int32.MaxValue * [1..bigLoopLimit]) /// Expected double is positive and negative infinity /// Note: /// ToString() can not operate such large values diff --git a/src/libraries/System.Runtime.Numerics/tests/BigInteger/log.cs b/src/libraries/System.Runtime.Numerics/tests/BigInteger/log.cs index 416fddb98739e9..3f3edd0778c73e 100644 --- a/src/libraries/System.Runtime.Numerics/tests/BigInteger/log.cs +++ b/src/libraries/System.Runtime.Numerics/tests/BigInteger/log.cs @@ -139,8 +139,8 @@ public static void RunLargeValueLogTests() } /// - /// Test Log Method on Very Large BigInteger more than (1 << (1 << 24)) by base 2 - /// Tested BigInteger are: pow(2, startShift + smallLoopShift * [1..smallLoopLimit] + (1 << 24) * [1..bigLoopLimit]) + /// Test Log Method on Very Large BigInteger more than (1 << Int.MaxValue) by base 2 + /// Tested BigInteger are: pow(2, startShift + smallLoopShift * [1..smallLoopLimit] + Int32.MaxValue * [1..bigLoopLimit]) /// Note: /// ToString() can not operate such large values /// VerifyLogString() can not operate such large values,