3 ms·
> In Java, the compiler inserts null checks before every single dereference and throws an exception for null references. Doesn't OpenJDK install a SIGSEGV hand
by remexre 3y ago
> In Java, the compiler inserts null checks before every single dereference and throws an exception for null references.
Doesn't OpenJDK install a SIGSEGV handler, and generate the exception from that on a null dereference?
(AFAIK, a lot of runtimes for GC'd languages that support thread-based parallelism do so anyway, because they can use mprotect to do a write barrier in hardware.)
- trealira 3y ago> Doesn't OpenJDK install a SIGSEGV handler, and generate the exception from that on a null dereference? I thought I had read that they explicitly don't do that, but I can't find it anymore. You may be right. I should have checked before saying that. > (AFAIK, a lot of runtimes for GC'd languages that support thread-based parallelism do so anyway, because they can use mprotect to do a write barrier in hardware.) That's true. I guess those implementations must do something more advanced than "throw a NullPointerException if the program segfaults," given their garbage collector runtimes also rely on that signal.
- vips7L 3y ago> I thought I had read that they explicitly don't do that This is exactly what they do: https://shipilev.net/jvm/anatomy-quarks/25-implicit-null-checks/ https://shipilev.net/jvm/anatomy-quarks/25-implicit-null-che... When this happens it'll cause a deoptimization and recompilation of the code to include the null check rather than rely on the signal handler repeatedly.
- trealira 3y agoThanks for the link!