Skip to content

itsu-dev/ChuruVM

Repository files navigation

jvm-on-typescript

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

This project is for research purpose, and we are aiming at understanding the structure of JVM and proposing a new way to develop web frontends. For these reason, we will not accept any PRs targeting codes in this repository. As a result of this project, this VM will support all features of JVM defined at the specification.

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

About

A JVM focusing on web development (DOM managing in Java) written in TypeScript

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors