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 4656 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4667 case SHORT_EXTERNAL_STRING_TYPE: return short_external_symbol_map(); | 4667 case SHORT_EXTERNAL_STRING_TYPE: return short_external_symbol_map(); |
4668 case SHORT_EXTERNAL_ASCII_STRING_TYPE: | 4668 case SHORT_EXTERNAL_ASCII_STRING_TYPE: |
4669 return short_external_ascii_symbol_map(); | 4669 return short_external_ascii_symbol_map(); |
4670 case SHORT_EXTERNAL_STRING_WITH_ASCII_DATA_TYPE: | 4670 case SHORT_EXTERNAL_STRING_WITH_ASCII_DATA_TYPE: |
4671 return short_external_symbol_with_ascii_data_map(); | 4671 return short_external_symbol_with_ascii_data_map(); |
4672 default: return NULL; // No match found. | 4672 default: return NULL; // No match found. |
4673 } | 4673 } |
4674 } | 4674 } |
4675 | 4675 |
4676 | 4676 |
4677 template<typename T> | 4677 static inline void WriteOneByteData(Vector<const char> vector, |
4678 class AllocateInternalSymbolHelper { | 4678 uint8_t* chars, |
4679 public: | 4679 int len) { |
4680 static void WriteOneByteData(T t, char* chars, int len); | 4680 // Only works for ascii. |
4681 static void WriteTwoByteData(T t, uint16_t* chars, int len); | 4681 ASSERT(vector.length() == len); |
4682 private: | 4682 memcpy(chars, vector.start(), len); |
4683 DISALLOW_COPY_AND_ASSIGN(AllocateInternalSymbolHelper); | 4683 } |
4684 }; | 4684 |
| 4685 static inline void WriteTwoByteData(Vector<const char> vector, |
| 4686 uint16_t* chars, |
| 4687 int len) { |
| 4688 const uint8_t* stream = reinterpret_cast<const uint8_t*>(vector.start()); |
| 4689 unsigned stream_length = vector.length(); |
| 4690 while (stream_length != 0) { |
| 4691 unsigned consumed = 0; |
| 4692 uint32_t c = unibrow::Utf8::ValueOf(stream, stream_length, &consumed); |
| 4693 ASSERT(c != unibrow::Utf8::kBadChar); |
| 4694 ASSERT(consumed <= stream_length); |
| 4695 stream_length -= consumed; |
| 4696 stream += consumed; |
| 4697 if (c > unibrow::Utf16::kMaxNonSurrogateCharCode) { |
| 4698 len -= 2; |
| 4699 if (len < 0) break; |
| 4700 *chars++ = unibrow::Utf16::LeadSurrogate(c); |
| 4701 *chars++ = unibrow::Utf16::TrailSurrogate(c); |
| 4702 } else { |
| 4703 len -= 1; |
| 4704 if (len < 0) break; |
| 4705 *chars++ = c; |
| 4706 } |
| 4707 } |
| 4708 ASSERT(stream_length == 0); |
| 4709 ASSERT(len == 0); |
| 4710 } |
4685 | 4711 |
4686 | 4712 |
4687 template<> | 4713 static inline void WriteOneByteData(String* s, uint8_t* chars, int len) { |
4688 class AllocateInternalSymbolHelper< Vector<const char> > { | 4714 ASSERT(s->length() == len); |
4689 public: | 4715 String::WriteToFlat(s, chars, 0, len); |
4690 static inline void WriteOneByteData(Vector<const char> vector, | 4716 } |
4691 uint8_t* chars, | |
4692 int len) { | |
4693 // Only works for ascii. | |
4694 ASSERT(vector.length() == len); | |
4695 memcpy(chars, vector.start(), len); | |
4696 } | |
4697 | 4717 |
4698 static inline void WriteTwoByteData(Vector<const char> vector, | 4718 static inline void WriteTwoByteData(String* s, uint16_t* chars, int len) { |
4699 uint16_t* chars, | 4719 ASSERT(s->length() == len); |
4700 int len) { | 4720 String::WriteToFlat(s, chars, 0, len); |
4701 const uint8_t* stream = reinterpret_cast<const uint8_t*>(vector.start()); | 4721 } |
4702 unsigned stream_length = vector.length(); | |
4703 while (stream_length != 0) { | |
4704 unsigned consumed = 0; | |
4705 uint32_t c = unibrow::Utf8::ValueOf(stream, stream_length, &consumed); | |
4706 ASSERT(c != unibrow::Utf8::kBadChar); | |
4707 ASSERT(consumed <= stream_length); | |
4708 stream_length -= consumed; | |
4709 stream += consumed; | |
4710 if (c > unibrow::Utf16::kMaxNonSurrogateCharCode) { | |
4711 len -= 2; | |
4712 if (len < 0) break; | |
4713 *chars++ = unibrow::Utf16::LeadSurrogate(c); | |
4714 *chars++ = unibrow::Utf16::TrailSurrogate(c); | |
4715 } else { | |
4716 len -= 1; | |
4717 if (len < 0) break; | |
4718 *chars++ = c; | |
4719 } | |
4720 } | |
4721 ASSERT(stream_length == 0); | |
4722 ASSERT(len == 0); | |
4723 } | |
4724 | |
4725 private: | |
4726 DISALLOW_COPY_AND_ASSIGN(AllocateInternalSymbolHelper); | |
4727 }; | |
4728 | |
4729 | |
4730 template<> | |
4731 class AllocateInternalSymbolHelper<String*> { | |
4732 public: | |
4733 static inline void WriteOneByteData(String* s, uint8_t* chars, int len) { | |
4734 ASSERT(s->length() == len); | |
4735 String::WriteToFlat(s, chars, 0, len); | |
4736 } | |
4737 | |
4738 static inline void WriteTwoByteData(String* s, uint16_t* chars, int len) { | |
4739 ASSERT(s->length() == len); | |
4740 String::WriteToFlat(s, chars, 0, len); | |
4741 } | |
4742 | |
4743 private: | |
4744 DISALLOW_COPY_AND_ASSIGN(AllocateInternalSymbolHelper<String*>); | |
4745 }; | |
4746 | 4722 |
4747 | 4723 |
4748 template<bool is_one_byte, typename T> | 4724 template<bool is_one_byte, typename T> |
4749 MaybeObject* Heap::AllocateInternalSymbol(T t, | 4725 MaybeObject* Heap::AllocateInternalSymbol(T t, |
4750 int chars, | 4726 int chars, |
4751 uint32_t hash_field) { | 4727 uint32_t hash_field) { |
4752 typedef AllocateInternalSymbolHelper<T> H; | |
4753 ASSERT(chars >= 0); | 4728 ASSERT(chars >= 0); |
4754 // Compute map and object size. | 4729 // Compute map and object size. |
4755 int size; | 4730 int size; |
4756 Map* map; | 4731 Map* map; |
4757 | 4732 |
4758 if (is_one_byte) { | 4733 if (is_one_byte) { |
4759 if (chars > SeqOneByteString::kMaxLength) { | 4734 if (chars > SeqOneByteString::kMaxLength) { |
4760 return Failure::OutOfMemoryException(0x9); | 4735 return Failure::OutOfMemoryException(0x9); |
4761 } | 4736 } |
4762 map = ascii_symbol_map(); | 4737 map = ascii_symbol_map(); |
(...skipping 16 matching lines...) Expand all Loading... |
4779 | 4754 |
4780 reinterpret_cast<HeapObject*>(result)->set_map_no_write_barrier(map); | 4755 reinterpret_cast<HeapObject*>(result)->set_map_no_write_barrier(map); |
4781 // Set length and hash fields of the allocated string. | 4756 // Set length and hash fields of the allocated string. |
4782 String* answer = String::cast(result); | 4757 String* answer = String::cast(result); |
4783 answer->set_length(chars); | 4758 answer->set_length(chars); |
4784 answer->set_hash_field(hash_field); | 4759 answer->set_hash_field(hash_field); |
4785 | 4760 |
4786 ASSERT_EQ(size, answer->Size()); | 4761 ASSERT_EQ(size, answer->Size()); |
4787 | 4762 |
4788 if (is_one_byte) { | 4763 if (is_one_byte) { |
4789 H::WriteOneByteData(t, SeqOneByteString::cast(answer)->GetChars(), chars); | 4764 WriteOneByteData(t, SeqOneByteString::cast(answer)->GetChars(), chars); |
4790 } else { | 4765 } else { |
4791 H::WriteTwoByteData(t, SeqTwoByteString::cast(answer)->GetChars(), chars); | 4766 WriteTwoByteData(t, SeqTwoByteString::cast(answer)->GetChars(), chars); |
4792 } | 4767 } |
4793 return answer; | 4768 return answer; |
4794 } | 4769 } |
4795 | 4770 |
4796 | 4771 |
4797 // Need explicit instantiations. | 4772 // Need explicit instantiations. |
4798 template | 4773 template |
4799 MaybeObject* Heap::AllocateInternalSymbol<true>(String*, int, uint32_t); | 4774 MaybeObject* Heap::AllocateInternalSymbol<true>(String*, int, uint32_t); |
4800 template | 4775 template |
4801 MaybeObject* Heap::AllocateInternalSymbol<false>(String*, int, uint32_t); | 4776 MaybeObject* Heap::AllocateInternalSymbol<false>(String*, int, uint32_t); |
(...skipping 2730 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7532 static_cast<int>(object_sizes_last_time_[index])); | 7507 static_cast<int>(object_sizes_last_time_[index])); |
7533 FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(ADJUST_LAST_TIME_OBJECT_COUNT) | 7508 FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(ADJUST_LAST_TIME_OBJECT_COUNT) |
7534 #undef ADJUST_LAST_TIME_OBJECT_COUNT | 7509 #undef ADJUST_LAST_TIME_OBJECT_COUNT |
7535 | 7510 |
7536 memcpy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); | 7511 memcpy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); |
7537 memcpy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); | 7512 memcpy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); |
7538 ClearObjectStats(); | 7513 ClearObjectStats(); |
7539 } | 7514 } |
7540 | 7515 |
7541 } } // namespace v8::internal | 7516 } } // namespace v8::internal |
OLD | NEW |