From 39062b4248d2d11d2b24fa53f2b058e35d3fbe9e Mon Sep 17 00:00:00 2001 From: Stefan Siegl Date: Sun, 28 Feb 2016 17:48:44 +0100 Subject: [PATCH] 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. --- config.m4 | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ v8js_v8.cc | 7 +++++++ 2 files changed, 55 insertions(+) diff --git a/config.m4 b/config.m4 index 1e3c488..a192f5d 100644 --- a/config.m4 +++ b/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 diff --git a/v8js_v8.cc b/v8js_v8.cc index 8b52063..0b1b4b3 100644 --- a/v8js_v8.cc +++ b/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);