[kotlin.reflect] Introduce ClassValue-based cache for KClassImpl
* Replace pcollections with ClassValue/ConcurrentHashMap-based caches * Do not store weak references, instead cache strong references and count on ClassValue to unload the corresponding classloader if necessary * ConcurrentHashMap does not rely on WeakReference as it's only selected on Android where classloader leaks don't exist * Update reflect/scripting JDK requirement to Java 8 in order to proceed #KT-53454 #KT-50705 Merge-request: KT-MR-6788 Merged-by: Vsevolod Tolstopyatov <qwwdfsad@gmail.com>
This commit is contained in:
committed by
Space
parent
d5164fbc86
commit
14b13a2f17
-26
@@ -1,26 +0,0 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.reflect.jvm.internal.pcollections.HashPMap
|
||||
import kotlin.test.*
|
||||
|
||||
fun box(): String {
|
||||
val map = HashPMap.empty<String, Any>()!!
|
||||
|
||||
assertEquals(0, map.size())
|
||||
|
||||
assertFalse(map.containsKey(""))
|
||||
assertFalse(map.containsKey("abacaba"))
|
||||
assertEquals(null, map[""])
|
||||
assertEquals(null, map["lol"])
|
||||
|
||||
// Check that doesn't create a new map
|
||||
assertEquals(map, map.minus(""))
|
||||
|
||||
// Check that all empty()s are equal
|
||||
val other = HashPMap.empty<String, Any>()!!
|
||||
assertEquals(map, other)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
|
||||
// Out of memory on Android 4.4
|
||||
// IGNORE_BACKEND: ANDROID
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
import java.util.*
|
||||
import kotlin.reflect.jvm.internal.pcollections.HashPMap
|
||||
import kotlin.test.*
|
||||
|
||||
fun digitSum(number: Int): Int {
|
||||
var x = number
|
||||
var ans = 0
|
||||
while (x != 0) {
|
||||
ans += x % 10
|
||||
x /= 10
|
||||
}
|
||||
return ans
|
||||
}
|
||||
|
||||
val N = 1000000
|
||||
|
||||
fun box(): String {
|
||||
var map = HashPMap.empty<Int, Any>()!!
|
||||
|
||||
for (x in 1..N) {
|
||||
map = map.plus(x, digitSum(x))!!
|
||||
}
|
||||
|
||||
assertEquals(N, map.size())
|
||||
|
||||
// Check in reverse order just in case
|
||||
for (x in N downTo 1) {
|
||||
assertTrue(map.containsKey(x), "Not found: $x")
|
||||
assertEquals(digitSum(x), map[x], "Incorrect value for $x")
|
||||
}
|
||||
|
||||
// Delete in random order
|
||||
val list = (1..N).toCollection(ArrayList<Int>())
|
||||
Collections.shuffle(list, Random(42))
|
||||
for (x in list) {
|
||||
map = map.minus(x)!!
|
||||
}
|
||||
|
||||
assertEquals(0, map.size())
|
||||
|
||||
for (x in 1..N) {
|
||||
assertFalse(map.containsKey(x), "Incorrectly found: $x")
|
||||
assertEquals(null, map[x], "Incorrectly found value for $x")
|
||||
}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.reflect.jvm.internal.pcollections.HashPMap
|
||||
import kotlin.test.*
|
||||
|
||||
fun box(): String {
|
||||
var map = HashPMap.empty<String, Any>()!!
|
||||
|
||||
map = map.plus("lol", 42)!!
|
||||
map = map.plus("lol", 239)!!
|
||||
|
||||
assertEquals(1, map.size())
|
||||
assertTrue(map.containsKey("lol"))
|
||||
assertFalse(map.containsKey(""))
|
||||
assertEquals(239, map["lol"])
|
||||
assertEquals(null, map[""])
|
||||
|
||||
map = map.plus("", 0)!!
|
||||
map = map.plus("", 2.71828)!!
|
||||
map = map.plus("lol", 42)!!
|
||||
map = map.plus("", 3.14)!!
|
||||
|
||||
assertEquals(2, map.size())
|
||||
assertTrue(map.containsKey("lol"))
|
||||
assertTrue(map.containsKey(""))
|
||||
assertEquals(42, map["lol"])
|
||||
assertEquals(3.14, map[""])
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.reflect.jvm.internal.pcollections.HashPMap
|
||||
import kotlin.test.*
|
||||
|
||||
fun box(): String {
|
||||
var map = HashPMap.empty<String, Any>()!!
|
||||
|
||||
map = map.plus("lol", 42)!!
|
||||
map = map.plus("lol", 42)!!
|
||||
|
||||
assertEquals(1, map.size())
|
||||
assertTrue(map.containsKey("lol"))
|
||||
assertFalse(map.containsKey(""))
|
||||
assertEquals(42, map["lol"])
|
||||
assertEquals(null, map[""])
|
||||
|
||||
map = map.plus("", 0)!!
|
||||
map = map.plus("", 0)!!
|
||||
map = map.plus("lol", 42)!!
|
||||
map = map.plus("", 0)!!
|
||||
|
||||
assertEquals(2, map.size())
|
||||
assertTrue(map.containsKey("lol"))
|
||||
assertTrue(map.containsKey(""))
|
||||
assertEquals(42, map["lol"])
|
||||
assertEquals(0, map[""])
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.reflect.jvm.internal.pcollections.HashPMap
|
||||
import kotlin.test.*
|
||||
|
||||
fun box(): String {
|
||||
var map = HashPMap.empty<String, Any>()!!
|
||||
|
||||
map = map.plus("lol", 42)!!
|
||||
|
||||
assertEquals(1, map.size())
|
||||
assertTrue(map.containsKey("lol"))
|
||||
assertFalse(map.containsKey(""))
|
||||
assertEquals(42, map["lol"])
|
||||
assertEquals(null, map[""])
|
||||
|
||||
map = map.plus("", 0)!!
|
||||
|
||||
assertEquals(2, map.size())
|
||||
assertTrue(map.containsKey("lol"))
|
||||
assertTrue(map.containsKey(""))
|
||||
assertEquals(42, map["lol"])
|
||||
assertEquals(0, map[""])
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.reflect.jvm.internal.pcollections.HashPMap
|
||||
import kotlin.test.*
|
||||
|
||||
fun box(): String {
|
||||
var map = HashPMap.empty<String, Any>()!!
|
||||
|
||||
map = map.plus("lol", 42)!!
|
||||
map = map.minus("lol")!!
|
||||
|
||||
assertEquals(0, map.size())
|
||||
assertFalse(map.containsKey("lol"))
|
||||
assertEquals(null, map["lol"])
|
||||
|
||||
map = map.plus("abc", "a")!!
|
||||
map = map.minus("abc")!!
|
||||
map = map.plus("abc", "d")!!
|
||||
|
||||
assertEquals(1, map.size())
|
||||
assertTrue(map.containsKey("abc"))
|
||||
assertEquals("d", map["abc"])
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user