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

Side by Side Diff: src/heap.cc

Issue 7782025: Optimize the common obfuscator pattern where ["foo","bar","baz"] (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 9 years, 3 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/heap.h ('k') | src/runtime.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 824 matching lines...) Expand 10 before | Expand all | Expand 10 after
835 contexts_disposed_ = 0; 835 contexts_disposed_ = 0;
836 } 836 }
837 837
838 838
839 void Heap::MarkCompactPrologue(bool is_compacting) { 839 void Heap::MarkCompactPrologue(bool is_compacting) {
840 // At any old GC clear the keyed lookup cache to enable collection of unused 840 // At any old GC clear the keyed lookup cache to enable collection of unused
841 // maps. 841 // maps.
842 isolate_->keyed_lookup_cache()->Clear(); 842 isolate_->keyed_lookup_cache()->Clear();
843 isolate_->context_slot_cache()->Clear(); 843 isolate_->context_slot_cache()->Clear();
844 isolate_->descriptor_lookup_cache()->Clear(); 844 isolate_->descriptor_lookup_cache()->Clear();
845 StringSplitCache::Clear(string_split_cache());
845 846
846 isolate_->compilation_cache()->MarkCompactPrologue(); 847 isolate_->compilation_cache()->MarkCompactPrologue();
847 848
848 CompletelyClearInstanceofCache(); 849 CompletelyClearInstanceofCache();
849 850
850 if (is_compacting) FlushNumberStringCache(); 851 if (is_compacting) FlushNumberStringCache();
851 if (FLAG_cleanup_code_caches_at_gc) { 852 if (FLAG_cleanup_code_caches_at_gc) {
852 polymorphic_code_cache()->set_cache(undefined_value()); 853 polymorphic_code_cache()->set_cache(undefined_value());
853 } 854 }
854 855
(...skipping 1361 matching lines...) Expand 10 before | Expand all | Expand 10 after
2216 2217
2217 if (InitializeNumberStringCache()->IsFailure()) return false; 2218 if (InitializeNumberStringCache()->IsFailure()) return false;
2218 2219
2219 // Allocate cache for single character ASCII strings. 2220 // Allocate cache for single character ASCII strings.
2220 { MaybeObject* maybe_obj = 2221 { MaybeObject* maybe_obj =
2221 AllocateFixedArray(String::kMaxAsciiCharCode + 1, TENURED); 2222 AllocateFixedArray(String::kMaxAsciiCharCode + 1, TENURED);
2222 if (!maybe_obj->ToObject(&obj)) return false; 2223 if (!maybe_obj->ToObject(&obj)) return false;
2223 } 2224 }
2224 set_single_character_string_cache(FixedArray::cast(obj)); 2225 set_single_character_string_cache(FixedArray::cast(obj));
2225 2226
2227 // Allocate cache for string split.
2228 { MaybeObject* maybe_obj =
2229 AllocateFixedArray(StringSplitCache::kStringSplitCacheSize, TENURED);
2230 if (!maybe_obj->ToObject(&obj)) return false;
2231 }
2232 set_string_split_cache(FixedArray::cast(obj));
2233
2226 // Allocate cache for external strings pointing to native source code. 2234 // Allocate cache for external strings pointing to native source code.
2227 { MaybeObject* maybe_obj = AllocateFixedArray(Natives::GetBuiltinsCount()); 2235 { MaybeObject* maybe_obj = AllocateFixedArray(Natives::GetBuiltinsCount());
2228 if (!maybe_obj->ToObject(&obj)) return false; 2236 if (!maybe_obj->ToObject(&obj)) return false;
2229 } 2237 }
2230 set_natives_source_cache(FixedArray::cast(obj)); 2238 set_natives_source_cache(FixedArray::cast(obj));
2231 2239
2232 // Handling of script id generation is in FACTORY->NewScript. 2240 // Handling of script id generation is in FACTORY->NewScript.
2233 set_last_script_id(undefined_value()); 2241 set_last_script_id(undefined_value());
2234 2242
2235 // Initialize keyed lookup cache. 2243 // Initialize keyed lookup cache.
2236 isolate_->keyed_lookup_cache()->Clear(); 2244 isolate_->keyed_lookup_cache()->Clear();
2237 2245
2238 // Initialize context slot cache. 2246 // Initialize context slot cache.
2239 isolate_->context_slot_cache()->Clear(); 2247 isolate_->context_slot_cache()->Clear();
2240 2248
2241 // Initialize descriptor cache. 2249 // Initialize descriptor cache.
2242 isolate_->descriptor_lookup_cache()->Clear(); 2250 isolate_->descriptor_lookup_cache()->Clear();
2243 2251
2244 // Initialize compilation cache. 2252 // Initialize compilation cache.
2245 isolate_->compilation_cache()->Clear(); 2253 isolate_->compilation_cache()->Clear();
2246 2254
2247 return true; 2255 return true;
2248 } 2256 }
2249 2257
2250 2258
2259 Object* StringSplitCache::Lookup(
2260 FixedArray* cache, String* string, String* pattern) {
2261 if (!string->IsSymbol() || !pattern->IsSymbol()) return Smi::FromInt(0);
2262 uintptr_t hash = string->Hash();
2263 uintptr_t index = ((hash & (kStringSplitCacheSize - 1)) &
2264 ~(kArrayEntriesPerCacheEntry - 1));
2265 if (cache->get(index + kStringOffset) == string &&
2266 cache->get(index + kPatternOffset) == pattern) {
2267 return cache->get(index + kArrayOffset);
2268 }
2269 index = ((index + kArrayEntriesPerCacheEntry) & (kStringSplitCacheSize - 1));
2270 if (cache->get(index + kStringOffset) == string &&
2271 cache->get(index + kPatternOffset) == pattern) {
2272 return cache->get(index + kArrayOffset);
2273 }
2274 return Smi::FromInt(0);
2275 }
2276
2277
2278 void StringSplitCache::Enter(Heap* heap,
2279 FixedArray* cache,
2280 String* string,
2281 String* pattern,
2282 FixedArray* array) {
2283 if (!string->IsSymbol() || !pattern->IsSymbol()) return;
2284 uintptr_t hash = string->Hash();
2285 array->set_map(heap->fixed_cow_array_map());
2286 uintptr_t index = ((hash & (kStringSplitCacheSize - 1)) &
2287 ~(kArrayEntriesPerCacheEntry - 1));
2288 if (cache->get(index + kStringOffset) == Smi::FromInt(0)) {
2289 cache->set(index + kStringOffset, string);
2290 cache->set(index + kPatternOffset, pattern);
2291 cache->set(index + kArrayOffset, array);
2292 return;
2293 }
2294 uintptr_t index2 =
2295 ((index + kArrayEntriesPerCacheEntry) & (kStringSplitCacheSize - 1));
2296 if (cache->get(index2 + kStringOffset) == Smi::FromInt(0)) {
2297 cache->set(index2 + kStringOffset, string);
2298 cache->set(index2 + kPatternOffset, pattern);
2299 cache->set(index2 + kArrayOffset, array);
2300 return;
2301 }
2302 cache->set(index2 + kStringOffset, Smi::FromInt(0));
2303 cache->set(index2 + kPatternOffset, Smi::FromInt(0));
2304 cache->set(index2 + kArrayOffset, Smi::FromInt(0));
2305 cache->set(index + kStringOffset, string);
2306 cache->set(index + kPatternOffset, pattern);
2307 cache->set(index + kArrayOffset, array);
2308 if (array->length() < 100) { // Limit how many new symbols we want to make.
2309 for (int i = 0; i < array->length(); i++) {
2310 String* str = String::cast(array->get(i));
2311 Object* symbol;
2312 MaybeObject* maybe_symbol = heap->LookupSymbol(str);
2313 if (maybe_symbol->ToObject(&symbol)) {
2314 array->set(i, symbol);
2315 }
2316 }
2317 }
2318 }
2319
2320
2321 void StringSplitCache::Clear(FixedArray* cache) {
2322 for (int i = 0; i < kStringSplitCacheSize; i++) {
2323 cache->set(i, Smi::FromInt(0));
2324 }
2325 }
2326
2327
2251 MaybeObject* Heap::InitializeNumberStringCache() { 2328 MaybeObject* Heap::InitializeNumberStringCache() {
2252 // Compute the size of the number string cache based on the max heap size. 2329 // Compute the size of the number string cache based on the max heap size.
2253 // max_semispace_size_ == 512 KB => number_string_cache_size = 32. 2330 // max_semispace_size_ == 512 KB => number_string_cache_size = 32.
2254 // max_semispace_size_ == 8 MB => number_string_cache_size = 16KB. 2331 // max_semispace_size_ == 8 MB => number_string_cache_size = 16KB.
2255 int number_string_cache_size = max_semispace_size_ / 512; 2332 int number_string_cache_size = max_semispace_size_ / 512;
2256 number_string_cache_size = Max(32, Min(16*KB, number_string_cache_size)); 2333 number_string_cache_size = Max(32, Min(16*KB, number_string_cache_size));
2257 Object* obj; 2334 Object* obj;
2258 MaybeObject* maybe_obj = 2335 MaybeObject* maybe_obj =
2259 AllocateFixedArray(number_string_cache_size * 2, TENURED); 2336 AllocateFixedArray(number_string_cache_size * 2, TENURED);
2260 if (maybe_obj->ToObject(&obj)) set_number_string_cache(FixedArray::cast(obj)); 2337 if (maybe_obj->ToObject(&obj)) set_number_string_cache(FixedArray::cast(obj));
(...skipping 3885 matching lines...) Expand 10 before | Expand all | Expand 10 after
6146 } 6223 }
6147 6224
6148 6225
6149 void ExternalStringTable::TearDown() { 6226 void ExternalStringTable::TearDown() {
6150 new_space_strings_.Free(); 6227 new_space_strings_.Free();
6151 old_space_strings_.Free(); 6228 old_space_strings_.Free();
6152 } 6229 }
6153 6230
6154 6231
6155 } } // namespace v8::internal 6232 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/heap.h ('k') | src/runtime.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698