Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions src/jni/Constants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ bool Constants::V8_CACHE_COMPILED_CODE = false;
bool Constants::V8_HEAP_SNAPSHOT = false;
std::string Constants::V8_STARTUP_FLAGS = "";
std::string Constants::V8_HEAP_SNAPSHOT_SCRIPT = "";
std::string Constants::V8_HEAP_SNAPSHOT_BLOB = "";
1 change: 1 addition & 0 deletions src/jni/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Constants
static std::string APP_ROOT_FOLDER_PATH;
static std::string V8_STARTUP_FLAGS;
static std::string V8_HEAP_SNAPSHOT_SCRIPT;
static std::string V8_HEAP_SNAPSHOT_BLOB;
static bool V8_CACHE_COMPILED_CODE;
static bool V8_HEAP_SNAPSHOT;

Expand Down
22 changes: 18 additions & 4 deletions src/jni/Runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ void Runtime::Init(jstring filesPath, bool verboseLoggingEnabled, jstring packag
Constants::V8_HEAP_SNAPSHOT = (bool)snapshot;
JniLocalRef snapshotScript(m_env.GetObjectArrayElement(args, 3));
Constants::V8_HEAP_SNAPSHOT_SCRIPT = ArgConverter::jstringToString(snapshotScript);
JniLocalRef profilerOutputDir(m_env.GetObjectArrayElement(args, 4));
JniLocalRef snapshotBlob(m_env.GetObjectArrayElement(args, 4));
Constants::V8_HEAP_SNAPSHOT_BLOB = ArgConverter::jstringToString(snapshotBlob);
JniLocalRef profilerOutputDir(m_env.GetObjectArrayElement(args, 5));

DEBUG_WRITE("Initializing Telerik NativeScript");

Expand Down Expand Up @@ -360,16 +362,28 @@ Isolate* Runtime::PrepareV8Runtime(const string& filesPath, jstring packageName,

m_startupData = new StartupData();

auto snapshotPath = filesPath + "/internal/snapshot.blob";
if( File::Exists(snapshotPath))
string snapshotPath;
bool saveSnapshot = true;
// we have a precompiled snapshot blob provided - try to load it directly
if (Constants::V8_HEAP_SNAPSHOT_BLOB.size() > 0)
{
snapshotPath = Constants::V8_HEAP_SNAPSHOT_BLOB;
saveSnapshot = false;
}
else
{
snapshotPath = filesPath + "/internal/snapshot.blob";
}

if (File::Exists(snapshotPath))
{
int length;
m_startupData->data = reinterpret_cast<char*>(File::ReadBinary(snapshotPath, length));
m_startupData->raw_size = length;

DEBUG_WRITE_FORCE("Snapshot read %s (%dB).", snapshotPath.c_str(), length);
}
else
else if(saveSnapshot)
{
// check for custom script to include in the snapshot
if(Constants::V8_HEAP_SNAPSHOT_SCRIPT.size() > 0 && File::Exists(Constants::V8_HEAP_SNAPSHOT_SCRIPT))
Expand Down
21 changes: 20 additions & 1 deletion src/src/com/tns/V8Config.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
package com.tns;

import java.io.File;

import org.json.JSONObject;

import android.os.Build;

class V8Config
{
private static final String AndroidKey = "android";
private static final String V8FlagsKey = "v8Flags";
private static final String CodeCacheKey = "codeCache";
private static final String HeapSnapshotKey = "heapSnapshot";
private static final String HeapSnapshotScriptKey = "heapSnapshotScript";
private static final String HeapSnapshotBlobKey = "heapSnapshotBlob";
private static final String SnapshotFile = "snapshot.blob";
private static final String ProfilerOutputDirKey = "profilerOutputDir";

public static Object[] fromPackageJSON(File appDir)
Expand Down Expand Up @@ -45,9 +50,21 @@ public static Object[] fromPackageJSON(File appDir)
String value = androidObject.getString(HeapSnapshotScriptKey);
result[3] = FileSystem.resolveRelativePath(appDir.getPath(), value, appDir + "/app/");
}
if(androidObject.has(HeapSnapshotBlobKey))
{
String value = androidObject.getString(HeapSnapshotBlobKey);
String path = FileSystem.resolveRelativePath(appDir.getPath(), value, appDir + "/app/");
File dir = new File(path);
if(dir.exists() && dir.isDirectory())
{
// this path is expected to be a directory, containing three sub-directories: armeabi-v7a, x86 and arm64-v8a
path = path + "/" + Build.CPU_ABI + "/" + SnapshotFile;
result[4] = path;
}
}
if(androidObject.has(ProfilerOutputDirKey))
{
result[4] = androidObject.getString(ProfilerOutputDirKey);
result[5] = androidObject.getString(ProfilerOutputDirKey);
}
}
}
Expand All @@ -70,6 +87,8 @@ private static Object[] makeDefaultOptions()
false,
// arbitrary script to be included in the snapshot
"",
// a binary file containing an already saved snapshot
"",
// V8 profiler output directory
""
};
Expand Down