Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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/v8.h" | 5 #include "src/v8.h" |
| 6 | 6 |
| 7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
| 8 #include "src/api.h" | 8 #include "src/api.h" |
| 9 #include "src/base/bits.h" | 9 #include "src/base/bits.h" |
| 10 #include "src/base/once.h" | 10 #include "src/base/once.h" |
| (...skipping 2126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2137 heap->OnMoveEvent(target, source, size); | 2137 heap->OnMoveEvent(target, source, size); |
| 2138 } | 2138 } |
| 2139 | 2139 |
| 2140 if (marks_handling == TRANSFER_MARKS) { | 2140 if (marks_handling == TRANSFER_MARKS) { |
| 2141 if (Marking::TransferColor(source, target)) { | 2141 if (Marking::TransferColor(source, target)) { |
| 2142 MemoryChunk::IncrementLiveBytesFromGC(target->address(), size); | 2142 MemoryChunk::IncrementLiveBytesFromGC(target->address(), size); |
| 2143 } | 2143 } |
| 2144 } | 2144 } |
| 2145 } | 2145 } |
| 2146 | 2146 |
| 2147 template <int alignment> | 2147 template <AllocationAlignment alignment> |
| 2148 static inline bool SemiSpaceCopyObject(Map* map, HeapObject** slot, | 2148 static inline bool SemiSpaceCopyObject(Map* map, HeapObject** slot, |
| 2149 HeapObject* object, int object_size) { | 2149 HeapObject* object, int object_size) { |
| 2150 Heap* heap = map->GetHeap(); | 2150 Heap* heap = map->GetHeap(); |
| 2151 | 2151 |
| 2152 DCHECK(heap->AllowedToBeMigrated(object, NEW_SPACE)); | 2152 DCHECK(heap->AllowedToBeMigrated(object, NEW_SPACE)); |
| 2153 AllocationAlignment align = | |
| 2154 alignment == kDoubleAlignment ? kDoubleAligned : kWordAligned; | |
| 2155 AllocationResult allocation = | 2153 AllocationResult allocation = |
| 2156 heap->new_space()->AllocateRaw(object_size, align); | 2154 heap->new_space()->AllocateRaw(object_size, alignment); |
| 2157 | 2155 |
| 2158 HeapObject* target = NULL; // Initialization to please compiler. | 2156 HeapObject* target = NULL; // Initialization to please compiler. |
| 2159 if (allocation.To(&target)) { | 2157 if (allocation.To(&target)) { |
| 2160 // Order is important here: Set the promotion limit before storing a | 2158 // Order is important here: Set the promotion limit before storing a |
| 2161 // filler for double alignment or migrating the object. Otherwise we | 2159 // filler for double alignment or migrating the object. Otherwise we |
| 2162 // may end up overwriting promotion queue entries when we migrate the | 2160 // may end up overwriting promotion queue entries when we migrate the |
| 2163 // object. | 2161 // object. |
| 2164 heap->promotion_queue()->SetNewLimit(heap->new_space()->top()); | 2162 heap->promotion_queue()->SetNewLimit(heap->new_space()->top()); |
| 2165 | 2163 |
| 2166 MigrateObject(heap, object, target, object_size); | 2164 MigrateObject(heap, object, target, object_size); |
| 2167 | 2165 |
| 2168 // Update slot to new target. | 2166 // Update slot to new target. |
| 2169 *slot = target; | 2167 *slot = target; |
| 2170 | 2168 |
| 2171 heap->IncrementSemiSpaceCopiedObjectSize(object_size); | 2169 heap->IncrementSemiSpaceCopiedObjectSize(object_size); |
| 2172 return true; | 2170 return true; |
| 2173 } | 2171 } |
| 2174 return false; | 2172 return false; |
| 2175 } | 2173 } |
| 2176 | 2174 |
| 2177 | 2175 |
| 2178 template <ObjectContents object_contents, int alignment> | 2176 template <ObjectContents object_contents, AllocationAlignment alignment> |
| 2179 static inline bool PromoteObject(Map* map, HeapObject** slot, | 2177 static inline bool PromoteObject(Map* map, HeapObject** slot, |
| 2180 HeapObject* object, int object_size) { | 2178 HeapObject* object, int object_size) { |
| 2181 Heap* heap = map->GetHeap(); | 2179 Heap* heap = map->GetHeap(); |
| 2182 | 2180 |
| 2183 AllocationAlignment align = | |
| 2184 alignment == kDoubleAlignment ? kDoubleAligned : kWordAligned; | |
| 2185 AllocationResult allocation = | 2181 AllocationResult allocation = |
| 2186 heap->old_space()->AllocateRaw(object_size, align); | 2182 heap->old_space()->AllocateRaw(object_size, alignment); |
| 2187 | 2183 |
| 2188 HeapObject* target = NULL; // Initialization to please compiler. | 2184 HeapObject* target = NULL; // Initialization to please compiler. |
| 2189 if (allocation.To(&target)) { | 2185 if (allocation.To(&target)) { |
| 2190 MigrateObject(heap, object, target, object_size); | 2186 MigrateObject(heap, object, target, object_size); |
| 2191 | 2187 |
| 2192 // Update slot to new target. | 2188 // Update slot to new target. |
| 2193 *slot = target; | 2189 *slot = target; |
| 2194 | 2190 |
| 2195 if (object_contents == POINTER_OBJECT) { | 2191 if (object_contents == POINTER_OBJECT) { |
| 2196 if (map->instance_type() == JS_FUNCTION_TYPE) { | 2192 if (map->instance_type() == JS_FUNCTION_TYPE) { |
| 2197 heap->promotion_queue()->insert(target, | 2193 heap->promotion_queue()->insert(target, |
| 2198 JSFunction::kNonWeakFieldsEndOffset); | 2194 JSFunction::kNonWeakFieldsEndOffset); |
| 2199 } else { | 2195 } else { |
| 2200 heap->promotion_queue()->insert(target, object_size); | 2196 heap->promotion_queue()->insert(target, object_size); |
| 2201 } | 2197 } |
| 2202 } | 2198 } |
| 2203 heap->IncrementPromotedObjectsSize(object_size); | 2199 heap->IncrementPromotedObjectsSize(object_size); |
| 2204 return true; | 2200 return true; |
| 2205 } | 2201 } |
| 2206 return false; | 2202 return false; |
| 2207 } | 2203 } |
| 2208 | 2204 |
| 2209 | 2205 |
| 2210 template <ObjectContents object_contents, int alignment> | 2206 template <ObjectContents object_contents, AllocationAlignment alignment> |
| 2211 static inline void EvacuateObject(Map* map, HeapObject** slot, | 2207 static inline void EvacuateObject(Map* map, HeapObject** slot, |
| 2212 HeapObject* object, int object_size) { | 2208 HeapObject* object, int object_size) { |
| 2213 SLOW_DCHECK(object_size <= Page::kMaxRegularHeapObjectSize); | 2209 SLOW_DCHECK(object_size <= Page::kMaxRegularHeapObjectSize); |
| 2214 SLOW_DCHECK(object->Size() == object_size); | 2210 SLOW_DCHECK(object->Size() == object_size); |
| 2215 Heap* heap = map->GetHeap(); | 2211 Heap* heap = map->GetHeap(); |
| 2216 | 2212 |
| 2217 if (!heap->ShouldBePromoted(object->address(), object_size)) { | 2213 if (!heap->ShouldBePromoted(object->address(), object_size)) { |
| 2218 // A semi-space copy may fail due to fragmentation. In that case, we | 2214 // A semi-space copy may fail due to fragmentation. In that case, we |
| 2219 // try to promote the object. | 2215 // try to promote the object. |
| 2220 if (SemiSpaceCopyObject<alignment>(map, slot, object, object_size)) { | 2216 if (SemiSpaceCopyObject<alignment>(map, slot, object, object_size)) { |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 2250 // promotion queue processing (IterateAndMarkPointersToFromSpace) will | 2246 // promotion queue processing (IterateAndMarkPointersToFromSpace) will |
| 2251 // miss it as it is not HeapObject-tagged. | 2247 // miss it as it is not HeapObject-tagged. |
| 2252 Address code_entry_slot = | 2248 Address code_entry_slot = |
| 2253 target->address() + JSFunction::kCodeEntryOffset; | 2249 target->address() + JSFunction::kCodeEntryOffset; |
| 2254 Code* code = Code::cast(Code::GetObjectFromEntryAddress(code_entry_slot)); | 2250 Code* code = Code::cast(Code::GetObjectFromEntryAddress(code_entry_slot)); |
| 2255 map->GetHeap()->mark_compact_collector()->RecordCodeEntrySlot( | 2251 map->GetHeap()->mark_compact_collector()->RecordCodeEntrySlot( |
| 2256 code_entry_slot, code); | 2252 code_entry_slot, code); |
| 2257 } | 2253 } |
| 2258 } | 2254 } |
| 2259 | 2255 |
| 2256 #if V8_HOST_ARCH_64_BIT | |
| 2257 #define kObjectAligned kDoubleAligned | |
|
Hannes Payer (out of office)
2015/05/22 06:11:12
Why do we need this?
bbudge
2015/05/22 07:34:33
I was confused about word size vs. word aligned, w
| |
| 2258 #else | |
| 2259 #define kObjectAligned kWordAligned | |
| 2260 #endif | |
| 2260 | 2261 |
| 2261 static inline void EvacuateFixedArray(Map* map, HeapObject** slot, | 2262 static inline void EvacuateFixedArray(Map* map, HeapObject** slot, |
| 2262 HeapObject* object) { | 2263 HeapObject* object) { |
| 2263 int object_size = FixedArray::BodyDescriptor::SizeOf(map, object); | 2264 int object_size = FixedArray::BodyDescriptor::SizeOf(map, object); |
| 2264 EvacuateObject<POINTER_OBJECT, kObjectAlignment>(map, slot, object, | 2265 EvacuateObject<POINTER_OBJECT, kObjectAligned>(map, slot, object, |
|
Hannes Payer (out of office)
2015/05/22 06:11:13
Why not kWordAligned?
bbudge
2015/05/22 07:34:33
Changed to use kWordAligned.
| |
| 2265 object_size); | 2266 object_size); |
| 2266 } | 2267 } |
| 2267 | 2268 |
| 2268 | 2269 |
| 2269 static inline void EvacuateFixedDoubleArray(Map* map, HeapObject** slot, | 2270 static inline void EvacuateFixedDoubleArray(Map* map, HeapObject** slot, |
| 2270 HeapObject* object) { | 2271 HeapObject* object) { |
| 2271 int length = reinterpret_cast<FixedDoubleArray*>(object)->length(); | 2272 int length = reinterpret_cast<FixedDoubleArray*>(object)->length(); |
| 2272 int object_size = FixedDoubleArray::SizeFor(length); | 2273 int object_size = FixedDoubleArray::SizeFor(length); |
| 2273 EvacuateObject<DATA_OBJECT, kDoubleAlignment>(map, slot, object, | 2274 EvacuateObject<DATA_OBJECT, kDoubleAligned>(map, slot, object, object_size); |
| 2274 object_size); | |
| 2275 } | 2275 } |
| 2276 | 2276 |
| 2277 | 2277 |
| 2278 static inline void EvacuateFixedTypedArray(Map* map, HeapObject** slot, | 2278 static inline void EvacuateFixedTypedArray(Map* map, HeapObject** slot, |
| 2279 HeapObject* object) { | 2279 HeapObject* object) { |
| 2280 int object_size = reinterpret_cast<FixedTypedArrayBase*>(object)->size(); | 2280 int object_size = reinterpret_cast<FixedTypedArrayBase*>(object)->size(); |
| 2281 EvacuateObject<DATA_OBJECT, kObjectAlignment>(map, slot, object, | 2281 EvacuateObject<DATA_OBJECT, kObjectAligned>(map, slot, object, object_size); |
| 2282 object_size); | |
| 2283 } | 2282 } |
| 2284 | 2283 |
| 2285 | 2284 |
| 2286 static inline void EvacuateFixedFloat64Array(Map* map, HeapObject** slot, | 2285 static inline void EvacuateFixedFloat64Array(Map* map, HeapObject** slot, |
| 2287 HeapObject* object) { | 2286 HeapObject* object) { |
| 2288 int object_size = reinterpret_cast<FixedFloat64Array*>(object)->size(); | 2287 int object_size = reinterpret_cast<FixedFloat64Array*>(object)->size(); |
| 2289 EvacuateObject<DATA_OBJECT, kDoubleAlignment>(map, slot, object, | 2288 EvacuateObject<DATA_OBJECT, kDoubleAligned>(map, slot, object, object_size); |
| 2290 object_size); | |
| 2291 } | 2289 } |
| 2292 | 2290 |
| 2293 | 2291 |
| 2294 static inline void EvacuateByteArray(Map* map, HeapObject** slot, | 2292 static inline void EvacuateByteArray(Map* map, HeapObject** slot, |
| 2295 HeapObject* object) { | 2293 HeapObject* object) { |
| 2296 int object_size = reinterpret_cast<ByteArray*>(object)->ByteArraySize(); | 2294 int object_size = reinterpret_cast<ByteArray*>(object)->ByteArraySize(); |
| 2297 EvacuateObject<DATA_OBJECT, kObjectAlignment>(map, slot, object, | 2295 EvacuateObject<DATA_OBJECT, kObjectAligned>(map, slot, object, object_size); |
| 2298 object_size); | |
| 2299 } | 2296 } |
| 2300 | 2297 |
| 2301 | 2298 |
| 2302 static inline void EvacuateSeqOneByteString(Map* map, HeapObject** slot, | 2299 static inline void EvacuateSeqOneByteString(Map* map, HeapObject** slot, |
| 2303 HeapObject* object) { | 2300 HeapObject* object) { |
| 2304 int object_size = SeqOneByteString::cast(object) | 2301 int object_size = SeqOneByteString::cast(object) |
| 2305 ->SeqOneByteStringSize(map->instance_type()); | 2302 ->SeqOneByteStringSize(map->instance_type()); |
| 2306 EvacuateObject<DATA_OBJECT, kObjectAlignment>(map, slot, object, | 2303 EvacuateObject<DATA_OBJECT, kObjectAligned>(map, slot, object, object_size); |
| 2307 object_size); | |
| 2308 } | 2304 } |
| 2309 | 2305 |
| 2310 | 2306 |
| 2311 static inline void EvacuateSeqTwoByteString(Map* map, HeapObject** slot, | 2307 static inline void EvacuateSeqTwoByteString(Map* map, HeapObject** slot, |
| 2312 HeapObject* object) { | 2308 HeapObject* object) { |
| 2313 int object_size = SeqTwoByteString::cast(object) | 2309 int object_size = SeqTwoByteString::cast(object) |
| 2314 ->SeqTwoByteStringSize(map->instance_type()); | 2310 ->SeqTwoByteStringSize(map->instance_type()); |
| 2315 EvacuateObject<DATA_OBJECT, kObjectAlignment>(map, slot, object, | 2311 EvacuateObject<DATA_OBJECT, kObjectAligned>(map, slot, object, object_size); |
| 2316 object_size); | |
| 2317 } | 2312 } |
| 2318 | 2313 |
| 2319 | 2314 |
| 2320 static inline void EvacuateShortcutCandidate(Map* map, HeapObject** slot, | 2315 static inline void EvacuateShortcutCandidate(Map* map, HeapObject** slot, |
| 2321 HeapObject* object) { | 2316 HeapObject* object) { |
| 2322 DCHECK(IsShortcutCandidate(map->instance_type())); | 2317 DCHECK(IsShortcutCandidate(map->instance_type())); |
| 2323 | 2318 |
| 2324 Heap* heap = map->GetHeap(); | 2319 Heap* heap = map->GetHeap(); |
| 2325 | 2320 |
| 2326 if (marks_handling == IGNORE_MARKS && | 2321 if (marks_handling == IGNORE_MARKS && |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 2343 object->set_map_word(MapWord::FromForwardingAddress(target)); | 2338 object->set_map_word(MapWord::FromForwardingAddress(target)); |
| 2344 return; | 2339 return; |
| 2345 } | 2340 } |
| 2346 | 2341 |
| 2347 heap->DoScavengeObject(first->map(), slot, first); | 2342 heap->DoScavengeObject(first->map(), slot, first); |
| 2348 object->set_map_word(MapWord::FromForwardingAddress(*slot)); | 2343 object->set_map_word(MapWord::FromForwardingAddress(*slot)); |
| 2349 return; | 2344 return; |
| 2350 } | 2345 } |
| 2351 | 2346 |
| 2352 int object_size = ConsString::kSize; | 2347 int object_size = ConsString::kSize; |
| 2353 EvacuateObject<POINTER_OBJECT, kObjectAlignment>(map, slot, object, | 2348 EvacuateObject<POINTER_OBJECT, kObjectAligned>(map, slot, object, |
| 2354 object_size); | 2349 object_size); |
| 2355 } | 2350 } |
| 2356 | 2351 |
| 2357 template <ObjectContents object_contents> | 2352 template <ObjectContents object_contents> |
| 2358 class ObjectEvacuationStrategy { | 2353 class ObjectEvacuationStrategy { |
| 2359 public: | 2354 public: |
| 2360 template <int object_size> | 2355 template <int object_size> |
| 2361 static inline void VisitSpecialized(Map* map, HeapObject** slot, | 2356 static inline void VisitSpecialized(Map* map, HeapObject** slot, |
| 2362 HeapObject* object) { | 2357 HeapObject* object) { |
| 2363 EvacuateObject<object_contents, kObjectAlignment>(map, slot, object, | 2358 EvacuateObject<object_contents, kObjectAligned>(map, slot, object, |
| 2364 object_size); | 2359 object_size); |
| 2365 } | 2360 } |
| 2366 | 2361 |
| 2367 static inline void Visit(Map* map, HeapObject** slot, HeapObject* object) { | 2362 static inline void Visit(Map* map, HeapObject** slot, HeapObject* object) { |
| 2368 int object_size = map->instance_size(); | 2363 int object_size = map->instance_size(); |
| 2369 EvacuateObject<object_contents, kObjectAlignment>(map, slot, object, | 2364 EvacuateObject<object_contents, kObjectAligned>(map, slot, object, |
| 2370 object_size); | 2365 object_size); |
| 2371 } | 2366 } |
| 2372 }; | 2367 }; |
| 2373 | 2368 |
| 2374 static VisitorDispatchTable<ScavengingCallback> table_; | 2369 static VisitorDispatchTable<ScavengingCallback> table_; |
| 2375 }; | 2370 }; |
| 2376 | 2371 |
| 2377 | 2372 |
| 2378 template <MarksHandling marks_handling, | 2373 template <MarksHandling marks_handling, |
| 2379 LoggingAndProfiling logging_and_profiling_mode> | 2374 LoggingAndProfiling logging_and_profiling_mode> |
| 2380 VisitorDispatchTable<ScavengingCallback> | 2375 VisitorDispatchTable<ScavengingCallback> |
| (...skipping 4197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6578 *object_type = "CODE_TYPE"; \ | 6573 *object_type = "CODE_TYPE"; \ |
| 6579 *object_sub_type = "CODE_AGE/" #name; \ | 6574 *object_sub_type = "CODE_AGE/" #name; \ |
| 6580 return true; | 6575 return true; |
| 6581 CODE_AGE_LIST_COMPLETE(COMPARE_AND_RETURN_NAME) | 6576 CODE_AGE_LIST_COMPLETE(COMPARE_AND_RETURN_NAME) |
| 6582 #undef COMPARE_AND_RETURN_NAME | 6577 #undef COMPARE_AND_RETURN_NAME |
| 6583 } | 6578 } |
| 6584 return false; | 6579 return false; |
| 6585 } | 6580 } |
| 6586 } | 6581 } |
| 6587 } // namespace v8::internal | 6582 } // namespace v8::internal |
| OLD | NEW |