Skip to content

Commit 9b1de90

Browse files
committed
Cache async-profiler when using -Xprofile
1 parent bea82ba commit 9b1de90

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

compiler/cli/src/org/jetbrains/kotlin/cli/common/profiling/AsyncProfilerWrapper.kt

+8-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,14 @@ interface AsyncProfilerReflected {
1717
}
1818

1919
object AsyncProfilerHelper {
20+
private var instance: AsyncProfilerReflected? = null
21+
2022
fun getInstance(libPath: String?): AsyncProfilerReflected {
23+
// JVM doesn't support loading a native library multiple times even in different class loaders, so we don't attempt to load
24+
// async-profiler again after the first use, which allows to profile the same compiler process multiple times,
25+
// for example in the compiler daemon scenario.
26+
instance?.let { return it }
27+
2128
val profilerClass = loadAsyncProfilerClass(libPath)
2229
val getInstanceHandle =
2330
MethodHandles.lookup().findStatic(profilerClass, "getInstance", MethodType.methodType(profilerClass, String::class.java))
@@ -49,7 +56,7 @@ object AsyncProfilerHelper {
4956
override val version: String
5057
get() = boundGetVersion.invokeWithArguments() as String
5158

52-
}
59+
}.also { this.instance = it }
5360
}
5461

5562
private fun loadAsyncProfilerClass(libPath: String?): Class<*> {

0 commit comments

Comments
 (0)