diff options
author | Vadim Mishenev <vad-mishenev@yandex.ru> | 2022-11-26 01:11:53 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-26 01:11:53 +0200 |
commit | 9ed17b64f0dd071afaa4f2e9c507937c4e9571d2 (patch) | |
tree | f218bedc28f66e1f7d803eae99c0ed1d5ac5cb84 /plugins/base/src/main/kotlin | |
parent | dc1f9d20f599ca8f9311b779645bc5e53784ca92 (diff) | |
download | dokka-9ed17b64f0dd071afaa4f2e9c507937c4e9571d2.tar.gz dokka-9ed17b64f0dd071afaa4f2e9c507937c4e9571d2.tar.bz2 dokka-9ed17b64f0dd071afaa4f2e9c507937c4e9571d2.zip |
Fix OOME: Metaspace (#2678)
* Fix OOME: Metaspace
* Add stress test
* Run sample analysis from `Dispatchers.Default`
Diffstat (limited to 'plugins/base/src/main/kotlin')
-rw-r--r-- | plugins/base/src/main/kotlin/transformers/pages/samples/SamplesTransformer.kt | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/plugins/base/src/main/kotlin/transformers/pages/samples/SamplesTransformer.kt b/plugins/base/src/main/kotlin/transformers/pages/samples/SamplesTransformer.kt index 9c78972a..ed4c4792 100644 --- a/plugins/base/src/main/kotlin/transformers/pages/samples/SamplesTransformer.kt +++ b/plugins/base/src/main/kotlin/transformers/pages/samples/SamplesTransformer.kt @@ -1,6 +1,8 @@ package org.jetbrains.dokka.base.transformers.pages.samples import com.intellij.psi.PsiElement +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.runBlocking import org.jetbrains.dokka.DokkaConfiguration.DokkaSourceSet import org.jetbrains.dokka.Platform import org.jetbrains.dokka.analysis.AnalysisEnvironment @@ -22,33 +24,37 @@ import org.jetbrains.kotlin.idea.kdoc.resolveKDocLink import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils -import org.jetbrains.kotlin.utils.PathUtil +internal const val KOTLIN_PLAYGROUND_SCRIPT = "<script src=\"https://unpkg.com/kotlin-playground@1\"></script>" abstract class SamplesTransformer(val context: DokkaContext) : PageTransformer { abstract fun processBody(psiElement: PsiElement): String abstract fun processImports(psiElement: PsiElement): String - final override fun invoke(input: RootPageNode): RootPageNode { - val analysis = setUpAnalysis(context) - val kotlinPlaygroundScript = - "<script src=\"https://unpkg.com/kotlin-playground@1\"></script>" - - return input.transformContentPagesTree { page -> - val samples = (page as? WithDocumentables)?.documentables?.flatMap { - it.documentation.entries.flatMap { entry -> - entry.value.children.filterIsInstance<Sample>().map { entry.key to it } + final override fun invoke(input: RootPageNode): RootPageNode = + /** + * Run from the thread of [Dispatchers.Default]. It can help to avoid a memory leaks in `ThreadLocal`s (that keep `URLCLassLoader`) + * since we shut down Dispatchers. Default at the end of each task (see [org.jetbrains.dokka.DokkaConfiguration.finalizeCoroutines]). + * Currently, all `ThreadLocal`s are in a compiler/IDE codebase. + */ + runBlocking(Dispatchers.Default) { + val analysis = setUpAnalysis(context) + + input.transformContentPagesTree { page -> + val samples = (page as? WithDocumentables)?.documentables?.flatMap { + it.documentation.entries.flatMap { entry -> + entry.value.children.filterIsInstance<Sample>().map { entry.key to it } + } } - } - samples?.fold(page as ContentPage) { acc, (sampleSourceSet, sample) -> + samples?.fold(page as ContentPage) { acc, (sampleSourceSet, sample) -> acc.modified( content = acc.content.addSample(page, sampleSourceSet, sample.name, analysis), - embeddedResources = acc.embeddedResources + kotlinPlaygroundScript + embeddedResources = acc.embeddedResources + KOTLIN_PLAYGROUND_SCRIPT ) } ?: page + } } - } private fun setUpAnalysis(context: DokkaContext) = context.configuration.sourceSets.associateWith { sourceSet -> if (sourceSet.samples.isEmpty()) context.plugin<DokkaBase>() |