| OLD | NEW |
| 1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2009 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 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 Object* result; | 460 Object* result; |
| 461 { MaybeObject* maybe_result = | 461 { MaybeObject* maybe_result = |
| 462 receiver->UpdateMapCodeCache(name, Code::cast(code)); | 462 receiver->UpdateMapCodeCache(name, Code::cast(code)); |
| 463 if (!maybe_result->ToObject(&result)) return maybe_result; | 463 if (!maybe_result->ToObject(&result)) return maybe_result; |
| 464 } | 464 } |
| 465 } | 465 } |
| 466 return code; | 466 return code; |
| 467 } | 467 } |
| 468 | 468 |
| 469 | 469 |
| 470 MaybeObject* StubCache::ComputeKeyedLoadPixelArray(JSObject* receiver) { | |
| 471 // Using NORMAL as the PropertyType for array element loads is a misuse. The | |
| 472 // generated stub always accesses fast elements, not slow-mode fields, but | |
| 473 // some property type is required for the stub lookup. Note that overloading | |
| 474 // the NORMAL PropertyType is only safe as long as no stubs are generated for | |
| 475 // other keyed field loads. This is guaranteed to be the case since all field | |
| 476 // keyed loads that are not array elements go through a generic builtin stub. | |
| 477 Code::Flags flags = | |
| 478 Code::ComputeMonomorphicFlags(Code::KEYED_LOAD_IC, NORMAL); | |
| 479 String* name = Heap::KeyedLoadPixelArray_symbol(); | |
| 480 Object* code = receiver->map()->FindInCodeCache(name, flags); | |
| 481 if (code->IsUndefined()) { | |
| 482 KeyedLoadStubCompiler compiler; | |
| 483 { MaybeObject* maybe_code = compiler.CompileLoadPixelArray(receiver); | |
| 484 if (!maybe_code->ToObject(&code)) return maybe_code; | |
| 485 } | |
| 486 PROFILE(CodeCreateEvent(Logger::KEYED_LOAD_IC_TAG, Code::cast(code), 0)); | |
| 487 Object* result; | |
| 488 { MaybeObject* maybe_result = | |
| 489 receiver->UpdateMapCodeCache(name, Code::cast(code)); | |
| 490 if (!maybe_result->ToObject(&result)) return maybe_result; | |
| 491 } | |
| 492 } | |
| 493 return code; | |
| 494 } | |
| 495 | |
| 496 | |
| 497 MaybeObject* StubCache::ComputeStoreField(String* name, | 470 MaybeObject* StubCache::ComputeStoreField(String* name, |
| 498 JSObject* receiver, | 471 JSObject* receiver, |
| 499 int field_index, | 472 int field_index, |
| 500 Map* transition, | 473 Map* transition, |
| 501 Code::ExtraICState extra_ic_state) { | 474 Code::ExtraICState extra_ic_state) { |
| 502 PropertyType type = (transition == NULL) ? FIELD : MAP_TRANSITION; | 475 PropertyType type = (transition == NULL) ? FIELD : MAP_TRANSITION; |
| 503 Code::Flags flags = Code::ComputeMonomorphicFlags( | 476 Code::Flags flags = Code::ComputeMonomorphicFlags( |
| 504 Code::STORE_IC, type, extra_ic_state); | 477 Code::STORE_IC, type, extra_ic_state); |
| 505 Object* code = receiver->map()->FindInCodeCache(name, flags); | 478 Object* code = receiver->map()->FindInCodeCache(name, flags); |
| 506 if (code->IsUndefined()) { | 479 if (code->IsUndefined()) { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 535 Object* result; | 508 Object* result; |
| 536 { MaybeObject* maybe_result = | 509 { MaybeObject* maybe_result = |
| 537 receiver->UpdateMapCodeCache(name, Code::cast(code)); | 510 receiver->UpdateMapCodeCache(name, Code::cast(code)); |
| 538 if (!maybe_result->ToObject(&result)) return maybe_result; | 511 if (!maybe_result->ToObject(&result)) return maybe_result; |
| 539 } | 512 } |
| 540 } | 513 } |
| 541 return code; | 514 return code; |
| 542 } | 515 } |
| 543 | 516 |
| 544 | 517 |
| 545 MaybeObject* StubCache::ComputeKeyedStorePixelArray(JSObject* receiver) { | |
| 546 // Using NORMAL as the PropertyType for array element stores is a misuse. The | |
| 547 // generated stub always accesses fast elements, not slow-mode fields, but | |
| 548 // some property type is required for the stub lookup. Note that overloading | |
| 549 // the NORMAL PropertyType is only safe as long as no stubs are generated for | |
| 550 // other keyed field stores. This is guaranteed to be the case since all field | |
| 551 // keyed stores that are not array elements go through a generic builtin stub. | |
| 552 Code::Flags flags = | |
| 553 Code::ComputeMonomorphicFlags(Code::KEYED_STORE_IC, NORMAL); | |
| 554 String* name = Heap::KeyedStorePixelArray_symbol(); | |
| 555 Object* code = receiver->map()->FindInCodeCache(name, flags); | |
| 556 if (code->IsUndefined()) { | |
| 557 KeyedStoreStubCompiler compiler; | |
| 558 { MaybeObject* maybe_code = compiler.CompileStorePixelArray(receiver); | |
| 559 if (!maybe_code->ToObject(&code)) return maybe_code; | |
| 560 } | |
| 561 PROFILE(CodeCreateEvent(Logger::KEYED_STORE_IC_TAG, Code::cast(code), 0)); | |
| 562 Object* result; | |
| 563 { MaybeObject* maybe_result = | |
| 564 receiver->UpdateMapCodeCache(name, Code::cast(code)); | |
| 565 if (!maybe_result->ToObject(&result)) return maybe_result; | |
| 566 } | |
| 567 } | |
| 568 return code; | |
| 569 } | |
| 570 | |
| 571 | |
| 572 namespace { | 518 namespace { |
| 573 | 519 |
| 574 ExternalArrayType ElementsKindToExternalArrayType(JSObject::ElementsKind kind) { | 520 ExternalArrayType ElementsKindToExternalArrayType(JSObject::ElementsKind kind) { |
| 575 switch (kind) { | 521 switch (kind) { |
| 576 case JSObject::EXTERNAL_BYTE_ELEMENTS: | 522 case JSObject::EXTERNAL_BYTE_ELEMENTS: |
| 577 return kExternalByteArray; | 523 return kExternalByteArray; |
| 578 case JSObject::EXTERNAL_UNSIGNED_BYTE_ELEMENTS: | 524 case JSObject::EXTERNAL_UNSIGNED_BYTE_ELEMENTS: |
| 579 return kExternalUnsignedByteArray; | 525 return kExternalUnsignedByteArray; |
| 580 case JSObject::EXTERNAL_SHORT_ELEMENTS: | 526 case JSObject::EXTERNAL_SHORT_ELEMENTS: |
| 581 return kExternalShortArray; | 527 return kExternalShortArray; |
| 582 case JSObject::EXTERNAL_UNSIGNED_SHORT_ELEMENTS: | 528 case JSObject::EXTERNAL_UNSIGNED_SHORT_ELEMENTS: |
| 583 return kExternalUnsignedShortArray; | 529 return kExternalUnsignedShortArray; |
| 584 case JSObject::EXTERNAL_INT_ELEMENTS: | 530 case JSObject::EXTERNAL_INT_ELEMENTS: |
| 585 return kExternalIntArray; | 531 return kExternalIntArray; |
| 586 case JSObject::EXTERNAL_UNSIGNED_INT_ELEMENTS: | 532 case JSObject::EXTERNAL_UNSIGNED_INT_ELEMENTS: |
| 587 return kExternalUnsignedIntArray; | 533 return kExternalUnsignedIntArray; |
| 588 case JSObject::EXTERNAL_FLOAT_ELEMENTS: | 534 case JSObject::EXTERNAL_FLOAT_ELEMENTS: |
| 589 return kExternalFloatArray; | 535 return kExternalFloatArray; |
| 536 case JSObject::EXTERNAL_PIXEL_ELEMENTS: |
| 537 return kExternalPixelArray; |
| 590 default: | 538 default: |
| 591 UNREACHABLE(); | 539 UNREACHABLE(); |
| 592 return static_cast<ExternalArrayType>(0); | 540 return static_cast<ExternalArrayType>(0); |
| 593 } | 541 } |
| 594 } | 542 } |
| 595 | 543 |
| 544 String* ExternalArrayTypeToStubName(ExternalArrayType array_type, |
| 545 bool is_store) { |
| 546 if (is_store) { |
| 547 switch (array_type) { |
| 548 case kExternalByteArray: |
| 549 return Heap::KeyedStoreExternalByteArray_symbol(); |
| 550 case kExternalUnsignedByteArray: |
| 551 return Heap::KeyedStoreExternalUnsignedByteArray_symbol(); |
| 552 case kExternalShortArray: |
| 553 return Heap::KeyedStoreExternalShortArray_symbol(); |
| 554 case kExternalUnsignedShortArray: |
| 555 return Heap::KeyedStoreExternalUnsignedShortArray_symbol(); |
| 556 case kExternalIntArray: |
| 557 return Heap::KeyedStoreExternalIntArray_symbol(); |
| 558 case kExternalUnsignedIntArray: |
| 559 return Heap::KeyedStoreExternalUnsignedIntArray_symbol(); |
| 560 case kExternalPixelArray: |
| 561 return Heap::KeyedStoreExternalPixelArray_symbol(); |
| 562 default: |
| 563 UNREACHABLE(); |
| 564 return NULL; |
| 565 } |
| 566 } else { |
| 567 switch (array_type) { |
| 568 case kExternalByteArray: |
| 569 return Heap::KeyedLoadExternalByteArray_symbol(); |
| 570 case kExternalUnsignedByteArray: |
| 571 return Heap::KeyedLoadExternalUnsignedByteArray_symbol(); |
| 572 case kExternalShortArray: |
| 573 return Heap::KeyedLoadExternalShortArray_symbol(); |
| 574 case kExternalUnsignedShortArray: |
| 575 return Heap::KeyedLoadExternalUnsignedShortArray_symbol(); |
| 576 case kExternalIntArray: |
| 577 return Heap::KeyedLoadExternalIntArray_symbol(); |
| 578 case kExternalUnsignedIntArray: |
| 579 return Heap::KeyedLoadExternalUnsignedIntArray_symbol(); |
| 580 case kExternalPixelArray: |
| 581 return Heap::KeyedLoadExternalPixelArray_symbol(); |
| 582 default: |
| 583 UNREACHABLE(); |
| 584 return NULL; |
| 585 } |
| 586 } |
| 587 } |
| 588 |
| 596 } // anonymous namespace | 589 } // anonymous namespace |
| 597 | 590 |
| 598 | 591 |
| 599 MaybeObject* StubCache::ComputeKeyedLoadOrStoreExternalArray( | 592 MaybeObject* StubCache::ComputeKeyedLoadOrStoreExternalArray( |
| 600 JSObject* receiver, | 593 JSObject* receiver, |
| 601 bool is_store) { | 594 bool is_store) { |
| 602 Code::Flags flags = | 595 Code::Flags flags = |
| 603 Code::ComputeMonomorphicFlags( | 596 Code::ComputeMonomorphicFlags( |
| 604 is_store ? Code::KEYED_STORE_IC : Code::KEYED_LOAD_IC, | 597 is_store ? Code::KEYED_EXTERNAL_ARRAY_STORE_IC : |
| 598 Code::KEYED_EXTERNAL_ARRAY_LOAD_IC, |
| 605 NORMAL); | 599 NORMAL); |
| 606 ExternalArrayType array_type = | 600 ExternalArrayType array_type = |
| 607 ElementsKindToExternalArrayType(receiver->GetElementsKind()); | 601 ElementsKindToExternalArrayType(receiver->GetElementsKind()); |
| 608 String* name = | 602 String* name = ExternalArrayTypeToStubName(array_type, is_store); |
| 609 is_store ? Heap::KeyedStoreExternalArray_symbol() | 603 Object* code = receiver->map()->FindInCodeCache(name, flags); |
| 610 : Heap::KeyedLoadExternalArray_symbol(); | |
| 611 // Use the global maps for the particular external array types, | |
| 612 // rather than the receiver's map, when looking up the cached code, | |
| 613 // so that we actually canonicalize these stubs. | |
| 614 Map* map = Heap::MapForExternalArrayType(array_type); | |
| 615 Object* code = map->FindInCodeCache(name, flags); | |
| 616 if (code->IsUndefined()) { | 604 if (code->IsUndefined()) { |
| 617 ExternalArrayStubCompiler compiler; | 605 ExternalArrayStubCompiler compiler; |
| 618 { MaybeObject* maybe_code = | 606 { MaybeObject* maybe_code = |
| 619 is_store ? compiler.CompileKeyedStoreStub(array_type, flags) : | 607 is_store ? |
| 620 compiler.CompileKeyedLoadStub(array_type, flags); | 608 compiler.CompileKeyedStoreStub(receiver, array_type, flags) : |
| 609 compiler.CompileKeyedLoadStub(receiver, array_type, flags); |
| 621 if (!maybe_code->ToObject(&code)) return maybe_code; | 610 if (!maybe_code->ToObject(&code)) return maybe_code; |
| 622 } | 611 } |
| 623 if (is_store) { | 612 if (is_store) { |
| 624 PROFILE( | 613 PROFILE( |
| 625 CodeCreateEvent(Logger::KEYED_STORE_IC_TAG, Code::cast(code), 0)); | 614 CodeCreateEvent(Logger::KEYED_EXTERNAL_ARRAY_STORE_IC_TAG, |
| 615 Code::cast(code), 0)); |
| 626 } else { | 616 } else { |
| 627 PROFILE( | 617 PROFILE( |
| 628 CodeCreateEvent(Logger::KEYED_LOAD_IC_TAG, Code::cast(code), 0)); | 618 CodeCreateEvent(Logger::KEYED_EXTERNAL_ARRAY_LOAD_IC_TAG, |
| 619 Code::cast(code), 0)); |
| 629 } | 620 } |
| 630 Object* result; | 621 Object* result; |
| 631 { MaybeObject* maybe_result = | 622 { MaybeObject* maybe_result = |
| 632 map->UpdateCodeCache(name, Code::cast(code)); | 623 receiver->map()->UpdateCodeCache(name, Code::cast(code)); |
| 633 if (!maybe_result->ToObject(&result)) return maybe_result; | 624 if (!maybe_result->ToObject(&result)) return maybe_result; |
| 634 } | 625 } |
| 635 } | 626 } |
| 636 return code; | 627 return code; |
| 637 } | 628 } |
| 638 | 629 |
| 639 | 630 |
| 640 MaybeObject* StubCache::ComputeStoreNormal(Code::ExtraICState extra_ic_state) { | 631 MaybeObject* StubCache::ComputeStoreNormal(Code::ExtraICState extra_ic_state) { |
| 641 return Builtins::builtin(extra_ic_state == StoreIC::kStoreICStrict | 632 return Builtins::builtin(extra_ic_state == StoreIC::kStoreICStrict |
| 642 ? Builtins::StoreIC_Normal_Strict | 633 ? Builtins::StoreIC_Normal_Strict |
| (...skipping 1212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1855 if (!maybe_result->ToObject(&result)) return maybe_result; | 1846 if (!maybe_result->ToObject(&result)) return maybe_result; |
| 1856 } | 1847 } |
| 1857 Code* code = Code::cast(result); | 1848 Code* code = Code::cast(result); |
| 1858 USE(code); | 1849 USE(code); |
| 1859 PROFILE(CodeCreateEvent(Logger::STUB_TAG, code, "ExternalArrayStub")); | 1850 PROFILE(CodeCreateEvent(Logger::STUB_TAG, code, "ExternalArrayStub")); |
| 1860 return result; | 1851 return result; |
| 1861 } | 1852 } |
| 1862 | 1853 |
| 1863 | 1854 |
| 1864 } } // namespace v8::internal | 1855 } } // namespace v8::internal |
| OLD | NEW |