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,1520 @@
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
+ #include "v8.h"
29
+
30
+ #if defined(V8_TARGET_ARCH_X64)
31
+
32
+ #include "codegen.h"
33
+ #include "deoptimizer.h"
34
+ #include "full-codegen.h"
35
+
36
+ namespace v8 {
37
+ namespace internal {
38
+
39
+
40
+ #define __ ACCESS_MASM(masm)
41
+
42
+
43
+ void Builtins::Generate_Adaptor(MacroAssembler* masm,
44
+ CFunctionId id,
45
+ BuiltinExtraArguments extra_args) {
46
+ // ----------- S t a t e -------------
47
+ // -- rax : number of arguments excluding receiver
48
+ // -- rdi : called function (only guaranteed when
49
+ // extra_args requires it)
50
+ // -- rsi : context
51
+ // -- rsp[0] : return address
52
+ // -- rsp[8] : last argument
53
+ // -- ...
54
+ // -- rsp[8 * argc] : first argument (argc == rax)
55
+ // -- rsp[8 * (argc +1)] : receiver
56
+ // -----------------------------------
57
+
58
+ // Insert extra arguments.
59
+ int num_extra_args = 0;
60
+ if (extra_args == NEEDS_CALLED_FUNCTION) {
61
+ num_extra_args = 1;
62
+ __ pop(kScratchRegister); // Save return address.
63
+ __ push(rdi);
64
+ __ push(kScratchRegister); // Restore return address.
65
+ } else {
66
+ ASSERT(extra_args == NO_EXTRA_ARGUMENTS);
67
+ }
68
+
69
+ // JumpToExternalReference expects rax to contain the number of arguments
70
+ // including the receiver and the extra arguments.
71
+ __ addq(rax, Immediate(num_extra_args + 1));
72
+ __ JumpToExternalReference(ExternalReference(id, masm->isolate()), 1);
73
+ }
74
+
75
+
76
+ void Builtins::Generate_JSConstructCall(MacroAssembler* masm) {
77
+ // ----------- S t a t e -------------
78
+ // -- rax: number of arguments
79
+ // -- rdi: constructor function
80
+ // -----------------------------------
81
+
82
+ Label non_function_call;
83
+ // Check that function is not a smi.
84
+ __ JumpIfSmi(rdi, &non_function_call);
85
+ // Check that function is a JSFunction.
86
+ __ CmpObjectType(rdi, JS_FUNCTION_TYPE, rcx);
87
+ __ j(not_equal, &non_function_call);
88
+
89
+ // Jump to the function-specific construct stub.
90
+ __ movq(rbx, FieldOperand(rdi, JSFunction::kSharedFunctionInfoOffset));
91
+ __ movq(rbx, FieldOperand(rbx, SharedFunctionInfo::kConstructStubOffset));
92
+ __ lea(rbx, FieldOperand(rbx, Code::kHeaderSize));
93
+ __ jmp(rbx);
94
+
95
+ // rdi: called object
96
+ // rax: number of arguments
97
+ __ bind(&non_function_call);
98
+ // Set expected number of arguments to zero (not changing rax).
99
+ __ Set(rbx, 0);
100
+ __ GetBuiltinEntry(rdx, Builtins::CALL_NON_FUNCTION_AS_CONSTRUCTOR);
101
+ __ SetCallKind(rcx, CALL_AS_METHOD);
102
+ __ Jump(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(),
103
+ RelocInfo::CODE_TARGET);
104
+ }
105
+
106
+
107
+ static void Generate_JSConstructStubHelper(MacroAssembler* masm,
108
+ bool is_api_function,
109
+ bool count_constructions) {
110
+ // Should never count constructions for api objects.
111
+ ASSERT(!is_api_function || !count_constructions);
112
+
113
+ // Enter a construct frame.
114
+ __ EnterConstructFrame();
115
+
116
+ // Store a smi-tagged arguments count on the stack.
117
+ __ Integer32ToSmi(rax, rax);
118
+ __ push(rax);
119
+
120
+ // Push the function to invoke on the stack.
121
+ __ push(rdi);
122
+
123
+ // Try to allocate the object without transitioning into C code. If any of the
124
+ // preconditions is not met, the code bails out to the runtime call.
125
+ Label rt_call, allocated;
126
+ if (FLAG_inline_new) {
127
+ Label undo_allocation;
128
+
129
+ #ifdef ENABLE_DEBUGGER_SUPPORT
130
+ ExternalReference debug_step_in_fp =
131
+ ExternalReference::debug_step_in_fp_address(masm->isolate());
132
+ __ movq(kScratchRegister, debug_step_in_fp);
133
+ __ cmpq(Operand(kScratchRegister, 0), Immediate(0));
134
+ __ j(not_equal, &rt_call);
135
+ #endif
136
+
137
+ // Verified that the constructor is a JSFunction.
138
+ // Load the initial map and verify that it is in fact a map.
139
+ // rdi: constructor
140
+ __ movq(rax, FieldOperand(rdi, JSFunction::kPrototypeOrInitialMapOffset));
141
+ // Will both indicate a NULL and a Smi
142
+ ASSERT(kSmiTag == 0);
143
+ __ JumpIfSmi(rax, &rt_call);
144
+ // rdi: constructor
145
+ // rax: initial map (if proven valid below)
146
+ __ CmpObjectType(rax, MAP_TYPE, rbx);
147
+ __ j(not_equal, &rt_call);
148
+
149
+ // Check that the constructor is not constructing a JSFunction (see comments
150
+ // in Runtime_NewObject in runtime.cc). In which case the initial map's
151
+ // instance type would be JS_FUNCTION_TYPE.
152
+ // rdi: constructor
153
+ // rax: initial map
154
+ __ CmpInstanceType(rax, JS_FUNCTION_TYPE);
155
+ __ j(equal, &rt_call);
156
+
157
+ if (count_constructions) {
158
+ Label allocate;
159
+ // Decrease generous allocation count.
160
+ __ movq(rcx, FieldOperand(rdi, JSFunction::kSharedFunctionInfoOffset));
161
+ __ decb(FieldOperand(rcx, SharedFunctionInfo::kConstructionCountOffset));
162
+ __ j(not_zero, &allocate);
163
+
164
+ __ push(rax);
165
+ __ push(rdi);
166
+
167
+ __ push(rdi); // constructor
168
+ // The call will replace the stub, so the countdown is only done once.
169
+ __ CallRuntime(Runtime::kFinalizeInstanceSize, 1);
170
+
171
+ __ pop(rdi);
172
+ __ pop(rax);
173
+
174
+ __ bind(&allocate);
175
+ }
176
+
177
+ // Now allocate the JSObject on the heap.
178
+ __ movzxbq(rdi, FieldOperand(rax, Map::kInstanceSizeOffset));
179
+ __ shl(rdi, Immediate(kPointerSizeLog2));
180
+ // rdi: size of new object
181
+ __ AllocateInNewSpace(rdi,
182
+ rbx,
183
+ rdi,
184
+ no_reg,
185
+ &rt_call,
186
+ NO_ALLOCATION_FLAGS);
187
+ // Allocated the JSObject, now initialize the fields.
188
+ // rax: initial map
189
+ // rbx: JSObject (not HeapObject tagged - the actual address).
190
+ // rdi: start of next object
191
+ __ movq(Operand(rbx, JSObject::kMapOffset), rax);
192
+ __ LoadRoot(rcx, Heap::kEmptyFixedArrayRootIndex);
193
+ __ movq(Operand(rbx, JSObject::kPropertiesOffset), rcx);
194
+ __ movq(Operand(rbx, JSObject::kElementsOffset), rcx);
195
+ // Set extra fields in the newly allocated object.
196
+ // rax: initial map
197
+ // rbx: JSObject
198
+ // rdi: start of next object
199
+ { Label loop, entry;
200
+ // To allow for truncation.
201
+ if (count_constructions) {
202
+ __ LoadRoot(rdx, Heap::kOnePointerFillerMapRootIndex);
203
+ } else {
204
+ __ LoadRoot(rdx, Heap::kUndefinedValueRootIndex);
205
+ }
206
+ __ lea(rcx, Operand(rbx, JSObject::kHeaderSize));
207
+ __ jmp(&entry);
208
+ __ bind(&loop);
209
+ __ movq(Operand(rcx, 0), rdx);
210
+ __ addq(rcx, Immediate(kPointerSize));
211
+ __ bind(&entry);
212
+ __ cmpq(rcx, rdi);
213
+ __ j(less, &loop);
214
+ }
215
+
216
+ // Add the object tag to make the JSObject real, so that we can continue and
217
+ // jump into the continuation code at any time from now on. Any failures
218
+ // need to undo the allocation, so that the heap is in a consistent state
219
+ // and verifiable.
220
+ // rax: initial map
221
+ // rbx: JSObject
222
+ // rdi: start of next object
223
+ __ or_(rbx, Immediate(kHeapObjectTag));
224
+
225
+ // Check if a non-empty properties array is needed.
226
+ // Allocate and initialize a FixedArray if it is.
227
+ // rax: initial map
228
+ // rbx: JSObject
229
+ // rdi: start of next object
230
+ // Calculate total properties described map.
231
+ __ movzxbq(rdx, FieldOperand(rax, Map::kUnusedPropertyFieldsOffset));
232
+ __ movzxbq(rcx, FieldOperand(rax, Map::kPreAllocatedPropertyFieldsOffset));
233
+ __ addq(rdx, rcx);
234
+ // Calculate unused properties past the end of the in-object properties.
235
+ __ movzxbq(rcx, FieldOperand(rax, Map::kInObjectPropertiesOffset));
236
+ __ subq(rdx, rcx);
237
+ // Done if no extra properties are to be allocated.
238
+ __ j(zero, &allocated);
239
+ __ Assert(positive, "Property allocation count failed.");
240
+
241
+ // Scale the number of elements by pointer size and add the header for
242
+ // FixedArrays to the start of the next object calculation from above.
243
+ // rbx: JSObject
244
+ // rdi: start of next object (will be start of FixedArray)
245
+ // rdx: number of elements in properties array
246
+ __ AllocateInNewSpace(FixedArray::kHeaderSize,
247
+ times_pointer_size,
248
+ rdx,
249
+ rdi,
250
+ rax,
251
+ no_reg,
252
+ &undo_allocation,
253
+ RESULT_CONTAINS_TOP);
254
+
255
+ // Initialize the FixedArray.
256
+ // rbx: JSObject
257
+ // rdi: FixedArray
258
+ // rdx: number of elements
259
+ // rax: start of next object
260
+ __ LoadRoot(rcx, Heap::kFixedArrayMapRootIndex);
261
+ __ movq(Operand(rdi, HeapObject::kMapOffset), rcx); // setup the map
262
+ __ Integer32ToSmi(rdx, rdx);
263
+ __ movq(Operand(rdi, FixedArray::kLengthOffset), rdx); // and length
264
+
265
+ // Initialize the fields to undefined.
266
+ // rbx: JSObject
267
+ // rdi: FixedArray
268
+ // rax: start of next object
269
+ // rdx: number of elements
270
+ { Label loop, entry;
271
+ __ LoadRoot(rdx, Heap::kUndefinedValueRootIndex);
272
+ __ lea(rcx, Operand(rdi, FixedArray::kHeaderSize));
273
+ __ jmp(&entry);
274
+ __ bind(&loop);
275
+ __ movq(Operand(rcx, 0), rdx);
276
+ __ addq(rcx, Immediate(kPointerSize));
277
+ __ bind(&entry);
278
+ __ cmpq(rcx, rax);
279
+ __ j(below, &loop);
280
+ }
281
+
282
+ // Store the initialized FixedArray into the properties field of
283
+ // the JSObject
284
+ // rbx: JSObject
285
+ // rdi: FixedArray
286
+ __ or_(rdi, Immediate(kHeapObjectTag)); // add the heap tag
287
+ __ movq(FieldOperand(rbx, JSObject::kPropertiesOffset), rdi);
288
+
289
+
290
+ // Continue with JSObject being successfully allocated
291
+ // rbx: JSObject
292
+ __ jmp(&allocated);
293
+
294
+ // Undo the setting of the new top so that the heap is verifiable. For
295
+ // example, the map's unused properties potentially do not match the
296
+ // allocated objects unused properties.
297
+ // rbx: JSObject (previous new top)
298
+ __ bind(&undo_allocation);
299
+ __ UndoAllocationInNewSpace(rbx);
300
+ }
301
+
302
+ // Allocate the new receiver object using the runtime call.
303
+ // rdi: function (constructor)
304
+ __ bind(&rt_call);
305
+ // Must restore rdi (constructor) before calling runtime.
306
+ __ movq(rdi, Operand(rsp, 0));
307
+ __ push(rdi);
308
+ __ CallRuntime(Runtime::kNewObject, 1);
309
+ __ movq(rbx, rax); // store result in rbx
310
+
311
+ // New object allocated.
312
+ // rbx: newly allocated object
313
+ __ bind(&allocated);
314
+ // Retrieve the function from the stack.
315
+ __ pop(rdi);
316
+
317
+ // Retrieve smi-tagged arguments count from the stack.
318
+ __ movq(rax, Operand(rsp, 0));
319
+ __ SmiToInteger32(rax, rax);
320
+
321
+ // Push the allocated receiver to the stack. We need two copies
322
+ // because we may have to return the original one and the calling
323
+ // conventions dictate that the called function pops the receiver.
324
+ __ push(rbx);
325
+ __ push(rbx);
326
+
327
+ // Setup pointer to last argument.
328
+ __ lea(rbx, Operand(rbp, StandardFrameConstants::kCallerSPOffset));
329
+
330
+ // Copy arguments and receiver to the expression stack.
331
+ Label loop, entry;
332
+ __ movq(rcx, rax);
333
+ __ jmp(&entry);
334
+ __ bind(&loop);
335
+ __ push(Operand(rbx, rcx, times_pointer_size, 0));
336
+ __ bind(&entry);
337
+ __ decq(rcx);
338
+ __ j(greater_equal, &loop);
339
+
340
+ // Call the function.
341
+ if (is_api_function) {
342
+ __ movq(rsi, FieldOperand(rdi, JSFunction::kContextOffset));
343
+ Handle<Code> code =
344
+ masm->isolate()->builtins()->HandleApiCallConstruct();
345
+ ParameterCount expected(0);
346
+ __ InvokeCode(code, expected, expected,
347
+ RelocInfo::CODE_TARGET, CALL_FUNCTION);
348
+ } else {
349
+ ParameterCount actual(rax);
350
+ __ InvokeFunction(rdi, actual, CALL_FUNCTION);
351
+ }
352
+
353
+ // Restore context from the frame.
354
+ __ movq(rsi, Operand(rbp, StandardFrameConstants::kContextOffset));
355
+
356
+ // If the result is an object (in the ECMA sense), we should get rid
357
+ // of the receiver and use the result; see ECMA-262 section 13.2.2-7
358
+ // on page 74.
359
+ Label use_receiver, exit;
360
+ // If the result is a smi, it is *not* an object in the ECMA sense.
361
+ __ JumpIfSmi(rax, &use_receiver);
362
+
363
+ // If the type of the result (stored in its map) is less than
364
+ // FIRST_JS_OBJECT_TYPE, it is not an object in the ECMA sense.
365
+ __ CmpObjectType(rax, FIRST_JS_OBJECT_TYPE, rcx);
366
+ __ j(above_equal, &exit);
367
+
368
+ // Throw away the result of the constructor invocation and use the
369
+ // on-stack receiver as the result.
370
+ __ bind(&use_receiver);
371
+ __ movq(rax, Operand(rsp, 0));
372
+
373
+ // Restore the arguments count and leave the construct frame.
374
+ __ bind(&exit);
375
+ __ movq(rbx, Operand(rsp, kPointerSize)); // get arguments count
376
+ __ LeaveConstructFrame();
377
+
378
+ // Remove caller arguments from the stack and return.
379
+ __ pop(rcx);
380
+ SmiIndex index = masm->SmiToIndex(rbx, rbx, kPointerSizeLog2);
381
+ __ lea(rsp, Operand(rsp, index.reg, index.scale, 1 * kPointerSize));
382
+ __ push(rcx);
383
+ Counters* counters = masm->isolate()->counters();
384
+ __ IncrementCounter(counters->constructed_objects(), 1);
385
+ __ ret(0);
386
+ }
387
+
388
+
389
+ void Builtins::Generate_JSConstructStubCountdown(MacroAssembler* masm) {
390
+ Generate_JSConstructStubHelper(masm, false, true);
391
+ }
392
+
393
+
394
+ void Builtins::Generate_JSConstructStubGeneric(MacroAssembler* masm) {
395
+ Generate_JSConstructStubHelper(masm, false, false);
396
+ }
397
+
398
+
399
+ void Builtins::Generate_JSConstructStubApi(MacroAssembler* masm) {
400
+ Generate_JSConstructStubHelper(masm, true, false);
401
+ }
402
+
403
+
404
+ static void Generate_JSEntryTrampolineHelper(MacroAssembler* masm,
405
+ bool is_construct) {
406
+ // Expects five C++ function parameters.
407
+ // - Address entry (ignored)
408
+ // - JSFunction* function (
409
+ // - Object* receiver
410
+ // - int argc
411
+ // - Object*** argv
412
+ // (see Handle::Invoke in execution.cc).
413
+
414
+ // Platform specific argument handling. After this, the stack contains
415
+ // an internal frame and the pushed function and receiver, and
416
+ // register rax and rbx holds the argument count and argument array,
417
+ // while rdi holds the function pointer and rsi the context.
418
+ #ifdef _WIN64
419
+ // MSVC parameters in:
420
+ // rcx : entry (ignored)
421
+ // rdx : function
422
+ // r8 : receiver
423
+ // r9 : argc
424
+ // [rsp+0x20] : argv
425
+
426
+ // Clear the context before we push it when entering the JS frame.
427
+ __ Set(rsi, 0);
428
+ __ EnterInternalFrame();
429
+
430
+ // Load the function context into rsi.
431
+ __ movq(rsi, FieldOperand(rdx, JSFunction::kContextOffset));
432
+
433
+ // Push the function and the receiver onto the stack.
434
+ __ push(rdx);
435
+ __ push(r8);
436
+
437
+ // Load the number of arguments and setup pointer to the arguments.
438
+ __ movq(rax, r9);
439
+ // Load the previous frame pointer to access C argument on stack
440
+ __ movq(kScratchRegister, Operand(rbp, 0));
441
+ __ movq(rbx, Operand(kScratchRegister, EntryFrameConstants::kArgvOffset));
442
+ // Load the function pointer into rdi.
443
+ __ movq(rdi, rdx);
444
+ #else // _WIN64
445
+ // GCC parameters in:
446
+ // rdi : entry (ignored)
447
+ // rsi : function
448
+ // rdx : receiver
449
+ // rcx : argc
450
+ // r8 : argv
451
+
452
+ __ movq(rdi, rsi);
453
+ // rdi : function
454
+
455
+ // Clear the context before we push it when entering the JS frame.
456
+ __ Set(rsi, 0);
457
+ // Enter an internal frame.
458
+ __ EnterInternalFrame();
459
+
460
+ // Push the function and receiver and setup the context.
461
+ __ push(rdi);
462
+ __ push(rdx);
463
+ __ movq(rsi, FieldOperand(rdi, JSFunction::kContextOffset));
464
+
465
+ // Load the number of arguments and setup pointer to the arguments.
466
+ __ movq(rax, rcx);
467
+ __ movq(rbx, r8);
468
+ #endif // _WIN64
469
+
470
+ // Current stack contents:
471
+ // [rsp + 2 * kPointerSize ... ]: Internal frame
472
+ // [rsp + kPointerSize] : function
473
+ // [rsp] : receiver
474
+ // Current register contents:
475
+ // rax : argc
476
+ // rbx : argv
477
+ // rsi : context
478
+ // rdi : function
479
+
480
+ // Copy arguments to the stack in a loop.
481
+ // Register rbx points to array of pointers to handle locations.
482
+ // Push the values of these handles.
483
+ Label loop, entry;
484
+ __ Set(rcx, 0); // Set loop variable to 0.
485
+ __ jmp(&entry);
486
+ __ bind(&loop);
487
+ __ movq(kScratchRegister, Operand(rbx, rcx, times_pointer_size, 0));
488
+ __ push(Operand(kScratchRegister, 0)); // dereference handle
489
+ __ addq(rcx, Immediate(1));
490
+ __ bind(&entry);
491
+ __ cmpq(rcx, rax);
492
+ __ j(not_equal, &loop);
493
+
494
+ // Invoke the code.
495
+ if (is_construct) {
496
+ // Expects rdi to hold function pointer.
497
+ __ Call(masm->isolate()->builtins()->JSConstructCall(),
498
+ RelocInfo::CODE_TARGET);
499
+ } else {
500
+ ParameterCount actual(rax);
501
+ // Function must be in rdi.
502
+ __ InvokeFunction(rdi, actual, CALL_FUNCTION);
503
+ }
504
+
505
+ // Exit the JS frame. Notice that this also removes the empty
506
+ // context and the function left on the stack by the code
507
+ // invocation.
508
+ __ LeaveInternalFrame();
509
+ // TODO(X64): Is argument correct? Is there a receiver to remove?
510
+ __ ret(1 * kPointerSize); // remove receiver
511
+ }
512
+
513
+
514
+ void Builtins::Generate_JSEntryTrampoline(MacroAssembler* masm) {
515
+ Generate_JSEntryTrampolineHelper(masm, false);
516
+ }
517
+
518
+
519
+ void Builtins::Generate_JSConstructEntryTrampoline(MacroAssembler* masm) {
520
+ Generate_JSEntryTrampolineHelper(masm, true);
521
+ }
522
+
523
+
524
+ void Builtins::Generate_LazyCompile(MacroAssembler* masm) {
525
+ // Enter an internal frame.
526
+ __ EnterInternalFrame();
527
+
528
+ // Push a copy of the function onto the stack.
529
+ __ push(rdi);
530
+ // Push call kind information.
531
+ __ push(rcx);
532
+
533
+ __ push(rdi); // Function is also the parameter to the runtime call.
534
+ __ CallRuntime(Runtime::kLazyCompile, 1);
535
+
536
+ // Restore call kind information.
537
+ __ pop(rcx);
538
+ // Restore receiver.
539
+ __ pop(rdi);
540
+
541
+ // Tear down temporary frame.
542
+ __ LeaveInternalFrame();
543
+
544
+ // Do a tail-call of the compiled function.
545
+ __ lea(rax, FieldOperand(rax, Code::kHeaderSize));
546
+ __ jmp(rax);
547
+ }
548
+
549
+
550
+ void Builtins::Generate_LazyRecompile(MacroAssembler* masm) {
551
+ // Enter an internal frame.
552
+ __ EnterInternalFrame();
553
+
554
+ // Push a copy of the function onto the stack.
555
+ __ push(rdi);
556
+ // Push call kind information.
557
+ __ push(rcx);
558
+
559
+ __ push(rdi); // Function is also the parameter to the runtime call.
560
+ __ CallRuntime(Runtime::kLazyRecompile, 1);
561
+
562
+ // Restore call kind information.
563
+ __ pop(rcx);
564
+ // Restore function.
565
+ __ pop(rdi);
566
+
567
+ // Tear down temporary frame.
568
+ __ LeaveInternalFrame();
569
+
570
+ // Do a tail-call of the compiled function.
571
+ __ lea(rax, FieldOperand(rax, Code::kHeaderSize));
572
+ __ jmp(rax);
573
+ }
574
+
575
+
576
+ static void Generate_NotifyDeoptimizedHelper(MacroAssembler* masm,
577
+ Deoptimizer::BailoutType type) {
578
+ // Enter an internal frame.
579
+ __ EnterInternalFrame();
580
+
581
+ // Pass the deoptimization type to the runtime system.
582
+ __ Push(Smi::FromInt(static_cast<int>(type)));
583
+
584
+ __ CallRuntime(Runtime::kNotifyDeoptimized, 1);
585
+ // Tear down temporary frame.
586
+ __ LeaveInternalFrame();
587
+
588
+ // Get the full codegen state from the stack and untag it.
589
+ __ SmiToInteger32(rcx, Operand(rsp, 1 * kPointerSize));
590
+
591
+ // Switch on the state.
592
+ Label not_no_registers, not_tos_rax;
593
+ __ cmpq(rcx, Immediate(FullCodeGenerator::NO_REGISTERS));
594
+ __ j(not_equal, &not_no_registers, Label::kNear);
595
+ __ ret(1 * kPointerSize); // Remove state.
596
+
597
+ __ bind(&not_no_registers);
598
+ __ movq(rax, Operand(rsp, 2 * kPointerSize));
599
+ __ cmpq(rcx, Immediate(FullCodeGenerator::TOS_REG));
600
+ __ j(not_equal, &not_tos_rax, Label::kNear);
601
+ __ ret(2 * kPointerSize); // Remove state, rax.
602
+
603
+ __ bind(&not_tos_rax);
604
+ __ Abort("no cases left");
605
+ }
606
+
607
+ void Builtins::Generate_NotifyDeoptimized(MacroAssembler* masm) {
608
+ Generate_NotifyDeoptimizedHelper(masm, Deoptimizer::EAGER);
609
+ }
610
+
611
+
612
+ void Builtins::Generate_NotifyLazyDeoptimized(MacroAssembler* masm) {
613
+ Generate_NotifyDeoptimizedHelper(masm, Deoptimizer::LAZY);
614
+ }
615
+
616
+
617
+ void Builtins::Generate_NotifyOSR(MacroAssembler* masm) {
618
+ // For now, we are relying on the fact that Runtime::NotifyOSR
619
+ // doesn't do any garbage collection which allows us to save/restore
620
+ // the registers without worrying about which of them contain
621
+ // pointers. This seems a bit fragile.
622
+ __ Pushad();
623
+ __ EnterInternalFrame();
624
+ __ CallRuntime(Runtime::kNotifyOSR, 0);
625
+ __ LeaveInternalFrame();
626
+ __ Popad();
627
+ __ ret(0);
628
+ }
629
+
630
+
631
+ void Builtins::Generate_FunctionCall(MacroAssembler* masm) {
632
+ // Stack Layout:
633
+ // rsp[0]: Return address
634
+ // rsp[1]: Argument n
635
+ // rsp[2]: Argument n-1
636
+ // ...
637
+ // rsp[n]: Argument 1
638
+ // rsp[n+1]: Receiver (function to call)
639
+ //
640
+ // rax contains the number of arguments, n, not counting the receiver.
641
+ //
642
+ // 1. Make sure we have at least one argument.
643
+ { Label done;
644
+ __ testq(rax, rax);
645
+ __ j(not_zero, &done);
646
+ __ pop(rbx);
647
+ __ Push(FACTORY->undefined_value());
648
+ __ push(rbx);
649
+ __ incq(rax);
650
+ __ bind(&done);
651
+ }
652
+
653
+ // 2. Get the function to call (passed as receiver) from the stack, check
654
+ // if it is a function.
655
+ Label non_function;
656
+ // The function to call is at position n+1 on the stack.
657
+ __ movq(rdi, Operand(rsp, rax, times_pointer_size, 1 * kPointerSize));
658
+ __ JumpIfSmi(rdi, &non_function);
659
+ __ CmpObjectType(rdi, JS_FUNCTION_TYPE, rcx);
660
+ __ j(not_equal, &non_function);
661
+
662
+ // 3a. Patch the first argument if necessary when calling a function.
663
+ Label shift_arguments;
664
+ { Label convert_to_object, use_global_receiver, patch_receiver;
665
+ // Change context eagerly in case we need the global receiver.
666
+ __ movq(rsi, FieldOperand(rdi, JSFunction::kContextOffset));
667
+
668
+ // Do not transform the receiver for strict mode functions.
669
+ __ movq(rbx, FieldOperand(rdi, JSFunction::kSharedFunctionInfoOffset));
670
+ __ testb(FieldOperand(rbx, SharedFunctionInfo::kStrictModeByteOffset),
671
+ Immediate(1 << SharedFunctionInfo::kStrictModeBitWithinByte));
672
+ __ j(not_equal, &shift_arguments);
673
+
674
+ // Do not transform the receiver for natives.
675
+ // SharedFunctionInfo is already loaded into rbx.
676
+ __ testb(FieldOperand(rbx, SharedFunctionInfo::kES5NativeByteOffset),
677
+ Immediate(1 << SharedFunctionInfo::kES5NativeBitWithinByte));
678
+ __ j(not_zero, &shift_arguments);
679
+
680
+ // Compute the receiver in non-strict mode.
681
+ __ movq(rbx, Operand(rsp, rax, times_pointer_size, 0));
682
+ __ JumpIfSmi(rbx, &convert_to_object, Label::kNear);
683
+
684
+ __ CompareRoot(rbx, Heap::kNullValueRootIndex);
685
+ __ j(equal, &use_global_receiver);
686
+ __ CompareRoot(rbx, Heap::kUndefinedValueRootIndex);
687
+ __ j(equal, &use_global_receiver);
688
+
689
+ STATIC_ASSERT(LAST_JS_OBJECT_TYPE + 1 == LAST_TYPE);
690
+ STATIC_ASSERT(LAST_TYPE == JS_FUNCTION_TYPE);
691
+ __ CmpObjectType(rbx, FIRST_JS_OBJECT_TYPE, rcx);
692
+ __ j(above_equal, &shift_arguments);
693
+
694
+ __ bind(&convert_to_object);
695
+ __ EnterInternalFrame(); // In order to preserve argument count.
696
+ __ Integer32ToSmi(rax, rax);
697
+ __ push(rax);
698
+
699
+ __ push(rbx);
700
+ __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION);
701
+ __ movq(rbx, rax);
702
+
703
+ __ pop(rax);
704
+ __ SmiToInteger32(rax, rax);
705
+ __ LeaveInternalFrame();
706
+ // Restore the function to rdi.
707
+ __ movq(rdi, Operand(rsp, rax, times_pointer_size, 1 * kPointerSize));
708
+ __ jmp(&patch_receiver, Label::kNear);
709
+
710
+ // Use the global receiver object from the called function as the
711
+ // receiver.
712
+ __ bind(&use_global_receiver);
713
+ const int kGlobalIndex =
714
+ Context::kHeaderSize + Context::GLOBAL_INDEX * kPointerSize;
715
+ __ movq(rbx, FieldOperand(rsi, kGlobalIndex));
716
+ __ movq(rbx, FieldOperand(rbx, GlobalObject::kGlobalContextOffset));
717
+ __ movq(rbx, FieldOperand(rbx, kGlobalIndex));
718
+ __ movq(rbx, FieldOperand(rbx, GlobalObject::kGlobalReceiverOffset));
719
+
720
+ __ bind(&patch_receiver);
721
+ __ movq(Operand(rsp, rax, times_pointer_size, 0), rbx);
722
+
723
+ __ jmp(&shift_arguments);
724
+ }
725
+
726
+
727
+ // 3b. Patch the first argument when calling a non-function. The
728
+ // CALL_NON_FUNCTION builtin expects the non-function callee as
729
+ // receiver, so overwrite the first argument which will ultimately
730
+ // become the receiver.
731
+ __ bind(&non_function);
732
+ __ movq(Operand(rsp, rax, times_pointer_size, 0), rdi);
733
+ __ Set(rdi, 0);
734
+
735
+ // 4. Shift arguments and return address one slot down on the stack
736
+ // (overwriting the original receiver). Adjust argument count to make
737
+ // the original first argument the new receiver.
738
+ __ bind(&shift_arguments);
739
+ { Label loop;
740
+ __ movq(rcx, rax);
741
+ __ bind(&loop);
742
+ __ movq(rbx, Operand(rsp, rcx, times_pointer_size, 0));
743
+ __ movq(Operand(rsp, rcx, times_pointer_size, 1 * kPointerSize), rbx);
744
+ __ decq(rcx);
745
+ __ j(not_sign, &loop); // While non-negative (to copy return address).
746
+ __ pop(rbx); // Discard copy of return address.
747
+ __ decq(rax); // One fewer argument (first argument is new receiver).
748
+ }
749
+
750
+ // 5a. Call non-function via tail call to CALL_NON_FUNCTION builtin.
751
+ { Label function;
752
+ __ testq(rdi, rdi);
753
+ __ j(not_zero, &function);
754
+ __ Set(rbx, 0);
755
+ __ GetBuiltinEntry(rdx, Builtins::CALL_NON_FUNCTION);
756
+ __ SetCallKind(rcx, CALL_AS_METHOD);
757
+ __ Jump(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(),
758
+ RelocInfo::CODE_TARGET);
759
+ __ bind(&function);
760
+ }
761
+
762
+ // 5b. Get the code to call from the function and check that the number of
763
+ // expected arguments matches what we're providing. If so, jump
764
+ // (tail-call) to the code in register edx without checking arguments.
765
+ __ movq(rdx, FieldOperand(rdi, JSFunction::kSharedFunctionInfoOffset));
766
+ __ movsxlq(rbx,
767
+ FieldOperand(rdx,
768
+ SharedFunctionInfo::kFormalParameterCountOffset));
769
+ __ movq(rdx, FieldOperand(rdi, JSFunction::kCodeEntryOffset));
770
+ __ SetCallKind(rcx, CALL_AS_METHOD);
771
+ __ cmpq(rax, rbx);
772
+ __ j(not_equal,
773
+ masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(),
774
+ RelocInfo::CODE_TARGET);
775
+
776
+ ParameterCount expected(0);
777
+ __ InvokeCode(rdx, expected, expected, JUMP_FUNCTION);
778
+ }
779
+
780
+
781
+ void Builtins::Generate_FunctionApply(MacroAssembler* masm) {
782
+ // Stack at entry:
783
+ // rsp: return address
784
+ // rsp+8: arguments
785
+ // rsp+16: receiver ("this")
786
+ // rsp+24: function
787
+ __ EnterInternalFrame();
788
+ // Stack frame:
789
+ // rbp: Old base pointer
790
+ // rbp[1]: return address
791
+ // rbp[2]: function arguments
792
+ // rbp[3]: receiver
793
+ // rbp[4]: function
794
+ static const int kArgumentsOffset = 2 * kPointerSize;
795
+ static const int kReceiverOffset = 3 * kPointerSize;
796
+ static const int kFunctionOffset = 4 * kPointerSize;
797
+ __ push(Operand(rbp, kFunctionOffset));
798
+ __ push(Operand(rbp, kArgumentsOffset));
799
+ __ InvokeBuiltin(Builtins::APPLY_PREPARE, CALL_FUNCTION);
800
+
801
+ // Check the stack for overflow. We are not trying need to catch
802
+ // interruptions (e.g. debug break and preemption) here, so the "real stack
803
+ // limit" is checked.
804
+ Label okay;
805
+ __ LoadRoot(kScratchRegister, Heap::kRealStackLimitRootIndex);
806
+ __ movq(rcx, rsp);
807
+ // Make rcx the space we have left. The stack might already be overflowed
808
+ // here which will cause rcx to become negative.
809
+ __ subq(rcx, kScratchRegister);
810
+ // Make rdx the space we need for the array when it is unrolled onto the
811
+ // stack.
812
+ __ PositiveSmiTimesPowerOfTwoToInteger64(rdx, rax, kPointerSizeLog2);
813
+ // Check if the arguments will overflow the stack.
814
+ __ cmpq(rcx, rdx);
815
+ __ j(greater, &okay); // Signed comparison.
816
+
817
+ // Out of stack space.
818
+ __ push(Operand(rbp, kFunctionOffset));
819
+ __ push(rax);
820
+ __ InvokeBuiltin(Builtins::APPLY_OVERFLOW, CALL_FUNCTION);
821
+ __ bind(&okay);
822
+ // End of stack check.
823
+
824
+ // Push current index and limit.
825
+ const int kLimitOffset =
826
+ StandardFrameConstants::kExpressionsOffset - 1 * kPointerSize;
827
+ const int kIndexOffset = kLimitOffset - 1 * kPointerSize;
828
+ __ push(rax); // limit
829
+ __ push(Immediate(0)); // index
830
+
831
+ // Change context eagerly to get the right global object if
832
+ // necessary.
833
+ __ movq(rdi, Operand(rbp, kFunctionOffset));
834
+ __ movq(rsi, FieldOperand(rdi, JSFunction::kContextOffset));
835
+
836
+ // Compute the receiver.
837
+ Label call_to_object, use_global_receiver, push_receiver;
838
+ __ movq(rbx, Operand(rbp, kReceiverOffset));
839
+
840
+ // Do not transform the receiver for strict mode functions.
841
+ __ movq(rdx, FieldOperand(rdi, JSFunction::kSharedFunctionInfoOffset));
842
+ __ testb(FieldOperand(rdx, SharedFunctionInfo::kStrictModeByteOffset),
843
+ Immediate(1 << SharedFunctionInfo::kStrictModeBitWithinByte));
844
+ __ j(not_equal, &push_receiver);
845
+
846
+ // Do not transform the receiver for natives.
847
+ __ testb(FieldOperand(rdx, SharedFunctionInfo::kES5NativeByteOffset),
848
+ Immediate(1 << SharedFunctionInfo::kES5NativeBitWithinByte));
849
+ __ j(not_zero, &push_receiver);
850
+
851
+ // Compute the receiver in non-strict mode.
852
+ __ JumpIfSmi(rbx, &call_to_object, Label::kNear);
853
+ __ CompareRoot(rbx, Heap::kNullValueRootIndex);
854
+ __ j(equal, &use_global_receiver);
855
+ __ CompareRoot(rbx, Heap::kUndefinedValueRootIndex);
856
+ __ j(equal, &use_global_receiver);
857
+
858
+ // If given receiver is already a JavaScript object then there's no
859
+ // reason for converting it.
860
+ STATIC_ASSERT(LAST_JS_OBJECT_TYPE + 1 == LAST_TYPE);
861
+ STATIC_ASSERT(LAST_TYPE == JS_FUNCTION_TYPE);
862
+ __ CmpObjectType(rbx, FIRST_JS_OBJECT_TYPE, rcx);
863
+ __ j(above_equal, &push_receiver);
864
+
865
+ // Convert the receiver to an object.
866
+ __ bind(&call_to_object);
867
+ __ push(rbx);
868
+ __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION);
869
+ __ movq(rbx, rax);
870
+ __ jmp(&push_receiver, Label::kNear);
871
+
872
+ // Use the current global receiver object as the receiver.
873
+ __ bind(&use_global_receiver);
874
+ const int kGlobalOffset =
875
+ Context::kHeaderSize + Context::GLOBAL_INDEX * kPointerSize;
876
+ __ movq(rbx, FieldOperand(rsi, kGlobalOffset));
877
+ __ movq(rbx, FieldOperand(rbx, GlobalObject::kGlobalContextOffset));
878
+ __ movq(rbx, FieldOperand(rbx, kGlobalOffset));
879
+ __ movq(rbx, FieldOperand(rbx, GlobalObject::kGlobalReceiverOffset));
880
+
881
+ // Push the receiver.
882
+ __ bind(&push_receiver);
883
+ __ push(rbx);
884
+
885
+ // Copy all arguments from the array to the stack.
886
+ Label entry, loop;
887
+ __ movq(rax, Operand(rbp, kIndexOffset));
888
+ __ jmp(&entry);
889
+ __ bind(&loop);
890
+ __ movq(rdx, Operand(rbp, kArgumentsOffset)); // load arguments
891
+
892
+ // Use inline caching to speed up access to arguments.
893
+ Handle<Code> ic =
894
+ masm->isolate()->builtins()->KeyedLoadIC_Initialize();
895
+ __ Call(ic, RelocInfo::CODE_TARGET);
896
+ // It is important that we do not have a test instruction after the
897
+ // call. A test instruction after the call is used to indicate that
898
+ // we have generated an inline version of the keyed load. In this
899
+ // case, we know that we are not generating a test instruction next.
900
+
901
+ // Push the nth argument.
902
+ __ push(rax);
903
+
904
+ // Update the index on the stack and in register rax.
905
+ __ movq(rax, Operand(rbp, kIndexOffset));
906
+ __ SmiAddConstant(rax, rax, Smi::FromInt(1));
907
+ __ movq(Operand(rbp, kIndexOffset), rax);
908
+
909
+ __ bind(&entry);
910
+ __ cmpq(rax, Operand(rbp, kLimitOffset));
911
+ __ j(not_equal, &loop);
912
+
913
+ // Invoke the function.
914
+ ParameterCount actual(rax);
915
+ __ SmiToInteger32(rax, rax);
916
+ __ movq(rdi, Operand(rbp, kFunctionOffset));
917
+ __ InvokeFunction(rdi, actual, CALL_FUNCTION);
918
+
919
+ __ LeaveInternalFrame();
920
+ __ ret(3 * kPointerSize); // remove function, receiver, and arguments
921
+ }
922
+
923
+
924
+ // Number of empty elements to allocate for an empty array.
925
+ static const int kPreallocatedArrayElements = 4;
926
+
927
+
928
+ // Allocate an empty JSArray. The allocated array is put into the result
929
+ // register. If the parameter initial_capacity is larger than zero an elements
930
+ // backing store is allocated with this size and filled with the hole values.
931
+ // Otherwise the elements backing store is set to the empty FixedArray.
932
+ static void AllocateEmptyJSArray(MacroAssembler* masm,
933
+ Register array_function,
934
+ Register result,
935
+ Register scratch1,
936
+ Register scratch2,
937
+ Register scratch3,
938
+ int initial_capacity,
939
+ Label* gc_required) {
940
+ ASSERT(initial_capacity >= 0);
941
+
942
+ // Load the initial map from the array function.
943
+ __ movq(scratch1, FieldOperand(array_function,
944
+ JSFunction::kPrototypeOrInitialMapOffset));
945
+
946
+ // Allocate the JSArray object together with space for a fixed array with the
947
+ // requested elements.
948
+ int size = JSArray::kSize;
949
+ if (initial_capacity > 0) {
950
+ size += FixedArray::SizeFor(initial_capacity);
951
+ }
952
+ __ AllocateInNewSpace(size,
953
+ result,
954
+ scratch2,
955
+ scratch3,
956
+ gc_required,
957
+ TAG_OBJECT);
958
+
959
+ // Allocated the JSArray. Now initialize the fields except for the elements
960
+ // array.
961
+ // result: JSObject
962
+ // scratch1: initial map
963
+ // scratch2: start of next object
964
+ __ movq(FieldOperand(result, JSObject::kMapOffset), scratch1);
965
+ __ Move(FieldOperand(result, JSArray::kPropertiesOffset),
966
+ FACTORY->empty_fixed_array());
967
+ // Field JSArray::kElementsOffset is initialized later.
968
+ __ Move(FieldOperand(result, JSArray::kLengthOffset), Smi::FromInt(0));
969
+
970
+ // If no storage is requested for the elements array just set the empty
971
+ // fixed array.
972
+ if (initial_capacity == 0) {
973
+ __ Move(FieldOperand(result, JSArray::kElementsOffset),
974
+ FACTORY->empty_fixed_array());
975
+ return;
976
+ }
977
+
978
+ // Calculate the location of the elements array and set elements array member
979
+ // of the JSArray.
980
+ // result: JSObject
981
+ // scratch2: start of next object
982
+ __ lea(scratch1, Operand(result, JSArray::kSize));
983
+ __ movq(FieldOperand(result, JSArray::kElementsOffset), scratch1);
984
+
985
+ // Initialize the FixedArray and fill it with holes. FixedArray length is
986
+ // stored as a smi.
987
+ // result: JSObject
988
+ // scratch1: elements array
989
+ // scratch2: start of next object
990
+ __ Move(FieldOperand(scratch1, HeapObject::kMapOffset),
991
+ FACTORY->fixed_array_map());
992
+ __ Move(FieldOperand(scratch1, FixedArray::kLengthOffset),
993
+ Smi::FromInt(initial_capacity));
994
+
995
+ // Fill the FixedArray with the hole value. Inline the code if short.
996
+ // Reconsider loop unfolding if kPreallocatedArrayElements gets changed.
997
+ static const int kLoopUnfoldLimit = 4;
998
+ ASSERT(kPreallocatedArrayElements <= kLoopUnfoldLimit);
999
+ __ Move(scratch3, FACTORY->the_hole_value());
1000
+ if (initial_capacity <= kLoopUnfoldLimit) {
1001
+ // Use a scratch register here to have only one reloc info when unfolding
1002
+ // the loop.
1003
+ for (int i = 0; i < initial_capacity; i++) {
1004
+ __ movq(FieldOperand(scratch1,
1005
+ FixedArray::kHeaderSize + i * kPointerSize),
1006
+ scratch3);
1007
+ }
1008
+ } else {
1009
+ Label loop, entry;
1010
+ __ jmp(&entry);
1011
+ __ bind(&loop);
1012
+ __ movq(Operand(scratch1, 0), scratch3);
1013
+ __ addq(scratch1, Immediate(kPointerSize));
1014
+ __ bind(&entry);
1015
+ __ cmpq(scratch1, scratch2);
1016
+ __ j(below, &loop);
1017
+ }
1018
+ }
1019
+
1020
+
1021
+ // Allocate a JSArray with the number of elements stored in a register. The
1022
+ // register array_function holds the built-in Array function and the register
1023
+ // array_size holds the size of the array as a smi. The allocated array is put
1024
+ // into the result register and beginning and end of the FixedArray elements
1025
+ // storage is put into registers elements_array and elements_array_end (see
1026
+ // below for when that is not the case). If the parameter fill_with_holes is
1027
+ // true the allocated elements backing store is filled with the hole values
1028
+ // otherwise it is left uninitialized. When the backing store is filled the
1029
+ // register elements_array is scratched.
1030
+ static void AllocateJSArray(MacroAssembler* masm,
1031
+ Register array_function, // Array function.
1032
+ Register array_size, // As a smi.
1033
+ Register result,
1034
+ Register elements_array,
1035
+ Register elements_array_end,
1036
+ Register scratch,
1037
+ bool fill_with_hole,
1038
+ Label* gc_required) {
1039
+ Label not_empty, allocated;
1040
+
1041
+ // Load the initial map from the array function.
1042
+ __ movq(elements_array,
1043
+ FieldOperand(array_function,
1044
+ JSFunction::kPrototypeOrInitialMapOffset));
1045
+
1046
+ // Check whether an empty sized array is requested.
1047
+ __ testq(array_size, array_size);
1048
+ __ j(not_zero, &not_empty);
1049
+
1050
+ // If an empty array is requested allocate a small elements array anyway. This
1051
+ // keeps the code below free of special casing for the empty array.
1052
+ int size = JSArray::kSize + FixedArray::SizeFor(kPreallocatedArrayElements);
1053
+ __ AllocateInNewSpace(size,
1054
+ result,
1055
+ elements_array_end,
1056
+ scratch,
1057
+ gc_required,
1058
+ TAG_OBJECT);
1059
+ __ jmp(&allocated);
1060
+
1061
+ // Allocate the JSArray object together with space for a FixedArray with the
1062
+ // requested elements.
1063
+ __ bind(&not_empty);
1064
+ SmiIndex index =
1065
+ masm->SmiToIndex(kScratchRegister, array_size, kPointerSizeLog2);
1066
+ __ AllocateInNewSpace(JSArray::kSize + FixedArray::kHeaderSize,
1067
+ index.scale,
1068
+ index.reg,
1069
+ result,
1070
+ elements_array_end,
1071
+ scratch,
1072
+ gc_required,
1073
+ TAG_OBJECT);
1074
+
1075
+ // Allocated the JSArray. Now initialize the fields except for the elements
1076
+ // array.
1077
+ // result: JSObject
1078
+ // elements_array: initial map
1079
+ // elements_array_end: start of next object
1080
+ // array_size: size of array (smi)
1081
+ __ bind(&allocated);
1082
+ __ movq(FieldOperand(result, JSObject::kMapOffset), elements_array);
1083
+ __ Move(elements_array, FACTORY->empty_fixed_array());
1084
+ __ movq(FieldOperand(result, JSArray::kPropertiesOffset), elements_array);
1085
+ // Field JSArray::kElementsOffset is initialized later.
1086
+ __ movq(FieldOperand(result, JSArray::kLengthOffset), array_size);
1087
+
1088
+ // Calculate the location of the elements array and set elements array member
1089
+ // of the JSArray.
1090
+ // result: JSObject
1091
+ // elements_array_end: start of next object
1092
+ // array_size: size of array (smi)
1093
+ __ lea(elements_array, Operand(result, JSArray::kSize));
1094
+ __ movq(FieldOperand(result, JSArray::kElementsOffset), elements_array);
1095
+
1096
+ // Initialize the fixed array. FixedArray length is stored as a smi.
1097
+ // result: JSObject
1098
+ // elements_array: elements array
1099
+ // elements_array_end: start of next object
1100
+ // array_size: size of array (smi)
1101
+ __ Move(FieldOperand(elements_array, JSObject::kMapOffset),
1102
+ FACTORY->fixed_array_map());
1103
+ Label not_empty_2, fill_array;
1104
+ __ SmiTest(array_size);
1105
+ __ j(not_zero, &not_empty_2);
1106
+ // Length of the FixedArray is the number of pre-allocated elements even
1107
+ // though the actual JSArray has length 0.
1108
+ __ Move(FieldOperand(elements_array, FixedArray::kLengthOffset),
1109
+ Smi::FromInt(kPreallocatedArrayElements));
1110
+ __ jmp(&fill_array);
1111
+ __ bind(&not_empty_2);
1112
+ // For non-empty JSArrays the length of the FixedArray and the JSArray is the
1113
+ // same.
1114
+ __ movq(FieldOperand(elements_array, FixedArray::kLengthOffset), array_size);
1115
+
1116
+ // Fill the allocated FixedArray with the hole value if requested.
1117
+ // result: JSObject
1118
+ // elements_array: elements array
1119
+ // elements_array_end: start of next object
1120
+ __ bind(&fill_array);
1121
+ if (fill_with_hole) {
1122
+ Label loop, entry;
1123
+ __ Move(scratch, FACTORY->the_hole_value());
1124
+ __ lea(elements_array, Operand(elements_array,
1125
+ FixedArray::kHeaderSize - kHeapObjectTag));
1126
+ __ jmp(&entry);
1127
+ __ bind(&loop);
1128
+ __ movq(Operand(elements_array, 0), scratch);
1129
+ __ addq(elements_array, Immediate(kPointerSize));
1130
+ __ bind(&entry);
1131
+ __ cmpq(elements_array, elements_array_end);
1132
+ __ j(below, &loop);
1133
+ }
1134
+ }
1135
+
1136
+
1137
+ // Create a new array for the built-in Array function. This function allocates
1138
+ // the JSArray object and the FixedArray elements array and initializes these.
1139
+ // If the Array cannot be constructed in native code the runtime is called. This
1140
+ // function assumes the following state:
1141
+ // rdi: constructor (built-in Array function)
1142
+ // rax: argc
1143
+ // rsp[0]: return address
1144
+ // rsp[8]: last argument
1145
+ // This function is used for both construct and normal calls of Array. The only
1146
+ // difference between handling a construct call and a normal call is that for a
1147
+ // construct call the constructor function in rdi needs to be preserved for
1148
+ // entering the generic code. In both cases argc in rax needs to be preserved.
1149
+ // Both registers are preserved by this code so no need to differentiate between
1150
+ // a construct call and a normal call.
1151
+ static void ArrayNativeCode(MacroAssembler* masm,
1152
+ Label *call_generic_code) {
1153
+ Label argc_one_or_more, argc_two_or_more;
1154
+
1155
+ // Check for array construction with zero arguments.
1156
+ __ testq(rax, rax);
1157
+ __ j(not_zero, &argc_one_or_more);
1158
+
1159
+ // Handle construction of an empty array.
1160
+ AllocateEmptyJSArray(masm,
1161
+ rdi,
1162
+ rbx,
1163
+ rcx,
1164
+ rdx,
1165
+ r8,
1166
+ kPreallocatedArrayElements,
1167
+ call_generic_code);
1168
+ Counters* counters = masm->isolate()->counters();
1169
+ __ IncrementCounter(counters->array_function_native(), 1);
1170
+ __ movq(rax, rbx);
1171
+ __ ret(kPointerSize);
1172
+
1173
+ // Check for one argument. Bail out if argument is not smi or if it is
1174
+ // negative.
1175
+ __ bind(&argc_one_or_more);
1176
+ __ cmpq(rax, Immediate(1));
1177
+ __ j(not_equal, &argc_two_or_more);
1178
+ __ movq(rdx, Operand(rsp, kPointerSize)); // Get the argument from the stack.
1179
+ __ JumpUnlessNonNegativeSmi(rdx, call_generic_code);
1180
+
1181
+ // Handle construction of an empty array of a certain size. Bail out if size
1182
+ // is to large to actually allocate an elements array.
1183
+ __ SmiCompare(rdx, Smi::FromInt(JSObject::kInitialMaxFastElementArray));
1184
+ __ j(greater_equal, call_generic_code);
1185
+
1186
+ // rax: argc
1187
+ // rdx: array_size (smi)
1188
+ // rdi: constructor
1189
+ // esp[0]: return address
1190
+ // esp[8]: argument
1191
+ AllocateJSArray(masm,
1192
+ rdi,
1193
+ rdx,
1194
+ rbx,
1195
+ rcx,
1196
+ r8,
1197
+ r9,
1198
+ true,
1199
+ call_generic_code);
1200
+ __ IncrementCounter(counters->array_function_native(), 1);
1201
+ __ movq(rax, rbx);
1202
+ __ ret(2 * kPointerSize);
1203
+
1204
+ // Handle construction of an array from a list of arguments.
1205
+ __ bind(&argc_two_or_more);
1206
+ __ movq(rdx, rax);
1207
+ __ Integer32ToSmi(rdx, rdx); // Convet argc to a smi.
1208
+ // rax: argc
1209
+ // rdx: array_size (smi)
1210
+ // rdi: constructor
1211
+ // esp[0] : return address
1212
+ // esp[8] : last argument
1213
+ AllocateJSArray(masm,
1214
+ rdi,
1215
+ rdx,
1216
+ rbx,
1217
+ rcx,
1218
+ r8,
1219
+ r9,
1220
+ false,
1221
+ call_generic_code);
1222
+ __ IncrementCounter(counters->array_function_native(), 1);
1223
+
1224
+ // rax: argc
1225
+ // rbx: JSArray
1226
+ // rcx: elements_array
1227
+ // r8: elements_array_end (untagged)
1228
+ // esp[0]: return address
1229
+ // esp[8]: last argument
1230
+
1231
+ // Location of the last argument
1232
+ __ lea(r9, Operand(rsp, kPointerSize));
1233
+
1234
+ // Location of the first array element (Parameter fill_with_holes to
1235
+ // AllocateJSArrayis false, so the FixedArray is returned in rcx).
1236
+ __ lea(rdx, Operand(rcx, FixedArray::kHeaderSize - kHeapObjectTag));
1237
+
1238
+ // rax: argc
1239
+ // rbx: JSArray
1240
+ // rdx: location of the first array element
1241
+ // r9: location of the last argument
1242
+ // esp[0]: return address
1243
+ // esp[8]: last argument
1244
+ Label loop, entry;
1245
+ __ movq(rcx, rax);
1246
+ __ jmp(&entry);
1247
+ __ bind(&loop);
1248
+ __ movq(kScratchRegister, Operand(r9, rcx, times_pointer_size, 0));
1249
+ __ movq(Operand(rdx, 0), kScratchRegister);
1250
+ __ addq(rdx, Immediate(kPointerSize));
1251
+ __ bind(&entry);
1252
+ __ decq(rcx);
1253
+ __ j(greater_equal, &loop);
1254
+
1255
+ // Remove caller arguments from the stack and return.
1256
+ // rax: argc
1257
+ // rbx: JSArray
1258
+ // esp[0]: return address
1259
+ // esp[8]: last argument
1260
+ __ pop(rcx);
1261
+ __ lea(rsp, Operand(rsp, rax, times_pointer_size, 1 * kPointerSize));
1262
+ __ push(rcx);
1263
+ __ movq(rax, rbx);
1264
+ __ ret(0);
1265
+ }
1266
+
1267
+
1268
+ void Builtins::Generate_ArrayCode(MacroAssembler* masm) {
1269
+ // ----------- S t a t e -------------
1270
+ // -- rax : argc
1271
+ // -- rsp[0] : return address
1272
+ // -- rsp[8] : last argument
1273
+ // -----------------------------------
1274
+ Label generic_array_code;
1275
+
1276
+ // Get the Array function.
1277
+ __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, rdi);
1278
+
1279
+ if (FLAG_debug_code) {
1280
+ // Initial map for the builtin Array functions should be maps.
1281
+ __ movq(rbx, FieldOperand(rdi, JSFunction::kPrototypeOrInitialMapOffset));
1282
+ // Will both indicate a NULL and a Smi.
1283
+ ASSERT(kSmiTag == 0);
1284
+ Condition not_smi = NegateCondition(masm->CheckSmi(rbx));
1285
+ __ Check(not_smi, "Unexpected initial map for Array function");
1286
+ __ CmpObjectType(rbx, MAP_TYPE, rcx);
1287
+ __ Check(equal, "Unexpected initial map for Array function");
1288
+ }
1289
+
1290
+ // Run the native code for the Array function called as a normal function.
1291
+ ArrayNativeCode(masm, &generic_array_code);
1292
+
1293
+ // Jump to the generic array code in case the specialized code cannot handle
1294
+ // the construction.
1295
+ __ bind(&generic_array_code);
1296
+ Handle<Code> array_code =
1297
+ masm->isolate()->builtins()->ArrayCodeGeneric();
1298
+ __ Jump(array_code, RelocInfo::CODE_TARGET);
1299
+ }
1300
+
1301
+
1302
+ void Builtins::Generate_ArrayConstructCode(MacroAssembler* masm) {
1303
+ // ----------- S t a t e -------------
1304
+ // -- rax : argc
1305
+ // -- rdi : constructor
1306
+ // -- rsp[0] : return address
1307
+ // -- rsp[8] : last argument
1308
+ // -----------------------------------
1309
+ Label generic_constructor;
1310
+
1311
+ if (FLAG_debug_code) {
1312
+ // The array construct code is only set for the builtin and internal
1313
+ // Array functions which always have a map.
1314
+ // Initial map for the builtin Array function should be a map.
1315
+ __ movq(rbx, FieldOperand(rdi, JSFunction::kPrototypeOrInitialMapOffset));
1316
+ // Will both indicate a NULL and a Smi.
1317
+ ASSERT(kSmiTag == 0);
1318
+ Condition not_smi = NegateCondition(masm->CheckSmi(rbx));
1319
+ __ Check(not_smi, "Unexpected initial map for Array function");
1320
+ __ CmpObjectType(rbx, MAP_TYPE, rcx);
1321
+ __ Check(equal, "Unexpected initial map for Array function");
1322
+ }
1323
+
1324
+ // Run the native code for the Array function called as constructor.
1325
+ ArrayNativeCode(masm, &generic_constructor);
1326
+
1327
+ // Jump to the generic construct code in case the specialized code cannot
1328
+ // handle the construction.
1329
+ __ bind(&generic_constructor);
1330
+ Handle<Code> generic_construct_stub =
1331
+ masm->isolate()->builtins()->JSConstructStubGeneric();
1332
+ __ Jump(generic_construct_stub, RelocInfo::CODE_TARGET);
1333
+ }
1334
+
1335
+
1336
+ void Builtins::Generate_StringConstructCode(MacroAssembler* masm) {
1337
+ // TODO(849): implement custom construct stub.
1338
+ // Generate a copy of the generic stub for now.
1339
+ Generate_JSConstructStubGeneric(masm);
1340
+ }
1341
+
1342
+
1343
+ static void EnterArgumentsAdaptorFrame(MacroAssembler* masm) {
1344
+ __ push(rbp);
1345
+ __ movq(rbp, rsp);
1346
+
1347
+ // Store the arguments adaptor context sentinel.
1348
+ __ Push(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR));
1349
+
1350
+ // Push the function on the stack.
1351
+ __ push(rdi);
1352
+
1353
+ // Preserve the number of arguments on the stack. Must preserve rax,
1354
+ // rbx and rcx because these registers are used when copying the
1355
+ // arguments and the receiver.
1356
+ __ Integer32ToSmi(r8, rax);
1357
+ __ push(r8);
1358
+ }
1359
+
1360
+
1361
+ static void LeaveArgumentsAdaptorFrame(MacroAssembler* masm) {
1362
+ // Retrieve the number of arguments from the stack. Number is a Smi.
1363
+ __ movq(rbx, Operand(rbp, ArgumentsAdaptorFrameConstants::kLengthOffset));
1364
+
1365
+ // Leave the frame.
1366
+ __ movq(rsp, rbp);
1367
+ __ pop(rbp);
1368
+
1369
+ // Remove caller arguments from the stack.
1370
+ __ pop(rcx);
1371
+ SmiIndex index = masm->SmiToIndex(rbx, rbx, kPointerSizeLog2);
1372
+ __ lea(rsp, Operand(rsp, index.reg, index.scale, 1 * kPointerSize));
1373
+ __ push(rcx);
1374
+ }
1375
+
1376
+
1377
+ void Builtins::Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm) {
1378
+ // ----------- S t a t e -------------
1379
+ // -- rax : actual number of arguments
1380
+ // -- rbx : expected number of arguments
1381
+ // -- rcx : call kind information
1382
+ // -- rdx : code entry to call
1383
+ // -----------------------------------
1384
+
1385
+ Label invoke, dont_adapt_arguments;
1386
+ Counters* counters = masm->isolate()->counters();
1387
+ __ IncrementCounter(counters->arguments_adaptors(), 1);
1388
+
1389
+ Label enough, too_few;
1390
+ __ cmpq(rax, rbx);
1391
+ __ j(less, &too_few);
1392
+ __ cmpq(rbx, Immediate(SharedFunctionInfo::kDontAdaptArgumentsSentinel));
1393
+ __ j(equal, &dont_adapt_arguments);
1394
+
1395
+ { // Enough parameters: Actual >= expected.
1396
+ __ bind(&enough);
1397
+ EnterArgumentsAdaptorFrame(masm);
1398
+
1399
+ // Copy receiver and all expected arguments.
1400
+ const int offset = StandardFrameConstants::kCallerSPOffset;
1401
+ __ lea(rax, Operand(rbp, rax, times_pointer_size, offset));
1402
+ __ Set(r8, -1); // account for receiver
1403
+
1404
+ Label copy;
1405
+ __ bind(&copy);
1406
+ __ incq(r8);
1407
+ __ push(Operand(rax, 0));
1408
+ __ subq(rax, Immediate(kPointerSize));
1409
+ __ cmpq(r8, rbx);
1410
+ __ j(less, &copy);
1411
+ __ jmp(&invoke);
1412
+ }
1413
+
1414
+ { // Too few parameters: Actual < expected.
1415
+ __ bind(&too_few);
1416
+ EnterArgumentsAdaptorFrame(masm);
1417
+
1418
+ // Copy receiver and all actual arguments.
1419
+ const int offset = StandardFrameConstants::kCallerSPOffset;
1420
+ __ lea(rdi, Operand(rbp, rax, times_pointer_size, offset));
1421
+ __ Set(r8, -1); // account for receiver
1422
+
1423
+ Label copy;
1424
+ __ bind(&copy);
1425
+ __ incq(r8);
1426
+ __ push(Operand(rdi, 0));
1427
+ __ subq(rdi, Immediate(kPointerSize));
1428
+ __ cmpq(r8, rax);
1429
+ __ j(less, &copy);
1430
+
1431
+ // Fill remaining expected arguments with undefined values.
1432
+ Label fill;
1433
+ __ LoadRoot(kScratchRegister, Heap::kUndefinedValueRootIndex);
1434
+ __ bind(&fill);
1435
+ __ incq(r8);
1436
+ __ push(kScratchRegister);
1437
+ __ cmpq(r8, rbx);
1438
+ __ j(less, &fill);
1439
+
1440
+ // Restore function pointer.
1441
+ __ movq(rdi, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset));
1442
+ }
1443
+
1444
+ // Call the entry point.
1445
+ __ bind(&invoke);
1446
+ __ call(rdx);
1447
+
1448
+ // Leave frame and return.
1449
+ LeaveArgumentsAdaptorFrame(masm);
1450
+ __ ret(0);
1451
+
1452
+ // -------------------------------------------
1453
+ // Dont adapt arguments.
1454
+ // -------------------------------------------
1455
+ __ bind(&dont_adapt_arguments);
1456
+ __ jmp(rdx);
1457
+ }
1458
+
1459
+
1460
+ void Builtins::Generate_OnStackReplacement(MacroAssembler* masm) {
1461
+ // Get the loop depth of the stack guard check. This is recorded in
1462
+ // a test(rax, depth) instruction right after the call.
1463
+ Label stack_check;
1464
+ __ movq(rbx, Operand(rsp, 0)); // return address
1465
+ __ movzxbq(rbx, Operand(rbx, 1)); // depth
1466
+
1467
+ // Get the loop nesting level at which we allow OSR from the
1468
+ // unoptimized code and check if we want to do OSR yet. If not we
1469
+ // should perform a stack guard check so we can get interrupts while
1470
+ // waiting for on-stack replacement.
1471
+ __ movq(rax, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset));
1472
+ __ movq(rcx, FieldOperand(rax, JSFunction::kSharedFunctionInfoOffset));
1473
+ __ movq(rcx, FieldOperand(rcx, SharedFunctionInfo::kCodeOffset));
1474
+ __ cmpb(rbx, FieldOperand(rcx, Code::kAllowOSRAtLoopNestingLevelOffset));
1475
+ __ j(greater, &stack_check);
1476
+
1477
+ // Pass the function to optimize as the argument to the on-stack
1478
+ // replacement runtime function.
1479
+ __ EnterInternalFrame();
1480
+ __ push(rax);
1481
+ __ CallRuntime(Runtime::kCompileForOnStackReplacement, 1);
1482
+ __ LeaveInternalFrame();
1483
+
1484
+ // If the result was -1 it means that we couldn't optimize the
1485
+ // function. Just return and continue in the unoptimized version.
1486
+ Label skip;
1487
+ __ SmiCompare(rax, Smi::FromInt(-1));
1488
+ __ j(not_equal, &skip, Label::kNear);
1489
+ __ ret(0);
1490
+
1491
+ // If we decide not to perform on-stack replacement we perform a
1492
+ // stack guard check to enable interrupts.
1493
+ __ bind(&stack_check);
1494
+ Label ok;
1495
+ __ CompareRoot(rsp, Heap::kStackLimitRootIndex);
1496
+ __ j(above_equal, &ok, Label::kNear);
1497
+
1498
+ StackCheckStub stub;
1499
+ __ TailCallStub(&stub);
1500
+ __ Abort("Unreachable code: returned from tail call.");
1501
+ __ bind(&ok);
1502
+ __ ret(0);
1503
+
1504
+ __ bind(&skip);
1505
+ // Untag the AST id and push it on the stack.
1506
+ __ SmiToInteger32(rax, rax);
1507
+ __ push(rax);
1508
+
1509
+ // Generate the code for doing the frame-to-frame translation using
1510
+ // the deoptimizer infrastructure.
1511
+ Deoptimizer::EntryGenerator generator(masm, Deoptimizer::OSR);
1512
+ generator.Generate();
1513
+ }
1514
+
1515
+
1516
+ #undef __
1517
+
1518
+ } } // namespace v8::internal
1519
+
1520
+ #endif // V8_TARGET_ARCH_X64