• Stars
    star
    169
  • Rank 224,453 (Top 5 %)
  • Language
    Go
  • License
    MIT License
  • Created over 7 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

πŸš€ A sandboxed VM any Java developer can afford

Javo

NOTE: (previously named Jago)

A simplified Java virtual machine written in Go language. One aim is to learn JVM specification in depth and try to understand the behind-the-scene behaviour when a Java program runs. This VM can be used for the educational purpose, for example, for a course about how to design a runtime for a language with the complete specification.

I only refer to "Java Virtual Machine Specification" and then look into how we should design one. Some production-level features are intentionally ignored and it is supposed to make it as simplified as possible so as to demonstrate the general idea. For the educational purpose, it is more than enough.

If you have no time to read OpenJDK source code or always guess the JVM behaviour when you need to tune your program, then your right here to be the lord of your universe.

A overview presentation can be found: https://drive.google.com/file/d/1gESJTwm_tJL8pA7WBxJfhz4iUW7KwihP/view?usp=sharing

Any thought is welcome and I am happy to be wrong.

Roadmap

  • Java class file reader
  • Interpreter engine
  • Class loader delegation
  • multi-threading support
  • monitor, sleep, wait, notify support
  • JDK native methods
  • GC
  • JIT

How to run

build and install

❯ cd ~/javo
❯ ./build.sh

By default, javo will be installed to /usr/local/javo

/usr/local/javo
β”œβ”€β”€ bin
β”‚Β Β  └── javo
β”œβ”€β”€ jdk
β”‚Β Β  └── classes
β”‚Β Β      β”œβ”€β”€ META-INF
β”‚Β Β      β”œβ”€β”€ apple
β”‚Β Β      β”œβ”€β”€ com
β”‚Β Β      β”œβ”€β”€ java
β”‚Β Β      β”œβ”€β”€ javax
β”‚Β Β      β”œβ”€β”€ jdk
β”‚Β Β      β”œβ”€β”€ org
β”‚Β Β      └── sun
└── log
    β”œβ”€β”€ classloader.log
    β”œβ”€β”€ io.log
    β”œβ”€β”€ misc.log
    β”œβ”€β”€ thread-bootstrap.log
    β”œβ”€β”€ thread-main.log
    └── threads.log

javo command

❯ javo -h
NAME:
   Javo - A simplified Java Virtual Machine for the educational purpose

USAGE:
   javo [-options] class [args...]

VERSION:
   1.0.0

DESCRIPTION:
   A Java Virtual Machine demonstrating the basic features of execution engine, class loading, type/value system, exception handling, native methods etc.

AUTHOR:
   Chao Yang <[email protected]>

COMMANDS:
     help, h  Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --classpath value, --cp value  application classpath separated by colon
   --noLogo, --nl                 don't show logo
   --debug, -d                    debug mode
   --trace, -t                    trace mode
   --log:thread value             log level of instruction execution in a thread context, options: info, debug, trace
   --log:classloader value        log level of class loading, options: info, debug, trace
   --profile, -p                  profile javo
   --help, -h                     show help
   --version, -v                  print the version

Run a calendar program

❯ javo -nl -cp . Calendar 8 2018

Run a pyramid program

❯ javo -nl -cp . Pyramid

run a program traversing a tree in the level order

❯ javo -nl -cp . TreeLevelOrderTraverse

Run a program into exception

❯ javo -nl . test/test_athrow

More examples to demonstrate features

  • Print system properties
javo -d test.test_system_properties
  • Multi-threading
javo -d test.test_thread
javo -d Multithread
  • Thread sleep or wait / interrupt
javo -d SleepInterrupt
javo -d WaitInterrupt
  • Java monitor lock with synchronized
javo -d Counter
  • Java wait() and notify(), notifyAll()
javo -d ProducerConsumer

trace the execution

log/thread-[name].log

This log file records the each instruction execution and method call hierarchy within a thread context. Set the log level to info to view call hierarchy more clearly.

