Imported Upstream version 1.0.0
[platform/upstream/js.git] / js / src / jsgcstats.h
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2  * vim: set ts=4 sw=4 et tw=99 ft=cpp:
3  *
4  * ***** BEGIN LICENSE BLOCK *****
5  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6  *
7  * The contents of this file are subject to the Mozilla Public License Version
8  * 1.1 (the "License"); you may not use this file except in compliance with
9  * the License. You may obtain a copy of the License at
10  * http://www.mozilla.org/MPL/
11  *
12  * Software distributed under the License is distributed on an "AS IS" basis,
13  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14  * for the specific language governing rights and limitations under the
15  * License.
16  *
17  * The Original Code is Mozilla SpiderMonkey JavaScript 1.9 code, released
18  * June 30, 2010
19  *
20  * The Initial Developer of the Original Code is
21  *   the Mozilla Corporation.
22  *
23  * Contributor(s):
24  *
25  * Alternatively, the contents of this file may be used under the terms of
26  * either of the GNU General Public License Version 2 or later (the "GPL"),
27  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28  * in which case the provisions of the GPL or the LGPL are applicable instead
29  * of those above. If you wish to allow use of your version of this file only
30  * under the terms of either the GPL or the LGPL, and not to allow others to
31  * use your version of this file under the terms of the MPL, indicate your
32  * decision by deleting the provisions above and replace them with the notice
33  * and other provisions required by the GPL or the LGPL. If you do not delete
34  * the provisions above, a recipient may use your version of this file under
35  * the terms of any one of the MPL, the GPL or the LGPL.
36  *
37  * ***** END LICENSE BLOCK ***** */
38
39 #ifndef jsgcstats_h___
40 #define jsgcstats_h___
41
42 #if !defined JS_DUMP_CONSERVATIVE_GC_ROOTS && defined DEBUG
43 # define JS_DUMP_CONSERVATIVE_GC_ROOTS 1
44 #endif
45
46 /* Define JS_GCMETER here if wanted */
47 #if defined JS_GCMETER
48 const bool JS_WANT_GC_METER_PRINT = true;
49 const bool JS_WANT_GC_PER_COMPARTMENT_PRINT = true;
50 const bool JS_WANT_CONSERVATIVE_GC_PRINT = true;
51 #elif defined DEBUG
52 # define JS_GCMETER 1
53 const bool JS_WANT_GC_METER_PRINT = false;
54 const bool JS_WANT_GC_PER_COMPARTMENT_PRINT = false;
55 const bool JS_WANT_CONSERVATIVE_GC_PRINT = false;
56 #endif
57
58 namespace js {
59 namespace gc {
60 /*
61  * The conservative GC test for a word shows that it is either a valid GC
62  * thing or is not for one of the following reasons.
63  */
64 enum ConservativeGCTest {
65     CGCT_VALID,
66     CGCT_VALIDWITHOFFSET, /* points within an object */
67     CGCT_LOWBITSET, /* excluded because one of the low bits was set */
68     CGCT_NOTARENA,  /* not within arena range in a chunk */
69     CGCT_NOTCHUNK,  /* not within a valid chunk */
70     CGCT_FREEARENA, /* within arena containing only free things */
71     CGCT_WRONGTAG,  /* tagged pointer but wrong type */
72     CGCT_NOTLIVE,   /* gcthing is not allocated */
73     CGCT_END
74 };
75
76 struct ConservativeGCStats {
77     uint32  counter[gc::CGCT_END];  /* ConservativeGCTest classification
78                                    counters */
79
80     void add(const ConservativeGCStats &another) {
81         for (size_t i = 0; i != JS_ARRAY_LENGTH(counter); ++i)
82             counter[i] += another.counter[i];
83     }
84
85     void dump(FILE *fp);
86 };
87
88 #ifdef JS_GCMETER
89 struct JSGCArenaStats {
90     uint32  alloc;          /* allocation attempts */
91     uint32  localalloc;     /* allocations from local lists */
92     uint32  nthings;        /* live GC things */
93     uint32  maxthings;      /* maximum of live GC cells */
94     double  totalthings;    /* live GC things the GC scanned so far */
95     uint32  narenas;        /* number of arena in list before the GC */
96     uint32  newarenas;      /* new arenas allocated before the last GC */
97     uint32  livearenas;     /* number of live arenas after the last GC */
98     uint32  maxarenas;      /* maximum of allocated arenas */
99     uint32  totalarenas;    /* total number of arenas with live things that
100                                GC scanned so far */
101 };
102 #endif
103
104 #ifdef JS_GCMETER
105
106 struct JSGCStats {
107     uint32  lock;       /* valid lock calls */
108     uint32  unlock;     /* valid unlock calls */
109     uint32  unmarked;   /* number of times marking of GC thing's children were
110                            delayed due to a low C stack */
111     uint32  lastditch;  /* number of times the last ditch GC run */
112     uint32  fail;       /* allocation failures */
113 #ifdef DEBUG
114     uint32  maxunmarked;/* maximum number of things with children to mark
115                            later */
116 #endif
117     uint32  poke;           /* number of potentially useful GC calls */
118     uint32  afree;          /* thing arenas freed so far */
119     uint32  nallarenas;     /* number of all allocated arenas */
120     uint32  maxnallarenas;  /* maximum number of all allocated arenas */
121     uint32  nchunks;        /* number of allocated chunks */
122     uint32  maxnchunks;     /* maximum number of allocated chunks */
123
124     ConservativeGCStats conservative;
125 };
126
127 extern void
128 UpdateCompartmentStats(JSCompartment *comp, unsigned thingKind, uint32 nlivearenas,
129                        uint32 nkilledArenas, uint32 nthings);
130 #endif /* JS_GCMETER */
131
132 #if defined JS_DUMP_CONSERVATIVE_GC_ROOTS
133 void *GetAlignedThing(void *thing, int thingKind);
134 #endif
135
136 } //gc
137
138 #ifdef MOZ_GCTIMER
139
140 const bool JS_WANT_GC_SUITE_PRINT = false;  //false for gnuplot output
141
142 extern jsrefcount newChunkCount;
143 extern jsrefcount destroyChunkCount;
144
145 struct GCTimer {
146     uint64 enter;
147     uint64 startMark;
148     uint64 startSweep;
149     uint64 sweepObjectEnd;
150     uint64 sweepStringEnd;
151     uint64 sweepShapeEnd;
152     uint64 sweepDestroyEnd;
153     uint64 end;
154
155     GCTimer();
156
157     uint64 getFirstEnter();
158
159     void finish(bool lastGC);
160 };
161
162 # define GCTIMER_PARAM      , GCTimer &gcTimer
163 # define GCTIMER_ARG        , gcTimer
164 # define TIMESTAMP(x)       (gcTimer.x = rdtsc())
165 # define GCTIMER_BEGIN()    GCTimer gcTimer
166 # define GCTIMER_END(last)  (gcTimer.finish(last))
167 #else
168 # define GCTIMER_PARAM
169 # define GCTIMER_ARG
170 # define TIMESTAMP(x)       ((void) 0)
171 # define GCTIMER_BEGIN()    ((void) 0)
172 # define GCTIMER_END(last)  ((void) 0)
173 #endif
174
175 } //js
176
177 extern JS_FRIEND_API(void)
178 js_DumpGCStats(JSRuntime *rt, FILE *fp);
179
180 #endif /* jsgcstats_h__ */