Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(421)

Side by Side Diff: src/objects.cc

Issue 21117: Allow the morphing of strings to external strings to avoid having to... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 11 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 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 649 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 cs->set_first(result); 660 cs->set_first(result);
661 cs->set_second(Heap::empty_string()); 661 cs->set_second(Heap::empty_string());
662 return this; 662 return this;
663 } 663 }
664 default: 664 default:
665 return this; 665 return this;
666 } 666 }
667 } 667 }
668 668
669 669
670 bool String::MakeExternal(v8::String::ExternalStringResource* resource) {
671 #ifdef DEBUG
672 { // NOLINT (presubmit.py gets confused about if and braces)
673 // Assert that the resource and the string are equivalent.
674 ASSERT(static_cast<size_t>(this->length()) == resource->length());
675 SmartPointer<uc16> smart_chars = this->ToWideCString();
676 ASSERT(memcmp(*smart_chars,
677 resource->data(),
678 resource->length()*sizeof(**smart_chars)) == 0);
679 }
680 #endif // DEBUG
681
682 int size = this->Size(); // Byte size of the original string.
683 if (size < ExternalString::kSize) {
684 // The string is too small to fit an external String in its place. This can
685 // only happen for zero length strings.
686 return false;
687 }
688 ASSERT(size >= ExternalString::kSize);
689 bool is_symbol = this->IsSymbol();
690 int length = this->length();
691
692 // Morph the object to an external string by adjusting the map and
693 // reinitializing the fields.
694 this->set_map(ExternalTwoByteString::StringMap(length));
695 ExternalTwoByteString* self = ExternalTwoByteString::cast(this);
696 self->set_length(length);
697 self->set_resource(resource);
698 // Additionally make the object into an external symbol if the original string
699 // was a symbol to start with.
700 if (is_symbol) {
701 self->Hash(); // Force regeneration of the hash value.
702 // Now morph this external string into a external symbol.
703 self->set_map(ExternalTwoByteString::SymbolMap(length));
704 }
705
706 // Fill the remainder of the string with dead wood.
707 int new_size = this->Size(); // Byte size of the external String object.
708 Heap::CreateFillerObjectAt(this->address() + new_size, size - new_size);
709 return true;
710 }
711
712
713 bool String::MakeExternal(v8::String::ExternalAsciiStringResource* resource) {
714 #ifdef DEBUG
715 { // NOLINT (presubmit.py gets confused about if and braces)
716 // Assert that the resource and the string are equivalent.
717 ASSERT(static_cast<size_t>(this->length()) == resource->length());
718 SmartPointer<char> smart_chars = this->ToCString();
719 ASSERT(memcmp(*smart_chars,
720 resource->data(),
721 resource->length()*sizeof(**smart_chars)) == 0);
722 }
723 #endif // DEBUG
724
725 int size = this->Size(); // Byte size of the original string.
726 if (size < ExternalString::kSize) {
727 // The string is too small to fit an external String in its place. This can
728 // only happen for zero length strings.
729 return false;
730 }
731 ASSERT(size >= ExternalString::kSize);
732 bool is_symbol = this->IsSymbol();
733 int length = this->length();
734
735 // Morph the object to an external string by adjusting the map and
736 // reinitializing the fields.
737 this->set_map(ExternalAsciiString::StringMap(length));
738 ExternalAsciiString* self = ExternalAsciiString::cast(this);
739 self->set_length(length);
740 self->set_resource(resource);
741 // Additionally make the object into an external symbol if the original string
742 // was a symbol to start with.
743 if (is_symbol) {
744 self->Hash(); // Force regeneration of the hash value.
745 // Now morph this external string into a external symbol.
746 self->set_map(ExternalAsciiString::SymbolMap(length));
747 }
748
749 // Fill the remainder of the string with dead wood.
750 int new_size = this->Size(); // Byte size of the external String object.
751 Heap::CreateFillerObjectAt(this->address() + new_size, size - new_size);
752 return true;
753 }
754
755
670 void String::StringShortPrint(StringStream* accumulator) { 756 void String::StringShortPrint(StringStream* accumulator) {
671 StringShape shape(this); 757 StringShape shape(this);
672 int len = length(shape); 758 int len = length(shape);
673 if (len > kMaxMediumStringSize) { 759 if (len > kMaxMediumStringSize) {
674 accumulator->Add("<Very long string[%u]>", len); 760 accumulator->Add("<Very long string[%u]>", len);
675 return; 761 return;
676 } 762 }
677 763
678 if (!LooksValid()) { 764 if (!LooksValid()) {
679 accumulator->Add("<Invalid String>"); 765 accumulator->Add("<Invalid String>");
(...skipping 1240 matching lines...) Expand 10 before | Expand all | Expand 10 after
1920 2006
1921 // Copy the next enumeration index from instance descriptor. 2007 // Copy the next enumeration index from instance descriptor.
1922 int index = map()->instance_descriptors()->NextEnumerationIndex(); 2008 int index = map()->instance_descriptors()->NextEnumerationIndex();
1923 dictionary->SetNextEnumerationIndex(index); 2009 dictionary->SetNextEnumerationIndex(index);
1924 2010
1925 // Allocate new map. 2011 // Allocate new map.
1926 obj = map()->Copy(); 2012 obj = map()->Copy();
1927 if (obj->IsFailure()) return obj; 2013 if (obj->IsFailure()) return obj;
1928 Map* new_map = Map::cast(obj); 2014 Map* new_map = Map::cast(obj);
1929 2015
1930 // Clear inobject properties if needed by adjusting the instance 2016 // Clear inobject properties if needed by adjusting the instance size and
1931 // size and putting in a filler or byte array instead of the 2017 // putting in a filler object instead of the inobject properties.
1932 // inobject properties.
1933 if (mode == CLEAR_INOBJECT_PROPERTIES && map()->inobject_properties() > 0) { 2018 if (mode == CLEAR_INOBJECT_PROPERTIES && map()->inobject_properties() > 0) {
1934 int instance_size_delta = map()->inobject_properties() * kPointerSize; 2019 int instance_size_delta = map()->inobject_properties() * kPointerSize;
1935 int new_instance_size = map()->instance_size() - instance_size_delta; 2020 int new_instance_size = map()->instance_size() - instance_size_delta;
1936 new_map->set_inobject_properties(0); 2021 new_map->set_inobject_properties(0);
1937 new_map->set_instance_size(new_instance_size); 2022 new_map->set_instance_size(new_instance_size);
1938 if (instance_size_delta == kPointerSize) { 2023 Heap::CreateFillerObjectAt(this->address() + new_instance_size,
1939 WRITE_FIELD(this, new_instance_size, Heap::one_word_filler_map()); 2024 instance_size_delta);
1940 } else {
1941 int byte_array_length = ByteArray::LengthFor(instance_size_delta);
1942 int byte_array_length_offset = new_instance_size + kPointerSize;
1943 WRITE_FIELD(this, new_instance_size, Heap::byte_array_map());
1944 WRITE_INT_FIELD(this, byte_array_length_offset, byte_array_length);
1945 }
1946 WRITE_BARRIER(this, new_instance_size);
1947 } 2025 }
1948 new_map->set_unused_property_fields(0); 2026 new_map->set_unused_property_fields(0);
1949 2027
1950 // We have now successfully allocated all the necessary objects. 2028 // We have now successfully allocated all the necessary objects.
1951 // Changes can now be made with the guarantee that all of them take effect. 2029 // Changes can now be made with the guarantee that all of them take effect.
1952 set_map(new_map); 2030 set_map(new_map);
1953 map()->set_instance_descriptors(Heap::empty_descriptor_array()); 2031 map()->set_instance_descriptors(Heap::empty_descriptor_array());
1954 2032
1955 set_properties(dictionary); 2033 set_properties(dictionary);
1956 2034
(...skipping 5120 matching lines...) Expand 10 before | Expand all | Expand 10 after
7077 // No break point. 7155 // No break point.
7078 if (break_point_objects()->IsUndefined()) return 0; 7156 if (break_point_objects()->IsUndefined()) return 0;
7079 // Single beak point. 7157 // Single beak point.
7080 if (!break_point_objects()->IsFixedArray()) return 1; 7158 if (!break_point_objects()->IsFixedArray()) return 1;
7081 // Multiple break points. 7159 // Multiple break points.
7082 return FixedArray::cast(break_point_objects())->length(); 7160 return FixedArray::cast(break_point_objects())->length();
7083 } 7161 }
7084 7162
7085 7163
7086 } } // namespace v8::internal 7164 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698