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

Side by Side Diff: src/heap.cc

Issue 8568013: Introduce read buffer for external strings when using charAt (ia32). (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: . Created 9 years, 1 month 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/heap.h ('k') | src/ia32/code-stubs-ia32.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 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 2989 matching lines...) Expand 10 before | Expand all | Expand 10 after
3000 3000
3001 3001
3002 MaybeObject* Heap::AllocateExternalStringFromAscii( 3002 MaybeObject* Heap::AllocateExternalStringFromAscii(
3003 const ExternalAsciiString::Resource* resource) { 3003 const ExternalAsciiString::Resource* resource) {
3004 size_t length = resource->length(); 3004 size_t length = resource->length();
3005 if (length > static_cast<size_t>(String::kMaxLength)) { 3005 if (length > static_cast<size_t>(String::kMaxLength)) {
3006 isolate()->context()->mark_out_of_memory(); 3006 isolate()->context()->mark_out_of_memory();
3007 return Failure::OutOfMemoryException(); 3007 return Failure::OutOfMemoryException();
3008 } 3008 }
3009 3009
3010 Map* map = external_ascii_string_map(); 3010 Map* map;
3011 if (length < static_cast<size_t>(ExternalString::kMinBufferedStringLength)) {
3012 map = external_ascii_string_map();
3013 } else {
3014 map = external_buffered_ascii_string_map();
3015 }
3011 Object* result; 3016 Object* result;
3012 { MaybeObject* maybe_result = Allocate(map, NEW_SPACE); 3017 { MaybeObject* maybe_result = Allocate(map, NEW_SPACE);
3013 if (!maybe_result->ToObject(&result)) return maybe_result; 3018 if (!maybe_result->ToObject(&result)) return maybe_result;
3014 } 3019 }
3015 3020
3016 ExternalAsciiString* external_string = ExternalAsciiString::cast(result); 3021 ExternalAsciiString* external_string = ExternalAsciiString::cast(result);
3017 external_string->set_length(static_cast<int>(length)); 3022 external_string->set_length(static_cast<int>(length));
3018 external_string->set_hash_field(String::kEmptyHashField); 3023 external_string->set_hash_field(String::kEmptyHashField);
3019 external_string->set_resource(resource); 3024 external_string->set_resource(resource);
3020 3025 if (external_string->IsBuffered()) {
3026 external_string->set_buffer_index(ExternalString::kInvalidBufferIndex);
3027 }
3021 return result; 3028 return result;
3022 } 3029 }
3023 3030
3024 3031
3025 MaybeObject* Heap::AllocateExternalStringFromTwoByte( 3032 MaybeObject* Heap::AllocateExternalStringFromTwoByte(
3026 const ExternalTwoByteString::Resource* resource) { 3033 const ExternalTwoByteString::Resource* resource) {
3027 size_t length = resource->length(); 3034 size_t length = resource->length();
3028 if (length > static_cast<size_t>(String::kMaxLength)) { 3035 if (length > static_cast<size_t>(String::kMaxLength)) {
3029 isolate()->context()->mark_out_of_memory(); 3036 isolate()->context()->mark_out_of_memory();
3030 return Failure::OutOfMemoryException(); 3037 return Failure::OutOfMemoryException();
3031 } 3038 }
3032 3039
3033 // For small strings we check whether the resource contains only 3040 // For small strings we check whether the resource contains only
3034 // ASCII characters. If yes, we use a different string map. 3041 // ASCII characters. If yes, we use a different string map.
3035 static const size_t kAsciiCheckLengthLimit = 32; 3042 static const size_t kAsciiCheckLengthLimit = 32;
3036 bool is_ascii = length <= kAsciiCheckLengthLimit && 3043 bool is_ascii = length <= kAsciiCheckLengthLimit &&
3037 String::IsAscii(resource->data(), static_cast<int>(length)); 3044 String::IsAscii(resource->data(), static_cast<int>(length));
3038 Map* map = is_ascii ? 3045 Map* map;
3039 external_string_with_ascii_data_map() : external_string_map(); 3046 if (length < static_cast<size_t>(ExternalString::kMinBufferedStringLength)) {
3047 map = is_ascii ? external_string_with_ascii_data_map()
3048 : external_string_map();
3049 } else {
3050 map = is_ascii ? external_buffered_string_with_ascii_data_map()
3051 : external_buffered_string_map();
3052 }
3040 Object* result; 3053 Object* result;
3041 { MaybeObject* maybe_result = Allocate(map, NEW_SPACE); 3054 { MaybeObject* maybe_result = Allocate(map, NEW_SPACE);
3042 if (!maybe_result->ToObject(&result)) return maybe_result; 3055 if (!maybe_result->ToObject(&result)) return maybe_result;
3043 } 3056 }
3044 3057
3045 ExternalTwoByteString* external_string = ExternalTwoByteString::cast(result); 3058 ExternalTwoByteString* external_string = ExternalTwoByteString::cast(result);
3046 external_string->set_length(static_cast<int>(length)); 3059 external_string->set_length(static_cast<int>(length));
3047 external_string->set_hash_field(String::kEmptyHashField); 3060 external_string->set_hash_field(String::kEmptyHashField);
3048 external_string->set_resource(resource); 3061 external_string->set_resource(resource);
3049 3062 if (external_string->IsBuffered()) {
3063 external_string->set_buffer_index(ExternalString::kInvalidBufferIndex);
3064 }
3050 return result; 3065 return result;
3051 } 3066 }
3052 3067
3053 3068
3054 MaybeObject* Heap::LookupSingleCharacterStringFromCode(uint16_t code) { 3069 MaybeObject* Heap::LookupSingleCharacterStringFromCode(uint16_t code) {
3055 if (code <= String::kMaxAsciiCharCode) { 3070 if (code <= String::kMaxAsciiCharCode) {
3056 Object* value = single_character_string_cache()->get(code); 3071 Object* value = single_character_string_cache()->get(code);
3057 if (value != undefined_value()) return value; 3072 if (value != undefined_value()) return value;
3058 3073
3059 char buffer[1]; 3074 char buffer[1];
(...skipping 3398 matching lines...) Expand 10 before | Expand all | Expand 10 after
6458 isolate_->heap()->store_buffer()->Compact(); 6473 isolate_->heap()->store_buffer()->Compact();
6459 isolate_->heap()->store_buffer()->Filter(MemoryChunk::ABOUT_TO_BE_FREED); 6474 isolate_->heap()->store_buffer()->Filter(MemoryChunk::ABOUT_TO_BE_FREED);
6460 for (chunk = chunks_queued_for_free_; chunk != NULL; chunk = next) { 6475 for (chunk = chunks_queued_for_free_; chunk != NULL; chunk = next) {
6461 next = chunk->next_chunk(); 6476 next = chunk->next_chunk();
6462 isolate_->memory_allocator()->Free(chunk); 6477 isolate_->memory_allocator()->Free(chunk);
6463 } 6478 }
6464 chunks_queued_for_free_ = NULL; 6479 chunks_queued_for_free_ = NULL;
6465 } 6480 }
6466 6481
6467 } } // namespace v8::internal 6482 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/heap.h ('k') | src/ia32/code-stubs-ia32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698