|
22 | 22 | #include "include/libplatform/libplatform.h" |
23 | 23 | #include "include/zipconf.h" |
24 | 24 | #include <sstream> |
| 25 | +#include <dlfcn.h> |
25 | 26 |
|
26 | 27 | using namespace v8; |
27 | 28 | using namespace std; |
@@ -425,13 +426,20 @@ Isolate* Runtime::PrepareV8Runtime(const string& filesPath, jstring packageName, |
425 | 426 | bool didInitializeV8 = false; |
426 | 427 |
|
427 | 428 | create_params.array_buffer_allocator = &g_allocator; |
428 | | - // prepare the snapshot blob |
429 | | - if (!Constants::V8_HEAP_SNAPSHOT_BLOB.empty() || !Constants::V8_HEAP_SNAPSHOT_SCRIPT.empty()) |
| 429 | + |
| 430 | + m_startupData = new StartupData(); |
| 431 | + |
| 432 | + void* snapshotPtr = dlopen("libsnapshot.so", RTLD_LAZY | RTLD_LOCAL); |
| 433 | + if (snapshotPtr) |
| 434 | + { |
| 435 | + m_startupData->data = static_cast<const char *>(dlsym(snapshotPtr, "TNSSnapshot_blob")); |
| 436 | + m_startupData->raw_size = *static_cast<const unsigned int *>(dlsym(snapshotPtr, "TNSSnapshot_blob_len")); |
| 437 | + DEBUG_WRITE_FORCE("Snapshot library read %p (%dB).", m_startupData->data, m_startupData->raw_size); |
| 438 | + } |
| 439 | + else if (!Constants::V8_HEAP_SNAPSHOT_BLOB.empty() || !Constants::V8_HEAP_SNAPSHOT_SCRIPT.empty()) |
430 | 440 | { |
431 | 441 | DEBUG_WRITE_FORCE("Snapshot enabled."); |
432 | 442 |
|
433 | | - m_startupData = new StartupData(); |
434 | | - |
435 | 443 | string snapshotPath; |
436 | 444 | bool saveSnapshot = true; |
437 | 445 | // we have a precompiled snapshot blob provided - try to load it directly |
@@ -496,10 +504,10 @@ Isolate* Runtime::PrepareV8Runtime(const string& filesPath, jstring packageName, |
496 | 504 | } |
497 | 505 | } |
498 | 506 | } |
499 | | - |
500 | | - create_params.snapshot_blob = m_startupData; |
501 | 507 | } |
502 | 508 |
|
| 509 | + create_params.snapshot_blob = m_startupData; |
| 510 | + |
503 | 511 | /* |
504 | 512 | * Setup the V8Platform only once per process - once for the application lifetime |
505 | 513 | * Don't execute again if main thread has already been initialized |
|
0 commit comments