OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/compiler/js-native-context-specialization.h" | 5 #include "src/compiler/js-native-context-specialization.h" |
6 | 6 |
7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
8 #include "src/compilation-dependencies.h" | 8 #include "src/compilation-dependencies.h" |
9 #include "src/compiler/access-builder.h" | 9 #include "src/compiler/access-builder.h" |
10 #include "src/compiler/js-graph.h" | 10 #include "src/compiler/js-graph.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 | 27 |
28 | 28 |
29 JSNativeContextSpecialization::JSNativeContextSpecialization( | 29 JSNativeContextSpecialization::JSNativeContextSpecialization( |
30 Editor* editor, JSGraph* jsgraph, Flags flags, | 30 Editor* editor, JSGraph* jsgraph, Flags flags, |
31 Handle<GlobalObject> global_object, CompilationDependencies* dependencies, | 31 Handle<GlobalObject> global_object, CompilationDependencies* dependencies, |
32 Zone* zone) | 32 Zone* zone) |
33 : AdvancedReducer(editor), | 33 : AdvancedReducer(editor), |
34 jsgraph_(jsgraph), | 34 jsgraph_(jsgraph), |
35 flags_(flags), | 35 flags_(flags), |
36 global_object_(global_object), | 36 global_object_(global_object), |
| 37 native_context_(global_object->native_context(), isolate()), |
37 dependencies_(dependencies), | 38 dependencies_(dependencies), |
38 zone_(zone) {} | 39 zone_(zone) {} |
39 | 40 |
40 | 41 |
41 Reduction JSNativeContextSpecialization::Reduce(Node* node) { | 42 Reduction JSNativeContextSpecialization::Reduce(Node* node) { |
42 switch (node->opcode()) { | 43 switch (node->opcode()) { |
43 case IrOpcode::kJSLoadGlobal: | 44 case IrOpcode::kJSLoadGlobal: |
44 return ReduceJSLoadGlobal(node); | 45 return ReduceJSLoadGlobal(node); |
45 case IrOpcode::kJSStoreGlobal: | 46 case IrOpcode::kJSStoreGlobal: |
46 return ReduceJSStoreGlobal(node); | 47 return ReduceJSStoreGlobal(node); |
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 | 429 |
429 // Don't search on the prototype chain for special indices in case of | 430 // Don't search on the prototype chain for special indices in case of |
430 // integer indexed exotic objects (see ES6 section 9.4.5). | 431 // integer indexed exotic objects (see ES6 section 9.4.5). |
431 if (map->IsJSTypedArrayMap() && name->IsString() && | 432 if (map->IsJSTypedArrayMap() && name->IsString() && |
432 IsSpecialIndex(isolate()->unicode_cache(), String::cast(*name))) { | 433 IsSpecialIndex(isolate()->unicode_cache(), String::cast(*name))) { |
433 break; | 434 break; |
434 } | 435 } |
435 | 436 |
436 // Walk up the prototype chain. | 437 // Walk up the prototype chain. |
437 if (!map->prototype()->IsJSObject()) { | 438 if (!map->prototype()->IsJSObject()) { |
438 // TODO(bmeurer): Handle the not found case if the prototype is null. | 439 // Perform the implicit ToObject for primitives here. |
439 break; | 440 // Implemented according to ES6 section 7.3.2 GetV (V, P). |
| 441 Handle<JSFunction> constructor; |
| 442 if (Map::GetConstructorFunction(map, native_context()) |
| 443 .ToHandle(&constructor)) { |
| 444 map = handle(constructor->initial_map(), isolate()); |
| 445 DCHECK(map->prototype()->IsJSObject()); |
| 446 } else { |
| 447 // TODO(bmeurer): Handle the not found case if the prototype is null. |
| 448 break; |
| 449 } |
440 } | 450 } |
441 Handle<JSObject> map_prototype(JSObject::cast(map->prototype()), isolate()); | 451 Handle<JSObject> map_prototype(JSObject::cast(map->prototype()), isolate()); |
442 if (map_prototype->map()->is_deprecated()) { | 452 if (map_prototype->map()->is_deprecated()) { |
443 // Try to migrate the prototype object so we don't embed the deprecated | 453 // Try to migrate the prototype object so we don't embed the deprecated |
444 // map into the optimized code. | 454 // map into the optimized code. |
445 JSObject::TryMigrateInstance(map_prototype); | 455 JSObject::TryMigrateInstance(map_prototype); |
446 } | 456 } |
447 map = handle(map_prototype->map(), isolate()); | 457 map = handle(map_prototype->map(), isolate()); |
448 holder = map_prototype; | 458 holder = map_prototype; |
449 } | 459 } |
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
886 result->immutable = IsImmutableVariableMode(lookup_result.mode); | 896 result->immutable = IsImmutableVariableMode(lookup_result.mode); |
887 result->index = lookup_result.slot_index; | 897 result->index = lookup_result.slot_index; |
888 return true; | 898 return true; |
889 } | 899 } |
890 | 900 |
891 | 901 |
892 void JSNativeContextSpecialization::AssumePrototypesStable( | 902 void JSNativeContextSpecialization::AssumePrototypesStable( |
893 Type* receiver_type, Handle<JSObject> holder) { | 903 Type* receiver_type, Handle<JSObject> holder) { |
894 // Determine actual holder and perform prototype chain checks. | 904 // Determine actual holder and perform prototype chain checks. |
895 for (auto i = receiver_type->Classes(); !i.Done(); i.Advance()) { | 905 for (auto i = receiver_type->Classes(); !i.Done(); i.Advance()) { |
896 Handle<Map> const map = i.Current(); | 906 Handle<Map> map = i.Current(); |
| 907 // Perform the implicit ToObject for primitives here. |
| 908 // Implemented according to ES6 section 7.3.2 GetV (V, P). |
| 909 Handle<JSFunction> constructor; |
| 910 if (Map::GetConstructorFunction(map, native_context()) |
| 911 .ToHandle(&constructor)) { |
| 912 map = handle(constructor->initial_map(), isolate()); |
| 913 } |
897 for (PrototypeIterator j(map);; j.Advance()) { | 914 for (PrototypeIterator j(map);; j.Advance()) { |
898 // Check that the {prototype} still has the same map. All prototype | 915 // Check that the {prototype} still has the same map. All prototype |
899 // maps are guaranteed to be stable, so it's sufficient to add a | 916 // maps are guaranteed to be stable, so it's sufficient to add a |
900 // stability dependency here. | 917 // stability dependency here. |
901 Handle<JSReceiver> const prototype = | 918 Handle<JSReceiver> const prototype = |
902 PrototypeIterator::GetCurrent<JSReceiver>(j); | 919 PrototypeIterator::GetCurrent<JSReceiver>(j); |
903 dependencies()->AssumeMapStable(handle(prototype->map(), isolate())); | 920 dependencies()->AssumeMapStable(handle(prototype->map(), isolate())); |
904 // Stop once we get to the holder. | 921 // Stop once we get to the holder. |
905 if (prototype.is_identical_to(holder)) break; | 922 if (prototype.is_identical_to(holder)) break; |
906 } | 923 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
938 } | 955 } |
939 | 956 |
940 | 957 |
941 SimplifiedOperatorBuilder* JSNativeContextSpecialization::simplified() const { | 958 SimplifiedOperatorBuilder* JSNativeContextSpecialization::simplified() const { |
942 return jsgraph()->simplified(); | 959 return jsgraph()->simplified(); |
943 } | 960 } |
944 | 961 |
945 } // namespace compiler | 962 } // namespace compiler |
946 } // namespace internal | 963 } // namespace internal |
947 } // namespace v8 | 964 } // namespace v8 |
OLD | NEW |