Using the weekend's time, write a tool to detect the JIT friendliness of the Android code, taking a name of Droidjitchecker. Hope to help you quickly find a bad taste of the code, and timely correction.
noun explanation
- Jit:jit Full name Just-in-time compilation. Real-time compilation is an optimization technique in the JVM, which translates bytecode into machine code and improves execution efficiency by optimizing the frequently invoked and eligible methods.
- Method Size: The method body implementation of each method is measured in bytes as a unit, and in general, the larger the method body, the larger the method size.
- JIT-friendly: Usually the smaller the method, the simpler, the more JIT-compiled friendly.
What is it
- This is a tool to detect the JIT friendliness of Android (Directory organization structure) code
- The tool is assembled based on the jarscan.sh in Adoptopenjdk/jitwatch
- Output supports HTML for easy viewing in browsers
Prerequisite Preparation
- The detected Android project can support Gradle compilation success
- Install Jitwatch Kit
- Ruby Running Environment
Installation
Installing Jitwatch Components
Get code
git clone git@github.com:adoptopenjdk/jitwatch.git
Compile
Enter the repo directory above, using one of the following three methods can be
Ant
Ant Clean compile test run
Maven
MVN Clean Compile test Exec:java
Gradle
Gradlew Clean Build Run
Configuration
Get the code for this repo and open config.ini file modification
[Setup]
Jarscan = "/users/androidyue/github/jitwatch/jarscan.sh"
maxmethodsize = 325
OutputDir = "/tmp/ droidjitchecker/output_new/"
Modification Notes
- Jarscan must be modified to a jarscan path that has been installed
- Maxmethodsize do not need to change, such as change caution
- Output directory, OutputDir, recommended to be modified as a sustainable directory
How to use
Easy to use, open the terminal, execute the following statement
Ruby Jitchecker.rb Your_android_project Jartask
Note: Jartask is a task that compiles a project's Java file into a jar package that can be viewed by performing the./gradlew tasks, and then selecting a task that starts with a jar.
View Results
- When the check is finished, the results are automatically opened using the browser
- The resulting file path is also exported to the terminal
- The result file name contains the relevant Jartask information for easy lookup
- The resulting content, sorted by the byte size of the method, in descending order from large to small
A typical sample of content
Md4.mdfour64
Package:com.app.utils
parameters:int[]
bytesize:1129
- Md4.mdfour64 methods of JIT-unfriendly and their classes
- Package:com.app.utils the above MD4 belong to the package
- Parameters:int[] The parameters accepted by the Mdfour64 method
- BYTESIZE:1129 represents the size held by the Mdfour64 method
How to Solve
- A simple method of writing logic and a single responsibility
- A simple method of writing logic and a single responsibility
- A simple method of writing logic and a single responsibility
Contribution Code
Any helpful suggestions are welcome.
The following code contribution is more welcome
Landscaping Results Display page (HTML,CSS)
Problem
Q: A large number of bytes of the method must be modified, modify the JIT can be compiled?
A: A large number of bytes of the method proposed to modify, not mandatory, modified may not be JIT-compiled, because the JIT optimization does not mean that the JIT compiled the method, but also need other factors, such as the frequency of calls to the method. So this is a thing that you love me.
Why use Ruby
A: It's a struggle to have idea, because it's not sure what language to implement, especially between Python and Ruby, to ask a lot of students, and finally "just" decided to use Ruby, do not like the mandatory alignment of Python, super like Ruby string template. Ruby is simple and humane, and I'm sure you'll like it.
Source
Droidjitchecker@github
The above is on the Android JIT code friendliness testing tool data collation, thank you for your support of this site!