Cleanup Platform

Reviewed By: dcaspi

Differential Revision: D5185504

fbshipit-source-id: 4f7e9f9068598418b346a7370f6be241a0784b60
This commit is contained in:
Pieter De Baets 2017-06-07 10:17:58 -07:00 committed by Facebook Github Bot
parent f7c89b4187
commit 81c2f3b189
5 changed files with 49 additions and 46 deletions

View File

@ -48,7 +48,7 @@ JSValueRef nativePerformanceNow(
void RCTPrepareJSCExecutor() { void RCTPrepareJSCExecutor() {
ReactMarker::logTaggedMarker = [](const ReactMarker::ReactMarkerId, const char *tag) {}; ReactMarker::logTaggedMarker = [](const ReactMarker::ReactMarkerId, const char *tag) {};
PerfLogging::installNativeHooks = RCTFBQuickPerformanceLoggerConfigureHooks; JSCNativeHooks::loggingHook = nativeLoggingHook;
JSNativeHooks::loggingHook = nativeLoggingHook; JSCNativeHooks::nowHook = nativePerformanceNow;
JSNativeHooks::nowHook = nativePerformanceNow; JSCNativeHooks::installPerfHooks = RCTFBQuickPerformanceLoggerConfigureHooks;
} }

View File

@ -1,30 +1,31 @@
// Copyright 2004-present Facebook. All Rights Reserved. // Copyright 2004-present Facebook. All Rights Reserved.
#include <folly/dynamic.h> #include <string>
#include <fb/fbjni.h>
#include <fb/glog_init.h>
#include <fb/log.h>
#include <cxxreact/Executor.h> #include <cxxreact/Executor.h>
#include <cxxreact/JSCExecutor.h> #include <cxxreact/JSCExecutor.h>
#include <cxxreact/Platform.h> #include <cxxreact/Platform.h>
#include <jschelpers/JSCHelpers.h>
#include <fb/fbjni.h>
#include <fb/glog_init.h>
#include <fb/log.h>
#include <folly/dynamic.h>
#include <jschelpers/Value.h> #include <jschelpers/Value.h>
#include "CatalystInstanceImpl.h" #include "CatalystInstanceImpl.h"
#include "CxxModuleWrapper.h" #include "CxxModuleWrapper.h"
#include "JavaScriptExecutorHolder.h" #include "JavaScriptExecutorHolder.h"
#include "JSCPerfLogging.h"
#include "ProxyExecutor.h"
#include "JCallback.h" #include "JCallback.h"
#include "JSCPerfLogging.h"
#include "JSLogging.h" #include "JSLogging.h"
#include "ProxyExecutor.h"
#include "WritableNativeArray.h"
#include "WritableNativeMap.h"
#ifdef WITH_INSPECTOR #ifdef WITH_INSPECTOR
#include "JInspector.h" #include "JInspector.h"
#endif #endif
#include "WritableNativeMap.h"
#include "WritableNativeArray.h"
#include <string>
using namespace facebook::jni; using namespace facebook::jni;
namespace facebook { namespace facebook {
@ -32,6 +33,7 @@ namespace react {
namespace { namespace {
// TODO: can we avoid these wrapper classes, and instead specialize the logic in CatalystInstanceImpl
class JSCJavaScriptExecutorHolder : public HybridClass<JSCJavaScriptExecutorHolder, class JSCJavaScriptExecutorHolder : public HybridClass<JSCJavaScriptExecutorHolder,
JavaScriptExecutorHolder> { JavaScriptExecutorHolder> {
public: public:
@ -151,19 +153,15 @@ extern "C" JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) {
gloginit::initialize(); gloginit::initialize();
// Inject some behavior into react/ // Inject some behavior into react/
ReactMarker::logTaggedMarker = logPerfMarker; ReactMarker::logTaggedMarker = logPerfMarker;
PerfLogging::installNativeHooks = addNativePerfLoggingHooks; JSCNativeHooks::loggingHook = nativeLoggingHook;
JSNativeHooks::loggingHook = nativeLoggingHook; JSCNativeHooks::nowHook = nativePerformanceNow;
JSNativeHooks::nowHook = nativePerformanceNow; JSCNativeHooks::installPerfHooks = addNativePerfLoggingHooks;
JSCJavaScriptExecutorHolder::registerNatives(); JSCJavaScriptExecutorHolder::registerNatives();
ProxyJavaScriptExecutorHolder::registerNatives(); ProxyJavaScriptExecutorHolder::registerNatives();
CatalystInstanceImpl::registerNatives(); CatalystInstanceImpl::registerNatives();
CxxModuleWrapperBase::registerNatives(); CxxModuleWrapperBase::registerNatives();
CxxModuleWrapper::registerNatives(); CxxModuleWrapper::registerNatives();
JCxxCallbackImpl::registerNatives(); JCxxCallbackImpl::registerNatives();
#ifdef WITH_INSPECTOR
JInspector::registerNatives();
#endif
NativeArray::registerNatives(); NativeArray::registerNatives();
ReadableNativeArray::registerNatives(); ReadableNativeArray::registerNatives();
WritableNativeArray::registerNatives(); WritableNativeArray::registerNatives();
@ -171,6 +169,10 @@ extern "C" JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) {
ReadableNativeMap::registerNatives(); ReadableNativeMap::registerNatives();
WritableNativeMap::registerNatives(); WritableNativeMap::registerNatives();
ReadableNativeMapKeySetIterator::registerNatives(); ReadableNativeMapKeySetIterator::registerNatives();
#ifdef WITH_INSPECTOR
JInspector::registerNatives();
#endif
}); });
} }

View File

@ -226,8 +226,8 @@ void JSCExecutor::initOnJSVMThread() throw(JSException) {
installNativeHook<&JSCExecutor::nativeFlushQueueImmediate>("nativeFlushQueueImmediate"); installNativeHook<&JSCExecutor::nativeFlushQueueImmediate>("nativeFlushQueueImmediate");
installNativeHook<&JSCExecutor::nativeCallSyncHook>("nativeCallSyncHook"); installNativeHook<&JSCExecutor::nativeCallSyncHook>("nativeCallSyncHook");
installGlobalFunction(m_context, "nativeLoggingHook", JSNativeHooks::loggingHook); installGlobalFunction(m_context, "nativeLoggingHook", JSCNativeHooks::loggingHook);
installGlobalFunction(m_context, "nativePerformanceNow", JSNativeHooks::nowHook); installGlobalFunction(m_context, "nativePerformanceNow", JSCNativeHooks::nowHook);
#if DEBUG #if DEBUG
installGlobalFunction(m_context, "nativeInjectHMRUpdate", nativeInjectHMRUpdate); installGlobalFunction(m_context, "nativeInjectHMRUpdate", nativeInjectHMRUpdate);
@ -242,7 +242,7 @@ void JSCExecutor::initOnJSVMThread() throw(JSException) {
addNativeTracingLegacyHooks(m_context); addNativeTracingLegacyHooks(m_context);
#endif #endif
PerfLogging::installNativeHooks(m_context); JSCNativeHooks::installPerfHooks(m_context);
#if defined(__APPLE__) || defined(WITH_JSC_EXTRA_TRACING) #if defined(__APPLE__) || defined(WITH_JSC_EXTRA_TRACING)
if (JSC_JSSamplingProfilerEnabled(m_context)) { if (JSC_JSSamplingProfilerEnabled(m_context)) {

View File

@ -11,20 +11,20 @@ namespace react {
#endif #endif
namespace ReactMarker { namespace ReactMarker {
LogTaggedMarker logTaggedMarker = nullptr;
LogTaggedMarker logTaggedMarker = nullptr;
void logMarker(const ReactMarkerId markerId) { void logMarker(const ReactMarkerId markerId) {
logTaggedMarker(markerId, nullptr); logTaggedMarker(markerId, nullptr);
} }
};
namespace PerfLogging { }
InstallNativeHooks installNativeHooks = nullptr;
}; namespace JSCNativeHooks {
namespace JSNativeHooks {
Hook loggingHook = nullptr; Hook loggingHook = nullptr;
Hook nowHook = nullptr; Hook nowHook = nullptr;
ConfigurationHook installPerfHooks = nullptr;
} }
#if __clang__ #if __clang__

View File

@ -14,6 +14,7 @@ namespace facebook {
namespace react { namespace react {
namespace ReactMarker { namespace ReactMarker {
enum ReactMarkerId { enum ReactMarkerId {
NATIVE_REQUIRE_START, NATIVE_REQUIRE_START,
NATIVE_REQUIRE_STOP, NATIVE_REQUIRE_STOP,
@ -29,14 +30,10 @@ extern LogTaggedMarker logTaggedMarker;
extern void logMarker(const ReactMarkerId markerId); extern void logMarker(const ReactMarkerId markerId);
}; }
namespace PerfLogging { namespace JSCNativeHooks {
using InstallNativeHooks = std::function<void(JSGlobalContextRef)>;
extern InstallNativeHooks installNativeHooks;
};
namespace JSNativeHooks {
using Hook = JSValueRef(*)( using Hook = JSValueRef(*)(
JSContextRef ctx, JSContextRef ctx,
JSObjectRef function, JSObjectRef function,
@ -46,6 +43,10 @@ namespace JSNativeHooks {
JSValueRef *exception); JSValueRef *exception);
extern Hook loggingHook; extern Hook loggingHook;
extern Hook nowHook; extern Hook nowHook;
using ConfigurationHook = std::function<void(JSGlobalContextRef)>;
extern ConfigurationHook installPerfHooks;
} }
} } } }