A tiny JVM (Java Virtual Machine) program written in TypeScript.

Overview

jvm-on-typescript

A tiny JVM (Java Virtual Machine) program written in TypeScript.
This virtual machine specification compliants Java Virtual Machine Specification (Java 8 Edition).

Usage

Instant Run

  1. Open index.html on Browser.
  2. Select a *.class file.
  3. Open "Developer Tool" and open "Console" tab.

Run in code

const buffer: ArrayBuffer = new ArrayBuffer();  // Binary data of the class file;
const jvm = new JVM(buffer);
jvm.load();  // Load class file and invoke main method.

Functions

  • Some of primitive/reference types
    • int/long/float/double values, variables
      • addition/subtraction/multiply/division/shl/shr
      • String type
    • String
      • sum of String (by StringBuilder)
  • Print "Hello, World!"
    • System.out.println("Hello, World!");
  • Fizz Buzz problem
    • If statement
    • For statement

Implemented Opcodes

Mnemonic Opcode isImplemented
nop 0x00
aconst_null 0x01
iconst_m1 0x02
iconst_0 0x03
iconst_1 0x04
iconst_2 0x05
iconst_3 0x06
iconst_4 0x07
iconst_5 0x08
lconst_0 0x09
lconst_1 0x0a
fconst_0 0x0b
fconst_1 0x0c
fconst_2 0x0d
dconst_0 0x0e
dconst_1 0x0f
bipush 0x10
sipush 0x11
ldc 0x12
ldc_w 0x13
ldc2_w 0x14
iload 0x15
lload 0x16
fload 0x17
dload 0x18
aload 0x19
iload_0 0x1a
iload_1 0x1b
iload_2 0x1c
iload_3 0x1d
lload_0 0x1e
lload_1 0x1f
lload_2 0x20
lload_3 0x21
fload_0 0x22
fload_1 0x23
fload_2 0x24
fload_3 0x25
dload_0 0x26
dload_1 0x27
dload_2 0x28
dload_3 0x29
aload_0 0x2a
aload_1 0x2b
aload_2 0x2c
aload_3 0x2d
iaload 0x2e
laload 0x2f
faload 0x30
daload 0x31
aaload 0x32
baload 0x33
caload 0x34
saload 0x35
istore 0x36
lstore 0x37
fstore 0x38
dstore 0x39
astore 0x3a
istore_0 0x3b
istore_1 0x3c
istore_2 0x3d
istore_3 0x3e
lstore_0 0x3f
lstore_1 0x40
lstore_2 0x41
lstore_3 0x42
fstore_0 0x43
fstore_1 0x44
fstore_2 0x45
fstore_3 0x46
dstore_0 0x47
dstore_1 0x48
dstore_2 0x49
dstore_3 0x4a
astore_0 0x4b
astore_1 0x4c
astore_2 0x4d
astore_3 0x4e
iastore 0x4f
lastore 0x50
fastore 0x51
dastore 0x52
aastore 0x53
bastore 0x54
castore 0x55
sastore 0x56
pop 0x57
pop2 0x58
dup 0x59
dup_x1 0x5a
dup_x2 0x5b
dup2 0x5c
dup2_x1 0x5d
dup2_x2 0x5e
swap 0x5f
iadd 0x60
ladd 0x61
fadd 0x62
dadd 0x63
isub 0x64
lsub 0x65
fsub 0x66
dsub 0x67
imul 0x68
lmul 0x69
fmul 0x6a
dmul 0x6b
idiv 0x6c
ldiv 0x6d
fdiv 0x6e
ddiv 0x6f
irem 0x70
lrem 0x71
frem 0x72
drem 0x73
ineg 0x74
lneg 0x75
fneg 0x76
dneg 0x77
ishl 0x78
lshl 0x79
ishr 0x7a
lshr 0x7b
iushr 0x7c
lushr 0x7d
iand 0x7e
land 0x7f
ior 0x80
lor 0x81
ixor 0x82
lxor 0x83
iinc 0x84
i2l 0x85 -
i2f 0x86 -
i2d 0x87 -
l2i 0x88 -
l2f 0x89 -
l2d 0x8a -
f2i 0x8b -
f2l 0x8c -
f2d 0x8d -
d2i 0x8e -
d2l 0x8f -
d2f 0x90 -
i2b 0x91 -
i2c 0x92 -
i2s 0x93 -
lcmp 0x94
fcmpl 0x95
fcmpg 0x96
dcmpl 0x97
dcmpg 0x98
ifeq 0x99
ifne 0x9a
iflt 0x9b
ifge 0x9c
ifgt 0x9d
ifle 0x9e
if_icmpeq 0x9f
if_icmpne 0xa0
if_icmplt 0xa1
if_icmpge 0xa2
if_icmpgt 0xa3
if_icmple 0xa4
if_acmpeq 0xa5
if_acmpne 0xa6
goto 0xa7
jsr 0xa8
ret 0xa9
tableswitch 0xaa
lookupswitch 0xab
ireturn 0xac
lreturn 0xad
freturn 0xae
dreturn 0xaf
areturn 0xb0
return 0xb1
getstatic 0xb2
putstatic 0xb3
getfield 0xb4
putfield 0xb5
invokevirtual 0xb6
invokespecial 0xb7
invokestatic 0xb8
invokeinterface 0xb9
invokedynamic 0xba
new 0xbb
newarray 0xbc
anewarray 0xbd
arraylength 0xbe
athrow 0xbf
checkcast 0xc0
instanceof 0xc1
monitorenter 0xc2
monitorexit 0xc3
wide 0xc4
multianewarray 0xc5
ifnull 0xc6
ifnonnull 0xc7
goto_w 0xc8
jsr_w 0xc9
breakpoint 0xca

