Reviewers: Vyacheslav Egorov,

Message:
Could you please take a look? This is one of Steven's open CLs.

Description:
Increase eval compilation cache hits.

This CL introduces two changes to the eval compilation cache. Firstly,
instead of checking for SharedFunctionInfo equivalence to ensure
equivalence of direct eval call sites we now check for Script and
scope start position equivalence.

Furthermore, we increase the cache hits by allowing to share global
eval code for direct and indirect call sites, e.g. in the case
var x = eval; x("12"); eval("12");

Patch from Steven Keuchel <[email protected]>
Original CL: http://codereview.chromium.org/8879010/

BUG=v8:1854
TEST=existing tests in mjsunit
[email protected]

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

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files:
  M src/compilation-cache.h
  M src/compilation-cache.cc
  M src/objects.cc


Index: src/compilation-cache.cc
diff --git a/src/compilation-cache.cc b/src/compilation-cache.cc
index 82cc2231a36326a38191a95cf2c80fea3112fbff..db4ce5f2a493dbaf70a1cbf43e800742de2d4cdc 100644
--- a/src/compilation-cache.cc
+++ b/src/compilation-cache.cc
@@ -404,8 +404,9 @@ Handle<SharedFunctionInfo> CompilationCache::LookupEval(

   Handle<SharedFunctionInfo> result;
   if (is_global) {
+    ASSERT(context->IsGlobalContext());
     result = eval_global_.Lookup(
-        source, context, language_mode, scope_position);
+        source, context, language_mode, RelocInfo::kNoPosition);
   } else {
     ASSERT(scope_position != RelocInfo::kNoPosition);
     result = eval_contextual_.Lookup(
@@ -446,7 +447,8 @@ void CompilationCache::PutEval(Handle<String> source,

   HandleScope scope(isolate());
   if (is_global) {
-    eval_global_.Put(source, context, function_info, scope_position);
+    ASSERT(context->IsGlobalContext());
+ eval_global_.Put(source, context, function_info, RelocInfo::kNoPosition);
   } else {
     ASSERT(scope_position != RelocInfo::kNoPosition);
     eval_contextual_.Put(source, context, function_info, scope_position);
Index: src/compilation-cache.h
diff --git a/src/compilation-cache.h b/src/compilation-cache.h
index 2f2fbadb2e5904cff99896bb38b7cbefb34e3d35..39420f713ebabfc7065302f02424db4db6c99851 100644
--- a/src/compilation-cache.h
+++ b/src/compilation-cache.h
@@ -126,14 +126,19 @@ class CompilationCacheScript : public CompilationSubCache {
 // considers the following pieces of information when checking for matching
 // entries:
 // 1. The source string.
-// 2. The shared function info of the calling function.
+// 2. The script of the calling function.
 // 3. Whether the source should be compiled as strict code or as non-strict
 //    code.
 //    Note: Currently there are clients of CompileEval that always compile
// non-strict code even if the calling function is a strict mode function.
 //    More specifically these are the CompileString, DebugEvaluate and
 //    DebugEvaluateGlobal runtime functions.
-// 4. The start position of the calling scope.
+// 4. The start position of the calling scope in the script source code.
+// Note: The script plus the start position of the calling scope uniquely
+//    determine the shape of the outer scope of the eval call.
+// Note: For eval calls in global context RelocInfo::kNoPosition is always +// used as the scope position to enable sharing between direct and indirect
+//    global eval calls.
 class CompilationCacheEval: public CompilationSubCache {
  public:
   CompilationCacheEval(Isolate* isolate, int generations)
Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index 41f2ab6d8823f2e85ee1ec636e0016a495273fa6..6adfaa6d0b91c3cb21bbc499f0ff8c85ed153db1 100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -10497,7 +10497,7 @@ class StringSharedKey : public HashTableKey {
     if (!other->IsFixedArray()) return false;
     FixedArray* other_array = FixedArray::cast(other);
SharedFunctionInfo* shared = SharedFunctionInfo::cast(other_array->get(0));
-    if (shared != shared_) return false;
+    if (shared->script() != shared_->script()) return false;
     int language_unchecked = Smi::cast(other_array->get(2))->value();
     ASSERT(language_unchecked == CLASSIC_MODE ||
            language_unchecked == STRICT_MODE ||


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

Reply via email to