From 9bb0e84b0cb5faa35f0424fbb828cdd2b6be0fc0 Mon Sep 17 00:00:00 2001 From: mvicsokolova Date: Tue, 25 Oct 2022 16:37:01 +0200 Subject: [PATCH 1/7] Update atomicfu to 0.18.5, apply JVM IR plugin --- gradle.properties | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gradle.properties b/gradle.properties index dd4a4ac685..2adbab5a43 100644 --- a/gradle.properties +++ b/gradle.properties @@ -10,7 +10,7 @@ kotlin_version=1.7.20 # Dependencies junit_version=4.12 junit5_version=5.7.0 -atomicfu_version=0.18.4 +atomicfu_version=0.18.5 knit_version=0.4.0 html_version=0.7.2 lincheck_version=2.14.1 @@ -58,4 +58,5 @@ org.gradle.jvmargs=-Xmx3g kotlin.mpp.enableCompatibilityMetadataVariant=true kotlin.mpp.stability.nowarn=true -kotlinx.atomicfu.enableIrTransformation=true +kotlinx.atomicfu.enableJvmIrTransformation=true +kotlinx.atomicfu.enableJsIrTransformation=true From f9a56a7e9efe2bfb6950c6e45a1cf2612a32dbc2 Mon Sep 17 00:00:00 2001 From: SokolovaMaria Date: Mon, 7 Dec 2020 16:00:07 +0300 Subject: [PATCH 2/7] Atomicfu delegated properties --- .../api/kotlinx-coroutines-core.api | 2 +- kotlinx-coroutines-core/common/src/Await.kt | 4 +--- .../common/src/CancellableContinuationImpl.kt | 2 +- .../common/src/CompletionState.kt | 2 +- .../common/src/EventLoop.common.kt | 4 +--- kotlinx-coroutines-core/common/src/JobSupport.kt | 16 ++++------------ .../common/src/channels/ArrayBroadcastChannel.kt | 16 ++++------------ .../common/src/internal/Atomic.kt | 2 +- .../common/src/internal/ConcurrentLinkedList.kt | 4 ++-- .../channels/ChannelUndeliveredElementTest.kt | 3 +-- .../src/internal/LockFreeLinkedList.kt | 6 +++--- .../jvm/src/debug/internal/ConcurrentWeakMap.kt | 3 +-- .../jvm/src/scheduling/CoroutineScheduler.kt | 2 +- 13 files changed, 22 insertions(+), 44 deletions(-) diff --git a/kotlinx-coroutines-core/api/kotlinx-coroutines-core.api b/kotlinx-coroutines-core/api/kotlinx-coroutines-core.api index 3a2d08f428..6753492576 100644 --- a/kotlinx-coroutines-core/api/kotlinx-coroutines-core.api +++ b/kotlinx-coroutines-core/api/kotlinx-coroutines-core.api @@ -446,7 +446,6 @@ public class kotlinx/coroutines/JobSupport : kotlinx/coroutines/ChildJob, kotlin public final fun getKey ()Lkotlin/coroutines/CoroutineContext$Key; protected final fun getOnAwaitInternal ()Lkotlinx/coroutines/selects/SelectClause1; public final fun getOnJoin ()Lkotlinx/coroutines/selects/SelectClause0; - public fun getParent ()Lkotlinx/coroutines/Job; protected fun handleJobException (Ljava/lang/Throwable;)Z protected final fun initParentJob (Lkotlinx/coroutines/Job;)V public final fun invokeOnCompletion (Lkotlin/jvm/functions/Function1;)Lkotlinx/coroutines/DisposableHandle; @@ -464,6 +463,7 @@ public class kotlinx/coroutines/JobSupport : kotlinx/coroutines/ChildJob, kotlin public final fun parentCancelled (Lkotlinx/coroutines/ParentJob;)V public fun plus (Lkotlin/coroutines/CoroutineContext;)Lkotlin/coroutines/CoroutineContext; public fun plus (Lkotlinx/coroutines/Job;)Lkotlinx/coroutines/Job; + public final fun registerSelectClause0 (Lkotlinx/coroutines/selects/SelectInstance;Lkotlin/jvm/functions/Function1;)V public final fun start ()Z protected final fun toCancellationException (Ljava/lang/Throwable;Ljava/lang/String;)Ljava/util/concurrent/CancellationException; public static synthetic fun toCancellationException$default (Lkotlinx/coroutines/JobSupport;Ljava/lang/Throwable;Ljava/lang/String;ILjava/lang/Object;)Ljava/util/concurrent/CancellationException; diff --git a/kotlinx-coroutines-core/common/src/Await.kt b/kotlinx-coroutines-core/common/src/Await.kt index c1669e2554..1f84d4f943 100644 --- a/kotlinx-coroutines-core/common/src/Await.kt +++ b/kotlinx-coroutines-core/common/src/Await.kt @@ -104,9 +104,7 @@ private class AwaitAll(private val deferreds: Array>) { lateinit var handle: DisposableHandle private val _disposer = atomic(null) - var disposer: DisposeHandlersOnCancel? - get() = _disposer.value - set(value) { _disposer.value = value } + var disposer: DisposeHandlersOnCancel? by _disposer override fun invoke(cause: Throwable?) { if (cause != null) { diff --git a/kotlinx-coroutines-core/common/src/CancellableContinuationImpl.kt b/kotlinx-coroutines-core/common/src/CancellableContinuationImpl.kt index ef49da23df..ca606d9b9b 100644 --- a/kotlinx-coroutines-core/common/src/CancellableContinuationImpl.kt +++ b/kotlinx-coroutines-core/common/src/CancellableContinuationImpl.kt @@ -93,7 +93,7 @@ internal open class CancellableContinuationImpl( private val parentHandle: DisposableHandle? get() = _parentHandle.value - internal val state: Any? get() = _state.value + internal val state: Any? by _state public override val isActive: Boolean get() = state is NotCompleted diff --git a/kotlinx-coroutines-core/common/src/CompletionState.kt b/kotlinx-coroutines-core/common/src/CompletionState.kt index 43330af460..6c0aa91fb7 100644 --- a/kotlinx-coroutines-core/common/src/CompletionState.kt +++ b/kotlinx-coroutines-core/common/src/CompletionState.kt @@ -44,7 +44,7 @@ internal open class CompletedExceptionally( handled: Boolean = false ) { private val _handled = atomic(handled) - val handled: Boolean get() = _handled.value + val handled: Boolean by _handled fun makeHandled(): Boolean = _handled.compareAndSet(false, true) override fun toString(): String = "$classSimpleName[$cause]" } diff --git a/kotlinx-coroutines-core/common/src/EventLoop.common.kt b/kotlinx-coroutines-core/common/src/EventLoop.common.kt index 5308120cc8..2e9cd0e621 100644 --- a/kotlinx-coroutines-core/common/src/EventLoop.common.kt +++ b/kotlinx-coroutines-core/common/src/EventLoop.common.kt @@ -185,9 +185,7 @@ internal abstract class EventLoopImplBase: EventLoopImplPlatform(), Delay { private val _delayed = atomic(null) private val _isCompleted = atomic(false) - private var isCompleted - get() = _isCompleted.value - set(value) { _isCompleted.value = value } + private var isCompleted: Boolean by _isCompleted override val isEmpty: Boolean get() { if (!isUnconfinedQueueEmpty) return false diff --git a/kotlinx-coroutines-core/common/src/JobSupport.kt b/kotlinx-coroutines-core/common/src/JobSupport.kt index 2950ed9814..55825f78b1 100644 --- a/kotlinx-coroutines-core/common/src/JobSupport.kt +++ b/kotlinx-coroutines-core/common/src/JobSupport.kt @@ -127,9 +127,7 @@ public open class JobSupport constructor(active: Boolean) : Job, ChildJob, Paren private val _state = atomic(if (active) EMPTY_ACTIVE else EMPTY_NEW) private val _parentHandle = atomic(null) - internal var parentHandle: ChildHandle? - get() = _parentHandle.value - set(value) { _parentHandle.value = value } + internal var parentHandle: ChildHandle? by _parentHandle override val parent: Job? get() = parentHandle?.parent @@ -1080,19 +1078,13 @@ public open class JobSupport constructor(active: Boolean) : Job, ChildJob, Paren rootCause: Throwable? ) : SynchronizedObject(), Incomplete { private val _isCompleting = atomic(isCompleting) - var isCompleting: Boolean - get() = _isCompleting.value - set(value) { _isCompleting.value = value } + var isCompleting: Boolean by _isCompleting private val _rootCause = atomic(rootCause) - var rootCause: Throwable? // NOTE: rootCause is kept even when SEALED - get() = _rootCause.value - set(value) { _rootCause.value = value } + var rootCause: Throwable? by _rootCause // NOTE: rootCause is kept even when SEALED private val _exceptionsHolder = atomic(null) - private var exceptionsHolder: Any? // Contains null | Throwable | ArrayList | SEALED - get() = _exceptionsHolder.value - set(value) { _exceptionsHolder.value = value } + private var exceptionsHolder: Any? by _exceptionsHolder // Contains null | Throwable | ArrayList | SEALED // Note: cannot be modified when sealed val isSealed: Boolean get() = exceptionsHolder === SEALED diff --git a/kotlinx-coroutines-core/common/src/channels/ArrayBroadcastChannel.kt b/kotlinx-coroutines-core/common/src/channels/ArrayBroadcastChannel.kt index a9aaf08a53..768063de55 100644 --- a/kotlinx-coroutines-core/common/src/channels/ArrayBroadcastChannel.kt +++ b/kotlinx-coroutines-core/common/src/channels/ArrayBroadcastChannel.kt @@ -51,19 +51,13 @@ internal class ArrayBroadcastChannel( // head, tail, and size are guarded by bufferLock private val _head = atomic(0L) - private var head: Long // do modulo on use of head - get() = _head.value - set(value) { _head.value = value } + private var head: Long by _head // do modulo on use of head private val _tail = atomic(0L) - private var tail: Long // do modulo on use of tail - get() = _tail.value - set(value) { _tail.value = value } + private var tail: Long by _tail // do modulo on use of tail private val _size = atomic(0) - private var size: Int - get() = _size.value - set(value) { _size.value = value } + private var size: Int by _size @Suppress("DEPRECATION") private val subscribers = subscriberList>() @@ -196,9 +190,7 @@ internal class ArrayBroadcastChannel( private val subLock = ReentrantLock() private val _subHead = atomic(0L) - var subHead: Long // guarded by subLock - get() = _subHead.value - set(value) { _subHead.value = value } + var subHead: Long by _subHead // guarded by subLock override val isBufferAlwaysEmpty: Boolean get() = false override val isBufferEmpty: Boolean get() = subHead >= broadcastChannel.tail diff --git a/kotlinx-coroutines-core/common/src/internal/Atomic.kt b/kotlinx-coroutines-core/common/src/internal/Atomic.kt index 127b70f7e8..9b9781afea 100644 --- a/kotlinx-coroutines-core/common/src/internal/Atomic.kt +++ b/kotlinx-coroutines-core/common/src/internal/Atomic.kt @@ -56,7 +56,7 @@ public abstract class AtomicOp : OpDescriptor() { private val _consensus = atomic(NO_DECISION) // Returns NO_DECISION when there is not decision yet - val consensus: Any? get() = _consensus.value + val consensus: Any? by _consensus val isDecided: Boolean get() = _consensus.value !== NO_DECISION diff --git a/kotlinx-coroutines-core/common/src/internal/ConcurrentLinkedList.kt b/kotlinx-coroutines-core/common/src/internal/ConcurrentLinkedList.kt index 5eee2bd59c..182aef61de 100644 --- a/kotlinx-coroutines-core/common/src/internal/ConcurrentLinkedList.kt +++ b/kotlinx-coroutines-core/common/src/internal/ConcurrentLinkedList.kt @@ -95,7 +95,7 @@ internal abstract class ConcurrentLinkedListNode // Pointer to the previous node, updates in [remove] function. private val _prev = atomic(prev) - private val nextOrClosed get() = _next.value + private val nextOrClosed: Any? by _next /** * Returns the next segment or `null` of the one does not exist, @@ -122,7 +122,7 @@ internal abstract class ConcurrentLinkedListNode */ val isTail: Boolean get() = next == null - val prev: N? get() = _prev.value + val prev: N? by _prev /** * Cleans the pointer to the previous node. diff --git a/kotlinx-coroutines-core/common/test/channels/ChannelUndeliveredElementTest.kt b/kotlinx-coroutines-core/common/test/channels/ChannelUndeliveredElementTest.kt index f26361f2f8..0bc8a5a818 100644 --- a/kotlinx-coroutines-core/common/test/channels/ChannelUndeliveredElementTest.kt +++ b/kotlinx-coroutines-core/common/test/channels/ChannelUndeliveredElementTest.kt @@ -116,8 +116,7 @@ class ChannelUndeliveredElementTest : TestBase() { private class Resource(val value: String) { private val _cancelled = atomic(false) - val isCancelled: Boolean - get() = _cancelled.value + val isCancelled: Boolean by _cancelled fun cancel() { check(!_cancelled.getAndSet(true)) { "Already cancelled" } diff --git a/kotlinx-coroutines-core/concurrent/src/internal/LockFreeLinkedList.kt b/kotlinx-coroutines-core/concurrent/src/internal/LockFreeLinkedList.kt index c9a1b61261..a99f492c22 100644 --- a/kotlinx-coroutines-core/concurrent/src/internal/LockFreeLinkedList.kt +++ b/kotlinx-coroutines-core/concurrent/src/internal/LockFreeLinkedList.kt @@ -322,7 +322,7 @@ public actual open class LockFreeLinkedListNode { queue.correctPrev(op) // queue head is never removed, so null result can only mean RETRY_ATOMIC private val _affectedNode = atomic(null) - final override val affectedNode: Node? get() = _affectedNode.value + final override val affectedNode: Node? by _affectedNode final override val originalNext: Node get() = queue override fun retry(affected: Node, next: Any): Boolean = next !== queue @@ -368,8 +368,8 @@ public actual open class LockFreeLinkedListNode { } } - final override val affectedNode: Node? get() = _affectedNode.value - final override val originalNext: Node? get() = _originalNext.value + final override val affectedNode: Node? by _affectedNode + final override val originalNext: Node? by _originalNext // check node predicates here, must signal failure if affect is not of type T protected override fun failure(affected: Node): Any? = diff --git a/kotlinx-coroutines-core/jvm/src/debug/internal/ConcurrentWeakMap.kt b/kotlinx-coroutines-core/jvm/src/debug/internal/ConcurrentWeakMap.kt index b02eac6397..87f1d09ec3 100644 --- a/kotlinx-coroutines-core/jvm/src/debug/internal/ConcurrentWeakMap.kt +++ b/kotlinx-coroutines-core/jvm/src/debug/internal/ConcurrentWeakMap.kt @@ -22,8 +22,7 @@ internal class ConcurrentWeakMap( private val core = atomic(Core(MIN_CAPACITY)) private val weakRefQueue: ReferenceQueue? = if (weakRefQueue) ReferenceQueue() else null - override val size: Int - get() = _size.value + override val size: Int by _size private fun decrementSize() { _size.decrementAndGet() } diff --git a/kotlinx-coroutines-core/jvm/src/scheduling/CoroutineScheduler.kt b/kotlinx-coroutines-core/jvm/src/scheduling/CoroutineScheduler.kt index e08d1cef90..558f3270a0 100644 --- a/kotlinx-coroutines-core/jvm/src/scheduling/CoroutineScheduler.kt +++ b/kotlinx-coroutines-core/jvm/src/scheduling/CoroutineScheduler.kt @@ -295,7 +295,7 @@ internal class CoroutineScheduler( // This is used a "stop signal" for close and shutdown functions private val _isTerminated = atomic(false) - val isTerminated: Boolean get() = _isTerminated.value + val isTerminated: Boolean by _isTerminated companion object { // A symbol to mark workers that are not in parkedWorkersStack From 193fc0fb3ab7d85601dac61747c384d9c1436355 Mon Sep 17 00:00:00 2001 From: mvicsokolova Date: Tue, 7 Jun 2022 15:46:41 +0300 Subject: [PATCH 3/7] AwaitAllNode disposer may be just a volatile property --- kotlinx-coroutines-core/common/src/Await.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/kotlinx-coroutines-core/common/src/Await.kt b/kotlinx-coroutines-core/common/src/Await.kt index 1f84d4f943..3f33298676 100644 --- a/kotlinx-coroutines-core/common/src/Await.kt +++ b/kotlinx-coroutines-core/common/src/Await.kt @@ -6,6 +6,7 @@ package kotlinx.coroutines import kotlinx.atomicfu.* import kotlin.coroutines.* +import kotlin.jvm.* /** * Awaits for completion of given deferred values without blocking a thread and resumes normally with the list of values @@ -103,8 +104,8 @@ private class AwaitAll(private val deferreds: Array>) { private inner class AwaitAllNode(private val continuation: CancellableContinuation>) : JobNode() { lateinit var handle: DisposableHandle - private val _disposer = atomic(null) - var disposer: DisposeHandlersOnCancel? by _disposer + @Volatile + var disposer: DisposeHandlersOnCancel? = null override fun invoke(cause: Throwable?) { if (cause != null) { From 4b456cc708ff86598e0dbc5591960182bf7b94de Mon Sep 17 00:00:00 2001 From: mvicsokolova Date: Tue, 1 Nov 2022 09:37:15 +0000 Subject: [PATCH 4/7] Turn off jsir transformation --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 2adbab5a43..406e68a63e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -59,4 +59,4 @@ org.gradle.jvmargs=-Xmx3g kotlin.mpp.enableCompatibilityMetadataVariant=true kotlin.mpp.stability.nowarn=true kotlinx.atomicfu.enableJvmIrTransformation=true -kotlinx.atomicfu.enableJsIrTransformation=true +kotlinx.atomicfu.enableJsIrTransformation=false From 575bb1d6a3631f27d0e7901d6f349bfb4e22cb69 Mon Sep 17 00:00:00 2001 From: mvicsokolova Date: Sun, 13 Nov 2022 22:25:02 +0100 Subject: [PATCH 5/7] Revert changes in apiDamp --- kotlinx-coroutines-core/api/kotlinx-coroutines-core.api | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kotlinx-coroutines-core/api/kotlinx-coroutines-core.api b/kotlinx-coroutines-core/api/kotlinx-coroutines-core.api index 6753492576..3a2d08f428 100644 --- a/kotlinx-coroutines-core/api/kotlinx-coroutines-core.api +++ b/kotlinx-coroutines-core/api/kotlinx-coroutines-core.api @@ -446,6 +446,7 @@ public class kotlinx/coroutines/JobSupport : kotlinx/coroutines/ChildJob, kotlin public final fun getKey ()Lkotlin/coroutines/CoroutineContext$Key; protected final fun getOnAwaitInternal ()Lkotlinx/coroutines/selects/SelectClause1; public final fun getOnJoin ()Lkotlinx/coroutines/selects/SelectClause0; + public fun getParent ()Lkotlinx/coroutines/Job; protected fun handleJobException (Ljava/lang/Throwable;)Z protected final fun initParentJob (Lkotlinx/coroutines/Job;)V public final fun invokeOnCompletion (Lkotlin/jvm/functions/Function1;)Lkotlinx/coroutines/DisposableHandle; @@ -463,7 +464,6 @@ public class kotlinx/coroutines/JobSupport : kotlinx/coroutines/ChildJob, kotlin public final fun parentCancelled (Lkotlinx/coroutines/ParentJob;)V public fun plus (Lkotlin/coroutines/CoroutineContext;)Lkotlin/coroutines/CoroutineContext; public fun plus (Lkotlinx/coroutines/Job;)Lkotlinx/coroutines/Job; - public final fun registerSelectClause0 (Lkotlinx/coroutines/selects/SelectInstance;Lkotlin/jvm/functions/Function1;)V public final fun start ()Z protected final fun toCancellationException (Ljava/lang/Throwable;Ljava/lang/String;)Ljava/util/concurrent/CancellationException; public static synthetic fun toCancellationException$default (Lkotlinx/coroutines/JobSupport;Ljava/lang/Throwable;Ljava/lang/String;ILjava/lang/Object;)Ljava/util/concurrent/CancellationException; From ea92646b575668d9b8957ea13b0ea7cdb9d84189 Mon Sep 17 00:00:00 2001 From: mvicsokolova Date: Mon, 14 Nov 2022 17:22:47 +0100 Subject: [PATCH 6/7] Turn on JS IR transformation --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 406e68a63e..2adbab5a43 100644 --- a/gradle.properties +++ b/gradle.properties @@ -59,4 +59,4 @@ org.gradle.jvmargs=-Xmx3g kotlin.mpp.enableCompatibilityMetadataVariant=true kotlin.mpp.stability.nowarn=true kotlinx.atomicfu.enableJvmIrTransformation=true -kotlinx.atomicfu.enableJsIrTransformation=false +kotlinx.atomicfu.enableJsIrTransformation=true From 7b80ba861531c5d27a85c40f17bc3298fafdb2e1 Mon Sep 17 00:00:00 2001 From: mvicsokolova Date: Mon, 14 Nov 2022 17:23:42 +0100 Subject: [PATCH 7/7] Update Kotlin to 1.7.21 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 2adbab5a43..fb2d529443 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,7 +5,7 @@ # Kotlin version=1.6.4-SNAPSHOT group=org.jetbrains.kotlinx -kotlin_version=1.7.20 +kotlin_version=1.7.21 # Dependencies junit_version=4.12