Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 275 | 275 |
| 276 #ifdef DEBUG | 276 #ifdef DEBUG |
| 277 class HeapDebugUtils; | 277 class HeapDebugUtils; |
| 278 #endif | 278 #endif |
| 279 | 279 |
| 280 | 280 |
| 281 // A queue of objects promoted during scavenge. Each object is accompanied | 281 // A queue of objects promoted during scavenge. Each object is accompanied |
| 282 // by it's size to avoid dereferencing a map pointer for scanning. | 282 // by it's size to avoid dereferencing a map pointer for scanning. |
| 283 class PromotionQueue { | 283 class PromotionQueue { |
| 284 public: | 284 public: |
| 285 PromotionQueue() : front_(NULL), rear_(NULL) { } | 285 PromotionQueue() |
| 286 : front_(NULL), rear_(NULL), limit_(NULL), emergency_stack_(0) { } | |
| 286 | 287 |
| 287 void Initialize(Address start_address) { | 288 void Initialize(NewSpace* new_space) { |
| 288 // Assumes that a NewSpacePage exactly fits a number of promotion queue | 289 // Assumes that a NewSpacePage exactly fits a number of promotion queue |
| 289 // entries (where each is a pair of intptr_t). This allows us to simplify | 290 // entries (where each is a pair of intptr_t). This allows us to simplify |
| 290 // the test fpr when to switch pages. | 291 // the test fpr when to switch pages. |
| 291 ASSERT((Page::kPageSize - MemoryChunk::kBodyOffset) % (2 * kPointerSize) | 292 ASSERT((Page::kPageSize - MemoryChunk::kBodyOffset) % (2 * kPointerSize) |
| 292 == 0); | 293 == 0); |
| 293 ASSERT(NewSpacePage::IsAtEnd(start_address)); | 294 limit_ = reinterpret_cast<intptr_t*>(new_space->ToSpaceStart()); |
| 294 front_ = rear_ = reinterpret_cast<intptr_t*>(start_address); | 295 front_ = rear_ = reinterpret_cast<intptr_t*>(new_space->ToSpaceEnd()); |
| 296 emergency_stack_ = NULL; | |
| 295 } | 297 } |
| 296 | 298 |
| 297 bool is_empty() { return front_ == rear_; } | 299 void Destroy() { |
| 300 delete emergency_stack_; | |
|
Erik Corry
2011/11/07 16:35:25
I would be more comfortable if you also nulled it.
| |
| 301 } | |
| 302 | |
| 303 void SetNewLimit(Address limit); | |
| 304 | |
| 305 bool is_empty() { | |
| 306 return (front_ == rear_) && | |
| 307 (emergency_stack_ == NULL || emergency_stack_->length() == 0); | |
| 308 } | |
| 298 | 309 |
| 299 inline void insert(HeapObject* target, int size); | 310 inline void insert(HeapObject* target, int size); |
| 300 | 311 |
| 301 void remove(HeapObject** target, int* size) { | 312 void remove(HeapObject** target, int* size) { |
| 302 ASSERT(!is_empty()); | 313 ASSERT(!is_empty()); |
| 314 if (front_ == rear_) { | |
| 315 Entry e = emergency_stack_->RemoveLast(); | |
| 316 *target = e.obj_; | |
| 317 *size = e.size_; | |
| 318 return; | |
| 319 } | |
| 320 | |
| 303 if (NewSpacePage::IsAtStart(reinterpret_cast<Address>(front_))) { | 321 if (NewSpacePage::IsAtStart(reinterpret_cast<Address>(front_))) { |
| 304 NewSpacePage* front_page = | 322 NewSpacePage* front_page = |
| 305 NewSpacePage::FromAddress(reinterpret_cast<Address>(front_)); | 323 NewSpacePage::FromAddress(reinterpret_cast<Address>(front_)); |
| 306 ASSERT(!front_page->prev_page()->is_anchor()); | 324 ASSERT(!front_page->prev_page()->is_anchor()); |
| 307 front_ = | 325 front_ = |
| 308 reinterpret_cast<intptr_t*>(front_page->prev_page()->body_limit()); | 326 reinterpret_cast<intptr_t*>(front_page->prev_page()->body_limit()); |
| 309 } | 327 } |
| 310 *target = reinterpret_cast<HeapObject*>(*(--front_)); | 328 *target = reinterpret_cast<HeapObject*>(*(--front_)); |
| 311 *size = static_cast<int>(*(--front_)); | 329 *size = static_cast<int>(*(--front_)); |
| 312 // Assert no underflow. | 330 // Assert no underflow. |
| 313 SemiSpace::AssertValidRange(reinterpret_cast<Address>(rear_), | 331 SemiSpace::AssertValidRange(reinterpret_cast<Address>(rear_), |
| 314 reinterpret_cast<Address>(front_)); | 332 reinterpret_cast<Address>(front_)); |
| 315 } | 333 } |
| 316 | 334 |
| 317 private: | 335 private: |
| 318 // The front of the queue is higher in the memory page chain than the rear. | 336 // The front of the queue is higher in the memory page chain than the rear. |
| 319 intptr_t* front_; | 337 intptr_t* front_; |
| 320 intptr_t* rear_; | 338 intptr_t* rear_; |
| 339 intptr_t* limit_; | |
| 340 | |
| 341 static const int kEntrySizeInWords = 2; | |
| 342 | |
| 343 struct Entry { | |
| 344 Entry(HeapObject* obj, int size) : obj_(obj), size_(size) { } | |
| 345 | |
| 346 HeapObject* obj_; | |
| 347 int size_; | |
| 348 }; | |
| 349 List<Entry>* emergency_stack_; | |
| 350 | |
| 351 void RelocateQueueHead(); | |
| 321 | 352 |
| 322 DISALLOW_COPY_AND_ASSIGN(PromotionQueue); | 353 DISALLOW_COPY_AND_ASSIGN(PromotionQueue); |
| 323 }; | 354 }; |
| 324 | 355 |
| 325 | 356 |
| 326 typedef void (*ScavengingCallback)(Map* map, | 357 typedef void (*ScavengingCallback)(Map* map, |
| 327 HeapObject** slot, | 358 HeapObject** slot, |
| 328 HeapObject* object); | 359 HeapObject* object); |
| 329 | 360 |
| 330 | 361 |
| (...skipping 2147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2478 | 2509 |
| 2479 DISALLOW_IMPLICIT_CONSTRUCTORS(PathTracer); | 2510 DISALLOW_IMPLICIT_CONSTRUCTORS(PathTracer); |
| 2480 }; | 2511 }; |
| 2481 #endif // DEBUG || LIVE_OBJECT_LIST | 2512 #endif // DEBUG || LIVE_OBJECT_LIST |
| 2482 | 2513 |
| 2483 } } // namespace v8::internal | 2514 } } // namespace v8::internal |
| 2484 | 2515 |
| 2485 #undef HEAP | 2516 #undef HEAP |
| 2486 | 2517 |
| 2487 #endif // V8_HEAP_H_ | 2518 #endif // V8_HEAP_H_ |
| OLD | NEW |