OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 934 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
945 ASSERT(static_cast<size_t>(this->length()) == resource->length()); | 945 ASSERT(static_cast<size_t>(this->length()) == resource->length()); |
946 ScopedVector<uc16> smart_chars(this->length()); | 946 ScopedVector<uc16> smart_chars(this->length()); |
947 String::WriteToFlat(this, smart_chars.start(), 0, this->length()); | 947 String::WriteToFlat(this, smart_chars.start(), 0, this->length()); |
948 ASSERT(memcmp(smart_chars.start(), | 948 ASSERT(memcmp(smart_chars.start(), |
949 resource->data(), | 949 resource->data(), |
950 resource->length() * sizeof(smart_chars[0])) == 0); | 950 resource->length() * sizeof(smart_chars[0])) == 0); |
951 } | 951 } |
952 #endif // DEBUG | 952 #endif // DEBUG |
953 Heap* heap = GetHeap(); | 953 Heap* heap = GetHeap(); |
954 int size = this->Size(); // Byte size of the original string. | 954 int size = this->Size(); // Byte size of the original string. |
955 if (size < ExternalString::kSize) { | 955 if (size < ExternalString::kShortSize) { |
956 return false; | 956 return false; |
957 } | 957 } |
958 ASSERT(size >= ExternalString::kSize); | |
959 bool is_ascii = this->IsAsciiRepresentation(); | 958 bool is_ascii = this->IsAsciiRepresentation(); |
960 bool is_symbol = this->IsSymbol(); | 959 bool is_symbol = this->IsSymbol(); |
961 int length = this->length(); | |
962 int hash_field = this->hash_field(); | |
963 | 960 |
964 // Morph the object to an external string by adjusting the map and | 961 // Morph the object to an external string by adjusting the map and |
965 // reinitializing the fields. | 962 // reinitializing the fields. |
966 this->set_map(is_ascii ? | 963 if (size >= ExternalString::kSize) { |
967 heap->external_string_with_ascii_data_map() : | 964 this->set_map( |
968 heap->external_string_map()); | 965 is_symbol |
| 966 ? (is_ascii ? heap->external_symbol_with_ascii_data_map() |
| 967 : heap->external_symbol_map()) |
| 968 : (is_ascii ? heap->external_string_with_ascii_data_map() |
| 969 : heap->external_string_map())); |
| 970 } else { |
| 971 this->set_map( |
| 972 is_symbol |
| 973 ? (is_ascii ? heap->short_external_symbol_with_ascii_data_map() |
| 974 : heap->short_external_symbol_map()) |
| 975 : (is_ascii ? heap->short_external_string_with_ascii_data_map() |
| 976 : heap->short_external_string_map())); |
| 977 } |
969 ExternalTwoByteString* self = ExternalTwoByteString::cast(this); | 978 ExternalTwoByteString* self = ExternalTwoByteString::cast(this); |
970 self->set_length(length); | |
971 self->set_hash_field(hash_field); | |
972 self->set_resource(resource); | 979 self->set_resource(resource); |
973 // Additionally make the object into an external symbol if the original string | 980 if (is_symbol) self->Hash(); // Force regeneration of the hash value. |
974 // was a symbol to start with. | |
975 if (is_symbol) { | |
976 self->Hash(); // Force regeneration of the hash value. | |
977 // Now morph this external string into a external symbol. | |
978 this->set_map(is_ascii ? | |
979 heap->external_symbol_with_ascii_data_map() : | |
980 heap->external_symbol_map()); | |
981 } | |
982 | 981 |
983 // Fill the remainder of the string with dead wood. | 982 // Fill the remainder of the string with dead wood. |
984 int new_size = this->Size(); // Byte size of the external String object. | 983 int new_size = this->Size(); // Byte size of the external String object. |
985 heap->CreateFillerObjectAt(this->address() + new_size, size - new_size); | 984 heap->CreateFillerObjectAt(this->address() + new_size, size - new_size); |
986 if (Marking::IsBlack(Marking::MarkBitFrom(this))) { | 985 if (Marking::IsBlack(Marking::MarkBitFrom(this))) { |
987 MemoryChunk::IncrementLiveBytes(this->address(), new_size - size); | 986 MemoryChunk::IncrementLiveBytes(this->address(), new_size - size); |
988 } | 987 } |
989 return true; | 988 return true; |
990 } | 989 } |
991 | 990 |
992 | 991 |
993 bool String::MakeExternal(v8::String::ExternalAsciiStringResource* resource) { | 992 bool String::MakeExternal(v8::String::ExternalAsciiStringResource* resource) { |
994 #ifdef DEBUG | 993 #ifdef DEBUG |
995 if (FLAG_enable_slow_asserts) { | 994 if (FLAG_enable_slow_asserts) { |
996 // Assert that the resource and the string are equivalent. | 995 // Assert that the resource and the string are equivalent. |
997 ASSERT(static_cast<size_t>(this->length()) == resource->length()); | 996 ASSERT(static_cast<size_t>(this->length()) == resource->length()); |
998 ScopedVector<char> smart_chars(this->length()); | 997 ScopedVector<char> smart_chars(this->length()); |
999 String::WriteToFlat(this, smart_chars.start(), 0, this->length()); | 998 String::WriteToFlat(this, smart_chars.start(), 0, this->length()); |
1000 ASSERT(memcmp(smart_chars.start(), | 999 ASSERT(memcmp(smart_chars.start(), |
1001 resource->data(), | 1000 resource->data(), |
1002 resource->length() * sizeof(smart_chars[0])) == 0); | 1001 resource->length() * sizeof(smart_chars[0])) == 0); |
1003 } | 1002 } |
1004 #endif // DEBUG | 1003 #endif // DEBUG |
1005 Heap* heap = GetHeap(); | 1004 Heap* heap = GetHeap(); |
1006 int size = this->Size(); // Byte size of the original string. | 1005 int size = this->Size(); // Byte size of the original string. |
1007 if (size < ExternalString::kSize) { | 1006 if (size < ExternalString::kShortSize) { |
1008 return false; | 1007 return false; |
1009 } | 1008 } |
1010 ASSERT(size >= ExternalString::kSize); | |
1011 bool is_symbol = this->IsSymbol(); | 1009 bool is_symbol = this->IsSymbol(); |
1012 int length = this->length(); | |
1013 int hash_field = this->hash_field(); | |
1014 | 1010 |
1015 // Morph the object to an external string by adjusting the map and | 1011 // Morph the object to an external string by adjusting the map and |
1016 // reinitializing the fields. | 1012 // reinitializing the fields. Use short version if space is limited. |
1017 this->set_map(heap->external_ascii_string_map()); | 1013 if (size >= ExternalString::kSize) { |
| 1014 this->set_map(is_symbol ? heap->external_ascii_symbol_map() |
| 1015 : heap->external_ascii_string_map()); |
| 1016 } else { |
| 1017 this->set_map(is_symbol ? heap->short_external_ascii_symbol_map() |
| 1018 : heap->short_external_ascii_string_map()); |
| 1019 } |
1018 ExternalAsciiString* self = ExternalAsciiString::cast(this); | 1020 ExternalAsciiString* self = ExternalAsciiString::cast(this); |
1019 self->set_length(length); | |
1020 self->set_hash_field(hash_field); | |
1021 self->set_resource(resource); | 1021 self->set_resource(resource); |
1022 // Additionally make the object into an external symbol if the original string | 1022 if (is_symbol) self->Hash(); // Force regeneration of the hash value. |
1023 // was a symbol to start with. | |
1024 if (is_symbol) { | |
1025 self->Hash(); // Force regeneration of the hash value. | |
1026 // Now morph this external string into a external symbol. | |
1027 this->set_map(heap->external_ascii_symbol_map()); | |
1028 } | |
1029 | 1023 |
1030 // Fill the remainder of the string with dead wood. | 1024 // Fill the remainder of the string with dead wood. |
1031 int new_size = this->Size(); // Byte size of the external String object. | 1025 int new_size = this->Size(); // Byte size of the external String object. |
1032 heap->CreateFillerObjectAt(this->address() + new_size, size - new_size); | 1026 heap->CreateFillerObjectAt(this->address() + new_size, size - new_size); |
1033 if (Marking::IsBlack(Marking::MarkBitFrom(this))) { | 1027 if (Marking::IsBlack(Marking::MarkBitFrom(this))) { |
1034 MemoryChunk::IncrementLiveBytes(this->address(), new_size - size); | 1028 MemoryChunk::IncrementLiveBytes(this->address(), new_size - size); |
1035 } | 1029 } |
1036 | |
1037 return true; | 1030 return true; |
1038 } | 1031 } |
1039 | 1032 |
1040 | 1033 |
1041 void String::StringShortPrint(StringStream* accumulator) { | 1034 void String::StringShortPrint(StringStream* accumulator) { |
1042 int len = length(); | 1035 int len = length(); |
1043 if (len > kMaxShortPrintLength) { | 1036 if (len > kMaxShortPrintLength) { |
1044 accumulator->Add("<Very long string[%u]>", len); | 1037 accumulator->Add("<Very long string[%u]>", len); |
1045 return; | 1038 return; |
1046 } | 1039 } |
(...skipping 11468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12515 if (break_point_objects()->IsUndefined()) return 0; | 12508 if (break_point_objects()->IsUndefined()) return 0; |
12516 // Single break point. | 12509 // Single break point. |
12517 if (!break_point_objects()->IsFixedArray()) return 1; | 12510 if (!break_point_objects()->IsFixedArray()) return 1; |
12518 // Multiple break points. | 12511 // Multiple break points. |
12519 return FixedArray::cast(break_point_objects())->length(); | 12512 return FixedArray::cast(break_point_objects())->length(); |
12520 } | 12513 } |
12521 #endif // ENABLE_DEBUGGER_SUPPORT | 12514 #endif // ENABLE_DEBUGGER_SUPPORT |
12522 | 12515 |
12523 | 12516 |
12524 } } // namespace v8::internal | 12517 } } // namespace v8::internal |
OLD | NEW |