| 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 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 ASSERT(size > 0); | 333 ASSERT(size > 0); |
| 334 ASSERT(initial_chunk_ != NULL); | 334 ASSERT(initial_chunk_ != NULL); |
| 335 ASSERT(InInitialChunk(start)); | 335 ASSERT(InInitialChunk(start)); |
| 336 ASSERT(InInitialChunk(start + size - 1)); | 336 ASSERT(InInitialChunk(start + size - 1)); |
| 337 | 337 |
| 338 if (!initial_chunk_->Commit(start, size, executable)) return false; | 338 if (!initial_chunk_->Commit(start, size, executable)) return false; |
| 339 Counters::memory_allocated.Increment(size); | 339 Counters::memory_allocated.Increment(size); |
| 340 return true; | 340 return true; |
| 341 } | 341 } |
| 342 | 342 |
| 343 bool MemoryAllocator::UncommitBlock(Address start, size_t size) { |
| 344 ASSERT(start != NULL); |
| 345 ASSERT(size > 0); |
| 346 ASSERT(initial_chunk_ != NULL); |
| 347 ASSERT(InInitialChunk(start)); |
| 348 ASSERT(InInitialChunk(start + size - 1)); |
| 349 |
| 350 if (!initial_chunk_->Uncommit(start, size)) return false; |
| 351 Counters::memory_allocated.Decrement(size); |
| 352 return true; |
| 353 } |
| 343 | 354 |
| 344 Page* MemoryAllocator::InitializePagesInChunk(int chunk_id, int pages_in_chunk, | 355 Page* MemoryAllocator::InitializePagesInChunk(int chunk_id, int pages_in_chunk, |
| 345 PagedSpace* owner) { | 356 PagedSpace* owner) { |
| 346 ASSERT(IsValidChunk(chunk_id)); | 357 ASSERT(IsValidChunk(chunk_id)); |
| 347 ASSERT(pages_in_chunk > 0); | 358 ASSERT(pages_in_chunk > 0); |
| 348 | 359 |
| 349 Address chunk_start = chunks_[chunk_id].address(); | 360 Address chunk_start = chunks_[chunk_id].address(); |
| 350 | 361 |
| 351 Address low = RoundUp(chunk_start, Page::kPageSize); | 362 Address low = RoundUp(chunk_start, Page::kPageSize); |
| 352 | 363 |
| (...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1032 | 1043 |
| 1033 current += size; | 1044 current += size; |
| 1034 } | 1045 } |
| 1035 | 1046 |
| 1036 // The allocation pointer should not be in the middle of an object. | 1047 // The allocation pointer should not be in the middle of an object. |
| 1037 ASSERT(current == top()); | 1048 ASSERT(current == top()); |
| 1038 } | 1049 } |
| 1039 #endif | 1050 #endif |
| 1040 | 1051 |
| 1041 | 1052 |
| 1053 bool SemiSpace::Commit() { |
| 1054 ASSERT(!is_committed()); |
| 1055 if (!MemoryAllocator::CommitBlock(start_, capacity_, executable())) { |
| 1056 return false; |
| 1057 } |
| 1058 committed_ = true; |
| 1059 return true; |
| 1060 } |
| 1061 |
| 1062 |
| 1063 bool SemiSpace::Uncommit() { |
| 1064 ASSERT(is_committed()); |
| 1065 if (!MemoryAllocator::UncommitBlock(start_, capacity_)) { |
| 1066 return false; |
| 1067 } |
| 1068 committed_ = false; |
| 1069 return true; |
| 1070 } |
| 1071 |
| 1072 |
| 1042 // ----------------------------------------------------------------------------- | 1073 // ----------------------------------------------------------------------------- |
| 1043 // SemiSpace implementation | 1074 // SemiSpace implementation |
| 1044 | 1075 |
| 1045 bool SemiSpace::Setup(Address start, | 1076 bool SemiSpace::Setup(Address start, |
| 1046 int initial_capacity, | 1077 int initial_capacity, |
| 1047 int maximum_capacity) { | 1078 int maximum_capacity) { |
| 1048 // Creates a space in the young generation. The constructor does not | 1079 // Creates a space in the young generation. The constructor does not |
| 1049 // allocate memory from the OS. A SemiSpace is given a contiguous chunk of | 1080 // allocate memory from the OS. A SemiSpace is given a contiguous chunk of |
| 1050 // memory of size 'capacity' when set up, and does not grow or shrink | 1081 // memory of size 'capacity' when set up, and does not grow or shrink |
| 1051 // otherwise. In the mark-compact collector, the memory region of the from | 1082 // otherwise. In the mark-compact collector, the memory region of the from |
| 1052 // space is used as the marking stack. It requires contiguous memory | 1083 // space is used as the marking stack. It requires contiguous memory |
| 1053 // addresses. | 1084 // addresses. |
| 1054 capacity_ = initial_capacity; | 1085 capacity_ = initial_capacity; |
| 1055 maximum_capacity_ = maximum_capacity; | 1086 maximum_capacity_ = maximum_capacity; |
| 1056 | 1087 committed_ = false; |
| 1057 if (!MemoryAllocator::CommitBlock(start, capacity_, executable())) { | |
| 1058 return false; | |
| 1059 } | |
| 1060 | 1088 |
| 1061 start_ = start; | 1089 start_ = start; |
| 1062 address_mask_ = ~(maximum_capacity - 1); | 1090 address_mask_ = ~(maximum_capacity - 1); |
| 1063 object_mask_ = address_mask_ | kHeapObjectTag; | 1091 object_mask_ = address_mask_ | kHeapObjectTag; |
| 1064 object_expected_ = reinterpret_cast<uintptr_t>(start) | kHeapObjectTag; | 1092 object_expected_ = reinterpret_cast<uintptr_t>(start) | kHeapObjectTag; |
| 1093 age_mark_ = start_; |
| 1065 | 1094 |
| 1066 age_mark_ = start_; | 1095 return Commit(); |
| 1067 return true; | |
| 1068 } | 1096 } |
| 1069 | 1097 |
| 1070 | 1098 |
| 1071 void SemiSpace::TearDown() { | 1099 void SemiSpace::TearDown() { |
| 1072 start_ = NULL; | 1100 start_ = NULL; |
| 1073 capacity_ = 0; | 1101 capacity_ = 0; |
| 1074 } | 1102 } |
| 1075 | 1103 |
| 1076 | 1104 |
| 1077 bool SemiSpace::Grow() { | 1105 bool SemiSpace::Grow() { |
| 1078 // Commit 50% extra space but only up to maximum capacity. | 1106 // Commit 50% extra space but only up to maximum capacity. |
| 1079 int extra = capacity_/2; | 1107 int extra = RoundUp(capacity_ / 2, OS::AllocateAlignment()); |
| 1080 if (capacity_ + extra > maximum_capacity_) { | 1108 if (capacity_ + extra > maximum_capacity_) { |
| 1081 extra = maximum_capacity_ - capacity_; | 1109 extra = maximum_capacity_ - capacity_; |
| 1082 } | 1110 } |
| 1083 if (!MemoryAllocator::CommitBlock(high(), extra, executable())) { | 1111 if (!MemoryAllocator::CommitBlock(high(), extra, executable())) { |
| 1084 return false; | 1112 return false; |
| 1085 } | 1113 } |
| 1086 capacity_ += extra; | 1114 capacity_ += extra; |
| 1087 return true; | 1115 return true; |
| 1088 } | 1116 } |
| 1089 | 1117 |
| (...skipping 1508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2598 reinterpret_cast<Object**>(object->address() | 2626 reinterpret_cast<Object**>(object->address() |
| 2599 + Page::kObjectAreaSize), | 2627 + Page::kObjectAreaSize), |
| 2600 allocation_top); | 2628 allocation_top); |
| 2601 PrintF("\n"); | 2629 PrintF("\n"); |
| 2602 } | 2630 } |
| 2603 } | 2631 } |
| 2604 } | 2632 } |
| 2605 #endif // DEBUG | 2633 #endif // DEBUG |
| 2606 | 2634 |
| 2607 } } // namespace v8::internal | 2635 } } // namespace v8::internal |
| OLD | NEW |