Hey! I'm running a JVM server with `-disableassert...
# compiler
c
Hey! I'm running a JVM server with
-disableassertions
under the profiler and I think the compiler isn't organizing the assertion code correctly. As you can see, the profiler is able to measure a hot spot in the assertion evaluation even though it is not evaluated (even if it fails, nothing happens, as expected). I would expect the compiler to emit bytecode such that the JVM completely skips the entire expression if assertions are disabled (which is what Java does).
j
Is your Kotlin compiled with
-Xassertions=jvm
?
c
If it's not the default, then no. Let me try it.
j
It is not the default
c
I still see the same result
Working here. Without the flag the conditional is done before the assertions enabled check. With the flag the order is the opposite.
c
I've added a simple
Copy code
object AssertionUtils {
    val areAssertionsEnabled = this.javaClass.desiredAssertionStatus()
}

inline fun assert(message: () -> String, block: () -> Boolean) {
    if (AssertionUtils.areAssertionsEnabled) {
        if (!block()) {
            throw AssertionError(message())
        }
    }
}
and that way I don't see the intermediate expressions being executed