libv8-sgonyea 3.3.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (500) hide show
  1. data/.gitignore +8 -0
  2. data/.gitmodules +3 -0
  3. data/Gemfile +4 -0
  4. data/README.md +76 -0
  5. data/Rakefile +113 -0
  6. data/ext/libv8/extconf.rb +28 -0
  7. data/lib/libv8.rb +15 -0
  8. data/lib/libv8/Makefile +30 -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/v8/.gitignore +35 -0
  12. data/lib/libv8/v8/AUTHORS +44 -0
  13. data/lib/libv8/v8/ChangeLog +2839 -0
  14. data/lib/libv8/v8/LICENSE +52 -0
  15. data/lib/libv8/v8/LICENSE.strongtalk +29 -0
  16. data/lib/libv8/v8/LICENSE.v8 +26 -0
  17. data/lib/libv8/v8/LICENSE.valgrind +45 -0
  18. data/lib/libv8/v8/SConstruct +1478 -0
  19. data/lib/libv8/v8/build/README.txt +49 -0
  20. data/lib/libv8/v8/build/all.gyp +18 -0
  21. data/lib/libv8/v8/build/armu.gypi +32 -0
  22. data/lib/libv8/v8/build/common.gypi +144 -0
  23. data/lib/libv8/v8/build/gyp_v8 +145 -0
  24. data/lib/libv8/v8/include/v8-debug.h +395 -0
  25. data/lib/libv8/v8/include/v8-preparser.h +117 -0
  26. data/lib/libv8/v8/include/v8-profiler.h +505 -0
  27. data/lib/libv8/v8/include/v8-testing.h +104 -0
  28. data/lib/libv8/v8/include/v8.h +4124 -0
  29. data/lib/libv8/v8/include/v8stdint.h +53 -0
  30. data/lib/libv8/v8/preparser/SConscript +38 -0
  31. data/lib/libv8/v8/preparser/preparser-process.cc +379 -0
  32. data/lib/libv8/v8/src/SConscript +368 -0
  33. data/lib/libv8/v8/src/accessors.cc +767 -0
  34. data/lib/libv8/v8/src/accessors.h +123 -0
  35. data/lib/libv8/v8/src/allocation-inl.h +49 -0
  36. data/lib/libv8/v8/src/allocation.cc +122 -0
  37. data/lib/libv8/v8/src/allocation.h +143 -0
  38. data/lib/libv8/v8/src/api.cc +5845 -0
  39. data/lib/libv8/v8/src/api.h +574 -0
  40. data/lib/libv8/v8/src/apinatives.js +110 -0
  41. data/lib/libv8/v8/src/apiutils.h +73 -0
  42. data/lib/libv8/v8/src/arguments.h +118 -0
  43. data/lib/libv8/v8/src/arm/assembler-arm-inl.h +353 -0
  44. data/lib/libv8/v8/src/arm/assembler-arm.cc +2661 -0
  45. data/lib/libv8/v8/src/arm/assembler-arm.h +1375 -0
  46. data/lib/libv8/v8/src/arm/builtins-arm.cc +1658 -0
  47. data/lib/libv8/v8/src/arm/code-stubs-arm.cc +6398 -0
  48. data/lib/libv8/v8/src/arm/code-stubs-arm.h +673 -0
  49. data/lib/libv8/v8/src/arm/codegen-arm.cc +52 -0
  50. data/lib/libv8/v8/src/arm/codegen-arm.h +91 -0
  51. data/lib/libv8/v8/src/arm/constants-arm.cc +152 -0
  52. data/lib/libv8/v8/src/arm/constants-arm.h +775 -0
  53. data/lib/libv8/v8/src/arm/cpu-arm.cc +120 -0
  54. data/lib/libv8/v8/src/arm/debug-arm.cc +317 -0
  55. data/lib/libv8/v8/src/arm/deoptimizer-arm.cc +754 -0
  56. data/lib/libv8/v8/src/arm/disasm-arm.cc +1506 -0
  57. data/lib/libv8/v8/src/arm/frames-arm.cc +45 -0
  58. data/lib/libv8/v8/src/arm/frames-arm.h +168 -0
  59. data/lib/libv8/v8/src/arm/full-codegen-arm.cc +4375 -0
  60. data/lib/libv8/v8/src/arm/ic-arm.cc +1562 -0
  61. data/lib/libv8/v8/src/arm/lithium-arm.cc +2206 -0
  62. data/lib/libv8/v8/src/arm/lithium-arm.h +2348 -0
  63. data/lib/libv8/v8/src/arm/lithium-codegen-arm.cc +4526 -0
  64. data/lib/libv8/v8/src/arm/lithium-codegen-arm.h +403 -0
  65. data/lib/libv8/v8/src/arm/lithium-gap-resolver-arm.cc +305 -0
  66. data/lib/libv8/v8/src/arm/lithium-gap-resolver-arm.h +84 -0
  67. data/lib/libv8/v8/src/arm/macro-assembler-arm.cc +3163 -0
  68. data/lib/libv8/v8/src/arm/macro-assembler-arm.h +1126 -0
  69. data/lib/libv8/v8/src/arm/regexp-macro-assembler-arm.cc +1287 -0
  70. data/lib/libv8/v8/src/arm/regexp-macro-assembler-arm.h +253 -0
  71. data/lib/libv8/v8/src/arm/simulator-arm.cc +3424 -0
  72. data/lib/libv8/v8/src/arm/simulator-arm.h +431 -0
  73. data/lib/libv8/v8/src/arm/stub-cache-arm.cc +4243 -0
  74. data/lib/libv8/v8/src/array.js +1366 -0
  75. data/lib/libv8/v8/src/assembler.cc +1207 -0
  76. data/lib/libv8/v8/src/assembler.h +858 -0
  77. data/lib/libv8/v8/src/ast-inl.h +112 -0
  78. data/lib/libv8/v8/src/ast.cc +1146 -0
  79. data/lib/libv8/v8/src/ast.h +2188 -0
  80. data/lib/libv8/v8/src/atomicops.h +167 -0
  81. data/lib/libv8/v8/src/atomicops_internals_arm_gcc.h +145 -0
  82. data/lib/libv8/v8/src/atomicops_internals_mips_gcc.h +169 -0
  83. data/lib/libv8/v8/src/atomicops_internals_x86_gcc.cc +133 -0
  84. data/lib/libv8/v8/src/atomicops_internals_x86_gcc.h +287 -0
  85. data/lib/libv8/v8/src/atomicops_internals_x86_macosx.h +301 -0
  86. data/lib/libv8/v8/src/atomicops_internals_x86_msvc.h +203 -0
  87. data/lib/libv8/v8/src/bignum-dtoa.cc +655 -0
  88. data/lib/libv8/v8/src/bignum-dtoa.h +81 -0
  89. data/lib/libv8/v8/src/bignum.cc +768 -0
  90. data/lib/libv8/v8/src/bignum.h +140 -0
  91. data/lib/libv8/v8/src/bootstrapper.cc +2184 -0
  92. data/lib/libv8/v8/src/bootstrapper.h +188 -0
  93. data/lib/libv8/v8/src/builtins.cc +1707 -0
  94. data/lib/libv8/v8/src/builtins.h +371 -0
  95. data/lib/libv8/v8/src/bytecodes-irregexp.h +105 -0
  96. data/lib/libv8/v8/src/cached-powers.cc +177 -0
  97. data/lib/libv8/v8/src/cached-powers.h +65 -0
  98. data/lib/libv8/v8/src/char-predicates-inl.h +94 -0
  99. data/lib/libv8/v8/src/char-predicates.h +67 -0
  100. data/lib/libv8/v8/src/checks.cc +110 -0
  101. data/lib/libv8/v8/src/checks.h +296 -0
  102. data/lib/libv8/v8/src/circular-queue-inl.h +53 -0
  103. data/lib/libv8/v8/src/circular-queue.cc +122 -0
  104. data/lib/libv8/v8/src/circular-queue.h +103 -0
  105. data/lib/libv8/v8/src/code-stubs.cc +267 -0
  106. data/lib/libv8/v8/src/code-stubs.h +1011 -0
  107. data/lib/libv8/v8/src/code.h +70 -0
  108. data/lib/libv8/v8/src/codegen.cc +231 -0
  109. data/lib/libv8/v8/src/codegen.h +84 -0
  110. data/lib/libv8/v8/src/compilation-cache.cc +540 -0
  111. data/lib/libv8/v8/src/compilation-cache.h +287 -0
  112. data/lib/libv8/v8/src/compiler.cc +786 -0
  113. data/lib/libv8/v8/src/compiler.h +312 -0
  114. data/lib/libv8/v8/src/contexts.cc +347 -0
  115. data/lib/libv8/v8/src/contexts.h +391 -0
  116. data/lib/libv8/v8/src/conversions-inl.h +106 -0
  117. data/lib/libv8/v8/src/conversions.cc +1131 -0
  118. data/lib/libv8/v8/src/conversions.h +135 -0
  119. data/lib/libv8/v8/src/counters.cc +93 -0
  120. data/lib/libv8/v8/src/counters.h +254 -0
  121. data/lib/libv8/v8/src/cpu-profiler-inl.h +101 -0
  122. data/lib/libv8/v8/src/cpu-profiler.cc +609 -0
  123. data/lib/libv8/v8/src/cpu-profiler.h +302 -0
  124. data/lib/libv8/v8/src/cpu.h +69 -0
  125. data/lib/libv8/v8/src/d8-debug.cc +367 -0
  126. data/lib/libv8/v8/src/d8-debug.h +158 -0
  127. data/lib/libv8/v8/src/d8-posix.cc +695 -0
  128. data/lib/libv8/v8/src/d8-readline.cc +130 -0
  129. data/lib/libv8/v8/src/d8-windows.cc +42 -0
  130. data/lib/libv8/v8/src/d8.cc +803 -0
  131. data/lib/libv8/v8/src/d8.gyp +91 -0
  132. data/lib/libv8/v8/src/d8.h +235 -0
  133. data/lib/libv8/v8/src/d8.js +2798 -0
  134. data/lib/libv8/v8/src/data-flow.cc +66 -0
  135. data/lib/libv8/v8/src/data-flow.h +205 -0
  136. data/lib/libv8/v8/src/date.js +1103 -0
  137. data/lib/libv8/v8/src/dateparser-inl.h +127 -0
  138. data/lib/libv8/v8/src/dateparser.cc +178 -0
  139. data/lib/libv8/v8/src/dateparser.h +266 -0
  140. data/lib/libv8/v8/src/debug-agent.cc +447 -0
  141. data/lib/libv8/v8/src/debug-agent.h +129 -0
  142. data/lib/libv8/v8/src/debug-debugger.js +2569 -0
  143. data/lib/libv8/v8/src/debug.cc +3165 -0
  144. data/lib/libv8/v8/src/debug.h +1057 -0
  145. data/lib/libv8/v8/src/deoptimizer.cc +1256 -0
  146. data/lib/libv8/v8/src/deoptimizer.h +602 -0
  147. data/lib/libv8/v8/src/disasm.h +80 -0
  148. data/lib/libv8/v8/src/disassembler.cc +343 -0
  149. data/lib/libv8/v8/src/disassembler.h +58 -0
  150. data/lib/libv8/v8/src/diy-fp.cc +58 -0
  151. data/lib/libv8/v8/src/diy-fp.h +117 -0
  152. data/lib/libv8/v8/src/double.h +238 -0
  153. data/lib/libv8/v8/src/dtoa.cc +103 -0
  154. data/lib/libv8/v8/src/dtoa.h +85 -0
  155. data/lib/libv8/v8/src/execution.cc +849 -0
  156. data/lib/libv8/v8/src/execution.h +297 -0
  157. data/lib/libv8/v8/src/extensions/experimental/break-iterator.cc +250 -0
  158. data/lib/libv8/v8/src/extensions/experimental/break-iterator.h +89 -0
  159. data/lib/libv8/v8/src/extensions/experimental/collator.cc +218 -0
  160. data/lib/libv8/v8/src/extensions/experimental/collator.h +69 -0
  161. data/lib/libv8/v8/src/extensions/experimental/experimental.gyp +94 -0
  162. data/lib/libv8/v8/src/extensions/experimental/i18n-extension.cc +78 -0
  163. data/lib/libv8/v8/src/extensions/experimental/i18n-extension.h +54 -0
  164. data/lib/libv8/v8/src/extensions/experimental/i18n-locale.cc +112 -0
  165. data/lib/libv8/v8/src/extensions/experimental/i18n-locale.h +60 -0
  166. data/lib/libv8/v8/src/extensions/experimental/i18n-utils.cc +43 -0
  167. data/lib/libv8/v8/src/extensions/experimental/i18n-utils.h +49 -0
  168. data/lib/libv8/v8/src/extensions/experimental/i18n.js +180 -0
  169. data/lib/libv8/v8/src/extensions/experimental/language-matcher.cc +251 -0
  170. data/lib/libv8/v8/src/extensions/experimental/language-matcher.h +95 -0
  171. data/lib/libv8/v8/src/extensions/externalize-string-extension.cc +141 -0
  172. data/lib/libv8/v8/src/extensions/externalize-string-extension.h +50 -0
  173. data/lib/libv8/v8/src/extensions/gc-extension.cc +58 -0
  174. data/lib/libv8/v8/src/extensions/gc-extension.h +49 -0
  175. data/lib/libv8/v8/src/factory.cc +1222 -0
  176. data/lib/libv8/v8/src/factory.h +442 -0
  177. data/lib/libv8/v8/src/fast-dtoa.cc +736 -0
  178. data/lib/libv8/v8/src/fast-dtoa.h +83 -0
  179. data/lib/libv8/v8/src/fixed-dtoa.cc +405 -0
  180. data/lib/libv8/v8/src/fixed-dtoa.h +55 -0
  181. data/lib/libv8/v8/src/flag-definitions.h +560 -0
  182. data/lib/libv8/v8/src/flags.cc +551 -0
  183. data/lib/libv8/v8/src/flags.h +79 -0
  184. data/lib/libv8/v8/src/frames-inl.h +247 -0
  185. data/lib/libv8/v8/src/frames.cc +1243 -0
  186. data/lib/libv8/v8/src/frames.h +870 -0
  187. data/lib/libv8/v8/src/full-codegen.cc +1374 -0
  188. data/lib/libv8/v8/src/full-codegen.h +771 -0
  189. data/lib/libv8/v8/src/func-name-inferrer.cc +92 -0
  190. data/lib/libv8/v8/src/func-name-inferrer.h +111 -0
  191. data/lib/libv8/v8/src/gdb-jit.cc +1555 -0
  192. data/lib/libv8/v8/src/gdb-jit.h +143 -0
  193. data/lib/libv8/v8/src/global-handles.cc +665 -0
  194. data/lib/libv8/v8/src/global-handles.h +284 -0
  195. data/lib/libv8/v8/src/globals.h +325 -0
  196. data/lib/libv8/v8/src/handles-inl.h +177 -0
  197. data/lib/libv8/v8/src/handles.cc +987 -0
  198. data/lib/libv8/v8/src/handles.h +382 -0
  199. data/lib/libv8/v8/src/hashmap.cc +230 -0
  200. data/lib/libv8/v8/src/hashmap.h +123 -0
  201. data/lib/libv8/v8/src/heap-inl.h +704 -0
  202. data/lib/libv8/v8/src/heap-profiler.cc +1173 -0
  203. data/lib/libv8/v8/src/heap-profiler.h +397 -0
  204. data/lib/libv8/v8/src/heap.cc +5930 -0
  205. data/lib/libv8/v8/src/heap.h +2268 -0
  206. data/lib/libv8/v8/src/hydrogen-instructions.cc +1769 -0
  207. data/lib/libv8/v8/src/hydrogen-instructions.h +3971 -0
  208. data/lib/libv8/v8/src/hydrogen.cc +6239 -0
  209. data/lib/libv8/v8/src/hydrogen.h +1202 -0
  210. data/lib/libv8/v8/src/ia32/assembler-ia32-inl.h +446 -0
  211. data/lib/libv8/v8/src/ia32/assembler-ia32.cc +2487 -0
  212. data/lib/libv8/v8/src/ia32/assembler-ia32.h +1144 -0
  213. data/lib/libv8/v8/src/ia32/builtins-ia32.cc +1621 -0
  214. data/lib/libv8/v8/src/ia32/code-stubs-ia32.cc +6198 -0
  215. data/lib/libv8/v8/src/ia32/code-stubs-ia32.h +517 -0
  216. data/lib/libv8/v8/src/ia32/codegen-ia32.cc +265 -0
  217. data/lib/libv8/v8/src/ia32/codegen-ia32.h +79 -0
  218. data/lib/libv8/v8/src/ia32/cpu-ia32.cc +88 -0
  219. data/lib/libv8/v8/src/ia32/debug-ia32.cc +312 -0
  220. data/lib/libv8/v8/src/ia32/deoptimizer-ia32.cc +774 -0
  221. data/lib/libv8/v8/src/ia32/disasm-ia32.cc +1628 -0
  222. data/lib/libv8/v8/src/ia32/frames-ia32.cc +45 -0
  223. data/lib/libv8/v8/src/ia32/frames-ia32.h +142 -0
  224. data/lib/libv8/v8/src/ia32/full-codegen-ia32.cc +4338 -0
  225. data/lib/libv8/v8/src/ia32/ic-ia32.cc +1597 -0
  226. data/lib/libv8/v8/src/ia32/lithium-codegen-ia32.cc +4461 -0
  227. data/lib/libv8/v8/src/ia32/lithium-codegen-ia32.h +375 -0
  228. data/lib/libv8/v8/src/ia32/lithium-gap-resolver-ia32.cc +475 -0
  229. data/lib/libv8/v8/src/ia32/lithium-gap-resolver-ia32.h +110 -0
  230. data/lib/libv8/v8/src/ia32/lithium-ia32.cc +2261 -0
  231. data/lib/libv8/v8/src/ia32/lithium-ia32.h +2396 -0
  232. data/lib/libv8/v8/src/ia32/macro-assembler-ia32.cc +2136 -0
  233. data/lib/libv8/v8/src/ia32/macro-assembler-ia32.h +775 -0
  234. data/lib/libv8/v8/src/ia32/regexp-macro-assembler-ia32.cc +1263 -0
  235. data/lib/libv8/v8/src/ia32/regexp-macro-assembler-ia32.h +216 -0
  236. data/lib/libv8/v8/src/ia32/simulator-ia32.cc +30 -0
  237. data/lib/libv8/v8/src/ia32/simulator-ia32.h +74 -0
  238. data/lib/libv8/v8/src/ia32/stub-cache-ia32.cc +3847 -0
  239. data/lib/libv8/v8/src/ic-inl.h +130 -0
  240. data/lib/libv8/v8/src/ic.cc +2577 -0
  241. data/lib/libv8/v8/src/ic.h +736 -0
  242. data/lib/libv8/v8/src/inspector.cc +63 -0
  243. data/lib/libv8/v8/src/inspector.h +62 -0
  244. data/lib/libv8/v8/src/interpreter-irregexp.cc +659 -0
  245. data/lib/libv8/v8/src/interpreter-irregexp.h +49 -0
  246. data/lib/libv8/v8/src/isolate-inl.h +50 -0
  247. data/lib/libv8/v8/src/isolate.cc +1869 -0
  248. data/lib/libv8/v8/src/isolate.h +1382 -0
  249. data/lib/libv8/v8/src/json-parser.cc +504 -0
  250. data/lib/libv8/v8/src/json-parser.h +161 -0
  251. data/lib/libv8/v8/src/json.js +342 -0
  252. data/lib/libv8/v8/src/jsregexp.cc +5385 -0
  253. data/lib/libv8/v8/src/jsregexp.h +1492 -0
  254. data/lib/libv8/v8/src/list-inl.h +212 -0
  255. data/lib/libv8/v8/src/list.h +174 -0
  256. data/lib/libv8/v8/src/lithium-allocator-inl.h +142 -0
  257. data/lib/libv8/v8/src/lithium-allocator.cc +2123 -0
  258. data/lib/libv8/v8/src/lithium-allocator.h +630 -0
  259. data/lib/libv8/v8/src/lithium.cc +190 -0
  260. data/lib/libv8/v8/src/lithium.h +597 -0
  261. data/lib/libv8/v8/src/liveedit-debugger.js +1082 -0
  262. data/lib/libv8/v8/src/liveedit.cc +1691 -0
  263. data/lib/libv8/v8/src/liveedit.h +180 -0
  264. data/lib/libv8/v8/src/liveobjectlist-inl.h +126 -0
  265. data/lib/libv8/v8/src/liveobjectlist.cc +2589 -0
  266. data/lib/libv8/v8/src/liveobjectlist.h +322 -0
  267. data/lib/libv8/v8/src/log-inl.h +59 -0
  268. data/lib/libv8/v8/src/log-utils.cc +428 -0
  269. data/lib/libv8/v8/src/log-utils.h +231 -0
  270. data/lib/libv8/v8/src/log.cc +1993 -0
  271. data/lib/libv8/v8/src/log.h +476 -0
  272. data/lib/libv8/v8/src/macro-assembler.h +120 -0
  273. data/lib/libv8/v8/src/macros.py +178 -0
  274. data/lib/libv8/v8/src/mark-compact.cc +3143 -0
  275. data/lib/libv8/v8/src/mark-compact.h +506 -0
  276. data/lib/libv8/v8/src/math.js +264 -0
  277. data/lib/libv8/v8/src/messages.cc +179 -0
  278. data/lib/libv8/v8/src/messages.h +113 -0
  279. data/lib/libv8/v8/src/messages.js +1096 -0
  280. data/lib/libv8/v8/src/mips/assembler-mips-inl.h +312 -0
  281. data/lib/libv8/v8/src/mips/assembler-mips.cc +1960 -0
  282. data/lib/libv8/v8/src/mips/assembler-mips.h +1138 -0
  283. data/lib/libv8/v8/src/mips/builtins-mips.cc +1628 -0
  284. data/lib/libv8/v8/src/mips/code-stubs-mips.cc +6656 -0
  285. data/lib/libv8/v8/src/mips/code-stubs-mips.h +682 -0
  286. data/lib/libv8/v8/src/mips/codegen-mips.cc +52 -0
  287. data/lib/libv8/v8/src/mips/codegen-mips.h +98 -0
  288. data/lib/libv8/v8/src/mips/constants-mips.cc +352 -0
  289. data/lib/libv8/v8/src/mips/constants-mips.h +739 -0
  290. data/lib/libv8/v8/src/mips/cpu-mips.cc +96 -0
  291. data/lib/libv8/v8/src/mips/debug-mips.cc +308 -0
  292. data/lib/libv8/v8/src/mips/deoptimizer-mips.cc +91 -0
  293. data/lib/libv8/v8/src/mips/disasm-mips.cc +1050 -0
  294. data/lib/libv8/v8/src/mips/frames-mips.cc +47 -0
  295. data/lib/libv8/v8/src/mips/frames-mips.h +219 -0
  296. data/lib/libv8/v8/src/mips/full-codegen-mips.cc +4388 -0
  297. data/lib/libv8/v8/src/mips/ic-mips.cc +1580 -0
  298. data/lib/libv8/v8/src/mips/lithium-codegen-mips.h +65 -0
  299. data/lib/libv8/v8/src/mips/lithium-mips.h +307 -0
  300. data/lib/libv8/v8/src/mips/macro-assembler-mips.cc +4056 -0
  301. data/lib/libv8/v8/src/mips/macro-assembler-mips.h +1214 -0
  302. data/lib/libv8/v8/src/mips/regexp-macro-assembler-mips.cc +1251 -0
  303. data/lib/libv8/v8/src/mips/regexp-macro-assembler-mips.h +252 -0
  304. data/lib/libv8/v8/src/mips/simulator-mips.cc +2621 -0
  305. data/lib/libv8/v8/src/mips/simulator-mips.h +401 -0
  306. data/lib/libv8/v8/src/mips/stub-cache-mips.cc +4285 -0
  307. data/lib/libv8/v8/src/mirror-debugger.js +2382 -0
  308. data/lib/libv8/v8/src/mksnapshot.cc +328 -0
  309. data/lib/libv8/v8/src/natives.h +64 -0
  310. data/lib/libv8/v8/src/objects-debug.cc +738 -0
  311. data/lib/libv8/v8/src/objects-inl.h +4323 -0
  312. data/lib/libv8/v8/src/objects-printer.cc +829 -0
  313. data/lib/libv8/v8/src/objects-visiting.cc +148 -0
  314. data/lib/libv8/v8/src/objects-visiting.h +424 -0
  315. data/lib/libv8/v8/src/objects.cc +10585 -0
  316. data/lib/libv8/v8/src/objects.h +6838 -0
  317. data/lib/libv8/v8/src/parser.cc +4997 -0
  318. data/lib/libv8/v8/src/parser.h +765 -0
  319. data/lib/libv8/v8/src/platform-cygwin.cc +779 -0
  320. data/lib/libv8/v8/src/platform-freebsd.cc +826 -0
  321. data/lib/libv8/v8/src/platform-linux.cc +1149 -0
  322. data/lib/libv8/v8/src/platform-macos.cc +830 -0
  323. data/lib/libv8/v8/src/platform-nullos.cc +479 -0
  324. data/lib/libv8/v8/src/platform-openbsd.cc +640 -0
  325. data/lib/libv8/v8/src/platform-posix.cc +424 -0
  326. data/lib/libv8/v8/src/platform-solaris.cc +762 -0
  327. data/lib/libv8/v8/src/platform-tls-mac.h +62 -0
  328. data/lib/libv8/v8/src/platform-tls-win32.h +62 -0
  329. data/lib/libv8/v8/src/platform-tls.h +50 -0
  330. data/lib/libv8/v8/src/platform-win32.cc +2021 -0
  331. data/lib/libv8/v8/src/platform.h +667 -0
  332. data/lib/libv8/v8/src/preparse-data-format.h +62 -0
  333. data/lib/libv8/v8/src/preparse-data.cc +183 -0
  334. data/lib/libv8/v8/src/preparse-data.h +225 -0
  335. data/lib/libv8/v8/src/preparser-api.cc +220 -0
  336. data/lib/libv8/v8/src/preparser.cc +1450 -0
  337. data/lib/libv8/v8/src/preparser.h +493 -0
  338. data/lib/libv8/v8/src/prettyprinter.cc +1493 -0
  339. data/lib/libv8/v8/src/prettyprinter.h +223 -0
  340. data/lib/libv8/v8/src/profile-generator-inl.h +128 -0
  341. data/lib/libv8/v8/src/profile-generator.cc +3098 -0
  342. data/lib/libv8/v8/src/profile-generator.h +1126 -0
  343. data/lib/libv8/v8/src/property.cc +105 -0
  344. data/lib/libv8/v8/src/property.h +365 -0
  345. data/lib/libv8/v8/src/proxy.js +83 -0
  346. data/lib/libv8/v8/src/regexp-macro-assembler-irregexp-inl.h +78 -0
  347. data/lib/libv8/v8/src/regexp-macro-assembler-irregexp.cc +471 -0
  348. data/lib/libv8/v8/src/regexp-macro-assembler-irregexp.h +142 -0
  349. data/lib/libv8/v8/src/regexp-macro-assembler-tracer.cc +373 -0
  350. data/lib/libv8/v8/src/regexp-macro-assembler-tracer.h +104 -0
  351. data/lib/libv8/v8/src/regexp-macro-assembler.cc +267 -0
  352. data/lib/libv8/v8/src/regexp-macro-assembler.h +243 -0
  353. data/lib/libv8/v8/src/regexp-stack.cc +111 -0
  354. data/lib/libv8/v8/src/regexp-stack.h +147 -0
  355. data/lib/libv8/v8/src/regexp.js +483 -0
  356. data/lib/libv8/v8/src/rewriter.cc +360 -0
  357. data/lib/libv8/v8/src/rewriter.h +50 -0
  358. data/lib/libv8/v8/src/runtime-profiler.cc +489 -0
  359. data/lib/libv8/v8/src/runtime-profiler.h +201 -0
  360. data/lib/libv8/v8/src/runtime.cc +12227 -0
  361. data/lib/libv8/v8/src/runtime.h +652 -0
  362. data/lib/libv8/v8/src/runtime.js +649 -0
  363. data/lib/libv8/v8/src/safepoint-table.cc +256 -0
  364. data/lib/libv8/v8/src/safepoint-table.h +270 -0
  365. data/lib/libv8/v8/src/scanner-base.cc +952 -0
  366. data/lib/libv8/v8/src/scanner-base.h +670 -0
  367. data/lib/libv8/v8/src/scanner.cc +345 -0
  368. data/lib/libv8/v8/src/scanner.h +146 -0
  369. data/lib/libv8/v8/src/scopeinfo.cc +646 -0
  370. data/lib/libv8/v8/src/scopeinfo.h +254 -0
  371. data/lib/libv8/v8/src/scopes.cc +1150 -0
  372. data/lib/libv8/v8/src/scopes.h +507 -0
  373. data/lib/libv8/v8/src/serialize.cc +1574 -0
  374. data/lib/libv8/v8/src/serialize.h +589 -0
  375. data/lib/libv8/v8/src/shell.h +55 -0
  376. data/lib/libv8/v8/src/simulator.h +43 -0
  377. data/lib/libv8/v8/src/small-pointer-list.h +163 -0
  378. data/lib/libv8/v8/src/smart-pointer.h +109 -0
  379. data/lib/libv8/v8/src/snapshot-common.cc +83 -0
  380. data/lib/libv8/v8/src/snapshot-empty.cc +54 -0
  381. data/lib/libv8/v8/src/snapshot.h +91 -0
  382. data/lib/libv8/v8/src/spaces-inl.h +529 -0
  383. data/lib/libv8/v8/src/spaces.cc +3145 -0
  384. data/lib/libv8/v8/src/spaces.h +2369 -0
  385. data/lib/libv8/v8/src/splay-tree-inl.h +310 -0
  386. data/lib/libv8/v8/src/splay-tree.h +205 -0
  387. data/lib/libv8/v8/src/string-search.cc +41 -0
  388. data/lib/libv8/v8/src/string-search.h +568 -0
  389. data/lib/libv8/v8/src/string-stream.cc +592 -0
  390. data/lib/libv8/v8/src/string-stream.h +191 -0
  391. data/lib/libv8/v8/src/string.js +994 -0
  392. data/lib/libv8/v8/src/strtod.cc +440 -0
  393. data/lib/libv8/v8/src/strtod.h +40 -0
  394. data/lib/libv8/v8/src/stub-cache.cc +1965 -0
  395. data/lib/libv8/v8/src/stub-cache.h +924 -0
  396. data/lib/libv8/v8/src/third_party/valgrind/valgrind.h +3925 -0
  397. data/lib/libv8/v8/src/token.cc +63 -0
  398. data/lib/libv8/v8/src/token.h +288 -0
  399. data/lib/libv8/v8/src/type-info.cc +507 -0
  400. data/lib/libv8/v8/src/type-info.h +272 -0
  401. data/lib/libv8/v8/src/unbound-queue-inl.h +95 -0
  402. data/lib/libv8/v8/src/unbound-queue.h +69 -0
  403. data/lib/libv8/v8/src/unicode-inl.h +238 -0
  404. data/lib/libv8/v8/src/unicode.cc +1624 -0
  405. data/lib/libv8/v8/src/unicode.h +280 -0
  406. data/lib/libv8/v8/src/uri.js +408 -0
  407. data/lib/libv8/v8/src/utils-inl.h +48 -0
  408. data/lib/libv8/v8/src/utils.cc +371 -0
  409. data/lib/libv8/v8/src/utils.h +800 -0
  410. data/lib/libv8/v8/src/v8-counters.cc +62 -0
  411. data/lib/libv8/v8/src/v8-counters.h +314 -0
  412. data/lib/libv8/v8/src/v8.cc +213 -0
  413. data/lib/libv8/v8/src/v8.h +131 -0
  414. data/lib/libv8/v8/src/v8checks.h +64 -0
  415. data/lib/libv8/v8/src/v8dll-main.cc +44 -0
  416. data/lib/libv8/v8/src/v8globals.h +512 -0
  417. data/lib/libv8/v8/src/v8memory.h +82 -0
  418. data/lib/libv8/v8/src/v8natives.js +1310 -0
  419. data/lib/libv8/v8/src/v8preparserdll-main.cc +39 -0
  420. data/lib/libv8/v8/src/v8threads.cc +464 -0
  421. data/lib/libv8/v8/src/v8threads.h +165 -0
  422. data/lib/libv8/v8/src/v8utils.h +319 -0
  423. data/lib/libv8/v8/src/variables.cc +114 -0
  424. data/lib/libv8/v8/src/variables.h +167 -0
  425. data/lib/libv8/v8/src/version.cc +116 -0
  426. data/lib/libv8/v8/src/version.h +68 -0
  427. data/lib/libv8/v8/src/vm-state-inl.h +138 -0
  428. data/lib/libv8/v8/src/vm-state.h +71 -0
  429. data/lib/libv8/v8/src/win32-headers.h +96 -0
  430. data/lib/libv8/v8/src/x64/assembler-x64-inl.h +462 -0
  431. data/lib/libv8/v8/src/x64/assembler-x64.cc +3027 -0
  432. data/lib/libv8/v8/src/x64/assembler-x64.h +1633 -0
  433. data/lib/libv8/v8/src/x64/builtins-x64.cc +1520 -0
  434. data/lib/libv8/v8/src/x64/code-stubs-x64.cc +5132 -0
  435. data/lib/libv8/v8/src/x64/code-stubs-x64.h +514 -0
  436. data/lib/libv8/v8/src/x64/codegen-x64.cc +146 -0
  437. data/lib/libv8/v8/src/x64/codegen-x64.h +76 -0
  438. data/lib/libv8/v8/src/x64/cpu-x64.cc +88 -0
  439. data/lib/libv8/v8/src/x64/debug-x64.cc +319 -0
  440. data/lib/libv8/v8/src/x64/deoptimizer-x64.cc +815 -0
  441. data/lib/libv8/v8/src/x64/disasm-x64.cc +1832 -0
  442. data/lib/libv8/v8/src/x64/frames-x64.cc +45 -0
  443. data/lib/libv8/v8/src/x64/frames-x64.h +130 -0
  444. data/lib/libv8/v8/src/x64/full-codegen-x64.cc +4318 -0
  445. data/lib/libv8/v8/src/x64/ic-x64.cc +1608 -0
  446. data/lib/libv8/v8/src/x64/lithium-codegen-x64.cc +4267 -0
  447. data/lib/libv8/v8/src/x64/lithium-codegen-x64.h +367 -0
  448. data/lib/libv8/v8/src/x64/lithium-gap-resolver-x64.cc +320 -0
  449. data/lib/libv8/v8/src/x64/lithium-gap-resolver-x64.h +74 -0
  450. data/lib/libv8/v8/src/x64/lithium-x64.cc +2202 -0
  451. data/lib/libv8/v8/src/x64/lithium-x64.h +2333 -0
  452. data/lib/libv8/v8/src/x64/macro-assembler-x64.cc +3745 -0
  453. data/lib/libv8/v8/src/x64/macro-assembler-x64.h +1290 -0
  454. data/lib/libv8/v8/src/x64/regexp-macro-assembler-x64.cc +1398 -0
  455. data/lib/libv8/v8/src/x64/regexp-macro-assembler-x64.h +282 -0
  456. data/lib/libv8/v8/src/x64/simulator-x64.cc +27 -0
  457. data/lib/libv8/v8/src/x64/simulator-x64.h +72 -0
  458. data/lib/libv8/v8/src/x64/stub-cache-x64.cc +3610 -0
  459. data/lib/libv8/v8/src/zone-inl.h +140 -0
  460. data/lib/libv8/v8/src/zone.cc +196 -0
  461. data/lib/libv8/v8/src/zone.h +240 -0
  462. data/lib/libv8/v8/tools/codemap.js +265 -0
  463. data/lib/libv8/v8/tools/consarray.js +93 -0
  464. data/lib/libv8/v8/tools/csvparser.js +78 -0
  465. data/lib/libv8/v8/tools/disasm.py +92 -0
  466. data/lib/libv8/v8/tools/freebsd-tick-processor +10 -0
  467. data/lib/libv8/v8/tools/gc-nvp-trace-processor.py +342 -0
  468. data/lib/libv8/v8/tools/gcmole/README +62 -0
  469. data/lib/libv8/v8/tools/gcmole/gccause.lua +60 -0
  470. data/lib/libv8/v8/tools/gcmole/gcmole.cc +1261 -0
  471. data/lib/libv8/v8/tools/gcmole/gcmole.lua +378 -0
  472. data/lib/libv8/v8/tools/generate-ten-powers.scm +286 -0
  473. data/lib/libv8/v8/tools/grokdump.py +841 -0
  474. data/lib/libv8/v8/tools/gyp/v8.gyp +995 -0
  475. data/lib/libv8/v8/tools/js2c.py +364 -0
  476. data/lib/libv8/v8/tools/jsmin.py +280 -0
  477. data/lib/libv8/v8/tools/linux-tick-processor +35 -0
  478. data/lib/libv8/v8/tools/ll_prof.py +942 -0
  479. data/lib/libv8/v8/tools/logreader.js +185 -0
  480. data/lib/libv8/v8/tools/mac-nm +18 -0
  481. data/lib/libv8/v8/tools/mac-tick-processor +6 -0
  482. data/lib/libv8/v8/tools/oom_dump/README +31 -0
  483. data/lib/libv8/v8/tools/oom_dump/SConstruct +42 -0
  484. data/lib/libv8/v8/tools/oom_dump/oom_dump.cc +288 -0
  485. data/lib/libv8/v8/tools/presubmit.py +305 -0
  486. data/lib/libv8/v8/tools/process-heap-prof.py +120 -0
  487. data/lib/libv8/v8/tools/profile.js +751 -0
  488. data/lib/libv8/v8/tools/profile_view.js +219 -0
  489. data/lib/libv8/v8/tools/run-valgrind.py +77 -0
  490. data/lib/libv8/v8/tools/splaytree.js +316 -0
  491. data/lib/libv8/v8/tools/stats-viewer.py +468 -0
  492. data/lib/libv8/v8/tools/test.py +1510 -0
  493. data/lib/libv8/v8/tools/tickprocessor-driver.js +59 -0
  494. data/lib/libv8/v8/tools/tickprocessor.js +877 -0
  495. data/lib/libv8/v8/tools/utils.py +96 -0
  496. data/lib/libv8/v8/tools/visual_studio/README.txt +12 -0
  497. data/lib/libv8/v8/tools/windows-tick-processor.bat +30 -0
  498. data/lib/libv8/version.rb +5 -0
  499. data/libv8.gemspec +36 -0
  500. metadata +578 -0
