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

Side by Side Diff: src/heap.cc

Issue 10407090: Ensure integrity of ASCII strings. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: addressed comments. Created 8 years, 7 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/d8.cc ('k') | src/heap-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 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 3308 matching lines...) Expand 10 before | Expand all | Expand 10 after
3319 3319
3320 3320
3321 MaybeObject* Heap::AllocateExternalStringFromAscii( 3321 MaybeObject* Heap::AllocateExternalStringFromAscii(
3322 const ExternalAsciiString::Resource* resource) { 3322 const ExternalAsciiString::Resource* resource) {
3323 size_t length = resource->length(); 3323 size_t length = resource->length();
3324 if (length > static_cast<size_t>(String::kMaxLength)) { 3324 if (length > static_cast<size_t>(String::kMaxLength)) {
3325 isolate()->context()->mark_out_of_memory(); 3325 isolate()->context()->mark_out_of_memory();
3326 return Failure::OutOfMemoryException(); 3326 return Failure::OutOfMemoryException();
3327 } 3327 }
3328 3328
3329 ASSERT(String::IsAscii(resource->data(), length));
3330
3329 Map* map = external_ascii_string_map(); 3331 Map* map = external_ascii_string_map();
3330 Object* result; 3332 Object* result;
3331 { MaybeObject* maybe_result = Allocate(map, NEW_SPACE); 3333 { MaybeObject* maybe_result = Allocate(map, NEW_SPACE);
3332 if (!maybe_result->ToObject(&result)) return maybe_result; 3334 if (!maybe_result->ToObject(&result)) return maybe_result;
3333 } 3335 }
3334 3336
3335 ExternalAsciiString* external_string = ExternalAsciiString::cast(result); 3337 ExternalAsciiString* external_string = ExternalAsciiString::cast(result);
3336 external_string->set_length(static_cast<int>(length)); 3338 external_string->set_length(static_cast<int>(length));
3337 external_string->set_hash_field(String::kEmptyHashField); 3339 external_string->set_hash_field(String::kEmptyHashField);
3338 external_string->set_resource(resource); 3340 external_string->set_resource(resource);
(...skipping 1144 matching lines...) Expand 10 before | Expand all | Expand 10 after
4483 Object* result; 4485 Object* result;
4484 { MaybeObject* maybe_result = AllocateRaw(size, space, retry_space); 4486 { MaybeObject* maybe_result = AllocateRaw(size, space, retry_space);
4485 if (!maybe_result->ToObject(&result)) return maybe_result; 4487 if (!maybe_result->ToObject(&result)) return maybe_result;
4486 } 4488 }
4487 4489
4488 // Partially initialize the object. 4490 // Partially initialize the object.
4489 HeapObject::cast(result)->set_map_no_write_barrier(ascii_string_map()); 4491 HeapObject::cast(result)->set_map_no_write_barrier(ascii_string_map());
4490 String::cast(result)->set_length(length); 4492 String::cast(result)->set_length(length);
4491 String::cast(result)->set_hash_field(String::kEmptyHashField); 4493 String::cast(result)->set_hash_field(String::kEmptyHashField);
4492 ASSERT_EQ(size, HeapObject::cast(result)->Size()); 4494 ASSERT_EQ(size, HeapObject::cast(result)->Size());
4495
4496 #ifdef DEBUG
4497 if (FLAG_verify_heap) {
4498 // Initialize string's content to ensure ASCII-ness (character range 0-127)
4499 // as required when verifying the heap.
4500 char* dest = SeqAsciiString::cast(result)->GetChars();
4501 memset(dest, 0x0F, length * kCharSize);
4502 }
4503 #endif // DEBUG
4504
4493 return result; 4505 return result;
4494 } 4506 }
4495 4507
4496 4508
4497 MaybeObject* Heap::AllocateRawTwoByteString(int length, 4509 MaybeObject* Heap::AllocateRawTwoByteString(int length,
4498 PretenureFlag pretenure) { 4510 PretenureFlag pretenure) {
4499 if (length < 0 || length > SeqTwoByteString::kMaxLength) { 4511 if (length < 0 || length > SeqTwoByteString::kMaxLength) {
4500 return Failure::OutOfMemoryException(); 4512 return Failure::OutOfMemoryException();
4501 } 4513 }
4502 int size = SeqTwoByteString::SizeFor(length); 4514 int size = SeqTwoByteString::SizeFor(length);
(...skipping 2629 matching lines...) Expand 10 before | Expand all | Expand 10 after
7132 } else { 7144 } else {
7133 p ^= 0x1d1ed & (Page::kPageSize - 1); // I died. 7145 p ^= 0x1d1ed & (Page::kPageSize - 1); // I died.
7134 } 7146 }
7135 remembered_unmapped_pages_[remembered_unmapped_pages_index_] = 7147 remembered_unmapped_pages_[remembered_unmapped_pages_index_] =
7136 reinterpret_cast<Address>(p); 7148 reinterpret_cast<Address>(p);
7137 remembered_unmapped_pages_index_++; 7149 remembered_unmapped_pages_index_++;
7138 remembered_unmapped_pages_index_ %= kRememberedUnmappedPages; 7150 remembered_unmapped_pages_index_ %= kRememberedUnmappedPages;
7139 } 7151 }
7140 7152
7141 } } // namespace v8::internal 7153 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/d8.cc ('k') | src/heap-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698