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 837 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
848 if (FLAG_trace_ic) PrintF("[LoadIC : +#length /string]\n"); | 848 if (FLAG_trace_ic) PrintF("[LoadIC : +#length /string]\n"); |
849 #endif | 849 #endif |
850 } | 850 } |
851 // Get the string if we have a string wrapper object. | 851 // Get the string if we have a string wrapper object. |
852 Handle<Object> string = object->IsJSValue() | 852 Handle<Object> string = object->IsJSValue() |
853 ? Handle<Object>(Handle<JSValue>::cast(object)->value(), isolate()) | 853 ? Handle<Object>(Handle<JSValue>::cast(object)->value(), isolate()) |
854 : object; | 854 : object; |
855 return Smi::FromInt(String::cast(*string)->length()); | 855 return Smi::FromInt(String::cast(*string)->length()); |
856 } | 856 } |
857 | 857 |
858 // Use specialized code for getting the length of arrays. | |
859 if (object->IsJSArray() && | |
860 name->Equals(isolate()->heap()->length_string())) { | |
861 Handle<Code> stub; | |
862 if (state == UNINITIALIZED) { | |
863 stub = pre_monomorphic_stub(); | |
864 } else if (state == PREMONOMORPHIC) { | |
865 ArrayLengthStub array_length_stub(kind()); | |
866 stub = array_length_stub.GetCode(isolate()); | |
867 } else if (state != MEGAMORPHIC) { | |
868 ASSERT(state != GENERIC); | |
869 stub = megamorphic_stub(); | |
870 } | |
871 if (!stub.is_null()) { | |
872 set_target(*stub); | |
873 #ifdef DEBUG | |
874 if (FLAG_trace_ic) PrintF("[LoadIC : +#length /array]\n"); | |
875 #endif | |
876 } | |
877 return JSArray::cast(*object)->length(); | |
878 } | |
879 | |
880 // Use specialized code for getting prototype of functions. | 858 // Use specialized code for getting prototype of functions. |
881 if (object->IsJSFunction() && | 859 if (object->IsJSFunction() && |
882 name->Equals(isolate()->heap()->prototype_string()) && | 860 name->Equals(isolate()->heap()->prototype_string()) && |
883 Handle<JSFunction>::cast(object)->should_have_prototype()) { | 861 Handle<JSFunction>::cast(object)->should_have_prototype()) { |
884 Handle<Code> stub; | 862 Handle<Code> stub; |
885 if (state == UNINITIALIZED) { | 863 if (state == UNINITIALIZED) { |
886 stub = pre_monomorphic_stub(); | 864 stub = pre_monomorphic_stub(); |
887 } else if (state == PREMONOMORPHIC) { | 865 } else if (state == PREMONOMORPHIC) { |
888 FunctionPrototypeStub function_prototype_stub(kind()); | 866 FunctionPrototypeStub function_prototype_stub(kind()); |
889 stub = function_prototype_stub.GetCode(isolate()); | 867 stub = function_prototype_stub.GetCode(isolate()); |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1026 CodeHandleList handlers; | 1004 CodeHandleList handlers; |
1027 { | 1005 { |
1028 AssertNoAllocation no_gc; | 1006 AssertNoAllocation no_gc; |
1029 target()->FindAllMaps(&receiver_maps); | 1007 target()->FindAllMaps(&receiver_maps); |
1030 target()->FindAllCode(&handlers, receiver_maps.length()); | 1008 target()->FindAllCode(&handlers, receiver_maps.length()); |
1031 } | 1009 } |
1032 for (int i = 0; i < receiver_maps.length(); i++) { | 1010 for (int i = 0; i < receiver_maps.length(); i++) { |
1033 UpdateMegamorphicCache(*receiver_maps.at(i), *name, *handlers.at(i)); | 1011 UpdateMegamorphicCache(*receiver_maps.at(i), *name, *handlers.at(i)); |
1034 } | 1012 } |
1035 } | 1013 } |
1036 | 1014 |
danno
2013/03/22 14:25:40
nit: two spaces before and after function
| |
1015 bool IC::IsTransitionedMapOfMonomorphicTarget(Map* receiver_map) { | |
1016 AssertNoAllocation no_allocation; | |
1017 | |
1018 Map* current_map = target()->FindFirstMap(); | |
1019 ElementsKind receiver_elements_kind = receiver_map->elements_kind(); | |
1020 bool more_general_transition = | |
1021 IsMoreGeneralElementsKindTransition( | |
1022 current_map->elements_kind(), receiver_elements_kind); | |
1023 Map* transitioned_map = more_general_transition | |
1024 ? current_map->LookupElementsTransitionMap(receiver_elements_kind) | |
1025 : NULL; | |
1026 | |
1027 return transitioned_map == receiver_map; | |
1028 } | |
1037 | 1029 |
1038 // Since GC may have been invoked, by the time PatchCache is called, |state| is | 1030 // Since GC may have been invoked, by the time PatchCache is called, |state| is |
1039 // not necessarily equal to target()->state(). | 1031 // not necessarily equal to target()->state(). |
1040 void IC::PatchCache(State state, | 1032 void IC::PatchCache(State state, |
1041 StrictModeFlag strict_mode, | 1033 StrictModeFlag strict_mode, |
1042 Handle<JSObject> receiver, | 1034 Handle<JSObject> receiver, |
1043 Handle<String> name, | 1035 Handle<String> name, |
1044 Handle<Code> code) { | 1036 Handle<Code> code) { |
1045 switch (state) { | 1037 switch (state) { |
1046 case UNINITIALIZED: | 1038 case UNINITIALIZED: |
1047 case PREMONOMORPHIC: | 1039 case PREMONOMORPHIC: |
1048 case MONOMORPHIC_PROTOTYPE_FAILURE: | 1040 case MONOMORPHIC_PROTOTYPE_FAILURE: |
1049 UpdateMonomorphicIC(receiver, code, name); | 1041 UpdateMonomorphicIC(receiver, code, name); |
1050 break; | 1042 break; |
1051 case MONOMORPHIC: | 1043 case MONOMORPHIC: |
1052 // Only move to megamorphic if the target changes. | 1044 // Only move to megamorphic if the target changes. |
1053 if (target() != *code) { | 1045 if (target() != *code) { |
1054 if (target()->is_load_stub()) { | 1046 if (target()->is_load_stub()) { |
1047 bool is_same_handler = false; | |
1048 { | |
1049 AssertNoAllocation no_allocation; | |
1050 Code* old_handler = target()->FindFirstCode(); | |
1051 is_same_handler = old_handler == *code; | |
1052 } | |
1053 if (is_same_handler | |
1054 && IsTransitionedMapOfMonomorphicTarget(receiver->map())) { | |
1055 UpdateMonomorphicIC(receiver, code, name); | |
1056 break; | |
1057 } | |
1055 if (UpdatePolymorphicIC(state, strict_mode, receiver, name, code)) { | 1058 if (UpdatePolymorphicIC(state, strict_mode, receiver, name, code)) { |
1056 break; | 1059 break; |
1057 } | 1060 } |
1058 } | 1061 } |
1059 if (target()->type() != Code::NORMAL) { | 1062 if (target()->type() != Code::NORMAL) { |
1060 if (target()->is_load_stub()) { | 1063 if (target()->is_load_stub()) { |
1061 CopyICToMegamorphicCache(name); | 1064 CopyICToMegamorphicCache(name); |
1062 } else { | 1065 } else { |
1063 Code* handler = target(); | 1066 Code* handler = target(); |
1064 Map* map = handler->FindFirstMap(); | 1067 Map* map = handler->FindFirstMap(); |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1216 return isolate()->stub_cache()->ComputeLoadCallback( | 1219 return isolate()->stub_cache()->ComputeLoadCallback( |
1217 name, receiver, holder, info); | 1220 name, receiver, holder, info); |
1218 } else if (callback->IsAccessorPair()) { | 1221 } else if (callback->IsAccessorPair()) { |
1219 Handle<Object> getter(Handle<AccessorPair>::cast(callback)->getter(), | 1222 Handle<Object> getter(Handle<AccessorPair>::cast(callback)->getter(), |
1220 isolate()); | 1223 isolate()); |
1221 if (!getter->IsJSFunction()) break; | 1224 if (!getter->IsJSFunction()) break; |
1222 if (holder->IsGlobalObject()) break; | 1225 if (holder->IsGlobalObject()) break; |
1223 if (!holder->HasFastProperties()) break; | 1226 if (!holder->HasFastProperties()) break; |
1224 return isolate()->stub_cache()->ComputeLoadViaGetter( | 1227 return isolate()->stub_cache()->ComputeLoadViaGetter( |
1225 name, receiver, holder, Handle<JSFunction>::cast(getter)); | 1228 name, receiver, holder, Handle<JSFunction>::cast(getter)); |
1229 } else if (receiver->IsJSArray() && | |
1230 name->Equals(isolate()->heap()->length_string())) { | |
1231 PropertyIndex lengthIndex = | |
1232 PropertyIndex::NewHeaderIndex(JSArray::kLengthOffset / kPointerSize); | |
1233 return isolate()->stub_cache()->ComputeLoadField( | |
1234 name, receiver, holder, lengthIndex); | |
1226 } | 1235 } |
1227 // TODO(dcarney): Handle correctly. | 1236 // TODO(dcarney): Handle correctly. |
1228 if (callback->IsDeclaredAccessorInfo()) break; | 1237 if (callback->IsDeclaredAccessorInfo()) break; |
1229 ASSERT(callback->IsForeign()); | 1238 ASSERT(callback->IsForeign()); |
1230 // No IC support for old-style native accessors. | 1239 // No IC support for old-style native accessors. |
1231 break; | 1240 break; |
1232 } | 1241 } |
1233 case INTERCEPTOR: | 1242 case INTERCEPTOR: |
1234 ASSERT(HasInterceptorGetter(*holder)); | 1243 ASSERT(HasInterceptorGetter(*holder)); |
1235 return isolate()->stub_cache()->ComputeLoadInterceptor( | 1244 return isolate()->stub_cache()->ComputeLoadInterceptor( |
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1690 Code::GetKeyedAccessStoreMode(target()->extra_ic_state()); | 1699 Code::GetKeyedAccessStoreMode(target()->extra_ic_state()); |
1691 Handle<Map> previous_receiver_map = target_receiver_maps.at(0); | 1700 Handle<Map> previous_receiver_map = target_receiver_maps.at(0); |
1692 if (ic_state == MONOMORPHIC && old_store_mode == STANDARD_STORE) { | 1701 if (ic_state == MONOMORPHIC && old_store_mode == STANDARD_STORE) { |
1693 // If the "old" and "new" maps are in the same elements map family, stay | 1702 // If the "old" and "new" maps are in the same elements map family, stay |
1694 // MONOMORPHIC and use the map for the most generic ElementsKind. | 1703 // MONOMORPHIC and use the map for the most generic ElementsKind. |
1695 Handle<Map> transitioned_receiver_map = receiver_map; | 1704 Handle<Map> transitioned_receiver_map = receiver_map; |
1696 if (IsTransitionStoreMode(store_mode)) { | 1705 if (IsTransitionStoreMode(store_mode)) { |
1697 transitioned_receiver_map = | 1706 transitioned_receiver_map = |
1698 ComputeTransitionedMap(receiver, store_mode); | 1707 ComputeTransitionedMap(receiver, store_mode); |
1699 } | 1708 } |
1700 ElementsKind transitioned_kind = | 1709 if (IsTransitionedMapOfMonomorphicTarget(*transitioned_receiver_map)) { |
1701 transitioned_receiver_map->elements_kind(); | |
1702 bool more_general_transition = | |
1703 IsMoreGeneralElementsKindTransition( | |
1704 previous_receiver_map->elements_kind(), | |
1705 transitioned_kind); | |
1706 Map* transitioned_previous_map = more_general_transition | |
1707 ? previous_receiver_map->LookupElementsTransitionMap(transitioned_kind) | |
1708 : NULL; | |
1709 if (transitioned_previous_map == *transitioned_receiver_map) { | |
1710 // Element family is the same, use the "worst" case map. | 1710 // Element family is the same, use the "worst" case map. |
1711 store_mode = GetNonTransitioningStoreMode(store_mode); | 1711 store_mode = GetNonTransitioningStoreMode(store_mode); |
1712 return isolate()->stub_cache()->ComputeKeyedStoreElement( | 1712 return isolate()->stub_cache()->ComputeKeyedStoreElement( |
1713 transitioned_receiver_map, strict_mode, store_mode); | 1713 transitioned_receiver_map, strict_mode, store_mode); |
1714 } else if (*previous_receiver_map == receiver->map()) { | 1714 } else if (*previous_receiver_map == receiver->map()) { |
1715 if (IsGrowStoreMode(store_mode)) { | 1715 if (IsGrowStoreMode(store_mode)) { |
1716 // A "normal" IC that handles stores can switch to a version that can | 1716 // A "normal" IC that handles stores can switch to a version that can |
1717 // grow at the end of the array and still stay MONOMORPHIC. | 1717 // grow at the end of the array and still stay MONOMORPHIC. |
1718 return isolate()->stub_cache()->ComputeKeyedStoreElement( | 1718 return isolate()->stub_cache()->ComputeKeyedStoreElement( |
1719 receiver_map, strict_mode, store_mode); | 1719 receiver_map, strict_mode, store_mode); |
(...skipping 1017 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2737 #undef ADDR | 2737 #undef ADDR |
2738 }; | 2738 }; |
2739 | 2739 |
2740 | 2740 |
2741 Address IC::AddressFromUtilityId(IC::UtilityId id) { | 2741 Address IC::AddressFromUtilityId(IC::UtilityId id) { |
2742 return IC_utilities[id]; | 2742 return IC_utilities[id]; |
2743 } | 2743 } |
2744 | 2744 |
2745 | 2745 |
2746 } } // namespace v8::internal | 2746 } } // namespace v8::internal |
OLD | NEW |