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

Unified 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: Created 8 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index 0d88047aa212f4d0abcba489cae3247774e6e397..104ba25a2c027e086a8747eda930c42ca0ae3987 100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -6373,22 +6373,47 @@ char* HandleScopeImplementer::RestoreThread(char* storage) {
}
+template<bool HasCompilationBlock>
Erik Corry 2012/06/22 11:08:36 This should be named_like_this, but I wonder wheth
sanjoy 2012/06/22 20:08:10 Reverted.
void HandleScopeImplementer::IterateThis(ObjectVisitor* v) {
// Iterate over all handles in the blocks except for the last.
for (int i = blocks()->length() - 2; i >= 0; --i) {
Object** block = blocks()->at(i);
- v->VisitPointers(block, &block[kHandleBlockSize]);
+ if (HasCompilationBlock && block == last_block_before_compilation_) {
+ ASSERT(last_valid_handle_before_compilation_ >= block &&
+ last_valid_handle_before_compilation_ <
+ (&block[kHandleBlockSize]));
+ v->VisitPointers(block, last_valid_handle_before_compilation_);
+ } else {
+ v->VisitPointers(block, &block[kHandleBlockSize]);
+ }
}
// Iterate over live handles in the last block (if any).
if (!blocks()->is_empty()) {
v->VisitPointers(blocks()->last(), handle_scope_data_.next);
+ ASSERT(!HasCompilationBlock ||
+ blocks()->last() != last_block_before_compilation_);
}
if (!saved_contexts_.is_empty()) {
Object** start = reinterpret_cast<Object**>(&saved_contexts_.first());
v->VisitPointers(start, start + saved_contexts_.length());
}
+
+ // Iterate over the extensions hidden by the compiler.
+ for (HiddenExtensions* extension = hidden_extensions_head_; extension;
+ extension = extension->next) {
+ if (!extension->blocks.is_empty()) {
+ for (int i = 0; i < extension->blocks.length() - 1; i++) {
+ v->VisitPointers(extension->blocks[i],
+ &(extension->blocks[i][kHandleBlockSize]));
+ }
+ }
+ ASSERT(extension->last_block_end <
+ &extension->blocks.last()[kHandleBlockSize]);
+ ASSERT(extension->last_block_end >= extension->blocks.last());
+ v->VisitPointers(extension->blocks.last(), extension->last_block_end);
+ }
}
@@ -6396,15 +6421,74 @@ void HandleScopeImplementer::Iterate(ObjectVisitor* v) {
v8::ImplementationUtilities::HandleScopeData* current =
isolate_->handle_scope_data();
handle_scope_data_ = *current;
- IterateThis(v);
+ if (last_block_before_compilation_ == NULL) {
+ IterateThis<false>(v);
+ } else {
+ IterateThis<true>(v);
+ }
}
char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) {
HandleScopeImplementer* scope_implementer =
reinterpret_cast<HandleScopeImplementer*>(storage);
- scope_implementer->IterateThis(v);
+
+ if (scope_implementer->last_block_before_compilation_ == NULL) {
+ scope_implementer->IterateThis<false>(v);
+ } else {
+ scope_implementer->IterateThis<true>(v);
+ }
return storage + ArchiveSpacePerThread();
}
+
+HandleScopeImplementer::HiddenExtensions*
+HandleScopeImplementer::HideExtensions(Object** prev_limit) {
+ HiddenExtensions* extension = new HiddenExtensions;
+ while (!blocks_.is_empty()) {
+ internal::Object** block_start = blocks_.last();
+ internal::Object** block_limit = block_start + kHandleBlockSize;
+
+ // We should not need to check for NoHandleAllocation here.
+ // ASSERT this.
Erik Corry 2012/06/22 11:08:36 ASSERT -> Assert (in the comment)
sanjoy 2012/06/22 20:08:10 Fixed.
+ ASSERT(prev_limit == block_limit ||
+ !(block_start <= prev_limit && prev_limit <= block_limit));
+ if (prev_limit == block_limit) break;
+ extension->blocks.Add(blocks_.last());
+ blocks_.RemoveLast();
+ }
+
+ ASSERT(!blocks_.is_empty() && prev_limit != NULL);
+
+ extension->next = hidden_extensions_head_;
+ extension->previous = NULL;
+ extension->last_block_end = isolate_->handle_scope_data()->next;
+ hidden_extensions_head_ = extension;
+ return extension;
+}
+
+
+void HandleScopeImplementer::DeleteHiddenExtensions(
+ HiddenExtensions* extension) {
+ if (hidden_extensions_head_ == extension) {
+ hidden_extensions_head_ = extension->next;
+ }
+ if (extension->next) {
Erik Corry 2012/06/22 11:08:36 We don't allow implicit conversions to bool.
sanjoy 2012/06/22 20:08:10 Fixed.
+ extension->next->previous = extension->previous;
+ }
+ if (extension->previous) {
Erik Corry 2012/06/22 11:08:36 and here
sanjoy 2012/06/22 20:08:10 Fixed.
+ extension->previous->next = extension->next;
+ }
+
+ for (int i = 0; i < extension->blocks.length(); i++) {
+#ifdef DEBUG
+ HandleScope::ZapRange(extension->blocks[i],
+ &extension->blocks[i][kHandleBlockSize]);
+#endif
+ if (spare_ != NULL) DeleteArray(spare_);
+ spare_ = extension->blocks[i];
+ }
+ delete extension;
+}
+
} } // namespace v8::internal

Powered by Google App Engine
This is Rietveld 408576698