| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 844 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 855 bool NewSpace::Setup(Address start, int size) { | 855 bool NewSpace::Setup(Address start, int size) { |
| 856 // Setup new space based on the preallocated memory block defined by | 856 // Setup new space based on the preallocated memory block defined by |
| 857 // start and size. The provided space is divided into two semi-spaces. | 857 // start and size. The provided space is divided into two semi-spaces. |
| 858 // To support fast containment testing in the new space, the size of | 858 // To support fast containment testing in the new space, the size of |
| 859 // this chunk must be a power of two and it must be aligned to its size. | 859 // this chunk must be a power of two and it must be aligned to its size. |
| 860 int initial_semispace_capacity = Heap::InitialSemiSpaceSize(); | 860 int initial_semispace_capacity = Heap::InitialSemiSpaceSize(); |
| 861 int maximum_semispace_capacity = Heap::SemiSpaceSize(); | 861 int maximum_semispace_capacity = Heap::SemiSpaceSize(); |
| 862 | 862 |
| 863 ASSERT(initial_semispace_capacity <= maximum_semispace_capacity); | 863 ASSERT(initial_semispace_capacity <= maximum_semispace_capacity); |
| 864 ASSERT(IsPowerOf2(maximum_semispace_capacity)); | 864 ASSERT(IsPowerOf2(maximum_semispace_capacity)); |
| 865 maximum_capacity_ = maximum_semispace_capacity; | |
| 866 capacity_ = initial_semispace_capacity; | |
| 867 | 865 |
| 868 // Allocate and setup the histogram arrays if necessary. | 866 // Allocate and setup the histogram arrays if necessary. |
| 869 #if defined(DEBUG) || defined(ENABLE_LOGGING_AND_PROFILING) | 867 #if defined(DEBUG) || defined(ENABLE_LOGGING_AND_PROFILING) |
| 870 allocated_histogram_ = NewArray<HistogramInfo>(LAST_TYPE + 1); | 868 allocated_histogram_ = NewArray<HistogramInfo>(LAST_TYPE + 1); |
| 871 promoted_histogram_ = NewArray<HistogramInfo>(LAST_TYPE + 1); | 869 promoted_histogram_ = NewArray<HistogramInfo>(LAST_TYPE + 1); |
| 872 | 870 |
| 873 #define SET_NAME(name) allocated_histogram_[name].set_name(#name); \ | 871 #define SET_NAME(name) allocated_histogram_[name].set_name(#name); \ |
| 874 promoted_histogram_[name].set_name(#name); | 872 promoted_histogram_[name].set_name(#name); |
| 875 INSTANCE_TYPE_LIST(SET_NAME) | 873 INSTANCE_TYPE_LIST(SET_NAME) |
| 876 #undef SET_NAME | 874 #undef SET_NAME |
| 877 #endif | 875 #endif |
| 878 | 876 |
| 879 ASSERT(size == 2 * maximum_capacity_); | 877 ASSERT(size == 2 * maximum_semispace_capacity); |
| 880 ASSERT(IsAddressAligned(start, size, 0)); | 878 ASSERT(IsAddressAligned(start, size, 0)); |
| 881 | 879 |
| 882 if (!to_space_.Setup(start, capacity_, maximum_capacity_)) { | 880 if (!to_space_.Setup(start, |
| 881 initial_semispace_capacity, |
| 882 maximum_semispace_capacity)) { |
| 883 return false; | 883 return false; |
| 884 } | 884 } |
| 885 if (!from_space_.Setup(start + maximum_capacity_, | 885 if (!from_space_.Setup(start + maximum_semispace_capacity, |
| 886 capacity_, | 886 initial_semispace_capacity, |
| 887 maximum_capacity_)) { | 887 maximum_semispace_capacity)) { |
| 888 return false; | 888 return false; |
| 889 } | 889 } |
| 890 | 890 |
| 891 start_ = start; | 891 start_ = start; |
| 892 address_mask_ = ~(size - 1); | 892 address_mask_ = ~(size - 1); |
| 893 object_mask_ = address_mask_ | kHeapObjectTag; | 893 object_mask_ = address_mask_ | kHeapObjectTag; |
| 894 object_expected_ = reinterpret_cast<uintptr_t>(start) | kHeapObjectTag; | 894 object_expected_ = reinterpret_cast<uintptr_t>(start) | kHeapObjectTag; |
| 895 | 895 |
| 896 allocation_info_.top = to_space_.low(); | 896 allocation_info_.top = to_space_.low(); |
| 897 allocation_info_.limit = to_space_.high(); | 897 allocation_info_.limit = to_space_.high(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 909 DeleteArray(allocated_histogram_); | 909 DeleteArray(allocated_histogram_); |
| 910 allocated_histogram_ = NULL; | 910 allocated_histogram_ = NULL; |
| 911 } | 911 } |
| 912 if (promoted_histogram_) { | 912 if (promoted_histogram_) { |
| 913 DeleteArray(promoted_histogram_); | 913 DeleteArray(promoted_histogram_); |
| 914 promoted_histogram_ = NULL; | 914 promoted_histogram_ = NULL; |
| 915 } | 915 } |
| 916 #endif | 916 #endif |
| 917 | 917 |
| 918 start_ = NULL; | 918 start_ = NULL; |
| 919 capacity_ = 0; | |
| 920 allocation_info_.top = NULL; | 919 allocation_info_.top = NULL; |
| 921 allocation_info_.limit = NULL; | 920 allocation_info_.limit = NULL; |
| 922 mc_forwarding_info_.top = NULL; | 921 mc_forwarding_info_.top = NULL; |
| 923 mc_forwarding_info_.limit = NULL; | 922 mc_forwarding_info_.limit = NULL; |
| 924 | 923 |
| 925 to_space_.TearDown(); | 924 to_space_.TearDown(); |
| 926 from_space_.TearDown(); | 925 from_space_.TearDown(); |
| 927 } | 926 } |
| 928 | 927 |
| 929 | 928 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 945 #endif | 944 #endif |
| 946 | 945 |
| 947 | 946 |
| 948 void NewSpace::Flip() { | 947 void NewSpace::Flip() { |
| 949 SemiSpace tmp = from_space_; | 948 SemiSpace tmp = from_space_; |
| 950 from_space_ = to_space_; | 949 from_space_ = to_space_; |
| 951 to_space_ = tmp; | 950 to_space_ = tmp; |
| 952 } | 951 } |
| 953 | 952 |
| 954 | 953 |
| 955 bool NewSpace::Double() { | 954 bool NewSpace::Grow() { |
| 956 ASSERT(capacity_ <= maximum_capacity_ / 2); | 955 ASSERT(Capacity() < MaximumCapacity()); |
| 957 // TODO(1240712): Failure to double the from space can result in | 956 // TODO(1240712): Failure to double the from space can result in |
| 958 // semispaces of different sizes. In the event of that failure, the | 957 // semispaces of different sizes. In the event of that failure, the |
| 959 // to space doubling should be rolled back before returning false. | 958 // to space doubling should be rolled back before returning false. |
| 960 if (!to_space_.Double() || !from_space_.Double()) return false; | 959 if (!to_space_.Grow() || !from_space_.Grow()) return false; |
| 961 capacity_ *= 2; | |
| 962 allocation_info_.limit = to_space_.high(); | 960 allocation_info_.limit = to_space_.high(); |
| 963 ASSERT_SEMISPACE_ALLOCATION_INFO(allocation_info_, to_space_); | 961 ASSERT_SEMISPACE_ALLOCATION_INFO(allocation_info_, to_space_); |
| 964 return true; | 962 return true; |
| 965 } | 963 } |
| 966 | 964 |
| 967 | 965 |
| 968 void NewSpace::ResetAllocationInfo() { | 966 void NewSpace::ResetAllocationInfo() { |
| 969 allocation_info_.top = to_space_.low(); | 967 allocation_info_.top = to_space_.low(); |
| 970 allocation_info_.limit = to_space_.high(); | 968 allocation_info_.limit = to_space_.high(); |
| 971 ASSERT_SEMISPACE_ALLOCATION_INFO(allocation_info_, to_space_); | 969 ASSERT_SEMISPACE_ALLOCATION_INFO(allocation_info_, to_space_); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1073 return Commit(); | 1071 return Commit(); |
| 1074 } | 1072 } |
| 1075 | 1073 |
| 1076 | 1074 |
| 1077 void SemiSpace::TearDown() { | 1075 void SemiSpace::TearDown() { |
| 1078 start_ = NULL; | 1076 start_ = NULL; |
| 1079 capacity_ = 0; | 1077 capacity_ = 0; |
| 1080 } | 1078 } |
| 1081 | 1079 |
| 1082 | 1080 |
| 1083 bool SemiSpace::Double() { | 1081 bool SemiSpace::Grow() { |
| 1084 if (!MemoryAllocator::CommitBlock(high(), capacity_, executable())) { | 1082 // Commit 50% extra space but only up to maximum capacity. |
| 1083 int maximum_extra = maximum_capacity_ - capacity_; |
| 1084 int extra = Min(RoundUp(capacity_ / 2, OS::AllocateAlignment()), |
| 1085 maximum_extra); |
| 1086 if (!MemoryAllocator::CommitBlock(high(), extra, executable())) { |
| 1085 return false; | 1087 return false; |
| 1086 } | 1088 } |
| 1087 capacity_ *= 2; | 1089 capacity_ += extra; |
| 1088 return true; | 1090 return true; |
| 1089 } | 1091 } |
| 1090 | 1092 |
| 1091 | 1093 |
| 1092 #ifdef DEBUG | 1094 #ifdef DEBUG |
| 1093 void SemiSpace::Print() { } | 1095 void SemiSpace::Print() { } |
| 1094 | 1096 |
| 1095 | 1097 |
| 1096 void SemiSpace::Verify() { } | 1098 void SemiSpace::Verify() { } |
| 1097 #endif | 1099 #endif |
| (...skipping 1501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2599 reinterpret_cast<Object**>(object->address() | 2601 reinterpret_cast<Object**>(object->address() |
| 2600 + Page::kObjectAreaSize), | 2602 + Page::kObjectAreaSize), |
| 2601 allocation_top); | 2603 allocation_top); |
| 2602 PrintF("\n"); | 2604 PrintF("\n"); |
| 2603 } | 2605 } |
| 2604 } | 2606 } |
| 2605 } | 2607 } |
| 2606 #endif // DEBUG | 2608 #endif // DEBUG |
| 2607 | 2609 |
| 2608 } } // namespace v8::internal | 2610 } } // namespace v8::internal |
| OLD | NEW |