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);
Name | Type | Description |
---|---|---|
cx | JSContext * | A context. The GC zeal level of the associated JSRuntime is set. |
zeal | uint8_t | The desired level of garbage collection. |
frequency | uint32_t | With 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 level | Description |
---|---|
0 | Normal amount of collection. The default: no additional collections are performed. |
1 | Collect when roots are added or removed. |
2 | Collect when every frequency allocations. |
3 | Collect on window paints. |
4 | Verify pre write barriers between instructions. |
5 | Verify pre write barriers between window paints. |
6 | Verify stack rooting. |
7 | Collect the nursery every frequency nursery allocations. |
8 | Incremental GC in two slices: 1) mark roots 2) finish collection. |
9 | Incremental GC in two slices: 1) mark all 2) new marking and finish. |
10 | Incremental GC in multiple slices. |
11 | Verify post write barriers between instructions. |
12 | Verify post write barriers between paints. |
13 | Check internal hashtables on minor GC. |
14 | Perform 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论