| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 } | 384 } |
| 385 | 385 |
| 386 | 386 |
| 387 void Page::InitializeAsAnchor(PagedSpace* owner) { | 387 void Page::InitializeAsAnchor(PagedSpace* owner) { |
| 388 set_owner(owner); | 388 set_owner(owner); |
| 389 set_prev_page(this); | 389 set_prev_page(this); |
| 390 set_next_page(this); | 390 set_next_page(this); |
| 391 } | 391 } |
| 392 | 392 |
| 393 | 393 |
| 394 NewSpacePage* NewSpacePage::Initialize(Heap* heap, Address start) { |
| 395 MemoryChunk* chunk = MemoryChunk::Initialize(heap, |
| 396 start, |
| 397 Page::kPageSize, |
| 398 NOT_EXECUTABLE, |
| 399 heap->new_space()); |
| 400 return static_cast<NewSpacePage*>(chunk); |
| 401 } |
| 402 |
| 403 |
| 394 MemoryChunk* MemoryChunk::Initialize(Heap* heap, | 404 MemoryChunk* MemoryChunk::Initialize(Heap* heap, |
| 395 Address base, | 405 Address base, |
| 396 size_t size, | 406 size_t size, |
| 397 Executability executable, | 407 Executability executable, |
| 398 Space* owner) { | 408 Space* owner) { |
| 399 MemoryChunk* chunk = FromAddress(base); | 409 MemoryChunk* chunk = FromAddress(base); |
| 400 | 410 |
| 401 ASSERT(base == chunk->address()); | 411 ASSERT(base == chunk->address()); |
| 402 | 412 |
| 403 chunk->heap_ = heap; | 413 chunk->heap_ = heap; |
| (...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1006 #endif | 1016 #endif |
| 1007 | 1017 |
| 1008 | 1018 |
| 1009 bool SemiSpace::Commit() { | 1019 bool SemiSpace::Commit() { |
| 1010 ASSERT(!is_committed()); | 1020 ASSERT(!is_committed()); |
| 1011 if (!heap()->isolate()->memory_allocator()->CommitBlock( | 1021 if (!heap()->isolate()->memory_allocator()->CommitBlock( |
| 1012 start_, capacity_, executable())) { | 1022 start_, capacity_, executable())) { |
| 1013 return false; | 1023 return false; |
| 1014 } | 1024 } |
| 1015 committed_ = true; | 1025 committed_ = true; |
| 1026 // FIXME: When more than one page is present, initialize and |
| 1027 // chain them all. |
| 1028 current_page_ = NewSpacePage::Initialize(heap(), start_); |
| 1016 return true; | 1029 return true; |
| 1017 } | 1030 } |
| 1018 | 1031 |
| 1019 | 1032 |
| 1020 bool SemiSpace::Uncommit() { | 1033 bool SemiSpace::Uncommit() { |
| 1021 ASSERT(is_committed()); | 1034 ASSERT(is_committed()); |
| 1022 if (!heap()->isolate()->memory_allocator()->UncommitBlock( | 1035 if (!heap()->isolate()->memory_allocator()->UncommitBlock( |
| 1023 start_, capacity_)) { | 1036 start_, capacity_)) { |
| 1024 return false; | 1037 return false; |
| 1025 } | 1038 } |
| 1026 committed_ = false; | 1039 committed_ = false; |
| 1027 return true; | 1040 return true; |
| 1028 } | 1041 } |
| 1029 | 1042 |
| 1030 | 1043 |
| 1031 // ----------------------------------------------------------------------------- | 1044 // ----------------------------------------------------------------------------- |
| 1032 // SemiSpace implementation | 1045 // SemiSpace implementation |
| 1033 | 1046 |
| 1034 bool SemiSpace::Setup(Address start, | 1047 bool SemiSpace::Setup(Address start, |
| 1035 int initial_capacity, | 1048 int initial_capacity, |
| 1036 int maximum_capacity) { | 1049 int maximum_capacity) { |
| 1037 // Creates a space in the young generation. The constructor does not | 1050 // Creates a space in the young generation. The constructor does not |
| 1038 // allocate memory from the OS. A SemiSpace is given a contiguous chunk of | 1051 // allocate memory from the OS. A SemiSpace is given a contiguous chunk of |
| 1039 // memory of size 'capacity' when set up, and does not grow or shrink | 1052 // memory of size 'capacity' when set up, and does not grow or shrink |
| 1040 // otherwise. In the mark-compact collector, the memory region of the from | 1053 // otherwise. In the mark-compact collector, the memory region of the from |
| 1041 // space is used as the marking stack. It requires contiguous memory | 1054 // space is used as the marking stack. It requires contiguous memory |
| 1042 // addresses. | 1055 // addresses. |
| 1056 ASSERT(maximum_capacity >= Page::kPageSize); |
| 1057 if (initial_capacity < Page::kPageSize) { |
| 1058 initial_capacity = Page::kPageSize; |
| 1059 } else { |
| 1060 initial_capacity &= ~Page::kPageAlignmentMask; |
| 1061 } |
| 1043 initial_capacity_ = initial_capacity; | 1062 initial_capacity_ = initial_capacity; |
| 1044 capacity_ = initial_capacity; | 1063 capacity_ = initial_capacity; |
| 1045 maximum_capacity_ = maximum_capacity; | 1064 maximum_capacity_ = maximum_capacity; |
| 1046 committed_ = false; | 1065 committed_ = false; |
| 1047 | |
| 1048 start_ = start; | 1066 start_ = start; |
| 1049 address_mask_ = ~(maximum_capacity - 1); | 1067 address_mask_ = ~(maximum_capacity - 1); |
| 1050 object_mask_ = address_mask_ | kHeapObjectTagMask; | 1068 object_mask_ = address_mask_ | kHeapObjectTagMask; |
| 1051 object_expected_ = reinterpret_cast<uintptr_t>(start) | kHeapObjectTag; | 1069 object_expected_ = reinterpret_cast<uintptr_t>(start) | kHeapObjectTag; |
| 1052 age_mark_ = start_; | 1070 age_mark_ = start_; |
| 1053 | 1071 |
| 1054 return Commit(); | 1072 return Commit(); |
| 1055 } | 1073 } |
| 1056 | 1074 |
| 1057 | 1075 |
| 1058 void SemiSpace::TearDown() { | 1076 void SemiSpace::TearDown() { |
| 1059 start_ = NULL; | 1077 start_ = NULL; |
| 1060 capacity_ = 0; | 1078 capacity_ = 0; |
| 1061 } | 1079 } |
| 1062 | 1080 |
| 1063 | 1081 |
| 1064 bool SemiSpace::Grow() { | 1082 bool SemiSpace::Grow() { |
| 1083 return false; // FIXME: Temporary hack while semispaces are only one page. |
| 1065 // Double the semispace size but only up to maximum capacity. | 1084 // Double the semispace size but only up to maximum capacity. |
| 1066 int maximum_extra = maximum_capacity_ - capacity_; | 1085 int maximum_extra = maximum_capacity_ - capacity_; |
| 1067 int extra = Min(RoundUp(capacity_, static_cast<int>(OS::AllocateAlignment())), | 1086 int extra = Min(RoundUp(capacity_, static_cast<int>(OS::AllocateAlignment())), |
| 1068 maximum_extra); | 1087 maximum_extra); |
| 1069 if (!heap()->isolate()->memory_allocator()->CommitBlock( | 1088 if (!heap()->isolate()->memory_allocator()->CommitBlock( |
| 1070 high(), extra, executable())) { | 1089 high(), extra, executable())) { |
| 1071 return false; | 1090 return false; |
| 1072 } | 1091 } |
| 1073 capacity_ += extra; | 1092 capacity_ += extra; |
| 1074 return true; | 1093 return true; |
| 1075 } | 1094 } |
| 1076 | 1095 |
| 1077 | 1096 |
| 1078 bool SemiSpace::GrowTo(int new_capacity) { | 1097 bool SemiSpace::GrowTo(int new_capacity) { |
| 1098 return false; // FIXME: Temporary hack while semispaces are only one page. |
| 1079 ASSERT(new_capacity <= maximum_capacity_); | 1099 ASSERT(new_capacity <= maximum_capacity_); |
| 1080 ASSERT(new_capacity > capacity_); | 1100 ASSERT(new_capacity > capacity_); |
| 1081 size_t delta = new_capacity - capacity_; | 1101 size_t delta = new_capacity - capacity_; |
| 1082 ASSERT(IsAligned(delta, OS::AllocateAlignment())); | 1102 ASSERT(IsAligned(delta, OS::AllocateAlignment())); |
| 1083 if (!heap()->isolate()->memory_allocator()->CommitBlock( | 1103 if (!heap()->isolate()->memory_allocator()->CommitBlock( |
| 1084 high(), delta, executable())) { | 1104 high(), delta, executable())) { |
| 1085 return false; | 1105 return false; |
| 1086 } | 1106 } |
| 1087 capacity_ = new_capacity; | 1107 capacity_ = new_capacity; |
| 1088 return true; | 1108 return true; |
| 1089 } | 1109 } |
| 1090 | 1110 |
| 1091 | 1111 |
| 1092 bool SemiSpace::ShrinkTo(int new_capacity) { | 1112 bool SemiSpace::ShrinkTo(int new_capacity) { |
| 1113 return false; // FIXME: Temporary hack while semispaces are only one page. |
| 1093 ASSERT(new_capacity >= initial_capacity_); | 1114 ASSERT(new_capacity >= initial_capacity_); |
| 1094 ASSERT(new_capacity < capacity_); | 1115 ASSERT(new_capacity < capacity_); |
| 1095 size_t delta = capacity_ - new_capacity; | 1116 size_t delta = capacity_ - new_capacity; |
| 1096 ASSERT(IsAligned(delta, OS::AllocateAlignment())); | 1117 ASSERT(IsAligned(delta, OS::AllocateAlignment())); |
| 1097 if (!heap()->isolate()->memory_allocator()->UncommitBlock( | 1118 if (!heap()->isolate()->memory_allocator()->UncommitBlock( |
| 1098 high() - delta, delta)) { | 1119 high() - delta, delta)) { |
| 1099 return false; | 1120 return false; |
| 1100 } | 1121 } |
| 1101 capacity_ = new_capacity; | 1122 capacity_ = new_capacity; |
| 1102 return true; | 1123 return true; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1122 HeapObjectCallback size_func) { | 1143 HeapObjectCallback size_func) { |
| 1123 Initialize(space, space->bottom(), space->top(), size_func); | 1144 Initialize(space, space->bottom(), space->top(), size_func); |
| 1124 } | 1145 } |
| 1125 | 1146 |
| 1126 | 1147 |
| 1127 SemiSpaceIterator::SemiSpaceIterator(NewSpace* space, Address start) { | 1148 SemiSpaceIterator::SemiSpaceIterator(NewSpace* space, Address start) { |
| 1128 Initialize(space, start, space->top(), NULL); | 1149 Initialize(space, start, space->top(), NULL); |
| 1129 } | 1150 } |
| 1130 | 1151 |
| 1131 | 1152 |
| 1132 void SemiSpaceIterator::Initialize(NewSpace* space, Address start, | 1153 void SemiSpaceIterator::Initialize(NewSpace* space, |
| 1154 Address start, |
| 1133 Address end, | 1155 Address end, |
| 1134 HeapObjectCallback size_func) { | 1156 HeapObjectCallback size_func) { |
| 1135 ASSERT(space->ToSpaceContains(start)); | 1157 ASSERT(space->ToSpaceContains(start)); |
| 1136 ASSERT(space->ToSpaceLow() <= end | 1158 ASSERT(space->ToSpaceLow() <= end |
| 1137 && end <= space->ToSpaceHigh()); | 1159 && end <= space->ToSpaceHigh()); |
| 1138 space_ = &space->to_space_; | 1160 space_ = &space->to_space_; |
| 1139 current_ = start; | 1161 current_ = start; |
| 1162 NewSpacePage* page = NewSpacePage::FromAddress(start); |
| 1163 current_page_limit_ = page->body() + page->body_size(); |
| 1164 if (current_page_limit_ > end) current_page_limit_ = end; |
| 1140 limit_ = end; | 1165 limit_ = end; |
| 1141 size_func_ = size_func; | 1166 size_func_ = size_func; |
| 1142 } | 1167 } |
| 1143 | 1168 |
| 1144 | 1169 |
| 1145 #ifdef DEBUG | 1170 #ifdef DEBUG |
| 1146 // heap_histograms is shared, always clear it before using it. | 1171 // heap_histograms is shared, always clear it before using it. |
| 1147 static void ClearHistograms() { | 1172 static void ClearHistograms() { |
| 1148 Isolate* isolate = Isolate::Current(); | 1173 Isolate* isolate = Isolate::Current(); |
| 1149 // We reset the name each time, though it hasn't changed. | 1174 // We reset the name each time, though it hasn't changed. |
| (...skipping 1038 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2188 for (HeapObject* obj = obj_it.next(); obj != NULL; obj = obj_it.next()) { | 2213 for (HeapObject* obj = obj_it.next(); obj != NULL; obj = obj_it.next()) { |
| 2189 if (obj->IsCode()) { | 2214 if (obj->IsCode()) { |
| 2190 Code* code = Code::cast(obj); | 2215 Code* code = Code::cast(obj); |
| 2191 isolate->code_kind_statistics()[code->kind()] += code->Size(); | 2216 isolate->code_kind_statistics()[code->kind()] += code->Size(); |
| 2192 } | 2217 } |
| 2193 } | 2218 } |
| 2194 } | 2219 } |
| 2195 #endif // DEBUG | 2220 #endif // DEBUG |
| 2196 | 2221 |
| 2197 } } // namespace v8::internal | 2222 } } // namespace v8::internal |
| OLD | NEW |