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

Side by Side Diff: src/api.cc

Issue 10697094: Add a second kind of HandleScope that ties the lifetime of Handles created in its scope to the life… (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 5 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/api.h ('k') | src/compiler.h » ('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 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 6367 matching lines...) Expand 10 before | Expand all | Expand 10 after
6378 6378
6379 6379
6380 char* HandleScopeImplementer::RestoreThread(char* storage) { 6380 char* HandleScopeImplementer::RestoreThread(char* storage) {
6381 memcpy(this, storage, sizeof(*this)); 6381 memcpy(this, storage, sizeof(*this));
6382 *isolate_->handle_scope_data() = handle_scope_data_; 6382 *isolate_->handle_scope_data() = handle_scope_data_;
6383 return storage + ArchiveSpacePerThread(); 6383 return storage + ArchiveSpacePerThread();
6384 } 6384 }
6385 6385
6386 6386
6387 void HandleScopeImplementer::IterateThis(ObjectVisitor* v) { 6387 void HandleScopeImplementer::IterateThis(ObjectVisitor* v) {
6388 #ifdef DEBUG
6389 bool found_block_before_deferred = false;
6390 #endif
6388 // Iterate over all handles in the blocks except for the last. 6391 // Iterate over all handles in the blocks except for the last.
6389 for (int i = blocks()->length() - 2; i >= 0; --i) { 6392 for (int i = blocks()->length() - 2; i >= 0; --i) {
6390 Object** block = blocks()->at(i); 6393 Object** block = blocks()->at(i);
6391 v->VisitPointers(block, &block[kHandleBlockSize]); 6394 if (last_handle_before_deferred_block_ != NULL &&
6395 (last_handle_before_deferred_block_ < &block[kHandleBlockSize]) &&
6396 (last_handle_before_deferred_block_ >= block)) {
6397 v->VisitPointers(block, last_handle_before_deferred_block_);
6398 ASSERT(!found_block_before_deferred);
6399 #ifdef DEBUG
6400 found_block_before_deferred = true;
6401 #endif
6402 } else {
6403 v->VisitPointers(block, &block[kHandleBlockSize]);
6404 }
6392 } 6405 }
6393 6406
6407 ASSERT(last_handle_before_deferred_block_ == NULL ||
6408 found_block_before_deferred);
6409
6394 // Iterate over live handles in the last block (if any). 6410 // Iterate over live handles in the last block (if any).
6395 if (!blocks()->is_empty()) { 6411 if (!blocks()->is_empty()) {
6396 v->VisitPointers(blocks()->last(), handle_scope_data_.next); 6412 v->VisitPointers(blocks()->last(), handle_scope_data_.next);
6397 } 6413 }
6398 6414
6399 if (!saved_contexts_.is_empty()) { 6415 if (!saved_contexts_.is_empty()) {
6400 Object** start = reinterpret_cast<Object**>(&saved_contexts_.first()); 6416 Object** start = reinterpret_cast<Object**>(&saved_contexts_.first());
6401 v->VisitPointers(start, start + saved_contexts_.length()); 6417 v->VisitPointers(start, start + saved_contexts_.length());
6402 } 6418 }
6419
6420 for (DeferredHandles* deferred = deferred_handles_head_;
6421 deferred != NULL;
6422 deferred = deferred->next_) {
6423 deferred->Iterate(v);
6424 }
6403 } 6425 }
6404 6426
6405 6427
6406 void HandleScopeImplementer::Iterate(ObjectVisitor* v) { 6428 void HandleScopeImplementer::Iterate(ObjectVisitor* v) {
6407 v8::ImplementationUtilities::HandleScopeData* current = 6429 v8::ImplementationUtilities::HandleScopeData* current =
6408 isolate_->handle_scope_data(); 6430 isolate_->handle_scope_data();
6409 handle_scope_data_ = *current; 6431 handle_scope_data_ = *current;
6410 IterateThis(v); 6432 IterateThis(v);
6411 } 6433 }
6412 6434
6413 6435
6414 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) { 6436 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) {
6415 HandleScopeImplementer* scope_implementer = 6437 HandleScopeImplementer* scope_implementer =
6416 reinterpret_cast<HandleScopeImplementer*>(storage); 6438 reinterpret_cast<HandleScopeImplementer*>(storage);
6417 scope_implementer->IterateThis(v); 6439 scope_implementer->IterateThis(v);
6418 return storage + ArchiveSpacePerThread(); 6440 return storage + ArchiveSpacePerThread();
6419 } 6441 }
6420 6442
6443
6444 DeferredHandles* HandleScopeImplementer::Detach(Object** prev_limit) {
6445 DeferredHandles* deferred = new DeferredHandles(
6446 deferred_handles_head_, isolate()->handle_scope_data()->next, this);
6447
6448 while (!blocks_.is_empty()) {
6449 Object** block_start = blocks_.last();
6450 Object** block_limit = &block_start[kHandleBlockSize];
6451 // We should not need to check for NoHandleAllocation here. Assert
6452 // this.
6453 ASSERT(prev_limit == block_limit ||
6454 !(block_start <= prev_limit && prev_limit <= block_limit));
6455 if (prev_limit == block_limit) break;
6456 deferred->blocks_.Add(blocks_.last());
6457 blocks_.RemoveLast();
6458 }
6459
6460 ASSERT(!blocks_.is_empty() && prev_limit != NULL);
6461 deferred_handles_head_ = deferred;
6462 ASSERT(last_handle_before_deferred_block_ != NULL);
6463 last_handle_before_deferred_block_ = NULL;
6464 return deferred;
6465 }
6466
6467
6468 void HandleScopeImplementer::DestroyDeferredHandles(DeferredHandles* deferred) {
6469 if (deferred_handles_head_ == deferred) {
6470 deferred_handles_head_ = deferred_handles_head_->next_;
6471 }
6472 if (deferred->next_ != NULL) {
6473 deferred->next_->previous_ = deferred->previous_;
6474 }
6475 if (deferred->previous_ != NULL) {
6476 deferred->previous_->next_ = deferred->next_;
6477 }
6478 for (int i = 0; i < deferred->blocks_.length(); i++) {
6479 #ifdef DEBUG
6480 HandleScope::ZapRange(deferred->blocks_[i],
6481 &deferred->blocks_[i][kHandleBlockSize]);
6482 #endif
6483 if (spare_ != NULL) DeleteArray(spare_);
6484 spare_ = deferred->blocks_[i];
6485 }
6486 }
6487
6488
6489 void HandleScopeImplementer::BeginDeferredScope() {
6490 ASSERT(last_handle_before_deferred_block_ == NULL);
6491 last_handle_before_deferred_block_ = isolate()->handle_scope_data()->next;
6492 }
6493
6494
6495 DeferredHandles::~DeferredHandles() {
6496 impl_->DestroyDeferredHandles(this);
6497 }
6498
6499
6500 void DeferredHandles::Iterate(ObjectVisitor* v) {
6501 ASSERT(!blocks_.is_empty());
6502
6503 for (int i = 0; i < (blocks_.length() - 1); i++) {
6504 v->VisitPointers(blocks_[i], &blocks_[i][kHandleBlockSize]);
6505 }
6506
6507 ASSERT((last_block_limit_ >= blocks_.last()) &&
6508 (last_block_limit_ < &(blocks_.last())[kHandleBlockSize]));
6509
6510 v->VisitPointers(blocks_.last(), last_block_limit_);
6511 }
6512
6513
6421 } } // namespace v8::internal 6514 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/api.h ('k') | src/compiler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698