Skip to content

Commit 49032ef

Browse files
committed
Introduce Java Object Layout to the codebase and write tests for core primitives
It should further simplify reasoning about new fields in core classes
1 parent 03176c7 commit 49032ef

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

kotlinx-coroutines-core/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ kotlin.sourceSets {
168168
api "org.jetbrains.kotlinx:lincheck:$lincheck_version"
169169
api "org.jetbrains.kotlinx:kotlinx-knit-test:$knit_version"
170170
implementation project(":android-unit-tests")
171+
implementation "org.openjdk.jol:jol-core:0.16"
171172
}
172173
}
173174

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright 2016-2022 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
package kotlinx.coroutines
6+
7+
import org.junit.Test
8+
import org.openjdk.jol.info.ClassLayout
9+
import kotlin.test.*
10+
11+
12+
class MemoryFootprintTest : TestBase(true) {
13+
14+
@Test
15+
fun testJobLayout() = assertLayout(Job().javaClass, 24)
16+
17+
@Test
18+
fun testCancellableContinuationFootprint() = assertLayout(CancellableContinuationImpl::class.java, 48)
19+
20+
private fun assertLayout(clz: Class<*>, expectedSize: Int) {
21+
val size = ClassLayout.parseClass(clz).instanceSize()
22+
// println(ClassLayout.parseClass(clz).toPrintable())
23+
assertEquals(expectedSize.toLong(), size)
24+
}
25+
}

0 commit comments

Comments
 (0)