JVM Notes - 2

原创 2005年05月30日 21:47:00

The Java Class File
First the java programmer should know is that the class file is precisely defined
binary file(8-biy bytes). Every bit in it should be meaningful and can be validated
by the JVM.

The following is the item which defined in the class file sequencely:
1. Magic :
The identifier of the java class file which is the constant(0xCAFEBABE),
The derivation of this number is funny, it is the reference to a waiter in the Peet's

2. minor version and major_version.
As the java technology is growing fast, every time a new version comes, the format
of the class file may change, that there is such tag kept in the class file to
identify whether the class file is compatible for the JVM that user uses.
0003    3 minor_version
002D    45 major_version

3. constant_pool_count
0011    17 constant_pool_count
Indicates how many constant exist in the class file, it is also the total length
of constant_pool array. Note the zeroeth element does not appear in the class file
([:?:] where does it appear), JVM will expect to find element 1 to 16.

4. constant_pool
Every constants pool starts with a one-byte tag which indicates the type of constant.

07    7 tag
000C    12 name_index

when the JVM encounter the 7, it will get know that the current entry(not byte) is the
CONTANT_Class_info, base on the JVM spec


CONSTANT_Class_info {
    u1 tag;//a single unsigned byte
    u2 name_index;//2 unsigned byte, it should be a valid index of the constant_pool table
                  //it is the symbolic reference to a class or interface.
From the point 3. the range is 1 to 16. Let's jump to constant_pool[12]
01     1  tag
0010     16  length
6A6176612F6C616E672F4F626A656374  "java/lang/Object" bytes[length]
It is a Utf-8 entry
CONSTANT_Utf8_info {
     u1 tag;
     u2 length;
     u1 bytes[length];
From all those, JVM will know the super class is the object as it does not
explicitly specify any super calss. This procedure is to resolve the symbolic.

Actually, constant_pool contains:
1. class/interface info
2. field info
3. method info
And those ensure that the constant_pool will play an important role in the dynamic linking.

5. access_flag
The access_flag is followed by constant_pool. which can be the following possible values
ACC_PUBLIC     0x0001
ACC_FINAL      0x0010
ACC_SUPER      0x0020
such flag is two byte, as you seen in the above definition, every flag is two byte then
how can the class tell the JVM it is the public final class? good question, see the
following example you will know about these :
public final = (ACC_PUBLIC | ACC_FINAL) = 00011;
: ), quite smart.

6. this class
this_class should be next to access flag .
0002  2 this_class

the detail of contant_pool[2]:
07    7 tag
000D  13 name_index
then jump to constant_pool[13]
01  1  tag
0003  3  length
416374  "Act"  bytes[length]
It indicates this_class is the Act class
7. supper class
this class should be next to supper class.
0001  1 super_class

the detail of contant_pool[1]:
07    7 tag
000C    12 name_index
then jump to constant_pool[12]
01     1  tag
0010    16  length
6A6176612F6C616E672F4F626A656374  "java/lang/Object" bytes[length]
It indicates the super_class is the Object.

8. interface count and interfaces
the interface count is the length of the interfaces array, which indicates
how many interface such class is implemented, the item of interfaces array
is the reference to constant_pool.

9. fields count and fields
similar with above

10. methods_count ad methods
0009   access_flags
0006  6 name_index
0010  16 descriptor_index

take a look at constant_pool[6]
01      1   tag
000D    13   length
646F4D617468466F7265766572  "doMathForever"  bytes[length]
it indicates the method name
take a look at constant_pool[16]
01      1 tag
0003  3 length
282956  "()V" bytes[length]
it indicates the method has no argument and no return values.

also it defines the stak(max) size and local variable size.

11. attribute_count and attributes
attribute is something like the exceptions, innerclasses and so forth.

配置notes.ini参数调整domino JVM虚拟机内存大小

最近有个项目采用了金格的iWebOffice控件,集成到应用中之后,发现处理特别大的doc文件(>7M,>170页,基本上全是表格)时常要报错,提示内存溢出       在排除控件本身问题之后...

Understanding the JVM Reading Notes 1



本篇讲述小米便签中的定时提醒功能。  便签,可以理解为一件事情,一项任务,有个定时提醒的功能,还是蛮不错的~    小米便签定时功能,是当编辑便签的时候,有个菜单项,选了之后,就弹出一个“日期对话框”...

jfinal notes(2)

基于JFinal 的web项目需要创建一个 继承自 JFinalConfig类的 子类 ,该类用 于对整个  web项目进行配置 项目进行配置 。 JFinalConfig 子类需要实现 五个抽...

Programming Notes 2011_2


关于Andrew Ng讲义cs229-notes2-Generative Learning algorithms中1.2节的证明


Ng机器学习课程Notes学习及编程实战系列-Part 2 Logistic Regression

编者按:本系列系统总结Ng机器学习课程(http://cs229.stanford.edu/materials.html) Notes理论要点,并且给出所有课程exercise的作业code和实验结果...

机器学习基石notes-Lecture2 Learning to Answer Yes/No

感知机模型对于一组特征向量 X=(X1,X2,⋯,Xd)X = (X_1,X_2,\cdots,X_d),y:+1,−1{\cal y}:{+1,-1},将特征向量与权值向量做内积,其计算结果与阀值作...

Java Notes (2) - Conditionals and Control Flow

The note introduces how to use control flow and conditional statements in Java. Java notes of open c...
  • cxsydjn
  • cxsydjn
  • 2017年05月10日 01:36
  • 86

computer organization and design notes(2)

(1) 在MIPS中,一个字的地址必须是4的倍数,这叫做严格对齐。(alignment restriction) (2) MIPS采用big endian. (3) MIPS寻址时,偏移量先乘4再...
您举报文章:JVM Notes - 2