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

Side by Side Diff: src/spaces.h

Issue 23903008: Drop OS::IsOutsideAllocatedSpace() and move the tracking to the MemoryAllocator. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fix invalid calculation of committed memory boundaries. Created 7 years, 3 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
« no previous file with comments | « src/platform-win32.cc ('k') | src/spaces.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 1065 matching lines...) Expand 10 before | Expand all | Expand 10 after
1076 } 1076 }
1077 1077
1078 // Returns allocated executable spaces in bytes. 1078 // Returns allocated executable spaces in bytes.
1079 intptr_t SizeExecutable() { return size_executable_; } 1079 intptr_t SizeExecutable() { return size_executable_; }
1080 1080
1081 // Returns maximum available bytes that the old space can have. 1081 // Returns maximum available bytes that the old space can have.
1082 intptr_t MaxAvailable() { 1082 intptr_t MaxAvailable() {
1083 return (Available() / Page::kPageSize) * Page::kMaxNonCodeHeapObjectSize; 1083 return (Available() / Page::kPageSize) * Page::kMaxNonCodeHeapObjectSize;
1084 } 1084 }
1085 1085
1086 // Returns an indication of whether a pointer is in a space that has
1087 // been allocated by this MemoryAllocator.
1088 V8_INLINE(bool IsOutsideAllocatedSpace(const void* address)) const {
1089 return address < lowest_ever_allocated_ ||
1090 address >= highest_ever_allocated_;
1091 }
1092
1086 #ifdef DEBUG 1093 #ifdef DEBUG
1087 // Reports statistic info of the space. 1094 // Reports statistic info of the space.
1088 void ReportStatistics(); 1095 void ReportStatistics();
1089 #endif 1096 #endif
1090 1097
1091 // Returns a MemoryChunk in which the memory region from commit_area_size to 1098 // Returns a MemoryChunk in which the memory region from commit_area_size to
1092 // reserve_area_size of the chunk area is reserved but not committed, it 1099 // reserve_area_size of the chunk area is reserved but not committed, it
1093 // could be committed later by calling MemoryChunk::CommitArea. 1100 // could be committed later by calling MemoryChunk::CommitArea.
1094 MemoryChunk* AllocateChunk(intptr_t reserve_area_size, 1101 MemoryChunk* AllocateChunk(intptr_t reserve_area_size,
1095 intptr_t commit_area_size, 1102 intptr_t commit_area_size,
1096 Executability executable, 1103 Executability executable,
1097 Space* space); 1104 Space* space);
1098 1105
1099 Address ReserveAlignedMemory(size_t requested, 1106 Address ReserveAlignedMemory(size_t requested,
1100 size_t alignment, 1107 size_t alignment,
1101 VirtualMemory* controller); 1108 VirtualMemory* controller);
1102 Address AllocateAlignedMemory(size_t reserve_size, 1109 Address AllocateAlignedMemory(size_t reserve_size,
1103 size_t commit_size, 1110 size_t commit_size,
1104 size_t alignment, 1111 size_t alignment,
1105 Executability executable, 1112 Executability executable,
1106 VirtualMemory* controller); 1113 VirtualMemory* controller);
1107 1114
1115 bool CommitMemory(Address addr, size_t size, Executability executable);
1116
1108 void FreeMemory(VirtualMemory* reservation, Executability executable); 1117 void FreeMemory(VirtualMemory* reservation, Executability executable);
1109 void FreeMemory(Address addr, size_t size, Executability executable); 1118 void FreeMemory(Address addr, size_t size, Executability executable);
1110 1119
1111 // Commit a contiguous block of memory from the initial chunk. Assumes that 1120 // Commit a contiguous block of memory from the initial chunk. Assumes that
1112 // the address is not NULL, the size is greater than zero, and that the 1121 // the address is not NULL, the size is greater than zero, and that the
1113 // block is contained in the initial chunk. Returns true if it succeeded 1122 // block is contained in the initial chunk. Returns true if it succeeded
1114 // and false otherwise. 1123 // and false otherwise.
1115 bool CommitBlock(Address start, size_t size, Executability executable); 1124 bool CommitBlock(Address start, size_t size, Executability executable);
1116 1125
1117 // Uncommit a contiguous block of memory [start..(start+size)[. 1126 // Uncommit a contiguous block of memory [start..(start+size)[.
(...skipping 25 matching lines...) Expand all
1143 static int CodePageGuardSize(); 1152 static int CodePageGuardSize();
1144 1153
1145 static int CodePageAreaStartOffset(); 1154 static int CodePageAreaStartOffset();
1146 1155
1147 static int CodePageAreaEndOffset(); 1156 static int CodePageAreaEndOffset();
1148 1157
1149 static int CodePageAreaSize() { 1158 static int CodePageAreaSize() {
1150 return CodePageAreaEndOffset() - CodePageAreaStartOffset(); 1159 return CodePageAreaEndOffset() - CodePageAreaStartOffset();
1151 } 1160 }
1152 1161
1153 MUST_USE_RESULT static bool CommitExecutableMemory(VirtualMemory* vm, 1162 MUST_USE_RESULT bool CommitExecutableMemory(VirtualMemory* vm,
1154 Address start, 1163 Address start,
1155 size_t commit_size, 1164 size_t commit_size,
1156 size_t reserved_size); 1165 size_t reserved_size);
1157 1166
1158 private: 1167 private:
1159 Isolate* isolate_; 1168 Isolate* isolate_;
1160 1169
1161 // Maximum space size in bytes. 1170 // Maximum space size in bytes.
1162 size_t capacity_; 1171 size_t capacity_;
1163 // Maximum subset of capacity_ that can be executable 1172 // Maximum subset of capacity_ that can be executable
1164 size_t capacity_executable_; 1173 size_t capacity_executable_;
1165 1174
1166 // Allocated space size in bytes. 1175 // Allocated space size in bytes.
1167 size_t size_; 1176 size_t size_;
1168 // Allocated executable space size in bytes. 1177 // Allocated executable space size in bytes.
1169 size_t size_executable_; 1178 size_t size_executable_;
1170 1179
1180 // We keep the lowest and highest addresses allocated as a quick way
1181 // of determining that pointers are outside the heap. The estimate is
1182 // conservative, i.e. not all addrsses in 'allocated' space are allocated
1183 // to our heap. The range is [lowest, highest[, inclusive on the low end
1184 // and exclusive on the high end.
1185 void* lowest_ever_allocated_;
1186 void* highest_ever_allocated_;
1187
1171 struct MemoryAllocationCallbackRegistration { 1188 struct MemoryAllocationCallbackRegistration {
1172 MemoryAllocationCallbackRegistration(MemoryAllocationCallback callback, 1189 MemoryAllocationCallbackRegistration(MemoryAllocationCallback callback,
1173 ObjectSpace space, 1190 ObjectSpace space,
1174 AllocationAction action) 1191 AllocationAction action)
1175 : callback(callback), space(space), action(action) { 1192 : callback(callback), space(space), action(action) {
1176 } 1193 }
1177 MemoryAllocationCallback callback; 1194 MemoryAllocationCallback callback;
1178 ObjectSpace space; 1195 ObjectSpace space;
1179 AllocationAction action; 1196 AllocationAction action;
1180 }; 1197 };
1181 1198
1182 // A List of callback that are triggered when memory is allocated or free'd 1199 // A List of callback that are triggered when memory is allocated or free'd
1183 List<MemoryAllocationCallbackRegistration> 1200 List<MemoryAllocationCallbackRegistration>
1184 memory_allocation_callbacks_; 1201 memory_allocation_callbacks_;
1185 1202
1186 // Initializes pages in a chunk. Returns the first page address. 1203 // Initializes pages in a chunk. Returns the first page address.
1187 // This function and GetChunkId() are provided for the mark-compact 1204 // This function and GetChunkId() are provided for the mark-compact
1188 // collector to rebuild page headers in the from space, which is 1205 // collector to rebuild page headers in the from space, which is
1189 // used as a marking stack and its page headers are destroyed. 1206 // used as a marking stack and its page headers are destroyed.
1190 Page* InitializePagesInChunk(int chunk_id, int pages_in_chunk, 1207 Page* InitializePagesInChunk(int chunk_id, int pages_in_chunk,
1191 PagedSpace* owner); 1208 PagedSpace* owner);
1192 1209
1210 void UpdateAllocatedSpaceLimits(void* low, void* high) {
1211 lowest_ever_allocated_ = Min(lowest_ever_allocated_, low);
1212 highest_ever_allocated_ = Max(highest_ever_allocated_, high);
1213 }
1214
1193 DISALLOW_IMPLICIT_CONSTRUCTORS(MemoryAllocator); 1215 DISALLOW_IMPLICIT_CONSTRUCTORS(MemoryAllocator);
1194 }; 1216 };
1195 1217
1196 1218
1197 // ----------------------------------------------------------------------------- 1219 // -----------------------------------------------------------------------------
1198 // Interface for heap object iterator to be implemented by all object space 1220 // Interface for heap object iterator to be implemented by all object space
1199 // object iterators. 1221 // object iterators.
1200 // 1222 //
1201 // NOTE: The space specific object iterators also implements the own next() 1223 // NOTE: The space specific object iterators also implements the own next()
1202 // method which is used to avoid using virtual functions 1224 // method which is used to avoid using virtual functions
(...skipping 1671 matching lines...) Expand 10 before | Expand all | Expand 10 after
2874 } 2896 }
2875 // Must be small, since an iteration is used for lookup. 2897 // Must be small, since an iteration is used for lookup.
2876 static const int kMaxComments = 64; 2898 static const int kMaxComments = 64;
2877 }; 2899 };
2878 #endif 2900 #endif
2879 2901
2880 2902
2881 } } // namespace v8::internal 2903 } } // namespace v8::internal
2882 2904
2883 #endif // V8_SPACES_H_ 2905 #endif // V8_SPACES_H_
OLDNEW
« no previous file with comments | « src/platform-win32.cc ('k') | src/spaces.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698