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

Increase memory used for forked compiler #1753

Merged
merged 3 commits into from
Dec 11, 2024

Conversation

sciwhiz12
Copy link
Member

This PR fixes an out of memory error when compiling with a non-Java 21 JVM running the Gradle Daemon, by specifically setting the maximum memory used by the forked Java compiler process.

When running the Gradle Daemon with a non-J21 JVM, it will fork the Java compiler into a separate process rather than running it in-process with the Daemon. However, that means the compiler process uses the default amount of memory, which is not able to compile all of NeoForge & Minecraft (as it fails with an OutOfMemoryError).

Setting the memory when the compiler is forked ensures that whether the compiler runs in-process with the Daemon or as a forked process, it will always have enough memory to compile all the sources properly.


This is an alternative solution to the problem that #1692 also seeks to fix, which is more tailored to the problem by specifically addressing the root cause of the out-of-memory error.

To test, first set the Daemon to use a non-Java 21 JVM (via the JAVA_HOME environment variable pointed to a Java 17 JVM, for example), then run ./gradlew clean, ./gradlew setup (to prepare the workspace), then ./gradlew assemble --no-build-cache --rerun-tasks. Without this PR, :neoforge:compileJava will fail with a "Java heap space" error; with this PR, the build will succeed.

When running the Gradle Daemon with a non-J21 JVM, it will fork the
Java compiler into a separate process rather than running it in-process
with the Daemon. However, that means the compiler process uses the
default amount of memory, which is not able to compile all of NeoForge &
Minecraft (as it fails with an OutOfMemoryError).

Setting the memory when the compiler is forked ensures that whether the
compiler runs in-process with the Daemon or as a forked process, it will
always have enough memory to compile all the sources properly.
@sciwhiz12 sciwhiz12 added bug A bug or error ci/build Related to continuous integration/build system 1.21.4 Targeted at Minecraft 1.21.4 labels Dec 10, 2024
@neoforged-pr-publishing
Copy link

neoforged-pr-publishing bot commented Dec 10, 2024

  • Publish PR to GitHub Packages

Last commit published: b961a4b5a7def793d906530bd3d256f5bcccb4ff.

PR Publishing

The artifacts published by this PR:

Repository Declaration

In order to use the artifacts published by the PR, add the following repository to your buildscript:

repositories {
    maven {
        name 'Maven for PR #1753' // https://github.com/neoforged/NeoForge/pull/1753
        url 'https://prmaven.neoforged.net/NeoForge/pr1753'
        content {
            includeModule('net.neoforged', 'testframework')
            includeModule('net.neoforged', 'neoforge')
        }
    }
}

MDK installation

In order to setup a MDK using the latest PR version, run the following commands in a terminal.
The script works on both *nix and Windows as long as you have the JDK bin folder on the path.
The script will clone the MDK in a folder named NeoForge-pr1753.
On Powershell you will need to remove the -L flag from the curl invocation.

mkdir NeoForge-pr1753
cd NeoForge-pr1753
curl -L https://prmaven.neoforged.net/NeoForge/pr1753/net/neoforged/neoforge/21.4.17-beta-pr-1753-neoforge-compiler-memory/mdk-pr1753.zip -o mdk.zip
jar xf mdk.zip
rm mdk.zip || del mdk.zip

To test a production environment, you can download the installer from here.

Technici4n
Technici4n previously approved these changes Dec 10, 2024
The Daemon should require less memory as more things are now run out of
process. This also matches the max memory argument passed to the compile
tasks.
@embeddedt embeddedt merged commit 96c69d4 into neoforged:1.21.x Dec 11, 2024
6 checks passed
@sciwhiz12 sciwhiz12 deleted the neoforge-compiler-memory branch December 11, 2024 03:19
@neoforged-releases
Copy link

🚀 This PR has been released as NeoForge version 21.4.15-beta.

Soaryn pushed a commit to Soaryn/EnergyHandlerPR that referenced this pull request Jan 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.21.4 Targeted at Minecraft 1.21.4 bug A bug or error ci/build Related to continuous integration/build system
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants