Update DexLoadReporter to comply with the new reporting API

This is a partial cherry pick of commit
3bec94d78b.

It is partial because it only adapts DexLoadReporter to use the new
reporter BaseDexClassLoader.Reporter API.

Bug: 38138251
Test: make
Merged-In: I2486522fb811f9fc58a44b92642f43a41e7d5bac

(cherry picked from commit 3bec94d78b)

Change-Id: I4c41dbeb8a9297caac8b0eb936cf74832569f33e
This commit is contained in:
Calin Juravle
2017-07-22 12:33:41 -07:00
parent 01d686b85e
commit cd8fbd25d3

View File

@@ -28,6 +28,8 @@ import dalvik.system.VMRuntime;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -86,29 +88,46 @@ import java.util.Set;
}
@Override
public void report(List<String> dexPaths) {
if (dexPaths.isEmpty()) {
public void report(List<BaseDexClassLoader> classLoadersChain, List<String> classPaths) {
if (classLoadersChain.size() != classPaths.size()) {
Slog.wtf(TAG, "Bad call to DexLoadReporter: argument size mismatch");
return;
}
if (classPaths.isEmpty()) {
Slog.wtf(TAG, "Bad call to DexLoadReporter: empty dex paths");
return;
}
// The first element of classPaths is the list of dex files that should be registered.
// The classpath is represented as a list of dex files separated by File.pathSeparator.
String[] dexPathsForRegistration = classPaths.get(0).split(File.pathSeparator);
if (dexPathsForRegistration.length == 0) {
// No dex files to register.
return;
}
// Notify the package manager about the dex loads unconditionally.
// The load might be for either a primary or secondary dex file.
notifyPackageManager(dexPaths);
// Check for secondary dex files and register them for profiling if
// possible.
registerSecondaryDexForProfiling(dexPaths);
notifyPackageManager(classLoadersChain, classPaths);
// Check for secondary dex files and register them for profiling if possible.
// Note that we only register the dex paths belonging to the first class loader.
registerSecondaryDexForProfiling(dexPathsForRegistration);
}
private void notifyPackageManager(List<String> dexPaths) {
private void notifyPackageManager(List<BaseDexClassLoader> ignored,
List<String> classPaths) {
String packageName = ActivityThread.currentPackageName();
try {
// Notify only the paths of the first class loader for now.
ActivityThread.getPackageManager().notifyDexLoad(
packageName, dexPaths, VMRuntime.getRuntime().vmInstructionSet());
packageName, Arrays.asList(classPaths.get(0).split(File.pathSeparator)),
VMRuntime.getRuntime().vmInstructionSet());
} catch (RemoteException re) {
Slog.e(TAG, "Failed to notify PM about dex load for package " + packageName, re);
}
}
private void registerSecondaryDexForProfiling(List<String> dexPaths) {
private void registerSecondaryDexForProfiling(String[] dexPaths) {
if (!SystemProperties.getBoolean("dalvik.vm.dexopt.secondary", false)) {
return;
}