@@ -0,0 +1,1149 @@
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
+ // Platform specific code for Linux goes here. For the POSIX comaptible parts
29
+ // the implementation is in platform-posix.cc.
30
+
31
+ #include <pthread.h>
32
+ #include <semaphore.h>
33
+ #include <signal.h>
34
+ #include <sys/prctl.h>
35
+ #include <sys/time.h>
36
+ #include <sys/resource.h>
37
+ #include <sys/syscall.h>
38
+ #include <sys/types.h>
39
+ #include <stdlib.h>
40
+
41
+ // Ubuntu Dapper requires memory pages to be marked as
42
+ // executable. Otherwise, OS raises an exception when executing code
43
+ // in that page.
44
+ #include <sys/types.h> // mmap & munmap
45
+ #include <sys/mman.h> // mmap & munmap
46
+ #include <sys/stat.h> // open
47
+ #include <fcntl.h> // open
48
+ #include <unistd.h> // sysconf
49
+ #ifdef __GLIBC__
50
+ #include <execinfo.h> // backtrace, backtrace_symbols
51
+ #endif // def __GLIBC__
52
+ #include <strings.h> // index
53
+ #include <errno.h>
54
+ #include <stdarg.h>
55
+
56
+ #undef MAP_TYPE
57
+
58
+ #include "v8.h"
59
+
60
+ #include "platform.h"
61
+ #include "v8threads.h"
62
+ #include "vm-state-inl.h"
63
+
64
+
65
+ namespace v8 {
66
+ namespace internal {
67
+
68
+ // 0 is never a valid thread id on Linux since tids and pids share a
69
+ // name space and pid 0 is reserved (see man 2 kill).
70
+ static const pthread_t kNoThread = (pthread_t) 0;
71
+
72
+
73
+ double ceiling(double x) {
74
+ return ceil(x);
75
+ }
76
+
77
+
78
+ static Mutex* limit_mutex = NULL;
79
+
80
+
81
+ void OS::Setup() {
82
+ // Seed the random number generator.
83
+ // Convert the current time to a 64-bit integer first, before converting it
84
+ // to an unsigned. Going directly can cause an overflow and the seed to be
85
+ // set to all ones. The seed will be identical for different instances that
86
+ // call this setup code within the same millisecond.
87
+ uint64_t seed = static_cast<uint64_t>(TimeCurrentMillis());
88
+ srandom(static_cast<unsigned int>(seed));
89
+ limit_mutex = CreateMutex();
90
+
91
+ #ifdef __arm__
92
+ // When running on ARM hardware check that the EABI used by V8 and
93
+ // by the C code is the same.
94
+ bool hard_float = OS::ArmUsingHardFloat();
95
+ if (hard_float) {
96
+ #if !USE_EABI_HARDFLOAT
97
+ PrintF("ERROR: Binary compiled with -mfloat-abi=hard but without "
98
+ "-DUSE_EABI_HARDFLOAT\n");
99
+ exit(1);
100
+ #endif
101
+ } else {
102
+ #if USE_EABI_HARDFLOAT
103
+ PrintF("ERROR: Binary not compiled with -mfloat-abi=hard but with "
104
+ "-DUSE_EABI_HARDFLOAT\n");
105
+ exit(1);
106
+ #endif
107
+ }
108
+ #endif
109
+ }
110
+
111
+
112
+ uint64_t OS::CpuFeaturesImpliedByPlatform() {
113
+ #if(defined(__mips_hard_float) && __mips_hard_float != 0)
114
+ // Here gcc is telling us that we are on an MIPS and gcc is assuming that we
115
+ // have FPU instructions. If gcc can assume it then so can we.
116
+ return 1u << FPU;
117
+ #else
118
+ return 0; // Linux runs on anything.
119
+ #endif
120
+ }
121
+
122
+
123
+ #ifdef __arm__
124
+ static bool CPUInfoContainsString(const char * search_string) {
125
+ const char* file_name = "/proc/cpuinfo";
126
+ // This is written as a straight shot one pass parser
127
+ // and not using STL string and ifstream because,
128
+ // on Linux, it's reading from a (non-mmap-able)
129
+ // character special device.
130
+ FILE* f = NULL;
131
+ const char* what = search_string;
132
+
133
+ if (NULL == (f = fopen(file_name, "r")))
134
+ return false;
135
+
136
+ int k;
137
+ while (EOF != (k = fgetc(f))) {
138
+ if (k == *what) {
139
+ ++what;
140
+ while ((*what != '\0') && (*what == fgetc(f))) {
141
+ ++what;
142
+ }
143
+ if (*what == '\0') {
144
+ fclose(f);
145
+ return true;
146
+ } else {
147
+ what = search_string;
148
+ }
149
+ }
150
+ }
151
+ fclose(f);
152
+
153
+ // Did not find string in the proc file.
154
+ return false;
155
+ }
156
+
157
+
158
+ bool OS::ArmCpuHasFeature(CpuFeature feature) {
159
+ const char* search_string = NULL;
160
+ // Simple detection of VFP at runtime for Linux.
161
+ // It is based on /proc/cpuinfo, which reveals hardware configuration
162
+ // to user-space applications. According to ARM (mid 2009), no similar
163
+ // facility is universally available on the ARM architectures,
164
+ // so it's up to individual OSes to provide such.
165
+ switch (feature) {
166
+ case VFP3:
167
+ search_string = "vfpv3";
168
+ break;
169
+ case ARMv7:
170
+ search_string = "ARMv7";
171
+ break;
172
+ default:
173
+ UNREACHABLE();
174
+ }
175
+
176
+ if (CPUInfoContainsString(search_string)) {
177
+ return true;
178
+ }
179
+
180
+ if (feature == VFP3) {
181
+ // Some old kernels will report vfp not vfpv3. Here we make a last attempt
182
+ // to detect vfpv3 by checking for vfp *and* neon, since neon is only
183
+ // available on architectures with vfpv3.
184
+ // Checking neon on its own is not enough as it is possible to have neon
185
+ // without vfp.
186
+ if (CPUInfoContainsString("vfp") && CPUInfoContainsString("neon")) {
187
+ return true;
188
+ }
189
+ }
190
+
191
+ return false;
192
+ }
193
+
194
+
195
+ // Simple helper function to detect whether the C code is compiled with
196
+ // option -mfloat-abi=hard. The register d0 is loaded with 1.0 and the register
197
+ // pair r0, r1 is loaded with 0.0. If -mfloat-abi=hard is pased to GCC then
198
+ // calling this will return 1.0 and otherwise 0.0.
199
+ static void ArmUsingHardFloatHelper() {
200
+ asm("mov r0, #0");
201
+ #if defined(__VFP_FP__) && !defined(__SOFTFP__)
202
+ // Load 0x3ff00000 into r1 using instructions available in both ARM
203
+ // and Thumb mode.
204
+ asm("mov r1, #3");
205
+ asm("mov r2, #255");
206
+ asm("lsl r1, r1, #8");
207
+ asm("orr r1, r1, r2");
208
+ asm("lsl r1, r1, #20");
209
+ // For vmov d0, r0, r1 use ARM mode.
210
+ #ifdef __thumb__
211
+ asm volatile(
212
+ "@ Enter ARM Mode \n\t"
213
+ " adr r3, 1f \n\t"
214
+ " bx r3 \n\t"
215
+ " .ALIGN 4 \n\t"
216
+ " .ARM \n"
217
+ "1: vmov d0, r0, r1 \n\t"
218
+ "@ Enter THUMB Mode\n\t"
219
+ " adr r3, 2f+1 \n\t"
220
+ " bx r3 \n\t"
221
+ " .THUMB \n"
222
+ "2: \n\t");
223
+ #else
224
+ asm("vmov d0, r0, r1");
225
+ #endif // __thumb__
226
+ #endif // defined(__VFP_FP__) && !defined(__SOFTFP__)
227
+ asm("mov r1, #0");
228
+ }
229
+
230
+
231
+ bool OS::ArmUsingHardFloat() {
232
+ // Cast helper function from returning void to returning double.
233
+ typedef double (*F)();
234
+ F f = FUNCTION_CAST<F>(FUNCTION_ADDR(ArmUsingHardFloatHelper));
235
+ return f() == 1.0;
236
+ }
237
+ #endif // def __arm__
238
+
239
+
240
+ #ifdef __mips__
241
+ bool OS::MipsCpuHasFeature(CpuFeature feature) {
242
+ const char* search_string = NULL;
243
+ const char* file_name = "/proc/cpuinfo";
244
+ // Simple detection of FPU at runtime for Linux.
245
+ // It is based on /proc/cpuinfo, which reveals hardware configuration
246
+ // to user-space applications. According to MIPS (early 2010), no similar
247
+ // facility is universally available on the MIPS architectures,
248
+ // so it's up to individual OSes to provide such.
249
+ //
250
+ // This is written as a straight shot one pass parser
251
+ // and not using STL string and ifstream because,
252
+ // on Linux, it's reading from a (non-mmap-able)
253
+ // character special device.
254
+
255
+ switch (feature) {
256
+ case FPU:
257
+ search_string = "FPU";
258
+ break;
259
+ default:
260
+ UNREACHABLE();
261
+ }
262
+
263
+ FILE* f = NULL;
264
+ const char* what = search_string;
265
+
266
+ if (NULL == (f = fopen(file_name, "r")))
267
+ return false;
268
+
269
+ int k;
270
+ while (EOF != (k = fgetc(f))) {
271
+ if (k == *what) {
272
+ ++what;
273
+ while ((*what != '\0') && (*what == fgetc(f))) {
274
+ ++what;
275
+ }
276
+ if (*what == '\0') {
277
+ fclose(f);
278
+ return true;
279
+ } else {
280
+ what = search_string;
281
+ }
282
+ }
283
+ }
284
+ fclose(f);
285
+
286
+ // Did not find string in the proc file.
287
+ return false;
288
+ }
289
+ #endif // def __mips__
290
+
291
+
292
+ int OS::ActivationFrameAlignment() {
293
+ #ifdef V8_TARGET_ARCH_ARM
294
+ // On EABI ARM targets this is required for fp correctness in the
295
+ // runtime system.
296
+ return 8;
297
+ #elif V8_TARGET_ARCH_MIPS
298
+ return 8;
299
+ #endif
300
+ // With gcc 4.4 the tree vectorization optimizer can generate code
301
+ // that requires 16 byte alignment such as movdqa on x86.
302
+ return 16;
303
+ }
304
+
305
+
306
+ void OS::ReleaseStore(volatile AtomicWord* ptr, AtomicWord value) {
307
+ #if (defined(V8_TARGET_ARCH_ARM) && defined(__arm__)) || \
308
+ (defined(V8_TARGET_ARCH_MIPS) && defined(__mips__))
309
+ // Only use on ARM or MIPS hardware.
310
+ MemoryBarrier();
311
+ #else
312
+ __asm__ __volatile__("" : : : "memory");
313
+ // An x86 store acts as a release barrier.
314
+ #endif
315
+ *ptr = value;
316
+ }
317
+
318
+
319
+ const char* OS::LocalTimezone(double time) {
320
+ if (isnan(time)) return "";
321
+ time_t tv = static_cast<time_t>(floor(time/msPerSecond));
322
+ struct tm* t = localtime(&tv);
323
+ if (NULL == t) return "";
324
+ return t->tm_zone;
325
+ }
326
+
327
+
328
+ double OS::LocalTimeOffset() {
329
+ time_t tv = time(NULL);
330
+ struct tm* t = localtime(&tv);
331
+ // tm_gmtoff includes any daylight savings offset, so subtract it.
332
+ return static_cast<double>(t->tm_gmtoff * msPerSecond -
333
+ (t->tm_isdst > 0 ? 3600 * msPerSecond : 0));
334
+ }
335
+
336
+
337
+ // We keep the lowest and highest addresses mapped as a quick way of
338
+ // determining that pointers are outside the heap (used mostly in assertions
339
+ // and verification). The estimate is conservative, ie, not all addresses in
340
+ // 'allocated' space are actually allocated to our heap. The range is
341
+ // [lowest, highest), inclusive on the low and and exclusive on the high end.
342
+ static void* lowest_ever_allocated = reinterpret_cast<void*>(-1);
343
+ static void* highest_ever_allocated = reinterpret_cast<void*>(0);
344
+
345
+
346
+ static void UpdateAllocatedSpaceLimits(void* address, int size) {
347
+ ASSERT(limit_mutex != NULL);
348
+ ScopedLock lock(limit_mutex);
349
+
350
+ lowest_ever_allocated = Min(lowest_ever_allocated, address);
351
+ highest_ever_allocated =
352
+ Max(highest_ever_allocated,
353
+ reinterpret_cast<void*>(reinterpret_cast<char*>(address) + size));
354
+ }
355
+
356
+
357
+ bool OS::IsOutsideAllocatedSpace(void* address) {
358
+ return address < lowest_ever_allocated || address >= highest_ever_allocated;
359
+ }
360
+
361
+
362
+ size_t OS::AllocateAlignment() {
363
+ return sysconf(_SC_PAGESIZE);
364
+ }
365
+
366
+
367
+ void* OS::Allocate(const size_t requested,
368
+ size_t* allocated,
369
+ bool is_executable) {
370
+ // TODO(805): Port randomization of allocated executable memory to Linux.
371
+ const size_t msize = RoundUp(requested, sysconf(_SC_PAGESIZE));
372
+ int prot = PROT_READ | PROT_WRITE | (is_executable ? PROT_EXEC : 0);
373
+ void* mbase = mmap(NULL, msize, prot, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
374
+ if (mbase == MAP_FAILED) {
375
+ LOG(i::Isolate::Current(),
376
+ StringEvent("OS::Allocate", "mmap failed"));
377
+ return NULL;
378
+ }
379
+ *allocated = msize;
380
+ UpdateAllocatedSpaceLimits(mbase, msize);
381
+ return mbase;
382
+ }
383
+
384
+
385
+ void OS::Free(void* address, const size_t size) {
386
+ // TODO(1240712): munmap has a return value which is ignored here.
387
+ int result = munmap(address, size);
388
+ USE(result);
389
+ ASSERT(result == 0);
390
+ }
391
+
392
+
393
+ #ifdef ENABLE_HEAP_PROTECTION
394
+
395
+ void OS::Protect(void* address, size_t size) {
396
+ // TODO(1240712): mprotect has a return value which is ignored here.
397
+ mprotect(address, size, PROT_READ);
398
+ }
399
+
400
+
401
+ void OS::Unprotect(void* address, size_t size, bool is_executable) {
402
+ // TODO(1240712): mprotect has a return value which is ignored here.
403
+ int prot = PROT_READ | PROT_WRITE | (is_executable ? PROT_EXEC : 0);
404
+ mprotect(address, size, prot);
405
+ }
406
+
407
+ #endif
408
+
409
+
410
+ void OS::Sleep(int milliseconds) {
411
+ unsigned int ms = static_cast<unsigned int>(milliseconds);
412
+ usleep(1000 * ms);
413
+ }
414
+
415
+
416
+ void OS::Abort() {
417
+ // Redirect to std abort to signal abnormal program termination.
418
+ abort();
419
+ }
420
+
421
+
422
+ void OS::DebugBreak() {
423
+ // TODO(lrn): Introduce processor define for runtime system (!= V8_ARCH_x,
424
+ // which is the architecture of generated code).
425
+ #if (defined(__arm__) || defined(__thumb__))
426
+ # if defined(CAN_USE_ARMV5_INSTRUCTIONS)
427
+ asm("bkpt 0");
428
+ # endif
429
+ #elif defined(__mips__)
430
+ asm("break");
431
+ #else
432
+ asm("int $3");
433
+ #endif
434
+ }
435
+
436
+
437
+ class PosixMemoryMappedFile : public OS::MemoryMappedFile {
438
+ public:
439
+ PosixMemoryMappedFile(FILE* file, void* memory, int size)
440
+ : file_(file), memory_(memory), size_(size) { }
441
+ virtual ~PosixMemoryMappedFile();
442
+ virtual void* memory() { return memory_; }
443
+ virtual int size() { return size_; }
444
+ private:
445
+ FILE* file_;
446
+ void* memory_;
447
+ int size_;
448
+ };
449
+
450
+
451
+ OS::MemoryMappedFile* OS::MemoryMappedFile::open(const char* name) {
452
+ FILE* file = fopen(name, "r+");
453
+ if (file == NULL) return NULL;
454
+
455
+ fseek(file, 0, SEEK_END);
456
+ int size = ftell(file);
457
+
458
+ void* memory =
459
+ mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fileno(file), 0);
460
+ return new PosixMemoryMappedFile(file, memory, size);
461
+ }
462
+
463
+
464
+ OS::MemoryMappedFile* OS::MemoryMappedFile::create(const char* name, int size,
465
+ void* initial) {
466
+ FILE* file = fopen(name, "w+");
467
+ if (file == NULL) return NULL;
468
+ int result = fwrite(initial, size, 1, file);
469
+ if (result < 1) {
470
+ fclose(file);
471
+ return NULL;
472
+ }
473
+ void* memory =
474
+ mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fileno(file), 0);
475
+ return new PosixMemoryMappedFile(file, memory, size);
476
+ }
477
+
478
+
479
+ PosixMemoryMappedFile::~PosixMemoryMappedFile() {
480
+ if (memory_) munmap(memory_, size_);
481
+ fclose(file_);
482
+ }
483
+
484
+
485
+ void OS::LogSharedLibraryAddresses() {
486
+ #ifdef ENABLE_LOGGING_AND_PROFILING
487
+ // This function assumes that the layout of the file is as follows:
488
+ // hex_start_addr-hex_end_addr rwxp <unused data> [binary_file_name]
489
+ // If we encounter an unexpected situation we abort scanning further entries.
490
+ FILE* fp = fopen("/proc/self/maps", "r");
491
+ if (fp == NULL) return;
492
+
493
+ // Allocate enough room to be able to store a full file name.
494
+ const int kLibNameLen = FILENAME_MAX + 1;
495
+ char* lib_name = reinterpret_cast<char*>(malloc(kLibNameLen));
496
+
497
+ i::Isolate* isolate = ISOLATE;
498
+ // This loop will terminate once the scanning hits an EOF.
499
+ while (true) {
500
+ uintptr_t start, end;
501
+ char attr_r, attr_w, attr_x, attr_p;
502
+ // Parse the addresses and permission bits at the beginning of the line.
503
+ if (fscanf(fp, "%" V8PRIxPTR "-%" V8PRIxPTR, &start, &end) != 2) break;
504
+ if (fscanf(fp, " %c%c%c%c", &attr_r, &attr_w, &attr_x, &attr_p) != 4) break;
505
+
506
+ int c;
507
+ if (attr_r == 'r' && attr_w != 'w' && attr_x == 'x') {
508
+ // Found a read-only executable entry. Skip characters until we reach
509
+ // the beginning of the filename or the end of the line.
510
+ do {
511
+ c = getc(fp);
512
+ } while ((c != EOF) && (c != '\n') && (c != '/'));
513
+ if (c == EOF) break; // EOF: Was unexpected, just exit.
514
+
515
+ // Process the filename if found.
516
+ if (c == '/') {
517
+ ungetc(c, fp); // Push the '/' back into the stream to be read below.
518
+
519
+ // Read to the end of the line. Exit if the read fails.
520
+ if (fgets(lib_name, kLibNameLen, fp) == NULL) break;
521
+
522
+ // Drop the newline character read by fgets. We do not need to check
523
+ // for a zero-length string because we know that we at least read the
524
+ // '/' character.
525
+ lib_name[strlen(lib_name) - 1] = '\0';
526
+ } else {
527
+ // No library name found, just record the raw address range.
528
+ snprintf(lib_name, kLibNameLen,
529
+ "%08" V8PRIxPTR "-%08" V8PRIxPTR, start, end);
530
+ }
531
+ LOG(isolate, SharedLibraryEvent(lib_name, start, end));
532
+ } else {
533
+ // Entry not describing executable data. Skip to end of line to setup
534
+ // reading the next entry.
535
+ do {
536
+ c = getc(fp);
537
+ } while ((c != EOF) && (c != '\n'));
538
+ if (c == EOF) break;
539
+ }
540
+ }
541
+ free(lib_name);
542
+ fclose(fp);
543
+ #endif
544
+ }
545
+
546
+
547
+ static const char kGCFakeMmap[] = "/tmp/__v8_gc__";
548
+
549
+
550
+ void OS::SignalCodeMovingGC() {
551
+ #ifdef ENABLE_LOGGING_AND_PROFILING
552
+ // Support for ll_prof.py.
553
+ //
554
+ // The Linux profiler built into the kernel logs all mmap's with
555
+ // PROT_EXEC so that analysis tools can properly attribute ticks. We
556
+ // do a mmap with a name known by ll_prof.py and immediately munmap
557
+ // it. This injects a GC marker into the stream of events generated
558
+ // by the kernel and allows us to synchronize V8 code log and the
559
+ // kernel log.
560
+ int size = sysconf(_SC_PAGESIZE);
561
+ FILE* f = fopen(kGCFakeMmap, "w+");
562
+ void* addr = mmap(NULL, size, PROT_READ | PROT_EXEC, MAP_PRIVATE,
563
+ fileno(f), 0);
564
+ ASSERT(addr != MAP_FAILED);
565
+ munmap(addr, size);
566
+ fclose(f);
567
+ #endif
568
+ }
569
+
570
+
571
+ int OS::StackWalk(Vector<OS::StackFrame> frames) {
572
+ // backtrace is a glibc extension.
573
+ #ifdef __GLIBC__
574
+ int frames_size = frames.length();
575
+ ScopedVector<void*> addresses(frames_size);
576
+
577
+ int frames_count = backtrace(addresses.start(), frames_size);
578
+
579
+ char** symbols = backtrace_symbols(addresses.start(), frames_count);
580
+ if (symbols == NULL) {
581
+ return kStackWalkError;
582
+ }
583
+
584
+ for (int i = 0; i < frames_count; i++) {
585
+ frames[i].address = addresses[i];
586
+ // Format a text representation of the frame based on the information
587
+ // available.
588
+ SNPrintF(MutableCStrVector(frames[i].text, kStackWalkMaxTextLen),
589
+ "%s",
590
+ symbols[i]);
591
+ // Make sure line termination is in place.
592
+ frames[i].text[kStackWalkMaxTextLen - 1] = '\0';
593
+ }
594
+
595
+ free(symbols);
596
+
597
+ return frames_count;
598
+ #else // ndef __GLIBC__
599
+ return 0;
600
+ #endif // ndef __GLIBC__
601
+ }
602
+
603
+
604
+ // Constants used for mmap.
605
+ static const int kMmapFd = -1;
606
+ static const int kMmapFdOffset = 0;
607
+
608
+
609
+ VirtualMemory::VirtualMemory(size_t size) {
610
+ address_ = mmap(NULL, size, PROT_NONE,
611
+ MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE,
612
+ kMmapFd, kMmapFdOffset);
613
+ size_ = size;
614
+ }
615
+
616
+
617
+ VirtualMemory::~VirtualMemory() {
618
+ if (IsReserved()) {
619
+ if (0 == munmap(address(), size())) address_ = MAP_FAILED;
620
+ }
621
+ }
622
+
623
+
624
+ bool VirtualMemory::IsReserved() {
625
+ return address_ != MAP_FAILED;
626
+ }
627
+
628
+
629
+ bool VirtualMemory::Commit(void* address, size_t size, bool is_executable) {
630
+ int prot = PROT_READ | PROT_WRITE | (is_executable ? PROT_EXEC : 0);
631
+ if (MAP_FAILED == mmap(address, size, prot,
632
+ MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED,
633
+ kMmapFd, kMmapFdOffset)) {
634
+ return false;
635
+ }
636
+
637
+ UpdateAllocatedSpaceLimits(address, size);
638
+ return true;
639
+ }
640
+
641
+
642
+ bool VirtualMemory::Uncommit(void* address, size_t size) {
643
+ return mmap(address, size, PROT_NONE,
644
+ MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE | MAP_FIXED,
645
+ kMmapFd, kMmapFdOffset) != MAP_FAILED;
646
+ }
647
+
648
+
649
+ class Thread::PlatformData : public Malloced {
650
+ public:
651
+ PlatformData() : thread_(kNoThread) {}
652
+
653
+ pthread_t thread_; // Thread handle for pthread.
654
+ };
655
+
656
+ Thread::Thread(Isolate* isolate, const Options& options)
657
+ : data_(new PlatformData()),
658
+ isolate_(isolate),
659
+ stack_size_(options.stack_size) {
660
+ set_name(options.name);
661
+ }
662
+
663
+
664
+ Thread::Thread(Isolate* isolate, const char* name)
665
+ : data_(new PlatformData()),
666
+ isolate_(isolate),
667
+ stack_size_(0) {
668
+ set_name(name);
669
+ }
670
+
671
+
672
+ Thread::~Thread() {
673
+ delete data_;
674
+ }
675
+
676
+
677
+ static void* ThreadEntry(void* arg) {
678
+ Thread* thread = reinterpret_cast<Thread*>(arg);
679
+ // This is also initialized by the first argument to pthread_create() but we
680
+ // don't know which thread will run first (the original thread or the new
681
+ // one) so we initialize it here too.
682
+ prctl(PR_SET_NAME,
683
+ reinterpret_cast<unsigned long>(thread->name()), // NOLINT
684
+ 0, 0, 0);
685
+ thread->data()->thread_ = pthread_self();
686
+ ASSERT(thread->data()->thread_ != kNoThread);
687
+ Thread::SetThreadLocal(Isolate::isolate_key(), thread->isolate());
688
+ thread->Run();
689
+ return NULL;
690
+ }
691
+
692
+
693
+ void Thread::set_name(const char* name) {
694
+ strncpy(name_, name, sizeof(name_));
695
+ name_[sizeof(name_) - 1] = '\0';
696
+ }
697
+
698
+
699
+ void Thread::Start() {
700
+ pthread_attr_t* attr_ptr = NULL;
701
+ pthread_attr_t attr;
702
+ if (stack_size_ > 0) {
703
+ pthread_attr_init(&attr);
704
+ pthread_attr_setstacksize(&attr, static_cast<size_t>(stack_size_));
705
+ attr_ptr = &attr;
706
+ }
707
+ pthread_create(&data_->thread_, attr_ptr, ThreadEntry, this);
708
+ ASSERT(data_->thread_ != kNoThread);
709
+ }
710
+
711
+
712
+ void Thread::Join() {
713
+ pthread_join(data_->thread_, NULL);
714
+ }
715
+
716
+
717
+ Thread::LocalStorageKey Thread::CreateThreadLocalKey() {
718
+ pthread_key_t key;
719
+ int result = pthread_key_create(&key, NULL);
720
+ USE(result);
721
+ ASSERT(result == 0);
722
+ return static_cast<LocalStorageKey>(key);
723
+ }
724
+
725
+
726
+ void Thread::DeleteThreadLocalKey(LocalStorageKey key) {
727
+ pthread_key_t pthread_key = static_cast<pthread_key_t>(key);
728
+ int result = pthread_key_delete(pthread_key);
729
+ USE(result);
730
+ ASSERT(result == 0);
731
+ }
732
+
733
+
734
+ void* Thread::GetThreadLocal(LocalStorageKey key) {
735
+ pthread_key_t pthread_key = static_cast<pthread_key_t>(key);
736
+ return pthread_getspecific(pthread_key);
737
+ }
738
+
739
+
740
+ void Thread::SetThreadLocal(LocalStorageKey key, void* value) {
741
+ pthread_key_t pthread_key = static_cast<pthread_key_t>(key);
742
+ pthread_setspecific(pthread_key, value);
743
+ }
744
+
745
+
746
+ void Thread::YieldCPU() {
747
+ sched_yield();
748
+ }
749
+
750
+
751
+ class LinuxMutex : public Mutex {
752
+ public:
753
+
754
+ LinuxMutex() {
755
+ pthread_mutexattr_t attrs;
756
+ int result = pthread_mutexattr_init(&attrs);
757
+ ASSERT(result == 0);
758
+ result = pthread_mutexattr_settype(&attrs, PTHREAD_MUTEX_RECURSIVE);
759
+ ASSERT(result == 0);
760
+ result = pthread_mutex_init(&mutex_, &attrs);
761
+ ASSERT(result == 0);
762
+ }
763
+
764
+ virtual ~LinuxMutex() { pthread_mutex_destroy(&mutex_); }
765
+
766
+ virtual int Lock() {
767
+ int result = pthread_mutex_lock(&mutex_);
768
+ return result;
769
+ }
770
+
771
+ virtual int Unlock() {
772
+ int result = pthread_mutex_unlock(&mutex_);
773
+ return result;
774
+ }
775
+
776
+ virtual bool TryLock() {
777
+ int result = pthread_mutex_trylock(&mutex_);
778
+ // Return false if the lock is busy and locking failed.
779
+ if (result == EBUSY) {
780
+ return false;
781
+ }
782
+ ASSERT(result == 0); // Verify no other errors.
783
+ return true;
784
+ }
785
+
786
+ private:
787
+ pthread_mutex_t mutex_; // Pthread mutex for POSIX platforms.
788
+ };
789
+
790
+
791
+ Mutex* OS::CreateMutex() {
792
+ return new LinuxMutex();
793
+ }
794
+
795
+
796
+ class LinuxSemaphore : public Semaphore {
797
+ public:
798
+ explicit LinuxSemaphore(int count) { sem_init(&sem_, 0, count); }
799
+ virtual ~LinuxSemaphore() { sem_destroy(&sem_); }
800
+
801
+ virtual void Wait();
802
+ virtual bool Wait(int timeout);
803
+ virtual void Signal() { sem_post(&sem_); }
804
+ private:
805
+ sem_t sem_;
806
+ };
807
+
808
+
809
+ void LinuxSemaphore::Wait() {
810
+ while (true) {
811
+ int result = sem_wait(&sem_);
812
+ if (result == 0) return; // Successfully got semaphore.
813
+ CHECK(result == -1 && errno == EINTR); // Signal caused spurious wakeup.
814
+ }
815
+ }
816
+
817
+
818
+ #ifndef TIMEVAL_TO_TIMESPEC
819
+ #define TIMEVAL_TO_TIMESPEC(tv, ts) do { \
820
+ (ts)->tv_sec = (tv)->tv_sec; \
821
+ (ts)->tv_nsec = (tv)->tv_usec * 1000; \
822
+ } while (false)
823
+ #endif
824
+
825
+
826
+ bool LinuxSemaphore::Wait(int timeout) {
827
+ const long kOneSecondMicros = 1000000; // NOLINT
828
+
829
+ // Split timeout into second and nanosecond parts.
830
+ struct timeval delta;
831
+ delta.tv_usec = timeout % kOneSecondMicros;
832
+ delta.tv_sec = timeout / kOneSecondMicros;
833
+
834
+ struct timeval current_time;
835
+ // Get the current time.
836
+ if (gettimeofday(&current_time, NULL) == -1) {
837
+ return false;
838
+ }
839
+
840
+ // Calculate time for end of timeout.
841
+ struct timeval end_time;
842
+ timeradd(&current_time, &delta, &end_time);
843
+
844
+ struct timespec ts;
845
+ TIMEVAL_TO_TIMESPEC(&end_time, &ts);
846
+ // Wait for semaphore signalled or timeout.
847
+ while (true) {
848
+ int result = sem_timedwait(&sem_, &ts);
849
+ if (result == 0) return true; // Successfully got semaphore.
850
+ if (result > 0) {
851
+ // For glibc prior to 2.3.4 sem_timedwait returns the error instead of -1.
852
+ errno = result;
853
+ result = -1;
854
+ }
855
+ if (result == -1 && errno == ETIMEDOUT) return false; // Timeout.
856
+ CHECK(result == -1 && errno == EINTR); // Signal caused spurious wakeup.
857
+ }
858
+ }
859
+
860
+
861
+ Semaphore* OS::CreateSemaphore(int count) {
862
+ return new LinuxSemaphore(count);
863
+ }
864
+
865
+
866
+ #ifdef ENABLE_LOGGING_AND_PROFILING
867
+
868
+ #if !defined(__GLIBC__) && (defined(__arm__) || defined(__thumb__))
869
+ // Android runs a fairly new Linux kernel, so signal info is there,
870
+ // but the C library doesn't have the structs defined.
871
+
872
+ struct sigcontext {
873
+ uint32_t trap_no;
874
+ uint32_t error_code;
875
+ uint32_t oldmask;
876
+ uint32_t gregs[16];
877
+ uint32_t arm_cpsr;
878
+ uint32_t fault_address;
879
+ };
880
+ typedef uint32_t __sigset_t;
881
+ typedef struct sigcontext mcontext_t;
882
+ typedef struct ucontext {
883
+ uint32_t uc_flags;
884
+ struct ucontext* uc_link;
885
+ stack_t uc_stack;
886
+ mcontext_t uc_mcontext;
887
+ __sigset_t uc_sigmask;
888
+ } ucontext_t;
889
+ enum ArmRegisters {R15 = 15, R13 = 13, R11 = 11};
890
+
891
+ #endif
892
+
893
+
894
+ static int GetThreadID() {
895
+ // Glibc doesn't provide a wrapper for gettid(2).
896
+ #if defined(ANDROID)
897
+ return syscall(__NR_gettid);
898
+ #else
899
+ return syscall(SYS_gettid);
900
+ #endif
901
+ }
902
+
903
+
904
+ static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) {
905
+ #ifndef V8_HOST_ARCH_MIPS
906
+ USE(info);
907
+ if (signal != SIGPROF) return;
908
+ Isolate* isolate = Isolate::UncheckedCurrent();
909
+ if (isolate == NULL || !isolate->IsInitialized() || !isolate->IsInUse()) {
910
+ // We require a fully initialized and entered isolate.
911
+ return;
912
+ }
913
+ if (v8::Locker::IsActive() &&
914
+ !isolate->thread_manager()->IsLockedByCurrentThread()) {
915
+ return;
916
+ }
917
+
918
+ Sampler* sampler = isolate->logger()->sampler();
919
+ if (sampler == NULL || !sampler->IsActive()) return;
920
+
921
+ TickSample sample_obj;
922
+ TickSample* sample = CpuProfiler::TickSampleEvent(isolate);
923
+ if (sample == NULL) sample = &sample_obj;
924
+
925
+ // Extracting the sample from the context is extremely machine dependent.
926
+ ucontext_t* ucontext = reinterpret_cast<ucontext_t*>(context);
927
+ mcontext_t& mcontext = ucontext->uc_mcontext;
928
+ sample->state = isolate->current_vm_state();
929
+ #if V8_HOST_ARCH_IA32
930
+ sample->pc = reinterpret_cast<Address>(mcontext.gregs[REG_EIP]);
931
+ sample->sp = reinterpret_cast<Address>(mcontext.gregs[REG_ESP]);
932
+ sample->fp = reinterpret_cast<Address>(mcontext.gregs[REG_EBP]);
933
+ #elif V8_HOST_ARCH_X64
934
+ sample->pc = reinterpret_cast<Address>(mcontext.gregs[REG_RIP]);
935
+ sample->sp = reinterpret_cast<Address>(mcontext.gregs[REG_RSP]);
936
+ sample->fp = reinterpret_cast<Address>(mcontext.gregs[REG_RBP]);
937
+ #elif V8_HOST_ARCH_ARM
938
+ // An undefined macro evaluates to 0, so this applies to Android's Bionic also.
939
+ #if (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ <= 3))
940
+ sample->pc = reinterpret_cast<Address>(mcontext.gregs[R15]);
941
+ sample->sp = reinterpret_cast<Address>(mcontext.gregs[R13]);
942
+ sample->fp = reinterpret_cast<Address>(mcontext.gregs[R11]);
943
+ #else
944
+ sample->pc = reinterpret_cast<Address>(mcontext.arm_pc);
945
+ sample->sp = reinterpret_cast<Address>(mcontext.arm_sp);
946
+ sample->fp = reinterpret_cast<Address>(mcontext.arm_fp);
947
+ #endif
948
+ #elif V8_HOST_ARCH_MIPS
949
+ sample.pc = reinterpret_cast<Address>(mcontext.pc);
950
+ sample.sp = reinterpret_cast<Address>(mcontext.gregs[29]);
951
+ sample.fp = reinterpret_cast<Address>(mcontext.gregs[30]);
952
+ #endif
953
+ sampler->SampleStack(sample);
954
+ sampler->Tick(sample);
955
+ #endif
956
+ }
957
+
958
+
959
+ class Sampler::PlatformData : public Malloced {
960
+ public:
961
+ PlatformData() : vm_tid_(GetThreadID()) {}
962
+
963
+ int vm_tid() const { return vm_tid_; }
964
+
965
+ private:
966
+ const int vm_tid_;
967
+ };
968
+
969
+
970
+ class SignalSender : public Thread {
971
+ public:
972
+ enum SleepInterval {
973
+ HALF_INTERVAL,
974
+ FULL_INTERVAL
975
+ };
976
+
977
+ explicit SignalSender(int interval)
978
+ : Thread(NULL, "SignalSender"),
979
+ vm_tgid_(getpid()),
980
+ interval_(interval) {}
981
+
982
+ static void AddActiveSampler(Sampler* sampler) {
983
+ ScopedLock lock(mutex_);
984
+ SamplerRegistry::AddActiveSampler(sampler);
985
+ if (instance_ == NULL) {
986
+ // Install a signal handler.
987
+ struct sigaction sa;
988
+ sa.sa_sigaction = ProfilerSignalHandler;
989
+ sigemptyset(&sa.sa_mask);
990
+ sa.sa_flags = SA_RESTART | SA_SIGINFO;
991
+ signal_handler_installed_ =
992
+ (sigaction(SIGPROF, &sa, &old_signal_handler_) == 0);
993
+
994
+ // Start a thread that sends SIGPROF signal to VM threads.
995
+ instance_ = new SignalSender(sampler->interval());
996
+ instance_->Start();
997
+ } else {
998
+ ASSERT(instance_->interval_ == sampler->interval());
999
+ }
1000
+ }
1001
+
1002
+ static void RemoveActiveSampler(Sampler* sampler) {
1003
+ ScopedLock lock(mutex_);
1004
+ SamplerRegistry::RemoveActiveSampler(sampler);
1005
+ if (SamplerRegistry::GetState() == SamplerRegistry::HAS_NO_SAMPLERS) {
1006
+ RuntimeProfiler::WakeUpRuntimeProfilerThreadBeforeShutdown();
1007
+ instance_->Join();
1008
+ delete instance_;
1009
+ instance_ = NULL;
1010
+
1011
+ // Restore the old signal handler.
1012
+ if (signal_handler_installed_) {
1013
+ sigaction(SIGPROF, &old_signal_handler_, 0);
1014
+ signal_handler_installed_ = false;
1015
+ }
1016
+ }
1017
+ }
1018
+
1019
+ // Implement Thread::Run().
1020
+ virtual void Run() {
1021
+ SamplerRegistry::State state;
1022
+ while ((state = SamplerRegistry::GetState()) !=
1023
+ SamplerRegistry::HAS_NO_SAMPLERS) {
1024
+ bool cpu_profiling_enabled =
1025
+ (state == SamplerRegistry::HAS_CPU_PROFILING_SAMPLERS);
1026
+ bool runtime_profiler_enabled = RuntimeProfiler::IsEnabled();
1027
+ // When CPU profiling is enabled both JavaScript and C++ code is
1028
+ // profiled. We must not suspend.
1029
+ if (!cpu_profiling_enabled) {
1030
+ if (rate_limiter_.SuspendIfNecessary()) continue;
1031
+ }
1032
+ if (cpu_profiling_enabled && runtime_profiler_enabled) {
1033
+ if (!SamplerRegistry::IterateActiveSamplers(&DoCpuProfile, this)) {
1034
+ return;
1035
+ }
1036
+ Sleep(HALF_INTERVAL);
1037
+ if (!SamplerRegistry::IterateActiveSamplers(&DoRuntimeProfile, NULL)) {
1038
+ return;
1039
+ }
1040
+ Sleep(HALF_INTERVAL);
1041
+ } else {
1042
+ if (cpu_profiling_enabled) {
1043
+ if (!SamplerRegistry::IterateActiveSamplers(&DoCpuProfile,
1044
+ this)) {
1045
+ return;
1046
+ }
1047
+ }
1048
+ if (runtime_profiler_enabled) {
1049
+ if (!SamplerRegistry::IterateActiveSamplers(&DoRuntimeProfile,
1050
+ NULL)) {
1051
+ return;
1052
+ }
1053
+ }
1054
+ Sleep(FULL_INTERVAL);
1055
+ }
1056
+ }
1057
+ }
1058
+
1059
+ static void DoCpuProfile(Sampler* sampler, void* raw_sender) {
1060
+ if (!sampler->IsProfiling()) return;
1061
+ SignalSender* sender = reinterpret_cast<SignalSender*>(raw_sender);
1062
+ sender->SendProfilingSignal(sampler->platform_data()->vm_tid());
1063
+ }
1064
+
1065
+ static void DoRuntimeProfile(Sampler* sampler, void* ignored) {
1066
+ if (!sampler->isolate()->IsInitialized()) return;
1067
+ sampler->isolate()->runtime_profiler()->NotifyTick();
1068
+ }
1069
+
1070
+ void SendProfilingSignal(int tid) {
1071
+ if (!signal_handler_installed_) return;
1072
+ // Glibc doesn't provide a wrapper for tgkill(2).
1073
+ #if defined(ANDROID)
1074
+ syscall(__NR_tgkill, vm_tgid_, tid, SIGPROF);
1075
+ #else
1076
+ syscall(SYS_tgkill, vm_tgid_, tid, SIGPROF);
1077
+ #endif
1078
+ }
1079
+
1080
+ void Sleep(SleepInterval full_or_half) {
1081
+ // Convert ms to us and subtract 100 us to compensate delays
1082
+ // occuring during signal delivery.
1083
+ useconds_t interval = interval_ * 1000 - 100;
1084
+ if (full_or_half == HALF_INTERVAL) interval /= 2;
1085
+ int result = usleep(interval);
1086
+ #ifdef DEBUG
1087
+ if (result != 0 && errno != EINTR) {
1088
+ fprintf(stderr,
1089
+ "SignalSender usleep error; interval = %u, errno = %d\n",
1090
+ interval,
1091
+ errno);
1092
+ ASSERT(result == 0 || errno == EINTR);
1093
+ }
1094
+ #endif
1095
+ USE(result);
1096
+ }
1097
+
1098
+ const int vm_tgid_;
1099
+ const int interval_;
1100
+ RuntimeProfilerRateLimiter rate_limiter_;
1101
+
1102
+ // Protects the process wide state below.
1103
+ static Mutex* mutex_;
1104
+ static SignalSender* instance_;
1105
+ static bool signal_handler_installed_;
1106
+ static struct sigaction old_signal_handler_;
1107
+
1108
+ DISALLOW_COPY_AND_ASSIGN(SignalSender);
1109
+ };
1110
+
1111
+
1112
+ Mutex* SignalSender::mutex_ = OS::CreateMutex();
1113
+ SignalSender* SignalSender::instance_ = NULL;
1114
+ struct sigaction SignalSender::old_signal_handler_;
1115
+ bool SignalSender::signal_handler_installed_ = false;
1116
+
1117
+
1118
+ Sampler::Sampler(Isolate* isolate, int interval)
1119
+ : isolate_(isolate),
1120
+ interval_(interval),
1121
+ profiling_(false),
1122
+ active_(false),
1123
+ samples_taken_(0) {
1124
+ data_ = new PlatformData;
1125
+ }
1126
+
1127
+
1128
+ Sampler::~Sampler() {
1129
+ ASSERT(!IsActive());
1130
+ delete data_;
1131
+ }
1132
+
1133
+
1134
+ void Sampler::Start() {
1135
+ ASSERT(!IsActive());
1136
+ SetActive(true);
1137
+ SignalSender::AddActiveSampler(this);
1138
+ }
1139
+
1140
+
1141
+ void Sampler::Stop() {
1142
+ ASSERT(IsActive());
1143
+ SignalSender::RemoveActiveSampler(this);
1144
+ SetActive(false);
1145
+ }
1146
+
1147
+ #endif // ENABLE_LOGGING_AND_PROFILING
1148
+
1149
+ } } // namespace v8::internal