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(SetUpKind set_up_kind) { |
1837 ASSERT(!initialized_); | 1841 ASSERT(!initialized_ || set_up_kind == AFTER_DESERIALIZATION); |
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 (set_up_kind == AFTER_DESERIALIZATION && functions[i].in_snapshot) { |
1855 MacroAssembler masm(isolate, u.buffer, sizeof u.buffer); | 1859 // This builtin was deserialized from the snapshot. |
1856 // Generate the code/adaptor. | 1860 ASSERT(builtins_[i] != NULL); |
1857 typedef void (*Generator)(MacroAssembler*, int, BuiltinExtraArguments); | 1861 continue; |
1858 Generator g = FUNCTION_CAST<Generator>(functions[i].generator); | 1862 } |
1859 // We pass all arguments to the generator, but it may not use all of | 1863 |
1860 // them. This works because the first arguments are on top of the | 1864 if (set_up_kind == FOR_SNAPSHOT && !functions[i].in_snapshot) { |
1861 // stack. | 1865 // This builtin should not be included in the snapshot. |
1862 ASSERT(!masm.has_frame()); | 1866 builtins_[i] = NULL; |
1863 g(&masm, functions[i].name, functions[i].extra_args); | 1867 continue; |
1864 // Move the code into the object heap. | 1868 } |
1865 CodeDesc desc; | 1869 |
1866 masm.GetCode(&desc); | 1870 names_[i] = functions[i].s_name; |
1867 Code::Flags flags = functions[i].flags; | 1871 |
1868 Object* code = NULL; | 1872 if (set_up_kind == BEFORE_DESERIALIZATION) { |
1869 { | 1873 builtins_[i] = NULL; |
1870 // During startup it's OK to always allocate and defer GC to later. | 1874 continue; |
1871 // This simplifies things because we don't need to retry. | 1875 } |
1872 AlwaysAllocateScope __scope__; | 1876 |
1873 { MaybeObject* maybe_code = | 1877 MacroAssembler masm(isolate, u.buffer, sizeof u.buffer); |
1874 heap->CreateCode(desc, flags, masm.CodeObject()); | 1878 // Generate the code/adaptor. |
1875 if (!maybe_code->ToObject(&code)) { | 1879 typedef void (*Generator)(MacroAssembler*, int, BuiltinExtraArguments); |
1876 v8::internal::V8::FatalProcessOutOfMemory("CreateCode"); | 1880 Generator g = FUNCTION_CAST<Generator>(functions[i].generator); |
1877 } | 1881 // We pass all arguments to the generator, but it may not use all of |
| 1882 // them. This works because the first arguments are on top of the |
| 1883 // stack. |
| 1884 ASSERT(!masm.has_frame()); |
| 1885 g(&masm, functions[i].name, functions[i].extra_args); |
| 1886 // Move the code into the object heap. |
| 1887 CodeDesc desc; |
| 1888 masm.GetCode(&desc); |
| 1889 Code::Flags flags = functions[i].flags; |
| 1890 Object* code = NULL; |
| 1891 { |
| 1892 // During startup it's OK to always allocate and defer GC to later. |
| 1893 // This simplifies things because we don't need to retry. |
| 1894 AlwaysAllocateScope __scope__; |
| 1895 { MaybeObject* maybe_code = |
| 1896 heap->CreateCode(desc, flags, masm.CodeObject()); |
| 1897 if (!maybe_code->ToObject(&code)) { |
| 1898 v8::internal::V8::FatalProcessOutOfMemory("CreateCode"); |
1878 } | 1899 } |
1879 } | 1900 } |
1880 // Log the event and add the code to the builtins array. | 1901 } |
1881 PROFILE(isolate, | 1902 // Log the event and add the code to the builtins array. |
1882 CodeCreateEvent(Logger::BUILTIN_TAG, | 1903 PROFILE(isolate, |
1883 Code::cast(code), | 1904 CodeCreateEvent(Logger::BUILTIN_TAG, |
1884 functions[i].s_name)); | 1905 Code::cast(code), |
1885 GDBJIT(AddCode(GDBJITInterface::BUILTIN, | 1906 functions[i].s_name)); |
1886 functions[i].s_name, | 1907 GDBJIT(AddCode(GDBJITInterface::BUILTIN, |
1887 Code::cast(code))); | 1908 functions[i].s_name, |
1888 builtins_[i] = code; | 1909 Code::cast(code))); |
| 1910 builtins_[i] = code; |
1889 #ifdef ENABLE_DISASSEMBLER | 1911 #ifdef ENABLE_DISASSEMBLER |
1890 if (FLAG_print_builtin_code) { | 1912 if (FLAG_print_builtin_code) { |
1891 PrintF("Builtin: %s\n", functions[i].s_name); | 1913 PrintF("Builtin: %s\n", functions[i].s_name); |
1892 Code::cast(code)->Disassemble(functions[i].s_name); | 1914 Code::cast(code)->Disassemble(functions[i].s_name); |
1893 PrintF("\n"); | 1915 PrintF("\n"); |
1894 } | 1916 } |
1895 #endif | 1917 #endif |
1896 } else { | |
1897 // Deserializing. The values will be filled in during IterateBuiltins. | |
1898 builtins_[i] = NULL; | |
1899 } | |
1900 names_[i] = functions[i].s_name; | 1918 names_[i] = functions[i].s_name; |
1901 } | 1919 } |
1902 | 1920 |
1903 // Mark as initialized. | 1921 // Mark as initialized. |
1904 initialized_ = true; | 1922 initialized_ = true; |
1905 } | 1923 } |
1906 | 1924 |
1907 | 1925 |
1908 void Builtins::TearDown() { | 1926 void Builtins::TearDown() { |
1909 initialized_ = false; | 1927 initialized_ = false; |
(...skipping 18 matching lines...) Expand all Loading... |
1928 return NULL; | 1946 return NULL; |
1929 } | 1947 } |
1930 | 1948 |
1931 | 1949 |
1932 #define DEFINE_BUILTIN_ACCESSOR_C(name, ignore) \ | 1950 #define DEFINE_BUILTIN_ACCESSOR_C(name, ignore) \ |
1933 Handle<Code> Builtins::name() { \ | 1951 Handle<Code> Builtins::name() { \ |
1934 Code** code_address = \ | 1952 Code** code_address = \ |
1935 reinterpret_cast<Code**>(builtin_address(k##name)); \ | 1953 reinterpret_cast<Code**>(builtin_address(k##name)); \ |
1936 return Handle<Code>(code_address); \ | 1954 return Handle<Code>(code_address); \ |
1937 } | 1955 } |
1938 #define DEFINE_BUILTIN_ACCESSOR_A(name, kind, state, extra) \ | 1956 #define DEFINE_BUILTIN_ACCESSOR_A(name, kind, state, extra, extra2) \ |
1939 Handle<Code> Builtins::name() { \ | 1957 Handle<Code> Builtins::name() { \ |
1940 Code** code_address = \ | 1958 Code** code_address = \ |
1941 reinterpret_cast<Code**>(builtin_address(k##name)); \ | 1959 reinterpret_cast<Code**>(builtin_address(k##name)); \ |
1942 return Handle<Code>(code_address); \ | 1960 return Handle<Code>(code_address); \ |
1943 } | 1961 } |
1944 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) | 1962 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) |
1945 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) | 1963 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) |
1946 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) | 1964 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) |
1947 #undef DEFINE_BUILTIN_ACCESSOR_C | 1965 #undef DEFINE_BUILTIN_ACCESSOR_C |
1948 #undef DEFINE_BUILTIN_ACCESSOR_A | 1966 #undef DEFINE_BUILTIN_ACCESSOR_A |
1949 | 1967 |
1950 | 1968 |
1951 } } // namespace v8::internal | 1969 } } // namespace v8::internal |
OLD | NEW |