Step 1. Magic Number
hex bytes name
--------- ----
CAFEBABE magic
First the Java Virtual Machine (JVM) must make sure that the class
file starts with the proper magic number. In this case the JVM will
be happy because it will find the CafeBabe magic right where it's
supposed to be.
Note that, because all multi-byte values are stored in the class
file in big-endian order, the first byte of every class file is 0xCA.
****
Step 2. Version Numbers
hex dec name
--- --- ----
0003 3 minor_version
002D 45 major_version
Next, the JVM must make sure that it recognizes and fully understands
the format of the class file being loaded. If either the major or
minor version number is not among the version numbers for which
this JVM was implemented, the JVM must reject the class file. In this
case, the JVM will be relieved to find that the file has major
version 45 and minor version 3, of which it has intimate knowledge.
****
Step 3. Constant Pool Count
0011 17 constant_pool_count
The next two bytes make up an unsigned short integer that indicates
the number of entries in the constant pool. In this case the
constant pool will have 17 entries, but because the zeroeth entry
doesn't appear in the class file, the JVM will expect to find
entries 1 through 16 next in the stream.
**
Step 4. constant_pool[1]
07 7 tag
0007 7 name_index
Each constant pool entry contains a table whose type is indicated
by the first byte of the entry, the tag.
The first constant pool entry is a CONSTANT_Class_info table. The JVM
knows this because it finds a 7, which means CONSTANT_Class, in the
tag byte position. Aside from the tag, the CONSTANT_Class_info table
has only a name_index, which in this case is 7. This is an index into
the constant pool. The JVM doesn't know it yet, because it hasn't
read in the 7th entry of the constant pool, but the 7th entry will
be the string "java/lang/Object", the name of the superclass of this
class. Because class Act doesn't explicitly descend from any other
class, it by default descends from class Object.
Note that this is the first constant pool entry and that it already
has index 1. constant_pool[0] doesn't appear in the class file.
***
Step 5. constant_pool[2]
07 7 tag
0010 16 name_index
The 2nd constant pool entry is another CONSTANT_Class_info table. The
JVM knows this because it again finds a 7, which still means
CONSTANT_Class, in the tag byte position. The name_index here,
however, is 16. constant_pool[16] will be the string "Act", although
once again the JVM doesn't know this yet because it hasn't read that
far into the constant pool. At this point the JVM only knows that
when it does get around to the 16th constant pool entry, that entry
will contain the name of the class that is represented by the
CONSTANT_Class_info table occupying constant_pool[2].
constant_pool[2] therefore represents the "this" class, class Act,
which this class file defines.
***
Step 6. constant_pool[3]
0A 10 tag
0002 1 class_index
0004 4 name_and_type_index
constant_pool[3] contains a CONSTANT_Methodref_info table, indicated
by the tag of 10, which means CONSTANT_Methodref. A
CONSTANT_Methodref_info table represents a method and records its
name, type, and the class to which it belongs. The first two bytes
after the tag, the class_index, form an index into the constant pool,
in this case a 2. constant_pool[2] represents class Act, so this
method is declared in Act.
The next two bytes make up the name_and_type_index, which is an index
into the constant pool pointing to a CONSTANT_NameAndType table. In
this case name_and_type_index is 4 and constant_pool[4] defines
"void <init>()". Because class Act doesn't declare its own
constructor, the javac compiler generates a default constructor,
Act(). Act() becomes the instance initialization method <init>() in
the class file. Act's <init>() method just calls <init>() in
superclass Object.
*****
Step 7. constant_pool[4]
0C 12 tag
0006 6 name_index
0005 5 descriptor_index
constant_pool[4] is a CONSTANT_NameAndType_info table identified by
its initial tag of 12, which stands for CONSTANT_NameAndType.
Following the tag byte is the name_index, which is 6.
constant_pool[6] will be the string "<init>". Next is the
descriptor_index, which is 5. constant_pool[5] will be the string
"()V".
"<init>" is the name of the method being described. "()V" is the
type. In plain Java it would look like "void <init>()". "()V" is a
method descriptor. The "()" indicates that there are no arguments to
"<init>". The "V" indicates the return type of "<init>" is void.
*****
Step 8. constant_pool[5]
01 1 tag
0003 3 length
282956 "()V" bytes[length]
constant_pool[5] is a CONSTANT_Utf8_info table that contains the
string "()V", a method descriptor that translates to a method that
takes no arguments and returns void.
CONSTANT_Utf8 is how strings are encoded in the constant pool. The
UTF-8 format allows any 16 bit character to be represented by either
1, 2, or 3 bytes. The characters '\u0001' to '\u007F' occupy only one
byte. Other characters require 2 or 3 bytes, however, these
characters are expected to appear less frequently than the characters
that require only 1 byte. By this means the full 16 bit Unicode
character set can be supported by the class file without using as
much space as would likely be used by just making each character 16
bits long.
The tag byte of a CONSTANT_Utf8_info table is followed by a length,
in this case 13, which indicates the length in bytes of the UTF-8
format string that follows. In this case the string spells out
"ConstantValue". This string is used internally by the class file in
a manner that will be described later in the file loading simulation.
There is no trailing null character in a CONSTANT_Utf8_info bytes
item, as that would unnecessarily waste bandwidth.
******
Step 9. constant_pool[6]
01 1 tag
0006 6 length
3C696E69743E "<init>" bytes[length]
constant_pool[6] is a CONSTANT_Utf8_info table that contains the
string "<init>", the name of a method in the superclass, Object.
*********
Step 10. constant_pool[7]
01 1 tag
0003 3 length
416374 "Act" bytes[length]
constant_pool[7] is a CONSTANT_Utf8_info table that contains the
string "Act". This is the name of the class that is being defined by
this file.
******
Step 11. constant_pool[8]
01 1 tag
000B 11 length
736E697065742E6A617661 "Act.java" bytes[length]
constant_pool[8] is a CONSTANT_Utf8_info table that contains the
string "Act.java", the name of the source file in which class Act was
defined. This string is referred to by a SourceFile attribute.
***********
Step 12. constant_pool[9]
01 1 tag
0004 4 length
436F6465 "Code" bytes[length]
constant_pool[9] is a CONSTANT_Utf8_info table that contains the
string "Code", an attribute name.
*******
Step 13. constant_pool[10]
01 1 tag
000D 13 length
436F6E7374616E7456616C7565 "ConstantValue" bytes[length]
constant_pool[10] is a CONSTANT_Utf8_info table that contains the
string "ConstantValue", an attribute name.
****************
Step 14. constant_pool[11]
01 1 tag
000A 10 length
457863657074696F6E73 "Exceptions" bytes[length]
constant_pool[11] is a CONSTANT_Utf8_info table that contains the string
"Exceptions", an attribute name.
*************
Step 15. constant_pool[12]
01 1 tag
000F 15 length
4C696E654E756D6265725461626C65 "LineNumberTable" bytes[length]
constant_pool[12] is a CONSTANT_Utf8_info table that contains the string
"LineNumberTable", an attribute name.
******************
Step 16. constant_pool[13]
01 1 tag
000E 14 length
4C6F63616C5661726961626C6573 "LocalVariables" bytes[length]
constant_pool[13] is a CONSTANT_Utf8_info tabl
没有合适的资源?快使用搜索试试~ 我知道了~
深入java虚拟机——applet 演示

共462个文件
java:204个
class:203个
html:24个

需积分: 10 74 浏览量
2007-05-10
20:56:14
上传
评论
收藏 679KB RAR 举报
温馨提示
深入java虚拟机——applet 演示, 深入java虚拟机的光盘中的所有文件。打包上传了
资源推荐
资源详情
资源评论



















收起资源包目录





































































































共 462 条
- 1
- 2
- 3
- 4
- 5
资源评论


iceman1952
- 粉丝: 42
- 资源: 33
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


安全验证
文档复制为VIP权益,开通VIP直接复制
