From 9feb834d97155e499ba03dbffffccc33159aa65d Mon Sep 17 00:00:00 2001 From: Yan Zhulanow Date: Tue, 6 Nov 2018 15:35:38 +0900 Subject: [PATCH] Kapt: Support paranoid mode in memory leak searcher --- .../src/org/jetbrains/kotlin/utils/kapt/MemoryLeakDetector.kt | 4 ++-- .../src/org/jetbrains/kotlin/kapt3/Kapt3Extension.kt | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/compiler/util/src/org/jetbrains/kotlin/utils/kapt/MemoryLeakDetector.kt b/compiler/util/src/org/jetbrains/kotlin/utils/kapt/MemoryLeakDetector.kt index e7437f331b4..f549394cacb 100644 --- a/compiler/util/src/org/jetbrains/kotlin/utils/kapt/MemoryLeakDetector.kt +++ b/compiler/util/src/org/jetbrains/kotlin/utils/kapt/MemoryLeakDetector.kt @@ -51,7 +51,7 @@ object MemoryLeakDetector { } } - fun process(): Set { + fun process(isParanoid: Boolean): Set { val memoryLeaks = mutableSetOf() synchronized(classLoaderData) { @@ -60,7 +60,7 @@ object MemoryLeakDetector { val classLoader = data.ref.get() ?: continue data.age += 1 - if (data.age >= 5) { + if (isParanoid || data.age >= 5) { // Inspect statics just once. // Note the 'data' is not added to 'nextClassLoaderData' used the next time. inspectStatics(classLoader) diff --git a/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/Kapt3Extension.kt b/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/Kapt3Extension.kt index 5ba95571f1f..75884465025 100644 --- a/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/Kapt3Extension.kt +++ b/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/Kapt3Extension.kt @@ -228,7 +228,8 @@ abstract class AbstractKapt3Extension( if (options.detectMemoryLeaks != DetectMemoryLeaksMode.NONE) { MemoryLeakDetector.add(processors.classLoader) - val (leakDetectionTime, leaks) = measureTimeMillis { MemoryLeakDetector.process() } + val isParanoid = options.detectMemoryLeaks == DetectMemoryLeaksMode.PARANOID + val (leakDetectionTime, leaks) = measureTimeMillis { MemoryLeakDetector.process(isParanoid) } logger.info { "Leak detection took $leakDetectionTime ms" } for (leak in leaks) {