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

Side by Side Diff: src/heap/heap-inl.h

Issue 2549773002: Internalize strings in-place (Closed)
Patch Set: rebased Created 3 years, 11 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
« no previous file with comments | « src/heap/heap.cc ('k') | src/heap/mark-compact.cc » ('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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_HEAP_HEAP_INL_H_ 5 #ifndef V8_HEAP_HEAP_INL_H_
6 #define V8_HEAP_HEAP_INL_H_ 6 #define V8_HEAP_HEAP_INL_H_
7 7
8 #include <cmath> 8 #include <cmath>
9 9
10 #include "src/base/platform/platform.h" 10 #include "src/base/platform/platform.h"
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 if (IsOneByte(t, chars)) { 218 if (IsOneByte(t, chars)) {
219 return AllocateInternalizedStringImpl<true>(t, chars, hash_field); 219 return AllocateInternalizedStringImpl<true>(t, chars, hash_field);
220 } 220 }
221 return AllocateInternalizedStringImpl<false>(t, chars, hash_field); 221 return AllocateInternalizedStringImpl<false>(t, chars, hash_field);
222 } 222 }
223 223
224 224
225 AllocationResult Heap::AllocateOneByteInternalizedString( 225 AllocationResult Heap::AllocateOneByteInternalizedString(
226 Vector<const uint8_t> str, uint32_t hash_field) { 226 Vector<const uint8_t> str, uint32_t hash_field) {
227 CHECK_GE(String::kMaxLength, str.length()); 227 CHECK_GE(String::kMaxLength, str.length());
228 // The canonical empty_string is the only zero-length string we allow.
229 DCHECK_IMPLIES(str.length() == 0, roots_[kempty_stringRootIndex] == nullptr);
228 // Compute map and object size. 230 // Compute map and object size.
229 Map* map = one_byte_internalized_string_map(); 231 Map* map = one_byte_internalized_string_map();
230 int size = SeqOneByteString::SizeFor(str.length()); 232 int size = SeqOneByteString::SizeFor(str.length());
231 233
232 // Allocate string. 234 // Allocate string.
233 HeapObject* result = nullptr; 235 HeapObject* result = nullptr;
234 { 236 {
235 AllocationResult allocation = AllocateRaw(size, OLD_SPACE); 237 AllocationResult allocation = AllocateRaw(size, OLD_SPACE);
236 if (!allocation.To(&result)) return allocation; 238 if (!allocation.To(&result)) return allocation;
237 } 239 }
(...skipping 11 matching lines...) Expand all
249 MemCopy(answer->address() + SeqOneByteString::kHeaderSize, str.start(), 251 MemCopy(answer->address() + SeqOneByteString::kHeaderSize, str.start(),
250 str.length()); 252 str.length());
251 253
252 return answer; 254 return answer;
253 } 255 }
254 256
255 257
256 AllocationResult Heap::AllocateTwoByteInternalizedString(Vector<const uc16> str, 258 AllocationResult Heap::AllocateTwoByteInternalizedString(Vector<const uc16> str,
257 uint32_t hash_field) { 259 uint32_t hash_field) {
258 CHECK_GE(String::kMaxLength, str.length()); 260 CHECK_GE(String::kMaxLength, str.length());
261 DCHECK_NE(0, str.length()); // Use Heap::empty_string() instead.
259 // Compute map and object size. 262 // Compute map and object size.
260 Map* map = internalized_string_map(); 263 Map* map = internalized_string_map();
261 int size = SeqTwoByteString::SizeFor(str.length()); 264 int size = SeqTwoByteString::SizeFor(str.length());
262 265
263 // Allocate string. 266 // Allocate string.
264 HeapObject* result = nullptr; 267 HeapObject* result = nullptr;
265 { 268 {
266 AllocationResult allocation = AllocateRaw(size, OLD_SPACE); 269 AllocationResult allocation = AllocateRaw(size, OLD_SPACE);
267 if (!allocation.To(&result)) return allocation; 270 if (!allocation.To(&result)) return allocation;
268 } 271 }
(...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after
859 862
860 void VerifySmisVisitor::VisitPointers(Object** start, Object** end) { 863 void VerifySmisVisitor::VisitPointers(Object** start, Object** end) {
861 for (Object** current = start; current < end; current++) { 864 for (Object** current = start; current < end; current++) {
862 CHECK((*current)->IsSmi()); 865 CHECK((*current)->IsSmi());
863 } 866 }
864 } 867 }
865 } // namespace internal 868 } // namespace internal
866 } // namespace v8 869 } // namespace v8
867 870
868 #endif // V8_HEAP_HEAP_INL_H_ 871 #endif // V8_HEAP_HEAP_INL_H_
OLDNEW
« no previous file with comments | « src/heap/heap.cc ('k') | src/heap/mark-compact.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698