Skip to content
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

Closed
wants to merge 2 commits into from
Closed

Conversation

yuyichao
Copy link
Contributor

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)

@JeffBezanson
Copy link
Sponsor Member

Can we close this?

@yuyichao
Copy link
Contributor Author

yuyichao commented Dec 4, 2015

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 ccalls of pointers).

@JeffBezanson
Copy link
Sponsor Member

Does this distinguish null julia references from other null pointers? I'm not sure we want to turn all null dereferences into exceptions.

@yuyichao
Copy link
Contributor Author

yuyichao commented Dec 5, 2015

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.

@JeffBezanson
Copy link
Sponsor Member

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?

@vtjnash
Copy link
Sponsor Member

vtjnash commented Dec 29, 2015

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

@JeffBezanson
Copy link
Sponsor Member

Actually, is an LLVM program that dereferences NULL guaranteed to raise segv, or is it undefined?

@Keno
Copy link
Member

Keno commented Dec 31, 2015

It's guaranteed to raise SEGV. Also, as an extra point of reference see http://llvm.org/docs/FaultMaps.html.

@JeffBezanson
Copy link
Sponsor Member

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.

@Keno
Copy link
Member

Keno commented Dec 31, 2015

Yes, I think that would be a good idea. It's new in 3.8 though, so we'll have to wait a bit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:error handling Handling of exceptions by Julia or the user
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants