OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 6356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6367 | 6367 |
6368 | 6368 |
6369 char* HandleScopeImplementer::RestoreThread(char* storage) { | 6369 char* HandleScopeImplementer::RestoreThread(char* storage) { |
6370 memcpy(this, storage, sizeof(*this)); | 6370 memcpy(this, storage, sizeof(*this)); |
6371 *isolate_->handle_scope_data() = handle_scope_data_; | 6371 *isolate_->handle_scope_data() = handle_scope_data_; |
6372 return storage + ArchiveSpacePerThread(); | 6372 return storage + ArchiveSpacePerThread(); |
6373 } | 6373 } |
6374 | 6374 |
6375 | 6375 |
6376 void HandleScopeImplementer::IterateThis(ObjectVisitor* v) { | 6376 void HandleScopeImplementer::IterateThis(ObjectVisitor* v) { |
6377 #ifdef DEBUG | |
6378 bool found_block_before_deferred = false; | |
6379 #endif | |
6377 // Iterate over all handles in the blocks except for the last. | 6380 // Iterate over all handles in the blocks except for the last. |
6378 for (int i = blocks()->length() - 2; i >= 0; --i) { | 6381 for (int i = blocks()->length() - 2; i >= 0; --i) { |
6379 Object** block = blocks()->at(i); | 6382 Object** block = blocks()->at(i); |
6380 v->VisitPointers(block, &block[kHandleBlockSize]); | 6383 if (last_handle_before_deferred_block_ != NULL && |
6384 (last_handle_before_deferred_block_ < &block[kHandleBlockSize]) && | |
6385 (last_handle_before_deferred_block_ >= block)) { | |
6386 v->VisitPointers(block, last_handle_before_deferred_block_); | |
6387 ASSERT(!found_block_before_deferred); | |
6388 #ifdef DEBUG | |
6389 found_block_before_deferred = true; | |
6390 #endif | |
6391 } else { | |
6392 v->VisitPointers(block, &block[kHandleBlockSize]); | |
6393 } | |
6381 } | 6394 } |
6382 | 6395 |
6396 ASSERT(last_handle_before_deferred_block_ == NULL || | |
6397 found_block_before_deferred); | |
6398 | |
6383 // Iterate over live handles in the last block (if any). | 6399 // Iterate over live handles in the last block (if any). |
6384 if (!blocks()->is_empty()) { | 6400 if (!blocks()->is_empty()) { |
6385 v->VisitPointers(blocks()->last(), handle_scope_data_.next); | 6401 v->VisitPointers(blocks()->last(), handle_scope_data_.next); |
6386 } | 6402 } |
6387 | 6403 |
6388 if (!saved_contexts_.is_empty()) { | 6404 if (!saved_contexts_.is_empty()) { |
6389 Object** start = reinterpret_cast<Object**>(&saved_contexts_.first()); | 6405 Object** start = reinterpret_cast<Object**>(&saved_contexts_.first()); |
6390 v->VisitPointers(start, start + saved_contexts_.length()); | 6406 v->VisitPointers(start, start + saved_contexts_.length()); |
6391 } | 6407 } |
6408 | |
6409 for (DeferredHandles* deferred = deferred_handles_head_; deferred; | |
Erik Corry
2012/06/27 10:28:15
Please put the parts of a for loop either all on o
sanjoy
2012/06/27 11:17:09
Fixed.
| |
6410 deferred = deferred->next_) { | |
6411 deferred->Iterate(v); | |
6412 } | |
6392 } | 6413 } |
6393 | 6414 |
6394 | 6415 |
6395 void HandleScopeImplementer::Iterate(ObjectVisitor* v) { | 6416 void HandleScopeImplementer::Iterate(ObjectVisitor* v) { |
6396 v8::ImplementationUtilities::HandleScopeData* current = | 6417 v8::ImplementationUtilities::HandleScopeData* current = |
6397 isolate_->handle_scope_data(); | 6418 isolate_->handle_scope_data(); |
6398 handle_scope_data_ = *current; | 6419 handle_scope_data_ = *current; |
6399 IterateThis(v); | 6420 IterateThis(v); |
6400 } | 6421 } |
6401 | 6422 |
6402 | 6423 |
6403 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) { | 6424 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) { |
6404 HandleScopeImplementer* scope_implementer = | 6425 HandleScopeImplementer* scope_implementer = |
6405 reinterpret_cast<HandleScopeImplementer*>(storage); | 6426 reinterpret_cast<HandleScopeImplementer*>(storage); |
6406 scope_implementer->IterateThis(v); | 6427 scope_implementer->IterateThis(v); |
6407 return storage + ArchiveSpacePerThread(); | 6428 return storage + ArchiveSpacePerThread(); |
6408 } | 6429 } |
6409 | 6430 |
6431 | |
6432 DeferredHandles* HandleScopeImplementer::Detach(Object** prev_limit) { | |
6433 DeferredHandles* deferred = new DeferredHandles( | |
6434 deferred_handles_head_, isolate()->handle_scope_data()->next, this); | |
6435 | |
6436 while (!blocks_.is_empty()) { | |
6437 Object** block_start = blocks_.last(); | |
6438 Object** block_limit = &block_start[kHandleBlockSize]; | |
6439 // We should not need to check for NoHandleAllocation here. Assert | |
6440 // this. | |
6441 ASSERT(prev_limit == block_limit || | |
6442 !(block_start <= prev_limit && prev_limit <= block_limit)); | |
6443 if (prev_limit == block_limit) break; | |
6444 deferred->blocks_.Add(blocks_.last()); | |
6445 blocks_.RemoveLast(); | |
6446 } | |
6447 | |
6448 ASSERT(!blocks_.is_empty() && prev_limit != NULL); | |
6449 deferred_handles_head_ = deferred; | |
6450 ASSERT(last_handle_before_deferred_block_); | |
Erik Corry
2012/06/27 10:28:15
No implicit boolean conversions.
sanjoy
2012/06/27 11:17:09
Fixed.
| |
6451 last_handle_before_deferred_block_ = NULL; | |
6452 return deferred; | |
6453 } | |
6454 | |
6455 | |
6456 void HandleScopeImplementer::DestroyDeferredHandles(DeferredHandles* deferred) { | |
6457 if (deferred_handles_head_ == deferred) { | |
6458 deferred_handles_head_ = deferred_handles_head_->next_; | |
6459 } | |
6460 if (deferred->next_ != NULL) { | |
6461 deferred->next_->previous_ = deferred->previous_; | |
6462 } | |
6463 if (deferred->previous_ != NULL) { | |
6464 deferred->previous_->next_ = deferred->next_; | |
6465 } | |
6466 for (int i = 0; i < deferred->blocks_.length(); i++) { | |
6467 #ifdef DEBUG | |
6468 HandleScope::ZapRange(deferred->blocks_[i], | |
6469 &deferred->blocks_[i][kHandleBlockSize]); | |
6470 #endif | |
6471 if (spare_ != NULL) DeleteArray(spare_); | |
6472 spare_ = deferred->blocks_[i]; | |
6473 } | |
6474 } | |
6475 | |
6476 | |
6477 void HandleScopeImplementer::BeginDeferredScope() { | |
6478 ASSERT(last_handle_before_deferred_block_ == NULL); | |
6479 last_handle_before_deferred_block_ = isolate()->handle_scope_data()->next; | |
6480 } | |
6481 | |
6482 | |
6483 DeferredHandles::~DeferredHandles() { | |
6484 impl_->DestroyDeferredHandles(this); | |
6485 } | |
6486 | |
6487 | |
6488 void DeferredHandles::Iterate(ObjectVisitor* v) { | |
6489 ASSERT(!blocks_.is_empty()); | |
6490 | |
6491 for (int i = 0; i < (blocks_.length() - 1); i++) { | |
6492 v->VisitPointers(blocks_[i], &blocks_[i][kHandleBlockSize]); | |
6493 } | |
6494 | |
6495 ASSERT((last_block_limit_ >= blocks_.last()) && | |
6496 (last_block_limit_ < &(blocks_.last())[kHandleBlockSize])); | |
6497 | |
6498 v->VisitPointers(blocks_.last(), last_block_limit_); | |
6499 } | |
6500 | |
6501 | |
6410 } } // namespace v8::internal | 6502 } } // namespace v8::internal |
OLD | NEW |