From f513230b08ef7aafa2ae5504d7a2da116d1d3e74 Mon Sep 17 00:00:00 2001 From: Stephen Amar Date: Sun, 15 Mar 2026 00:51:47 +0000 Subject: [PATCH] Fix Scala Native build --- .github/workflows/release-build.yaml | 2 +- sjsonnet/src-js/sjsonnet/Platform.scala | 2 ++ sjsonnet/src-jvm/sjsonnet/Platform.scala | 18 ++++++++++++++++++ sjsonnet/src-native/sjsonnet/Platform.scala | 2 ++ sjsonnet/src/sjsonnet/DebugStats.scala | 16 +--------------- 5 files changed, 24 insertions(+), 16 deletions(-) diff --git a/.github/workflows/release-build.yaml b/.github/workflows/release-build.yaml index b0c2ddea..745bf939 100644 --- a/.github/workflows/release-build.yaml +++ b/.github/workflows/release-build.yaml @@ -16,7 +16,7 @@ jobs: - uses: actions/checkout@v6 - uses: actions/setup-java@v5 with: - java-version: 17 + java-version: 21 distribution: 'zulu' - name: Set up Node.js 24 uses: actions/setup-node@v6 diff --git a/sjsonnet/src-js/sjsonnet/Platform.scala b/sjsonnet/src-js/sjsonnet/Platform.scala index 25c6bf37..e18d617a 100644 --- a/sjsonnet/src-js/sjsonnet/Platform.scala +++ b/sjsonnet/src-js/sjsonnet/Platform.scala @@ -144,4 +144,6 @@ object Platform { } def regexQuote(s: String): String = Pattern.quote(s) + + def appendMemoryStats(sb: StringBuilder): Unit = {} } diff --git a/sjsonnet/src-jvm/sjsonnet/Platform.scala b/sjsonnet/src-jvm/sjsonnet/Platform.scala index 7ded488a..2bc28595 100644 --- a/sjsonnet/src-jvm/sjsonnet/Platform.scala +++ b/sjsonnet/src-jvm/sjsonnet/Platform.scala @@ -165,4 +165,22 @@ object Platform { quote } } + + def appendMemoryStats(sb: StringBuilder): Unit = { + val rt = Runtime.getRuntime + val usedBytes = rt.totalMemory() - rt.freeMemory() + val maxBytes = rt.maxMemory() + sb.append(formatBytesLine("heap_used", usedBytes)) + sb.append(formatBytesLine("heap_max", maxBytes)) + } + + private def formatBytesLine(label: String, bytes: Long): String = + f"$label%-25s ${formatBytes(bytes)}%s%n" + + private def formatBytes(bytes: Long): String = { + if (bytes < 1024L) s"${bytes}B" + else if (bytes < 1024L * 1024) f"${bytes / 1024.0}%.1fKB" + else if (bytes < 1024L * 1024 * 1024) f"${bytes / (1024.0 * 1024)}%.1fMB" + else f"${bytes / (1024.0 * 1024 * 1024)}%.2fGB" + } } diff --git a/sjsonnet/src-native/sjsonnet/Platform.scala b/sjsonnet/src-native/sjsonnet/Platform.scala index eb3030a7..527e8f09 100644 --- a/sjsonnet/src-native/sjsonnet/Platform.scala +++ b/sjsonnet/src-native/sjsonnet/Platform.scala @@ -188,4 +188,6 @@ object Platform { quote } } + + def appendMemoryStats(sb: StringBuilder): Unit = {} } diff --git a/sjsonnet/src/sjsonnet/DebugStats.scala b/sjsonnet/src/sjsonnet/DebugStats.scala index cadbd7e2..7392910e 100644 --- a/sjsonnet/src/sjsonnet/DebugStats.scala +++ b/sjsonnet/src/sjsonnet/DebugStats.scala @@ -53,11 +53,7 @@ final class DebugStats { sb.append(formatTimeLine("materialize_time", materializeTimeNs)) sb.append(formatTimeLine("total_time", totalTimeNs)) - val rt = Runtime.getRuntime - val usedBytes = rt.totalMemory() - rt.freeMemory() - val maxBytes = rt.maxMemory() - sb.append(formatBytesLine("heap_used", usedBytes)) - sb.append(formatBytesLine("heap_max", maxBytes)) + Platform.appendMemoryStats(sb) sb.toString } @@ -68,22 +64,12 @@ final class DebugStats { private def formatTimeLine(label: String, ns: Long): String = f"$label%-25s ${formatNs(ns)}%s%n" - private def formatBytesLine(label: String, bytes: Long): String = - f"$label%-25s ${formatBytes(bytes)}%s%n" - private def formatNs(ns: Long): String = { if (ns < 1000L) s"${ns}ns" else if (ns < 1000000L) f"${ns / 1000.0}%.1fμs" else if (ns < 1000000000L) f"${ns / 1000000.0}%.1fms" else f"${ns / 1000000000.0}%.3fs" } - - private def formatBytes(bytes: Long): String = { - if (bytes < 1024L) s"${bytes}B" - else if (bytes < 1024L * 1024) f"${bytes / 1024.0}%.1fKB" - else if (bytes < 1024L * 1024 * 1024) f"${bytes / (1024.0 * 1024)}%.1fMB" - else f"${bytes / (1024.0 * 1024 * 1024)}%.2fGB" - } } /**