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); }
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 }
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); }
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); }); }
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); }
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 }
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 }
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 }
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); }
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 }
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 }
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); }
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); }
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); }); }
void addJSCPerfStatsHooks(JSGlobalContextRef ctx) { #ifdef JSC_HAS_PERF_STATS_API installGlobalFunction(ctx, "nativeGetHeapStats", nativeGetHeapStats); installGlobalFunction(ctx, "nativeGetGCStats", nativeGetGCStats); #endif }
void JSCExecutor::setJSModulesUnbundle(std::unique_ptr<JSModulesUnbundle> unbundle) { if (!m_unbundle) { installGlobalFunction(m_context, "nativeRequire", nativeRequire); } m_unbundle = std::move(unbundle); }
void addNativeProfilingHooks(JSGlobalContextRef ctx) { JSEnableByteCodeProfiling(); installGlobalFunction(ctx, "nativeProfilerStart", nativeProfilerStart); installGlobalFunction(ctx, "nativeProfilerEnd", nativeProfilerEnd); }
void addNativeMemoryHooks(JSGlobalContextRef ctx) { #ifdef WITH_FB_MEMORY_PROFILING installGlobalFunction(ctx, "nativeCaptureHeap", nativeCaptureHeap); #endif // WITH_FB_MEMORY_PROFILING }
void addNativeTracingLegacyHooks(JSGlobalContextRef ctx) { #if defined(WITH_JSC_EXTRA_TRACING) installGlobalFunction(ctx, "nativeTraceBeginLegacy", nativeTraceBeginLegacy); installGlobalFunction(ctx, "nativeTraceEndLegacy", nativeTraceEndLegacy); #endif }
void addNativeTracingLegacyHooks(JSGlobalContextRef ctx) { installGlobalFunction(ctx, "nativeTraceBeginLegacy", nativeTraceBeginLegacy); installGlobalFunction(ctx, "nativeTraceEndLegacy", nativeTraceEndLegacy); }