| 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 772 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 783 return RoundDown(size, kCodeAlignment); | 783 return RoundDown(size, kCodeAlignment); |
| 784 } else { | 784 } else { |
| 785 return RoundDown(size, kPointerSize); | 785 return RoundDown(size, kPointerSize); |
| 786 } | 786 } |
| 787 } | 787 } |
| 788 | 788 |
| 789 #ifdef DEBUG | 789 #ifdef DEBUG |
| 790 virtual void Print() = 0; | 790 virtual void Print() = 0; |
| 791 #endif | 791 #endif |
| 792 | 792 |
| 793 // After calling this we can allocate a certain number of bytes using only | |
| 794 // linear allocation (with a LinearAllocationScope and an AlwaysAllocateScope) | |
| 795 // without using freelists or causing a GC. This is used by partial | |
| 796 // snapshots. It returns true of space was reserved or false if a GC is | |
| 797 // needed. For paged spaces the space requested must include the space wasted | |
| 798 // at the end of each when allocating linearly. | |
| 799 virtual bool ReserveSpace(int bytes) = 0; | |
| 800 | |
| 801 private: | 793 private: |
| 802 Heap* heap_; | 794 Heap* heap_; |
| 803 AllocationSpace id_; | 795 AllocationSpace id_; |
| 804 Executability executable_; | 796 Executability executable_; |
| 805 }; | 797 }; |
| 806 | 798 |
| 807 | 799 |
| 808 // ---------------------------------------------------------------------------- | 800 // ---------------------------------------------------------------------------- |
| 809 // All heap objects containing executable code (code objects) must be allocated | 801 // All heap objects containing executable code (code objects) must be allocated |
| 810 // from a 2 GB range of memory, so that they can call each other using 32-bit | 802 // from a 2 GB range of memory, so that they can call each other using 32-bit |
| (...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1311 // functions. | 1303 // functions. |
| 1312 void set_size(Heap* heap, int size_in_bytes); | 1304 void set_size(Heap* heap, int size_in_bytes); |
| 1313 | 1305 |
| 1314 // Accessors for the next field. | 1306 // Accessors for the next field. |
| 1315 inline FreeListNode* next(); | 1307 inline FreeListNode* next(); |
| 1316 inline FreeListNode** next_address(); | 1308 inline FreeListNode** next_address(); |
| 1317 inline void set_next(FreeListNode* next); | 1309 inline void set_next(FreeListNode* next); |
| 1318 | 1310 |
| 1319 inline void Zap(); | 1311 inline void Zap(); |
| 1320 | 1312 |
| 1313 static inline FreeListNode* cast(MaybeObject* maybe) { |
| 1314 ASSERT(!maybe->IsFailure()); |
| 1315 return reinterpret_cast<FreeListNode*>(maybe); |
| 1316 } |
| 1317 |
| 1321 private: | 1318 private: |
| 1322 static const int kNextOffset = POINTER_SIZE_ALIGN(FreeSpace::kHeaderSize); | 1319 static const int kNextOffset = POINTER_SIZE_ALIGN(FreeSpace::kHeaderSize); |
| 1323 | 1320 |
| 1324 DISALLOW_IMPLICIT_CONSTRUCTORS(FreeListNode); | 1321 DISALLOW_IMPLICIT_CONSTRUCTORS(FreeListNode); |
| 1325 }; | 1322 }; |
| 1326 | 1323 |
| 1327 | 1324 |
| 1328 // The free list for the old space. The free list is organized in such a way | 1325 // The free list for the old space. The free list is organized in such a way |
| 1329 // as to encourage objects allocated around the same time to be near each | 1326 // as to encourage objects allocated around the same time to be near each |
| 1330 // other. The normal way to allocate is intended to be by bumping a 'top' | 1327 // other. The normal way to allocate is intended to be by bumping a 'top' |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1373 MUST_USE_RESULT HeapObject* Allocate(int size_in_bytes); | 1370 MUST_USE_RESULT HeapObject* Allocate(int size_in_bytes); |
| 1374 | 1371 |
| 1375 #ifdef DEBUG | 1372 #ifdef DEBUG |
| 1376 void Zap(); | 1373 void Zap(); |
| 1377 static intptr_t SumFreeList(FreeListNode* node); | 1374 static intptr_t SumFreeList(FreeListNode* node); |
| 1378 static int FreeListLength(FreeListNode* cur); | 1375 static int FreeListLength(FreeListNode* cur); |
| 1379 intptr_t SumFreeLists(); | 1376 intptr_t SumFreeLists(); |
| 1380 bool IsVeryLong(); | 1377 bool IsVeryLong(); |
| 1381 #endif | 1378 #endif |
| 1382 | 1379 |
| 1380 // Used after booting the VM. |
| 1381 void RepairLists(Heap* heap); |
| 1382 |
| 1383 struct SizeStats { | 1383 struct SizeStats { |
| 1384 intptr_t Total() { | 1384 intptr_t Total() { |
| 1385 return small_size_ + medium_size_ + large_size_ + huge_size_; | 1385 return small_size_ + medium_size_ + large_size_ + huge_size_; |
| 1386 } | 1386 } |
| 1387 | 1387 |
| 1388 intptr_t small_size_; | 1388 intptr_t small_size_; |
| 1389 intptr_t medium_size_; | 1389 intptr_t medium_size_; |
| 1390 intptr_t large_size_; | 1390 intptr_t large_size_; |
| 1391 intptr_t huge_size_; | 1391 intptr_t huge_size_; |
| 1392 }; | 1392 }; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1453 // Checks whether an object/address is in this space. | 1453 // Checks whether an object/address is in this space. |
| 1454 inline bool Contains(Address a); | 1454 inline bool Contains(Address a); |
| 1455 bool Contains(HeapObject* o) { return Contains(o->address()); } | 1455 bool Contains(HeapObject* o) { return Contains(o->address()); } |
| 1456 | 1456 |
| 1457 // Given an address occupied by a live object, return that object if it is | 1457 // Given an address occupied by a live object, return that object if it is |
| 1458 // in this space, or Failure::Exception() if it is not. The implementation | 1458 // in this space, or Failure::Exception() if it is not. The implementation |
| 1459 // iterates over objects in the page containing the address, the cost is | 1459 // iterates over objects in the page containing the address, the cost is |
| 1460 // linear in the number of objects in the page. It may be slow. | 1460 // linear in the number of objects in the page. It may be slow. |
| 1461 MUST_USE_RESULT MaybeObject* FindObject(Address addr); | 1461 MUST_USE_RESULT MaybeObject* FindObject(Address addr); |
| 1462 | 1462 |
| 1463 // During boot the free_space_map is created, and afterwards we may need |
| 1464 // to write it into the free list nodes that were already created. |
| 1465 virtual void RepairFreeListsAfterBoot(); |
| 1466 |
| 1463 // Prepares for a mark-compact GC. | 1467 // Prepares for a mark-compact GC. |
| 1464 virtual void PrepareForMarkCompact(); | 1468 virtual void PrepareForMarkCompact(); |
| 1465 | 1469 |
| 1466 // Current capacity without growing (Size() + Available()). | 1470 // Current capacity without growing (Size() + Available()). |
| 1467 intptr_t Capacity() { return accounting_stats_.Capacity(); } | 1471 intptr_t Capacity() { return accounting_stats_.Capacity(); } |
| 1468 | 1472 |
| 1469 // Total amount of memory committed for this space. For paged | 1473 // Total amount of memory committed for this space. For paged |
| 1470 // spaces this equals the capacity. | 1474 // spaces this equals the capacity. |
| 1471 intptr_t CommittedMemory() { return Capacity(); } | 1475 intptr_t CommittedMemory() { return Capacity(); } |
| 1472 | 1476 |
| (...skipping 1172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2645 } | 2649 } |
| 2646 // Must be small, since an iteration is used for lookup. | 2650 // Must be small, since an iteration is used for lookup. |
| 2647 static const int kMaxComments = 64; | 2651 static const int kMaxComments = 64; |
| 2648 }; | 2652 }; |
| 2649 #endif | 2653 #endif |
| 2650 | 2654 |
| 2651 | 2655 |
| 2652 } } // namespace v8::internal | 2656 } } // namespace v8::internal |
| 2653 | 2657 |
| 2654 #endif // V8_SPACES_H_ | 2658 #endif // V8_SPACES_H_ |
| OLD | NEW |