| 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 6404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6415 | 6415 |
| 6416 // Iterate over live handles in the last block (if any). | 6416 // Iterate over live handles in the last block (if any). |
| 6417 if (!blocks()->is_empty()) { | 6417 if (!blocks()->is_empty()) { |
| 6418 v->VisitPointers(blocks()->last(), handle_scope_data_.next); | 6418 v->VisitPointers(blocks()->last(), handle_scope_data_.next); |
| 6419 } | 6419 } |
| 6420 | 6420 |
| 6421 if (!saved_contexts_.is_empty()) { | 6421 if (!saved_contexts_.is_empty()) { |
| 6422 Object** start = reinterpret_cast<Object**>(&saved_contexts_.first()); | 6422 Object** start = reinterpret_cast<Object**>(&saved_contexts_.first()); |
| 6423 v->VisitPointers(start, start + saved_contexts_.length()); | 6423 v->VisitPointers(start, start + saved_contexts_.length()); |
| 6424 } | 6424 } |
| 6425 | |
| 6426 for (DeferredHandles* deferred = deferred_handles_head_; | |
| 6427 deferred != NULL; | |
| 6428 deferred = deferred->next_) { | |
| 6429 deferred->Iterate(v); | |
| 6430 } | |
| 6431 } | 6425 } |
| 6432 | 6426 |
| 6433 | 6427 |
| 6434 void HandleScopeImplementer::Iterate(ObjectVisitor* v) { | 6428 void HandleScopeImplementer::Iterate(ObjectVisitor* v) { |
| 6435 v8::ImplementationUtilities::HandleScopeData* current = | 6429 v8::ImplementationUtilities::HandleScopeData* current = |
| 6436 isolate_->handle_scope_data(); | 6430 isolate_->handle_scope_data(); |
| 6437 handle_scope_data_ = *current; | 6431 handle_scope_data_ = *current; |
| 6438 IterateThis(v); | 6432 IterateThis(v); |
| 6439 } | 6433 } |
| 6440 | 6434 |
| 6441 | 6435 |
| 6442 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) { | 6436 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) { |
| 6443 HandleScopeImplementer* scope_implementer = | 6437 HandleScopeImplementer* scope_implementer = |
| 6444 reinterpret_cast<HandleScopeImplementer*>(storage); | 6438 reinterpret_cast<HandleScopeImplementer*>(storage); |
| 6445 scope_implementer->IterateThis(v); | 6439 scope_implementer->IterateThis(v); |
| 6446 return storage + ArchiveSpacePerThread(); | 6440 return storage + ArchiveSpacePerThread(); |
| 6447 } | 6441 } |
| 6448 | 6442 |
| 6449 | 6443 |
| 6450 DeferredHandles* HandleScopeImplementer::Detach(Object** prev_limit) { | 6444 DeferredHandles* HandleScopeImplementer::Detach(Object** prev_limit) { |
| 6451 DeferredHandles* deferred = new DeferredHandles( | 6445 DeferredHandles* deferred = |
| 6452 deferred_handles_head_, isolate()->handle_scope_data()->next, this); | 6446 new DeferredHandles(isolate()->handle_scope_data()->next, isolate()); |
| 6453 | 6447 |
| 6454 while (!blocks_.is_empty()) { | 6448 while (!blocks_.is_empty()) { |
| 6455 Object** block_start = blocks_.last(); | 6449 Object** block_start = blocks_.last(); |
| 6456 Object** block_limit = &block_start[kHandleBlockSize]; | 6450 Object** block_limit = &block_start[kHandleBlockSize]; |
| 6457 // We should not need to check for NoHandleAllocation here. Assert | 6451 // We should not need to check for NoHandleAllocation here. Assert |
| 6458 // this. | 6452 // this. |
| 6459 ASSERT(prev_limit == block_limit || | 6453 ASSERT(prev_limit == block_limit || |
| 6460 !(block_start <= prev_limit && prev_limit <= block_limit)); | 6454 !(block_start <= prev_limit && prev_limit <= block_limit)); |
| 6461 if (prev_limit == block_limit) break; | 6455 if (prev_limit == block_limit) break; |
| 6462 deferred->blocks_.Add(blocks_.last()); | 6456 deferred->blocks_.Add(blocks_.last()); |
| 6463 blocks_.RemoveLast(); | 6457 blocks_.RemoveLast(); |
| 6464 } | 6458 } |
| 6465 | 6459 |
| 6466 // deferred->blocks_ now contains the blocks installed on the | 6460 // deferred->blocks_ now contains the blocks installed on the |
| 6467 // HandleScope stack since BeginDeferredScope was called, but in | 6461 // HandleScope stack since BeginDeferredScope was called, but in |
| 6468 // reverse order. | 6462 // reverse order. |
| 6469 | 6463 |
| 6470 ASSERT(prev_limit == NULL || !blocks_.is_empty()); | 6464 ASSERT(prev_limit == NULL || !blocks_.is_empty()); |
| 6471 | 6465 |
| 6472 ASSERT(!blocks_.is_empty() && prev_limit != NULL); | 6466 ASSERT(!blocks_.is_empty() && prev_limit != NULL); |
| 6473 deferred_handles_head_ = deferred; | |
| 6474 ASSERT(last_handle_before_deferred_block_ != NULL); | 6467 ASSERT(last_handle_before_deferred_block_ != NULL); |
| 6475 last_handle_before_deferred_block_ = NULL; | 6468 last_handle_before_deferred_block_ = NULL; |
| 6476 return deferred; | 6469 return deferred; |
| 6477 } | 6470 } |
| 6478 | 6471 |
| 6479 | 6472 |
| 6480 void HandleScopeImplementer::DestroyDeferredHandles(DeferredHandles* deferred) { | |
| 6481 #ifdef DEBUG | |
| 6482 DeferredHandles* deferred_iterator = deferred; | |
| 6483 while (deferred_iterator->previous_ != NULL) { | |
| 6484 deferred_iterator = deferred_iterator->previous_; | |
| 6485 } | |
| 6486 ASSERT(deferred_handles_head_ == deferred_iterator); | |
| 6487 #endif | |
| 6488 if (deferred_handles_head_ == deferred) { | |
| 6489 deferred_handles_head_ = deferred_handles_head_->next_; | |
| 6490 } | |
| 6491 if (deferred->next_ != NULL) { | |
| 6492 deferred->next_->previous_ = deferred->previous_; | |
| 6493 } | |
| 6494 if (deferred->previous_ != NULL) { | |
| 6495 deferred->previous_->next_ = deferred->next_; | |
| 6496 } | |
| 6497 for (int i = 0; i < deferred->blocks_.length(); i++) { | |
| 6498 #ifdef DEBUG | |
| 6499 HandleScope::ZapRange(deferred->blocks_[i], | |
| 6500 &deferred->blocks_[i][kHandleBlockSize]); | |
| 6501 #endif | |
| 6502 if (spare_ != NULL) DeleteArray(spare_); | |
| 6503 spare_ = deferred->blocks_[i]; | |
| 6504 } | |
| 6505 } | |
| 6506 | |
| 6507 | |
| 6508 void HandleScopeImplementer::BeginDeferredScope() { | 6473 void HandleScopeImplementer::BeginDeferredScope() { |
| 6509 ASSERT(last_handle_before_deferred_block_ == NULL); | 6474 ASSERT(last_handle_before_deferred_block_ == NULL); |
| 6510 last_handle_before_deferred_block_ = isolate()->handle_scope_data()->next; | 6475 last_handle_before_deferred_block_ = isolate()->handle_scope_data()->next; |
| 6511 } | 6476 } |
| 6512 | 6477 |
| 6513 | 6478 |
| 6514 DeferredHandles::~DeferredHandles() { | 6479 DeferredHandles::~DeferredHandles() { |
| 6515 impl_->DestroyDeferredHandles(this); | 6480 isolate_->DestroyDeferredHandles(this); |
| 6516 } | 6481 } |
| 6517 | 6482 |
| 6518 | 6483 |
| 6519 void DeferredHandles::Iterate(ObjectVisitor* v) { | 6484 void DeferredHandles::Iterate(ObjectVisitor* v) { |
| 6520 ASSERT(!blocks_.is_empty()); | 6485 ASSERT(!blocks_.is_empty()); |
| 6521 | 6486 |
| 6522 ASSERT((first_block_limit_ >= blocks_.first()) && | 6487 ASSERT((first_block_limit_ >= blocks_.first()) && |
| 6523 (first_block_limit_ <= &(blocks_.first())[kHandleBlockSize])); | 6488 (first_block_limit_ <= &(blocks_.first())[kHandleBlockSize])); |
| 6524 | 6489 |
| 6525 v->VisitPointers(blocks_.first(), first_block_limit_); | 6490 v->VisitPointers(blocks_.first(), first_block_limit_); |
| 6526 | 6491 |
| 6527 for (int i = 1; i < blocks_.length(); i++) { | 6492 for (int i = 1; i < blocks_.length(); i++) { |
| 6528 v->VisitPointers(blocks_[i], &blocks_[i][kHandleBlockSize]); | 6493 v->VisitPointers(blocks_[i], &blocks_[i][kHandleBlockSize]); |
| 6529 } | 6494 } |
| 6530 } | 6495 } |
| 6531 | 6496 |
| 6532 | 6497 |
| 6533 } } // namespace v8::internal | 6498 } } // namespace v8::internal |
| OLD | NEW |