diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2024-02-02 19:05:51 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2024-02-02 19:05:51 +0000 |
commit | 7deb5ff066affe5d5b685debc7387c2706d74ed9 (patch) | |
tree | df56d424573d4b03a1b75224831d9c79c8a237eb | |
parent | 21ffb29652345b484aff33717ff0d74bfd606ddd (diff) | |
parent | f4d07472e4eabeefd0ce60ecb9cf437ceec38505 (diff) | |
download | support-snap-temp-L75400030001793635.tar.gz |
Merge "Fix method bitmap storage for V015S formats." into snap-temp-L75400030001793635snap-temp-L75400030001793635
-rw-r--r-- | profileinstaller/profileinstaller/src/main/java/androidx/profileinstaller/ProfileTranscoder.java | 49 | ||||
-rw-r--r-- | profileinstaller/profileinstaller/src/test/java/androidx/profileinstaller/ProfileTranscoderTests.java | 19 | ||||
-rw-r--r-- | profileinstaller/profileinstaller/src/test/test-data/katana/baseline-p.prof | bin | 0 -> 151 bytes | |||
-rw-r--r-- | profileinstaller/profileinstaller/src/test/test-data/katana/baseline-s.prof | bin | 0 -> 120 bytes | |||
-rw-r--r-- | profileinstaller/profileinstaller/src/test/test-data/katana/baseline-s.profm | bin | 0 -> 46 bytes |
5 files changed, 56 insertions, 12 deletions
diff --git a/profileinstaller/profileinstaller/src/main/java/androidx/profileinstaller/ProfileTranscoder.java b/profileinstaller/profileinstaller/src/main/java/androidx/profileinstaller/ProfileTranscoder.java index 700a73710cb..adf0f86be69 100644 --- a/profileinstaller/profileinstaller/src/main/java/androidx/profileinstaller/ProfileTranscoder.java +++ b/profileinstaller/profileinstaller/src/main/java/androidx/profileinstaller/ProfileTranscoder.java @@ -38,7 +38,6 @@ import static androidx.profileinstaller.Encoding.writeUInt8; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.annotation.RequiresApi; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -52,7 +51,6 @@ import java.util.List; import java.util.Map; import java.util.TreeMap; -@RequiresApi(19) class ProfileTranscoder { private ProfileTranscoder() { } @@ -219,7 +217,7 @@ class ProfileTranscoder { * (M|dex_map_size) * type_index_diff[dex_map_size] * where `M` stands for special encodings indicating missing types (kIsMissingTypesEncoding) - * or memamorphic call (kIsMegamorphicEncoding) which both imply `dex_map_size == 0`. + * or megamorphic call (kIsMegamorphicEncoding) which both imply `dex_map_size == 0`. */ private static void writeProfileForS( @NonNull OutputStream os, @@ -371,7 +369,7 @@ class ProfileTranscoder { // Method Flags int methodFlags = computeMethodFlags(profile); // Bitmap Contents - byte[] bitmapContents = createMethodBitmapRegion(profile); + byte[] bitmapContents = createMethodBitmapRegionForS(methodFlags, profile); // Methods with Inline Caches byte[] methodRegionContents = createMethodsWithInlineCaches(profile); // Profile Index @@ -404,11 +402,12 @@ class ProfileTranscoder { } } - private static byte[] createMethodBitmapRegion( + private static byte[] createMethodBitmapRegionForS( + int methodFlags, @NonNull DexProfileData profile ) throws IOException { try (ByteArrayOutputStream out = new ByteArrayOutputStream()) { - writeMethodBitmap(out, profile); + writeMethodBitmapForS(out, methodFlags, profile); return out.toByteArray(); } } @@ -543,8 +542,8 @@ class ProfileTranscoder { } /** - * Create compressable body only for V0.1.0 v0.0.9. - * + * Create compressible body only for V0.1.0 v0.0.9. + * <p> * For 0.1.0 this will write header/header/header/body/body/body * For 0.0.9 this will write header/body/header/body/header/body */ @@ -613,6 +612,12 @@ class ProfileTranscoder { return roundUpToByte(methodBitmapBits) / SIZEOF_BYTE; } + private static int getMethodBitmapStorageSizeForS(int methodFlags, int numMethodIds) { + int bits = Integer.bitCount(methodFlags & ~HOT); + int methodBitmapBits = bits * numMethodIds; + return roundUpToByte(methodBitmapBits) / SIZEOF_BYTE; + } + private static int roundUpToByte(int bits) { return (bits + SIZEOF_BYTE - 1) & -SIZEOF_BYTE; } @@ -721,6 +726,34 @@ class ProfileTranscoder { } } + private static void writeMethodBitmapForS( + @NonNull OutputStream os, + int methodFlags, + @NonNull DexProfileData dexData + ) throws IOException { + int methodBitmapStorageSize = getMethodBitmapStorageSizeForS( + methodFlags, dexData.numMethodIds + ); + byte[] bitmap = new byte[methodBitmapStorageSize]; + for (Map.Entry<Integer, Integer> entry : dexData.methods.entrySet()) { + int methodIndex = entry.getKey(); + int flagValue = entry.getValue(); + + if ((flagValue & methodFlags) == 0) { + continue; + } + + if ((flagValue & STARTUP) != 0) { + setMethodBitmapBit(bitmap, STARTUP, methodIndex, dexData); + } + + if ((flagValue & POST_STARTUP) != 0) { + setMethodBitmapBit(bitmap, POST_STARTUP, methodIndex, dexData); + } + } + os.write(bitmap); + } + /** * Writes the methods flags as a bitmap to the output stream. * @param os the destination OutputStream to write to diff --git a/profileinstaller/profileinstaller/src/test/java/androidx/profileinstaller/ProfileTranscoderTests.java b/profileinstaller/profileinstaller/src/test/java/androidx/profileinstaller/ProfileTranscoderTests.java index 23a4c108185..a5e924039f5 100644 --- a/profileinstaller/profileinstaller/src/test/java/androidx/profileinstaller/ProfileTranscoderTests.java +++ b/profileinstaller/profileinstaller/src/test/java/androidx/profileinstaller/ProfileTranscoderTests.java @@ -65,7 +65,7 @@ public class ProfileTranscoderTests { @Test public void testTranscodeForN() throws IOException { assertGoldenTranscode( - testFile("baseline.prof"), + testFile("baseline-p.prof"), testFile("baseline-n.prof"), ProfileVersion.V001_N ); @@ -74,7 +74,7 @@ public class ProfileTranscoderTests { @Test public void testTranscodeForO() throws IOException { assertGoldenTranscode( - testFile("baseline.prof"), + testFile("baseline-p.prof"), testFile("baseline-o.prof"), ProfileVersion.V005_O ); @@ -83,7 +83,7 @@ public class ProfileTranscoderTests { @Test public void testTranscodeForO_MR1() throws IOException { assertGoldenTranscode( - testFile("baseline.prof"), + testFile("baseline-p.prof"), testFile("baseline-o-mr1.prof"), ProfileVersion.V009_O_MR1 ); @@ -92,7 +92,7 @@ public class ProfileTranscoderTests { @Test public void testTranscodeForP() throws IOException { assertGoldenTranscode( - testFile("baseline.prof"), + testFile("baseline-p.prof"), testFile("baseline-p.prof"), ProfileVersion.V010_P ); @@ -110,6 +110,17 @@ public class ProfileTranscoderTests { } @Test + public void testTranscodeForS_methodBitmapStorage() throws IOException { + assertGoldenTranscodeWithMeta( + testFile("katana/baseline-p.prof"), + testFile("katana/baseline-s.profm"), + testFile("katana/baseline-s.prof"), + ProfileVersion.V015_S, + "" /* apkName */ + ); + } + + @Test public void testMultidexTranscodeForO() throws IOException { assertGoldenTranscode( testFile("baseline-multidex.prof"), diff --git a/profileinstaller/profileinstaller/src/test/test-data/katana/baseline-p.prof b/profileinstaller/profileinstaller/src/test/test-data/katana/baseline-p.prof Binary files differnew file mode 100644 index 00000000000..5633b9283d6 --- /dev/null +++ b/profileinstaller/profileinstaller/src/test/test-data/katana/baseline-p.prof diff --git a/profileinstaller/profileinstaller/src/test/test-data/katana/baseline-s.prof b/profileinstaller/profileinstaller/src/test/test-data/katana/baseline-s.prof Binary files differnew file mode 100644 index 00000000000..43ad67ee50b --- /dev/null +++ b/profileinstaller/profileinstaller/src/test/test-data/katana/baseline-s.prof diff --git a/profileinstaller/profileinstaller/src/test/test-data/katana/baseline-s.profm b/profileinstaller/profileinstaller/src/test/test-data/katana/baseline-s.profm Binary files differnew file mode 100644 index 00000000000..596d8bc90cc --- /dev/null +++ b/profileinstaller/profileinstaller/src/test/test-data/katana/baseline-s.profm |