| OLD | NEW |
| 1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2009 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 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 case Code::LOAD_IC: return LoadIC::Clear(address, target); | 275 case Code::LOAD_IC: return LoadIC::Clear(address, target); |
| 276 case Code::KEYED_LOAD_IC: | 276 case Code::KEYED_LOAD_IC: |
| 277 case Code::KEYED_EXTERNAL_ARRAY_LOAD_IC: | 277 case Code::KEYED_EXTERNAL_ARRAY_LOAD_IC: |
| 278 return KeyedLoadIC::Clear(address, target); | 278 return KeyedLoadIC::Clear(address, target); |
| 279 case Code::STORE_IC: return StoreIC::Clear(address, target); | 279 case Code::STORE_IC: return StoreIC::Clear(address, target); |
| 280 case Code::KEYED_STORE_IC: | 280 case Code::KEYED_STORE_IC: |
| 281 case Code::KEYED_EXTERNAL_ARRAY_STORE_IC: | 281 case Code::KEYED_EXTERNAL_ARRAY_STORE_IC: |
| 282 return KeyedStoreIC::Clear(address, target); | 282 return KeyedStoreIC::Clear(address, target); |
| 283 case Code::CALL_IC: return CallIC::Clear(address, target); | 283 case Code::CALL_IC: return CallIC::Clear(address, target); |
| 284 case Code::KEYED_CALL_IC: return KeyedCallIC::Clear(address, target); | 284 case Code::KEYED_CALL_IC: return KeyedCallIC::Clear(address, target); |
| 285 case Code::BINARY_OP_IC: | |
| 286 case Code::TYPE_RECORDING_BINARY_OP_IC: | 285 case Code::TYPE_RECORDING_BINARY_OP_IC: |
| 287 case Code::COMPARE_IC: | 286 case Code::COMPARE_IC: |
| 288 // Clearing these is tricky and does not | 287 // Clearing these is tricky and does not |
| 289 // make any performance difference. | 288 // make any performance difference. |
| 290 return; | 289 return; |
| 291 default: UNREACHABLE(); | 290 default: UNREACHABLE(); |
| 292 } | 291 } |
| 293 } | 292 } |
| 294 | 293 |
| 295 | 294 |
| (...skipping 1676 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1972 IC::State state = IC::StateFrom(ic.target(), args[0], args[1]); | 1971 IC::State state = IC::StateFrom(ic.target(), args[0], args[1]); |
| 1973 Code::ExtraICState extra_ic_state = ic.target()->extra_ic_state(); | 1972 Code::ExtraICState extra_ic_state = ic.target()->extra_ic_state(); |
| 1974 return ic.Store(state, | 1973 return ic.Store(state, |
| 1975 static_cast<StrictModeFlag>(extra_ic_state & kStrictMode), | 1974 static_cast<StrictModeFlag>(extra_ic_state & kStrictMode), |
| 1976 args.at<Object>(0), | 1975 args.at<Object>(0), |
| 1977 args.at<Object>(1), | 1976 args.at<Object>(1), |
| 1978 args.at<Object>(2)); | 1977 args.at<Object>(2)); |
| 1979 } | 1978 } |
| 1980 | 1979 |
| 1981 | 1980 |
| 1982 void BinaryOpIC::patch(Code* code) { | |
| 1983 set_target(code); | |
| 1984 } | |
| 1985 | |
| 1986 | |
| 1987 const char* BinaryOpIC::GetName(TypeInfo type_info) { | |
| 1988 switch (type_info) { | |
| 1989 case UNINIT_OR_SMI: return "UninitOrSmi"; | |
| 1990 case DEFAULT: return "Default"; | |
| 1991 case GENERIC: return "Generic"; | |
| 1992 case HEAP_NUMBERS: return "HeapNumbers"; | |
| 1993 case STRINGS: return "Strings"; | |
| 1994 default: return "Invalid"; | |
| 1995 } | |
| 1996 } | |
| 1997 | |
| 1998 | |
| 1999 BinaryOpIC::State BinaryOpIC::ToState(TypeInfo type_info) { | |
| 2000 switch (type_info) { | |
| 2001 case UNINIT_OR_SMI: | |
| 2002 return UNINITIALIZED; | |
| 2003 case DEFAULT: | |
| 2004 case HEAP_NUMBERS: | |
| 2005 case STRINGS: | |
| 2006 return MONOMORPHIC; | |
| 2007 case GENERIC: | |
| 2008 return MEGAMORPHIC; | |
| 2009 } | |
| 2010 UNREACHABLE(); | |
| 2011 return UNINITIALIZED; | |
| 2012 } | |
| 2013 | |
| 2014 | |
| 2015 BinaryOpIC::TypeInfo BinaryOpIC::GetTypeInfo(Object* left, | |
| 2016 Object* right) { | |
| 2017 if (left->IsSmi() && right->IsSmi()) { | |
| 2018 // If we have two smi inputs we can reach here because | |
| 2019 // of an overflow. Enter default state. | |
| 2020 return DEFAULT; | |
| 2021 } | |
| 2022 | |
| 2023 if (left->IsNumber() && right->IsNumber()) { | |
| 2024 return HEAP_NUMBERS; | |
| 2025 } | |
| 2026 | |
| 2027 if (left->IsString() || right->IsString()) { | |
| 2028 // Patching for fast string ADD makes sense even if only one of the | |
| 2029 // arguments is a string. | |
| 2030 return STRINGS; | |
| 2031 } | |
| 2032 | |
| 2033 return GENERIC; | |
| 2034 } | |
| 2035 | |
| 2036 | |
| 2037 // defined in code-stubs-<arch>.cc | |
| 2038 Handle<Code> GetBinaryOpStub(int key, BinaryOpIC::TypeInfo type_info); | |
| 2039 | |
| 2040 | |
| 2041 RUNTIME_FUNCTION(MaybeObject*, BinaryOp_Patch) { | |
| 2042 ASSERT(args.length() == 5); | |
| 2043 | |
| 2044 HandleScope scope(isolate); | |
| 2045 Handle<Object> left = args.at<Object>(0); | |
| 2046 Handle<Object> right = args.at<Object>(1); | |
| 2047 int key = Smi::cast(args[2])->value(); | |
| 2048 Token::Value op = static_cast<Token::Value>(Smi::cast(args[3])->value()); | |
| 2049 BinaryOpIC::TypeInfo previous_type = | |
| 2050 static_cast<BinaryOpIC::TypeInfo>(Smi::cast(args[4])->value()); | |
| 2051 | |
| 2052 BinaryOpIC::TypeInfo type = BinaryOpIC::GetTypeInfo(*left, *right); | |
| 2053 Handle<Code> code = GetBinaryOpStub(key, type); | |
| 2054 if (!code.is_null()) { | |
| 2055 BinaryOpIC ic(isolate); | |
| 2056 ic.patch(*code); | |
| 2057 if (FLAG_trace_ic) { | |
| 2058 PrintF("[BinaryOpIC (%s->%s)#%s]\n", | |
| 2059 BinaryOpIC::GetName(previous_type), | |
| 2060 BinaryOpIC::GetName(type), | |
| 2061 Token::Name(op)); | |
| 2062 } | |
| 2063 } | |
| 2064 | |
| 2065 Handle<JSBuiltinsObject> builtins = Handle<JSBuiltinsObject>( | |
| 2066 isolate->thread_local_top()->context_->builtins(), isolate); | |
| 2067 Object* builtin = NULL; // Initialization calms down the compiler. | |
| 2068 switch (op) { | |
| 2069 case Token::ADD: | |
| 2070 builtin = builtins->javascript_builtin(Builtins::ADD); | |
| 2071 break; | |
| 2072 case Token::SUB: | |
| 2073 builtin = builtins->javascript_builtin(Builtins::SUB); | |
| 2074 break; | |
| 2075 case Token::MUL: | |
| 2076 builtin = builtins->javascript_builtin(Builtins::MUL); | |
| 2077 break; | |
| 2078 case Token::DIV: | |
| 2079 builtin = builtins->javascript_builtin(Builtins::DIV); | |
| 2080 break; | |
| 2081 case Token::MOD: | |
| 2082 builtin = builtins->javascript_builtin(Builtins::MOD); | |
| 2083 break; | |
| 2084 case Token::BIT_AND: | |
| 2085 builtin = builtins->javascript_builtin(Builtins::BIT_AND); | |
| 2086 break; | |
| 2087 case Token::BIT_OR: | |
| 2088 builtin = builtins->javascript_builtin(Builtins::BIT_OR); | |
| 2089 break; | |
| 2090 case Token::BIT_XOR: | |
| 2091 builtin = builtins->javascript_builtin(Builtins::BIT_XOR); | |
| 2092 break; | |
| 2093 case Token::SHR: | |
| 2094 builtin = builtins->javascript_builtin(Builtins::SHR); | |
| 2095 break; | |
| 2096 case Token::SAR: | |
| 2097 builtin = builtins->javascript_builtin(Builtins::SAR); | |
| 2098 break; | |
| 2099 case Token::SHL: | |
| 2100 builtin = builtins->javascript_builtin(Builtins::SHL); | |
| 2101 break; | |
| 2102 default: | |
| 2103 UNREACHABLE(); | |
| 2104 } | |
| 2105 | |
| 2106 Handle<JSFunction> builtin_function(JSFunction::cast(builtin), | |
| 2107 isolate); | |
| 2108 | |
| 2109 bool caught_exception; | |
| 2110 Object** builtin_args[] = { right.location() }; | |
| 2111 Handle<Object> result = Execution::Call(builtin_function, | |
| 2112 left, | |
| 2113 ARRAY_SIZE(builtin_args), | |
| 2114 builtin_args, | |
| 2115 &caught_exception); | |
| 2116 if (caught_exception) { | |
| 2117 return Failure::Exception(); | |
| 2118 } | |
| 2119 return *result; | |
| 2120 } | |
| 2121 | |
| 2122 | |
| 2123 void TRBinaryOpIC::patch(Code* code) { | 1981 void TRBinaryOpIC::patch(Code* code) { |
| 2124 set_target(code); | 1982 set_target(code); |
| 2125 } | 1983 } |
| 2126 | 1984 |
| 2127 | 1985 |
| 2128 const char* TRBinaryOpIC::GetName(TypeInfo type_info) { | 1986 const char* TRBinaryOpIC::GetName(TypeInfo type_info) { |
| 2129 switch (type_info) { | 1987 switch (type_info) { |
| 2130 case UNINITIALIZED: return "Uninitialized"; | 1988 case UNINITIALIZED: return "Uninitialized"; |
| 2131 case SMI: return "SMI"; | 1989 case SMI: return "SMI"; |
| 2132 case INT32: return "Int32s"; | 1990 case INT32: return "Int32s"; |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2380 #undef ADDR | 2238 #undef ADDR |
| 2381 }; | 2239 }; |
| 2382 | 2240 |
| 2383 | 2241 |
| 2384 Address IC::AddressFromUtilityId(IC::UtilityId id) { | 2242 Address IC::AddressFromUtilityId(IC::UtilityId id) { |
| 2385 return IC_utilities[id]; | 2243 return IC_utilities[id]; |
| 2386 } | 2244 } |
| 2387 | 2245 |
| 2388 | 2246 |
| 2389 } } // namespace v8::internal | 2247 } } // namespace v8::internal |
| OLD | NEW |