Skip to content

OutOfMemoryError: Metaspace when compiling multiple functions with Viper verification enabled #54

@pawinkler

Description

@pawinkler

Description
When running ./gradlew compileKotlin multiple times with the Gradle daemon enabled (the default), the compiler eventually crashes with:

e: java.lang.OutOfMemoryError: Metaspace                                                                                                                                                                 
    at scala.collection.immutable.List$.<clinit>(List.scala:682)                                                                                                                                         
    ...
    at org.jetbrains.kotlin.formver.viper.Verifier.<init>(Verifier.kt:27)
    at org.jetbrains.kotlin.formver.plugin.compiler.ViperPoweredDeclarationChecker.check(ViperPoweredDeclarationChecker.kt:82)

Suspected Root Cause

ViperPoweredDeclarationChecker.check() is called once per function declaration. On line 82, it constructs a new Verifier instance for every function: val verifier = Verifier()

Each Verifier construction initializes a Config with seqOf(...), which triggers loading of Scala's collections library (List$, Seq$, etc.) into JVM Metaspace. Because the Gradle daemon is a long-lived process, these class definitions accumulate across builds until Metaspace is exhausted.

Steps to Reproduce

  1. Enable conversionTargetsSelection("all_targets") in the Gradle plugin config
  2. Have a project with several Kotlin functions to verify
  3. Run ./gradlew compileKotlin --rerun-tasks three or more times in succession

Expected Behavior

Metaspace usage should remain stable across repeated compilations.

Workaround

Add to gradle.properties:
kotlin.daemon.jvm.options=-XX:MaxMetaspaceSize=512m

This delays the OOM but does not fix the underlying issue.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions