Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions test-app/runtime/src/main/cpp/Runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ Isolate* Runtime::PrepareV8Runtime(const string& filesPath, const string& native

void* snapshotPtr = nullptr;
string snapshotPath;
bool snapshotPathExists = false;

// If device isn't running on Sdk 17
if (m_androidVersion != 17) {
Expand Down Expand Up @@ -488,20 +489,28 @@ Isolate* Runtime::PrepareV8Runtime(const string& filesPath, const string& native
// we have a precompiled snapshot blob provided - try to load it directly
if (!Constants::V8_HEAP_SNAPSHOT_BLOB.empty()) {
snapshotPath = Constants::V8_HEAP_SNAPSHOT_BLOB;
snapshotPathExists = File::Exists(snapshotPath);
saveSnapshot = false;
} else {
snapshotPath = filesPath + "/internal/snapshot.blob";
std::string oldSnapshotBlobPath = filesPath + "/internal/snapshot.blob";
std::string snapshotBlobPath = filesPath + "/internal/TNSSnapshot.blob";

bool oldSnapshotExists = File::Exists(oldSnapshotBlobPath);
bool snapshotExists = File::Exists(snapshotBlobPath);

snapshotPathExists = oldSnapshotExists || snapshotExists;
snapshotPath = oldSnapshotExists ? oldSnapshotBlobPath : snapshotBlobPath;
}

if (File::Exists(snapshotPath)) {
if (snapshotPathExists) {
m_heapSnapshotBlob = new MemoryMappedFile(MemoryMappedFile::Open(snapshotPath.c_str()));
m_startupData->data = static_cast<const char*>(m_heapSnapshotBlob->memory);
m_startupData->raw_size = m_heapSnapshotBlob->size;
V8::SetSnapshotDataBlob(m_startupData);
isCustomSnapshotFound = true;
DEBUG_WRITE_FORCE("Snapshot read %s (%zuB).", snapshotPath.c_str(), m_heapSnapshotBlob->size);
} else if (!saveSnapshot) {
DEBUG_WRITE_FORCE("No snapshot file found at %s", snapshotPath.c_str());
throw NativeScriptException("No snapshot file found at: " + snapshotPath);
} else {
// This should be executed before V8::Initialize, which calls it with false.
NativeScriptExtension::CpuFeaturesProbe(true);
Expand Down