-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix 'kotlinx.coroutines.debug' split package problem (#4247)
* kotlinx-coroutines-debug: Fix split-package with the -core module - `kotlinx.coroutines.debug.internal` owned by coroutines-core - `kotlinx.coroutines.debug` owned by coroutines-debug (Which also reflects the nature of the debug module, which exposes _some_ public API from the .debug.internal package) This requires moving: - AgentPremain -> .debug.internal - ByteBuddyDynamicAttach -> .debug - NoOpProbes.kt -> .debug * kotlinx-coroutines-debug: Soften requirements on bytebuddy & junit As those dependencies are not *required* to be available at runtime - bytebuddy: Is shadowed and packaged into the -debug.jar - junit: Is optional * AgentInstallationType: Mark as @PublishedApi, as we want to keep the API stable ... as it has known usages in products which we do not want to break
- Loading branch information
Showing
20 changed files
with
141 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.kotlin | ||
kotlin-js-store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
@file:Suppress("PropertyName") | ||
plugins { | ||
kotlin("jvm") | ||
} | ||
|
||
val coroutines_version: String by project | ||
|
||
repositories { | ||
if (project.properties["build_snapshot_train"]?.toString()?.toBoolean() == true) { | ||
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev") | ||
} | ||
mavenLocal() | ||
mavenCentral() | ||
} | ||
|
||
java { | ||
modularity.inferModulePath.set(true) | ||
} | ||
|
||
kotlin { | ||
jvmToolchain(17) | ||
|
||
val test = target.compilations.getByName("test") | ||
target.compilations.create("debugDynamicAgentJpmsTest") { | ||
associateWith(test) | ||
|
||
|
||
defaultSourceSet.dependencies { | ||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version") | ||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-debug:$coroutines_version") | ||
} | ||
|
||
tasks.register<Test>("debugDynamicAgentJpmsTest") { | ||
testClassesDirs = output.classesDirs | ||
classpath = javaSourceSet.runtimeClasspath | ||
} | ||
} | ||
} | ||
|
||
tasks.named("check") { | ||
dependsOn(tasks.withType<Test>()) | ||
} | ||
|
||
dependencies { | ||
testImplementation(kotlin("test-junit")) | ||
} | ||
|
7 changes: 7 additions & 0 deletions
7
integration-testing/jpmsTest/src/debugDynamicAgentJpmsTest/java/module-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module debug.dynamic.agent.jpms.test { | ||
requires kotlin.stdlib; | ||
requires kotlinx.coroutines.core; | ||
requires kotlinx.coroutines.debug; | ||
requires junit; | ||
requires kotlin.test; | ||
} |
54 changes: 54 additions & 0 deletions
54
...ation-testing/jpmsTest/src/debugDynamicAgentJpmsTest/kotlin/DynamicAttachDebugJpmsTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
@file:OptIn(ExperimentalCoroutinesApi::class) | ||
|
||
import org.junit.* | ||
import kotlinx.coroutines.* | ||
import kotlinx.coroutines.debug.* | ||
import org.junit.Ignore | ||
import org.junit.Test | ||
import java.io.* | ||
import java.lang.IllegalStateException | ||
import kotlin.test.* | ||
|
||
class DynamicAttachDebugJpmsTest { | ||
|
||
/** | ||
* This test is disabled because: | ||
* Dynamic Attach with JPMS is not yet supported. | ||
* | ||
* Here is the state of experiments: | ||
* When launching this test with additional workarounds like | ||
* ``` | ||
* jvmArgs("--add-exports=kotlinx.coroutines.debug/kotlinx.coroutines.repackaged.net.bytebuddy=com.sun.jna") | ||
* jvmArgs("--add-exports=kotlinx.coroutines.debug/kotlinx.coroutines.repackaged.net.bytebuddy.agent=com.sun.jna") | ||
*``` | ||
* | ||
* Then we see issues like | ||
* | ||
* ``` | ||
* Caused by: java.lang.IllegalStateException: The Byte Buddy agent is not loaded or this method is not called via the system class loader | ||
* at kotlinx.coroutines.debug/kotlinx.coroutines.repackaged.net.bytebuddy.agent.Installer.getInstrumentation(Installer.java:61) | ||
* ... 54 more | ||
* ``` | ||
*/ | ||
@Ignore("shaded byte-buddy does not work with JPMS") | ||
@Test | ||
fun testAgentDumpsCoroutines() = | ||
DebugProbes.withDebugProbes { | ||
runBlocking { | ||
val baos = ByteArrayOutputStream() | ||
DebugProbes.dumpCoroutines(PrintStream(baos)) | ||
// if the agent works, then dumps should contain something, | ||
// at least the fact that this test is running. | ||
Assert.assertTrue(baos.toString().contains("testAgentDumpsCoroutines")) | ||
} | ||
} | ||
|
||
@Test | ||
fun testAgentIsNotInstalled() { | ||
assertEquals(false, DebugProbes.isInstalled) | ||
assertFailsWith<IllegalStateException> { | ||
DebugProbes.dumpCoroutines(PrintStream(ByteArrayOutputStream())) | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
...utines-core/jvm/src/debug/AgentPremain.kt → ...re/jvm/src/debug/internal/AgentPremain.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...routines-debug/src/internal/NoOpProbes.kt → kotlinx-coroutines-debug/src/NoOpProbes.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters