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

Side by Side Diff: src/spaces.h

Issue 7619: - Removed a few indirections by making the two SemiSpaces... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 12 years, 2 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 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 860 matching lines...) Expand 10 before | Expand all | Expand 10 after
871 871
872 // ----------------------------------------------------------------------------- 872 // -----------------------------------------------------------------------------
873 // SemiSpace in young generation 873 // SemiSpace in young generation
874 // 874 //
875 // A semispace is a contiguous chunk of memory. The mark-compact collector 875 // A semispace is a contiguous chunk of memory. The mark-compact collector
876 // uses the memory in the from space as a marking stack when tracing live 876 // uses the memory in the from space as a marking stack when tracing live
877 // objects. 877 // objects.
878 878
879 class SemiSpace : public Space { 879 class SemiSpace : public Space {
880 public: 880 public:
881 // Creates a space in the young generation. The constructor does not 881 // Constructor.
882 // allocate memory from the OS. A SemiSpace is given a contiguous chunk of 882 SemiSpace() :Space(NEW_SPACE, NOT_EXECUTABLE) {
Kevin Millikin (Chromium) 2008/10/17 09:02:41 A space (character) before 'Space'?
883 // memory of size 'capacity' when set up, and does not grow or shrink 883 start_ = NULL;
884 // otherwise. In the mark-compact collector, the memory region of the from 884 age_mark_ = NULL;
885 // space is used as the marking stack. It requires contiguous memory 885 }
886 // addresses.
887 SemiSpace(int initial_capacity,
888 int maximum_capacity,
889 AllocationSpace id);
890 virtual ~SemiSpace() {}
891 886
892 // Sets up the semispace using the given chunk. 887 // Sets up the semispace using the given chunk.
893 bool Setup(Address start, int size); 888 bool Setup(Address start, int initial_capacity, int maximum_capacity);
894 889
895 // Tear down the space. Heap memory was not allocated by the space, so it 890 // Tear down the space. Heap memory was not allocated by the space, so it
896 // is not deallocated here. 891 // is not deallocated here.
897 void TearDown(); 892 void TearDown();
898 893
899 // True if the space has been set up but not torn down. 894 // True if the space has been set up but not torn down.
900 bool HasBeenSetup() { return start_ != NULL; } 895 bool HasBeenSetup() { return start_ != NULL; }
901 896
902 // Double the size of the semispace by committing extra virtual memory. 897 // Double the size of the semispace by committing extra virtual memory.
903 // Assumes that the caller has checked that the semispace has not reached 898 // Assumes that the caller has checked that the semispace has not reached
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
1009 1004
1010 1005
1011 // ----------------------------------------------------------------------------- 1006 // -----------------------------------------------------------------------------
1012 // The young generation space. 1007 // The young generation space.
1013 // 1008 //
1014 // The new space consists of a contiguous pair of semispaces. It simply 1009 // The new space consists of a contiguous pair of semispaces. It simply
1015 // forwards most functions to the appropriate semispace. 1010 // forwards most functions to the appropriate semispace.
1016 1011
1017 class NewSpace : public Space { 1012 class NewSpace : public Space {
1018 public: 1013 public:
1019 // Create a new space with a given allocation capacity (ie, the capacity of 1014 // Constructor.
1020 // *one* of the semispaces). The constructor does not allocate heap memory 1015 NewSpace() : Space(NEW_SPACE, NOT_EXECUTABLE) {}
1021 // from the OS. When the space is set up, it is given a contiguous chunk of
1022 // memory of size 2 * semispace_capacity. To support fast containment
1023 // testing in the new space, the size of this chunk must be a power of two
1024 // and it must be aligned to its size.
1025 NewSpace(int initial_semispace_capacity,
1026 int maximum_semispace_capacity,
1027 AllocationSpace id);
1028 virtual ~NewSpace() {}
1029 1016
1030 // Sets up the new space using the given chunk. 1017 // Sets up the new space using the given chunk.
1031 bool Setup(Address start, int size); 1018 bool Setup(Address start, int size);
1032 1019
1033 // Tears down the space. Heap memory was not allocated by the space, so it 1020 // Tears down the space. Heap memory was not allocated by the space, so it
1034 // is not deallocated here. 1021 // is not deallocated here.
1035 void TearDown(); 1022 void TearDown();
1036 1023
1037 // True if the space has been set up but not torn down. 1024 // True if the space has been set up but not torn down.
1038 bool HasBeenSetup() { 1025 bool HasBeenSetup() {
1039 return to_space_->HasBeenSetup() && from_space_->HasBeenSetup(); 1026 return to_space_.HasBeenSetup() && from_space_.HasBeenSetup();
1040 } 1027 }
1041 1028
1042 // Flip the pair of spaces. 1029 // Flip the pair of spaces.
1043 void Flip(); 1030 void Flip();
1044 1031
1045 // Doubles the capacity of the semispaces. Assumes that they are not at 1032 // Doubles the capacity of the semispaces. Assumes that they are not at
1046 // their maximum capacity. Returns a flag indicating success or failure. 1033 // their maximum capacity. Returns a flag indicating success or failure.
1047 bool Double(); 1034 bool Double();
1048 1035
1049 // True if the address or object lies in the address range of either 1036 // True if the address or object lies in the address range of either
(...skipping 12 matching lines...) Expand all
1062 int Capacity() { return capacity_; } 1049 int Capacity() { return capacity_; }
1063 // Return the available bytes without growing in the active semispace. 1050 // Return the available bytes without growing in the active semispace.
1064 int Available() { return Capacity() - Size(); } 1051 int Available() { return Capacity() - Size(); }
1065 1052
1066 // Return the maximum capacity of a semispace. 1053 // Return the maximum capacity of a semispace.
1067 int MaximumCapacity() { return maximum_capacity_; } 1054 int MaximumCapacity() { return maximum_capacity_; }
1068 1055
1069 // Return the address of the allocation pointer in the active semispace. 1056 // Return the address of the allocation pointer in the active semispace.
1070 Address top() { return allocation_info_.top; } 1057 Address top() { return allocation_info_.top; }
1071 // Return the address of the first object in the active semispace. 1058 // Return the address of the first object in the active semispace.
1072 Address bottom() { return to_space_->low(); } 1059 Address bottom() { return to_space_.low(); }
1073 1060
1074 // Get the age mark of the inactive semispace. 1061 // Get the age mark of the inactive semispace.
1075 Address age_mark() { return from_space_->age_mark(); } 1062 Address age_mark() { return from_space_.age_mark(); }
1076 // Set the age mark in the active semispace. 1063 // Set the age mark in the active semispace.
1077 void set_age_mark(Address mark) { to_space_->set_age_mark(mark); } 1064 void set_age_mark(Address mark) { to_space_.set_age_mark(mark); }
1078 1065
1079 // The start address of the space and a bit mask. Anding an address in the 1066 // The start address of the space and a bit mask. Anding an address in the
1080 // new space with the mask will result in the start address. 1067 // new space with the mask will result in the start address.
1081 Address start() { return start_; } 1068 Address start() { return start_; }
1082 uint32_t mask() { return address_mask_; } 1069 uint32_t mask() { return address_mask_; }
1083 1070
1084 // The allocation top and limit addresses. 1071 // The allocation top and limit addresses.
1085 Address* allocation_top_address() { return &allocation_info_.top; } 1072 Address* allocation_top_address() { return &allocation_info_.top; }
1086 Address* allocation_limit_address() { return &allocation_info_.limit; } 1073 Address* allocation_limit_address() { return &allocation_info_.limit; }
1087 1074
(...skipping 10 matching lines...) Expand all
1098 // Reset the allocation pointer to the beginning of the active semispace. 1085 // Reset the allocation pointer to the beginning of the active semispace.
1099 void ResetAllocationInfo(); 1086 void ResetAllocationInfo();
1100 // Reset the reloction pointer to the bottom of the inactive semispace in 1087 // Reset the reloction pointer to the bottom of the inactive semispace in
1101 // preparation for mark-compact collection. 1088 // preparation for mark-compact collection.
1102 void MCResetRelocationInfo(); 1089 void MCResetRelocationInfo();
1103 // Update the allocation pointer in the active semispace after a 1090 // Update the allocation pointer in the active semispace after a
1104 // mark-compact collection. 1091 // mark-compact collection.
1105 void MCCommitRelocationInfo(); 1092 void MCCommitRelocationInfo();
1106 1093
1107 // Get the extent of the inactive semispace (for use as a marking stack). 1094 // Get the extent of the inactive semispace (for use as a marking stack).
1108 Address FromSpaceLow() { return from_space_->low(); } 1095 Address FromSpaceLow() { return from_space_.low(); }
1109 Address FromSpaceHigh() { return from_space_->high(); } 1096 Address FromSpaceHigh() { return from_space_.high(); }
1110 1097
1111 // Get the extent of the active semispace (to sweep newly copied objects 1098 // Get the extent of the active semispace (to sweep newly copied objects
1112 // during a scavenge collection). 1099 // during a scavenge collection).
1113 Address ToSpaceLow() { return to_space_->low(); } 1100 Address ToSpaceLow() { return to_space_.low(); }
1114 Address ToSpaceHigh() { return to_space_->high(); } 1101 Address ToSpaceHigh() { return to_space_.high(); }
1115 1102
1116 // Offsets from the beginning of the semispaces. 1103 // Offsets from the beginning of the semispaces.
1117 int ToSpaceOffsetForAddress(Address a) { 1104 int ToSpaceOffsetForAddress(Address a) {
1118 return to_space_->SpaceOffsetForAddress(a); 1105 return to_space_.SpaceOffsetForAddress(a);
1119 } 1106 }
1120 int FromSpaceOffsetForAddress(Address a) { 1107 int FromSpaceOffsetForAddress(Address a) {
1121 return from_space_->SpaceOffsetForAddress(a); 1108 return from_space_.SpaceOffsetForAddress(a);
1122 } 1109 }
1123 1110
1124 // True if the object is a heap object in the address range of the 1111 // True if the object is a heap object in the address range of the
1125 // respective semispace (not necessarily below the allocation pointer of the 1112 // respective semispace (not necessarily below the allocation pointer of the
1126 // semispace). 1113 // semispace).
1127 bool ToSpaceContains(Object* o) { return to_space_->Contains(o); } 1114 bool ToSpaceContains(Object* o) { return to_space_.Contains(o); }
1128 bool FromSpaceContains(Object* o) { return from_space_->Contains(o); } 1115 bool FromSpaceContains(Object* o) { return from_space_.Contains(o); }
1129 1116
1130 bool ToSpaceContains(Address a) { return to_space_->Contains(a); } 1117 bool ToSpaceContains(Address a) { return to_space_.Contains(a); }
1131 bool FromSpaceContains(Address a) { return from_space_->Contains(a); } 1118 bool FromSpaceContains(Address a) { return from_space_.Contains(a); }
1132 1119
1133 #ifdef DEBUG 1120 #ifdef DEBUG
1134 // Verify the active semispace. 1121 // Verify the active semispace.
1135 virtual void Verify(); 1122 virtual void Verify();
1136 // Print the active semispace. 1123 // Print the active semispace.
1137 virtual void Print() { to_space_->Print(); } 1124 virtual void Print() { to_space_.Print(); }
1138 #endif 1125 #endif
1139 1126
1140 #if defined(DEBUG) || defined(ENABLE_LOGGING_AND_PROFILING) 1127 #if defined(DEBUG) || defined(ENABLE_LOGGING_AND_PROFILING)
1141 // Iterates the active semispace to collect statistics. 1128 // Iterates the active semispace to collect statistics.
1142 void CollectStatistics(); 1129 void CollectStatistics();
1143 // Reports previously collected statistics of the active semispace. 1130 // Reports previously collected statistics of the active semispace.
1144 void ReportStatistics(); 1131 void ReportStatistics();
1145 // Clears previously collected statistics. 1132 // Clears previously collected statistics.
1146 void ClearHistograms(); 1133 void ClearHistograms();
1147 1134
1148 // Record the allocation or promotion of a heap object. Note that we don't 1135 // Record the allocation or promotion of a heap object. Note that we don't
1149 // record every single allocation, but only those that happen in the 1136 // record every single allocation, but only those that happen in the
1150 // to space during a scavenge GC. 1137 // to space during a scavenge GC.
1151 void RecordAllocation(HeapObject* obj); 1138 void RecordAllocation(HeapObject* obj);
1152 void RecordPromotion(HeapObject* obj); 1139 void RecordPromotion(HeapObject* obj);
1153 #endif 1140 #endif
1154 1141
1155 private: 1142 private:
1156 // The current and maximum capacities of a semispace. 1143 // The current and maximum capacities of a semispace.
1157 int capacity_; 1144 int capacity_;
1158 int maximum_capacity_; 1145 int maximum_capacity_;
1159 1146
1160 // The semispaces. 1147 // The semispaces.
1161 SemiSpace* to_space_; 1148 SemiSpace to_space_;
1162 SemiSpace* from_space_; 1149 SemiSpace from_space_;
1163 1150
1164 // Start address and bit mask for containment testing. 1151 // Start address and bit mask for containment testing.
1165 Address start_; 1152 Address start_;
1166 uint32_t address_mask_; 1153 uint32_t address_mask_;
1167 uint32_t object_mask_; 1154 uint32_t object_mask_;
1168 uint32_t object_expected_; 1155 uint32_t object_expected_;
1169 1156
1170 // Allocation pointer and limit for normal allocation and allocation during 1157 // Allocation pointer and limit for normal allocation and allocation during
1171 // mark-compact collection. 1158 // mark-compact collection.
1172 AllocationInfo allocation_info_; 1159 AllocationInfo allocation_info_;
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after
1667 1654
1668 private: 1655 private:
1669 LargeObjectChunk* current_; 1656 LargeObjectChunk* current_;
1670 HeapObjectCallback size_func_; 1657 HeapObjectCallback size_func_;
1671 }; 1658 };
1672 1659
1673 1660
1674 } } // namespace v8::internal 1661 } } // namespace v8::internal
1675 1662
1676 #endif // V8_SPACES_H_ 1663 #endif // V8_SPACES_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698