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