OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/api.h" | 7 #include "src/api.h" |
8 #include "src/arguments.h" | 8 #include "src/arguments.h" |
9 #include "src/ast.h" | 9 #include "src/ast.h" |
10 #include "src/code-stubs.h" | 10 #include "src/code-stubs.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 | 27 |
28 | 28 |
29 void StubCache::Initialize() { | 29 void StubCache::Initialize() { |
30 ASSERT(IsPowerOf2(kPrimaryTableSize)); | 30 ASSERT(IsPowerOf2(kPrimaryTableSize)); |
31 ASSERT(IsPowerOf2(kSecondaryTableSize)); | 31 ASSERT(IsPowerOf2(kSecondaryTableSize)); |
32 Clear(); | 32 Clear(); |
33 } | 33 } |
34 | 34 |
35 | 35 |
36 static Code::Flags CommonStubCacheChecks(Name* name, Map* map, | 36 static Code::Flags CommonStubCacheChecks(Name* name, Map* map, |
37 Code::Flags flags, Heap* heap) { | 37 Code::Flags flags) { |
38 flags = Code::RemoveTypeAndHolderFromFlags(flags); | 38 flags = Code::RemoveTypeAndHolderFromFlags(flags); |
39 | 39 |
40 // Validate that the name does not move on scavenge, and that we | 40 // Validate that the name does not move on scavenge, and that we |
41 // can use identity checks instead of structural equality checks. | 41 // can use identity checks instead of structural equality checks. |
42 ASSERT(!heap->InNewSpace(name)); | 42 ASSERT(!name->GetHeap()->InNewSpace(name)); |
43 ASSERT(name->IsUniqueName()); | 43 ASSERT(name->IsUniqueName()); |
44 | 44 |
45 // The state bits are not important to the hash function because the stub | 45 // The state bits are not important to the hash function because the stub |
46 // cache only contains handlers. Make sure that the bits are the least | 46 // cache only contains handlers. Make sure that the bits are the least |
47 // significant so they will be the ones masked out. | 47 // significant so they will be the ones masked out. |
48 ASSERT_EQ(Code::HANDLER, Code::ExtractKindFromFlags(flags)); | 48 ASSERT_EQ(Code::HANDLER, Code::ExtractKindFromFlags(flags)); |
49 STATIC_ASSERT((Code::ICStateField::kMask & 1) == 1); | 49 STATIC_ASSERT((Code::ICStateField::kMask & 1) == 1); |
50 | 50 |
51 // Make sure that the code type and cache holder are not included in the hash. | 51 // Make sure that the code type and cache holder are not included in the hash. |
52 ASSERT(Code::ExtractTypeFromFlags(flags) == 0); | 52 ASSERT(Code::ExtractTypeFromFlags(flags) == 0); |
53 ASSERT(Code::ExtractCacheHolderFromFlags(flags) == 0); | 53 ASSERT(Code::ExtractCacheHolderFromFlags(flags) == 0); |
54 | 54 |
55 return flags; | 55 return flags; |
56 } | 56 } |
57 | 57 |
58 | 58 |
59 Code* StubCache::Set(Name* name, Map* map, Code* code) { | 59 Code* StubCache::Set(Name* name, Map* map, Code* code) { |
60 Code::Flags flags = | 60 Code::Flags flags = CommonStubCacheChecks(name, map, code->flags()); |
61 CommonStubCacheChecks(name, map, code->flags(), isolate()->heap()); | |
62 | 61 |
63 // Compute the primary entry. | 62 // Compute the primary entry. |
64 int primary_offset = PrimaryOffset(name, flags, map); | 63 int primary_offset = PrimaryOffset(name, flags, map); |
65 Entry* primary = entry(primary_, primary_offset); | 64 Entry* primary = entry(primary_, primary_offset); |
66 Code* old_code = primary->value; | 65 Code* old_code = primary->value; |
67 | 66 |
68 // If the primary entry has useful data in it, we retire it to the | 67 // If the primary entry has useful data in it, we retire it to the |
69 // secondary cache before overwriting it. | 68 // secondary cache before overwriting it. |
70 if (old_code != isolate_->builtins()->builtin(Builtins::kIllegal)) { | 69 if (old_code != isolate_->builtins()->builtin(Builtins::kIllegal)) { |
71 Map* old_map = primary->map; | 70 Map* old_map = primary->map; |
72 Code::Flags old_flags = | 71 Code::Flags old_flags = |
73 Code::RemoveTypeAndHolderFromFlags(old_code->flags()); | 72 Code::RemoveTypeAndHolderFromFlags(old_code->flags()); |
74 int seed = PrimaryOffset(primary->key, old_flags, old_map); | 73 int seed = PrimaryOffset(primary->key, old_flags, old_map); |
75 int secondary_offset = SecondaryOffset(primary->key, old_flags, seed); | 74 int secondary_offset = SecondaryOffset(primary->key, old_flags, seed); |
76 Entry* secondary = entry(secondary_, secondary_offset); | 75 Entry* secondary = entry(secondary_, secondary_offset); |
77 *secondary = *primary; | 76 *secondary = *primary; |
78 } | 77 } |
79 | 78 |
80 // Update primary cache. | 79 // Update primary cache. |
81 primary->key = name; | 80 primary->key = name; |
82 primary->value = code; | 81 primary->value = code; |
83 primary->map = map; | 82 primary->map = map; |
84 isolate()->counters()->megamorphic_stub_cache_updates()->Increment(); | 83 isolate()->counters()->megamorphic_stub_cache_updates()->Increment(); |
85 return code; | 84 return code; |
86 } | 85 } |
87 | 86 |
88 | 87 |
89 Code* StubCache::Get(Name* name, Map* map, Code::Flags flags) { | 88 Code* StubCache::Get(Name* name, Map* map, Code::Flags flags) { |
90 flags = CommonStubCacheChecks(name, map, flags, isolate()->heap()); | 89 flags = CommonStubCacheChecks(name, map, flags); |
91 int primary_offset = PrimaryOffset(name, flags, map); | 90 int primary_offset = PrimaryOffset(name, flags, map); |
92 Entry* primary = entry(primary_, primary_offset); | 91 Entry* primary = entry(primary_, primary_offset); |
93 if (primary->key == name && primary->map == map) { | 92 if (primary->key == name && primary->map == map) { |
94 return primary->value; | 93 return primary->value; |
95 } | 94 } |
96 int secondary_offset = SecondaryOffset(name, flags, primary_offset); | 95 int secondary_offset = SecondaryOffset(name, flags, primary_offset); |
97 Entry* secondary = entry(secondary_, secondary_offset); | 96 Entry* secondary = entry(secondary_, secondary_offset); |
98 if (secondary->key == name && secondary->map == map) { | 97 if (secondary->key == name && secondary->map == map) { |
99 return secondary->value; | 98 return secondary->value; |
100 } | 99 } |
101 return NULL; | 100 return NULL; |
102 } | 101 } |
103 | 102 |
104 | 103 |
105 Handle<Code> PropertyICCompiler::Find(Handle<Name> name, | 104 Handle<Code> PropertyICCompiler::Find(Handle<Name> name, |
106 Handle<Map> stub_holder, Code::Kind kind, | 105 Handle<Map> stub_holder, Code::Kind kind, |
107 ExtraICState extra_state, | 106 ExtraICState extra_state, |
108 CacheHolderFlag cache_holder) { | 107 CacheHolderFlag cache_holder) { |
109 Code::Flags flags = Code::ComputeMonomorphicFlags( | 108 Code::Flags flags = Code::ComputeMonomorphicFlags( |
110 kind, extra_state, cache_holder); | 109 kind, extra_state, cache_holder); |
111 Handle<Object> probe(stub_holder->FindInCodeCache(*name, flags), | 110 Object* probe = stub_holder->FindInCodeCache(*name, flags); |
112 name->GetIsolate()); | 111 if (probe->IsCode()) return handle(Code::cast(probe)); |
113 if (probe->IsCode()) return Handle<Code>::cast(probe); | |
114 return Handle<Code>::null(); | 112 return Handle<Code>::null(); |
115 } | 113 } |
116 | 114 |
117 | 115 |
118 Handle<Code> PropertyHandlerCompiler::Find(Handle<Name> name, | 116 Handle<Code> PropertyHandlerCompiler::Find(Handle<Name> name, |
119 Handle<Map> stub_holder, | 117 Handle<Map> stub_holder, |
120 Code::Kind kind, | 118 Code::Kind kind, |
121 CacheHolderFlag cache_holder, | 119 CacheHolderFlag cache_holder, |
122 Code::StubType type) { | 120 Code::StubType type) { |
123 Code::Flags flags = Code::ComputeHandlerFlags(kind, type, cache_holder); | 121 Code::Flags flags = Code::ComputeHandlerFlags(kind, type, cache_holder); |
124 | 122 Object* probe = stub_holder->FindInCodeCache(*name, flags); |
125 Handle<Object> probe(stub_holder->FindInCodeCache(*name, flags), | 123 if (probe->IsCode()) return handle(Code::cast(probe)); |
126 name->GetIsolate()); | |
127 if (probe->IsCode()) return Handle<Code>::cast(probe); | |
128 return Handle<Code>::null(); | 124 return Handle<Code>::null(); |
129 } | 125 } |
130 | 126 |
131 | 127 |
132 Handle<Code> PropertyICCompiler::ComputeMonomorphic( | 128 Handle<Code> PropertyICCompiler::ComputeMonomorphic( |
133 Code::Kind kind, Handle<Name> name, Handle<HeapType> type, | 129 Code::Kind kind, Handle<Name> name, Handle<HeapType> type, |
134 Handle<Code> handler, ExtraICState extra_ic_state) { | 130 Handle<Code> handler, ExtraICState extra_ic_state) { |
135 Isolate* isolate = name->GetIsolate(); | 131 Isolate* isolate = name->GetIsolate(); |
136 if (handler.is_identical_to(isolate->builtins()->LoadIC_Normal()) || | 132 if (handler.is_identical_to(isolate->builtins()->LoadIC_Normal()) || |
137 handler.is_identical_to(isolate->builtins()->StoreIC_Normal())) { | 133 handler.is_identical_to(isolate->builtins()->StoreIC_Normal())) { |
(...skipping 812 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
950 Handle<Code> NamedLoadHandlerCompiler::CompileLoadViaGetter( | 946 Handle<Code> NamedLoadHandlerCompiler::CompileLoadViaGetter( |
951 Handle<Name> name, Handle<JSFunction> getter) { | 947 Handle<Name> name, Handle<JSFunction> getter) { |
952 Frontend(receiver(), name); | 948 Frontend(receiver(), name); |
953 GenerateLoadViaGetter(masm(), type(), receiver(), getter); | 949 GenerateLoadViaGetter(masm(), type(), receiver(), getter); |
954 return GetCode(kind(), Code::FAST, name); | 950 return GetCode(kind(), Code::FAST, name); |
955 } | 951 } |
956 | 952 |
957 | 953 |
958 // TODO(verwaest): Cleanup. holder() is actually the receiver. | 954 // TODO(verwaest): Cleanup. holder() is actually the receiver. |
959 Handle<Code> NamedStoreHandlerCompiler::CompileStoreTransition( | 955 Handle<Code> NamedStoreHandlerCompiler::CompileStoreTransition( |
960 LookupResult* lookup, Handle<Map> transition, Handle<Name> name) { | 956 Handle<Map> transition, Handle<Name> name) { |
961 Label miss, slow; | 957 Label miss, slow; |
962 | 958 |
963 // Ensure no transitions to deprecated maps are followed. | 959 // Ensure no transitions to deprecated maps are followed. |
964 __ CheckMapDeprecated(transition, scratch1(), &miss); | 960 __ CheckMapDeprecated(transition, scratch1(), &miss); |
965 | 961 |
966 // Check that we are allowed to write this. | 962 // Check that we are allowed to write this. |
967 bool is_nonexistent = holder()->map() == transition->GetBackPointer(); | 963 bool is_nonexistent = holder()->map() == transition->GetBackPointer(); |
968 if (is_nonexistent) { | 964 if (is_nonexistent) { |
969 // Find the top object. | 965 // Find the top object. |
970 Handle<JSObject> last; | 966 Handle<JSObject> last; |
971 PrototypeIterator iter(isolate(), holder()); | 967 PrototypeIterator iter(isolate(), holder()); |
972 do { | 968 do { |
973 last = Handle<JSObject>::cast(PrototypeIterator::GetCurrent(iter)); | 969 last = Handle<JSObject>::cast(PrototypeIterator::GetCurrent(iter)); |
974 iter.Advance(); | 970 iter.Advance(); |
975 } while (!iter.IsAtEnd()); | 971 } while (!iter.IsAtEnd()); |
976 set_holder(last); | 972 set_holder(last); |
977 } | 973 } |
978 | 974 |
979 Register holder_reg = FrontendHeader(receiver(), name, &miss); | 975 Register holder_reg = FrontendHeader(receiver(), name, &miss); |
980 | 976 |
981 // If no property was found, and the holder (the last object in the | 977 // If no property was found, and the holder (the last object in the |
982 // prototype chain) is in slow mode, we need to do a negative lookup on the | 978 // prototype chain) is in slow mode, we need to do a negative lookup on the |
983 // holder. | 979 // holder. |
984 if (is_nonexistent) { | 980 if (is_nonexistent) { |
985 GenerateNegativeHolderLookup(masm(), holder(), holder_reg, name, &miss); | 981 GenerateNegativeHolderLookup(holder_reg, name, &miss); |
986 } | 982 } |
987 | 983 |
988 GenerateStoreTransition(masm(), | 984 GenerateStoreTransition(transition, name, receiver(), this->name(), value(), |
989 lookup, | 985 scratch1(), scratch2(), scratch3(), &miss, &slow); |
990 transition, | |
991 name, | |
992 receiver(), this->name(), value(), | |
993 scratch1(), scratch2(), scratch3(), | |
994 &miss, | |
995 &slow); | |
996 | 986 |
997 // Handle store cache miss. | 987 // Handle store cache miss. |
998 GenerateRestoreName(masm(), &miss, name); | 988 GenerateRestoreName(&miss, name); |
999 TailCallBuiltin(masm(), MissBuiltin(kind())); | 989 TailCallBuiltin(masm(), MissBuiltin(kind())); |
1000 | 990 |
1001 GenerateRestoreName(masm(), &slow, name); | 991 GenerateRestoreName(&slow, name); |
1002 TailCallBuiltin(masm(), SlowBuiltin(kind())); | 992 TailCallBuiltin(masm(), SlowBuiltin(kind())); |
1003 return GetCode(kind(), Code::FAST, name); | 993 return GetCode(kind(), Code::FAST, name); |
1004 } | 994 } |
1005 | 995 |
1006 | 996 |
1007 Handle<Code> NamedStoreHandlerCompiler::CompileStoreField(LookupResult* lookup, | 997 Handle<Code> NamedStoreHandlerCompiler::CompileStoreField(LookupResult* lookup, |
1008 Handle<Name> name) { | 998 Handle<Name> name) { |
1009 Label miss; | 999 Label miss; |
1010 | 1000 |
1011 FrontendHeader(receiver(), name, &miss); | 1001 FrontendHeader(receiver(), name, &miss); |
1012 | 1002 |
1013 // Generate store field code. | 1003 // Generate store field code. |
1014 GenerateStoreField(masm(), holder(), lookup, receiver(), this->name(), | 1004 GenerateStoreField(holder(), lookup, receiver(), this->name(), value(), |
1015 value(), scratch1(), scratch2(), &miss); | 1005 scratch1(), scratch2(), &miss); |
1016 | 1006 |
1017 // Handle store cache miss. | 1007 // Handle store cache miss. |
1018 __ bind(&miss); | 1008 __ bind(&miss); |
1019 TailCallBuiltin(masm(), MissBuiltin(kind())); | 1009 TailCallBuiltin(masm(), MissBuiltin(kind())); |
1020 return GetCode(kind(), Code::FAST, name); | 1010 return GetCode(kind(), Code::FAST, name); |
1021 } | 1011 } |
1022 | 1012 |
1023 | 1013 |
1024 Handle<Code> NamedStoreHandlerCompiler::CompileStoreArrayLength( | |
1025 LookupResult* lookup, Handle<Name> name) { | |
1026 // This accepts as a receiver anything JSArray::SetElementsLength accepts | |
1027 // (currently anything except for external arrays which means anything with | |
1028 // elements of FixedArray type). Value must be a number, but only smis are | |
1029 // accepted as the most common case. | |
1030 Label miss; | |
1031 | |
1032 // Check that value is a smi. | |
1033 __ JumpIfNotSmi(value(), &miss); | |
1034 | |
1035 // Generate tail call to StoreIC_ArrayLength. | |
1036 GenerateStoreArrayLength(); | |
1037 | |
1038 // Handle miss case. | |
1039 __ bind(&miss); | |
1040 TailCallBuiltin(masm(), MissBuiltin(kind())); | |
1041 return GetCode(kind(), Code::FAST, name); | |
1042 } | |
1043 | |
1044 | |
1045 Handle<Code> NamedStoreHandlerCompiler::CompileStoreViaSetter( | 1014 Handle<Code> NamedStoreHandlerCompiler::CompileStoreViaSetter( |
1046 Handle<JSObject> object, Handle<Name> name, Handle<JSFunction> setter) { | 1015 Handle<JSObject> object, Handle<Name> name, Handle<JSFunction> setter) { |
1047 Frontend(receiver(), name); | 1016 Frontend(receiver(), name); |
1048 GenerateStoreViaSetter(masm(), type(), receiver(), setter); | 1017 GenerateStoreViaSetter(masm(), type(), receiver(), setter); |
1049 | 1018 |
1050 return GetCode(kind(), Code::FAST, name); | 1019 return GetCode(kind(), Code::FAST, name); |
1051 } | 1020 } |
1052 | 1021 |
1053 | 1022 |
1054 Handle<Code> NamedStoreHandlerCompiler::CompileStoreCallback( | 1023 Handle<Code> NamedStoreHandlerCompiler::CompileStoreCallback( |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1327 Handle<FunctionTemplateInfo>( | 1296 Handle<FunctionTemplateInfo>( |
1328 FunctionTemplateInfo::cast(signature->receiver())); | 1297 FunctionTemplateInfo::cast(signature->receiver())); |
1329 } | 1298 } |
1330 } | 1299 } |
1331 | 1300 |
1332 is_simple_api_call_ = true; | 1301 is_simple_api_call_ = true; |
1333 } | 1302 } |
1334 | 1303 |
1335 | 1304 |
1336 } } // namespace v8::internal | 1305 } } // namespace v8::internal |
OLD | NEW |