Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Side by Side Diff: src/ic.cc

Issue 170343002: Reland "Allow ICs to be generated for own global proxy." (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fix setting through global proxy without interceptor setter. Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/code-stubs-hydrogen.cc ('k') | src/isolate.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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->IsJSGlobalProxy()); 1072 ASSERT(!object->IsAccessCheckNeeded());
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 18 matching lines...) Expand all
1101 1101
1102 1102
1103 static bool LookupForWrite(Handle<JSObject> receiver, 1103 static bool LookupForWrite(Handle<JSObject> receiver,
1104 Handle<String> name, 1104 Handle<String> name,
1105 Handle<Object> value, 1105 Handle<Object> value,
1106 LookupResult* lookup, 1106 LookupResult* lookup,
1107 IC* ic) { 1107 IC* ic) {
1108 Handle<JSObject> holder = receiver; 1108 Handle<JSObject> holder = receiver;
1109 receiver->Lookup(*name, lookup); 1109 receiver->Lookup(*name, lookup);
1110 if (lookup->IsFound()) { 1110 if (lookup->IsFound()) {
1111 if (lookup->IsReadOnly() || !lookup->IsCacheable()) return false; 1111 if (lookup->IsInterceptor() && !HasInterceptorSetter(lookup->holder())) {
1112 1112 receiver->LocalLookupRealNamedProperty(*name, lookup);
1113 if (lookup->holder() == *receiver) { 1113 if (!lookup->IsFound()) return false;
1114 if (lookup->IsInterceptor() && !HasInterceptorSetter(*receiver)) {
1115 receiver->LocalLookupRealNamedProperty(*name, lookup);
1116 return lookup->IsFound() &&
1117 !lookup->IsReadOnly() &&
1118 lookup->CanHoldValue(value) &&
1119 lookup->IsCacheable();
1120 }
1121 return lookup->CanHoldValue(value);
1122 } 1114 }
1123 1115
1116 if (lookup->IsReadOnly() || !lookup->IsCacheable()) return false;
1117 if (lookup->holder() == *receiver) return lookup->CanHoldValue(value);
1124 if (lookup->IsPropertyCallbacks()) return true; 1118 if (lookup->IsPropertyCallbacks()) return true;
1125 // JSGlobalProxy always goes via the runtime, so it's safe to cache. 1119 // JSGlobalProxy either stores on the global object in the prototype, or
1120 // goes into the runtime if access checks are needed, so this is always
1121 // safe.
1126 if (receiver->IsJSGlobalProxy()) return true; 1122 if (receiver->IsJSGlobalProxy()) return true;
1127 // Currently normal holders in the prototype chain are not supported. They 1123 // Currently normal holders in the prototype chain are not supported. They
1128 // would require a runtime positive lookup and verification that the details 1124 // would require a runtime positive lookup and verification that the details
1129 // have not changed. 1125 // have not changed.
1130 if (lookup->IsInterceptor() || lookup->IsNormal()) return false; 1126 if (lookup->IsInterceptor() || lookup->IsNormal()) return false;
1131 holder = Handle<JSObject>(lookup->holder(), lookup->isolate()); 1127 holder = Handle<JSObject>(lookup->holder(), lookup->isolate());
1132 } 1128 }
1133 1129
1134 // While normally LookupTransition gets passed the receiver, in this case we 1130 // While normally LookupTransition gets passed the receiver, in this case we
1135 // pass the holder of the property that we overwrite. This keeps the holder in 1131 // 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
1302 PatchCache(CurrentTypeOf(receiver, isolate()), name, code); 1298 PatchCache(CurrentTypeOf(receiver, isolate()), name, code);
1303 TRACE_IC("StoreIC", name); 1299 TRACE_IC("StoreIC", name);
1304 } 1300 }
1305 1301
1306 1302
1307 Handle<Code> StoreIC::CompileHandler(LookupResult* lookup, 1303 Handle<Code> StoreIC::CompileHandler(LookupResult* lookup,
1308 Handle<Object> object, 1304 Handle<Object> object,
1309 Handle<String> name, 1305 Handle<String> name,
1310 Handle<Object> value, 1306 Handle<Object> value,
1311 InlineCacheHolderFlag cache_holder) { 1307 InlineCacheHolderFlag cache_holder) {
1312 if (object->IsJSGlobalProxy()) return slow_stub(); 1308 if (object->IsAccessCheckNeeded()) return slow_stub();
1313 ASSERT(cache_holder == OWN_MAP); 1309 ASSERT(cache_holder == OWN_MAP);
1314 // This is currently guaranteed by checks in StoreIC::Store. 1310 // This is currently guaranteed by checks in StoreIC::Store.
1315 Handle<JSObject> receiver = Handle<JSObject>::cast(object); 1311 Handle<JSObject> receiver = Handle<JSObject>::cast(object);
1316 1312
1317 Handle<JSObject> holder(lookup->holder()); 1313 Handle<JSObject> holder(lookup->holder());
1318 // Handlers do not use strict mode. 1314 // Handlers do not use strict mode.
1319 StoreStubCompiler compiler(isolate(), kNonStrictMode, kind()); 1315 StoreStubCompiler compiler(isolate(), kNonStrictMode, kind());
1320 switch (lookup->type()) { 1316 switch (lookup->type()) {
1321 case FIELD: 1317 case FIELD:
1322 return compiler.CompileStoreField(receiver, lookup, name); 1318 return compiler.CompileStoreField(receiver, lookup, name);
1323 case TRANSITION: { 1319 case TRANSITION: {
1324 // Explicitly pass in the receiver map since LookupForWrite may have 1320 // Explicitly pass in the receiver map since LookupForWrite may have
1325 // stored something else than the receiver in the holder. 1321 // stored something else than the receiver in the holder.
1326 Handle<Map> transition( 1322 Handle<Map> transition(
1327 lookup->GetTransitionTarget(receiver->map()), isolate()); 1323 lookup->GetTransitionTarget(receiver->map()), isolate());
1328 int descriptor = transition->LastAdded(); 1324 int descriptor = transition->LastAdded();
1329 1325
1330 DescriptorArray* target_descriptors = transition->instance_descriptors(); 1326 DescriptorArray* target_descriptors = transition->instance_descriptors();
1331 PropertyDetails details = target_descriptors->GetDetails(descriptor); 1327 PropertyDetails details = target_descriptors->GetDetails(descriptor);
1332 1328
1333 if (details.type() == CALLBACKS || details.attributes() != NONE) break; 1329 if (details.type() == CALLBACKS || details.attributes() != NONE) break;
1334 1330
1335 return compiler.CompileStoreTransition( 1331 return compiler.CompileStoreTransition(
1336 receiver, lookup, transition, name); 1332 receiver, lookup, transition, name);
1337 } 1333 }
1338 case NORMAL: 1334 case NORMAL:
1339 if (kind() == Code::KEYED_STORE_IC) break; 1335 if (kind() == Code::KEYED_STORE_IC) break;
1340 if (receiver->IsGlobalObject()) { 1336 if (receiver->IsJSGlobalProxy() || receiver->IsGlobalObject()) {
1341 // The stub generated for the global object picks the value directly 1337 // The stub generated for the global object picks the value directly
1342 // from the property cell. So the property must be directly on the 1338 // from the property cell. So the property must be directly on the
1343 // global object. 1339 // global object.
1344 Handle<GlobalObject> global = Handle<GlobalObject>::cast(receiver); 1340 Handle<GlobalObject> global = receiver->IsJSGlobalProxy()
1341 ? handle(GlobalObject::cast(receiver->GetPrototype()))
1342 : Handle<GlobalObject>::cast(receiver);
1345 Handle<PropertyCell> cell(global->GetPropertyCell(lookup), isolate()); 1343 Handle<PropertyCell> cell(global->GetPropertyCell(lookup), isolate());
1346 Handle<HeapType> union_type = PropertyCell::UpdatedType(cell, value); 1344 Handle<HeapType> union_type = PropertyCell::UpdatedType(cell, value);
1347 StoreGlobalStub stub(union_type->IsConstant()); 1345 StoreGlobalStub stub(
1348 1346 union_type->IsConstant(), receiver->IsJSGlobalProxy());
1349 Handle<Code> code = stub.GetCodeCopyFromTemplate( 1347 Handle<Code> code = stub.GetCodeCopyFromTemplate(
1350 isolate(), receiver->map(), *cell); 1348 isolate(), *global, *cell);
1351 // TODO(verwaest): Move caching of these NORMAL stubs outside as well. 1349 // TODO(verwaest): Move caching of these NORMAL stubs outside as well.
1352 HeapObject::UpdateMapCodeCache(receiver, name, code); 1350 HeapObject::UpdateMapCodeCache(receiver, name, code);
1353 return code; 1351 return code;
1354 } 1352 }
1355 ASSERT(holder.is_identical_to(receiver)); 1353 ASSERT(holder.is_identical_to(receiver));
1356 return isolate()->builtins()->StoreIC_Normal(); 1354 return isolate()->builtins()->StoreIC_Normal();
1357 case CALLBACKS: { 1355 case CALLBACKS: {
1358 if (kind() == Code::KEYED_STORE_IC) break; 1356 if (kind() == Code::KEYED_STORE_IC) break;
1359 Handle<Object> callback(lookup->GetCallbackObject(), isolate()); 1357 Handle<Object> callback(lookup->GetCallbackObject(), isolate());
1360 if (callback->IsExecutableAccessorInfo()) { 1358 if (callback->IsExecutableAccessorInfo()) {
(...skipping 20 matching lines...) Expand all
1381 receiver, holder, name, Handle<JSFunction>::cast(setter)); 1379 receiver, holder, name, Handle<JSFunction>::cast(setter));
1382 } 1380 }
1383 // TODO(dcarney): Handle correctly. 1381 // TODO(dcarney): Handle correctly.
1384 if (callback->IsDeclaredAccessorInfo()) break; 1382 if (callback->IsDeclaredAccessorInfo()) break;
1385 ASSERT(callback->IsForeign()); 1383 ASSERT(callback->IsForeign());
1386 // No IC support for old-style native accessors. 1384 // No IC support for old-style native accessors.
1387 break; 1385 break;
1388 } 1386 }
1389 case INTERCEPTOR: 1387 case INTERCEPTOR:
1390 if (kind() == Code::KEYED_STORE_IC) break; 1388 if (kind() == Code::KEYED_STORE_IC) break;
1391 ASSERT(HasInterceptorSetter(*receiver)); 1389 ASSERT(HasInterceptorSetter(*holder));
1392 return compiler.CompileStoreInterceptor(receiver, name); 1390 return compiler.CompileStoreInterceptor(receiver, name);
1393 case CONSTANT: 1391 case CONSTANT:
1394 break; 1392 break;
1395 case NONEXISTENT: 1393 case NONEXISTENT:
1396 case HANDLER: 1394 case HANDLER:
1397 UNREACHABLE(); 1395 UNREACHABLE();
1398 break; 1396 break;
1399 } 1397 }
1400 return slow_stub(); 1398 return slow_stub();
1401 } 1399 }
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
1677 JSObject::cast(*object)->map()->is_observed()); 1675 JSObject::cast(*object)->map()->is_observed());
1678 if (use_ic && !object->IsSmi()) { 1676 if (use_ic && !object->IsSmi()) {
1679 // Don't use ICs for maps of the objects in Array's prototype chain. We 1677 // Don't use ICs for maps of the objects in Array's prototype chain. We
1680 // expect to be able to trap element sets to objects with those maps in 1678 // expect to be able to trap element sets to objects with those maps in
1681 // the runtime to enable optimization of element hole access. 1679 // the runtime to enable optimization of element hole access.
1682 Handle<HeapObject> heap_object = Handle<HeapObject>::cast(object); 1680 Handle<HeapObject> heap_object = Handle<HeapObject>::cast(object);
1683 if (heap_object->map()->IsMapInArrayPrototypeChain()) use_ic = false; 1681 if (heap_object->map()->IsMapInArrayPrototypeChain()) use_ic = false;
1684 } 1682 }
1685 1683
1686 if (use_ic) { 1684 if (use_ic) {
1687 ASSERT(!object->IsJSGlobalProxy()); 1685 ASSERT(!object->IsAccessCheckNeeded());
1688 1686
1689 if (object->IsJSObject()) { 1687 if (object->IsJSObject()) {
1690 Handle<JSObject> receiver = Handle<JSObject>::cast(object); 1688 Handle<JSObject> receiver = Handle<JSObject>::cast(object);
1691 bool key_is_smi_like = key->IsSmi() || !key->ToSmi()->IsFailure(); 1689 bool key_is_smi_like = key->IsSmi() || !key->ToSmi()->IsFailure();
1692 if (receiver->elements()->map() == 1690 if (receiver->elements()->map() ==
1693 isolate()->heap()->non_strict_arguments_elements_map()) { 1691 isolate()->heap()->non_strict_arguments_elements_map()) {
1694 stub = non_strict_arguments_stub(); 1692 stub = non_strict_arguments_stub();
1695 } else if (key_is_smi_like && 1693 } else if (key_is_smi_like &&
1696 !(target().is_identical_to(non_strict_arguments_stub()))) { 1694 !(target().is_identical_to(non_strict_arguments_stub()))) {
1697 // We should go generic if receiver isn't a dictionary, but our 1695 // We should go generic if receiver isn't a dictionary, but our
(...skipping 1117 matching lines...) Expand 10 before | Expand all | Expand 10 after
2815 #undef ADDR 2813 #undef ADDR
2816 }; 2814 };
2817 2815
2818 2816
2819 Address IC::AddressFromUtilityId(IC::UtilityId id) { 2817 Address IC::AddressFromUtilityId(IC::UtilityId id) {
2820 return IC_utilities[id]; 2818 return IC_utilities[id];
2821 } 2819 }
2822 2820
2823 2821
2824 } } // namespace v8::internal 2822 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/code-stubs-hydrogen.cc ('k') | src/isolate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698