Garbage collector issues on spidermonkey… JS_AnchorPtr()?

流过昼夜 提交于 2019-12-01 23:07:40

Well, blame seems to say that bug 519949 is recommending you use js::Anchor so that the conservative stack scanner will pick it up.

Note that the conservative scanner can find any GC thing that's on the stack or in registers, so the only really tricky case is where you use derived values when the "owning" GC thing may be dead, like so:

{
    JSString *str = GetMeSomeStringYo();
    const jschar *chars = str->chars();
    // Note, |str| is not "live" here, but the derived |chars| is!
    // The conservative stack scanner won't see |chars| and know
    // to keep |str| alive, so we should be anchoring |str|.
    DoSomethingThatCanCauseGC();
    return chars[0];
}

If you're using C the JS_AnchorPtr at the end of the functions should be enough. You are correct that the function has a nop implementation! The idea is that, so long as it's performing a call to a shared object symbol with the variable to keep alive as a parameter, the calling function will have to keep that value around in machine state in order to perform the do-nothing call. This is more sucky for perf than js::Anchor.

There's one potential trap in the unlikely case that you're statically linking against SpiderMonkey and have Link Time Optimization enabled: the cross-object call may be inlined with a null implementation, eliminating liveness of the variable, in which case the same GC hazards may pop back up.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!