OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/heap/spaces.h" | 5 #include "src/heap/spaces.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "src/base/bits.h" | 9 #include "src/base/bits.h" |
10 #include "src/base/platform/platform.h" | 10 #include "src/base/platform/platform.h" |
(...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
625 chunk->area_end_ -= bytes_to_shrink; | 625 chunk->area_end_ -= bytes_to_shrink; |
626 UncommitBlock(free_start, bytes_to_shrink); | 626 UncommitBlock(free_start, bytes_to_shrink); |
627 if (chunk->IsFlagSet(MemoryChunk::IS_EXECUTABLE)) { | 627 if (chunk->IsFlagSet(MemoryChunk::IS_EXECUTABLE)) { |
628 if (chunk->reservation_.IsReserved()) | 628 if (chunk->reservation_.IsReserved()) |
629 chunk->reservation_.Guard(chunk->area_end_); | 629 chunk->reservation_.Guard(chunk->area_end_); |
630 else | 630 else |
631 base::OS::Guard(chunk->area_end_, base::OS::CommitPageSize()); | 631 base::OS::Guard(chunk->area_end_, base::OS::CommitPageSize()); |
632 } | 632 } |
633 } | 633 } |
634 | 634 |
635 MemoryChunk* MemoryAllocator::AllocateChunk(intptr_t reserve_area_size, | 635 MemoryChunk* MemoryAllocator::AllocateChunk(size_t reserve_area_size, |
636 intptr_t commit_area_size, | 636 size_t commit_area_size, |
637 Executability executable, | 637 Executability executable, |
638 Space* owner) { | 638 Space* owner) { |
639 DCHECK(commit_area_size <= reserve_area_size); | 639 DCHECK_LE(commit_area_size, reserve_area_size); |
640 | 640 |
641 size_t chunk_size; | 641 size_t chunk_size; |
642 Heap* heap = isolate_->heap(); | 642 Heap* heap = isolate_->heap(); |
643 Address base = NULL; | 643 Address base = nullptr; |
644 base::VirtualMemory reservation; | 644 base::VirtualMemory reservation; |
645 Address area_start = NULL; | 645 Address area_start = nullptr; |
646 Address area_end = NULL; | 646 Address area_end = nullptr; |
647 | 647 |
648 // | 648 // |
649 // MemoryChunk layout: | 649 // MemoryChunk layout: |
650 // | 650 // |
651 // Executable | 651 // Executable |
652 // +----------------------------+<- base aligned with MemoryChunk::kAlignment | 652 // +----------------------------+<- base aligned with MemoryChunk::kAlignment |
653 // | Header | | 653 // | Header | |
654 // +----------------------------+<- base + CodePageGuardStartOffset | 654 // +----------------------------+<- base + CodePageGuardStartOffset |
655 // | Guard | | 655 // | Guard | |
656 // +----------------------------+<- area_start_ | 656 // +----------------------------+<- area_start_ |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
907 | 907 |
908 template void MemoryAllocator::Free<MemoryAllocator::kFull>(MemoryChunk* chunk); | 908 template void MemoryAllocator::Free<MemoryAllocator::kFull>(MemoryChunk* chunk); |
909 | 909 |
910 template void MemoryAllocator::Free<MemoryAllocator::kPreFreeAndQueue>( | 910 template void MemoryAllocator::Free<MemoryAllocator::kPreFreeAndQueue>( |
911 MemoryChunk* chunk); | 911 MemoryChunk* chunk); |
912 | 912 |
913 template void MemoryAllocator::Free<MemoryAllocator::kPooledAndQueue>( | 913 template void MemoryAllocator::Free<MemoryAllocator::kPooledAndQueue>( |
914 MemoryChunk* chunk); | 914 MemoryChunk* chunk); |
915 | 915 |
916 template <MemoryAllocator::AllocationMode alloc_mode, typename SpaceType> | 916 template <MemoryAllocator::AllocationMode alloc_mode, typename SpaceType> |
917 Page* MemoryAllocator::AllocatePage(intptr_t size, SpaceType* owner, | 917 Page* MemoryAllocator::AllocatePage(size_t size, SpaceType* owner, |
918 Executability executable) { | 918 Executability executable) { |
919 MemoryChunk* chunk = nullptr; | 919 MemoryChunk* chunk = nullptr; |
920 if (alloc_mode == kPooled) { | 920 if (alloc_mode == kPooled) { |
921 DCHECK_EQ(size, static_cast<intptr_t>(MemoryChunk::kAllocatableMemory)); | 921 DCHECK_EQ(size, static_cast<size_t>(MemoryChunk::kAllocatableMemory)); |
922 DCHECK_EQ(executable, NOT_EXECUTABLE); | 922 DCHECK_EQ(executable, NOT_EXECUTABLE); |
923 chunk = AllocatePagePooled(owner); | 923 chunk = AllocatePagePooled(owner); |
924 } | 924 } |
925 if (chunk == nullptr) { | 925 if (chunk == nullptr) { |
926 chunk = AllocateChunk(size, size, executable, owner); | 926 chunk = AllocateChunk(size, size, executable, owner); |
927 } | 927 } |
928 if (chunk == nullptr) return nullptr; | 928 if (chunk == nullptr) return nullptr; |
929 return Page::Initialize(isolate_->heap(), chunk, executable, owner); | 929 return Page::Initialize(isolate_->heap(), chunk, executable, owner); |
930 } | 930 } |
931 | 931 |
932 template Page* | 932 template Page* |
933 MemoryAllocator::AllocatePage<MemoryAllocator::kRegular, PagedSpace>( | 933 MemoryAllocator::AllocatePage<MemoryAllocator::kRegular, PagedSpace>( |
934 intptr_t size, PagedSpace* owner, Executability executable); | 934 size_t size, PagedSpace* owner, Executability executable); |
935 template Page* | 935 template Page* |
936 MemoryAllocator::AllocatePage<MemoryAllocator::kRegular, SemiSpace>( | 936 MemoryAllocator::AllocatePage<MemoryAllocator::kRegular, SemiSpace>( |
937 intptr_t size, SemiSpace* owner, Executability executable); | 937 size_t size, SemiSpace* owner, Executability executable); |
938 template Page* | 938 template Page* |
939 MemoryAllocator::AllocatePage<MemoryAllocator::kPooled, SemiSpace>( | 939 MemoryAllocator::AllocatePage<MemoryAllocator::kPooled, SemiSpace>( |
940 intptr_t size, SemiSpace* owner, Executability executable); | 940 size_t size, SemiSpace* owner, Executability executable); |
941 | 941 |
942 LargePage* MemoryAllocator::AllocateLargePage(intptr_t size, | 942 LargePage* MemoryAllocator::AllocateLargePage(size_t size, |
943 LargeObjectSpace* owner, | 943 LargeObjectSpace* owner, |
944 Executability executable) { | 944 Executability executable) { |
945 MemoryChunk* chunk = AllocateChunk(size, size, executable, owner); | 945 MemoryChunk* chunk = AllocateChunk(size, size, executable, owner); |
946 if (chunk == nullptr) return nullptr; | 946 if (chunk == nullptr) return nullptr; |
947 return LargePage::Initialize(isolate_->heap(), chunk, executable, owner); | 947 return LargePage::Initialize(isolate_->heap(), chunk, executable, owner); |
948 } | 948 } |
949 | 949 |
950 template <typename SpaceType> | 950 template <typename SpaceType> |
951 MemoryChunk* MemoryAllocator::AllocatePagePooled(SpaceType* owner) { | 951 MemoryChunk* MemoryAllocator::AllocatePagePooled(SpaceType* owner) { |
952 MemoryChunk* chunk = unmapper()->TryGetPooledMemoryChunkSafe(); | 952 MemoryChunk* chunk = unmapper()->TryGetPooledMemoryChunkSafe(); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
993 | 993 |
994 #ifdef DEBUG | 994 #ifdef DEBUG |
995 void MemoryAllocator::ReportStatistics() { | 995 void MemoryAllocator::ReportStatistics() { |
996 size_t size = Size(); | 996 size_t size = Size(); |
997 float pct = static_cast<float>(capacity_ - size) / capacity_; | 997 float pct = static_cast<float>(capacity_ - size) / capacity_; |
998 PrintF(" capacity: %zu , used: %" V8PRIdPTR ", available: %%%d\n\n", | 998 PrintF(" capacity: %zu , used: %" V8PRIdPTR ", available: %%%d\n\n", |
999 capacity_, size, static_cast<int>(pct * 100)); | 999 capacity_, size, static_cast<int>(pct * 100)); |
1000 } | 1000 } |
1001 #endif | 1001 #endif |
1002 | 1002 |
1003 | 1003 size_t MemoryAllocator::CodePageGuardStartOffset() { |
1004 int MemoryAllocator::CodePageGuardStartOffset() { | |
1005 // We are guarding code pages: the first OS page after the header | 1004 // We are guarding code pages: the first OS page after the header |
1006 // will be protected as non-writable. | 1005 // will be protected as non-writable. |
1007 return RoundUp(Page::kObjectStartOffset, base::OS::CommitPageSize()); | 1006 return RoundUp(Page::kObjectStartOffset, base::OS::CommitPageSize()); |
1008 } | 1007 } |
1009 | 1008 |
1010 | 1009 size_t MemoryAllocator::CodePageGuardSize() { |
1011 int MemoryAllocator::CodePageGuardSize() { | |
1012 return static_cast<int>(base::OS::CommitPageSize()); | 1010 return static_cast<int>(base::OS::CommitPageSize()); |
1013 } | 1011 } |
1014 | 1012 |
1015 | 1013 size_t MemoryAllocator::CodePageAreaStartOffset() { |
1016 int MemoryAllocator::CodePageAreaStartOffset() { | |
1017 // We are guarding code pages: the first OS page after the header | 1014 // We are guarding code pages: the first OS page after the header |
1018 // will be protected as non-writable. | 1015 // will be protected as non-writable. |
1019 return CodePageGuardStartOffset() + CodePageGuardSize(); | 1016 return CodePageGuardStartOffset() + CodePageGuardSize(); |
1020 } | 1017 } |
1021 | 1018 |
1022 | 1019 size_t MemoryAllocator::CodePageAreaEndOffset() { |
1023 int MemoryAllocator::CodePageAreaEndOffset() { | |
1024 // We are guarding code pages: the last OS page will be protected as | 1020 // We are guarding code pages: the last OS page will be protected as |
1025 // non-writable. | 1021 // non-writable. |
1026 return Page::kPageSize - static_cast<int>(base::OS::CommitPageSize()); | 1022 return Page::kPageSize - static_cast<int>(base::OS::CommitPageSize()); |
1027 } | 1023 } |
1028 | 1024 |
1029 | 1025 |
1030 bool MemoryAllocator::CommitExecutableMemory(base::VirtualMemory* vm, | 1026 bool MemoryAllocator::CommitExecutableMemory(base::VirtualMemory* vm, |
1031 Address start, size_t commit_size, | 1027 Address start, size_t commit_size, |
1032 size_t reserved_size) { | 1028 size_t reserved_size) { |
1033 // Commit page header (not executable). | 1029 // Commit page header (not executable). |
(...skipping 2201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3235 object->ShortPrint(); | 3231 object->ShortPrint(); |
3236 PrintF("\n"); | 3232 PrintF("\n"); |
3237 } | 3233 } |
3238 printf(" --------------------------------------\n"); | 3234 printf(" --------------------------------------\n"); |
3239 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); | 3235 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); |
3240 } | 3236 } |
3241 | 3237 |
3242 #endif // DEBUG | 3238 #endif // DEBUG |
3243 } // namespace internal | 3239 } // namespace internal |
3244 } // namespace v8 | 3240 } // namespace v8 |
OLD | NEW |