aboutsummaryrefslogtreecommitdiff
path: root/files/ja/mozilla/projects/spidermonkey/jsapi_reference/js_setgczeal/index.html
blob: 0be58ee8dc1d3710907f1e2280caab836d417616 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
---
title: JS_SetGCZeal
slug: Mozilla/Projects/SpiderMonkey/JSAPI_reference/JS_SetGCZeal
tags:
  - JSAPI Reference
  - SpiderMonkey
translation_of: Mozilla/Projects/SpiderMonkey/JSAPI_reference/JS_SetGCZeal
---
<div>{{SpiderMonkeySidebar("JSAPI")}}</div>

<div>{{jsapi_minversion_header("1.8")}}</div>

<div class="summary">
<p>GC の活動量、JSAPI アプリケーションの GC 関連のバグを見つけるのに役立つテストおよびデバッグ機能を有効にします。</p>
</div>

<h2 id="Syntax" name="Syntax">構文</h2>

<pre class="brush: cpp">void
JS_SetGCZeal(JSContext *cx, uint8_t zeal, uint32_t frequency);
</pre>

<table class="fullwidth-table">
 <tbody>
  <tr>
   <th>Name</th>
   <th>Type</th>
   <th>Description</th>
  </tr>
  <tr>
   <td><code>cx</code></td>
   <td>{{jsapixref("JSRuntime", "JSContext *")}}</td>
   <td>A context. The GC zeal level of the associated {{jsapixref("JSRuntime")}} is set.</td>
  </tr>
  <tr>
   <td><code>zeal</code></td>
   <td><code>uint8_t</code></td>
   <td>The desired level of garbage collection.</td>
  </tr>
  <tr>
   <td><code>frequency</code></td>
   <td><code>uint32_t</code></td>
   <td>With some zeal levels, a GC is triggered every <code>frequency</code> allocations.</td>
  </tr>
 </tbody>
</table>

<h2 id="Description" name="Description">説明</h2>

<p><strong><code>JS_SetGCZeal</code></strong> sets the level of additional garbage collection to perform for a runtime, for the purpose of finding or reproducing bugs.</p>

<p>There are several different levels which have different functions:</p>

<table class="fullwidth-table">
 <thead>
  <tr>
   <th scope="col">Zeal level</th>
   <th scope="col">Description</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>0</td>
   <td>Normal amount of collection.  The default: no additional collections are performed.</td>
  </tr>
  <tr>
   <td>1</td>
   <td>Collect when roots are added or removed.</td>
  </tr>
  <tr>
   <td>2</td>
   <td>Collect when every <code>frequency</code> allocations.</td>
  </tr>
  <tr>
   <td>3</td>
   <td>Collect on window paints.</td>
  </tr>
  <tr>
   <td>4</td>
   <td>Verify pre write barriers between instructions.</td>
  </tr>
  <tr>
   <td>5</td>
   <td>Verify pre write barriers between window paints.</td>
  </tr>
  <tr>
   <td>6</td>
   <td>Verify stack rooting.</td>
  </tr>
  <tr>
   <td>7</td>
   <td>Collect the nursery every <code>frequency</code> nursery allocations.</td>
  </tr>
  <tr>
   <td>8</td>
   <td>Incremental GC in two slices: 1) mark roots 2) finish collection.</td>
  </tr>
  <tr>
   <td>9</td>
   <td>Incremental GC in two slices: 1) mark all 2) new marking and finish.</td>
  </tr>
  <tr>
   <td>10</td>
   <td>Incremental GC in multiple slices.</td>
  </tr>
  <tr>
   <td>11</td>
   <td>Verify post write barriers between instructions.</td>
  </tr>
  <tr>
   <td>12</td>
   <td>Verify post write barriers between paints.</td>
  </tr>
  <tr>
   <td>13</td>
   <td>Check internal hashtables on minor GC.</td>
  </tr>
  <tr>
   <td>14</td>
   <td>Perform a shrinking collection every <code>frequency</code> allocations.</td>
  </tr>
 </tbody>
</table>

<p>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.</p>

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

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

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

<h2 id="See_Also" name="See_Also">あわせて参照</h2>

<ul>
 <li>{{LXRSearch("ident", "i", "JS_SetGCZeal")}}</li>
 <li>{{LXRSearch("ident", "i", "JS_GC_ZEAL")}}</li>
 <li>{{jsapixref("JS_ScheduleGC")}}</li>
 <li>{{bug(308429)}}</li>
 <li>{{bug(650978)}}</li>
</ul>