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

java.lang.OutOfMemoryError: Java heap space #3885

Open
mahozad opened this issue Oct 25, 2024 · 6 comments
Open

java.lang.OutOfMemoryError: Java heap space #3885

mahozad opened this issue Oct 25, 2024 · 6 comments
Labels

Comments

@mahozad
Copy link
Contributor

mahozad commented Oct 25, 2024

Describe the bug
When upgrading Dokka from 1.9.20 to 2.0.0-Beta, executing dokkaGenerate task fails:

...
> Task :wavy-slider:dokkaGenerateModuleHtml
> Task :wavy-slider:dokkaGeneratePublicationHtml

java.lang.OutOfMemoryError: Java heap space
Dumping heap to java_pid37140.hprof ...
java.lang.OutOfMemoryError: Java heap space
Dumping heap to java_pid20352.hprof ...
Heap dump file created [804336399 bytes in 7.145 secs]

> Task :wavy-slider:dokkaGenerateModuleHtml FAILED
Heap dump file created [804312093 bytes in 6.518 secs]
> Task :wavy-slider:dokkaGeneratePublicationHtml FAILED

Expected behaviour
Should generate HTML output.

To Reproduce
Please checkout this commit and apply the below dokka configs in library/build.gradle.kts and run ./gradlew wavy-slider:dokkaGenerate

Dokka configuration
gradle.properties:

org.jetbrains.dokka.experimental.gradle.pluginMode=V2EnabledWithHelpers

library/build.gradle.kts:

dokka {
    moduleName = "Hello"

    dokkaSourceSets.configureEach {
        reportUndocumented = true
        enableJdkDocumentationLink = true
        enableAndroidDocumentationLink = true
        enableKotlinStdLibDocumentationLink = true
        jdkVersion = libs.versions.java.get().toInt()
    }

    pluginsConfiguration.html {
        customStyleSheets.from(file("../asset/logo-styles.css"))
        customAssets.from(file("../asset/logo-icon.svg"))
        separateInheritedMembers = true
    }
}

Installation

  • Operating system: Windows
  • Build tool: Gradle v8.10.2
  • Dokka version: 2.0.0-Beta

Additional context
Dokka 1.9.20 worked properly.

@mahozad mahozad added the bug label Oct 25, 2024
@whyoleg
Copy link
Collaborator

whyoleg commented Oct 31, 2024

Hey!
Yeah, that's because Gradle Plugin v2 uses a bit different way of running Dokka generator/engine by default. We are thinking of changing it.
In the meanwhile, you can do that explicitly:

dokka {
    dokkaGeneratorIsolation = ClassLoaderIsolation()
}

For more information on what it does, you can take a look on updated extensive KDoc.

@mahozad
Copy link
Contributor Author

mahozad commented Oct 31, 2024

Thank you. that resolved the problem.

@SakurajimaMaii
Copy link

Gradle version should also be above 8.10

@ShreckYe
Copy link

ShreckYe commented Nov 6, 2024

@whyoleg should this be added to the subprojects (the convention plugin), or the root project, or both, if I have a multi-module build?

@SakurajimaMaii
Copy link

SakurajimaMaii commented Nov 6, 2024

@whyoleg should this be added to the subprojects (the convention plugin), or the root project, or both, if I have a multi-module build?

You can take a look at my project, maybe it can help you https://github.com/SakurajimaMaii/Android-Vast-Extension/tree/preview/kotlin-2.0.0/libraries

@ShreckYe
Copy link

ShreckYe commented Nov 6, 2024

@SakurajimaMaii OK thanks.

ShreckYe added a commit to huanshankeji/compose-multiplatform-material that referenced this issue Nov 6, 2024
…adapted from "gradle-common", and resolve heap memory issues

A source commit: huanshankeji/gradle-common@c1c69c3

`java.lang.OutOfMemoryError: Java heap space` occurs when running the `dokkaGenerate` Gradle task without further configuration and is resolved with the approach from Kotlin/dokka#3885 (comment). The solution code `dokkaGeneratorIsolation = ClassLoaderIsolation()` has to be added to the subproject build scripts (the convention plugin) to work.

Moreover, this happens when the heap space is not enough:

```text
The Daemon will expire immediately since the JVM garbage collector is thrashing
The project memory settings are likely not configured or are configured to an insufficient value.
The memory settings for this project must be adjusted to avoid this failure.
These settings can be adjusted by setting 'org.gradle.jvmargs' in 'gradle.properties'.
The currently configured max heap space is '2 GiB' and the configured max metaspace is 'unknown'.
```

Therefore, `Xmx` in `org.gradle.jvmargs` is increased all the way to 32 GB. 4 GB and 8 GB still cause GC thrashing, and 16 GB is enough but the task takes more time compared to 32 GB with swap. The actual max memory usage is about 30 GB with the 32 GB max heap size. This seems to be caused by parallelism so to reduce the max memory usage, the `--max-workers` Gradle argument can be used and is tested to work. `--no-parallel` doesn't make a difference as tested, however.

Eventually, after the 2 issues above are fixed, the task still fails because of Kotlin/dokka#3900.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants