All Projects โ†’ chaoyangnz โ†’ Javo

chaoyangnz / Javo

Licence: mit
๐Ÿš€ A sandboxed VM any Java developer can afford

Programming Languages

java
68154 projects - #9 most used programming language
go
31211 projects - #10 most used programming language
golang
3204 projects
bytecode
52 projects

Projects that are alternatives of or similar to Javo

snap
An embeddable scripting language inspired by Lua and JavaScript.
Stars: โœญ 32 (-77.78%)
Mutual labels:  vm, interpreter
SandboxJS
Safe eval runtime
Stars: โœญ 18 (-87.5%)
Mutual labels:  vm, interpreter
go-jdk
Run JVM-based code in Go efficiently
Stars: โœญ 61 (-57.64%)
Mutual labels:  vm, interpreter
AlchemyVM
WebAssembly Virtual Machine Built In Elixir
Stars: โœญ 184 (+27.78%)
Mutual labels:  vm, interpreter
Vm.js
Javascript ่งฃ้‡Šๅ™จ. Javascript Interpreter
Stars: โœญ 343 (+138.19%)
Mutual labels:  interpreter, vm
RSqueak
A Squeak/Smalltalk VM written in RPython.
Stars: โœญ 78 (-45.83%)
Mutual labels:  vm, interpreter
interp
Interpreter experiment. Testing dispatch methods: Switching, Direct/Indirect Threaded Code, Tail-Calls and Inlining
Stars: โœญ 32 (-77.78%)
Mutual labels:  vm, interpreter
clox
A virtual machine and a tree-walk interpreter for the Lox programming language in C89 ๐ŸŒ€
Stars: โœญ 38 (-73.61%)
Mutual labels:  vm, interpreter
Passerine
A small extensible programming language designed for concise expression with little code.
Stars: โœญ 341 (+136.81%)
Mutual labels:  interpreter, vm
Eval5
A JavaScript interpreter written in TypeScript - Support ES5
Stars: โœญ 281 (+95.14%)
Mutual labels:  interpreter, vm
quickjs-build
Build for QuickJS JavaScript Engine
Stars: โœญ 25 (-82.64%)
Mutual labels:  vm, interpreter
Zetavm
Multi-Language Platform for Dynamic Programming Languages
Stars: โœญ 592 (+311.11%)
Mutual labels:  interpreter, vm
pocketlang
A lightweight, fast embeddable scripting language.
Stars: โœญ 1,412 (+880.56%)
Mutual labels:  vm, interpreter
Animach
Scheme่ฏญ่จ€ๅฎž็Žฐๅ’Œ่ฟ่กŒๆ—ถ็Žฏๅขƒ / A Scheme runtime & implementation
Stars: โœญ 45 (-68.75%)
Mutual labels:  vm, interpreter
Tagha
Minimal, low-level, fast, and self-contained register-based bytecode virtual machine/runtime environment.
Stars: โœญ 101 (-29.86%)
Mutual labels:  vm, interpreter
retro12
This repo is retired. See http://forthworks.com:8000/
Stars: โœญ 18 (-87.5%)
Mutual labels:  vm, interpreter
Janet
A dynamic language and bytecode vm
Stars: โœญ 2,216 (+1438.89%)
Mutual labels:  interpreter, vm
Alchemyvm
WebAssembly Virtual Machine Built In Elixir
Stars: โœญ 176 (+22.22%)
Mutual labels:  interpreter, vm
RISVM
A low overhead, embeddable bytecode virtual machine in C++
Stars: โœญ 21 (-85.42%)
Mutual labels:  vm, interpreter
Q3vm
Q3VM - Single file (vm.c) bytecode virtual machine/interpreter for C-language input
Stars: โœญ 585 (+306.25%)
Mutual labels:  interpreter, vm

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

  • [x] Java class file reader
  • [x] Interpreter engine
  • [x] Class loader delegation
  • [x] multi-threading support
  • [x] monitor, sleep, wait, notify support
  • [x] 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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].