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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1045 switch (state) { | 1023 switch (state) { |
1046 case UNINITIALIZED: | 1024 case UNINITIALIZED: |
1047 case PREMONOMORPHIC: | 1025 case PREMONOMORPHIC: |
1048 case MONOMORPHIC_PROTOTYPE_FAILURE: | 1026 case MONOMORPHIC_PROTOTYPE_FAILURE: |
1049 UpdateMonomorphicIC(receiver, code, name); | 1027 UpdateMonomorphicIC(receiver, code, name); |
1050 break; | 1028 break; |
1051 case MONOMORPHIC: | 1029 case MONOMORPHIC: |
1052 // Only move to megamorphic if the target changes. | 1030 // Only move to megamorphic if the target changes. |
1053 if (target() != *code) { | 1031 if (target() != *code) { |
1054 if (target()->is_load_stub()) { | 1032 if (target()->is_load_stub()) { |
1033 bool is_map_transition = false; | |
danno
2013/03/13 11:49:48
How about refactoring this code into a method "IsT
Dmitry Lomov (no reviews)
2013/03/13 16:14:31
Done.
| |
1034 { | |
1035 // Stay monomorpic if: | |
1036 // 1. Target handler is identical to a new handler | |
1037 // 2. New map can transition to a receiver map | |
1038 AssertNoAllocation no_allocation; | |
1039 Code* old_handler = target()->FindFirstCode(); | |
1040 if (old_handler == *code) { | |
1041 Map* old_map = target()->FindFirstMap(); | |
1042 Map* receiver_map = receiver->map(); | |
1043 ElementsKind receiver_elements_kind = | |
1044 receiver_map->elements_kind(); | |
1045 bool more_general_transition = | |
1046 IsMoreGeneralElementsKindTransition( | |
1047 old_map->elements_kind(), receiver_elements_kind); | |
1048 Map* transitioned_old_map = more_general_transition | |
1049 ? old_map->LookupElementsTransitionMap(receiver_elements_kind) | |
1050 : NULL; | |
Toon Verwaest
2013/03/13 11:56:48
I think we could make this more generic by followi
| |
1051 | |
1052 if (transitioned_old_map == receiver_map) { | |
1053 is_map_transition = true; | |
1054 } | |
1055 } | |
1056 } | |
1057 if (is_map_transition) { | |
1058 UpdateMonomorphicIC(receiver, code, name); | |
1059 break; | |
1060 } | |
1055 if (UpdatePolymorphicIC(state, strict_mode, receiver, name, code)) { | 1061 if (UpdatePolymorphicIC(state, strict_mode, receiver, name, code)) { |
1056 break; | 1062 break; |
1057 } | 1063 } |
1058 } | 1064 } |
1059 if (target()->type() != Code::NORMAL) { | 1065 if (target()->type() != Code::NORMAL) { |
1060 if (target()->is_load_stub()) { | 1066 if (target()->is_load_stub()) { |
1061 CopyICToMegamorphicCache(name); | 1067 CopyICToMegamorphicCache(name); |
1062 } else { | 1068 } else { |
1063 Code* handler = target(); | 1069 Code* handler = target(); |
1064 Map* map = handler->FindFirstMap(); | 1070 Map* map = handler->FindFirstMap(); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1155 if (state == UNINITIALIZED) { | 1161 if (state == UNINITIALIZED) { |
1156 // This is the first time we execute this inline cache. | 1162 // This is the first time we execute this inline cache. |
1157 // Set the target to the pre monomorphic stub to delay | 1163 // Set the target to the pre monomorphic stub to delay |
1158 // setting the monomorphic state. | 1164 // setting the monomorphic state. |
1159 code = pre_monomorphic_stub(); | 1165 code = pre_monomorphic_stub(); |
1160 } else { | 1166 } else { |
1161 code = ComputeLoadHandler(lookup, receiver, name); | 1167 code = ComputeLoadHandler(lookup, receiver, name); |
1162 if (code.is_null()) return; | 1168 if (code.is_null()) return; |
1163 } | 1169 } |
1164 | 1170 |
1171 | |
danno
2013/03/13 11:49:48
nit: remove extra whitespace
Dmitry Lomov (no reviews)
2013/03/13 16:14:31
Done.
| |
1165 PatchCache(state, kNonStrictMode, receiver, name, code); | 1172 PatchCache(state, kNonStrictMode, receiver, name, code); |
1166 TRACE_IC("LoadIC", name, state, target()); | 1173 TRACE_IC("LoadIC", name, state, target()); |
1167 } | 1174 } |
1168 | 1175 |
1169 | 1176 |
1170 void IC::UpdateMegamorphicCache(Map* map, String* name, Code* code) { | 1177 void IC::UpdateMegamorphicCache(Map* map, String* name, Code* code) { |
1171 // Cache code holding map should be consistent with | 1178 // Cache code holding map should be consistent with |
1172 // GenerateMonomorphicCacheProbe. | 1179 // GenerateMonomorphicCacheProbe. |
1173 isolate()->stub_cache()->Set(name, map, code); | 1180 isolate()->stub_cache()->Set(name, map, code); |
1174 } | 1181 } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1216 return isolate()->stub_cache()->ComputeLoadCallback( | 1223 return isolate()->stub_cache()->ComputeLoadCallback( |
1217 name, receiver, holder, info); | 1224 name, receiver, holder, info); |
1218 } else if (callback->IsAccessorPair()) { | 1225 } else if (callback->IsAccessorPair()) { |
1219 Handle<Object> getter(Handle<AccessorPair>::cast(callback)->getter(), | 1226 Handle<Object> getter(Handle<AccessorPair>::cast(callback)->getter(), |
1220 isolate()); | 1227 isolate()); |
1221 if (!getter->IsJSFunction()) break; | 1228 if (!getter->IsJSFunction()) break; |
1222 if (holder->IsGlobalObject()) break; | 1229 if (holder->IsGlobalObject()) break; |
1223 if (!holder->HasFastProperties()) break; | 1230 if (!holder->HasFastProperties()) break; |
1224 return isolate()->stub_cache()->ComputeLoadViaGetter( | 1231 return isolate()->stub_cache()->ComputeLoadViaGetter( |
1225 name, receiver, holder, Handle<JSFunction>::cast(getter)); | 1232 name, receiver, holder, Handle<JSFunction>::cast(getter)); |
1233 } else if (receiver->IsJSArray() && | |
1234 name->Equals(isolate()->heap()->length_string())) { | |
1235 PropertyIndex lengthIndex = | |
1236 PropertyIndex::NewHeaderIndex(JSArray::kLengthOffset / kPointerSize); | |
1237 return isolate()->stub_cache()->ComputeLoadField( | |
1238 name, receiver, holder, lengthIndex); | |
1226 } | 1239 } |
1227 // TODO(dcarney): Handle correctly. | 1240 // TODO(dcarney): Handle correctly. |
1228 if (callback->IsDeclaredAccessorInfo()) break; | 1241 if (callback->IsDeclaredAccessorInfo()) break; |
1229 ASSERT(callback->IsForeign()); | 1242 ASSERT(callback->IsForeign()); |
1230 // No IC support for old-style native accessors. | 1243 // No IC support for old-style native accessors. |
1231 break; | 1244 break; |
1232 } | 1245 } |
1233 case INTERCEPTOR: | 1246 case INTERCEPTOR: |
1234 ASSERT(HasInterceptorGetter(*holder)); | 1247 ASSERT(HasInterceptorGetter(*holder)); |
1235 return isolate()->stub_cache()->ComputeLoadInterceptor( | 1248 return isolate()->stub_cache()->ComputeLoadInterceptor( |
(...skipping 1501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2737 #undef ADDR | 2750 #undef ADDR |
2738 }; | 2751 }; |
2739 | 2752 |
2740 | 2753 |
2741 Address IC::AddressFromUtilityId(IC::UtilityId id) { | 2754 Address IC::AddressFromUtilityId(IC::UtilityId id) { |
2742 return IC_utilities[id]; | 2755 return IC_utilities[id]; |
2743 } | 2756 } |
2744 | 2757 |
2745 | 2758 |
2746 } } // namespace v8::internal | 2759 } } // namespace v8::internal |
OLD | NEW |