RN catalyst instance destroy markers

Reviewed By: alexeylang

Differential Revision: D6109891

fbshipit-source-id: 2cd1491381220a80f71f9ab205a2c6a309ed35ae
This commit is contained in:
Charles Dick
2017-10-26 10:06:07 -07:00
committed by Facebook Github Bot
parent f0fb720eaa
commit 1c104310fb
2 changed files with 27 additions and 22 deletions

View File

@@ -12,7 +12,6 @@ package com.facebook.react.bridge;
import android.content.res.AssetManager;
import android.os.AsyncTask;
import android.util.Log;
import com.facebook.common.logging.FLog;
import com.facebook.infer.annotation.Assertions;
import com.facebook.jni.HybridData;
@@ -320,35 +319,39 @@ public class CatalystInstanceImpl implements CatalystInstance {
}
// TODO: tell all APIs to shut down
ReactMarker.logMarker(ReactMarkerConstants.DESTROY_CATALYST_INSTANCE_START);
mDestroyed = true;
mNativeModulesQueueThread.runOnQueue(new Runnable() {
@Override
public void run() {
mNativeModuleRegistry.notifyJSInstanceDestroy();
boolean wasIdle = (mPendingJSCalls.getAndSet(0) == 0);
if (!wasIdle && !mBridgeIdleListeners.isEmpty()) {
for (NotThreadSafeBridgeIdleDebugListener listener : mBridgeIdleListeners) {
listener.onTransitionToBridgeIdle();
}
}
AsyncTask.execute(new Runnable() {
mNativeModulesQueueThread.runOnQueue(
new Runnable() {
@Override
public void run() {
// Kill non-UI threads from neutral third party
// potentially expensive, so don't run on UI thread
mNativeModuleRegistry.notifyJSInstanceDestroy();
boolean wasIdle = (mPendingJSCalls.getAndSet(0) == 0);
if (!wasIdle && !mBridgeIdleListeners.isEmpty()) {
for (NotThreadSafeBridgeIdleDebugListener listener : mBridgeIdleListeners) {
listener.onTransitionToBridgeIdle();
}
}
AsyncTask.execute(
new Runnable() {
@Override
public void run() {
// Kill non-UI threads from neutral third party
// potentially expensive, so don't run on UI thread
// contextHolder is used as a lock to guard against other users of the JS VM having
// the VM destroyed underneath them, so notify them before we resetNative
mJavaScriptContextHolder.clear();
// contextHolder is used as a lock to guard against other users of the JS VM having
// the VM destroyed underneath them, so notify them before we resetNative
mJavaScriptContextHolder.clear();
mHybridData.resetNative();
getReactQueueConfiguration().destroy();
Log.d(ReactConstants.TAG, "CatalystInstanceImpl.destroy() end");
mHybridData.resetNative();
getReactQueueConfiguration().destroy();
Log.d(ReactConstants.TAG, "CatalystInstanceImpl.destroy() end");
ReactMarker.logMarker(ReactMarkerConstants.DESTROY_CATALYST_INSTANCE_END);
}
});
}
});
}
});
// This is a noop if the listener was not yet registered.
Systrace.unregisterListener(mTraceListener);

View File

@@ -14,6 +14,8 @@ public enum ReactMarkerConstants {
BUILD_NATIVE_MODULE_REGISTRY_END,
CREATE_CATALYST_INSTANCE_START,
CREATE_CATALYST_INSTANCE_END,
DESTROY_CATALYST_INSTANCE_START,
DESTROY_CATALYST_INSTANCE_END,
RUN_JS_BUNDLE_START,
RUN_JS_BUNDLE_END,
NATIVE_MODULE_INITIALIZE_START,