Self-made JVM-implements JVM with Go language

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

Although written for many years of Java code, but basically only the JVM when blackbox processing. The book on the JVM has also seen several books, but the results are poor. See OPENJDK code? Not interested. I've had a few weeks of free time, so I decided to write a JVM in the Go language and conquer the JVM monster!

Why Choose Go

First don't want to write in Dynamic language . The JVM was designed to be closer to the machine, eliminating JavaScript, Python, Ruby and other languages. Next also do not want to write in Java , the reason is basically ibid. Another reason is that you are too familiar with Java, use it to write, not challenging. I don't want to use C + +again, because I don't like the two languages. C is too low, C + + is too complex. So I ended up choosing go.

Go is a Google release language, compiled, close to the bottom, to some extent, can serve as a system language to use. Go's syntax is concise, the learning curve is smooth, the document is more detailed. And go cross-platform, there is garbage collection mechanism, security, anyway go language between C and Java, is a good choice. Of course, go also has a lot of shortcomings, the biggest problem is Go's official website in the domestic inaccessible, resulting in a variety of inconvenience. Fortunately, there are many go language-related sites in the country, from which you can download the Go installation program or visit Godoc. In addition, the go language itself has some flaws, such as strange error handling, not supporting the model, and so on.

Basic ideas

As we all know, to run a Java program, you actually need the JRE. The complete JRE consists of two parts: theJVM and the class libraries. It takes a lot more work to implement a complete class library than the JVM. Fortunately for Oracle's published JDK, most of the code for the class library is open source and can be seen by anyone. After this part of the Java code is compiled, it is Rt.jar. So the basic idea is to implement the JVM with go, and then the JVM must be able to use Rt.jar as a class library. The actual work can be divided into two parts, the first part is to implement the JVM itself with go, the second part is to implement the corresponding class native method in Rt.jar. The details are not too much to describe.

The current progress

After three weeks of effort, the JVM is now basically molded. It took about a week or so, and theHelloWorld program could run, but with some hack. The second week continues to refine the JVM to implement the necessary native methods. Most of the work of the third week is the native approach to achieving rt.jar. But for the time being, the JVM is still incomplete, and there are many areas that need to be perfected, such as threads, files, reflections, and so on. The next step is to refine these areas, implement more native methods, fix bugs, and do some optimizations, with the goal of implementing a complete JVM.

Project Address

If you are interested in this project, you can visit its GitHub homepage: Https://github.com/zxh0/jvm.go. If you want to encourage me, give it a star:)

Compiling and running

This project was developed primarily on Mac OS X 10.7.5 , and the Go language version is go1.4, Rt.jar is copied from Java 1.8.0_11-b12 . No tests have been done under windows for the time being.

Compile:

    • Installing go1.4
    • Cloning Jvm.go
    • Export gopath=path/to/jvm.go/
    • Go Install Jvmgo

After the install command is executed properly, the executable file will appear in the path/to/jvm.go/bin/directory Jvmgo

Run Jvmgo:

    • CD to path/to/jvm.go/bin/directory
    • JVMGO-CP path/to/rt.jar:path/to/classes HelloWorld


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.