Why `Intrinsics.checkParameterIsNotNull` is not inlined?


In Kotlin, if we decompile some Kotlin bytecode to Java, we can often see this statement which does null checks:

Intrinsics.checkParameterIsNotNull(foo, "foo")

If we explore furthur, we can see the decompiled implementation of this method, it’s implementation is exactly the same as it’s name:

public static void checkParameterIsNotNull(Object value, String paramName) {
	if (value == null) {

Due to the existense of this class (Intrinsics), I can’t use Kotlin without the stdlib, even if I tried my best to avoid using functions from stdlib, it automatically generates calls to Intrinsics.checkParameterIsNotNull.

Since the implementation of this method is very short (and appears very very often), why isn’t this function inlined?

Is there some annotations that allow us to prevent Kotlin compiler from generating this null check? (maybe something like @TrustedNotNull)


Corresponding StackOverflow question:https://stackoverflow.com/questions/47844098/why-intrinsics-checkparameterisnotnull-is-not-inlined


The main reason probably is efficiency. JIT will inline this method if necessary, otherwise method call is shorter than comparison and throwing exception.

I don’t think that using Kotlin without stdlib is supported use-case. This problem could easily be solved with creating your own jar with this class and substituting it at runtime, but I’m sure that there will be more difficult problems.


Could you explain that or point me to an article? I have no idea how a method call could ever be shorter, since it still performs the same operations?

btw @ice1000 theres a compiler option for avoiding these, see here: https://stackoverflow.com/questions/31723143/kotlin-uses-runtime-assertions-for-null-checking-performance-overhead/31723265#31723265