Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(39)

Side by Side Diff: src/spaces.cc

Issue 9950048: Reduce initial boot-up memory use. This is an other attempt at what (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 547 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 chunk_size, 558 chunk_size,
559 area_start, 559 area_start,
560 area_end, 560 area_end,
561 executable, 561 executable,
562 owner); 562 owner);
563 result->set_reserved_memory(&reservation); 563 result->set_reserved_memory(&reservation);
564 return result; 564 return result;
565 } 565 }
566 566
567 567
568 Page* MemoryAllocator::AllocatePage(PagedSpace* owner, 568 Page* MemoryAllocator::AllocatePage(intptr_t size,
569 PagedSpace* owner,
569 Executability executable) { 570 Executability executable) {
570 MemoryChunk* chunk = AllocateChunk(owner->AreaSize(), 571 MemoryChunk* chunk = AllocateChunk(size, executable, owner);
571 executable,
572 owner);
573 572
574 if (chunk == NULL) return NULL; 573 if (chunk == NULL) return NULL;
575 574
576 return Page::Initialize(isolate_->heap(), chunk, executable, owner); 575 return Page::Initialize(isolate_->heap(), chunk, executable, owner);
577 } 576 }
578 577
579 578
580 LargePage* MemoryAllocator::AllocateLargePage(intptr_t object_size, 579 LargePage* MemoryAllocator::AllocateLargePage(intptr_t object_size,
581 Executability executable, 580 Executability executable,
582 Space* owner) { 581 Space* owner) {
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
826 Address next = cur + obj->Size(); 825 Address next = cur + obj->Size();
827 if ((cur <= addr) && (addr < next)) return obj; 826 if ((cur <= addr) && (addr < next)) return obj;
828 } 827 }
829 828
830 UNREACHABLE(); 829 UNREACHABLE();
831 return Failure::Exception(); 830 return Failure::Exception();
832 } 831 }
833 832
834 bool PagedSpace::CanExpand() { 833 bool PagedSpace::CanExpand() {
835 ASSERT(max_capacity_ % AreaSize() == 0); 834 ASSERT(max_capacity_ % AreaSize() == 0);
836 ASSERT(Capacity() % AreaSize() == 0);
837 835
838 if (Capacity() == max_capacity_) return false; 836 if (Capacity() == max_capacity_) return false;
839 837
840 ASSERT(Capacity() < max_capacity_); 838 ASSERT(Capacity() < max_capacity_);
841 839
842 // Are we going to exceed capacity for this space? 840 // Are we going to exceed capacity for this space?
843 if ((Capacity() + Page::kPageSize) > max_capacity_) return false; 841 if ((Capacity() + Page::kPageSize) > max_capacity_) return false;
844 842
845 return true; 843 return true;
846 } 844 }
847 845
848 bool PagedSpace::Expand() { 846 bool PagedSpace::Expand() {
849 if (!CanExpand()) return false; 847 if (!CanExpand()) return false;
850 848
851 Page* p = heap()->isolate()->memory_allocator()-> 849 intptr_t size = AreaSize();
852 AllocatePage(this, executable()); 850
851 if (anchor_.next_page() == &anchor_) {
852 size = SizeOfFirstPage();
853 }
854
855 Page* p = heap()->isolate()->memory_allocator()->AllocatePage(
856 size, this, executable());
853 if (p == NULL) return false; 857 if (p == NULL) return false;
854 858
855 ASSERT(Capacity() <= max_capacity_); 859 ASSERT(Capacity() <= max_capacity_);
856 860
857 p->InsertAfter(anchor_.prev_page()); 861 p->InsertAfter(anchor_.prev_page());
858 862
859 return true; 863 return true;
860 } 864 }
861 865
862 866
867 intptr_t PagedSpace::SizeOfFirstPage() {
868 int size = 0;
869 void* dummy;
870 switch (identity()) {
871 case OLD_POINTER_SPACE:
872 size = 64 * sizeof(dummy) * KB;
Michael Starzinger 2012/04/02 08:25:05 Why not use kPointerSize here?
873 break;
874 case OLD_DATA_SPACE:
875 size = 192 * KB;
876 break;
877 case MAP_SPACE:
878 size = 128 * KB;
879 break;
880 case CELL_SPACE:
881 size = 96 * KB;
882 break;
883 case CODE_SPACE:
884 if (sizeof(dummy) == 8) {
Michael Starzinger 2012/04/02 08:25:05 Why not use kPointerSize here?
885 // On x64 we allocate code pages in a special way (from the reserved
886 // 2Byte area). That part of the code is not yet upgraded to handle
887 // small pages.
888 size = AreaSize();
889 } else {
890 size = 384 * KB;
891 }
892 break;
893 default:
894 UNREACHABLE();
895 }
896 return Min(size, AreaSize());
897 }
898
899
863 int PagedSpace::CountTotalPages() { 900 int PagedSpace::CountTotalPages() {
864 PageIterator it(this); 901 PageIterator it(this);
865 int count = 0; 902 int count = 0;
866 while (it.has_next()) { 903 while (it.has_next()) {
867 it.next(); 904 it.next();
868 count++; 905 count++;
869 } 906 }
870 return count; 907 return count;
871 } 908 }
872 909
(...skipping 23 matching lines...) Expand all
896 } 933 }
897 934
898 page->Unlink(); 935 page->Unlink();
899 if (page->IsFlagSet(MemoryChunk::CONTAINS_ONLY_DATA)) { 936 if (page->IsFlagSet(MemoryChunk::CONTAINS_ONLY_DATA)) {
900 heap()->isolate()->memory_allocator()->Free(page); 937 heap()->isolate()->memory_allocator()->Free(page);
901 } else { 938 } else {
902 heap()->QueueMemoryChunkForFree(page); 939 heap()->QueueMemoryChunkForFree(page);
903 } 940 }
904 941
905 ASSERT(Capacity() > 0); 942 ASSERT(Capacity() > 0);
906 ASSERT(Capacity() % AreaSize() == 0);
907 accounting_stats_.ShrinkSpace(AreaSize()); 943 accounting_stats_.ShrinkSpace(AreaSize());
908 } 944 }
909 945
910 946
911 void PagedSpace::ReleaseAllUnusedPages() { 947 void PagedSpace::ReleaseAllUnusedPages() {
912 PageIterator it(this); 948 PageIterator it(this);
913 while (it.has_next()) { 949 while (it.has_next()) {
914 Page* page = it.next(); 950 Page* page = it.next();
915 if (!page->WasSwept()) { 951 if (!page->WasSwept()) {
916 if (page->LiveBytes() == 0) ReleasePage(page); 952 if (page->LiveBytes() == 0) ReleasePage(page);
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
1035 1071
1036 to_space_.SetUp(chunk_base_, 1072 to_space_.SetUp(chunk_base_,
1037 initial_semispace_capacity, 1073 initial_semispace_capacity,
1038 maximum_semispace_capacity); 1074 maximum_semispace_capacity);
1039 from_space_.SetUp(chunk_base_ + reserved_semispace_capacity, 1075 from_space_.SetUp(chunk_base_ + reserved_semispace_capacity,
1040 initial_semispace_capacity, 1076 initial_semispace_capacity,
1041 maximum_semispace_capacity); 1077 maximum_semispace_capacity);
1042 if (!to_space_.Commit()) { 1078 if (!to_space_.Commit()) {
1043 return false; 1079 return false;
1044 } 1080 }
1081 ASSERT(!from_space_.is_committed()); // No need to use memory yet.
1045 1082
1046 start_ = chunk_base_; 1083 start_ = chunk_base_;
1047 address_mask_ = ~(2 * reserved_semispace_capacity - 1); 1084 address_mask_ = ~(2 * reserved_semispace_capacity - 1);
1048 object_mask_ = address_mask_ | kHeapObjectTagMask; 1085 object_mask_ = address_mask_ | kHeapObjectTagMask;
1049 object_expected_ = reinterpret_cast<uintptr_t>(start_) | kHeapObjectTag; 1086 object_expected_ = reinterpret_cast<uintptr_t>(start_) | kHeapObjectTag;
1050 1087
1051 ResetAllocationInfo(); 1088 ResetAllocationInfo();
1052 1089
1053 return true; 1090 return true;
1054 } 1091 }
(...skipping 1759 matching lines...) Expand 10 before | Expand all | Expand 10 after
2814 object->ShortPrint(); 2851 object->ShortPrint();
2815 PrintF("\n"); 2852 PrintF("\n");
2816 } 2853 }
2817 printf(" --------------------------------------\n"); 2854 printf(" --------------------------------------\n");
2818 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); 2855 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes());
2819 } 2856 }
2820 2857
2821 #endif // DEBUG 2858 #endif // DEBUG
2822 2859
2823 } } // namespace v8::internal 2860 } } // namespace v8::internal
OLDNEW
« src/spaces.h ('K') | « src/spaces.h ('k') | src/spaces-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698