Skip to content
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

Create a separate source set for the shared Blackhole #207

Merged
merged 2 commits into from
May 10, 2024
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
34 changes: 16 additions & 18 deletions runtime/api/kotlinx-benchmark-runtime.klib.api
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
// Klib ABI Dump
// Targets: [androidNativeArm32, androidNativeArm64, androidNativeX64, androidNativeX86, iosArm64, iosSimulatorArm64, iosX64, js.jsIr, linuxArm64, linuxX64, macosArm64, macosX64, mingwX64, tvosArm64, tvosSimulatorArm64, tvosX64, wasmJs, watchosArm32, watchosArm64, watchosDeviceArm64, watchosSimulatorArm64, watchosX64]
// Alias: native => [androidNativeArm32, androidNativeArm64, androidNativeX64, androidNativeX86, iosArm64, iosSimulatorArm64, iosX64, linuxArm64, linuxX64, macosArm64, macosX64, mingwX64, tvosArm64, tvosSimulatorArm64, tvosX64, watchosArm32, watchosArm64, watchosDeviceArm64, watchosSimulatorArm64, watchosX64]
// Rendering settings:
// - Signature version: 2
// - Show manifest properties: true
// - Show declarations: true

// Library unique name: <org.jetbrains.kotlinx:kotlinx-benchmark-runtime>
final class kotlinx.benchmark/Blackhole { // kotlinx.benchmark/Blackhole|null[0]
constructor <init>() // kotlinx.benchmark/Blackhole.<init>|<init>(){}[0]
final inline fun consume(kotlin/Any?) // kotlinx.benchmark/Blackhole.consume|consume(kotlin.Any?){}[0]
final inline fun consume(kotlin/Boolean) // kotlinx.benchmark/Blackhole.consume|consume(kotlin.Boolean){}[0]
final inline fun consume(kotlin/Byte) // kotlinx.benchmark/Blackhole.consume|consume(kotlin.Byte){}[0]
final inline fun consume(kotlin/Char) // kotlinx.benchmark/Blackhole.consume|consume(kotlin.Char){}[0]
final inline fun consume(kotlin/Double) // kotlinx.benchmark/Blackhole.consume|consume(kotlin.Double){}[0]
final inline fun consume(kotlin/Float) // kotlinx.benchmark/Blackhole.consume|consume(kotlin.Float){}[0]
final inline fun consume(kotlin/Int) // kotlinx.benchmark/Blackhole.consume|consume(kotlin.Int){}[0]
final inline fun consume(kotlin/Long) // kotlinx.benchmark/Blackhole.consume|consume(kotlin.Long){}[0]
final inline fun consume(kotlin/Short) // kotlinx.benchmark/Blackhole.consume|consume(kotlin.Short){}[0]
// Targets: [js.jsIr, wasmJs]
final fun consumeAny(kotlin/Any?) // kotlinx.benchmark/Blackhole.consumeAny|consumeAny(kotlin.Any?){}[0]
// Targets: [js.jsIr, wasmJs]
final fun consumeInt(kotlin/Int) // kotlinx.benchmark/Blackhole.consumeInt|consumeInt(kotlin.Int){}[0]
}
final enum class kotlinx.benchmark/BenchmarkTimeUnit : kotlin/Enum<kotlinx.benchmark/BenchmarkTimeUnit> { // kotlinx.benchmark/BenchmarkTimeUnit|null[0]
enum entry MICROSECONDS // kotlinx.benchmark/BenchmarkTimeUnit.MICROSECONDS|null[0]
enum entry MILLISECONDS // kotlinx.benchmark/BenchmarkTimeUnit.MILLISECONDS|null[0]
Expand Down Expand Up @@ -87,20 +102,3 @@ open annotation class kotlinx.benchmark/Warmup : kotlin/Annotation { // kotlinx.
final val timeUnit // kotlinx.benchmark/Warmup.timeUnit|{}timeUnit[0]
final fun <get-timeUnit>(): kotlinx.benchmark/BenchmarkTimeUnit // kotlinx.benchmark/Warmup.timeUnit.<get-timeUnit>|<get-timeUnit>(){}[0]
}
// Targets: [native]
final class kotlinx.benchmark/Blackhole { // kotlinx.benchmark/Blackhole|null[0]
constructor <init>() // kotlinx.benchmark/Blackhole.<init>|<init>(){}[0]
final inline fun consume(kotlin/Any?) // kotlinx.benchmark/Blackhole.consume|consume(kotlin.Any?){}[0]
final inline fun consume(kotlin/Boolean) // kotlinx.benchmark/Blackhole.consume|consume(kotlin.Boolean){}[0]
final inline fun consume(kotlin/Byte) // kotlinx.benchmark/Blackhole.consume|consume(kotlin.Byte){}[0]
final inline fun consume(kotlin/Char) // kotlinx.benchmark/Blackhole.consume|consume(kotlin.Char){}[0]
final inline fun consume(kotlin/Double) // kotlinx.benchmark/Blackhole.consume|consume(kotlin.Double){}[0]
final inline fun consume(kotlin/Float) // kotlinx.benchmark/Blackhole.consume|consume(kotlin.Float){}[0]
final inline fun consume(kotlin/Int) // kotlinx.benchmark/Blackhole.consume|consume(kotlin.Int){}[0]
final inline fun consume(kotlin/Long) // kotlinx.benchmark/Blackhole.consume|consume(kotlin.Long){}[0]
final inline fun consume(kotlin/Short) // kotlinx.benchmark/Blackhole.consume|consume(kotlin.Short){}[0]
}
// Targets: [js.jsIr, wasmJs]
final class kotlinx.benchmark/Blackhole : kotlinx.benchmark/CommonBlackhole { // kotlinx.benchmark/Blackhole|null[0]
constructor <init>() // kotlinx.benchmark/Blackhole.<init>|<init>(){}[0]
}
9 changes: 8 additions & 1 deletion runtime/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,14 @@ kotlin {
js("jsIr", IR) { nodejs() }
wasm("wasmJs") { d8() }

applyDefaultHierarchyTemplate()
applyDefaultHierarchyTemplate { root ->
root.common { common ->
common.group("jsWasmJsShared") { group ->
group.withJs()
group.withWasm()
}
}
}

targets.configureEach {
compilations.configureEach {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import kotlinx.benchmark.internal.KotlinxBenchmarkRuntimeInternalApi

private const val MAGIC_SIZE: Int = 13

// TODO: Drop this class once it becomes internal
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: TODOs should have an issue reference, e.g. // TODO KT-1234 ....

Adding an issue ref helps make sure the TODO isn't forgotten. The issue also provides a place for quickly updating the status of the TODO, which can be really helpful when developing in the future (e.g. if I discover a TODO and see the issue is closed as no-longer-needed, then I can be confident in deleting the TODO).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This TODO is part of the @KotlinxBenchmarkRuntimeInternalApi. I have mentioned the need to drop the APIs that are unused after they become internal here: #211

@KotlinxBenchmarkRuntimeInternalApi
open class CommonBlackhole {
private val arrayOfAny: Array<Any?> = arrayOfNulls(MAGIC_SIZE)
Expand Down
9 changes: 0 additions & 9 deletions runtime/jsMain/src/kotlinx/benchmark/JsBlackhole.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package kotlinx.benchmark

import kotlinx.benchmark.internal.KotlinxBenchmarkRuntimeInternalApi

private const val MAGIC_SIZE: Int = 13

@Suppress("NOTHING_TO_INLINE")
public actual class Blackhole {
private val arrayOfAny: Array<Any?> = arrayOfNulls(MAGIC_SIZE)
private var currentAnyPosition: Int = 0

@PublishedApi
internal fun consumeAny(obj: Any?) {
arrayOfAny[currentAnyPosition] = obj
currentAnyPosition = if (currentAnyPosition == MAGIC_SIZE - 1) 0 else currentAnyPosition + 1
}

private val arrayOfInt: IntArray = IntArray(MAGIC_SIZE)
private var currentIntPosition: Int = 0

@PublishedApi
internal fun consumeInt(i: Int) {
arrayOfInt[currentIntPosition] = i
currentIntPosition = if (currentIntPosition == MAGIC_SIZE - 1) 0 else currentIntPosition + 1
}

internal fun flushMe() {
val sums = arrayOfAny.sumOf { it.hashCode() } + arrayOfInt.sum()
println("Consumed blackhole value: $sums")
}

actual inline fun consume(obj: Any?) = consumeAny(obj)

actual inline fun consume(bool: Boolean) = consumeInt(bool.hashCode())

actual inline fun consume(c: Char) = consumeInt(c.hashCode())

actual inline fun consume(b: Byte) = consumeInt(b.hashCode())

actual inline fun consume(s: Short) = consumeInt(s.hashCode())

actual inline fun consume(i: Int) = consumeInt(i.hashCode())

actual inline fun consume(l: Long) = consumeInt(l.hashCode())

actual inline fun consume(f: Float) = consumeInt(f.hashCode())

actual inline fun consume(d: Double) = consumeInt(d.hashCode())
}


@KotlinxBenchmarkRuntimeInternalApi
actual fun Blackhole.flush() = flushMe()
8 changes: 0 additions & 8 deletions runtime/wasmJsMain/src/kotlinx/benchmark/WasmBlackhole.kt

This file was deleted.