| 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 1270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1281 JUMP_FUNCTION, NullCallWrapper()); | 1281 JUMP_FUNCTION, NullCallWrapper()); |
| 1282 } | 1282 } |
| 1283 | 1283 |
| 1284 | 1284 |
| 1285 Handle<Code> CallStubCompiler::CompileCallConstant( | 1285 Handle<Code> CallStubCompiler::CompileCallConstant( |
| 1286 Handle<Object> object, | 1286 Handle<Object> object, |
| 1287 Handle<JSObject> holder, | 1287 Handle<JSObject> holder, |
| 1288 Handle<Name> name, | 1288 Handle<Name> name, |
| 1289 CheckType check, | 1289 CheckType check, |
| 1290 Handle<JSFunction> function) { | 1290 Handle<JSFunction> function) { |
| 1291 if (HasCustomCallGenerator(function)) { | |
| 1292 Handle<Code> code = CompileCustomCall(object, holder, | |
| 1293 Handle<Cell>::null(), | |
| 1294 function, Handle<String>::cast(name), | |
| 1295 Code::FAST); | |
| 1296 // A null handle means bail out to the regular compiler code below. | |
| 1297 if (!code.is_null()) return code; | |
| 1298 } | |
| 1299 | |
| 1300 Label miss; | 1291 Label miss; |
| 1301 HandlerFrontendHeader(object, holder, name, check, &miss); | 1292 HandlerFrontendHeader(object, holder, name, check, &miss); |
| 1302 GenerateJumpFunction(object, function); | 1293 GenerateJumpFunction(object, function); |
| 1303 HandlerFrontendFooter(&miss); | 1294 HandlerFrontendFooter(&miss); |
| 1304 | 1295 |
| 1305 // Return the generated code. | 1296 // Return the generated code. |
| 1306 return GetCode(function); | 1297 return GetCode(function); |
| 1307 } | 1298 } |
| 1308 | 1299 |
| 1309 | 1300 |
| (...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1870 Code::Kind kind, | 1861 Code::Kind kind, |
| 1871 ExtraICState extra_state, | 1862 ExtraICState extra_state, |
| 1872 InlineCacheHolderFlag cache_holder) | 1863 InlineCacheHolderFlag cache_holder) |
| 1873 : StubCompiler(isolate, extra_state), | 1864 : StubCompiler(isolate, extra_state), |
| 1874 arguments_(argc), | 1865 arguments_(argc), |
| 1875 kind_(kind), | 1866 kind_(kind), |
| 1876 cache_holder_(cache_holder) { | 1867 cache_holder_(cache_holder) { |
| 1877 } | 1868 } |
| 1878 | 1869 |
| 1879 | 1870 |
| 1880 bool CallStubCompiler::HasCustomCallGenerator(Handle<JSFunction> function) { | |
| 1881 CallOptimization optimization(function); | |
| 1882 return optimization.is_simple_api_call(); | |
| 1883 } | |
| 1884 | |
| 1885 | |
| 1886 Handle<Code> CallStubCompiler::CompileCustomCall( | |
| 1887 Handle<Object> object, | |
| 1888 Handle<JSObject> holder, | |
| 1889 Handle<Cell> cell, | |
| 1890 Handle<JSFunction> function, | |
| 1891 Handle<String> fname, | |
| 1892 Code::StubType type) { | |
| 1893 ASSERT(HasCustomCallGenerator(function)); | |
| 1894 CallOptimization optimization(function); | |
| 1895 ASSERT(optimization.is_simple_api_call()); | |
| 1896 return CompileFastApiCall(optimization, | |
| 1897 object, | |
| 1898 holder, | |
| 1899 cell, | |
| 1900 function, | |
| 1901 fname); | |
| 1902 } | |
| 1903 | |
| 1904 | |
| 1905 Handle<Code> CallStubCompiler::GetCode(Code::StubType type, | 1871 Handle<Code> CallStubCompiler::GetCode(Code::StubType type, |
| 1906 Handle<Name> name) { | 1872 Handle<Name> name) { |
| 1907 int argc = arguments_.immediate(); | 1873 int argc = arguments_.immediate(); |
| 1908 Code::Flags flags = Code::ComputeMonomorphicFlags( | 1874 Code::Flags flags = Code::ComputeMonomorphicFlags( |
| 1909 kind_, extra_state(), cache_holder_, type, argc); | 1875 kind_, extra_state(), cache_holder_, type, argc); |
| 1910 return GetCodeWithFlags(flags, name); | 1876 return GetCodeWithFlags(flags, name); |
| 1911 } | 1877 } |
| 1912 | 1878 |
| 1913 | 1879 |
| 1914 Handle<Code> CallStubCompiler::GetCode(Handle<JSFunction> function) { | 1880 Handle<Code> CallStubCompiler::GetCode(Handle<JSFunction> function) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1930 Initialize(Handle<JSFunction>::null()); | 1896 Initialize(Handle<JSFunction>::null()); |
| 1931 } | 1897 } |
| 1932 } | 1898 } |
| 1933 | 1899 |
| 1934 | 1900 |
| 1935 CallOptimization::CallOptimization(Handle<JSFunction> function) { | 1901 CallOptimization::CallOptimization(Handle<JSFunction> function) { |
| 1936 Initialize(function); | 1902 Initialize(function); |
| 1937 } | 1903 } |
| 1938 | 1904 |
| 1939 | 1905 |
| 1940 Handle<Map> CallOptimization::LookupHolderOfExpectedType( | 1906 Handle<JSObject> CallOptimization::LookupHolderOfExpectedType( |
| 1941 Handle<JSObject> receiver, | 1907 Handle<Map> object_map, |
| 1942 Handle<JSObject> object, | |
| 1943 Handle<JSObject> holder, | |
| 1944 HolderLookup* holder_lookup) const { | 1908 HolderLookup* holder_lookup) const { |
| 1945 ASSERT(is_simple_api_call()); | 1909 ASSERT(is_simple_api_call()); |
| 1946 ASSERT_EQ(kHolderNotFound, *holder_lookup); | 1910 ASSERT_EQ(kHolderNotFound, *holder_lookup); |
| 1947 *holder_lookup = kHolderIsReceiver; | 1911 if (!object_map->IsJSObjectMap()) { |
| 1948 Handle<Map> map_to_holder; | 1912 *holder_lookup = kHolderNotFound; |
| 1949 if (expected_receiver_type_.is_null()) { | 1913 return Handle<JSObject>::null(); |
| 1950 // no expected type, load from receiver. | |
| 1951 return map_to_holder; | |
| 1952 } | 1914 } |
| 1953 // walk down the prototype chain to the object | 1915 if (expected_receiver_type_.is_null() || |
| 1954 while (!receiver.is_identical_to(object)) { | 1916 expected_receiver_type_->IsTemplateFor(*object_map)) { |
| 1955 *holder_lookup = kHolderIsPrototypeOfMap; | 1917 *holder_lookup = kHolderIsReceiver; |
| 1956 map_to_holder = Handle<Map>(receiver->map()); | 1918 return Handle<JSObject>::null(); |
| 1957 receiver = Handle<JSObject>(JSObject::cast(map_to_holder->prototype())); | |
| 1958 } | 1919 } |
| 1959 // start looking for the holder | 1920 while (true) { |
| 1960 while (!object.is_identical_to(holder)) { | 1921 if (!object_map->prototype()->IsJSObject()) break; |
| 1961 Handle<Map> object_map(object->map()); | 1922 Handle<JSObject> prototype(JSObject::cast(object_map->prototype())); |
| 1923 if (!prototype->map()->is_hidden_prototype()) break; |
| 1924 object_map = handle(prototype->map()); |
| 1962 if (expected_receiver_type_->IsTemplateFor(*object_map)) { | 1925 if (expected_receiver_type_->IsTemplateFor(*object_map)) { |
| 1963 return map_to_holder; | 1926 *holder_lookup = kHolderFound; |
| 1927 return prototype; |
| 1964 } | 1928 } |
| 1965 if (!object_map->is_hidden_prototype()) { | |
| 1966 *holder_lookup = kHolderNotFound; | |
| 1967 return Handle<Map>::null(); | |
| 1968 } | |
| 1969 *holder_lookup = kHolderIsPrototypeOfMap; | |
| 1970 map_to_holder = object_map; | |
| 1971 object = Handle<JSObject>(JSObject::cast(object_map->prototype())); | |
| 1972 } | |
| 1973 if (expected_receiver_type_->IsTemplateFor(holder->map())) { | |
| 1974 return map_to_holder; | |
| 1975 } | 1929 } |
| 1976 *holder_lookup = kHolderNotFound; | 1930 *holder_lookup = kHolderNotFound; |
| 1977 return Handle<Map>::null(); | 1931 return Handle<JSObject>::null(); |
| 1978 } | 1932 } |
| 1979 | 1933 |
| 1980 | 1934 |
| 1981 void CallOptimization::Initialize(Handle<JSFunction> function) { | 1935 void CallOptimization::Initialize(Handle<JSFunction> function) { |
| 1982 constant_function_ = Handle<JSFunction>::null(); | 1936 constant_function_ = Handle<JSFunction>::null(); |
| 1983 is_simple_api_call_ = false; | 1937 is_simple_api_call_ = false; |
| 1984 expected_receiver_type_ = Handle<FunctionTemplateInfo>::null(); | 1938 expected_receiver_type_ = Handle<FunctionTemplateInfo>::null(); |
| 1985 api_call_info_ = Handle<CallHandlerInfo>::null(); | 1939 api_call_info_ = Handle<CallHandlerInfo>::null(); |
| 1986 | 1940 |
| 1987 if (function.is_null() || !function->is_compiled()) return; | 1941 if (function.is_null() || !function->is_compiled()) return; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 2011 Handle<FunctionTemplateInfo>( | 1965 Handle<FunctionTemplateInfo>( |
| 2012 FunctionTemplateInfo::cast(signature->receiver())); | 1966 FunctionTemplateInfo::cast(signature->receiver())); |
| 2013 } | 1967 } |
| 2014 } | 1968 } |
| 2015 | 1969 |
| 2016 is_simple_api_call_ = true; | 1970 is_simple_api_call_ = true; |
| 2017 } | 1971 } |
| 2018 | 1972 |
| 2019 | 1973 |
| 2020 } } // namespace v8::internal | 1974 } } // namespace v8::internal |
| OLD | NEW |