| 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 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 : id_(id), executable_(executable) {} | 364 : id_(id), executable_(executable) {} |
| 365 | 365 |
| 366 virtual ~Space() {} | 366 virtual ~Space() {} |
| 367 | 367 |
| 368 // Does the space need executable memory? | 368 // Does the space need executable memory? |
| 369 Executability executable() { return executable_; } | 369 Executability executable() { return executable_; } |
| 370 | 370 |
| 371 // Identity used in error reporting. | 371 // Identity used in error reporting. |
| 372 AllocationSpace identity() { return id_; } | 372 AllocationSpace identity() { return id_; } |
| 373 | 373 |
| 374 virtual int Size() = 0; | 374 virtual intptr_t Size() = 0; |
| 375 | 375 |
| 376 #ifdef ENABLE_HEAP_PROTECTION | 376 #ifdef ENABLE_HEAP_PROTECTION |
| 377 // Protect/unprotect the space by marking it read-only/writable. | 377 // Protect/unprotect the space by marking it read-only/writable. |
| 378 virtual void Protect() = 0; | 378 virtual void Protect() = 0; |
| 379 virtual void Unprotect() = 0; | 379 virtual void Unprotect() = 0; |
| 380 #endif | 380 #endif |
| 381 | 381 |
| 382 #ifdef DEBUG | 382 #ifdef DEBUG |
| 383 virtual void Print() = 0; | 383 virtual void Print() = 0; |
| 384 #endif | 384 #endif |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 // induces a constraint on the order of pages in a linked lists. We say that | 484 // induces a constraint on the order of pages in a linked lists. We say that |
| 485 // pages are linked in the chunk-order if and only if every two consecutive | 485 // pages are linked in the chunk-order if and only if every two consecutive |
| 486 // pages from the same chunk are consecutive in the linked list. | 486 // pages from the same chunk are consecutive in the linked list. |
| 487 // | 487 // |
| 488 | 488 |
| 489 | 489 |
| 490 class MemoryAllocator : public AllStatic { | 490 class MemoryAllocator : public AllStatic { |
| 491 public: | 491 public: |
| 492 // Initializes its internal bookkeeping structures. | 492 // Initializes its internal bookkeeping structures. |
| 493 // Max capacity of the total space. | 493 // Max capacity of the total space. |
| 494 static bool Setup(int max_capacity); | 494 static bool Setup(intptr_t max_capacity); |
| 495 | 495 |
| 496 // Deletes valid chunks. | 496 // Deletes valid chunks. |
| 497 static void TearDown(); | 497 static void TearDown(); |
| 498 | 498 |
| 499 // Reserves an initial address range of virtual memory to be split between | 499 // Reserves an initial address range of virtual memory to be split between |
| 500 // the two new space semispaces, the old space, and the map space. The | 500 // the two new space semispaces, the old space, and the map space. The |
| 501 // memory is not yet committed or assigned to spaces and split into pages. | 501 // memory is not yet committed or assigned to spaces and split into pages. |
| 502 // The initial chunk is unmapped when the memory allocator is torn down. | 502 // The initial chunk is unmapped when the memory allocator is torn down. |
| 503 // This function should only be called when there is not already a reserved | 503 // This function should only be called when there is not already a reserved |
| 504 // initial chunk (initial_chunk_ should be NULL). It returns the start | 504 // initial chunk (initial_chunk_ should be NULL). It returns the start |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 575 | 575 |
| 576 static void AddMemoryAllocationCallback(MemoryAllocationCallback callback, | 576 static void AddMemoryAllocationCallback(MemoryAllocationCallback callback, |
| 577 ObjectSpace space, | 577 ObjectSpace space, |
| 578 AllocationAction action); | 578 AllocationAction action); |
| 579 static void RemoveMemoryAllocationCallback( | 579 static void RemoveMemoryAllocationCallback( |
| 580 MemoryAllocationCallback callback); | 580 MemoryAllocationCallback callback); |
| 581 static bool MemoryAllocationCallbackRegistered( | 581 static bool MemoryAllocationCallbackRegistered( |
| 582 MemoryAllocationCallback callback); | 582 MemoryAllocationCallback callback); |
| 583 | 583 |
| 584 // Returns the maximum available bytes of heaps. | 584 // Returns the maximum available bytes of heaps. |
| 585 static int Available() { return capacity_ < size_ ? 0 : capacity_ - size_; } | 585 static intptr_t Available() { |
| 586 return capacity_ < size_ ? 0 : capacity_ - size_; |
| 587 } |
| 586 | 588 |
| 587 // Returns allocated spaces in bytes. | 589 // Returns allocated spaces in bytes. |
| 588 static int Size() { return size_; } | 590 static intptr_t Size() { return size_; } |
| 589 | 591 |
| 590 // Returns allocated executable spaces in bytes. | 592 // Returns allocated executable spaces in bytes. |
| 591 static int SizeExecutable() { return size_executable_; } | 593 static intptr_t SizeExecutable() { return size_executable_; } |
| 592 | 594 |
| 593 // Returns maximum available bytes that the old space can have. | 595 // Returns maximum available bytes that the old space can have. |
| 594 static int MaxAvailable() { | 596 static intptr_t MaxAvailable() { |
| 595 return (Available() / Page::kPageSize) * Page::kObjectAreaSize; | 597 return (Available() / Page::kPageSize) * Page::kObjectAreaSize; |
| 596 } | 598 } |
| 597 | 599 |
| 598 // Links two pages. | 600 // Links two pages. |
| 599 static inline void SetNextPage(Page* prev, Page* next); | 601 static inline void SetNextPage(Page* prev, Page* next); |
| 600 | 602 |
| 601 // Returns the next page of a given page. | 603 // Returns the next page of a given page. |
| 602 static inline Page* GetNextPage(Page* p); | 604 static inline Page* GetNextPage(Page* p); |
| 603 | 605 |
| 604 // Checks whether a page belongs to a space. | 606 // Checks whether a page belongs to a space. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 642 // 8K * 8K * 16 = 1G bytes. | 644 // 8K * 8K * 16 = 1G bytes. |
| 643 #ifdef V8_TARGET_ARCH_X64 | 645 #ifdef V8_TARGET_ARCH_X64 |
| 644 static const int kPagesPerChunk = 32; | 646 static const int kPagesPerChunk = 32; |
| 645 #else | 647 #else |
| 646 static const int kPagesPerChunk = 16; | 648 static const int kPagesPerChunk = 16; |
| 647 #endif | 649 #endif |
| 648 static const int kChunkSize = kPagesPerChunk * Page::kPageSize; | 650 static const int kChunkSize = kPagesPerChunk * Page::kPageSize; |
| 649 | 651 |
| 650 private: | 652 private: |
| 651 // Maximum space size in bytes. | 653 // Maximum space size in bytes. |
| 652 static int capacity_; | 654 static intptr_t capacity_; |
| 653 | 655 |
| 654 // Allocated space size in bytes. | 656 // Allocated space size in bytes. |
| 655 static int size_; | 657 static intptr_t size_; |
| 656 // Allocated executable space size in bytes. | 658 // Allocated executable space size in bytes. |
| 657 static int size_executable_; | 659 static intptr_t size_executable_; |
| 658 | 660 |
| 659 struct MemoryAllocationCallbackRegistration { | 661 struct MemoryAllocationCallbackRegistration { |
| 660 MemoryAllocationCallbackRegistration(MemoryAllocationCallback callback, | 662 MemoryAllocationCallbackRegistration(MemoryAllocationCallback callback, |
| 661 ObjectSpace space, | 663 ObjectSpace space, |
| 662 AllocationAction action) | 664 AllocationAction action) |
| 663 : callback(callback), space(space), action(action) { | 665 : callback(callback), space(space), action(action) { |
| 664 } | 666 } |
| 665 MemoryAllocationCallback callback; | 667 MemoryAllocationCallback callback; |
| 666 ObjectSpace space; | 668 ObjectSpace space; |
| 667 AllocationAction action; | 669 AllocationAction action; |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 920 | 922 |
| 921 // Reset the allocation statistics (ie, available = capacity with no | 923 // Reset the allocation statistics (ie, available = capacity with no |
| 922 // wasted or allocated bytes). | 924 // wasted or allocated bytes). |
| 923 void Reset() { | 925 void Reset() { |
| 924 available_ = capacity_; | 926 available_ = capacity_; |
| 925 size_ = 0; | 927 size_ = 0; |
| 926 waste_ = 0; | 928 waste_ = 0; |
| 927 } | 929 } |
| 928 | 930 |
| 929 // Accessors for the allocation statistics. | 931 // Accessors for the allocation statistics. |
| 930 int Capacity() { return capacity_; } | 932 intptr_t Capacity() { return capacity_; } |
| 931 int Available() { return available_; } | 933 intptr_t Available() { return available_; } |
| 932 int Size() { return size_; } | 934 intptr_t Size() { return size_; } |
| 933 int Waste() { return waste_; } | 935 intptr_t Waste() { return waste_; } |
| 934 | 936 |
| 935 // Grow the space by adding available bytes. | 937 // Grow the space by adding available bytes. |
| 936 void ExpandSpace(int size_in_bytes) { | 938 void ExpandSpace(int size_in_bytes) { |
| 937 capacity_ += size_in_bytes; | 939 capacity_ += size_in_bytes; |
| 938 available_ += size_in_bytes; | 940 available_ += size_in_bytes; |
| 939 } | 941 } |
| 940 | 942 |
| 941 // Shrink the space by removing available bytes. | 943 // Shrink the space by removing available bytes. |
| 942 void ShrinkSpace(int size_in_bytes) { | 944 void ShrinkSpace(int size_in_bytes) { |
| 943 capacity_ -= size_in_bytes; | 945 capacity_ -= size_in_bytes; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 963 } | 965 } |
| 964 | 966 |
| 965 // Consider the wasted bytes to be allocated, as they contain filler | 967 // Consider the wasted bytes to be allocated, as they contain filler |
| 966 // objects (waste -> size). | 968 // objects (waste -> size). |
| 967 void FillWastedBytes(int size_in_bytes) { | 969 void FillWastedBytes(int size_in_bytes) { |
| 968 waste_ -= size_in_bytes; | 970 waste_ -= size_in_bytes; |
| 969 size_ += size_in_bytes; | 971 size_ += size_in_bytes; |
| 970 } | 972 } |
| 971 | 973 |
| 972 private: | 974 private: |
| 973 int capacity_; | 975 intptr_t capacity_; |
| 974 int available_; | 976 intptr_t available_; |
| 975 int size_; | 977 intptr_t size_; |
| 976 int waste_; | 978 intptr_t waste_; |
| 977 }; | 979 }; |
| 978 | 980 |
| 979 | 981 |
| 980 class PagedSpace : public Space { | 982 class PagedSpace : public Space { |
| 981 public: | 983 public: |
| 982 // Creates a space with a maximum capacity, and an id. | 984 // Creates a space with a maximum capacity, and an id. |
| 983 PagedSpace(int max_capacity, AllocationSpace id, Executability executable); | 985 PagedSpace(intptr_t max_capacity, |
| 986 AllocationSpace id, |
| 987 Executability executable); |
| 984 | 988 |
| 985 virtual ~PagedSpace() {} | 989 virtual ~PagedSpace() {} |
| 986 | 990 |
| 987 // Set up the space using the given address range of virtual memory (from | 991 // Set up the space using the given address range of virtual memory (from |
| 988 // the memory allocator's initial chunk) if possible. If the block of | 992 // the memory allocator's initial chunk) if possible. If the block of |
| 989 // addresses is not big enough to contain a single page-aligned page, a | 993 // addresses is not big enough to contain a single page-aligned page, a |
| 990 // fresh chunk will be allocated. | 994 // fresh chunk will be allocated. |
| 991 bool Setup(Address start, size_t size); | 995 bool Setup(Address start, size_t size); |
| 992 | 996 |
| 993 // Returns true if the space has been successfully set up and not | 997 // Returns true if the space has been successfully set up and not |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1024 | 1028 |
| 1025 // The limit of allocation for a page in this space. | 1029 // The limit of allocation for a page in this space. |
| 1026 virtual Address PageAllocationLimit(Page* page) = 0; | 1030 virtual Address PageAllocationLimit(Page* page) = 0; |
| 1027 | 1031 |
| 1028 void FlushTopPageWatermark() { | 1032 void FlushTopPageWatermark() { |
| 1029 AllocationTopPage()->SetCachedAllocationWatermark(top()); | 1033 AllocationTopPage()->SetCachedAllocationWatermark(top()); |
| 1030 AllocationTopPage()->InvalidateWatermark(true); | 1034 AllocationTopPage()->InvalidateWatermark(true); |
| 1031 } | 1035 } |
| 1032 | 1036 |
| 1033 // Current capacity without growing (Size() + Available() + Waste()). | 1037 // Current capacity without growing (Size() + Available() + Waste()). |
| 1034 int Capacity() { return accounting_stats_.Capacity(); } | 1038 intptr_t Capacity() { return accounting_stats_.Capacity(); } |
| 1035 | 1039 |
| 1036 // Total amount of memory committed for this space. For paged | 1040 // Total amount of memory committed for this space. For paged |
| 1037 // spaces this equals the capacity. | 1041 // spaces this equals the capacity. |
| 1038 int CommittedMemory() { return Capacity(); } | 1042 intptr_t CommittedMemory() { return Capacity(); } |
| 1039 | 1043 |
| 1040 // Available bytes without growing. | 1044 // Available bytes without growing. |
| 1041 int Available() { return accounting_stats_.Available(); } | 1045 intptr_t Available() { return accounting_stats_.Available(); } |
| 1042 | 1046 |
| 1043 // Allocated bytes in this space. | 1047 // Allocated bytes in this space. |
| 1044 virtual int Size() { return accounting_stats_.Size(); } | 1048 virtual intptr_t Size() { return accounting_stats_.Size(); } |
| 1045 | 1049 |
| 1046 // Wasted bytes due to fragmentation and not recoverable until the | 1050 // Wasted bytes due to fragmentation and not recoverable until the |
| 1047 // next GC of this space. | 1051 // next GC of this space. |
| 1048 int Waste() { return accounting_stats_.Waste(); } | 1052 intptr_t Waste() { return accounting_stats_.Waste(); } |
| 1049 | 1053 |
| 1050 // Returns the address of the first object in this space. | 1054 // Returns the address of the first object in this space. |
| 1051 Address bottom() { return first_page_->ObjectAreaStart(); } | 1055 Address bottom() { return first_page_->ObjectAreaStart(); } |
| 1052 | 1056 |
| 1053 // Returns the allocation pointer in this space. | 1057 // Returns the allocation pointer in this space. |
| 1054 Address top() { return allocation_info_.top; } | 1058 Address top() { return allocation_info_.top; } |
| 1055 | 1059 |
| 1056 // Allocate the requested number of bytes in the space if possible, return a | 1060 // Allocate the requested number of bytes in the space if possible, return a |
| 1057 // failure object if not. | 1061 // failure object if not. |
| 1058 inline Object* AllocateRaw(int size_in_bytes); | 1062 inline Object* AllocateRaw(int size_in_bytes); |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1321 return (reinterpret_cast<uintptr_t>(o) & object_mask_) == object_expected_; | 1325 return (reinterpret_cast<uintptr_t>(o) & object_mask_) == object_expected_; |
| 1322 } | 1326 } |
| 1323 | 1327 |
| 1324 // The offset of an address from the beginning of the space. | 1328 // The offset of an address from the beginning of the space. |
| 1325 int SpaceOffsetForAddress(Address addr) { | 1329 int SpaceOffsetForAddress(Address addr) { |
| 1326 return static_cast<int>(addr - low()); | 1330 return static_cast<int>(addr - low()); |
| 1327 } | 1331 } |
| 1328 | 1332 |
| 1329 // If we don't have these here then SemiSpace will be abstract. However | 1333 // If we don't have these here then SemiSpace will be abstract. However |
| 1330 // they should never be called. | 1334 // they should never be called. |
| 1331 virtual int Size() { | 1335 virtual intptr_t Size() { |
| 1332 UNREACHABLE(); | 1336 UNREACHABLE(); |
| 1333 return 0; | 1337 return 0; |
| 1334 } | 1338 } |
| 1335 | 1339 |
| 1336 virtual bool ReserveSpace(int bytes) { | 1340 virtual bool ReserveSpace(int bytes) { |
| 1337 UNREACHABLE(); | 1341 UNREACHABLE(); |
| 1338 return false; | 1342 return false; |
| 1339 } | 1343 } |
| 1340 | 1344 |
| 1341 bool is_committed() { return committed_; } | 1345 bool is_committed() { return committed_; } |
| 1342 bool Commit(); | 1346 bool Commit(); |
| 1343 bool Uncommit(); | 1347 bool Uncommit(); |
| 1344 | 1348 |
| 1345 #ifdef ENABLE_HEAP_PROTECTION | 1349 #ifdef ENABLE_HEAP_PROTECTION |
| 1346 // Protect/unprotect the space by marking it read-only/writable. | 1350 // Protect/unprotect the space by marking it read-only/writable. |
| 1347 virtual void Protect() {} | 1351 virtual void Protect() {} |
| 1348 virtual void Unprotect() {} | 1352 virtual void Unprotect() {} |
| 1349 #endif | 1353 #endif |
| 1350 | 1354 |
| 1351 #ifdef DEBUG | 1355 #ifdef DEBUG |
| 1352 virtual void Print(); | 1356 virtual void Print(); |
| 1353 virtual void Verify(); | 1357 virtual void Verify(); |
| 1354 #endif | 1358 #endif |
| 1355 | 1359 |
| 1356 // Returns the current capacity of the semi space. | 1360 // Returns the current capacity of the semi space. |
| 1357 int Capacity() { return capacity_; } | 1361 intptr_t Capacity() { return capacity_; } |
| 1358 | 1362 |
| 1359 // Returns the maximum capacity of the semi space. | 1363 // Returns the maximum capacity of the semi space. |
| 1360 int MaximumCapacity() { return maximum_capacity_; } | 1364 int MaximumCapacity() { return maximum_capacity_; } |
| 1361 | 1365 |
| 1362 // Returns the initial capacity of the semi space. | 1366 // Returns the initial capacity of the semi space. |
| 1363 int InitialCapacity() { return initial_capacity_; } | 1367 int InitialCapacity() { return initial_capacity_; } |
| 1364 | 1368 |
| 1365 private: | 1369 private: |
| 1366 // The current and maximum capacity of the space. | 1370 // The current and maximum capacity of the space. |
| 1367 int capacity_; | 1371 int capacity_; |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1464 // semispace (not necessarily below the allocation pointer). | 1468 // semispace (not necessarily below the allocation pointer). |
| 1465 bool Contains(Address a) { | 1469 bool Contains(Address a) { |
| 1466 return (reinterpret_cast<uintptr_t>(a) & address_mask_) | 1470 return (reinterpret_cast<uintptr_t>(a) & address_mask_) |
| 1467 == reinterpret_cast<uintptr_t>(start_); | 1471 == reinterpret_cast<uintptr_t>(start_); |
| 1468 } | 1472 } |
| 1469 bool Contains(Object* o) { | 1473 bool Contains(Object* o) { |
| 1470 return (reinterpret_cast<uintptr_t>(o) & object_mask_) == object_expected_; | 1474 return (reinterpret_cast<uintptr_t>(o) & object_mask_) == object_expected_; |
| 1471 } | 1475 } |
| 1472 | 1476 |
| 1473 // Return the allocated bytes in the active semispace. | 1477 // Return the allocated bytes in the active semispace. |
| 1474 virtual int Size() { return static_cast<int>(top() - bottom()); } | 1478 virtual intptr_t Size() { return static_cast<int>(top() - bottom()); } |
| 1475 | 1479 |
| 1476 // Return the current capacity of a semispace. | 1480 // Return the current capacity of a semispace. |
| 1477 int Capacity() { | 1481 intptr_t Capacity() { |
| 1478 ASSERT(to_space_.Capacity() == from_space_.Capacity()); | 1482 ASSERT(to_space_.Capacity() == from_space_.Capacity()); |
| 1479 return to_space_.Capacity(); | 1483 return to_space_.Capacity(); |
| 1480 } | 1484 } |
| 1481 | 1485 |
| 1482 // Return the total amount of memory committed for new space. | 1486 // Return the total amount of memory committed for new space. |
| 1483 int CommittedMemory() { | 1487 intptr_t CommittedMemory() { |
| 1484 if (from_space_.is_committed()) return 2 * Capacity(); | 1488 if (from_space_.is_committed()) return 2 * Capacity(); |
| 1485 return Capacity(); | 1489 return Capacity(); |
| 1486 } | 1490 } |
| 1487 | 1491 |
| 1488 // Return the available bytes without growing in the active semispace. | 1492 // Return the available bytes without growing in the active semispace. |
| 1489 int Available() { return Capacity() - Size(); } | 1493 intptr_t Available() { return Capacity() - Size(); } |
| 1490 | 1494 |
| 1491 // Return the maximum capacity of a semispace. | 1495 // Return the maximum capacity of a semispace. |
| 1492 int MaximumCapacity() { | 1496 int MaximumCapacity() { |
| 1493 ASSERT(to_space_.MaximumCapacity() == from_space_.MaximumCapacity()); | 1497 ASSERT(to_space_.MaximumCapacity() == from_space_.MaximumCapacity()); |
| 1494 return to_space_.MaximumCapacity(); | 1498 return to_space_.MaximumCapacity(); |
| 1495 } | 1499 } |
| 1496 | 1500 |
| 1497 // Returns the initial capacity of a semispace. | 1501 // Returns the initial capacity of a semispace. |
| 1498 int InitialCapacity() { | 1502 intptr_t InitialCapacity() { |
| 1499 ASSERT(to_space_.InitialCapacity() == from_space_.InitialCapacity()); | 1503 ASSERT(to_space_.InitialCapacity() == from_space_.InitialCapacity()); |
| 1500 return to_space_.InitialCapacity(); | 1504 return to_space_.InitialCapacity(); |
| 1501 } | 1505 } |
| 1502 | 1506 |
| 1503 // Return the address of the allocation pointer in the active semispace. | 1507 // Return the address of the allocation pointer in the active semispace. |
| 1504 Address top() { return allocation_info_.top; } | 1508 Address top() { return allocation_info_.top; } |
| 1505 // Return the address of the first object in the active semispace. | 1509 // Return the address of the first object in the active semispace. |
| 1506 Address bottom() { return to_space_.low(); } | 1510 Address bottom() { return to_space_.low(); } |
| 1507 | 1511 |
| 1508 // Get the age mark of the inactive semispace. | 1512 // Get the age mark of the inactive semispace. |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1674 | 1678 |
| 1675 // The free list for the old space. | 1679 // The free list for the old space. |
| 1676 class OldSpaceFreeList BASE_EMBEDDED { | 1680 class OldSpaceFreeList BASE_EMBEDDED { |
| 1677 public: | 1681 public: |
| 1678 explicit OldSpaceFreeList(AllocationSpace owner); | 1682 explicit OldSpaceFreeList(AllocationSpace owner); |
| 1679 | 1683 |
| 1680 // Clear the free list. | 1684 // Clear the free list. |
| 1681 void Reset(); | 1685 void Reset(); |
| 1682 | 1686 |
| 1683 // Return the number of bytes available on the free list. | 1687 // Return the number of bytes available on the free list. |
| 1684 int available() { return available_; } | 1688 intptr_t available() { return available_; } |
| 1685 | 1689 |
| 1686 // Place a node on the free list. The block of size 'size_in_bytes' | 1690 // Place a node on the free list. The block of size 'size_in_bytes' |
| 1687 // starting at 'start' is placed on the free list. The return value is the | 1691 // starting at 'start' is placed on the free list. The return value is the |
| 1688 // number of bytes that have been lost due to internal fragmentation by | 1692 // number of bytes that have been lost due to internal fragmentation by |
| 1689 // freeing the block. Bookkeeping information will be written to the block, | 1693 // freeing the block. Bookkeeping information will be written to the block, |
| 1690 // ie, its contents will be destroyed. The start address should be word | 1694 // ie, its contents will be destroyed. The start address should be word |
| 1691 // aligned, and the size should be a non-zero multiple of the word size. | 1695 // aligned, and the size should be a non-zero multiple of the word size. |
| 1692 int Free(Address start, int size_in_bytes); | 1696 int Free(Address start, int size_in_bytes); |
| 1693 | 1697 |
| 1694 // Allocate a block of size 'size_in_bytes' from the free list. The block | 1698 // Allocate a block of size 'size_in_bytes' from the free list. The block |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1776 | 1780 |
| 1777 // The free list for the map space. | 1781 // The free list for the map space. |
| 1778 class FixedSizeFreeList BASE_EMBEDDED { | 1782 class FixedSizeFreeList BASE_EMBEDDED { |
| 1779 public: | 1783 public: |
| 1780 FixedSizeFreeList(AllocationSpace owner, int object_size); | 1784 FixedSizeFreeList(AllocationSpace owner, int object_size); |
| 1781 | 1785 |
| 1782 // Clear the free list. | 1786 // Clear the free list. |
| 1783 void Reset(); | 1787 void Reset(); |
| 1784 | 1788 |
| 1785 // Return the number of bytes available on the free list. | 1789 // Return the number of bytes available on the free list. |
| 1786 int available() { return available_; } | 1790 intptr_t available() { return available_; } |
| 1787 | 1791 |
| 1788 // Place a node on the free list. The block starting at 'start' (assumed to | 1792 // Place a node on the free list. The block starting at 'start' (assumed to |
| 1789 // have size object_size_) is placed on the free list. Bookkeeping | 1793 // have size object_size_) is placed on the free list. Bookkeeping |
| 1790 // information will be written to the block, ie, its contents will be | 1794 // information will be written to the block, ie, its contents will be |
| 1791 // destroyed. The start address should be word aligned. | 1795 // destroyed. The start address should be word aligned. |
| 1792 void Free(Address start); | 1796 void Free(Address start); |
| 1793 | 1797 |
| 1794 // Allocate a fixed sized block from the free list. The block is unitialized. | 1798 // Allocate a fixed sized block from the free list. The block is unitialized. |
| 1795 // A failure is returned if no block is available. | 1799 // A failure is returned if no block is available. |
| 1796 Object* Allocate(); | 1800 Object* Allocate(); |
| 1797 | 1801 |
| 1798 private: | 1802 private: |
| 1799 // Available bytes on the free list. | 1803 // Available bytes on the free list. |
| 1800 int available_; | 1804 intptr_t available_; |
| 1801 | 1805 |
| 1802 // The head of the free list. | 1806 // The head of the free list. |
| 1803 Address head_; | 1807 Address head_; |
| 1804 | 1808 |
| 1805 // The tail of the free list. | 1809 // The tail of the free list. |
| 1806 Address tail_; | 1810 Address tail_; |
| 1807 | 1811 |
| 1808 // The identity of the owning space, for building allocation Failure | 1812 // The identity of the owning space, for building allocation Failure |
| 1809 // objects. | 1813 // objects. |
| 1810 AllocationSpace owner_; | 1814 AllocationSpace owner_; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1825 // The constructor does not allocate pages from OS. | 1829 // The constructor does not allocate pages from OS. |
| 1826 explicit OldSpace(int max_capacity, | 1830 explicit OldSpace(int max_capacity, |
| 1827 AllocationSpace id, | 1831 AllocationSpace id, |
| 1828 Executability executable) | 1832 Executability executable) |
| 1829 : PagedSpace(max_capacity, id, executable), free_list_(id) { | 1833 : PagedSpace(max_capacity, id, executable), free_list_(id) { |
| 1830 page_extra_ = 0; | 1834 page_extra_ = 0; |
| 1831 } | 1835 } |
| 1832 | 1836 |
| 1833 // The bytes available on the free list (ie, not above the linear allocation | 1837 // The bytes available on the free list (ie, not above the linear allocation |
| 1834 // pointer). | 1838 // pointer). |
| 1835 int AvailableFree() { return free_list_.available(); } | 1839 intptr_t AvailableFree() { return free_list_.available(); } |
| 1836 | 1840 |
| 1837 // The limit of allocation for a page in this space. | 1841 // The limit of allocation for a page in this space. |
| 1838 virtual Address PageAllocationLimit(Page* page) { | 1842 virtual Address PageAllocationLimit(Page* page) { |
| 1839 return page->ObjectAreaEnd(); | 1843 return page->ObjectAreaEnd(); |
| 1840 } | 1844 } |
| 1841 | 1845 |
| 1842 // Give a block of memory to the space's free list. It might be added to | 1846 // Give a block of memory to the space's free list. It might be added to |
| 1843 // the free list or accounted as waste. | 1847 // the free list or accounted as waste. |
| 1844 // If add_to_freelist is false then just accounting stats are updated and | 1848 // If add_to_freelist is false then just accounting stats are updated and |
| 1845 // no attempt to add area to free list is made. | 1849 // no attempt to add area to free list is made. |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2158 void TearDown(); | 2162 void TearDown(); |
| 2159 | 2163 |
| 2160 // Allocates a (non-FixedArray, non-Code) large object. | 2164 // Allocates a (non-FixedArray, non-Code) large object. |
| 2161 Object* AllocateRaw(int size_in_bytes); | 2165 Object* AllocateRaw(int size_in_bytes); |
| 2162 // Allocates a large Code object. | 2166 // Allocates a large Code object. |
| 2163 Object* AllocateRawCode(int size_in_bytes); | 2167 Object* AllocateRawCode(int size_in_bytes); |
| 2164 // Allocates a large FixedArray. | 2168 // Allocates a large FixedArray. |
| 2165 Object* AllocateRawFixedArray(int size_in_bytes); | 2169 Object* AllocateRawFixedArray(int size_in_bytes); |
| 2166 | 2170 |
| 2167 // Available bytes for objects in this space. | 2171 // Available bytes for objects in this space. |
| 2168 int Available() { | 2172 intptr_t Available() { |
| 2169 return LargeObjectChunk::ObjectSizeFor(MemoryAllocator::Available()); | 2173 return LargeObjectChunk::ObjectSizeFor(MemoryAllocator::Available()); |
| 2170 } | 2174 } |
| 2171 | 2175 |
| 2172 virtual int Size() { | 2176 virtual intptr_t Size() { |
| 2173 return size_; | 2177 return size_; |
| 2174 } | 2178 } |
| 2175 | 2179 |
| 2176 int PageCount() { | 2180 int PageCount() { |
| 2177 return page_count_; | 2181 return page_count_; |
| 2178 } | 2182 } |
| 2179 | 2183 |
| 2180 // Finds an object for a given address, returns Failure::Exception() | 2184 // Finds an object for a given address, returns Failure::Exception() |
| 2181 // if it is not found. The function iterates through all objects in this | 2185 // if it is not found. The function iterates through all objects in this |
| 2182 // space, may be slow. | 2186 // space, may be slow. |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2216 void ReportStatistics(); | 2220 void ReportStatistics(); |
| 2217 void CollectCodeStatistics(); | 2221 void CollectCodeStatistics(); |
| 2218 #endif | 2222 #endif |
| 2219 // Checks whether an address is in the object area in this space. It | 2223 // Checks whether an address is in the object area in this space. It |
| 2220 // iterates all objects in the space. May be slow. | 2224 // iterates all objects in the space. May be slow. |
| 2221 bool SlowContains(Address addr) { return !FindObject(addr)->IsFailure(); } | 2225 bool SlowContains(Address addr) { return !FindObject(addr)->IsFailure(); } |
| 2222 | 2226 |
| 2223 private: | 2227 private: |
| 2224 // The head of the linked list of large object chunks. | 2228 // The head of the linked list of large object chunks. |
| 2225 LargeObjectChunk* first_chunk_; | 2229 LargeObjectChunk* first_chunk_; |
| 2226 int size_; // allocated bytes | 2230 intptr_t size_; // allocated bytes |
| 2227 int page_count_; // number of chunks | 2231 int page_count_; // number of chunks |
| 2228 | 2232 |
| 2229 | 2233 |
| 2230 // Shared implementation of AllocateRaw, AllocateRawCode and | 2234 // Shared implementation of AllocateRaw, AllocateRawCode and |
| 2231 // AllocateRawFixedArray. | 2235 // AllocateRawFixedArray. |
| 2232 Object* AllocateRawInternal(int requested_size, | 2236 Object* AllocateRawInternal(int requested_size, |
| 2233 int object_size, | 2237 int object_size, |
| 2234 Executability executable); | 2238 Executability executable); |
| 2235 | 2239 |
| 2236 friend class LargeObjectIterator; | 2240 friend class LargeObjectIterator; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 2252 | 2256 |
| 2253 private: | 2257 private: |
| 2254 LargeObjectChunk* current_; | 2258 LargeObjectChunk* current_; |
| 2255 HeapObjectCallback size_func_; | 2259 HeapObjectCallback size_func_; |
| 2256 }; | 2260 }; |
| 2257 | 2261 |
| 2258 | 2262 |
| 2259 } } // namespace v8::internal | 2263 } } // namespace v8::internal |
| 2260 | 2264 |
| 2261 #endif // V8_SPACES_H_ | 2265 #endif // V8_SPACES_H_ |
| OLD | NEW |