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

Side by Side Diff: src/heap.cc

Issue 1563005: Introduce fast native caches and use it in String.search. (Closed)
Patch Set: Last round :) Created 10 years, 8 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.h ('k') | src/ia32/codegen-ia32.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 2009 the V8 project authors. All rights reserved. 1 // Copyright 2009 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 1652 matching lines...) Expand 10 before | Expand all | Expand 10 after
1663 // Allocate the non_monomorphic_cache used in stub-cache.cc. The initial size 1663 // Allocate the non_monomorphic_cache used in stub-cache.cc. The initial size
1664 // is set to avoid expanding the dictionary during bootstrapping. 1664 // is set to avoid expanding the dictionary during bootstrapping.
1665 obj = NumberDictionary::Allocate(64); 1665 obj = NumberDictionary::Allocate(64);
1666 if (obj->IsFailure()) return false; 1666 if (obj->IsFailure()) return false;
1667 set_non_monomorphic_cache(NumberDictionary::cast(obj)); 1667 set_non_monomorphic_cache(NumberDictionary::cast(obj));
1668 1668
1669 CreateFixedStubs(); 1669 CreateFixedStubs();
1670 1670
1671 if (InitializeNumberStringCache()->IsFailure()) return false; 1671 if (InitializeNumberStringCache()->IsFailure()) return false;
1672 1672
1673 // Allocate cache for single character strings. 1673 // Allocate cache for single character ASCII strings.
1674 obj = AllocateFixedArray(String::kMaxAsciiCharCode+1, TENURED); 1674 obj = AllocateFixedArray(String::kMaxAsciiCharCode + 1, TENURED);
1675 if (obj->IsFailure()) return false; 1675 if (obj->IsFailure()) return false;
1676 set_single_character_string_cache(FixedArray::cast(obj)); 1676 set_single_character_string_cache(FixedArray::cast(obj));
1677 1677
1678 // Allocate cache for external strings pointing to native source code. 1678 // Allocate cache for external strings pointing to native source code.
1679 obj = AllocateFixedArray(Natives::GetBuiltinsCount()); 1679 obj = AllocateFixedArray(Natives::GetBuiltinsCount());
1680 if (obj->IsFailure()) return false; 1680 if (obj->IsFailure()) return false;
1681 set_natives_source_cache(FixedArray::cast(obj)); 1681 set_natives_source_cache(FixedArray::cast(obj));
1682 1682
1683 // Handling of script id generation is in Factory::NewScript. 1683 // Handling of script id generation is in Factory::NewScript.
1684 set_last_script_id(undefined_value()); 1684 set_last_script_id(undefined_value());
(...skipping 1321 matching lines...) Expand 10 before | Expand all | Expand 10 after
3006 FixedArray* array = FixedArray::cast(result); 3006 FixedArray* array = FixedArray::cast(result);
3007 array->set_length(length); 3007 array->set_length(length);
3008 // Initialize body. 3008 // Initialize body.
3009 ASSERT(!Heap::InNewSpace(undefined_value())); 3009 ASSERT(!Heap::InNewSpace(undefined_value()));
3010 MemsetPointer(array->data_start(), undefined_value(), length); 3010 MemsetPointer(array->data_start(), undefined_value(), length);
3011 } 3011 }
3012 return result; 3012 return result;
3013 } 3013 }
3014 3014
3015 3015
3016 Object* Heap::AllocateFixedArray(int length, PretenureFlag pretenure) { 3016 Object* Heap::AllocateRawFixedArray(int length, PretenureFlag pretenure) {
3017 ASSERT(length >= 0);
3018 ASSERT(empty_fixed_array()->IsFixedArray());
3019 if (length < 0 || length > FixedArray::kMaxLength) { 3017 if (length < 0 || length > FixedArray::kMaxLength) {
3020 return Failure::OutOfMemoryException(); 3018 return Failure::OutOfMemoryException();
3021 } 3019 }
3022 if (length == 0) return empty_fixed_array();
3023 3020
3024 AllocationSpace space = 3021 AllocationSpace space =
3025 (pretenure == TENURED) ? OLD_POINTER_SPACE : NEW_SPACE; 3022 (pretenure == TENURED) ? OLD_POINTER_SPACE : NEW_SPACE;
3026 int size = FixedArray::SizeFor(length); 3023 int size = FixedArray::SizeFor(length);
3027 if (space == NEW_SPACE && size > kMaxObjectSizeInNewSpace) { 3024 if (space == NEW_SPACE && size > kMaxObjectSizeInNewSpace) {
3028 // Too big for new space. 3025 // Too big for new space.
3029 space = LO_SPACE; 3026 space = LO_SPACE;
3030 } else if (space == OLD_POINTER_SPACE && 3027 } else if (space == OLD_POINTER_SPACE &&
3031 size > MaxObjectSizeInPagedSpace()) { 3028 size > MaxObjectSizeInPagedSpace()) {
3032 // Too big for old pointer space. 3029 // Too big for old pointer space.
(...skipping 13 matching lines...) Expand all
3046 } else { 3043 } else {
3047 result = lo_space_->AllocateRawFixedArray(size); 3044 result = lo_space_->AllocateRawFixedArray(size);
3048 } 3045 }
3049 } 3046 }
3050 } else if (space == OLD_POINTER_SPACE) { 3047 } else if (space == OLD_POINTER_SPACE) {
3051 result = old_pointer_space_->AllocateRaw(size); 3048 result = old_pointer_space_->AllocateRaw(size);
3052 } else { 3049 } else {
3053 ASSERT(space == LO_SPACE); 3050 ASSERT(space == LO_SPACE);
3054 result = lo_space_->AllocateRawFixedArray(size); 3051 result = lo_space_->AllocateRawFixedArray(size);
3055 } 3052 }
3053 return result;
3054 }
3055
3056
3057 static Object* AllocateFixedArrayWithFiller(int length,
3058 PretenureFlag pretenure,
3059 Object* filler) {
3060 ASSERT(length >= 0);
3061 ASSERT(Heap::empty_fixed_array()->IsFixedArray());
3062 if (length == 0) return Heap::empty_fixed_array();
3063
3064 ASSERT(!Heap::InNewSpace(filler));
3065 Object* result = Heap::AllocateRawFixedArray(length, pretenure);
3056 if (result->IsFailure()) return result; 3066 if (result->IsFailure()) return result;
3057 3067
3058 // Initialize the object. 3068 HeapObject::cast(result)->set_map(Heap::fixed_array_map());
3059 reinterpret_cast<Array*>(result)->set_map(fixed_array_map());
3060 FixedArray* array = FixedArray::cast(result); 3069 FixedArray* array = FixedArray::cast(result);
3061 array->set_length(length); 3070 array->set_length(length);
3062 ASSERT(!Heap::InNewSpace(undefined_value())); 3071 MemsetPointer(array->data_start(), filler, length);
3063 MemsetPointer(array->data_start(), undefined_value(), length);
3064 return array; 3072 return array;
3065 } 3073 }
3066 3074
3067 3075
3076 Object* Heap::AllocateFixedArray(int length, PretenureFlag pretenure) {
3077 return AllocateFixedArrayWithFiller(length, pretenure, undefined_value());
3078 }
3079
3080
3081 Object* Heap::AllocateFixedArrayWithHoles(int length, PretenureFlag pretenure) {
3082 return AllocateFixedArrayWithFiller(length, pretenure, the_hole_value());
3083 }
3084
3085
3068 Object* Heap::AllocateUninitializedFixedArray(int length) { 3086 Object* Heap::AllocateUninitializedFixedArray(int length) {
3069 if (length == 0) return empty_fixed_array(); 3087 if (length == 0) return empty_fixed_array();
3070 3088
3071 Object* obj = AllocateRawFixedArray(length); 3089 Object* obj = AllocateRawFixedArray(length);
3072 if (obj->IsFailure()) return obj; 3090 if (obj->IsFailure()) return obj;
3073 3091
3074 reinterpret_cast<FixedArray*>(obj)->set_map(fixed_array_map()); 3092 reinterpret_cast<FixedArray*>(obj)->set_map(fixed_array_map());
3075 FixedArray::cast(obj)->set_length(length); 3093 FixedArray::cast(obj)->set_length(length);
3076 return obj; 3094 return obj;
3077 } 3095 }
3078 3096
3079 3097
3080 Object* Heap::AllocateFixedArrayWithHoles(int length) {
3081 if (length == 0) return empty_fixed_array();
3082 Object* result = AllocateRawFixedArray(length);
3083 if (!result->IsFailure()) {
3084 // Initialize header.
3085 reinterpret_cast<Array*>(result)->set_map(fixed_array_map());
3086 FixedArray* array = FixedArray::cast(result);
3087 array->set_length(length);
3088 // Initialize body.
3089 ASSERT(!Heap::InNewSpace(the_hole_value()));
3090 MemsetPointer(array->data_start(), the_hole_value(), length);
3091 }
3092 return result;
3093 }
3094
3095
3096 Object* Heap::AllocateHashTable(int length, PretenureFlag pretenure) { 3098 Object* Heap::AllocateHashTable(int length, PretenureFlag pretenure) {
3097 Object* result = Heap::AllocateFixedArray(length, pretenure); 3099 Object* result = Heap::AllocateFixedArray(length, pretenure);
3098 if (result->IsFailure()) return result; 3100 if (result->IsFailure()) return result;
3099 reinterpret_cast<Array*>(result)->set_map(hash_table_map()); 3101 reinterpret_cast<Array*>(result)->set_map(hash_table_map());
3100 ASSERT(result->IsHashTable()); 3102 ASSERT(result->IsHashTable());
3101 return result; 3103 return result;
3102 } 3104 }
3103 3105
3104 3106
3105 Object* Heap::AllocateGlobalContext() { 3107 Object* Heap::AllocateGlobalContext() {
(...skipping 1286 matching lines...) Expand 10 before | Expand all | Expand 10 after
4392 void ExternalStringTable::TearDown() { 4394 void ExternalStringTable::TearDown() {
4393 new_space_strings_.Free(); 4395 new_space_strings_.Free();
4394 old_space_strings_.Free(); 4396 old_space_strings_.Free();
4395 } 4397 }
4396 4398
4397 4399
4398 List<Object*> ExternalStringTable::new_space_strings_; 4400 List<Object*> ExternalStringTable::new_space_strings_;
4399 List<Object*> ExternalStringTable::old_space_strings_; 4401 List<Object*> ExternalStringTable::old_space_strings_;
4400 4402
4401 } } // namespace v8::internal 4403 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/heap.h ('k') | src/ia32/codegen-ia32.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698