void addNativePerfLoggingHooks(JSGlobalContextRef ctx) {
    installGlobalFunction(ctx, "nativeQPLMarkerStart", nativeQPLMarkerStart);
    installGlobalFunction(ctx, "nativeQPLMarkerEnd", nativeQPLMarkerEnd);
    installGlobalFunction(ctx, "nativeQPLMarkerNote", nativeQPLMarkerNote);
    installGlobalFunction(ctx, "nativeQPLMarkerCancel", nativeQPLMarkerCancel);
    installGlobalFunction(ctx, "nativeQPLTimestamp", nativeQPLTimestamp);
}
void addNativeTracingHooks()
{
  installGlobalFunction("nativeTraceBeginSection", nativeTraceBeginSectionJNF);
  installGlobalFunction("nativeTraceEndSection", nativeTraceEndSectionJNF);
  installGlobalFunction("nativeTraceBeginAsyncSection", nativeTraceBeginAsyncSectionJNF);
  installGlobalFunction("nativeTraceEndAsyncSection", nativeTraceEndAsyncSectionJNF);
  installGlobalFunction("nativeTraceCounter", nativeTraceCounterJNF);
}
Пример #3
0
void JSCExecutor::initOnJSVMThread() {
  #if defined(WITH_FB_JSC_TUNING)
  configureJSCForAndroid(m_jscConfig);
  #endif
  m_context = JSGlobalContextCreateInGroup(nullptr, nullptr);
  s_globalContextRefToJSCExecutor[m_context] = this;
  installGlobalFunction(m_context, "nativeFlushQueueImmediate", nativeFlushQueueImmediate);
  installGlobalFunction(m_context, "nativeStartWorker", nativeStartWorker);
  installGlobalFunction(m_context, "nativePostMessageToWorker", nativePostMessageToWorker);
  installGlobalFunction(m_context, "nativeTerminateWorker", nativeTerminateWorker);
  installGlobalFunction(m_context, "nativeInjectHMRUpdate", nativeInjectHMRUpdate);
  installGlobalFunction(m_context, "nativeCallSyncHook", nativeCallSyncHook);

  installGlobalFunction(m_context, "nativeLoggingHook", JSNativeHooks::loggingHook);
  installGlobalFunction(m_context, "nativePerformanceNow", JSNativeHooks::nowHook);

  #ifdef WITH_JSC_EXTRA_TRACING
  addNativeTracingHooks(m_context);
  addNativeProfilingHooks(m_context);
  PerfLogging::installNativeHooks(m_context);
  #endif

  #ifdef WITH_FB_MEMORY_PROFILING
  addNativeMemoryHooks(m_context);
  #endif

  #ifdef JSC_HAS_PERF_STATS_API
  addJSCPerfStatsHooks(m_context);
  #endif

  #if defined(WITH_FB_JSC_TUNING)
  configureJSContextForAndroid(m_context, m_jscConfig, m_deviceCacheDir);
  #endif
}
Пример #4
0
void addNativeTracingHooks(JSGlobalContextRef ctx) {
  installGlobalFunction(ctx, "nativeTraceBeginSection", nativeTraceBeginSection);
  installGlobalFunction(ctx, "nativeTraceEndSection", nativeTraceEndSection);
  installGlobalFunction(ctx, "nativeTraceBeginAsyncSection", nativeTraceBeginAsyncSection);
  installGlobalFunction(ctx, "nativeTraceEndAsyncSection", nativeTraceEndAsyncSection);
  installGlobalFunction(ctx, "nativeTraceAsyncSectionStage", nativeTraceAsyncSectionStage);
  installGlobalFunction(ctx, "nativeTraceBeginAsyncFlow", nativeTraceBeginAsyncFlow);
  installGlobalFunction(ctx, "nativeTraceEndAsyncFlow", nativeTraceEndAsyncFlow);
  installGlobalFunction(ctx, "nativeTraceAsyncFlowStage", nativeTraceAsyncFlowStage);
  installGlobalFunction(ctx, "nativeTraceCounter", nativeTraceCounter);
}
Пример #5
0
JSCExecutor::JSCExecutor(
    Bridge *bridge,
    int workerId,
    JSCExecutor *owner,
    const std::string& script,
    const std::unordered_map<std::string, std::string>& globalObjAsJSON,
    const folly::dynamic& jscConfig) :
    m_bridge(bridge),
    m_workerId(workerId),
    m_owner(owner),
    m_deviceCacheDir(owner->m_deviceCacheDir),
    m_messageQueueThread(MessageQueues::getCurrentMessageQueueThread()),
    m_jscConfig(jscConfig) {
  // We post initOnJSVMThread here so that the owner doesn't have to wait for
  // initialization on its own thread
  m_messageQueueThread->runOnQueue([this, script, globalObjAsJSON] () {
    initOnJSVMThread();

    installGlobalFunction(m_context, "postMessage", nativePostMessage);

    for (auto& it : globalObjAsJSON) {
      setGlobalVariable(it.first, it.second);
    }

    // TODO(9604438): Protect against script does not exist
    std::string scriptSrc = WebWorkerUtil::loadScriptFromAssets(script);
    // TODO(9994180): Throw on error
    loadApplicationScript(scriptSrc, script);
  });
}
Пример #6
0
void initSamplingProfilerOnMainJSCThread(JSGlobalContextRef ctx) {
  JSC_JSStartSamplingProfilingOnMainJSCThread(ctx);

  // Allow the profiler to be poked from JS as well
  // (see SamplingProfiler.js for an example of how it could be used with the JSCSamplingProfiler module).
  installGlobalFunction(ctx, "pokeSamplingProfiler", pokeSamplingProfiler);
}
Пример #7
0
JSCExecutor::JSCExecutor(FlushImmediateCallback cb) :
    m_flushImmediateCallback(cb) {
  m_context = JSGlobalContextCreateInGroup(nullptr, nullptr);
  s_globalContextRefToJSCExecutor[m_context] = this;
  installGlobalFunction(m_context, "nativeFlushQueueImmediate", nativeFlushQueueImmediate);
  installGlobalFunction(m_context, "nativeLoggingHook", nativeLoggingHook);

  #ifdef WITH_FB_JSC_TUNING
  configureJSCForAndroid();
  #endif

  #ifdef WITH_JSC_EXTRA_TRACING
  addNativeTracingHooks(m_context);
  addNativeProfilingHooks(m_context);
  addNativePerfLoggingHooks(m_context);
  #endif
}
Пример #8
0
void JSCExecutor::initOnJSVMThread() {
  #if defined(WITH_FB_JSC_TUNING) && !defined(WITH_JSC_INTERNAL)
  // TODO: Find a way to pass m_jscConfig to configureJSCForAndroid()
  configureJSCForAndroid(m_jscConfig.getDefault("GCTimers", false).asBool());
  #endif
  m_context = JSGlobalContextCreateInGroup(nullptr, nullptr);
  s_globalContextRefToJSCExecutor[m_context] = this;
  installGlobalFunction(m_context, "nativeFlushQueueImmediate", nativeFlushQueueImmediate);
  installGlobalFunction(m_context, "nativePerformanceNow", nativePerformanceNow);
  installGlobalFunction(m_context, "nativeStartWorker", nativeStartWorker);
  installGlobalFunction(m_context, "nativePostMessageToWorker", nativePostMessageToWorker);
  installGlobalFunction(m_context, "nativeTerminateWorker", nativeTerminateWorker);
  installGlobalFunction(m_context, "nativeInjectHMRUpdate", nativeInjectHMRUpdate);

  installGlobalFunction(m_context, "nativeLoggingHook", JSLogging::nativeHook);

  #if defined(WITH_JSC_INTERNAL) && defined(WITH_FB_JSC_TUNING)
  configureJSCForAndroid();
  #endif

  #ifdef WITH_JSC_EXTRA_TRACING
  addNativeTracingHooks(m_context);
  addNativeProfilingHooks(m_context);
  PerfLogging::installNativeHooks(m_context);
  #endif

  #ifdef WITH_FB_MEMORY_PROFILING
  addNativeMemoryHooks(m_context);
  #endif

  #ifdef JSC_HAS_PERF_STATS_API
  addJSCPerfStatsHooks(m_context);
  #endif
}
Пример #9
0
void JSCExecutor::initOnJSVMThread() {
  m_context = JSGlobalContextCreateInGroup(nullptr, nullptr);
  s_globalContextRefToJSCExecutor[m_context] = this;
  installGlobalFunction(m_context, "nativeFlushQueueImmediate", nativeFlushQueueImmediate);
  installGlobalFunction(m_context, "nativePerformanceNow", nativePerformanceNow);
  installGlobalFunction(m_context, "nativeStartWorker", nativeStartWorker);
  installGlobalFunction(m_context, "nativePostMessageToWorker", nativePostMessageToWorker);
  installGlobalFunction(m_context, "nativeTerminateWorker", nativeTerminateWorker);
  installGlobalFunction(m_context, "nativeInjectHMRUpdate", nativeInjectHMRUpdate);

  installGlobalFunction(m_context, "nativeLoggingHook", JSLogging::nativeHook);

  // TODO (t10136849): Pass the config options from map to JSC

  #ifdef WITH_FB_JSC_TUNING
  configureJSCForAndroid();
  #endif

  #ifdef WITH_JSC_EXTRA_TRACING
  addNativeTracingHooks(m_context);
  addNativeProfilingHooks(m_context);
  PerfLogging::installNativeHooks(m_context);
  #endif

  #ifdef WITH_FB_MEMORY_PROFILING
  addNativeMemoryHooks(m_context);
  #endif
}
Пример #10
0
void JSCExecutor::loadApplicationUnbundle(
    std::unique_ptr<JSModulesUnbundle> unbundle,
    const std::string& startupCode,
    const std::string& sourceURL) {
  if (!m_unbundle) {
    installGlobalFunction(m_context, "nativeRequire", nativeRequire);
  }
  m_unbundle = std::move(unbundle);
  loadApplicationScript(startupCode, sourceURL);
}
Пример #11
0
JSCExecutor::JSCExecutor(FlushImmediateCallback cb, const std::string& cacheDir) :
    m_flushImmediateCallback(cb), m_deviceCacheDir(cacheDir) {
    m_context = JSGlobalContextCreateInGroup(nullptr, nullptr);
    m_messageQueueThread = MessageQueues::getCurrentMessageQueueThread();
    s_globalContextRefToJSCExecutor[m_context] = this;
    installGlobalFunction(m_context, "nativeFlushQueueImmediate", nativeFlushQueueImmediate);
    installGlobalFunction(m_context, "nativePerformanceNow", nativePerformanceNow);
    installGlobalFunction(m_context, "nativeStartWorker", nativeStartWorker);
    installGlobalFunction(m_context, "nativePostMessageToWorker", nativePostMessageToWorker);
    installGlobalFunction(m_context, "nativeTerminateWorker", nativeTerminateWorker);

    installGlobalFunction(m_context, "nativeLoggingHook", JSLogging::nativeHook);

#ifdef WITH_FB_JSC_TUNING
    configureJSCForAndroid();
#endif

#ifdef WITH_JSC_EXTRA_TRACING
    addNativeTracingHooks(m_context);
    addNativeProfilingHooks(m_context);
    PerfLogging::installNativeHooks(m_context);
#endif

#ifdef WITH_FB_MEMORY_PROFILING
    addNativeMemoryHooks(m_context);
#endif
}
Пример #12
0
void addNativeTracingHooks(JSGlobalContextRef ctx) {
#if USE_JSCTRACING
  installGlobalFunction(ctx, "nativeTraceBeginSection", nativeTraceBeginSection);
  installGlobalFunction(ctx, "nativeTraceEndSection", nativeTraceEndSection);
  installGlobalFunction(ctx, "nativeTraceBeginAsyncSection", nativeTraceBeginAsyncSection);
  installGlobalFunction(ctx, "nativeTraceEndAsyncSection", nativeTraceEndAsyncSection);
  installGlobalFunction(ctx, "nativeTraceBeginAsyncFlow", nativeTraceBeginAsyncFlow);
  installGlobalFunction(ctx, "nativeTraceEndAsyncFlow", nativeTraceEndAsyncFlow);
  installGlobalFunction(ctx, "nativeTraceCounter", nativeTraceCounter);
#endif
}
Пример #13
0
void JSCWebWorker::initJSVMAndLoadScript() {
  FBASSERTMSGF(!isTerminated(), "Worker was already finished!");
  FBASSERTMSGF(!context_, "Worker JS VM was already created!");

  context_ = JSGlobalContextCreateInGroup(
      NULL, // use default JS 'global' object
      NULL // create new group (i.e. new VM)
  ); 
  s_globalContextRefToJSCWebWorker[context_] = this;
  
  // TODO(9604438): Protect against script does not exist
  std::string script = loadScriptFromAssets(scriptName_);
  evaluateScript(context_, String(script.c_str()), String(scriptName_.c_str()));

  installGlobalFunction(context_, "postMessage", nativePostMessage);
}
Пример #14
0
void JSCWebWorker::initJSVMAndLoadScript() {
  CHECK(!isTerminated()) << "Worker was already finished!";
  CHECK(!context_) << "Worker JS VM was already created!";

  context_ = JSGlobalContextCreateInGroup(
      NULL, // use default JS 'global' object
      NULL // create new group (i.e. new VM)
  );
  s_globalContextRefToJSCWebWorker[context_] = this;

  // TODO(9604438): Protect against script does not exist
  std::unique_ptr<const JSBigString> script = WebWorkerUtil::loadScriptFromAssets(scriptName_);
  evaluateScript(context_, jsStringFromBigString(*script), String(scriptName_.c_str()));

  installGlobalFunction(context_, "postMessage", nativePostMessage);
}
Пример #15
0
JSCExecutor::JSCExecutor(
    Bridge *bridge,
    std::shared_ptr<MessageQueueThread> messageQueueThread,
    int workerId,
    JSCExecutor *owner,
    const std::string& script,
    const std::unordered_map<std::string, std::string>& globalObjAsJSON,
    const folly::dynamic& jscConfig) :
    m_bridge(bridge),
    m_workerId(workerId),
    m_owner(owner),
    m_deviceCacheDir(owner->m_deviceCacheDir),
    m_messageQueueThread(messageQueueThread),
    m_jscConfig(jscConfig) {
  // We post initOnJSVMThread here so that the owner doesn't have to wait for
  // initialization on its own thread
  m_messageQueueThread->runOnQueue([this, script, globalObjAsJSON] () {
    initOnJSVMThread();

    installGlobalFunction(m_context, "postMessage", nativePostMessage);

    for (auto& it : globalObjAsJSON) {
      setGlobalVariable(it.first, it.second);
    }

    // Try to load the script from the network if script is a URL
    // NB: For security, this will only work in debug builds
    std::string scriptSrc;
    if (script.find("http://") == 0 || script.find("https://") == 0) {
      std::stringstream outfileBuilder;
      outfileBuilder << m_deviceCacheDir << "/workerScript" << m_workerId << ".js";
      scriptSrc = WebWorkerUtil::loadScriptFromNetworkSync(script, outfileBuilder.str());
    } else {
      // TODO(9604438): Protect against script does not exist
      scriptSrc = WebWorkerUtil::loadScriptFromAssets(script);
    }

    // TODO(9994180): Throw on error
    loadApplicationScript(scriptSrc, script);
  });
}
Пример #16
0
void addJSCPerfStatsHooks(JSGlobalContextRef ctx) {
#ifdef JSC_HAS_PERF_STATS_API
  installGlobalFunction(ctx, "nativeGetHeapStats", nativeGetHeapStats);
  installGlobalFunction(ctx, "nativeGetGCStats", nativeGetGCStats);
#endif
}
Пример #17
0
void JSCExecutor::setJSModulesUnbundle(std::unique_ptr<JSModulesUnbundle> unbundle) {
  if (!m_unbundle) {
    installGlobalFunction(m_context, "nativeRequire", nativeRequire);
  }
  m_unbundle = std::move(unbundle);
}
Пример #18
0
void addNativeProfilingHooks(JSGlobalContextRef ctx) {
  JSEnableByteCodeProfiling();
  installGlobalFunction(ctx, "nativeProfilerStart", nativeProfilerStart);
  installGlobalFunction(ctx, "nativeProfilerEnd", nativeProfilerEnd);
}
Пример #19
0
void addNativeMemoryHooks(JSGlobalContextRef ctx) {
#ifdef WITH_FB_MEMORY_PROFILING
  installGlobalFunction(ctx, "nativeCaptureHeap", nativeCaptureHeap);
#endif // WITH_FB_MEMORY_PROFILING

}
Пример #20
0
void addNativeTracingLegacyHooks(JSGlobalContextRef ctx) {
#if defined(WITH_JSC_EXTRA_TRACING)
  installGlobalFunction(ctx, "nativeTraceBeginLegacy", nativeTraceBeginLegacy);
  installGlobalFunction(ctx, "nativeTraceEndLegacy", nativeTraceEndLegacy);
#endif
}
Пример #21
0
void addNativeTracingLegacyHooks(JSGlobalContextRef ctx) {
  installGlobalFunction(ctx, "nativeTraceBeginLegacy", nativeTraceBeginLegacy);
  installGlobalFunction(ctx, "nativeTraceEndLegacy", nativeTraceEndLegacy);
}