Skip to content

Commit

Permalink
Fix "Out of heap space grow heap" error after migration to Scala Nati…
Browse files Browse the repository at this point in the history
…ve 0.5.5
  • Loading branch information
plokhotnyuk committed Aug 19, 2024
1 parent 1ff9cad commit 2489af7
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 52 deletions.
1 change: 1 addition & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ lazy val nativeSettings = Seq(
.withLTO(LTO.none)
.withGC(GC.immix)
},
Test / parallelExecution := false, // FIXME: Remove after fixing of https://github.com/scala-native/scala-native/issues/4032
coverageEnabled := false // FIXME: Unexpected linking error
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2417,7 +2417,7 @@ class JsonReaderSpec extends AnyWordSpec with Matchers with ScalaCheckPropertyCh
forAll(arbitrary[Byte], genWhitespaces, minSuccessful(10000))(check)
}
"parse keys and strigified values with leading zeros" in {
forAll(arbitrary[Byte].map(x => f"$x%05d"), genWhitespaces, minSuccessful(1000))(check2)
forAll(arbitrary[Byte].map(x => f"$x%05d"), genWhitespaces, minSuccessful(100))(check2)
}
"throw parsing exception on valid number values with '.', 'e', 'E' chars" in {
checkError("123.0", "illegal number, offset: 0x00000003", "illegal number, offset: 0x00000004")
Expand Down Expand Up @@ -2481,7 +2481,7 @@ class JsonReaderSpec extends AnyWordSpec with Matchers with ScalaCheckPropertyCh
forAll(arbitrary[Short], genWhitespaces, minSuccessful(10000))(check)
}
"parse keys and strigified values with leading zeros" in {
forAll(arbitrary[Short].map(x => f"$x%07d"), genWhitespaces, minSuccessful(1000))(check2)
forAll(arbitrary[Short].map(x => f"$x%07d"), genWhitespaces, minSuccessful(100))(check2)
}
"throw parsing exception on valid number values with '.', 'e', 'E' chars" in {
checkError("12345.0", "illegal number, offset: 0x00000005", "illegal number, offset: 0x00000006")
Expand Down Expand Up @@ -2545,7 +2545,7 @@ class JsonReaderSpec extends AnyWordSpec with Matchers with ScalaCheckPropertyCh
forAll(arbitrary[Int], genWhitespaces, minSuccessful(10000))(check)
}
"parse keys and strigified values with leading zeros" in {
forAll(arbitrary[Int].map(x => f"$x%011d"), genWhitespaces, minSuccessful(1000))(check2)
forAll(arbitrary[Int].map(x => f"$x%011d"), genWhitespaces, minSuccessful(100))(check2)
}
"throw parsing exception on valid number values with '.', 'e', 'E' chars" in {
checkError("123456789.0", "illegal number, offset: 0x00000009", "illegal number, offset: 0x0000000a")
Expand Down Expand Up @@ -2613,7 +2613,7 @@ class JsonReaderSpec extends AnyWordSpec with Matchers with ScalaCheckPropertyCh
forAll(arbitrary[Long], genWhitespaces, minSuccessful(10000))(check)
}
"parse keys and strigified values with leading zeros" in {
forAll(arbitrary[Long].map(x => f"$x%021d"), genWhitespaces, minSuccessful(1000))(check2)
forAll(arbitrary[Long].map(x => f"$x%021d"), genWhitespaces, minSuccessful(100))(check2)
}
"throw parsing exception on valid number values with '.', 'e', 'E' chars" in {
checkError("1234567890123456789.0", "illegal number, offset: 0x00000013", "illegal number, offset: 0x00000014")
Expand Down Expand Up @@ -2747,7 +2747,7 @@ class JsonReaderSpec extends AnyWordSpec with Matchers with ScalaCheckPropertyCh
}
}
"parse keys and strigified values with leading zeros in mantissas and exponents" in {
forAll(arbitrary[Float], choose(1, 7), genWhitespaces, minSuccessful(1000)) { (x, z, ws) =>
forAll(arbitrary[Float], choose(1, 7), genWhitespaces, minSuccessful(100)) { (x, z, ws) =>
check2({
val s = x.toString
if (x < 0) s.replace("-", "-" + zeros(z))
Expand All @@ -2765,10 +2765,8 @@ class JsonReaderSpec extends AnyWordSpec with Matchers with ScalaCheckPropertyCh
}
}
"parse denormalized numbers with long mantissa and compensating exponent" in {
forAll(genWhitespaces) { ws =>
check("1" + millionZeros + "e-1000000", 1.0f, ws)
check("0." + millionZeros + "1e1000000", 0.1f, ws)
}
check("1" + millionZeros + "e-1000000", 1.0f, "")
check("0." + millionZeros + "1e1000000", 0.1f, "")
}
"throw parsing exception on illegal or empty input" in {
checkError("", "unexpected end of input, offset: 0x00000000", "illegal number, offset: 0x00000001")
Expand Down Expand Up @@ -2885,7 +2883,7 @@ class JsonReaderSpec extends AnyWordSpec with Matchers with ScalaCheckPropertyCh
}
}
"parse keys and strigified values with leading zeros in mantissas and exponents" in {
forAll(arbitrary[Double], choose(1, 7), genWhitespaces, minSuccessful(1000)) { (x, z, ws) =>
forAll(arbitrary[Double], choose(1, 7), genWhitespaces, minSuccessful(100)) { (x, z, ws) =>
check2({
val s = x.toString
if (x < 0) s.replace("-", "-" + zeros(z))
Expand All @@ -2903,10 +2901,8 @@ class JsonReaderSpec extends AnyWordSpec with Matchers with ScalaCheckPropertyCh
}
}
"parse denormalized numbers with long mantissa and compensating exponent" in {
forAll(genWhitespaces) { ws =>
check("1" + millionZeros + "e-1000000", 1.0, ws)
check("0." + millionZeros + "1e1000000", 0.1, ws)
}
check("1" + millionZeros + "e-1000000", 1.0, "")
check("0." + millionZeros + "1e1000000", 0.1, "")
}
"throw parsing exception on illegal or empty input" in {
checkError("", "unexpected end of input, offset: 0x00000000", "illegal number, offset: 0x00000001")
Expand Down Expand Up @@ -2978,17 +2974,15 @@ class JsonReaderSpec extends AnyWordSpec with Matchers with ScalaCheckPropertyCh
forAll(genBigInt, genWhitespaces, minSuccessful(10000))(check)
}
"parse keys and strigified values with leading zeros" in {
forAll(genBigInt, choose(1, 7), genWhitespaces, minSuccessful(1000))((x, z, ws) => check2({
forAll(genBigInt, choose(1, 7), genWhitespaces, minSuccessful(100))((x, z, ws) => check2({
val s = x.toString
if (x < 0) s.replace("-", "-" + zeros(z))
else zeros(z) + s
}, ws))
}
"parse big number values without overflow up to limits" in {
forAll(genWhitespaces) { ws =>
check(BigInt(bigNumber), ws)
check(BigInt(s"-$bigNumber"), ws)
}
check(BigInt(bigNumber), "")
check(BigInt(s"-$bigNumber"), "")
}
"throw parsing exception for values with more than max allowed digits" in {
checkError(fill('9', 308),
Expand Down Expand Up @@ -3090,32 +3084,28 @@ class JsonReaderSpec extends AnyWordSpec with Matchers with ScalaCheckPropertyCh
}
}
"parse big number values without overflow up to limits" in {
forAll(genWhitespaces) { ws =>
check(fill('9', 300), bigDecimalMathContext, bigDecimalScaleLimit, bigDecimalDigitsLimit, ws)
check("12345e67", bigDecimalMathContext, bigDecimalScaleLimit, bigDecimalDigitsLimit, ws)
check("-12345e67", bigDecimalMathContext, bigDecimalScaleLimit, bigDecimalDigitsLimit, ws)
check("12345678901234567890123456789012345678901234567890123456789012345678901234567890e-123456789",
MathContext.UNLIMITED, Int.MaxValue, Int.MaxValue, ws)
check("-12345678901234567890123456789012345678901234567890123456789012345678901234567890e-123456789",
MathContext.UNLIMITED, Int.MaxValue, Int.MaxValue, ws)
check("1E+2147483646", MathContext.UNLIMITED, Int.MaxValue, Int.MaxValue, ws) // max positive scale that can be parsed
}
check(fill('9', 300), bigDecimalMathContext, bigDecimalScaleLimit, bigDecimalDigitsLimit, "")
check("12345e67", bigDecimalMathContext, bigDecimalScaleLimit, bigDecimalDigitsLimit, "")
check("-12345e67", bigDecimalMathContext, bigDecimalScaleLimit, bigDecimalDigitsLimit, "")
check("12345678901234567890123456789012345678901234567890123456789012345678901234567890e-123456789",
MathContext.UNLIMITED, Int.MaxValue, Int.MaxValue, "")
check("-12345678901234567890123456789012345678901234567890123456789012345678901234567890e-123456789",
MathContext.UNLIMITED, Int.MaxValue, Int.MaxValue, "")
check("1E+2147483646", MathContext.UNLIMITED, Int.MaxValue, Int.MaxValue, "") // max positive scale that can be parsed
}
"parse small number values without underflow up to limits" in {
forAll(genWhitespaces) { ws =>
check(s"0.${zeros(100)}1234567890123456789012345678901234",
bigDecimalMathContext, bigDecimalScaleLimit, bigDecimalDigitsLimit, ws)
check("12345e-67", bigDecimalMathContext, bigDecimalScaleLimit, bigDecimalDigitsLimit, ws)
check("-12345e-67", bigDecimalMathContext, bigDecimalScaleLimit, bigDecimalDigitsLimit, ws)
check("12345678901234567890123456789012345678901234567890123456789012345678901234567890e-123456789",
MathContext.UNLIMITED, Int.MaxValue, Int.MaxValue, ws)
check("-12345678901234567890123456789012345678901234567890123456789012345678901234567890e-123456789",
MathContext.UNLIMITED, Int.MaxValue, Int.MaxValue, ws)
check("1E-2147483646", MathContext.UNLIMITED, Int.MaxValue, Int.MaxValue, ws) // max negative scale that can be parsed
}
check(s"0.${zeros(100)}1234567890123456789012345678901234",
bigDecimalMathContext, bigDecimalScaleLimit, bigDecimalDigitsLimit, "")
check("12345e-67", bigDecimalMathContext, bigDecimalScaleLimit, bigDecimalDigitsLimit, "")
check("-12345e-67", bigDecimalMathContext, bigDecimalScaleLimit, bigDecimalDigitsLimit, "")
check("12345678901234567890123456789012345678901234567890123456789012345678901234567890e-123456789",
MathContext.UNLIMITED, Int.MaxValue, Int.MaxValue, "")
check("-12345678901234567890123456789012345678901234567890123456789012345678901234567890e-123456789",
MathContext.UNLIMITED, Int.MaxValue, Int.MaxValue, "")
check("1E-2147483646", MathContext.UNLIMITED, Int.MaxValue, Int.MaxValue, "") // max negative scale that can be parsed
}
"parse keys and strigified values with leading zeros in mantissas and exponents" in {
forAll(genBigDecimal, choose(1, 7), genWhitespaces, minSuccessful(1000)) { (x, z, ws) =>
forAll(genBigDecimal, choose(1, 7), genWhitespaces, minSuccessful(100)) { (x, z, ws) =>
check2({
val s = x.toString
if (x < 0) s.replace("-", "-" + zeros(z))
Expand Down Expand Up @@ -3144,14 +3134,12 @@ class JsonReaderSpec extends AnyWordSpec with Matchers with ScalaCheckPropertyCh
"value exceeds limit for number of digits, offset: 0x00000134")
}
"throw number format exception for too big scale" in {
forAll(genWhitespaces) { ws =>
check(s"1e${bigDecimalScaleLimit - 1}", bigDecimalMathContext, bigDecimalScaleLimit, bigDecimalDigitsLimit, ws)
check(s"1e-${bigDecimalScaleLimit - 1}", bigDecimalMathContext, bigDecimalScaleLimit, bigDecimalDigitsLimit, ws)
check(s"${fill('1', 50)}e${bigDecimalScaleLimit - 17}",
MathContext.DECIMAL128, bigDecimalScaleLimit, bigDecimalDigitsLimit, ws)
check(s"${fill('1', 50)}e-${bigDecimalScaleLimit + 15}",
MathContext.DECIMAL128, bigDecimalScaleLimit, bigDecimalDigitsLimit, ws)
}
check(s"1e${bigDecimalScaleLimit - 1}", bigDecimalMathContext, bigDecimalScaleLimit, bigDecimalDigitsLimit, "")
check(s"1e-${bigDecimalScaleLimit - 1}", bigDecimalMathContext, bigDecimalScaleLimit, bigDecimalDigitsLimit, "")
check(s"${fill('1', 50)}e${bigDecimalScaleLimit - 17}",
MathContext.DECIMAL128, bigDecimalScaleLimit, bigDecimalDigitsLimit, "")
check(s"${fill('1', 50)}e-${bigDecimalScaleLimit + 15}",
MathContext.DECIMAL128, bigDecimalScaleLimit, bigDecimalDigitsLimit, "")
checkError(s"1e$bigDecimalScaleLimit",
"value exceeds limit for scale, offset: 0x00000005",
"value exceeds limit for scale, offset: 0x00000006")
Expand Down Expand Up @@ -3377,11 +3365,11 @@ class JsonReaderSpec extends AnyWordSpec with Matchers with ScalaCheckPropertyCh
.withPreferredCharBufSize(Random.nextInt(32))
.withThrowReaderExceptionWithStackTrace(true)

val tooLongNumber: String = fill('1', ReaderConfig.maxBufSize)
def tooLongNumber: String = fill('1', ReaderConfig.maxBufSize)

val millionZeros: String = zeros(1000000)
def millionZeros: String = zeros(1000000)

val bigNumber: String = fill('9', 1000)
def bigNumber: String = fill('9', 1000)

def zeros(n: Int): String = fill('0', n)

Expand Down

0 comments on commit 2489af7

Please sign in to comment.