JS_SetGCZeal 编辑

This article covers features introduced in SpiderMonkey 1.8

Enable GC zeal, a testing and debugging feature that helps find GC-related bugs in JSAPI applications.

Syntax

void
JS_SetGCZeal(JSContext *cx, uint8_t zeal, uint32_t frequency);
NameTypeDescription
cxJSContext *A context. The GC zeal level of the associated JSRuntime is set.
zealuint8_tThe desired level of garbage collection.
frequencyuint32_tWith some zeal levels, a GC is triggered every frequency allocations.

Description

JS_SetGCZeal sets the level of additional garbage collection to perform for a runtime, for the purpose of finding or reproducing bugs.

There are several different levels which have different functions:

Zeal levelDescription
0Normal amount of collection.  The default: no additional collections are performed.
1Collect when roots are added or removed.
2Collect when every frequency allocations.
3Collect on window paints.
4Verify pre write barriers between instructions.
5Verify pre write barriers between window paints.
6Verify stack rooting.
7Collect the nursery every frequency nursery allocations.
8Incremental GC in two slices: 1) mark roots 2) finish collection.
9Incremental GC in two slices: 1) mark all 2) new marking and finish.
10Incremental GC in multiple slices.
11Verify post write barriers between instructions.
12Verify post write barriers between paints.
13Check internal hashtables on minor GC.
14Perform a shrinking collection every frequency allocations.

With GC zeal enabled, GC-related crashes are much easier to reproduce (they happen more reliably) and debug (they happen sooner, closer to the source of the bug). The drawback is that GC zeal can cause JavaScript code to run extremely slowly.

Regularly running your test suite with GC zeal enabled at level 2 is a good practice.

This function is available only in DEBUG builds. To enable this function in an optimized build, define the macro JS_GC_ZEAL building SpiderMonkey.

(In a debug build of Gecko, you can also set the current GC zeal level using the javascript.options.gczeal preference.)

See Also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:62 次

字数:4428

最后编辑:6年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文