-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Hermes support to React Native on Android (#25613)
Summary: Yesterday we shipped hermesengine.dev as part of the current 0.60 release. This PR brings those changes to master. ## Changelog [General] [Added] - Added support for Hermes Pull Request resolved: #25613 Test Plan: * CI is green both on GitHub and at FB * Creating a new app from source can use Hermes on Android Reviewed By: cpojer Differential Revision: D16221777 Pulled By: willholen fbshipit-source-id: aa6be10537863039cb666292465ba2e1d44b64ef
- Loading branch information
1 parent
fee7f06
commit d7f5153
Showing
106 changed files
with
17,050 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
ReactAndroid/src/main/java/com/facebook/hermes/instrumentation/BUCK
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
load("//tools/build_defs/oss:rn_defs.bzl", "rn_android_library") | ||
|
||
rn_android_library( | ||
name = "instrumentation", | ||
srcs = glob(["**/*.java"]), | ||
visibility = [ | ||
"PUBLIC", | ||
], | ||
) |
48 changes: 48 additions & 0 deletions
48
ReactAndroid/src/main/java/com/facebook/hermes/instrumentation/HermesMemoryDumper.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* 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. | ||
*/ | ||
#include <fb/fbjni.h> | ||
#include <string> | ||
|
||
namespace facebook { | ||
namespace jsi { | ||
namespace jni { | ||
|
||
namespace jni = ::facebook::jni; | ||
|
||
class HermesMemoryDumper : public jni::JavaClass<HermesMemoryDumper> { | ||
public: | ||
constexpr static auto kJavaDescriptor = | ||
"Lcom/facebook/hermes/instrumentation/HermesMemoryDumper;"; | ||
|
||
bool shouldSaveSnapshot() { | ||
static auto shouldSaveSnapshotMethod = | ||
javaClassStatic()->getMethod<jboolean()>("shouldSaveSnapshot"); | ||
return shouldSaveSnapshotMethod(self()); | ||
} | ||
|
||
std::string getInternalStorage() { | ||
static auto getInternalStorageMethod = | ||
javaClassStatic()->getMethod<jstring()>("getInternalStorage"); | ||
return getInternalStorageMethod(self())->toStdString(); | ||
} | ||
|
||
std::string getId() { | ||
static auto getInternalStorageMethod = | ||
javaClassStatic()->getMethod<jstring()>("getId"); | ||
return getInternalStorageMethod(self())->toStdString(); | ||
} | ||
|
||
void setMetaData(std::string crashId) { | ||
static auto getIdMethod = | ||
javaClassStatic()->getMethod<void(std::string)>("setMetaData"); | ||
getIdMethod(self(), crashId); | ||
} | ||
}; | ||
|
||
} // namespace jni | ||
} // namespace jsi | ||
} // namespace facebook |
17 changes: 17 additions & 0 deletions
17
ReactAndroid/src/main/java/com/facebook/hermes/instrumentation/HermesMemoryDumper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* <p>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.instrumentation; | ||
|
||
public interface HermesMemoryDumper { | ||
boolean shouldSaveSnapshot(); | ||
|
||
String getInternalStorage(); | ||
|
||
String getId(); | ||
|
||
void setMetaData(String crashId); | ||
} |
40 changes: 40 additions & 0 deletions
40
ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/Android.mk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# 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. | ||
|
||
LOCAL_PATH := $(call my-dir) | ||
|
||
include $(CLEAR_VARS) | ||
REACT_NATIVE := $(LOCAL_PATH)/../../../../../../../.. | ||
|
||
LOCAL_MODULE := hermes-executor-release | ||
|
||
LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/*.cpp) | ||
|
||
LOCAL_C_INCLUDES := $(LOCAL_PATH) $(REACT_NATIVE)/ReactCommon/jsi $(REACT_NATIVE)/node_modules/hermesvm/android/include $(REACT_NATIVE)/../hermesvm/android/include $(REACT_NATIVE)/../node_modules/hermesvm/include | ||
|
||
LOCAL_CPP_FEATURES := exceptions | ||
|
||
LOCAL_STATIC_LIBRARIES := libjsireact libjsi | ||
LOCAL_SHARED_LIBRARIES := libfolly_json libfb libreactnativejni libhermes | ||
|
||
include $(BUILD_SHARED_LIBRARY) | ||
|
||
|
||
include $(CLEAR_VARS) | ||
REACT_NATIVE := $(LOCAL_PATH)/../../../../../../../.. | ||
|
||
LOCAL_MODULE := hermes-executor-debug | ||
LOCAL_CFLAGS := -DHERMES_ENABLE_DEBUGGER=1 | ||
|
||
LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/*.cpp) | ||
|
||
LOCAL_C_INCLUDES := $(LOCAL_PATH) $(REACT_NATIVE)/ReactCommon/jsi $(REACT_NATIVE)/node_modules/hermesvm/android/include $(REACT_NATIVE)/../hermesvm/android/include $(REACT_NATIVE)/../node_modules/hermesvm/include | ||
|
||
LOCAL_CPP_FEATURES := exceptions | ||
|
||
LOCAL_STATIC_LIBRARIES := libjsireact libjsi libhermes-inspector | ||
LOCAL_SHARED_LIBRARIES := libfolly_json libfb libreactnativejni libhermes | ||
|
||
include $(BUILD_SHARED_LIBRARY) |
68 changes: 68 additions & 0 deletions
68
ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/HermesExecutor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* <p>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; | ||
|
||
import com.facebook.hermes.instrumentation.HermesMemoryDumper; | ||
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_; | ||
|
||
static { | ||
// libhermes must be loaded explicitly to invoke its JNI_OnLoad. | ||
SoLoader.loadLibrary("hermes"); | ||
try { | ||
SoLoader.loadLibrary("hermes-executor-release"); | ||
mode_ = "Release"; | ||
} catch (UnsatisfiedLinkError e) { | ||
SoLoader.loadLibrary("hermes-executor-debug"); | ||
mode_ = "Debug"; | ||
} | ||
} | ||
|
||
HermesExecutor(@Nullable RuntimeConfig config) { | ||
super( | ||
config == null | ||
? initHybridDefaultConfig() | ||
: initHybrid( | ||
config.heapSizeMB, | ||
config.es6Symbol, | ||
config.bytecodeWarmupPercent, | ||
config.tripWireEnabled, | ||
config.heapDumper, | ||
config.tripWireCooldownMS, | ||
config.tripWireLimitBytes)); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "HermesExecutor" + mode_; | ||
} | ||
|
||
/** | ||
* Return whether this class can load a file at the given path, based on a binary compatibility | ||
* check between the contents of the file and the Hermes VM. | ||
* | ||
* @param path the path containing the file to inspect. | ||
* @return whether the given file is compatible with the Hermes VM. | ||
*/ | ||
public static native boolean canLoadFile(String path); | ||
|
||
private static native HybridData initHybridDefaultConfig(); | ||
|
||
private static native HybridData initHybrid( | ||
long heapSizeMB, | ||
boolean es6Symbol, | ||
int bytecodeWarmupPercent, | ||
boolean tripWireEnabled, | ||
@Nullable HermesMemoryDumper heapDumper, | ||
long tripWireCooldownMS, | ||
long tripWireLimitBytes); | ||
} |
Oops, something went wrong.