From 897be0e8e7f5490d6b40f23e50af6537344063da Mon Sep 17 00:00:00 2001 From: Vadim Mishenev Date: Tue, 26 Nov 2024 13:23:38 +0200 Subject: [PATCH] Update Analysis API to 2.1.20-dev-4370 (#3802) --- .../kotlin/SequentialTasksExecutionStressTest.kt | 5 ++++- .../analysis-java-psi/api/analysis-java-psi.api | 1 + .../dokka/analysis/java/JavaAnalysisPlugin.kt | 15 +++++++++++++++ .../configuration/TestDokkaConfigurationMapper.kt | 2 +- .../symbols/plugin/SymbolsAnalysisPlugin.kt | 14 +++++++++----- .../kotlin/org/jetbrains/dokka/configuration.kt | 11 ++++++++--- gradle/libs.versions.toml | 2 +- 7 files changed, 39 insertions(+), 11 deletions(-) diff --git a/dokka-integration-tests/gradle/src/testTemplateProjectTasksExecutionStress/kotlin/SequentialTasksExecutionStressTest.kt b/dokka-integration-tests/gradle/src/testTemplateProjectTasksExecutionStress/kotlin/SequentialTasksExecutionStressTest.kt index 162e99fbe6..a2d4aec71a 100644 --- a/dokka-integration-tests/gradle/src/testTemplateProjectTasksExecutionStress/kotlin/SequentialTasksExecutionStressTest.kt +++ b/dokka-integration-tests/gradle/src/testTemplateProjectTasksExecutionStress/kotlin/SequentialTasksExecutionStressTest.kt @@ -25,7 +25,10 @@ class SequentialTasksExecutionStressTest : AbstractGradleIntegrationTest() { buildVersions, "runTasks", "-Ptask_number=$iterations", - jvmArgs = listOf("-Xmx1G", "-XX:MaxMetaspaceSize=500m"), + jvmArgs = listOf( + "-Xmx1G", "-XX:MaxMetaspaceSize=500m", + "-XX:SoftRefLRUPolicyMSPerMB=10" // to free up the metaspace on JVM 8, see https://youtrack.jetbrains.com/issue/KT-55831/ + ), enableBuildCache = false, ).buildRelaxed() diff --git a/dokka-subprojects/analysis-java-psi/api/analysis-java-psi.api b/dokka-subprojects/analysis-java-psi/api/analysis-java-psi.api index 02d6628479..5cb0cc30e1 100644 --- a/dokka-subprojects/analysis-java-psi/api/analysis-java-psi.api +++ b/dokka-subprojects/analysis-java-psi/api/analysis-java-psi.api @@ -26,6 +26,7 @@ public final class org/jetbrains/dokka/analysis/java/ExceptionJavadocTag$Compani public final class org/jetbrains/dokka/analysis/java/JavaAnalysisPlugin : org/jetbrains/dokka/plugability/DokkaPlugin { public fun ()V + public final fun disposeGlobalStandaloneApplicationServices ()V public final fun getDocCommentCreators ()Lorg/jetbrains/dokka/plugability/ExtensionPoint; public final fun getDocCommentFinder ()Lorg/jetbrains/dokka/analysis/java/doccomment/DocCommentFinder; public final fun getDocCommentParsers ()Lorg/jetbrains/dokka/plugability/ExtensionPoint; diff --git a/dokka-subprojects/analysis-java-psi/src/main/kotlin/org/jetbrains/dokka/analysis/java/JavaAnalysisPlugin.kt b/dokka-subprojects/analysis-java-psi/src/main/kotlin/org/jetbrains/dokka/analysis/java/JavaAnalysisPlugin.kt index 8a322a7466..d4d3dc582a 100644 --- a/dokka-subprojects/analysis-java-psi/src/main/kotlin/org/jetbrains/dokka/analysis/java/JavaAnalysisPlugin.kt +++ b/dokka-subprojects/analysis-java-psi/src/main/kotlin/org/jetbrains/dokka/analysis/java/JavaAnalysisPlugin.kt @@ -71,6 +71,21 @@ public class JavaAnalysisPlugin : DokkaPlugin() { DocCommentFinder(logger, docCommentFactory) } + // TODO #3936(https://youtrack.jetbrains.com/issue/KT-71862) use an endpoint from AA + /** + * Disposes global resources which would persist after unloading Analysis API (Symbols analysis) and IJ platform classes. + * + * **Important:** Once this function has been called, Analysis API *and* IntelliJ platform classes should not be used anymore. The classes + * should either be unloaded or the whole program should be shut down. + * + * Note: Disposing of resources, including threads, allows unloading Dokka's class loader. + */ + @InternalDokkaApi + public fun disposeGlobalStandaloneApplicationServices() { + @Suppress("UnstableApiUsage") + com.intellij.util.concurrency.AppExecutorUtil.shutdownApplicationScheduledExecutorService() + } + internal val javaDocCommentCreator by extending { docCommentCreators providing { JavaDocCommentCreator() } } diff --git a/dokka-subprojects/analysis-kotlin-api/src/testFixtures/kotlin/org/jetbrains/dokka/analysis/test/api/configuration/TestDokkaConfigurationMapper.kt b/dokka-subprojects/analysis-kotlin-api/src/testFixtures/kotlin/org/jetbrains/dokka/analysis/test/api/configuration/TestDokkaConfigurationMapper.kt index 35c084e3a6..04bb6a6180 100644 --- a/dokka-subprojects/analysis-kotlin-api/src/testFixtures/kotlin/org/jetbrains/dokka/analysis/test/api/configuration/TestDokkaConfigurationMapper.kt +++ b/dokka-subprojects/analysis-kotlin-api/src/testFixtures/kotlin/org/jetbrains/dokka/analysis/test/api/configuration/TestDokkaConfigurationMapper.kt @@ -82,7 +82,7 @@ fun TestDokkaConfiguration.toDokkaConfiguration(projectDir: File): DokkaConfigur override val suppressInheritedMembers: Boolean get() = throw NotImplementedError("Not expected to be used by analysis modules") override val finalizeCoroutines: Boolean - get() = throw NotImplementedError("Not expected to be used by analysis modules") + get() = false } } diff --git a/dokka-subprojects/analysis-kotlin-symbols/src/main/kotlin/org/jetbrains/dokka/analysis/kotlin/symbols/plugin/SymbolsAnalysisPlugin.kt b/dokka-subprojects/analysis-kotlin-symbols/src/main/kotlin/org/jetbrains/dokka/analysis/kotlin/symbols/plugin/SymbolsAnalysisPlugin.kt index 5c5cf233f2..f12ff3f033 100644 --- a/dokka-subprojects/analysis-kotlin-symbols/src/main/kotlin/org/jetbrains/dokka/analysis/kotlin/symbols/plugin/SymbolsAnalysisPlugin.kt +++ b/dokka-subprojects/analysis-kotlin-symbols/src/main/kotlin/org/jetbrains/dokka/analysis/kotlin/symbols/plugin/SymbolsAnalysisPlugin.kt @@ -20,10 +20,7 @@ import org.jetbrains.dokka.analysis.kotlin.symbols.services.* import org.jetbrains.dokka.analysis.kotlin.symbols.services.KotlinDocumentableSourceLanguageParser import org.jetbrains.dokka.analysis.kotlin.symbols.services.SymbolExternalDocumentablesProvider import org.jetbrains.dokka.analysis.kotlin.symbols.translators.DefaultSymbolToDocumentableTranslator -import org.jetbrains.dokka.plugability.DokkaPlugin -import org.jetbrains.dokka.plugability.DokkaPluginApiPreview -import org.jetbrains.dokka.plugability.PluginApiPreviewAcknowledgement -import org.jetbrains.dokka.plugability.querySingle +import org.jetbrains.dokka.plugability.* import org.jetbrains.dokka.renderers.PostAction import org.jetbrains.kotlin.asJava.elements.KtLightAbstractAnnotation @@ -42,7 +39,14 @@ public class SymbolsAnalysisPlugin : DokkaPlugin() { } internal val disposeKotlinAnalysisPostAction by extending { - CoreExtensions.postActions with PostAction { querySingle { kotlinAnalysis }.close() } + CoreExtensions.postActions providing { context -> + PostAction { + querySingle { kotlinAnalysis }.close() + if (context.configuration.finalizeCoroutines) + // TODO #3936(https://youtrack.jetbrains.com/issue/KT-71862) use an endpoint from AA + javaAnalysisPlugin.disposeGlobalStandaloneApplicationServices() + } + } } internal val symbolToDocumentableTranslator by extending { diff --git a/dokka-subprojects/core/src/main/kotlin/org/jetbrains/dokka/configuration.kt b/dokka-subprojects/core/src/main/kotlin/org/jetbrains/dokka/configuration.kt index d510e47a8b..f5a18adf0e 100644 --- a/dokka-subprojects/core/src/main/kotlin/org/jetbrains/dokka/configuration.kt +++ b/dokka-subprojects/core/src/main/kotlin/org/jetbrains/dokka/configuration.kt @@ -147,17 +147,22 @@ public interface DokkaConfiguration : Serializable { /** * Whether coroutines dispatchers should be shutdown after * generating documentation via [DokkaGenerator.generate]. + * Additionally, whether the Analysis API and IJ platform global + * services should be shutdown. * - * It effectively stops all background threads associated with + * If this is enabled, Coroutines *and* the Analysis API *and* IntelliJ + * platform classes should no longer be used after the documentation is generated once. + * + * For example, it effectively stops all background threads associated with * coroutines in order to make classes unloadable by the JVM, * and rejects all new tasks with [RejectedExecutionException] * - * This is primarily useful for multi-module builds where coroutines + * This is primarily useful for multi-module builds where global services * can be shut down after each module's partial task to avoid * possible memory leaks. * * However, this can lead to problems in specific lifecycles where - * coroutines are shared and will be reused after documentation generation, + * global services are shared and will be reused after documentation generation, * and closing it down will leave the build in an inoperable state. * One such example is unit tests, for which finalization should be disabled. */ diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index ce00053816..e43721de71 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -16,7 +16,7 @@ javaDiffUtils = "4.12" ## Analysis kotlin-compiler = "2.0.20" -kotlin-compiler-k2 = "2.1.0-dev-5441" +kotlin-compiler-k2 = "2.1.20-dev-4370" # MUST match the version of the intellij platform used in the kotlin compiler, # otherwise this will lead to different versions of psi API and implementations