Changed saved context stack to using direct pointers. Before we would

create a new persistent handle to hold the context to save when
entering another context, now we use a stack of direct pointers that
the gc knows about.

Review URL: http://codereview.chromium.org/199021

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@2820 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 5b3ce109
......@@ -427,7 +427,7 @@ void Context::Enter() {
i::Handle<i::Context> env = Utils::OpenHandle(this);
thread_local.EnterContext(env);
thread_local.SaveContext(i::GlobalHandles::Create(i::Top::context()));
thread_local.SaveContext(i::Top::context());
i::Top::set_context(*env);
}
......@@ -441,9 +441,8 @@ void Context::Exit() {
}
// Content of 'last_context' could be NULL.
i::Handle<i::Object> last_context = thread_local.RestoreContext();
i::Top::set_context(static_cast<i::Context*>(*last_context));
i::GlobalHandles::Destroy(last_context.location());
i::Context* last_context = thread_local.RestoreContext();
i::Top::set_context(last_context);
}
......@@ -3700,19 +3699,21 @@ char* HandleScopeImplementer::RestoreThreadHelper(char* storage) {
}
void HandleScopeImplementer::Iterate(
ObjectVisitor* v,
List<i::Object**>* blocks,
v8::ImplementationUtilities::HandleScopeData* handle_data) {
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);
for (int i = Blocks()->length() - 2; i >= 0; --i) {
Object** block = Blocks()->at(i);
v->VisitPointers(block, &block[kHandleBlockSize]);
}
// Iterate over live handles in the last block (if any).
if (!blocks->is_empty()) {
v->VisitPointers(blocks->last(), handle_data->next);
if (!Blocks()->is_empty()) {
v->VisitPointers(Blocks()->last(), handle_scope_data_.next);
}
if (!saved_contexts_.is_empty()) {
Object** start = reinterpret_cast<Object**>(&saved_contexts_.first());
v->VisitPointers(start, start + saved_contexts_.length());
}
}
......@@ -3720,18 +3721,15 @@ void HandleScopeImplementer::Iterate(
void HandleScopeImplementer::Iterate(ObjectVisitor* v) {
v8::ImplementationUtilities::HandleScopeData* current =
v8::ImplementationUtilities::CurrentHandleScope();
Iterate(v, thread_local.Blocks(), current);
thread_local.handle_scope_data_ = *current;
thread_local.IterateThis(v);
}
char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) {
HandleScopeImplementer* thread_local =
reinterpret_cast<HandleScopeImplementer*>(storage);
List<internal::Object**>* blocks_of_archived_thread = thread_local->Blocks();
v8::ImplementationUtilities::HandleScopeData* handle_data_of_archived_thread =
&thread_local->handle_scope_data_;
Iterate(v, blocks_of_archived_thread, handle_data_of_archived_thread);
thread_local->IterateThis(v);
return storage + ArchiveSpacePerThread();
}
......
......@@ -352,8 +352,8 @@ class HandleScopeImplementer {
// contexts have been entered.
inline Handle<Object> LastEnteredContext();
inline void SaveContext(Handle<Object> context);
inline Handle<Object> RestoreContext();
inline void SaveContext(Context* context);
inline Context* RestoreContext();
inline bool HasSavedContexts();
inline List<internal::Object**>* Blocks() { return &blocks; }
......@@ -368,14 +368,12 @@ class HandleScopeImplementer {
// Used as a stack to keep track of entered contexts.
List<Handle<Object> > entered_contexts_;
// Used as a stack to keep track of saved contexts.
List<Handle<Object> > saved_contexts_;
List<Context*> saved_contexts_;
bool ignore_out_of_memory;
// This is only used for threading support.
v8::ImplementationUtilities::HandleScopeData handle_scope_data_;
static void Iterate(ObjectVisitor* v,
List<internal::Object**>* blocks,
v8::ImplementationUtilities::HandleScopeData* handle_data);
void IterateThis(ObjectVisitor* v);
char* RestoreThreadHelper(char* from);
char* ArchiveThreadHelper(char* to);
......@@ -386,12 +384,12 @@ class HandleScopeImplementer {
static const int kHandleBlockSize = v8::internal::KB - 2; // fit in one page
void HandleScopeImplementer::SaveContext(Handle<Object> context) {
void HandleScopeImplementer::SaveContext(Context* context) {
saved_contexts_.Add(context);
}
Handle<Object> HandleScopeImplementer::RestoreContext() {
Context* HandleScopeImplementer::RestoreContext() {
return saved_contexts_.RemoveLast();
}
......
......@@ -62,9 +62,8 @@ class List {
return data_[i];
}
inline T& at(int i) const { return operator[](i); }
inline T& last() const {
return at(length_ - 1);
}
inline T& last() const { return at(length_ - 1); }
inline T& first() const { return at(0); }
INLINE(bool is_empty() const) { return length_ == 0; }
INLINE(int length() const) { return length_; }
......
......@@ -1201,19 +1201,24 @@ void Serializer::PutGlobalHandleStack(const List<Handle<Object> >& stack) {
void Serializer::PutContextStack() {
List<Handle<Object> > contexts(2);
List<Context*> contexts(2);
while (HandleScopeImplementer::instance()->HasSavedContexts()) {
Handle<Object> context =
Context* context =
HandleScopeImplementer::instance()->RestoreContext();
contexts.Add(context);
}
for (int i = contexts.length() - 1; i >= 0; i--) {
HandleScopeImplementer::instance()->SaveContext(contexts[i]);
}
PutGlobalHandleStack(contexts);
writer_->PutC('[');
writer_->PutInt(contexts.length());
if (!contexts.is_empty()) {
Object** start = reinterpret_cast<Object**>(&contexts.first());
VisitPointers(start, start + contexts.length());
}
writer_->PutC(']');
}
void Serializer::PutEncodedAddress(Address addr) {
writer_->PutC('P');
writer_->PutAddress(addr);
......@@ -1541,9 +1546,15 @@ void Deserializer::GetGlobalHandleStack(List<Handle<Object> >* stack) {
void Deserializer::GetContextStack() {
List<Handle<Object> > entered_contexts(2);
GetGlobalHandleStack(&entered_contexts);
for (int i = 0; i < entered_contexts.length(); i++) {
reader_.ExpectC('[');
int count = reader_.GetInt();
List<Context*> entered_contexts(count);
if (count > 0) {
Object** start = reinterpret_cast<Object**>(&entered_contexts.first());
VisitPointers(start, start + count);
}
reader_.ExpectC(']');
for (int i = 0; i < count; i++) {
HandleScopeImplementer::instance()->SaveContext(entered_contexts[i]);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment