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 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 // greater than zero. | 360 // greater than zero. |
361 static Page* CommitPages(Address start, size_t size, PagedSpace* owner, | 361 static Page* CommitPages(Address start, size_t size, PagedSpace* owner, |
362 int* num_pages); | 362 int* num_pages); |
363 | 363 |
364 // Commit a contiguous block of memory from the initial chunk. Assumes that | 364 // Commit a contiguous block of memory from the initial chunk. Assumes that |
365 // the address is not NULL, the size is greater than zero, and that the | 365 // the address is not NULL, the size is greater than zero, and that the |
366 // block is contained in the initial chunk. Returns true if it succeeded | 366 // block is contained in the initial chunk. Returns true if it succeeded |
367 // and false otherwise. | 367 // and false otherwise. |
368 static bool CommitBlock(Address start, size_t size, Executability executable); | 368 static bool CommitBlock(Address start, size_t size, Executability executable); |
369 | 369 |
| 370 |
| 371 // Uncommit a contiguous block of memory [start..(start+size)[. |
| 372 // start is not NULL, the size is greater than zero, and the |
| 373 // block is contained in the initial chunk. Returns true if it succeeded |
| 374 // and false otherwise. |
| 375 static bool UncommitBlock(Address start, size_t size); |
| 376 |
370 // Attempts to allocate the requested (non-zero) number of pages from the | 377 // Attempts to allocate the requested (non-zero) number of pages from the |
371 // OS. Fewer pages might be allocated than requested. If it fails to | 378 // OS. Fewer pages might be allocated than requested. If it fails to |
372 // allocate memory for the OS or cannot allocate a single page, this | 379 // allocate memory for the OS or cannot allocate a single page, this |
373 // function returns an invalid page pointer (NULL). The caller must check | 380 // function returns an invalid page pointer (NULL). The caller must check |
374 // whether the returned page is valid (by calling Page::is_valid()). It is | 381 // whether the returned page is valid (by calling Page::is_valid()). It is |
375 // guaranteed that allocated pages have contiguous addresses. The actual | 382 // guaranteed that allocated pages have contiguous addresses. The actual |
376 // number of allocated page is returned in the output parameter | 383 // number of allocated page is returned in the output parameter |
377 // allocated_pages. | 384 // allocated_pages. |
378 static Page* AllocatePages(int requested_pages, int* allocated_pages, | 385 static Page* AllocatePages(int requested_pages, int* allocated_pages, |
379 PagedSpace* owner); | 386 PagedSpace* owner); |
(...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1028 // The offset of an address from the beginning of the space. | 1035 // The offset of an address from the beginning of the space. |
1029 int SpaceOffsetForAddress(Address addr) { return addr - low(); } | 1036 int SpaceOffsetForAddress(Address addr) { return addr - low(); } |
1030 | 1037 |
1031 // If we don't have this here then SemiSpace will be abstract. However | 1038 // If we don't have this here then SemiSpace will be abstract. However |
1032 // it should never be called. | 1039 // it should never be called. |
1033 virtual int Size() { | 1040 virtual int Size() { |
1034 UNREACHABLE(); | 1041 UNREACHABLE(); |
1035 return 0; | 1042 return 0; |
1036 } | 1043 } |
1037 | 1044 |
| 1045 bool is_committed() { return committed_; } |
| 1046 bool Commit(); |
| 1047 bool Uncommit(); |
| 1048 |
1038 #ifdef DEBUG | 1049 #ifdef DEBUG |
1039 virtual void Print(); | 1050 virtual void Print(); |
1040 virtual void Verify(); | 1051 virtual void Verify(); |
1041 #endif | 1052 #endif |
1042 | 1053 |
1043 // Returns the current capacity of the semi space. | 1054 // Returns the current capacity of the semi space. |
1044 int Capacity() { return capacity_; } | 1055 int Capacity() { return capacity_; } |
1045 | 1056 |
1046 private: | 1057 private: |
1047 // The current and maximum capacity of the space. | 1058 // The current and maximum capacity of the space. |
1048 int capacity_; | 1059 int capacity_; |
1049 int maximum_capacity_; | 1060 int maximum_capacity_; |
1050 | 1061 |
1051 // The start address of the space. | 1062 // The start address of the space. |
1052 Address start_; | 1063 Address start_; |
1053 // Used to govern object promotion during mark-compact collection. | 1064 // Used to govern object promotion during mark-compact collection. |
1054 Address age_mark_; | 1065 Address age_mark_; |
1055 | 1066 |
1056 // Masks and comparison values to test for containment in this semispace. | 1067 // Masks and comparison values to test for containment in this semispace. |
1057 uintptr_t address_mask_; | 1068 uintptr_t address_mask_; |
1058 uintptr_t object_mask_; | 1069 uintptr_t object_mask_; |
1059 uintptr_t object_expected_; | 1070 uintptr_t object_expected_; |
1060 | 1071 |
| 1072 bool committed_; |
| 1073 |
1061 public: | 1074 public: |
1062 TRACK_MEMORY("SemiSpace") | 1075 TRACK_MEMORY("SemiSpace") |
1063 }; | 1076 }; |
1064 | 1077 |
1065 | 1078 |
1066 // A SemiSpaceIterator is an ObjectIterator that iterates over the active | 1079 // A SemiSpaceIterator is an ObjectIterator that iterates over the active |
1067 // semispace of the heap's new space. It iterates over the objects in the | 1080 // semispace of the heap's new space. It iterates over the objects in the |
1068 // semispace from a given start address (defaulting to the bottom of the | 1081 // semispace from a given start address (defaulting to the bottom of the |
1069 // semispace) to the top of the semispace. New objects allocated after the | 1082 // semispace) to the top of the semispace. New objects allocated after the |
1070 // iterator is created are not iterated. | 1083 // iterator is created are not iterated. |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1243 // Clears previously collected statistics. | 1256 // Clears previously collected statistics. |
1244 void ClearHistograms(); | 1257 void ClearHistograms(); |
1245 | 1258 |
1246 // Record the allocation or promotion of a heap object. Note that we don't | 1259 // Record the allocation or promotion of a heap object. Note that we don't |
1247 // record every single allocation, but only those that happen in the | 1260 // record every single allocation, but only those that happen in the |
1248 // to space during a scavenge GC. | 1261 // to space during a scavenge GC. |
1249 void RecordAllocation(HeapObject* obj); | 1262 void RecordAllocation(HeapObject* obj); |
1250 void RecordPromotion(HeapObject* obj); | 1263 void RecordPromotion(HeapObject* obj); |
1251 #endif | 1264 #endif |
1252 | 1265 |
| 1266 // Return whether the operation succeded. |
| 1267 bool CommitFromSpaceIfNeeded() { |
| 1268 if (from_space_.is_committed()) return true; |
| 1269 return from_space_.Commit(); |
| 1270 } |
| 1271 |
| 1272 bool UncommitFromSpace() { |
| 1273 if (!from_space_.is_committed()) return true; |
| 1274 return from_space_.Uncommit(); |
| 1275 } |
| 1276 |
1253 private: | 1277 private: |
1254 // The current and maximum capacities of a semispace. | 1278 // The current and maximum capacities of a semispace. |
1255 int capacity_; | 1279 int capacity_; |
1256 int maximum_capacity_; | 1280 int maximum_capacity_; |
1257 | 1281 |
1258 // The semispaces. | 1282 // The semispaces. |
1259 SemiSpace to_space_; | 1283 SemiSpace to_space_; |
1260 SemiSpace from_space_; | 1284 SemiSpace from_space_; |
1261 | 1285 |
1262 // Start address and bit mask for containment testing. | 1286 // Start address and bit mask for containment testing. |
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1812 | 1836 |
1813 private: | 1837 private: |
1814 LargeObjectChunk* current_; | 1838 LargeObjectChunk* current_; |
1815 HeapObjectCallback size_func_; | 1839 HeapObjectCallback size_func_; |
1816 }; | 1840 }; |
1817 | 1841 |
1818 | 1842 |
1819 } } // namespace v8::internal | 1843 } } // namespace v8::internal |
1820 | 1844 |
1821 #endif // V8_SPACES_H_ | 1845 #endif // V8_SPACES_H_ |
OLD | NEW |