References

You might also like...

Very simple full-stack application using React, Java Spring Boot, and PostgreSQL

Very simple full-stack application using React, Java Spring Boot, and PostgreSQL. The API was built following the N-Tier architecture. The goal was to explore and learn more in-depth the development of APIs, the use of Docker and deploying with AWS.

Apr 23, 2022

Blockchain, Smart Contract, Ganache, Remix, Web3, Solidity, Java Script, MQTT, ESP32, RFID, DHT11,

Blockchain, Smart Contract, Ganache, Remix, Web3, Solidity, Java Script, MQTT, ESP32, RFID, DHT11,

May 24, 2022

Projeto desenvolvido em Angular e Material, para conclusão do curso de extensão em Java

EmpresaFront This project was generated with Angular CLI version 13.0.4. Development server Run ng serve for a dev server. Navigate to http://localhos

Mar 18, 2022

Nodejs,Expreess,Mongodb,Reactjs,Redux,Java app,Google,Docker,Heroku,...

Nodejs,Expreess,Mongodb,Reactjs,Redux,Java app,Google,Docker,Heroku,...

Tiến độ công việc Team: https://docs.google.com/spreadsheets/d/1BBv4CXNniNjqdIE7tjrG9UM4nprd3NSVy2FX9oaWq0Q/edit#gid=0 Web Online: https://movienetfli

Sep 17, 2022

🦾 Tiny 2kb Markdown parser written, almost as fast and smart as Tony Stark

Starkdown 🦾 Starkdown is a Tiny 2kb Markdown parser written, almost as fast and smart as Tony Stark. npm i starkdown Motivation It is a continuation

Sep 22, 2022

A Lua plugin, written in TypeScript, to write TypeScript (Lua optional).

typescript.nvim A minimal typescript-language-server integration plugin to set up the language server via nvim-lspconfig and add commands for convenie

Dec 29, 2022

Screeps Typescript Starter is a starting point for a Screeps AI written in Typescript.

