From ec5a5faf82c6b7f799c9f98023d07cc1050ce824 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20Leuth=C3=A4user?= <1417198+max-leuthaeuser@users.noreply.github.com> Date: Fri, 4 Oct 2024 09:18:42 +0200 Subject: [PATCH 1/2] [jssrc2cpg] Pass JVM max memory setting to astgen --- .../io/joern/jssrc2cpg/utils/AstGenRunner.scala | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/joern-cli/frontends/jssrc2cpg/src/main/scala/io/joern/jssrc2cpg/utils/AstGenRunner.scala b/joern-cli/frontends/jssrc2cpg/src/main/scala/io/joern/jssrc2cpg/utils/AstGenRunner.scala index 17f636c75958..c1f227774e0e 100644 --- a/joern-cli/frontends/jssrc2cpg/src/main/scala/io/joern/jssrc2cpg/utils/AstGenRunner.scala +++ b/joern-cli/frontends/jssrc2cpg/src/main/scala/io/joern/jssrc2cpg/utils/AstGenRunner.scala @@ -23,7 +23,17 @@ object AstGenRunner { private val LineLengthThreshold: Int = 10000 - private val NODE_OPTIONS: Map[String, String] = Map("NODE_OPTIONS" -> "--max-old-space-size=8192") + private def getMaxHeapSizeInMB: Long = { + val maxHeapSizeInBytes = Runtime.getRuntime.maxMemory() + val maxHeapSizeInMB = maxHeapSizeInBytes / (1024 * 1024) + maxHeapSizeInMB // nodejs expects MB + } + + private def nodejsSpaceSize: Int = { + Math.max(getMaxHeapSizeInMB.toInt, 8192) // as default we set 8G minimum + } + + private val NODE_OPTIONS: Map[String, String] = Map("NODE_OPTIONS" -> s"--max-old-space-size=$nodejsSpaceSize") private val TypeDefinitionFileExtensions = List(".t.ts", ".d.ts") From 64b604b49b1e5c55b39e16baba05ddf74816b98d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20Leuth=C3=A4user?= <1417198+max-leuthaeuser@users.noreply.github.com> Date: Fri, 4 Oct 2024 09:24:33 +0200 Subject: [PATCH 2/2] bit safer --- .../src/main/scala/io/joern/jssrc2cpg/utils/AstGenRunner.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/joern-cli/frontends/jssrc2cpg/src/main/scala/io/joern/jssrc2cpg/utils/AstGenRunner.scala b/joern-cli/frontends/jssrc2cpg/src/main/scala/io/joern/jssrc2cpg/utils/AstGenRunner.scala index c1f227774e0e..357b0d0a9573 100644 --- a/joern-cli/frontends/jssrc2cpg/src/main/scala/io/joern/jssrc2cpg/utils/AstGenRunner.scala +++ b/joern-cli/frontends/jssrc2cpg/src/main/scala/io/joern/jssrc2cpg/utils/AstGenRunner.scala @@ -30,7 +30,7 @@ object AstGenRunner { } private def nodejsSpaceSize: Int = { - Math.max(getMaxHeapSizeInMB.toInt, 8192) // as default we set 8G minimum + Math.max((0.75 * getMaxHeapSizeInMB).toInt, 8192) // as default we set 8G minimum } private val NODE_OPTIONS: Map[String, String] = Map("NODE_OPTIONS" -> s"--max-old-space-size=$nodejsSpaceSize")