From a40f973f58609ca717fac63bc501d5cf93b748ad Mon Sep 17 00:00:00 2001 From: Ashoat Tevosyan Date: Thu, 2 Sep 2021 12:15:04 -0700 Subject: [PATCH] Remove custom Hermes config for Android (#31900) Summary: Right now, `react-native` on Android passes in an explicit Hermes config when initializes Hermes. The upcoming version of Hermes shipping with React Native 0.66 will handle this default config itself, so there's no need to override it from Android anymore. Changelog: [Android][Changed] - Hermes initialization will no longer need an explicit configuration. Pull Request resolved: https://github.com/facebook/react-native/pull/31900 Test Plan: I compiled and ran a React Native app using the Android build, making sure to build `ReactAndroid` from source. I confirmed that the config was actually being applied by testing how much memory an application could eat before being killed. Reviewed By: sshic Differential Revision: D30675510 Pulled By: yungsters fbshipit-source-id: 5eef056893b72ddd433ee808eb08d0eb56f22f72 --- .../com/facebook/hermes/reactexecutor/BUCK | 16 -------- .../hermes/reactexecutor/HermesExecutor.java | 9 ++--- .../reactexecutor/HermesExecutorFactory.java | 12 +----- .../facebook/hermes/reactexecutor/OnLoad.cpp | 40 +------------------ .../hermes/reactexecutor/RuntimeConfig.java | 19 --------- 5 files changed, 5 insertions(+), 91 deletions(-) delete mode 100644 ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/RuntimeConfig.java diff --git a/ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/BUCK b/ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/BUCK index fca40c1027f..f305aa4fe0e 100644 --- a/ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/BUCK +++ b/ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/BUCK @@ -17,22 +17,6 @@ rn_android_library( react_native_target("java/com/facebook/hermes/instrumentation:hermes_samplingprofiler"), react_native_target("java/com/facebook/react/bridge:bridge"), ":jni", - ":runtimeconfig", - ], -) - -rn_android_library( - name = "runtimeconfig", - srcs = [ - "RuntimeConfig.java", - ], - autoglob = False, - visibility = [ - "PUBLIC", - ], - deps = [ - react_native_dep("third-party/java/jsr-305:jsr-305"), - react_native_target("java/com/facebook/hermes/instrumentation:instrumentation"), ], ) diff --git a/ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/HermesExecutor.java b/ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/HermesExecutor.java index 7519f2146fa..cdee2c9ef80 100644 --- a/ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/HermesExecutor.java +++ b/ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/HermesExecutor.java @@ -10,7 +10,6 @@ package com.facebook.hermes.reactexecutor; import com.facebook.jni.HybridData; import com.facebook.react.bridge.JavaScriptExecutor; import com.facebook.soloader.SoLoader; -import javax.annotation.Nullable; public class HermesExecutor extends JavaScriptExecutor { private static String mode_; @@ -27,8 +26,8 @@ public class HermesExecutor extends JavaScriptExecutor { } } - HermesExecutor(@Nullable RuntimeConfig config) { - super(config == null ? initHybridDefaultConfig() : initHybrid(config.heapSizeMB)); + HermesExecutor() { + super(initHybrid()); } @Override @@ -45,7 +44,5 @@ public class HermesExecutor extends JavaScriptExecutor { */ public static native boolean canLoadFile(String path); - private static native HybridData initHybridDefaultConfig(); - - private static native HybridData initHybrid(long heapSizeMB); + private static native HybridData initHybrid(); } diff --git a/ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/HermesExecutorFactory.java b/ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/HermesExecutorFactory.java index 976af80b1ee..a2686dba3a9 100644 --- a/ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/HermesExecutorFactory.java +++ b/ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/HermesExecutorFactory.java @@ -14,19 +14,9 @@ import com.facebook.react.bridge.JavaScriptExecutorFactory; public class HermesExecutorFactory implements JavaScriptExecutorFactory { private static final String TAG = "Hermes"; - private final RuntimeConfig mConfig; - - public HermesExecutorFactory() { - this(new RuntimeConfig(1024)); - } - - public HermesExecutorFactory(RuntimeConfig config) { - mConfig = config; - } - @Override public JavaScriptExecutor create() { - return new HermesExecutor(mConfig); + return new HermesExecutor(); } @Override diff --git a/ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/OnLoad.cpp b/ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/OnLoad.cpp index 56a9f589490..f02a1b19068 100644 --- a/ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/OnLoad.cpp +++ b/ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/OnLoad.cpp @@ -10,8 +10,6 @@ #include #include #include -#include -#include #include #include #include @@ -30,26 +28,6 @@ static void hermesFatalHandler(const std::string &reason) { static std::once_flag flag; -static ::hermes::vm::RuntimeConfig makeRuntimeConfig(jlong heapSizeMB) { - namespace vm = ::hermes::vm; - auto gcConfigBuilder = - vm::GCConfig::Builder() - .withName("RN") - // For the next two arguments: avoid GC before TTI by initializing the - // runtime to allocate directly in the old generation, but revert to - // normal operation when we reach the (first) TTI point. - .withAllocInYoung(false) - .withRevertToYGAtTTI(true); - - if (heapSizeMB > 0) { - gcConfigBuilder.withMaxHeapSize(heapSizeMB << 20); - } - - return vm::RuntimeConfig::Builder() - .withGCConfig(gcConfigBuilder.build()) - .build(); -} - static void installBindings(jsi::Runtime &runtime) { react::Logger androidLogger = static_cast( @@ -67,8 +45,7 @@ class HermesExecutorHolder static constexpr auto kJavaDescriptor = "Lcom/facebook/hermes/reactexecutor/HermesExecutor;"; - static jni::local_ref initHybridDefaultConfig( - jni::alias_ref) { + static jni::local_ref initHybrid(jni::alias_ref) { JReactMarker::setLogPerfMarkerIfNeeded(); std::call_once(flag, []() { @@ -78,18 +55,6 @@ class HermesExecutorHolder std::make_unique(installBindings)); } - static jni::local_ref initHybrid( - jni::alias_ref, - jlong heapSizeMB) { - JReactMarker::setLogPerfMarkerIfNeeded(); - auto runtimeConfig = makeRuntimeConfig(heapSizeMB); - std::call_once(flag, []() { - facebook::hermes::HermesRuntime::setFatalHandler(hermesFatalHandler); - }); - return makeCxxInstance(std::make_unique( - installBindings, JSIExecutor::defaultTimeoutInvoker, runtimeConfig)); - } - static bool canLoadFile(jni::alias_ref, const std::string &path) { return true; } @@ -97,9 +62,6 @@ class HermesExecutorHolder static void registerNatives() { registerHybrid( {makeNativeMethod("initHybrid", HermesExecutorHolder::initHybrid), - makeNativeMethod( - "initHybridDefaultConfig", - HermesExecutorHolder::initHybridDefaultConfig), makeNativeMethod("canLoadFile", HermesExecutorHolder::canLoadFile)}); } diff --git a/ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/RuntimeConfig.java b/ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/RuntimeConfig.java deleted file mode 100644 index fec7c457bc8..00000000000 --- a/ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/RuntimeConfig.java +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -package com.facebook.hermes.reactexecutor; - -/** Holds runtime configuration for a Hermes VM instance (master or snapshot). */ -public final class RuntimeConfig { - public long heapSizeMB; - - RuntimeConfig() {} - - RuntimeConfig(long heapSizeMB) { - this.heapSizeMB = heapSizeMB; - } -}