Skip to content

Commit c9d3f7b

Browse files
authored
ConcurrentWeakMap-related minor improvements (#3346)
1 parent cb65eb1 commit c9d3f7b

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

kotlinx-coroutines-core/jvm/src/debug/internal/ConcurrentWeakMap.kt

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@ import java.lang.ref.*
1010

1111
// This is very limited implementation, not suitable as a generic map replacement.
1212
// It has lock-free get and put with synchronized rehash for simplicity (and better CPU usage on contention)
13-
@OptIn(ExperimentalStdlibApi::class)
1413
@Suppress("UNCHECKED_CAST")
1514
internal class ConcurrentWeakMap<K : Any, V: Any>(
1615
/**
17-
* Weak reference queue is needed when a small key is mapped to a large value and we need to promptly release a
16+
* Weak reference queue is needed when a small key is mapped to a large value, and we need to promptly release a
1817
* reference to the value when the key was already disposed.
1918
*/
2019
weakRefQueue: Boolean = false

kotlinx-coroutines-core/jvm/test/TestBase.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,9 @@ public actual open class TestBase(private var disableOutCheck: Boolean) {
236236
if (expected != null) {
237237
if (!expected(e))
238238
error("Unexpected exception: $e", e)
239-
} else
239+
} else {
240240
throw e
241+
}
241242
} finally {
242243
if (ex == null && expected != null) error("Exception was expected but none produced")
243244
}

kotlinx-coroutines-core/jvm/test/internal/ConcurrentWeakMapOperationStressTest.kt

+5-5
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class ConcurrentWeakMapOperationStressTest : TestBase() {
3434
var generationOffset = 0L
3535
while (!stop.value) {
3636
val kvs = (generationOffset + batchSize * index until generationOffset + batchSize * (index + 1))
37-
.associateBy({ Key(it) }, { it * it })
37+
.associateBy({ Key(it) }, { it * it })
3838
generationOffset += batchSize * nThreads
3939
for ((k, v) in kvs) {
4040
assertEquals(null, m.put(k, v))
@@ -45,8 +45,8 @@ class ConcurrentWeakMapOperationStressTest : TestBase() {
4545
for ((k, v) in kvs) {
4646
assertEquals(v, m.remove(k))
4747
}
48-
for ((k, v) in kvs) {
49-
assertEquals(null, m.get(k))
48+
for ((k, _) in kvs) {
49+
assertEquals(null, m[k])
5050
}
5151
count.incrementAndGet()
5252
}
@@ -68,6 +68,6 @@ class ConcurrentWeakMapOperationStressTest : TestBase() {
6868
}
6969
stop.value = true
7070
threads.forEach { it.join() }
71-
assertEquals(0, m.size)
71+
assertEquals(0, m.size, "Unexpected map state: $m")
7272
}
73-
}
73+
}

0 commit comments

Comments
 (0)