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 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 Object* result; | 485 Object* result; |
486 { MaybeObject* maybe_result = | 486 { MaybeObject* maybe_result = |
487 receiver->UpdateMapCodeCache(name, Code::cast(code)); | 487 receiver->UpdateMapCodeCache(name, Code::cast(code)); |
488 if (!maybe_result->ToObject(&result)) return maybe_result; | 488 if (!maybe_result->ToObject(&result)) return maybe_result; |
489 } | 489 } |
490 } | 490 } |
491 return code; | 491 return code; |
492 } | 492 } |
493 | 493 |
494 | 494 |
| 495 namespace { |
| 496 |
| 497 ExternalArrayType ElementsKindToExternalArrayType(JSObject::ElementsKind kind) { |
| 498 switch (kind) { |
| 499 case JSObject::EXTERNAL_BYTE_ELEMENTS: |
| 500 return kExternalByteArray; |
| 501 case JSObject::EXTERNAL_UNSIGNED_BYTE_ELEMENTS: |
| 502 return kExternalUnsignedByteArray; |
| 503 case JSObject::EXTERNAL_SHORT_ELEMENTS: |
| 504 return kExternalShortArray; |
| 505 case JSObject::EXTERNAL_UNSIGNED_SHORT_ELEMENTS: |
| 506 return kExternalUnsignedShortArray; |
| 507 case JSObject::EXTERNAL_INT_ELEMENTS: |
| 508 return kExternalIntArray; |
| 509 case JSObject::EXTERNAL_UNSIGNED_INT_ELEMENTS: |
| 510 return kExternalUnsignedIntArray; |
| 511 case JSObject::EXTERNAL_FLOAT_ELEMENTS: |
| 512 return kExternalFloatArray; |
| 513 default: |
| 514 UNREACHABLE(); |
| 515 return static_cast<ExternalArrayType>(0); |
| 516 } |
| 517 } |
| 518 |
| 519 } // anonymous namespace |
| 520 |
| 521 |
| 522 MaybeObject* StubCache::ComputeKeyedLoadOrStoreExternalArray( |
| 523 JSObject* receiver, |
| 524 bool is_store) { |
| 525 Code::Flags flags = |
| 526 Code::ComputeMonomorphicFlags( |
| 527 is_store ? Code::KEYED_STORE_IC : Code::KEYED_LOAD_IC, |
| 528 NORMAL); |
| 529 ExternalArrayType array_type = |
| 530 ElementsKindToExternalArrayType(receiver->GetElementsKind()); |
| 531 HeapStringAllocator string_allocator; |
| 532 StringStream name_stream(&string_allocator); |
| 533 name_stream.Add("Keyed"); |
| 534 if (is_store) { |
| 535 name_stream.Add("Store"); |
| 536 } else { |
| 537 name_stream.Add("Load"); |
| 538 } |
| 539 name_stream.Add("External"); |
| 540 switch (array_type) { |
| 541 case kExternalByteArray: |
| 542 name_stream.Add("Byte"); |
| 543 break; |
| 544 case kExternalUnsignedByteArray: |
| 545 name_stream.Add("UnsignedByte"); |
| 546 break; |
| 547 case kExternalShortArray: |
| 548 name_stream.Add("Short"); |
| 549 break; |
| 550 case kExternalUnsignedShortArray: |
| 551 name_stream.Add("UnsignedShort"); |
| 552 break; |
| 553 case kExternalIntArray: |
| 554 name_stream.Add("Int"); |
| 555 break; |
| 556 case kExternalUnsignedIntArray: |
| 557 name_stream.Add("UnsignedInt"); |
| 558 break; |
| 559 case kExternalFloatArray: |
| 560 name_stream.Add("Float"); |
| 561 break; |
| 562 default: |
| 563 UNREACHABLE(); |
| 564 return Failure::InternalError(); |
| 565 } |
| 566 name_stream.Add("Array"); |
| 567 HandleScope scope; |
| 568 Handle<String> name = name_stream.ToSymbol(); |
| 569 // Use the global maps for the particular external array types, |
| 570 // rather than the receiver's map, when looking up the cached code, |
| 571 // so that we actually canonicalize these stubs. |
| 572 Map* map = Heap::MapForExternalArrayType(array_type); |
| 573 Object* code = map->FindInCodeCache(*name, flags); |
| 574 if (code->IsUndefined()) { |
| 575 ExternalArrayStubCompiler compiler; |
| 576 { MaybeObject* maybe_code = |
| 577 is_store ? compiler.CompileKeyedStoreStub(array_type, flags) : |
| 578 compiler.CompileKeyedLoadStub(array_type, flags); |
| 579 if (!maybe_code->ToObject(&code)) return maybe_code; |
| 580 } |
| 581 if (is_store) { |
| 582 PROFILE( |
| 583 CodeCreateEvent(Logger::KEYED_STORE_IC_TAG, Code::cast(code), 0)); |
| 584 } else { |
| 585 PROFILE( |
| 586 CodeCreateEvent(Logger::KEYED_LOAD_IC_TAG, Code::cast(code), 0)); |
| 587 } |
| 588 Object* result; |
| 589 { MaybeObject* maybe_result = |
| 590 map->UpdateCodeCache(*name, Code::cast(code)); |
| 591 if (!maybe_result->ToObject(&result)) return maybe_result; |
| 592 } |
| 593 } |
| 594 return code; |
| 595 } |
| 596 |
| 597 |
495 MaybeObject* StubCache::ComputeStoreNormal() { | 598 MaybeObject* StubCache::ComputeStoreNormal() { |
496 return Builtins::builtin(Builtins::StoreIC_Normal); | 599 return Builtins::builtin(Builtins::StoreIC_Normal); |
497 } | 600 } |
498 | 601 |
499 | 602 |
500 MaybeObject* StubCache::ComputeStoreGlobal(String* name, | 603 MaybeObject* StubCache::ComputeStoreGlobal(String* name, |
501 GlobalObject* receiver, | 604 GlobalObject* receiver, |
502 JSGlobalPropertyCell* cell) { | 605 JSGlobalPropertyCell* cell) { |
503 Code::Flags flags = Code::ComputeMonomorphicFlags(Code::STORE_IC, NORMAL); | 606 Code::Flags flags = Code::ComputeMonomorphicFlags(Code::STORE_IC, NORMAL); |
504 Object* code = receiver->map()->FindInCodeCache(name, flags); | 607 Object* code = receiver->map()->FindInCodeCache(name, flags); |
(...skipping 1118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1623 if (!signature->receiver()->IsUndefined()) { | 1726 if (!signature->receiver()->IsUndefined()) { |
1624 expected_receiver_type_ = | 1727 expected_receiver_type_ = |
1625 FunctionTemplateInfo::cast(signature->receiver()); | 1728 FunctionTemplateInfo::cast(signature->receiver()); |
1626 } | 1729 } |
1627 } | 1730 } |
1628 | 1731 |
1629 is_simple_api_call_ = true; | 1732 is_simple_api_call_ = true; |
1630 } | 1733 } |
1631 | 1734 |
1632 | 1735 |
| 1736 MaybeObject* ExternalArrayStubCompiler::GetCode(Code::Flags flags) { |
| 1737 Object* result; |
| 1738 { MaybeObject* maybe_result = GetCodeWithFlags(flags, "ExternalArrayStub"); |
| 1739 if (!maybe_result->ToObject(&result)) return maybe_result; |
| 1740 } |
| 1741 Code* code = Code::cast(result); |
| 1742 USE(code); |
| 1743 PROFILE(CodeCreateEvent(Logger::STUB_TAG, code, "ExternalArrayStub")); |
| 1744 return result; |
| 1745 } |
| 1746 |
| 1747 |
1633 } } // namespace v8::internal | 1748 } } // namespace v8::internal |
OLD | NEW |