New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Raise UndefRefError using SegFault handler #14147
Conversation
17c4c8a
to
0ccdee5
Compare
0ccdee5
to
eafd435
Compare
Can we close this? |
This was mainly an experiment before relying on the seg fault handler for gc synchronization. It does reduce the code generated for the undef ref check (especially for |
Does this distinguish null julia references from other null pointers? I'm not sure we want to turn all null dereferences into exceptions. |
Not it doesn't distinguish them. What's the issue with turning null pointer dereferences into exceptions in general? There isn't anything better whoever causing it can expect anyway since we are overwriting the signal handler. |
I admit it would be nice to avoid generating null-check code. If we do this, maybe there should be a build time option, or switch of some kind, to select whether signals are used for this? I suspect we might want to retain a version of the language that doesn't require signal handlers, but I could be wrong. @vtjnash what do you think? |
we probably want to maintain a version that can avoid signals for easier porting to unusual environments. obviously that has different build-time codegen requirements, so it might be some sort of switch. i suspect that code will bit-rot pretty quickly (although minimally) without any real use / test case |
Actually, is an LLVM program that dereferences NULL guaranteed to raise segv, or is it undefined? |
It's guaranteed to raise SEGV. Also, as an extra point of reference see http://llvm.org/docs/FaultMaps.html. |
Cool! Do you think we should actually use the ImplicitNullChecks pass and fault maps? At least for now we know we can do this safely, but we should retain a build time option. |
Yes, I think that would be a good idea. It's new in 3.8 though, so we'll have to wait a bit. |
30223f6
to
aad2781
Compare
e378290
to
1f1575a
Compare
1f1575a
to
04fac72
Compare
04fac72
to
126b3bd
Compare
Now that we have #11691 (hopefully) sorted out we can try to use
SIGSEGV
to do other useful things.The main reason for this PR is to check if we can reliably trigger SegFault on a load and throw an exception from the signal handler, which we might use for thread-safe GC safepoint.
I originally tried to omit the comparison and use the load both as a null pointer check and as a way to throw the exception. However, it seems that the memory read overhead is quick significant and it causes a measureable slow down in certain cases (up to 15%).
@vtjnash (sorry for stealing something you always wanted to implement but it seems that this is a perfect test for the GC safepoint implementation)