Revision: 12397
Author:   [email protected]
Date:     Tue Aug 28 03:49:23 2012
Log:      Index script compilation cache over context, too,
in preparation for global lexical scope.

[email protected]
BUG=
TEST=

Review URL: https://chromiumcodereview.appspot.com/10878007
http://code.google.com/p/v8/source/detail?r=12397

Modified:
 /branches/bleeding_edge/src/api.cc
 /branches/bleeding_edge/src/bootstrapper.cc
 /branches/bleeding_edge/src/compilation-cache.cc
 /branches/bleeding_edge/src/compilation-cache.h
 /branches/bleeding_edge/src/compiler.cc
 /branches/bleeding_edge/src/compiler.h
 /branches/bleeding_edge/src/debug.cc
 /branches/bleeding_edge/src/objects.cc
 /branches/bleeding_edge/src/objects.h
 /branches/bleeding_edge/test/cctest/test-compiler.cc
 /branches/bleeding_edge/test/cctest/test-decls.cc

=======================================
--- /branches/bleeding_edge/src/api.cc  Mon Aug 27 12:47:02 2012
+++ /branches/bleeding_edge/src/api.cc  Tue Aug 28 03:49:23 2012
@@ -1539,6 +1539,7 @@
                            name_obj,
                            line_offset,
                            column_offset,
+                           isolate->native_context(),
                            NULL,
                            pre_data_impl,
                            Utils::OpenHandle(*script_data),
=======================================
--- /branches/bleeding_edge/src/bootstrapper.cc Mon Aug 27 06:47:34 2012
+++ /branches/bleeding_edge/src/bootstrapper.cc Tue Aug 28 03:49:23 2012
@@ -1347,6 +1347,7 @@
         script_name,
         0,
         0,
+        top_context,
         extension,
         NULL,
         Handle<String>::null(),
=======================================
--- /branches/bleeding_edge/src/compilation-cache.cc Thu Nov 24 07:17:04 2011 +++ /branches/bleeding_edge/src/compilation-cache.cc Tue Aug 28 03:49:23 2012
@@ -165,10 +165,12 @@
 // be cached in the same script generation. Currently the first use
 // will be cached, but subsequent code from different source / line
 // won't.
