OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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/ic/ic-compiler.h" | 5 #include "src/ic/ic-compiler.h" |
6 | 6 |
7 #include "src/ic/handler-compiler.h" | 7 #include "src/ic/handler-compiler.h" |
8 #include "src/ic/ic-inl.h" | 8 #include "src/ic/ic-inl.h" |
9 #include "src/profiler/cpu-profiler.h" | 9 #include "src/profiler/cpu-profiler.h" |
10 | 10 |
11 | 11 |
12 namespace v8 { | 12 namespace v8 { |
13 namespace internal { | 13 namespace internal { |
14 | 14 |
15 | 15 |
16 Handle<Code> PropertyICCompiler::Find(Handle<Name> name, | |
17 Handle<Map> stub_holder, Code::Kind kind, | |
18 ExtraICState extra_state, | |
19 CacheHolderFlag cache_holder) { | |
20 Code::Flags flags = | |
21 Code::ComputeMonomorphicFlags(kind, extra_state, cache_holder); | |
22 Object* probe = stub_holder->FindInCodeCache(*name, flags); | |
23 if (probe->IsCode()) return handle(Code::cast(probe)); | |
24 return Handle<Code>::null(); | |
25 } | |
26 | |
27 | |
28 bool PropertyICCompiler::IncludesNumberMap(MapHandleList* maps) { | |
29 for (int i = 0; i < maps->length(); ++i) { | |
30 if (maps->at(i)->instance_type() == HEAP_NUMBER_TYPE) return true; | |
31 } | |
32 return false; | |
33 } | |
34 | |
35 | |
36 Handle<Code> PropertyICCompiler::ComputeKeyedLoadMonomorphicHandler( | 16 Handle<Code> PropertyICCompiler::ComputeKeyedLoadMonomorphicHandler( |
37 Handle<Map> receiver_map, ExtraICState extra_ic_state) { | 17 Handle<Map> receiver_map, ExtraICState extra_ic_state) { |
38 Isolate* isolate = receiver_map->GetIsolate(); | 18 Isolate* isolate = receiver_map->GetIsolate(); |
39 bool is_js_array = receiver_map->instance_type() == JS_ARRAY_TYPE; | 19 bool is_js_array = receiver_map->instance_type() == JS_ARRAY_TYPE; |
40 ElementsKind elements_kind = receiver_map->elements_kind(); | 20 ElementsKind elements_kind = receiver_map->elements_kind(); |
41 | 21 |
42 // No need to check for an elements-free prototype chain here, the generated | 22 // No need to check for an elements-free prototype chain here, the generated |
43 // stub code needs to check that dynamically anyway. | 23 // stub code needs to check that dynamically anyway. |
44 bool convert_hole_to_undefined = | 24 bool convert_hole_to_undefined = |
45 is_js_array && elements_kind == FAST_HOLEY_ELEMENTS && | 25 is_js_array && elements_kind == FAST_HOLEY_ELEMENTS && |
(...skipping 30 matching lines...) Expand all Loading... |
76 store_mode == STORE_NO_TRANSITION_IGNORE_OUT_OF_BOUNDS || | 56 store_mode == STORE_NO_TRANSITION_IGNORE_OUT_OF_BOUNDS || |
77 store_mode == STORE_NO_TRANSITION_HANDLE_COW); | 57 store_mode == STORE_NO_TRANSITION_HANDLE_COW); |
78 | 58 |
79 PropertyICCompiler compiler(isolate, Code::KEYED_STORE_IC, extra_state); | 59 PropertyICCompiler compiler(isolate, Code::KEYED_STORE_IC, extra_state); |
80 Handle<Code> code = | 60 Handle<Code> code = |
81 compiler.CompileKeyedStoreMonomorphicHandler(receiver_map, store_mode); | 61 compiler.CompileKeyedStoreMonomorphicHandler(receiver_map, store_mode); |
82 return code; | 62 return code; |
83 } | 63 } |
84 | 64 |
85 | 65 |
86 Code* PropertyICCompiler::FindPreMonomorphic(Isolate* isolate, Code::Kind kind, | |
87 ExtraICState state) { | |
88 Code::Flags flags = Code::ComputeFlags(kind, PREMONOMORPHIC, state); | |
89 UnseededNumberDictionary* dictionary = | |
90 isolate->heap()->non_monomorphic_cache(); | |
91 int entry = dictionary->FindEntry(isolate, flags); | |
92 DCHECK(entry != -1); | |
93 Object* code = dictionary->ValueAt(entry); | |
94 // This might be called during the marking phase of the collector | |
95 // hence the unchecked cast. | |
96 return reinterpret_cast<Code*>(code); | |
97 } | |
98 | |
99 | |
100 static void FillCache(Isolate* isolate, Handle<Code> code) { | 66 static void FillCache(Isolate* isolate, Handle<Code> code) { |
101 Handle<UnseededNumberDictionary> dictionary = UnseededNumberDictionary::Set( | 67 Handle<UnseededNumberDictionary> dictionary = UnseededNumberDictionary::Set( |
102 isolate->factory()->non_monomorphic_cache(), code->flags(), code); | 68 isolate->factory()->non_monomorphic_cache(), code->flags(), code); |
103 isolate->heap()->SetRootNonMonomorphicCache(*dictionary); | 69 isolate->heap()->SetRootNonMonomorphicCache(*dictionary); |
104 } | 70 } |
105 | 71 |
106 | 72 |
107 Handle<Code> PropertyICCompiler::ComputeStore(Isolate* isolate, | 73 Handle<Code> PropertyICCompiler::ComputeStore(Isolate* isolate, |
108 InlineCacheState ic_state, | 74 InlineCacheState ic_state, |
109 ExtraICState extra_state) { | 75 ExtraICState extra_state) { |
| 76 DCHECK_EQ(MEGAMORPHIC, ic_state); |
110 Code::Flags flags = Code::ComputeFlags(Code::STORE_IC, ic_state, extra_state); | 77 Code::Flags flags = Code::ComputeFlags(Code::STORE_IC, ic_state, extra_state); |
111 Handle<UnseededNumberDictionary> cache = | 78 Handle<UnseededNumberDictionary> cache = |
112 isolate->factory()->non_monomorphic_cache(); | 79 isolate->factory()->non_monomorphic_cache(); |
113 int entry = cache->FindEntry(isolate, flags); | 80 int entry = cache->FindEntry(isolate, flags); |
114 if (entry != -1) return Handle<Code>(Code::cast(cache->ValueAt(entry))); | 81 if (entry != -1) return Handle<Code>(Code::cast(cache->ValueAt(entry))); |
115 | 82 |
116 PropertyICCompiler compiler(isolate, Code::STORE_IC); | 83 PropertyICCompiler compiler(isolate, Code::STORE_IC); |
117 Handle<Code> code; | 84 Handle<Code> code = compiler.CompileStoreMegamorphic(flags); |
118 if (ic_state == UNINITIALIZED) { | |
119 code = compiler.CompileStoreInitialize(flags); | |
120 } else if (ic_state == PREMONOMORPHIC) { | |
121 code = compiler.CompileStorePreMonomorphic(flags); | |
122 } else if (ic_state == GENERIC) { | |
123 code = compiler.CompileStoreGeneric(flags); | |
124 } else if (ic_state == MEGAMORPHIC) { | |
125 code = compiler.CompileStoreMegamorphic(flags); | |
126 } else { | |
127 UNREACHABLE(); | |
128 } | |
129 | 85 |
130 FillCache(isolate, code); | 86 FillCache(isolate, code); |
131 return code; | 87 return code; |
132 } | 88 } |
133 | 89 |
134 | 90 |
135 void PropertyICCompiler::ComputeKeyedStorePolymorphicHandlers( | 91 void PropertyICCompiler::ComputeKeyedStorePolymorphicHandlers( |
136 MapHandleList* receiver_maps, MapHandleList* transitioned_maps, | 92 MapHandleList* receiver_maps, MapHandleList* transitioned_maps, |
137 CodeHandleList* handlers, KeyedAccessStoreMode store_mode, | 93 CodeHandleList* handlers, KeyedAccessStoreMode store_mode, |
138 LanguageMode language_mode) { | 94 LanguageMode language_mode) { |
139 Isolate* isolate = receiver_maps->at(0)->GetIsolate(); | 95 Isolate* isolate = receiver_maps->at(0)->GetIsolate(); |
140 DCHECK(store_mode == STANDARD_STORE || | 96 DCHECK(store_mode == STANDARD_STORE || |
141 store_mode == STORE_AND_GROW_NO_TRANSITION || | 97 store_mode == STORE_AND_GROW_NO_TRANSITION || |
142 store_mode == STORE_NO_TRANSITION_IGNORE_OUT_OF_BOUNDS || | 98 store_mode == STORE_NO_TRANSITION_IGNORE_OUT_OF_BOUNDS || |
143 store_mode == STORE_NO_TRANSITION_HANDLE_COW); | 99 store_mode == STORE_NO_TRANSITION_HANDLE_COW); |
144 ExtraICState extra_state = | 100 ExtraICState extra_state = |
145 KeyedStoreIC::ComputeExtraICState(language_mode, store_mode); | 101 KeyedStoreIC::ComputeExtraICState(language_mode, store_mode); |
146 PropertyICCompiler compiler(isolate, Code::KEYED_STORE_IC, extra_state); | 102 PropertyICCompiler compiler(isolate, Code::KEYED_STORE_IC, extra_state); |
147 compiler.CompileKeyedStorePolymorphicHandlers( | 103 compiler.CompileKeyedStorePolymorphicHandlers( |
148 receiver_maps, transitioned_maps, handlers, store_mode); | 104 receiver_maps, transitioned_maps, handlers, store_mode); |
149 } | 105 } |
150 | 106 |
151 | 107 |
152 Handle<Code> PropertyICCompiler::CompileLoadInitialize(Code::Flags flags) { | |
153 LoadIC::GenerateInitialize(masm()); | |
154 Handle<Code> code = GetCodeWithFlags(flags, "CompileLoadInitialize"); | |
155 PROFILE(isolate(), CodeCreateEvent(Logger::LOAD_INITIALIZE_TAG, | |
156 AbstractCode::cast(*code), 0)); | |
157 return code; | |
158 } | |
159 | |
160 | |
161 Handle<Code> PropertyICCompiler::CompileStoreInitialize(Code::Flags flags) { | |
162 StoreIC::GenerateInitialize(masm()); | |
163 Handle<Code> code = GetCodeWithFlags(flags, "CompileStoreInitialize"); | |
164 PROFILE(isolate(), CodeCreateEvent(Logger::STORE_INITIALIZE_TAG, | |
165 AbstractCode::cast(*code), 0)); | |
166 return code; | |
167 } | |
168 | |
169 | |
170 Handle<Code> PropertyICCompiler::CompileStorePreMonomorphic(Code::Flags flags) { | |
171 StoreIC::GeneratePreMonomorphic(masm()); | |
172 Handle<Code> code = GetCodeWithFlags(flags, "CompileStorePreMonomorphic"); | |
173 PROFILE(isolate(), CodeCreateEvent(Logger::STORE_PREMONOMORPHIC_TAG, | |
174 AbstractCode::cast(*code), 0)); | |
175 return code; | |
176 } | |
177 | |
178 | |
179 Handle<Code> PropertyICCompiler::CompileStoreGeneric(Code::Flags flags) { | |
180 ExtraICState extra_state = Code::ExtractExtraICStateFromFlags(flags); | |
181 LanguageMode language_mode = StoreICState::GetLanguageMode(extra_state); | |
182 GenerateRuntimeSetProperty(masm(), language_mode); | |
183 Handle<Code> code = GetCodeWithFlags(flags, "CompileStoreGeneric"); | |
184 PROFILE(isolate(), CodeCreateEvent(Logger::STORE_GENERIC_TAG, | |
185 AbstractCode::cast(*code), 0)); | |
186 return code; | |
187 } | |
188 | |
189 | |
190 Handle<Code> PropertyICCompiler::CompileStoreMegamorphic(Code::Flags flags) { | 108 Handle<Code> PropertyICCompiler::CompileStoreMegamorphic(Code::Flags flags) { |
191 StoreIC::GenerateMegamorphic(masm()); | 109 StoreIC::GenerateMegamorphic(masm()); |
192 Handle<Code> code = GetCodeWithFlags(flags, "CompileStoreMegamorphic"); | 110 Handle<Code> code = GetCodeWithFlags(flags, "CompileStoreMegamorphic"); |
193 PROFILE(isolate(), CodeCreateEvent(Logger::STORE_MEGAMORPHIC_TAG, | 111 PROFILE(isolate(), CodeCreateEvent(Logger::STORE_MEGAMORPHIC_TAG, |
194 AbstractCode::cast(*code), 0)); | 112 AbstractCode::cast(*code), 0)); |
195 return code; | 113 return code; |
196 } | 114 } |
197 | 115 |
198 | 116 Handle<Code> PropertyICCompiler::GetCode(Code::Kind kind, Handle<Name> name, |
199 Handle<Code> PropertyICCompiler::GetCode(Code::Kind kind, Code::StubType type, | |
200 Handle<Name> name, | |
201 InlineCacheState state) { | 117 InlineCacheState state) { |
202 Code::Flags flags = | 118 Code::Flags flags = |
203 Code::ComputeFlags(kind, state, extra_ic_state_, type, cache_holder()); | 119 Code::ComputeFlags(kind, state, extra_ic_state_, cache_holder()); |
204 Handle<Code> code = GetCodeWithFlags(flags, name); | 120 Handle<Code> code = GetCodeWithFlags(flags, name); |
205 PROFILE(isolate(), | 121 PROFILE(isolate(), |
206 CodeCreateEvent(log_kind(code), AbstractCode::cast(*code), *name)); | 122 CodeCreateEvent(log_kind(code), AbstractCode::cast(*code), *name)); |
207 #ifdef DEBUG | 123 #ifdef DEBUG |
208 code->VerifyEmbeddedObjects(); | 124 code->VerifyEmbeddedObjects(); |
209 #endif | 125 #endif |
210 return code; | 126 return code; |
211 } | 127 } |
212 | 128 |
213 | 129 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 receiver_map->has_fixed_typed_array_elements()) { | 186 receiver_map->has_fixed_typed_array_elements()) { |
271 stub = StoreFastElementStub(isolate(), is_jsarray, elements_kind, | 187 stub = StoreFastElementStub(isolate(), is_jsarray, elements_kind, |
272 store_mode).GetCode(); | 188 store_mode).GetCode(); |
273 } else { | 189 } else { |
274 stub = StoreElementStub(isolate(), elements_kind, store_mode).GetCode(); | 190 stub = StoreElementStub(isolate(), elements_kind, store_mode).GetCode(); |
275 } | 191 } |
276 return stub; | 192 return stub; |
277 } | 193 } |
278 | 194 |
279 | 195 |
280 Handle<Code> PropertyICCompiler::CompileKeyedStoreMonomorphic( | |
281 Handle<Map> receiver_map, KeyedAccessStoreMode store_mode) { | |
282 Handle<Code> stub = | |
283 CompileKeyedStoreMonomorphicHandler(receiver_map, store_mode); | |
284 | |
285 Handle<WeakCell> cell = Map::WeakCellForMap(receiver_map); | |
286 | |
287 __ DispatchWeakMap(receiver(), scratch1(), scratch2(), cell, stub, | |
288 DO_SMI_CHECK); | |
289 | |
290 TailCallBuiltin(masm(), Builtins::kKeyedStoreIC_Miss); | |
291 | |
292 return GetCode(kind(), Code::NORMAL, factory()->empty_string()); | |
293 } | |
294 | |
295 | |
296 #undef __ | 196 #undef __ |
297 } // namespace internal | 197 } // namespace internal |
298 } // namespace v8 | 198 } // namespace v8 |
OLD | NEW |