Skip to content

Commit 1770aa5

Browse files
authored
Merge pull request #602 from NativeScript/jassonpet/snapshot-so
Load snapshot from external shared library
2 parents ba54425 + 147705b commit 1770aa5

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

runtime/src/main/jni/Runtime.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "include/libplatform/libplatform.h"
2323
#include "include/zipconf.h"
2424
#include <sstream>
25+
#include <dlfcn.h>
2526

2627
using namespace v8;
2728
using namespace std;
@@ -425,13 +426,20 @@ Isolate* Runtime::PrepareV8Runtime(const string& filesPath, jstring packageName,
425426
bool didInitializeV8 = false;
426427

427428
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())
430440
{
431441
DEBUG_WRITE_FORCE("Snapshot enabled.");
432442

433-
m_startupData = new StartupData();
434-
435443
string snapshotPath;
436444
bool saveSnapshot = true;
437445
// we have a precompiled snapshot blob provided - try to load it directly
@@ -496,10 +504,10 @@ Isolate* Runtime::PrepareV8Runtime(const string& filesPath, jstring packageName,
496504
}
497505
}
498506
}
499-
500-
create_params.snapshot_blob = m_startupData;
501507
}
502508

509+
create_params.snapshot_blob = m_startupData;
510+
503511
/*
504512
* Setup the V8Platform only once per process - once for the application lifetime
505513
* Don't execute again if main thread has already been initialized

0 commit comments

Comments
 (0)