| 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 StrictModeFlag strict_mode) { | 474 StrictModeFlag strict_mode) { |
| 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, strict_mode); | 477 Code::STORE_IC, type, strict_mode); |
| 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 30 matching lines...) Expand all Loading... |
| 537 Object* result; | 510 Object* result; |
| 538 { MaybeObject* maybe_result = | 511 { MaybeObject* maybe_result = |
| 539 receiver->UpdateMapCodeCache(name, Code::cast(code)); | 512 receiver->UpdateMapCodeCache(name, Code::cast(code)); |
| 540 if (!maybe_result->ToObject(&result)) return maybe_result; | 513 if (!maybe_result->ToObject(&result)) return maybe_result; |
| 541 } | 514 } |
| 542 } | 515 } |
| 543 return code; | 516 return code; |
| 544 } | 517 } |
| 545 | 518 |
| 546 | 519 |
| 547 MaybeObject* StubCache::ComputeKeyedStorePixelArray( | |
| 548 JSObject* receiver, | |
| 549 StrictModeFlag strict_mode) { | |
| 550 // Using NORMAL as the PropertyType for array element stores is a misuse. The | |
| 551 // generated stub always accesses fast elements, not slow-mode fields, but | |
| 552 // some property type is required for the stub lookup. Note that overloading | |
| 553 // the NORMAL PropertyType is only safe as long as no stubs are generated for | |
| 554 // other keyed field stores. This is guaranteed to be the case since all field | |
| 555 // keyed stores that are not array elements go through a generic builtin stub. | |
| 556 Code::Flags flags = | |
| 557 Code::ComputeMonomorphicFlags(Code::KEYED_STORE_IC, NORMAL, strict_mode); | |
| 558 String* name = Heap::KeyedStorePixelArray_symbol(); | |
| 559 Object* code = receiver->map()->FindInCodeCache(name, flags); | |
| 560 if (code->IsUndefined()) { | |
| 561 KeyedStoreStubCompiler compiler(strict_mode); | |
| 562 { MaybeObject* maybe_code = compiler.CompileStorePixelArray(receiver); | |
| 563 if (!maybe_code->ToObject(&code)) return maybe_code; | |
| 564 } | |
| 565 PROFILE(CodeCreateEvent(Logger::KEYED_STORE_IC_TAG, Code::cast(code), 0)); | |
| 566 Object* result; | |
| 567 { MaybeObject* maybe_result = | |
| 568 receiver->UpdateMapCodeCache(name, Code::cast(code)); | |
| 569 if (!maybe_result->ToObject(&result)) return maybe_result; | |
| 570 } | |
| 571 } | |
| 572 return code; | |
| 573 } | |
| 574 | |
| 575 | |
| 576 namespace { | 520 namespace { |
| 577 | 521 |
| 578 ExternalArrayType ElementsKindToExternalArrayType(JSObject::ElementsKind kind) { | 522 ExternalArrayType ElementsKindToExternalArrayType(JSObject::ElementsKind kind) { |
| 579 switch (kind) { | 523 switch (kind) { |
| 580 case JSObject::EXTERNAL_BYTE_ELEMENTS: | 524 case JSObject::EXTERNAL_BYTE_ELEMENTS: |
| 581 return kExternalByteArray; | 525 return kExternalByteArray; |
| 582 case JSObject::EXTERNAL_UNSIGNED_BYTE_ELEMENTS: | 526 case JSObject::EXTERNAL_UNSIGNED_BYTE_ELEMENTS: |
| 583 return kExternalUnsignedByteArray; | 527 return kExternalUnsignedByteArray; |
| 584 case JSObject::EXTERNAL_SHORT_ELEMENTS: | 528 case JSObject::EXTERNAL_SHORT_ELEMENTS: |
| 585 return kExternalShortArray; | 529 return kExternalShortArray; |
| 586 case JSObject::EXTERNAL_UNSIGNED_SHORT_ELEMENTS: | 530 case JSObject::EXTERNAL_UNSIGNED_SHORT_ELEMENTS: |
| 587 return kExternalUnsignedShortArray; | 531 return kExternalUnsignedShortArray; |
| 588 case JSObject::EXTERNAL_INT_ELEMENTS: | 532 case JSObject::EXTERNAL_INT_ELEMENTS: |
| 589 return kExternalIntArray; | 533 return kExternalIntArray; |
| 590 case JSObject::EXTERNAL_UNSIGNED_INT_ELEMENTS: | 534 case JSObject::EXTERNAL_UNSIGNED_INT_ELEMENTS: |
| 591 return kExternalUnsignedIntArray; | 535 return kExternalUnsignedIntArray; |
| 592 case JSObject::EXTERNAL_FLOAT_ELEMENTS: | 536 case JSObject::EXTERNAL_FLOAT_ELEMENTS: |
| 593 return kExternalFloatArray; | 537 return kExternalFloatArray; |
| 538 case JSObject::EXTERNAL_PIXEL_ELEMENTS: |
| 539 return kExternalPixelArray; |
| 594 default: | 540 default: |
| 595 UNREACHABLE(); | 541 UNREACHABLE(); |
| 596 return static_cast<ExternalArrayType>(0); | 542 return static_cast<ExternalArrayType>(0); |
| 597 } | 543 } |
| 598 } | 544 } |
| 599 | 545 |
| 546 String* ExternalArrayTypeToStubName(ExternalArrayType array_type, |
| 547 bool is_store) { |
| 548 if (is_store) { |
| 549 switch (array_type) { |
| 550 case kExternalByteArray: |
| 551 return Heap::KeyedStoreExternalByteArray_symbol(); |
| 552 case kExternalUnsignedByteArray: |
| 553 return Heap::KeyedStoreExternalUnsignedByteArray_symbol(); |
| 554 case kExternalShortArray: |
| 555 return Heap::KeyedStoreExternalShortArray_symbol(); |
| 556 case kExternalUnsignedShortArray: |
| 557 return Heap::KeyedStoreExternalUnsignedShortArray_symbol(); |
| 558 case kExternalIntArray: |
| 559 return Heap::KeyedStoreExternalIntArray_symbol(); |
| 560 case kExternalUnsignedIntArray: |
| 561 return Heap::KeyedStoreExternalUnsignedIntArray_symbol(); |
| 562 case kExternalFloatArray: |
| 563 return Heap::KeyedStoreExternalFloatArray_symbol(); |
| 564 case kExternalPixelArray: |
| 565 return Heap::KeyedStoreExternalPixelArray_symbol(); |
| 566 default: |
| 567 UNREACHABLE(); |
| 568 return NULL; |
| 569 } |
| 570 } else { |
| 571 switch (array_type) { |
| 572 case kExternalByteArray: |
| 573 return Heap::KeyedLoadExternalByteArray_symbol(); |
| 574 case kExternalUnsignedByteArray: |
| 575 return Heap::KeyedLoadExternalUnsignedByteArray_symbol(); |
| 576 case kExternalShortArray: |
| 577 return Heap::KeyedLoadExternalShortArray_symbol(); |
| 578 case kExternalUnsignedShortArray: |
| 579 return Heap::KeyedLoadExternalUnsignedShortArray_symbol(); |
| 580 case kExternalIntArray: |
| 581 return Heap::KeyedLoadExternalIntArray_symbol(); |
| 582 case kExternalUnsignedIntArray: |
| 583 return Heap::KeyedLoadExternalUnsignedIntArray_symbol(); |
| 584 case kExternalFloatArray: |
| 585 return Heap::KeyedLoadExternalFloatArray_symbol(); |
| 586 case kExternalPixelArray: |
| 587 return Heap::KeyedLoadExternalPixelArray_symbol(); |
| 588 default: |
| 589 UNREACHABLE(); |
| 590 return NULL; |
| 591 } |
| 592 } |
| 593 } |
| 594 |
| 600 } // anonymous namespace | 595 } // anonymous namespace |
| 601 | 596 |
| 602 | 597 |
| 603 MaybeObject* StubCache::ComputeKeyedLoadOrStoreExternalArray( | 598 MaybeObject* StubCache::ComputeKeyedLoadOrStoreExternalArray( |
| 604 JSObject* receiver, | 599 JSObject* receiver, |
| 605 bool is_store, | 600 bool is_store, |
| 606 StrictModeFlag strict_mode) { | 601 StrictModeFlag strict_mode) { |
| 607 Code::Flags flags = | 602 Code::Flags flags = |
| 608 Code::ComputeMonomorphicFlags( | 603 Code::ComputeMonomorphicFlags( |
| 609 is_store ? Code::KEYED_STORE_IC : Code::KEYED_LOAD_IC, | 604 is_store ? Code::KEYED_EXTERNAL_ARRAY_STORE_IC : |
| 605 Code::KEYED_EXTERNAL_ARRAY_LOAD_IC, |
| 610 NORMAL, | 606 NORMAL, |
| 611 strict_mode); | 607 strict_mode); |
| 612 ExternalArrayType array_type = | 608 ExternalArrayType array_type = |
| 613 ElementsKindToExternalArrayType(receiver->GetElementsKind()); | 609 ElementsKindToExternalArrayType(receiver->GetElementsKind()); |
| 614 String* name = | 610 String* name = ExternalArrayTypeToStubName(array_type, is_store); |
| 615 is_store ? Heap::KeyedStoreExternalArray_symbol() | 611 Object* code = receiver->map()->FindInCodeCache(name, flags); |
| 616 : Heap::KeyedLoadExternalArray_symbol(); | |
| 617 // Use the global maps for the particular external array types, | |
| 618 // rather than the receiver's map, when looking up the cached code, | |
| 619 // so that we actually canonicalize these stubs. | |
| 620 Map* map = Heap::MapForExternalArrayType(array_type); | |
| 621 Object* code = map->FindInCodeCache(name, flags); | |
| 622 if (code->IsUndefined()) { | 612 if (code->IsUndefined()) { |
| 623 ExternalArrayStubCompiler compiler; | 613 ExternalArrayStubCompiler compiler; |
| 624 { MaybeObject* maybe_code = is_store | 614 { MaybeObject* maybe_code = |
| 625 ? compiler.CompileKeyedStoreStub(array_type, flags) | 615 is_store ? |
| 626 : compiler.CompileKeyedLoadStub(array_type, flags); | 616 compiler.CompileKeyedStoreStub(receiver, array_type, flags) : |
| 617 compiler.CompileKeyedLoadStub(receiver, array_type, flags); |
| 627 if (!maybe_code->ToObject(&code)) return maybe_code; | 618 if (!maybe_code->ToObject(&code)) return maybe_code; |
| 628 } | 619 } |
| 620 Code::cast(code)->set_external_array_type(array_type); |
| 629 if (is_store) { | 621 if (is_store) { |
| 630 PROFILE( | 622 PROFILE( |
| 631 CodeCreateEvent(Logger::KEYED_STORE_IC_TAG, Code::cast(code), 0)); | 623 CodeCreateEvent(Logger::KEYED_EXTERNAL_ARRAY_STORE_IC_TAG, |
| 624 Code::cast(code), 0)); |
| 632 } else { | 625 } else { |
| 633 PROFILE( | 626 PROFILE( |
| 634 CodeCreateEvent(Logger::KEYED_LOAD_IC_TAG, Code::cast(code), 0)); | 627 CodeCreateEvent(Logger::KEYED_EXTERNAL_ARRAY_LOAD_IC_TAG, |
| 628 Code::cast(code), 0)); |
| 635 } | 629 } |
| 636 Object* result; | 630 Object* result; |
| 637 { MaybeObject* maybe_result = | 631 { MaybeObject* maybe_result = |
| 638 map->UpdateCodeCache(name, Code::cast(code)); | 632 receiver->map()->UpdateCodeCache(name, Code::cast(code)); |
| 639 if (!maybe_result->ToObject(&result)) return maybe_result; | 633 if (!maybe_result->ToObject(&result)) return maybe_result; |
| 640 } | 634 } |
| 641 } | 635 } |
| 642 return code; | 636 return code; |
| 643 } | 637 } |
| 644 | 638 |
| 645 | 639 |
| 646 MaybeObject* StubCache::ComputeStoreNormal(StrictModeFlag strict_mode) { | 640 MaybeObject* StubCache::ComputeStoreNormal(StrictModeFlag strict_mode) { |
| 647 return Builtins::builtin((strict_mode == kStrictMode) | 641 return Builtins::builtin((strict_mode == kStrictMode) |
| 648 ? Builtins::StoreIC_Normal_Strict | 642 ? Builtins::StoreIC_Normal_Strict |
| (...skipping 1220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1869 if (!maybe_result->ToObject(&result)) return maybe_result; | 1863 if (!maybe_result->ToObject(&result)) return maybe_result; |
| 1870 } | 1864 } |
| 1871 Code* code = Code::cast(result); | 1865 Code* code = Code::cast(result); |
| 1872 USE(code); | 1866 USE(code); |
| 1873 PROFILE(CodeCreateEvent(Logger::STUB_TAG, code, "ExternalArrayStub")); | 1867 PROFILE(CodeCreateEvent(Logger::STUB_TAG, code, "ExternalArrayStub")); |
| 1874 return result; | 1868 return result; |
| 1875 } | 1869 } |
| 1876 | 1870 |
| 1877 | 1871 |
| 1878 } } // namespace v8::internal | 1872 } } // namespace v8::internal |
| OLD | NEW |