| 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 1270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1281 table_.Register(kVisitFixedDoubleArray, &EvacuateFixedDoubleArray); | 1281 table_.Register(kVisitFixedDoubleArray, &EvacuateFixedDoubleArray); |
| 1282 | 1282 |
| 1283 table_.Register(kVisitGlobalContext, | 1283 table_.Register(kVisitGlobalContext, |
| 1284 &ObjectEvacuationStrategy<POINTER_OBJECT>:: | 1284 &ObjectEvacuationStrategy<POINTER_OBJECT>:: |
| 1285 template VisitSpecialized<Context::kSize>); | 1285 template VisitSpecialized<Context::kSize>); |
| 1286 | 1286 |
| 1287 table_.Register(kVisitConsString, | 1287 table_.Register(kVisitConsString, |
| 1288 &ObjectEvacuationStrategy<POINTER_OBJECT>:: | 1288 &ObjectEvacuationStrategy<POINTER_OBJECT>:: |
| 1289 template VisitSpecialized<ConsString::kSize>); | 1289 template VisitSpecialized<ConsString::kSize>); |
| 1290 | 1290 |
| 1291 table_.Register(kVisitSlicedString, |
| 1292 &ObjectEvacuationStrategy<POINTER_OBJECT>:: |
| 1293 template VisitSpecialized<SlicedString::kSize>); |
| 1294 |
| 1291 table_.Register(kVisitSharedFunctionInfo, | 1295 table_.Register(kVisitSharedFunctionInfo, |
| 1292 &ObjectEvacuationStrategy<POINTER_OBJECT>:: | 1296 &ObjectEvacuationStrategy<POINTER_OBJECT>:: |
| 1293 template VisitSpecialized<SharedFunctionInfo::kSize>); | 1297 template VisitSpecialized<SharedFunctionInfo::kSize>); |
| 1294 | 1298 |
| 1295 table_.Register(kVisitJSRegExp, | 1299 table_.Register(kVisitJSRegExp, |
| 1296 &ObjectEvacuationStrategy<POINTER_OBJECT>:: | 1300 &ObjectEvacuationStrategy<POINTER_OBJECT>:: |
| 1297 Visit); | 1301 Visit); |
| 1298 | 1302 |
| 1299 table_.Register(kVisitJSFunction, | 1303 table_.Register(kVisitJSFunction, |
| 1300 &ObjectEvacuationStrategy<POINTER_OBJECT>:: | 1304 &ObjectEvacuationStrategy<POINTER_OBJECT>:: |
| (...skipping 1237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2538 // we can try to save memory if all chars actually fit in ascii. | 2542 // we can try to save memory if all chars actually fit in ascii. |
| 2539 is_ascii_data_in_two_byte_string = | 2543 is_ascii_data_in_two_byte_string = |
| 2540 first->HasOnlyAsciiChars() && second->HasOnlyAsciiChars(); | 2544 first->HasOnlyAsciiChars() && second->HasOnlyAsciiChars(); |
| 2541 if (is_ascii_data_in_two_byte_string) { | 2545 if (is_ascii_data_in_two_byte_string) { |
| 2542 isolate_->counters()->string_add_runtime_ext_to_ascii()->Increment(); | 2546 isolate_->counters()->string_add_runtime_ext_to_ascii()->Increment(); |
| 2543 } | 2547 } |
| 2544 } | 2548 } |
| 2545 | 2549 |
| 2546 // If the resulting string is small make a flat string. | 2550 // If the resulting string is small make a flat string. |
| 2547 if (length < String::kMinNonFlatLength) { | 2551 if (length < String::kMinNonFlatLength) { |
| 2552 // Note that neither of the two inputs can be a slice because: |
| 2553 STATIC_ASSERT(String::kMinNonFlatLength <= SlicedString::kMinLength); |
| 2548 ASSERT(first->IsFlat()); | 2554 ASSERT(first->IsFlat()); |
| 2549 ASSERT(second->IsFlat()); | 2555 ASSERT(second->IsFlat()); |
| 2550 if (is_ascii) { | 2556 if (is_ascii) { |
| 2551 Object* result; | 2557 Object* result; |
| 2552 { MaybeObject* maybe_result = AllocateRawAsciiString(length); | 2558 { MaybeObject* maybe_result = AllocateRawAsciiString(length); |
| 2553 if (!maybe_result->ToObject(&result)) return maybe_result; | 2559 if (!maybe_result->ToObject(&result)) return maybe_result; |
| 2554 } | 2560 } |
| 2555 // Copy the characters into the new object. | 2561 // Copy the characters into the new object. |
| 2556 char* dest = SeqAsciiString::cast(result)->GetChars(); | 2562 char* dest = SeqAsciiString::cast(result)->GetChars(); |
| 2557 // Copy first part. | 2563 // Copy first part. |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2629 // dictionary. Check whether we already have the string in the symbol | 2635 // dictionary. Check whether we already have the string in the symbol |
| 2630 // table to prevent creation of many unneccesary strings. | 2636 // table to prevent creation of many unneccesary strings. |
| 2631 unsigned c1 = buffer->Get(start); | 2637 unsigned c1 = buffer->Get(start); |
| 2632 unsigned c2 = buffer->Get(start + 1); | 2638 unsigned c2 = buffer->Get(start + 1); |
| 2633 return MakeOrFindTwoCharacterString(this, c1, c2); | 2639 return MakeOrFindTwoCharacterString(this, c1, c2); |
| 2634 } | 2640 } |
| 2635 | 2641 |
| 2636 // Make an attempt to flatten the buffer to reduce access time. | 2642 // Make an attempt to flatten the buffer to reduce access time. |
| 2637 buffer = buffer->TryFlattenGetString(); | 2643 buffer = buffer->TryFlattenGetString(); |
| 2638 | 2644 |
| 2645 // TODO(1626): For now slicing external strings is not supported. However, |
| 2646 // a flat cons string can have an external string as first part in some cases. |
| 2647 // Therefore we have to single out this case as well. |
| 2648 if (!FLAG_string_slices || |
| 2649 (buffer->IsConsString() && |
| 2650 (!buffer->IsFlat() || |
| 2651 !ConsString::cast(buffer)->first()->IsSeqString())) || |
| 2652 buffer->IsExternalString() || |
| 2653 length < SlicedString::kMinLength || |
| 2654 pretenure == TENURED) { |
| 2655 Object* result; |
| 2656 { MaybeObject* maybe_result = buffer->IsAsciiRepresentation() |
| 2657 ? AllocateRawAsciiString(length, pretenure) |
| 2658 : AllocateRawTwoByteString(length, pretenure); |
| 2659 if (!maybe_result->ToObject(&result)) return maybe_result; |
| 2660 } |
| 2661 String* string_result = String::cast(result); |
| 2662 // Copy the characters into the new object. |
| 2663 if (buffer->IsAsciiRepresentation()) { |
| 2664 ASSERT(string_result->IsAsciiRepresentation()); |
| 2665 char* dest = SeqAsciiString::cast(string_result)->GetChars(); |
| 2666 String::WriteToFlat(buffer, dest, start, end); |
| 2667 } else { |
| 2668 ASSERT(string_result->IsTwoByteRepresentation()); |
| 2669 uc16* dest = SeqTwoByteString::cast(string_result)->GetChars(); |
| 2670 String::WriteToFlat(buffer, dest, start, end); |
| 2671 } |
| 2672 return result; |
| 2673 } |
| 2674 |
| 2675 ASSERT(buffer->IsFlat()); |
| 2676 ASSERT(!buffer->IsExternalString()); |
| 2677 #if DEBUG |
| 2678 buffer->StringVerify(); |
| 2679 #endif |
| 2680 |
| 2639 Object* result; | 2681 Object* result; |
| 2640 { MaybeObject* maybe_result = buffer->IsAsciiRepresentation() | 2682 { Map* map = buffer->IsAsciiRepresentation() |
| 2641 ? AllocateRawAsciiString(length, pretenure ) | 2683 ? sliced_ascii_string_map() |
| 2642 : AllocateRawTwoByteString(length, pretenure); | 2684 : sliced_string_map(); |
| 2685 MaybeObject* maybe_result = Allocate(map, NEW_SPACE); |
| 2643 if (!maybe_result->ToObject(&result)) return maybe_result; | 2686 if (!maybe_result->ToObject(&result)) return maybe_result; |
| 2644 } | 2687 } |
| 2645 String* string_result = String::cast(result); | 2688 |
| 2646 // Copy the characters into the new object. | 2689 AssertNoAllocation no_gc; |
| 2647 if (buffer->IsAsciiRepresentation()) { | 2690 SlicedString* sliced_string = SlicedString::cast(result); |
| 2648 ASSERT(string_result->IsAsciiRepresentation()); | 2691 sliced_string->set_length(length); |
| 2649 char* dest = SeqAsciiString::cast(string_result)->GetChars(); | 2692 sliced_string->set_hash_field(String::kEmptyHashField); |
| 2650 String::WriteToFlat(buffer, dest, start, end); | 2693 if (buffer->IsConsString()) { |
| 2694 ConsString* cons = ConsString::cast(buffer); |
| 2695 ASSERT(cons->second()->length() == 0); |
| 2696 sliced_string->set_parent(cons->first()); |
| 2697 sliced_string->set_offset(start); |
| 2698 } else if (buffer->IsSlicedString()) { |
| 2699 // Prevent nesting sliced strings. |
| 2700 SlicedString* parent_slice = SlicedString::cast(buffer); |
| 2701 sliced_string->set_parent(parent_slice->parent()); |
| 2702 sliced_string->set_offset(start + parent_slice->offset()); |
| 2651 } else { | 2703 } else { |
| 2652 ASSERT(string_result->IsTwoByteRepresentation()); | 2704 sliced_string->set_parent(buffer); |
| 2653 uc16* dest = SeqTwoByteString::cast(string_result)->GetChars(); | 2705 sliced_string->set_offset(start); |
| 2654 String::WriteToFlat(buffer, dest, start, end); | |
| 2655 } | 2706 } |
| 2656 | 2707 ASSERT(sliced_string->parent()->IsSeqString()); |
| 2657 return result; | 2708 return result; |
| 2658 } | 2709 } |
| 2659 | 2710 |
| 2660 | 2711 |
| 2661 MaybeObject* Heap::AllocateExternalStringFromAscii( | 2712 MaybeObject* Heap::AllocateExternalStringFromAscii( |
| 2662 ExternalAsciiString::Resource* resource) { | 2713 ExternalAsciiString::Resource* resource) { |
| 2663 size_t length = resource->length(); | 2714 size_t length = resource->length(); |
| 2664 if (length > static_cast<size_t>(String::kMaxLength)) { | 2715 if (length > static_cast<size_t>(String::kMaxLength)) { |
| 2665 isolate()->context()->mark_out_of_memory(); | 2716 isolate()->context()->mark_out_of_memory(); |
| 2666 return Failure::OutOfMemoryException(); | 2717 return Failure::OutOfMemoryException(); |
| (...skipping 3357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6024 } | 6075 } |
| 6025 | 6076 |
| 6026 | 6077 |
| 6027 void ExternalStringTable::TearDown() { | 6078 void ExternalStringTable::TearDown() { |
| 6028 new_space_strings_.Free(); | 6079 new_space_strings_.Free(); |
| 6029 old_space_strings_.Free(); | 6080 old_space_strings_.Free(); |
| 6030 } | 6081 } |
| 6031 | 6082 |
| 6032 | 6083 |
| 6033 } } // namespace v8::internal | 6084 } } // namespace v8::internal |
| OLD | NEW |