Patch ThreadTracker during Kotlin plugin init
This commit is contained in:
@@ -95,9 +95,7 @@ fun doKotlinTearDown(project: Project, runnable: RunnableWithException) {
|
||||
|
||||
fun doKotlinTearDown(project: Project, runnable: () -> Unit) {
|
||||
unInvalidateBuiltinsAndStdLib(project) {
|
||||
patchThreadTracker {
|
||||
runnable()
|
||||
}
|
||||
runnable()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,55 +146,4 @@ fun Document.extractMarkerOffset(project: Project, caretMarker: String = "<caret
|
||||
PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(this)
|
||||
|
||||
return offset
|
||||
}
|
||||
|
||||
private val patched = AtomicBoolean(false)
|
||||
|
||||
fun patchThreadTracker(runnable: RunnableWithException) {
|
||||
patchThreadTracker {
|
||||
runnable.run()
|
||||
}
|
||||
}
|
||||
|
||||
fun patchThreadTracker(runnable: () -> Unit) {
|
||||
fun patch() {
|
||||
if (patched.get()) return
|
||||
|
||||
patched.compareAndSet(false, true)
|
||||
|
||||
IdeaForkJoinWorkerThreadFactory.setupForkJoinCommonPool()
|
||||
|
||||
// Check setup was successful
|
||||
val commonPoolFactoryName = ForkJoinPool.commonPool().factory.javaClass.name
|
||||
if (commonPoolFactoryName == IdeaForkJoinWorkerThreadFactory::class.java.name) {
|
||||
return
|
||||
}
|
||||
|
||||
println("Patching!")
|
||||
|
||||
try {
|
||||
val wellKnownOffendersField = try {
|
||||
ThreadTracker::class.java.getDeclaredField("wellKnownOffenders")
|
||||
}
|
||||
catch (communityPropertyNotFoundEx: NoSuchFieldException) {
|
||||
ThreadTracker::class.java.getDeclaredField("a")
|
||||
}
|
||||
|
||||
wellKnownOffendersField.isAccessible = true
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val wellKnownOffenders = wellKnownOffendersField.get(null) as MutableSet<String>
|
||||
|
||||
wellKnownOffenders.add("ForkJoinPool.commonPool-worker-")
|
||||
}
|
||||
catch (e: NoSuchFieldException) {
|
||||
println("Patching failed: " + e)
|
||||
}
|
||||
catch (e: IllegalAccessException) {
|
||||
println("Patching failed: " + e)
|
||||
}
|
||||
}
|
||||
|
||||
patch()
|
||||
runnable()
|
||||
}
|
||||
Reference in New Issue
Block a user