Skip to content

Commit a3a3849

Browse files
Abduqodiri Qurbonzodaqurbonzoda
authored andcommitted
Create a separate source set for the shared Blackhole
The CommonBlackhole class is going to be hidden/internalized. Once it is internal, the public Js and WasmJs Blackhole classes won’t be able to inherit from it. This separate source set, shared btw Js and WasmJs, ensures that the targets have a shared implementation, allowing the CommonBlackhole class to be properly internalized or dropped.
1 parent 81aed39 commit a3a3849

File tree

6 files changed

+96
-35
lines changed

6 files changed

+96
-35
lines changed

runtime/api/kotlinx-benchmark-runtime.klib.api

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,45 @@
77
// - Show declarations: true
88

99
// Library unique name: <org.jetbrains.kotlinx:kotlinx-benchmark-runtime>
10+
final class kotlinx.benchmark/Blackhole { // kotlinx.benchmark/Blackhole|null[0]
11+
constructor <init>() // kotlinx.benchmark/Blackhole.<init>|<init>(){}[0]
12+
// Targets: [native]
13+
final inline fun consume(kotlin/Any?) // kotlinx.benchmark/Blackhole.consume|consume(kotlin.Any?){}[0]
14+
// Targets: [native]
15+
final inline fun consume(kotlin/Boolean) // kotlinx.benchmark/Blackhole.consume|consume(kotlin.Boolean){}[0]
16+
// Targets: [native]
17+
final inline fun consume(kotlin/Byte) // kotlinx.benchmark/Blackhole.consume|consume(kotlin.Byte){}[0]
18+
// Targets: [native]
19+
final inline fun consume(kotlin/Char) // kotlinx.benchmark/Blackhole.consume|consume(kotlin.Char){}[0]
20+
// Targets: [native]
21+
final inline fun consume(kotlin/Double) // kotlinx.benchmark/Blackhole.consume|consume(kotlin.Double){}[0]
22+
// Targets: [native]
23+
final inline fun consume(kotlin/Float) // kotlinx.benchmark/Blackhole.consume|consume(kotlin.Float){}[0]
24+
// Targets: [native]
25+
final inline fun consume(kotlin/Int) // kotlinx.benchmark/Blackhole.consume|consume(kotlin.Int){}[0]
26+
// Targets: [native]
27+
final inline fun consume(kotlin/Long) // kotlinx.benchmark/Blackhole.consume|consume(kotlin.Long){}[0]
28+
// Targets: [native]
29+
final inline fun consume(kotlin/Short) // kotlinx.benchmark/Blackhole.consume|consume(kotlin.Short){}[0]
30+
// Targets: [js.jsIr, wasmJs]
31+
final fun consume(kotlin/Any?) // kotlinx.benchmark/Blackhole.consume|consume(kotlin.Any?){}[0]
32+
// Targets: [js.jsIr, wasmJs]
33+
final fun consume(kotlin/Boolean) // kotlinx.benchmark/Blackhole.consume|consume(kotlin.Boolean){}[0]
34+
// Targets: [js.jsIr, wasmJs]
35+
final fun consume(kotlin/Byte) // kotlinx.benchmark/Blackhole.consume|consume(kotlin.Byte){}[0]
36+
// Targets: [js.jsIr, wasmJs]
37+
final fun consume(kotlin/Char) // kotlinx.benchmark/Blackhole.consume|consume(kotlin.Char){}[0]
38+
// Targets: [js.jsIr, wasmJs]
39+
final fun consume(kotlin/Double) // kotlinx.benchmark/Blackhole.consume|consume(kotlin.Double){}[0]
40+
// Targets: [js.jsIr, wasmJs]
41+
final fun consume(kotlin/Float) // kotlinx.benchmark/Blackhole.consume|consume(kotlin.Float){}[0]
42+
// Targets: [js.jsIr, wasmJs]
43+
final fun consume(kotlin/Int) // kotlinx.benchmark/Blackhole.consume|consume(kotlin.Int){}[0]
44+
// Targets: [js.jsIr, wasmJs]
45+
final fun consume(kotlin/Long) // kotlinx.benchmark/Blackhole.consume|consume(kotlin.Long){}[0]
46+
// Targets: [js.jsIr, wasmJs]
47+
final fun consume(kotlin/Short) // kotlinx.benchmark/Blackhole.consume|consume(kotlin.Short){}[0]
48+
}
1049
final enum class kotlinx.benchmark/BenchmarkTimeUnit : kotlin/Enum<kotlinx.benchmark/BenchmarkTimeUnit> { // kotlinx.benchmark/BenchmarkTimeUnit|null[0]
1150
enum entry MICROSECONDS // kotlinx.benchmark/BenchmarkTimeUnit.MICROSECONDS|null[0]
1251
enum entry MILLISECONDS // kotlinx.benchmark/BenchmarkTimeUnit.MILLISECONDS|null[0]
@@ -87,20 +126,3 @@ open annotation class kotlinx.benchmark/Warmup : kotlin/Annotation { // kotlinx.
87126
final val timeUnit // kotlinx.benchmark/Warmup.timeUnit|{}timeUnit[0]
88127
final fun <get-timeUnit>(): kotlinx.benchmark/BenchmarkTimeUnit // kotlinx.benchmark/Warmup.timeUnit.<get-timeUnit>|<get-timeUnit>(){}[0]
89128
}
90-
// Targets: [native]
91-
final class kotlinx.benchmark/Blackhole { // kotlinx.benchmark/Blackhole|null[0]
92-
constructor <init>() // kotlinx.benchmark/Blackhole.<init>|<init>(){}[0]
93-
final inline fun consume(kotlin/Any?) // kotlinx.benchmark/Blackhole.consume|consume(kotlin.Any?){}[0]
94-
final inline fun consume(kotlin/Boolean) // kotlinx.benchmark/Blackhole.consume|consume(kotlin.Boolean){}[0]
95-
final inline fun consume(kotlin/Byte) // kotlinx.benchmark/Blackhole.consume|consume(kotlin.Byte){}[0]
96-
final inline fun consume(kotlin/Char) // kotlinx.benchmark/Blackhole.consume|consume(kotlin.Char){}[0]
97-
final inline fun consume(kotlin/Double) // kotlinx.benchmark/Blackhole.consume|consume(kotlin.Double){}[0]
98-
final inline fun consume(kotlin/Float) // kotlinx.benchmark/Blackhole.consume|consume(kotlin.Float){}[0]
99-
final inline fun consume(kotlin/Int) // kotlinx.benchmark/Blackhole.consume|consume(kotlin.Int){}[0]
100-
final inline fun consume(kotlin/Long) // kotlinx.benchmark/Blackhole.consume|consume(kotlin.Long){}[0]
101-
final inline fun consume(kotlin/Short) // kotlinx.benchmark/Blackhole.consume|consume(kotlin.Short){}[0]
102-
}
103-
// Targets: [js.jsIr, wasmJs]
104-
final class kotlinx.benchmark/Blackhole : kotlinx.benchmark/CommonBlackhole { // kotlinx.benchmark/Blackhole|null[0]
105-
constructor <init>() // kotlinx.benchmark/Blackhole.<init>|<init>(){}[0]
106-
}

runtime/build.gradle

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,14 @@ kotlin {
4141
js("jsIr", IR) { nodejs() }
4242
wasm("wasmJs") { d8() }
4343

44-
applyDefaultHierarchyTemplate()
44+
applyDefaultHierarchyTemplate { root ->
45+
root.common { common ->
46+
common.group("jsWasmJsShared") { group ->
47+
group.withJs()
48+
group.withWasm()
49+
}
50+
}
51+
}
4552

4653
targets.configureEach {
4754
compilations.configureEach {

runtime/commonMain/src/kotlinx/benchmark/CommonBlackhole.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import kotlinx.benchmark.internal.KotlinxBenchmarkRuntimeInternalApi
44

55
private const val MAGIC_SIZE: Int = 13
66

7+
// TODO: Drop this class once it becomes internal
78
@KotlinxBenchmarkRuntimeInternalApi
89
open class CommonBlackhole {
910
private val arrayOfAny: Array<Any?> = arrayOfNulls(MAGIC_SIZE)

runtime/jsMain/src/kotlinx/benchmark/JsBlackhole.kt

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package kotlinx.benchmark
2+
3+
import kotlinx.benchmark.internal.KotlinxBenchmarkRuntimeInternalApi
4+
5+
private const val MAGIC_SIZE: Int = 13
6+
7+
public actual class Blackhole {
8+
private val arrayOfAny: Array<Any?> = arrayOfNulls(MAGIC_SIZE)
9+
private var currentAnyPosition: Int = 0
10+
private fun consumeAny(obj: Any?) {
11+
arrayOfAny[currentAnyPosition] = obj
12+
currentAnyPosition = if (currentAnyPosition == MAGIC_SIZE - 1) 0 else currentAnyPosition + 1
13+
}
14+
15+
private val arrayOfInt: IntArray = IntArray(MAGIC_SIZE)
16+
private var currentIntPosition: Int = 0
17+
private fun consumeInt(i: Int) {
18+
arrayOfInt[currentIntPosition] = i
19+
currentIntPosition = if (currentIntPosition == MAGIC_SIZE - 1) 0 else currentIntPosition + 1
20+
}
21+
22+
internal fun flushMe() {
23+
val sums = arrayOfAny.sumOf { it.hashCode() } + arrayOfInt.sum()
24+
println("Consumed blackhole value: $sums")
25+
}
26+
27+
actual fun consume(obj: Any?) = consumeAny(obj)
28+
29+
actual fun consume(bool: Boolean) = consumeInt(bool.hashCode())
30+
31+
actual fun consume(c: Char) = consumeInt(c.hashCode())
32+
33+
actual fun consume(b: Byte) = consumeInt(b.hashCode())
34+
35+
actual fun consume(s: Short) = consumeInt(s.hashCode())
36+
37+
actual fun consume(i: Int) = consumeInt(i.hashCode())
38+
39+
actual fun consume(l: Long) = consumeInt(l.hashCode())
40+
41+
actual fun consume(f: Float) = consumeInt(f.hashCode())
42+
43+
actual fun consume(d: Double) = consumeInt(d.hashCode())
44+
}
45+
46+
47+
@KotlinxBenchmarkRuntimeInternalApi
48+
actual fun Blackhole.flush() = flushMe()

runtime/wasmJsMain/src/kotlinx/benchmark/WasmBlackhole.kt

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)