-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
104 changed files
with
17,160 additions
and
62 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
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 |
14 changes: 14 additions & 0 deletions
14
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,14 @@ | ||
/** | ||
* 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.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 | ||
|
||
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 | ||
|
||
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. | ||
* | ||
* 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 java.util.concurrent.ScheduledExecutorService; | ||
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.