| 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 3017 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3028 // call Heap::TearDown() to release allocated memory. | 3028 // call Heap::TearDown() to release allocated memory. |
| 3029 // | 3029 // |
| 3030 // If the heap is not yet configured (eg, through the API), configure it. | 3030 // If the heap is not yet configured (eg, through the API), configure it. |
| 3031 // Configuration is based on the flags new-space-size (really the semispace | 3031 // Configuration is based on the flags new-space-size (really the semispace |
| 3032 // size) and old-space-size if set or the initial values of semispace_size_ | 3032 // size) and old-space-size if set or the initial values of semispace_size_ |
| 3033 // and old_generation_size_ otherwise. | 3033 // and old_generation_size_ otherwise. |
| 3034 if (!heap_configured) { | 3034 if (!heap_configured) { |
| 3035 if (!ConfigureHeapDefault()) return false; | 3035 if (!ConfigureHeapDefault()) return false; |
| 3036 } | 3036 } |
| 3037 | 3037 |
| 3038 // Setup memory allocator and allocate an initial chunk of memory. The | 3038 // Setup memory allocator and reserve a chunk of memory for new |
| 3039 // initial chunk is double the size of the new space to ensure that we can | 3039 // space. The chunk is double the size of the new space to ensure |
| 3040 // find a pair of semispaces that are contiguous and aligned to their size. | 3040 // that we can find a pair of semispaces that are contiguous and |
| 3041 // aligned to their size. |
| 3041 if (!MemoryAllocator::Setup(MaxCapacity())) return false; | 3042 if (!MemoryAllocator::Setup(MaxCapacity())) return false; |
| 3042 void* chunk | 3043 void* chunk = |
| 3043 = MemoryAllocator::ReserveInitialChunk(2 * young_generation_size_); | 3044 MemoryAllocator::ReserveInitialChunk(2 * young_generation_size_); |
| 3044 if (chunk == NULL) return false; | 3045 if (chunk == NULL) return false; |
| 3045 | 3046 |
| 3046 // Put the initial chunk of the old space at the start of the initial | 3047 // Align the pair of semispaces to their size, which must be a power |
| 3047 // chunk, then the two new space semispaces, then the initial chunk of | 3048 // of 2. |
| 3048 // code space. Align the pair of semispaces to their size, which must be | |
| 3049 // a power of 2. | |
| 3050 ASSERT(IsPowerOf2(young_generation_size_)); | 3049 ASSERT(IsPowerOf2(young_generation_size_)); |
| 3051 Address code_space_start = reinterpret_cast<Address>(chunk); | 3050 Address new_space_start = |
| 3052 Address new_space_start = RoundUp(code_space_start, young_generation_size_); | 3051 RoundUp(reinterpret_cast<byte*>(chunk), young_generation_size_); |
| 3053 Address old_space_start = new_space_start + young_generation_size_; | |
| 3054 int code_space_size = new_space_start - code_space_start; | |
| 3055 int old_space_size = young_generation_size_ - code_space_size; | |
| 3056 | |
| 3057 // Initialize new space. | |
| 3058 if (!new_space_.Setup(new_space_start, young_generation_size_)) return false; | 3052 if (!new_space_.Setup(new_space_start, young_generation_size_)) return false; |
| 3059 | 3053 |
| 3060 // Initialize old space, set the maximum capacity to the old generation | 3054 // Initialize old pointer space. |
| 3061 // size. It will not contain code. | |
| 3062 old_pointer_space_ = | 3055 old_pointer_space_ = |
| 3063 new OldSpace(old_generation_size_, OLD_POINTER_SPACE, NOT_EXECUTABLE); | 3056 new OldSpace(old_generation_size_, OLD_POINTER_SPACE, NOT_EXECUTABLE); |
| 3064 if (old_pointer_space_ == NULL) return false; | 3057 if (old_pointer_space_ == NULL) return false; |
| 3065 if (!old_pointer_space_->Setup(old_space_start, old_space_size >> 1)) { | 3058 if (!old_pointer_space_->Setup(NULL, 0)) return false; |
| 3066 return false; | 3059 |
| 3067 } | 3060 // Initialize old data space. |
| 3068 old_data_space_ = | 3061 old_data_space_ = |
| 3069 new OldSpace(old_generation_size_, OLD_DATA_SPACE, NOT_EXECUTABLE); | 3062 new OldSpace(old_generation_size_, OLD_DATA_SPACE, NOT_EXECUTABLE); |
| 3070 if (old_data_space_ == NULL) return false; | 3063 if (old_data_space_ == NULL) return false; |
| 3071 if (!old_data_space_->Setup(old_space_start + (old_space_size >> 1), | 3064 if (!old_data_space_->Setup(NULL, 0)) return false; |
| 3072 old_space_size >> 1)) { | |
| 3073 return false; | |
| 3074 } | |
| 3075 | 3065 |
| 3076 // Initialize the code space, set its maximum capacity to the old | 3066 // Initialize the code space, set its maximum capacity to the old |
| 3077 // generation size. It needs executable memory. | 3067 // generation size. It needs executable memory. |
| 3078 code_space_ = | 3068 code_space_ = |
| 3079 new OldSpace(old_generation_size_, CODE_SPACE, EXECUTABLE); | 3069 new OldSpace(old_generation_size_, CODE_SPACE, EXECUTABLE); |
| 3080 if (code_space_ == NULL) return false; | 3070 if (code_space_ == NULL) return false; |
| 3081 if (!code_space_->Setup(code_space_start, code_space_size)) return false; | 3071 if (!code_space_->Setup(NULL, 0)) return false; |
| 3082 | 3072 |
| 3083 // Initialize map space. | 3073 // Initialize map space. |
| 3084 map_space_ = new MapSpace(kMaxMapSpaceSize, MAP_SPACE); | 3074 map_space_ = new MapSpace(kMaxMapSpaceSize, MAP_SPACE); |
| 3085 if (map_space_ == NULL) return false; | 3075 if (map_space_ == NULL) return false; |
| 3086 // Setting up a paged space without giving it a virtual memory range big | |
| 3087 // enough to hold at least a page will cause it to allocate. | |
| 3088 if (!map_space_->Setup(NULL, 0)) return false; | 3076 if (!map_space_->Setup(NULL, 0)) return false; |
| 3089 | 3077 |
| 3090 // Initialize global property cell space. | 3078 // Initialize global property cell space. |
| 3091 cell_space_ = new CellSpace(old_generation_size_, CELL_SPACE); | 3079 cell_space_ = new CellSpace(old_generation_size_, CELL_SPACE); |
| 3092 if (cell_space_ == NULL) return false; | 3080 if (cell_space_ == NULL) return false; |
| 3093 // Setting up a paged space without giving it a virtual memory range big | |
| 3094 // enough to hold at least a page will cause it to allocate. | |
| 3095 if (!cell_space_->Setup(NULL, 0)) return false; | 3081 if (!cell_space_->Setup(NULL, 0)) return false; |
| 3096 | 3082 |
| 3097 // The large object code space may contain code or data. We set the memory | 3083 // The large object code space may contain code or data. We set the memory |
| 3098 // to be non-executable here for safety, but this means we need to enable it | 3084 // to be non-executable here for safety, but this means we need to enable it |
| 3099 // explicitly when allocating large code objects. | 3085 // explicitly when allocating large code objects. |
| 3100 lo_space_ = new LargeObjectSpace(LO_SPACE); | 3086 lo_space_ = new LargeObjectSpace(LO_SPACE); |
| 3101 if (lo_space_ == NULL) return false; | 3087 if (lo_space_ == NULL) return false; |
| 3102 if (!lo_space_->Setup()) return false; | 3088 if (!lo_space_->Setup()) return false; |
| 3103 | 3089 |
| 3104 if (create_heap_objects) { | 3090 if (create_heap_objects) { |
| (...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3713 #ifdef DEBUG | 3699 #ifdef DEBUG |
| 3714 bool Heap::GarbageCollectionGreedyCheck() { | 3700 bool Heap::GarbageCollectionGreedyCheck() { |
| 3715 ASSERT(FLAG_gc_greedy); | 3701 ASSERT(FLAG_gc_greedy); |
| 3716 if (Bootstrapper::IsActive()) return true; | 3702 if (Bootstrapper::IsActive()) return true; |
| 3717 if (disallow_allocation_failure()) return true; | 3703 if (disallow_allocation_failure()) return true; |
| 3718 return CollectGarbage(0, NEW_SPACE); | 3704 return CollectGarbage(0, NEW_SPACE); |
| 3719 } | 3705 } |
| 3720 #endif | 3706 #endif |
| 3721 | 3707 |
| 3722 } } // namespace v8::internal | 3708 } } // namespace v8::internal |
| OLD | NEW |