The blue diamond symbol πŸ”Ή means pure Java methods while the yellow one πŸ”Έ means native methods which is implemented within Javo internally.

The fire symbol πŸ”₯ means exception throwing (thrown by athrow bytecode, rethrown if uncaught or thrown by VM internally), while the blue water symbol πŸ’§ means an exception is caught by a method.

  • TRACE: log all low level bytecode instructions, method call and exception thrown/caught
  • DEBUG: only method call and exception thrown/caught
  • INFO: only exception thrown/caught info

log/classloader.log

This log file records the class loading process, including what triggers a class loading and when its class initialization method <clinit> is invoked. The trigger reason can be viewed after a class name.

log/threads.log

This log file records thread creation/exit information and object monitor enter/exit, thread sleep(), wait(), notify() etc.

log/io.log

This log file records I/O details around system interactions.

log/misc.log

Other trivial logs

Profiling

https://flaviocopes.com/golang-profiling/

  • install Graphviz
  • run javo with -p option
  • go tool pprof --pdf /usr/local/bin/javo /var/../cpu.pprof > cpu.pdf

Documentation

Really sorry, I have no time to write documentation but it is in my plan. The Ebook about how it works internally is in progress: https://www.gitbook.com/book/chaoyangnz/go-my-jvm

Testing

I am really keen to get missing tests done if I have time. Another reason I didn't enjoy writing tests in Go is that I cannot find an awesome unit test library like Jest. For some libraries I looked into, it requires me to change my code just for testing. I don't like the idea about breaking the encapsulation just for testing.

More Repositories

1

opencv3-android-sdk-with-contrib

Build OpenCV3 Android SDK with contrib modules
C++
102
star
2

simpledb

SimpleDB is developed by Edward Sciore. This repo is to enhance it and provide more features.
Java
15
star
3

maxine

Maxine VM - a meta-circular JVM originally created by Oracle. For learning only.
Java
6
star
4

zava

Mini Java VM in Zig
Zig
6
star
5

webworker-polyfill

Let web worker access `localStorage` etc
JavaScript
6
star
6

weiv

🀑 weiv.js - A pragmatic UI view library for modern component-oriented web development.
JavaScript
6
star
7

sqlite-3.11.1

This copy is a companion to read book "SQLite Database System Design and Implementation".
C
5
star
8

yapai

🌹Yet Another Promises/A+ Implementation
JavaScript
4
star
9

eudic-hack

JavaScript
4
star
10

node-http-interceptor

A low-level NodeJS http.request or https.request interceptor useful for debugging, logging, monitoring, instrumentations etc
TypeScript
3
star
11

node-library-template

A template repo to set up your NodeJS library project
TypeScript
3
star
12

rvz

xv6 port on RISC-V VisionFive2 / Nezha in Zig
Zig
3
star
13

openjdk9

2
star
14

BoomCast

πŸ’‚ A simple Podcast manager
Java
2
star
15

cookie-audit

Audit how/where/when a cookie is born (client-side cookies & HTTP cookies)
JavaScript
2
star
16

rsql-js

RSQL parser and builder for Javascript
TypeScript
1
star
17

types-extension

Typescript types extending the built-in types
TypeScript
1
star
18

breezedb

A simplified database implementation
Go
1
star
19

cosmos

πŸŽ„πŸŽ…A kernel for my delight of system programming
C
1
star
20

maven-fatjar-plugin

A maven plugin for archiving standalone JAR(run it directly on the fly)
Java
1
star
21

android-lirc

Android LIRC wrapper library for Infrared transmitters
C
1
star
22

Whatson

🎈 Find nearby events
Java
1
star
23

patchable

Ease the API Patch implementation in Spring Boot and Micronaut
Java
1
star
24

cookie-collector

JavaScript
1
star
25

rvx

xv6 on risc-v baremetal -> Nezha (Allwinner D1)
C
1
star
26

oskit

C
1
star
27

loadrush

Simple and flexible load testing tool by developers and for developers
TypeScript
1
star