Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DefaultJvmMetadataDetector#getMetadataFromInstallation misses Xmx, so the JVM might allocate significant amount of memory #25628

Closed
vlsi opened this issue Jul 6, 2023 · 2 comments · Fixed by #25761
Labels
a:bug good first issue Good for newcomers has:reproducer Indicates the issue has a confirmed reproducer in:toolchains Java Toolchains
Milestone

Comments

@vlsi
Copy link
Contributor

vlsi commented Jul 6, 2023

Expected Behavior

Gradle builds should not consume excessive amounts of memory.
See

private JvmInstallationMetadata getMetadataFromInstallation(File jdkPath) {
File tmpDir = temporaryFileProvider.createTemporaryDirectory("jvm", "probe");
File probe = writeProbeClass(tmpDir);
ExecHandleBuilder exec = execHandleFactory.newExec();
exec.setWorkingDir(probe.getParentFile());
exec.executable(javaExecutable(jdkPath));
try {
ByteArrayOutputStream out = new ByteArrayOutputStream();
ByteArrayOutputStream errorOutput = new ByteArrayOutputStream();
String mainClassname = Files.getNameWithoutExtension(probe.getName());
exec.args("-cp", ".", mainClassname);
exec.setStandardOutput(out);
exec.setErrorOutput(errorOutput);
exec.setIgnoreExitValue(true);

Current Behavior

Gradle spawns .../bin/java -cp . JavaProbe without -Xmx

Context (optional)

See sample.
Java with defaults "commits" 1.15G ram while Java with -Xmx32m commits 0.11G only.

$ java -XX:NativeMemoryTracking=summary -XX:+UnlockDiagnosticVMOptions -XX:+PrintNMTStatistics -version

openjdk version "17.0.7" 2023-04-18 LTS
OpenJDK Runtime Environment (build 17.0.7+7-LTS)
OpenJDK 64-Bit Server VM (build 17.0.7+7-LTS, mixed mode, sharing)

Native Memory Tracking:

Total: reserved=19313204297, committed=1235819593
       malloc: 22932553 #4973
       mmap:   reserved=19290271744, committed=1212887040

-                 Java Heap (reserved=17179869184, committed=1090519040)
                            (mmap: reserved=17179869184, committed=1090519040)

-                     Class (reserved=1073812158, committed=135870)
                            (classes #447)
                            (  instance classes #362, array classes #85)
                            (malloc=70334 #465)
                            (mmap: reserved=1073741824, committed=65536)
                            (  Metadata:   )
                            (    reserved=67108864, committed=65536)
                            (    used=52576)
                            (    waste=12960 =19,78%)
                            (  Class space:)
                            (    reserved=1073741824, committed=65536)
                            (    used=1624)
                            (    waste=63912 =97,52%)

-                    Thread (reserved=27465584, committed=27465584)
                            (thread #13)
                            (stack: reserved=27422720, committed=27422720)
                            (malloc=24432 #106)
                            (arena=18432 #32)

-                      Code (reserved=253671496, committed=7796808)
                            (malloc=30792 #535)
                            (mmap: reserved=253640704, committed=7766016)

-                        GC (reserved=692389522, committed=95323794)
                            (malloc=20743826 #588)
                            (mmap: reserved=671645696, committed=74579968)

-                  Compiler (reserved=170808, committed=170808)
                            (malloc=2248 #19)
                            (arena=168560 #5)

-                  Internal (reserved=177265, committed=177265)
                            (malloc=144497 #1115)
                            (mmap: reserved=32768, committed=32768)

-                    Symbol (reserved=1157952, committed=1157952)
                            (malloc=789312 #36)
                            (arena=368640 #1)

-    Native Memory Tracking (reserved=83624, committed=83624)
                            (malloc=4040 #55)
                            (tracking overhead=79584)

-        Shared class space (reserved=16777216, committed=12402688)
                            (mmap: reserved=16777216, committed=12402688)

-               Arena Chunk (reserved=375088, committed=375088)
                            (malloc=375088)

-                   Tracing (reserved=313, committed=313)
                            (malloc=313 #9)

-                 Arguments (reserved=171, committed=171)
                            (malloc=171 #5)

-                    Module (reserved=13800, committed=13800)
                            (malloc=13800 #401)

-                 Safepoint (reserved=32768, committed=32768)
                            (mmap: reserved=32768, committed=32768)

-           Synchronization (reserved=86804, committed=86804)
                            (malloc=86804 #1559)

-            Serviceability (reserved=576, committed=576)
                            (malloc=576 #6)

-                 Metaspace (reserved=67118944, committed=75616)
                            (malloc=10080 #6)
                            (mmap: reserved=67108864, committed=65536)

-      String Deduplication (reserved=608, committed=608)
                            (malloc=608 #8)

-           Object Monitors (reserved=416, committed=416)
                            (malloc=416 #2)

The same with -Xmx32m:

% java -XX:NativeMemoryTracking=summary -XX:+UnlockDiagnosticVMOptions -XX:+PrintNMTStatistics -Xmx32m -version
openjdk version "17.0.7" 2023-04-18 LTS
OpenJDK Runtime Environment (build 17.0.7+7-LTS)
OpenJDK 64-Bit Server VM (build 17.0.7+7-LTS, mixed mode, sharing)

Native Memory Tracking:

Total: reserved=1528320534, committed=137351702
       malloc: 21193238 #4086
       mmap:   reserved=1507127296, committed=116158464

-                 Java Heap (reserved=33554432, committed=33554432)
                            (mmap: reserved=33554432, committed=33554432)

-                     Class (reserved=1073812158, committed=135870)
                            (classes #447)
                            (  instance classes #362, array classes #85)
                            (malloc=70334 #465)
                            (mmap: reserved=1073741824, committed=65536)
                            (  Metadata:   )
                            (    reserved=67108864, committed=65536)
                            (    used=52576)
                            (    waste=12960 =19,78%)
                            (  Class space:)
                            (    reserved=1073741824, committed=65536)
                            (    used=1624)
                            (    waste=63912 =97,52%)

-                    Thread (reserved=27465584, committed=27465584)
                            (thread #13)
                            (stack: reserved=27422720, committed=27422720)
                            (malloc=24432 #106)
                            (arena=18432 #32)

-                      Code (reserved=253671352, committed=7796664)
                            (malloc=30648 #529)
                            (mmap: reserved=253640704, committed=7766016)

-                        GC (reserved=53962202, committed=53962202)
                            (malloc=19146202 #294)
                            (mmap: reserved=34816000, committed=34816000)

-                  Compiler (reserved=382296, committed=382296)
                            (malloc=2248 #19)
                            (arena=380048 #13)

-                  Internal (reserved=172182, committed=172182)
                            (malloc=139414 #922)
                            (mmap: reserved=32768, committed=32768)

-                    Symbol (reserved=1157952, committed=1157952)
                            (malloc=789312 #36)
                            (arena=368640 #1)

-    Native Memory Tracking (reserved=69096, committed=69096)
                            (malloc=3704 #49)
                            (tracking overhead=65392)

-        Shared class space (reserved=16777216, committed=12402688)
                            (mmap: reserved=16777216, committed=12402688)

-               Arena Chunk (reserved=66368, committed=66368)
                            (malloc=66368)

-                   Tracing (reserved=313, committed=313)
                            (malloc=313 #9)

-                 Arguments (reserved=171, committed=171)
                            (malloc=171 #5)

-                    Module (reserved=13800, committed=13800)
                            (malloc=13800 #401)

-                 Safepoint (reserved=32768, committed=32768)
                            (mmap: reserved=32768, committed=32768)

-           Synchronization (reserved=62100, committed=62100)
                            (malloc=62100 #1173)

-            Serviceability (reserved=576, committed=576)
                            (malloc=576 #6)

-                 Metaspace (reserved=67118944, committed=75616)
                            (malloc=10080 #6)
                            (mmap: reserved=67108864, committed=65536)

-      String Deduplication (reserved=608, committed=608)
                            (malloc=608 #8)

-           Object Monitors (reserved=416, committed=416)
                            (malloc=416 #2)

Steps to Reproduce

Run Gradle build with toolchains.

Gradle version

8.1.1

Build scan URL (optional)

No response

Your Environment (optional)

No response

@ov7a
Copy link
Member

ov7a commented Jul 7, 2023

Thank you for providing a valid reproducer.

The issue is in the backlog of the relevant team, but this area of Gradle is currently not a focus one, so it might take a while before a fix is made.

@ov7a ov7a added in:toolchains Java Toolchains has:reproducer Indicates the issue has a confirmed reproducer good first issue Good for newcomers and removed to-triage labels Jul 7, 2023
@ov7a
Copy link
Member

ov7a commented Jul 7, 2023

This issue is a good choice for first-time contributors to Gradle, it is actionable and ready for contribution.

See CONTRIBUTING.md for more information.


Let's pass Xmx and Xms with 32M as default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:bug good first issue Good for newcomers has:reproducer Indicates the issue has a confirmed reproducer in:toolchains Java Toolchains
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants