Make fields representing variables in coroutines non-volatile
#KT-14636 Fixed
This commit is contained in:
+1
-1
@@ -281,7 +281,7 @@ class CoroutineTransformerMethodVisitor(
|
|||||||
val (type, maxIndex) = entry
|
val (type, maxIndex) = entry
|
||||||
for (index in 0..maxIndex) {
|
for (index in 0..maxIndex) {
|
||||||
classBuilder.newField(
|
classBuilder.newField(
|
||||||
JvmDeclarationOrigin.NO_ORIGIN, Opcodes.ACC_PRIVATE or Opcodes.ACC_VOLATILE,
|
JvmDeclarationOrigin.NO_ORIGIN, Opcodes.ACC_PRIVATE,
|
||||||
type.fieldNameForVar(index), type.descriptor, null, null)
|
type.fieldNameForVar(index), type.descriptor, null, null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
class Controller {
|
||||||
|
suspend fun suspendHere(x: Continuation<String>) {
|
||||||
|
x.resume("OK")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun builder(coroutine c: Controller.(String, Long) -> Continuation<Unit>) {
|
||||||
|
c(Controller(), "", 2L).resume(Unit)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
var result = ""
|
||||||
|
|
||||||
|
builder { x, y ->
|
||||||
|
val z = ""
|
||||||
|
val u = 1L
|
||||||
|
result = suspendHere()
|
||||||
|
|
||||||
|
result += z + u
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
@kotlin.Metadata
|
||||||
|
public final class Controller {
|
||||||
|
public method <init>(): void
|
||||||
|
public final method suspendHere(@org.jetbrains.annotations.NotNull p0: kotlin.coroutines.Continuation): void
|
||||||
|
}
|
||||||
|
|
||||||
|
@kotlin.Metadata
|
||||||
|
final class CoroutineFieldsKt$box$1 {
|
||||||
|
synthetic final field $result: kotlin.jvm.internal.Ref$ObjectRef
|
||||||
|
private field J$0: long
|
||||||
|
private field L$0: java.lang.Object
|
||||||
|
private field L$1: java.lang.Object
|
||||||
|
private final field p$0: java.lang.String
|
||||||
|
private final field p$1: long
|
||||||
|
inner class CoroutineFieldsKt$box$1
|
||||||
|
method <init>(p0: kotlin.jvm.internal.Ref$ObjectRef): void
|
||||||
|
protected final method doResume(@org.jetbrains.annotations.Nullable p0: java.lang.Object, @org.jetbrains.annotations.Nullable p1: java.lang.Throwable): void
|
||||||
|
public final @org.jetbrains.annotations.NotNull method invoke(@org.jetbrains.annotations.NotNull p0: Controller, @org.jetbrains.annotations.NotNull p1: java.lang.String, p2: long): kotlin.coroutines.Continuation
|
||||||
|
public synthetic method invoke(p0: java.lang.Object, p1: java.lang.Object, p2: java.lang.Object): java.lang.Object
|
||||||
|
}
|
||||||
|
|
||||||
|
@kotlin.Metadata
|
||||||
|
public final class CoroutineFieldsKt {
|
||||||
|
inner class CoroutineFieldsKt$box$1
|
||||||
|
public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String
|
||||||
|
public final static method builder(@org.jetbrains.annotations.NotNull p0: kotlin.jvm.functions.Function3): void
|
||||||
|
}
|
||||||
@@ -140,8 +140,10 @@ abstract class AbstractBytecodeListingTest : CodegenTestCase() {
|
|||||||
|
|
||||||
override fun visitField(access: Int, name: String, desc: String, signature: String?, value: Any?): FieldVisitor? {
|
override fun visitField(access: Int, name: String, desc: String, signature: String?, value: Any?): FieldVisitor? {
|
||||||
val type = Type.getType(desc).className
|
val type = Type.getType(desc).className
|
||||||
declarationsInsideClass.add(Declaration("field $name: $type"))
|
val fieldDeclaration = Declaration("field $name: $type")
|
||||||
|
declarationsInsideClass.add(fieldDeclaration)
|
||||||
handleModifiers(access)
|
handleModifiers(access)
|
||||||
|
if (access and ACC_VOLATILE != 0) addModifier("volatile", fieldDeclaration.annotations)
|
||||||
|
|
||||||
return object : FieldVisitor(ASM5) {
|
return object : FieldVisitor(ASM5) {
|
||||||
override fun visitAnnotation(desc: String, visible: Boolean): AnnotationVisitor? {
|
override fun visitAnnotation(desc: String, visible: Boolean): AnnotationVisitor? {
|
||||||
|
|||||||
@@ -41,6 +41,12 @@ public class BytecodeListingTestGenerated extends AbstractBytecodeListingTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("coroutineFields.kt")
|
||||||
|
public void testCoroutineFields() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeListing/coroutineFields.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("defaultImpls.kt")
|
@TestMetadata("defaultImpls.kt")
|
||||||
public void testDefaultImpls() throws Exception {
|
public void testDefaultImpls() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeListing/defaultImpls.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeListing/defaultImpls.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user