-Handle<SharedFunctionInfo> CompilationCacheScript::Lookup(Handle<String> source, - Handle<Object> name,
-                                                          int line_offset,
- int column_offset) {
+Handle<SharedFunctionInfo> CompilationCacheScript::Lookup(
+    Handle<String> source,
+    Handle<Object> name,
+    int line_offset,
+    int column_offset,
+    Handle<Context> context) {
   Object* result = NULL;
   int generation;

@@ -177,7 +179,7 @@
   { HandleScope scope(isolate());
     for (generation = 0; generation < generations(); generation++) {
       Handle<CompilationCacheTable> table = GetTable(generation);
-      Handle<Object> probe(table->Lookup(*source), isolate());
+      Handle<Object> probe(table->Lookup(*source, *context), isolate());
       if (probe->IsSharedFunctionInfo()) {
         Handle<SharedFunctionInfo> function_info =
             Handle<SharedFunctionInfo>::cast(probe);
@@ -214,7 +216,7 @@
     ASSERT(HasOrigin(shared, name, line_offset, column_offset));
     // If the script was found in a later generation, we promote it to
     // the first generation to let it survive longer in the cache.
-    if (generation != 0) Put(source, shared);
+    if (generation != 0) Put(source, context, shared);
     isolate()->counters()->compilation_cache_hits()->Increment();
     return shared;
   } else {
@@ -226,25 +228,28 @@

 MaybeObject* CompilationCacheScript::TryTablePut(
     Handle<String> source,
+    Handle<Context> context,
     Handle<SharedFunctionInfo> function_info) {
   Handle<CompilationCacheTable> table = GetFirstTable();
-  return table->Put(*source, *function_info);
+  return table->Put(*source, *context, *function_info);
 }


 Handle<CompilationCacheTable> CompilationCacheScript::TablePut(
     Handle<String> source,
+    Handle<Context> context,
     Handle<SharedFunctionInfo> function_info) {
   CALL_HEAP_FUNCTION(isolate(),
-                     TryTablePut(source, function_info),
+                     TryTablePut(source, context, function_info),
                      CompilationCacheTable);
 }


 void CompilationCacheScript::Put(Handle<String> source,
+                                 Handle<Context> context,
Handle<SharedFunctionInfo> function_info) {
   HandleScope scope(isolate());
-  SetFirstTable(TablePut(source, function_info));
+  SetFirstTable(TablePut(source, context, function_info));
 }


@@ -380,15 +385,17 @@
 }


-Handle<SharedFunctionInfo> CompilationCache::LookupScript(Handle<String> source, - Handle<Object> name,
-                                                          int line_offset,
- int column_offset) {
+Handle<SharedFunctionInfo> CompilationCache::LookupScript(
+    Handle<String> source,
+    Handle<Object> name,
+    int line_offset,
+    int column_offset,
+    Handle<Context> context) {
   if (!IsEnabled()) {
     return Handle<SharedFunctionInfo>::null();
   }

-  return script_.Lookup(source, name, line_offset, column_offset);
+  return script_.Lookup(source, name, line_offset, column_offset, context);
 }


@@ -426,12 +433,13 @@


 void CompilationCache::PutScript(Handle<String> source,
+                                 Handle<Context> context,
Handle<SharedFunctionInfo> function_info) {
   if (!IsEnabled()) {
     return;
   }

-  script_.Put(source, function_info);
+  script_.Put(source, context, function_info);
 }


=======================================
--- /branches/bleeding_edge/src/compilation-cache.h     Fri Aug 17 02:03:08 2012
+++ /branches/bleeding_edge/src/compilation-cache.h     Tue Aug 28 03:49:23 2012
@@ -98,16 +98,23 @@
   Handle<SharedFunctionInfo> Lookup(Handle<String> source,
                                     Handle<Object> name,
                                     int line_offset,
-                                    int column_offset);
- void Put(Handle<String> source, Handle<SharedFunctionInfo> function_info);
+                                    int column_offset,
+                                    Handle<Context> context);
+  void Put(Handle<String> source,
+           Handle<Context> context,
+           Handle<SharedFunctionInfo> function_info);

  private:
   MUST_USE_RESULT MaybeObject* TryTablePut(
-      Handle<String> source, Handle<SharedFunctionInfo> function_info);
+      Handle<String> source,
+      Handle<Context> context,
+      Handle<SharedFunctionInfo> function_info);

   // Note: Returns a new hash table if operation results in expansion.
   Handle<CompilationCacheTable> TablePut(
-      Handle<String> source, Handle<SharedFunctionInfo> function_info);
+      Handle<String> source,
+      Handle<Context> context,
+      Handle<SharedFunctionInfo> function_info);

   bool HasOrigin(Handle<SharedFunctionInfo> function_info,
                  Handle<Object> name,
@@ -204,7 +211,8 @@
   Handle<SharedFunctionInfo> LookupScript(Handle<String> source,
                                           Handle<Object> name,
                                           int line_offset,
-                                          int column_offset);
+                                          int column_offset,
+                                          Handle<Context> context);

   // Finds the shared function info for a source string for eval in a
   // given context.  Returns an empty handle if the cache doesn't
@@ -223,6 +231,7 @@
   // Associate the (source, kind) pair to the shared function
   // info. This may overwrite an existing mapping.
   void PutScript(Handle<String> source,
+                 Handle<Context> context,
                  Handle<SharedFunctionInfo> function_info);

   // Associate the (source, context->closure()->shared(), kind) triple
=======================================
--- /branches/bleeding_edge/src/compiler.cc     Tue Aug 28 00:18:06 2012
+++ /branches/bleeding_edge/src/compiler.cc     Tue Aug 28 03:49:23 2012
@@ -541,6 +541,7 @@
                                              Handle<Object> script_name,
                                              int line_offset,
                                              int column_offset,
+                                             Handle<Context> context,
                                              v8::Extension* extension,
                                              ScriptDataImpl* pre_data,
                                              Handle<Object> script_data,
@@ -561,7 +562,8 @@
     result = compilation_cache->LookupScript(source,
                                              script_name,
                                              line_offset,
-                                             column_offset);
+                                             column_offset,
+                                             context);
   }

   if (result.is_null()) {
@@ -598,7 +600,7 @@
     }
     result = MakeFunctionInfo(&info);
     if (extension == NULL && !result.is_null() && !result->dont_cache()) {
-      compilation_cache->PutScript(source, result);
+      compilation_cache->PutScript(source, context, result);
     }
   } else {
     if (result->ic_age() != HEAP->global_ic_age()) {
=======================================
--- /branches/bleeding_edge/src/compiler.h      Tue Aug 28 00:18:06 2012
+++ /branches/bleeding_edge/src/compiler.h      Tue Aug 28 03:49:23 2012
@@ -431,6 +431,7 @@
                                             Handle<Object> script_name,
                                             int line_offset,
                                             int column_offset,
+                                            Handle<Context> context,
                                             v8::Extension* extension,
                                             ScriptDataImpl* pre_data,
                                             Handle<Object> script_data,
=======================================
--- /branches/bleeding_edge/src/debug.cc        Fri Aug 17 05:59:00 2012
+++ /branches/bleeding_edge/src/debug.cc        Tue Aug 28 03:49:23 2012
@@ -745,12 +745,15 @@
       isolate->bootstrapper()->NativesSourceLookup(index);
   Vector<const char> name = Natives::GetScriptName(index);
   Handle<String> script_name = factory->NewStringFromAscii(name);
+  Handle<Context> context = isolate->native_context();

   // Compile the script.
   Handle<SharedFunctionInfo> function_info;
   function_info = Compiler::Compile(source_code,
                                     script_name,
-                                    0, 0, NULL, NULL,
+                                    0, 0,
+                                    context,
+                                    NULL, NULL,
                                     Handle<String>::null(),
                                     NATIVES_CODE);

@@ -762,7 +765,6 @@
   }

   // Execute the shared function in the debugger context.
-  Handle<Context> context = isolate->native_context();
   bool caught_exception;
   Handle<JSFunction> function =
       factory->NewFunctionFromSharedFunctionInfo(function_info, context);
=======================================
--- /branches/bleeding_edge/src/objects.cc      Tue Aug 28 00:18:06 2012
+++ /branches/bleeding_edge/src/objects.cc      Tue Aug 28 03:49:23 2012
@@ -11944,8 +11944,23 @@
 }


