[atomicfu-JVM] Preparation for commonization of JVM and K/N transformers
The following updates in the JVM/IR plugin were made: * Lots of refactoring with preparation for K/N support: commonization of transformations. * Improved error handling (checks for visibility constraints, appending message about usage constraints in case of an error). * Explicit requirements for the visibility of atomic properties: to prevent leaking they should be private/internal or be members of private/internal classes. * Fixed visibility of generated properties: volatile properties are always private and atomic updaters have the same visibility as the original atomic property. * Volatile fields are generated from scratch and original atomic properties are removed. * Delegated properties support is fixed (only declaration in the same scope is allowed). * Non-inline atomic extensions are forbidden. * For top-level atomics: only one wrapper class per file (with corresponding visibility) is generated. * Bug fixes. The corresponding tickets: https://github.com/Kotlin/kotlinx-atomicfu/issues/322 KT-60528 Merge-request: KT-MR-10579 Merged-by: Maria Sokolova <maria.sokolova@jetbrains.com>
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
import kotlinx.atomicfu.*
|
||||
import kotlin.test.*
|
||||
|
||||
class TraceTest {
|
||||
private val defaultTrace = Trace()
|
||||
private val a1 = atomic(5, defaultTrace)
|
||||
|
||||
private val traceWithSize = Trace(30)
|
||||
private val a2 = atomic(1, traceWithSize)
|
||||
|
||||
private val traceWithFormat = Trace(format = TraceFormat { i, text -> "[$i: $text]" })
|
||||
private val a = atomic(0, traceWithFormat)
|
||||
|
||||
private val traceWithSizeAndFormat = Trace(30, TraceFormat { id, text -> "$id: $text"})
|
||||
private val a3 = atomic(2)
|
||||
|
||||
private val shortTrace = Trace(4)
|
||||
private val s = atomic(0, shortTrace.named("s"))
|
||||
|
||||
fun testDefaultTrace() {
|
||||
val oldValue = a1.value
|
||||
defaultTrace { "before CAS value = $oldValue" }
|
||||
val res = a1.compareAndSet(oldValue, oldValue * 10)
|
||||
val newValue = a1.value
|
||||
defaultTrace { "after CAS value = $newValue" }
|
||||
}
|
||||
|
||||
fun testTraceWithSize() {
|
||||
val oldValue = a2.value
|
||||
traceWithSize { "before CAS value = $oldValue" }
|
||||
assertTrue(a2.compareAndSet(oldValue, oldValue * 10))
|
||||
traceWithSize { "after CAS value = ${a2.value}" }
|
||||
traceWithSize { "before getAndDecrement value = ${a2.value}" }
|
||||
a2.getAndDecrement()
|
||||
assertEquals(9, a2.value)
|
||||
traceWithSize { "after getAndDecrement value = ${a2.value}" }
|
||||
}
|
||||
|
||||
fun testTraceWithFormat() {
|
||||
val oldValue = a3.value
|
||||
traceWithFormat { "before CAS value = $oldValue" }
|
||||
assertTrue(a3.compareAndSet(oldValue, oldValue * 10))
|
||||
traceWithFormat { "after CAS value = ${a3.value}" }
|
||||
traceWithFormat { "before getAndDecrement value = ${a3.value}" }
|
||||
a3.getAndDecrement()
|
||||
assertEquals(19, a3.value)
|
||||
traceWithFormat { "after getAndDecrement value = ${a3.value}" }
|
||||
}
|
||||
|
||||
fun testNamedTrace() {
|
||||
s.value = 5
|
||||
shortTrace { "before CAS value = ${s.value}" }
|
||||
s.compareAndSet(5, -2)
|
||||
assertEquals(-2, s.value)
|
||||
shortTrace { "after CAS value = ${s.value}" }
|
||||
}
|
||||
|
||||
private enum class Status { START, END }
|
||||
|
||||
fun testMultipleAppend() {
|
||||
val i = 1
|
||||
traceWithFormat.append(i, Status.START)
|
||||
assertEquals(0, a.value)
|
||||
a.incrementAndGet()
|
||||
traceWithFormat.append(i, a.value, "incAndGet")
|
||||
assertEquals(1, a.value)
|
||||
a.lazySet(10)
|
||||
traceWithFormat.append(i, a.value, "lazySet")
|
||||
assertEquals(10, a.value)
|
||||
traceWithFormat.append(i, Status.END)
|
||||
}
|
||||
|
||||
fun testTraceInBlock() {
|
||||
a1.lazySet(5)
|
||||
if (a1.value == 5) {
|
||||
defaultTrace { "Value checked" }
|
||||
if (a1.compareAndSet(5, 10)) {
|
||||
defaultTrace { "CAS succeeded" }
|
||||
}
|
||||
}
|
||||
assertEquals(10, a1.value)
|
||||
while (true) {
|
||||
if (a1.value == 10) {
|
||||
defaultTrace.append("Value checked", a1.value)
|
||||
a1.value = 15
|
||||
break
|
||||
} else {
|
||||
defaultTrace.append("Wrong value", a1.value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun test() {
|
||||
testDefaultTrace()
|
||||
testTraceWithSize()
|
||||
testTraceWithFormat()
|
||||
testNamedTrace()
|
||||
testMultipleAppend()
|
||||
testTraceInBlock()
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
TraceTest().test()
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
@kotlin.Metadata
|
||||
final enum class TraceTest$Status {
|
||||
// source: 'TraceTest.kt'
|
||||
private synthetic final static field $ENTRIES: kotlin.enums.EnumEntries
|
||||
private synthetic final static field $VALUES: TraceTest$Status[]
|
||||
public final enum static field END: TraceTest$Status
|
||||
public final enum static field START: TraceTest$Status
|
||||
private synthetic final static method $values(): TraceTest$Status[]
|
||||
static method <clinit>(): void
|
||||
private method <init>(p0: java.lang.String, p1: int): void
|
||||
public static @org.jetbrains.annotations.NotNull method getEntries(): kotlin.enums.EnumEntries
|
||||
public static method valueOf(p0: java.lang.String): TraceTest$Status
|
||||
public static method values(): TraceTest$Status[]
|
||||
private final inner class TraceTest$Status
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
public final class TraceTest {
|
||||
// source: 'TraceTest.kt'
|
||||
private synthetic final static field a$volatile$FU: java.util.concurrent.atomic.AtomicIntegerFieldUpdater
|
||||
private synthetic volatile field a$volatile: int
|
||||
private synthetic final static field a1$volatile$FU: java.util.concurrent.atomic.AtomicIntegerFieldUpdater
|
||||
private synthetic volatile field a1$volatile: int
|
||||
private synthetic final static field a2$volatile$FU: java.util.concurrent.atomic.AtomicIntegerFieldUpdater
|
||||
private synthetic volatile field a2$volatile: int
|
||||
private synthetic final static field a3$volatile$FU: java.util.concurrent.atomic.AtomicIntegerFieldUpdater
|
||||
private synthetic volatile field a3$volatile: int
|
||||
private synthetic final static field s$volatile$FU: java.util.concurrent.atomic.AtomicIntegerFieldUpdater
|
||||
private synthetic volatile field s$volatile: int
|
||||
static method <clinit>(): void
|
||||
public method <init>(): void
|
||||
private synthetic final static method getA$volatile$FU(): java.util.concurrent.atomic.AtomicIntegerFieldUpdater
|
||||
private synthetic final method getA$volatile(): int
|
||||
private synthetic final static method getA1$volatile$FU(): java.util.concurrent.atomic.AtomicIntegerFieldUpdater
|
||||
private synthetic final method getA1$volatile(): int
|
||||
private synthetic final static method getA2$volatile$FU(): java.util.concurrent.atomic.AtomicIntegerFieldUpdater
|
||||
private synthetic final method getA2$volatile(): int
|
||||
private synthetic final static method getA3$volatile$FU(): java.util.concurrent.atomic.AtomicIntegerFieldUpdater
|
||||
private synthetic final method getA3$volatile(): int
|
||||
private synthetic final static method getS$volatile$FU(): java.util.concurrent.atomic.AtomicIntegerFieldUpdater
|
||||
private synthetic final method getS$volatile(): int
|
||||
private synthetic final method setA$volatile(p0: int): void
|
||||
private synthetic final method setA1$volatile(p0: int): void
|
||||
private synthetic final method setA2$volatile(p0: int): void
|
||||
private synthetic final method setA3$volatile(p0: int): void
|
||||
private synthetic final method setS$volatile(p0: int): void
|
||||
public final method test(): void
|
||||
public final method testDefaultTrace(): void
|
||||
public final method testMultipleAppend(): void
|
||||
public final method testNamedTrace(): void
|
||||
public final method testTraceInBlock(): void
|
||||
public final method testTraceWithFormat(): void
|
||||
public final method testTraceWithSize(): void
|
||||
private final inner class TraceTest$Status
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
public final class TraceTestKt {
|
||||
// source: 'TraceTest.kt'
|
||||
public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String
|
||||
}
|
||||
Reference in New Issue
Block a user