termux / termux-tools

Scripts and small programs that are packaged into termux's termux-tools package
GNU General Public License v3.0
306 stars 71 forks source link

[Bug]: dalvikvm script needs to be updated for Android 11 #16

Closed hanyman7 closed 1 year ago

hanyman7 commented 2 years ago

Problem description

The default time to run a .dex Java/.class file when invoking the dallvikvm script takes close to 4 seconds

I made a run on my own version of javap and here are the results [/data/data/com.termux/files/home] 127 -> time dalvikvm props.javap htel.Ssi Compiled from: htel.Ssi public class htel.Ssi extends java.lang.Object { java.io.BufferedInputStream bi; java.io.BufferedOutputStream bo; java.io.BufferedReader br; java.io.InputStream i; java.lang.String inputname; java.lang.String name; htel.Ssi next; public java.io.OutputStream o; java.io.PrintWriter pw; boolean t; static java.lang.String lock; public htel.Ssi(java.io.InputStream); public htel.Ssi(java.io.OutputStream); public static void msg(java.lang.String); private int read(byte[], int, boolean) throws java.io.IOException; public void add(htel.Ssi); public void close() throws java.io.IOException; public void dump(byte[], int, int); public void flush(); public java.lang.String name(); public void name(java.lang.String); public void println(java.lang.String); public int read(byte[]) throws java.io.IOException; public int read(byte[], int) throws java.io.IOException; public java.lang.String readLine() throws java.io.IOException; public void readN(byte[]) throws java.io.IOException; public void trace(boolean); public boolean trace(); public void write(byte[]) throws java.io.IOException; public void write(byte[], int, int) throws java.io.IOException; }

real 0m3.807s user 0m8.591s sys 0m0.598s

So I modified dalvikvm script to add -Xnoimage-dex2oat And the performance is back to real 0m0.603s user 0m0.457s sys 0m0.140s

The default on the binary /system/bin/dallvikvm on Android 11 has changed to generate an OAT file on every invocation which is not needed when simply running a .dex/.class file.

I compared older versions of /system/bin/dallvikvm and found out that the -Xnoimage-dex2oat was in fact the default. However on some Android 11 it is not

Steps to reproduce the behavior.

Write any Hello hello world in Java Use ecj to get .class file Use dx to make a .dex file Add dex file to CLASSPATH use dalvikvm mypackage.Hello

What is the expected behavior?

Subsecond response time instead of 3.8 seconds

System information

Grimler91 commented 1 year ago

Thanks, added in https://github.com/termux/termux-tools/commit/5dbde2e4556d1291daca911bdb75f6591365758a