Chromium Code Reviews| 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 1250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2551 Object* result; | 2555 Object* result; |
| 2552 { MaybeObject* maybe_result = AllocateRawAsciiString(length); | 2556 { MaybeObject* maybe_result = AllocateRawAsciiString(length); |
| 2553 if (!maybe_result->ToObject(&result)) return maybe_result; | 2557 if (!maybe_result->ToObject(&result)) return maybe_result; |
| 2554 } | 2558 } |
| 2555 // Copy the characters into the new object. | 2559 // Copy the characters into the new object. |
| 2556 char* dest = SeqAsciiString::cast(result)->GetChars(); | 2560 char* dest = SeqAsciiString::cast(result)->GetChars(); |
| 2557 // Copy first part. | 2561 // Copy first part. |
| 2558 const char* src; | 2562 const char* src; |
| 2559 if (first->IsExternalString()) { | 2563 if (first->IsExternalString()) { |
| 2560 src = ExternalAsciiString::cast(first)->resource()->data(); | 2564 src = ExternalAsciiString::cast(first)->resource()->data(); |
| 2565 } else if (first->IsSlicedString()) { | |
| 2566 SlicedString *slice = SlicedString::cast(first); | |
| 2567 src = SeqAsciiString::cast(slice->parent())->GetChars() | |
| 2568 + slice->offset(); | |
| 2561 } else { | 2569 } else { |
| 2562 src = SeqAsciiString::cast(first)->GetChars(); | 2570 src = SeqAsciiString::cast(first)->GetChars(); |
| 2563 } | 2571 } |
| 2564 for (int i = 0; i < first_length; i++) *dest++ = src[i]; | 2572 for (int i = 0; i < first_length; i++) *dest++ = src[i]; |
| 2565 // Copy second part. | 2573 // Copy second part. |
| 2566 if (second->IsExternalString()) { | 2574 if (second->IsExternalString()) { |
| 2567 src = ExternalAsciiString::cast(second)->resource()->data(); | 2575 src = ExternalAsciiString::cast(second)->resource()->data(); |
| 2576 } else if (second->IsSlicedString()) { | |
| 2577 SlicedString *slice = SlicedString::cast(second); | |
| 2578 src = SeqAsciiString::cast(slice->parent())->GetChars() | |
| 2579 + slice->offset(); | |
| 2568 } else { | 2580 } else { |
| 2569 src = SeqAsciiString::cast(second)->GetChars(); | 2581 src = SeqAsciiString::cast(second)->GetChars(); |
| 2570 } | 2582 } |
| 2571 for (int i = 0; i < second_length; i++) *dest++ = src[i]; | 2583 for (int i = 0; i < second_length; i++) *dest++ = src[i]; |
| 2572 return result; | 2584 return result; |
| 2573 } else { | 2585 } else { |
| 2574 if (is_ascii_data_in_two_byte_string) { | 2586 if (is_ascii_data_in_two_byte_string) { |
| 2575 Object* result; | 2587 Object* result; |
| 2576 { MaybeObject* maybe_result = AllocateRawAsciiString(length); | 2588 { MaybeObject* maybe_result = AllocateRawAsciiString(length); |
| 2577 if (!maybe_result->ToObject(&result)) return maybe_result; | 2589 if (!maybe_result->ToObject(&result)) return maybe_result; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2629 // dictionary. Check whether we already have the string in the symbol | 2641 // dictionary. Check whether we already have the string in the symbol |
| 2630 // table to prevent creation of many unneccesary strings. | 2642 // table to prevent creation of many unneccesary strings. |
| 2631 unsigned c1 = buffer->Get(start); | 2643 unsigned c1 = buffer->Get(start); |
| 2632 unsigned c2 = buffer->Get(start + 1); | 2644 unsigned c2 = buffer->Get(start + 1); |
| 2633 return MakeOrFindTwoCharacterString(this, c1, c2); | 2645 return MakeOrFindTwoCharacterString(this, c1, c2); |
| 2634 } | 2646 } |
| 2635 | 2647 |
| 2636 // Make an attempt to flatten the buffer to reduce access time. | 2648 // Make an attempt to flatten the buffer to reduce access time. |
| 2637 buffer = buffer->TryFlattenGetString(); | 2649 buffer = buffer->TryFlattenGetString(); |
| 2638 | 2650 |
| 2651 if (!buffer->IsFlat() || | |
| 2652 buffer->IsExternalString() || | |
| 2653 length < SlicedString::kMinLength) { | |
| 2654 Object* result; | |
| 2655 { MaybeObject* maybe_result = buffer->IsAsciiRepresentation() | |
| 2656 ? AllocateRawAsciiString(length, pretenure ) | |
| 2657 : AllocateRawTwoByteString(length, pretenure); | |
| 2658 if (!maybe_result->ToObject(&result)) return maybe_result; | |
| 2659 } | |
| 2660 String* string_result = String::cast(result); | |
| 2661 // Copy the characters into the new object. | |
| 2662 if (buffer->IsAsciiRepresentation()) { | |
| 2663 ASSERT(string_result->IsAsciiRepresentation()); | |
| 2664 char* dest = SeqAsciiString::cast(string_result)->GetChars(); | |
| 2665 String::WriteToFlat(buffer, dest, start, end); | |
| 2666 } else { | |
| 2667 ASSERT(string_result->IsTwoByteRepresentation()); | |
| 2668 uc16* dest = SeqTwoByteString::cast(string_result)->GetChars(); | |
| 2669 String::WriteToFlat(buffer, dest, start, end); | |
| 2670 } | |
| 2671 return result; | |
| 2672 } | |
| 2673 | |
| 2674 ASSERT(buffer->IsFlat()); | |
| 2675 ASSERT(!buffer->IsExternalString()); | |
| 2676 | |
| 2639 Object* result; | 2677 Object* result; |
| 2640 { MaybeObject* maybe_result = buffer->IsAsciiRepresentation() | 2678 { Map* map = buffer->IsAsciiRepresentation() |
| 2641 ? AllocateRawAsciiString(length, pretenure ) | 2679 ? sliced_ascii_string_map() |
| 2642 : AllocateRawTwoByteString(length, pretenure); | 2680 : sliced_string_map(); |
| 2681 MaybeObject* maybe_result = Allocate(map, NEW_SPACE); | |
| 2643 if (!maybe_result->ToObject(&result)) return maybe_result; | 2682 if (!maybe_result->ToObject(&result)) return maybe_result; |
| 2644 } | 2683 } |
| 2645 String* string_result = String::cast(result); | 2684 |
| 2646 // Copy the characters into the new object. | 2685 AssertNoAllocation no_gc; |
| 2647 if (buffer->IsAsciiRepresentation()) { | 2686 SlicedString* sliced_string = SlicedString::cast(result); |
| 2648 ASSERT(string_result->IsAsciiRepresentation()); | 2687 WriteBarrierMode mode = sliced_string->GetWriteBarrierMode(no_gc); |
|
antonm
2011/07/27 12:16:39
sliced_string should be allocated in new space, so
| |
| 2649 char* dest = SeqAsciiString::cast(string_result)->GetChars(); | 2688 sliced_string->set_length(length); |
| 2650 String::WriteToFlat(buffer, dest, start, end); | 2689 sliced_string->set_hash_field(String::kEmptyHashField); |
| 2690 if (buffer->IsConsString()) { | |
| 2691 ConsString* cons = ConsString::cast(buffer); | |
| 2692 sliced_string->set_parent(cons->first(), mode); | |
|
antonm
2011/07/27 12:16:39
why first? what if I slice in the second part?
| |
| 2693 sliced_string->set_offset(start); | |
| 2694 } else if (buffer->IsSlicedString()) { | |
| 2695 // Prevent nesting sliced strings. | |
| 2696 SlicedString* parent_slice = SlicedString::cast(buffer); | |
| 2697 sliced_string->set_parent(parent_slice->parent(), mode); | |
| 2698 sliced_string->set_offset(start + parent_slice->offset()); | |
| 2651 } else { | 2699 } else { |
| 2652 ASSERT(string_result->IsTwoByteRepresentation()); | 2700 sliced_string->set_parent(buffer, mode); |
| 2653 uc16* dest = SeqTwoByteString::cast(string_result)->GetChars(); | 2701 sliced_string->set_offset(start); |
| 2654 String::WriteToFlat(buffer, dest, start, end); | |
| 2655 } | 2702 } |
| 2656 | 2703 |
| 2657 return result; | 2704 return result; |
| 2658 } | 2705 } |
| 2659 | 2706 |
| 2660 | 2707 |
| 2661 MaybeObject* Heap::AllocateExternalStringFromAscii( | 2708 MaybeObject* Heap::AllocateExternalStringFromAscii( |
| 2662 ExternalAsciiString::Resource* resource) { | 2709 ExternalAsciiString::Resource* resource) { |
| 2663 size_t length = resource->length(); | 2710 size_t length = resource->length(); |
| 2664 if (length > static_cast<size_t>(String::kMaxLength)) { | 2711 if (length > static_cast<size_t>(String::kMaxLength)) { |
| (...skipping 3359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6024 } | 6071 } |
| 6025 | 6072 |
| 6026 | 6073 |
| 6027 void ExternalStringTable::TearDown() { | 6074 void ExternalStringTable::TearDown() { |
| 6028 new_space_strings_.Free(); | 6075 new_space_strings_.Free(); |
| 6029 old_space_strings_.Free(); | 6076 old_space_strings_.Free(); |
| 6030 } | 6077 } |
| 6031 | 6078 |
| 6032 | 6079 |
| 6033 } } // namespace v8::internal | 6080 } } // namespace v8::internal |
| OLD | NEW |