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.
- Open index.html on Browser.
- Select a *.class file.
- Open "Developer Tool" and open "Console" tab.
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.- 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)
- int/long/float/double values, variables
- Print "Hello, World!"
- System.out.println("Hello, World!");
- Fizz Buzz problem
- If statement
- For statement
| 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 |
- Java Virtual Machine Specification (Java 8 Edition)
- PHPใงJVMใๅฎ่ฃ ใใฆHello Worldใๅบๅใใใพใง (How to implement JVM in PHP and print "Hello, World".)
- ใใคใใณใผใ (ByteCode)
- JVM Stacks and Stack Frames
- Hotspot JVMใฎFrameใซใคใใฆ (About Frame on Hotspot JVM)
- Use cases of jvm dup instruction (StackOverFlow)
- Javaไปฎๆณใใทใณ (Wikipedia)
- ใณใณใใฅใผใฟใทในใใ ใฎ็่ซใจๅฎ่ฃ / ่จณ: ้ฝ่ค ๅบทๆฏ (The Elements of Computing Systems / Noam Nisan, Shimon Schocken)