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