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