I'm using the ExecutionSample event from HotSpot in OpenJDK11.
It has a field for thread state, but I only ever see one value for the field: STATE_RUNNABLE
How does HotSpot choose which threads to sample? Why are they always runnable?
Simple reproduction code in Kotlin:
import jdk.jfr.Recording
import jdk.jfr.consumer.RecordingFile
import java.nio.file.Path
object ExecutionSampleTest {
private const val EXECUTION_SAMPLE = "jdk.ExecutionSample"
private val RECORDING_PATH = Path.of("/tmp/recording.jfr")
@JvmStatic
fun main(args: Array<String>) {
Recording().use { recording ->
recording.enable(EXECUTION_SAMPLE)
recording.settings = recording.settings.plus("$EXECUTION_SAMPLE#period" to "1 ms")
recording.start()
repeat(100) {
// start some sleeping threads, just so we've got something to sample
Thread { Thread.sleep(20_000) }.start()
}
Thread.sleep(20_000)
recording.stop()
recording.dump(RECORDING_PATH)
RecordingFile.readAllEvents(RECORDING_PATH).forEach {
println("Thread state: ${it.getString("state")}")
}
}
}
}
Only ever prints: Thread state: STATE_RUNNABLE