libv8 3.3.10.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (700) hide show
  1. data/.gitignore +8 -0
  2. data/.gitmodules +3 -0
  3. data/Gemfile +4 -0
  4. data/README.md +44 -0
  5. data/Rakefile +73 -0
  6. data/ext/libv8/extconf.rb +9 -0
  7. data/lib/libv8.rb +15 -0
  8. data/lib/libv8/Makefile +38 -0
  9. data/lib/libv8/detect_cpu.rb +27 -0
  10. data/lib/libv8/fpic-on-linux-amd64.patch +13 -0
  11. data/lib/libv8/scons/CHANGES.txt +5334 -0
  12. data/lib/libv8/scons/LICENSE.txt +20 -0
  13. data/lib/libv8/scons/MANIFEST +199 -0
  14. data/lib/libv8/scons/PKG-INFO +13 -0
  15. data/lib/libv8/scons/README.txt +243 -0
  16. data/lib/libv8/scons/RELEASE.txt +98 -0
  17. data/lib/libv8/scons/engine/SCons/Action.py +1241 -0
  18. data/lib/libv8/scons/engine/SCons/Builder.py +877 -0
  19. data/lib/libv8/scons/engine/SCons/CacheDir.py +216 -0
  20. data/lib/libv8/scons/engine/SCons/Conftest.py +793 -0
  21. data/lib/libv8/scons/engine/SCons/Debug.py +220 -0
  22. data/lib/libv8/scons/engine/SCons/Defaults.py +480 -0
  23. data/lib/libv8/scons/engine/SCons/Environment.py +2318 -0
  24. data/lib/libv8/scons/engine/SCons/Errors.py +205 -0
  25. data/lib/libv8/scons/engine/SCons/Executor.py +633 -0
  26. data/lib/libv8/scons/engine/SCons/Job.py +435 -0
  27. data/lib/libv8/scons/engine/SCons/Memoize.py +244 -0
  28. data/lib/libv8/scons/engine/SCons/Node/Alias.py +152 -0
  29. data/lib/libv8/scons/engine/SCons/Node/FS.py +3142 -0
  30. data/lib/libv8/scons/engine/SCons/Node/Python.py +128 -0
  31. data/lib/libv8/scons/engine/SCons/Node/__init__.py +1328 -0
  32. data/lib/libv8/scons/engine/SCons/Options/BoolOption.py +50 -0
  33. data/lib/libv8/scons/engine/SCons/Options/EnumOption.py +50 -0
  34. data/lib/libv8/scons/engine/SCons/Options/ListOption.py +50 -0
  35. data/lib/libv8/scons/engine/SCons/Options/PackageOption.py +50 -0
  36. data/lib/libv8/scons/engine/SCons/Options/PathOption.py +76 -0
  37. data/lib/libv8/scons/engine/SCons/Options/__init__.py +67 -0
  38. data/lib/libv8/scons/engine/SCons/PathList.py +231 -0
  39. data/lib/libv8/scons/engine/SCons/Platform/__init__.py +241 -0
  40. data/lib/libv8/scons/engine/SCons/Platform/aix.py +69 -0
  41. data/lib/libv8/scons/engine/SCons/Platform/cygwin.py +55 -0
  42. data/lib/libv8/scons/engine/SCons/Platform/darwin.py +46 -0
  43. data/lib/libv8/scons/engine/SCons/Platform/hpux.py +46 -0
  44. data/lib/libv8/scons/engine/SCons/Platform/irix.py +44 -0
  45. data/lib/libv8/scons/engine/SCons/Platform/os2.py +58 -0
  46. data/lib/libv8/scons/engine/SCons/Platform/posix.py +263 -0
  47. data/lib/libv8/scons/engine/SCons/Platform/sunos.py +50 -0
  48. data/lib/libv8/scons/engine/SCons/Platform/win32.py +385 -0
  49. data/lib/libv8/scons/engine/SCons/SConf.py +1030 -0
  50. data/lib/libv8/scons/engine/SCons/SConsign.py +383 -0
  51. data/lib/libv8/scons/engine/SCons/Scanner/C.py +132 -0
  52. data/lib/libv8/scons/engine/SCons/Scanner/D.py +73 -0
  53. data/lib/libv8/scons/engine/SCons/Scanner/Dir.py +109 -0
  54. data/lib/libv8/scons/engine/SCons/Scanner/Fortran.py +316 -0
  55. data/lib/libv8/scons/engine/SCons/Scanner/IDL.py +48 -0
  56. data/lib/libv8/scons/engine/SCons/Scanner/LaTeX.py +384 -0
  57. data/lib/libv8/scons/engine/SCons/Scanner/Prog.py +101 -0
  58. data/lib/libv8/scons/engine/SCons/Scanner/RC.py +55 -0
  59. data/lib/libv8/scons/engine/SCons/Scanner/__init__.py +413 -0
  60. data/lib/libv8/scons/engine/SCons/Script/Interactive.py +384 -0
  61. data/lib/libv8/scons/engine/SCons/Script/Main.py +1334 -0
  62. data/lib/libv8/scons/engine/SCons/Script/SConsOptions.py +939 -0
  63. data/lib/libv8/scons/engine/SCons/Script/SConscript.py +640 -0
  64. data/lib/libv8/scons/engine/SCons/Script/__init__.py +412 -0
  65. data/lib/libv8/scons/engine/SCons/Sig.py +63 -0
  66. data/lib/libv8/scons/engine/SCons/Subst.py +904 -0
  67. data/lib/libv8/scons/engine/SCons/Taskmaster.py +1017 -0
  68. data/lib/libv8/scons/engine/SCons/Tool/386asm.py +61 -0
  69. data/lib/libv8/scons/engine/SCons/Tool/BitKeeper.py +67 -0
  70. data/lib/libv8/scons/engine/SCons/Tool/CVS.py +73 -0
  71. data/lib/libv8/scons/engine/SCons/Tool/FortranCommon.py +246 -0
  72. data/lib/libv8/scons/engine/SCons/Tool/JavaCommon.py +323 -0
  73. data/lib/libv8/scons/engine/SCons/Tool/MSCommon/__init__.py +56 -0
  74. data/lib/libv8/scons/engine/SCons/Tool/MSCommon/arch.py +61 -0
  75. data/lib/libv8/scons/engine/SCons/Tool/MSCommon/common.py +240 -0
  76. data/lib/libv8/scons/engine/SCons/Tool/MSCommon/netframework.py +82 -0
  77. data/lib/libv8/scons/engine/SCons/Tool/MSCommon/sdk.py +391 -0
  78. data/lib/libv8/scons/engine/SCons/Tool/MSCommon/vc.py +456 -0
  79. data/lib/libv8/scons/engine/SCons/Tool/MSCommon/vs.py +499 -0
  80. data/lib/libv8/scons/engine/SCons/Tool/Perforce.py +103 -0
  81. data/lib/libv8/scons/engine/SCons/Tool/PharLapCommon.py +137 -0
  82. data/lib/libv8/scons/engine/SCons/Tool/RCS.py +64 -0
  83. data/lib/libv8/scons/engine/SCons/Tool/SCCS.py +64 -0
  84. data/lib/libv8/scons/engine/SCons/Tool/Subversion.py +71 -0
  85. data/lib/libv8/scons/engine/SCons/Tool/__init__.py +681 -0
  86. data/lib/libv8/scons/engine/SCons/Tool/aixc++.py +82 -0
  87. data/lib/libv8/scons/engine/SCons/Tool/aixcc.py +74 -0
  88. data/lib/libv8/scons/engine/SCons/Tool/aixf77.py +80 -0
  89. data/lib/libv8/scons/engine/SCons/Tool/aixlink.py +76 -0
  90. data/lib/libv8/scons/engine/SCons/Tool/applelink.py +71 -0
  91. data/lib/libv8/scons/engine/SCons/Tool/ar.py +63 -0
  92. data/lib/libv8/scons/engine/SCons/Tool/as.py +78 -0
  93. data/lib/libv8/scons/engine/SCons/Tool/bcc32.py +81 -0
  94. data/lib/libv8/scons/engine/SCons/Tool/c++.py +99 -0
  95. data/lib/libv8/scons/engine/SCons/Tool/cc.py +102 -0
  96. data/lib/libv8/scons/engine/SCons/Tool/cvf.py +58 -0
  97. data/lib/libv8/scons/engine/SCons/Tool/default.py +50 -0
  98. data/lib/libv8/scons/engine/SCons/Tool/dmd.py +223 -0
  99. data/lib/libv8/scons/engine/SCons/Tool/dvi.py +64 -0
  100. data/lib/libv8/scons/engine/SCons/Tool/dvipdf.py +124 -0
  101. data/lib/libv8/scons/engine/SCons/Tool/dvips.py +94 -0
  102. data/lib/libv8/scons/engine/SCons/Tool/f77.py +62 -0
  103. data/lib/libv8/scons/engine/SCons/Tool/f90.py +62 -0
  104. data/lib/libv8/scons/engine/SCons/Tool/f95.py +63 -0
  105. data/lib/libv8/scons/engine/SCons/Tool/filesystem.py +98 -0
  106. data/lib/libv8/scons/engine/SCons/Tool/fortran.py +62 -0
  107. data/lib/libv8/scons/engine/SCons/Tool/g++.py +90 -0
  108. data/lib/libv8/scons/engine/SCons/Tool/g77.py +73 -0
  109. data/lib/libv8/scons/engine/SCons/Tool/gas.py +53 -0
  110. data/lib/libv8/scons/engine/SCons/Tool/gcc.py +80 -0
  111. data/lib/libv8/scons/engine/SCons/Tool/gfortran.py +64 -0
  112. data/lib/libv8/scons/engine/SCons/Tool/gnulink.py +63 -0
  113. data/lib/libv8/scons/engine/SCons/Tool/gs.py +81 -0
  114. data/lib/libv8/scons/engine/SCons/Tool/hpc++.py +84 -0
  115. data/lib/libv8/scons/engine/SCons/Tool/hpcc.py +53 -0
  116. data/lib/libv8/scons/engine/SCons/Tool/hplink.py +77 -0
  117. data/lib/libv8/scons/engine/SCons/Tool/icc.py +59 -0
  118. data/lib/libv8/scons/engine/SCons/Tool/icl.py +52 -0
  119. data/lib/libv8/scons/engine/SCons/Tool/ifl.py +72 -0
  120. data/lib/libv8/scons/engine/SCons/Tool/ifort.py +88 -0
  121. data/lib/libv8/scons/engine/SCons/Tool/ilink.py +59 -0
  122. data/lib/libv8/scons/engine/SCons/Tool/ilink32.py +60 -0
  123. data/lib/libv8/scons/engine/SCons/Tool/install.py +229 -0
  124. data/lib/libv8/scons/engine/SCons/Tool/intelc.py +482 -0
  125. data/lib/libv8/scons/engine/SCons/Tool/ipkg.py +67 -0
  126. data/lib/libv8/scons/engine/SCons/Tool/jar.py +110 -0
  127. data/lib/libv8/scons/engine/SCons/Tool/javac.py +230 -0
  128. data/lib/libv8/scons/engine/SCons/Tool/javah.py +137 -0
  129. data/lib/libv8/scons/engine/SCons/Tool/latex.py +79 -0
  130. data/lib/libv8/scons/engine/SCons/Tool/lex.py +97 -0
  131. data/lib/libv8/scons/engine/SCons/Tool/link.py +121 -0
  132. data/lib/libv8/scons/engine/SCons/Tool/linkloc.py +112 -0
  133. data/lib/libv8/scons/engine/SCons/Tool/m4.py +63 -0
  134. data/lib/libv8/scons/engine/SCons/Tool/masm.py +77 -0
  135. data/lib/libv8/scons/engine/SCons/Tool/midl.py +88 -0
  136. data/lib/libv8/scons/engine/SCons/Tool/mingw.py +158 -0
  137. data/lib/libv8/scons/engine/SCons/Tool/mslib.py +64 -0
  138. data/lib/libv8/scons/engine/SCons/Tool/mslink.py +266 -0
  139. data/lib/libv8/scons/engine/SCons/Tool/mssdk.py +50 -0
  140. data/lib/libv8/scons/engine/SCons/Tool/msvc.py +268 -0
  141. data/lib/libv8/scons/engine/SCons/Tool/msvs.py +1388 -0
  142. data/lib/libv8/scons/engine/SCons/Tool/mwcc.py +207 -0
  143. data/lib/libv8/scons/engine/SCons/Tool/mwld.py +107 -0
  144. data/lib/libv8/scons/engine/SCons/Tool/nasm.py +72 -0
  145. data/lib/libv8/scons/engine/SCons/Tool/packaging/__init__.py +312 -0
  146. data/lib/libv8/scons/engine/SCons/Tool/packaging/ipk.py +185 -0
  147. data/lib/libv8/scons/engine/SCons/Tool/packaging/msi.py +527 -0
  148. data/lib/libv8/scons/engine/SCons/Tool/packaging/rpm.py +365 -0
  149. data/lib/libv8/scons/engine/SCons/Tool/packaging/src_tarbz2.py +43 -0
  150. data/lib/libv8/scons/engine/SCons/Tool/packaging/src_targz.py +43 -0
  151. data/lib/libv8/scons/engine/SCons/Tool/packaging/src_zip.py +43 -0
  152. data/lib/libv8/scons/engine/SCons/Tool/packaging/tarbz2.py +44 -0
  153. data/lib/libv8/scons/engine/SCons/Tool/packaging/targz.py +44 -0
  154. data/lib/libv8/scons/engine/SCons/Tool/packaging/zip.py +44 -0
  155. data/lib/libv8/scons/engine/SCons/Tool/pdf.py +78 -0
  156. data/lib/libv8/scons/engine/SCons/Tool/pdflatex.py +83 -0
  157. data/lib/libv8/scons/engine/SCons/Tool/pdftex.py +108 -0
  158. data/lib/libv8/scons/engine/SCons/Tool/qt.py +336 -0
  159. data/lib/libv8/scons/engine/SCons/Tool/rmic.py +120 -0
  160. data/lib/libv8/scons/engine/SCons/Tool/rpcgen.py +70 -0
  161. data/lib/libv8/scons/engine/SCons/Tool/rpm.py +132 -0
  162. data/lib/libv8/scons/engine/SCons/Tool/sgiar.py +68 -0
  163. data/lib/libv8/scons/engine/SCons/Tool/sgic++.py +58 -0
  164. data/lib/libv8/scons/engine/SCons/Tool/sgicc.py +53 -0
  165. data/lib/libv8/scons/engine/SCons/Tool/sgilink.py +63 -0
  166. data/lib/libv8/scons/engine/SCons/Tool/sunar.py +67 -0
  167. data/lib/libv8/scons/engine/SCons/Tool/sunc++.py +142 -0
  168. data/lib/libv8/scons/engine/SCons/Tool/suncc.py +58 -0
  169. data/lib/libv8/scons/engine/SCons/Tool/sunf77.py +63 -0
  170. data/lib/libv8/scons/engine/SCons/Tool/sunf90.py +64 -0
  171. data/lib/libv8/scons/engine/SCons/Tool/sunf95.py +64 -0
  172. data/lib/libv8/scons/engine/SCons/Tool/sunlink.py +77 -0
  173. data/lib/libv8/scons/engine/SCons/Tool/swig.py +182 -0
  174. data/lib/libv8/scons/engine/SCons/Tool/tar.py +73 -0
  175. data/lib/libv8/scons/engine/SCons/Tool/tex.py +813 -0
  176. data/lib/libv8/scons/engine/SCons/Tool/textfile.py +175 -0
  177. data/lib/libv8/scons/engine/SCons/Tool/tlib.py +53 -0
  178. data/lib/libv8/scons/engine/SCons/Tool/wix.py +99 -0
  179. data/lib/libv8/scons/engine/SCons/Tool/yacc.py +130 -0
  180. data/lib/libv8/scons/engine/SCons/Tool/zip.py +99 -0
  181. data/lib/libv8/scons/engine/SCons/Util.py +1492 -0
  182. data/lib/libv8/scons/engine/SCons/Variables/BoolVariable.py +89 -0
  183. data/lib/libv8/scons/engine/SCons/Variables/EnumVariable.py +103 -0
  184. data/lib/libv8/scons/engine/SCons/Variables/ListVariable.py +135 -0
  185. data/lib/libv8/scons/engine/SCons/Variables/PackageVariable.py +106 -0
  186. data/lib/libv8/scons/engine/SCons/Variables/PathVariable.py +147 -0
  187. data/lib/libv8/scons/engine/SCons/Variables/__init__.py +312 -0
  188. data/lib/libv8/scons/engine/SCons/Warnings.py +246 -0
  189. data/lib/libv8/scons/engine/SCons/__init__.py +49 -0
  190. data/lib/libv8/scons/engine/SCons/compat/__init__.py +237 -0
  191. data/lib/libv8/scons/engine/SCons/compat/_scons_builtins.py +150 -0
  192. data/lib/libv8/scons/engine/SCons/compat/_scons_collections.py +45 -0
  193. data/lib/libv8/scons/engine/SCons/compat/_scons_dbm.py +45 -0
  194. data/lib/libv8/scons/engine/SCons/compat/_scons_hashlib.py +76 -0
  195. data/lib/libv8/scons/engine/SCons/compat/_scons_io.py +45 -0
  196. data/lib/libv8/scons/engine/SCons/compat/_scons_sets.py +563 -0
  197. data/lib/libv8/scons/engine/SCons/compat/_scons_subprocess.py +1281 -0
  198. data/lib/libv8/scons/engine/SCons/cpp.py +589 -0
  199. data/lib/libv8/scons/engine/SCons/dblite.py +251 -0
  200. data/lib/libv8/scons/engine/SCons/exitfuncs.py +77 -0
  201. data/lib/libv8/scons/os_spawnv_fix.diff +83 -0
  202. data/lib/libv8/scons/scons-time.1 +1017 -0
  203. data/lib/libv8/scons/scons.1 +15219 -0
  204. data/lib/libv8/scons/sconsign.1 +208 -0
  205. data/lib/libv8/scons/script/scons +196 -0
  206. data/lib/libv8/scons/script/scons-time +1544 -0
  207. data/lib/libv8/scons/script/scons.bat +31 -0
  208. data/lib/libv8/scons/script/sconsign +513 -0
  209. data/lib/libv8/scons/setup.cfg +6 -0
  210. data/lib/libv8/scons/setup.py +425 -0
  211. data/lib/libv8/v8/.gitignore +35 -0
  212. data/lib/libv8/v8/AUTHORS +44 -0
  213. data/lib/libv8/v8/ChangeLog +2839 -0
  214. data/lib/libv8/v8/LICENSE +52 -0
  215. data/lib/libv8/v8/LICENSE.strongtalk +29 -0
  216. data/lib/libv8/v8/LICENSE.v8 +26 -0
  217. data/lib/libv8/v8/LICENSE.valgrind +45 -0
  218. data/lib/libv8/v8/SConstruct +1478 -0
  219. data/lib/libv8/v8/build/README.txt +49 -0
  220. data/lib/libv8/v8/build/all.gyp +18 -0
  221. data/lib/libv8/v8/build/armu.gypi +32 -0
  222. data/lib/libv8/v8/build/common.gypi +144 -0
  223. data/lib/libv8/v8/build/gyp_v8 +145 -0
  224. data/lib/libv8/v8/include/v8-debug.h +395 -0
  225. data/lib/libv8/v8/include/v8-preparser.h +117 -0
  226. data/lib/libv8/v8/include/v8-profiler.h +505 -0
  227. data/lib/libv8/v8/include/v8-testing.h +104 -0
  228. data/lib/libv8/v8/include/v8.h +4124 -0
  229. data/lib/libv8/v8/include/v8stdint.h +53 -0
  230. data/lib/libv8/v8/preparser/SConscript +38 -0
  231. data/lib/libv8/v8/preparser/preparser-process.cc +379 -0
  232. data/lib/libv8/v8/src/SConscript +368 -0
  233. data/lib/libv8/v8/src/accessors.cc +767 -0
  234. data/lib/libv8/v8/src/accessors.h +123 -0
  235. data/lib/libv8/v8/src/allocation-inl.h +49 -0
  236. data/lib/libv8/v8/src/allocation.cc +122 -0
  237. data/lib/libv8/v8/src/allocation.h +143 -0
  238. data/lib/libv8/v8/src/api.cc +5845 -0
  239. data/lib/libv8/v8/src/api.h +574 -0
  240. data/lib/libv8/v8/src/apinatives.js +110 -0
  241. data/lib/libv8/v8/src/apiutils.h +73 -0
  242. data/lib/libv8/v8/src/arguments.h +118 -0
  243. data/lib/libv8/v8/src/arm/assembler-arm-inl.h +353 -0
  244. data/lib/libv8/v8/src/arm/assembler-arm.cc +2661 -0
  245. data/lib/libv8/v8/src/arm/assembler-arm.h +1375 -0
  246. data/lib/libv8/v8/src/arm/builtins-arm.cc +1658 -0
  247. data/lib/libv8/v8/src/arm/code-stubs-arm.cc +6398 -0
  248. data/lib/libv8/v8/src/arm/code-stubs-arm.h +673 -0
  249. data/lib/libv8/v8/src/arm/codegen-arm.cc +52 -0
  250. data/lib/libv8/v8/src/arm/codegen-arm.h +91 -0
  251. data/lib/libv8/v8/src/arm/constants-arm.cc +152 -0
  252. data/lib/libv8/v8/src/arm/constants-arm.h +775 -0
  253. data/lib/libv8/v8/src/arm/cpu-arm.cc +120 -0
  254. data/lib/libv8/v8/src/arm/debug-arm.cc +317 -0
  255. data/lib/libv8/v8/src/arm/deoptimizer-arm.cc +754 -0
  256. data/lib/libv8/v8/src/arm/disasm-arm.cc +1506 -0
  257. data/lib/libv8/v8/src/arm/frames-arm.cc +45 -0
  258. data/lib/libv8/v8/src/arm/frames-arm.h +168 -0
  259. data/lib/libv8/v8/src/arm/full-codegen-arm.cc +4375 -0
  260. data/lib/libv8/v8/src/arm/ic-arm.cc +1562 -0
  261. data/lib/libv8/v8/src/arm/lithium-arm.cc +2206 -0
  262. data/lib/libv8/v8/src/arm/lithium-arm.h +2348 -0
  263. data/lib/libv8/v8/src/arm/lithium-codegen-arm.cc +4526 -0
  264. data/lib/libv8/v8/src/arm/lithium-codegen-arm.h +403 -0
  265. data/lib/libv8/v8/src/arm/lithium-gap-resolver-arm.cc +305 -0
  266. data/lib/libv8/v8/src/arm/lithium-gap-resolver-arm.h +84 -0
  267. data/lib/libv8/v8/src/arm/macro-assembler-arm.cc +3163 -0
  268. data/lib/libv8/v8/src/arm/macro-assembler-arm.h +1126 -0
  269. data/lib/libv8/v8/src/arm/regexp-macro-assembler-arm.cc +1287 -0
  270. data/lib/libv8/v8/src/arm/regexp-macro-assembler-arm.h +253 -0
  271. data/lib/libv8/v8/src/arm/simulator-arm.cc +3424 -0
  272. data/lib/libv8/v8/src/arm/simulator-arm.h +431 -0
  273. data/lib/libv8/v8/src/arm/stub-cache-arm.cc +4243 -0
  274. data/lib/libv8/v8/src/array.js +1366 -0
  275. data/lib/libv8/v8/src/assembler.cc +1207 -0
  276. data/lib/libv8/v8/src/assembler.h +858 -0
  277. data/lib/libv8/v8/src/ast-inl.h +112 -0
  278. data/lib/libv8/v8/src/ast.cc +1146 -0
  279. data/lib/libv8/v8/src/ast.h +2188 -0
  280. data/lib/libv8/v8/src/atomicops.h +167 -0
  281. data/lib/libv8/v8/src/atomicops_internals_arm_gcc.h +145 -0
  282. data/lib/libv8/v8/src/atomicops_internals_mips_gcc.h +169 -0
  283. data/lib/libv8/v8/src/atomicops_internals_x86_gcc.cc +133 -0
  284. data/lib/libv8/v8/src/atomicops_internals_x86_gcc.h +287 -0
  285. data/lib/libv8/v8/src/atomicops_internals_x86_macosx.h +301 -0
  286. data/lib/libv8/v8/src/atomicops_internals_x86_msvc.h +203 -0
  287. data/lib/libv8/v8/src/bignum-dtoa.cc +655 -0
  288. data/lib/libv8/v8/src/bignum-dtoa.h +81 -0
  289. data/lib/libv8/v8/src/bignum.cc +768 -0
  290. data/lib/libv8/v8/src/bignum.h +140 -0
  291. data/lib/libv8/v8/src/bootstrapper.cc +2184 -0
  292. data/lib/libv8/v8/src/bootstrapper.h +188 -0
  293. data/lib/libv8/v8/src/builtins.cc +1707 -0
  294. data/lib/libv8/v8/src/builtins.h +371 -0
  295. data/lib/libv8/v8/src/bytecodes-irregexp.h +105 -0
  296. data/lib/libv8/v8/src/cached-powers.cc +177 -0
  297. data/lib/libv8/v8/src/cached-powers.h +65 -0
  298. data/lib/libv8/v8/src/char-predicates-inl.h +94 -0
  299. data/lib/libv8/v8/src/char-predicates.h +67 -0
  300. data/lib/libv8/v8/src/checks.cc +110 -0
  301. data/lib/libv8/v8/src/checks.h +296 -0
  302. data/lib/libv8/v8/src/circular-queue-inl.h +53 -0
  303. data/lib/libv8/v8/src/circular-queue.cc +122 -0
  304. data/lib/libv8/v8/src/circular-queue.h +103 -0
  305. data/lib/libv8/v8/src/code-stubs.cc +267 -0
  306. data/lib/libv8/v8/src/code-stubs.h +1011 -0
  307. data/lib/libv8/v8/src/code.h +70 -0
  308. data/lib/libv8/v8/src/codegen.cc +231 -0
  309. data/lib/libv8/v8/src/codegen.h +84 -0
  310. data/lib/libv8/v8/src/compilation-cache.cc +540 -0
  311. data/lib/libv8/v8/src/compilation-cache.h +287 -0
  312. data/lib/libv8/v8/src/compiler.cc +786 -0
  313. data/lib/libv8/v8/src/compiler.h +312 -0
  314. data/lib/libv8/v8/src/contexts.cc +347 -0
  315. data/lib/libv8/v8/src/contexts.h +391 -0
  316. data/lib/libv8/v8/src/conversions-inl.h +106 -0
  317. data/lib/libv8/v8/src/conversions.cc +1131 -0
  318. data/lib/libv8/v8/src/conversions.h +135 -0
  319. data/lib/libv8/v8/src/counters.cc +93 -0
  320. data/lib/libv8/v8/src/counters.h +254 -0
  321. data/lib/libv8/v8/src/cpu-profiler-inl.h +101 -0
  322. data/lib/libv8/v8/src/cpu-profiler.cc +609 -0
  323. data/lib/libv8/v8/src/cpu-profiler.h +302 -0
  324. data/lib/libv8/v8/src/cpu.h +69 -0
  325. data/lib/libv8/v8/src/d8-debug.cc +367 -0
  326. data/lib/libv8/v8/src/d8-debug.h +158 -0
  327. data/lib/libv8/v8/src/d8-posix.cc +695 -0
  328. data/lib/libv8/v8/src/d8-readline.cc +130 -0
  329. data/lib/libv8/v8/src/d8-windows.cc +42 -0
  330. data/lib/libv8/v8/src/d8.cc +803 -0
  331. data/lib/libv8/v8/src/d8.gyp +91 -0
  332. data/lib/libv8/v8/src/d8.h +235 -0
  333. data/lib/libv8/v8/src/d8.js +2798 -0
  334. data/lib/libv8/v8/src/data-flow.cc +66 -0
  335. data/lib/libv8/v8/src/data-flow.h +205 -0
  336. data/lib/libv8/v8/src/date.js +1103 -0
  337. data/lib/libv8/v8/src/dateparser-inl.h +127 -0
  338. data/lib/libv8/v8/src/dateparser.cc +178 -0
  339. data/lib/libv8/v8/src/dateparser.h +266 -0
  340. data/lib/libv8/v8/src/debug-agent.cc +447 -0
  341. data/lib/libv8/v8/src/debug-agent.h +129 -0
  342. data/lib/libv8/v8/src/debug-debugger.js +2569 -0
  343. data/lib/libv8/v8/src/debug.cc +3165 -0
  344. data/lib/libv8/v8/src/debug.h +1057 -0
  345. data/lib/libv8/v8/src/deoptimizer.cc +1256 -0
  346. data/lib/libv8/v8/src/deoptimizer.h +602 -0
  347. data/lib/libv8/v8/src/disasm.h +80 -0
  348. data/lib/libv8/v8/src/disassembler.cc +343 -0
  349. data/lib/libv8/v8/src/disassembler.h +58 -0
  350. data/lib/libv8/v8/src/diy-fp.cc +58 -0
  351. data/lib/libv8/v8/src/diy-fp.h +117 -0
  352. data/lib/libv8/v8/src/double.h +238 -0
  353. data/lib/libv8/v8/src/dtoa.cc +103 -0
  354. data/lib/libv8/v8/src/dtoa.h +85 -0
  355. data/lib/libv8/v8/src/execution.cc +849 -0
  356. data/lib/libv8/v8/src/execution.h +297 -0
  357. data/lib/libv8/v8/src/extensions/experimental/break-iterator.cc +250 -0
  358. data/lib/libv8/v8/src/extensions/experimental/break-iterator.h +89 -0
  359. data/lib/libv8/v8/src/extensions/experimental/collator.cc +218 -0
  360. data/lib/libv8/v8/src/extensions/experimental/collator.h +69 -0
  361. data/lib/libv8/v8/src/extensions/experimental/experimental.gyp +94 -0
  362. data/lib/libv8/v8/src/extensions/experimental/i18n-extension.cc +78 -0
  363. data/lib/libv8/v8/src/extensions/experimental/i18n-extension.h +54 -0
  364. data/lib/libv8/v8/src/extensions/experimental/i18n-locale.cc +112 -0
  365. data/lib/libv8/v8/src/extensions/experimental/i18n-locale.h +60 -0
  366. data/lib/libv8/v8/src/extensions/experimental/i18n-utils.cc +43 -0
  367. data/lib/libv8/v8/src/extensions/experimental/i18n-utils.h +49 -0
  368. data/lib/libv8/v8/src/extensions/experimental/i18n.js +180 -0
  369. data/lib/libv8/v8/src/extensions/experimental/language-matcher.cc +251 -0
  370. data/lib/libv8/v8/src/extensions/experimental/language-matcher.h +95 -0
  371. data/lib/libv8/v8/src/extensions/externalize-string-extension.cc +141 -0
  372. data/lib/libv8/v8/src/extensions/externalize-string-extension.h +50 -0
  373. data/lib/libv8/v8/src/extensions/gc-extension.cc +58 -0
  374. data/lib/libv8/v8/src/extensions/gc-extension.h +49 -0
  375. data/lib/libv8/v8/src/factory.cc +1222 -0
  376. data/lib/libv8/v8/src/factory.h +442 -0
  377. data/lib/libv8/v8/src/fast-dtoa.cc +736 -0
  378. data/lib/libv8/v8/src/fast-dtoa.h +83 -0
  379. data/lib/libv8/v8/src/fixed-dtoa.cc +405 -0
  380. data/lib/libv8/v8/src/fixed-dtoa.h +55 -0
  381. data/lib/libv8/v8/src/flag-definitions.h +560 -0
  382. data/lib/libv8/v8/src/flags.cc +551 -0
  383. data/lib/libv8/v8/src/flags.h +79 -0
  384. data/lib/libv8/v8/src/frames-inl.h +247 -0
  385. data/lib/libv8/v8/src/frames.cc +1243 -0
  386. data/lib/libv8/v8/src/frames.h +870 -0
  387. data/lib/libv8/v8/src/full-codegen.cc +1374 -0
  388. data/lib/libv8/v8/src/full-codegen.h +771 -0
  389. data/lib/libv8/v8/src/func-name-inferrer.cc +92 -0
  390. data/lib/libv8/v8/src/func-name-inferrer.h +111 -0
  391. data/lib/libv8/v8/src/gdb-jit.cc +1555 -0
  392. data/lib/libv8/v8/src/gdb-jit.h +143 -0
  393. data/lib/libv8/v8/src/global-handles.cc +665 -0
  394. data/lib/libv8/v8/src/global-handles.h +284 -0
  395. data/lib/libv8/v8/src/globals.h +325 -0
  396. data/lib/libv8/v8/src/handles-inl.h +177 -0
  397. data/lib/libv8/v8/src/handles.cc +987 -0
  398. data/lib/libv8/v8/src/handles.h +382 -0
  399. data/lib/libv8/v8/src/hashmap.cc +230 -0
  400. data/lib/libv8/v8/src/hashmap.h +123 -0
  401. data/lib/libv8/v8/src/heap-inl.h +704 -0
  402. data/lib/libv8/v8/src/heap-profiler.cc +1173 -0
  403. data/lib/libv8/v8/src/heap-profiler.h +397 -0
  404. data/lib/libv8/v8/src/heap.cc +5930 -0
  405. data/lib/libv8/v8/src/heap.h +2268 -0
  406. data/lib/libv8/v8/src/hydrogen-instructions.cc +1769 -0
  407. data/lib/libv8/v8/src/hydrogen-instructions.h +3971 -0
  408. data/lib/libv8/v8/src/hydrogen.cc +6239 -0
  409. data/lib/libv8/v8/src/hydrogen.h +1202 -0
  410. data/lib/libv8/v8/src/ia32/assembler-ia32-inl.h +446 -0
  411. data/lib/libv8/v8/src/ia32/assembler-ia32.cc +2487 -0
  412. data/lib/libv8/v8/src/ia32/assembler-ia32.h +1144 -0
  413. data/lib/libv8/v8/src/ia32/builtins-ia32.cc +1621 -0
  414. data/lib/libv8/v8/src/ia32/code-stubs-ia32.cc +6198 -0
  415. data/lib/libv8/v8/src/ia32/code-stubs-ia32.h +517 -0
  416. data/lib/libv8/v8/src/ia32/codegen-ia32.cc +265 -0
  417. data/lib/libv8/v8/src/ia32/codegen-ia32.h +79 -0
  418. data/lib/libv8/v8/src/ia32/cpu-ia32.cc +88 -0
  419. data/lib/libv8/v8/src/ia32/debug-ia32.cc +312 -0
  420. data/lib/libv8/v8/src/ia32/deoptimizer-ia32.cc +774 -0
  421. data/lib/libv8/v8/src/ia32/disasm-ia32.cc +1628 -0
  422. data/lib/libv8/v8/src/ia32/frames-ia32.cc +45 -0
  423. data/lib/libv8/v8/src/ia32/frames-ia32.h +142 -0
  424. data/lib/libv8/v8/src/ia32/full-codegen-ia32.cc +4338 -0
  425. data/lib/libv8/v8/src/ia32/ic-ia32.cc +1597 -0
  426. data/lib/libv8/v8/src/ia32/lithium-codegen-ia32.cc +4461 -0
  427. data/lib/libv8/v8/src/ia32/lithium-codegen-ia32.h +375 -0
  428. data/lib/libv8/v8/src/ia32/lithium-gap-resolver-ia32.cc +475 -0
  429. data/lib/libv8/v8/src/ia32/lithium-gap-resolver-ia32.h +110 -0
  430. data/lib/libv8/v8/src/ia32/lithium-ia32.cc +2261 -0
  431. data/lib/libv8/v8/src/ia32/lithium-ia32.h +2396 -0
  432. data/lib/libv8/v8/src/ia32/macro-assembler-ia32.cc +2136 -0
  433. data/lib/libv8/v8/src/ia32/macro-assembler-ia32.h +775 -0
  434. data/lib/libv8/v8/src/ia32/regexp-macro-assembler-ia32.cc +1263 -0
  435. data/lib/libv8/v8/src/ia32/regexp-macro-assembler-ia32.h +216 -0
  436. data/lib/libv8/v8/src/ia32/simulator-ia32.cc +30 -0
  437. data/lib/libv8/v8/src/ia32/simulator-ia32.h +74 -0
  438. data/lib/libv8/v8/src/ia32/stub-cache-ia32.cc +3847 -0
  439. data/lib/libv8/v8/src/ic-inl.h +130 -0
  440. data/lib/libv8/v8/src/ic.cc +2577 -0
  441. data/lib/libv8/v8/src/ic.h +736 -0
  442. data/lib/libv8/v8/src/inspector.cc +63 -0
  443. data/lib/libv8/v8/src/inspector.h +62 -0
  444. data/lib/libv8/v8/src/interpreter-irregexp.cc +659 -0
  445. data/lib/libv8/v8/src/interpreter-irregexp.h +49 -0
  446. data/lib/libv8/v8/src/isolate-inl.h +50 -0
  447. data/lib/libv8/v8/src/isolate.cc +1869 -0
  448. data/lib/libv8/v8/src/isolate.h +1382 -0
  449. data/lib/libv8/v8/src/json-parser.cc +504 -0
  450. data/lib/libv8/v8/src/json-parser.h +161 -0
  451. data/lib/libv8/v8/src/json.js +342 -0
  452. data/lib/libv8/v8/src/jsregexp.cc +5385 -0
  453. data/lib/libv8/v8/src/jsregexp.h +1492 -0
  454. data/lib/libv8/v8/src/list-inl.h +212 -0
  455. data/lib/libv8/v8/src/list.h +174 -0
  456. data/lib/libv8/v8/src/lithium-allocator-inl.h +142 -0
  457. data/lib/libv8/v8/src/lithium-allocator.cc +2123 -0
  458. data/lib/libv8/v8/src/lithium-allocator.h +630 -0
  459. data/lib/libv8/v8/src/lithium.cc +190 -0
  460. data/lib/libv8/v8/src/lithium.h +597 -0
  461. data/lib/libv8/v8/src/liveedit-debugger.js +1082 -0
  462. data/lib/libv8/v8/src/liveedit.cc +1691 -0
  463. data/lib/libv8/v8/src/liveedit.h +180 -0
  464. data/lib/libv8/v8/src/liveobjectlist-inl.h +126 -0
  465. data/lib/libv8/v8/src/liveobjectlist.cc +2589 -0
  466. data/lib/libv8/v8/src/liveobjectlist.h +322 -0
  467. data/lib/libv8/v8/src/log-inl.h +59 -0
  468. data/lib/libv8/v8/src/log-utils.cc +428 -0
  469. data/lib/libv8/v8/src/log-utils.h +231 -0
  470. data/lib/libv8/v8/src/log.cc +1993 -0
  471. data/lib/libv8/v8/src/log.h +476 -0
  472. data/lib/libv8/v8/src/macro-assembler.h +120 -0
  473. data/lib/libv8/v8/src/macros.py +178 -0
  474. data/lib/libv8/v8/src/mark-compact.cc +3143 -0
  475. data/lib/libv8/v8/src/mark-compact.h +506 -0
  476. data/lib/libv8/v8/src/math.js +264 -0
  477. data/lib/libv8/v8/src/messages.cc +179 -0
  478. data/lib/libv8/v8/src/messages.h +113 -0
  479. data/lib/libv8/v8/src/messages.js +1096 -0
  480. data/lib/libv8/v8/src/mips/assembler-mips-inl.h +312 -0
  481. data/lib/libv8/v8/src/mips/assembler-mips.cc +1960 -0
  482. data/lib/libv8/v8/src/mips/assembler-mips.h +1138 -0
  483. data/lib/libv8/v8/src/mips/builtins-mips.cc +1628 -0
  484. data/lib/libv8/v8/src/mips/code-stubs-mips.cc +6656 -0
  485. data/lib/libv8/v8/src/mips/code-stubs-mips.h +682 -0
  486. data/lib/libv8/v8/src/mips/codegen-mips.cc +52 -0
  487. data/lib/libv8/v8/src/mips/codegen-mips.h +98 -0
  488. data/lib/libv8/v8/src/mips/constants-mips.cc +352 -0
  489. data/lib/libv8/v8/src/mips/constants-mips.h +739 -0
  490. data/lib/libv8/v8/src/mips/cpu-mips.cc +96 -0
  491. data/lib/libv8/v8/src/mips/debug-mips.cc +308 -0
  492. data/lib/libv8/v8/src/mips/deoptimizer-mips.cc +91 -0
  493. data/lib/libv8/v8/src/mips/disasm-mips.cc +1050 -0
  494. data/lib/libv8/v8/src/mips/frames-mips.cc +47 -0
  495. data/lib/libv8/v8/src/mips/frames-mips.h +219 -0
  496. data/lib/libv8/v8/src/mips/full-codegen-mips.cc +4388 -0
  497. data/lib/libv8/v8/src/mips/ic-mips.cc +1580 -0
  498. data/lib/libv8/v8/src/mips/lithium-codegen-mips.h +65 -0
  499. data/lib/libv8/v8/src/mips/lithium-mips.h +307 -0
  500. data/lib/libv8/v8/src/mips/macro-assembler-mips.cc +4056 -0
  501. data/lib/libv8/v8/src/mips/macro-assembler-mips.h +1214 -0
  502. data/lib/libv8/v8/src/mips/regexp-macro-assembler-mips.cc +1251 -0
  503. data/lib/libv8/v8/src/mips/regexp-macro-assembler-mips.h +252 -0
  504. data/lib/libv8/v8/src/mips/simulator-mips.cc +2621 -0
  505. data/lib/libv8/v8/src/mips/simulator-mips.h +401 -0
  506. data/lib/libv8/v8/src/mips/stub-cache-mips.cc +4285 -0
  507. data/lib/libv8/v8/src/mirror-debugger.js +2382 -0
  508. data/lib/libv8/v8/src/mksnapshot.cc +328 -0
  509. data/lib/libv8/v8/src/natives.h +64 -0
  510. data/lib/libv8/v8/src/objects-debug.cc +738 -0
  511. data/lib/libv8/v8/src/objects-inl.h +4323 -0
  512. data/lib/libv8/v8/src/objects-printer.cc +829 -0
  513. data/lib/libv8/v8/src/objects-visiting.cc +148 -0
  514. data/lib/libv8/v8/src/objects-visiting.h +424 -0
  515. data/lib/libv8/v8/src/objects.cc +10585 -0
  516. data/lib/libv8/v8/src/objects.h +6838 -0
  517. data/lib/libv8/v8/src/parser.cc +4997 -0
  518. data/lib/libv8/v8/src/parser.h +765 -0
  519. data/lib/libv8/v8/src/platform-cygwin.cc +779 -0
  520. data/lib/libv8/v8/src/platform-freebsd.cc +826 -0
  521. data/lib/libv8/v8/src/platform-linux.cc +1149 -0
  522. data/lib/libv8/v8/src/platform-macos.cc +830 -0
  523. data/lib/libv8/v8/src/platform-nullos.cc +479 -0
  524. data/lib/libv8/v8/src/platform-openbsd.cc +640 -0
  525. data/lib/libv8/v8/src/platform-posix.cc +424 -0
  526. data/lib/libv8/v8/src/platform-solaris.cc +762 -0
  527. data/lib/libv8/v8/src/platform-tls-mac.h +62 -0
  528. data/lib/libv8/v8/src/platform-tls-win32.h +62 -0
  529. data/lib/libv8/v8/src/platform-tls.h +50 -0
  530. data/lib/libv8/v8/src/platform-win32.cc +2021 -0
  531. data/lib/libv8/v8/src/platform.h +667 -0
  532. data/lib/libv8/v8/src/preparse-data-format.h +62 -0
  533. data/lib/libv8/v8/src/preparse-data.cc +183 -0
  534. data/lib/libv8/v8/src/preparse-data.h +225 -0
  535. data/lib/libv8/v8/src/preparser-api.cc +220 -0
  536. data/lib/libv8/v8/src/preparser.cc +1450 -0
  537. data/lib/libv8/v8/src/preparser.h +493 -0
  538. data/lib/libv8/v8/src/prettyprinter.cc +1493 -0
  539. data/lib/libv8/v8/src/prettyprinter.h +223 -0
  540. data/lib/libv8/v8/src/profile-generator-inl.h +128 -0
  541. data/lib/libv8/v8/src/profile-generator.cc +3098 -0
  542. data/lib/libv8/v8/src/profile-generator.h +1126 -0
  543. data/lib/libv8/v8/src/property.cc +105 -0
  544. data/lib/libv8/v8/src/property.h +365 -0
  545. data/lib/libv8/v8/src/proxy.js +83 -0
  546. data/lib/libv8/v8/src/regexp-macro-assembler-irregexp-inl.h +78 -0
  547. data/lib/libv8/v8/src/regexp-macro-assembler-irregexp.cc +471 -0
  548. data/lib/libv8/v8/src/regexp-macro-assembler-irregexp.h +142 -0
  549. data/lib/libv8/v8/src/regexp-macro-assembler-tracer.cc +373 -0
  550. data/lib/libv8/v8/src/regexp-macro-assembler-tracer.h +104 -0
  551. data/lib/libv8/v8/src/regexp-macro-assembler.cc +267 -0
  552. data/lib/libv8/v8/src/regexp-macro-assembler.h +243 -0
  553. data/lib/libv8/v8/src/regexp-stack.cc +111 -0
  554. data/lib/libv8/v8/src/regexp-stack.h +147 -0
  555. data/lib/libv8/v8/src/regexp.js +483 -0
  556. data/lib/libv8/v8/src/rewriter.cc +360 -0
  557. data/lib/libv8/v8/src/rewriter.h +50 -0
  558. data/lib/libv8/v8/src/runtime-profiler.cc +489 -0
  559. data/lib/libv8/v8/src/runtime-profiler.h +201 -0
  560. data/lib/libv8/v8/src/runtime.cc +12227 -0
  561. data/lib/libv8/v8/src/runtime.h +652 -0
  562. data/lib/libv8/v8/src/runtime.js +649 -0
  563. data/lib/libv8/v8/src/safepoint-table.cc +256 -0
  564. data/lib/libv8/v8/src/safepoint-table.h +270 -0
  565. data/lib/libv8/v8/src/scanner-base.cc +952 -0
  566. data/lib/libv8/v8/src/scanner-base.h +670 -0
  567. data/lib/libv8/v8/src/scanner.cc +345 -0
  568. data/lib/libv8/v8/src/scanner.h +146 -0
  569. data/lib/libv8/v8/src/scopeinfo.cc +646 -0
  570. data/lib/libv8/v8/src/scopeinfo.h +254 -0
  571. data/lib/libv8/v8/src/scopes.cc +1150 -0
  572. data/lib/libv8/v8/src/scopes.h +507 -0
  573. data/lib/libv8/v8/src/serialize.cc +1574 -0
  574. data/lib/libv8/v8/src/serialize.h +589 -0
  575. data/lib/libv8/v8/src/shell.h +55 -0
  576. data/lib/libv8/v8/src/simulator.h +43 -0
  577. data/lib/libv8/v8/src/small-pointer-list.h +163 -0
  578. data/lib/libv8/v8/src/smart-pointer.h +109 -0
  579. data/lib/libv8/v8/src/snapshot-common.cc +83 -0
  580. data/lib/libv8/v8/src/snapshot-empty.cc +54 -0
  581. data/lib/libv8/v8/src/snapshot.h +91 -0
  582. data/lib/libv8/v8/src/spaces-inl.h +529 -0
  583. data/lib/libv8/v8/src/spaces.cc +3145 -0
  584. data/lib/libv8/v8/src/spaces.h +2369 -0
  585. data/lib/libv8/v8/src/splay-tree-inl.h +310 -0
  586. data/lib/libv8/v8/src/splay-tree.h +205 -0
  587. data/lib/libv8/v8/src/string-search.cc +41 -0
  588. data/lib/libv8/v8/src/string-search.h +568 -0
  589. data/lib/libv8/v8/src/string-stream.cc +592 -0
  590. data/lib/libv8/v8/src/string-stream.h +191 -0
  591. data/lib/libv8/v8/src/string.js +994 -0
  592. data/lib/libv8/v8/src/strtod.cc +440 -0
  593. data/lib/libv8/v8/src/strtod.h +40 -0
  594. data/lib/libv8/v8/src/stub-cache.cc +1965 -0
  595. data/lib/libv8/v8/src/stub-cache.h +924 -0
  596. data/lib/libv8/v8/src/third_party/valgrind/valgrind.h +3925 -0
  597. data/lib/libv8/v8/src/token.cc +63 -0
  598. data/lib/libv8/v8/src/token.h +288 -0
  599. data/lib/libv8/v8/src/type-info.cc +507 -0
  600. data/lib/libv8/v8/src/type-info.h +272 -0
  601. data/lib/libv8/v8/src/unbound-queue-inl.h +95 -0
  602. data/lib/libv8/v8/src/unbound-queue.h +69 -0
  603. data/lib/libv8/v8/src/unicode-inl.h +238 -0
  604. data/lib/libv8/v8/src/unicode.cc +1624 -0
  605. data/lib/libv8/v8/src/unicode.h +280 -0
  606. data/lib/libv8/v8/src/uri.js +408 -0
  607. data/lib/libv8/v8/src/utils-inl.h +48 -0
  608. data/lib/libv8/v8/src/utils.cc +371 -0
  609. data/lib/libv8/v8/src/utils.h +800 -0
  610. data/lib/libv8/v8/src/v8-counters.cc +62 -0
  611. data/lib/libv8/v8/src/v8-counters.h +314 -0
  612. data/lib/libv8/v8/src/v8.cc +213 -0
  613. data/lib/libv8/v8/src/v8.h +131 -0
  614. data/lib/libv8/v8/src/v8checks.h +64 -0
  615. data/lib/libv8/v8/src/v8dll-main.cc +44 -0
  616. data/lib/libv8/v8/src/v8globals.h +512 -0
  617. data/lib/libv8/v8/src/v8memory.h +82 -0
  618. data/lib/libv8/v8/src/v8natives.js +1310 -0
  619. data/lib/libv8/v8/src/v8preparserdll-main.cc +39 -0
  620. data/lib/libv8/v8/src/v8threads.cc +464 -0
  621. data/lib/libv8/v8/src/v8threads.h +165 -0
  622. data/lib/libv8/v8/src/v8utils.h +319 -0
  623. data/lib/libv8/v8/src/variables.cc +114 -0
  624. data/lib/libv8/v8/src/variables.h +167 -0
  625. data/lib/libv8/v8/src/version.cc +116 -0
  626. data/lib/libv8/v8/src/version.h +68 -0
  627. data/lib/libv8/v8/src/vm-state-inl.h +138 -0
  628. data/lib/libv8/v8/src/vm-state.h +71 -0
  629. data/lib/libv8/v8/src/win32-headers.h +96 -0
  630. data/lib/libv8/v8/src/x64/assembler-x64-inl.h +462 -0
  631. data/lib/libv8/v8/src/x64/assembler-x64.cc +3027 -0
  632. data/lib/libv8/v8/src/x64/assembler-x64.h +1633 -0
  633. data/lib/libv8/v8/src/x64/builtins-x64.cc +1520 -0
  634. data/lib/libv8/v8/src/x64/code-stubs-x64.cc +5132 -0
  635. data/lib/libv8/v8/src/x64/code-stubs-x64.h +514 -0
  636. data/lib/libv8/v8/src/x64/codegen-x64.cc +146 -0
  637. data/lib/libv8/v8/src/x64/codegen-x64.h +76 -0
  638. data/lib/libv8/v8/src/x64/cpu-x64.cc +88 -0
  639. data/lib/libv8/v8/src/x64/debug-x64.cc +319 -0
  640. data/lib/libv8/v8/src/x64/deoptimizer-x64.cc +815 -0
  641. data/lib/libv8/v8/src/x64/disasm-x64.cc +1832 -0
  642. data/lib/libv8/v8/src/x64/frames-x64.cc +45 -0
  643. data/lib/libv8/v8/src/x64/frames-x64.h +130 -0
  644. data/lib/libv8/v8/src/x64/full-codegen-x64.cc +4318 -0
  645. data/lib/libv8/v8/src/x64/ic-x64.cc +1608 -0
  646. data/lib/libv8/v8/src/x64/lithium-codegen-x64.cc +4267 -0
  647. data/lib/libv8/v8/src/x64/lithium-codegen-x64.h +367 -0
  648. data/lib/libv8/v8/src/x64/lithium-gap-resolver-x64.cc +320 -0
  649. data/lib/libv8/v8/src/x64/lithium-gap-resolver-x64.h +74 -0
  650. data/lib/libv8/v8/src/x64/lithium-x64.cc +2202 -0
  651. data/lib/libv8/v8/src/x64/lithium-x64.h +2333 -0
  652. data/lib/libv8/v8/src/x64/macro-assembler-x64.cc +3745 -0
  653. data/lib/libv8/v8/src/x64/macro-assembler-x64.h +1290 -0
  654. data/lib/libv8/v8/src/x64/regexp-macro-assembler-x64.cc +1398 -0
  655. data/lib/libv8/v8/src/x64/regexp-macro-assembler-x64.h +282 -0
  656. data/lib/libv8/v8/src/x64/simulator-x64.cc +27 -0
  657. data/lib/libv8/v8/src/x64/simulator-x64.h +72 -0
  658. data/lib/libv8/v8/src/x64/stub-cache-x64.cc +3610 -0
  659. data/lib/libv8/v8/src/zone-inl.h +140 -0
  660. data/lib/libv8/v8/src/zone.cc +196 -0
  661. data/lib/libv8/v8/src/zone.h +240 -0
  662. data/lib/libv8/v8/tools/codemap.js +265 -0
  663. data/lib/libv8/v8/tools/consarray.js +93 -0
  664. data/lib/libv8/v8/tools/csvparser.js +78 -0
  665. data/lib/libv8/v8/tools/disasm.py +92 -0
  666. data/lib/libv8/v8/tools/freebsd-tick-processor +10 -0
  667. data/lib/libv8/v8/tools/gc-nvp-trace-processor.py +342 -0
  668. data/lib/libv8/v8/tools/gcmole/README +62 -0
  669. data/lib/libv8/v8/tools/gcmole/gccause.lua +60 -0
  670. data/lib/libv8/v8/tools/gcmole/gcmole.cc +1261 -0
  671. data/lib/libv8/v8/tools/gcmole/gcmole.lua +378 -0
  672. data/lib/libv8/v8/tools/generate-ten-powers.scm +286 -0
  673. data/lib/libv8/v8/tools/grokdump.py +841 -0
  674. data/lib/libv8/v8/tools/gyp/v8.gyp +995 -0
  675. data/lib/libv8/v8/tools/js2c.py +364 -0
  676. data/lib/libv8/v8/tools/jsmin.py +280 -0
  677. data/lib/libv8/v8/tools/linux-tick-processor +35 -0
  678. data/lib/libv8/v8/tools/ll_prof.py +942 -0
  679. data/lib/libv8/v8/tools/logreader.js +185 -0
  680. data/lib/libv8/v8/tools/mac-nm +18 -0
  681. data/lib/libv8/v8/tools/mac-tick-processor +6 -0
  682. data/lib/libv8/v8/tools/oom_dump/README +31 -0
  683. data/lib/libv8/v8/tools/oom_dump/SConstruct +42 -0
  684. data/lib/libv8/v8/tools/oom_dump/oom_dump.cc +288 -0
  685. data/lib/libv8/v8/tools/presubmit.py +305 -0
  686. data/lib/libv8/v8/tools/process-heap-prof.py +120 -0
  687. data/lib/libv8/v8/tools/profile.js +751 -0
  688. data/lib/libv8/v8/tools/profile_view.js +219 -0
  689. data/lib/libv8/v8/tools/run-valgrind.py +77 -0
  690. data/lib/libv8/v8/tools/splaytree.js +316 -0
  691. data/lib/libv8/v8/tools/stats-viewer.py +468 -0
  692. data/lib/libv8/v8/tools/test.py +1510 -0
  693. data/lib/libv8/v8/tools/tickprocessor-driver.js +59 -0
  694. data/lib/libv8/v8/tools/tickprocessor.js +877 -0
  695. data/lib/libv8/v8/tools/utils.py +96 -0
  696. data/lib/libv8/v8/tools/visual_studio/README.txt +12 -0
  697. data/lib/libv8/v8/tools/windows-tick-processor.bat +30 -0
  698. data/lib/libv8/version.rb +4 -0
  699. data/libv8.gemspec +31 -0
  700. metadata +800 -0
