OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 1754 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1765 #undef DEF_JS_NAME | 1765 #undef DEF_JS_NAME |
1766 #undef DEF_JS_ARGC | 1766 #undef DEF_JS_ARGC |
1767 | 1767 |
1768 struct BuiltinDesc { | 1768 struct BuiltinDesc { |
1769 byte* generator; | 1769 byte* generator; |
1770 byte* c_code; | 1770 byte* c_code; |
1771 const char* s_name; // name is only used for generating log information. | 1771 const char* s_name; // name is only used for generating log information. |
1772 int name; | 1772 int name; |
1773 Code::Flags flags; | 1773 Code::Flags flags; |
1774 BuiltinExtraArguments extra_args; | 1774 BuiltinExtraArguments extra_args; |
| 1775 bool in_snapshot; // whether this builtin should be included in snapshot. |
1775 }; | 1776 }; |
1776 | 1777 |
1777 #define BUILTIN_FUNCTION_TABLE_INIT { V8_ONCE_INIT, {} } | 1778 #define BUILTIN_FUNCTION_TABLE_INIT { V8_ONCE_INIT, {} } |
1778 | 1779 |
1779 class BuiltinFunctionTable { | 1780 class BuiltinFunctionTable { |
1780 public: | 1781 public: |
1781 BuiltinDesc* functions() { | 1782 BuiltinDesc* functions() { |
1782 CallOnce(&once_, &Builtins::InitBuiltinFunctionTable); | 1783 CallOnce(&once_, &Builtins::InitBuiltinFunctionTable); |
1783 return functions_; | 1784 return functions_; |
1784 } | 1785 } |
(...skipping 12 matching lines...) Expand all Loading... |
1797 // within the lexical scope of Builtins:: and within a context where | 1798 // within the lexical scope of Builtins:: and within a context where |
1798 // Code::Flags names a non-abstract type. | 1799 // Code::Flags names a non-abstract type. |
1799 void Builtins::InitBuiltinFunctionTable() { | 1800 void Builtins::InitBuiltinFunctionTable() { |
1800 BuiltinDesc* functions = builtin_function_table.functions_; | 1801 BuiltinDesc* functions = builtin_function_table.functions_; |
1801 functions[builtin_count].generator = NULL; | 1802 functions[builtin_count].generator = NULL; |
1802 functions[builtin_count].c_code = NULL; | 1803 functions[builtin_count].c_code = NULL; |
1803 functions[builtin_count].s_name = NULL; | 1804 functions[builtin_count].s_name = NULL; |
1804 functions[builtin_count].name = builtin_count; | 1805 functions[builtin_count].name = builtin_count; |
1805 functions[builtin_count].flags = static_cast<Code::Flags>(0); | 1806 functions[builtin_count].flags = static_cast<Code::Flags>(0); |
1806 functions[builtin_count].extra_args = NO_EXTRA_ARGUMENTS; | 1807 functions[builtin_count].extra_args = NO_EXTRA_ARGUMENTS; |
| 1808 functions[builtin_count].in_snapshot = false; |
1807 | 1809 |
1808 #define DEF_FUNCTION_PTR_C(aname, aextra_args) \ | 1810 #define DEF_FUNCTION_PTR_C(aname, aextra_args) \ |
1809 functions->generator = FUNCTION_ADDR(Generate_Adaptor); \ | 1811 functions->generator = FUNCTION_ADDR(Generate_Adaptor); \ |
1810 functions->c_code = FUNCTION_ADDR(Builtin_##aname); \ | 1812 functions->c_code = FUNCTION_ADDR(Builtin_##aname); \ |
1811 functions->s_name = #aname; \ | 1813 functions->s_name = #aname; \ |
1812 functions->name = c_##aname; \ | 1814 functions->name = c_##aname; \ |
1813 functions->flags = Code::ComputeFlags(Code::BUILTIN); \ | 1815 functions->flags = Code::ComputeFlags(Code::BUILTIN); \ |
1814 functions->extra_args = aextra_args; \ | 1816 functions->extra_args = aextra_args; \ |
| 1817 functions->in_snapshot = true; \ |
1815 ++functions; | 1818 ++functions; |
1816 | 1819 |
1817 #define DEF_FUNCTION_PTR_A(aname, kind, state, extra) \ | 1820 #define DEF_FUNCTION_PTR_A(aname, kind, state, extra, in_snapshot_arg) \ |
1818 functions->generator = FUNCTION_ADDR(Generate_##aname); \ | 1821 functions->generator = FUNCTION_ADDR(Generate_##aname); \ |
1819 functions->c_code = NULL; \ | 1822 functions->c_code = NULL; \ |
1820 functions->s_name = #aname; \ | 1823 functions->s_name = #aname; \ |
1821 functions->name = k##aname; \ | 1824 functions->name = k##aname; \ |
1822 functions->flags = Code::ComputeFlags(Code::kind, \ | 1825 functions->flags = Code::ComputeFlags(Code::kind, \ |
1823 state, \ | 1826 state, \ |
1824 extra); \ | 1827 extra); \ |
1825 functions->extra_args = NO_EXTRA_ARGUMENTS; \ | 1828 functions->extra_args = NO_EXTRA_ARGUMENTS; \ |
| 1829 functions->in_snapshot = (in_snapshot_arg == IN_SNAPSHOT); \ |
1826 ++functions; | 1830 ++functions; |
1827 | 1831 |
1828 BUILTIN_LIST_C(DEF_FUNCTION_PTR_C) | 1832 BUILTIN_LIST_C(DEF_FUNCTION_PTR_C) |
1829 BUILTIN_LIST_A(DEF_FUNCTION_PTR_A) | 1833 BUILTIN_LIST_A(DEF_FUNCTION_PTR_A) |
1830 BUILTIN_LIST_DEBUG_A(DEF_FUNCTION_PTR_A) | 1834 BUILTIN_LIST_DEBUG_A(DEF_FUNCTION_PTR_A) |
1831 | 1835 |
1832 #undef DEF_FUNCTION_PTR_C | 1836 #undef DEF_FUNCTION_PTR_C |
1833 #undef DEF_FUNCTION_PTR_A | 1837 #undef DEF_FUNCTION_PTR_A |
1834 } | 1838 } |
1835 | 1839 |
1836 void Builtins::SetUp(bool create_heap_objects) { | 1840 void Builtins::SetUp(bool create_heap_objects, bool after_serialization) { |
1837 ASSERT(!initialized_); | 1841 ASSERT(!initialized_ || after_serialization); |
1838 Isolate* isolate = Isolate::Current(); | 1842 Isolate* isolate = Isolate::Current(); |
1839 Heap* heap = isolate->heap(); | 1843 Heap* heap = isolate->heap(); |
1840 | 1844 |
1841 // Create a scope for the handles in the builtins. | 1845 // Create a scope for the handles in the builtins. |
1842 HandleScope scope(isolate); | 1846 HandleScope scope(isolate); |
1843 | 1847 |
1844 const BuiltinDesc* functions = builtin_function_table.functions(); | 1848 const BuiltinDesc* functions = builtin_function_table.functions(); |
1845 | 1849 |
1846 // For now we generate builtin adaptor code into a stack-allocated | 1850 // For now we generate builtin adaptor code into a stack-allocated |
1847 // buffer, before copying it into individual code objects. Be careful | 1851 // buffer, before copying it into individual code objects. Be careful |
1848 // with alignment, some platforms don't like unaligned code. | 1852 // with alignment, some platforms don't like unaligned code. |
1849 union { int force_alignment; byte buffer[8*KB]; } u; | 1853 union { int force_alignment; byte buffer[8*KB]; } u; |
1850 | 1854 |
1851 // Traverse the list of builtins and generate an adaptor in a | 1855 // Traverse the list of builtins and generate an adaptor in a |
1852 // separate code object for each one. | 1856 // separate code object for each one. |
1853 for (int i = 0; i < builtin_count; i++) { | 1857 for (int i = 0; i < builtin_count; i++) { |
1854 if (create_heap_objects) { | 1858 if (after_serialization && functions[i].in_snapshot) { |
| 1859 // This builtin has already been generated. |
| 1860 continue; |
| 1861 } |
| 1862 |
| 1863 if (create_heap_objects || |
| 1864 (after_serialization && !functions[i].in_snapshot)) { |
| 1865 if (!after_serialization && !functions[i].in_snapshot) { |
| 1866 // This builtin should not be included in the snapshot. |
| 1867 continue; |
| 1868 } |
| 1869 |
1855 MacroAssembler masm(isolate, u.buffer, sizeof u.buffer); | 1870 MacroAssembler masm(isolate, u.buffer, sizeof u.buffer); |
1856 // Generate the code/adaptor. | 1871 // Generate the code/adaptor. |
1857 typedef void (*Generator)(MacroAssembler*, int, BuiltinExtraArguments); | 1872 typedef void (*Generator)(MacroAssembler*, int, BuiltinExtraArguments); |
1858 Generator g = FUNCTION_CAST<Generator>(functions[i].generator); | 1873 Generator g = FUNCTION_CAST<Generator>(functions[i].generator); |
1859 // We pass all arguments to the generator, but it may not use all of | 1874 // We pass all arguments to the generator, but it may not use all of |
1860 // them. This works because the first arguments are on top of the | 1875 // them. This works because the first arguments are on top of the |
1861 // stack. | 1876 // stack. |
1862 ASSERT(!masm.has_frame()); | 1877 ASSERT(!masm.has_frame()); |
1863 g(&masm, functions[i].name, functions[i].extra_args); | 1878 g(&masm, functions[i].name, functions[i].extra_args); |
1864 // Move the code into the object heap. | 1879 // Move the code into the object heap. |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1928 return NULL; | 1943 return NULL; |
1929 } | 1944 } |
1930 | 1945 |
1931 | 1946 |
1932 #define DEFINE_BUILTIN_ACCESSOR_C(name, ignore) \ | 1947 #define DEFINE_BUILTIN_ACCESSOR_C(name, ignore) \ |
1933 Handle<Code> Builtins::name() { \ | 1948 Handle<Code> Builtins::name() { \ |
1934 Code** code_address = \ | 1949 Code** code_address = \ |
1935 reinterpret_cast<Code**>(builtin_address(k##name)); \ | 1950 reinterpret_cast<Code**>(builtin_address(k##name)); \ |
1936 return Handle<Code>(code_address); \ | 1951 return Handle<Code>(code_address); \ |
1937 } | 1952 } |
1938 #define DEFINE_BUILTIN_ACCESSOR_A(name, kind, state, extra) \ | 1953 #define DEFINE_BUILTIN_ACCESSOR_A(name, kind, state, extra, extra2) \ |
1939 Handle<Code> Builtins::name() { \ | 1954 Handle<Code> Builtins::name() { \ |
1940 Code** code_address = \ | 1955 Code** code_address = \ |
1941 reinterpret_cast<Code**>(builtin_address(k##name)); \ | 1956 reinterpret_cast<Code**>(builtin_address(k##name)); \ |
1942 return Handle<Code>(code_address); \ | 1957 return Handle<Code>(code_address); \ |
1943 } | 1958 } |
1944 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) | 1959 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) |
1945 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) | 1960 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) |
1946 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) | 1961 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) |
1947 #undef DEFINE_BUILTIN_ACCESSOR_C | 1962 #undef DEFINE_BUILTIN_ACCESSOR_C |
1948 #undef DEFINE_BUILTIN_ACCESSOR_A | 1963 #undef DEFINE_BUILTIN_ACCESSOR_A |
1949 | 1964 |
1950 | 1965 |
1951 } } // namespace v8::internal | 1966 } } // namespace v8::internal |
OLD | NEW |