OLD | NEW |
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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 // Alias the inline cache state type to make the IC code more readable. | 80 // Alias the inline cache state type to make the IC code more readable. |
81 typedef InlineCacheState State; | 81 typedef InlineCacheState State; |
82 | 82 |
83 // The IC code is either invoked with no extra frames on the stack | 83 // The IC code is either invoked with no extra frames on the stack |
84 // or with a single extra frame for supporting calls. | 84 // or with a single extra frame for supporting calls. |
85 enum FrameDepth { | 85 enum FrameDepth { |
86 NO_EXTRA_FRAME = 0, | 86 NO_EXTRA_FRAME = 0, |
87 EXTRA_CALL_FRAME = 1 | 87 EXTRA_CALL_FRAME = 1 |
88 }; | 88 }; |
89 | 89 |
| 90 // ExtraICState shared by all ICs. |
| 91 class Contextual: public BitField<ContextualMode, 0, 1> {}; |
| 92 STATIC_ASSERT(static_cast<int>(NOT_CONTEXTUAL) == 0); |
| 93 static ExtraICState ComputeExtraICState(ContextualMode mode) { |
| 94 return Contextual::encode(mode); |
| 95 } |
| 96 |
| 97 static ContextualMode GetContextualMode(ExtraICState state) { |
| 98 return Contextual::decode(state); |
| 99 } |
| 100 |
| 101 static const ExtraICState kContextualState = |
| 102 static_cast<int>(CONTEXTUAL) << Contextual::kShift; |
| 103 |
90 // Construct the IC structure with the given number of extra | 104 // Construct the IC structure with the given number of extra |
91 // JavaScript frames on the stack. | 105 // JavaScript frames on the stack. |
92 IC(FrameDepth depth, Isolate* isolate); | 106 IC(FrameDepth depth, Isolate* isolate); |
93 virtual ~IC() {} | 107 virtual ~IC() {} |
94 | 108 |
95 State state() const { return state_; } | 109 State state() const { return state_; } |
96 inline Address address() const; | 110 inline Address address() const; |
97 | 111 |
98 // Compute the current IC state based on the target stub, receiver and name. | 112 // Compute the current IC state based on the target stub, receiver and name. |
99 void UpdateState(Handle<Object> receiver, Handle<Object> name); | 113 void UpdateState(Handle<Object> receiver, Handle<Object> name); |
100 void MarkMonomorphicPrototypeFailure() { | 114 void MarkMonomorphicPrototypeFailure() { |
101 state_ = MONOMORPHIC_PROTOTYPE_FAILURE; | 115 state_ = MONOMORPHIC_PROTOTYPE_FAILURE; |
102 } | 116 } |
103 | 117 |
104 // Clear the inline cache to initial state. | 118 // Clear the inline cache to initial state. |
105 static void Clear(Isolate* isolate, Address address); | 119 static void Clear(Isolate* isolate, Address address); |
106 | 120 |
107 // Computes the reloc info for this IC. This is a fairly expensive | |
108 // operation as it has to search through the heap to find the code | |
109 // object that contains this IC site. | |
110 RelocInfo::Mode ComputeMode(); | |
111 | |
112 // Returns if this IC is for contextual (no explicit receiver) | 121 // Returns if this IC is for contextual (no explicit receiver) |
113 // access to properties. | 122 // access to properties. |
114 bool IsUndeclaredGlobal(Handle<Object> receiver) { | 123 bool IsUndeclaredGlobal(Handle<Object> receiver) { |
115 if (receiver->IsGlobalObject()) { | 124 if (receiver->IsGlobalObject()) { |
116 return SlowIsUndeclaredGlobal(); | 125 return contextual_mode(); |
117 } else { | 126 } else { |
118 ASSERT(!SlowIsUndeclaredGlobal()); | 127 ASSERT(!contextual_mode()); |
119 return false; | 128 return false; |
120 } | 129 } |
121 } | 130 } |
122 | 131 |
123 bool SlowIsUndeclaredGlobal() { | |
124 return ComputeMode() == RelocInfo::CODE_TARGET_CONTEXT; | |
125 } | |
126 | |
127 #ifdef DEBUG | 132 #ifdef DEBUG |
128 bool IsLoadStub() { | 133 bool IsLoadStub() { |
129 return target()->is_load_stub() || target()->is_keyed_load_stub(); | 134 return target()->is_load_stub() || target()->is_keyed_load_stub(); |
130 } | 135 } |
131 | 136 |
132 bool IsStoreStub() { | 137 bool IsStoreStub() { |
133 return target()->is_store_stub() || target()->is_keyed_store_stub(); | 138 return target()->is_store_stub() || target()->is_keyed_store_stub(); |
134 } | 139 } |
135 | 140 |
136 bool IsCallStub() { | 141 bool IsCallStub() { |
(...skipping 23 matching lines...) Expand all Loading... |
160 | 165 |
161 // Utility functions to convert maps to types and back. There are two special | 166 // Utility functions to convert maps to types and back. There are two special |
162 // cases: | 167 // cases: |
163 // - The heap_number_map is used as a marker which includes heap numbers as | 168 // - The heap_number_map is used as a marker which includes heap numbers as |
164 // well as smis. | 169 // well as smis. |
165 // - The oddball map is only used for booleans. | 170 // - The oddball map is only used for booleans. |
166 static Handle<Map> TypeToMap(Type* type, Isolate* isolate); | 171 static Handle<Map> TypeToMap(Type* type, Isolate* isolate); |
167 static Type* MapToType(Handle<Map> type); | 172 static Type* MapToType(Handle<Map> type); |
168 static Handle<Type> CurrentTypeOf(Handle<Object> object, Isolate* isolate); | 173 static Handle<Type> CurrentTypeOf(Handle<Object> object, Isolate* isolate); |
169 | 174 |
| 175 ContextualMode contextual_mode() const { |
| 176 return Contextual::decode(extra_ic_state()); |
| 177 } |
| 178 |
170 protected: | 179 protected: |
171 // Get the call-site target; used for determining the state. | 180 // Get the call-site target; used for determining the state. |
172 Handle<Code> target() const { return target_; } | 181 Handle<Code> target() const { return target_; } |
173 | 182 |
174 Address fp() const { return fp_; } | 183 Address fp() const { return fp_; } |
175 Address pc() const { return *pc_address_; } | 184 Address pc() const { return *pc_address_; } |
176 Isolate* isolate() const { return isolate_; } | 185 Isolate* isolate() const { return isolate_; } |
177 | 186 |
178 #ifdef ENABLE_DEBUGGER_SUPPORT | 187 #ifdef ENABLE_DEBUGGER_SUPPORT |
179 // Computes the address in the original code when the code running is | 188 // Computes the address in the original code when the code running is |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 } | 257 } |
249 virtual Handle<Code> generic_stub() const { | 258 virtual Handle<Code> generic_stub() const { |
250 UNREACHABLE(); | 259 UNREACHABLE(); |
251 return Handle<Code>::null(); | 260 return Handle<Code>::null(); |
252 } | 261 } |
253 | 262 |
254 bool TryRemoveInvalidPrototypeDependentStub(Handle<Object> receiver, | 263 bool TryRemoveInvalidPrototypeDependentStub(Handle<Object> receiver, |
255 Handle<String> name); | 264 Handle<String> name); |
256 void TryRemoveInvalidHandlers(Handle<Map> map, Handle<String> name); | 265 void TryRemoveInvalidHandlers(Handle<Map> map, Handle<String> name); |
257 | 266 |
258 virtual ExtraICState extra_ic_state() { return kNoExtraICState; } | 267 ExtraICState extra_ic_state() const { return extra_ic_state_; } |
| 268 void set_extra_ic_state(ExtraICState state) { |
| 269 extra_ic_state_ = state; |
| 270 } |
259 | 271 |
260 private: | 272 private: |
261 Code* raw_target() const { return GetTargetAtAddress(address()); } | 273 Code* raw_target() const { return GetTargetAtAddress(address()); } |
262 | 274 |
263 // Frame pointer for the frame that uses (calls) the IC. | 275 // Frame pointer for the frame that uses (calls) the IC. |
264 Address fp_; | 276 Address fp_; |
265 | 277 |
266 // All access to the program counter of an IC structure is indirect | 278 // All access to the program counter of an IC structure is indirect |
267 // to make the code GC safe. This feature is crucial since | 279 // to make the code GC safe. This feature is crucial since |
268 // GetProperty and SetProperty are called and they in turn might | 280 // GetProperty and SetProperty are called and they in turn might |
269 // invoke the garbage collector. | 281 // invoke the garbage collector. |
270 Address* pc_address_; | 282 Address* pc_address_; |
271 | 283 |
272 Isolate* isolate_; | 284 Isolate* isolate_; |
273 | 285 |
274 // The original code target that missed. | 286 // The original code target that missed. |
275 Handle<Code> target_; | 287 Handle<Code> target_; |
276 State state_; | 288 State state_; |
277 bool target_set_; | 289 bool target_set_; |
278 | 290 |
| 291 ExtraICState extra_ic_state_; |
| 292 |
279 DISALLOW_IMPLICIT_CONSTRUCTORS(IC); | 293 DISALLOW_IMPLICIT_CONSTRUCTORS(IC); |
280 }; | 294 }; |
281 | 295 |
282 | 296 |
283 // An IC_Utility encapsulates IC::UtilityId. It exists mainly because you | 297 // An IC_Utility encapsulates IC::UtilityId. It exists mainly because you |
284 // cannot make forward declarations to an enum. | 298 // cannot make forward declarations to an enum. |
285 class IC_Utility { | 299 class IC_Utility { |
286 public: | 300 public: |
287 explicit IC_Utility(IC::UtilityId id) | 301 explicit IC_Utility(IC::UtilityId id) |
288 : address_(IC::AddressFromUtilityId(id)), id_(id) {} | 302 : address_(IC::AddressFromUtilityId(id)), id_(id) {} |
289 | 303 |
290 Address address() const { return address_; } | 304 Address address() const { return address_; } |
291 | 305 |
292 IC::UtilityId id() const { return id_; } | 306 IC::UtilityId id() const { return id_; } |
293 private: | 307 private: |
294 Address address_; | 308 Address address_; |
295 IC::UtilityId id_; | 309 IC::UtilityId id_; |
296 }; | 310 }; |
297 | 311 |
298 | 312 |
299 class CallICBase: public IC { | 313 class CallICBase: public IC { |
300 public: | 314 public: |
301 // ExtraICState bits | 315 // ExtraICState bits |
302 class Contextual: public BitField<ContextualMode, 0, 1> {}; | |
303 class StringStubState: public BitField<StringStubFeedback, 1, 1> {}; | 316 class StringStubState: public BitField<StringStubFeedback, 1, 1> {}; |
304 static ExtraICState ComputeExtraICState(ContextualMode mode, | 317 static ExtraICState ComputeExtraICState(ContextualMode mode, |
305 StringStubFeedback feedback) { | 318 StringStubFeedback feedback) { |
306 return Contextual::encode(mode) | StringStubState::encode(feedback); | 319 return Contextual::encode(mode) | StringStubState::encode(feedback); |
307 } | 320 } |
308 | 321 |
309 // Returns a JSFunction or a Failure. | 322 // Returns a JSFunction or a Failure. |
310 MUST_USE_RESULT MaybeObject* LoadFunction(Handle<Object> object, | 323 MUST_USE_RESULT MaybeObject* LoadFunction(Handle<Object> object, |
311 Handle<String> name); | 324 Handle<String> name); |
312 | 325 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 | 366 |
354 Code::Kind kind_; | 367 Code::Kind kind_; |
355 | 368 |
356 friend class IC; | 369 friend class IC; |
357 }; | 370 }; |
358 | 371 |
359 | 372 |
360 class CallIC: public CallICBase { | 373 class CallIC: public CallICBase { |
361 public: | 374 public: |
362 explicit CallIC(Isolate* isolate) | 375 explicit CallIC(Isolate* isolate) |
363 : CallICBase(Code::CALL_IC, isolate), | 376 : CallICBase(Code::CALL_IC, isolate) { |
364 extra_ic_state_(target()->extra_ic_state()) { | |
365 ASSERT(target()->is_call_stub()); | 377 ASSERT(target()->is_call_stub()); |
366 } | 378 } |
367 | 379 |
368 // Code generator routines. | 380 // Code generator routines. |
369 static void GenerateInitialize(MacroAssembler* masm, | 381 static void GenerateInitialize(MacroAssembler* masm, |
370 int argc, | 382 int argc, |
371 ExtraICState extra_state) { | 383 ExtraICState extra_state) { |
372 GenerateMiss(masm, argc, extra_state); | 384 GenerateMiss(masm, argc, extra_state); |
373 } | 385 } |
374 | 386 |
375 static void GenerateMiss(MacroAssembler* masm, | 387 static void GenerateMiss(MacroAssembler* masm, |
376 int argc, | 388 int argc, |
377 ExtraICState extra_state) { | 389 ExtraICState extra_state) { |
378 CallICBase::GenerateMiss(masm, argc, IC::kCallIC_Miss, extra_state); | 390 CallICBase::GenerateMiss(masm, argc, IC::kCallIC_Miss, extra_state); |
379 } | 391 } |
380 | 392 |
381 static void GenerateMegamorphic(MacroAssembler* masm, | 393 static void GenerateMegamorphic(MacroAssembler* masm, |
382 int argc, | 394 int argc, |
383 ExtraICState extra_ic_state); | 395 ExtraICState extra_ic_state); |
384 | 396 |
385 static void GenerateNormal(MacroAssembler* masm, int argc) { | 397 static void GenerateNormal(MacroAssembler* masm, int argc) { |
386 CallICBase::GenerateNormal(masm, argc); | 398 CallICBase::GenerateNormal(masm, argc); |
387 GenerateMiss(masm, argc, kNoExtraICState); | 399 GenerateMiss(masm, argc, kNoExtraICState); |
388 } | 400 } |
389 bool TryUpdateExtraICState(LookupResult* lookup, Handle<Object> object); | 401 bool TryUpdateExtraICState(LookupResult* lookup, Handle<Object> object); |
390 | |
391 protected: | |
392 virtual ExtraICState extra_ic_state() { return extra_ic_state_; } | |
393 | |
394 private: | |
395 ExtraICState extra_ic_state_; | |
396 }; | 402 }; |
397 | 403 |
398 | 404 |
399 class KeyedCallIC: public CallICBase { | 405 class KeyedCallIC: public CallICBase { |
400 public: | 406 public: |
401 explicit KeyedCallIC(Isolate* isolate) | 407 explicit KeyedCallIC(Isolate* isolate) |
402 : CallICBase(Code::KEYED_CALL_IC, isolate) { | 408 : CallICBase(Code::KEYED_CALL_IC, isolate) { |
403 ASSERT(target()->is_keyed_call_stub()); | 409 ASSERT(target()->is_keyed_call_stub()); |
404 } | 410 } |
405 | 411 |
(...skipping 11 matching lines...) Expand all Loading... |
417 } | 423 } |
418 | 424 |
419 static void GenerateMegamorphic(MacroAssembler* masm, int argc); | 425 static void GenerateMegamorphic(MacroAssembler* masm, int argc); |
420 static void GenerateNormal(MacroAssembler* masm, int argc); | 426 static void GenerateNormal(MacroAssembler* masm, int argc); |
421 static void GenerateNonStrictArguments(MacroAssembler* masm, int argc); | 427 static void GenerateNonStrictArguments(MacroAssembler* masm, int argc); |
422 }; | 428 }; |
423 | 429 |
424 | 430 |
425 class LoadIC: public IC { | 431 class LoadIC: public IC { |
426 public: | 432 public: |
427 explicit LoadIC(FrameDepth depth, Isolate* isolate) : IC(depth, isolate) { | 433 explicit LoadIC(FrameDepth depth, Isolate* isolate) |
| 434 : IC(depth, isolate) { |
428 ASSERT(IsLoadStub()); | 435 ASSERT(IsLoadStub()); |
429 } | 436 } |
430 | 437 |
431 // Code generator routines. | 438 // Code generator routines. |
432 static void GenerateInitialize(MacroAssembler* masm) { GenerateMiss(masm); } | 439 static void GenerateInitialize(MacroAssembler* masm) { GenerateMiss(masm); } |
433 static void GeneratePreMonomorphic(MacroAssembler* masm) { | 440 static void GeneratePreMonomorphic(MacroAssembler* masm) { |
434 GenerateMiss(masm); | 441 GenerateMiss(masm); |
435 } | 442 } |
436 static void GenerateMiss(MacroAssembler* masm); | 443 static void GenerateMiss(MacroAssembler* masm); |
437 static void GenerateMegamorphic(MacroAssembler* masm); | 444 static void GenerateMegamorphic(MacroAssembler* masm, ContextualMode mode); |
438 static void GenerateNormal(MacroAssembler* masm); | 445 static void GenerateNormal(MacroAssembler* masm); |
439 static void GenerateRuntimeGetProperty(MacroAssembler* masm); | 446 static void GenerateRuntimeGetProperty(MacroAssembler* masm); |
440 | 447 |
441 MUST_USE_RESULT MaybeObject* Load(Handle<Object> object, | 448 MUST_USE_RESULT MaybeObject* Load(Handle<Object> object, |
442 Handle<String> name); | 449 Handle<String> name); |
443 | 450 |
444 protected: | 451 protected: |
445 virtual Code::Kind kind() const { return Code::LOAD_IC; } | 452 virtual Code::Kind kind() const { return Code::LOAD_IC; } |
446 | 453 |
447 virtual Handle<Code> slow_stub() const { | 454 virtual Handle<Code> slow_stub() const { |
448 return isolate()->builtins()->LoadIC_Slow(); | 455 return isolate()->builtins()->LoadIC_Slow(); |
449 } | 456 } |
450 | 457 |
451 virtual Handle<Code> megamorphic_stub() { | 458 virtual Handle<Code> megamorphic_stub() { |
452 return isolate()->builtins()->LoadIC_Megamorphic(); | 459 if (contextual_mode() == CONTEXTUAL) { |
| 460 return isolate()->builtins()->LoadIC_Megamorphic_Contextual(); |
| 461 } else { |
| 462 return isolate()->builtins()->LoadIC_Megamorphic(); |
| 463 } |
453 } | 464 } |
454 | 465 |
455 // Update the inline cache and the global stub cache based on the | 466 // Update the inline cache and the global stub cache based on the |
456 // lookup result. | 467 // lookup result. |
457 void UpdateCaches(LookupResult* lookup, | 468 void UpdateCaches(LookupResult* lookup, |
458 Handle<Object> object, | 469 Handle<Object> object, |
459 Handle<String> name); | 470 Handle<String> name); |
460 | 471 |
461 virtual Handle<Code> CompileHandler(LookupResult* lookup, | 472 virtual Handle<Code> CompileHandler(LookupResult* lookup, |
462 Handle<Object> object, | 473 Handle<Object> object, |
463 Handle<String> name, | 474 Handle<String> name, |
464 Handle<Object> unused, | 475 Handle<Object> unused, |
465 InlineCacheHolderFlag cache_holder); | 476 InlineCacheHolderFlag cache_holder); |
466 | 477 |
467 private: | 478 private: |
468 // Stub accessors. | 479 // Stub accessors. |
469 static Handle<Code> initialize_stub(Isolate* isolate) { | 480 static Handle<Code> pre_monomorphic_stub(Isolate* isolate, |
470 return isolate->builtins()->LoadIC_Initialize(); | 481 ContextualMode mode) { |
471 } | 482 return mode == CONTEXTUAL |
472 | 483 ? isolate->builtins()->LoadIC_PreMonomorphic_Contextual() |
473 static Handle<Code> pre_monomorphic_stub(Isolate* isolate) { | 484 : isolate->builtins()->LoadIC_PreMonomorphic(); |
474 return isolate->builtins()->LoadIC_PreMonomorphic(); | |
475 } | 485 } |
476 | 486 |
477 virtual Handle<Code> pre_monomorphic_stub() { | 487 virtual Handle<Code> pre_monomorphic_stub() { |
478 return pre_monomorphic_stub(isolate()); | 488 return pre_monomorphic_stub(isolate(), contextual_mode()); |
479 } | 489 } |
480 | 490 |
481 Handle<Code> SimpleFieldLoad(int offset, | 491 Handle<Code> SimpleFieldLoad(int offset, |
482 bool inobject = true, | 492 bool inobject = true, |
483 Representation representation = | 493 Representation representation = |
484 Representation::Tagged()); | 494 Representation::Tagged()); |
485 | 495 |
486 static void Clear(Isolate* isolate, Address address, Code* target); | 496 static void Clear(Isolate* isolate, Address address, Code* target); |
487 | 497 |
488 friend class IC; | 498 friend class IC; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
530 return isolate()->builtins()->KeyedLoadIC_Generic(); | 540 return isolate()->builtins()->KeyedLoadIC_Generic(); |
531 } | 541 } |
532 virtual Handle<Code> slow_stub() const { | 542 virtual Handle<Code> slow_stub() const { |
533 return isolate()->builtins()->KeyedLoadIC_Slow(); | 543 return isolate()->builtins()->KeyedLoadIC_Slow(); |
534 } | 544 } |
535 | 545 |
536 virtual void UpdateMegamorphicCache(Type* type, Name* name, Code* code) { } | 546 virtual void UpdateMegamorphicCache(Type* type, Name* name, Code* code) { } |
537 | 547 |
538 private: | 548 private: |
539 // Stub accessors. | 549 // Stub accessors. |
540 static Handle<Code> initialize_stub(Isolate* isolate) { | |
541 return isolate->builtins()->KeyedLoadIC_Initialize(); | |
542 } | |
543 static Handle<Code> pre_monomorphic_stub(Isolate* isolate) { | 550 static Handle<Code> pre_monomorphic_stub(Isolate* isolate) { |
544 return isolate->builtins()->KeyedLoadIC_PreMonomorphic(); | 551 return isolate->builtins()->KeyedLoadIC_PreMonomorphic(); |
545 } | 552 } |
546 virtual Handle<Code> pre_monomorphic_stub() { | 553 virtual Handle<Code> pre_monomorphic_stub() { |
547 return pre_monomorphic_stub(isolate()); | 554 return pre_monomorphic_stub(isolate()); |
548 } | 555 } |
549 Handle<Code> indexed_interceptor_stub() { | 556 Handle<Code> indexed_interceptor_stub() { |
550 return isolate()->builtins()->KeyedLoadIC_IndexedInterceptor(); | 557 return isolate()->builtins()->KeyedLoadIC_IndexedInterceptor(); |
551 } | 558 } |
552 Handle<Code> non_strict_arguments_stub() { | 559 Handle<Code> non_strict_arguments_stub() { |
553 return isolate()->builtins()->KeyedLoadIC_NonStrictArguments(); | 560 return isolate()->builtins()->KeyedLoadIC_NonStrictArguments(); |
554 } | 561 } |
555 Handle<Code> string_stub() { | 562 Handle<Code> string_stub() { |
556 return isolate()->builtins()->KeyedLoadIC_String(); | 563 return isolate()->builtins()->KeyedLoadIC_String(); |
557 } | 564 } |
558 | 565 |
559 static void Clear(Isolate* isolate, Address address, Code* target); | 566 static void Clear(Isolate* isolate, Address address, Code* target); |
560 | 567 |
561 friend class IC; | 568 friend class IC; |
562 }; | 569 }; |
563 | 570 |
564 | 571 |
565 class StoreIC: public IC { | 572 class StoreIC: public IC { |
566 public: | 573 public: |
567 // ExtraICState bits | 574 // ExtraICState bits |
568 class StrictModeState: public BitField<StrictModeFlag, 0, 1> {}; | 575 class StrictModeState: public BitField<StrictModeFlag, 1, 1> {}; |
569 static ExtraICState ComputeExtraICState(StrictModeFlag flag) { | 576 static ExtraICState ComputeExtraICState(StrictModeFlag flag) { |
570 return StrictModeState::encode(flag); | 577 return StrictModeState::encode(flag); |
571 } | 578 } |
572 | 579 |
| 580 static ExtraICState ComputeExtraICState(StrictModeFlag flag, |
| 581 ContextualMode mode) { |
| 582 return StrictModeState::encode(flag) | Contextual::encode(mode); |
| 583 } |
| 584 |
573 static StrictModeFlag GetStrictMode(ExtraICState state) { | 585 static StrictModeFlag GetStrictMode(ExtraICState state) { |
574 return StrictModeState::decode(state); | 586 return StrictModeState::decode(state); |
575 } | 587 } |
576 | 588 |
577 // For convenience, a statically declared encoding of strict mode extra | 589 // For convenience, a statically declared encoding of strict mode extra |
578 // IC state. | 590 // IC state. |
579 static const ExtraICState kStrictModeState = | 591 static const ExtraICState kStrictModeState = |
580 1 << StrictModeState::kShift; | 592 1 << StrictModeState::kShift; |
581 | 593 |
582 StoreIC(FrameDepth depth, Isolate* isolate) | 594 StoreIC(FrameDepth depth, Isolate* isolate) |
583 : IC(depth, isolate), | 595 : IC(depth, isolate) { |
584 strict_mode_(GetStrictMode(target()->extra_ic_state())) { | |
585 ASSERT(IsStoreStub()); | 596 ASSERT(IsStoreStub()); |
586 } | 597 } |
587 | 598 |
588 StrictModeFlag strict_mode() const { return strict_mode_; } | 599 StrictModeFlag strict_mode() const { |
| 600 return StrictModeState::decode(extra_ic_state()); |
| 601 } |
589 | 602 |
590 // Code generators for stub routines. Only called once at startup. | 603 // Code generators for stub routines. Only called once at startup. |
591 static void GenerateSlow(MacroAssembler* masm); | 604 static void GenerateSlow(MacroAssembler* masm); |
592 static void GenerateInitialize(MacroAssembler* masm) { GenerateMiss(masm); } | 605 static void GenerateInitialize(MacroAssembler* masm) { GenerateMiss(masm); } |
593 static void GeneratePreMonomorphic(MacroAssembler* masm) { | 606 static void GeneratePreMonomorphic(MacroAssembler* masm) { |
594 GenerateMiss(masm); | 607 GenerateMiss(masm); |
595 } | 608 } |
596 static void GenerateMiss(MacroAssembler* masm); | 609 static void GenerateMiss(MacroAssembler* masm); |
597 static void GenerateMegamorphic(MacroAssembler* masm, | 610 static void GenerateMegamorphic(MacroAssembler* masm, |
598 StrictModeFlag strict_mode); | 611 StrictModeFlag strict_mode, |
| 612 ContextualMode mode); |
599 static void GenerateNormal(MacroAssembler* masm); | 613 static void GenerateNormal(MacroAssembler* masm); |
600 static void GenerateRuntimeSetProperty(MacroAssembler* masm, | 614 static void GenerateRuntimeSetProperty(MacroAssembler* masm, |
601 StrictModeFlag strict_mode); | 615 StrictModeFlag strict_mode); |
602 | 616 |
603 MUST_USE_RESULT MaybeObject* Store( | 617 MUST_USE_RESULT MaybeObject* Store( |
604 Handle<Object> object, | 618 Handle<Object> object, |
605 Handle<String> name, | 619 Handle<String> name, |
606 Handle<Object> value, | 620 Handle<Object> value, |
607 JSReceiver::StoreFromKeyed store_mode = | 621 JSReceiver::StoreFromKeyed store_mode = |
608 JSReceiver::CERTAINLY_NOT_STORE_FROM_KEYED); | 622 JSReceiver::CERTAINLY_NOT_STORE_FROM_KEYED); |
609 | 623 |
610 protected: | 624 protected: |
611 virtual Code::Kind kind() const { return Code::STORE_IC; } | 625 virtual Code::Kind kind() const { return Code::STORE_IC; } |
612 virtual Handle<Code> megamorphic_stub() { | 626 virtual Handle<Code> megamorphic_stub() { |
613 if (strict_mode() == kStrictMode) { | 627 if (strict_mode() == kStrictMode) { |
614 return isolate()->builtins()->StoreIC_Megamorphic_Strict(); | 628 if (contextual_mode() == CONTEXTUAL) { |
| 629 return isolate()->builtins()->StoreIC_Megamorphic_Contextual_Strict(); |
| 630 } else { |
| 631 return isolate()->builtins()->StoreIC_Megamorphic_Strict(); |
| 632 } |
615 } else { | 633 } else { |
| 634 ASSERT(contextual_mode() != CONTEXTUAL); |
616 return isolate()->builtins()->StoreIC_Megamorphic(); | 635 return isolate()->builtins()->StoreIC_Megamorphic(); |
617 } | 636 } |
618 } | 637 } |
619 // Stub accessors. | 638 // Stub accessors. |
620 virtual Handle<Code> generic_stub() const { | 639 virtual Handle<Code> generic_stub() const { |
621 if (strict_mode() == kStrictMode) { | 640 if (strict_mode() == kStrictMode) { |
622 return isolate()->builtins()->StoreIC_Generic_Strict(); | 641 return isolate()->builtins()->StoreIC_Generic_Strict(); |
623 } else { | 642 } else { |
624 return isolate()->builtins()->StoreIC_Generic(); | 643 return isolate()->builtins()->StoreIC_Generic(); |
625 } | 644 } |
626 } | 645 } |
627 | 646 |
628 virtual Handle<Code> slow_stub() const { | 647 virtual Handle<Code> slow_stub() const { |
629 return isolate()->builtins()->StoreIC_Slow(); | 648 return isolate()->builtins()->StoreIC_Slow(); |
630 } | 649 } |
631 | 650 |
632 virtual Handle<Code> pre_monomorphic_stub() { | 651 virtual Handle<Code> pre_monomorphic_stub() { |
633 return pre_monomorphic_stub(isolate(), strict_mode()); | 652 return pre_monomorphic_stub(isolate(), strict_mode(), contextual_mode()); |
634 } | 653 } |
635 | 654 |
636 static Handle<Code> pre_monomorphic_stub(Isolate* isolate, | 655 static Handle<Code> pre_monomorphic_stub(Isolate* isolate, |
637 StrictModeFlag strict_mode) { | 656 StrictModeFlag strict_mode, |
| 657 ContextualMode contextual_mode) { |
638 if (strict_mode == kStrictMode) { | 658 if (strict_mode == kStrictMode) { |
639 return isolate->builtins()->StoreIC_PreMonomorphic_Strict(); | 659 return contextual_mode == CONTEXTUAL |
| 660 ? isolate->builtins()->StoreIC_PreMonomorphic_Contextual_Strict() |
| 661 : isolate->builtins()->StoreIC_PreMonomorphic_Strict(); |
640 } else { | 662 } else { |
| 663 ASSERT(contextual_mode != CONTEXTUAL); |
641 return isolate->builtins()->StoreIC_PreMonomorphic(); | 664 return isolate->builtins()->StoreIC_PreMonomorphic(); |
642 } | 665 } |
643 } | 666 } |
644 | 667 |
645 // Update the inline cache and the global stub cache based on the | 668 // Update the inline cache and the global stub cache based on the |
646 // lookup result. | 669 // lookup result. |
647 void UpdateCaches(LookupResult* lookup, | 670 void UpdateCaches(LookupResult* lookup, |
648 Handle<JSObject> receiver, | 671 Handle<JSObject> receiver, |
649 Handle<String> name, | 672 Handle<String> name, |
650 Handle<Object> value); | 673 Handle<Object> value); |
651 virtual Handle<Code> CompileHandler(LookupResult* lookup, | 674 virtual Handle<Code> CompileHandler(LookupResult* lookup, |
652 Handle<Object> object, | 675 Handle<Object> object, |
653 Handle<String> name, | 676 Handle<String> name, |
654 Handle<Object> value, | 677 Handle<Object> value, |
655 InlineCacheHolderFlag cache_holder); | 678 InlineCacheHolderFlag cache_holder); |
656 | 679 |
657 virtual ExtraICState extra_ic_state() { | |
658 return ComputeExtraICState(strict_mode()); | |
659 } | |
660 | |
661 private: | 680 private: |
662 void set_target(Code* code) { | 681 void set_target(Code* code) { |
663 // Strict mode must be preserved across IC patching. | 682 // Strict mode must be preserved across IC patching. |
664 ASSERT(GetStrictMode(code->extra_ic_state()) == | 683 ASSERT(GetStrictMode(code->extra_ic_state()) == |
665 GetStrictMode(target()->extra_ic_state())); | 684 GetStrictMode(target()->extra_ic_state())); |
666 IC::set_target(code); | 685 IC::set_target(code); |
667 } | 686 } |
668 | 687 |
669 static Handle<Code> initialize_stub(Isolate* isolate, | |
670 StrictModeFlag strict_mode) { | |
671 if (strict_mode == kStrictMode) { | |
672 return isolate->builtins()->StoreIC_Initialize_Strict(); | |
673 } else { | |
674 return isolate->builtins()->StoreIC_Initialize(); | |
675 } | |
676 } | |
677 | |
678 static void Clear(Isolate* isolate, Address address, Code* target); | 688 static void Clear(Isolate* isolate, Address address, Code* target); |
679 | 689 |
680 StrictModeFlag strict_mode_; | |
681 | |
682 friend class IC; | 690 friend class IC; |
683 }; | 691 }; |
684 | 692 |
685 | 693 |
686 enum KeyedStoreCheckMap { | 694 enum KeyedStoreCheckMap { |
687 kDontCheckMap, | 695 kDontCheckMap, |
688 kCheckMap | 696 kCheckMap |
689 }; | 697 }; |
690 | 698 |
691 | 699 |
692 enum KeyedStoreIncrementLength { | 700 enum KeyedStoreIncrementLength { |
693 kDontIncrementLength, | 701 kDontIncrementLength, |
694 kIncrementLength | 702 kIncrementLength |
695 }; | 703 }; |
696 | 704 |
697 | 705 |
698 class KeyedStoreIC: public StoreIC { | 706 class KeyedStoreIC: public StoreIC { |
699 public: | 707 public: |
700 // ExtraICState bits (building on IC) | 708 // ExtraICState bits (building on IC) |
701 // ExtraICState bits | 709 // ExtraICState bits |
702 class ExtraICStateKeyedAccessStoreMode: | 710 class ExtraICStateKeyedAccessStoreMode: |
703 public BitField<KeyedAccessStoreMode, 1, 4> {}; // NOLINT | 711 public BitField<KeyedAccessStoreMode, 2, 4> {}; // NOLINT |
704 | 712 |
705 static ExtraICState ComputeExtraICState(StrictModeFlag flag, | 713 static ExtraICState ComputeExtraICState(StrictModeFlag flag, |
706 KeyedAccessStoreMode mode) { | 714 KeyedAccessStoreMode mode) { |
707 return StrictModeState::encode(flag) | | 715 return StrictModeState::encode(flag) | |
708 ExtraICStateKeyedAccessStoreMode::encode(mode); | 716 ExtraICStateKeyedAccessStoreMode::encode(mode); |
709 } | 717 } |
710 | 718 |
711 static KeyedAccessStoreMode GetKeyedAccessStoreMode( | 719 static KeyedAccessStoreMode GetKeyedAccessStoreMode( |
712 ExtraICState extra_state) { | 720 ExtraICState extra_state) { |
713 return ExtraICStateKeyedAccessStoreMode::decode(extra_state); | 721 return ExtraICStateKeyedAccessStoreMode::decode(extra_state); |
714 } | 722 } |
715 | 723 |
716 KeyedStoreIC(FrameDepth depth, Isolate* isolate) | 724 KeyedStoreIC(FrameDepth depth, Isolate* isolate) |
(...skipping 15 matching lines...) Expand all Loading... |
732 static void GenerateRuntimeSetProperty(MacroAssembler* masm, | 740 static void GenerateRuntimeSetProperty(MacroAssembler* masm, |
733 StrictModeFlag strict_mode); | 741 StrictModeFlag strict_mode); |
734 static void GenerateGeneric(MacroAssembler* masm, StrictModeFlag strict_mode); | 742 static void GenerateGeneric(MacroAssembler* masm, StrictModeFlag strict_mode); |
735 static void GenerateNonStrictArguments(MacroAssembler* masm); | 743 static void GenerateNonStrictArguments(MacroAssembler* masm); |
736 | 744 |
737 protected: | 745 protected: |
738 virtual Code::Kind kind() const { return Code::KEYED_STORE_IC; } | 746 virtual Code::Kind kind() const { return Code::KEYED_STORE_IC; } |
739 | 747 |
740 virtual void UpdateMegamorphicCache(Type* type, Name* name, Code* code) { } | 748 virtual void UpdateMegamorphicCache(Type* type, Name* name, Code* code) { } |
741 | 749 |
742 virtual ExtraICState extra_ic_state() { | |
743 return ComputeExtraICState(strict_mode(), STANDARD_STORE); | |
744 } | |
745 | |
746 virtual Handle<Code> pre_monomorphic_stub() { | 750 virtual Handle<Code> pre_monomorphic_stub() { |
747 return pre_monomorphic_stub(isolate(), strict_mode()); | 751 return pre_monomorphic_stub(isolate(), strict_mode()); |
748 } | 752 } |
749 static Handle<Code> pre_monomorphic_stub(Isolate* isolate, | 753 static Handle<Code> pre_monomorphic_stub(Isolate* isolate, |
750 StrictModeFlag strict_mode) { | 754 StrictModeFlag strict_mode) { |
751 if (strict_mode == kStrictMode) { | 755 if (strict_mode == kStrictMode) { |
752 return isolate->builtins()->KeyedStoreIC_PreMonomorphic_Strict(); | 756 return isolate->builtins()->KeyedStoreIC_PreMonomorphic_Strict(); |
753 } else { | 757 } else { |
754 return isolate->builtins()->KeyedStoreIC_PreMonomorphic(); | 758 return isolate->builtins()->KeyedStoreIC_PreMonomorphic(); |
755 } | 759 } |
(...skipping 13 matching lines...) Expand all Loading... |
769 KeyedAccessStoreMode store_mode); | 773 KeyedAccessStoreMode store_mode); |
770 | 774 |
771 private: | 775 private: |
772 void set_target(Code* code) { | 776 void set_target(Code* code) { |
773 // Strict mode must be preserved across IC patching. | 777 // Strict mode must be preserved across IC patching. |
774 ASSERT(GetStrictMode(code->extra_ic_state()) == strict_mode()); | 778 ASSERT(GetStrictMode(code->extra_ic_state()) == strict_mode()); |
775 IC::set_target(code); | 779 IC::set_target(code); |
776 } | 780 } |
777 | 781 |
778 // Stub accessors. | 782 // Stub accessors. |
779 static Handle<Code> initialize_stub(Isolate* isolate, | |
780 StrictModeFlag strict_mode) { | |
781 if (strict_mode == kStrictMode) { | |
782 return isolate->builtins()->KeyedStoreIC_Initialize_Strict(); | |
783 } else { | |
784 return isolate->builtins()->KeyedStoreIC_Initialize(); | |
785 } | |
786 } | |
787 | |
788 virtual Handle<Code> generic_stub() const { | 783 virtual Handle<Code> generic_stub() const { |
789 if (strict_mode() == kStrictMode) { | 784 if (strict_mode() == kStrictMode) { |
790 return isolate()->builtins()->KeyedStoreIC_Generic_Strict(); | 785 return isolate()->builtins()->KeyedStoreIC_Generic_Strict(); |
791 } else { | 786 } else { |
792 return isolate()->builtins()->KeyedStoreIC_Generic(); | 787 return isolate()->builtins()->KeyedStoreIC_Generic(); |
793 } | 788 } |
794 } | 789 } |
795 | 790 |
796 Handle<Code> non_strict_arguments_stub() { | 791 Handle<Code> non_strict_arguments_stub() { |
797 return isolate()->builtins()->KeyedStoreIC_NonStrictArguments(); | 792 return isolate()->builtins()->KeyedStoreIC_NonStrictArguments(); |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
939 DECLARE_RUNTIME_FUNCTION(MaybeObject*, KeyedCallIC_MissFromStubFailure); | 934 DECLARE_RUNTIME_FUNCTION(MaybeObject*, KeyedCallIC_MissFromStubFailure); |
940 DECLARE_RUNTIME_FUNCTION(MaybeObject*, ElementsTransitionAndStoreIC_Miss); | 935 DECLARE_RUNTIME_FUNCTION(MaybeObject*, ElementsTransitionAndStoreIC_Miss); |
941 DECLARE_RUNTIME_FUNCTION(MaybeObject*, BinaryOpIC_Miss); | 936 DECLARE_RUNTIME_FUNCTION(MaybeObject*, BinaryOpIC_Miss); |
942 DECLARE_RUNTIME_FUNCTION(MaybeObject*, CompareNilIC_Miss); | 937 DECLARE_RUNTIME_FUNCTION(MaybeObject*, CompareNilIC_Miss); |
943 DECLARE_RUNTIME_FUNCTION(MaybeObject*, ToBooleanIC_Miss); | 938 DECLARE_RUNTIME_FUNCTION(MaybeObject*, ToBooleanIC_Miss); |
944 | 939 |
945 | 940 |
946 } } // namespace v8::internal | 941 } } // namespace v8::internal |
947 | 942 |
948 #endif // V8_IC_H_ | 943 #endif // V8_IC_H_ |
OLD | NEW |