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 1051 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1062 Handle<Code> stub = generic_stub(); | 1062 Handle<Code> stub = generic_stub(); |
1063 | 1063 |
1064 // Check for non-string values that can be converted into an | 1064 // Check for non-string values that can be converted into an |
1065 // internalized string directly or is representable as a smi. | 1065 // internalized string directly or is representable as a smi. |
1066 key = TryConvertKey(key, isolate()); | 1066 key = TryConvertKey(key, isolate()); |
1067 | 1067 |
1068 if (key->IsInternalizedString()) { | 1068 if (key->IsInternalizedString()) { |
1069 maybe_object = LoadIC::Load(object, Handle<String>::cast(key)); | 1069 maybe_object = LoadIC::Load(object, Handle<String>::cast(key)); |
1070 if (maybe_object->IsFailure()) return maybe_object; | 1070 if (maybe_object->IsFailure()) return maybe_object; |
1071 } else if (FLAG_use_ic && !object->IsAccessCheckNeeded()) { | 1071 } else if (FLAG_use_ic && !object->IsAccessCheckNeeded()) { |
1072 ASSERT(!object->IsAccessCheckNeeded()); | 1072 ASSERT(!object->IsJSGlobalProxy()); |
1073 if (object->IsString() && key->IsNumber()) { | 1073 if (object->IsString() && key->IsNumber()) { |
1074 if (state() == UNINITIALIZED) stub = string_stub(); | 1074 if (state() == UNINITIALIZED) stub = string_stub(); |
1075 } else if (object->IsJSObject()) { | 1075 } else if (object->IsJSObject()) { |
1076 Handle<JSObject> receiver = Handle<JSObject>::cast(object); | 1076 Handle<JSObject> receiver = Handle<JSObject>::cast(object); |
1077 if (receiver->elements()->map() == | 1077 if (receiver->elements()->map() == |
1078 isolate()->heap()->non_strict_arguments_elements_map()) { | 1078 isolate()->heap()->non_strict_arguments_elements_map()) { |
1079 stub = non_strict_arguments_stub(); | 1079 stub = non_strict_arguments_stub(); |
1080 } else if (receiver->HasIndexedInterceptor()) { | 1080 } else if (receiver->HasIndexedInterceptor()) { |
1081 stub = indexed_interceptor_stub(); | 1081 stub = indexed_interceptor_stub(); |
1082 } else if (!key->ToSmi()->IsFailure() && | 1082 } else if (!key->ToSmi()->IsFailure() && |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1115 receiver->LocalLookupRealNamedProperty(*name, lookup); | 1115 receiver->LocalLookupRealNamedProperty(*name, lookup); |
1116 return lookup->IsFound() && | 1116 return lookup->IsFound() && |
1117 !lookup->IsReadOnly() && | 1117 !lookup->IsReadOnly() && |
1118 lookup->CanHoldValue(value) && | 1118 lookup->CanHoldValue(value) && |
1119 lookup->IsCacheable(); | 1119 lookup->IsCacheable(); |
1120 } | 1120 } |
1121 return lookup->CanHoldValue(value); | 1121 return lookup->CanHoldValue(value); |
1122 } | 1122 } |
1123 | 1123 |
1124 if (lookup->IsPropertyCallbacks()) return true; | 1124 if (lookup->IsPropertyCallbacks()) return true; |
1125 // JSGlobalProxy either stores on the global object in the prototype, or | 1125 // JSGlobalProxy always goes via the runtime, so it's safe to cache. |
1126 // goes into the runtime if access checks are needed, so this is always | |
1127 // safe. | |
1128 if (receiver->IsJSGlobalProxy()) return true; | 1126 if (receiver->IsJSGlobalProxy()) return true; |
1129 // Currently normal holders in the prototype chain are not supported. They | 1127 // Currently normal holders in the prototype chain are not supported. They |
1130 // would require a runtime positive lookup and verification that the details | 1128 // would require a runtime positive lookup and verification that the details |
1131 // have not changed. | 1129 // have not changed. |
1132 if (lookup->IsInterceptor() || lookup->IsNormal()) return false; | 1130 if (lookup->IsInterceptor() || lookup->IsNormal()) return false; |
1133 holder = Handle<JSObject>(lookup->holder(), lookup->isolate()); | 1131 holder = Handle<JSObject>(lookup->holder(), lookup->isolate()); |
1134 } | 1132 } |
1135 | 1133 |
1136 // While normally LookupTransition gets passed the receiver, in this case we | 1134 // While normally LookupTransition gets passed the receiver, in this case we |
1137 // pass the holder of the property that we overwrite. This keeps the holder in | 1135 // pass the holder of the property that we overwrite. This keeps the holder in |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1304 PatchCache(CurrentTypeOf(receiver, isolate()), name, code); | 1302 PatchCache(CurrentTypeOf(receiver, isolate()), name, code); |
1305 TRACE_IC("StoreIC", name); | 1303 TRACE_IC("StoreIC", name); |
1306 } | 1304 } |
1307 | 1305 |
1308 | 1306 |
1309 Handle<Code> StoreIC::CompileHandler(LookupResult* lookup, | 1307 Handle<Code> StoreIC::CompileHandler(LookupResult* lookup, |
1310 Handle<Object> object, | 1308 Handle<Object> object, |
1311 Handle<String> name, | 1309 Handle<String> name, |
1312 Handle<Object> value, | 1310 Handle<Object> value, |
1313 InlineCacheHolderFlag cache_holder) { | 1311 InlineCacheHolderFlag cache_holder) { |
1314 if (object->IsAccessCheckNeeded()) return slow_stub(); | 1312 if (object->IsJSGlobalProxy()) return slow_stub(); |
1315 ASSERT(cache_holder == OWN_MAP); | 1313 ASSERT(cache_holder == OWN_MAP); |
1316 // This is currently guaranteed by checks in StoreIC::Store. | 1314 // This is currently guaranteed by checks in StoreIC::Store. |
1317 Handle<JSObject> receiver = Handle<JSObject>::cast(object); | 1315 Handle<JSObject> receiver = Handle<JSObject>::cast(object); |
1318 | 1316 |
1319 Handle<JSObject> holder(lookup->holder()); | 1317 Handle<JSObject> holder(lookup->holder()); |
1320 // Handlers do not use strict mode. | 1318 // Handlers do not use strict mode. |
1321 StoreStubCompiler compiler(isolate(), kNonStrictMode, kind()); | 1319 StoreStubCompiler compiler(isolate(), kNonStrictMode, kind()); |
1322 switch (lookup->type()) { | 1320 switch (lookup->type()) { |
1323 case FIELD: | 1321 case FIELD: |
1324 return compiler.CompileStoreField(receiver, lookup, name); | 1322 return compiler.CompileStoreField(receiver, lookup, name); |
1325 case TRANSITION: { | 1323 case TRANSITION: { |
1326 // Explicitly pass in the receiver map since LookupForWrite may have | 1324 // Explicitly pass in the receiver map since LookupForWrite may have |
1327 // stored something else than the receiver in the holder. | 1325 // stored something else than the receiver in the holder. |
1328 Handle<Map> transition( | 1326 Handle<Map> transition( |
1329 lookup->GetTransitionTarget(receiver->map()), isolate()); | 1327 lookup->GetTransitionTarget(receiver->map()), isolate()); |
1330 int descriptor = transition->LastAdded(); | 1328 int descriptor = transition->LastAdded(); |
1331 | 1329 |
1332 DescriptorArray* target_descriptors = transition->instance_descriptors(); | 1330 DescriptorArray* target_descriptors = transition->instance_descriptors(); |
1333 PropertyDetails details = target_descriptors->GetDetails(descriptor); | 1331 PropertyDetails details = target_descriptors->GetDetails(descriptor); |
1334 | 1332 |
1335 if (details.type() == CALLBACKS || details.attributes() != NONE) break; | 1333 if (details.type() == CALLBACKS || details.attributes() != NONE) break; |
1336 | 1334 |
1337 return compiler.CompileStoreTransition( | 1335 return compiler.CompileStoreTransition( |
1338 receiver, lookup, transition, name); | 1336 receiver, lookup, transition, name); |
1339 } | 1337 } |
1340 case NORMAL: | 1338 case NORMAL: |
1341 if (kind() == Code::KEYED_STORE_IC) break; | 1339 if (kind() == Code::KEYED_STORE_IC) break; |
1342 if (receiver->IsJSGlobalProxy() || receiver->IsGlobalObject()) { | 1340 if (receiver->IsGlobalObject()) { |
1343 // The stub generated for the global object picks the value directly | 1341 // The stub generated for the global object picks the value directly |
1344 // from the property cell. So the property must be directly on the | 1342 // from the property cell. So the property must be directly on the |
1345 // global object. | 1343 // global object. |
1346 Handle<GlobalObject> global = receiver->IsJSGlobalProxy() | 1344 Handle<GlobalObject> global = Handle<GlobalObject>::cast(receiver); |
1347 ? handle(GlobalObject::cast(receiver->GetPrototype())) | |
1348 : Handle<GlobalObject>::cast(receiver); | |
1349 Handle<PropertyCell> cell(global->GetPropertyCell(lookup), isolate()); | 1345 Handle<PropertyCell> cell(global->GetPropertyCell(lookup), isolate()); |
1350 Handle<HeapType> union_type = PropertyCell::UpdatedType(cell, value); | 1346 Handle<HeapType> union_type = PropertyCell::UpdatedType(cell, value); |
1351 StoreGlobalStub stub( | 1347 StoreGlobalStub stub(union_type->IsConstant()); |
1352 union_type->IsConstant(), receiver->IsJSGlobalProxy()); | 1348 |
1353 Handle<Code> code = stub.GetCodeCopyFromTemplate( | 1349 Handle<Code> code = stub.GetCodeCopyFromTemplate( |
1354 isolate(), *global, *cell); | 1350 isolate(), receiver->map(), *cell); |
1355 // TODO(verwaest): Move caching of these NORMAL stubs outside as well. | 1351 // TODO(verwaest): Move caching of these NORMAL stubs outside as well. |
1356 HeapObject::UpdateMapCodeCache(receiver, name, code); | 1352 HeapObject::UpdateMapCodeCache(receiver, name, code); |
1357 return code; | 1353 return code; |
1358 } | 1354 } |
1359 ASSERT(holder.is_identical_to(receiver)); | 1355 ASSERT(holder.is_identical_to(receiver)); |
1360 return isolate()->builtins()->StoreIC_Normal(); | 1356 return isolate()->builtins()->StoreIC_Normal(); |
1361 case CALLBACKS: { | 1357 case CALLBACKS: { |
1362 if (kind() == Code::KEYED_STORE_IC) break; | 1358 if (kind() == Code::KEYED_STORE_IC) break; |
1363 Handle<Object> callback(lookup->GetCallbackObject(), isolate()); | 1359 Handle<Object> callback(lookup->GetCallbackObject(), isolate()); |
1364 if (callback->IsExecutableAccessorInfo()) { | 1360 if (callback->IsExecutableAccessorInfo()) { |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1681 JSObject::cast(*object)->map()->is_observed()); | 1677 JSObject::cast(*object)->map()->is_observed()); |
1682 if (use_ic && !object->IsSmi()) { | 1678 if (use_ic && !object->IsSmi()) { |
1683 // Don't use ICs for maps of the objects in Array's prototype chain. We | 1679 // Don't use ICs for maps of the objects in Array's prototype chain. We |
1684 // expect to be able to trap element sets to objects with those maps in | 1680 // expect to be able to trap element sets to objects with those maps in |
1685 // the runtime to enable optimization of element hole access. | 1681 // the runtime to enable optimization of element hole access. |
1686 Handle<HeapObject> heap_object = Handle<HeapObject>::cast(object); | 1682 Handle<HeapObject> heap_object = Handle<HeapObject>::cast(object); |
1687 if (heap_object->map()->IsMapInArrayPrototypeChain()) use_ic = false; | 1683 if (heap_object->map()->IsMapInArrayPrototypeChain()) use_ic = false; |
1688 } | 1684 } |
1689 | 1685 |
1690 if (use_ic) { | 1686 if (use_ic) { |
1691 ASSERT(!object->IsAccessCheckNeeded()); | 1687 ASSERT(!object->IsJSGlobalProxy()); |
1692 | 1688 |
1693 if (object->IsJSObject()) { | 1689 if (object->IsJSObject()) { |
1694 Handle<JSObject> receiver = Handle<JSObject>::cast(object); | 1690 Handle<JSObject> receiver = Handle<JSObject>::cast(object); |
1695 bool key_is_smi_like = key->IsSmi() || !key->ToSmi()->IsFailure(); | 1691 bool key_is_smi_like = key->IsSmi() || !key->ToSmi()->IsFailure(); |
1696 if (receiver->elements()->map() == | 1692 if (receiver->elements()->map() == |
1697 isolate()->heap()->non_strict_arguments_elements_map()) { | 1693 isolate()->heap()->non_strict_arguments_elements_map()) { |
1698 stub = non_strict_arguments_stub(); | 1694 stub = non_strict_arguments_stub(); |
1699 } else if (key_is_smi_like && | 1695 } else if (key_is_smi_like && |
1700 !(target().is_identical_to(non_strict_arguments_stub()))) { | 1696 !(target().is_identical_to(non_strict_arguments_stub()))) { |
1701 // We should go generic if receiver isn't a dictionary, but our | 1697 // We should go generic if receiver isn't a dictionary, but our |
(...skipping 1117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2819 #undef ADDR | 2815 #undef ADDR |
2820 }; | 2816 }; |
2821 | 2817 |
2822 | 2818 |
2823 Address IC::AddressFromUtilityId(IC::UtilityId id) { | 2819 Address IC::AddressFromUtilityId(IC::UtilityId id) { |
2824 return IC_utilities[id]; | 2820 return IC_utilities[id]; |
2825 } | 2821 } |
2826 | 2822 |
2827 | 2823 |
2828 } } // namespace v8::internal | 2824 } } // namespace v8::internal |
OLD | NEW |