Reviewers: Mads Ager,

Description:
[Isolates] Speed up Context::Lookup by avoiding implicit TLS reads.

Please review this at http://codereview.chromium.org/6538089/

Affected files:
  M src/contexts.cc
  M src/runtime.cc


Index: src/contexts.cc
diff --git a/src/contexts.cc b/src/contexts.cc
index 2698342397ba503144095a4ee35be4f0043e0507..520f3dde2444e4d87e5817ddb6f3e54c27edbcc1 100644
--- a/src/contexts.cc
+++ b/src/contexts.cc
@@ -76,8 +76,8 @@ void Context::set_global_proxy(JSObject* object) {

Handle<Object> Context::Lookup(Handle<String> name, ContextLookupFlags flags, int* index_, PropertyAttributes* attributes) {
-  Heap* heap = GetHeap();
-  Handle<Context> context(this);
+  Isolate* isolate = GetIsolate();
+  Handle<Context> context(this, isolate);

   bool follow_context_chain = (flags & FOLLOW_CONTEXT_CHAIN) != 0;
   *index_ = -1;
@@ -98,7 +98,8 @@ Handle<Object> Context::Lookup(Handle<String> name, ContextLookupFlags flags,

     // check extension/with object
     if (context->has_extension()) {
-      Handle<JSObject> extension = Handle<JSObject>(context->extension());
+      Handle<JSObject> extension = Handle<JSObject>(context->extension(),
+                                                    isolate);
       // Context extension objects needs to behave as if they have no
       // prototype.  So even if we want to follow prototype chains, we
       // need to only do a local lookup for context extension objects.
@@ -123,7 +124,7 @@ Handle<Object> Context::Lookup(Handle<String> name, ContextLookupFlags flags,

       // check non-parameter locals in context
       Handle<SerializedScopeInfo> scope_info(
-          context->closure()->shared()->scope_info());
+          context->closure()->shared()->scope_info(), isolate);
       Variable::Mode mode;
       int index = scope_info->ContextSlotIndex(*name, &mode);
       ASSERT(index < 0 || index >= MIN_CONTEXT_SLOTS);
@@ -156,11 +157,12 @@ Handle<Object> Context::Lookup(Handle<String> name, ContextLookupFlags flags,
       int param_index = scope_info->ParameterIndex(*name);
       if (param_index >= 0) {
         // slot found.
-        int index =
- scope_info->ContextSlotIndex(heap->arguments_shadow_symbol(), NULL);
+        int index = scope_info->ContextSlotIndex(
+            isolate->heap()->arguments_shadow_symbol(), NULL);
ASSERT(index >= 0); // arguments must exist and be in the heap context
-        Handle<JSObject> arguments(JSObject::cast(context->get(index)));
-        ASSERT(arguments->HasLocalProperty(heap->length_symbol()));
+        Handle<JSObject> arguments(JSObject::cast(context->get(index)),
+                                   isolate);
+ ASSERT(arguments->HasLocalProperty(isolate->heap()->length_symbol()));
         if (FLAG_trace_contexts) {
PrintF("=> found parameter %d in arguments object\n", param_index);
         }
@@ -189,9 +191,10 @@ Handle<Object> Context::Lookup(Handle<String> name, ContextLookupFlags flags,
     if (context->IsGlobalContext()) {
       follow_context_chain = false;
     } else if (context->is_function_context()) {
- context = Handle<Context>(Context::cast(context->closure()->context())); + context = Handle<Context>(Context::cast(context->closure()->context()),
+                                isolate);
     } else {
-      context = Handle<Context>(context->previous());
+      context = Handle<Context>(context->previous(), isolate);
     }
   } while (follow_context_chain);

Index: src/runtime.cc
diff --git a/src/runtime.cc b/src/runtime.cc
index 3c40896f742cf8bd23de10f79f6e5f9ad73fabc0..4d430c3651978cab63c1dfd70b0134d2ffa3a494 100644
--- a/src/runtime.cc
+++ b/src/runtime.cc
@@ -5444,7 +5444,7 @@ static MaybeObject* Runtime_StringToArray(RUNTIME_CALLING_CONVENTION) {
           isolate->heap()->AllocateUninitializedFixedArray(length);
       if (!maybe_obj->ToObject(&obj)) return maybe_obj;
     }
-    elements = Handle<FixedArray>(FixedArray::cast(obj));
+    elements = Handle<FixedArray>(FixedArray::cast(obj), isolate);

     Vector<const char> chars = s->ToAsciiVector();
     // Note, this will initialize all elements (not only the prefix)
@@ -7893,7 +7893,7 @@ static ObjectPair Runtime_ResolvePossiblyDirectEval(
   Handle<Object> receiver;  // Will be overwritten.

   // Compute the calling context.
-  Handle<Context> context = Handle<Context>(isolate->context());
+  Handle<Context> context = Handle<Context>(isolate->context(), isolate);
 #ifdef DEBUG
   // Make sure Isolate::context() agrees with the old code that traversed
   // the stack frames to compute the context.
@@ -7914,9 +7914,10 @@ static ObjectPair Runtime_ResolvePossiblyDirectEval(
     // reached.
     if (attributes != ABSENT || context->IsGlobalContext()) break;
     if (context->is_function_context()) {
- context = Handle<Context>(Context::cast(context->closure()->context())); + context = Handle<Context>(Context::cast(context->closure()->context()),
+                                isolate);
     } else {
-      context = Handle<Context>(context->previous());
+      context = Handle<Context>(context->previous(), isolate);
     }
   }

@@ -7938,7 +7939,7 @@ static ObjectPair Runtime_ResolvePossiblyDirectEval(
       receiver = Handle<Object>(context->get(index), isolate);
     } else if (receiver->IsJSContextExtensionObject()) {
       receiver = Handle<JSObject>(
-          isolate->context()->global()->global_receiver());
+          isolate->context()->global()->global_receiver(), isolate);
     }
     return MakePair(*callee, *receiver);
   }


--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to