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

Side by Side Diff: src/heap.cc

Issue 11818025: Continues Latin-1 support. All tests pass with ENABLE_LATIN_1 flag. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: ARM fix Created 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 3298 matching lines...) Expand 10 before | Expand all | Expand 10 after
3309 return symbol; 3309 return symbol;
3310 // Now we know the length is 2, we might as well make use of that fact 3310 // Now we know the length is 2, we might as well make use of that fact
3311 // when building the new string. 3311 // when building the new string.
3312 } else if (static_cast<unsigned>(c1 | c2) <= String::kMaxOneByteCharCodeU) { 3312 } else if (static_cast<unsigned>(c1 | c2) <= String::kMaxOneByteCharCodeU) {
3313 // We can do this. 3313 // We can do this.
3314 ASSERT(IsPowerOf2(String::kMaxOneByteCharCodeU + 1)); // because of this. 3314 ASSERT(IsPowerOf2(String::kMaxOneByteCharCodeU + 1)); // because of this.
3315 Object* result; 3315 Object* result;
3316 { MaybeObject* maybe_result = heap->AllocateRawOneByteString(2); 3316 { MaybeObject* maybe_result = heap->AllocateRawOneByteString(2);
3317 if (!maybe_result->ToObject(&result)) return maybe_result; 3317 if (!maybe_result->ToObject(&result)) return maybe_result;
3318 } 3318 }
3319 char* dest = SeqOneByteString::cast(result)->GetChars(); 3319 uint8_t* dest = SeqOneByteString::cast(result)->GetChars();
3320 dest[0] = static_cast<char>(c1); 3320 dest[0] = static_cast<uint8_t>(c1);
3321 dest[1] = static_cast<char>(c2); 3321 dest[1] = static_cast<uint8_t>(c2);
3322 return result; 3322 return result;
3323 } else { 3323 } else {
3324 Object* result; 3324 Object* result;
3325 { MaybeObject* maybe_result = heap->AllocateRawTwoByteString(2); 3325 { MaybeObject* maybe_result = heap->AllocateRawTwoByteString(2);
3326 if (!maybe_result->ToObject(&result)) return maybe_result; 3326 if (!maybe_result->ToObject(&result)) return maybe_result;
3327 } 3327 }
3328 uc16* dest = SeqTwoByteString::cast(result)->GetChars(); 3328 uc16* dest = SeqTwoByteString::cast(result)->GetChars();
3329 dest[0] = c1; 3329 dest[0] = c1;
3330 dest[1] = c2; 3330 dest[1] = c2;
3331 return result; 3331 return result;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
3382 // Note that neither of the two inputs can be a slice because: 3382 // Note that neither of the two inputs can be a slice because:
3383 STATIC_ASSERT(ConsString::kMinLength <= SlicedString::kMinLength); 3383 STATIC_ASSERT(ConsString::kMinLength <= SlicedString::kMinLength);
3384 ASSERT(first->IsFlat()); 3384 ASSERT(first->IsFlat());
3385 ASSERT(second->IsFlat()); 3385 ASSERT(second->IsFlat());
3386 if (is_one_byte) { 3386 if (is_one_byte) {
3387 Object* result; 3387 Object* result;
3388 { MaybeObject* maybe_result = AllocateRawOneByteString(length); 3388 { MaybeObject* maybe_result = AllocateRawOneByteString(length);
3389 if (!maybe_result->ToObject(&result)) return maybe_result; 3389 if (!maybe_result->ToObject(&result)) return maybe_result;
3390 } 3390 }
3391 // Copy the characters into the new object. 3391 // Copy the characters into the new object.
3392 char* dest = SeqOneByteString::cast(result)->GetChars(); 3392 uint8_t* dest = SeqOneByteString::cast(result)->GetChars();
3393 // Copy first part. 3393 // Copy first part.
3394 const char* src; 3394 const uint8_t* src;
3395 if (first->IsExternalString()) { 3395 if (first->IsExternalString()) {
3396 src = ExternalAsciiString::cast(first)->GetChars(); 3396 src = ExternalAsciiString::cast(first)->GetChars();
3397 } else { 3397 } else {
3398 src = SeqOneByteString::cast(first)->GetChars(); 3398 src = SeqOneByteString::cast(first)->GetChars();
3399 } 3399 }
3400 for (int i = 0; i < first_length; i++) *dest++ = src[i]; 3400 for (int i = 0; i < first_length; i++) *dest++ = src[i];
3401 // Copy second part. 3401 // Copy second part.
3402 if (second->IsExternalString()) { 3402 if (second->IsExternalString()) {
3403 src = ExternalAsciiString::cast(second)->GetChars(); 3403 src = ExternalAsciiString::cast(second)->GetChars();
3404 } else { 3404 } else {
3405 src = SeqOneByteString::cast(second)->GetChars(); 3405 src = SeqOneByteString::cast(second)->GetChars();
3406 } 3406 }
3407 for (int i = 0; i < second_length; i++) *dest++ = src[i]; 3407 for (int i = 0; i < second_length; i++) *dest++ = src[i];
3408 return result; 3408 return result;
3409 } else { 3409 } else {
3410 if (is_ascii_data_in_two_byte_string) { 3410 if (is_ascii_data_in_two_byte_string) {
3411 Object* result; 3411 Object* result;
3412 { MaybeObject* maybe_result = AllocateRawOneByteString(length); 3412 { MaybeObject* maybe_result = AllocateRawOneByteString(length);
3413 if (!maybe_result->ToObject(&result)) return maybe_result; 3413 if (!maybe_result->ToObject(&result)) return maybe_result;
3414 } 3414 }
3415 // Copy the characters into the new object. 3415 // Copy the characters into the new object.
3416 char* dest = SeqOneByteString::cast(result)->GetChars(); 3416 uint8_t* dest = SeqOneByteString::cast(result)->GetChars();
3417 String::WriteToFlat(first, dest, 0, first_length); 3417 String::WriteToFlat(first, dest, 0, first_length);
3418 String::WriteToFlat(second, dest + first_length, 0, second_length); 3418 String::WriteToFlat(second, dest + first_length, 0, second_length);
3419 isolate_->counters()->string_add_runtime_ext_to_ascii()->Increment(); 3419 isolate_->counters()->string_add_runtime_ext_to_ascii()->Increment();
3420 return result; 3420 return result;
3421 } 3421 }
3422 3422
3423 Object* result; 3423 Object* result;
3424 { MaybeObject* maybe_result = AllocateRawTwoByteString(length); 3424 { MaybeObject* maybe_result = AllocateRawTwoByteString(length);
3425 if (!maybe_result->ToObject(&result)) return maybe_result; 3425 if (!maybe_result->ToObject(&result)) return maybe_result;
3426 } 3426 }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
3483 bool is_one_byte = buffer->IsOneByteRepresentation(); 3483 bool is_one_byte = buffer->IsOneByteRepresentation();
3484 { MaybeObject* maybe_result = is_one_byte 3484 { MaybeObject* maybe_result = is_one_byte
3485 ? AllocateRawOneByteString(length, pretenure) 3485 ? AllocateRawOneByteString(length, pretenure)
3486 : AllocateRawTwoByteString(length, pretenure); 3486 : AllocateRawTwoByteString(length, pretenure);
3487 if (!maybe_result->ToObject(&result)) return maybe_result; 3487 if (!maybe_result->ToObject(&result)) return maybe_result;
3488 } 3488 }
3489 String* string_result = String::cast(result); 3489 String* string_result = String::cast(result);
3490 // Copy the characters into the new object. 3490 // Copy the characters into the new object.
3491 if (is_one_byte) { 3491 if (is_one_byte) {
3492 ASSERT(string_result->IsOneByteRepresentation()); 3492 ASSERT(string_result->IsOneByteRepresentation());
3493 char* dest = SeqOneByteString::cast(string_result)->GetChars(); 3493 uint8_t* dest = SeqOneByteString::cast(string_result)->GetChars();
3494 String::WriteToFlat(buffer, dest, start, end); 3494 String::WriteToFlat(buffer, dest, start, end);
3495 } else { 3495 } else {
3496 ASSERT(string_result->IsTwoByteRepresentation()); 3496 ASSERT(string_result->IsTwoByteRepresentation());
3497 uc16* dest = SeqTwoByteString::cast(string_result)->GetChars(); 3497 uc16* dest = SeqTwoByteString::cast(string_result)->GetChars();
3498 String::WriteToFlat(buffer, dest, start, end); 3498 String::WriteToFlat(buffer, dest, start, end);
3499 } 3499 }
3500 return result; 3500 return result;
3501 } 3501 }
3502 3502
3503 ASSERT(buffer->IsFlat()); 3503 ASSERT(buffer->IsFlat());
(...skipping 1021 matching lines...) Expand 10 before | Expand all | Expand 10 after
4525 if (length == 1) { 4525 if (length == 1) {
4526 return Heap::LookupSingleCharacterStringFromCode(string[0]); 4526 return Heap::LookupSingleCharacterStringFromCode(string[0]);
4527 } 4527 }
4528 Object* result; 4528 Object* result;
4529 { MaybeObject* maybe_result = 4529 { MaybeObject* maybe_result =
4530 AllocateRawOneByteString(string.length(), pretenure); 4530 AllocateRawOneByteString(string.length(), pretenure);
4531 if (!maybe_result->ToObject(&result)) return maybe_result; 4531 if (!maybe_result->ToObject(&result)) return maybe_result;
4532 } 4532 }
4533 4533
4534 // Copy the characters into the new object. 4534 // Copy the characters into the new object.
4535 CopyChars(SeqOneByteString::cast(result)->GetCharsU(), 4535 CopyChars(SeqOneByteString::cast(result)->GetChars(),
4536 string.start(), 4536 string.start(),
4537 length); 4537 length);
4538 return result; 4538 return result;
4539 } 4539 }
4540 4540
4541 4541
4542 MaybeObject* Heap::AllocateStringFromUtf8Slow(Vector<const char> string, 4542 MaybeObject* Heap::AllocateStringFromUtf8Slow(Vector<const char> string,
4543 int non_ascii_start, 4543 int non_ascii_start,
4544 PretenureFlag pretenure) { 4544 PretenureFlag pretenure) {
4545 // Continue counting the number of characters in the UTF-8 string, starting 4545 // Continue counting the number of characters in the UTF-8 string, starting
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
4624 static void WriteTwoByteData(T t, uint16_t* chars, int len); 4624 static void WriteTwoByteData(T t, uint16_t* chars, int len);
4625 private: 4625 private:
4626 DISALLOW_COPY_AND_ASSIGN(AllocateInternalSymbolHelper); 4626 DISALLOW_COPY_AND_ASSIGN(AllocateInternalSymbolHelper);
4627 }; 4627 };
4628 4628
4629 4629
4630 template<> 4630 template<>
4631 class AllocateInternalSymbolHelper< Vector<const char> > { 4631 class AllocateInternalSymbolHelper< Vector<const char> > {
4632 public: 4632 public:
4633 static inline void WriteOneByteData(Vector<const char> vector, 4633 static inline void WriteOneByteData(Vector<const char> vector,
4634 char* chars, 4634 uint8_t* chars,
4635 int len) { 4635 int len) {
4636 // Only works for ascii. 4636 // Only works for ascii.
4637 ASSERT(vector.length() == len); 4637 ASSERT(vector.length() == len);
4638 memcpy(chars, vector.start(), len); 4638 memcpy(chars, vector.start(), len);
4639 } 4639 }
4640 4640
4641 static inline void WriteTwoByteData(Vector<const char> vector, 4641 static inline void WriteTwoByteData(Vector<const char> vector,
4642 uint16_t* chars, 4642 uint16_t* chars,
4643 int len) { 4643 int len) {
4644 const uint8_t* stream = reinterpret_cast<const uint8_t*>(vector.start()); 4644 const uint8_t* stream = reinterpret_cast<const uint8_t*>(vector.start());
(...skipping 21 matching lines...) Expand all
4666 } 4666 }
4667 4667
4668 private: 4668 private:
4669 DISALLOW_COPY_AND_ASSIGN(AllocateInternalSymbolHelper); 4669 DISALLOW_COPY_AND_ASSIGN(AllocateInternalSymbolHelper);
4670 }; 4670 };
4671 4671
4672 4672
4673 template<> 4673 template<>
4674 class AllocateInternalSymbolHelper<String*> { 4674 class AllocateInternalSymbolHelper<String*> {
4675 public: 4675 public:
4676 static inline void WriteOneByteData(String* s, char* chars, int len) { 4676 static inline void WriteOneByteData(String* s, uint8_t* chars, int len) {
4677 ASSERT(s->length() == len); 4677 ASSERT(s->length() == len);
4678 String::WriteToFlat(s, chars, 0, len); 4678 String::WriteToFlat(s, chars, 0, len);
4679 } 4679 }
4680 4680
4681 static inline void WriteTwoByteData(String* s, uint16_t* chars, int len) { 4681 static inline void WriteTwoByteData(String* s, uint16_t* chars, int len) {
4682 ASSERT(s->length() == len); 4682 ASSERT(s->length() == len);
4683 String::WriteToFlat(s, chars, 0, len); 4683 String::WriteToFlat(s, chars, 0, len);
4684 } 4684 }
4685 4685
4686 private: 4686 private:
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
4776 { MaybeObject* maybe_result = AllocateRaw(size, space, retry_space); 4776 { MaybeObject* maybe_result = AllocateRaw(size, space, retry_space);
4777 if (!maybe_result->ToObject(&result)) return maybe_result; 4777 if (!maybe_result->ToObject(&result)) return maybe_result;
4778 } 4778 }
4779 4779
4780 // Partially initialize the object. 4780 // Partially initialize the object.
4781 HeapObject::cast(result)->set_map_no_write_barrier(ascii_string_map()); 4781 HeapObject::cast(result)->set_map_no_write_barrier(ascii_string_map());
4782 String::cast(result)->set_length(length); 4782 String::cast(result)->set_length(length);
4783 String::cast(result)->set_hash_field(String::kEmptyHashField); 4783 String::cast(result)->set_hash_field(String::kEmptyHashField);
4784 ASSERT_EQ(size, HeapObject::cast(result)->Size()); 4784 ASSERT_EQ(size, HeapObject::cast(result)->Size());
4785 4785
4786 #ifndef ENABLE_LATIN_1
4786 #ifdef VERIFY_HEAP 4787 #ifdef VERIFY_HEAP
4787 if (FLAG_verify_heap) { 4788 if (FLAG_verify_heap) {
4788 // Initialize string's content to ensure ASCII-ness (character range 0-127) 4789 // Initialize string's content to ensure ASCII-ness (character range 0-127)
4789 // as required when verifying the heap. 4790 // as required when verifying the heap.
4790 char* dest = SeqOneByteString::cast(result)->GetChars(); 4791 uint8_t* dest = SeqOneByteString::cast(result)->GetChars();
4791 memset(dest, 0x0F, length * kCharSize); 4792 memset(dest, 0x0F, length * kCharSize);
4792 } 4793 }
4793 #endif 4794 #endif
4795 #endif
4794 4796
4795 return result; 4797 return result;
4796 } 4798 }
4797 4799
4798 4800
4799 MaybeObject* Heap::AllocateRawTwoByteString(int length, 4801 MaybeObject* Heap::AllocateRawTwoByteString(int length,
4800 PretenureFlag pretenure) { 4802 PretenureFlag pretenure) {
4801 if (length < 0 || length > SeqTwoByteString::kMaxLength) { 4803 if (length < 0 || length > SeqTwoByteString::kMaxLength) {
4802 return Failure::OutOfMemoryException(); 4804 return Failure::OutOfMemoryException();
4803 } 4805 }
(...skipping 2553 matching lines...) Expand 10 before | Expand all | Expand 10 after
7357 static_cast<int>(object_sizes_last_time_[index])); 7359 static_cast<int>(object_sizes_last_time_[index]));
7358 FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(ADJUST_LAST_TIME_OBJECT_COUNT) 7360 FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(ADJUST_LAST_TIME_OBJECT_COUNT)
7359 #undef ADJUST_LAST_TIME_OBJECT_COUNT 7361 #undef ADJUST_LAST_TIME_OBJECT_COUNT
7360 7362
7361 memcpy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); 7363 memcpy(object_counts_last_time_, object_counts_, sizeof(object_counts_));
7362 memcpy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); 7364 memcpy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_));
7363 ClearObjectStats(); 7365 ClearObjectStats();
7364 } 7366 }
7365 7367
7366 } } // namespace v8::internal 7368 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/handles.cc ('k') | src/ia32/code-stubs-ia32.cc » ('j') | src/isolate.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698