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

Reduce visibility of JavaMethodWrapper and JavaModuleWrapper to package only #38591

Closed
wants to merge 3 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 @@ -12,7 +12,6 @@
import com.facebook.proguard.annotations.DoNotStrip;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.turbomodule.core.TurboModuleManagerDelegate;
import com.facebook.soloader.SoLoader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand All @@ -21,8 +20,6 @@
public class CompositeReactPackageTurboModuleManagerDelegate
extends ReactPackageTurboModuleManagerDelegate {

private static volatile boolean sIsSoLibraryLoaded;

protected native HybridData initHybrid();

private CompositeReactPackageTurboModuleManagerDelegate(
Expand Down Expand Up @@ -53,12 +50,4 @@ protected ReactPackageTurboModuleManagerDelegate build(
return new CompositeReactPackageTurboModuleManagerDelegate(context, packages, delegates);
}
}

protected synchronized void maybeLoadOtherSoLibraries() {
// Prevents issues with initializer interruptions. See T38996825 and D13793825 for more context.
if (!sIsSoLibraryLoaded) {
SoLoader.loadLibrary("turbomodulejsijni");
sIsSoLibraryLoaded = true;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,7 @@ public ReactModuleInfoProvider getReactModuleInfoProvider() {
TurboModule.class.isAssignableFrom(moduleClass)));
}

return new ReactModuleInfoProvider() {
@Override
public Map<String, ReactModuleInfo> getReactModuleInfos() {
return reactModuleInfoMap;
}
};
return () -> reactModuleInfoMap;
} catch (InstantiationException e) {
throw new RuntimeException(
"No ReactModuleInfoProvider for CoreModulesPackage$$ReactModuleInfoProvider", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class JavaMethodWrapper implements NativeModule.NativeMethod {
class JavaMethodWrapper implements NativeModule.NativeMethod {

private abstract static class ArgumentExtractor<T> {
public int getJSArgumentsNeeded() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* read and means fewer JNI calls.
*/
@DoNotStrip
public class JavaModuleWrapper {
class JavaModuleWrapper {
@DoNotStrip
public class MethodDescriptor {
@DoNotStrip Method method;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class ReactModuleInfo {
private final boolean mNeedsEagerInit;
private final boolean mHasConstants;
private final boolean mIsCxxModule;
private String mClassName;
private final String mClassName;
private final boolean mIsTurboModule;

public ReactModuleInfo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
@ReactModule(name = NativeAppStateSpec.NAME)
public class AppStateModule extends NativeAppStateSpec
implements LifecycleEventListener, WindowFocusChangeListener {
public static final String TAG = AppStateModule.class.getSimpleName();

public static final String APP_STATE_ACTIVE = "active";
public static final String APP_STATE_BACKGROUND = "background";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,20 @@

import com.facebook.jni.HybridData;
import com.facebook.react.turbomodule.core.interfaces.CallInvokerHolder;
import com.facebook.soloader.SoLoader;

/**
* JSCallInvoker is created at a different time/place (i.e: in CatalystInstance) than
* TurboModuleManager. Therefore, we need to wrap JSCallInvoker within a hybrid class so that we may
* pass it from CatalystInstance, through Java, to TurboModuleManager::initHybrid.
*/
public class CallInvokerHolderImpl implements CallInvokerHolder {
private static volatile boolean sIsSoLibraryLoaded;

private final HybridData mHybridData;

private CallInvokerHolderImpl(HybridData hd) {
maybeLoadSoLibrary();
mHybridData = hd;
static {
NativeModuleSoLoader.maybeLoadSoLibrary();
}

// Prevents issues with initializer interruptions. See T38996825 and D13793825 for more context.
private static synchronized void maybeLoadSoLibrary() {
if (!sIsSoLibraryLoaded) {
SoLoader.loadLibrary("turbomodulejsijni");
sIsSoLibraryLoaded = true;
}
private CallInvokerHolderImpl(HybridData hd) {
mHybridData = hd;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import com.facebook.jni.HybridData;
import com.facebook.react.turbomodule.core.interfaces.NativeMethodCallInvokerHolder;
import com.facebook.soloader.SoLoader;

/**
* NativeMethodCallInvokerHolder is created at a different time/place (i.e: in CatalystInstance)
Expand All @@ -18,20 +17,14 @@
* TurboModuleManager::initHybrid.
*/
public class NativeMethodCallInvokerHolderImpl implements NativeMethodCallInvokerHolder {
private static volatile boolean sIsSoLibraryLoaded;

private final HybridData mHybridData;

private NativeMethodCallInvokerHolderImpl(HybridData hd) {
maybeLoadSoLibrary();
mHybridData = hd;
static {
NativeModuleSoLoader.maybeLoadSoLibrary();
}

// Prevents issues with initializer interruptions. See T38996825 and D13793825 for more context.
private static synchronized void maybeLoadSoLibrary() {
if (!sIsSoLibraryLoaded) {
SoLoader.loadLibrary("turbomodulejsijni");
sIsSoLibraryLoaded = true;
}
private NativeMethodCallInvokerHolderImpl(HybridData hd) {
mHybridData = hd;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright (c) Meta Platforms, Inc. and 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.react.turbomodule.core

import com.facebook.soloader.SoLoader

internal class NativeModuleSoLoader {
companion object {
private var isSoLibraryLoaded = false

@Synchronized
@JvmStatic
fun maybeLoadSoLibrary() {
if (!isSoLibraryLoaded) {
SoLoader.loadLibrary("turbomodulejsijni")
isSoLibraryLoaded = true
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import com.facebook.react.turbomodule.core.interfaces.NativeMethodCallInvokerHolder;
import com.facebook.react.turbomodule.core.interfaces.TurboModule;
import com.facebook.react.turbomodule.core.interfaces.TurboModuleRegistry;
import com.facebook.soloader.SoLoader;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
Expand All @@ -38,12 +37,15 @@
* a Java module, that the C++ counterpart calls.
*/
public class TurboModuleManager implements JSIModule, TurboModuleRegistry {
private static volatile boolean sIsSoLibraryLoaded;
private final List<String> mEagerInitModuleNames;
private final ModuleProvider mTurboModuleProvider;
private final ModuleProvider mLegacyModuleProvider;
private final TurboModuleManagerDelegate mDelegate;

static {
NativeModuleSoLoader.maybeLoadSoLibrary();
}

// Prevents the creation of new TurboModules once cleanup as been initiated.
private final Object mModuleCleanupLock = new Object();

Expand All @@ -63,7 +65,6 @@ public TurboModuleManager(
@Nullable final TurboModuleManagerDelegate delegate,
CallInvokerHolder jsCallInvokerHolder,
NativeMethodCallInvokerHolder nativeMethodCallInvokerHolder) {
maybeLoadSoLibrary();
mDelegate = delegate;
mHybridData =
initHybrid(
Expand Down Expand Up @@ -451,14 +452,6 @@ public void onCatalystInstanceDestroy() {
mHybridData.resetNative();
}

// Prevents issues with initializer interruptions. See T38996825 and D13793825 for more context.
private static synchronized void maybeLoadSoLibrary() {
if (!sIsSoLibraryLoaded) {
SoLoader.loadLibrary("turbomodulejsijni");
sIsSoLibraryLoaded = true;
}
}

private static class ModuleHolder {
private volatile NativeModule mModule = null;
private volatile boolean mIsTryingToCreate = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import com.facebook.proguard.annotations.DoNotStrip;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.turbomodule.core.interfaces.TurboModule;
import com.facebook.soloader.SoLoader;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -21,13 +20,14 @@ public abstract class TurboModuleManagerDelegate {
@SuppressWarnings("unused")
private final HybridData mHybridData;

private static volatile boolean sIsSoLibraryLoaded;
static {
NativeModuleSoLoader.maybeLoadSoLibrary();
}

protected abstract HybridData initHybrid();

protected TurboModuleManagerDelegate() {
maybeLoadOtherSoLibraries();
maybeLoadSoLibrary();
mHybridData = initHybrid();
}

Expand Down Expand Up @@ -57,13 +57,5 @@ public List<String> getEagerInitModuleNames() {
return new ArrayList<>();
}

// Prevents issues with initializer interruptions. See T38996825 and D13793825 for more context.
private static synchronized void maybeLoadSoLibrary() {
if (!sIsSoLibraryLoaded) {
SoLoader.loadLibrary("turbomodulejsijni");
sIsSoLibraryLoaded = true;
}
}

protected synchronized void maybeLoadOtherSoLibraries() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@

import com.facebook.proguard.annotations.DoNotStrip;
import com.facebook.react.perflogger.NativeModulePerfLogger;
import com.facebook.soloader.SoLoader;
import javax.annotation.Nullable;

@DoNotStrip
public class TurboModulePerfLogger {

@Nullable private static NativeModulePerfLogger sNativeModulePerfLogger = null;
private static boolean sIsSoLibraryLoaded = false;

static {
NativeModuleSoLoader.maybeLoadSoLibrary();
}

public static void moduleDataCreateStart(String moduleName, int id) {
if (sNativeModulePerfLogger != null) {
Expand Down Expand Up @@ -79,17 +82,9 @@ public static void moduleCreateFail(String moduleName, int id) {

private static native void jniEnableCppLogging(NativeModulePerfLogger perfLogger);

private static synchronized void maybeLoadSoLibrary() {
if (!sIsSoLibraryLoaded) {
SoLoader.loadLibrary("turbomodulejsijni");
sIsSoLibraryLoaded = true;
}
}

public static void enableLogging(NativeModulePerfLogger perfLogger) {
if (perfLogger != null) {
sNativeModulePerfLogger = perfLogger;
maybeLoadSoLibrary();
jniEnableCppLogging(perfLogger);
}
}
Expand Down