Merge "Cleanup performDexOpt with instruction sets." into nyc-dev am: 89f4bff149

am: 0063f2c80b

* commit '0063f2c80b1d9512fd77ca71faa85737c1fd2424':
  Cleanup performDexOpt with instruction sets.

Change-Id: If15ee5ff3e58d3bf0226bea94707e228c77fbf08
This commit is contained in:
Nicolas Geoffray
2016-05-31 11:53:00 +00:00
committed by android-build-merger
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 * 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 * package if it already hasn't done so.
* so.
*
* If the supplied instructionSet is null, the package manager will use
* the packages default instruction set.
* *
* In most cases, apps are dexopted in advance and this function will * In most cases, apps are dexopted in advance and this function will
* be a no-op. * 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 * 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 * manager will map the reason to a compiler filter according to the current system
* configuration. * configuration.
*/ */
boolean performDexOpt(String packageName, String instructionSet, boolean checkProfiles, boolean performDexOpt(String packageName, boolean checkProfiles,
int compileReason, boolean force); int compileReason, boolean force);
/** /**
* Ask the package manager to perform a dex-opt with the given compiler filter. * 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 * Note: exposed only for the shell command to allow moving packages explicitly to a
* definite state. * definite state.
*/ */
boolean performDexOptMode(String packageName, String instructionSet, boolean checkProfiles, boolean performDexOptMode(String packageName, boolean checkProfiles,
String targetCompilerFilter, boolean force); String targetCompilerFilter, boolean force);
void forceDexOpt(String packageName); 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 // behave differently than "pm.dexopt.bg-dexopt=speed-profile" but that's a
// trade-off worth doing to save boot time work. // trade-off worth doing to save boot time work.
pm.performDexOpt(pkg, pm.performDexOpt(pkg,
/* instruction set */ null,
/* checkProfiles */ false, /* checkProfiles */ false,
PackageManagerService.REASON_BOOT, PackageManagerService.REASON_BOOT,
/* force */ false); /* force */ false);
@@ -192,7 +191,6 @@ public class BackgroundDexOptService extends JobService {
// Optimize package if needed. Note that there can be no race between // Optimize package if needed. Note that there can be no race between
// concurrent jobs because PackageDexOptimizer.performDexOpt is synchronized. // concurrent jobs because PackageDexOptimizer.performDexOpt is synchronized.
if (pm.performDexOpt(pkg, if (pm.performDexOpt(pkg,
/* instruction set */ null,
/* checkProfiles */ true, /* checkProfiles */ true,
PackageManagerService.REASON_BACKGROUND_DEXOPT, PackageManagerService.REASON_BACKGROUND_DEXOPT,
/* force */ false)) { /* force */ false)) {

View File

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

View File

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