Skip to content

Commit 32d6530

Browse files
arturazautofix-ci[bot]lihaoyi
authored
Fix/actually limit memory for client (#5026)
Properly implements fix done in #4163 Also adds JVisualVM support for native mill image. Tested manually by launching both the JVM and native versions and looking at the memory usage during compilation via JVisualVM --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Li Haoyi <[email protected]>
1 parent a3c9399 commit 32d6530

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

dist/package.mill

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ object `package` extends MillJavaModule with DistModule {
8282

8383
def localBinName = "mill-assembly.jar"
8484

85+
private def millClientJvmArgs = Seq(
86+
// Avoid reserving a lot of memory for the client, as the client only forward information
87+
"-Xmx128m"
88+
)
89+
8590
def launcher = Task {
8691
val isWin = scala.util.Properties.isWin
8792
val outputPath = Task.dest / (if (isWin) "run.bat" else "run")
@@ -102,9 +107,7 @@ object `package` extends MillJavaModule with DistModule {
102107
.mkString("\r\n")
103108

104109
os.write(vmOptionsFile, millOptionsContent)
105-
val jvmArgs = otherArgs ++ List(
106-
// Avoid reserving a lot of memory for the client, as the client only forward information
107-
"-Xmx32m",
110+
val jvmArgs = otherArgs ++ millClientJvmArgs ++ List(
108111
s"-DMILL_OPTIONS_PATH=$vmOptionsFile"
109112
)
110113
val classpath = runClasspath().map(_.path.toString)
@@ -129,7 +132,7 @@ object `package` extends MillJavaModule with DistModule {
129132
mill.scalalib.Assembly.Rule.ExcludePattern("mill/local-test-overrides/.*")
130133
)
131134

132-
def forkArgs = Seq(
135+
def forkArgs = millClientJvmArgs ++ Seq(
133136
// Workaround for Zinc/JNA bug
134137
// https://github.com/sbt/sbt/blame/6718803ee6023ab041b045a6988fafcfae9d15b5/main/src/main/scala/sbt/Main.scala#L130
135138
"-Djna.nosys=true"
@@ -278,7 +281,14 @@ object `package` extends MillJavaModule with DistModule {
278281
PathRef(executable)
279282
}
280283

281-
def nativeImageOptions = Seq("--no-fallback", "--enable-url-protocols=https", "-Os")
284+
def nativeImageOptions = Seq(
285+
"--no-fallback",
286+
"--enable-url-protocols=https",
287+
"-Os"
288+
// Enable JVisualVM support
289+
// https://www.graalvm.org/latest/tools/visualvm/#using-visualvm-with-graalvm-native-executables
290+
// "--enable-monitoring=jvmstat,heapdump"
291+
)
282292

283293
def jvmWorker = ModuleRef(JvmWorkerGraalvm)
284294

0 commit comments

Comments
 (0)