Screeps Typescript Starter Screeps Typescript Starter is a starting point for a Screeps AI written in Typescript. It provides everything you need to s

Jan 27, 2022

🐬 A simplified implementation of TypeScript's type system written in TypeScript's type system

🐬 A simplified implementation of TypeScript's type system written in TypeScript's type system

🐬 HypeScript Introduction This is a simplified implementation of TypeScript's type system that's written in TypeScript's type annotations. This means

Dec 20, 2022
Comments
  • Please add license

    Please add license

    Hi. I have a petproject intended to make old j2me games available in browser. I decompiled and rewrited in kotlin some games, but now I want to try to create the runtime on typescript that will support all the games without rewriting by hand. Some parts of your vm will be useful. Btw maybe you will be interested in the project? I'm also a third year student. Do you have any social networks, maybe telegram? I can show more of my experiments https://user-images.githubusercontent.com/25568730/201519844-f2902ae6-ced0-4425-bc6c-5a740a726bca.mp4

    opened by asimaranov 1
Owner
Itsu
ITF.21 scs2
Itsu
basic dissembler for Kasada's virtual machine obfuscation

Kasada Dissembler A simple kasada dissembler which is capable of tracing through and executing every single opcode in kasada's bytecode and then loggi

Felix Zhao 14 Jul 8, 2022
Shizuku Launcher is a simple AWS Virtual Machine helper.

shizuku-launcher-web Shizuku Launcher is a simple AWS Virtual Machine helper. Shizuku Launcher offers multiple solutions to keep your credential secur

Seraphim Lou 16 Oct 11, 2022
Shizuku Launcher is a simple AWS Virtual Machine helper. Now in Next.js

Shizuku Launcher Shizuku Launcher is a simple AWS Virtual Machine helper. Shizuku Launcher offers multiple solutions to keep your credential security

Seraphim Lou 50 Jan 3, 2023
High-order Virtual Machine (HVM) wrapper on JavaScript, via WASM

HVM on JavaScript HVM is now available as a JavaScript library! Installing npm i --save hvm-js Examples Evaluating a term to normal form import hvm fr

null 14 Nov 24, 2022
Full dynamic tool kit that is capable of deobfuscating and producing a javascript representation of Shape's Virtual Machine obfuscation

Shape Security Decompiler Tool-Kit This tool kit is capable of dynamically deobfuscating all versions of shape security's virtual machine interpreter

null 25 Dec 15, 2022
Solana blockchain candy machine app boilerplate on top of Metaplex Candy Machine. NextJS, Tailwind, Anchor, SolanaLabs.React, dev/mainnet automation scripts.

NFT Candy Factory NOTE: This repo will prob only work on unix-based environments. The NFT Candy Factory project is designed to let users fork, customi

Kevin Faveri 261 Dec 30, 2022
Quick One Liners in JavaScript, TypeScript, Python, Rust, Java, Ruby, C, C++

ONE LINERS This repository contains cool and simple one line utility functions to easily use common repetitive methods in JavaScript, TypeScript, Pyth

Divin Irakiza 3 Mar 2, 2022
High-quality QR Code generator library in Java, TypeScript/JavaScript, Python, Rust, C++, C.

QR Code generator library Introduction This project aims to be the best, clearest QR Code generator library in multiple languages. The primary goals a

Nayuki 3.3k Jan 4, 2023
A javascript written program that can be used to automatically join BloxFlip Rains.

Toxic Rainer Auto-BloxFlip Rain Joiner Toxic Rainer is a web-socket based background running program used to automatically join BloxFlip Rains to get

null 4 Jul 10, 2022
A Virtual Interactive Keyboard which replicates every key you press and a Text-Area in which everything is written and can be copied to the clipboard with a click of a button.

A Virtual Interactive Keyboard which replicates every key you press and a Text-Area in which everything is written and can be copied to the clipboard with a click of a button.

Devang Joshi 1 Mar 1, 2021