Upgrade to Pro — share decks privately, control downloads, hide ads and more …

[Aleksander Piotrowski] Android tool-chain and run-time improvements in N

[Aleksander Piotrowski] Android tool-chain and run-time improvements in N

Presentation from GDG DevFest Ukraine 2016.
Learn more at: https://devfest.gdg.org.ua

Google Developers Group Lviv

September 10, 2016
Tweet

More Decks by Google Developers Group Lviv

Other Decks in Technology

Transcript

  1. #dfua Other Java 8 lang features • Method references •

    Streams API (minSdkVersion 24) • Repeatable annotations https://www.youtube.com/watch?v=zfLKMun94Yc
  2. #dfua Jack & Jill • Open-sourced ◦ IfWithConstantSimplifier.java ◦ ub-jack

    branch • Designed for speed • Well integrated ◦ Shrinking ◦ Obfuscation ◦ Repackaging ◦ Multi-dex
  3. #dfua How to configure apply plugin: 'com.android.application' android { compileSdkVersion

    24 buildToolsVersion "24.0.2" defaultConfig { applicationId "pl.pelotasplus.demojava8" minSdkVersion 21 targetSdkVersion 24 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" jackOptions { enabled true } } }
  4. #dfua .java .java .java .class .class .class .class .class .class

    .dex .dex .dex .dex javac proguard dx obfuscated optimized .dex .dex .dex multidex our app
  5. #dfua .java .class .class .class .class .class .class javac proguard

    dx obfuscated optimized .dex .dex .dex multidex .class .class library our app
  6. #dfua .java jack obfuscated optimized dex dex dex multidex .class

    .class library our app .jayce .jayce jill
  7. #dfua .class .class library .jayce .jayce jill obfuscated optimized jack

    .jayce pre .dex resources .jack jack .java jack dex dex dex multidex our app obfuscated optimized
  8. #dfua .java jack obfuscated optimized dex dex dex multidex .class

    .class library our app .jayce .jayce jill .swift .kt
  9. #dfua AMA on reddit We’re on the Android engineering team

    and built Android Nougat. Ask us Anything! https://www.reddit.com/r/androiddev/comments/4tm8i6/were_on_the_andr oid_engineering_team_and_built/?sort=qa
  10. #dfua AMA: New language We don’t have any plans to

    officially support a new language in Android, so we’d encourage folks to continue to use Java:) That said, you should continue to use what works for you. Anwar Ghuloum Engineering Director for Android Core Platform
  11. #dfua AMA: Swift Q: Can you say anything about the

    rumours concerning official Swift-support for Android apps? A: Nope, not happening. Anwar Ghuloum Engineering Director for Android Core Platform
  12. #dfua AMA: Kotlin Kotlin is interesting: works well with Java,

    more concise. JetBrains has done a nice job supporting this on android. But no plans to officially support anything new. Anwar Ghuloum Engineering Director for Android Core Platform
  13. #dfua AMA: Kotlin I don’t think we have any plans

    to break what already works there, but we don’t have plans to have a second, idiomatic-Kotlin version of the whole framework API surface area either. That would be a big duplication of effort when Kotlin already interacts with the existing framework setup well. Adam Powell TLM on UI toolkit/framework
  14. #dfua OS Dalvik / ART Android Framework Application Facebook gmail

    slack JobSchedulerService WindowManagerService
  15. #dfua Stack based VM 29 add 1. iload 10 2.

    iload 5 3. iadd 10, 5, result 4. istore result SP 10 20 5 100 20 15 100 SP
  16. #dfua Register based VM 30 add 10 20 5 100

    1. add-int v0, v1, v2 v0 v2 v1 v3 15 5 100 10 v0 v2 v1 v2
  17. #dfua public class SimpleCls { public void execute(Runnable runnable) {

    runnable.run(); } public static void main() { SimpleCls clazz = new SimpleCls(); clazz.execute(new Runnable() { @Override public void run() { // nothing } }); } public static void main2() { SimpleCls clazz = new SimpleCls(); clazz.execute(() -> { // nothing }); } } interface Runnable { void run(); }
  18. #dfua Java 8 + anonymous class 0: new #3 //

    class pl/java8/SimpleCls 3: dup 4: invokespecial #4 // Method "<init>":()V 7: astore_0 8: aload_0 9: new #5 // class pl/java8/SimpleCls$1 12: dup 13: invokespecial #6 // Method pl/java8/SimpleCls$1."<init>":()V 16: invokevirtual #7 // Method execute:(Ljava/lang/Runnable;)V 19: return new Runnable() { @Override public void run() { // nothing } }
  19. #dfua Java 8 + lambda 0: new #3 // class

    pl/java8/SimpleCls 3: dup 4: invokespecial #4 // Method "<init>":()V 7: astore_0 8: aload_0 9: invokedynamic #8, 0 // InvokeDynamic #0:run:()Ljava/lang/Runnable; 14: invokevirtual #7 // Method execute:(Ljava/lang/Runnable;)V 17: return
  20. #dfua Jack + anonymous class 0000: new-instance v0, Lpl/java8/SimpleCls; 0002:

    invoke-direct {v0}, Lpl/java8/SimpleCls;.<init>:()V 0005: new-instance v1, Lpl/java8/SimpleCls$1; 0007: invoke-direct {v1}, Lpl/java8/SimpleCls$1;.<init>:()V 000a: invoke-virtual {v0, v1}, Lpl/java8/SimpleCls;.execute:(Ljava/lang/Runnable;)V 000d: return-void
  21. #dfua Jack + lambda 0000: new-instance v0, Lpl/java8/SimpleCls; 0002: invoke-direct

    {v0}, Lpl/java8/SimpleCls;.<init>:()V 0005: new-instance v1, Lpl/java8/SimpleCls$-void___main2__LambdaImpl0; 0007: invoke-direct {v1}, Lpl/java8/SimpleCls$-void___main2__LambdaImpl0;.<init>:()V 000a: invoke-virtual {v0, v1}, Lpl/java8/SimpleCls;.execute:(Ljava/lang/Runnable;)V 000d: return-void
  22. #dfua public class SimpleCls { public void execute(Runnable runnable) {

    runnable.run(); } public static void main() { SimpleCls clazz = new SimpleCls(); clazz.execute(new Runnable() { @Override public void run() { // nothing } }); } public static void main2() { SimpleCls clazz = new SimpleCls(); clazz.execute(() -> { // nothing }); } } Java 8 Jack anonymous class anonymous class anonymous class invokedynamic
  23. #dfua Evolution of Android VM • Interpretation + JIT compilation

    at runtime • Low memory footprint • Poor performance • Unsophisticated GC • Long two pauses and janky app experience • Ahead-of-time compilation at install-time • Plenty of optimizations • Much better performance • Better GC algorithms • Just one short pause Dalvik ART
  24. #dfua Android N • Still ART ◦ No new name

    • Back to JIT ◦ No need to compile whole app at install-time ◦ No need to recompile when system changes • Hybrid JIT/AOT ◦ Apps start with JIT ◦ Will be profile-guided compiled later on when phone is idle
  25. #dfua app interpret/jit profiles profile-guided compilation a bit compiled app

    thread dumping data to files system service in idle mode running on ART