Reviewers: Yang,

Description:
Put V8 extras into the snapshot

Previously, all extras were "experimental" and left out of the snapshot. This
patch moves them to the snapshot, so now all extras are non-experimental. A
future patch will re-introduce experimental extras as part of the linked bug.

[email protected]
BUG=https://code.google.com/p/chromium/issues/detail?id=507137
LOG=Y

Please review this at https://codereview.chromium.org/1289603002/

Base URL: https://chromium.googlesource.com/v8/v8.git@master

Affected files (+44, -11 lines):
  M src/api.cc
  M src/bootstrapper.cc
  M src/snapshot/serialize.h
  M src/snapshot/serialize.cc


Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index 4f98293556bbd8d3eca3a15c2361c135477334f2..03d0e51c74b0f7d553e89c250e7e60190d457f21 100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -383,12 +383,18 @@ StartupData V8::CreateSnapshotDataBlob(const char* custom_source) {
       }
     }
     if (!context.IsEmpty()) {
-      // Make sure all builtin scripts are cached.
       {
         HandleScope scope(isolate);
+
+        // Make sure all builtin scripts are cached.
         for (int i = 0; i < i::Natives::GetBuiltinsCount(); i++) {
           internal_isolate->bootstrapper()->SourceLookup<i::Natives>(i);
         }
+
+        // Make sure all extra scripts are cached.
+        for (int i = 0; i < i::ExtraNatives::GetBuiltinsCount(); i++) {
+ internal_isolate->bootstrapper()->SourceLookup<i::ExtraNatives>(i);
+        }
       }
// If we don't do this then we end up with a stray root pointing at the
       // context even after we have disposed of the context.
Index: src/bootstrapper.cc
diff --git a/src/bootstrapper.cc b/src/bootstrapper.cc
index 5fee78310d4575e97d723900a44d590c8bf70603..b7c053c999a16ace6d1cd673679f95cc5dbed5c6 100644
--- a/src/bootstrapper.cc
+++ b/src/bootstrapper.cc
@@ -238,7 +238,7 @@ class Genesis BASE_EMBEDDED {
   void InstallTypedArray(const char* name, ElementsKind elements_kind,
                          Handle<JSFunction>* fun);
   bool InstallExperimentalNatives();
-  bool InstallExtraNatives();
+  bool InstallExtraNatives(ContextType context_type);
   bool InstallDebuggerNatives();
   void InstallBuiltinFunctionIds();
   void InstallExperimentalBuiltinFunctionIds();
@@ -2100,12 +2100,6 @@ bool Genesis::InstallNatives(ContextType context_type) {
                                 "utils container for native scripts");
   native_context()->set_natives_utils_object(*utils);

-  Handle<JSObject> extras_binding =
-      factory()->NewJSObject(isolate()->object_function());
- JSObject::NormalizeProperties(extras_binding, CLEAR_INOBJECT_PROPERTIES, 2, - "container for binding to/from extra natives");
-  native_context()->set_extras_binding_object(*extras_binding);
-
   if (FLAG_expose_natives_as != NULL) {
Handle<String> utils_key = factory()->NewStringFromAsciiChecked("utils");
     JSObject::AddProperty(builtins, utils_key, utils, NONE);
@@ -2613,7 +2607,19 @@ bool Genesis::InstallExperimentalNatives() {
 }


-bool Genesis::InstallExtraNatives() {
+bool Genesis::InstallExtraNatives(ContextType context_type) {
+  if (context_type == THIN_CONTEXT) {
+    return true;
+  }
+
+  HandleScope scope(isolate());
+
+  Handle<JSObject> extras_binding =
+      factory()->NewJSObject(isolate()->object_function());
+ JSObject::NormalizeProperties(extras_binding, CLEAR_INOBJECT_PROPERTIES, 2, + "container for binding to/from extra natives");
+  native_context()->set_extras_binding_object(*extras_binding);
+
   for (int i = ExtraNatives::GetDebuggerCount();
        i < ExtraNatives::GetBuiltinsCount(); i++) {
     if (!Bootstrapper::CompileExtraBuiltin(isolate(), i)) return false;
@@ -3218,6 +3224,7 @@ Genesis::Genesis(Isolate* isolate,
     InitializeNormalizedMapCaches();

     if (!InstallNatives(context_type)) return;
+    if (!InstallExtraNatives(context_type)) return;

     MakeFunctionInstancePrototypeWritable();

@@ -3234,7 +3241,6 @@ Genesis::Genesis(Isolate* isolate,
     if (!isolate->serializer_enabled()) {
       InitializeExperimentalGlobal();
       if (!InstallExperimentalNatives()) return;
-      if (!InstallExtraNatives()) return;
       // By now the utils object is useless and can be removed.
       native_context()->set_natives_utils_object(
           isolate->heap()->undefined_value());
Index: src/snapshot/serialize.cc
diff --git a/src/snapshot/serialize.cc b/src/snapshot/serialize.cc
index 81e071c0fb05809d6b905fe8c5373bbb8e6bc5e6..5b4bf9b4da6a32a03b11df1d3924bb348f8cf0f1 100644
--- a/src/snapshot/serialize.cc
+++ b/src/snapshot/serialize.cc
@@ -577,6 +577,13 @@ void Deserializer::Deserialize(Isolate* isolate) {
     }
   }

+  for (int i = 0; i < ExtraNatives::GetBuiltinsCount(); i++) {
+ Object* source = isolate_->heap()->extra_natives_source_cache()->get(i);
+    if (!source->IsUndefined()) {
+      ExternalOneByteString::cast(source)->update_data_cache();
+    }
+  }
+
   for (int i = 0; i < CodeStubNatives::GetBuiltinsCount(); i++) {
Object* source = isolate_->heap()->code_stub_natives_source_cache()->get(i);
     if (!source->IsUndefined()) {
@@ -1181,6 +1188,11 @@ bool Deserializer::ReadData(Object** current, Object** limit, int source_space,
                                       current);
         break;

+      case kExtraNativesStringResource:
+        current = CopyInNativesSource(
+            ExtraNatives::GetScriptSource(source_.Get()), current);
+        break;
+
       case kCodeStubNativesStringResource:
         current = CopyInNativesSource(
             CodeStubNatives::GetScriptSource(source_.Get()), current);
@@ -2192,6 +2204,12 @@ void Serializer::ObjectSerializer::VisitExternalOneByteString(
     return;
   }
   if (SerializeExternalNativeSourceString(
+          ExtraNatives::GetBuiltinsCount(), resource_pointer,
+          serializer_->isolate()->heap()->extra_natives_source_cache(),
+          kExtraNativesStringResource)) {
+    return;
+  }
+  if (SerializeExternalNativeSourceString(
           CodeStubNatives::GetBuiltinsCount(), resource_pointer,
           serializer_->isolate()->heap()->code_stub_natives_source_cache(),
           kCodeStubNativesStringResource)) {
Index: src/snapshot/serialize.h
diff --git a/src/snapshot/serialize.h b/src/snapshot/serialize.h
index c92683dfccc035e566c46f36cc6d52e01ae49117..780ce0f83428b13023f84690a16ce4faa8b3ae4c 100644
--- a/src/snapshot/serialize.h
+++ b/src/snapshot/serialize.h
@@ -401,8 +401,11 @@ class SerializerDeserializer: public ObjectVisitor {
// Used for the source code for compiled stubs, which is in the executable,
   // but is referred to from external strings in the snapshot.
   static const int kCodeStubNativesStringResource = 0x5d;
+  // Used for the source code for V8 extras, which is in the executable,
+  // but is referred to from external strings in the snapshot.
+  static const int kExtraNativesStringResource = 0x5e;

-  // 0x5e..0x5f unused
+  // 0x5f unused

   // ---------- byte code range 0x80..0xff ----------
   // First 32 root array items.


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to