-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathMemoryFootprintTest.kt
43 lines (35 loc) · 1.24 KB
/
MemoryFootprintTest.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package kotlinx.coroutines
import kotlinx.coroutines.testing.*
import org.junit.Test
import org.openjdk.jol.info.*
import kotlin.test.*
@Ignore
class MemoryFootprintTest : TestBase(true) {
@Test
fun testJobLayout() = assertLayout(Job().javaClass, 24)
@Test
fun testJobSize() {
assertTotalSize(jobWithChildren(1), 112)
assertTotalSize(jobWithChildren(2), 192) // + 80
assertTotalSize(jobWithChildren(3), 248) // + 56
assertTotalSize(jobWithChildren(4), 304) // + 56
}
private fun jobWithChildren(numberOfChildren: Int): Job {
val result = Job()
repeat(numberOfChildren) {
Job(result)
}
return result
}
@Test
fun testCancellableContinuationFootprint() = assertLayout(CancellableContinuationImpl::class.java, 48)
private fun assertLayout(clz: Class<*>, expectedSize: Int) {
val size = ClassLayout.parseClass(clz).instanceSize()
// println(ClassLayout.parseClass(clz).toPrintable())
assertEquals(expectedSize.toLong(), size)
}
private fun assertTotalSize(instance: Job, expectedSize: Int) {
val size = GraphLayout.parseInstance(instance).totalSize()
assertEquals(expectedSize.toLong(), size)
}
}