@@ -0,0 +1,223 @@
1
+ // Copyright 2011 the V8 project authors. All rights reserved.
2
+ // Redistribution and use in source and binary forms, with or without
3
+ // modification, are permitted provided that the following conditions are
4
+ // met:
5
+ //
6
+ // * Redistributions of source code must retain the above copyright
7
+ // notice, this list of conditions and the following disclaimer.
8
+ // * Redistributions in binary form must reproduce the above
9
+ // copyright notice, this list of conditions and the following
10
+ // disclaimer in the documentation and/or other materials provided
11
+ // with the distribution.
12
+ // * Neither the name of Google Inc. nor the names of its
13
+ // contributors may be used to endorse or promote products derived
14
+ // from this software without specific prior written permission.
15
+ //
16
+ // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
+ // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18
+ // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19
+ // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20
+ // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21
+ // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
+ // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
+ // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
+ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
+ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
+ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+
28
+ #ifndef V8_PRETTYPRINTER_H_
29
+ #define V8_PRETTYPRINTER_H_
30
+
31
+ #include "allocation.h"
32
+ #include "ast.h"
33
+
34
+ namespace v8 {
35
+ namespace internal {
36
+
37
+ #ifdef DEBUG
38
+
39
+ class PrettyPrinter: public AstVisitor {
40
+ public:
41
+ PrettyPrinter();
42
+ virtual ~PrettyPrinter();
43
+
44
+ // The following routines print a node into a string.
45
+ // The result string is alive as long as the PrettyPrinter is alive.
46
+ const char* Print(AstNode* node);
47
+ const char* PrintExpression(FunctionLiteral* program);
48
+ const char* PrintProgram(FunctionLiteral* program);
49
+
50
+ void Print(const char* format, ...);
51
+
52
+ // Print a node to stdout.
53
+ static void PrintOut(AstNode* node);
54
+
55
+ virtual void VisitSlot(Slot* node);
56
+ // Individual nodes
57
+ #define DECLARE_VISIT(type) virtual void Visit##type(type* node);
58
+ AST_NODE_LIST(DECLARE_VISIT)
59
+ #undef DECLARE_VISIT
60
+
61
+ private:
62
+ char* output_; // output string buffer
63
+ int size_; // output_ size
64
+ int pos_; // current printing position
65
+
66
+ protected:
67
+ void Init();
68
+ const char* Output() const { return output_; }
69
+
70
+ virtual void PrintStatements(ZoneList<Statement*>* statements);
71
+ void PrintLabels(ZoneStringList* labels);
72
+ virtual void PrintArguments(ZoneList<Expression*>* arguments);
73
+ void PrintLiteral(Handle<Object> value, bool quote);
74
+ void PrintParameters(Scope* scope);
75
+ void PrintDeclarations(ZoneList<Declaration*>* declarations);
76
+ void PrintFunctionLiteral(FunctionLiteral* function);
77
+ void PrintCaseClause(CaseClause* clause);
78
+ };
79
+
80
+
81
+ // Prints the AST structure
82
+ class AstPrinter: public PrettyPrinter {
83
+ public:
84
+ AstPrinter();
85
+ virtual ~AstPrinter();
86
+
87
+ const char* PrintProgram(FunctionLiteral* program);
88
+
89
+ // Individual nodes
90
+ virtual void VisitSlot(Slot* node);
91
+ #define DECLARE_VISIT(type) virtual void Visit##type(type* node);
92
+ AST_NODE_LIST(DECLARE_VISIT)
93
+ #undef DECLARE_VISIT
94
+
95
+ private:
96
+ friend class IndentedScope;
97
+ void PrintIndented(const char* txt);
98
+ void PrintIndentedVisit(const char* s, AstNode* node);
99
+
100
+ void PrintStatements(ZoneList<Statement*>* statements);
101
+ void PrintDeclarations(ZoneList<Declaration*>* declarations);
102
+ void PrintParameters(Scope* scope);
103
+ void PrintArguments(ZoneList<Expression*>* arguments);
104
+ void PrintCaseClause(CaseClause* clause);
105
+ void PrintLiteralIndented(const char* info, Handle<Object> value, bool quote);
106
+ void PrintLiteralWithModeIndented(const char* info,
107
+ Variable* var,
108
+ Handle<Object> value);
109
+ void PrintLabelsIndented(const char* info, ZoneStringList* labels);
110
+
111
+ void inc_indent() { indent_++; }
112
+ void dec_indent() { indent_--; }
113
+
114
+ int indent_;
115
+ };
116
+
117
+
118
+ // Forward declaration of helper classes.
119
+ class TagScope;
120
+ class AttributesScope;
121
+
122
+ // Build a C string containing a JSON representation of a function's
123
+ // AST. The representation is based on JsonML (www.jsonml.org).
124
+ class JsonAstBuilder: public PrettyPrinter {
125
+ public:
126
+ JsonAstBuilder()
127
+ : indent_(0), top_tag_scope_(NULL), attributes_scope_(NULL) {
128
+ }
129
+ virtual ~JsonAstBuilder() {}
130
+
131
+ // Controls the indentation of subsequent lines of a tag body after
132
+ // the first line.
133
+ static const int kTagIndentSize = 2;
134
+
135
+ // Controls the indentation of subsequent lines of an attributes
136
+ // blocks's body after the first line.
137
+ static const int kAttributesIndentSize = 1;
138
+
139
+ // Construct a JSON representation of a function literal.
140
+ const char* BuildProgram(FunctionLiteral* program);
141
+
142
+ // Print text indented by the current indentation level.
143
+ void PrintIndented(const char* text) { Print("%*s%s", indent_, "", text); }
144
+
145
+ // Change the indentation level.
146
+ void increase_indent(int amount) { indent_ += amount; }
147
+ void decrease_indent(int amount) { indent_ -= amount; }
148
+
149
+ // The builder maintains a stack of opened AST node constructors.
150
+ // Each node constructor corresponds to a JsonML tag.
151
+ TagScope* tag() { return top_tag_scope_; }
152
+ void set_tag(TagScope* scope) { top_tag_scope_ = scope; }
153
+
154
+ // The builder maintains a pointer to the currently opened attributes
155
+ // of current AST node or NULL if the attributes are not opened.
156
+ AttributesScope* attributes() { return attributes_scope_; }
157
+ void set_attributes(AttributesScope* scope) { attributes_scope_ = scope; }
158
+
159
+ // Add an attribute to the currently opened attributes.
160
+ void AddAttribute(const char* name, Handle<String> value);
161
+ void AddAttribute(const char* name, const char* value);
162
+ void AddAttribute(const char* name, int value);
163
+ void AddAttribute(const char* name, bool value);
164
+
165
+ // AST node visit functions.
166
+ virtual void VisitSlot(Slot* node);
167
+ #define DECLARE_VISIT(type) virtual void Visit##type(type* node);
168
+ AST_NODE_LIST(DECLARE_VISIT)
169
+ #undef DECLARE_VISIT
170
+
171
+ private:
172
+ int indent_;
173
+ TagScope* top_tag_scope_;
174
+ AttributesScope* attributes_scope_;
175
+
176
+ // Utility function used by AddAttribute implementations.
177
+ void AddAttributePrefix(const char* name);
178
+ };
179
+
180
+
181
+ // The JSON AST builder keeps a stack of open element tags (AST node
182
+ // constructors from the current iteration point to the root of the
183
+ // AST). TagScope is a helper class to manage the opening and closing
184
+ // of tags, the indentation of their bodies, and comma separating their
185
+ // contents.
186
+ class TagScope BASE_EMBEDDED {
187
+ public:
188
+ TagScope(JsonAstBuilder* builder, const char* name);
189
+ ~TagScope();
190
+
191
+ void use() { has_body_ = true; }
192
+
193
+ private:
194
+ JsonAstBuilder* builder_;
195
+ TagScope* next_;
196
+ bool has_body_;
197
+ };
198
+
199
+
200
+ // AttributesScope is a helper class to manage the opening and closing
201
+ // of attribute blocks, the indentation of their bodies, and comma
202
+ // separating their contents. JsonAstBuilder::AddAttribute adds an
203
+ // attribute to the currently open AttributesScope. They cannot be
204
+ // nested so the builder keeps an optional single scope rather than a
205
+ // stack.
206
+ class AttributesScope BASE_EMBEDDED {
207
+ public:
208
+ explicit AttributesScope(JsonAstBuilder* builder);
209
+ ~AttributesScope();
210
+
211
+ bool is_used() { return attribute_count_ > 0; }
212
+ void use() { ++attribute_count_; }
213
+
214
+ private:
215
+ JsonAstBuilder* builder_;
216
+ int attribute_count_;
217
+ };
218
+
219
+ #endif // DEBUG
220
+
221
+ } } // namespace v8::internal
222
+
223
+ #endif // V8_PRETTYPRINTER_H_
@@ -0,0 +1,128 @@
1
+ // Copyright 2010 the V8 project authors. All rights reserved.
2
+ // Redistribution and use in source and binary forms, with or without
3
+ // modification, are permitted provided that the following conditions are
4
+ // met:
5
+ //
6
+ // * Redistributions of source code must retain the above copyright
7
+ // notice, this list of conditions and the following disclaimer.
8
+ // * Redistributions in binary form must reproduce the above
9
+ // copyright notice, this list of conditions and the following
10
+ // disclaimer in the documentation and/or other materials provided
11
+ // with the distribution.
12
+ // * Neither the name of Google Inc. nor the names of its
13
+ // contributors may be used to endorse or promote products derived
14
+ // from this software without specific prior written permission.
15
+ //
16
+ // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
+ // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18
+ // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19
+ // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20
+ // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21
+ // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
+ // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
+ // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
+ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
+ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
+ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+
28
+ #ifndef V8_PROFILE_GENERATOR_INL_H_
29
+ #define V8_PROFILE_GENERATOR_INL_H_
30
+
31
+ #ifdef ENABLE_LOGGING_AND_PROFILING
32
+
33
+ #include "profile-generator.h"
34
+
35
+ namespace v8 {
36
+ namespace internal {
37
+
38
+ const char* StringsStorage::GetFunctionName(String* name) {
39
+ return GetFunctionName(GetName(name));
40
+ }
41
+
42
+
43
+ const char* StringsStorage::GetFunctionName(const char* name) {
44
+ return strlen(name) > 0 ? name : ProfileGenerator::kAnonymousFunctionName;
45
+ }
46
+
47
+
48
+ CodeEntry::CodeEntry(Logger::LogEventsAndTags tag,
49
+ const char* name_prefix,
50
+ const char* name,
51
+ const char* resource_name,
52
+ int line_number,
53
+ int security_token_id)
54
+ : tag_(tag),
55
+ name_prefix_(name_prefix),
56
+ name_(name),
57
+ resource_name_(resource_name),
58
+ line_number_(line_number),
59
+ shared_id_(0),
60
+ security_token_id_(security_token_id) {
61
+ }
62
+
63
+
64
+ bool CodeEntry::is_js_function_tag(Logger::LogEventsAndTags tag) {
65
+ return tag == Logger::FUNCTION_TAG
66
+ || tag == Logger::LAZY_COMPILE_TAG
67
+ || tag == Logger::SCRIPT_TAG
68
+ || tag == Logger::NATIVE_FUNCTION_TAG
69
+ || tag == Logger::NATIVE_LAZY_COMPILE_TAG
70
+ || tag == Logger::NATIVE_SCRIPT_TAG;
71
+ }
72
+
73
+
74
+ ProfileNode::ProfileNode(ProfileTree* tree, CodeEntry* entry)
75
+ : tree_(tree),
76
+ entry_(entry),
77
+ total_ticks_(0),
78
+ self_ticks_(0),
79
+ children_(CodeEntriesMatch) {
80
+ }
81
+
82
+
83
+ void CodeMap::AddCode(Address addr, CodeEntry* entry, unsigned size) {
84
+ CodeTree::Locator locator;
85
+ tree_.Insert(addr, &locator);
86
+ locator.set_value(CodeEntryInfo(entry, size));
87
+ }
88
+
89
+
90
+ void CodeMap::MoveCode(Address from, Address to) {
91
+ tree_.Move(from, to);
92
+ }
93
+
94
+ void CodeMap::DeleteCode(Address addr) {
95
+ tree_.Remove(addr);
96
+ }
97
+
98
+
99
+ CodeEntry* ProfileGenerator::EntryForVMState(StateTag tag) {
100
+ switch (tag) {
101
+ case GC:
102
+ return gc_entry_;
103
+ case JS:
104
+ case COMPILER:
105
+ // DOM events handlers are reported as OTHER / EXTERNAL entries.
106
+ // To avoid confusing people, let's put all these entries into
107
+ // one bucket.
108
+ case OTHER:
109
+ case EXTERNAL:
110
+ return program_entry_;
111
+ default: return NULL;
112
+ }
113
+ }
114
+
115
+
116
+ uint64_t HeapEntry::id() {
117
+ union {
118
+ Id stored_id;
119
+ uint64_t returned_id;
120
+ } id_adaptor = {id_};
121
+ return id_adaptor.returned_id;
122
+ }
123
+
124
+ } } // namespace v8::internal
125
+
126
+ #endif // ENABLE_LOGGING_AND_PROFILING
127
+
128
+ #endif // V8_PROFILE_GENERATOR_INL_H_
@@ -0,0 +1,3098 @@
1
+ // Copyright 2011 the V8 project authors. All rights reserved.
2
+ // Redistribution and use in source and binary forms, with or without
3
+ // modification, are permitted provided that the following conditions are
4
+ // met:
5
+ //
6
+ // * Redistributions of source code must retain the above copyright
7
+ // notice, this list of conditions and the following disclaimer.
8
+ // * Redistributions in binary form must reproduce the above
9
+ // copyright notice, this list of conditions and the following
10
+ // disclaimer in the documentation and/or other materials provided
11
+ // with the distribution.
12
+ // * Neither the name of Google Inc. nor the names of its
13
+ // contributors may be used to endorse or promote products derived
14
+ // from this software without specific prior written permission.
15
+ //
16
+ // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
+ // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18
+ // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19
+ // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20
+ // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21
+ // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
+ // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
+ // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
+ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
+ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
+ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+
28
+ #ifdef ENABLE_LOGGING_AND_PROFILING
29
+
30
+ #include "v8.h"
31
+
32
+ #include "profile-generator-inl.h"
33
+
34
+ #include "global-handles.h"
35
+ #include "heap-profiler.h"
36
+ #include "scopeinfo.h"
37
+ #include "unicode.h"
38
+ #include "zone-inl.h"
39
+
40
+ namespace v8 {
41
+ namespace internal {
42
+
43
+
44
+ TokenEnumerator::TokenEnumerator()
45
+ : token_locations_(4),
46
+ token_removed_(4) {
47
+ }
48
+
49
+
50
+ TokenEnumerator::~TokenEnumerator() {
51
+ Isolate* isolate = Isolate::Current();
52
+ for (int i = 0; i < token_locations_.length(); ++i) {
53
+ if (!token_removed_[i]) {
54
+ isolate->global_handles()->ClearWeakness(token_locations_[i]);
55
+ isolate->global_handles()->Destroy(token_locations_[i]);
56
+ }
57
+ }
58
+ }
59
+
60
+
61
+ int TokenEnumerator::GetTokenId(Object* token) {
62
+ Isolate* isolate = Isolate::Current();
63
+ if (token == NULL) return TokenEnumerator::kNoSecurityToken;
64
+ for (int i = 0; i < token_locations_.length(); ++i) {
65
+ if (*token_locations_[i] == token && !token_removed_[i]) return i;
66
+ }
67
+ Handle<Object> handle = isolate->global_handles()->Create(token);
68
+ // handle.location() points to a memory cell holding a pointer
69
+ // to a token object in the V8's heap.
70
+ isolate->global_handles()->MakeWeak(handle.location(), this,
71
+ TokenRemovedCallback);
72
+ token_locations_.Add(handle.location());
73
+ token_removed_.Add(false);
74
+ return token_locations_.length() - 1;
75
+ }
76
+
77
+
78
+ void TokenEnumerator::TokenRemovedCallback(v8::Persistent<v8::Value> handle,
79
+ void* parameter) {
80
+ reinterpret_cast<TokenEnumerator*>(parameter)->TokenRemoved(
81
+ Utils::OpenHandle(*handle).location());
82
+ handle.Dispose();
83
+ }
84
+
85
+
86
+ void TokenEnumerator::TokenRemoved(Object** token_location) {
87
+ for (int i = 0; i < token_locations_.length(); ++i) {
88
+ if (token_locations_[i] == token_location && !token_removed_[i]) {
89
+ token_removed_[i] = true;
90
+ return;
91
+ }
92
+ }
93
+ }
94
+
95
+
96
+ StringsStorage::StringsStorage()
97
+ : names_(StringsMatch) {
98
+ }
99
+
100
+
101
+ StringsStorage::~StringsStorage() {
102
+ for (HashMap::Entry* p = names_.Start();
103
+ p != NULL;
104
+ p = names_.Next(p)) {
105
+ DeleteArray(reinterpret_cast<const char*>(p->value));
106
+ }
107
+ }
108
+
109
+
110
+ const char* StringsStorage::GetCopy(const char* src) {
111
+ int len = static_cast<int>(strlen(src));
112
+ Vector<char> dst = Vector<char>::New(len + 1);
113
+ OS::StrNCpy(dst, src, len);
114
+ dst[len] = '\0';
115
+ uint32_t hash = HashSequentialString(dst.start(), len);
116
+ return AddOrDisposeString(dst.start(), hash);
117
+ }
118
+
119
+
120
+ const char* StringsStorage::GetFormatted(const char* format, ...) {
121
+ va_list args;
122
+ va_start(args, format);
123
+ const char* result = GetVFormatted(format, args);
124
+ va_end(args);
125
+ return result;
126
+ }
127
+
128
+
129
+ const char* StringsStorage::AddOrDisposeString(char* str, uint32_t hash) {
130
+ HashMap::Entry* cache_entry = names_.Lookup(str, hash, true);
131
+ if (cache_entry->value == NULL) {
132
+ // New entry added.
133
+ cache_entry->value = str;
134
+ } else {
135
+ DeleteArray(str);
136
+ }
137
+ return reinterpret_cast<const char*>(cache_entry->value);
138
+ }
139
+
140
+
141
+ const char* StringsStorage::GetVFormatted(const char* format, va_list args) {
142
+ Vector<char> str = Vector<char>::New(1024);
143
+ int len = OS::VSNPrintF(str, format, args);
144
+ if (len == -1) {
145
+ DeleteArray(str.start());
146
+ return format;
147
+ }
148
+ uint32_t hash = HashSequentialString(str.start(), len);
149
+ return AddOrDisposeString(str.start(), hash);
150
+ }
151
+
152
+
153
+ const char* StringsStorage::GetName(String* name) {
154
+ if (name->IsString()) {
155
+ return AddOrDisposeString(
156
+ name->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL).Detach(),
157
+ name->Hash());
158
+ }
159
+ return "";
160
+ }
161
+
162
+
163
+ const char* StringsStorage::GetName(int index) {
164
+ return GetFormatted("%d", index);
165
+ }
166
+
167
+
168
+ const char* const CodeEntry::kEmptyNamePrefix = "";
169
+
170
+
171
+ void CodeEntry::CopyData(const CodeEntry& source) {
172
+ tag_ = source.tag_;
173
+ name_prefix_ = source.name_prefix_;
174
+ name_ = source.name_;
175
+ resource_name_ = source.resource_name_;
176
+ line_number_ = source.line_number_;
177
+ }
178
+
179
+
180
+ uint32_t CodeEntry::GetCallUid() const {
181
+ uint32_t hash = ComputeIntegerHash(tag_);
182
+ if (shared_id_ != 0) {
183
+ hash ^= ComputeIntegerHash(
184
+ static_cast<uint32_t>(shared_id_));
185
+ } else {
186
+ hash ^= ComputeIntegerHash(
187
+ static_cast<uint32_t>(reinterpret_cast<uintptr_t>(name_prefix_)));
188
+ hash ^= ComputeIntegerHash(
189
+ static_cast<uint32_t>(reinterpret_cast<uintptr_t>(name_)));
190
+ hash ^= ComputeIntegerHash(
191
+ static_cast<uint32_t>(reinterpret_cast<uintptr_t>(resource_name_)));
192
+ hash ^= ComputeIntegerHash(line_number_);
193
+ }
194
+ return hash;
195
+ }
196
+
197
+
198
+ bool CodeEntry::IsSameAs(CodeEntry* entry) const {
199
+ return this == entry
200
+ || (tag_ == entry->tag_
201
+ && shared_id_ == entry->shared_id_
202
+ && (shared_id_ != 0
203
+ || (name_prefix_ == entry->name_prefix_
204
+ && name_ == entry->name_
205
+ && resource_name_ == entry->resource_name_
206
+ && line_number_ == entry->line_number_)));
207
+ }
208
+
209
+
210
+ ProfileNode* ProfileNode::FindChild(CodeEntry* entry) {
211
+ HashMap::Entry* map_entry =
212
+ children_.Lookup(entry, CodeEntryHash(entry), false);
213
+ return map_entry != NULL ?
214
+ reinterpret_cast<ProfileNode*>(map_entry->value) : NULL;
215
+ }
216
+
217
+
218
+ ProfileNode* ProfileNode::FindOrAddChild(CodeEntry* entry) {
219
+ HashMap::Entry* map_entry =
220
+ children_.Lookup(entry, CodeEntryHash(entry), true);
221
+ if (map_entry->value == NULL) {
222
+ // New node added.
223
+ ProfileNode* new_node = new ProfileNode(tree_, entry);
224
+ map_entry->value = new_node;
225
+ children_list_.Add(new_node);
226
+ }
227
+ return reinterpret_cast<ProfileNode*>(map_entry->value);
228
+ }
229
+
230
+
231
+ double ProfileNode::GetSelfMillis() const {
232
+ return tree_->TicksToMillis(self_ticks_);
233
+ }
234
+
235
+
236
+ double ProfileNode::GetTotalMillis() const {
237
+ return tree_->TicksToMillis(total_ticks_);
238
+ }
239
+
240
+
241
+ void ProfileNode::Print(int indent) {
242
+ OS::Print("%5u %5u %*c %s%s [%d]",
243
+ total_ticks_, self_ticks_,
244
+ indent, ' ',
245
+ entry_->name_prefix(),
246
+ entry_->name(),
247
+ entry_->security_token_id());
248
+ if (entry_->resource_name()[0] != '\0')
249
+ OS::Print(" %s:%d", entry_->resource_name(), entry_->line_number());
250
+ OS::Print("\n");
251
+ for (HashMap::Entry* p = children_.Start();
252
+ p != NULL;
253
+ p = children_.Next(p)) {
254
+ reinterpret_cast<ProfileNode*>(p->value)->Print(indent + 2);
255
+ }
256
+ }
257
+
258
+
259
+ class DeleteNodesCallback {
260
+ public:
261
+ void BeforeTraversingChild(ProfileNode*, ProfileNode*) { }
262
+
263
+ void AfterAllChildrenTraversed(ProfileNode* node) {
264
+ delete node;
265
+ }
266
+
267
+ void AfterChildTraversed(ProfileNode*, ProfileNode*) { }
268
+ };
269
+
270
+
271
+ ProfileTree::ProfileTree()
272
+ : root_entry_(Logger::FUNCTION_TAG,
273
+ "",
274
+ "(root)",
275
+ "",
276
+ 0,
277
+ TokenEnumerator::kNoSecurityToken),
278
+ root_(new ProfileNode(this, &root_entry_)) {
279
+ }
280
+
281
+
282
+ ProfileTree::~ProfileTree() {
283
+ DeleteNodesCallback cb;
284
+ TraverseDepthFirst(&cb);
285
+ }
286
+
287
+
288
+ void ProfileTree::AddPathFromEnd(const Vector<CodeEntry*>& path) {
289
+ ProfileNode* node = root_;
290
+ for (CodeEntry** entry = path.start() + path.length() - 1;
291
+ entry != path.start() - 1;
292
+ --entry) {
293
+ if (*entry != NULL) {
294
+ node = node->FindOrAddChild(*entry);
295
+ }
296
+ }
297
+ node->IncrementSelfTicks();
298
+ }
299
+
300
+
301
+ void ProfileTree::AddPathFromStart(const Vector<CodeEntry*>& path) {
302
+ ProfileNode* node = root_;
303
+ for (CodeEntry** entry = path.start();
304
+ entry != path.start() + path.length();
305
+ ++entry) {
306
+ if (*entry != NULL) {
307
+ node = node->FindOrAddChild(*entry);
308
+ }
309
+ }
310
+ node->IncrementSelfTicks();
311
+ }
312
+
313
+
314
+ struct NodesPair {
315
+ NodesPair(ProfileNode* src, ProfileNode* dst)
316
+ : src(src), dst(dst) { }
317
+ ProfileNode* src;
318
+ ProfileNode* dst;
319
+ };
320
+
321
+
322
+ class FilteredCloneCallback {
323
+ public:
324
+ FilteredCloneCallback(ProfileNode* dst_root, int security_token_id)
325
+ : stack_(10),
326
+ security_token_id_(security_token_id) {
327
+ stack_.Add(NodesPair(NULL, dst_root));
328
+ }
329
+
330
+ void BeforeTraversingChild(ProfileNode* parent, ProfileNode* child) {
331
+ if (IsTokenAcceptable(child->entry()->security_token_id(),
332
+ parent->entry()->security_token_id())) {
333
+ ProfileNode* clone = stack_.last().dst->FindOrAddChild(child->entry());
334
+ clone->IncreaseSelfTicks(child->self_ticks());
335
+ stack_.Add(NodesPair(child, clone));
336
+ } else {
337
+ // Attribute ticks to parent node.
338
+ stack_.last().dst->IncreaseSelfTicks(child->self_ticks());
339
+ }
340
+ }
341
+
342
+ void AfterAllChildrenTraversed(ProfileNode* parent) { }
343
+
344
+ void AfterChildTraversed(ProfileNode*, ProfileNode* child) {
345
+ if (stack_.last().src == child) {
346
+ stack_.RemoveLast();
347
+ }
348
+ }
349
+
350
+ private:
351
+ bool IsTokenAcceptable(int token, int parent_token) {
352
+ if (token == TokenEnumerator::kNoSecurityToken
353
+ || token == security_token_id_) return true;
354
+ if (token == TokenEnumerator::kInheritsSecurityToken) {
355
+ ASSERT(parent_token != TokenEnumerator::kInheritsSecurityToken);
356
+ return parent_token == TokenEnumerator::kNoSecurityToken
357
+ || parent_token == security_token_id_;
358
+ }
359
+ return false;
360
+ }
361
+
362
+ List<NodesPair> stack_;
363
+ int security_token_id_;
364
+ };
365
+
366
+ void ProfileTree::FilteredClone(ProfileTree* src, int security_token_id) {
367
+ ms_to_ticks_scale_ = src->ms_to_ticks_scale_;
368
+ FilteredCloneCallback cb(root_, security_token_id);
369
+ src->TraverseDepthFirst(&cb);
370
+ CalculateTotalTicks();
371
+ }
372
+
373
+
374
+ void ProfileTree::SetTickRatePerMs(double ticks_per_ms) {
375
+ ms_to_ticks_scale_ = ticks_per_ms > 0 ? 1.0 / ticks_per_ms : 1.0;
376
+ }
377
+
378
+
379
+ class Position {
380
+ public:
381
+ explicit Position(ProfileNode* node)
382
+ : node(node), child_idx_(0) { }
383
+ INLINE(ProfileNode* current_child()) {
384
+ return node->children()->at(child_idx_);
385
+ }
386
+ INLINE(bool has_current_child()) {
387
+ return child_idx_ < node->children()->length();
388
+ }
389
+ INLINE(void next_child()) { ++child_idx_; }
390
+
391
+ ProfileNode* node;
392
+ private:
393
+ int child_idx_;
394
+ };
395
+
396
+
397
+ // Non-recursive implementation of a depth-first post-order tree traversal.
398
+ template <typename Callback>
399
+ void ProfileTree::TraverseDepthFirst(Callback* callback) {
400
+ List<Position> stack(10);
401
+ stack.Add(Position(root_));
402
+ while (stack.length() > 0) {
403
+ Position& current = stack.last();
404
+ if (current.has_current_child()) {
405
+ callback->BeforeTraversingChild(current.node, current.current_child());
406
+ stack.Add(Position(current.current_child()));
407
+ } else {
408
+ callback->AfterAllChildrenTraversed(current.node);
409
+ if (stack.length() > 1) {
410
+ Position& parent = stack[stack.length() - 2];
411
+ callback->AfterChildTraversed(parent.node, current.node);
412
+ parent.next_child();
413
+ }
414
+ // Remove child from the stack.
415
+ stack.RemoveLast();
416
+ }
417
+ }
418
+ }
419
+
420
+
421
+ class CalculateTotalTicksCallback {
422
+ public:
423
+ void BeforeTraversingChild(ProfileNode*, ProfileNode*) { }
424
+
425
+ void AfterAllChildrenTraversed(ProfileNode* node) {
426
+ node->IncreaseTotalTicks(node->self_ticks());
427
+ }
428
+
429
+ void AfterChildTraversed(ProfileNode* parent, ProfileNode* child) {
430
+ parent->IncreaseTotalTicks(child->total_ticks());
431
+ }
432
+ };
433
+
434
+
435
+ void ProfileTree::CalculateTotalTicks() {
436
+ CalculateTotalTicksCallback cb;
437
+ TraverseDepthFirst(&cb);
438
+ }
439
+
440
+
441
+ void ProfileTree::ShortPrint() {
442
+ OS::Print("root: %u %u %.2fms %.2fms\n",
443
+ root_->total_ticks(), root_->self_ticks(),
444
+ root_->GetTotalMillis(), root_->GetSelfMillis());
445
+ }
446
+
447
+
448
+ void CpuProfile::AddPath(const Vector<CodeEntry*>& path) {
449
+ top_down_.AddPathFromEnd(path);
450
+ bottom_up_.AddPathFromStart(path);
451
+ }
452
+
453
+
454
+ void CpuProfile::CalculateTotalTicks() {
455
+ top_down_.CalculateTotalTicks();
456
+ bottom_up_.CalculateTotalTicks();
457
+ }
458
+
459
+
460
+ void CpuProfile::SetActualSamplingRate(double actual_sampling_rate) {
461
+ top_down_.SetTickRatePerMs(actual_sampling_rate);
462
+ bottom_up_.SetTickRatePerMs(actual_sampling_rate);
463
+ }
464
+
465
+
466
+ CpuProfile* CpuProfile::FilteredClone(int security_token_id) {
467
+ ASSERT(security_token_id != TokenEnumerator::kNoSecurityToken);
468
+ CpuProfile* clone = new CpuProfile(title_, uid_);
469
+ clone->top_down_.FilteredClone(&top_down_, security_token_id);
470
+ clone->bottom_up_.FilteredClone(&bottom_up_, security_token_id);
471
+ return clone;
472
+ }
473
+
474
+
475
+ void CpuProfile::ShortPrint() {
476
+ OS::Print("top down ");
477
+ top_down_.ShortPrint();
478
+ OS::Print("bottom up ");
479
+ bottom_up_.ShortPrint();
480
+ }
481
+
482
+
483
+ void CpuProfile::Print() {
484
+ OS::Print("[Top down]:\n");
485
+ top_down_.Print();
486
+ OS::Print("[Bottom up]:\n");
487
+ bottom_up_.Print();
488
+ }
489
+
490
+
491
+ CodeEntry* const CodeMap::kSharedFunctionCodeEntry = NULL;
492
+ const CodeMap::CodeTreeConfig::Key CodeMap::CodeTreeConfig::kNoKey = NULL;
493
+ const CodeMap::CodeTreeConfig::Value CodeMap::CodeTreeConfig::kNoValue =
494
+ CodeMap::CodeEntryInfo(NULL, 0);
495
+
496
+
497
+ CodeEntry* CodeMap::FindEntry(Address addr) {
498
+ CodeTree::Locator locator;
499
+ if (tree_.FindGreatestLessThan(addr, &locator)) {
500
+ // locator.key() <= addr. Need to check that addr is within entry.
501
+ const CodeEntryInfo& entry = locator.value();
502
+ if (addr < (locator.key() + entry.size))
503
+ return entry.entry;
504
+ }
505
+ return NULL;
506
+ }
507
+
508
+
509
+ int CodeMap::GetSharedId(Address addr) {
510
+ CodeTree::Locator locator;
511
+ // For shared function entries, 'size' field is used to store their IDs.
512
+ if (tree_.Find(addr, &locator)) {
513
+ const CodeEntryInfo& entry = locator.value();
514
+ ASSERT(entry.entry == kSharedFunctionCodeEntry);
515
+ return entry.size;
516
+ } else {
517
+ tree_.Insert(addr, &locator);
518
+ int id = next_shared_id_++;
519
+ locator.set_value(CodeEntryInfo(kSharedFunctionCodeEntry, id));
520
+ return id;
521
+ }
522
+ }
523
+
524
+
525
+ void CodeMap::CodeTreePrinter::Call(
526
+ const Address& key, const CodeMap::CodeEntryInfo& value) {
527
+ OS::Print("%p %5d %s\n", key, value.size, value.entry->name());
528
+ }
529
+
530
+
531
+ void CodeMap::Print() {
532
+ CodeTreePrinter printer;
533
+ tree_.ForEach(&printer);
534
+ }
535
+
536
+
537
+ CpuProfilesCollection::CpuProfilesCollection()
538
+ : profiles_uids_(UidsMatch),
539
+ current_profiles_semaphore_(OS::CreateSemaphore(1)) {
540
+ // Create list of unabridged profiles.
541
+ profiles_by_token_.Add(new List<CpuProfile*>());
542
+ }
543
+
544
+
545
+ static void DeleteCodeEntry(CodeEntry** entry_ptr) {
546
+ delete *entry_ptr;
547
+ }
548
+
549
+ static void DeleteCpuProfile(CpuProfile** profile_ptr) {
550
+ delete *profile_ptr;
551
+ }
552
+
553
+ static void DeleteProfilesList(List<CpuProfile*>** list_ptr) {
554
+ if (*list_ptr != NULL) {
555
+ (*list_ptr)->Iterate(DeleteCpuProfile);
556
+ delete *list_ptr;
557
+ }
558
+ }
559
+
560
+ CpuProfilesCollection::~CpuProfilesCollection() {
561
+ delete current_profiles_semaphore_;
562
+ current_profiles_.Iterate(DeleteCpuProfile);
563
+ detached_profiles_.Iterate(DeleteCpuProfile);
564
+ profiles_by_token_.Iterate(DeleteProfilesList);
565
+ code_entries_.Iterate(DeleteCodeEntry);
566
+ }
567
+
568
+
569
+ bool CpuProfilesCollection::StartProfiling(const char* title, unsigned uid) {
570
+ ASSERT(uid > 0);
571
+ current_profiles_semaphore_->Wait();
572
+ if (current_profiles_.length() >= kMaxSimultaneousProfiles) {
573
+ current_profiles_semaphore_->Signal();
574
+ return false;
575
+ }
576
+ for (int i = 0; i < current_profiles_.length(); ++i) {
577
+ if (strcmp(current_profiles_[i]->title(), title) == 0) {
578
+ // Ignore attempts to start profile with the same title.
579
+ current_profiles_semaphore_->Signal();
580
+ return false;
581
+ }
582
+ }
583
+ current_profiles_.Add(new CpuProfile(title, uid));
584
+ current_profiles_semaphore_->Signal();
585
+ return true;
586
+ }
587
+
588
+
589
+ bool CpuProfilesCollection::StartProfiling(String* title, unsigned uid) {
590
+ return StartProfiling(GetName(title), uid);
591
+ }
592
+
593
+
594
+ CpuProfile* CpuProfilesCollection::StopProfiling(int security_token_id,
595
+ const char* title,
596
+ double actual_sampling_rate) {
597
+ const int title_len = StrLength(title);
598
+ CpuProfile* profile = NULL;
599
+ current_profiles_semaphore_->Wait();
600
+ for (int i = current_profiles_.length() - 1; i >= 0; --i) {
601
+ if (title_len == 0 || strcmp(current_profiles_[i]->title(), title) == 0) {
602
+ profile = current_profiles_.Remove(i);
603
+ break;
604
+ }
605
+ }
606
+ current_profiles_semaphore_->Signal();
607
+
608
+ if (profile != NULL) {
609
+ profile->CalculateTotalTicks();
610
+ profile->SetActualSamplingRate(actual_sampling_rate);
611
+ List<CpuProfile*>* unabridged_list =
612
+ profiles_by_token_[TokenToIndex(TokenEnumerator::kNoSecurityToken)];
613
+ unabridged_list->Add(profile);
614
+ HashMap::Entry* entry =
615
+ profiles_uids_.Lookup(reinterpret_cast<void*>(profile->uid()),
616
+ static_cast<uint32_t>(profile->uid()),
617
+ true);
618
+ ASSERT(entry->value == NULL);
619
+ entry->value = reinterpret_cast<void*>(unabridged_list->length() - 1);
620
+ return GetProfile(security_token_id, profile->uid());
621
+ }
622
+ return NULL;
623
+ }
624
+
625
+
626
+ CpuProfile* CpuProfilesCollection::GetProfile(int security_token_id,
627
+ unsigned uid) {
628
+ int index = GetProfileIndex(uid);
629
+ if (index < 0) return NULL;
630
+ List<CpuProfile*>* unabridged_list =
631
+ profiles_by_token_[TokenToIndex(TokenEnumerator::kNoSecurityToken)];
632
+ if (security_token_id == TokenEnumerator::kNoSecurityToken) {
633
+ return unabridged_list->at(index);
634
+ }
635
+ List<CpuProfile*>* list = GetProfilesList(security_token_id);
636
+ if (list->at(index) == NULL) {
637
+ (*list)[index] =
638
+ unabridged_list->at(index)->FilteredClone(security_token_id);
639
+ }
640
+ return list->at(index);
641
+ }
642
+
643
+
644
+ int CpuProfilesCollection::GetProfileIndex(unsigned uid) {
645
+ HashMap::Entry* entry = profiles_uids_.Lookup(reinterpret_cast<void*>(uid),
646
+ static_cast<uint32_t>(uid),
647
+ false);
648
+ return entry != NULL ?
649
+ static_cast<int>(reinterpret_cast<intptr_t>(entry->value)) : -1;
650
+ }
651
+
652
+
653
+ bool CpuProfilesCollection::IsLastProfile(const char* title) {
654
+ // Called from VM thread, and only it can mutate the list,
655
+ // so no locking is needed here.
656
+ if (current_profiles_.length() != 1) return false;
657
+ return StrLength(title) == 0
658
+ || strcmp(current_profiles_[0]->title(), title) == 0;
659
+ }
660
+
661
+
662
+ void CpuProfilesCollection::RemoveProfile(CpuProfile* profile) {
663
+ // Called from VM thread for a completed profile.
664
+ unsigned uid = profile->uid();
665
+ int index = GetProfileIndex(uid);
666
+ if (index < 0) {
667
+ detached_profiles_.RemoveElement(profile);
668
+ return;
669
+ }
670
+ profiles_uids_.Remove(reinterpret_cast<void*>(uid),
671
+ static_cast<uint32_t>(uid));
672
+ // Decrement all indexes above the deleted one.
673
+ for (HashMap::Entry* p = profiles_uids_.Start();
674
+ p != NULL;
675
+ p = profiles_uids_.Next(p)) {
676
+ intptr_t p_index = reinterpret_cast<intptr_t>(p->value);
677
+ if (p_index > index) {
678
+ p->value = reinterpret_cast<void*>(p_index - 1);
679
+ }
680
+ }
681
+ for (int i = 0; i < profiles_by_token_.length(); ++i) {
682
+ List<CpuProfile*>* list = profiles_by_token_[i];
683
+ if (list != NULL && index < list->length()) {
684
+ // Move all filtered clones into detached_profiles_,
685
+ // so we can know that they are still in use.
686
+ CpuProfile* cloned_profile = list->Remove(index);
687
+ if (cloned_profile != NULL && cloned_profile != profile) {
688
+ detached_profiles_.Add(cloned_profile);
689
+ }
690
+ }
691
+ }
692
+ }
693
+
694
+
695
+ int CpuProfilesCollection::TokenToIndex(int security_token_id) {
696
+ ASSERT(TokenEnumerator::kNoSecurityToken == -1);
697
+ return security_token_id + 1; // kNoSecurityToken -> 0, 0 -> 1, ...
698
+ }
699
+
700
+
701
+ List<CpuProfile*>* CpuProfilesCollection::GetProfilesList(
702
+ int security_token_id) {
703
+ const int index = TokenToIndex(security_token_id);
704
+ const int lists_to_add = index - profiles_by_token_.length() + 1;
705
+ if (lists_to_add > 0) profiles_by_token_.AddBlock(NULL, lists_to_add);
706
+ List<CpuProfile*>* unabridged_list =
707
+ profiles_by_token_[TokenToIndex(TokenEnumerator::kNoSecurityToken)];
708
+ const int current_count = unabridged_list->length();
709
+ if (profiles_by_token_[index] == NULL) {
710
+ profiles_by_token_[index] = new List<CpuProfile*>(current_count);
711
+ }
712
+ List<CpuProfile*>* list = profiles_by_token_[index];
713
+ const int profiles_to_add = current_count - list->length();
714
+ if (profiles_to_add > 0) list->AddBlock(NULL, profiles_to_add);
715
+ return list;
716
+ }
717
+
718
+
719
+ List<CpuProfile*>* CpuProfilesCollection::Profiles(int security_token_id) {
720
+ List<CpuProfile*>* unabridged_list =
721
+ profiles_by_token_[TokenToIndex(TokenEnumerator::kNoSecurityToken)];
722
+ if (security_token_id == TokenEnumerator::kNoSecurityToken) {
723
+ return unabridged_list;
724
+ }
725
+ List<CpuProfile*>* list = GetProfilesList(security_token_id);
726
+ const int current_count = unabridged_list->length();
727
+ for (int i = 0; i < current_count; ++i) {
728
+ if (list->at(i) == NULL) {
729
+ (*list)[i] = unabridged_list->at(i)->FilteredClone(security_token_id);
730
+ }
731
+ }
732
+ return list;
733
+ }
734
+
735
+
736
+ CodeEntry* CpuProfilesCollection::NewCodeEntry(Logger::LogEventsAndTags tag,
737
+ String* name,
738
+ String* resource_name,
739
+ int line_number) {
740
+ CodeEntry* entry = new CodeEntry(tag,
741
+ CodeEntry::kEmptyNamePrefix,
742
+ GetFunctionName(name),
743
+ GetName(resource_name),
744
+ line_number,
745
+ TokenEnumerator::kNoSecurityToken);
746
+ code_entries_.Add(entry);
747
+ return entry;
748
+ }
749
+
750
+
751
+ CodeEntry* CpuProfilesCollection::NewCodeEntry(Logger::LogEventsAndTags tag,
752
+ const char* name) {
753
+ CodeEntry* entry = new CodeEntry(tag,
754
+ CodeEntry::kEmptyNamePrefix,
755
+ GetFunctionName(name),
756
+ "",
757
+ v8::CpuProfileNode::kNoLineNumberInfo,
758
+ TokenEnumerator::kNoSecurityToken);
759
+ code_entries_.Add(entry);
760
+ return entry;
761
+ }
762
+
763
+
764
+ CodeEntry* CpuProfilesCollection::NewCodeEntry(Logger::LogEventsAndTags tag,
765
+ const char* name_prefix,
766
+ String* name) {
767
+ CodeEntry* entry = new CodeEntry(tag,
768
+ name_prefix,
769
+ GetName(name),
770
+ "",
771
+ v8::CpuProfileNode::kNoLineNumberInfo,
772
+ TokenEnumerator::kInheritsSecurityToken);
773
+ code_entries_.Add(entry);
774
+ return entry;
775
+ }
776
+
777
+
778
+ CodeEntry* CpuProfilesCollection::NewCodeEntry(Logger::LogEventsAndTags tag,
779
+ int args_count) {
780
+ CodeEntry* entry = new CodeEntry(tag,
781
+ "args_count: ",
782
+ GetName(args_count),
783
+ "",
784
+ v8::CpuProfileNode::kNoLineNumberInfo,
785
+ TokenEnumerator::kInheritsSecurityToken);
786
+ code_entries_.Add(entry);
787
+ return entry;
788
+ }
789
+
790
+
791
+ void CpuProfilesCollection::AddPathToCurrentProfiles(
792
+ const Vector<CodeEntry*>& path) {
793
+ // As starting / stopping profiles is rare relatively to this
794
+ // method, we don't bother minimizing the duration of lock holding,
795
+ // e.g. copying contents of the list to a local vector.
796
+ current_profiles_semaphore_->Wait();
797
+ for (int i = 0; i < current_profiles_.length(); ++i) {
798
+ current_profiles_[i]->AddPath(path);
799
+ }
800
+ current_profiles_semaphore_->Signal();
801
+ }
802
+
803
+
804
+ void SampleRateCalculator::Tick() {
805
+ if (--wall_time_query_countdown_ == 0)
806
+ UpdateMeasurements(OS::TimeCurrentMillis());
807
+ }
808
+
809
+
810
+ void SampleRateCalculator::UpdateMeasurements(double current_time) {
811
+ if (measurements_count_++ != 0) {
812
+ const double measured_ticks_per_ms =
813
+ (kWallTimeQueryIntervalMs * ticks_per_ms_) /
814
+ (current_time - last_wall_time_);
815
+ // Update the average value.
816
+ ticks_per_ms_ +=
817
+ (measured_ticks_per_ms - ticks_per_ms_) / measurements_count_;
818
+ // Update the externally accessible result.
819
+ result_ = static_cast<AtomicWord>(ticks_per_ms_ * kResultScale);
820
+ }
821
+ last_wall_time_ = current_time;
822
+ wall_time_query_countdown_ =
823
+ static_cast<unsigned>(kWallTimeQueryIntervalMs * ticks_per_ms_);
824
+ }
825
+
826
+
827
+ const char* const ProfileGenerator::kAnonymousFunctionName =
828
+ "(anonymous function)";
829
+ const char* const ProfileGenerator::kProgramEntryName =
830
+ "(program)";
831
+ const char* const ProfileGenerator::kGarbageCollectorEntryName =
832
+ "(garbage collector)";
833
+
834
+
835
+ ProfileGenerator::ProfileGenerator(CpuProfilesCollection* profiles)
836
+ : profiles_(profiles),
837
+ program_entry_(
838
+ profiles->NewCodeEntry(Logger::FUNCTION_TAG, kProgramEntryName)),
839
+ gc_entry_(
840
+ profiles->NewCodeEntry(Logger::BUILTIN_TAG,
841
+ kGarbageCollectorEntryName)) {
842
+ }
843
+
844
+
845
+ void ProfileGenerator::RecordTickSample(const TickSample& sample) {
846
+ // Allocate space for stack frames + pc + function + vm-state.
847
+ ScopedVector<CodeEntry*> entries(sample.frames_count + 3);
848
+ // As actual number of decoded code entries may vary, initialize
849
+ // entries vector with NULL values.
850
+ CodeEntry** entry = entries.start();
851
+ memset(entry, 0, entries.length() * sizeof(*entry));
852
+ if (sample.pc != NULL) {
853
+ *entry++ = code_map_.FindEntry(sample.pc);
854
+
855
+ if (sample.has_external_callback) {
856
+ // Don't use PC when in external callback code, as it can point
857
+ // inside callback's code, and we will erroneously report
858
+ // that a callback calls itself.
859
+ *(entries.start()) = NULL;
860
+ *entry++ = code_map_.FindEntry(sample.external_callback);
861
+ } else if (sample.tos != NULL) {
862
+ // Find out, if top of stack was pointing inside a JS function
863
+ // meaning that we have encountered a frameless invocation.
864
+ *entry = code_map_.FindEntry(sample.tos);
865
+ if (*entry != NULL && !(*entry)->is_js_function()) {
866
+ *entry = NULL;
867
+ }
868
+ entry++;
869
+ }
870
+
871
+ for (const Address *stack_pos = sample.stack,
872
+ *stack_end = stack_pos + sample.frames_count;
873
+ stack_pos != stack_end;
874
+ ++stack_pos) {
875
+ *entry++ = code_map_.FindEntry(*stack_pos);
876
+ }
877
+ }
878
+
879
+ if (FLAG_prof_browser_mode) {
880
+ bool no_symbolized_entries = true;
881
+ for (CodeEntry** e = entries.start(); e != entry; ++e) {
882
+ if (*e != NULL) {
883
+ no_symbolized_entries = false;
884
+ break;
885
+ }
886
+ }
887
+ // If no frames were symbolized, put the VM state entry in.
888
+ if (no_symbolized_entries) {
889
+ *entry++ = EntryForVMState(sample.state);
890
+ }
891
+ }
892
+
893
+ profiles_->AddPathToCurrentProfiles(entries);
894
+ }
895
+
896
+
897
+ void HeapGraphEdge::Init(
898
+ int child_index, Type type, const char* name, HeapEntry* to) {
899
+ ASSERT(type == kContextVariable
900
+ || type == kProperty
901
+ || type == kInternal
902
+ || type == kShortcut);
903
+ child_index_ = child_index;
904
+ type_ = type;
905
+ name_ = name;
906
+ to_ = to;
907
+ }
908
+
909
+
910
+ void HeapGraphEdge::Init(int child_index, Type type, int index, HeapEntry* to) {
911
+ ASSERT(type == kElement || type == kHidden);
912
+ child_index_ = child_index;
913
+ type_ = type;
914
+ index_ = index;
915
+ to_ = to;
916
+ }
917
+
918
+
919
+ void HeapGraphEdge::Init(int child_index, int index, HeapEntry* to) {
920
+ Init(child_index, kElement, index, to);
921
+ }
922
+
923
+
924
+ HeapEntry* HeapGraphEdge::From() {
925
+ return reinterpret_cast<HeapEntry*>(this - child_index_) - 1;
926
+ }
927
+
928
+
929
+ void HeapEntry::Init(HeapSnapshot* snapshot,
930
+ Type type,
931
+ const char* name,
932
+ uint64_t id,
933
+ int self_size,
934
+ int children_count,
935
+ int retainers_count) {
936
+ snapshot_ = snapshot;
937
+ type_ = type;
938
+ painted_ = kUnpainted;
939
+ name_ = name;
940
+ self_size_ = self_size;
941
+ retained_size_ = 0;
942
+ children_count_ = children_count;
943
+ retainers_count_ = retainers_count;
944
+ dominator_ = NULL;
945
+
946
+ union {
947
+ uint64_t set_id;
948
+ Id stored_id;
949
+ } id_adaptor = {id};
950
+ id_ = id_adaptor.stored_id;
951
+ }
952
+
953
+
954
+ void HeapEntry::SetNamedReference(HeapGraphEdge::Type type,
955
+ int child_index,
956
+ const char* name,
957
+ HeapEntry* entry,
958
+ int retainer_index) {
959
+ children_arr()[child_index].Init(child_index, type, name, entry);
960
+ entry->retainers_arr()[retainer_index] = children_arr() + child_index;
961
+ }
962
+
963
+
964
+ void HeapEntry::SetIndexedReference(HeapGraphEdge::Type type,
965
+ int child_index,
966
+ int index,
967
+ HeapEntry* entry,
968
+ int retainer_index) {
969
+ children_arr()[child_index].Init(child_index, type, index, entry);
970
+ entry->retainers_arr()[retainer_index] = children_arr() + child_index;
971
+ }
972
+
973
+
974
+ void HeapEntry::SetUnidirElementReference(
975
+ int child_index, int index, HeapEntry* entry) {
976
+ children_arr()[child_index].Init(child_index, index, entry);
977
+ }
978
+
979
+
980
+ int HeapEntry::RetainedSize(bool exact) {
981
+ if (exact && (retained_size_ & kExactRetainedSizeTag) == 0) {
982
+ CalculateExactRetainedSize();
983
+ }
984
+ return retained_size_ & (~kExactRetainedSizeTag);
985
+ }
986
+
987
+
988
+ template<class Visitor>
989
+ void HeapEntry::ApplyAndPaintAllReachable(Visitor* visitor) {
990
+ List<HeapEntry*> list(10);
991
+ list.Add(this);
992
+ this->paint_reachable();
993
+ visitor->Apply(this);
994
+ while (!list.is_empty()) {
995
+ HeapEntry* entry = list.RemoveLast();
996
+ Vector<HeapGraphEdge> children = entry->children();
997
+ for (int i = 0; i < children.length(); ++i) {
998
+ if (children[i].type() == HeapGraphEdge::kShortcut) continue;
999
+ HeapEntry* child = children[i].to();
1000
+ if (!child->painted_reachable()) {
1001
+ list.Add(child);
1002
+ child->paint_reachable();
1003
+ visitor->Apply(child);
1004
+ }
1005
+ }
1006
+ }
1007
+ }
1008
+
1009
+
1010
+ class NullClass {
1011
+ public:
1012
+ void Apply(HeapEntry* entry) { }
1013
+ };
1014
+
1015
+ void HeapEntry::PaintAllReachable() {
1016
+ NullClass null;
1017
+ ApplyAndPaintAllReachable(&null);
1018
+ }
1019
+
1020
+
1021
+ void HeapEntry::Print(int max_depth, int indent) {
1022
+ OS::Print("%6d %6d [%llu] ", self_size(), RetainedSize(false), id());
1023
+ if (type() != kString) {
1024
+ OS::Print("%s %.40s\n", TypeAsString(), name_);
1025
+ } else {
1026
+ OS::Print("\"");
1027
+ const char* c = name_;
1028
+ while (*c && (c - name_) <= 40) {
1029
+ if (*c != '\n')
1030
+ OS::Print("%c", *c);
1031
+ else
1032
+ OS::Print("\\n");
1033
+ ++c;
1034
+ }
1035
+ OS::Print("\"\n");
1036
+ }
1037
+ if (--max_depth == 0) return;
1038
+ Vector<HeapGraphEdge> ch = children();
1039
+ for (int i = 0; i < ch.length(); ++i) {
1040
+ HeapGraphEdge& edge = ch[i];
1041
+ switch (edge.type()) {
1042
+ case HeapGraphEdge::kContextVariable:
1043
+ OS::Print(" %*c #%s: ", indent, ' ', edge.name());
1044
+ break;
1045
+ case HeapGraphEdge::kElement:
1046
+ OS::Print(" %*c %d: ", indent, ' ', edge.index());
1047
+ break;
1048
+ case HeapGraphEdge::kInternal:
1049
+ OS::Print(" %*c $%s: ", indent, ' ', edge.name());
1050
+ break;
1051
+ case HeapGraphEdge::kProperty:
1052
+ OS::Print(" %*c %s: ", indent, ' ', edge.name());
1053
+ break;
1054
+ case HeapGraphEdge::kHidden:
1055
+ OS::Print(" %*c $%d: ", indent, ' ', edge.index());
1056
+ break;
1057
+ case HeapGraphEdge::kShortcut:
1058
+ OS::Print(" %*c ^%s: ", indent, ' ', edge.name());
1059
+ break;
1060
+ default:
1061
+ OS::Print("!!! unknown edge type: %d ", edge.type());
1062
+ }
1063
+ edge.to()->Print(max_depth, indent + 2);
1064
+ }
1065
+ }
1066
+
1067
+
1068
+ const char* HeapEntry::TypeAsString() {
1069
+ switch (type()) {
1070
+ case kHidden: return "/hidden/";
1071
+ case kObject: return "/object/";
1072
+ case kClosure: return "/closure/";
1073
+ case kString: return "/string/";
1074
+ case kCode: return "/code/";
1075
+ case kArray: return "/array/";
1076
+ case kRegExp: return "/regexp/";
1077
+ case kHeapNumber: return "/number/";
1078
+ case kNative: return "/native/";
1079
+ default: return "???";
1080
+ }
1081
+ }
1082
+
1083
+
1084
+ int HeapEntry::EntriesSize(int entries_count,
1085
+ int children_count,
1086
+ int retainers_count) {
1087
+ return sizeof(HeapEntry) * entries_count // NOLINT
1088
+ + sizeof(HeapGraphEdge) * children_count // NOLINT
1089
+ + sizeof(HeapGraphEdge*) * retainers_count; // NOLINT
1090
+ }
1091
+
1092
+
1093
+ class RetainedSizeCalculator {
1094
+ public:
1095
+ RetainedSizeCalculator()
1096
+ : retained_size_(0) {
1097
+ }
1098
+
1099
+ int reained_size() const { return retained_size_; }
1100
+
1101
+ void Apply(HeapEntry** entry_ptr) {
1102
+ if ((*entry_ptr)->painted_reachable()) {
1103
+ retained_size_ += (*entry_ptr)->self_size();
1104
+ }
1105
+ }
1106
+
1107
+ private:
1108
+ int retained_size_;
1109
+ };
1110
+
1111
+ void HeapEntry::CalculateExactRetainedSize() {
1112
+ // To calculate retained size, first we paint all reachable nodes in
1113
+ // one color, then we paint (or re-paint) all nodes reachable from
1114
+ // other nodes with a different color. Then we sum up self sizes of
1115
+ // nodes painted with the first color.
1116
+ snapshot()->ClearPaint();
1117
+ PaintAllReachable();
1118
+
1119
+ List<HeapEntry*> list(10);
1120
+ HeapEntry* root = snapshot()->root();
1121
+ if (this != root) {
1122
+ list.Add(root);
1123
+ root->paint_reachable_from_others();
1124
+ }
1125
+ while (!list.is_empty()) {
1126
+ HeapEntry* curr = list.RemoveLast();
1127
+ Vector<HeapGraphEdge> children = curr->children();
1128
+ for (int i = 0; i < children.length(); ++i) {
1129
+ if (children[i].type() == HeapGraphEdge::kShortcut) continue;
1130
+ HeapEntry* child = children[i].to();
1131
+ if (child != this && child->not_painted_reachable_from_others()) {
1132
+ list.Add(child);
1133
+ child->paint_reachable_from_others();
1134
+ }
1135
+ }
1136
+ }
1137
+
1138
+ RetainedSizeCalculator ret_size_calc;
1139
+ snapshot()->IterateEntries(&ret_size_calc);
1140
+ retained_size_ = ret_size_calc.reained_size();
1141
+ ASSERT((retained_size_ & kExactRetainedSizeTag) == 0);
1142
+ retained_size_ |= kExactRetainedSizeTag;
1143
+ }
1144
+
1145
+
1146
+ // It is very important to keep objects that form a heap snapshot
1147
+ // as small as possible.
1148
+ namespace { // Avoid littering the global namespace.
1149
+
1150
+ template <size_t ptr_size> struct SnapshotSizeConstants;
1151
+
1152
+ template <> struct SnapshotSizeConstants<4> {
1153
+ static const int kExpectedHeapGraphEdgeSize = 12;
1154
+ static const int kExpectedHeapEntrySize = 36;
1155
+ };
1156
+
1157
+ template <> struct SnapshotSizeConstants<8> {
1158
+ static const int kExpectedHeapGraphEdgeSize = 24;
1159
+ static const int kExpectedHeapEntrySize = 48;
1160
+ };
1161
+
1162
+ } // namespace
1163
+
1164
+ HeapSnapshot::HeapSnapshot(HeapSnapshotsCollection* collection,
1165
+ HeapSnapshot::Type type,
1166
+ const char* title,
1167
+ unsigned uid)
1168
+ : collection_(collection),
1169
+ type_(type),
1170
+ title_(title),
1171
+ uid_(uid),
1172
+ root_entry_(NULL),
1173
+ gc_roots_entry_(NULL),
1174
+ natives_root_entry_(NULL),
1175
+ raw_entries_(NULL),
1176
+ entries_sorted_(false) {
1177
+ STATIC_ASSERT(
1178
+ sizeof(HeapGraphEdge) ==
1179
+ SnapshotSizeConstants<sizeof(void*)>::kExpectedHeapGraphEdgeSize); // NOLINT
1180
+ STATIC_ASSERT(
1181
+ sizeof(HeapEntry) ==
1182
+ SnapshotSizeConstants<sizeof(void*)>::kExpectedHeapEntrySize); // NOLINT
1183
+ }
1184
+
1185
+ HeapSnapshot::~HeapSnapshot() {
1186
+ DeleteArray(raw_entries_);
1187
+ }
1188
+
1189
+
1190
+ void HeapSnapshot::Delete() {
1191
+ collection_->RemoveSnapshot(this);
1192
+ delete this;
1193
+ }
1194
+
1195
+
1196
+ void HeapSnapshot::AllocateEntries(int entries_count,
1197
+ int children_count,
1198
+ int retainers_count) {
1199
+ ASSERT(raw_entries_ == NULL);
1200
+ raw_entries_ = NewArray<char>(
1201
+ HeapEntry::EntriesSize(entries_count, children_count, retainers_count));
1202
+ #ifdef DEBUG
1203
+ raw_entries_size_ =
1204
+ HeapEntry::EntriesSize(entries_count, children_count, retainers_count);
1205
+ #endif
1206
+ }
1207
+
1208
+
1209
+ static void HeapEntryClearPaint(HeapEntry** entry_ptr) {
1210
+ (*entry_ptr)->clear_paint();
1211
+ }
1212
+
1213
+ void HeapSnapshot::ClearPaint() {
1214
+ entries_.Iterate(HeapEntryClearPaint);
1215
+ }
1216
+
1217
+
1218
+ HeapEntry* HeapSnapshot::AddRootEntry(int children_count) {
1219
+ ASSERT(root_entry_ == NULL);
1220
+ return (root_entry_ = AddEntry(HeapEntry::kObject,
1221
+ "",
1222
+ HeapObjectsMap::kInternalRootObjectId,
1223
+ 0,
1224
+ children_count,
1225
+ 0));
1226
+ }
1227
+
1228
+
1229
+ HeapEntry* HeapSnapshot::AddGcRootsEntry(int children_count,
1230
+ int retainers_count) {
1231
+ ASSERT(gc_roots_entry_ == NULL);
1232
+ return (gc_roots_entry_ = AddEntry(HeapEntry::kObject,
1233
+ "(GC roots)",
1234
+ HeapObjectsMap::kGcRootsObjectId,
1235
+ 0,
1236
+ children_count,
1237
+ retainers_count));
1238
+ }
1239
+
1240
+
1241
+ HeapEntry* HeapSnapshot::AddNativesRootEntry(int children_count,
1242
+ int retainers_count) {
1243
+ ASSERT(natives_root_entry_ == NULL);
1244
+ return (natives_root_entry_ = AddEntry(
1245
+ HeapEntry::kObject,
1246
+ "(Native objects)",
1247
+ HeapObjectsMap::kNativesRootObjectId,
1248
+ 0,
1249
+ children_count,
1250
+ retainers_count));
1251
+ }
1252
+
1253
+
1254
+ HeapEntry* HeapSnapshot::AddEntry(HeapEntry::Type type,
1255
+ const char* name,
1256
+ uint64_t id,
1257
+ int size,
1258
+ int children_count,
1259
+ int retainers_count) {
1260
+ HeapEntry* entry = GetNextEntryToInit();
1261
+ entry->Init(this, type, name, id, size, children_count, retainers_count);
1262
+ return entry;
1263
+ }
1264
+
1265
+
1266
+ void HeapSnapshot::SetDominatorsToSelf() {
1267
+ for (int i = 0; i < entries_.length(); ++i) {
1268
+ HeapEntry* entry = entries_[i];
1269
+ if (entry->dominator() == NULL) entry->set_dominator(entry);
1270
+ }
1271
+ }
1272
+
1273
+
1274
+ HeapEntry* HeapSnapshot::GetNextEntryToInit() {
1275
+ if (entries_.length() > 0) {
1276
+ HeapEntry* last_entry = entries_.last();
1277
+ entries_.Add(reinterpret_cast<HeapEntry*>(
1278
+ reinterpret_cast<char*>(last_entry) + last_entry->EntrySize()));
1279
+ } else {
1280
+ entries_.Add(reinterpret_cast<HeapEntry*>(raw_entries_));
1281
+ }
1282
+ ASSERT(reinterpret_cast<char*>(entries_.last()) <
1283
+ (raw_entries_ + raw_entries_size_));
1284
+ return entries_.last();
1285
+ }
1286
+
1287
+
1288
+ HeapEntry* HeapSnapshot::GetEntryById(uint64_t id) {
1289
+ List<HeapEntry*>* entries_by_id = GetSortedEntriesList();
1290
+
1291
+ // Perform a binary search by id.
1292
+ int low = 0;
1293
+ int high = entries_by_id->length() - 1;
1294
+ while (low <= high) {
1295
+ int mid =
1296
+ (static_cast<unsigned int>(low) + static_cast<unsigned int>(high)) >> 1;
1297
+ uint64_t mid_id = entries_by_id->at(mid)->id();
1298
+ if (mid_id > id)
1299
+ high = mid - 1;
1300
+ else if (mid_id < id)
1301
+ low = mid + 1;
1302
+ else
1303
+ return entries_by_id->at(mid);
1304
+ }
1305
+ return NULL;
1306
+ }
1307
+
1308
+
1309
+ template<class T>
1310
+ static int SortByIds(const T* entry1_ptr,
1311
+ const T* entry2_ptr) {
1312
+ if ((*entry1_ptr)->id() == (*entry2_ptr)->id()) return 0;
1313
+ return (*entry1_ptr)->id() < (*entry2_ptr)->id() ? -1 : 1;
1314
+ }
1315
+
1316
+ List<HeapEntry*>* HeapSnapshot::GetSortedEntriesList() {
1317
+ if (!entries_sorted_) {
1318
+ entries_.Sort(SortByIds);
1319
+ entries_sorted_ = true;
1320
+ }
1321
+ return &entries_;
1322
+ }
1323
+
1324
+
1325
+ void HeapSnapshot::Print(int max_depth) {
1326
+ root()->Print(max_depth, 0);
1327
+ }
1328
+
1329
+
1330
+ // We split IDs on evens for embedder objects (see
1331
+ // HeapObjectsMap::GenerateId) and odds for native objects.
1332
+ const uint64_t HeapObjectsMap::kInternalRootObjectId = 1;
1333
+ const uint64_t HeapObjectsMap::kGcRootsObjectId = 3;
1334
+ const uint64_t HeapObjectsMap::kNativesRootObjectId = 5;
1335
+ // Increase kFirstAvailableObjectId if new 'special' objects appear.
1336
+ const uint64_t HeapObjectsMap::kFirstAvailableObjectId = 7;
1337
+
1338
+ HeapObjectsMap::HeapObjectsMap()
1339
+ : initial_fill_mode_(true),
1340
+ next_id_(kFirstAvailableObjectId),
1341
+ entries_map_(AddressesMatch),
1342
+ entries_(new List<EntryInfo>()) { }
1343
+
1344
+
1345
+ HeapObjectsMap::~HeapObjectsMap() {
1346
+ delete entries_;
1347
+ }
1348
+
1349
+
1350
+ void HeapObjectsMap::SnapshotGenerationFinished() {
1351
+ initial_fill_mode_ = false;
1352
+ RemoveDeadEntries();
1353
+ }
1354
+
1355
+
1356
+ uint64_t HeapObjectsMap::FindObject(Address addr) {
1357
+ if (!initial_fill_mode_) {
1358
+ uint64_t existing = FindEntry(addr);
1359
+ if (existing != 0) return existing;
1360
+ }
1361
+ uint64_t id = next_id_;
1362
+ next_id_ += 2;
1363
+ AddEntry(addr, id);
1364
+ return id;
1365
+ }
1366
+
1367
+
1368
+ void HeapObjectsMap::MoveObject(Address from, Address to) {
1369
+ if (from == to) return;
1370
+ HashMap::Entry* entry = entries_map_.Lookup(from, AddressHash(from), false);
1371
+ if (entry != NULL) {
1372
+ void* value = entry->value;
1373
+ entries_map_.Remove(from, AddressHash(from));
1374
+ entry = entries_map_.Lookup(to, AddressHash(to), true);
1375
+ // We can have an entry at the new location, it is OK, as GC can overwrite
1376
+ // dead objects with alive objects being moved.
1377
+ entry->value = value;
1378
+ }
1379
+ }
1380
+
1381
+
1382
+ void HeapObjectsMap::AddEntry(Address addr, uint64_t id) {
1383
+ HashMap::Entry* entry = entries_map_.Lookup(addr, AddressHash(addr), true);
1384
+ ASSERT(entry->value == NULL);
1385
+ entry->value = reinterpret_cast<void*>(entries_->length());
1386
+ entries_->Add(EntryInfo(id));
1387
+ }
1388
+
1389
+
1390
+ uint64_t HeapObjectsMap::FindEntry(Address addr) {
1391
+ HashMap::Entry* entry = entries_map_.Lookup(addr, AddressHash(addr), false);
1392
+ if (entry != NULL) {
1393
+ int entry_index =
1394
+ static_cast<int>(reinterpret_cast<intptr_t>(entry->value));
1395
+ EntryInfo& entry_info = entries_->at(entry_index);
1396
+ entry_info.accessed = true;
1397
+ return entry_info.id;
1398
+ } else {
1399
+ return 0;
1400
+ }
1401
+ }
1402
+
1403
+
1404
+ void HeapObjectsMap::RemoveDeadEntries() {
1405
+ List<EntryInfo>* new_entries = new List<EntryInfo>();
1406
+ List<void*> dead_entries;
1407
+ for (HashMap::Entry* entry = entries_map_.Start();
1408
+ entry != NULL;
1409
+ entry = entries_map_.Next(entry)) {
1410
+ int entry_index =
1411
+ static_cast<int>(reinterpret_cast<intptr_t>(entry->value));
1412
+ EntryInfo& entry_info = entries_->at(entry_index);
1413
+ if (entry_info.accessed) {
1414
+ entry->value = reinterpret_cast<void*>(new_entries->length());
1415
+ new_entries->Add(EntryInfo(entry_info.id, false));
1416
+ } else {
1417
+ dead_entries.Add(entry->key);
1418
+ }
1419
+ }
1420
+ for (int i = 0; i < dead_entries.length(); ++i) {
1421
+ void* raw_entry = dead_entries[i];
1422
+ entries_map_.Remove(
1423
+ raw_entry, AddressHash(reinterpret_cast<Address>(raw_entry)));
1424
+ }
1425
+ delete entries_;
1426
+ entries_ = new_entries;
1427
+ }
1428
+
1429
+
1430
+ uint64_t HeapObjectsMap::GenerateId(v8::RetainedObjectInfo* info) {
1431
+ uint64_t id = static_cast<uint64_t>(info->GetHash());
1432
+ const char* label = info->GetLabel();
1433
+ id ^= HashSequentialString(label, static_cast<int>(strlen(label)));
1434
+ intptr_t element_count = info->GetElementCount();
1435
+ if (element_count != -1)
1436
+ id ^= ComputeIntegerHash(static_cast<uint32_t>(element_count));
1437
+ return id << 1;
1438
+ }
1439
+
1440
+
1441
+ HeapSnapshotsCollection::HeapSnapshotsCollection()
1442
+ : is_tracking_objects_(false),
1443
+ snapshots_uids_(HeapSnapshotsMatch),
1444
+ token_enumerator_(new TokenEnumerator()) {
1445
+ }
1446
+
1447
+
1448
+ static void DeleteHeapSnapshot(HeapSnapshot** snapshot_ptr) {
1449
+ delete *snapshot_ptr;
1450
+ }
1451
+
1452
+
1453
+ HeapSnapshotsCollection::~HeapSnapshotsCollection() {
1454
+ delete token_enumerator_;
1455
+ snapshots_.Iterate(DeleteHeapSnapshot);
1456
+ }
1457
+
1458
+
1459
+ HeapSnapshot* HeapSnapshotsCollection::NewSnapshot(HeapSnapshot::Type type,
1460
+ const char* name,
1461
+ unsigned uid) {
1462
+ is_tracking_objects_ = true; // Start watching for heap objects moves.
1463
+ return new HeapSnapshot(this, type, name, uid);
1464
+ }
1465
+
1466
+
1467
+ void HeapSnapshotsCollection::SnapshotGenerationFinished(
1468
+ HeapSnapshot* snapshot) {
1469
+ ids_.SnapshotGenerationFinished();
1470
+ if (snapshot != NULL) {
1471
+ snapshots_.Add(snapshot);
1472
+ HashMap::Entry* entry =
1473
+ snapshots_uids_.Lookup(reinterpret_cast<void*>(snapshot->uid()),
1474
+ static_cast<uint32_t>(snapshot->uid()),
1475
+ true);
1476
+ ASSERT(entry->value == NULL);
1477
+ entry->value = snapshot;
1478
+ }
1479
+ }
1480
+
1481
+
1482
+ HeapSnapshot* HeapSnapshotsCollection::GetSnapshot(unsigned uid) {
1483
+ HashMap::Entry* entry = snapshots_uids_.Lookup(reinterpret_cast<void*>(uid),
1484
+ static_cast<uint32_t>(uid),
1485
+ false);
1486
+ return entry != NULL ? reinterpret_cast<HeapSnapshot*>(entry->value) : NULL;
1487
+ }
1488
+
1489
+
1490
+ void HeapSnapshotsCollection::RemoveSnapshot(HeapSnapshot* snapshot) {
1491
+ snapshots_.RemoveElement(snapshot);
1492
+ unsigned uid = snapshot->uid();
1493
+ snapshots_uids_.Remove(reinterpret_cast<void*>(uid),
1494
+ static_cast<uint32_t>(uid));
1495
+ }
1496
+
1497
+
1498
+ HeapEntry *const HeapEntriesMap::kHeapEntryPlaceholder =
1499
+ reinterpret_cast<HeapEntry*>(1);
1500
+
1501
+ HeapEntriesMap::HeapEntriesMap()
1502
+ : entries_(HeapThingsMatch),
1503
+ entries_count_(0),
1504
+ total_children_count_(0),
1505
+ total_retainers_count_(0) {
1506
+ }
1507
+
1508
+
1509
+ HeapEntriesMap::~HeapEntriesMap() {
1510
+ for (HashMap::Entry* p = entries_.Start(); p != NULL; p = entries_.Next(p)) {
1511
+ delete reinterpret_cast<EntryInfo*>(p->value);
1512
+ }
1513
+ }
1514
+
1515
+
1516
+ void HeapEntriesMap::AllocateEntries() {
1517
+ for (HashMap::Entry* p = entries_.Start();
1518
+ p != NULL;
1519
+ p = entries_.Next(p)) {
1520
+ EntryInfo* entry_info = reinterpret_cast<EntryInfo*>(p->value);
1521
+ entry_info->entry = entry_info->allocator->AllocateEntry(
1522
+ p->key,
1523
+ entry_info->children_count,
1524
+ entry_info->retainers_count);
1525
+ ASSERT(entry_info->entry != NULL);
1526
+ ASSERT(entry_info->entry != kHeapEntryPlaceholder);
1527
+ entry_info->children_count = 0;
1528
+ entry_info->retainers_count = 0;
1529
+ }
1530
+ }
1531
+
1532
+
1533
+ HeapEntry* HeapEntriesMap::Map(HeapThing thing) {
1534
+ HashMap::Entry* cache_entry = entries_.Lookup(thing, Hash(thing), false);
1535
+ if (cache_entry != NULL) {
1536
+ EntryInfo* entry_info = reinterpret_cast<EntryInfo*>(cache_entry->value);
1537
+ return entry_info->entry;
1538
+ } else {
1539
+ return NULL;
1540
+ }
1541
+ }
1542
+
1543
+
1544
+ void HeapEntriesMap::Pair(
1545
+ HeapThing thing, HeapEntriesAllocator* allocator, HeapEntry* entry) {
1546
+ HashMap::Entry* cache_entry = entries_.Lookup(thing, Hash(thing), true);
1547
+ ASSERT(cache_entry->value == NULL);
1548
+ cache_entry->value = new EntryInfo(entry, allocator);
1549
+ ++entries_count_;
1550
+ }
1551
+
1552
+
1553
+ void HeapEntriesMap::CountReference(HeapThing from, HeapThing to,
1554
+ int* prev_children_count,
1555
+ int* prev_retainers_count) {
1556
+ HashMap::Entry* from_cache_entry = entries_.Lookup(from, Hash(from), false);
1557
+ HashMap::Entry* to_cache_entry = entries_.Lookup(to, Hash(to), false);
1558
+ ASSERT(from_cache_entry != NULL);
1559
+ ASSERT(to_cache_entry != NULL);
1560
+ EntryInfo* from_entry_info =
1561
+ reinterpret_cast<EntryInfo*>(from_cache_entry->value);
1562
+ EntryInfo* to_entry_info =
1563
+ reinterpret_cast<EntryInfo*>(to_cache_entry->value);
1564
+ if (prev_children_count)
1565
+ *prev_children_count = from_entry_info->children_count;
1566
+ if (prev_retainers_count)
1567
+ *prev_retainers_count = to_entry_info->retainers_count;
1568
+ ++from_entry_info->children_count;
1569
+ ++to_entry_info->retainers_count;
1570
+ ++total_children_count_;
1571
+ ++total_retainers_count_;
1572
+ }
1573
+
1574
+
1575
+ HeapObjectsSet::HeapObjectsSet()
1576
+ : entries_(HeapEntriesMap::HeapThingsMatch) {
1577
+ }
1578
+
1579
+
1580
+ void HeapObjectsSet::Clear() {
1581
+ entries_.Clear();
1582
+ }
1583
+
1584
+
1585
+ bool HeapObjectsSet::Contains(Object* obj) {
1586
+ if (!obj->IsHeapObject()) return false;
1587
+ HeapObject* object = HeapObject::cast(obj);
1588
+ HashMap::Entry* cache_entry =
1589
+ entries_.Lookup(object, HeapEntriesMap::Hash(object), false);
1590
+ return cache_entry != NULL;
1591
+ }
1592
+
1593
+
1594
+ void HeapObjectsSet::Insert(Object* obj) {
1595
+ if (!obj->IsHeapObject()) return;
1596
+ HeapObject* object = HeapObject::cast(obj);
1597
+ HashMap::Entry* cache_entry =
1598
+ entries_.Lookup(object, HeapEntriesMap::Hash(object), true);
1599
+ if (cache_entry->value == NULL) {
1600
+ cache_entry->value = HeapEntriesMap::kHeapEntryPlaceholder;
1601
+ }
1602
+ }
1603
+
1604
+
1605
+ HeapObject *const V8HeapExplorer::kInternalRootObject =
1606
+ reinterpret_cast<HeapObject*>(
1607
+ static_cast<intptr_t>(HeapObjectsMap::kInternalRootObjectId));
1608
+ HeapObject *const V8HeapExplorer::kGcRootsObject =
1609
+ reinterpret_cast<HeapObject*>(
1610
+ static_cast<intptr_t>(HeapObjectsMap::kGcRootsObjectId));
1611
+
1612
+
1613
+ V8HeapExplorer::V8HeapExplorer(
1614
+ HeapSnapshot* snapshot,
1615
+ SnapshottingProgressReportingInterface* progress)
1616
+ : snapshot_(snapshot),
1617
+ collection_(snapshot_->collection()),
1618
+ progress_(progress),
1619
+ filler_(NULL) {
1620
+ }
1621
+
1622
+
1623
+ V8HeapExplorer::~V8HeapExplorer() {
1624
+ }
1625
+
1626
+
1627
+ HeapEntry* V8HeapExplorer::AllocateEntry(
1628
+ HeapThing ptr, int children_count, int retainers_count) {
1629
+ return AddEntry(
1630
+ reinterpret_cast<HeapObject*>(ptr), children_count, retainers_count);
1631
+ }
1632
+
1633
+
1634
+ HeapEntry* V8HeapExplorer::AddEntry(HeapObject* object,
1635
+ int children_count,
1636
+ int retainers_count) {
1637
+ if (object == kInternalRootObject) {
1638
+ ASSERT(retainers_count == 0);
1639
+ return snapshot_->AddRootEntry(children_count);
1640
+ } else if (object == kGcRootsObject) {
1641
+ return snapshot_->AddGcRootsEntry(children_count, retainers_count);
1642
+ } else if (object->IsJSFunction()) {
1643
+ JSFunction* func = JSFunction::cast(object);
1644
+ SharedFunctionInfo* shared = func->shared();
1645
+ return AddEntry(object,
1646
+ HeapEntry::kClosure,
1647
+ collection_->names()->GetName(String::cast(shared->name())),
1648
+ children_count,
1649
+ retainers_count);
1650
+ } else if (object->IsJSRegExp()) {
1651
+ JSRegExp* re = JSRegExp::cast(object);
1652
+ return AddEntry(object,
1653
+ HeapEntry::kRegExp,
1654
+ collection_->names()->GetName(re->Pattern()),
1655
+ children_count,
1656
+ retainers_count);
1657
+ } else if (object->IsJSObject()) {
1658
+ return AddEntry(object,
1659
+ HeapEntry::kObject,
1660
+ collection_->names()->GetName(
1661
+ GetConstructorNameForHeapProfile(
1662
+ JSObject::cast(object))),
1663
+ children_count,
1664
+ retainers_count);
1665
+ } else if (object->IsString()) {
1666
+ return AddEntry(object,
1667
+ HeapEntry::kString,
1668
+ collection_->names()->GetName(String::cast(object)),
1669
+ children_count,
1670
+ retainers_count);
1671
+ } else if (object->IsCode()) {
1672
+ return AddEntry(object,
1673
+ HeapEntry::kCode,
1674
+ "",
1675
+ children_count,
1676
+ retainers_count);
1677
+ } else if (object->IsSharedFunctionInfo()) {
1678
+ SharedFunctionInfo* shared = SharedFunctionInfo::cast(object);
1679
+ return AddEntry(object,
1680
+ HeapEntry::kCode,
1681
+ collection_->names()->GetName(String::cast(shared->name())),
1682
+ children_count,
1683
+ retainers_count);
1684
+ } else if (object->IsScript()) {
1685
+ Script* script = Script::cast(object);
1686
+ return AddEntry(object,
1687
+ HeapEntry::kCode,
1688
+ script->name()->IsString() ?
1689
+ collection_->names()->GetName(
1690
+ String::cast(script->name()))
1691
+ : "",
1692
+ children_count,
1693
+ retainers_count);
1694
+ } else if (object->IsFixedArray() || object->IsByteArray()) {
1695
+ return AddEntry(object,
1696
+ HeapEntry::kArray,
1697
+ "",
1698
+ children_count,
1699
+ retainers_count);
1700
+ } else if (object->IsHeapNumber()) {
1701
+ return AddEntry(object,
1702
+ HeapEntry::kHeapNumber,
1703
+ "number",
1704
+ children_count,
1705
+ retainers_count);
1706
+ }
1707
+ return AddEntry(object,
1708
+ HeapEntry::kHidden,
1709
+ GetSystemEntryName(object),
1710
+ children_count,
1711
+ retainers_count);
1712
+ }
1713
+
1714
+
1715
+ HeapEntry* V8HeapExplorer::AddEntry(HeapObject* object,
1716
+ HeapEntry::Type type,
1717
+ const char* name,
1718
+ int children_count,
1719
+ int retainers_count) {
1720
+ return snapshot_->AddEntry(type,
1721
+ name,
1722
+ collection_->GetObjectId(object->address()),
1723
+ object->Size(),
1724
+ children_count,
1725
+ retainers_count);
1726
+ }
1727
+
1728
+
1729
+ void V8HeapExplorer::AddRootEntries(SnapshotFillerInterface* filler) {
1730
+ filler->AddEntry(kInternalRootObject, this);
1731
+ filler->AddEntry(kGcRootsObject, this);
1732
+ }
1733
+
1734
+
1735
+ const char* V8HeapExplorer::GetSystemEntryName(HeapObject* object) {
1736
+ switch (object->map()->instance_type()) {
1737
+ case MAP_TYPE: return "system / Map";
1738
+ case JS_GLOBAL_PROPERTY_CELL_TYPE: return "system / JSGlobalPropertyCell";
1739
+ case FOREIGN_TYPE: return "system / Foreign";
1740
+ case ODDBALL_TYPE: return "system / Oddball";
1741
+ #define MAKE_STRUCT_CASE(NAME, Name, name) \
1742
+ case NAME##_TYPE: return "system / "#Name;
1743
+ STRUCT_LIST(MAKE_STRUCT_CASE)
1744
+ #undef MAKE_STRUCT_CASE
1745
+ default: return "system";
1746
+ }
1747
+ }
1748
+
1749
+
1750
+ int V8HeapExplorer::EstimateObjectsCount() {
1751
+ HeapIterator iterator(HeapIterator::kFilterUnreachable);
1752
+ int objects_count = 0;
1753
+ for (HeapObject* obj = iterator.next();
1754
+ obj != NULL;
1755
+ obj = iterator.next(), ++objects_count) {}
1756
+ return objects_count;
1757
+ }
1758
+
1759
+
1760
+ class IndexedReferencesExtractor : public ObjectVisitor {
1761
+ public:
1762
+ IndexedReferencesExtractor(V8HeapExplorer* generator,
1763
+ HeapObject* parent_obj,
1764
+ HeapEntry* parent_entry)
1765
+ : generator_(generator),
1766
+ parent_obj_(parent_obj),
1767
+ parent_(parent_entry),
1768
+ next_index_(1) {
1769
+ }
1770
+ void VisitPointers(Object** start, Object** end) {
1771
+ for (Object** p = start; p < end; p++) {
1772
+ if (CheckVisitedAndUnmark(p)) continue;
1773
+ generator_->SetHiddenReference(parent_obj_, parent_, next_index_++, *p);
1774
+ }
1775
+ }
1776
+ static void MarkVisitedField(HeapObject* obj, int offset) {
1777
+ if (offset < 0) return;
1778
+ Address field = obj->address() + offset;
1779
+ ASSERT(!Memory::Object_at(field)->IsFailure());
1780
+ ASSERT(Memory::Object_at(field)->IsHeapObject());
1781
+ *field |= kFailureTag;
1782
+ }
1783
+ private:
1784
+ bool CheckVisitedAndUnmark(Object** field) {
1785
+ if ((*field)->IsFailure()) {
1786
+ intptr_t untagged = reinterpret_cast<intptr_t>(*field) & ~kFailureTagMask;
1787
+ *field = reinterpret_cast<Object*>(untagged | kHeapObjectTag);
1788
+ ASSERT((*field)->IsHeapObject());
1789
+ return true;
1790
+ }
1791
+ return false;
1792
+ }
1793
+ V8HeapExplorer* generator_;
1794
+ HeapObject* parent_obj_;
1795
+ HeapEntry* parent_;
1796
+ int next_index_;
1797
+ };
1798
+
1799
+
1800
+ void V8HeapExplorer::ExtractReferences(HeapObject* obj) {
1801
+ HeapEntry* entry = GetEntry(obj);
1802
+ if (entry == NULL) return; // No interest in this object.
1803
+
1804
+ if (obj->IsJSGlobalProxy()) {
1805
+ // We need to reference JS global objects from snapshot's root.
1806
+ // We use JSGlobalProxy because this is what embedder (e.g. browser)
1807
+ // uses for the global object.
1808
+ JSGlobalProxy* proxy = JSGlobalProxy::cast(obj);
1809
+ SetRootShortcutReference(proxy->map()->prototype());
1810
+ SetInternalReference(obj, entry, "map", obj->map(), HeapObject::kMapOffset);
1811
+ IndexedReferencesExtractor refs_extractor(this, obj, entry);
1812
+ obj->Iterate(&refs_extractor);
1813
+ } else if (obj->IsJSObject()) {
1814
+ JSObject* js_obj = JSObject::cast(obj);
1815
+ ExtractClosureReferences(js_obj, entry);
1816
+ ExtractPropertyReferences(js_obj, entry);
1817
+ ExtractElementReferences(js_obj, entry);
1818
+ ExtractInternalReferences(js_obj, entry);
1819
+ SetPropertyReference(
1820
+ obj, entry, HEAP->Proto_symbol(), js_obj->GetPrototype());
1821
+ if (obj->IsJSFunction()) {
1822
+ JSFunction* js_fun = JSFunction::cast(js_obj);
1823
+ Object* proto_or_map = js_fun->prototype_or_initial_map();
1824
+ if (!proto_or_map->IsTheHole()) {
1825
+ if (!proto_or_map->IsMap()) {
1826
+ SetPropertyReference(
1827
+ obj, entry,
1828
+ HEAP->prototype_symbol(), proto_or_map,
1829
+ JSFunction::kPrototypeOrInitialMapOffset);
1830
+ } else {
1831
+ SetPropertyReference(
1832
+ obj, entry,
1833
+ HEAP->prototype_symbol(), js_fun->prototype());
1834
+ }
1835
+ }
1836
+ SetInternalReference(js_fun, entry,
1837
+ "shared", js_fun->shared(),
1838
+ JSFunction::kSharedFunctionInfoOffset);
1839
+ SetInternalReference(js_fun, entry,
1840
+ "context", js_fun->unchecked_context(),
1841
+ JSFunction::kContextOffset);
1842
+ SetInternalReference(js_fun, entry,
1843
+ "literals", js_fun->literals(),
1844
+ JSFunction::kLiteralsOffset);
1845
+ }
1846
+ SetInternalReference(obj, entry,
1847
+ "properties", js_obj->properties(),
1848
+ JSObject::kPropertiesOffset);
1849
+ SetInternalReference(obj, entry,
1850
+ "elements", js_obj->elements(),
1851
+ JSObject::kElementsOffset);
1852
+ SetInternalReference(obj, entry, "map", obj->map(), HeapObject::kMapOffset);
1853
+ IndexedReferencesExtractor refs_extractor(this, obj, entry);
1854
+ obj->Iterate(&refs_extractor);
1855
+ } else if (obj->IsString()) {
1856
+ if (obj->IsConsString()) {
1857
+ ConsString* cs = ConsString::cast(obj);
1858
+ SetInternalReference(obj, entry, 1, cs->first());
1859
+ SetInternalReference(obj, entry, 2, cs->second());
1860
+ }
1861
+ } else if (obj->IsMap()) {
1862
+ Map* map = Map::cast(obj);
1863
+ SetInternalReference(obj, entry,
1864
+ "prototype", map->prototype(), Map::kPrototypeOffset);
1865
+ SetInternalReference(obj, entry,
1866
+ "constructor", map->constructor(),
1867
+ Map::kConstructorOffset);
1868
+ if (!map->instance_descriptors()->IsEmpty()) {
1869
+ SetInternalReference(obj, entry,
1870
+ "descriptors", map->instance_descriptors(),
1871
+ Map::kInstanceDescriptorsOrBitField3Offset);
1872
+ }
1873
+ SetInternalReference(obj, entry,
1874
+ "code_cache", map->code_cache(),
1875
+ Map::kCodeCacheOffset);
1876
+ SetInternalReference(obj, entry, "map", obj->map(), HeapObject::kMapOffset);
1877
+ IndexedReferencesExtractor refs_extractor(this, obj, entry);
1878
+ obj->Iterate(&refs_extractor);
1879
+ } else if (obj->IsSharedFunctionInfo()) {
1880
+ SharedFunctionInfo* shared = SharedFunctionInfo::cast(obj);
1881
+ SetInternalReference(obj, entry,
1882
+ "name", shared->name(),
1883
+ SharedFunctionInfo::kNameOffset);
1884
+ SetInternalReference(obj, entry,
1885
+ "code", shared->unchecked_code(),
1886
+ SharedFunctionInfo::kCodeOffset);
1887
+ SetInternalReference(obj, entry,
1888
+ "instance_class_name", shared->instance_class_name(),
1889
+ SharedFunctionInfo::kInstanceClassNameOffset);
1890
+ SetInternalReference(obj, entry,
1891
+ "script", shared->script(),
1892
+ SharedFunctionInfo::kScriptOffset);
1893
+ SetInternalReference(obj, entry, "map", obj->map(), HeapObject::kMapOffset);
1894
+ IndexedReferencesExtractor refs_extractor(this, obj, entry);
1895
+ obj->Iterate(&refs_extractor);
1896
+ } else {
1897
+ SetInternalReference(obj, entry, "map", obj->map(), HeapObject::kMapOffset);
1898
+ IndexedReferencesExtractor refs_extractor(this, obj, entry);
1899
+ obj->Iterate(&refs_extractor);
1900
+ }
1901
+ }
1902
+
1903
+
1904
+ void V8HeapExplorer::ExtractClosureReferences(JSObject* js_obj,
1905
+ HeapEntry* entry) {
1906
+ if (js_obj->IsJSFunction()) {
1907
+ HandleScope hs;
1908
+ JSFunction* func = JSFunction::cast(js_obj);
1909
+ Context* context = func->context();
1910
+ ZoneScope zscope(Isolate::Current(), DELETE_ON_EXIT);
1911
+ SerializedScopeInfo* serialized_scope_info =
1912
+ context->closure()->shared()->scope_info();
1913
+ ScopeInfo<ZoneListAllocationPolicy> zone_scope_info(serialized_scope_info);
1914
+ int locals_number = zone_scope_info.NumberOfLocals();
1915
+ for (int i = 0; i < locals_number; ++i) {
1916
+ String* local_name = *zone_scope_info.LocalName(i);
1917
+ int idx = serialized_scope_info->ContextSlotIndex(local_name, NULL);
1918
+ if (idx >= 0 && idx < context->length()) {
1919
+ SetClosureReference(js_obj, entry, local_name, context->get(idx));
1920
+ }
1921
+ }
1922
+ }
1923
+ }
1924
+
1925
+
1926
+ void V8HeapExplorer::ExtractPropertyReferences(JSObject* js_obj,
1927
+ HeapEntry* entry) {
1928
+ if (js_obj->HasFastProperties()) {
1929
+ DescriptorArray* descs = js_obj->map()->instance_descriptors();
1930
+ for (int i = 0; i < descs->number_of_descriptors(); i++) {
1931
+ switch (descs->GetType(i)) {
1932
+ case FIELD: {
1933
+ int index = descs->GetFieldIndex(i);
1934
+ if (index < js_obj->map()->inobject_properties()) {
1935
+ SetPropertyReference(
1936
+ js_obj, entry,
1937
+ descs->GetKey(i), js_obj->InObjectPropertyAt(index),
1938
+ js_obj->GetInObjectPropertyOffset(index));
1939
+ } else {
1940
+ SetPropertyReference(
1941
+ js_obj, entry,
1942
+ descs->GetKey(i), js_obj->FastPropertyAt(index));
1943
+ }
1944
+ break;
1945
+ }
1946
+ case CONSTANT_FUNCTION:
1947
+ SetPropertyReference(
1948
+ js_obj, entry,
1949
+ descs->GetKey(i), descs->GetConstantFunction(i));
1950
+ break;
1951
+ default: ;
1952
+ }
1953
+ }
1954
+ } else {
1955
+ StringDictionary* dictionary = js_obj->property_dictionary();
1956
+ int length = dictionary->Capacity();
1957
+ for (int i = 0; i < length; ++i) {
1958
+ Object* k = dictionary->KeyAt(i);
1959
+ if (dictionary->IsKey(k)) {
1960
+ Object* target = dictionary->ValueAt(i);
1961
+ SetPropertyReference(
1962
+ js_obj, entry, String::cast(k), target);
1963
+ // We assume that global objects can only have slow properties.
1964
+ if (target->IsJSGlobalPropertyCell()) {
1965
+ SetPropertyShortcutReference(js_obj,
1966
+ entry,
1967
+ String::cast(k),
1968
+ JSGlobalPropertyCell::cast(
1969
+ target)->value());
1970
+ }
1971
+ }
1972
+ }
1973
+ }
1974
+ }
1975
+
1976
+
1977
+ void V8HeapExplorer::ExtractElementReferences(JSObject* js_obj,
1978
+ HeapEntry* entry) {
1979
+ if (js_obj->HasFastElements()) {
1980
+ FixedArray* elements = FixedArray::cast(js_obj->elements());
1981
+ int length = js_obj->IsJSArray() ?
1982
+ Smi::cast(JSArray::cast(js_obj)->length())->value() :
1983
+ elements->length();
1984
+ for (int i = 0; i < length; ++i) {
1985
+ if (!elements->get(i)->IsTheHole()) {
1986
+ SetElementReference(js_obj, entry, i, elements->get(i));
1987
+ }
1988
+ }
1989
+ } else if (js_obj->HasDictionaryElements()) {
1990
+ NumberDictionary* dictionary = js_obj->element_dictionary();
1991
+ int length = dictionary->Capacity();
1992
+ for (int i = 0; i < length; ++i) {
1993
+ Object* k = dictionary->KeyAt(i);
1994
+ if (dictionary->IsKey(k)) {
1995
+ ASSERT(k->IsNumber());
1996
+ uint32_t index = static_cast<uint32_t>(k->Number());
1997
+ SetElementReference(js_obj, entry, index, dictionary->ValueAt(i));
1998
+ }
1999
+ }
2000
+ }
2001
+ }
2002
+
2003
+
2004
+ void V8HeapExplorer::ExtractInternalReferences(JSObject* js_obj,
2005
+ HeapEntry* entry) {
2006
+ int length = js_obj->GetInternalFieldCount();
2007
+ for (int i = 0; i < length; ++i) {
2008
+ Object* o = js_obj->GetInternalField(i);
2009
+ SetInternalReference(
2010
+ js_obj, entry, i, o, js_obj->GetInternalFieldOffset(i));
2011
+ }
2012
+ }
2013
+
2014
+
2015
+ HeapEntry* V8HeapExplorer::GetEntry(Object* obj) {
2016
+ if (!obj->IsHeapObject()) return NULL;
2017
+ return filler_->FindOrAddEntry(obj, this);
2018
+ }
2019
+
2020
+
2021
+ class RootsReferencesExtractor : public ObjectVisitor {
2022
+ public:
2023
+ explicit RootsReferencesExtractor(V8HeapExplorer* explorer)
2024
+ : explorer_(explorer) {
2025
+ }
2026
+ void VisitPointers(Object** start, Object** end) {
2027
+ for (Object** p = start; p < end; p++) explorer_->SetGcRootsReference(*p);
2028
+ }
2029
+ private:
2030
+ V8HeapExplorer* explorer_;
2031
+ };
2032
+
2033
+
2034
+ bool V8HeapExplorer::IterateAndExtractReferences(
2035
+ SnapshotFillerInterface* filler) {
2036
+ filler_ = filler;
2037
+ HeapIterator iterator(HeapIterator::kFilterUnreachable);
2038
+ bool interrupted = false;
2039
+ // Heap iteration with filtering must be finished in any case.
2040
+ for (HeapObject* obj = iterator.next();
2041
+ obj != NULL;
2042
+ obj = iterator.next(), progress_->ProgressStep()) {
2043
+ if (!interrupted) {
2044
+ ExtractReferences(obj);
2045
+ if (!progress_->ProgressReport(false)) interrupted = true;
2046
+ }
2047
+ }
2048
+ if (interrupted) {
2049
+ filler_ = NULL;
2050
+ return false;
2051
+ }
2052
+ SetRootGcRootsReference();
2053
+ RootsReferencesExtractor extractor(this);
2054
+ HEAP->IterateRoots(&extractor, VISIT_ALL);
2055
+ filler_ = NULL;
2056
+ return progress_->ProgressReport(false);
2057
+ }
2058
+
2059
+
2060
+ void V8HeapExplorer::SetClosureReference(HeapObject* parent_obj,
2061
+ HeapEntry* parent_entry,
2062
+ String* reference_name,
2063
+ Object* child_obj) {
2064
+ HeapEntry* child_entry = GetEntry(child_obj);
2065
+ if (child_entry != NULL) {
2066
+ filler_->SetNamedReference(HeapGraphEdge::kContextVariable,
2067
+ parent_obj,
2068
+ parent_entry,
2069
+ collection_->names()->GetName(reference_name),
2070
+ child_obj,
2071
+ child_entry);
2072
+ }
2073
+ }
2074
+
2075
+
2076
+ void V8HeapExplorer::SetElementReference(HeapObject* parent_obj,
2077
+ HeapEntry* parent_entry,
2078
+ int index,
2079
+ Object* child_obj) {
2080
+ HeapEntry* child_entry = GetEntry(child_obj);
2081
+ if (child_entry != NULL) {
2082
+ filler_->SetIndexedReference(HeapGraphEdge::kElement,
2083
+ parent_obj,
2084
+ parent_entry,
2085
+ index,
2086
+ child_obj,
2087
+ child_entry);
2088
+ }
2089
+ }
2090
+
2091
+
2092
+ void V8HeapExplorer::SetInternalReference(HeapObject* parent_obj,
2093
+ HeapEntry* parent_entry,
2094
+ const char* reference_name,
2095
+ Object* child_obj,
2096
+ int field_offset) {
2097
+ HeapEntry* child_entry = GetEntry(child_obj);
2098
+ if (child_entry != NULL) {
2099
+ filler_->SetNamedReference(HeapGraphEdge::kInternal,
2100
+ parent_obj,
2101
+ parent_entry,
2102
+ reference_name,
2103
+ child_obj,
2104
+ child_entry);
2105
+ IndexedReferencesExtractor::MarkVisitedField(parent_obj, field_offset);
2106
+ }
2107
+ }
2108
+
2109
+
2110
+ void V8HeapExplorer::SetInternalReference(HeapObject* parent_obj,
2111
+ HeapEntry* parent_entry,
2112
+ int index,
2113
+ Object* child_obj,
2114
+ int field_offset) {
2115
+ HeapEntry* child_entry = GetEntry(child_obj);
2116
+ if (child_entry != NULL) {
2117
+ filler_->SetNamedReference(HeapGraphEdge::kInternal,
2118
+ parent_obj,
2119
+ parent_entry,
2120
+ collection_->names()->GetName(index),
2121
+ child_obj,
2122
+ child_entry);
2123
+ IndexedReferencesExtractor::MarkVisitedField(parent_obj, field_offset);
2124
+ }
2125
+ }
2126
+
2127
+
2128
+ void V8HeapExplorer::SetHiddenReference(HeapObject* parent_obj,
2129
+ HeapEntry* parent_entry,
2130
+ int index,
2131
+ Object* child_obj) {
2132
+ HeapEntry* child_entry = GetEntry(child_obj);
2133
+ if (child_entry != NULL) {
2134
+ filler_->SetIndexedReference(HeapGraphEdge::kHidden,
2135
+ parent_obj,
2136
+ parent_entry,
2137
+ index,
2138
+ child_obj,
2139
+ child_entry);
2140
+ }
2141
+ }
2142
+
2143
+
2144
+ void V8HeapExplorer::SetPropertyReference(HeapObject* parent_obj,
2145
+ HeapEntry* parent_entry,
2146
+ String* reference_name,
2147
+ Object* child_obj,
2148
+ int field_offset) {
2149
+ HeapEntry* child_entry = GetEntry(child_obj);
2150
+ if (child_entry != NULL) {
2151
+ HeapGraphEdge::Type type = reference_name->length() > 0 ?
2152
+ HeapGraphEdge::kProperty : HeapGraphEdge::kInternal;
2153
+ filler_->SetNamedReference(type,
2154
+ parent_obj,
2155
+ parent_entry,
2156
+ collection_->names()->GetName(reference_name),
2157
+ child_obj,
2158
+ child_entry);
2159
+ IndexedReferencesExtractor::MarkVisitedField(parent_obj, field_offset);
2160
+ }
2161
+ }
2162
+
2163
+
2164
+ void V8HeapExplorer::SetPropertyShortcutReference(HeapObject* parent_obj,
2165
+ HeapEntry* parent_entry,
2166
+ String* reference_name,
2167
+ Object* child_obj) {
2168
+ HeapEntry* child_entry = GetEntry(child_obj);
2169
+ if (child_entry != NULL) {
2170
+ filler_->SetNamedReference(HeapGraphEdge::kShortcut,
2171
+ parent_obj,
2172
+ parent_entry,
2173
+ collection_->names()->GetName(reference_name),
2174
+ child_obj,
2175
+ child_entry);
2176
+ }
2177
+ }
2178
+
2179
+
2180
+ void V8HeapExplorer::SetRootGcRootsReference() {
2181
+ filler_->SetIndexedAutoIndexReference(
2182
+ HeapGraphEdge::kElement,
2183
+ kInternalRootObject, snapshot_->root(),
2184
+ kGcRootsObject, snapshot_->gc_roots());
2185
+ }
2186
+
2187
+
2188
+ void V8HeapExplorer::SetRootShortcutReference(Object* child_obj) {
2189
+ HeapEntry* child_entry = GetEntry(child_obj);
2190
+ ASSERT(child_entry != NULL);
2191
+ filler_->SetNamedAutoIndexReference(
2192
+ HeapGraphEdge::kShortcut,
2193
+ kInternalRootObject, snapshot_->root(),
2194
+ child_obj, child_entry);
2195
+ }
2196
+
2197
+
2198
+ void V8HeapExplorer::SetGcRootsReference(Object* child_obj) {
2199
+ HeapEntry* child_entry = GetEntry(child_obj);
2200
+ if (child_entry != NULL) {
2201
+ filler_->SetIndexedAutoIndexReference(
2202
+ HeapGraphEdge::kElement,
2203
+ kGcRootsObject, snapshot_->gc_roots(),
2204
+ child_obj, child_entry);
2205
+ }
2206
+ }
2207
+
2208
+
2209
+ class GlobalHandlesExtractor : public ObjectVisitor {
2210
+ public:
2211
+ explicit GlobalHandlesExtractor(NativeObjectsExplorer* explorer)
2212
+ : explorer_(explorer) {}
2213
+ virtual ~GlobalHandlesExtractor() {}
2214
+ virtual void VisitPointers(Object** start, Object** end) {
2215
+ UNREACHABLE();
2216
+ }
2217
+ virtual void VisitEmbedderReference(Object** p, uint16_t class_id) {
2218
+ explorer_->VisitSubtreeWrapper(p, class_id);
2219
+ }
2220
+ private:
2221
+ NativeObjectsExplorer* explorer_;
2222
+ };
2223
+
2224
+ HeapThing const NativeObjectsExplorer::kNativesRootObject =
2225
+ reinterpret_cast<HeapThing>(
2226
+ static_cast<intptr_t>(HeapObjectsMap::kNativesRootObjectId));
2227
+
2228
+
2229
+ NativeObjectsExplorer::NativeObjectsExplorer(
2230
+ HeapSnapshot* snapshot, SnapshottingProgressReportingInterface* progress)
2231
+ : snapshot_(snapshot),
2232
+ collection_(snapshot_->collection()),
2233
+ progress_(progress),
2234
+ embedder_queried_(false),
2235
+ objects_by_info_(RetainedInfosMatch),
2236
+ filler_(NULL) {
2237
+ }
2238
+
2239
+
2240
+ NativeObjectsExplorer::~NativeObjectsExplorer() {
2241
+ for (HashMap::Entry* p = objects_by_info_.Start();
2242
+ p != NULL;
2243
+ p = objects_by_info_.Next(p)) {
2244
+ v8::RetainedObjectInfo* info =
2245
+ reinterpret_cast<v8::RetainedObjectInfo*>(p->key);
2246
+ info->Dispose();
2247
+ List<HeapObject*>* objects =
2248
+ reinterpret_cast<List<HeapObject*>* >(p->value);
2249
+ delete objects;
2250
+ }
2251
+ }
2252
+
2253
+
2254
+ HeapEntry* NativeObjectsExplorer::AllocateEntry(
2255
+ HeapThing ptr, int children_count, int retainers_count) {
2256
+ if (ptr == kNativesRootObject) {
2257
+ return snapshot_->AddNativesRootEntry(children_count, retainers_count);
2258
+ } else {
2259
+ v8::RetainedObjectInfo* info =
2260
+ reinterpret_cast<v8::RetainedObjectInfo*>(ptr);
2261
+ intptr_t elements = info->GetElementCount();
2262
+ intptr_t size = info->GetSizeInBytes();
2263
+ return snapshot_->AddEntry(
2264
+ HeapEntry::kNative,
2265
+ elements != -1 ?
2266
+ collection_->names()->GetFormatted(
2267
+ "%s / %" V8_PTR_PREFIX "d entries",
2268
+ info->GetLabel(),
2269
+ info->GetElementCount()) :
2270
+ collection_->names()->GetCopy(info->GetLabel()),
2271
+ HeapObjectsMap::GenerateId(info),
2272
+ size != -1 ? static_cast<int>(size) : 0,
2273
+ children_count,
2274
+ retainers_count);
2275
+ }
2276
+ }
2277
+
2278
+
2279
+ void NativeObjectsExplorer::AddRootEntries(SnapshotFillerInterface* filler) {
2280
+ if (EstimateObjectsCount() <= 0) return;
2281
+ filler->AddEntry(kNativesRootObject, this);
2282
+ }
2283
+
2284
+
2285
+ int NativeObjectsExplorer::EstimateObjectsCount() {
2286
+ FillRetainedObjects();
2287
+ return objects_by_info_.occupancy();
2288
+ }
2289
+
2290
+
2291
+ void NativeObjectsExplorer::FillRetainedObjects() {
2292
+ if (embedder_queried_) return;
2293
+ Isolate* isolate = Isolate::Current();
2294
+ // Record objects that are joined into ObjectGroups.
2295
+ isolate->heap()->CallGlobalGCPrologueCallback();
2296
+ List<ObjectGroup*>* groups = isolate->global_handles()->object_groups();
2297
+ for (int i = 0; i < groups->length(); ++i) {
2298
+ ObjectGroup* group = groups->at(i);
2299
+ if (group->info_ == NULL) continue;
2300
+ List<HeapObject*>* list = GetListMaybeDisposeInfo(group->info_);
2301
+ for (size_t j = 0; j < group->length_; ++j) {
2302
+ HeapObject* obj = HeapObject::cast(*group->objects_[j]);
2303
+ list->Add(obj);
2304
+ in_groups_.Insert(obj);
2305
+ }
2306
+ group->info_ = NULL; // Acquire info object ownership.
2307
+ }
2308
+ isolate->global_handles()->RemoveObjectGroups();
2309
+ isolate->heap()->CallGlobalGCEpilogueCallback();
2310
+ // Record objects that are not in ObjectGroups, but have class ID.
2311
+ GlobalHandlesExtractor extractor(this);
2312
+ isolate->global_handles()->IterateAllRootsWithClassIds(&extractor);
2313
+ embedder_queried_ = true;
2314
+ }
2315
+
2316
+
2317
+ List<HeapObject*>* NativeObjectsExplorer::GetListMaybeDisposeInfo(
2318
+ v8::RetainedObjectInfo* info) {
2319
+ HashMap::Entry* entry =
2320
+ objects_by_info_.Lookup(info, InfoHash(info), true);
2321
+ if (entry->value != NULL) {
2322
+ info->Dispose();
2323
+ } else {
2324
+ entry->value = new List<HeapObject*>(4);
2325
+ }
2326
+ return reinterpret_cast<List<HeapObject*>* >(entry->value);
2327
+ }
2328
+
2329
+
2330
+ bool NativeObjectsExplorer::IterateAndExtractReferences(
2331
+ SnapshotFillerInterface* filler) {
2332
+ if (EstimateObjectsCount() <= 0) return true;
2333
+ filler_ = filler;
2334
+ FillRetainedObjects();
2335
+ for (HashMap::Entry* p = objects_by_info_.Start();
2336
+ p != NULL;
2337
+ p = objects_by_info_.Next(p)) {
2338
+ v8::RetainedObjectInfo* info =
2339
+ reinterpret_cast<v8::RetainedObjectInfo*>(p->key);
2340
+ SetNativeRootReference(info);
2341
+ List<HeapObject*>* objects =
2342
+ reinterpret_cast<List<HeapObject*>* >(p->value);
2343
+ for (int i = 0; i < objects->length(); ++i) {
2344
+ SetWrapperNativeReferences(objects->at(i), info);
2345
+ }
2346
+ }
2347
+ SetRootNativesRootReference();
2348
+ filler_ = NULL;
2349
+ return true;
2350
+ }
2351
+
2352
+
2353
+ void NativeObjectsExplorer::SetNativeRootReference(
2354
+ v8::RetainedObjectInfo* info) {
2355
+ HeapEntry* child_entry = filler_->FindOrAddEntry(info, this);
2356
+ ASSERT(child_entry != NULL);
2357
+ filler_->SetIndexedAutoIndexReference(
2358
+ HeapGraphEdge::kElement,
2359
+ kNativesRootObject, snapshot_->natives_root(),
2360
+ info, child_entry);
2361
+ }
2362
+
2363
+
2364
+ void NativeObjectsExplorer::SetWrapperNativeReferences(
2365
+ HeapObject* wrapper, v8::RetainedObjectInfo* info) {
2366
+ HeapEntry* wrapper_entry = filler_->FindEntry(wrapper);
2367
+ ASSERT(wrapper_entry != NULL);
2368
+ HeapEntry* info_entry = filler_->FindOrAddEntry(info, this);
2369
+ ASSERT(info_entry != NULL);
2370
+ filler_->SetNamedReference(HeapGraphEdge::kInternal,
2371
+ wrapper, wrapper_entry,
2372
+ "native",
2373
+ info, info_entry);
2374
+ filler_->SetIndexedAutoIndexReference(HeapGraphEdge::kElement,
2375
+ info, info_entry,
2376
+ wrapper, wrapper_entry);
2377
+ }
2378
+
2379
+
2380
+ void NativeObjectsExplorer::SetRootNativesRootReference() {
2381
+ filler_->SetIndexedAutoIndexReference(
2382
+ HeapGraphEdge::kElement,
2383
+ V8HeapExplorer::kInternalRootObject, snapshot_->root(),
2384
+ kNativesRootObject, snapshot_->natives_root());
2385
+ }
2386
+
2387
+
2388
+ void NativeObjectsExplorer::VisitSubtreeWrapper(Object** p, uint16_t class_id) {
2389
+ if (in_groups_.Contains(*p)) return;
2390
+ Isolate* isolate = Isolate::Current();
2391
+ v8::RetainedObjectInfo* info =
2392
+ isolate->heap_profiler()->ExecuteWrapperClassCallback(class_id, p);
2393
+ if (info == NULL) return;
2394
+ GetListMaybeDisposeInfo(info)->Add(HeapObject::cast(*p));
2395
+ }
2396
+
2397
+
2398
+ HeapSnapshotGenerator::HeapSnapshotGenerator(HeapSnapshot* snapshot,
2399
+ v8::ActivityControl* control)
2400
+ : snapshot_(snapshot),
2401
+ control_(control),
2402
+ v8_heap_explorer_(snapshot_, this),
2403
+ dom_explorer_(snapshot_, this) {
2404
+ }
2405
+
2406
+
2407
+ class SnapshotCounter : public SnapshotFillerInterface {
2408
+ public:
2409
+ explicit SnapshotCounter(HeapEntriesMap* entries) : entries_(entries) { }
2410
+ HeapEntry* AddEntry(HeapThing ptr, HeapEntriesAllocator* allocator) {
2411
+ entries_->Pair(ptr, allocator, HeapEntriesMap::kHeapEntryPlaceholder);
2412
+ return HeapEntriesMap::kHeapEntryPlaceholder;
2413
+ }
2414
+ HeapEntry* FindEntry(HeapThing ptr) {
2415
+ return entries_->Map(ptr);
2416
+ }
2417
+ HeapEntry* FindOrAddEntry(HeapThing ptr, HeapEntriesAllocator* allocator) {
2418
+ HeapEntry* entry = FindEntry(ptr);
2419
+ return entry != NULL ? entry : AddEntry(ptr, allocator);
2420
+ }
2421
+ void SetIndexedReference(HeapGraphEdge::Type,
2422
+ HeapThing parent_ptr,
2423
+ HeapEntry*,
2424
+ int,
2425
+ HeapThing child_ptr,
2426
+ HeapEntry*) {
2427
+ entries_->CountReference(parent_ptr, child_ptr);
2428
+ }
2429
+ void SetIndexedAutoIndexReference(HeapGraphEdge::Type,
2430
+ HeapThing parent_ptr,
2431
+ HeapEntry*,
2432
+ HeapThing child_ptr,
2433
+ HeapEntry*) {
2434
+ entries_->CountReference(parent_ptr, child_ptr);
2435
+ }
2436
+ void SetNamedReference(HeapGraphEdge::Type,
2437
+ HeapThing parent_ptr,
2438
+ HeapEntry*,
2439
+ const char*,
2440
+ HeapThing child_ptr,
2441
+ HeapEntry*) {
2442
+ entries_->CountReference(parent_ptr, child_ptr);
2443
+ }
2444
+ void SetNamedAutoIndexReference(HeapGraphEdge::Type,
2445
+ HeapThing parent_ptr,
2446
+ HeapEntry*,
2447
+ HeapThing child_ptr,
2448
+ HeapEntry*) {
2449
+ entries_->CountReference(parent_ptr, child_ptr);
2450
+ }
2451
+ private:
2452
+ HeapEntriesMap* entries_;
2453
+ };
2454
+
2455
+
2456
+ class SnapshotFiller : public SnapshotFillerInterface {
2457
+ public:
2458
+ explicit SnapshotFiller(HeapSnapshot* snapshot, HeapEntriesMap* entries)
2459
+ : snapshot_(snapshot),
2460
+ collection_(snapshot->collection()),
2461
+ entries_(entries) { }
2462
+ HeapEntry* AddEntry(HeapThing ptr, HeapEntriesAllocator* allocator) {
2463
+ UNREACHABLE();
2464
+ return NULL;
2465
+ }
2466
+ HeapEntry* FindEntry(HeapThing ptr) {
2467
+ return entries_->Map(ptr);
2468
+ }
2469
+ HeapEntry* FindOrAddEntry(HeapThing ptr, HeapEntriesAllocator* allocator) {
2470
+ HeapEntry* entry = FindEntry(ptr);
2471
+ return entry != NULL ? entry : AddEntry(ptr, allocator);
2472
+ }
2473
+ void SetIndexedReference(HeapGraphEdge::Type type,
2474
+ HeapThing parent_ptr,
2475
+ HeapEntry* parent_entry,
2476
+ int index,
2477
+ HeapThing child_ptr,
2478
+ HeapEntry* child_entry) {
2479
+ int child_index, retainer_index;
2480
+ entries_->CountReference(
2481
+ parent_ptr, child_ptr, &child_index, &retainer_index);
2482
+ parent_entry->SetIndexedReference(
2483
+ type, child_index, index, child_entry, retainer_index);
2484
+ }
2485
+ void SetIndexedAutoIndexReference(HeapGraphEdge::Type type,
2486
+ HeapThing parent_ptr,
2487
+ HeapEntry* parent_entry,
2488
+ HeapThing child_ptr,
2489
+ HeapEntry* child_entry) {
2490
+ int child_index, retainer_index;
2491
+ entries_->CountReference(
2492
+ parent_ptr, child_ptr, &child_index, &retainer_index);
2493
+ parent_entry->SetIndexedReference(
2494
+ type, child_index, child_index + 1, child_entry, retainer_index);
2495
+ }
2496
+ void SetNamedReference(HeapGraphEdge::Type type,
2497
+ HeapThing parent_ptr,
2498
+ HeapEntry* parent_entry,
2499
+ const char* reference_name,
2500
+ HeapThing child_ptr,
2501
+ HeapEntry* child_entry) {
2502
+ int child_index, retainer_index;
2503
+ entries_->CountReference(
2504
+ parent_ptr, child_ptr, &child_index, &retainer_index);
2505
+ parent_entry->SetNamedReference(
2506
+ type, child_index, reference_name, child_entry, retainer_index);
2507
+ }
2508
+ void SetNamedAutoIndexReference(HeapGraphEdge::Type type,
2509
+ HeapThing parent_ptr,
2510
+ HeapEntry* parent_entry,
2511
+ HeapThing child_ptr,
2512
+ HeapEntry* child_entry) {
2513
+ int child_index, retainer_index;
2514
+ entries_->CountReference(
2515
+ parent_ptr, child_ptr, &child_index, &retainer_index);
2516
+ parent_entry->SetNamedReference(type,
2517
+ child_index,
2518
+ collection_->names()->GetName(child_index + 1),
2519
+ child_entry,
2520
+ retainer_index);
2521
+ }
2522
+ private:
2523
+ HeapSnapshot* snapshot_;
2524
+ HeapSnapshotsCollection* collection_;
2525
+ HeapEntriesMap* entries_;
2526
+ };
2527
+
2528
+
2529
+ bool HeapSnapshotGenerator::GenerateSnapshot() {
2530
+ AssertNoAllocation no_alloc;
2531
+
2532
+ SetProgressTotal(4); // 2 passes + dominators + sizes.
2533
+
2534
+ // Pass 1. Iterate heap contents to count entries and references.
2535
+ if (!CountEntriesAndReferences()) return false;
2536
+
2537
+ // Allocate and fill entries in the snapshot, allocate references.
2538
+ snapshot_->AllocateEntries(entries_.entries_count(),
2539
+ entries_.total_children_count(),
2540
+ entries_.total_retainers_count());
2541
+ entries_.AllocateEntries();
2542
+
2543
+ // Pass 2. Fill references.
2544
+ if (!FillReferences()) return false;
2545
+
2546
+ if (!SetEntriesDominators()) return false;
2547
+ if (!ApproximateRetainedSizes()) return false;
2548
+
2549
+ progress_counter_ = progress_total_;
2550
+ if (!ProgressReport(true)) return false;
2551
+ return true;
2552
+ }
2553
+
2554
+
2555
+ void HeapSnapshotGenerator::ProgressStep() {
2556
+ ++progress_counter_;
2557
+ }
2558
+
2559
+
2560
+ bool HeapSnapshotGenerator::ProgressReport(bool force) {
2561
+ const int kProgressReportGranularity = 10000;
2562
+ if (control_ != NULL
2563
+ && (force || progress_counter_ % kProgressReportGranularity == 0)) {
2564
+ return
2565
+ control_->ReportProgressValue(progress_counter_, progress_total_) ==
2566
+ v8::ActivityControl::kContinue;
2567
+ }
2568
+ return true;
2569
+ }
2570
+
2571
+
2572
+ void HeapSnapshotGenerator::SetProgressTotal(int iterations_count) {
2573
+ if (control_ == NULL) return;
2574
+ progress_total_ = (
2575
+ v8_heap_explorer_.EstimateObjectsCount() +
2576
+ dom_explorer_.EstimateObjectsCount()) * iterations_count;
2577
+ progress_counter_ = 0;
2578
+ }
2579
+
2580
+
2581
+ bool HeapSnapshotGenerator::CountEntriesAndReferences() {
2582
+ SnapshotCounter counter(&entries_);
2583
+ v8_heap_explorer_.AddRootEntries(&counter);
2584
+ dom_explorer_.AddRootEntries(&counter);
2585
+ return
2586
+ v8_heap_explorer_.IterateAndExtractReferences(&counter) &&
2587
+ dom_explorer_.IterateAndExtractReferences(&counter);
2588
+ }
2589
+
2590
+
2591
+ bool HeapSnapshotGenerator::FillReferences() {
2592
+ SnapshotFiller filler(snapshot_, &entries_);
2593
+ return
2594
+ v8_heap_explorer_.IterateAndExtractReferences(&filler) &&
2595
+ dom_explorer_.IterateAndExtractReferences(&filler);
2596
+ }
2597
+
2598
+
2599
+ void HeapSnapshotGenerator::FillReversePostorderIndexes(
2600
+ Vector<HeapEntry*>* entries) {
2601
+ snapshot_->ClearPaint();
2602
+ int current_entry = 0;
2603
+ List<HeapEntry*> nodes_to_visit;
2604
+ nodes_to_visit.Add(snapshot_->root());
2605
+ snapshot_->root()->paint_reachable();
2606
+ while (!nodes_to_visit.is_empty()) {
2607
+ HeapEntry* entry = nodes_to_visit.last();
2608
+ Vector<HeapGraphEdge> children = entry->children();
2609
+ bool has_new_edges = false;
2610
+ for (int i = 0; i < children.length(); ++i) {
2611
+ if (children[i].type() == HeapGraphEdge::kShortcut) continue;
2612
+ HeapEntry* child = children[i].to();
2613
+ if (!child->painted_reachable()) {
2614
+ nodes_to_visit.Add(child);
2615
+ child->paint_reachable();
2616
+ has_new_edges = true;
2617
+ }
2618
+ }
2619
+ if (!has_new_edges) {
2620
+ entry->set_ordered_index(current_entry);
2621
+ (*entries)[current_entry++] = entry;
2622
+ nodes_to_visit.RemoveLast();
2623
+ }
2624
+ }
2625
+ entries->Truncate(current_entry);
2626
+ }
2627
+
2628
+
2629
+ static int Intersect(int i1, int i2, const Vector<HeapEntry*>& dominators) {
2630
+ int finger1 = i1, finger2 = i2;
2631
+ while (finger1 != finger2) {
2632
+ while (finger1 < finger2) finger1 = dominators[finger1]->ordered_index();
2633
+ while (finger2 < finger1) finger2 = dominators[finger2]->ordered_index();
2634
+ }
2635
+ return finger1;
2636
+ }
2637
+
2638
+ // The algorithm is based on the article:
2639
+ // K. Cooper, T. Harvey and K. Kennedy "A Simple, Fast Dominance Algorithm"
2640
+ // Softw. Pract. Exper. 4 (2001), pp. 1-10.
2641
+ bool HeapSnapshotGenerator::BuildDominatorTree(
2642
+ const Vector<HeapEntry*>& entries,
2643
+ Vector<HeapEntry*>* dominators) {
2644
+ if (entries.length() == 0) return true;
2645
+ const int entries_length = entries.length(), root_index = entries_length - 1;
2646
+ for (int i = 0; i < root_index; ++i) (*dominators)[i] = NULL;
2647
+ (*dominators)[root_index] = entries[root_index];
2648
+ int changed = 1;
2649
+ const int base_progress_counter = progress_counter_;
2650
+ while (changed != 0) {
2651
+ changed = 0;
2652
+ for (int i = root_index - 1; i >= 0; --i) {
2653
+ HeapEntry* new_idom = NULL;
2654
+ Vector<HeapGraphEdge*> rets = entries[i]->retainers();
2655
+ int j = 0;
2656
+ for (; j < rets.length(); ++j) {
2657
+ if (rets[j]->type() == HeapGraphEdge::kShortcut) continue;
2658
+ HeapEntry* ret = rets[j]->From();
2659
+ if (dominators->at(ret->ordered_index()) != NULL) {
2660
+ new_idom = ret;
2661
+ break;
2662
+ }
2663
+ }
2664
+ for (++j; j < rets.length(); ++j) {
2665
+ if (rets[j]->type() == HeapGraphEdge::kShortcut) continue;
2666
+ HeapEntry* ret = rets[j]->From();
2667
+ if (dominators->at(ret->ordered_index()) != NULL) {
2668
+ new_idom = entries[Intersect(ret->ordered_index(),
2669
+ new_idom->ordered_index(),
2670
+ *dominators)];
2671
+ }
2672
+ }
2673
+ if (new_idom != NULL && dominators->at(i) != new_idom) {
2674
+ (*dominators)[i] = new_idom;
2675
+ ++changed;
2676
+ }
2677
+ }
2678
+ int remaining = entries_length - changed;
2679
+ if (remaining < 0) remaining = 0;
2680
+ progress_counter_ = base_progress_counter + remaining;
2681
+ if (!ProgressReport(true)) return false;
2682
+ }
2683
+ return true;
2684
+ }
2685
+
2686
+
2687
+ bool HeapSnapshotGenerator::SetEntriesDominators() {
2688
+ // This array is used for maintaining reverse postorder of nodes.
2689
+ ScopedVector<HeapEntry*> ordered_entries(snapshot_->entries()->length());
2690
+ FillReversePostorderIndexes(&ordered_entries);
2691
+ ScopedVector<HeapEntry*> dominators(ordered_entries.length());
2692
+ if (!BuildDominatorTree(ordered_entries, &dominators)) return false;
2693
+ for (int i = 0; i < ordered_entries.length(); ++i) {
2694
+ ASSERT(dominators[i] != NULL);
2695
+ ordered_entries[i]->set_dominator(dominators[i]);
2696
+ }
2697
+ return true;
2698
+ }
2699
+
2700
+
2701
+ bool HeapSnapshotGenerator::ApproximateRetainedSizes() {
2702
+ // As for the dominators tree we only know parent nodes, not
2703
+ // children, to sum up total sizes we "bubble" node's self size
2704
+ // adding it to all of its parents.
2705
+ for (int i = 0; i < snapshot_->entries()->length(); ++i) {
2706
+ HeapEntry* entry = snapshot_->entries()->at(i);
2707
+ entry->set_retained_size(entry->self_size());
2708
+ }
2709
+ for (int i = 0;
2710
+ i < snapshot_->entries()->length();
2711
+ ++i, ProgressStep()) {
2712
+ HeapEntry* entry = snapshot_->entries()->at(i);
2713
+ int entry_size = entry->self_size();
2714
+ for (HeapEntry* dominator = entry->dominator();
2715
+ dominator != entry;
2716
+ entry = dominator, dominator = entry->dominator()) {
2717
+ dominator->add_retained_size(entry_size);
2718
+ }
2719
+ if (!ProgressReport()) return false;
2720
+ }
2721
+ return true;
2722
+ }
2723
+
2724
+
2725
+ class OutputStreamWriter {
2726
+ public:
2727
+ explicit OutputStreamWriter(v8::OutputStream* stream)
2728
+ : stream_(stream),
2729
+ chunk_size_(stream->GetChunkSize()),
2730
+ chunk_(chunk_size_),
2731
+ chunk_pos_(0),
2732
+ aborted_(false) {
2733
+ ASSERT(chunk_size_ > 0);
2734
+ }
2735
+ bool aborted() { return aborted_; }
2736
+ void AddCharacter(char c) {
2737
+ ASSERT(c != '\0');
2738
+ ASSERT(chunk_pos_ < chunk_size_);
2739
+ chunk_[chunk_pos_++] = c;
2740
+ MaybeWriteChunk();
2741
+ }
2742
+ void AddString(const char* s) {
2743
+ AddSubstring(s, StrLength(s));
2744
+ }
2745
+ void AddSubstring(const char* s, int n) {
2746
+ if (n <= 0) return;
2747
+ ASSERT(static_cast<size_t>(n) <= strlen(s));
2748
+ const char* s_end = s + n;
2749
+ while (s < s_end) {
2750
+ int s_chunk_size = Min(
2751
+ chunk_size_ - chunk_pos_, static_cast<int>(s_end - s));
2752
+ ASSERT(s_chunk_size > 0);
2753
+ memcpy(chunk_.start() + chunk_pos_, s, s_chunk_size);
2754
+ s += s_chunk_size;
2755
+ chunk_pos_ += s_chunk_size;
2756
+ MaybeWriteChunk();
2757
+ }
2758
+ }
2759
+ void AddNumber(int n) { AddNumberImpl<int>(n, "%d"); }
2760
+ void AddNumber(unsigned n) { AddNumberImpl<unsigned>(n, "%u"); }
2761
+ void AddNumber(uint64_t n) { AddNumberImpl<uint64_t>(n, "%llu"); }
2762
+ void Finalize() {
2763
+ if (aborted_) return;
2764
+ ASSERT(chunk_pos_ < chunk_size_);
2765
+ if (chunk_pos_ != 0) {
2766
+ WriteChunk();
2767
+ }
2768
+ stream_->EndOfStream();
2769
+ }
2770
+
2771
+ private:
2772
+ template<typename T>
2773
+ void AddNumberImpl(T n, const char* format) {
2774
+ ScopedVector<char> buffer(32);
2775
+ int result = OS::SNPrintF(buffer, format, n);
2776
+ USE(result);
2777
+ ASSERT(result != -1);
2778
+ AddString(buffer.start());
2779
+ }
2780
+ void MaybeWriteChunk() {
2781
+ ASSERT(chunk_pos_ <= chunk_size_);
2782
+ if (chunk_pos_ == chunk_size_) {
2783
+ WriteChunk();
2784
+ chunk_pos_ = 0;
2785
+ }
2786
+ }
2787
+ void WriteChunk() {
2788
+ if (aborted_) return;
2789
+ if (stream_->WriteAsciiChunk(chunk_.start(), chunk_pos_) ==
2790
+ v8::OutputStream::kAbort) aborted_ = true;
2791
+ }
2792
+
2793
+ v8::OutputStream* stream_;
2794
+ int chunk_size_;
2795
+ ScopedVector<char> chunk_;
2796
+ int chunk_pos_;
2797
+ bool aborted_;
2798
+ };
2799
+
2800
+ void HeapSnapshotJSONSerializer::Serialize(v8::OutputStream* stream) {
2801
+ ASSERT(writer_ == NULL);
2802
+ writer_ = new OutputStreamWriter(stream);
2803
+
2804
+ // Since nodes graph is cyclic, we need the first pass to enumerate
2805
+ // them. Strings can be serialized in one pass.
2806
+ EnumerateNodes();
2807
+ SerializeImpl();
2808
+
2809
+ delete writer_;
2810
+ writer_ = NULL;
2811
+ }
2812
+
2813
+
2814
+ void HeapSnapshotJSONSerializer::SerializeImpl() {
2815
+ writer_->AddCharacter('{');
2816
+ writer_->AddString("\"snapshot\":{");
2817
+ SerializeSnapshot();
2818
+ if (writer_->aborted()) return;
2819
+ writer_->AddString("},\n");
2820
+ writer_->AddString("\"nodes\":[");
2821
+ SerializeNodes();
2822
+ if (writer_->aborted()) return;
2823
+ writer_->AddString("],\n");
2824
+ writer_->AddString("\"strings\":[");
2825
+ SerializeStrings();
2826
+ if (writer_->aborted()) return;
2827
+ writer_->AddCharacter(']');
2828
+ writer_->AddCharacter('}');
2829
+ writer_->Finalize();
2830
+ }
2831
+
2832
+
2833
+ class HeapSnapshotJSONSerializerEnumerator {
2834
+ public:
2835
+ explicit HeapSnapshotJSONSerializerEnumerator(HeapSnapshotJSONSerializer* s)
2836
+ : s_(s) {
2837
+ }
2838
+ void Apply(HeapEntry** entry) {
2839
+ s_->GetNodeId(*entry);
2840
+ }
2841
+ private:
2842
+ HeapSnapshotJSONSerializer* s_;
2843
+ };
2844
+
2845
+ void HeapSnapshotJSONSerializer::EnumerateNodes() {
2846
+ GetNodeId(snapshot_->root()); // Make sure root gets the first id.
2847
+ HeapSnapshotJSONSerializerEnumerator iter(this);
2848
+ snapshot_->IterateEntries(&iter);
2849
+ }
2850
+
2851
+
2852
+ int HeapSnapshotJSONSerializer::GetNodeId(HeapEntry* entry) {
2853
+ HashMap::Entry* cache_entry = nodes_.Lookup(entry, ObjectHash(entry), true);
2854
+ if (cache_entry->value == NULL) {
2855
+ cache_entry->value = reinterpret_cast<void*>(next_node_id_++);
2856
+ }
2857
+ return static_cast<int>(reinterpret_cast<intptr_t>(cache_entry->value));
2858
+ }
2859
+
2860
+
2861
+ int HeapSnapshotJSONSerializer::GetStringId(const char* s) {
2862
+ HashMap::Entry* cache_entry = strings_.Lookup(
2863
+ const_cast<char*>(s), ObjectHash(s), true);
2864
+ if (cache_entry->value == NULL) {
2865
+ cache_entry->value = reinterpret_cast<void*>(next_string_id_++);
2866
+ }
2867
+ return static_cast<int>(reinterpret_cast<intptr_t>(cache_entry->value));
2868
+ }
2869
+
2870
+
2871
+ void HeapSnapshotJSONSerializer::SerializeEdge(HeapGraphEdge* edge) {
2872
+ writer_->AddCharacter(',');
2873
+ writer_->AddNumber(edge->type());
2874
+ writer_->AddCharacter(',');
2875
+ if (edge->type() == HeapGraphEdge::kElement
2876
+ || edge->type() == HeapGraphEdge::kHidden) {
2877
+ writer_->AddNumber(edge->index());
2878
+ } else {
2879
+ writer_->AddNumber(GetStringId(edge->name()));
2880
+ }
2881
+ writer_->AddCharacter(',');
2882
+ writer_->AddNumber(GetNodeId(edge->to()));
2883
+ }
2884
+
2885
+
2886
+ void HeapSnapshotJSONSerializer::SerializeNode(HeapEntry* entry) {
2887
+ writer_->AddCharacter('\n');
2888
+ writer_->AddCharacter(',');
2889
+ writer_->AddNumber(entry->type());
2890
+ writer_->AddCharacter(',');
2891
+ writer_->AddNumber(GetStringId(entry->name()));
2892
+ writer_->AddCharacter(',');
2893
+ writer_->AddNumber(entry->id());
2894
+ writer_->AddCharacter(',');
2895
+ writer_->AddNumber(entry->self_size());
2896
+ writer_->AddCharacter(',');
2897
+ writer_->AddNumber(entry->RetainedSize(false));
2898
+ writer_->AddCharacter(',');
2899
+ writer_->AddNumber(GetNodeId(entry->dominator()));
2900
+ Vector<HeapGraphEdge> children = entry->children();
2901
+ writer_->AddCharacter(',');
2902
+ writer_->AddNumber(children.length());
2903
+ for (int i = 0; i < children.length(); ++i) {
2904
+ SerializeEdge(&children[i]);
2905
+ if (writer_->aborted()) return;
2906
+ }
2907
+ }
2908
+
2909
+
2910
+ void HeapSnapshotJSONSerializer::SerializeNodes() {
2911
+ // The first (zero) item of nodes array is an object describing node
2912
+ // serialization layout. We use a set of macros to improve
2913
+ // readability.
2914
+ #define JSON_A(s) "["s"]"
2915
+ #define JSON_O(s) "{"s"}"
2916
+ #define JSON_S(s) "\""s"\""
2917
+ writer_->AddString(JSON_O(
2918
+ JSON_S("fields") ":" JSON_A(
2919
+ JSON_S("type")
2920
+ "," JSON_S("name")
2921
+ "," JSON_S("id")
2922
+ "," JSON_S("self_size")
2923
+ "," JSON_S("retained_size")
2924
+ "," JSON_S("dominator")
2925
+ "," JSON_S("children_count")
2926
+ "," JSON_S("children"))
2927
+ "," JSON_S("types") ":" JSON_A(
2928
+ JSON_A(
2929
+ JSON_S("hidden")
2930
+ "," JSON_S("array")
2931
+ "," JSON_S("string")
2932
+ "," JSON_S("object")
2933
+ "," JSON_S("code")
2934
+ "," JSON_S("closure")
2935
+ "," JSON_S("regexp")
2936
+ "," JSON_S("number")
2937
+ "," JSON_S("native"))
2938
+ "," JSON_S("string")
2939
+ "," JSON_S("number")
2940
+ "," JSON_S("number")
2941
+ "," JSON_S("number")
2942
+ "," JSON_S("number")
2943
+ "," JSON_S("number")
2944
+ "," JSON_O(
2945
+ JSON_S("fields") ":" JSON_A(
2946
+ JSON_S("type")
2947
+ "," JSON_S("name_or_index")
2948
+ "," JSON_S("to_node"))
2949
+ "," JSON_S("types") ":" JSON_A(
2950
+ JSON_A(
2951
+ JSON_S("context")
2952
+ "," JSON_S("element")
2953
+ "," JSON_S("property")
2954
+ "," JSON_S("internal")
2955
+ "," JSON_S("hidden")
2956
+ "," JSON_S("shortcut"))
2957
+ "," JSON_S("string_or_number")
2958
+ "," JSON_S("node"))))));
2959
+ #undef JSON_S
2960
+ #undef JSON_O
2961
+ #undef JSON_A
2962
+
2963
+ const int node_fields_count = 7;
2964
+ // type,name,id,self_size,retained_size,dominator,children_count.
2965
+ const int edge_fields_count = 3; // type,name|index,to_node.
2966
+ List<HashMap::Entry*> sorted_nodes;
2967
+ SortHashMap(&nodes_, &sorted_nodes);
2968
+ // Rewrite node ids, so they refer to actual array positions.
2969
+ if (sorted_nodes.length() > 1) {
2970
+ // Nodes start from array index 1.
2971
+ int prev_value = 1;
2972
+ sorted_nodes[0]->value = reinterpret_cast<void*>(prev_value);
2973
+ for (int i = 1; i < sorted_nodes.length(); ++i) {
2974
+ HeapEntry* prev_heap_entry =
2975
+ reinterpret_cast<HeapEntry*>(sorted_nodes[i-1]->key);
2976
+ prev_value += node_fields_count +
2977
+ prev_heap_entry->children().length() * edge_fields_count;
2978
+ sorted_nodes[i]->value = reinterpret_cast<void*>(prev_value);
2979
+ }
2980
+ }
2981
+ for (int i = 0; i < sorted_nodes.length(); ++i) {
2982
+ SerializeNode(reinterpret_cast<HeapEntry*>(sorted_nodes[i]->key));
2983
+ if (writer_->aborted()) return;
2984
+ }
2985
+ }
2986
+
2987
+
2988
+ void HeapSnapshotJSONSerializer::SerializeSnapshot() {
2989
+ writer_->AddString("\"title\":\"");
2990
+ writer_->AddString(snapshot_->title());
2991
+ writer_->AddString("\"");
2992
+ writer_->AddString(",\"uid\":");
2993
+ writer_->AddNumber(snapshot_->uid());
2994
+ }
2995
+
2996
+
2997
+ static void WriteUChar(OutputStreamWriter* w, unibrow::uchar u) {
2998
+ static const char hex_chars[] = "0123456789ABCDEF";
2999
+ w->AddString("\\u");
3000
+ w->AddCharacter(hex_chars[(u >> 12) & 0xf]);
3001
+ w->AddCharacter(hex_chars[(u >> 8) & 0xf]);
3002
+ w->AddCharacter(hex_chars[(u >> 4) & 0xf]);
3003
+ w->AddCharacter(hex_chars[u & 0xf]);
3004
+ }
3005
+
3006
+ void HeapSnapshotJSONSerializer::SerializeString(const unsigned char* s) {
3007
+ writer_->AddCharacter('\n');
3008
+ writer_->AddCharacter('\"');
3009
+ for ( ; *s != '\0'; ++s) {
3010
+ switch (*s) {
3011
+ case '\b':
3012
+ writer_->AddString("\\b");
3013
+ continue;
3014
+ case '\f':
3015
+ writer_->AddString("\\f");
3016
+ continue;
3017
+ case '\n':
3018
+ writer_->AddString("\\n");
3019
+ continue;
3020
+ case '\r':
3021
+ writer_->AddString("\\r");
3022
+ continue;
3023
+ case '\t':
3024
+ writer_->AddString("\\t");
3025
+ continue;
3026
+ case '\"':
3027
+ case '\\':
3028
+ writer_->AddCharacter('\\');
3029
+ writer_->AddCharacter(*s);
3030
+ continue;
3031
+ default:
3032
+ if (*s > 31 && *s < 128) {
3033
+ writer_->AddCharacter(*s);
3034
+ } else if (*s <= 31) {
3035
+ // Special character with no dedicated literal.
3036
+ WriteUChar(writer_, *s);
3037
+ } else {
3038
+ // Convert UTF-8 into \u UTF-16 literal.
3039
+ unsigned length = 1, cursor = 0;
3040
+ for ( ; length <= 4 && *(s + length) != '\0'; ++length) { }
3041
+ unibrow::uchar c = unibrow::Utf8::CalculateValue(s, length, &cursor);
3042
+ if (c != unibrow::Utf8::kBadChar) {
3043
+ WriteUChar(writer_, c);
3044
+ ASSERT(cursor != 0);
3045
+ s += cursor - 1;
3046
+ } else {
3047
+ writer_->AddCharacter('?');
3048
+ }
3049
+ }
3050
+ }
3051
+ }
3052
+ writer_->AddCharacter('\"');
3053
+ }
3054
+
3055
+
3056
+ void HeapSnapshotJSONSerializer::SerializeStrings() {
3057
+ List<HashMap::Entry*> sorted_strings;
3058
+ SortHashMap(&strings_, &sorted_strings);
3059
+ writer_->AddString("\"<dummy>\"");
3060
+ for (int i = 0; i < sorted_strings.length(); ++i) {
3061
+ writer_->AddCharacter(',');
3062
+ SerializeString(
3063
+ reinterpret_cast<const unsigned char*>(sorted_strings[i]->key));
3064
+ if (writer_->aborted()) return;
3065
+ }
3066
+ }
3067
+
3068
+
3069
+ template<typename T>
3070
+ inline static int SortUsingEntryValue(const T* x, const T* y) {
3071
+ uintptr_t x_uint = reinterpret_cast<uintptr_t>((*x)->value);
3072
+ uintptr_t y_uint = reinterpret_cast<uintptr_t>((*y)->value);
3073
+ if (x_uint > y_uint) {
3074
+ return 1;
3075
+ } else if (x_uint == y_uint) {
3076
+ return 0;
3077
+ } else {
3078
+ return -1;
3079
+ }
3080
+ }
3081
+
3082
+
3083
+ void HeapSnapshotJSONSerializer::SortHashMap(
3084
+ HashMap* map, List<HashMap::Entry*>* sorted_entries) {
3085
+ for (HashMap::Entry* p = map->Start(); p != NULL; p = map->Next(p))
3086
+ sorted_entries->Add(p);
3087
+ sorted_entries->Sort(SortUsingEntryValue);
3088
+ }
3089
+
3090
+
3091
+ String* GetConstructorNameForHeapProfile(JSObject* object) {
3092
+ if (object->IsJSFunction()) return HEAP->closure_symbol();
3093
+ return object->constructor_name();
3094
+ }
3095
+
3096
+ } } // namespace v8::internal
3097
+
3098
+ #endif // ENABLE_LOGGING_AND_PROFILING