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/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/cpu-profiler.h" | 7 #include "src/cpu-profiler.h" |
8 #include "src/ic/handler-compiler.h" | 8 #include "src/ic/handler-compiler.h" |
9 #include "src/ic/ic-inl.h" | 9 #include "src/ic/ic-inl.h" |
10 #include "src/ic/ic-compiler.h" | 10 #include "src/ic/ic-compiler.h" |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 } | 80 } |
81 | 81 |
82 PropertyICCompiler ic_compiler(isolate, kind, extra_ic_state, flag); | 82 PropertyICCompiler ic_compiler(isolate, kind, extra_ic_state, flag); |
83 ic = ic_compiler.CompileMonomorphic(map, handler, name, PROPERTY); | 83 ic = ic_compiler.CompileMonomorphic(map, handler, name, PROPERTY); |
84 | 84 |
85 if (can_be_cached) Map::UpdateCodeCache(stub_holder, name, ic); | 85 if (can_be_cached) Map::UpdateCodeCache(stub_holder, name, ic); |
86 return ic; | 86 return ic; |
87 } | 87 } |
88 | 88 |
89 | 89 |
90 Handle<Code> PropertyICCompiler::ComputeKeyedLoadMonomorphic( | |
91 Handle<Map> receiver_map) { | |
92 Isolate* isolate = receiver_map->GetIsolate(); | |
93 DCHECK(KeyedLoadIC::GetKeyType(kNoExtraICState) == ELEMENT); | |
94 Code::Flags flags = Code::ComputeMonomorphicFlags(Code::KEYED_LOAD_IC); | |
95 Handle<Name> name = isolate->factory()->KeyedLoadMonomorphic_string(); | |
96 | |
97 Handle<Object> probe(receiver_map->FindInCodeCache(*name, flags), isolate); | |
98 if (probe->IsCode()) return Handle<Code>::cast(probe); | |
99 | |
100 Handle<Code> stub = ComputeKeyedLoadMonomorphicHandler(receiver_map); | |
101 PropertyICCompiler compiler(isolate, Code::KEYED_LOAD_IC); | |
102 Handle<Code> code = compiler.CompileMonomorphic( | |
103 receiver_map, stub, isolate->factory()->empty_string(), ELEMENT); | |
104 | |
105 Map::UpdateCodeCache(receiver_map, name, code); | |
106 return code; | |
107 } | |
108 | |
109 | |
110 Handle<Code> PropertyICCompiler::ComputeKeyedLoadMonomorphicHandler( | 90 Handle<Code> PropertyICCompiler::ComputeKeyedLoadMonomorphicHandler( |
111 Handle<Map> receiver_map) { | 91 Handle<Map> receiver_map) { |
112 Isolate* isolate = receiver_map->GetIsolate(); | 92 Isolate* isolate = receiver_map->GetIsolate(); |
113 bool is_js_array = receiver_map->instance_type() == JS_ARRAY_TYPE; | 93 bool is_js_array = receiver_map->instance_type() == JS_ARRAY_TYPE; |
114 ElementsKind elements_kind = receiver_map->elements_kind(); | 94 ElementsKind elements_kind = receiver_map->elements_kind(); |
115 | 95 |
116 // No need to check for an elements-free prototype chain here, the generated | 96 // No need to check for an elements-free prototype chain here, the generated |
117 // stub code needs to check that dynamically anyway. | 97 // stub code needs to check that dynamically anyway. |
118 bool convert_hole_to_undefined = | 98 bool convert_hole_to_undefined = |
119 is_js_array && elements_kind == FAST_HOLEY_ELEMENTS && | 99 is_js_array && elements_kind == FAST_HOLEY_ELEMENTS && |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 } | 162 } |
183 | 163 |
184 | 164 |
185 static void FillCache(Isolate* isolate, Handle<Code> code) { | 165 static void FillCache(Isolate* isolate, Handle<Code> code) { |
186 Handle<UnseededNumberDictionary> dictionary = UnseededNumberDictionary::Set( | 166 Handle<UnseededNumberDictionary> dictionary = UnseededNumberDictionary::Set( |
187 isolate->factory()->non_monomorphic_cache(), code->flags(), code); | 167 isolate->factory()->non_monomorphic_cache(), code->flags(), code); |
188 isolate->heap()->public_set_non_monomorphic_cache(*dictionary); | 168 isolate->heap()->public_set_non_monomorphic_cache(*dictionary); |
189 } | 169 } |
190 | 170 |
191 | 171 |
192 Handle<Code> PropertyICCompiler::ComputeLoad(Isolate* isolate, | |
193 InlineCacheState ic_state, | |
194 ExtraICState extra_state) { | |
195 Code::Flags flags = Code::ComputeFlags(Code::LOAD_IC, ic_state, extra_state); | |
196 Handle<UnseededNumberDictionary> cache = | |
197 isolate->factory()->non_monomorphic_cache(); | |
198 int entry = cache->FindEntry(isolate, flags); | |
199 if (entry != -1) return Handle<Code>(Code::cast(cache->ValueAt(entry))); | |
200 | |
201 PropertyICCompiler compiler(isolate, Code::LOAD_IC); | |
202 Handle<Code> code; | |
203 if (ic_state == UNINITIALIZED) { | |
204 code = compiler.CompileLoadInitialize(flags); | |
205 } else if (ic_state == PREMONOMORPHIC) { | |
206 code = compiler.CompileLoadPreMonomorphic(flags); | |
207 } else if (ic_state == MEGAMORPHIC) { | |
208 code = compiler.CompileLoadMegamorphic(flags); | |
209 } else { | |
210 UNREACHABLE(); | |
211 } | |
212 FillCache(isolate, code); | |
213 return code; | |
214 } | |
215 | |
216 | |
217 Handle<Code> PropertyICCompiler::ComputeStore(Isolate* isolate, | 172 Handle<Code> PropertyICCompiler::ComputeStore(Isolate* isolate, |
218 InlineCacheState ic_state, | 173 InlineCacheState ic_state, |
219 ExtraICState extra_state) { | 174 ExtraICState extra_state) { |
220 Code::Flags flags = Code::ComputeFlags(Code::STORE_IC, ic_state, extra_state); | 175 Code::Flags flags = Code::ComputeFlags(Code::STORE_IC, ic_state, extra_state); |
221 Handle<UnseededNumberDictionary> cache = | 176 Handle<UnseededNumberDictionary> cache = |
222 isolate->factory()->non_monomorphic_cache(); | 177 isolate->factory()->non_monomorphic_cache(); |
223 int entry = cache->FindEntry(isolate, flags); | 178 int entry = cache->FindEntry(isolate, flags); |
224 if (entry != -1) return Handle<Code>(Code::cast(cache->ValueAt(entry))); | 179 if (entry != -1) return Handle<Code>(Code::cast(cache->ValueAt(entry))); |
225 | 180 |
226 PropertyICCompiler compiler(isolate, Code::STORE_IC); | 181 PropertyICCompiler compiler(isolate, Code::STORE_IC); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 | 282 |
328 | 283 |
329 Handle<Code> PropertyICCompiler::CompileLoadInitialize(Code::Flags flags) { | 284 Handle<Code> PropertyICCompiler::CompileLoadInitialize(Code::Flags flags) { |
330 LoadIC::GenerateInitialize(masm()); | 285 LoadIC::GenerateInitialize(masm()); |
331 Handle<Code> code = GetCodeWithFlags(flags, "CompileLoadInitialize"); | 286 Handle<Code> code = GetCodeWithFlags(flags, "CompileLoadInitialize"); |
332 PROFILE(isolate(), CodeCreateEvent(Logger::LOAD_INITIALIZE_TAG, *code, 0)); | 287 PROFILE(isolate(), CodeCreateEvent(Logger::LOAD_INITIALIZE_TAG, *code, 0)); |
333 return code; | 288 return code; |
334 } | 289 } |
335 | 290 |
336 | 291 |
337 Handle<Code> PropertyICCompiler::CompileLoadPreMonomorphic(Code::Flags flags) { | |
338 LoadIC::GeneratePreMonomorphic(masm()); | |
339 Handle<Code> code = GetCodeWithFlags(flags, "CompileLoadPreMonomorphic"); | |
340 PROFILE(isolate(), | |
341 CodeCreateEvent(Logger::LOAD_PREMONOMORPHIC_TAG, *code, 0)); | |
342 return code; | |
343 } | |
344 | |
345 | |
346 Handle<Code> PropertyICCompiler::CompileLoadMegamorphic(Code::Flags flags) { | |
347 MegamorphicLoadStub stub(isolate(), LoadICState(extra_ic_state_)); | |
348 auto code = stub.GetCode(); | |
349 PROFILE(isolate(), CodeCreateEvent(Logger::LOAD_MEGAMORPHIC_TAG, *code, 0)); | |
350 return code; | |
351 } | |
352 | |
353 | |
354 Handle<Code> PropertyICCompiler::CompileStoreInitialize(Code::Flags flags) { | 292 Handle<Code> PropertyICCompiler::CompileStoreInitialize(Code::Flags flags) { |
355 StoreIC::GenerateInitialize(masm()); | 293 StoreIC::GenerateInitialize(masm()); |
356 Handle<Code> code = GetCodeWithFlags(flags, "CompileStoreInitialize"); | 294 Handle<Code> code = GetCodeWithFlags(flags, "CompileStoreInitialize"); |
357 PROFILE(isolate(), CodeCreateEvent(Logger::STORE_INITIALIZE_TAG, *code, 0)); | 295 PROFILE(isolate(), CodeCreateEvent(Logger::STORE_INITIALIZE_TAG, *code, 0)); |
358 return code; | 296 return code; |
359 } | 297 } |
360 | 298 |
361 | 299 |
362 Handle<Code> PropertyICCompiler::CompileStorePreMonomorphic(Code::Flags flags) { | 300 Handle<Code> PropertyICCompiler::CompileStorePreMonomorphic(Code::Flags flags) { |
363 StoreIC::GeneratePreMonomorphic(masm()); | 301 StoreIC::GeneratePreMonomorphic(masm()); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
472 | 410 |
473 TailCallBuiltin(masm(), Builtins::kKeyedStoreIC_Miss); | 411 TailCallBuiltin(masm(), Builtins::kKeyedStoreIC_Miss); |
474 | 412 |
475 return GetCode(kind(), Code::NORMAL, factory()->empty_string()); | 413 return GetCode(kind(), Code::NORMAL, factory()->empty_string()); |
476 } | 414 } |
477 | 415 |
478 | 416 |
479 #undef __ | 417 #undef __ |
480 } | 418 } |
481 } // namespace v8::internal | 419 } // namespace v8::internal |
OLD | NEW |