PageRenderTime 18ms CodeModel.GetById 2ms app.highlight 12ms RepoModel.GetById 1ms app.codeStats 0ms

/js/src/jsgcstats.cpp

http://github.com/zpao/v8monkey
C++ | 162 lines | 110 code | 15 blank | 37 comment | 11 complexity | 5b5bddbaf5bdf929f3d12b35deecab43 MD5 | raw file
  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#include "mozilla/Util.h"
 40
 41#include "jstypes.h"
 42#include "jscntxt.h"
 43#include "jsgcstats.h"
 44#include "jsgc.h"
 45#include "jsxml.h"
 46#include "jscompartment.h"
 47
 48#include "jsgcinlines.h"
 49#include "jsobjinlines.h"
 50
 51using namespace mozilla;
 52using namespace js;
 53using namespace js::gc;
 54
 55#define UL(x)       ((unsigned long)(x))
 56#define PERCENT(x,y)  (100.0 * (double) (x) / (double) (y))
 57
 58namespace js {
 59namespace gc {
 60
 61#if defined(JS_DUMP_CONSERVATIVE_GC_ROOTS)
 62
 63void
 64ConservativeGCStats::dump(FILE *fp)
 65{
 66    size_t words = 0;
 67    for (size_t i = 0; i < ArrayLength(counter); ++i)
 68        words += counter[i];
 69   
 70#define ULSTAT(x)       ((unsigned long)(x))
 71    fprintf(fp, "CONSERVATIVE STACK SCANNING:\n");
 72    fprintf(fp, "      number of stack words: %lu\n", ULSTAT(words));
 73    fprintf(fp, "      excluded, low bit set: %lu\n", ULSTAT(counter[CGCT_LOWBITSET]));
 74    fprintf(fp, "        not withing a chunk: %lu\n", ULSTAT(counter[CGCT_NOTCHUNK]));
 75    fprintf(fp, "     not within arena range: %lu\n", ULSTAT(counter[CGCT_NOTARENA]));
 76    fprintf(fp, "     in another compartment: %lu\n", ULSTAT(counter[CGCT_OTHERCOMPARTMENT]));
 77    fprintf(fp, "       points to free arena: %lu\n", ULSTAT(counter[CGCT_FREEARENA]));
 78    fprintf(fp, "         excluded, not live: %lu\n", ULSTAT(counter[CGCT_NOTLIVE]));
 79    fprintf(fp, "            valid GC things: %lu\n", ULSTAT(counter[CGCT_VALID]));
 80    fprintf(fp, "      valid but not aligned: %lu\n", ULSTAT(unaligned));
 81#undef ULSTAT
 82}
 83#endif
 84
 85} //gc
 86
 87#ifdef JS_DUMP_CONSERVATIVE_GC_ROOTS
 88void
 89GCMarker::dumpConservativeRoots()
 90{
 91    if (!conservativeDumpFileName)
 92        return;
 93
 94    FILE *fp;
 95    if (!strcmp(conservativeDumpFileName, "stdout")) {
 96        fp = stdout;
 97    } else if (!strcmp(conservativeDumpFileName, "stderr")) {
 98        fp = stderr;
 99    } else if (!(fp = fopen(conservativeDumpFileName, "aw"))) {
100        fprintf(stderr,
101                "Warning: cannot open %s to dump the conservative roots\n",
102                conservativeDumpFileName);
103        return;
104    }
105
106    conservativeStats.dump(fp);
107
108    for (void **thingp = conservativeRoots.begin(); thingp != conservativeRoots.end(); ++thingp) {
109        void *thing = thingp;
110        fprintf(fp, "  %p: ", thing);
111
112        switch (GetGCThingTraceKind(thing)) {
113          case JSTRACE_OBJECT: {
114            JSObject *obj = (JSObject *) thing;
115            fprintf(fp, "object %s", obj->getClass()->name);
116            break;
117          }
118          case JSTRACE_STRING: {
119            JSString *str = (JSString *) thing;
120            if (str->isLinear()) {
121                char buf[50];
122                PutEscapedString(buf, sizeof buf, &str->asLinear(), '"');
123                fprintf(fp, "string %s", buf);
124            } else {
125                fprintf(fp, "rope: length %d", (int)str->length());
126            }
127            break;
128          }
129          case JSTRACE_SCRIPT: {
130            fprintf(fp, "shape");
131            break;
132          }
133          case JSTRACE_SHAPE: {
134            fprintf(fp, "shape");
135            break;
136          }
137          case JSTRACE_BASE_SHAPE: {
138            fprintf(fp, "base_shape");
139            break;
140          }
141          case JSTRACE_TYPE_OBJECT: {
142            fprintf(fp, "type_object");
143            break;
144          }
145# if JS_HAS_XML_SUPPORT
146          case JSTRACE_XML: {
147            JSXML *xml = (JSXML *) thing;
148            fprintf(fp, "xml %u", (unsigned)xml->xml_class);
149            break;
150          }
151# endif
152        }
153        fputc('\n', fp);
154    }
155    fputc('\n', fp);
156
157    if (fp != stdout && fp != stderr)
158        fclose(fp);
159}
160#endif /* JS_DUMP_CONSERVATIVE_GC_ROOTS */
161
162} /* namespace js */