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

Side by Side Diff: src/api.cc

Issue 10640012: 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: Fix nits. 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 6356 matching lines...) Expand 10 before | Expand all | Expand 10 after
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_;
6410 deferred != NULL;
6411 deferred = deferred->next_) {
6412 deferred->Iterate(v);
6413 }
6392 } 6414 }
6393 6415
6394 6416
6395 void HandleScopeImplementer::Iterate(ObjectVisitor* v) { 6417 void HandleScopeImplementer::Iterate(ObjectVisitor* v) {
6396 v8::ImplementationUtilities::HandleScopeData* current = 6418 v8::ImplementationUtilities::HandleScopeData* current =
6397 isolate_->handle_scope_data(); 6419 isolate_->handle_scope_data();
6398 handle_scope_data_ = *current; 6420 handle_scope_data_ = *current;
6399 IterateThis(v); 6421 IterateThis(v);
6400 } 6422 }
6401 6423
6402 6424
6403 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) { 6425 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) {
6404 HandleScopeImplementer* scope_implementer = 6426 HandleScopeImplementer* scope_implementer =
6405 reinterpret_cast<HandleScopeImplementer*>(storage); 6427 reinterpret_cast<HandleScopeImplementer*>(storage);
6406 scope_implementer->IterateThis(v); 6428 scope_implementer->IterateThis(v);
6407 return storage + ArchiveSpacePerThread(); 6429 return storage + ArchiveSpacePerThread();
6408 } 6430 }
6409 6431
6432
6433 DeferredHandles* HandleScopeImplementer::Detach(Object** prev_limit) {
6434 DeferredHandles* deferred = new DeferredHandles(
6435 deferred_handles_head_, isolate()->handle_scope_data()->next, this);
6436
6437 while (!blocks_.is_empty()) {
6438 Object** block_start = blocks_.last();
6439 Object** block_limit = &block_start[kHandleBlockSize];
6440 // We should not need to check for NoHandleAllocation here. Assert
6441 // this.
6442 ASSERT(prev_limit == block_limit ||
6443 !(block_start <= prev_limit && prev_limit <= block_limit));
6444 if (prev_limit == block_limit) break;
6445 deferred->blocks_.Add(blocks_.last());
6446 blocks_.RemoveLast();
6447 }
6448
6449 ASSERT(!blocks_.is_empty() && prev_limit != NULL);
6450 deferred_handles_head_ = deferred;
6451 ASSERT(last_handle_before_deferred_block_ != NULL);
6452 last_handle_before_deferred_block_ = NULL;
6453 return deferred;
6454 }
6455
6456
6457 void HandleScopeImplementer::DestroyDeferredHandles(DeferredHandles* deferred) {
6458 if (deferred_handles_head_ == deferred) {
6459 deferred_handles_head_ = deferred_handles_head_->next_;
6460 }
6461 if (deferred->next_ != NULL) {
6462 deferred->next_->previous_ = deferred->previous_;
6463 }
6464 if (deferred->previous_ != NULL) {
6465 deferred->previous_->next_ = deferred->next_;
6466 }
6467 for (int i = 0; i < deferred->blocks_.length(); i++) {
6468 #ifdef DEBUG
6469 HandleScope::ZapRange(deferred->blocks_[i],
6470 &deferred->blocks_[i][kHandleBlockSize]);
6471 #endif
6472 if (spare_ != NULL) DeleteArray(spare_);
6473 spare_ = deferred->blocks_[i];
6474 }
6475 }
6476
6477
6478 void HandleScopeImplementer::BeginDeferredScope() {
6479 ASSERT(last_handle_before_deferred_block_ == NULL);
6480 last_handle_before_deferred_block_ = isolate()->handle_scope_data()->next;
6481 }
6482
6483
6484 DeferredHandles::~DeferredHandles() {
6485 impl_->DestroyDeferredHandles(this);
6486 }
6487
6488
6489 void DeferredHandles::Iterate(ObjectVisitor* v) {
6490 ASSERT(!blocks_.is_empty());
6491
6492 for (int i = 0; i < (blocks_.length() - 1); i++) {
6493 v->VisitPointers(blocks_[i], &blocks_[i][kHandleBlockSize]);
6494 }
6495
6496 ASSERT((last_block_limit_ >= blocks_.last()) &&
6497 (last_block_limit_ < &(blocks_.last())[kHandleBlockSize]));
6498
6499 v->VisitPointers(blocks_.last(), last_block_limit_);
6500 }
6501
6502
6410 } } // namespace v8::internal 6503 } } // 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