You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by ky...@apache.org on 2019/03/25 09:06:37 UTC

[incubator-weex] branch master updated: MultiThread Init sequence (#2241)

This is an automated email from the ASF dual-hosted git repository.

kyork pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-weex.git


The following commit(s) were added to refs/heads/master by this push:
     new 36dce32  MultiThread Init sequence (#2241)
36dce32 is described below

commit 36dce32c461a6ed4b2843d66b188d0bd04000f1f
Author: darin <dy...@qq.com>
AuthorDate: Mon Mar 25 17:06:32 2019 +0800

    MultiThread Init sequence (#2241)
---
 android/sdk/libs/armeabi-v7a/libweexcore.so        | Bin 2152328 -> 2160520 bytes
 android/sdk/libs/armeabi-v7a/libweexjss.so         | Bin 554600 -> 554600 bytes
 android/sdk/libs/armeabi/libweexcore.so            | Bin 2156424 -> 2160520 bytes
 android/sdk/libs/armeabi/libweexjss.so             | Bin 554600 -> 558696 bytes
 android/sdk/libs/x86/libweexcore.so                | Bin 3344296 -> 3356584 bytes
 android/sdk/libs/x86/libweexjss.so                 | Bin 988792 -> 992888 bytes
 .../com/taobao/weex/adapter/IWXConfigAdapter.java  |  18 +++++++
 .../taobao/weex/adapter/IWXJscProcessManager.java  |   1 +
 .../com/taobao/weex/base/SystemMessageHandler.java |  38 +++++++--------
 .../com/taobao/weex/bridge/WXBridgeManager.java    |   5 ++
 .../script/script_bridge_in_multi_process.cpp      |   4 ++
 .../bridge/script/script_side_in_queue.cpp         |  52 +++++++++++++++++----
 .../Source/android/jsengine/object/weex_env.cpp    |  42 +++++++++++++++++
 .../Source/android/jsengine/object/weex_env.h      |  38 +++++++++++++--
 .../android/jsengine/object/weex_object_holder.cpp |   3 +-
 .../android/jsengine/task/weex_task_queue.cpp      |   8 ++++
 .../Source/android/jsengine/weex_ipc_server.cpp    |   6 +--
 weex_core/Source/android/jsengine/weex_runtime.cpp |  38 +++++++++------
 weex_core/Source/base/crash/crash_handler.cpp      |   5 ++
 weex_core/Source/base/crash/crash_handler.h        |   3 +-
 20 files changed, 206 insertions(+), 55 deletions(-)

diff --git a/android/sdk/libs/armeabi-v7a/libweexcore.so b/android/sdk/libs/armeabi-v7a/libweexcore.so
index 18b5de7..20422d8 100644
Binary files a/android/sdk/libs/armeabi-v7a/libweexcore.so and b/android/sdk/libs/armeabi-v7a/libweexcore.so differ
diff --git a/android/sdk/libs/armeabi-v7a/libweexjss.so b/android/sdk/libs/armeabi-v7a/libweexjss.so
index 47ebe7e..7291bae 100644
Binary files a/android/sdk/libs/armeabi-v7a/libweexjss.so and b/android/sdk/libs/armeabi-v7a/libweexjss.so differ
diff --git a/android/sdk/libs/armeabi/libweexcore.so b/android/sdk/libs/armeabi/libweexcore.so
index b28376c..32d0f9f 100644
Binary files a/android/sdk/libs/armeabi/libweexcore.so and b/android/sdk/libs/armeabi/libweexcore.so differ
diff --git a/android/sdk/libs/armeabi/libweexjss.so b/android/sdk/libs/armeabi/libweexjss.so
index 55cf96f..162b3e6 100644
Binary files a/android/sdk/libs/armeabi/libweexjss.so and b/android/sdk/libs/armeabi/libweexjss.so differ
diff --git a/android/sdk/libs/x86/libweexcore.so b/android/sdk/libs/x86/libweexcore.so
index cc15bfd..e2e0dd7 100644
Binary files a/android/sdk/libs/x86/libweexcore.so and b/android/sdk/libs/x86/libweexcore.so differ
diff --git a/android/sdk/libs/x86/libweexjss.so b/android/sdk/libs/x86/libweexjss.so
index de0123b..bb1a94a 100644
Binary files a/android/sdk/libs/x86/libweexjss.so and b/android/sdk/libs/x86/libweexjss.so differ
diff --git a/android/sdk/src/main/java/com/taobao/weex/adapter/IWXConfigAdapter.java b/android/sdk/src/main/java/com/taobao/weex/adapter/IWXConfigAdapter.java
index 7897352..9eee5b0 100644
--- a/android/sdk/src/main/java/com/taobao/weex/adapter/IWXConfigAdapter.java
+++ b/android/sdk/src/main/java/com/taobao/weex/adapter/IWXConfigAdapter.java
@@ -1,3 +1,21 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
 package com.taobao.weex.adapter;
 
 /**
diff --git a/android/sdk/src/main/java/com/taobao/weex/adapter/IWXJscProcessManager.java b/android/sdk/src/main/java/com/taobao/weex/adapter/IWXJscProcessManager.java
index db15534..4c8d22a 100644
--- a/android/sdk/src/main/java/com/taobao/weex/adapter/IWXJscProcessManager.java
+++ b/android/sdk/src/main/java/com/taobao/weex/adapter/IWXJscProcessManager.java
@@ -22,6 +22,7 @@ import com.taobao.weex.WXSDKInstance;
 
 public interface IWXJscProcessManager {
     boolean enableBackupThread();
+    boolean enableBackUpThreadCache();
     boolean shouldReboot();
     long rebootTimeout();
     boolean withException(WXSDKInstance instance);
diff --git a/android/sdk/src/main/java/com/taobao/weex/base/SystemMessageHandler.java b/android/sdk/src/main/java/com/taobao/weex/base/SystemMessageHandler.java
index de4e599..50ecfa7 100644
--- a/android/sdk/src/main/java/com/taobao/weex/base/SystemMessageHandler.java
+++ b/android/sdk/src/main/java/com/taobao/weex/base/SystemMessageHandler.java
@@ -77,25 +77,25 @@ public class SystemMessageHandler extends Handler implements Serializable {
     private Message obtainAsyncMessage(int what) {
         Message msg = Message.obtain();
         msg.what = what;
-        if (mMessageMethodSetAsynchronous != null) {
-            // If invocation fails, assume this is indicative of future
-            // failures, and avoid log spam by nulling the reflected method.
-            try {
-                mMessageMethodSetAsynchronous.invoke(msg, true);
-            } catch (IllegalAccessException e) {
-                Log.e(TAG, "Illegal access to asynchronous message creation, disabling.");
-                mMessageMethodSetAsynchronous = null;
-            } catch (IllegalArgumentException e) {
-                Log.e(TAG, "Illegal argument for asynchronous message creation, disabling.");
-                mMessageMethodSetAsynchronous = null;
-            } catch (InvocationTargetException e) {
-                Log.e(TAG, "Invocation exception during asynchronous message creation, disabling.");
-                mMessageMethodSetAsynchronous = null;
-            } catch (RuntimeException e) {
-                Log.e(TAG, "Runtime exception during asynchronous message creation, disabling.");
-                mMessageMethodSetAsynchronous = null;
-            }
-        }
+//        if (mMessageMethodSetAsynchronous != null) {
+//            // If invocation fails, assume this is indicative of future
+//            // failures, and avoid log spam by nulling the reflected method.
+//            try {
+//                mMessageMethodSetAsynchronous.invoke(msg, true);
+//            } catch (IllegalAccessException e) {
+//                Log.e(TAG, "Illegal access to asynchronous message creation, disabling.");
+//                mMessageMethodSetAsynchronous = null;
+//            } catch (IllegalArgumentException e) {
+//                Log.e(TAG, "Illegal argument for asynchronous message creation, disabling.");
+//                mMessageMethodSetAsynchronous = null;
+//            } catch (InvocationTargetException e) {
+//                Log.e(TAG, "Invocation exception during asynchronous message creation, disabling.");
+//                mMessageMethodSetAsynchronous = null;
+//            } catch (RuntimeException e) {
+//                Log.e(TAG, "Runtime exception during asynchronous message creation, disabling.");
+//                mMessageMethodSetAsynchronous = null;
+//            }
+//        }
         return msg;
     }
 
diff --git a/android/sdk/src/main/java/com/taobao/weex/bridge/WXBridgeManager.java b/android/sdk/src/main/java/com/taobao/weex/bridge/WXBridgeManager.java
index 9e6d63f..ff0fd53 100644
--- a/android/sdk/src/main/java/com/taobao/weex/bridge/WXBridgeManager.java
+++ b/android/sdk/src/main/java/com/taobao/weex/bridge/WXBridgeManager.java
@@ -2054,6 +2054,11 @@ public class WXBridgeManager implements Callback, BactchExecutor {
     wxParams.setDeviceHeight(TextUtils.isEmpty(config.get("deviceHeight")) ? String.valueOf(WXViewUtils.getScreenHeight(WXEnvironment.sApplication)) : config.get("deviceHeight"));
     Map<String, String> customOptions = WXEnvironment.getCustomOptions();
     customOptions.put("enableBackupThread", String.valueOf(jsEngineMultiThreadEnable()));
+    IWXJscProcessManager wxJscProcessManager = WXSDKManager.getInstance().getWXJscProcessManager();
+    if(wxJscProcessManager != null) {
+      customOptions.put("enableBackupThreadCache", String.valueOf(wxJscProcessManager.enableBackUpThreadCache()));
+    }
+
     wxParams.setOptions(customOptions);
     wxParams.setNeedInitV8(WXSDKManager.getInstance().needInitV8());
     mInitParams = wxParams;
diff --git a/weex_core/Source/android/jsengine/bridge/script/script_bridge_in_multi_process.cpp b/weex_core/Source/android/jsengine/bridge/script/script_bridge_in_multi_process.cpp
index 56d83ac..101aac2 100644
--- a/weex_core/Source/android/jsengine/bridge/script/script_bridge_in_multi_process.cpp
+++ b/weex_core/Source/android/jsengine/bridge/script/script_bridge_in_multi_process.cpp
@@ -259,6 +259,10 @@ namespace weex {
                             auto enable = value == "true";
                             LOGE("enable backupThread %d",enable);
                             WeexEnv::getEnv()->setEnableBackupThread(enable);
+                        } else if(type == "enableBackupThreadCache") {
+                            auto enable = value == "true";
+                            LOGE("enable backupThreadCache %d",enable);
+                            WeexEnv::getEnv()->set_m_cache_task_(enable);
                         }
                     }
 
diff --git a/weex_core/Source/android/jsengine/bridge/script/script_side_in_queue.cpp b/weex_core/Source/android/jsengine/bridge/script/script_side_in_queue.cpp
index 3275790..b74ce04 100644
--- a/weex_core/Source/android/jsengine/bridge/script/script_side_in_queue.cpp
+++ b/weex_core/Source/android/jsengine/bridge/script/script_side_in_queue.cpp
@@ -49,9 +49,21 @@ int ScriptSideInQueue::InitFramework(
   weexTaskQueue_->init();
 
   if (WeexEnv::getEnv()->enableBackupThread()) {
-    weexTaskQueue_bk_ = new WeexTaskQueue(weexTaskQueue_->isMultiProgress);
-    weexTaskQueue_bk_->addTask(new InitFrameworkTask(String::fromUTF8(script), params));
-    weexTaskQueue_bk_->init();
+    WeexEnv::getEnv()->locker()->lock();
+    while (!WeexEnv::getEnv()->is_jsc_init_finished()) {
+      WeexEnv::getEnv()->locker()->wait();
+    }
+    WeexEnv::getEnv()->locker()->unlock();
+
+    if(WeexEnv::getEnv()->can_m_cache_task_()) {
+      WeexEnv::getEnv()->m_task_cache_.push_back(new InitFrameworkTask(String::fromUTF8(script), params));
+      LOGE("cache initFramework %d", WeexEnv::getEnv()->m_task_cache_.size());
+    } else {
+      weexTaskQueue_bk_ = new WeexTaskQueue(weexTaskQueue_->isMultiProgress);
+      weexTaskQueue_bk_->addTask(new InitFrameworkTask(String::fromUTF8(script), params));
+      weexTaskQueue_bk_->init();
+    }
+
   }
 
   return 1;
@@ -119,8 +131,15 @@ int ScriptSideInQueue::ExecJsService(const char *source) {
   LOGD("ScriptSideInQueue::ExecJsService");
 
   weexTaskQueue_->addTask(new ExeJsServicesTask(String::fromUTF8(source)));
-  if (WeexEnv::getEnv()->enableBackupThread() && weexTaskQueue_bk_ != nullptr) {
-    weexTaskQueue_bk_->addTask(new ExeJsServicesTask(String::fromUTF8(source)));
+  if (WeexEnv::getEnv()->enableBackupThread()) {
+    ExeJsServicesTask *task = new ExeJsServicesTask(String::fromUTF8(source));
+    if(WeexEnv::getEnv()->can_m_cache_task_() && weexTaskQueue_bk_ == nullptr){
+      WeexEnv::getEnv()->m_task_cache_.push_back(task);
+      LOGE("cache ExecJsService %d", WeexEnv::getEnv()->m_task_cache_.size());
+    } else {
+      weexTaskQueue_bk_->addTask(task);
+    }
+    
   }
 
   return 1;
@@ -148,8 +167,13 @@ int ScriptSideInQueue::ExecJS(const char *instanceId, const char *nameSpace,
   task->addExtraArg(String::fromUTF8(func));
 
   if (instanceId == nullptr || strlen(instanceId) == 0) {
-    if (WeexEnv::getEnv()->enableBackupThread() && weexTaskQueue_bk_ != nullptr) {
-      weexTaskQueue_bk_->addTask(task->clone());
+    if (WeexEnv::getEnv()->enableBackupThread()) {
+      if(WeexEnv::getEnv()->can_m_cache_task_() && weexTaskQueue_bk_ == nullptr){
+        WeexEnv::getEnv()->m_task_cache_.push_back(task->clone());
+        LOGE("cache ExecJS %d", WeexEnv::getEnv()->m_task_cache_.size());
+      } else {
+        weexTaskQueue_bk_->addTask(task->clone());
+      }
     }
 
     weexTaskQueue_->addTask(task);
@@ -198,6 +222,7 @@ int ScriptSideInQueue::CreateInstance(const char *instanceId,
       "CreateInstance id = %s, func = %s, script = %s, opts = %s, initData = "
       "%s, extendsApi = %s",
       instanceId, func, script, opts, initData, extendsApi);
+  bool backUpThread = false;
   if (WeexEnv::getEnv()->enableBackupThread()) {
     for (int i = 0; i < params.size(); ++i) {
       auto param = params[i];
@@ -205,12 +230,17 @@ int ScriptSideInQueue::CreateInstance(const char *instanceId,
       auto value = String::fromUTF8(param->value->content);
       if (type == "use_back_thread") {
         if (value == "true") {
-          useBackUpWeexRuntime(instanceId);
+          backUpThread = true;
         }
         break;
       }
     }
   }
+
+  if(backUpThread) {
+    useBackUpWeexRuntime(instanceId);
+  }
+
   auto string = String::fromUTF8(script);
   if (string.isEmpty()) {
     return 0;
@@ -289,6 +319,12 @@ WeexTaskQueue *ScriptSideInQueue::taskQueue(const char *id, bool log) {
   if (id != nullptr && shouldUseBackUpWeexRuntime(id)) {
     if (weexTaskQueue_bk_ == nullptr) {
       weexTaskQueue_bk_ = new WeexTaskQueue(weexTaskQueue_->isMultiProgress);
+      WeexEnv::getEnv()->set_m_cache_task_(false);
+      for (std::deque<WeexTask *>::iterator it = WeexEnv::getEnv()->m_task_cache_.begin(); it < WeexEnv::getEnv()->m_task_cache_.end(); ++it) {
+        auto reference = *it;
+        weexTaskQueue_bk_->addTask(std::move(reference));
+      }
+      WeexEnv::getEnv()->m_task_cache_.clear();
     }
     if (log) {
       LOGE("dyyLog instance %s use back up thread time is %lld", id, microTime());
diff --git a/weex_core/Source/android/jsengine/object/weex_env.cpp b/weex_core/Source/android/jsengine/object/weex_env.cpp
index f4d7241..755f926 100644
--- a/weex_core/Source/android/jsengine/object/weex_env.cpp
+++ b/weex_core/Source/android/jsengine/object/weex_env.cpp
@@ -34,9 +34,51 @@ void WeexEnv::setScriptBridge(WeexCore::ScriptBridge *scriptBridge) { scriptBrid
 
 void WeexEnv::initIPC() {
     // init IpcClient in io Thread
+    isMultiProcess = true;
     m_ipc_client_.reset(new WeexIPCClient(ipcClientFd_));
 }
 WeexEnv::WeexEnv() {
     this->enableBackupThread__ = false;
     this->isUsingWson = true;
+    this->isJscInitOk_ = false;
+    this->m_cache_task_ = true;
+}
+
+void WeexEnv::initJSC(bool isMultiProgress) {
+    static std::once_flag initJSCFlag;
+    std::call_once(initJSCFlag, [isMultiProgress]{
+      if (!WEEXICU::initICUEnv(isMultiProgress)) {
+          LOGE("failed to init ICUEnv single process");
+          // return false;
+      }
+
+      Options::enableRestrictedOptions(true);
+// Initialize JSC before getting VM.
+      WTF::initializeMainThread();
+      initHeapTimer();
+      JSC::initializeThreading();
+#if ENABLE(WEBASSEMBLY)
+      JSC::Wasm::enableFastMemory();
+#endif
+    });
+}
+void WeexEnv::init_crash_handler(std::string crashFileName) {
+  // initialize signal handler
+  isMultiProcess = true;
+  crashHandler.reset(new crash_handler::CrashHandlerInfo(crashFileName));
+  crashHandler->initializeCrashHandler();
+}
+bool WeexEnv::is_app_crashed() {
+  if(!isMultiProcess)
+    return false;
+  return crashHandler->is_crashed();
+}
+volatile bool WeexEnv::can_m_cache_task_() const {
+  return m_cache_task_;
+}
+void WeexEnv::set_m_cache_task_(volatile bool m_cache_task_) {
+  WeexEnv::m_cache_task_ = m_cache_task_;
+}
+WeexEnv::~WeexEnv() {
+  wson::destory();
 }
diff --git a/weex_core/Source/android/jsengine/object/weex_env.h b/weex_core/Source/android/jsengine/object/weex_env.h
index 207eca7..86e851d 100644
--- a/weex_core/Source/android/jsengine/object/weex_env.h
+++ b/weex_core/Source/android/jsengine/object/weex_env.h
@@ -24,6 +24,7 @@
 #define WEEXV8_WEEXENV_H
 
 #include <mutex>
+#include <task/weex_task.h>
 #include "android/jsengine/task/back_to_weex_core_queue.h"
 
 #include "android/jsengine/task/timer_queue.h"
@@ -41,6 +42,8 @@ public:
 
     WeexEnv();
 
+    ~WeexEnv();
+
     bool useWson();
 
     void setUseWson(bool useWson);
@@ -76,6 +79,8 @@ public:
 
     void initIPC();
 
+    void initJSC(bool isMultiProgress);
+
     void setEnableBackupThread(bool enable) {
         this->enableBackupThread__ = enable;
     }
@@ -84,16 +89,28 @@ public:
         return enableBackupThread__;
     }
 
-public:
+    void jsc_init_finished() { isJscInitOk_ = true; };
+
+    bool is_jsc_init_finished() {return isJscInitOk_; }
+
+    ThreadLocker* locker() { return &thread_locker_; }
+
+    void init_crash_handler(std::string crashFileName);
+
+    bool is_app_crashed();
+ public:
     std::unique_ptr<BackToWeexCoreQueue> m_back_to_weex_core_thread;
-    volatile bool isMultiProcess = true;
+    volatile bool isMultiProcess = false;
     std::unique_ptr<WeexIPCClient> m_ipc_client_;
-private:
+
+    std::deque<WeexTask *> m_task_cache_;
+
+ private:
     static WeexEnv *env_;
 
-    volatile bool isUsingWson = true;
+    volatile bool isJscInitOk_ = false;
 
-    std::unique_ptr<TimerQueue> weexTimerQueue_;
+    volatile bool isUsingWson = true;
 
     WeexCore::ScriptBridge *scriptBridge_;
 
@@ -102,6 +119,17 @@ private:
     volatile int ipcClientFd_;
     volatile int ipcServerFd_;
     volatile bool enableTrace_;
+
+    volatile bool m_cache_task_;
+ public:
+  volatile bool can_m_cache_task_() const;
+  void set_m_cache_task_(volatile bool m_cache_task_);
+ private:
+
+  ThreadLocker thread_locker_;
+
+   std::unique_ptr<crash_handler::CrashHandlerInfo> crashHandler;
+
 };
 
 
diff --git a/weex_core/Source/android/jsengine/object/weex_object_holder.cpp b/weex_core/Source/android/jsengine/object/weex_object_holder.cpp
index 196402f..343bde6 100644
--- a/weex_core/Source/android/jsengine/object/weex_object_holder.cpp
+++ b/weex_core/Source/android/jsengine/object/weex_object_holder.cpp
@@ -69,7 +69,6 @@ void WeexObjectHolder::initFromParams(std::vector<INIT_FRAMEWORK_PARAMS *> &para
     globalObject->timeQueue = this->timeQueue;
     m_globalObject.set(vm, globalObject);
     vm.heap.setGarbageCollectionTimerEnabled(true);
-    wson::init(&vm);
 }
 
 WeexObjectHolder::WeexObjectHolder(VM* vm,  TimerQueue* timeQueue, bool isMultiProgress) {
@@ -98,7 +97,7 @@ WeexGlobalObject *WeexObjectHolder::cloneWeexObject(std::string page_id, bool in
 }
 
 WeexObjectHolder::~WeexObjectHolder() {
-    wson::destory();
+//    wson::destory();
     JSLockHolder locker(this->m_globalVM);
     this->m_globalVM->heap.collectAllGarbage();
 }
diff --git a/weex_core/Source/android/jsengine/task/weex_task_queue.cpp b/weex_core/Source/android/jsengine/task/weex_task_queue.cpp
index 6fe03ce..baa8a1c 100644
--- a/weex_core/Source/android/jsengine/task/weex_task_queue.cpp
+++ b/weex_core/Source/android/jsengine/task/weex_task_queue.cpp
@@ -29,6 +29,9 @@
 #include "android/jsengine/object/weex_env.h"
 
 void WeexTaskQueue::run(WeexTask *task) {
+    if(task == nullptr || WeexEnv::getEnv()->is_app_crashed()) {
+        return;
+    }
     task->timeCalculator->set_task_name(task->taskName());
     task->timeCalculator->taskStart();
     task->run(weexRuntime);
@@ -60,6 +63,11 @@ WeexTask *WeexTaskQueue::getTask() {
             continue;
         }
 
+        if(WeexEnv::getEnv()->is_app_crashed()) {
+          threadLocker.unlock();
+          return nullptr;
+        }
+
         assert(!taskQueue_.empty());
         task = taskQueue_.front();
         taskQueue_.pop_front();
diff --git a/weex_core/Source/android/jsengine/weex_ipc_server.cpp b/weex_core/Source/android/jsengine/weex_ipc_server.cpp
index 2593a5a..3d31037 100644
--- a/weex_core/Source/android/jsengine/weex_ipc_server.cpp
+++ b/weex_core/Source/android/jsengine/weex_ipc_server.cpp
@@ -27,7 +27,6 @@
 using namespace JSC;
 using namespace WTF;
 using namespace WEEXICU;
-using namespace crash_handler;
 
 
 struct WeexJSServer::WeexJSServerImpl {
@@ -38,7 +37,6 @@ struct WeexJSServer::WeexJSServerImpl {
     std::unique_ptr<IPCHandler> handler;
     std::unique_ptr<IPCListener> listener;
     std::unique_ptr<IPCSerializer> serializer;
-    std::unique_ptr<CrashHandlerInfo> crashHandler;
 };
 
 WeexJSServer::WeexJSServerImpl::WeexJSServerImpl(int serverFd, int clientFd, bool enableTrace, std::string crashFileName) {
@@ -60,9 +58,7 @@ WeexJSServer::WeexJSServerImpl::WeexJSServerImpl(int serverFd, int clientFd, boo
     listener = std::move(createIPCListener(futexPageQueue.get(), handler.get()));
     serializer = std::move(createIPCSerializer());
 
-    // initialize signal handler
-    crashHandler.reset(new CrashHandlerInfo(crashFileName));
-    crashHandler->initializeCrashHandler();
+    WeexEnv::getEnv()->init_crash_handler(crashFileName);
 
     WeexEnv::getEnv()->m_back_to_weex_core_thread.reset(new BackToWeexCoreQueue());
     WeexEnv::getEnv()->m_back_to_weex_core_thread.get()->init();
diff --git a/weex_core/Source/android/jsengine/weex_runtime.cpp b/weex_core/Source/android/jsengine/weex_runtime.cpp
index e908cdc..300c03b 100644
--- a/weex_core/Source/android/jsengine/weex_runtime.cpp
+++ b/weex_core/Source/android/jsengine/weex_runtime.cpp
@@ -34,21 +34,18 @@ using namespace WEEXICU;
 
 
 WeexRuntime::WeexRuntime(TimerQueue* timeQueue,bool isMultiProgress) : is_multi_process_(isMultiProgress), script_bridge_(nullptr) {
-    if (!WEEXICU::initICUEnv(isMultiProgress)) {
-        LOGE("failed to init ICUEnv single process");
-        // return false;
-    }
-
-    Options::enableRestrictedOptions(true);
-// Initialize JSC before getting VM.
-    WTF::initializeMainThread();
-    initHeapTimer();
-    JSC::initializeThreading();
-#if ENABLE(WEBASSEMBLY)
-    JSC::Wasm::enableFastMemory();
-#endif
+    WeexEnv::getEnv()->initJSC(isMultiProgress);
     m_globalVM = std::move(VM::create(LargeHeap));
 
+    static bool wson_init_flag = false;
+    if(!wson_init_flag) {
+      wson_init_flag = true;
+      wson::init(m_globalVM.get());
+    }
+
+    WeexEnv::getEnv()->jsc_init_finished();
+    WeexEnv::getEnv()->locker()->signal();
+
     weexObjectHolder.reset(new WeexObjectHolder(m_globalVM.get(), timeQueue, isMultiProgress));
     LOGE("WeexRuntime is running and mode is %s", isMultiProgress ? "multiProcess" : "singleProcess");
 }
@@ -381,7 +378,12 @@ int WeexRuntime::exeJS(const String &instanceId, const String &nameSpace, const
     // if function is callJs on instance, should us Instance object to call __WEEX_CALL_JAVASCRIPT__
 
     if (std::strcmp("callJS", runFunc.utf8().data()) == 0) {
+
+      auto iterator = weexObjectHolder->m_jsInstanceGlobalObjectMap.find(instanceId.utf8().data());
+      if (iterator != weexObjectHolder->m_jsInstanceGlobalObjectMap.end()) {
         globalObject = weexObjectHolder->m_jsInstanceGlobalObjectMap[instanceId.utf8().data()];
+      }
+
         if (globalObject == NULL) {
             globalObject = weexObjectHolder->m_globalObject.get();
         } else {
@@ -644,9 +646,15 @@ int WeexRuntime::createInstance(const String &instanceId, const String &func, co
     if (instanceId == "") {
         globalObject = impl_globalObject;
     } else {
-        auto *temp_object = weexObjectHolder->m_jsInstanceGlobalObjectMap[instanceId.utf8().data()];
 
-        if (temp_object == NULL) {
+      WeexGlobalObject * temp_object = nullptr;
+
+      auto iterator = weexObjectHolder->m_jsInstanceGlobalObjectMap.find(instanceId.utf8().data());
+      if (iterator != weexObjectHolder->m_jsInstanceGlobalObjectMap.end()) {
+          temp_object = weexObjectHolder->m_jsInstanceGlobalObjectMap[instanceId.utf8().data()];
+      }
+
+        if (temp_object == nullptr) {
             // new a global object
             // --------------------------------------------------
 //            if (weexLiteAppObjectHolder.get() != nullptr) {
diff --git a/weex_core/Source/base/crash/crash_handler.cpp b/weex_core/Source/base/crash/crash_handler.cpp
index 12297ca..15197ca 100644
--- a/weex_core/Source/base/crash/crash_handler.cpp
+++ b/weex_core/Source/base/crash/crash_handler.cpp
@@ -101,6 +101,7 @@ static _Unwind_Reason_Code traceFunction(_Unwind_Context* context, void* arg)
 CrashHandlerInfo::CrashHandlerInfo(std::string fileName)
             : m_dumpFileFd(-1),
               m_mapsFileFd(-1),
+              m_crash_occurs(false),
               m_dumpFileName(fileName)
 {
     if (!g_crashHandler)
@@ -161,6 +162,7 @@ bool CrashHandlerInfo::handleSignal(int signum, siginfo_t* siginfo, void* uconte
     //TODO return false: add condition to filter which CrashHandlerInfo to handler the
     //signal
 
+    m_crash_occurs = true;
     LOG(INFO) << "CrashHandlerInfo::handleSignal";
     const char* signalName = nullptr;
     for (int i = 0; s_hookSignals[i].signum; ++i) {
@@ -412,5 +414,8 @@ void CrashHandlerInfo::saveFileContent()
         size -= byteWritten;
     }
 }
+bool CrashHandlerInfo::is_crashed() {
+    return m_crash_occurs;
+}
 
 }
diff --git a/weex_core/Source/base/crash/crash_handler.h b/weex_core/Source/base/crash/crash_handler.h
index e1c693e..9d76d67 100644
--- a/weex_core/Source/base/crash/crash_handler.h
+++ b/weex_core/Source/base/crash/crash_handler.h
@@ -34,7 +34,7 @@ public:
     bool initializeCrashHandler();
     bool handleSignal(int signum, siginfo_t* siginfo, void* ucontext);
     bool printIP(void* addr);
-
+    bool is_crashed();
     struct SignalInfo {
         int signum;
         const char* signame;
@@ -66,6 +66,7 @@ private:
     std::string m_dumpFileName;
     std::string m_fileContent;
     mcontext_t m_mcontext;
+    volatile bool m_crash_occurs;
 };
 }
 #endif /* CRASHHANDLER_H */