Skip to content

Commit

Permalink
Remove SoLoader.loadLibraryUnsafe usage in NativeLibrary.java
Browse files Browse the repository at this point in the history
Summary:
**Change**:
This diff refactors of the class `NativeLibrary` so that you pass both `List<String> libraryNames`(the libraries to be loaded) and `List<Runnable> libraryLoaders` (list of `Runnable` to invoke `SoLoader.loadLibrary`) to the constructor of `NativeLibrary`.

**Context**:
The change is motivated by testing delete dead native libraries in postprocessor on instagram and barcelona for android.

This can be achieved by using redex to track which libraries are loaded by SoLoader.loadLibrary D63471299 by looking at constant string passed to the method.

When SoLoader.loadLibrary is called on non-constant string variable, we replace it with SoLoader.loadLibraryUnsafeD63471297.

To make sure we can correctly compute the dead native libs in the postprocessor D64178470, this diff refactor the code to remove usage of loadLibraryUnsafe for instagram and barcleona.

Reviewed By: NTillmann

Differential Revision: D68152321

fbshipit-source-id: 3dd099575e18bc2d6be347d0848bbe6ac954faa8
  • Loading branch information
Rory Shu authored and facebook-github-bot committed Jan 15, 2025
1 parent f1d68fb commit 9040192
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions java/com/facebook/soloader/NativeLibrary.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ public abstract class NativeLibrary {
private static final String TAG = NativeLibrary.class.getName();

private final Object mLock;
private @Nullable List<String> mLibraryNames;
private @Nullable List<Runnable> mLibraryLoaders;
private Boolean mLoadLibraries;
private boolean mLibrariesLoaded;
private volatile @Nullable UnsatisfiedLinkError mLinkError;

protected NativeLibrary(List<String> libraryNames) {
protected NativeLibrary(List<Runnable> libraryLoaders) {
mLock = new Object();
mLoadLibraries = true;
mLibrariesLoaded = false;
mLinkError = null;
mLibraryNames = libraryNames;
mLibraryLoaders = libraryLoaders;
}

/**
Expand All @@ -57,14 +57,14 @@ public boolean loadLibraries() {
return mLibrariesLoaded;
}
try {
if (mLibraryNames != null) {
for (String name : mLibraryNames) {
SoLoader.loadLibraryUnsafe(name);
if (mLibraryLoaders != null) {
for (Runnable libraryLoader : mLibraryLoaders) {
libraryLoader.run();
}
}
initialNativeCheck();
mLibrariesLoaded = true;
mLibraryNames = null;
mLibraryLoaders = null;
} catch (UnsatisfiedLinkError error) {
LogUtil.e(TAG, "Failed to load native lib (initial check): ", error);
mLinkError = error;
Expand Down

0 comments on commit 9040192

Please sign in to comment.