[K/N] Change AtomicReference for the new MM ^KT-50026

Make AtomicReference behave like FreezableAtomicReference with the new MM: not frozen by default, don't require freezing value unless the ref itself is frozen. The behaviour with the old MM is unchanged.

Merge-request: KT-MR-5155
This commit is contained in:
Alexander Shabalin
2021-12-03 17:08:21 +00:00
committed by Space
parent 1d2e60a2af
commit 4fd61ad1b0
10 changed files with 84 additions and 33 deletions
@@ -215,7 +215,7 @@ private fun debugString(value: Any?): String {
* Otherwise memory leak could happen. To detect such leaks [kotlin.native.internal.GC.detectCycles]
* in debug mode could be helpful.
*/
@Frozen
@FrozenLegacyMM
@LeakDetectorCandidate
@NoReorderFields
public class AtomicReference<T> {
@@ -232,7 +232,9 @@ public class AtomicReference<T> {
* @throws InvalidMutabilityException if reference is not frozen.
*/
constructor(value: T) {
checkIfFrozen(value)
if (this.isFrozen) {
checkIfFrozen(value)
}
value_ = value
}
@@ -48,6 +48,13 @@ public annotation class ExportForCompiler
@Retention(AnnotationRetention.BINARY)
internal annotation class Frozen
/**
* Similar to `@Frozen`, but works only for legacy MM. On the new MM this has no effect.
*/
@Target(AnnotationTarget.CLASS)
@Retention(AnnotationRetention.BINARY)
internal annotation class FrozenLegacyMM
/**
* Fields of annotated class won't be sorted.
*/