https://docs.oracle.com/javase/specs/jvms/se8/jvms8.pdf
2.5 Run-Time Data Areas
运行时数据
PC
STACK
HEAP
The Java Virtual Machine has a method area that is shared among all Java Virtual Machine threads
方法区是所有线程共享的,不过和heap的区别是,堆存储的是实例和数组
类似于,操作系统的正文段,也就是编译后的方法代码
It stores per-class structures such as the run-time constant pool, field and method data, and the code for methods and constructors, including the special methods (§2.9) used in class and instance initialization and interface initialization.
2.5.5 Run-Time Constant Pool
运行时常量池
A run-time constant pool is a per-class or per-interface run-time representation of the constant_pool table in a class file (§4.4). It contains several kinds of constants, ranging from numeric literals known at compile-time to method and field references that must be resolved at run-time. The run-time constant pool serves a function similar to that of a symbol table for a conventional programming language, although it contains a wider range of data than a typical symbol table.
Each run-time constant pool is allocated from the Java Virtual Machine's method area (§2.5.4).
其实就是一个表,具体哪个表,参考:
IDEA使用jclasslib-bytecode-viewer插件查看字节码_newbaby2012的博客-CSDN博客
首先这些不是实例,所以不在heap,其次是所有线程共享的,所以不会再stack里
java有很多的异常处理器,exception handler
java的同步,主要通过管程来完成,通过ACC_SYNCHRONIZED标记一个方法是不是同步方法,然后有个字段代表是否有谁在访问这个同步方法,我觉得是monitorenter和moniterexit用来修改这个字段的
第三章 Java虚拟机编译器
Class文件格式
A class file consists of a single ClassFile structure:
this_class 类索引,即常量池中的一个index,索引中的项必须是CONSTANT_Class_info 类型常量
super_class父类索引,索引中的项必须是CONSTANT_Class_info 类型常量
4.2 内部表示名称
字段描述
The field descriptor of an instance variable of the multidimensional array type double[] [][] is [[[D
方法描述
签名
类签名
其中bounds定义如下:
字段类型签名
类的类型签名(不同于类的签名)
方法签名
4.4 常量池
常量池由两部分组成,一个标记,一个信息,常见的标记如下
CONSTANT_Class_info
值得一提的是,数组也是一种对象,而他们的名字就是:
CONSTANT_Fieldref_info, CONSTANT_Methodref_info 和
CONSTANT_InterfaceMethodref_info 结构
而CONSTANT_Utf8_info如下,哦这么看。class其实指向一个字节数组,里面其实就是类信息对应的字节码(不对,是常量String字符串),所以常量池就是CONSTANT_Utf8_info这一类CONSTANT开头的东西?
CONSTANT_MethodHandle_info 结构
CONSTANT_MethodType_info
CONSTANT_InvokeDynamic_info
method_info和field_info都包含attribute_info,属性信息常见的有:
ConstantValue,Code,Exception
field
method 咋感觉和field一模一样
里面的attributes_info就是
总共有23种attributes
The number of method parameters is limited to 255 by the definition of a method descriptor (§4.3.3), where the limit includes one unit for this in the case of instance or interface method invocations.
The size of an operand stack in a frame (§2.6) is limited to 65535 values by the max_stack field of the Code attribute (§4.7.3).
Loading, Linking, and Initializing
Loading就是找到二进制文件(classloader的功能),并且据此创建class字节码文件
符号引用( symbolic reference):就是不是直接指向内存地址,类似于spring中的${ocr.port}
The Run-Time Constant Pool
运行时常量池,其实首先取决于常量池,会有很多符号引用,而这些符号引用都来自于constant_pool的各种info
All references in the run-time constant pool are initially symbolic.
A symbolic reference to a field of a class or an interface is derived from a CONSTANT_Fieldref_info structure (§4.4.2) in the binary representation of a class or interface. Such a reference gives the name and descriptor of the field, as well as a symbolic reference to the class or interface in which the field is to be found.
一个引用会给出Field的名字和描述符,并且给出另一个引用,这个引用指向Field对应的class
Run-time constant values are derived from CONSTANT_Integer_info, CONSTANT_Float_info, CONSTANT_Long_info, or CONSTANT_Double_info structures (§4.4.4, §4.4.5) in the binary representation of a class or interface.
看到5.2