Skip to content

Commit 8e3b224

Browse files
author
东煜
committed
[WEEX-368][Android] Turn single process switch on
Turn single process switch on for jsengine. Make it can run on single process Bug: WEEX-368
1 parent 947767b commit 8e3b224

File tree

4 files changed

+57
-38
lines changed

4 files changed

+57
-38
lines changed
-2.9 MB
Binary file not shown.
0 Bytes
Binary file not shown.

weex_core/Source/android/jsengine/multiprocess/WeexProxy.cpp

+54-36
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ static IPCSender *sSender;
3434
static std::unique_ptr<IPCHandler> sHandler;
3535
static std::unique_ptr<WeexJSConnection> sConnection;
3636
static WEEX_CORE_JS_SERVER_API_FUNCTIONS *js_server_api_functions = nullptr;
37-
bool g_use_single_process = true;
37+
bool g_use_single_process = false;
3838

3939
namespace WeexCore {
4040
void WeexProxy::reset() {
@@ -122,7 +122,11 @@ namespace WeexCore {
122122
}
123123

124124
jint
125-
WeexProxy::initFrameworkInMultiProcess(JNIEnv *env, jstring script, jobject params) {
125+
WeexProxy::initFrameworkInMultiProcess(JNIEnv *env, jstring script, jobject params,
126+
IPCSerializer *serializer) {
127+
128+
IPCSerializer *realSerializer = nullptr;
129+
std::unique_ptr<IPCSerializer> serializerTemp(createIPCSerializer());
126130
bool reinit = false;
127131
startInitFrameWork:
128132
try {
@@ -138,6 +142,15 @@ namespace WeexCore {
138142
return false;
139143
}
140144
} else {
145+
if (reinit) {
146+
initFromParam(env, script,
147+
params,
148+
serializerTemp.get());
149+
realSerializer = serializerTemp.get();
150+
} else {
151+
realSerializer = serializer;
152+
}
153+
141154
// initHandler(sHandler.get());
142155

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

147160
// using base::debug::TraceEvent;
148161
// TraceEvent::StartATrace(env);
149-
std::unique_ptr<IPCSerializer> serializer(createIPCSerializer());
150-
initFromParam(env, script, params, serializer.get());
151-
serializer->setMsg(static_cast<uint32_t>(IPCJSMsg::INITFRAMEWORK));
152-
153-
std::unique_ptr<IPCBuffer> buffer = serializer->finish();
162+
realSerializer->setMsg(static_cast<uint32_t>(IPCJSMsg::INITFRAMEWORK));
163+
std::unique_ptr<IPCBuffer> buffer = realSerializer->finish();
154164
std::unique_ptr<IPCResult> result = sSender->send(buffer.get());
155165
if (result->getType() != IPCType::INT32) {
156166
LOGE("initFramework Unexpected result type");
@@ -179,27 +189,32 @@ namespace WeexCore {
179189
jobject params) {
180190

181191
Bridge_Impl_Android::getInstance()->setGlobalRef(jThis);
192+
std::unique_ptr<IPCSerializer> serializer(createIPCSerializer());
193+
const std::vector<INIT_FRAMEWORK_PARAMS *> &initFrameworkParams = initFromParam(env,
194+
script,
195+
params,
196+
serializer.get());
197+
LOGE("Single process ? %s", g_use_single_process ? "true" : "false");
198+
if (g_use_single_process) {
199+
if (initFrameworkInSingleProcess(env, script, initFrameworkParams)) {
200+
//reportNativeInitStatus("-1011", "init Single Process Success");
201+
return true;
202+
}
182203

183-
LOGE("doInitFramework is running");
184-
// if (g_use_single_process) {
185-
// if (initFrameworkInSingleProcess(env, script, nullptr)) {
186-
// //reportNativeInitStatus("-1011", "init Single Process Success");
187-
// return true;
188-
// }
189-
//
190-
// if (initFrameworkInMultiProcess(env, script, params)) {
191-
// return true;
192-
// }
193-
// } else {
194-
if (initFrameworkInMultiProcess(env, script, params)) {
195-
return true;
204+
if (initFrameworkInMultiProcess(env, script, params, serializer.get())) {
205+
return true;
206+
}
207+
} else {
208+
if (initFrameworkInMultiProcess(env, script, params, serializer.get())) {
209+
return true;
210+
}
211+
212+
if (initFrameworkInSingleProcess(env, script, initFrameworkParams)) {
213+
reportNativeInitStatus("-1011", "init Single Process Success");
214+
return true;
215+
}
196216
}
197217

198-
// if (initFrameworkInSingleProcess(env, script, nullptr)) {
199-
// reportNativeInitStatus("-1011", "init Single Process Success");
200-
// return true;
201-
// }
202-
// }
203218
reportNativeInitStatus("-1010", "init Failed");
204219
return false;
205220

@@ -445,7 +460,8 @@ namespace WeexCore {
445460
callDIspatchMessage
446461
};
447462

448-
auto *functions = (WEEX_CORE_JS_API_FUNCTIONS *) malloc(sizeof(WEEX_CORE_JS_API_FUNCTIONS));
463+
auto *functions = (WEEX_CORE_JS_API_FUNCTIONS *) malloc(
464+
sizeof(WEEX_CORE_JS_API_FUNCTIONS));
449465

450466
if (!functions) {
451467
return nullptr;
@@ -461,11 +477,8 @@ namespace WeexCore {
461477
WEEX_CORE_JS_API_FUNCTIONS *functions);
462478

463479
jint
464-
WeexProxy::initFrameworkInSingleProcess(JNIEnv *env, jstring script, jobject params) {
465-
std::unique_ptr<IPCSerializer> serializer(createIPCSerializer());
466-
const std::vector<INIT_FRAMEWORK_PARAMS *> &initFrameworkParams = initFromParam(env, script,
467-
params,
468-
serializer.get());
480+
WeexProxy::initFrameworkInSingleProcess(JNIEnv *env, jstring script,
481+
const std::vector<INIT_FRAMEWORK_PARAMS *> initFrameworkParams) {
469482
std::string soPath = "";
470483

471484
// -----------------------------------------------
@@ -918,7 +931,8 @@ namespace WeexCore {
918931
if (jTypeInt == 1) {
919932
if (jDoubleValueMethodId == NULL) {
920933
jclass jDoubleClazz = env->FindClass("java/lang/Double");
921-
jDoubleValueMethodId = env->GetMethodID(jDoubleClazz, "doubleValue", "()D");
934+
jDoubleValueMethodId = env->GetMethodID(jDoubleClazz, "doubleValue",
935+
"()D");
922936
env->DeleteLocalRef(jDoubleClazz);
923937
}
924938
jdouble jDoubleObj = env->CallDoubleMethod(jDataObj, jDoubleValueMethodId);
@@ -1164,7 +1178,8 @@ namespace WeexCore {
11641178
}
11651179

11661180
jstring
1167-
WeexProxy::execJSOnInstance(JNIEnv *env, jobject jcaller, jstring instanceId, jstring script,
1181+
WeexProxy::execJSOnInstance(JNIEnv *env, jobject jcaller, jstring instanceId,
1182+
jstring script,
11681183
jint type) {
11691184
if (instanceId == NULL || script == NULL) {
11701185
return env->NewStringUTF("");
@@ -1250,7 +1265,8 @@ namespace WeexCore {
12501265
if (jTypeInt == 1) {
12511266
if (jDoubleValueMethodId == NULL) {
12521267
jclass jDoubleClazz = env->FindClass("java/lang/Double");
1253-
jDoubleValueMethodId = env->GetMethodID(jDoubleClazz, "doubleValue", "()D");
1268+
jDoubleValueMethodId = env->GetMethodID(jDoubleClazz, "doubleValue",
1269+
"()D");
12541270
env->DeleteLocalRef(jDoubleClazz);
12551271
}
12561272
jdouble jDoubleObj = env->CallDoubleMethod(jDataObj, jDoubleValueMethodId);
@@ -1481,7 +1497,8 @@ namespace WeexCore {
14811497
if (jTypeInt == 1) {
14821498
if (jDoubleValueMethodId == NULL) {
14831499
jclass jDoubleClazz = env->FindClass("java/lang/Double");
1484-
jDoubleValueMethodId = env->GetMethodID(jDoubleClazz, "doubleValue", "()D");
1500+
jDoubleValueMethodId = env->GetMethodID(jDoubleClazz, "doubleValue",
1501+
"()D");
14851502
env->DeleteLocalRef(jDoubleClazz);
14861503
}
14871504
jdouble jDoubleObj = env->CallDoubleMethod(jDataObj, jDoubleValueMethodId);
@@ -1532,7 +1549,8 @@ namespace WeexCore {
15321549
ScopedJStringUTF8 instanceId(env, jinstanceid);
15331550
ScopedJStringUTF8 funcChar(env, jfunction);
15341551
return js_server_api_functions->funcCallJSOnAppContext(instanceId.getChars(),
1535-
funcChar.getChars(), params);
1552+
funcChar.getChars(),
1553+
params);
15361554
} else {
15371555
std::unique_ptr<IPCBuffer> buffer = serializer->finish();
15381556
std::unique_ptr<IPCResult> result = sSender->send(buffer.get());

weex_core/Source/android/jsengine/multiprocess/WeexProxy.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,9 @@ class WeexProxy {
5353
initFromParam(JNIEnv *env, jstring script, jobject params, IPCSerializer *serializer);
5454

5555
static jint
56-
initFrameworkInSingleProcess(JNIEnv *env, jstring script, jobject params);
57-
static jint initFrameworkInMultiProcess(JNIEnv *env, jstring script, jobject params);
56+
initFrameworkInSingleProcess(JNIEnv *env, jstring script,
57+
const std::vector<INIT_FRAMEWORK_PARAMS *> initFrameworkParams);
58+
static jint initFrameworkInMultiProcess(JNIEnv *env, jstring script, jobject params, IPCSerializer *serializer);
5859

5960
static const char *getCacheDir(JNIEnv *env);
6061

0 commit comments

Comments
 (0)