Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 878 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 889 // maps. | 889 // maps. |
| 890 isolate_->keyed_lookup_cache()->Clear(); | 890 isolate_->keyed_lookup_cache()->Clear(); |
| 891 isolate_->context_slot_cache()->Clear(); | 891 isolate_->context_slot_cache()->Clear(); |
| 892 isolate_->descriptor_lookup_cache()->Clear(); | 892 isolate_->descriptor_lookup_cache()->Clear(); |
| 893 StringSplitCache::Clear(string_split_cache()); | 893 StringSplitCache::Clear(string_split_cache()); |
| 894 | 894 |
| 895 isolate_->compilation_cache()->MarkCompactPrologue(); | 895 isolate_->compilation_cache()->MarkCompactPrologue(); |
| 896 | 896 |
| 897 CompletelyClearInstanceofCache(); | 897 CompletelyClearInstanceofCache(); |
| 898 | 898 |
| 899 // TODO(1605) select heuristic for flushing NumberString cache with | 899 FlushNumberStringCache(); |
|
Michael Starzinger
2012/01/25 13:00:56
If it's intentional that the new heuristic for flu
Erik Corry
2012/01/25 14:37:26
Done.
| |
| 900 // FlushNumberStringCache | |
| 901 if (FLAG_cleanup_code_caches_at_gc) { | 900 if (FLAG_cleanup_code_caches_at_gc) { |
| 902 polymorphic_code_cache()->set_cache(undefined_value()); | 901 polymorphic_code_cache()->set_cache(undefined_value()); |
| 903 } | 902 } |
| 904 | 903 |
| 905 ClearNormalizedMapCaches(); | 904 ClearNormalizedMapCaches(); |
| 906 } | 905 } |
| 907 | 906 |
| 908 | 907 |
| 909 Object* Heap::FindCodeObject(Address a) { | 908 Object* Heap::FindCodeObject(Address a) { |
| 910 return isolate()->inner_pointer_to_code_cache()-> | 909 return isolate()->inner_pointer_to_code_cache()-> |
| (...skipping 1588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2499 // Allocate the dictionary of intrinsic function names. | 2498 // Allocate the dictionary of intrinsic function names. |
| 2500 { MaybeObject* maybe_obj = StringDictionary::Allocate(Runtime::kNumFunctions); | 2499 { MaybeObject* maybe_obj = StringDictionary::Allocate(Runtime::kNumFunctions); |
| 2501 if (!maybe_obj->ToObject(&obj)) return false; | 2500 if (!maybe_obj->ToObject(&obj)) return false; |
| 2502 } | 2501 } |
| 2503 { MaybeObject* maybe_obj = Runtime::InitializeIntrinsicFunctionNames(this, | 2502 { MaybeObject* maybe_obj = Runtime::InitializeIntrinsicFunctionNames(this, |
| 2504 obj); | 2503 obj); |
| 2505 if (!maybe_obj->ToObject(&obj)) return false; | 2504 if (!maybe_obj->ToObject(&obj)) return false; |
| 2506 } | 2505 } |
| 2507 set_intrinsic_function_names(StringDictionary::cast(obj)); | 2506 set_intrinsic_function_names(StringDictionary::cast(obj)); |
| 2508 | 2507 |
| 2509 if (InitializeNumberStringCache()->IsFailure()) return false; | 2508 { MaybeObject* maybe_obj = AllocateInitialNumberStringCache(); |
| 2509 if (!maybe_obj->ToObject(&obj)) return false; | |
| 2510 } | |
| 2511 set_number_string_cache(FixedArray::cast(obj)); | |
| 2510 | 2512 |
| 2511 // Allocate cache for single character ASCII strings. | 2513 // Allocate cache for single character ASCII strings. |
| 2512 { MaybeObject* maybe_obj = | 2514 { MaybeObject* maybe_obj = |
| 2513 AllocateFixedArray(String::kMaxAsciiCharCode + 1, TENURED); | 2515 AllocateFixedArray(String::kMaxAsciiCharCode + 1, TENURED); |
| 2514 if (!maybe_obj->ToObject(&obj)) return false; | 2516 if (!maybe_obj->ToObject(&obj)) return false; |
| 2515 } | 2517 } |
| 2516 set_single_character_string_cache(FixedArray::cast(obj)); | 2518 set_single_character_string_cache(FixedArray::cast(obj)); |
| 2517 | 2519 |
| 2518 // Allocate cache for string split. | 2520 // Allocate cache for string split. |
| 2519 { MaybeObject* maybe_obj = | 2521 { MaybeObject* maybe_obj = |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2609 } | 2611 } |
| 2610 | 2612 |
| 2611 | 2613 |
| 2612 void StringSplitCache::Clear(FixedArray* cache) { | 2614 void StringSplitCache::Clear(FixedArray* cache) { |
| 2613 for (int i = 0; i < kStringSplitCacheSize; i++) { | 2615 for (int i = 0; i < kStringSplitCacheSize; i++) { |
| 2614 cache->set(i, Smi::FromInt(0)); | 2616 cache->set(i, Smi::FromInt(0)); |
| 2615 } | 2617 } |
| 2616 } | 2618 } |
| 2617 | 2619 |
| 2618 | 2620 |
| 2619 MaybeObject* Heap::InitializeNumberStringCache() { | 2621 MaybeObject* Heap::AllocateInitialNumberStringCache() { |
| 2622 MaybeObject* maybe_obj = | |
| 2623 AllocateFixedArray(kInitialNumberStringCacheSize * 2, TENURED); | |
| 2624 return maybe_obj; | |
| 2625 } | |
| 2626 | |
| 2627 | |
| 2628 int Heap::FullSizeNumberStringCacheLength() { | |
| 2620 // Compute the size of the number string cache based on the max heap size. | 2629 // Compute the size of the number string cache based on the max heap size. |
| 2621 // max_semispace_size_ == 512 KB => number_string_cache_size = 32. | 2630 // max_semispace_size_ == 512 KB => number_string_cache_size = 32. |
|
Michael Starzinger
2012/01/25 13:00:56
This comment no longer is on sync with the computa
Erik Corry
2012/01/25 14:37:26
Done.
| |
| 2622 // max_semispace_size_ == 8 MB => number_string_cache_size = 16KB. | 2631 // max_semispace_size_ == 8 MB => number_string_cache_size = 16KB. |
| 2623 int number_string_cache_size = max_semispace_size_ / 512; | 2632 int number_string_cache_size = max_semispace_size_ / 512; |
| 2624 number_string_cache_size = Max(32, Min(16*KB, number_string_cache_size)); | 2633 number_string_cache_size = Max(kInitialNumberStringCacheSize * 2, |
|
Michael Starzinger
2012/01/25 13:00:56
The constant is multiplied with 2 twice. I think w
Erik Corry
2012/01/25 14:37:26
The first multiplication is there to ensure that t
| |
| 2625 Object* obj; | 2634 Min(16*KB, number_string_cache_size)); |
| 2626 MaybeObject* maybe_obj = | 2635 return number_string_cache_size * 2; |
| 2627 AllocateFixedArray(number_string_cache_size * 2, TENURED); | |
| 2628 if (maybe_obj->ToObject(&obj)) set_number_string_cache(FixedArray::cast(obj)); | |
| 2629 return maybe_obj; | |
| 2630 } | 2636 } |
| 2631 | 2637 |
| 2632 | 2638 |
| 2639 void Heap::AllocateFullSizeNumberStringCache() { | |
| 2640 // The idea is to have a small number string cache in the snapshot to keep | |
| 2641 // boot-time memory usage down. If we expand the number string cache already | |
| 2642 // while creating the snapshot then that didn't work out. | |
| 2643 ASSERT(!Serializer::enabled()); | |
| 2644 MaybeObject* maybe_obj = | |
| 2645 AllocateFixedArray(FullSizeNumberStringCacheLength(), TENURED); | |
| 2646 Object* new_cache; | |
| 2647 if (maybe_obj->ToObject(&new_cache)) { | |
|
Michael Starzinger
2012/01/25 13:00:56
Can we add a comment that this is a best effort al
Erik Corry
2012/01/25 14:37:26
Done.
| |
| 2648 set_number_string_cache(FixedArray::cast(new_cache)); | |
| 2649 } | |
| 2650 } | |
| 2651 | |
| 2652 | |
| 2633 void Heap::FlushNumberStringCache() { | 2653 void Heap::FlushNumberStringCache() { |
| 2634 // Flush the number to string cache. | 2654 // Flush the number to string cache. |
| 2635 int len = number_string_cache()->length(); | 2655 int len = number_string_cache()->length(); |
| 2636 for (int i = 0; i < len; i++) { | 2656 for (int i = 0; i < len; i++) { |
| 2637 number_string_cache()->set_undefined(this, i); | 2657 number_string_cache()->set_undefined(this, i); |
| 2638 } | 2658 } |
| 2639 } | 2659 } |
| 2640 | 2660 |
| 2641 | 2661 |
| 2642 static inline int double_get_hash(double d) { | 2662 static inline int double_get_hash(double d) { |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 2668 } | 2688 } |
| 2669 return undefined_value(); | 2689 return undefined_value(); |
| 2670 } | 2690 } |
| 2671 | 2691 |
| 2672 | 2692 |
| 2673 void Heap::SetNumberStringCache(Object* number, String* string) { | 2693 void Heap::SetNumberStringCache(Object* number, String* string) { |
| 2674 int hash; | 2694 int hash; |
| 2675 int mask = (number_string_cache()->length() >> 1) - 1; | 2695 int mask = (number_string_cache()->length() >> 1) - 1; |
| 2676 if (number->IsSmi()) { | 2696 if (number->IsSmi()) { |
| 2677 hash = smi_get_hash(Smi::cast(number)) & mask; | 2697 hash = smi_get_hash(Smi::cast(number)) & mask; |
| 2678 number_string_cache()->set(hash * 2, Smi::cast(number)); | |
| 2679 } else { | 2698 } else { |
| 2680 hash = double_get_hash(number->Number()) & mask; | 2699 hash = double_get_hash(number->Number()) & mask; |
| 2681 number_string_cache()->set(hash * 2, number); | |
| 2682 } | 2700 } |
| 2701 if (number_string_cache()->get(hash * 2) != undefined_value() && | |
| 2702 number_string_cache()->length() != FullSizeNumberStringCacheLength()) { | |
| 2703 // The first time we have a hash collision, we move to the full sized | |
| 2704 // number string cache. | |
| 2705 AllocateFullSizeNumberStringCache(); | |
| 2706 return; | |
| 2707 } | |
| 2708 number_string_cache()->set(hash * 2, number); | |
| 2683 number_string_cache()->set(hash * 2 + 1, string); | 2709 number_string_cache()->set(hash * 2 + 1, string); |
| 2684 } | 2710 } |
| 2685 | 2711 |
| 2686 | 2712 |
| 2687 MaybeObject* Heap::NumberToString(Object* number, | 2713 MaybeObject* Heap::NumberToString(Object* number, |
| 2688 bool check_number_string_cache) { | 2714 bool check_number_string_cache) { |
| 2689 isolate_->counters()->number_to_string_runtime()->Increment(); | 2715 isolate_->counters()->number_to_string_runtime()->Increment(); |
| 2690 if (check_number_string_cache) { | 2716 if (check_number_string_cache) { |
| 2691 Object* cached = GetNumberStringCache(number); | 2717 Object* cached = GetNumberStringCache(number); |
| 2692 if (cached != undefined_value()) { | 2718 if (cached != undefined_value()) { |
| (...skipping 3994 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6687 isolate_->heap()->store_buffer()->Compact(); | 6713 isolate_->heap()->store_buffer()->Compact(); |
| 6688 isolate_->heap()->store_buffer()->Filter(MemoryChunk::ABOUT_TO_BE_FREED); | 6714 isolate_->heap()->store_buffer()->Filter(MemoryChunk::ABOUT_TO_BE_FREED); |
| 6689 for (chunk = chunks_queued_for_free_; chunk != NULL; chunk = next) { | 6715 for (chunk = chunks_queued_for_free_; chunk != NULL; chunk = next) { |
| 6690 next = chunk->next_chunk(); | 6716 next = chunk->next_chunk(); |
| 6691 isolate_->memory_allocator()->Free(chunk); | 6717 isolate_->memory_allocator()->Free(chunk); |
| 6692 } | 6718 } |
| 6693 chunks_queued_for_free_ = NULL; | 6719 chunks_queued_for_free_ = NULL; |
| 6694 } | 6720 } |
| 6695 | 6721 |
| 6696 } } // namespace v8::internal | 6722 } } // namespace v8::internal |
| OLD | NEW |