-Object* CompilationCacheTable::Lookup(String* src) {
-  StringKey key(src);
+// The key for the script compilation cache is dependent on the mode flags,
+// because they change the global language mode and thus binding behaviour.
+// If flags change at some point, we must ensure that we do not hit the cache
+// for code compiled with different settings.
+static LanguageMode CurrentGlobalLanguageMode() {
+  return FLAG_use_strict
+      ? (FLAG_harmony_scoping ? EXTENDED_MODE : STRICT_MODE)
+      : CLASSIC_MODE;
+}
+
+
+Object* CompilationCacheTable::Lookup(String* src, Context* context) {
+  SharedFunctionInfo* shared = context->closure()->shared();
+  StringSharedKey key(src,
+                      shared,
+                      CurrentGlobalLanguageMode(),
+                      RelocInfo::kNoPosition);
   int entry = FindEntry(&key);
   if (entry == kNotFound) return GetHeap()->undefined_value();
   return get(EntryToIndex(entry) + 1);
@@ -11975,8 +11990,14 @@
 }


-MaybeObject* CompilationCacheTable::Put(String* src, Object* value) {
-  StringKey key(src);
+MaybeObject* CompilationCacheTable::Put(String* src,
+                                        Context* context,
+                                        Object* value) {
+  SharedFunctionInfo* shared = context->closure()->shared();
+  StringSharedKey key(src,
+                      shared,
+                      CurrentGlobalLanguageMode(),
+                      RelocInfo::kNoPosition);
   Object* obj;
   { MaybeObject* maybe_obj = EnsureCapacity(1, &key);
     if (!maybe_obj->ToObject(&obj)) return maybe_obj;
@@ -11985,7 +12006,13 @@
   CompilationCacheTable* cache =
       reinterpret_cast<CompilationCacheTable*>(obj);
   int entry = cache->FindInsertionEntry(key.Hash());
-  cache->set(EntryToIndex(entry), src);
+
+  Object* k;
+  { MaybeObject* maybe_k = key.AsObject();
+    if (!maybe_k->ToObject(&k)) return maybe_k;
+  }
+
+  cache->set(EntryToIndex(entry), k);
   cache->set(EntryToIndex(entry) + 1, value);
   cache->ElementAdded();
   return cache;
=======================================
--- /branches/bleeding_edge/src/objects.h       Tue Aug 28 00:18:06 2012
+++ /branches/bleeding_edge/src/objects.h       Tue Aug 28 03:49:23 2012
@@ -6672,13 +6672,15 @@
                                               HashTableKey*> {
  public:
   // Find cached value for a string key, otherwise return null.
-  Object* Lookup(String* src);
+  Object* Lookup(String* src, Context* context);
   Object* LookupEval(String* src,
                      Context* context,
                      LanguageMode language_mode,
                      int scope_position);
   Object* LookupRegExp(String* source, JSRegExp::Flags flags);
-  MUST_USE_RESULT MaybeObject* Put(String* src, Object* value);
+  MUST_USE_RESULT MaybeObject* Put(String* src,
+                                   Context* context,
+                                   Object* value);
   MUST_USE_RESULT MaybeObject* PutEval(String* src,
                                        Context* context,
                                        SharedFunctionInfo* value,
=======================================
--- /branches/bleeding_edge/test/cctest/test-compiler.cc Fri Aug 17 05:59:00 2012 +++ /branches/bleeding_edge/test/cctest/test-compiler.cc Tue Aug 28 03:49:23 2012
@@ -120,6 +120,7 @@
                         Handle<String>(),
                         0,
                         0,
+ Handle<Context>(Isolate::Current()->native_context()),
                         NULL,
                         NULL,
                         Handle<String>::null(),
=======================================
--- /branches/bleeding_edge/test/cctest/test-decls.cc Thu Aug 23 09:38:15 2012 +++ /branches/bleeding_edge/test/cctest/test-decls.cc Tue Aug 28 03:49:23 2012
@@ -874,7 +874,7 @@
     context.Check("const x = 1; x",
                   EXPECT_RESULT, Number::New(1));
     context.Check("var x = 2; x",
-                  EXPECT_RESULT, Number::New(1));
+                  EXPECT_EXCEPTION);
   }

   { SimpleContext context;

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

Reply via email to