Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace NativeRunnable with fbjni implementation #33776

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,32 @@
import com.facebook.proguard.annotations.DoNotStrip;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;

@DoNotStrip
public class BackgroundExecutor {
private static final String TAG = "FabricBackgroundExecutor";

private static class NamedThreadFactory implements ThreadFactory {
private final String mName;

public NamedThreadFactory(String name) {
mName = name;
}

@Override
public Thread newThread(Runnable r) {
Thread thread = Executors.defaultThreadFactory().newThread(r);
thread.setName(mName);
return thread;
}
}

private final ExecutorService mExecutorService;

@DoNotStrip
private BackgroundExecutor() {
mExecutorService = Executors.newFixedThreadPool(1);
private BackgroundExecutor(String name) {
mExecutorService = Executors.newFixedThreadPool(1, new NamedThreadFactory(name));
}

@DoNotStrip
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
*/

#include "Binding.h"

#include "AsyncEventBeat.h"
#include "EventEmitterWrapper.h"
#include "JBackgroundExecutor.h"
#include "ReactNativeConfigHolder.h"
#include "StateWrapperImpl.h"

Expand Down Expand Up @@ -455,8 +457,8 @@ void Binding::installFabricUIManager(
toolbox.synchronousEventBeatFactory = synchronousBeatFactory;
toolbox.asynchronousEventBeatFactory = asynchronousBeatFactory;

backgroundExecutor_ = std::make_unique<JBackgroundExecutor>();
toolbox.backgroundExecutor = backgroundExecutor_->get();
backgroundExecutor_ = JBackgroundExecutor::create("fabric_bg");
toolbox.backgroundExecutor = backgroundExecutor_;

animationDriver_ = std::make_shared<LayoutAnimationDriver>(
runtimeExecutor, contextContainer, this);
Expand Down Expand Up @@ -558,8 +560,7 @@ void Binding::preallocateView(
};

if (dispatchPreallocationInBackground_) {
auto backgroundExecutor = backgroundExecutor_->get();
backgroundExecutor(preallocationFunction);
backgroundExecutor_(preallocationFunction);
} else {
preallocationFunction();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

#include "FabricMountingManager.h"

#include <memory>
#include <mutex>

#include <fbjni/fbjni.h>
#include <react/jni/JRuntimeExecutor.h>
#include <react/jni/JRuntimeScheduler.h>
Expand All @@ -18,12 +21,9 @@
#include <react/renderer/scheduler/SchedulerDelegate.h>
#include <react/renderer/uimanager/LayoutAnimationStatusDelegate.h>

#include <memory>
#include <mutex>
#include "ComponentFactory.h"
#include "EventBeatManager.h"
#include "EventEmitterWrapper.h"
#include "JBackgroundExecutor.h"
#include "SurfaceHandlerBinding.h"

namespace facebook {
Expand Down Expand Up @@ -144,7 +144,7 @@ class Binding : public jni::HybridClass<Binding>,

std::shared_ptr<LayoutAnimationDriver> animationDriver_;

std::unique_ptr<JBackgroundExecutor> backgroundExecutor_;
BackgroundExecutor backgroundExecutor_;

butter::map<SurfaceId, SurfaceHandler> surfaceHandlerRegistry_{};
butter::shared_mutex
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,24 @@
* LICENSE file in the root directory of this source tree.
*/

#include <fbjni/fbjni.h>
#include <react/jni/JNativeRunnable.h>

#include "JBackgroundExecutor.h"

#include <fbjni/NativeRunnable.h>
#include <fbjni/fbjni.h>

namespace facebook {
namespace react {

using namespace facebook::jni;

using facebook::react::JNativeRunnable;
using facebook::react::Runnable;

BackgroundExecutor JBackgroundExecutor::get() {
auto self = JBackgroundExecutor::create();

return [self](std::function<void()> &&runnable) {
BackgroundExecutor JBackgroundExecutor::create(const std::string &name) {
auto instance = make_global(newInstance(name));
return [instance = std::move(instance)](std::function<void()> &&runnable) {
static auto method =
findClassStatic(JBackgroundExecutor::JBackgroundExecutorJavaDescriptor)
->getMethod<void(Runnable::javaobject)>("queueRunnable");

javaClassStatic()->getMethod<void(JRunnable::javaobject)>(
"queueRunnable");
auto jrunnable = JNativeRunnable::newObjectCxxArgs(std::move(runnable));
method(self, static_ref_cast<Runnable::javaobject>(jrunnable).get());
method(instance, jrunnable.get());
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,7 @@ class JBackgroundExecutor : public JavaClass<JBackgroundExecutor> {
static auto constexpr kJavaDescriptor =
"Lcom/facebook/react/bridge/BackgroundExecutor;";

constexpr static auto JBackgroundExecutorJavaDescriptor =
"com/facebook/react/bridge/BackgroundExecutor";

static global_ref<javaobject> create() {
return make_global(newInstance());
}

BackgroundExecutor get();
static BackgroundExecutor create(const std::string &name);
};

} // namespace react
Expand Down
1 change: 0 additions & 1 deletion ReactAndroid/src/main/jni/react/jni/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ EXPORTED_HEADERS = [
"JavaScriptExecutorHolder.h",
"JCallback.h",
"JMessageQueueThread.h",
"JNativeRunnable.h",
"JReactMarker.h",
"JSLoader.h",
"JSLogging.h",
Expand Down
3 changes: 0 additions & 3 deletions ReactAndroid/src/main/jni/react/jni/CatalystInstanceImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
#include <logger/react_native_log.h>

#include "CxxModuleWrapper.h"
#include "JNativeRunnable.h"
#include "JReactCxxErrorHandler.h"
#include "JReactSoftExceptionLogger.h"
#include "JavaScriptExecutorHolder.h"
Expand Down Expand Up @@ -155,8 +154,6 @@ void CatalystInstanceImpl::registerNatives() {
"warnOnLegacyNativeModuleSystemUse",
CatalystInstanceImpl::warnOnLegacyNativeModuleSystemUse),
});

JNativeRunnable::registerNatives();
}

void log(ReactNativeLogLevel level, const char *message) {
Expand Down
12 changes: 5 additions & 7 deletions ReactAndroid/src/main/jni/react/jni/JMessageQueueThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@
#include <mutex>

#include <fb/log.h>
#include <fbjni/NativeRunnable.h>
#include <fbjni/fbjni.h>
#include <jsi/jsi.h>

#include "JNativeRunnable.h"

namespace facebook {
namespace react {

Expand Down Expand Up @@ -69,11 +68,10 @@ void JMessageQueueThread::runOnQueue(std::function<void()> &&runnable) {
jni::ThreadScope guard;
static auto method =
JavaMessageQueueThread::javaClassStatic()
->getMethod<jboolean(Runnable::javaobject)>("runOnQueue");
method(
m_jobj,
JNativeRunnable::newObjectCxxArgs(wrapRunnable(std::move(runnable)))
.get());
->getMethod<jboolean(JRunnable::javaobject)>("runOnQueue");
auto jrunnable =
JNativeRunnable::newObjectCxxArgs(wrapRunnable(std::move(runnable)));
method(m_jobj, jrunnable.get());
}

void JMessageQueueThread::runOnQueueSync(std::function<void()> &&runnable) {
Expand Down
52 changes: 0 additions & 52 deletions ReactAndroid/src/main/jni/react/jni/JNativeRunnable.h

This file was deleted.