Skip to content

Introduce Java Object Layout to the codebase and write tests for core… #3391

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions kotlinx-coroutines-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ kotlin.sourceSets {
api "org.jetbrains.kotlinx:lincheck:$lincheck_version"
api "org.jetbrains.kotlinx:kotlinx-knit-test:$knit_version"
implementation project(":android-unit-tests")
implementation "org.openjdk.jol:jol-core:0.16"
}
}

Expand Down
25 changes: 25 additions & 0 deletions kotlinx-coroutines-core/jvm/test/MemoryFootprintTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright 2016-2022 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/

package kotlinx.coroutines

import org.junit.Test
import org.openjdk.jol.info.ClassLayout
import kotlin.test.*


class MemoryFootprintTest : TestBase(true) {

@Test
fun testJobLayout() = assertLayout(Job().javaClass, 24)

@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)
}
}