-
Notifications
You must be signed in to change notification settings - Fork 0
/
android-dalvik-vm-on-java.txt
108 lines (86 loc) · 3.13 KB
/
android-dalvik-vm-on-java.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
* https://code.google.com/archive/p/android-dalvik-vm-on-java/
android-dalvik-vm-on-java
Pure Java implementaion of Android's Dalvik virtual machine
This project's objective is to develop a pure Java implementation of the Android's Dalvik virtual machine.
To study the concept and architecture of Dalvik VM, Koji Hisano is developing this for J2ME CLDC environments as on-going research at "eflow Inc."
Currently supported functions
Dalvik Execution file format (.dex)
Complete Dalvik instruction set
J2ME CLDC API
Multi-thread (include synchronized block, wait and notify)
Unsupported functions
Android frameworks (as implemented on CLDC)
Verifier
Debugger
Some array types
Annotation (as implemented on CLDC)
Enum (as implemented on CLDC)
Documents
Change history of this project
Tutorial 1: How to run a program
---------------
android-dalvik-vm-on-java - ChangeHistory.wiki
March 16, 2009
Released 0.8(alpha version) as open source
February 19, 2009
Added float instructions
Added double instructions
Added switch instructions
Added all other instructions
Many refactoring
February 18, 2009
Supported user defined interface
Added long instructions
Added cast & instanceof instructions
Supported user defined class
Supported user defined inner class
Supported thread mechanism
February 17, 2009
Added branch instructions
Added array instructions
Supported class method & field
Supported instance method & field
Supported exception
February 16, 2009
Developed base code
Added int instructions
February 14, 2009
Studied the Dalvik VM specification
Started implementation
Succeeded to run a 'Hello, World' dex file
-------------
android-dalvik-vm-on-java - Tutorial1.wiki
Introduction
This tutorial describes how to run a simple program on this vm step by step.
Details
Compile the below code and package it as App.jar ``` package tutorial1;
public final class HelloWorld { public static void main(final String[] args) { System.out.println("Hello, World!"); } } ```
Convert App.jar to App.dex which is a Dalvik Executable file dx --dex --output=<absolute file path to tutorial1/App.dex> <absolute file path to tutorial1/App.jar>
Write a launcher code and run it ``` import java.io.*;
import jp.eflow.hisano.dalvikvm.VirtualMachine;
public final class RunHelloWorld { public static void main(final String[] args) { final File dexFile = new File("tutorial1", "App.dex"); final String absoluteMainClassName = "tutorial1.HelloWorld";
final VirtualMachine vm = new VirtualMachine();
vm.load(toBytes(dexFile));
vm.run(absoluteMainClassName, new String[0]);
}
private static byte[] toBytes(final File dexFile) {
final byte[] bytes = new byte[(int)dexFile.length()];
DataInputStream in = null;
try {
in = new DataInputStream(new BufferedInputStream(new FileInputStream(dexFile)));
in.readFully(bytes);
} catch (IOException e) {
System.err.println("The specified dex file path is invalid: " + dexFile.getName());
System.exit(-1);
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
}
}
}
return bytes;
}
} ```
----------------