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虚拟机原代码
共462个文件
java:204个
class:203个
html:24个
5星 · 超过95%的资源 需积分: 3 190 下载量 126 浏览量
2008-01-30
14:59:48
上传
评论
收藏 678KB RAR 举报
温馨提示
深入JAVA虚拟机原代码
资源详情
资源评论
资源推荐
收起资源包目录
深入JAVA虚拟机原代码 (462个子文件)
policy.all 56B
makeit.bat 726B
ex2a.bat 181B
ex2b.bat 181B
ex2d.bat 181B
ex2c.bat 181B
Method.class 17KB
JVMSimulator.class 15KB
GarbageCollectCanvas.class 11KB
StringTable.class 10KB
InnerFloat.class 8KB
OpCode.class 6KB
LinkFishCanvas.class 6KB
GettingLoaded.class 6KB
UnlinkFishCanvas.class 5KB
AssignReferencesCanvas.class 5KB
SlicesOfPi.class 5KB
HeapOfFishStrings.class 4KB
OperandStackPanel.class 4KB
StackFrame.class 4KB
InnerInt.class 4KB
ThreeDArray.class 4KB
LocalVarsPanel.class 4KB
HopAround.class 3KB
MethodAreaPanel.class 3KB
LogicalResults.class 3KB
PrimeTime.class 3KB
PlayBall.class 3KB
JVMPacman.class 3KB
MoveFishCanvas.class 3KB
AllocateFishPanel.class 3KB
SayingTomato.class 3KB
HeapOfFish.class 3KB
SwimmingFishCanvas.class 3KB
FishIcon.class 3KB
ConversionDiversion.class 3KB
PoolsCanvas.class 3KB
GCHeap.class 2KB
CompactHeapCanvas.class 2KB
FibonacciForever.class 2KB
AssignReferencesPanel.class 2KB
CircleOfSquares.class 2KB
GreeterClassLoader.class 2KB
LittleYellowFishIcon.class 2KB
MediumBlueFishIcon.class 2KB
BigRedFishIcon.class 2KB
EternalMath.class 2KB
GreeterClassLoader.class 2KB
GridSnapLayout.class 2KB
HeapOfFishCanvases.class 2KB
GreeterClassLoader.class 2KB
CompactHeapPanel.class 2KB
HeapOfFishControlPanel.class 1KB
GarbageCollectPanel.class 1KB
Example1.class 1KB
IntAddTest.class 1KB
HeapOfFishModeCheckboxPanel.class 1KB
IntMultTest.class 1KB
AssignReferencesCheckboxPanel.class 1KB
PiCalculatorPrinter.class 1KB
YellowFishButtonCanvas.class 1KB
StepNode.class 1KB
NitpickyMath.class 1KB
BlueFishButtonCanvas.class 1KB
Example6.class 1KB
AssignReferencesCanvases.class 1KB
RedFishButtonCanvas.class 1KB
GreetAndForget.class 981B
GreetAndForget.class 981B
Example4.class 978B
GreetAndForget.class 956B
ControlPanel.class 954B
ColoredLabel.class 948B
HexString.class 947B
Greet.class 933B
Greet.class 933B
YellowFishButtonPanel.class 932B
ColoredLabel.class 930B
ColoredLabel.class 930B
ColoredLabel.class 930B
ColoredLabel.class 930B
HexString.class 929B
BlueFishButtonPanel.class 924B
RedFishButtonPanel.class 920B
TextFileDisplayer.class 910B
Greet.class 908B
ButtonPanel.class 904B
Echo.class 891B
CockerSpaniel.class 869B
AnswerReader.class 851B
EasyGreet.class 826B
EasyGreet.class 826B
Salutation.class 820B
HiTime.class 803B
Example1.class 794B
Example5.class 758B
ObjectHandle.class 748B
Cracker.class 743B
Subclass.class 731B
ExceptionTableEntry.class 710B
共 462 条
- 1
- 2
- 3
- 4
- 5
jxhtwang119
- 粉丝: 4
- 资源: 33
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论1