Преглед изворни кода

Test for snapshot support in V8

Looks like we have to test for internal functions unfortunately
since the public V8 snapshot API is available no matter whether
the library really supports it or not.
Stefan Siegl пре 9 година
родитељ
комит
39062b4248
2 измењених фајлова са 55 додато и 0 уклоњено
  1. 48 0
      config.m4
  2. 7 0
      v8js_v8.cc

+ 48 - 0
config.m4

@@ -130,6 +130,54 @@ int main ()
     AC_MSG_ERROR([could not determine libv8 version])
   fi
 
+  AC_MSG_CHECKING([for v8::internal::ReadNatives])
+  AC_TRY_LINK([
+    namespace v8 {
+      namespace internal {
+        void ReadNatives();
+      }
+    }], [v8::internal::ReadNatives();], [
+      AC_MSG_RESULT([found (using snapshots)])
+      AC_DEFINE([PHP_V8_USE_EXTERNAL_STARTUP_DATA], [1], [Whether V8 requires (and can be provided with custom versions of) external startup data])
+
+      SEARCH_PATH="$V8_DIR/lib"
+
+      AC_MSG_CHECKING([for natives_blob.bin])
+      SEARCH_FOR="natives_blob.bin"
+
+      for i in $SEARCH_PATH ; do
+        if test -r $i/$SEARCH_FOR; then
+          AC_MSG_RESULT([found ($i/$SEARCH_FOR)])
+          AC_DEFINE_UNQUOTED([PHP_V8_NATIVES_BLOB_PATH], "$i/$SEARCH_FOR", [Full path to natives_blob.bin file])
+          native_blob_found=1
+        fi
+      done
+
+      if test -z "$native_blob_found"; then
+        AC_MSG_RESULT([not found])
+        AC_MSG_ERROR([Please provide V8 native blob as needed])
+      fi
+
+      AC_MSG_CHECKING([for snapshot_blob.bin])
+      SEARCH_FOR="snapshot_blob.bin"
+
+      for i in $SEARCH_PATH ; do
+        if test -r $i/$SEARCH_FOR; then
+          AC_MSG_RESULT([found ($i/$SEARCH_FOR)])
+          AC_DEFINE_UNQUOTED([PHP_V8_SNAPSHOT_BLOB_PATH], "$i/$SEARCH_FOR", [Full path to snapshot_blob.bin file])
+          snapshot_blob_found=1
+        fi
+      done
+
+      if test -z "$snapshot_blob_found"; then
+        AC_MSG_RESULT([not found])
+        AC_MSG_ERROR([Please provide V8 snapshot blob as needed])
+      fi
+
+    ], [
+      AC_MSG_RESULT([not found (snapshots disabled)])
+    ])
+
   AC_LANG_RESTORE
   LIBS=$old_LIBS
   LDFLAGS=$old_LDFLAGS

+ 7 - 0
v8js_v8.cc

@@ -54,6 +54,13 @@ void v8js_v8_init(TSRMLS_D) /* {{{ */
 	}
 #endif
 
+#ifdef PHP_V8_USE_EXTERNAL_STARTUP_DATA
+	v8::V8::InitializeExternalStartupData(
+		PHP_V8_NATIVES_BLOB_PATH,
+		PHP_V8_SNAPSHOT_BLOB_PATH
+	);
+#endif
+
 #if !defined(_WIN32) && PHP_V8_API_VERSION >= 3029036
 	v8js_process_globals.v8_platform = v8::platform::CreateDefaultPlatform();
 	v8::V8::InitializePlatform(v8js_process_globals.v8_platform);