The title says it all pretty much. Can currently run a minecraft 1.8 server, as well as a variety of other Java programs. There are some major caveats and this is very much a one-person work in progress, so things may break at random.
Use docker to run the VM:
docker build -t rust_jvm_test .
docker run rust_jvm_test --main SecureRandomDemo --java-home /jdk8u252-b09/jre/ --classpath resources/test /jdk8u252-b09/jre/lib/ /jdk8u252-b09/jre/lib/ext/
See resources/test for more Demo classes. You only need to change "--main SecureRandomDemo" to run them. The above command uses standard library files from a real JDK. See below for more information.
To run useful programs a copy of rt.jar
is required. This jar contains essential class definitions such as the
definition of java.lang.Object
, and similar classes. If you want to run something which depends on SecureRandom
and
other Java features you will need additional jar files typically located in jre/lib/ext
of a JDK8 distribution.
This VM additionaly depends on libjava.so
and libnio.so
, as well as libraries depended on by those shared
libraries(except for libjvm.so
, which is provided by the libjvm crate). These libraries provide native
implementations of standard library methods, since if you want to interact with the outside world in java you eventually
need to use native code. You can find the aforementioned shared libraries in pretty much any jdk8 distribution, and
passing a --java-home
to the java binary generated by running cargo build
in the top level directory will allow you
to use rt.jar
/the java standard library/shared library dependencies from that distribution.
Alternatively cargo xtask
can compile the java standard library and shared library dependencies. See cargo xtask help
for more information.
This project uses rust nightly and as of now (9c9c1ad14f1a0314e134c9c1a31c7d8a75e399af
) compiles
with rustc 1.75.0-nightly (df871fbf0 2023-10-24)
. To compile you will also need external header files
specifically, jni.h
, jvmti.h
, and jvm.h
. These can also be found in a JDK8 distribution near you, except jvm.h
which needs to be obtained from the OpenJDK source. Paths to these headers need to be defined in the environment variables
JMM_H, JVM_H, JVM_MD_H, JNI_MD_H, JNI_H respectively, alternatively use cargo xtask clean
followed by cargo xtask deps
.
- Initialize a VM(with properties and the
System.in
/System.out
streams correctly initializedSystem.initProperties
) - Run a minecraft 1.8 server
- Verify Bytecode
- Basic first stage JIT, as well as interpreted mode.
- Most standard library IO including NIO
- Most reflection and introspection
- Class Loading w/ custom class loaders
- Float/Double Arithmetic
- Monitor operations
- Configure JVM properties
- String Internment
- Secure Random
- Pass arguments to the Java program in question
- JNI Interface
- JVMTI Interface
- Execute
invokedynamic
instructions - sun.misc.Unsafe implementation
- Access Control with
AccessController.doPrivileged
- Threads
- Run Swing applications
- JIT
- Garbage Collection with finalizers(there's a lot of infrastructure for this already, but still needs work)
- Expose openjdk compatible command line arguments
- ThreadGroups(except the main thread group)
- Support for anything other than x86_64 glibc linux