Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upMake runtime creation safe #450
Conversation
added a commit
to servo/servo
that referenced
this pull request
Dec 2, 2018
jdm
force-pushed the
jdm:parent-refactor
branch
from
bdd6e09
to
d0a6288
Dec 2, 2018
This comment has been minimized.
This comment has been minimized.
There is one hole that I've come up with so far - while the assertion in the Runtime drop implementation catches the point at which a parent runtime is dropped before all of its children are dropped, that only interrupts the thread on which the parent runtime is executing. The threads on which any child runtimes are executing have no signal that their parent runtime is now invalid. The best choice at this point would be to abort the whole program for the sake of safety, but this PR does not do that right now. |
jdm
force-pushed the
jdm:parent-refactor
branch
2 times, most recently
from
5c26260
to
ac7f350
Dec 2, 2018
emilio
reviewed
Dec 2, 2018
jdm
force-pushed the
jdm:parent-refactor
branch
from
ac7f350
to
69cfd4a
Dec 3, 2018
jdm
force-pushed the
jdm:parent-refactor
branch
2 times, most recently
from
d10b181
to
6e9cc73
Dec 21, 2018
This comment has been minimized.
This comment has been minimized.
I fixed the racing issues by switching to a single mutex around an enum that represents the engine state. This is ready for review. |
This comment has been minimized.
This comment has been minimized.
r? @asajeffrey |
asajeffrey
reviewed
Dec 21, 2018
Mostly nits, the main thing is it looks like you're assuming the |
@@ -42,9 +44,9 @@ doctest = false | |||
|
|||
[features] | |||
debugmozjs = ['mozjs_sys/debugmozjs'] | |||
init_once = [] |
This comment has been minimized.
This comment has been minimized.
impl Drop for JSEngine { | ||
fn drop(&mut self) { | ||
*ENGINE_STATE.lock().unwrap() = EngineState::ShutDown; | ||
unsafe { |
This comment has been minimized.
This comment has been minimized.
/// runtime can be dropped. | ||
pub struct ParentRuntime { | ||
parent: *mut JSRuntime, | ||
count: Arc<AtomicU32>, |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
asajeffrey
Dec 21, 2018
Member
Also, looking through the code it looks like the counter is incremented when the arc is cloned, and decremented when the arc is dropped, so the counter is always the same as the refcount. This makes me suspect that there's a simplification, where ParentRuntime
just contains an Arc<JSEngine>
or some such.
/// Unsafety: | ||
/// If panicking does not abort the program, any threads with child runtimes will | ||
/// continue executing after the thread with the parent runtime panics, but they | ||
/// will be in an invalid and undefined state. |
This comment has been minimized.
This comment has been minimized.
asajeffrey
Dec 21, 2018
Member
Hmm, this might be an issue for Servo when we do crash reporting? Not sure what we can do though, other than not put any JS on our crash reporting page and hope for the best.
jdm
referenced this pull request
Dec 21, 2018
Closed
Add some tests for default-initialized roots #411
This comment has been minimized.
This comment has been minimized.
@asajeffrey Review comments addressed. I've added more comments around the adjusted refcounting bits to hopefully make clear why it looks weird. |
This comment has been minimized.
This comment has been minimized.
LGTM. Squash and r=me? |
jdm
force-pushed the
jdm:parent-refactor
branch
from
60ab9de
to
5e3c3ba
Jan 14, 2019
This comment has been minimized.
This comment has been minimized.
@bors-servo r=asajeffrey |
This comment has been minimized.
This comment has been minimized.
|
This comment has been minimized.
This comment has been minimized.
added a commit
that referenced
this pull request
Jan 14, 2019
jdm
force-pushed the
jdm:parent-refactor
branch
from
5e3c3ba
to
3e1ef3c
Jan 14, 2019
jdm
added some commits
Dec 2, 2018
jdm
force-pushed the
jdm:parent-refactor
branch
from
3e1ef3c
to
981e266
Jan 14, 2019
This comment has been minimized.
This comment has been minimized.
@bors-servo r=asajeffrey |
This comment has been minimized.
This comment has been minimized.
|
This comment has been minimized.
This comment has been minimized.
added a commit
that referenced
this pull request
Jan 14, 2019
This comment has been minimized.
This comment has been minimized.
|
jdm commentedDec 2, 2018
•
edited by larsbergstrom
The fundamental problem exposed in servo/servo#22342 is that our concept of a parent runtime did not match reality. Using the first JSContext's runtime as the global parent for all subsequent contexts only makes sense if that JSContext outlives every other context. This is not guaranteed, leading to crashes when trying to use those contexts if the first context (and therefore its runtime) was destroyed.
The new design incorporates several changes for safer, more clear context and runtime management:
This change is