mustang 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (560) hide show
  1. data/.rspec +1 -0
  2. data/Isolate +9 -0
  3. data/README.md +6 -12
  4. data/Rakefile +30 -4
  5. data/TODO.md +9 -0
  6. data/ext/v8/extconf.rb +56 -0
  7. data/ext/v8/v8.cpp +37 -0
  8. data/ext/v8/v8_array.cpp +161 -0
  9. data/ext/v8/v8_array.h +17 -0
  10. data/ext/v8/v8_base.cpp +147 -0
  11. data/ext/v8/v8_base.h +23 -0
  12. data/ext/v8/v8_cast.cpp +151 -0
  13. data/ext/v8/v8_cast.h +64 -0
  14. data/ext/v8/v8_context.cpp +174 -0
  15. data/ext/v8/v8_context.h +12 -0
  16. data/ext/v8/v8_date.cpp +61 -0
  17. data/ext/v8/v8_date.h +16 -0
  18. data/ext/v8/v8_errors.cpp +147 -0
  19. data/ext/v8/v8_errors.h +19 -0
  20. data/ext/v8/v8_external.cpp +66 -0
  21. data/ext/v8/v8_external.h +16 -0
  22. data/ext/v8/v8_function.cpp +182 -0
  23. data/ext/v8/v8_function.h +14 -0
  24. data/ext/v8/v8_integer.cpp +70 -0
  25. data/ext/v8/v8_integer.h +16 -0
  26. data/ext/v8/v8_macros.h +30 -0
  27. data/ext/v8/v8_main.cpp +53 -0
  28. data/ext/v8/v8_main.h +13 -0
  29. data/ext/v8/v8_number.cpp +62 -0
  30. data/ext/v8/v8_number.h +16 -0
  31. data/ext/v8/v8_object.cpp +172 -0
  32. data/ext/v8/v8_object.h +17 -0
  33. data/ext/v8/v8_ref.cpp +72 -0
  34. data/ext/v8/v8_ref.h +43 -0
  35. data/ext/v8/v8_regexp.cpp +148 -0
  36. data/ext/v8/v8_regexp.h +16 -0
  37. data/ext/v8/v8_string.cpp +78 -0
  38. data/ext/v8/v8_string.h +16 -0
  39. data/ext/v8/v8_value.cpp +370 -0
  40. data/ext/v8/v8_value.h +19 -0
  41. data/gemspec.yml +2 -1
  42. data/lib/core_ext/class.rb +14 -0
  43. data/lib/core_ext/object.rb +12 -0
  44. data/lib/core_ext/symbol.rb +23 -0
  45. data/lib/mustang.rb +44 -0
  46. data/lib/mustang/context.rb +69 -0
  47. data/lib/mustang/errors.rb +36 -0
  48. data/lib/support/delegated.rb +25 -0
  49. data/lib/v8/array.rb +21 -0
  50. data/lib/v8/context.rb +13 -0
  51. data/lib/v8/date.rb +20 -0
  52. data/lib/v8/error.rb +15 -0
  53. data/lib/v8/external.rb +16 -0
  54. data/lib/v8/function.rb +11 -0
  55. data/lib/v8/integer.rb +16 -0
  56. data/lib/v8/number.rb +16 -0
  57. data/lib/v8/object.rb +66 -0
  58. data/lib/v8/regexp.rb +23 -0
  59. data/lib/v8/string.rb +27 -0
  60. data/mustang.gemspec +3 -0
  61. data/spec/core_ext/class_spec.rb +19 -0
  62. data/spec/core_ext/object_spec.rb +19 -0
  63. data/spec/core_ext/symbol_spec.rb +27 -0
  64. data/spec/fixtures/test1.js +2 -0
  65. data/spec/fixtures/test2.js +2 -0
  66. data/spec/spec_helper.rb +20 -0
  67. data/spec/v8/array_spec.rb +88 -0
  68. data/spec/v8/cast_spec.rb +151 -0
  69. data/spec/v8/context_spec.rb +78 -0
  70. data/spec/v8/data_spec.rb +39 -0
  71. data/spec/v8/date_spec.rb +45 -0
  72. data/spec/v8/empty_spec.rb +27 -0
  73. data/spec/v8/errors_spec.rb +142 -0
  74. data/spec/v8/external_spec.rb +44 -0
  75. data/spec/v8/function_spec.rb +170 -0
  76. data/spec/v8/integer_spec.rb +41 -0
  77. data/spec/v8/main_spec.rb +18 -0
  78. data/spec/v8/null_spec.rb +27 -0
  79. data/spec/v8/number_spec.rb +40 -0
  80. data/spec/v8/object_spec.rb +79 -0
  81. data/spec/v8/primitive_spec.rb +9 -0
  82. data/spec/v8/regexp_spec.rb +65 -0
  83. data/spec/v8/string_spec.rb +48 -0
  84. data/spec/v8/undefined_spec.rb +27 -0
  85. data/spec/v8/value_spec.rb +215 -0
  86. data/vendor/v8/.gitignore +2 -0
  87. data/vendor/v8/AUTHORS +3 -1
  88. data/vendor/v8/ChangeLog +117 -0
  89. data/vendor/v8/SConstruct +334 -53
  90. data/vendor/v8/include/v8-debug.h +21 -11
  91. data/vendor/v8/include/v8-preparser.h +1 -1
  92. data/vendor/v8/include/v8-profiler.h +122 -43
  93. data/vendor/v8/include/v8-testing.h +5 -0
  94. data/vendor/v8/include/v8.h +171 -17
  95. data/vendor/v8/preparser/SConscript +38 -0
  96. data/vendor/v8/preparser/preparser-process.cc +77 -114
  97. data/vendor/v8/samples/shell.cc +232 -46
  98. data/vendor/v8/src/SConscript +29 -5
  99. data/vendor/v8/src/accessors.cc +70 -211
  100. data/vendor/v8/{test/cctest/test-mips.cc → src/allocation-inl.h} +15 -18
  101. data/vendor/v8/src/allocation.cc +0 -82
  102. data/vendor/v8/src/allocation.h +9 -42
  103. data/vendor/v8/src/api.cc +1645 -1156
  104. data/vendor/v8/src/api.h +76 -12
  105. data/vendor/v8/src/apiutils.h +0 -7
  106. data/vendor/v8/src/arguments.h +15 -4
  107. data/vendor/v8/src/arm/assembler-arm-inl.h +10 -9
  108. data/vendor/v8/src/arm/assembler-arm.cc +62 -23
  109. data/vendor/v8/src/arm/assembler-arm.h +76 -11
  110. data/vendor/v8/src/arm/builtins-arm.cc +39 -33
  111. data/vendor/v8/src/arm/code-stubs-arm.cc +1182 -402
  112. data/vendor/v8/src/arm/code-stubs-arm.h +20 -54
  113. data/vendor/v8/src/arm/codegen-arm.cc +159 -106
  114. data/vendor/v8/src/arm/codegen-arm.h +6 -6
  115. data/vendor/v8/src/arm/constants-arm.h +16 -1
  116. data/vendor/v8/src/arm/cpu-arm.cc +7 -5
  117. data/vendor/v8/src/arm/debug-arm.cc +6 -4
  118. data/vendor/v8/src/arm/deoptimizer-arm.cc +51 -14
  119. data/vendor/v8/src/arm/disasm-arm.cc +47 -15
  120. data/vendor/v8/src/arm/frames-arm.h +1 -1
  121. data/vendor/v8/src/arm/full-codegen-arm.cc +724 -408
  122. data/vendor/v8/src/arm/ic-arm.cc +90 -85
  123. data/vendor/v8/src/arm/lithium-arm.cc +140 -69
  124. data/vendor/v8/src/arm/lithium-arm.h +161 -46
  125. data/vendor/v8/src/arm/lithium-codegen-arm.cc +567 -297
  126. data/vendor/v8/src/arm/lithium-codegen-arm.h +21 -9
  127. data/vendor/v8/src/arm/lithium-gap-resolver-arm.cc +2 -0
  128. data/vendor/v8/src/arm/macro-assembler-arm.cc +457 -96
  129. data/vendor/v8/src/arm/macro-assembler-arm.h +115 -18
  130. data/vendor/v8/src/arm/regexp-macro-assembler-arm.cc +20 -13
  131. data/vendor/v8/src/arm/regexp-macro-assembler-arm.h +1 -0
  132. data/vendor/v8/src/arm/simulator-arm.cc +184 -101
  133. data/vendor/v8/src/arm/simulator-arm.h +26 -21
  134. data/vendor/v8/src/arm/stub-cache-arm.cc +450 -467
  135. data/vendor/v8/src/arm/virtual-frame-arm.cc +14 -12
  136. data/vendor/v8/src/arm/virtual-frame-arm.h +11 -8
  137. data/vendor/v8/src/array.js +35 -18
  138. data/vendor/v8/src/assembler.cc +186 -92
  139. data/vendor/v8/src/assembler.h +106 -69
  140. data/vendor/v8/src/ast-inl.h +5 -0
  141. data/vendor/v8/src/ast.cc +46 -35
  142. data/vendor/v8/src/ast.h +107 -50
  143. data/vendor/v8/src/atomicops.h +2 -0
  144. data/vendor/v8/src/atomicops_internals_mips_gcc.h +169 -0
  145. data/vendor/v8/src/bootstrapper.cc +649 -399
  146. data/vendor/v8/src/bootstrapper.h +94 -27
  147. data/vendor/v8/src/builtins.cc +359 -227
  148. data/vendor/v8/src/builtins.h +157 -123
  149. data/vendor/v8/src/checks.cc +2 -2
  150. data/vendor/v8/src/checks.h +4 -0
  151. data/vendor/v8/src/code-stubs.cc +27 -17
  152. data/vendor/v8/src/code-stubs.h +38 -17
  153. data/vendor/v8/src/codegen-inl.h +5 -1
  154. data/vendor/v8/src/codegen.cc +27 -17
  155. data/vendor/v8/src/codegen.h +9 -9
  156. data/vendor/v8/src/compilation-cache.cc +92 -206
  157. data/vendor/v8/src/compilation-cache.h +205 -30
  158. data/vendor/v8/src/compiler.cc +107 -120
  159. data/vendor/v8/src/compiler.h +17 -2
  160. data/vendor/v8/src/contexts.cc +22 -15
  161. data/vendor/v8/src/contexts.h +14 -8
  162. data/vendor/v8/src/conversions.cc +86 -30
  163. data/vendor/v8/src/counters.cc +19 -4
  164. data/vendor/v8/src/counters.h +28 -16
  165. data/vendor/v8/src/cpu-profiler-inl.h +4 -3
  166. data/vendor/v8/src/cpu-profiler.cc +123 -72
  167. data/vendor/v8/src/cpu-profiler.h +33 -19
  168. data/vendor/v8/src/cpu.h +2 -0
  169. data/vendor/v8/src/d8-debug.cc +3 -3
  170. data/vendor/v8/src/d8-debug.h +7 -6
  171. data/vendor/v8/src/d8-posix.cc +2 -0
  172. data/vendor/v8/src/d8.cc +22 -12
  173. data/vendor/v8/src/d8.gyp +3 -0
  174. data/vendor/v8/src/d8.js +618 -0
  175. data/vendor/v8/src/data-flow.h +3 -3
  176. data/vendor/v8/src/dateparser.h +4 -2
  177. data/vendor/v8/src/debug-agent.cc +10 -9
  178. data/vendor/v8/src/debug-agent.h +9 -11
  179. data/vendor/v8/src/debug-debugger.js +121 -0
  180. data/vendor/v8/src/debug.cc +331 -227
  181. data/vendor/v8/src/debug.h +248 -219
  182. data/vendor/v8/src/deoptimizer.cc +173 -62
  183. data/vendor/v8/src/deoptimizer.h +119 -19
  184. data/vendor/v8/src/disasm.h +3 -0
  185. data/vendor/v8/src/disassembler.cc +10 -9
  186. data/vendor/v8/src/execution.cc +185 -129
  187. data/vendor/v8/src/execution.h +47 -78
  188. data/vendor/v8/src/extensions/experimental/break-iterator.cc +250 -0
  189. data/vendor/v8/src/extensions/experimental/break-iterator.h +89 -0
  190. data/vendor/v8/src/extensions/experimental/experimental.gyp +2 -0
  191. data/vendor/v8/src/extensions/experimental/i18n-extension.cc +22 -2
  192. data/vendor/v8/src/extensions/externalize-string-extension.cc +2 -2
  193. data/vendor/v8/src/extensions/gc-extension.cc +1 -1
  194. data/vendor/v8/src/factory.cc +261 -154
  195. data/vendor/v8/src/factory.h +162 -158
  196. data/vendor/v8/src/flag-definitions.h +17 -11
  197. data/vendor/v8/src/frame-element.cc +0 -5
  198. data/vendor/v8/src/frame-element.h +9 -13
  199. data/vendor/v8/src/frames-inl.h +7 -0
  200. data/vendor/v8/src/frames.cc +56 -46
  201. data/vendor/v8/src/frames.h +36 -25
  202. data/vendor/v8/src/full-codegen.cc +15 -24
  203. data/vendor/v8/src/full-codegen.h +13 -41
  204. data/vendor/v8/src/func-name-inferrer.cc +7 -6
  205. data/vendor/v8/src/func-name-inferrer.h +1 -1
  206. data/vendor/v8/src/gdb-jit.cc +1 -0
  207. data/vendor/v8/src/global-handles.cc +118 -56
  208. data/vendor/v8/src/global-handles.h +98 -40
  209. data/vendor/v8/src/globals.h +2 -2
  210. data/vendor/v8/src/handles-inl.h +106 -9
  211. data/vendor/v8/src/handles.cc +220 -157
  212. data/vendor/v8/src/handles.h +38 -59
  213. data/vendor/v8/src/hashmap.h +3 -3
  214. data/vendor/v8/src/heap-inl.h +141 -25
  215. data/vendor/v8/src/heap-profiler.cc +117 -63
  216. data/vendor/v8/src/heap-profiler.h +38 -21
  217. data/vendor/v8/src/heap.cc +805 -564
  218. data/vendor/v8/src/heap.h +640 -594
  219. data/vendor/v8/src/hydrogen-instructions.cc +216 -73
  220. data/vendor/v8/src/hydrogen-instructions.h +259 -124
  221. data/vendor/v8/src/hydrogen.cc +996 -1171
  222. data/vendor/v8/src/hydrogen.h +163 -144
  223. data/vendor/v8/src/ia32/assembler-ia32-inl.h +12 -11
  224. data/vendor/v8/src/ia32/assembler-ia32.cc +85 -39
  225. data/vendor/v8/src/ia32/assembler-ia32.h +82 -16
  226. data/vendor/v8/src/ia32/builtins-ia32.cc +64 -58
  227. data/vendor/v8/src/ia32/code-stubs-ia32.cc +248 -324
  228. data/vendor/v8/src/ia32/code-stubs-ia32.h +3 -44
  229. data/vendor/v8/src/ia32/codegen-ia32.cc +217 -165
  230. data/vendor/v8/src/ia32/codegen-ia32.h +3 -0
  231. data/vendor/v8/src/ia32/cpu-ia32.cc +6 -5
  232. data/vendor/v8/src/ia32/debug-ia32.cc +8 -5
  233. data/vendor/v8/src/ia32/deoptimizer-ia32.cc +124 -14
  234. data/vendor/v8/src/ia32/disasm-ia32.cc +85 -62
  235. data/vendor/v8/src/ia32/frames-ia32.h +1 -1
  236. data/vendor/v8/src/ia32/full-codegen-ia32.cc +348 -435
  237. data/vendor/v8/src/ia32/ic-ia32.cc +91 -91
  238. data/vendor/v8/src/ia32/lithium-codegen-ia32.cc +500 -255
  239. data/vendor/v8/src/ia32/lithium-codegen-ia32.h +13 -4
  240. data/vendor/v8/src/ia32/lithium-gap-resolver-ia32.cc +6 -0
  241. data/vendor/v8/src/ia32/lithium-ia32.cc +122 -45
  242. data/vendor/v8/src/ia32/lithium-ia32.h +128 -41
  243. data/vendor/v8/src/ia32/macro-assembler-ia32.cc +109 -84
  244. data/vendor/v8/src/ia32/macro-assembler-ia32.h +18 -9
  245. data/vendor/v8/src/ia32/regexp-macro-assembler-ia32.cc +26 -15
  246. data/vendor/v8/src/ia32/regexp-macro-assembler-ia32.h +1 -0
  247. data/vendor/v8/src/ia32/register-allocator-ia32.cc +30 -30
  248. data/vendor/v8/src/ia32/simulator-ia32.h +4 -4
  249. data/vendor/v8/src/ia32/stub-cache-ia32.cc +383 -400
  250. data/vendor/v8/src/ia32/virtual-frame-ia32.cc +36 -13
  251. data/vendor/v8/src/ia32/virtual-frame-ia32.h +11 -5
  252. data/vendor/v8/src/ic-inl.h +12 -2
  253. data/vendor/v8/src/ic.cc +304 -221
  254. data/vendor/v8/src/ic.h +115 -58
  255. data/vendor/v8/src/interpreter-irregexp.cc +25 -21
  256. data/vendor/v8/src/interpreter-irregexp.h +2 -1
  257. data/vendor/v8/src/isolate.cc +883 -0
  258. data/vendor/v8/src/isolate.h +1304 -0
  259. data/vendor/v8/src/json.js +10 -10
  260. data/vendor/v8/src/jsregexp.cc +111 -80
  261. data/vendor/v8/src/jsregexp.h +6 -7
  262. data/vendor/v8/src/jump-target-heavy.cc +5 -8
  263. data/vendor/v8/src/jump-target-heavy.h +0 -6
  264. data/vendor/v8/src/jump-target-inl.h +1 -1
  265. data/vendor/v8/src/jump-target-light.cc +3 -3
  266. data/vendor/v8/src/lithium-allocator-inl.h +2 -0
  267. data/vendor/v8/src/lithium-allocator.cc +42 -30
  268. data/vendor/v8/src/lithium-allocator.h +8 -22
  269. data/vendor/v8/src/lithium.cc +1 -0
  270. data/vendor/v8/src/liveedit.cc +141 -99
  271. data/vendor/v8/src/liveedit.h +7 -2
  272. data/vendor/v8/src/liveobjectlist-inl.h +90 -0
  273. data/vendor/v8/src/liveobjectlist.cc +2537 -1
  274. data/vendor/v8/src/liveobjectlist.h +245 -35
  275. data/vendor/v8/src/log-utils.cc +122 -35
  276. data/vendor/v8/src/log-utils.h +33 -36
  277. data/vendor/v8/src/log.cc +299 -241
  278. data/vendor/v8/src/log.h +177 -110
  279. data/vendor/v8/src/mark-compact.cc +612 -470
  280. data/vendor/v8/src/mark-compact.h +153 -80
  281. data/vendor/v8/src/messages.cc +16 -14
  282. data/vendor/v8/src/messages.js +30 -7
  283. data/vendor/v8/src/mips/assembler-mips-inl.h +155 -35
  284. data/vendor/v8/src/mips/assembler-mips.cc +1093 -219
  285. data/vendor/v8/src/mips/assembler-mips.h +552 -153
  286. data/vendor/v8/src/mips/builtins-mips.cc +43 -100
  287. data/vendor/v8/src/mips/code-stubs-mips.cc +752 -0
  288. data/vendor/v8/src/mips/code-stubs-mips.h +511 -0
  289. data/vendor/v8/src/mips/codegen-mips-inl.h +8 -14
  290. data/vendor/v8/src/mips/codegen-mips.cc +672 -896
  291. data/vendor/v8/src/mips/codegen-mips.h +271 -69
  292. data/vendor/v8/src/mips/constants-mips.cc +44 -20
  293. data/vendor/v8/src/mips/constants-mips.h +238 -40
  294. data/vendor/v8/src/mips/cpu-mips.cc +20 -3
  295. data/vendor/v8/src/mips/debug-mips.cc +35 -7
  296. data/vendor/v8/src/mips/deoptimizer-mips.cc +91 -0
  297. data/vendor/v8/src/mips/disasm-mips.cc +329 -93
  298. data/vendor/v8/src/mips/frames-mips.cc +2 -50
  299. data/vendor/v8/src/mips/frames-mips.h +24 -9
  300. data/vendor/v8/src/mips/full-codegen-mips.cc +473 -23
  301. data/vendor/v8/src/mips/ic-mips.cc +81 -45
  302. data/vendor/v8/src/mips/jump-target-mips.cc +11 -106
  303. data/vendor/v8/src/mips/lithium-codegen-mips.h +65 -0
  304. data/vendor/v8/src/mips/lithium-mips.h +304 -0
  305. data/vendor/v8/src/mips/macro-assembler-mips.cc +2391 -390
  306. data/vendor/v8/src/mips/macro-assembler-mips.h +718 -121
  307. data/vendor/v8/src/mips/regexp-macro-assembler-mips.cc +478 -0
  308. data/vendor/v8/src/mips/regexp-macro-assembler-mips.h +250 -0
  309. data/vendor/v8/src/mips/register-allocator-mips-inl.h +0 -3
  310. data/vendor/v8/src/mips/register-allocator-mips.h +3 -2
  311. data/vendor/v8/src/mips/simulator-mips.cc +1009 -221
  312. data/vendor/v8/src/mips/simulator-mips.h +119 -36
  313. data/vendor/v8/src/mips/stub-cache-mips.cc +331 -148
  314. data/vendor/v8/src/mips/{fast-codegen-mips.cc → virtual-frame-mips-inl.h} +11 -30
  315. data/vendor/v8/src/mips/virtual-frame-mips.cc +137 -149
  316. data/vendor/v8/src/mips/virtual-frame-mips.h +294 -312
  317. data/vendor/v8/src/mirror-debugger.js +9 -8
  318. data/vendor/v8/src/mksnapshot.cc +2 -2
  319. data/vendor/v8/src/objects-debug.cc +16 -16
  320. data/vendor/v8/src/objects-inl.h +421 -195
  321. data/vendor/v8/src/objects-printer.cc +7 -7
  322. data/vendor/v8/src/objects-visiting.cc +1 -1
  323. data/vendor/v8/src/objects-visiting.h +33 -12
  324. data/vendor/v8/src/objects.cc +935 -658
  325. data/vendor/v8/src/objects.h +234 -139
  326. data/vendor/v8/src/parser.cc +484 -439
  327. data/vendor/v8/src/parser.h +35 -14
  328. data/vendor/v8/src/platform-cygwin.cc +173 -107
  329. data/vendor/v8/src/platform-freebsd.cc +224 -72
  330. data/vendor/v8/src/platform-linux.cc +234 -95
  331. data/vendor/v8/src/platform-macos.cc +215 -82
  332. data/vendor/v8/src/platform-nullos.cc +9 -3
  333. data/vendor/v8/src/platform-openbsd.cc +22 -7
  334. data/vendor/v8/src/platform-posix.cc +30 -5
  335. data/vendor/v8/src/platform-solaris.cc +120 -38
  336. data/vendor/v8/src/platform-tls-mac.h +62 -0
  337. data/vendor/v8/src/platform-tls-win32.h +62 -0
  338. data/vendor/v8/src/platform-tls.h +50 -0
  339. data/vendor/v8/src/platform-win32.cc +195 -97
  340. data/vendor/v8/src/platform.h +72 -15
  341. data/vendor/v8/src/preparse-data.cc +2 -0
  342. data/vendor/v8/src/preparser-api.cc +8 -2
  343. data/vendor/v8/src/preparser.cc +1 -1
  344. data/vendor/v8/src/prettyprinter.cc +43 -52
  345. data/vendor/v8/src/prettyprinter.h +1 -1
  346. data/vendor/v8/src/profile-generator-inl.h +0 -28
  347. data/vendor/v8/src/profile-generator.cc +942 -685
  348. data/vendor/v8/src/profile-generator.h +210 -176
  349. data/vendor/v8/src/property.cc +6 -0
  350. data/vendor/v8/src/property.h +14 -3
  351. data/vendor/v8/src/regexp-macro-assembler-irregexp.cc +1 -1
  352. data/vendor/v8/src/regexp-macro-assembler.cc +28 -19
  353. data/vendor/v8/src/regexp-macro-assembler.h +11 -6
  354. data/vendor/v8/src/regexp-stack.cc +18 -10
  355. data/vendor/v8/src/regexp-stack.h +45 -21
  356. data/vendor/v8/src/regexp.js +3 -3
  357. data/vendor/v8/src/register-allocator-inl.h +3 -3
  358. data/vendor/v8/src/register-allocator.cc +1 -7
  359. data/vendor/v8/src/register-allocator.h +5 -15
  360. data/vendor/v8/src/rewriter.cc +2 -1
  361. data/vendor/v8/src/runtime-profiler.cc +158 -128
  362. data/vendor/v8/src/runtime-profiler.h +131 -15
  363. data/vendor/v8/src/runtime.cc +2409 -1692
  364. data/vendor/v8/src/runtime.h +93 -17
  365. data/vendor/v8/src/safepoint-table.cc +3 -0
  366. data/vendor/v8/src/safepoint-table.h +9 -3
  367. data/vendor/v8/src/scanner-base.cc +21 -28
  368. data/vendor/v8/src/scanner-base.h +22 -11
  369. data/vendor/v8/src/scanner.cc +3 -5
  370. data/vendor/v8/src/scanner.h +4 -2
  371. data/vendor/v8/src/scopeinfo.cc +11 -16
  372. data/vendor/v8/src/scopeinfo.h +26 -15
  373. data/vendor/v8/src/scopes.cc +67 -37
  374. data/vendor/v8/src/scopes.h +26 -12
  375. data/vendor/v8/src/serialize.cc +193 -154
  376. data/vendor/v8/src/serialize.h +41 -36
  377. data/vendor/v8/src/small-pointer-list.h +163 -0
  378. data/vendor/v8/src/snapshot-common.cc +1 -1
  379. data/vendor/v8/src/snapshot.h +3 -1
  380. data/vendor/v8/src/spaces-inl.h +30 -25
  381. data/vendor/v8/src/spaces.cc +263 -370
  382. data/vendor/v8/src/spaces.h +178 -166
  383. data/vendor/v8/src/string-search.cc +4 -3
  384. data/vendor/v8/src/string-search.h +21 -20
  385. data/vendor/v8/src/string-stream.cc +32 -24
  386. data/vendor/v8/src/string.js +7 -7
  387. data/vendor/v8/src/stub-cache.cc +324 -248
  388. data/vendor/v8/src/stub-cache.h +181 -155
  389. data/vendor/v8/src/token.cc +3 -3
  390. data/vendor/v8/src/token.h +3 -3
  391. data/vendor/v8/src/top.cc +218 -390
  392. data/vendor/v8/src/type-info.cc +98 -32
  393. data/vendor/v8/src/type-info.h +10 -3
  394. data/vendor/v8/src/unicode.cc +1 -1
  395. data/vendor/v8/src/unicode.h +1 -1
  396. data/vendor/v8/src/utils.h +3 -0
  397. data/vendor/v8/src/v8-counters.cc +18 -11
  398. data/vendor/v8/src/v8-counters.h +34 -13
  399. data/vendor/v8/src/v8.cc +66 -121
  400. data/vendor/v8/src/v8.h +7 -4
  401. data/vendor/v8/src/v8globals.h +18 -12
  402. data/vendor/v8/src/{memory.h → v8memory.h} +0 -0
  403. data/vendor/v8/src/v8natives.js +59 -18
  404. data/vendor/v8/src/v8threads.cc +127 -114
  405. data/vendor/v8/src/v8threads.h +42 -35
  406. data/vendor/v8/src/v8utils.h +2 -39
  407. data/vendor/v8/src/variables.h +1 -1
  408. data/vendor/v8/src/version.cc +26 -5
  409. data/vendor/v8/src/version.h +4 -0
  410. data/vendor/v8/src/virtual-frame-heavy-inl.h +2 -4
  411. data/vendor/v8/src/virtual-frame-light-inl.h +5 -4
  412. data/vendor/v8/src/vm-state-inl.h +21 -17
  413. data/vendor/v8/src/vm-state.h +7 -5
  414. data/vendor/v8/src/win32-headers.h +1 -0
  415. data/vendor/v8/src/x64/assembler-x64-inl.h +12 -11
  416. data/vendor/v8/src/x64/assembler-x64.cc +80 -40
  417. data/vendor/v8/src/x64/assembler-x64.h +67 -17
  418. data/vendor/v8/src/x64/builtins-x64.cc +34 -33
  419. data/vendor/v8/src/x64/code-stubs-x64.cc +636 -377
  420. data/vendor/v8/src/x64/code-stubs-x64.h +14 -48
  421. data/vendor/v8/src/x64/codegen-x64-inl.h +1 -1
  422. data/vendor/v8/src/x64/codegen-x64.cc +158 -136
  423. data/vendor/v8/src/x64/codegen-x64.h +4 -1
  424. data/vendor/v8/src/x64/cpu-x64.cc +7 -5
  425. data/vendor/v8/src/x64/debug-x64.cc +8 -6
  426. data/vendor/v8/src/x64/deoptimizer-x64.cc +195 -20
  427. data/vendor/v8/src/x64/disasm-x64.cc +42 -23
  428. data/vendor/v8/src/x64/frames-x64.cc +1 -1
  429. data/vendor/v8/src/x64/frames-x64.h +2 -2
  430. data/vendor/v8/src/x64/full-codegen-x64.cc +780 -218
  431. data/vendor/v8/src/x64/ic-x64.cc +77 -79
  432. data/vendor/v8/src/x64/jump-target-x64.cc +1 -1
  433. data/vendor/v8/src/x64/lithium-codegen-x64.cc +698 -181
  434. data/vendor/v8/src/x64/lithium-codegen-x64.h +31 -6
  435. data/vendor/v8/src/x64/lithium-x64.cc +136 -54
  436. data/vendor/v8/src/x64/lithium-x64.h +142 -51
  437. data/vendor/v8/src/x64/macro-assembler-x64.cc +456 -187
  438. data/vendor/v8/src/x64/macro-assembler-x64.h +166 -34
  439. data/vendor/v8/src/x64/regexp-macro-assembler-x64.cc +44 -28
  440. data/vendor/v8/src/x64/regexp-macro-assembler-x64.h +8 -4
  441. data/vendor/v8/src/x64/register-allocator-x64-inl.h +3 -3
  442. data/vendor/v8/src/x64/register-allocator-x64.cc +12 -8
  443. data/vendor/v8/src/x64/simulator-x64.h +5 -5
  444. data/vendor/v8/src/x64/stub-cache-x64.cc +299 -344
  445. data/vendor/v8/src/x64/virtual-frame-x64.cc +37 -13
  446. data/vendor/v8/src/x64/virtual-frame-x64.h +13 -7
  447. data/vendor/v8/src/zone-inl.h +49 -3
  448. data/vendor/v8/src/zone.cc +42 -41
  449. data/vendor/v8/src/zone.h +37 -34
  450. data/vendor/v8/test/benchmarks/testcfg.py +100 -0
  451. data/vendor/v8/test/cctest/SConscript +5 -4
  452. data/vendor/v8/test/cctest/cctest.h +3 -2
  453. data/vendor/v8/test/cctest/cctest.status +6 -11
  454. data/vendor/v8/test/cctest/test-accessors.cc +3 -3
  455. data/vendor/v8/test/cctest/test-alloc.cc +39 -33
  456. data/vendor/v8/test/cctest/test-api.cc +1092 -205
  457. data/vendor/v8/test/cctest/test-assembler-arm.cc +39 -25
  458. data/vendor/v8/test/cctest/test-assembler-ia32.cc +36 -37
  459. data/vendor/v8/test/cctest/test-assembler-mips.cc +1098 -40
  460. data/vendor/v8/test/cctest/test-assembler-x64.cc +32 -25
  461. data/vendor/v8/test/cctest/test-ast.cc +1 -0
  462. data/vendor/v8/test/cctest/test-circular-queue.cc +8 -5
  463. data/vendor/v8/test/cctest/test-compiler.cc +24 -24
  464. data/vendor/v8/test/cctest/test-cpu-profiler.cc +140 -5
  465. data/vendor/v8/test/cctest/test-dataflow.cc +1 -0
  466. data/vendor/v8/test/cctest/test-debug.cc +136 -77
  467. data/vendor/v8/test/cctest/test-decls.cc +1 -1
  468. data/vendor/v8/test/cctest/test-deoptimization.cc +25 -24
  469. data/vendor/v8/test/cctest/test-disasm-arm.cc +9 -4
  470. data/vendor/v8/test/cctest/test-disasm-ia32.cc +10 -8
  471. data/vendor/v8/test/cctest/test-func-name-inference.cc +10 -4
  472. data/vendor/v8/test/cctest/test-heap-profiler.cc +226 -164
  473. data/vendor/v8/test/cctest/test-heap.cc +240 -217
  474. data/vendor/v8/test/cctest/test-liveedit.cc +1 -0
  475. data/vendor/v8/test/cctest/test-log-stack-tracer.cc +18 -20
  476. data/vendor/v8/test/cctest/test-log.cc +114 -108
  477. data/vendor/v8/test/cctest/test-macro-assembler-x64.cc +247 -177
  478. data/vendor/v8/test/cctest/test-mark-compact.cc +129 -90
  479. data/vendor/v8/test/cctest/test-parsing.cc +15 -14
  480. data/vendor/v8/test/cctest/test-platform-linux.cc +1 -0
  481. data/vendor/v8/test/cctest/test-platform-tls.cc +66 -0
  482. data/vendor/v8/test/cctest/test-platform-win32.cc +1 -0
  483. data/vendor/v8/test/cctest/test-profile-generator.cc +1 -1
  484. data/vendor/v8/test/cctest/test-regexp.cc +53 -41
  485. data/vendor/v8/test/cctest/test-reloc-info.cc +18 -11
  486. data/vendor/v8/test/cctest/test-serialize.cc +44 -43
  487. data/vendor/v8/test/cctest/test-sockets.cc +8 -3
  488. data/vendor/v8/test/cctest/test-spaces.cc +47 -29
  489. data/vendor/v8/test/cctest/test-strings.cc +20 -20
  490. data/vendor/v8/test/cctest/test-thread-termination.cc +8 -3
  491. data/vendor/v8/test/cctest/test-threads.cc +5 -3
  492. data/vendor/v8/test/cctest/test-utils.cc +5 -4
  493. data/vendor/v8/test/cctest/testcfg.py +7 -3
  494. data/vendor/v8/test/es5conform/es5conform.status +2 -77
  495. data/vendor/v8/test/es5conform/testcfg.py +1 -1
  496. data/vendor/v8/test/message/testcfg.py +1 -1
  497. data/vendor/v8/test/mjsunit/accessors-on-global-object.js +3 -3
  498. data/vendor/v8/test/mjsunit/array-concat.js +43 -1
  499. data/vendor/v8/test/mjsunit/array-join.js +25 -0
  500. data/vendor/v8/test/mjsunit/bitops-info.js +7 -1
  501. data/vendor/v8/test/mjsunit/compiler/array-length.js +2 -2
  502. data/vendor/v8/test/mjsunit/compiler/global-accessors.js +47 -0
  503. data/vendor/v8/test/mjsunit/compiler/pic.js +1 -1
  504. data/vendor/v8/test/mjsunit/compiler/regress-loadfield.js +65 -0
  505. data/vendor/v8/test/mjsunit/math-sqrt.js +5 -1
  506. data/vendor/v8/test/mjsunit/mjsunit.js +59 -8
  507. data/vendor/v8/test/mjsunit/mjsunit.status +0 -12
  508. data/vendor/v8/test/mjsunit/mul-exhaustive.js +129 -11
  509. data/vendor/v8/test/mjsunit/negate-zero.js +1 -1
  510. data/vendor/v8/test/mjsunit/object-freeze.js +5 -13
  511. data/vendor/v8/test/mjsunit/object-prevent-extensions.js +9 -50
  512. data/vendor/v8/test/mjsunit/object-seal.js +4 -13
  513. data/vendor/v8/test/mjsunit/override-eval-with-non-function.js +36 -0
  514. data/vendor/v8/test/mjsunit/regress/regress-1145.js +54 -0
  515. data/vendor/v8/test/mjsunit/regress/regress-1172-bis.js +37 -0
  516. data/vendor/v8/test/mjsunit/regress/regress-1181.js +54 -0
  517. data/vendor/v8/test/mjsunit/regress/regress-1207.js +35 -0
  518. data/vendor/v8/test/mjsunit/regress/regress-1209.js +34 -0
  519. data/vendor/v8/test/mjsunit/regress/regress-1210.js +48 -0
  520. data/vendor/v8/test/mjsunit/regress/regress-1213.js +43 -0
  521. data/vendor/v8/test/mjsunit/regress/regress-1218.js +29 -0
  522. data/vendor/v8/test/mjsunit/regress/regress-1229.js +79 -0
  523. data/vendor/v8/test/mjsunit/regress/regress-1233.js +47 -0
  524. data/vendor/v8/test/mjsunit/regress/regress-1236.js +34 -0
  525. data/vendor/v8/test/mjsunit/regress/regress-1237.js +36 -0
  526. data/vendor/v8/test/mjsunit/regress/regress-1240.js +39 -0
  527. data/vendor/v8/test/mjsunit/regress/regress-1257.js +58 -0
  528. data/vendor/v8/test/mjsunit/regress/regress-1278.js +69 -0
  529. data/vendor/v8/test/mjsunit/regress/regress-create-exception.js +1 -0
  530. data/vendor/v8/test/mjsunit/regress/regress-lazy-deopt-reloc.js +52 -0
  531. data/vendor/v8/test/mjsunit/sin-cos.js +15 -10
  532. data/vendor/v8/test/mjsunit/smi-negative-zero.js +2 -2
  533. data/vendor/v8/test/mjsunit/str-to-num.js +1 -1
  534. data/vendor/v8/test/mjsunit/strict-mode.js +435 -0
  535. data/vendor/v8/test/mjsunit/testcfg.py +23 -6
  536. data/vendor/v8/test/mozilla/mozilla.status +0 -2
  537. data/vendor/v8/test/mozilla/testcfg.py +1 -1
  538. data/vendor/v8/test/preparser/empty.js +28 -0
  539. data/vendor/v8/test/preparser/functions-only.js +38 -0
  540. data/vendor/v8/test/preparser/non-alphanum.js +34 -0
  541. data/vendor/v8/test/preparser/symbols-only.js +49 -0
  542. data/vendor/v8/test/preparser/testcfg.py +90 -0
  543. data/vendor/v8/test/sputnik/testcfg.py +1 -1
  544. data/vendor/v8/test/test262/README +16 -0
  545. data/vendor/v8/test/test262/harness-adapt.js +80 -0
  546. data/vendor/v8/test/test262/test262.status +1506 -0
  547. data/vendor/v8/test/test262/testcfg.py +123 -0
  548. data/vendor/v8/tools/freebsd-tick-processor +10 -0
  549. data/vendor/v8/tools/gyp/v8.gyp +8 -33
  550. data/vendor/v8/tools/linux-tick-processor +5 -3
  551. data/vendor/v8/tools/test.py +37 -14
  552. data/vendor/v8/tools/tickprocessor.js +22 -8
  553. data/vendor/v8/tools/visual_studio/v8_base.vcproj +13 -1
  554. data/vendor/v8/tools/visual_studio/v8_base_arm.vcproj +5 -1
  555. data/vendor/v8/tools/visual_studio/v8_base_x64.vcproj +5 -1
  556. data/vendor/v8/tools/visual_studio/x64.vsprops +1 -0
  557. metadata +1495 -1341
  558. data/ext/extconf.rb +0 -22
  559. data/ext/mustang.cpp +0 -58
  560. data/vendor/v8/src/top.h +0 -608
