Merge "Cleanup performDexOpt with instruction sets." into nyc-dev

This commit is contained in:
TreeHugger Robot
2016-05-31 11:23:43 +00:00
committed by Android (Google) Code Review
4 changed files with 18 additions and 33 deletions

View File

@@ -459,23 +459,19 @@ interface IPackageManager {
/**
* Ask the package manager to perform dex-opt (if needed) on the given
* package and for the given instruction set if it already hasn't done
* so.
*
* If the supplied instructionSet is null, the package manager will use
* the packages default instruction set.
* package if it already hasn't done so.
*
* In most cases, apps are dexopted in advance and this function will
* be a no-op.
*/
boolean performDexOptIfNeeded(String packageName, String instructionSet);
boolean performDexOptIfNeeded(String packageName);
/**
* Ask the package manager to perform a dex-opt for the given reason. The package
* manager will map the reason to a compiler filter according to the current system
* configuration.
*/
boolean performDexOpt(String packageName, String instructionSet, boolean checkProfiles,
boolean performDexOpt(String packageName, boolean checkProfiles,
int compileReason, boolean force);
/**
* Ask the package manager to perform a dex-opt with the given compiler filter.
@@ -483,7 +479,7 @@ interface IPackageManager {
* Note: exposed only for the shell command to allow moving packages explicitly to a
* definite state.
*/
boolean performDexOptMode(String packageName, String instructionSet, boolean checkProfiles,
boolean performDexOptMode(String packageName, boolean checkProfiles,
String targetCompilerFilter, boolean force);
void forceDexOpt(String packageName);

View File

@@ -154,7 +154,6 @@ public class BackgroundDexOptService extends JobService {
// behave differently than "pm.dexopt.bg-dexopt=speed-profile" but that's a
// trade-off worth doing to save boot time work.
pm.performDexOpt(pkg,
/* instruction set */ null,
/* checkProfiles */ false,
PackageManagerService.REASON_BOOT,
/* force */ false);
@@ -192,7 +191,6 @@ public class BackgroundDexOptService extends JobService {
// Optimize package if needed. Note that there can be no race between
// concurrent jobs because PackageDexOptimizer.performDexOpt is synchronized.
if (pm.performDexOpt(pkg,
/* instruction set */ null,
/* checkProfiles */ true,
PackageManagerService.REASON_BACKGROUND_DEXOPT,
/* force */ false)) {

View File

@@ -7267,7 +7267,6 @@ public class PackageManagerService extends IPackageManager.Stub {
// behave differently than "pm.dexopt.bg-dexopt=speed-profile" but that's a
// trade-off worth doing to save boot time work.
int dexOptStatus = performDexOptTraced(pkg.packageName,
null /* instructionSet */,
false /* checkProfiles */,
getCompilerFilterForReason(causeFirstBoot ? REASON_FIRST_BOOT : REASON_BOOT),
false /* force */);
@@ -7309,33 +7308,33 @@ public class PackageManagerService extends IPackageManager.Stub {
// TODO: this is not used nor needed. Delete it.
@Override
public boolean performDexOptIfNeeded(String packageName, String instructionSet) {
int dexOptStatus = performDexOptTraced(packageName, instructionSet,
public boolean performDexOptIfNeeded(String packageName) {
int dexOptStatus = performDexOptTraced(packageName,
false /* checkProfiles */, getFullCompilerFilter(), false /* force */);
return dexOptStatus != PackageDexOptimizer.DEX_OPT_FAILED;
}
@Override
public boolean performDexOpt(String packageName, String instructionSet,
public boolean performDexOpt(String packageName,
boolean checkProfiles, int compileReason, boolean force) {
int dexOptStatus = performDexOptTraced(packageName, instructionSet, checkProfiles,
int dexOptStatus = performDexOptTraced(packageName, checkProfiles,
getCompilerFilterForReason(compileReason), force);
return dexOptStatus != PackageDexOptimizer.DEX_OPT_FAILED;
}
@Override
public boolean performDexOptMode(String packageName, String instructionSet,
public boolean performDexOptMode(String packageName,
boolean checkProfiles, String targetCompilerFilter, boolean force) {
int dexOptStatus = performDexOptTraced(packageName, instructionSet, checkProfiles,
int dexOptStatus = performDexOptTraced(packageName, checkProfiles,
targetCompilerFilter, force);
return dexOptStatus != PackageDexOptimizer.DEX_OPT_FAILED;
}
private int performDexOptTraced(String packageName, String instructionSet,
private int performDexOptTraced(String packageName,
boolean checkProfiles, String targetCompilerFilter, boolean force) {
Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "dexopt");
try {
return performDexOptInternal(packageName, instructionSet, checkProfiles,
return performDexOptInternal(packageName, checkProfiles,
targetCompilerFilter, force);
} finally {
Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
@@ -7344,10 +7343,9 @@ public class PackageManagerService extends IPackageManager.Stub {
// Run dexopt on a given package. Returns true if dexopt did not fail, i.e.
// if the package can now be considered up to date for the given filter.
private int performDexOptInternal(String packageName, String instructionSet,
private int performDexOptInternal(String packageName,
boolean checkProfiles, String targetCompilerFilter, boolean force) {
PackageParser.Package p;
final String targetInstructionSet;
synchronized (mPackages) {
p = mPackages.get(packageName);
if (p == null) {
@@ -7355,15 +7353,11 @@ public class PackageManagerService extends IPackageManager.Stub {
return PackageDexOptimizer.DEX_OPT_FAILED;
}
mPackageUsage.write(false);
targetInstructionSet = instructionSet != null ? instructionSet :
getPrimaryInstructionSet(p.applicationInfo);
}
long callingId = Binder.clearCallingIdentity();
try {
synchronized (mInstallLock) {
final String[] instructionSets = new String[] { targetInstructionSet };
return performDexOptInternalWithDependenciesLI(p, instructionSets, checkProfiles,
return performDexOptInternalWithDependenciesLI(p, checkProfiles,
targetCompilerFilter, force);
}
} finally {
@@ -7384,7 +7378,7 @@ public class PackageManagerService extends IPackageManager.Stub {
}
private int performDexOptInternalWithDependenciesLI(PackageParser.Package p,
String instructionSets[], boolean checkProfiles, String targetCompilerFilter,
boolean checkProfiles, String targetCompilerFilter,
boolean force) {
// Select the dex optimizer based on the force parameter.
// Note: The force option is rarely used (cmdline input for testing, mostly), so it's OK to
@@ -7396,6 +7390,7 @@ public class PackageManagerService extends IPackageManager.Stub {
// Optimize all dependencies first. Note: we ignore the return value and march on
// on errors.
Collection<PackageParser.Package> deps = findSharedNonSystemLibraries(p);
final String[] instructionSets = getAppDexInstructionSets(p.applicationInfo);
if (!deps.isEmpty()) {
for (PackageParser.Package depPackage : deps) {
// TODO: Analyze and investigate if we (should) profile libraries.
@@ -7405,7 +7400,6 @@ public class PackageManagerService extends IPackageManager.Stub {
getCompilerFilterForReason(REASON_NON_SYSTEM_LIBRARY));
}
}
return pdo.performDexOpt(p, p.usesLibraryFiles, instructionSets, checkProfiles,
targetCompilerFilter);
}
@@ -7477,14 +7471,11 @@ public class PackageManagerService extends IPackageManager.Stub {
}
synchronized (mInstallLock) {
final String[] instructionSets = new String[] {
getPrimaryInstructionSet(pkg.applicationInfo) };
Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "dexopt");
// Whoever is calling forceDexOpt wants a fully compiled package.
// Don't use profiles since that may cause compilation to be skipped.
final int res = performDexOptInternalWithDependenciesLI(pkg, instructionSets,
final int res = performDexOptInternalWithDependenciesLI(pkg,
false /* checkProfiles */, getCompilerFilterForReason(REASON_FORCED_DEXOPT),
true /* force */);

View File

@@ -358,7 +358,7 @@ class PackageManagerShellCommand extends ShellCommand {
mInterface.clearApplicationProfileData(packageName);
}
boolean result = mInterface.performDexOptMode(packageName, null /* instructionSet */,
boolean result = mInterface.performDexOptMode(packageName,
checkProfiles, targetCompilerFilter, forceCompilation);
if (!result) {
failedPackages.add(packageName);