Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

[WEEX-368][Android] Turn single process switch on for jsEngine #1178

Merged
merged 2 commits into from
May 16, 2018
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
Binary file modified android/sdk/libs/armeabi-v7a/libweexjss.so
Binary file not shown.
Binary file modified android/sdk/libs/armeabi/libweexjsc.so
Binary file not shown.
Binary file modified android/sdk/libs/armeabi/libweexjss.so
Binary file not shown.
90 changes: 54 additions & 36 deletions weex_core/Source/android/jsengine/multiprocess/WeexProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ static IPCSender *sSender;
static std::unique_ptr<IPCHandler> sHandler;
static std::unique_ptr<WeexJSConnection> sConnection;
static WEEX_CORE_JS_SERVER_API_FUNCTIONS *js_server_api_functions = nullptr;
bool g_use_single_process = true;
bool g_use_single_process = false;

namespace WeexCore {
void WeexProxy::reset() {
Expand Down Expand Up @@ -122,7 +122,11 @@ namespace WeexCore {
}

jint
WeexProxy::initFrameworkInMultiProcess(JNIEnv *env, jstring script, jobject params) {
WeexProxy::initFrameworkInMultiProcess(JNIEnv *env, jstring script, jobject params,
IPCSerializer *serializer) {

IPCSerializer *realSerializer = nullptr;
std::unique_ptr<IPCSerializer> serializerTemp(createIPCSerializer());
bool reinit = false;
startInitFrameWork:
try {
Expand All @@ -138,6 +142,15 @@ namespace WeexCore {
return false;
}
} else {
if (reinit) {
initFromParam(env, script,
params,
serializerTemp.get());
realSerializer = serializerTemp.get();
} else {
realSerializer = serializer;
}

// initHandler(sHandler.get());

ExtendJSApi *pExtensionJSApi = new ExtendJSApi();
Expand All @@ -146,11 +159,8 @@ namespace WeexCore {

// using base::debug::TraceEvent;
// TraceEvent::StartATrace(env);
std::unique_ptr<IPCSerializer> serializer(createIPCSerializer());
initFromParam(env, script, params, serializer.get());
serializer->setMsg(static_cast<uint32_t>(IPCJSMsg::INITFRAMEWORK));

std::unique_ptr<IPCBuffer> buffer = serializer->finish();
realSerializer->setMsg(static_cast<uint32_t>(IPCJSMsg::INITFRAMEWORK));
std::unique_ptr<IPCBuffer> buffer = realSerializer->finish();
std::unique_ptr<IPCResult> result = sSender->send(buffer.get());
if (result->getType() != IPCType::INT32) {
LOGE("initFramework Unexpected result type");
Expand Down Expand Up @@ -179,27 +189,32 @@ namespace WeexCore {
jobject params) {

Bridge_Impl_Android::getInstance()->setGlobalRef(jThis);
std::unique_ptr<IPCSerializer> serializer(createIPCSerializer());
const std::vector<INIT_FRAMEWORK_PARAMS *> &initFrameworkParams = initFromParam(env,
script,
params,
serializer.get());
LOGE("Single process ? %s", g_use_single_process ? "true" : "false");
if (g_use_single_process) {
if (initFrameworkInSingleProcess(env, script, initFrameworkParams)) {
//reportNativeInitStatus("-1011", "init Single Process Success");
return true;
}

LOGE("doInitFramework is running");
// if (g_use_single_process) {
// if (initFrameworkInSingleProcess(env, script, nullptr)) {
// //reportNativeInitStatus("-1011", "init Single Process Success");
// return true;
// }
//
// if (initFrameworkInMultiProcess(env, script, params)) {
// return true;
// }
// } else {
if (initFrameworkInMultiProcess(env, script, params)) {
return true;
if (initFrameworkInMultiProcess(env, script, params, serializer.get())) {
return true;
}
} else {
if (initFrameworkInMultiProcess(env, script, params, serializer.get())) {
return true;
}

if (initFrameworkInSingleProcess(env, script, initFrameworkParams)) {
reportNativeInitStatus("-1011", "init Single Process Success");
return true;
}
}

// if (initFrameworkInSingleProcess(env, script, nullptr)) {
// reportNativeInitStatus("-1011", "init Single Process Success");
// return true;
// }
// }
reportNativeInitStatus("-1010", "init Failed");
return false;

Expand Down Expand Up @@ -445,7 +460,8 @@ namespace WeexCore {
callDIspatchMessage
};

auto *functions = (WEEX_CORE_JS_API_FUNCTIONS *) malloc(sizeof(WEEX_CORE_JS_API_FUNCTIONS));
auto *functions = (WEEX_CORE_JS_API_FUNCTIONS *) malloc(
sizeof(WEEX_CORE_JS_API_FUNCTIONS));

if (!functions) {
return nullptr;
Expand All @@ -461,11 +477,8 @@ namespace WeexCore {
WEEX_CORE_JS_API_FUNCTIONS *functions);

jint
WeexProxy::initFrameworkInSingleProcess(JNIEnv *env, jstring script, jobject params) {
std::unique_ptr<IPCSerializer> serializer(createIPCSerializer());
const std::vector<INIT_FRAMEWORK_PARAMS *> &initFrameworkParams = initFromParam(env, script,
params,
serializer.get());
WeexProxy::initFrameworkInSingleProcess(JNIEnv *env, jstring script,
const std::vector<INIT_FRAMEWORK_PARAMS *> initFrameworkParams) {
std::string soPath = "";

// -----------------------------------------------
Expand Down Expand Up @@ -918,7 +931,8 @@ namespace WeexCore {
if (jTypeInt == 1) {
if (jDoubleValueMethodId == NULL) {
jclass jDoubleClazz = env->FindClass("java/lang/Double");
jDoubleValueMethodId = env->GetMethodID(jDoubleClazz, "doubleValue", "()D");
jDoubleValueMethodId = env->GetMethodID(jDoubleClazz, "doubleValue",
"()D");
env->DeleteLocalRef(jDoubleClazz);
}
jdouble jDoubleObj = env->CallDoubleMethod(jDataObj, jDoubleValueMethodId);
Expand Down Expand Up @@ -1164,7 +1178,8 @@ namespace WeexCore {
}

jstring
WeexProxy::execJSOnInstance(JNIEnv *env, jobject jcaller, jstring instanceId, jstring script,
WeexProxy::execJSOnInstance(JNIEnv *env, jobject jcaller, jstring instanceId,
jstring script,
jint type) {
if (instanceId == NULL || script == NULL) {
return env->NewStringUTF("");
Expand Down Expand Up @@ -1250,7 +1265,8 @@ namespace WeexCore {
if (jTypeInt == 1) {
if (jDoubleValueMethodId == NULL) {
jclass jDoubleClazz = env->FindClass("java/lang/Double");
jDoubleValueMethodId = env->GetMethodID(jDoubleClazz, "doubleValue", "()D");
jDoubleValueMethodId = env->GetMethodID(jDoubleClazz, "doubleValue",
"()D");
env->DeleteLocalRef(jDoubleClazz);
}
jdouble jDoubleObj = env->CallDoubleMethod(jDataObj, jDoubleValueMethodId);
Expand Down Expand Up @@ -1481,7 +1497,8 @@ namespace WeexCore {
if (jTypeInt == 1) {
if (jDoubleValueMethodId == NULL) {
jclass jDoubleClazz = env->FindClass("java/lang/Double");
jDoubleValueMethodId = env->GetMethodID(jDoubleClazz, "doubleValue", "()D");
jDoubleValueMethodId = env->GetMethodID(jDoubleClazz, "doubleValue",
"()D");
env->DeleteLocalRef(jDoubleClazz);
}
jdouble jDoubleObj = env->CallDoubleMethod(jDataObj, jDoubleValueMethodId);
Expand Down Expand Up @@ -1532,7 +1549,8 @@ namespace WeexCore {
ScopedJStringUTF8 instanceId(env, jinstanceid);
ScopedJStringUTF8 funcChar(env, jfunction);
return js_server_api_functions->funcCallJSOnAppContext(instanceId.getChars(),
funcChar.getChars(), params);
funcChar.getChars(),
params);
} else {
std::unique_ptr<IPCBuffer> buffer = serializer->finish();
std::unique_ptr<IPCResult> result = sSender->send(buffer.get());
Expand Down
5 changes: 3 additions & 2 deletions weex_core/Source/android/jsengine/multiprocess/WeexProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ class WeexProxy {
initFromParam(JNIEnv *env, jstring script, jobject params, IPCSerializer *serializer);

static jint
initFrameworkInSingleProcess(JNIEnv *env, jstring script, jobject params);
static jint initFrameworkInMultiProcess(JNIEnv *env, jstring script, jobject params);
initFrameworkInSingleProcess(JNIEnv *env, jstring script,
const std::vector<INIT_FRAMEWORK_PARAMS *> initFrameworkParams);
static jint initFrameworkInMultiProcess(JNIEnv *env, jstring script, jobject params, IPCSerializer *serializer);

static const char *getCacheDir(JNIEnv *env);

Expand Down