Skip to content

Commit

Permalink
add flag for DSONotFound error recovery for backup so source
Browse files Browse the repository at this point in the history
Summary:
Add flag for enabling DSONotFound error. The flag will be used for running QE experiment to understand the performance impact of recovering from DSONotFound error.

The flag is initially set to false.

Reviewed By: adicatana

Differential Revision: D56141106

fbshipit-source-id: cda9816f448f83890787e9843fb624384f1eff2e
  • Loading branch information
Rory Shu authored and facebook-github-bot committed Apr 19, 2024
1 parent 0fc08d3 commit e9905f6
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 8 deletions.
18 changes: 15 additions & 3 deletions java/com/facebook/soloader/SoLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ public class SoLoader {
/** Experiment ONLY: skip custom SoSources for base.apk and rely on System.loadLibrary calls. */
public static final int SOLOADER_ENABLE_BASE_APK_SPLIT_SOURCE = (1 << 10);

/** Experiment ONLY: skip DSONotFound error recovery for back up so source */
public static final int SOLOADER_ENABLE_BACKUP_SOSOURCE_DSONOTFOUND_ERROR_RECOVERY = (1 << 11);

@GuardedBy("sSoSourcesLock")
private static int sFlags;

Expand Down Expand Up @@ -269,7 +272,7 @@ public static void init(Context context, int flags, @Nullable SoFileLoader soFil
flags |= SOLOADER_DISABLE_BACKUP_SOSOURCE;
}

initSoLoader(context, soFileLoader);
initSoLoader(context, soFileLoader, flags);
initSoSources(context, flags);
LogUtil.v(TAG, "Init SoLoader delegate");
NativeLoader.initIfUninitialized(new NativeLoaderToSoLoaderDelegate());
Expand Down Expand Up @@ -522,8 +525,16 @@ private static int makePrepareFlags() {
}
}

private static int makeRecoveryFlags(int flags) {
int recoveryFlags = 0;
if ((flags & SOLOADER_ENABLE_BACKUP_SOSOURCE_DSONOTFOUND_ERROR_RECOVERY) != 0) {
recoveryFlags |= RecoveryStrategy.FLAG_ENABLE_DSONOTFOUND_ERROR_RECOVERY_FOR_BACKUP_SO_SOURCE;
}
return recoveryFlags;
}

private static synchronized void initSoLoader(
@Nullable Context context, @Nullable SoFileLoader soFileLoader) {
@Nullable Context context, @Nullable SoFileLoader soFileLoader, int flags) {
if (context != null) {
Context applicationContext = context.getApplicationContext();

Expand All @@ -537,7 +548,8 @@ private static synchronized void initSoLoader(
}

sApplicationContext = applicationContext;
sRecoveryStrategyFactory = new DefaultRecoveryStrategyFactory(applicationContext);
sRecoveryStrategyFactory =
new DefaultRecoveryStrategyFactory(applicationContext, makeRecoveryFlags(flags));
}

if (soFileLoader == null && sSoFileLoader != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
public class DefaultRecoveryStrategyFactory implements RecoveryStrategyFactory {
private final Context mContext;
private final BaseApkPathHistory mBaseApkPathHistory;
private final int mRecoveryFlags;

public DefaultRecoveryStrategyFactory(Context context) {
public DefaultRecoveryStrategyFactory(Context context, int recoveryFlags) {
mContext = context;
mRecoveryFlags = recoveryFlags;
mBaseApkPathHistory = new BaseApkPathHistory(5);
mBaseApkPathHistory.recordPathIfNew(context.getApplicationInfo().sourceDir);
}
Expand All @@ -34,7 +36,7 @@ public RecoveryStrategy get() {
new DetectDataAppMove(mContext, mBaseApkPathHistory),
new CheckBaseApkExists(mContext, mBaseApkPathHistory),
new WaitForAsyncInit(),
new ReunpackBackupSoSources(),
new ReunpackBackupSoSources(mRecoveryFlags),
new ReunpackNonBackupSoSources(),
new WaitForAsyncInit());
}
Expand Down
3 changes: 3 additions & 0 deletions java/com/facebook/soloader/recovery/RecoveryStrategy.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,8 @@

// Abstract interface for algorithms attempting to recover SoLoader from a corrupted state.
public interface RecoveryStrategy {

public static final int FLAG_ENABLE_DSONOTFOUND_ERROR_RECOVERY_FOR_BACKUP_SO_SOURCE = 1;

boolean recover(UnsatisfiedLinkError e, SoSource[] soSources);
}
23 changes: 20 additions & 3 deletions java/com/facebook/soloader/recovery/ReunpackBackupSoSources.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@
*/
public class ReunpackBackupSoSources implements RecoveryStrategy {

private int mRecoveryFlags;

public ReunpackBackupSoSources() {
this(0);
}

public ReunpackBackupSoSources(int recoveryFlags) {
mRecoveryFlags = recoveryFlags;
}

@Override
public boolean recover(UnsatisfiedLinkError error, SoSource[] soSources) {
if (!(error instanceof SoLoaderULError)) {
Expand All @@ -49,10 +59,17 @@ public boolean recover(UnsatisfiedLinkError error, SoSource[] soSources) {
}

if (err instanceof SoLoaderDSONotFoundError) {
// Recover if DSO is not found
logRecovery(err, soName);
if ((mRecoveryFlags
& RecoveryStrategy.FLAG_ENABLE_DSONOTFOUND_ERROR_RECOVERY_FOR_BACKUP_SO_SOURCE)
!= 0) {

// Recover if DSO is not found
logRecovery(err, soName);

return recoverDSONotFoundError(soSources, soName, 0);
return recoverDSONotFoundError(soSources, soName, 0);
} else {
return false;
}
} else if (message == null || (!message.contains("/app/") && !message.contains("/mnt/"))) {
// Don't recover if the DSO wasn't in the data/app directory

Expand Down

0 comments on commit e9905f6

Please sign in to comment.