Skip to content

Commit

Permalink
Merge pull request #20 from Anamorphosee/dev
Browse files Browse the repository at this point in the history
release 2.3.5
  • Loading branch information
Anamorphosee authored Dec 7, 2022
2 parents 90abdf5 + a761e04 commit 14e21b3
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 27 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ Thus, if the coroutine throws an exception, they mimic the real call stack of th

### JVM
There are three ways to enable Stacktrace-decoroutinator for JVM.
1. (recommended) Add dependency `dev.reformator.stacktracedecoroutinator:stacktrace-decoroutinator-jvm:2.3.4` and call method `DecoroutinatorRuntime.load()`.
2. Add `-javaagent:stacktrace-decoroutinator-jvm-agent-2.3.4.jar` to your JVM start arguments. Corresponding dependency is `dev.reformator.stacktracedecoroutinator:stacktrace-decoroutinator-jvm-agent:2.3.4`.
3. (less recommended) Add dependency `dev.reformator.stacktracedecoroutinator:stacktrace-decoroutinator-jvm-legacy:2.3.4` and call method `DecoroutinatorRuntime.load()`. This way doesn't use Java instrumentation API unlike the way number 1.
1. (recommended) Add dependency `dev.reformator.stacktracedecoroutinator:stacktrace-decoroutinator-jvm:2.3.5` and call method `DecoroutinatorRuntime.load()`.
2. Add `-javaagent:stacktrace-decoroutinator-jvm-agent-2.3.5.jar` to your JVM start arguments. Corresponding dependency is `dev.reformator.stacktracedecoroutinator:stacktrace-decoroutinator-jvm-agent:2.3.5`.
3. (less recommended) Add dependency `dev.reformator.stacktracedecoroutinator:stacktrace-decoroutinator-jvm-legacy:2.3.5` and call method `DecoroutinatorRuntime.load()`. This way doesn't use Java instrumentation API unlike the way number 1.

Usage example:
```kotlin
Expand Down Expand Up @@ -152,7 +152,7 @@ java.lang.Exception: exception at 1653565535416
```

### Android
To enable Stacktrace-decoroutinator for Android you should add dependency `dev.reformator.stacktracedecoroutinator:stacktrace-decoroutinator-android:2.3.4` in your Android application and call method `DecoroutinatorRuntime.load()` before creating any coroutines.
To enable Stacktrace-decoroutinator for Android you should add dependency `dev.reformator.stacktracedecoroutinator:stacktrace-decoroutinator-android:2.3.5` in your Android application and call method `DecoroutinatorRuntime.load()` before creating any coroutines.

It's recomended to add `DecoroutinatorRuntime.load()` call in your `Application.onCreate()` method. Example:
```kotlin
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ buildscript {

subprojects {
group = "dev.reformator.stacktracedecoroutinator"
version = "2.3.4"
version = "2.3.5"
}
Original file line number Diff line number Diff line change
Expand Up @@ -145,26 +145,15 @@ private fun MethodNode.getDebugMetadataInfo(): DebugMetadataInfo? {
.forEach { continuationIndex += it.size }
continuationIndex
}
val firstInstructions: List<AbstractInsnNode> = instructions.asSequence()
.filter { it.opcode != -1 && it.opcode != Opcodes.NOP }
.take(2)
.toList()
if (firstInstructions.size == 2) {
val isAloadContinuation = firstInstructions[0].let {
it is VarInsnNode && it.opcode == Opcodes.ALOAD && it.`var` == continuationIndex
return instructions.asSequence().filter {
val next = it.next
it is VarInsnNode && it.opcode == Opcodes.ALOAD && it.`var` == continuationIndex
&& next != null && next is TypeInsnNode && next.opcode == Opcodes.INSTANCEOF
}
val continuationClassName = firstInstructions[1].let {
if (it is TypeInsnNode && it.opcode == Opcodes.INSTANCEOF) {
it.desc.replace('/', '.')
} else {
null
}
.firstOrNull()?.let {
val continuationClassName = (it.next as TypeInsnNode).desc.replace('/', '.')
decoroutinatorJvmAgentRegistry.metadataInfoResolver.getDebugMetadataInfo(continuationClassName)
}
if (isAloadContinuation && continuationClassName != null) {
return decoroutinatorJvmAgentRegistry.metadataInfoResolver.getDebugMetadataInfo(continuationClassName)
}
}
return null
}

private val MethodNode.hasCode: Boolean
Expand Down
4 changes: 4 additions & 0 deletions stacktrace-decoroutinator-jvm/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ plugins {
kotlin("jvm")
`maven-publish`
signing
jacoco
}

repositories {
Expand All @@ -27,6 +28,9 @@ dependencies {

tasks.test {
useJUnitPlatform()
extensions.configure(JacocoTaskExtension::class) {
includes = listOf("dev.reformator.stacktracedecoroutinator.runtime.JacocoInstrumentedMethodTest*")
}
}

tasks.withType<KotlinCompile> {
Expand Down
28 changes: 24 additions & 4 deletions stacktrace-decoroutinator-jvm/src/test/kotlin/runtime-test-jvm.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,11 @@ import dev.reformator.stacktracedecoroutinator.common.isDecoroutinatorBaseContin
import dev.reformator.stacktracedecoroutinator.jvmagentcommon.DecoroutinatorJvmAgentDebugMetadataInfoResolveStrategy
import dev.reformator.stacktracedecoroutinator.utils.checkStacktrace
import dev.reformator.stacktracedecoroutinator.utils.getLineNumber
import kotlinx.coroutines.delay
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.transform
import kotlinx.coroutines.future.await
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.suspendCancellableCoroutine
import java.util.concurrent.CompletableFuture
import java.util.concurrent.ForkJoinPool
import java.util.concurrent.atomic.AtomicReference
Expand All @@ -26,6 +23,29 @@ private const val FILE_NAME = "runtime-test-jvm.kt"

class TestException(message: String): Exception(message)

// Jacoco only instruments this class
class JacocoInstrumentedMethodTest {
@BeforeTest
fun setup() {
System.setProperty(
"dev.reformator.stacktracedecoroutinator.jvmAgentDebugMetadataInfoResolveStrategy",
DecoroutinatorJvmAgentDebugMetadataInfoResolveStrategy.SYSTEM_RESOURCE.name
)
DecoroutinatorRuntime.load()
}

//@Disabled
@Test
fun jacocoInstrumentedMethodTest(): Unit = runBlocking {
suspend fun jacocoInstrumentedMethod() {
yield()
yield()
}

jacocoInstrumentedMethod()
}
}

class ReloadBaseContinuationTest {
@Test
fun reloadBaseContinuation() {
Expand Down

0 comments on commit 14e21b3

Please sign in to comment.