+ All Categories
Home > Software > Eric Lafortune - The Jack and Jill build system

Eric Lafortune - The Jack and Jill build system

Date post: 20-Jan-2017
Category:
Upload: guardsquare
View: 1,006 times
Download: 0 times
Share this document with a friend
23
The Jack and Jill build system Eric Lafortune Developer of ProGuard and DexGuard CTO at GuardSquare www.guardsquare.com
Transcript
Page 1: Eric Lafortune - The Jack and Jill build system

The Jack and Jillbuild system

Eric LafortuneDeveloper of ProGuard and DexGuard

CTO at GuardSquarewww.guardsquare.com

Page 2: Eric Lafortune - The Jack and Jill build system

The Jack and Jill build system

Inside the build system

Practical implications and results

Page 3: Eric Lafortune - The Jack and Jill build system

Jack and Jill

Java Android Compiler Kit

Jack Intermediate Library Linker

Page 4: Eric Lafortune - The Jack and Jill build system

Jack and Jill

● Now default in build process of AOSP

● Optional in Gradle build process:

android { defaultConfig { useJack true ... } ...}

android { defaultConfig { useJack true ... } ...}

Page 5: Eric Lafortune - The Jack and Jill build system

Why?

Technical

Legal ?

Strategical ?

Page 6: Eric Lafortune - The Jack and Jill build system

Android build process

Java bytecode(.class)

Libraries(.class)

Dx

JavacSource code

(.java)

Libraries(.class)

XML resources(.xml)

Assets Assets

CompiledXML resources

(.xml)Aapt

Dalvik bytecode(classes.dex)

Runtime(.class)

Page 7: Eric Lafortune - The Jack and Jill build system

ProGuard

Java bytecode(.class)

ProGuard

Libraries(.class)

OptimizedJava bytecode

(.class)Dx

Javac

Assets

CompiledXML resources

(.xml)Aapt

Dalvik bytecode(classes.dex)

ProGuardconfig(.txt)

ProGuardmapping

(.txt)

Source code(.java)

Libraries(.class)

XML resources(.xml)

Assets

Runtime(.class)

Page 8: Eric Lafortune - The Jack and Jill build system

ProGuard

Java bytecode(.class)

ProGuard

Libraries(.class)

OptimizedJava bytecode

(.class)Dx

Javac

Assets

CompiledXML resources

(.xml)Aapt

Dalvik bytecode(classes.dex)

ProGuardconfig(.txt)

ProGuardmapping

(.txt)

Source code(.java)

Libraries(.class)

XML resources(.xml)

Assets

Runtime(.class)

Page 9: Eric Lafortune - The Jack and Jill build system

Jack and Jill

Libraries(.jayce)

Jack

Assets

CompiledXML resources

(.xml)Aapt

Dalvik bytecode(classes.dex)

ProGuardconfig(.txt)

ProGuardmapping

(.txt)

Source code(.java)

Libraries(.class)

XML resources(.xml)

Assets

Runtime(.class)

Jill

Jill Runtime(.jayce)

Page 10: Eric Lafortune - The Jack and Jill build system

Code representations

for (int i = 0; i < 8; i++) ...for (int i = 0; i < 8; i++) ...

iconst 0istore v0iload v0bipush 8ificmpge +12...iinc v0, 1goto -12

iconst 0istore v0iload v0bipush 8ificmpge +12...iinc v0, 1goto -12

const/4 v0, #0const/16 v1, #8if-ge v0, v1, 8 ...add-int/lit8 v0, v0, #1goto -9

const/4 v0, #0const/16 v1, #8if-ge v0, v1, 8 ...add-int/lit8 v0, v0, #1goto -9

.class .dex

.java

Page 11: Eric Lafortune - The Jack and Jill build system

Code representations

for (int i = 0; i < 8; i++) ...for (int i = 0; i < 8; i++) ...

iconst 0istore v0iload v0bipush 8ificmpge +12...iinc v0, 1goto -12

iconst 0istore v0iload v0bipush 8ificmpge +12...iinc v0, 1goto -12

const/4 v0, #0const/16 v1, #8if-ge v0, v1, 8 ...add-int/lit8 v0, v0, #1goto -9

const/4 v0, #0const/16 v1, #8if-ge v0, v1, 8 ...add-int/lit8 v0, v0, #1goto -9

.class .dex

.java

Efficient to store and executeInconvenient to process

Page 12: Eric Lafortune - The Jack and Jill build system

Code representations

for (int i = 0; i < 8; i++) ...for (int i = 0; i < 8; i++) ...

iconst 0istore v0iload v0bipush 8ificmpge +12...iinc v0, 1goto -12

iconst 0istore v0iload v0bipush 8ificmpge +12...iinc v0, 1goto -12

const/4 v0, #0const/16 v1, #8if-ge v0, v1, 8 ...add-int/lit8 v0, v0, #1goto -9

const/4 v0, #0const/16 v1, #8if-ge v0, v1, 8 ...add-int/lit8 v0, v0, #1goto -9

LOCAL int n

FOR_STATEMENT:- EXPRESSION_STATEMENT: - ASG_OPERATION: - LOCAL_REF i - INT_LITERAL 1- LT_OPERATION: - LOCAL_REF i - INT_LITERAL 8- POSTFIX_INC_OPERATION: - LOCAL_REF i- ...

LOCAL int n

