| 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 765 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 776 // If there's no appropriate stub we simply avoid updating the caches. | 776 // If there's no appropriate stub we simply avoid updating the caches. |
| 777 // TODO(verwaest): Install a slow fallback in this case to avoid not learning, | 777 // TODO(verwaest): Install a slow fallback in this case to avoid not learning, |
| 778 // and deopting Crankshaft code. | 778 // and deopting Crankshaft code. |
| 779 if (code.is_null()) return; | 779 if (code.is_null()) return; |
| 780 | 780 |
| 781 Handle<JSObject> cache_object = object->IsJSObject() | 781 Handle<JSObject> cache_object = object->IsJSObject() |
| 782 ? Handle<JSObject>::cast(object) | 782 ? Handle<JSObject>::cast(object) |
| 783 : Handle<JSObject>(JSObject::cast(object->GetPrototype(isolate())), | 783 : Handle<JSObject>(JSObject::cast(object->GetPrototype(isolate())), |
| 784 isolate()); | 784 isolate()); |
| 785 | 785 |
| 786 PatchCache(handle(Type::CurrentOf(cache_object), isolate()), name, code); | 786 PatchCache(CurrentTypeOf(cache_object, isolate()), name, code); |
| 787 TRACE_IC("CallIC", name); | 787 TRACE_IC("CallIC", name); |
| 788 } | 788 } |
| 789 | 789 |
| 790 | 790 |
| 791 MaybeObject* KeyedCallIC::LoadFunction(Handle<Object> object, | 791 MaybeObject* KeyedCallIC::LoadFunction(Handle<Object> object, |
| 792 Handle<Object> key) { | 792 Handle<Object> key) { |
| 793 if (key->IsInternalizedString()) { | 793 if (key->IsInternalizedString()) { |
| 794 return CallICBase::LoadFunction(object, Handle<String>::cast(key)); | 794 return CallICBase::LoadFunction(object, Handle<String>::cast(key)); |
| 795 } | 795 } |
| 796 | 796 |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 982 number_of_valid_types = number_of_types; | 982 number_of_valid_types = number_of_types; |
| 983 | 983 |
| 984 for (int i = 0; i < number_of_types; i++) { | 984 for (int i = 0; i < number_of_types; i++) { |
| 985 Handle<Type> current_type = types.at(i); | 985 Handle<Type> current_type = types.at(i); |
| 986 // Filter out deprecated maps to ensure their instances get migrated. | 986 // Filter out deprecated maps to ensure their instances get migrated. |
| 987 if (current_type->IsClass() && current_type->AsClass()->is_deprecated()) { | 987 if (current_type->IsClass() && current_type->AsClass()->is_deprecated()) { |
| 988 number_of_valid_types--; | 988 number_of_valid_types--; |
| 989 // If the receiver type is already in the polymorphic IC, this indicates | 989 // If the receiver type is already in the polymorphic IC, this indicates |
| 990 // there was a prototoype chain failure. In that case, just overwrite the | 990 // there was a prototoype chain failure. In that case, just overwrite the |
| 991 // handler. | 991 // handler. |
| 992 } else if (type->Is(current_type)) { | 992 } else if (type->IsCurrently(current_type)) { |
| 993 ASSERT(handler_to_overwrite == -1); | 993 ASSERT(handler_to_overwrite == -1); |
| 994 number_of_valid_types--; | 994 number_of_valid_types--; |
| 995 handler_to_overwrite = i; | 995 handler_to_overwrite = i; |
| 996 } | 996 } |
| 997 } | 997 } |
| 998 | 998 |
| 999 if (number_of_valid_types >= 4) return false; | 999 if (number_of_valid_types >= 4) return false; |
| 1000 if (number_of_types == 0) return false; | 1000 if (number_of_types == 0) return false; |
| 1001 if (!target()->FindHandlers(&handlers, types.length())) return false; | 1001 if (!target()->FindHandlers(&handlers, types.length())) return false; |
| 1002 | 1002 |
| 1003 number_of_valid_types++; | 1003 number_of_valid_types++; |
| 1004 if (handler_to_overwrite >= 0) { | 1004 if (handler_to_overwrite >= 0) { |
| 1005 handlers.Set(handler_to_overwrite, code); | 1005 handlers.Set(handler_to_overwrite, code); |
| 1006 } else { | 1006 } else { |
| 1007 types.Add(type); | 1007 types.Add(type); |
| 1008 handlers.Add(code); | 1008 handlers.Add(code); |
| 1009 } | 1009 } |
| 1010 | 1010 |
| 1011 Handle<Code> ic = isolate()->stub_cache()->ComputePolymorphicIC( | 1011 Handle<Code> ic = isolate()->stub_cache()->ComputePolymorphicIC( |
| 1012 &types, &handlers, number_of_valid_types, name, strict_mode()); | 1012 &types, &handlers, number_of_valid_types, name, strict_mode()); |
| 1013 set_target(*ic); | 1013 set_target(*ic); |
| 1014 return true; | 1014 return true; |
| 1015 } | 1015 } |
| 1016 | 1016 |
| 1017 | 1017 |
| 1018 Handle<Type> IC::CurrentTypeOf(Handle<Object> object, Isolate* isolate) { |
| 1019 Type* type = object->IsJSGlobalObject() |
| 1020 ? Type::Constant(Handle<JSGlobalObject>::cast(object)) |
| 1021 : Type::CurrentOf(object); |
| 1022 return handle(type, isolate); |
| 1023 } |
| 1024 |
| 1025 |
| 1018 Handle<Map> IC::TypeToMap(Type* type, Isolate* isolate) { | 1026 Handle<Map> IC::TypeToMap(Type* type, Isolate* isolate) { |
| 1019 if (type->Is(Type::Number())) return isolate->factory()->heap_number_map(); | 1027 if (type->Is(Type::Number())) return isolate->factory()->heap_number_map(); |
| 1020 if (type->Is(Type::Boolean())) return isolate->factory()->oddball_map(); | 1028 if (type->Is(Type::Boolean())) return isolate->factory()->oddball_map(); |
| 1029 if (type->IsConstant()) { |
| 1030 return handle(Handle<JSGlobalObject>::cast(type->AsConstant())->map()); |
| 1031 } |
| 1021 ASSERT(type->IsClass()); | 1032 ASSERT(type->IsClass()); |
| 1022 return type->AsClass(); | 1033 return type->AsClass(); |
| 1023 } | 1034 } |
| 1024 | 1035 |
| 1025 | 1036 |
| 1026 Type* IC::MapToType(Handle<Map> map) { | 1037 Type* IC::MapToType(Handle<Map> map) { |
| 1027 if (map->instance_type() == HEAP_NUMBER_TYPE) return Type::Number(); | 1038 if (map->instance_type() == HEAP_NUMBER_TYPE) return Type::Number(); |
| 1028 // The only oddballs that can be recorded in ICs are booleans. | 1039 // The only oddballs that can be recorded in ICs are booleans. |
| 1029 if (map->instance_type() == ODDBALL_TYPE) return Type::Boolean(); | 1040 if (map->instance_type() == ODDBALL_TYPE) return Type::Boolean(); |
| 1030 return Type::Class(map); | 1041 return Type::Class(map); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1141 } else if (!lookup->IsProperty()) { | 1152 } else if (!lookup->IsProperty()) { |
| 1142 if (kind() == Code::LOAD_IC) { | 1153 if (kind() == Code::LOAD_IC) { |
| 1143 code = isolate()->stub_cache()->ComputeLoadNonexistent(name, object); | 1154 code = isolate()->stub_cache()->ComputeLoadNonexistent(name, object); |
| 1144 } else { | 1155 } else { |
| 1145 code = slow_stub(); | 1156 code = slow_stub(); |
| 1146 } | 1157 } |
| 1147 } else { | 1158 } else { |
| 1148 code = ComputeHandler(lookup, object, name); | 1159 code = ComputeHandler(lookup, object, name); |
| 1149 } | 1160 } |
| 1150 | 1161 |
| 1151 PatchCache(handle(Type::CurrentOf(object), isolate()), name, code); | 1162 PatchCache(CurrentTypeOf(object, isolate()), name, code); |
| 1152 TRACE_IC("LoadIC", name); | 1163 TRACE_IC("LoadIC", name); |
| 1153 } | 1164 } |
| 1154 | 1165 |
| 1155 | 1166 |
| 1156 void IC::UpdateMegamorphicCache(Type* type, Name* name, Code* code) { | 1167 void IC::UpdateMegamorphicCache(Type* type, Name* name, Code* code) { |
| 1157 // Cache code holding map should be consistent with | 1168 // Cache code holding map should be consistent with |
| 1158 // GenerateMonomorphicCacheProbe. | 1169 // GenerateMonomorphicCacheProbe. |
| 1159 Map* map = *TypeToMap(type, isolate()); | 1170 Map* map = *TypeToMap(type, isolate()); |
| 1160 isolate()->stub_cache()->Set(name, map, code); | 1171 isolate()->stub_cache()->Set(name, map, code); |
| 1161 } | 1172 } |
| (...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1605 Handle<String> name, | 1616 Handle<String> name, |
| 1606 Handle<Object> value) { | 1617 Handle<Object> value) { |
| 1607 ASSERT(!receiver->IsJSGlobalProxy()); | 1618 ASSERT(!receiver->IsJSGlobalProxy()); |
| 1608 ASSERT(lookup->IsFound()); | 1619 ASSERT(lookup->IsFound()); |
| 1609 | 1620 |
| 1610 // These are not cacheable, so we never see such LookupResults here. | 1621 // These are not cacheable, so we never see such LookupResults here. |
| 1611 ASSERT(!lookup->IsHandler()); | 1622 ASSERT(!lookup->IsHandler()); |
| 1612 | 1623 |
| 1613 Handle<Code> code = ComputeHandler(lookup, receiver, name, value); | 1624 Handle<Code> code = ComputeHandler(lookup, receiver, name, value); |
| 1614 | 1625 |
| 1615 PatchCache(handle(Type::CurrentOf(receiver), isolate()), name, code); | 1626 PatchCache(CurrentTypeOf(receiver, isolate()), name, code); |
| 1616 TRACE_IC("StoreIC", name); | 1627 TRACE_IC("StoreIC", name); |
| 1617 } | 1628 } |
| 1618 | 1629 |
| 1619 | 1630 |
| 1620 Handle<Code> StoreIC::CompileHandler(LookupResult* lookup, | 1631 Handle<Code> StoreIC::CompileHandler(LookupResult* lookup, |
| 1621 Handle<Object> object, | 1632 Handle<Object> object, |
| 1622 Handle<String> name, | 1633 Handle<String> name, |
| 1623 Handle<Object> value, | 1634 Handle<Object> value, |
| 1624 InlineCacheHolderFlag cache_holder) { | 1635 InlineCacheHolderFlag cache_holder) { |
| 1625 ASSERT(cache_holder == OWN_MAP); | 1636 ASSERT(cache_holder == OWN_MAP); |
| (...skipping 1142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2768 #undef ADDR | 2779 #undef ADDR |
| 2769 }; | 2780 }; |
| 2770 | 2781 |
| 2771 | 2782 |
| 2772 Address IC::AddressFromUtilityId(IC::UtilityId id) { | 2783 Address IC::AddressFromUtilityId(IC::UtilityId id) { |
| 2773 return IC_utilities[id]; | 2784 return IC_utilities[id]; |
| 2774 } | 2785 } |
| 2775 | 2786 |
| 2776 | 2787 |
| 2777 } } // namespace v8::internal | 2788 } } // namespace v8::internal |
| OLD | NEW |