mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Revert D30675510: Remove custom Hermes config for Android
Differential Revision: D30675510 (https://github.com/facebook/react-native/commit/a40f973f58609ca717fac63bc501d5cf93b748ad) Original commit changeset: 5eef056893b7 fbshipit-source-id: 25db31c4fbe938d92bba8b0bfe6523bced1524f0
This commit is contained in:
committed by
Facebook GitHub Bot
parent
7edf9274cf
commit
455433f481
@@ -17,6 +17,22 @@ 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"),
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ 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_;
|
||||
@@ -26,8 +27,8 @@ public class HermesExecutor extends JavaScriptExecutor {
|
||||
}
|
||||
}
|
||||
|
||||
HermesExecutor() {
|
||||
super(initHybrid());
|
||||
HermesExecutor(@Nullable RuntimeConfig config) {
|
||||
super(config == null ? initHybridDefaultConfig() : initHybrid(config.heapSizeMB));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -44,5 +45,7 @@ public class HermesExecutor extends JavaScriptExecutor {
|
||||
*/
|
||||
public static native boolean canLoadFile(String path);
|
||||
|
||||
private static native HybridData initHybrid();
|
||||
private static native HybridData initHybridDefaultConfig();
|
||||
|
||||
private static native HybridData initHybrid(long heapSizeMB);
|
||||
}
|
||||
|
||||
+11
-1
@@ -14,9 +14,19 @@ 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();
|
||||
return new HermesExecutor(mConfig);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
#include <android/log.h>
|
||||
#include <fbjni/fbjni.h>
|
||||
#include <glog/logging.h>
|
||||
#include <hermes/Public/GCConfig.h>
|
||||
#include <hermes/Public/RuntimeConfig.h>
|
||||
#include <jni.h>
|
||||
#include <react/jni/JReactMarker.h>
|
||||
#include <react/jni/JSLogging.h>
|
||||
@@ -28,6 +30,26 @@ 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<void (*)(const std::string &, unsigned int)>(
|
||||
@@ -45,7 +67,8 @@ class HermesExecutorHolder
|
||||
static constexpr auto kJavaDescriptor =
|
||||
"Lcom/facebook/hermes/reactexecutor/HermesExecutor;";
|
||||
|
||||
static jni::local_ref<jhybriddata> initHybrid(jni::alias_ref<jclass>) {
|
||||
static jni::local_ref<jhybriddata> initHybridDefaultConfig(
|
||||
jni::alias_ref<jclass>) {
|
||||
JReactMarker::setLogPerfMarkerIfNeeded();
|
||||
|
||||
std::call_once(flag, []() {
|
||||
@@ -55,6 +78,18 @@ class HermesExecutorHolder
|
||||
std::make_unique<HermesExecutorFactory>(installBindings));
|
||||
}
|
||||
|
||||
static jni::local_ref<jhybriddata> initHybrid(
|
||||
jni::alias_ref<jclass>,
|
||||
jlong heapSizeMB) {
|
||||
JReactMarker::setLogPerfMarkerIfNeeded();
|
||||
auto runtimeConfig = makeRuntimeConfig(heapSizeMB);
|
||||
std::call_once(flag, []() {
|
||||
facebook::hermes::HermesRuntime::setFatalHandler(hermesFatalHandler);
|
||||
});
|
||||
return makeCxxInstance(std::make_unique<HermesExecutorFactory>(
|
||||
installBindings, JSIExecutor::defaultTimeoutInvoker, runtimeConfig));
|
||||
}
|
||||
|
||||
static bool canLoadFile(jni::alias_ref<jclass>, const std::string &path) {
|
||||
return true;
|
||||
}
|
||||
@@ -62,6 +97,9 @@ class HermesExecutorHolder
|
||||
static void registerNatives() {
|
||||
registerHybrid(
|
||||
{makeNativeMethod("initHybrid", HermesExecutorHolder::initHybrid),
|
||||
makeNativeMethod(
|
||||
"initHybridDefaultConfig",
|
||||
HermesExecutorHolder::initHybridDefaultConfig),
|
||||
makeNativeMethod("canLoadFile", HermesExecutorHolder::canLoadFile)});
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user