JVM

JVM

字节码

一次编译,到处运行

只面对 Java虚拟机(JVM),不同 OS 实现不同虚拟机

跨平台的核心

存储 200 左右指令,1字节 2**8 = 256

文件结构:

cafe babe 0000 0034 0018 0a00 0400 1409
0003 0015 0700 1607 0017 0100 0161 0100
0149 0100 063c 696e 6974 3e01 0003 2829
5601 0004 436f 6465 0100 0f4c 696e 654e
756d 6265 7254 6162 6c65 0100 124c 6f63
616c 5661 7269 6162 6c65 5461 626c 6501
0004 7468 6973 0100 1c4c 636f 6d2f 7261
796b 6579 7a7a 7a2f 7465 7374 2f4d 7954
6573 7431 3b01 0004 6765 7441 0100 0328
2949 0100 0473 6574 4101 0004 2849 2956
0100 0a53 6f75 7263 6546 696c 6501 000c
4d79 5465 7374 312e 6a61 7661 0c00 0700
080c 0005 0006 0100 1a63 6f6d 2f72 6179
6b65 797a 7a7a 2f74 6573 742f 4d79 5465
7374 3101 0010 6a61 7661 2f6c 616e 672f
4f62 6a65 6374 0021 0003 0004 0000 0001
0002 0005 0006 0000 0003 0001 0007 0008
0001 0009 0000 0038 0002 0001 0000 000a
2ab7 0001 2a04 b500 02b1 0000 0002 000a
0000 000a 0002 0000 0003 0004 0004 000b
0000 000c 0001 0000 000a 000c 000d 0000
0001 000e 000f 0001 0009 0000 002f 0001
0001 0000 0005 2ab4 0002 ac00 0000 0200
0a00 0000 0600 0100 0000 0600 0b00 0000
0c00 0100 0000 0500 0c00 0d00 0000 0100
1000 1100 0100 0900 0000 3e00 0200 0200
0000 062a 1bb5 0002 b100 0000 0200 0a00
0000 0a00 0200 0000 0900 0500 0a00 0b00
0000 1600 0200 0000 0600 0c00 0d00 0000
0000 0600 0500 0600 0100 0100 1200 0000
0200 13

16 进制表示的二进制流

cafe babe 代表是Java文件,0000 0034 版本号 52(1.8)

解释执行:将编译好的字节码一行一行地翻译为机器码执行。

编译执行:以方法为单位,将字节码一次性翻译为机器码后执行。

Classfile /E:/SoftWare/eclipse/eclipse-workspace/数据结构与算法/target/classes/com/raykeyzzz/test/MyTest1.class
  Last modified 2020-8-23; size 483 bytes
  MD5 checksum e1527511778dc63ffdd933957c24b801
  Compiled from "MyTest1.java"
public class com.raykeyzzz.test.MyTest1
  minor version: 0
  major version: 52
  flags: ACC_PUBLIC, ACC_SUPER
Constant pool:
   #1 = Methodref          #4.#20         // java/lang/Object."<init>":()V
   #2 = Fieldref           #3.#21         // com/raykeyzzz/test/MyTest1.a:I
   #3 = Class              #22            // com/raykeyzzz/test/MyTest1
   #4 = Class              #23            // java/lang/Object
   #5 = Utf8               a
   #6 = Utf8               I
   #7 = Utf8               <init>
   #8 = Utf8               ()V
   #9 = Utf8               Code
  #10 = Utf8               LineNumberTable
  #11 = Utf8               LocalVariableTable
  #12 = Utf8               this
  #13 = Utf8               Lcom/raykeyzzz/test/MyTest1;
  #14 = Utf8               getA
  #15 = Utf8               ()I
  #16 = Utf8               setA
  #17 = Utf8               (I)V
  #18 = Utf8               SourceFile
  #19 = Utf8               MyTest1.java
  #20 = NameAndType        #7:#8          // "<init>":()V
  #21 = NameAndType        #5:#6          // a:I
  #22 = Utf8               com/raykeyzzz/test/MyTest1
  #23 = Utf8               java/lang/Object
{
  public com.raykeyzzz.test.MyTest1();
    descriptor: ()V
    flags: ACC_PUBLIC
    Code:
      stack=2, locals=1, args_size=1
         0: aload_0
         1: invokespecial #1                  // Method java/lang/Object."<init>":()V
         4: aload_0
         5: iconst_1
         6: putfield      #2                  // Field a:I
         9: return
      LineNumberTable:
        line 3: 0
        line 4: 4
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0      10     0  this   Lcom/raykeyzzz/test/MyTest1;

  public int getA();
    descriptor: ()I
    flags: ACC_PUBLIC
    Code:
      stack=1, locals=1, args_size=1
         0: aload_0
         1: getfield      #2                  // Field a:I
         4: ireturn
      LineNumberTable:
        line 6: 0
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0       5     0  this   Lcom/raykeyzzz/test/MyTest1;

  public void setA(int);
    descriptor: (I)V
    flags: ACC_PUBLIC
    Code:
      stack=2, locals=2, args_size=2
         0: aload_0
         1: iload_1
         2: putfield      #2                  // Field a:I
         5: return
      LineNumberTable:
        line 9: 0
        line 10: 5
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0       6     0  this   Lcom/raykeyzzz/test/MyTest1;
            0       6     1     a   I
}
上一篇:Vue- 绑定的图片不显示


下一篇:Vue中使用n-avatar时要注意的点