@@ -42,6 +42,7 @@
42
42
  #include <sys/stat.h> // open
43
43
  #include <sys/fcntl.h> // open
44
44
  #include <unistd.h> // getpagesize
45
+ // If you don't have execinfo.h then you need devel/libexecinfo from ports.
45
46
  #include <execinfo.h> // backtrace, backtrace_symbols
46
47
  #include <strings.h> // index
47
48
  #include <errno.h>
@@ -74,6 +75,9 @@ double ceiling(double x) {
74
75
  }
75
76
 
76
77
 
78
+ static Mutex* limit_mutex = NULL;
79
+
80
+
77
81
  void OS::Setup() {
78
82
  // Seed the random number generator.
79
83
  // Convert the current time to a 64-bit integer first, before converting it
@@ -82,6 +86,7 @@ void OS::Setup() {
82
86
  // call this setup code within the same millisecond.
83
87
  uint64_t seed = static_cast<uint64_t>(TimeCurrentMillis());
84
88
  srandom(static_cast<unsigned int>(seed));
89
+ limit_mutex = CreateMutex();
85
90
  }
86
91
 
87
92
 
@@ -130,6 +135,9 @@ static void* highest_ever_allocated = reinterpret_cast<void*>(0);
130
135
 
131
136
 
132
137
  static void UpdateAllocatedSpaceLimits(void* address, int size) {
138
+ ASSERT(limit_mutex != NULL);
139
+ ScopedLock lock(limit_mutex);
140
+
133
141
  lowest_ever_allocated = Min(lowest_ever_allocated, address);
134
142
  highest_ever_allocated =
135
143
  Max(highest_ever_allocated,
@@ -155,7 +163,7 @@ void* OS::Allocate(const size_t requested,
155
163
  void* mbase = mmap(NULL, msize, prot, MAP_PRIVATE | MAP_ANON, -1, 0);
156
164
 
157
165
  if (mbase == MAP_FAILED) {
158
- LOG(StringEvent("OS::Allocate", "mmap failed"));
166
+ LOG(ISOLATE, StringEvent("OS::Allocate", "mmap failed"));
159
167
  return NULL;
160
168
  }
161
169
  *allocated = msize;
@@ -299,7 +307,7 @@ void OS::LogSharedLibraryAddresses() {
299
307
  // There may be no filename in this line. Skip to next.
300
308
  if (start_of_path == NULL) continue;
301
309
  buffer[bytes_read] = 0;
302
- LOG(SharedLibraryEvent(start_of_path, start, end));
310
+ LOG(i::Isolate::Current(), SharedLibraryEvent(start_of_path, start, end));
303
311
  }
304
312
  close(fd);
305
313
  #endif
@@ -424,12 +432,18 @@ bool ThreadHandle::IsValid() const {
424
432
  }
425
433
 
426
434
 
427
- Thread::Thread() : ThreadHandle(ThreadHandle::INVALID) {
428
- set_name("v8:<unknown>");
435
+ Thread::Thread(Isolate* isolate, const Options& options)
436
+ : ThreadHandle(ThreadHandle::INVALID),
437
+ isolate_(isolate),
438
+ stack_size_(options.stack_size) {
439
+ set_name(options.name);
429
440
  }
430
441
 
431
442
 
432
- Thread::Thread(const char* name) : ThreadHandle(ThreadHandle::INVALID) {
443
+ Thread::Thread(Isolate* isolate, const char* name)
444
+ : ThreadHandle(ThreadHandle::INVALID),
445
+ isolate_(isolate),
446
+ stack_size_(0) {
433
447
  set_name(name);
434
448
  }
435
449
 
@@ -445,6 +459,7 @@ static void* ThreadEntry(void* arg) {
445
459
  // one) so we initialize it here too.
446
460
  thread->thread_handle_data()->thread_ = pthread_self();
447
461
  ASSERT(thread->IsValid());
462
+ Thread::SetThreadLocal(Isolate::isolate_key(), thread->isolate());
448
463
  thread->Run();
449
464
  return NULL;
450
465
  }
@@ -457,7 +472,14 @@ void Thread::set_name(const char* name) {
457
472
 
458
473
 
459
474
  void Thread::Start() {
460
- pthread_create(&thread_handle_data()->thread_, NULL, ThreadEntry, this);
475
+ pthread_attr_t* attr_ptr = NULL;
476
+ pthread_attr_t attr;
477
+ if (stack_size_ > 0) {
478
+ pthread_attr_init(&attr);
479
+ pthread_attr_setstacksize(&attr, static_cast<size_t>(stack_size_));
480
+ attr_ptr = &attr;
481
+ }
482
+ pthread_create(&thread_handle_data()->thread_, attr_ptr, ThreadEntry, this);
461
483
  ASSERT(IsValid());
462
484
  }
463
485
 
@@ -526,6 +548,16 @@ class FreeBSDMutex : public Mutex {
526
548
  return result;
527
549
  }
528
550
 
551
+ virtual bool TryLock() {
552
+ int result = pthread_mutex_trylock(&mutex_);
553
+ // Return false if the lock is busy and locking failed.
554
+ if (result == EBUSY) {
555
+ return false;
556
+ }
557
+ ASSERT(result == 0); // Verify no other errors.
558
+ return true;
559
+ }
560
+
529
561
  private:
530
562
  pthread_mutex_t mutex_; // Pthread mutex for POSIX platforms.
531
563
  };
@@ -594,107 +626,227 @@ Semaphore* OS::CreateSemaphore(int count) {
594
626
 
595
627
  #ifdef ENABLE_LOGGING_AND_PROFILING
596
628
 
597
- static Sampler* active_sampler_ = NULL;
629
+ static pthread_t GetThreadID() {
630
+ pthread_t thread_id = pthread_self();
631
+ return thread_id;
632
+ }
633
+
634
+
635
+ class Sampler::PlatformData : public Malloced {
636
+ public:
637
+ PlatformData() : vm_tid_(GetThreadID()) {}
638
+
639
+ pthread_t vm_tid() const { return vm_tid_; }
640
+
641
+ private:
642
+ pthread_t vm_tid_;
643
+ };
644
+
598
645
 
599
646
  static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) {
600
647
  USE(info);
601
648
  if (signal != SIGPROF) return;
602
- if (active_sampler_ == NULL) return;
603
-
604
- TickSample sample;
649
+ Isolate* isolate = Isolate::UncheckedCurrent();
650
+ if (isolate == NULL || !isolate->IsInitialized() || !isolate->IsInUse()) {
651
+ // We require a fully initialized and entered isolate.
652
+ return;
653
+ }
654
+ Sampler* sampler = isolate->logger()->sampler();
655
+ if (sampler == NULL || !sampler->IsActive()) return;
605
656
 
606
- // We always sample the VM state.
607
- sample.state = VMState::current_state();
657
+ TickSample sample_obj;
658
+ TickSample* sample = CpuProfiler::TickSampleEvent(isolate);
659
+ if (sample == NULL) sample = &sample_obj;
608
660
 
609
- // If profiling, we extract the current pc and sp.
610
- if (active_sampler_->IsProfiling()) {
611
- // Extracting the sample from the context is extremely machine dependent.
612
- ucontext_t* ucontext = reinterpret_cast<ucontext_t*>(context);
613
- mcontext_t& mcontext = ucontext->uc_mcontext;
661
+ // Extracting the sample from the context is extremely machine dependent.
662
+ ucontext_t* ucontext = reinterpret_cast<ucontext_t*>(context);
663
+ mcontext_t& mcontext = ucontext->uc_mcontext;
664
+ sample->state = isolate->current_vm_state();
614
665
  #if V8_HOST_ARCH_IA32
615
- sample.pc = reinterpret_cast<Address>(mcontext.mc_eip);
616
- sample.sp = reinterpret_cast<Address>(mcontext.mc_esp);
617
- sample.fp = reinterpret_cast<Address>(mcontext.mc_ebp);
666
+ sample->pc = reinterpret_cast<Address>(mcontext.mc_eip);
667
+ sample->sp = reinterpret_cast<Address>(mcontext.mc_esp);
668
+ sample->fp = reinterpret_cast<Address>(mcontext.mc_ebp);
618
669
  #elif V8_HOST_ARCH_X64
619
- sample.pc = reinterpret_cast<Address>(mcontext.mc_rip);
620
- sample.sp = reinterpret_cast<Address>(mcontext.mc_rsp);
621
- sample.fp = reinterpret_cast<Address>(mcontext.mc_rbp);
670
+ sample->pc = reinterpret_cast<Address>(mcontext.mc_rip);
671
+ sample->sp = reinterpret_cast<Address>(mcontext.mc_rsp);
672
+ sample->fp = reinterpret_cast<Address>(mcontext.mc_rbp);
622
673
  #elif V8_HOST_ARCH_ARM
623
- sample.pc = reinterpret_cast<Address>(mcontext.mc_r15);
624
- sample.sp = reinterpret_cast<Address>(mcontext.mc_r13);
625
- sample.fp = reinterpret_cast<Address>(mcontext.mc_r11);
674
+ sample->pc = reinterpret_cast<Address>(mcontext.mc_r15);
675
+ sample->sp = reinterpret_cast<Address>(mcontext.mc_r13);
676
+ sample->fp = reinterpret_cast<Address>(mcontext.mc_r11);
626
677
  #endif
627
- active_sampler_->SampleStack(&sample);
628
- }
629
-
630
- active_sampler_->Tick(&sample);
678
+ sampler->SampleStack(sample);
679
+ sampler->Tick(sample);
631
680
  }
632
681
 
633
682
 
634
- class Sampler::PlatformData : public Malloced {
683
+ class SignalSender : public Thread {
635
684
  public:
636
- PlatformData() {
637
- signal_handler_installed_ = false;
685
+ enum SleepInterval {
686
+ HALF_INTERVAL,
687
+ FULL_INTERVAL
688
+ };
689
+
690
+ explicit SignalSender(int interval)
691
+ : Thread(NULL, "SignalSender"),
692
+ interval_(interval) {}
693
+
694
+ static void AddActiveSampler(Sampler* sampler) {
695
+ ScopedLock lock(mutex_);
696
+ SamplerRegistry::AddActiveSampler(sampler);
697
+ if (instance_ == NULL) {
698
+ // Install a signal handler.
699
+ struct sigaction sa;
700
+ sa.sa_sigaction = ProfilerSignalHandler;
701
+ sigemptyset(&sa.sa_mask);
702
+ sa.sa_flags = SA_RESTART | SA_SIGINFO;
703
+ signal_handler_installed_ =
704
+ (sigaction(SIGPROF, &sa, &old_signal_handler_) == 0);
705
+
706
+ // Start a thread that sends SIGPROF signal to VM threads.
707
+ instance_ = new SignalSender(sampler->interval());
708
+ instance_->Start();
709
+ } else {
710
+ ASSERT(instance_->interval_ == sampler->interval());
711
+ }
638
712
  }
639
713
 
640
- bool signal_handler_installed_;
641
- struct sigaction old_signal_handler_;
642
- struct itimerval old_timer_value_;
714
+ static void RemoveActiveSampler(Sampler* sampler) {
715
+ ScopedLock lock(mutex_);
716
+ SamplerRegistry::RemoveActiveSampler(sampler);
717
+ if (SamplerRegistry::GetState() == SamplerRegistry::HAS_NO_SAMPLERS) {
718
+ RuntimeProfiler::WakeUpRuntimeProfilerThreadBeforeShutdown();
719
+ instance_->Join();
720
+ delete instance_;
721
+ instance_ = NULL;
722
+
723
+ // Restore the old signal handler.
724
+ if (signal_handler_installed_) {
725
+ sigaction(SIGPROF, &old_signal_handler_, 0);
726
+ signal_handler_installed_ = false;
727
+ }
728
+ }
729
+ }
730
+
731
+ // Implement Thread::Run().
732
+ virtual void Run() {
733
+ SamplerRegistry::State state;
734
+ while ((state = SamplerRegistry::GetState()) !=
735
+ SamplerRegistry::HAS_NO_SAMPLERS) {
736
+ bool cpu_profiling_enabled =
737
+ (state == SamplerRegistry::HAS_CPU_PROFILING_SAMPLERS);
738
+ bool runtime_profiler_enabled = RuntimeProfiler::IsEnabled();
739
+ // When CPU profiling is enabled both JavaScript and C++ code is
740
+ // profiled. We must not suspend.
741
+ if (!cpu_profiling_enabled) {
742
+ if (rate_limiter_.SuspendIfNecessary()) continue;
743
+ }
744
+ if (cpu_profiling_enabled && runtime_profiler_enabled) {
745
+ if (!SamplerRegistry::IterateActiveSamplers(&DoCpuProfile, this)) {
746
+ return;
747
+ }
748
+ Sleep(HALF_INTERVAL);
749
+ if (!SamplerRegistry::IterateActiveSamplers(&DoRuntimeProfile, NULL)) {
750
+ return;
751
+ }
752
+ Sleep(HALF_INTERVAL);
753
+ } else {
754
+ if (cpu_profiling_enabled) {
755
+ if (!SamplerRegistry::IterateActiveSamplers(&DoCpuProfile,
756
+ this)) {
757
+ return;
758
+ }
759
+ }
760
+ if (runtime_profiler_enabled) {
761
+ if (!SamplerRegistry::IterateActiveSamplers(&DoRuntimeProfile,
762
+ NULL)) {
763
+ return;
764
+ }
765
+ }
766
+ Sleep(FULL_INTERVAL);
767
+ }
768
+ }
769
+ }
770
+
771
+ static void DoCpuProfile(Sampler* sampler, void* raw_sender) {
772
+ if (!sampler->IsProfiling()) return;
773
+ SignalSender* sender = reinterpret_cast<SignalSender*>(raw_sender);
774
+ sender->SendProfilingSignal(sampler->platform_data()->vm_tid());
775
+ }
776
+
777
+ static void DoRuntimeProfile(Sampler* sampler, void* ignored) {
778
+ if (!sampler->isolate()->IsInitialized()) return;
779
+ sampler->isolate()->runtime_profiler()->NotifyTick();
780
+ }
781
+
782
+ void SendProfilingSignal(pthread_t tid) {
783
+ if (!signal_handler_installed_) return;
784
+ pthread_kill(tid, SIGPROF);
785
+ }
786
+
787
+ void Sleep(SleepInterval full_or_half) {
788
+ // Convert ms to us and subtract 100 us to compensate delays
789
+ // occuring during signal delivery.
790
+ useconds_t interval = interval_ * 1000 - 100;
791
+ if (full_or_half == HALF_INTERVAL) interval /= 2;
792
+ int result = usleep(interval);
793
+ #ifdef DEBUG
794
+ if (result != 0 && errno != EINTR) {
795
+ fprintf(stderr,
796
+ "SignalSender usleep error; interval = %u, errno = %d\n",
797
+ interval,
798
+ errno);
799
+ ASSERT(result == 0 || errno == EINTR);
800
+ }
801
+ #endif
802
+ USE(result);
803
+ }
804
+
805
+ const int interval_;
806
+ RuntimeProfilerRateLimiter rate_limiter_;
807
+
808
+ // Protects the process wide state below.
809
+ static Mutex* mutex_;
810
+ static SignalSender* instance_;
811
+ static bool signal_handler_installed_;
812
+ static struct sigaction old_signal_handler_;
813
+
814
+ DISALLOW_COPY_AND_ASSIGN(SignalSender);
643
815
  };
644
816
 
817
+ Mutex* SignalSender::mutex_ = OS::CreateMutex();
818
+ SignalSender* SignalSender::instance_ = NULL;
819
+ struct sigaction SignalSender::old_signal_handler_;
820
+ bool SignalSender::signal_handler_installed_ = false;
645
821
 
646
- Sampler::Sampler(int interval)
647
- : interval_(interval),
822
+
823
+ Sampler::Sampler(Isolate* isolate, int interval)
824
+ : isolate_(isolate),
825
+ interval_(interval),
648
826
  profiling_(false),
649
827
  active_(false),
650
828
  samples_taken_(0) {
651
- data_ = new PlatformData();
829
+ data_ = new PlatformData;
652
830
  }
653
831
 
654
832
 
655
833
  Sampler::~Sampler() {
834
+ ASSERT(!IsActive());
656
835
  delete data_;
657
836
  }
658
837
 
659
838
 
660
839
  void Sampler::Start() {
661
- // There can only be one active sampler at the time on POSIX
662
- // platforms.
663
- if (active_sampler_ != NULL) return;
664
-
665
- // Request profiling signals.
666
- struct sigaction sa;
667
- sa.sa_sigaction = ProfilerSignalHandler;
668
- sigemptyset(&sa.sa_mask);
669
- sa.sa_flags = SA_SIGINFO;
670
- if (sigaction(SIGPROF, &sa, &data_->old_signal_handler_) != 0) return;
671
- data_->signal_handler_installed_ = true;
672
-
673
- // Set the itimer to generate a tick for each interval.
674
- itimerval itimer;
675
- itimer.it_interval.tv_sec = interval_ / 1000;
676
- itimer.it_interval.tv_usec = (interval_ % 1000) * 1000;
677
- itimer.it_value.tv_sec = itimer.it_interval.tv_sec;
678
- itimer.it_value.tv_usec = itimer.it_interval.tv_usec;
679
- setitimer(ITIMER_PROF, &itimer, &data_->old_timer_value_);
680
-
681
- // Set this sampler as the active sampler.
682
- active_sampler_ = this;
683
- active_ = true;
840
+ ASSERT(!IsActive());
841
+ SetActive(true);
842
+ SignalSender::AddActiveSampler(this);
684
843
  }
685
844
 
686
845
 
687
846
  void Sampler::Stop() {
688
- // Restore old signal handler
689
- if (data_->signal_handler_installed_) {
690
- setitimer(ITIMER_PROF, &data_->old_timer_value_, NULL);
691
- sigaction(SIGPROF, &data_->old_signal_handler_, 0);
692
- data_->signal_handler_installed_ = false;
693
- }
694
-
695
- // This sampler is no longer the active sampler.
696
- active_sampler_ = NULL;
697
- active_ = false;
847
+ ASSERT(IsActive());
848
+ SignalSender::RemoveActiveSampler(this);
849
+ SetActive(false);
698
850
  }
699
851
 
700
852
  #endif // ENABLE_LOGGING_AND_PROFILING
@@ -58,7 +58,6 @@
58
58
  #include "v8.h"
59
59
 
60
60
  #include "platform.h"
61
- #include "top.h"
62
61
  #include "v8threads.h"
63
62
  #include "vm-state-inl.h"
64
63
 
@@ -76,6 +75,9 @@ double ceiling(double x) {
76
75
  }
77
76
 
78
77
 
78
+ static Mutex* limit_mutex = NULL;
79
+
80
+
79
81
  void OS::Setup() {
80
82
  // Seed the random number generator.
81
83
  // Convert the current time to a 64-bit integer first, before converting it
@@ -84,6 +86,7 @@ void OS::Setup() {
84
86
  // call this setup code within the same millisecond.
85
87
  uint64_t seed = static_cast<uint64_t>(TimeCurrentMillis());
86
88
  srandom(static_cast<unsigned int>(seed));
89
+ limit_mutex = CreateMutex();
87
90
  }
88
91
 
89
92
 
@@ -94,6 +97,10 @@ uint64_t OS::CpuFeaturesImpliedByPlatform() {
94
97
  return 1u << VFP3;
95
98
  #elif CAN_USE_ARMV7_INSTRUCTIONS
96
99
  return 1u << ARMv7;
100
+ #elif(defined(__mips_hard_float) && __mips_hard_float != 0)
101
+ // Here gcc is telling us that we are on an MIPS and gcc is assuming that we
102
+ // have FPU instructions. If gcc can assume it then so can we.
103
+ return 1u << FPU;
97
104
  #else
98
105
  return 0; // Linux runs on anything.
99
106
  #endif
@@ -172,6 +179,58 @@ bool OS::ArmCpuHasFeature(CpuFeature feature) {
172
179
  #endif // def __arm__
173
180
 
174
181
 
182
+ #ifdef __mips__
183
+ bool OS::MipsCpuHasFeature(CpuFeature feature) {
184
+ const char* search_string = NULL;
185
+ const char* file_name = "/proc/cpuinfo";
186
+ // Simple detection of FPU at runtime for Linux.
187
+ // It is based on /proc/cpuinfo, which reveals hardware configuration
188
+ // to user-space applications. According to MIPS (early 2010), no similar
189
+ // facility is universally available on the MIPS architectures,
190
+ // so it's up to individual OSes to provide such.
191
+ //
192
+ // This is written as a straight shot one pass parser
193
+ // and not using STL string and ifstream because,
194
+ // on Linux, it's reading from a (non-mmap-able)
195
+ // character special device.
196
+
197
+ switch (feature) {
198
+ case FPU:
199
+ search_string = "FPU";
200
+ break;
201
+ default:
202
+ UNREACHABLE();
203
+ }
204
+
205
+ FILE* f = NULL;
206
+ const char* what = search_string;
207
+
208
+ if (NULL == (f = fopen(file_name, "r")))
209
+ return false;
210
+
211
+ int k;
212
+ while (EOF != (k = fgetc(f))) {
213
+ if (k == *what) {
214
+ ++what;
215
+ while ((*what != '\0') && (*what == fgetc(f))) {
216
+ ++what;
217
+ }
218
+ if (*what == '\0') {
219
+ fclose(f);
220
+ return true;
221
+ } else {
222
+ what = search_string;
223
+ }
224
+ }
225
+ }
226
+ fclose(f);
227
+
228
+ // Did not find string in the proc file.
229
+ return false;
230
+ }
231
+ #endif // def __mips__
232
+
233
+
175
234
  int OS::ActivationFrameAlignment() {
176
235
  #ifdef V8_TARGET_ARCH_ARM
177
236
  // On EABI ARM targets this is required for fp correctness in the
@@ -187,8 +246,9 @@ int OS::ActivationFrameAlignment() {
187
246
 
188
247
 
189
248
  void OS::ReleaseStore(volatile AtomicWord* ptr, AtomicWord value) {
190
- #if defined(V8_TARGET_ARCH_ARM) && defined(__arm__)
191
- // Only use on ARM hardware.
249
+ #if (defined(V8_TARGET_ARCH_ARM) && defined(__arm__)) || \
250
+ (defined(V8_TARGET_ARCH_MIPS) && defined(__mips__))
251
+ // Only use on ARM or MIPS hardware.
192
252
  MemoryBarrier();
193
253
  #else
194
254
  __asm__ __volatile__("" : : : "memory");
@@ -226,6 +286,9 @@ static void* highest_ever_allocated = reinterpret_cast<void*>(0);
226
286
 
227
287
 
228
288
  static void UpdateAllocatedSpaceLimits(void* address, int size) {
289
+ ASSERT(limit_mutex != NULL);
290
+ ScopedLock lock(limit_mutex);
291
+
229
292
  lowest_ever_allocated = Min(lowest_ever_allocated, address);
230
293
  highest_ever_allocated =
231
294
  Max(highest_ever_allocated,
@@ -251,7 +314,8 @@ void* OS::Allocate(const size_t requested,
251
314
  int prot = PROT_READ | PROT_WRITE | (is_executable ? PROT_EXEC : 0);
252
315
  void* mbase = mmap(NULL, msize, prot, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
253
316
  if (mbase == MAP_FAILED) {
254
- LOG(StringEvent("OS::Allocate", "mmap failed"));
317
+ LOG(i::Isolate::Current(),
318
+ StringEvent("OS::Allocate", "mmap failed"));
255
319
  return NULL;
256
320
  }
257
321
  *allocated = msize;
@@ -372,6 +436,7 @@ void OS::LogSharedLibraryAddresses() {
372
436
  const int kLibNameLen = FILENAME_MAX + 1;
373
437
  char* lib_name = reinterpret_cast<char*>(malloc(kLibNameLen));
374
438
 
439
+ i::Isolate* isolate = ISOLATE;
375
440
  // This loop will terminate once the scanning hits an EOF.
376
441
  while (true) {
377
442
  uintptr_t start, end;
@@ -405,7 +470,7 @@ void OS::LogSharedLibraryAddresses() {
405
470
  snprintf(lib_name, kLibNameLen,
406
471
  "%08" V8PRIxPTR "-%08" V8PRIxPTR, start, end);
407
472
  }
408
- LOG(SharedLibraryEvent(lib_name, start, end));
473
+ LOG(isolate, SharedLibraryEvent(lib_name, start, end));
409
474
  } else {
410
475
  // Entry not describing executable data. Skip to end of line to setup
411
476
  // reading the next entry.
@@ -565,12 +630,18 @@ bool ThreadHandle::IsValid() const {
565
630
  }
566
631
 
567
632
 
568
- Thread::Thread() : ThreadHandle(ThreadHandle::INVALID) {
569
- set_name("v8:<unknown>");
633
+ Thread::Thread(Isolate* isolate, const Options& options)
634
+ : ThreadHandle(ThreadHandle::INVALID),
635
+ isolate_(isolate),
636
+ stack_size_(options.stack_size) {
637
+ set_name(options.name);
570
638
  }
571
639
 
572
640
 
573
- Thread::Thread(const char* name) : ThreadHandle(ThreadHandle::INVALID) {
641
+ Thread::Thread(Isolate* isolate, const char* name)
642
+ : ThreadHandle(ThreadHandle::INVALID),
643
+ isolate_(isolate),
644
+ stack_size_(0) {
574
645
  set_name(name);
575
646
  }
576
647
 
@@ -584,9 +655,12 @@ static void* ThreadEntry(void* arg) {
584
655
  // This is also initialized by the first argument to pthread_create() but we
585
656
  // don't know which thread will run first (the original thread or the new
586
657
  // one) so we initialize it here too.
587
- prctl(PR_SET_NAME, thread->name(), 0, 0, 0);
658
+ prctl(PR_SET_NAME,
659
+ reinterpret_cast<unsigned long>(thread->name()), // NOLINT
660
+ 0, 0, 0);
588
661
  thread->thread_handle_data()->thread_ = pthread_self();
589
662
  ASSERT(thread->IsValid());
663
+ Thread::SetThreadLocal(Isolate::isolate_key(), thread->isolate());
590
664
  thread->Run();
591
665
  return NULL;
592
666
  }
@@ -599,7 +673,14 @@ void Thread::set_name(const char* name) {
599
673
 
600
674
 
601
675
  void Thread::Start() {
602
- pthread_create(&thread_handle_data()->thread_, NULL, ThreadEntry, this);
676
+ pthread_attr_t* attr_ptr = NULL;
677
+ pthread_attr_t attr;
678
+ if (stack_size_ > 0) {
679
+ pthread_attr_init(&attr);
680
+ pthread_attr_setstacksize(&attr, static_cast<size_t>(stack_size_));
681
+ attr_ptr = &attr;
682
+ }
683
+ pthread_create(&thread_handle_data()->thread_, attr_ptr, ThreadEntry, this);
603
684
  ASSERT(IsValid());
604
685
  }
605
686
 
@@ -760,10 +841,6 @@ Semaphore* OS::CreateSemaphore(int count) {
760
841
 
761
842
  #ifdef ENABLE_LOGGING_AND_PROFILING
762
843
 
763
- static Sampler* active_sampler_ = NULL;
764
- static int vm_tid_ = 0;
765
-
766
-
767
844
  #if !defined(__GLIBC__) && (defined(__arm__) || defined(__thumb__))
768
845
  // Android runs a fairly new Linux kernel, so signal info is there,
769
846
  // but the C library doesn't have the structs defined.
@@ -792,7 +869,11 @@ enum ArmRegisters {R15 = 15, R13 = 13, R11 = 11};
792
869
 
793
870
  static int GetThreadID() {
794
871
  // Glibc doesn't provide a wrapper for gettid(2).
872
+ #if defined(ANDROID)
873
+ return syscall(__NR_gettid);
874
+ #else
795
875
  return syscall(SYS_gettid);
876
+ #endif
796
877
  }
797
878
 
798
879
 
@@ -800,17 +881,22 @@ static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) {
800
881
  #ifndef V8_HOST_ARCH_MIPS
801
882
  USE(info);
802
883
  if (signal != SIGPROF) return;
803
- if (active_sampler_ == NULL || !active_sampler_->IsActive()) return;
804
- if (vm_tid_ != GetThreadID()) return;
884
+ Isolate* isolate = Isolate::UncheckedCurrent();
885
+ if (isolate == NULL || !isolate->IsInitialized() || !isolate->IsInUse()) {
886
+ // We require a fully initialized and entered isolate.
887
+ return;
888
+ }
889
+ Sampler* sampler = isolate->logger()->sampler();
890
+ if (sampler == NULL || !sampler->IsActive()) return;
805
891
 
806
892
  TickSample sample_obj;
807
- TickSample* sample = CpuProfiler::TickSampleEvent();
893
+ TickSample* sample = CpuProfiler::TickSampleEvent(isolate);
808
894
  if (sample == NULL) sample = &sample_obj;
809
895
 
810
896
  // Extracting the sample from the context is extremely machine dependent.
811
897
  ucontext_t* ucontext = reinterpret_cast<ucontext_t*>(context);
812
898
  mcontext_t& mcontext = ucontext->uc_mcontext;
813
- sample->state = Top::current_vm_state();
899
+ sample->state = isolate->current_vm_state();
814
900
  #if V8_HOST_ARCH_IA32
815
901
  sample->pc = reinterpret_cast<Address>(mcontext.gregs[REG_EIP]);
816
902
  sample->sp = reinterpret_cast<Address>(mcontext.gregs[REG_ESP]);
@@ -831,54 +917,141 @@ static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) {
831
917
  sample->fp = reinterpret_cast<Address>(mcontext.arm_fp);
832
918
  #endif
833
919
  #elif V8_HOST_ARCH_MIPS
834
- // Implement this on MIPS.
835
- UNIMPLEMENTED();
920
+ sample.pc = reinterpret_cast<Address>(mcontext.pc);
921
+ sample.sp = reinterpret_cast<Address>(mcontext.gregs[29]);
922
+ sample.fp = reinterpret_cast<Address>(mcontext.gregs[30]);
836
923
  #endif
837
- active_sampler_->SampleStack(sample);
838
- active_sampler_->Tick(sample);
924
+ sampler->SampleStack(sample);
925
+ sampler->Tick(sample);
839
926
  #endif
840
927
  }
841
928
 
842
929
 
843
930
  class Sampler::PlatformData : public Malloced {
931
+ public:
932
+ PlatformData() : vm_tid_(GetThreadID()) {}
933
+
934
+ int vm_tid() const { return vm_tid_; }
935
+
936
+ private:
937
+ const int vm_tid_;
938
+ };
939
+
940
+
941
+ class SignalSender : public Thread {
844
942
  public:
845
943
  enum SleepInterval {
846
- FULL_INTERVAL,
847
- HALF_INTERVAL
944
+ HALF_INTERVAL,
945
+ FULL_INTERVAL
848
946
  };
849
947
 
850
- explicit PlatformData(Sampler* sampler)
851
- : sampler_(sampler),
852
- signal_handler_installed_(false),
948
+ explicit SignalSender(int interval)
949
+ : Thread(NULL, "SignalSender"),
853
950
  vm_tgid_(getpid()),
854
- signal_sender_launched_(false) {
951
+ interval_(interval) {}
952
+
953
+ static void AddActiveSampler(Sampler* sampler) {
954
+ ScopedLock lock(mutex_);
955
+ SamplerRegistry::AddActiveSampler(sampler);
956
+ if (instance_ == NULL) {
957
+ // Install a signal handler.
958
+ struct sigaction sa;
959
+ sa.sa_sigaction = ProfilerSignalHandler;
960
+ sigemptyset(&sa.sa_mask);
961
+ sa.sa_flags = SA_RESTART | SA_SIGINFO;
962
+ signal_handler_installed_ =
963
+ (sigaction(SIGPROF, &sa, &old_signal_handler_) == 0);
964
+
965
+ // Start a thread that sends SIGPROF signal to VM threads.
966
+ instance_ = new SignalSender(sampler->interval());
967
+ instance_->Start();
968
+ } else {
969
+ ASSERT(instance_->interval_ == sampler->interval());
970
+ }
855
971
  }
856
972
 
857
- void SignalSender() {
858
- while (sampler_->IsActive()) {
859
- if (rate_limiter_.SuspendIfNecessary()) continue;
860
- if (sampler_->IsProfiling() && RuntimeProfiler::IsEnabled()) {
861
- SendProfilingSignal();
973
+ static void RemoveActiveSampler(Sampler* sampler) {
974
+ ScopedLock lock(mutex_);
975
+ SamplerRegistry::RemoveActiveSampler(sampler);
976
+ if (SamplerRegistry::GetState() == SamplerRegistry::HAS_NO_SAMPLERS) {
977
+ RuntimeProfiler::WakeUpRuntimeProfilerThreadBeforeShutdown();
978
+ instance_->Join();
979
+ delete instance_;
980
+ instance_ = NULL;
981
+
982
+ // Restore the old signal handler.
983
+ if (signal_handler_installed_) {
984
+ sigaction(SIGPROF, &old_signal_handler_, 0);
985
+ signal_handler_installed_ = false;
986
+ }
987
+ }
988
+ }
989
+
990
+ // Implement Thread::Run().
991
+ virtual void Run() {
992
+ SamplerRegistry::State state;
993
+ while ((state = SamplerRegistry::GetState()) !=
994
+ SamplerRegistry::HAS_NO_SAMPLERS) {
995
+ bool cpu_profiling_enabled =
996
+ (state == SamplerRegistry::HAS_CPU_PROFILING_SAMPLERS);
997
+ bool runtime_profiler_enabled = RuntimeProfiler::IsEnabled();
998
+ // When CPU profiling is enabled both JavaScript and C++ code is
999
+ // profiled. We must not suspend.
1000
+ if (!cpu_profiling_enabled) {
1001
+ if (rate_limiter_.SuspendIfNecessary()) continue;
1002
+ }
1003
+ if (cpu_profiling_enabled && runtime_profiler_enabled) {
1004
+ if (!SamplerRegistry::IterateActiveSamplers(&DoCpuProfile, this)) {
1005
+ return;
1006
+ }
862
1007
  Sleep(HALF_INTERVAL);
863
- RuntimeProfiler::NotifyTick();
1008
+ if (!SamplerRegistry::IterateActiveSamplers(&DoRuntimeProfile, NULL)) {
1009
+ return;
1010
+ }
864
1011
  Sleep(HALF_INTERVAL);
865
1012
  } else {
866
- if (sampler_->IsProfiling()) SendProfilingSignal();
867
- if (RuntimeProfiler::IsEnabled()) RuntimeProfiler::NotifyTick();
1013
+ if (cpu_profiling_enabled) {
1014
+ if (!SamplerRegistry::IterateActiveSamplers(&DoCpuProfile,
1015
+ this)) {
1016
+ return;
1017
+ }
1018
+ }
1019
+ if (runtime_profiler_enabled) {
1020
+ if (!SamplerRegistry::IterateActiveSamplers(&DoRuntimeProfile,
1021
+ NULL)) {
1022
+ return;
1023
+ }
1024
+ }
868
1025
  Sleep(FULL_INTERVAL);
869
1026
  }
870
1027
  }
871
1028
  }
872
1029
 
873
- void SendProfilingSignal() {
1030
+ static void DoCpuProfile(Sampler* sampler, void* raw_sender) {
1031
+ if (!sampler->IsProfiling()) return;
1032
+ SignalSender* sender = reinterpret_cast<SignalSender*>(raw_sender);
1033
+ sender->SendProfilingSignal(sampler->platform_data()->vm_tid());
1034
+ }
1035
+
1036
+ static void DoRuntimeProfile(Sampler* sampler, void* ignored) {
1037
+ if (!sampler->isolate()->IsInitialized()) return;
1038
+ sampler->isolate()->runtime_profiler()->NotifyTick();
1039
+ }
1040
+
1041
+ void SendProfilingSignal(int tid) {
1042
+ if (!signal_handler_installed_) return;
874
1043
  // Glibc doesn't provide a wrapper for tgkill(2).
875
- syscall(SYS_tgkill, vm_tgid_, vm_tid_, SIGPROF);
1044
+ #if defined(ANDROID)
1045
+ syscall(__NR_tgkill, vm_tgid_, tid, SIGPROF);
1046
+ #else
1047
+ syscall(SYS_tgkill, vm_tgid_, tid, SIGPROF);
1048
+ #endif
876
1049
  }
877
1050
 
878
1051
  void Sleep(SleepInterval full_or_half) {
879
1052
  // Convert ms to us and subtract 100 us to compensate delays
880
1053
  // occuring during signal delivery.
881
- useconds_t interval = sampler_->interval_ * 1000 - 100;
1054
+ useconds_t interval = interval_ * 1000 - 100;
882
1055
  if (full_or_half == HALF_INTERVAL) interval /= 2;
883
1056
  int result = usleep(interval);
884
1057
  #ifdef DEBUG
@@ -893,89 +1066,55 @@ class Sampler::PlatformData : public Malloced {
893
1066
  USE(result);
894
1067
  }
895
1068
 
896
- Sampler* sampler_;
897
- bool signal_handler_installed_;
898
- struct sigaction old_signal_handler_;
899
- int vm_tgid_;
900
- bool signal_sender_launched_;
901
- pthread_t signal_sender_thread_;
1069
+ const int vm_tgid_;
1070
+ const int interval_;
902
1071
  RuntimeProfilerRateLimiter rate_limiter_;
1072
+
1073
+ // Protects the process wide state below.
1074
+ static Mutex* mutex_;
1075
+ static SignalSender* instance_;
1076
+ static bool signal_handler_installed_;
1077
+ static struct sigaction old_signal_handler_;
1078
+
1079
+ DISALLOW_COPY_AND_ASSIGN(SignalSender);
903
1080
  };
904
1081
 
905
1082
 
906
- static void* SenderEntry(void* arg) {
907
- Sampler::PlatformData* data =
908
- reinterpret_cast<Sampler::PlatformData*>(arg);
909
- data->SignalSender();
910
- return 0;
911
- }
1083
+ Mutex* SignalSender::mutex_ = OS::CreateMutex();
1084
+ SignalSender* SignalSender::instance_ = NULL;
1085
+ struct sigaction SignalSender::old_signal_handler_;
1086
+ bool SignalSender::signal_handler_installed_ = false;
912
1087
 
913
1088
 
914
- Sampler::Sampler(int interval)
915
- : interval_(interval),
1089
+ Sampler::Sampler(Isolate* isolate, int interval)
1090
+ : isolate_(isolate),
1091
+ interval_(interval),
916
1092
  profiling_(false),
917
1093
  active_(false),
918
1094
  samples_taken_(0) {
919
- data_ = new PlatformData(this);
1095
+ data_ = new PlatformData;
920
1096
  }
921
1097
 
922
1098
 
923
1099
  Sampler::~Sampler() {
924
- ASSERT(!data_->signal_sender_launched_);
1100
+ ASSERT(!IsActive());
925
1101
  delete data_;
926
1102
  }
927
1103
 
928
1104
 
929
1105
  void Sampler::Start() {
930
- // There can only be one active sampler at the time on POSIX
931
- // platforms.
932
1106
  ASSERT(!IsActive());
933
- vm_tid_ = GetThreadID();
934
-
935
- // Request profiling signals.
936
- struct sigaction sa;
937
- sa.sa_sigaction = ProfilerSignalHandler;
938
- sigemptyset(&sa.sa_mask);
939
- sa.sa_flags = SA_RESTART | SA_SIGINFO;
940
- if (sigaction(SIGPROF, &sa, &data_->old_signal_handler_) != 0) return;
941
- data_->signal_handler_installed_ = true;
942
-
943
- // Start a thread that sends SIGPROF signal to VM thread.
944
- // Sending the signal ourselves instead of relying on itimer provides
945
- // much better accuracy.
946
1107
  SetActive(true);
947
- if (pthread_create(
948
- &data_->signal_sender_thread_, NULL, SenderEntry, data_) == 0) {
949
- data_->signal_sender_launched_ = true;
950
- }
951
-
952
- // Set this sampler as the active sampler.
953
- active_sampler_ = this;
1108
+ SignalSender::AddActiveSampler(this);
954
1109
  }
955
1110
 
956
1111
 
957
1112
  void Sampler::Stop() {
1113
+ ASSERT(IsActive());
1114
+ SignalSender::RemoveActiveSampler(this);
958
1115
  SetActive(false);
959
-
960
- // Wait for signal sender termination (it will exit after setting
961
- // active_ to false).
962
- if (data_->signal_sender_launched_) {
963
- Top::WakeUpRuntimeProfilerThreadBeforeShutdown();
964
- pthread_join(data_->signal_sender_thread_, NULL);
965
- data_->signal_sender_launched_ = false;
966
- }
967
-
968
- // Restore old signal handler
969
- if (data_->signal_handler_installed_) {
970
- sigaction(SIGPROF, &data_->old_signal_handler_, 0);
971
- data_->signal_handler_installed_ = false;
972
- }
973
-
974
- // This sampler is no longer the active sampler.
975
- active_sampler_ = NULL;
976
1116
  }
977
1117
 
978
-
979
1118
  #endif // ENABLE_LOGGING_AND_PROFILING
980
1119
 
981
1120
  } } // namespace v8::internal