FOR_STATEMENT:- EXPRESSION_STATEMENT: - ASG_OPERATION: - LOCAL_REF i - INT_LITERAL 1- LT_OPERATION: - LOCAL_REF i - INT_LITERAL 8- POSTFIX_INC_OPERATION: - LOCAL_REF i- ...

.jayce.class .dex

.java

Page 13: Eric Lafortune - The Jack and Jill build system

Implications of Jack and Jill

● Java annotation processors – supported in JackE.g. Dagger, Butterknife

● Bytecode processors – only supported via JillE.g. JaCoCo, Retrolambda

● Other JVM languages – only supported via JillE.g. Scala, Groovy, Dart

Page 14: Eric Lafortune - The Jack and Jill build system

Implications of Jack and Jill

Libraries(.jayce)

Jack

Assets

CompiledXML resources

(.xml)Aapt

Dalvik bytecode(classes.dex)

Javac annotation processorsE.g. Dagger, Butterknife

Source code(.scala,...)

Libraries(.class)

XML resources(.xml)

Assets

Runtime(.class)

Jill

Jill Runtime(.jayce)

Bytecode processors

Java bytecode(.class)Scalac

Application(.jayce)Jill

Page 15: Eric Lafortune - The Jack and Jill build system

Internals

Jack: Java frontendEclipse ecj library

Jill: Java frontendASM4 library

Page 16: Eric Lafortune - The Jack and Jill build system

Build performance 56s – Javac + dx (clean build)

32s – Javac + ProGuard + dx (clean build)

53s – Javac + ProGuard optimize + dx (clean build)

29s – Javac + DexGuard + dx (clean build)

2m50s – Javac + DexGuard optimize + dx (clean build)

1m48s – Jack (clean build)

20s – Jack (clear all dex files)

11s – Javac + dx (clear all class files) 11s – Javac + dx (clear all class files)

9s – Javac + dx (clear one class file) 9s – Javac + dx (clear one class file)

8s – Javac + dx (code unchanged) 8s – Javac + dx (code unchanged)

9s – Jack (clear one dex file) 9s – Jack (clear one dex file)

9s – Jack (code unchanged) 9s – Jack (code unchanged)

Google I/O app

(AMD A10-7800, Ubuntu 14.04, Java 8, Android Gradle 1.2.3 / 1.3.1)

11s – Jack minify (clear all dex files) 11s – Jack minify (clear all dex files)

Page 17: Eric Lafortune - The Jack and Jill build system

Application runtime performance

50,000 – Javac + dx

63,800 – Javac + ProGuard optimize + dx

82,300 – Javac + DexGuard optimize

54,500 – Jack

Caffeinemark benchmark

(Nexus 5, Android 6.0, ART)

+9%

+28%

+65%

(higher is better)

Page 18: Eric Lafortune - The Jack and Jill build system

Application size

3.1M – Javac + dx

1.9M – Javac + ProGuard optimize + dx

1.8M – Javac + DexGuard optimize

1.9M – Jack + minify

Google I/O app

-39%

-38%

-44%

(smaller is better)

Page 19: Eric Lafortune - The Jack and Jill build system

DexGuard

Java bytecode(.class)

DexGuard

Libraries(.class)

Javac

Assets

OptimizedXML resources

(.xml)Aapt

OptimizedDalvik bytecode(classes.dex)

ProGuardconfig(.txt)

ProGuardmapping

(.txt)

Source code(.java)

Libraries(.class)

XML resources(.xml)

Assets

Runtime(.class)

CompiledXML resources

(.xml)

Page 20: Eric Lafortune - The Jack and Jill build system

Support for Java 8 – closures

● Under development in branch 'ub-jack-lang-dev'

● Test cases

● Compiled to anonymous classes

Interface lambda = i -> i + 1;Interface lambda = i -> i + 1;

$ java -jar jack.jar --help-properties...jack.java.source.version: Java source version (default is '1.8') {1.3,1.4,1.5,5.0,5,1.6,6.0,6,1.7,7.0,7,1.8,8.0,8}...

$ java -jar jack.jar --help-properties...jack.java.source.version: Java source version (default is '1.8') {1.3,1.4,1.5,5.0,5,1.6,6.0,6,1.7,7.0,7,1.8,8.0,8}...

Interface lambda = new Interface() { public int m(int i) { return i + 1; }}

Interface lambda = new Interface() { public int m(int i) { return i + 1; }}

Page 21: Eric Lafortune - The Jack and Jill build system

Conclusions

More efficient builds

Jack and Jill:● Java 8● Clean implementation● Room for growth

Page 22: Eric Lafortune - The Jack and Jill build system

Further reading

● “Experimental New Android Tool Chain - Jack and Jill”http://tools.android.com/tech-docs/jackandjill

● “Jack (Java Android Compiler Kit)”https://source.android.com/source/jack.html

● AOSP repositoryhttps://android.googlesource.com/toolchain/jack/

● “Hello World, meet our new experimental toolchain, Jack and Jill”, Paul Rashidihttp://android-developers.blogspot.be/2014/12/hello-world-meet-our-new-experimental.html

● “The upcoming Jack & Jill compilers in Android”, Eric Lafortunehttps://www.guardsquare.com/blog/201412

● “AO(sp)y Episode 2 - Lambdas”, Curious Techizen, Kiran Raohttp://kiranrao.in/blog/2015/09/06/ao-spy-2/

Page 23: Eric Lafortune - The Jack and Jill build system

Questions?

Size

Java bytecode

Performance

Jayce bytecode

Dalvik bytecode

Jack & Jill

ProGuard

DexGuard


Recommended