Skip to content

Commit c1869f5

Browse files
committed
Get rid of old Kotlin/Native memory model
Fixes #3375
1 parent 19666ac commit c1869f5

27 files changed

+59
-191
lines changed

kotlinx-coroutines-core/build.gradle

+13-34
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ void defineSourceSet(newName, dependsOn, includedInPred) {
5656
}
5757

5858
static boolean isNativeDarwin(String name) { return ["ios", "macos", "tvos", "watchos"].any { name.startsWith(it) } }
59+
5960
static boolean isNativeOther(String name) { return ["linux", "mingw"].any { name.startsWith(it) } }
6061

6162
defineSourceSet("concurrent", ["common"]) { it in ["jvm", "native"] }
@@ -77,40 +78,18 @@ kotlin {
7778
}
7879

7980
/*
80-
* Configure four test runs:
81-
* 1) Old memory model, Main thread
82-
* 2) New memory model, Main thread
83-
* 3) Old memory model, BG thread
84-
* 4) New memory model, BG thread (required for Dispatchers.Main tests on Darwin)
81+
* Configure two test runs:
82+
* 1) New memory model, Main thread
83+
* 2) New memory model, BG thread (required for Dispatchers.Main tests on Darwin)
8584
*
8685
* All new MM targets are build with optimize = true to have stress tests properly run.
8786
*/
8887
targets.withType(org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetWithTests.class).configureEach {
89-
binaries {
90-
// Test for memory leaks using a special entry point that does not exit but returns from main
91-
binaries.getTest("DEBUG").freeCompilerArgs += ["-e", "kotlinx.coroutines.mainNoExit"]
92-
}
93-
94-
binaries.test("newMM", [DEBUG]) {
95-
def thisTest = it
96-
freeCompilerArgs += ["-e", "kotlinx.coroutines.mainNoExit"]
97-
optimized = true
98-
binaryOptions["memoryModel"] = "experimental"
99-
testRuns.create("newMM") {
100-
setExecutionSourceFrom(thisTest)
101-
// A hack to get different suffixes in the aggregated report.
102-
executionTask.configure { targetName = "$targetName new MM" }
103-
}
104-
}
105-
106-
binaries.test("worker", [DEBUG]) {
107-
def thisTest = it
108-
freeCompilerArgs += ["-e", "kotlinx.coroutines.mainBackground"]
109-
testRuns.create("worker") {
110-
setExecutionSourceFrom(thisTest)
111-
executionTask.configure { targetName = "$targetName worker" }
112-
}
113-
}
88+
def defaultTests = binaries.getTest("DEBUG")
89+
// Test for memory leaks using a special entry point that does not exit but returns from main
90+
defaultTests.freeCompilerArgs += ["-e", "kotlinx.coroutines.mainNoExit"]
91+
defaultTests.optimized = true
92+
defaultTests.binaryOptions["memoryModel"] = "experimental"
11493

11594
binaries.test("workerWithNewMM", [DEBUG]) {
11695
def thisTest = it
@@ -150,11 +129,11 @@ def configureNativeSourceSetPreset(name, preset) {
150129
def implementationConfiguration = configurations[hostMainCompilation.defaultSourceSet.implementationMetadataConfigurationName]
151130
// Now find the libraries: Finds platform libs & stdlib, but platform declarations are still not resolved due to IDE bugs
152131
def hostNativePlatformLibs = files(
153-
provider {
154-
implementationConfiguration.findAll {
155-
it.path.endsWith(".klib") || it.absolutePath.contains("klib${File.separator}platform") || it.absolutePath.contains("stdlib")
132+
provider {
133+
implementationConfiguration.findAll {
134+
it.path.endsWith(".klib") || it.absolutePath.contains("klib${File.separator}platform") || it.absolutePath.contains("stdlib")
135+
}
156136
}
157-
}
158137
)
159138
// Add all those dependencies
160139
for (suffix in sourceSetSuffixes) {

kotlinx-coroutines-core/concurrent/test/AbstractDispatcherConcurrencyTest.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ abstract class AbstractDispatcherConcurrencyTest : TestBase() {
1212
public abstract val dispatcher: CoroutineDispatcher
1313

1414
@Test
15-
fun testLaunchAndJoin() = runMtTest {
15+
fun testLaunchAndJoin() = runTest {
1616
expect(1)
1717
var capturedMutableState = 0
1818
val job = GlobalScope.launch(dispatcher) {
@@ -25,7 +25,7 @@ abstract class AbstractDispatcherConcurrencyTest : TestBase() {
2525
}
2626

2727
@Test
28-
fun testDispatcherHasOwnThreads() = runMtTest {
28+
fun testDispatcherHasOwnThreads() = runTest {
2929
val channel = Channel<Int>()
3030
GlobalScope.launch(dispatcher) {
3131
channel.send(42)
@@ -41,7 +41,7 @@ abstract class AbstractDispatcherConcurrencyTest : TestBase() {
4141
}
4242

4343
@Test
44-
fun testDelayInDispatcher() = runMtTest {
44+
fun testDelayInDispatcher() = runTest {
4545
expect(1)
4646
val job = GlobalScope.launch(dispatcher) {
4747
expect(2)

kotlinx-coroutines-core/concurrent/test/ConcurrentExceptionsStressTest.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class ConcurrentExceptionsStressTest : TestBase() {
2222
}
2323

2424
@Test
25-
fun testStress() = runMtTest {
25+
fun testStress() = runTest {
2626
workers = Array(nWorkers) { index ->
2727
newSingleThreadContext("JobExceptionsStressTest-$index")
2828
}

kotlinx-coroutines-core/concurrent/test/JobStructuredJoinStressTest.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ class JobStructuredJoinStressTest : TestBase() {
1616
private val nRepeats = 10_000 * stressTestMultiplier
1717

1818
@Test
19-
fun testStressRegularJoin() = runMtTest {
19+
fun testStressRegularJoin() = runTest {
2020
stress(Job::join)
2121
}
2222

2323
@Test
24-
fun testStressSuspendCancellable() = runMtTest {
24+
fun testStressSuspendCancellable() = runTest {
2525
stress { job ->
2626
suspendCancellableCoroutine { cont ->
2727
job.invokeOnCompletion { cont.resume(Unit) }
@@ -30,7 +30,7 @@ class JobStructuredJoinStressTest : TestBase() {
3030
}
3131

3232
@Test
33-
fun testStressSuspendCancellableReusable() = runMtTest {
33+
fun testStressSuspendCancellableReusable() = runTest {
3434
stress { job ->
3535
suspendCancellableCoroutineReusable { cont ->
3636
job.invokeOnCompletion { cont.resume(Unit) }

kotlinx-coroutines-core/concurrent/test/LimitedParallelismConcurrentTest.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class LimitedParallelismConcurrentTest : TestBase() {
2323
}
2424

2525
@Test
26-
fun testLimitedExecutor() = runMtTest {
26+
fun testLimitedExecutor() = runTest {
2727
val executor = newFixedThreadPoolContext(targetParallelism, "test")
2828
val view = executor.limitedParallelism(targetParallelism)
2929
doStress {
@@ -45,7 +45,7 @@ class LimitedParallelismConcurrentTest : TestBase() {
4545
}
4646

4747
@Test
48-
fun testTaskFairness() = runMtTest {
48+
fun testTaskFairness() = runTest {
4949
val executor = newSingleThreadContext("test")
5050
val view = executor.limitedParallelism(1)
5151
val view2 = executor.limitedParallelism(1)

kotlinx-coroutines-core/concurrent/test/RunBlockingTest.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import kotlin.test.*
1010
class RunBlockingTest : TestBase() {
1111

1212
@Test
13-
fun testWithTimeoutBusyWait() = runMtTest {
13+
fun testWithTimeoutBusyWait() = runTest {
1414
val value = withTimeoutOrNull(10) {
1515
while (isActive) {
1616
// Busy wait
@@ -52,7 +52,7 @@ class RunBlockingTest : TestBase() {
5252
}
5353

5454
@Test
55-
fun testOtherDispatcher() = runMtTest {
55+
fun testOtherDispatcher() = runTest {
5656
expect(1)
5757
val name = "RunBlockingTest.testOtherDispatcher"
5858
val thread = newSingleThreadContext(name)
@@ -68,7 +68,7 @@ class RunBlockingTest : TestBase() {
6868
}
6969

7070
@Test
71-
fun testCancellation() = runMtTest {
71+
fun testCancellation() = runTest {
7272
newFixedThreadPoolContext(2, "testCancellation").use {
7373
val job = GlobalScope.launch(it) {
7474
runBlocking(coroutineContext) {

kotlinx-coroutines-core/concurrent/test/TestBaseExtension.common.kt

-10
This file was deleted.

kotlinx-coroutines-core/concurrent/test/channels/BroadcastChannelSubStressTest.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class BroadcastChannelSubStressTest: TestBase() {
2020
private val receivedTotal = atomic(0L)
2121

2222
@Test
23-
fun testStress() = runMtTest {
23+
fun testStress() = runTest {
2424
TestBroadcastChannelKind.values().forEach { kind ->
2525
println("--- BroadcastChannelSubStressTest $kind")
2626
val broadcast = kind.create<Long>()

kotlinx-coroutines-core/concurrent/test/channels/ChannelCancelUndeliveredElementStressTest.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class ChannelCancelUndeliveredElementStressTest : TestBase() {
2828
private val dUndeliveredCnt = atomic(0)
2929

3030
@Test
31-
fun testStress() = runMtTest {
31+
fun testStress() = runTest {
3232
repeat(repeatTimes) {
3333
val channel = Channel<Int>(1) { dUndeliveredCnt.incrementAndGet() }
3434
val j1 = launch(Dispatchers.Default) {

kotlinx-coroutines-core/concurrent/test/channels/ConflatedBroadcastChannelNotifyStressTest.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class ConflatedBroadcastChannelNotifyStressTest : TestBase() {
2222
private val receivedTotal = atomic(0)
2323

2424
@Test
25-
fun testStressNotify()= runMtTest {
25+
fun testStressNotify()= runTest {
2626
println("--- ConflatedBroadcastChannelNotifyStressTest")
2727
val senders = List(nSenders) { senderId ->
2828
launch(Dispatchers.Default + CoroutineName("Sender$senderId")) {

kotlinx-coroutines-core/concurrent/test/flow/CombineStressTest.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import kotlin.test.*
1010
class CombineStressTest : TestBase() {
1111

1212
@Test
13-
fun testCancellation() = runMtTest {
13+
fun testCancellation() = runTest {
1414
withContext(Dispatchers.Default + CoroutineExceptionHandler { _, _ -> expectUnreached() }) {
1515
flow {
1616
expect(1)
@@ -26,7 +26,7 @@ class CombineStressTest : TestBase() {
2626
}
2727

2828
@Test
29-
fun testFailure() = runMtTest {
29+
fun testFailure() = runTest {
3030
val innerIterations = 100 * stressTestMultiplierSqrt
3131
val outerIterations = 10 * stressTestMultiplierSqrt
3232
withContext(Dispatchers.Default + CoroutineExceptionHandler { _, _ -> expectUnreached() }) {

kotlinx-coroutines-core/concurrent/test/flow/FlowCancellationTest.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import kotlin.test.*
1212
class FlowCancellationTest : TestBase() {
1313

1414
@Test
15-
fun testEmitIsCooperative() = runMtTest {
15+
fun testEmitIsCooperative() = runTest {
1616
val latch = Channel<Unit>(1)
1717
val job = flow {
1818
expect(1)
@@ -29,7 +29,7 @@ class FlowCancellationTest : TestBase() {
2929
}
3030

3131
@Test
32-
fun testIsActiveOnCurrentContext() = runMtTest {
32+
fun testIsActiveOnCurrentContext() = runTest {
3333
val latch = Channel<Unit>(1)
3434
val job = flow<Unit> {
3535
expect(1)
@@ -46,7 +46,7 @@ class FlowCancellationTest : TestBase() {
4646
}
4747

4848
@Test
49-
fun testFlowWithEmptyContext() = runMtTest {
49+
fun testFlowWithEmptyContext() = runTest {
5050
expect(1)
5151
withEmptyContext {
5252
val flow = flow {

kotlinx-coroutines-core/concurrent/test/flow/StateFlowCommonStressTest.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class StateFlowCommonStressTest : TestBase() {
1313
private val state = MutableStateFlow<Long>(0)
1414

1515
@Test
16-
fun testSingleEmitterAndCollector() = runMtTest {
16+
fun testSingleEmitterAndCollector() = runTest {
1717
var collected = 0L
1818
val collector = launch(Dispatchers.Default) {
1919
// collect, but abort and collect again after every 1000 values to stress allocation/deallocation

kotlinx-coroutines-core/concurrent/test/flow/StateFlowUpdateCommonTest.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class StateFlowUpdateCommonTest : TestBase() {
2121
@Test
2222
fun testGetAndUpdate() = doTest { getAndUpdate { it + 1 } }
2323

24-
private fun doTest(increment: MutableStateFlow<Int>.() -> Unit) = runMtTest {
24+
private fun doTest(increment: MutableStateFlow<Int>.() -> Unit) = runTest {
2525
val flow = MutableStateFlow(0)
2626
val j1 = launch(Dispatchers.Default) {
2727
repeat(iterations / 2) {

kotlinx-coroutines-core/concurrent/test/selects/SelectChannelStressTest.kt

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class SelectChannelStressTest: TestBase() {
1515
private val iterations = (if (isNative) 1_000 else 1_000_000) * stressTestMultiplier
1616

1717
@Test
18-
fun testSelectSendResourceCleanupArrayChannel() = runMtTest {
18+
fun testSelectSendResourceCleanupArrayChannel() = runTest {
1919
val channel = Channel<Int>(1)
2020
expect(1)
2121
channel.send(-1) // fill the buffer, so all subsequent sends cannot proceed
@@ -29,7 +29,7 @@ class SelectChannelStressTest: TestBase() {
2929
}
3030

3131
@Test
32-
fun testSelectReceiveResourceCleanupArrayChannel() = runMtTest {
32+
fun testSelectReceiveResourceCleanupArrayChannel() = runTest {
3333
val channel = Channel<Int>(1)
3434
expect(1)
3535
repeat(iterations) { i ->
@@ -42,7 +42,7 @@ class SelectChannelStressTest: TestBase() {
4242
}
4343

4444
@Test
45-
fun testSelectSendResourceCleanupRendezvousChannel() = runMtTest {
45+
fun testSelectSendResourceCleanupRendezvousChannel() = runTest {
4646
val channel = Channel<Int>(Channel.RENDEZVOUS)
4747
expect(1)
4848
repeat(iterations) { i ->
@@ -55,7 +55,7 @@ class SelectChannelStressTest: TestBase() {
5555
}
5656

5757
@Test
58-
fun testSelectReceiveResourceRendezvousChannel() = runMtTest {
58+
fun testSelectReceiveResourceRendezvousChannel() = runTest {
5959
val channel = Channel<Int>(Channel.RENDEZVOUS)
6060
expect(1)
6161
repeat(iterations) { i ->

kotlinx-coroutines-core/concurrent/test/sync/MutexStressTest.kt

+7-7
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,24 @@ class MutexStressTest : TestBase() {
1414
private val n = (if (isNative) 1_000 else 10_000) * stressTestMultiplier
1515

1616
@Test
17-
fun testDefaultDispatcher() = runMtTest { testBody(Dispatchers.Default) }
17+
fun testDefaultDispatcher() = runTest { testBody(Dispatchers.Default) }
1818

1919
@Test
20-
fun testSingleThreadContext() = runMtTest {
20+
fun testSingleThreadContext() = runTest {
2121
newSingleThreadContext("testSingleThreadContext").use {
2222
testBody(it)
2323
}
2424
}
2525

2626
@Test
27-
fun testMultiThreadedContextWithSingleWorker() = runMtTest {
27+
fun testMultiThreadedContextWithSingleWorker() = runTest {
2828
newFixedThreadPoolContext(1, "testMultiThreadedContextWithSingleWorker").use {
2929
testBody(it)
3030
}
3131
}
3232

3333
@Test
34-
fun testMultiThreadedContext() = runMtTest {
34+
fun testMultiThreadedContext() = runTest {
3535
newFixedThreadPoolContext(8, "testMultiThreadedContext").use {
3636
testBody(it)
3737
}
@@ -56,7 +56,7 @@ class MutexStressTest : TestBase() {
5656
}
5757

5858
@Test
59-
fun stressUnlockCancelRace() = runMtTest {
59+
fun stressUnlockCancelRace() = runTest {
6060
val n = 10_000 * stressTestMultiplier
6161
val mutex = Mutex(true) // create a locked mutex
6262
newSingleThreadContext("SemaphoreStressTest").use { pool ->
@@ -86,7 +86,7 @@ class MutexStressTest : TestBase() {
8686
}
8787

8888
@Test
89-
fun stressUnlockCancelRaceWithSelect() = runMtTest {
89+
fun stressUnlockCancelRaceWithSelect() = runTest {
9090
val n = 10_000 * stressTestMultiplier
9191
val mutex = Mutex(true) // create a locked mutex
9292
newSingleThreadContext("SemaphoreStressTest").use { pool ->
@@ -119,7 +119,7 @@ class MutexStressTest : TestBase() {
119119
}
120120

121121
@Test
122-
fun testShouldBeUnlockedOnCancellation() = runMtTest {
122+
fun testShouldBeUnlockedOnCancellation() = runTest {
123123
val mutex = Mutex()
124124
val n = 1000 * stressTestMultiplier
125125
repeat(n) {

0 commit comments

Comments
 (0)