| OLD | NEW |
| 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 1972 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1983 | 1983 |
| 1984 Object* result = Heap::AllocateRawTwoByteString(1); | 1984 Object* result = Heap::AllocateRawTwoByteString(1); |
| 1985 if (result->IsFailure()) return result; | 1985 if (result->IsFailure()) return result; |
| 1986 String* answer = String::cast(result); | 1986 String* answer = String::cast(result); |
| 1987 answer->Set(0, code); | 1987 answer->Set(0, code); |
| 1988 return answer; | 1988 return answer; |
| 1989 } | 1989 } |
| 1990 | 1990 |
| 1991 | 1991 |
| 1992 Object* Heap::AllocateByteArray(int length, PretenureFlag pretenure) { | 1992 Object* Heap::AllocateByteArray(int length, PretenureFlag pretenure) { |
| 1993 if (length < 0 || length > ByteArray::kMaxLength) { |
| 1994 return Failure::OutOfMemoryException(); |
| 1995 } |
| 1993 if (pretenure == NOT_TENURED) { | 1996 if (pretenure == NOT_TENURED) { |
| 1994 return AllocateByteArray(length); | 1997 return AllocateByteArray(length); |
| 1995 } | 1998 } |
| 1996 int size = ByteArray::SizeFor(length); | 1999 int size = ByteArray::SizeFor(length); |
| 1997 AllocationSpace space = | 2000 AllocationSpace space = |
| 1998 size > MaxObjectSizeInPagedSpace() ? LO_SPACE : OLD_DATA_SPACE; | 2001 size > MaxObjectSizeInPagedSpace() ? LO_SPACE : OLD_DATA_SPACE; |
| 1999 | 2002 |
| 2000 Object* result = AllocateRaw(size, space, OLD_DATA_SPACE); | 2003 Object* result = AllocateRaw(size, space, OLD_DATA_SPACE); |
| 2001 | 2004 |
| 2002 if (result->IsFailure()) return result; | 2005 if (result->IsFailure()) return result; |
| 2003 | 2006 |
| 2004 reinterpret_cast<Array*>(result)->set_map(byte_array_map()); | 2007 reinterpret_cast<Array*>(result)->set_map(byte_array_map()); |
| 2005 reinterpret_cast<Array*>(result)->set_length(length); | 2008 reinterpret_cast<Array*>(result)->set_length(length); |
| 2006 return result; | 2009 return result; |
| 2007 } | 2010 } |
| 2008 | 2011 |
| 2009 | 2012 |
| 2010 Object* Heap::AllocateByteArray(int length) { | 2013 Object* Heap::AllocateByteArray(int length) { |
| 2014 if (length < 0 || length > ByteArray::kMaxLength) { |
| 2015 return Failure::OutOfMemoryException(); |
| 2016 } |
| 2011 int size = ByteArray::SizeFor(length); | 2017 int size = ByteArray::SizeFor(length); |
| 2012 AllocationSpace space = | 2018 AllocationSpace space = |
| 2013 size > MaxObjectSizeInPagedSpace() ? LO_SPACE : NEW_SPACE; | 2019 size > MaxObjectSizeInPagedSpace() ? LO_SPACE : NEW_SPACE; |
| 2014 | 2020 |
| 2015 // New space can't cope with forced allocation. | 2021 // New space can't cope with forced allocation. |
| 2016 if (always_allocate()) space = LO_SPACE; | 2022 if (always_allocate()) space = LO_SPACE; |
| 2017 | 2023 |
| 2018 Object* result = AllocateRaw(size, space, OLD_DATA_SPACE); | 2024 Object* result = AllocateRaw(size, space, OLD_DATA_SPACE); |
| 2019 | 2025 |
| 2020 if (result->IsFailure()) return result; | 2026 if (result->IsFailure()) return result; |
| (...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2659 } | 2665 } |
| 2660 | 2666 |
| 2661 // No match found. | 2667 // No match found. |
| 2662 return NULL; | 2668 return NULL; |
| 2663 } | 2669 } |
| 2664 | 2670 |
| 2665 | 2671 |
| 2666 Object* Heap::AllocateInternalSymbol(unibrow::CharacterStream* buffer, | 2672 Object* Heap::AllocateInternalSymbol(unibrow::CharacterStream* buffer, |
| 2667 int chars, | 2673 int chars, |
| 2668 uint32_t length_field) { | 2674 uint32_t length_field) { |
| 2675 ASSERT(chars >= 0); |
| 2669 // Ensure the chars matches the number of characters in the buffer. | 2676 // Ensure the chars matches the number of characters in the buffer. |
| 2670 ASSERT(static_cast<unsigned>(chars) == buffer->Length()); | 2677 ASSERT(static_cast<unsigned>(chars) == buffer->Length()); |
| 2671 // Determine whether the string is ascii. | 2678 // Determine whether the string is ascii. |
| 2672 bool is_ascii = true; | 2679 bool is_ascii = true; |
| 2673 while (buffer->has_more() && is_ascii) { | 2680 while (buffer->has_more()) { |
| 2674 if (buffer->GetNext() > unibrow::Utf8::kMaxOneByteChar) is_ascii = false; | 2681 if (buffer->GetNext() > unibrow::Utf8::kMaxOneByteChar) { |
| 2682 is_ascii = false; |
| 2683 break; |
| 2684 } |
| 2675 } | 2685 } |
| 2676 buffer->Rewind(); | 2686 buffer->Rewind(); |
| 2677 | 2687 |
| 2678 // Compute map and object size. | 2688 // Compute map and object size. |
| 2679 int size; | 2689 int size; |
| 2680 Map* map; | 2690 Map* map; |
| 2681 | 2691 |
| 2682 if (is_ascii) { | 2692 if (is_ascii) { |
| 2693 if (chars > SeqAsciiString::kMaxLength) { |
| 2694 return Failure::OutOfMemoryException(); |
| 2695 } |
| 2683 if (chars <= String::kMaxShortSize) { | 2696 if (chars <= String::kMaxShortSize) { |
| 2684 map = short_ascii_symbol_map(); | 2697 map = short_ascii_symbol_map(); |
| 2685 } else if (chars <= String::kMaxMediumSize) { | 2698 } else if (chars <= String::kMaxMediumSize) { |
| 2686 map = medium_ascii_symbol_map(); | 2699 map = medium_ascii_symbol_map(); |
| 2687 } else { | 2700 } else { |
| 2688 map = long_ascii_symbol_map(); | 2701 map = long_ascii_symbol_map(); |
| 2689 } | 2702 } |
| 2690 size = SeqAsciiString::SizeFor(chars); | 2703 size = SeqAsciiString::SizeFor(chars); |
| 2691 } else { | 2704 } else { |
| 2705 if (chars > SeqTwoByteString::kMaxLength) { |
| 2706 return Failure::OutOfMemoryException(); |
| 2707 } |
| 2692 if (chars <= String::kMaxShortSize) { | 2708 if (chars <= String::kMaxShortSize) { |
| 2693 map = short_symbol_map(); | 2709 map = short_symbol_map(); |
| 2694 } else if (chars <= String::kMaxMediumSize) { | 2710 } else if (chars <= String::kMaxMediumSize) { |
| 2695 map = medium_symbol_map(); | 2711 map = medium_symbol_map(); |
| 2696 } else { | 2712 } else { |
| 2697 map = long_symbol_map(); | 2713 map = long_symbol_map(); |
| 2698 } | 2714 } |
| 2699 size = SeqTwoByteString::SizeFor(chars); | 2715 size = SeqTwoByteString::SizeFor(chars); |
| 2700 } | 2716 } |
| 2701 | 2717 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 2714 | 2730 |
| 2715 // Fill in the characters. | 2731 // Fill in the characters. |
| 2716 for (int i = 0; i < chars; i++) { | 2732 for (int i = 0; i < chars; i++) { |
| 2717 answer->Set(i, buffer->GetNext()); | 2733 answer->Set(i, buffer->GetNext()); |
| 2718 } | 2734 } |
| 2719 return answer; | 2735 return answer; |
| 2720 } | 2736 } |
| 2721 | 2737 |
| 2722 | 2738 |
| 2723 Object* Heap::AllocateRawAsciiString(int length, PretenureFlag pretenure) { | 2739 Object* Heap::AllocateRawAsciiString(int length, PretenureFlag pretenure) { |
| 2740 if (length < 0 || length > SeqAsciiString::kMaxLength) { |
| 2741 return Failure::OutOfMemoryException(); |
| 2742 } |
| 2743 int size = SeqAsciiString::SizeFor(length); |
| 2744 ASSERT(size <= SeqAsciiString::kMaxSize); |
| 2745 |
| 2724 AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE; | 2746 AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE; |
| 2725 | 2747 |
| 2726 // New space can't cope with forced allocation. | 2748 // New space can't cope with forced allocation. |
| 2727 if (always_allocate()) space = OLD_DATA_SPACE; | 2749 if (always_allocate()) space = OLD_DATA_SPACE; |
| 2728 | 2750 |
| 2729 int size = SeqAsciiString::SizeFor(length); | |
| 2730 | |
| 2731 Object* result = Failure::OutOfMemoryException(); | 2751 Object* result = Failure::OutOfMemoryException(); |
| 2732 if (space == NEW_SPACE) { | 2752 if (space == NEW_SPACE) { |
| 2733 result = size <= kMaxObjectSizeInNewSpace | 2753 result = size <= kMaxObjectSizeInNewSpace |
| 2734 ? new_space_.AllocateRaw(size) | 2754 ? new_space_.AllocateRaw(size) |
| 2735 : lo_space_->AllocateRaw(size); | 2755 : lo_space_->AllocateRaw(size); |
| 2736 } else { | 2756 } else { |
| 2737 if (size > MaxObjectSizeInPagedSpace()) space = LO_SPACE; | 2757 if (size > MaxObjectSizeInPagedSpace()) space = LO_SPACE; |
| 2738 result = AllocateRaw(size, space, OLD_DATA_SPACE); | 2758 result = AllocateRaw(size, space, OLD_DATA_SPACE); |
| 2739 } | 2759 } |
| 2740 if (result->IsFailure()) return result; | 2760 if (result->IsFailure()) return result; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2751 | 2771 |
| 2752 // Partially initialize the object. | 2772 // Partially initialize the object. |
| 2753 HeapObject::cast(result)->set_map(map); | 2773 HeapObject::cast(result)->set_map(map); |
| 2754 String::cast(result)->set_length(length); | 2774 String::cast(result)->set_length(length); |
| 2755 ASSERT_EQ(size, HeapObject::cast(result)->Size()); | 2775 ASSERT_EQ(size, HeapObject::cast(result)->Size()); |
| 2756 return result; | 2776 return result; |
| 2757 } | 2777 } |
| 2758 | 2778 |
| 2759 | 2779 |
| 2760 Object* Heap::AllocateRawTwoByteString(int length, PretenureFlag pretenure) { | 2780 Object* Heap::AllocateRawTwoByteString(int length, PretenureFlag pretenure) { |
| 2781 if (length < 0 || length > SeqTwoByteString::kMaxLength) { |
| 2782 return Failure::OutOfMemoryException(); |
| 2783 } |
| 2784 int size = SeqTwoByteString::SizeFor(length); |
| 2785 ASSERT(size <= SeqTwoByteString::kMaxSize); |
| 2786 |
| 2761 AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE; | 2787 AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE; |
| 2762 | 2788 |
| 2763 // New space can't cope with forced allocation. | 2789 // New space can't cope with forced allocation. |
| 2764 if (always_allocate()) space = OLD_DATA_SPACE; | 2790 if (always_allocate()) space = OLD_DATA_SPACE; |
| 2765 | 2791 |
| 2766 int size = SeqTwoByteString::SizeFor(length); | |
| 2767 | |
| 2768 Object* result = Failure::OutOfMemoryException(); | 2792 Object* result = Failure::OutOfMemoryException(); |
| 2769 if (space == NEW_SPACE) { | 2793 if (space == NEW_SPACE) { |
| 2770 result = size <= kMaxObjectSizeInNewSpace | 2794 result = size <= kMaxObjectSizeInNewSpace |
| 2771 ? new_space_.AllocateRaw(size) | 2795 ? new_space_.AllocateRaw(size) |
| 2772 : lo_space_->AllocateRaw(size); | 2796 : lo_space_->AllocateRaw(size); |
| 2773 } else { | 2797 } else { |
| 2774 if (size > MaxObjectSizeInPagedSpace()) space = LO_SPACE; | 2798 if (size > MaxObjectSizeInPagedSpace()) space = LO_SPACE; |
| 2775 result = AllocateRaw(size, space, OLD_DATA_SPACE); | 2799 result = AllocateRaw(size, space, OLD_DATA_SPACE); |
| 2776 } | 2800 } |
| 2777 if (result->IsFailure()) return result; | 2801 if (result->IsFailure()) return result; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 2799 Object* result = AllocateRaw(size, OLD_DATA_SPACE, OLD_DATA_SPACE); | 2823 Object* result = AllocateRaw(size, OLD_DATA_SPACE, OLD_DATA_SPACE); |
| 2800 if (result->IsFailure()) return result; | 2824 if (result->IsFailure()) return result; |
| 2801 // Initialize the object. | 2825 // Initialize the object. |
| 2802 reinterpret_cast<Array*>(result)->set_map(fixed_array_map()); | 2826 reinterpret_cast<Array*>(result)->set_map(fixed_array_map()); |
| 2803 reinterpret_cast<Array*>(result)->set_length(0); | 2827 reinterpret_cast<Array*>(result)->set_length(0); |
| 2804 return result; | 2828 return result; |
| 2805 } | 2829 } |
| 2806 | 2830 |
| 2807 | 2831 |
| 2808 Object* Heap::AllocateRawFixedArray(int length) { | 2832 Object* Heap::AllocateRawFixedArray(int length) { |
| 2833 if (length < 0 || length > FixedArray::kMaxLength) { |
| 2834 return Failure::OutOfMemoryException(); |
| 2835 } |
| 2809 // Use the general function if we're forced to always allocate. | 2836 // Use the general function if we're forced to always allocate. |
| 2810 if (always_allocate()) return AllocateFixedArray(length, TENURED); | 2837 if (always_allocate()) return AllocateFixedArray(length, TENURED); |
| 2811 // Allocate the raw data for a fixed array. | 2838 // Allocate the raw data for a fixed array. |
| 2812 int size = FixedArray::SizeFor(length); | 2839 int size = FixedArray::SizeFor(length); |
| 2813 return size <= kMaxObjectSizeInNewSpace | 2840 return size <= kMaxObjectSizeInNewSpace |
| 2814 ? new_space_.AllocateRaw(size) | 2841 ? new_space_.AllocateRaw(size) |
| 2815 : lo_space_->AllocateRawFixedArray(size); | 2842 : lo_space_->AllocateRawFixedArray(size); |
| 2816 } | 2843 } |
| 2817 | 2844 |
| 2818 | 2845 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2850 // Initialize body. | 2877 // Initialize body. |
| 2851 for (int index = 0; index < length; index++) { | 2878 for (int index = 0; index < length; index++) { |
| 2852 array->set(index, value, SKIP_WRITE_BARRIER); | 2879 array->set(index, value, SKIP_WRITE_BARRIER); |
| 2853 } | 2880 } |
| 2854 } | 2881 } |
| 2855 return result; | 2882 return result; |
| 2856 } | 2883 } |
| 2857 | 2884 |
| 2858 | 2885 |
| 2859 Object* Heap::AllocateFixedArray(int length, PretenureFlag pretenure) { | 2886 Object* Heap::AllocateFixedArray(int length, PretenureFlag pretenure) { |
| 2887 ASSERT(length >= 0); |
| 2860 ASSERT(empty_fixed_array()->IsFixedArray()); | 2888 ASSERT(empty_fixed_array()->IsFixedArray()); |
| 2889 if (length < 0 || length > FixedArray::kMaxLength) { |
| 2890 return Failure::OutOfMemoryException(); |
| 2891 } |
| 2861 if (length == 0) return empty_fixed_array(); | 2892 if (length == 0) return empty_fixed_array(); |
| 2862 | 2893 |
| 2863 // New space can't cope with forced allocation. | 2894 // New space can't cope with forced allocation. |
| 2864 if (always_allocate()) pretenure = TENURED; | 2895 if (always_allocate()) pretenure = TENURED; |
| 2865 | 2896 |
| 2866 int size = FixedArray::SizeFor(length); | 2897 int size = FixedArray::SizeFor(length); |
| 2867 Object* result = Failure::OutOfMemoryException(); | 2898 Object* result = Failure::OutOfMemoryException(); |
| 2868 if (pretenure != TENURED) { | 2899 if (pretenure != TENURED) { |
| 2869 result = size <= kMaxObjectSizeInNewSpace | 2900 result = size <= kMaxObjectSizeInNewSpace |
| 2870 ? new_space_.AllocateRaw(size) | 2901 ? new_space_.AllocateRaw(size) |
| (...skipping 1200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4071 for (int i = 0; i < kNumberOfCaches; i++) { | 4102 for (int i = 0; i < kNumberOfCaches; i++) { |
| 4072 if (caches_[i] != NULL) { | 4103 if (caches_[i] != NULL) { |
| 4073 delete caches_[i]; | 4104 delete caches_[i]; |
| 4074 caches_[i] = NULL; | 4105 caches_[i] = NULL; |
| 4075 } | 4106 } |
| 4076 } | 4107 } |
| 4077 } | 4108 } |
| 4078 | 4109 |
| 4079 | 4110 |
| 4080 } } // namespace v8::internal | 4111 } } // namespace v8::internal |
| OLD | NEW |